/* ApexFlow motion layer: one interaction rhythm for every screen.
   Tokens live in design-system.css (:root). JS helpers live in ui.js.
   Only transform, opacity and paint-cheap properties move. Reduced motion
   (system setting or the effects toggle) leaves the finished, static state. */

/* 1. Press and hover. `scale` composes with any positioning transform. */
.primary-button,
.generate-button,
.subtle-button,
.menu-row,
.nav-item,
.studio-choices button,
.history-filters button,
.admin-text-button {
  transition:
    background-color var(--dur-fast) ease,
    border-color var(--dur-fast) ease,
    color var(--dur-fast) ease,
    box-shadow var(--dur-med) var(--ease-out),
    opacity var(--dur-fast) ease,
    scale var(--dur-press) var(--ease-out);
}
.icon-button {
  transition:
    background-color var(--dur-fast) ease,
    color var(--dur-fast) ease,
    opacity var(--dur-fast) ease,
    scale var(--dur-press) var(--ease-out);
}
:is(
    .primary-button,
    .generate-button,
    .subtle-button,
    .menu-row,
    .studio-choices button,
    .history-filters button
  ):active:not(:disabled) {
  scale: 0.97;
}
.icon-button:active:not(:disabled),
.nav-item:active:not(:disabled) {
  scale: 0.94;
}
html[data-motion="reduced"] :is(button, a, [role="button"]):active,
html[data-input="keyboard"] :is(button, a, [role="button"]):active {
  scale: none;
}

/* 2. Primary action: one warm light pass on hover (design-system ::after),
   slowed to read as light, plus a soft lift of its own glow. Never a loop. */
.primary-button::after,
.generate-button::after {
  transition:
    transform 160ms var(--ease-out),
    opacity 120ms ease;
}
@media (hover: hover) and (pointer: fine) {
  .primary-button:hover:not(:disabled)::after,
  .generate-button:hover:not(:disabled)::after {
    transition:
      transform 680ms var(--ease-out),
      opacity var(--dur-fast) ease;
  }
  html[data-motion="full"] .primary-button:not(:disabled):hover,
  html[data-motion="full"] .generate-button:not(:disabled):hover {
    box-shadow:
      0 8px 26px #efb8652e,
      inset 0 1px 0 #fff5;
  }
}

/* 3. Cursor light: the card edge catches light where the pointer is.
   ui.js writes --lx/--ly on the hovered card only (never on a container). */
:is(
    .project-card,
    .media-card,
    .pool-card,
    .admin-metric,
    .studio-film,
    .studio-stage-card,
    .studio-board-card
  ) {
  position: relative;
}
:is(
    .project-card,
    .media-card,
    .pool-card,
    .admin-metric,
    .studio-film,
    .studio-stage-card,
    .studio-board-card
  )::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 3;
  border-radius: inherit;
  pointer-events: none;
  padding: 1px;
  background: radial-gradient(
    220px circle at var(--lx, 50%) var(--ly, 0%),
    var(--spot-edge),
    transparent 70%
  );
  -webkit-mask:
    linear-gradient(#000 0 0) content-box exclude,
    linear-gradient(#000 0 0);
  mask:
    linear-gradient(#000 0 0) content-box exclude,
    linear-gradient(#000 0 0);
  opacity: 0;
  transition: opacity var(--dur-med) ease;
}
@media (hover: hover) and (pointer: fine) {
  html[data-motion="full"]
    :is(
      .project-card,
      .media-card,
      .pool-card,
      .admin-metric,
      .studio-film,
      .studio-stage-card,
      .studio-board-card
    ):hover::after {
    opacity: 1;
  }
  /* Media breathes slightly inside its own frame; the card never jumps. */
  html[data-motion="full"] .media-card .media-open :is(img, video) {
    transition:
      opacity var(--dur-med) ease,
      scale var(--dur-layout) var(--ease-out);
  }
  html[data-motion="full"] .media-card:hover .media-open :is(img, video) {
    scale: 1.025;
  }
}
.media-card .media-open {
  overflow: hidden;
}

/* 4. Darkroom: the signature moment of ApexFlow. Amber is the safelight of a
   photo lab. A card that is really generating shows live film grain, and a
   developing front advances with the provider's real progress (--progress,
   0–100, set by app.js from the job). Nothing here invents progress. */
@property --progress {
  syntax: "<number>";
  inherits: true;
  initial-value: 0;
}
.job-card:not(.job-failed) {
  overflow: hidden;
}
.job-card {
  position: relative;
  transition: --progress 1.2s var(--ease-out);
}
.job-card:is(
    [data-state="preparing"],
    [data-state="submitting"],
    [data-state="running"],
    [data-state="downloading"]
  )::before {
  content: "";
  position: absolute;
  inset: -40px;
  z-index: 0;
  pointer-events: none;
  background:
    url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='180' height='180'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 1 0 0 0 0 .8 0 0 0 0 .5 .75 0 0 0 0'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>"),
    radial-gradient(70% 90% at 50% 120%, #efb86524, transparent 70%);
  background-size:
    180px 180px,
    100% 100%;
  mix-blend-mode: screen;
  opacity: 0.2;
}
.job-card:is(
    [data-state="preparing"],
    [data-state="submitting"],
    [data-state="running"],
    [data-state="downloading"]
  )::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  /* Developed area is only a breath lighter; the front is a thin line of
     safelight with a soft bloom behind it. */
  background: linear-gradient(
    90deg,
    #efb86505 0%,
    #efb8650a calc(var(--progress) * 1% - 12%),
    #efb86526 calc(var(--progress) * 1% - 1.6%),
    #ffe2b8b3 calc(var(--progress) * 1% - 0.15%),
    #fff3dcd9 calc(var(--progress) * 1%),
    transparent calc(var(--progress) * 1% + 0.15%)
  );
}
html[data-motion="full"]
  .job-card:is(
    [data-state="preparing"],
    [data-state="submitting"],
    [data-state="running"],
    [data-state="downloading"]
  )::before {
  animation: film-grain 0.6s steps(6) infinite;
}
@keyframes film-grain {
  0% { translate: 0 0; }
  17% { translate: -22px 14px; }
  33% { translate: 18px -26px; }
  50% { translate: -12px 30px; }
  67% { translate: 28px -8px; }
  83% { translate: -30px -18px; }
  100% { translate: 0 0; }
}
/* The live status word shimmers while the provider is really working. */
html[data-motion="full"]
  .job-card:is([data-state="running"], [data-state="downloading"])
  .job-center
  > strong {
  background: linear-gradient(100deg, var(--text) 40%, #ffd59a 50%, var(--text) 60%) 0 0 / 250% 100%;
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  animation: live-pass 2.2s linear infinite;
}
.job-card .job-center {
  position: relative;
  z-index: 1;
}
.job-card .job-bar {
  z-index: 1;
  transition: transform var(--dur-layout) var(--ease-out);
}
@keyframes live-pass {
  from {
    background-position: 120% 0;
  }
  to {
    background-position: -20% 0;
  }
}
html[data-visibility="hidden"] .job-card::before,
html[data-visibility="hidden"] .job-card .job-center > strong,
.modal-open .job-card::before {
  animation-play-state: paused;
}

/* A finished frame develops in place: from a dim, warm, soft latent image
   with grain to the real picture. Runs once, when a new frame's pixels
   arrive (first load of a project or a finished generation). */
html[data-motion="full"] .gallery .media-card.developing .media-open img {
  animation: develop 1.7s var(--ease-out) var(--develop-delay, 0ms) both;
}
html[data-motion="full"] .gallery .media-card.developing:not(.is-expired) .media-open::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  background:
    url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='180' height='180'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 1 0 0 0 0 .78 0 0 0 0 .48 .9 0 0 0 0'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>") 0 0 / 180px 180px,
    radial-gradient(80% 70% at 50% 50%, #efb86533, transparent 75%);
  mix-blend-mode: screen;
  animation: develop-grain 1.7s ease-out var(--develop-delay, 0ms) both;
}
@keyframes develop {
  0% {
    filter: blur(18px) sepia(1) saturate(0.35) brightness(0.45) contrast(1.5);
    scale: 1.1;
  }
  45% {
    filter: blur(5px) sepia(0.55) saturate(0.7) brightness(0.8) contrast(1.2);
  }
  100% {
    filter: none;
    scale: 1;
  }
}
@keyframes develop-grain {
  0% { opacity: 0.95; }
  60% { opacity: 0.35; }
  100% { opacity: 0; }
}
/* 5. Skeletons: same geometry as the content they stand in for. */
.skeleton,
.admin-loading-preview > *,
.studio-skeleton {
  position: relative;
  overflow: hidden;
  background-color: #ffffff08;
  border-radius: var(--radius-sm);
}
:is(.skeleton, .admin-loading-preview > *, .studio-skeleton)::after {
  content: "";
  position: absolute;
  inset: 0;
  translate: -100% 0;
  background: linear-gradient(90deg, transparent, #ffffff0d, transparent);
  animation: skeleton-sweep 1.5s var(--ease-in-out) infinite;
}
@keyframes skeleton-sweep {
  to {
    translate: 100% 0;
  }
}

/* Gallery media still on its way: the frame keeps its final geometry and
   shows a quiet sweep instead of black bars. */
.gallery .media-card:has(.media-open img:not([data-loaded]))::before,
.gallery .media-card[data-measuring]::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
  background: linear-gradient(
    100deg,
    transparent 30%,
    #ffffff0a 50%,
    transparent 70%
  );
  background-size: 250% 100%;
  animation: live-pass 1.6s linear infinite;
}

/* 6. Disclosure: content settles in under the summary. */
@supports selector(::details-content) {
  html[data-motion="full"] details::details-content {
    transition:
      opacity var(--dur-med) ease,
      content-visibility var(--dur-med) allow-discrete;
    opacity: 0;
  }
  html[data-motion="full"] details[open]::details-content {
    opacity: 1;
  }
}
summary > .icon:first-child,
summary::marker {
  transition: rotate var(--dur-fast) var(--ease-out);
}

/* 7. Toast: top centre over the header band, never over the composer,
   page titles or dialog actions. */
#toast {
  position: fixed;
  top: max(12px, env(safe-area-inset-top));
  bottom: auto;
  left: 50%;
  z-index: 70;
  translate: -50% -12px;
  transform: none;
  scale: 0.98;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition:
    opacity var(--dur-fast) ease,
    translate var(--dur-slow) var(--ease-out),
    scale var(--dur-slow) var(--ease-out),
    visibility 0s linear var(--dur-slow);
}
#toast.visible {
  transform: none;
  translate: -50% 0;
  scale: 1;
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transition:
    opacity var(--dur-fast) ease,
    translate var(--dur-slow) var(--ease-out),
    scale var(--dur-slow) var(--ease-out),
    visibility 0s;
}
#toast::before {
  content: "";
  flex: 0 0 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-soft);
}
@media (max-width: 760px) {
  #toast {
    top: max(10px, env(safe-area-inset-top));
    width: calc(100vw - 32px);
    max-width: none;
  }
}

/* 8. Navigation: the active item carries a lit edge. */
.nav-item {
  position: relative;
}
.nav-item.active::before {
  content: "";
  position: absolute;
  left: -14px;
  top: 50%;
  width: 3px;
  height: 18px;
  translate: 0 -50%;
  border-radius: 0 3px 3px 0;
  background: var(--accent);
  box-shadow: 0 0 12px #efb86580;
}

/* 9. Tables and rows answer the pointer quietly. */
@media (hover: hover) and (pointer: fine) {
  .admin-table tbody tr {
    transition: background-color var(--dur-fast) ease;
  }
  .admin-table tbody tr:hover {
    background-color: #ffffff05;
  }
}

/* 10. Dialog material: the backdrop is part of the entrance. */
.modal-overlay {
  transition: opacity var(--dur-med) ease;
}

/* Reduced motion: finished states only, no loops, no tracking light. */
html[data-motion="reduced"] .job-card::before,
html[data-motion="reduced"] .gallery .media-card::before,
html[data-motion="reduced"] :is(.skeleton, .admin-loading-preview > *, .studio-skeleton)::after {
  animation: none;
  opacity: 0;
}
@media (prefers-reduced-motion: reduce) {
  .job-card::before,
  :is(.skeleton, .admin-loading-preview > *, .studio-skeleton)::after {
    animation: none;
    opacity: 0;
  }
  #toast,
  #toast.visible {
    translate: -50% 0;
    scale: 1;
  }
}


/* ── Response layer ─────────────────────────────────────────────────────
   Motion that answers the person: focusing the prompt, pressing, moving
   between sections, pointing at a frame. Amber light on graphite only. */

@property --spin {
  syntax: "<angle>";
  inherits: false;
  initial-value: 0deg;
}
@keyframes spin-light {
  to {
    --spin: 360deg;
  }
}
/* The prompt is the heart of Генерация: when it has focus, a ray of
   safelight runs around it. */
.composer {
  position: relative;
}
.composer::after {
  content: "";
  position: absolute;
  inset: -1px;
  z-index: 4;
  border-radius: inherit;
  padding: 1.5px;
  pointer-events: none;
  background: conic-gradient(
    from var(--spin),
    transparent 0deg 200deg,
    #efb86533 250deg,
    #efb865 320deg,
    #fff1d6 340deg,
    #efb86500 352deg,
    transparent 360deg
  );
  -webkit-mask:
    linear-gradient(#000 0 0) content-box exclude,
    linear-gradient(#000 0 0);
  mask:
    linear-gradient(#000 0 0) content-box exclude,
    linear-gradient(#000 0 0);
  opacity: 0;
  transition: opacity 420ms ease;
}
html[data-motion="full"] .composer:focus-within::after {
  opacity: 1;
  animation: spin-light 3.6s linear infinite;
}
html[data-motion="full"] .composer:focus-within {
  box-shadow:
    var(--shadow-float),
    0 0 0 1px #efb86526,
    0 24px 70px -18px #efb8654d;
}
html[data-visibility="hidden"] .composer::after {
  animation-play-state: paused;
}

/* Frames and projects rise slightly toward the pointer; the image breathes
   inside its own frame. Operational cards (pool, admin) stay still. */
:is(.gallery .media-card, .project-card) {
  transition:
    translate 420ms var(--ease-out),
    box-shadow 420ms var(--ease-out),
    border-color var(--dur-med) ease;
}
@media (hover: hover) and (pointer: fine) {
  html[data-motion="full"] :is(.gallery .media-card, .project-card):hover {
    translate: 0 -3px;
    border-color: #efb8654d;
    box-shadow:
      0 26px 60px -24px #000000e6,
      0 14px 44px -20px #efb86559;
  }
  html[data-motion="full"] .gallery .media-card:hover .media-open :is(img, video) {
    scale: 1.05;
  }
}

/* A press sends a ring of light out from the exact point of contact. */
.ripple-host {
  overflow: hidden;
  isolation: isolate;
}
.press-ripple {
  position: absolute;
  z-index: 0;
  width: var(--size);
  height: var(--size);
  left: var(--x);
  top: var(--y);
  translate: -50% -50%;
  border-radius: 50%;
  pointer-events: none;
  background: radial-gradient(circle, #fff5e066 0%, #efb86538 38%, transparent 70%);
  animation: press-ripple 620ms var(--ease-out) forwards;
}
:is(.primary-button, .generate-button) .press-ripple {
  background: radial-gradient(circle, #ffffffa0 0%, #fff4dd40 40%, transparent 70%);
}
@keyframes press-ripple {
  from {
    scale: 0.1;
    opacity: 1;
  }
  to {
    scale: 1;
    opacity: 0;
  }
}

/* Navigation: one lit pill glides to the active section. */
.has-glider {
  position: relative;
}
.nav-glider {
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  z-index: 0;
  height: var(--h, 43px);
  translate: 0 var(--y, 0);
  border-radius: 10px;
  background: var(--accent-soft);
  border: 1px solid #efb86526;
  box-shadow: 0 0 24px -6px #efb86540;
  pointer-events: none;
  opacity: 0;
  transition:
    translate 520ms var(--ease-spring),
    height 520ms var(--ease-spring),
    opacity 200ms ease;
}
.nav-glider::before {
  content: "";
  position: absolute;
  left: -14px;
  top: 50%;
  width: 3px;
  height: 18px;
  translate: 0 -50%;
  border-radius: 0 3px 3px 0;
  background: var(--accent);
  box-shadow: 0 0 14px #efb865b3;
}
.nav-glider.ready {
  opacity: 1;
}
.has-glider > .nav-item {
  position: relative;
  z-index: 1;
}
.has-glider:has(> .nav-glider.ready) > .nav-item.active {
  background: transparent;
  border-color: transparent;
}
.has-glider:has(> .nav-glider.ready) > .nav-item.active::before {
  display: none;
}

/* Reduced motion: resting states only. */
html[data-motion="reduced"] .composer::after,
html[data-motion="reduced"] .press-ripple {
  display: none;
}
html[data-motion="reduced"] .nav-glider {
  transition: none;
}
/* Thumbnail becomes the viewer (ui.js morphInto). The frame keeps its shape
   on the way: the small frame is cropped, the viewer frame is fitted. */
::view-transition-group(apex-media) {
  animation-duration: 480ms;
  animation-timing-function: var(--ease-out);
  border-radius: 13px;
  overflow: clip;
}
::view-transition-old(apex-media) {
  height: 100%;
  object-fit: cover;
}
::view-transition-new(apex-media) {
  height: 100%;
  object-fit: contain;
}

/* Safelight behind the prompt bar, only while a generation really runs. */
.composer-wrap::before {
  content: "";
  position: absolute;
  inset: -60px -12% -30px;
  z-index: -1;
  pointer-events: none;
  background: radial-gradient(50% 60% at 50% 70%, #efb86524, transparent 70%);
  opacity: 0;
  transition: opacity 900ms ease;
}
.composer-wrap.is-generating::before {
  opacity: 1;
}
html[data-motion="full"] .composer-wrap.is-generating::before {
  animation: safelight-breathe 5.5s ease-in-out infinite alternate;
}
@keyframes safelight-breathe {
  from {
    opacity: 0.55;
    scale: 0.96;
  }
  to {
    opacity: 1;
    scale: 1.04;
  }
}
html[data-visibility="hidden"] .composer-wrap::before,
.modal-open .composer-wrap::before {
  animation-play-state: paused;
}
/* During the frame-to-viewer morph the page stays still and the viewer
   develops over it; only the frame itself travels. */
html:active-view-transition-type(media)::view-transition-old(root) {
  animation: none;
}
html:active-view-transition-type(media)::view-transition-new(root) {
  animation: viewer-in 320ms ease-out both;
}
@keyframes viewer-in {
  from {
    opacity: 0;
  }
}