/* serov.dev — one frame, two planes. Tokens per stylization; the glow colour comes from the take (JS sets --glow). */
:root {
  --glow: #ffb04a;
  --bar-h: 120px;
  --bg: #000;
  --bg-2: #000;
  --ink: #f3efe6;        /* the thought */
  --ui: #e4ded3;         /* signature, buttons */
  --muted: #b3ac9f;      /* labels */
  --line: rgba(243, 239, 230, .28);
  --scrim: rgba(0, 0, 0, .62);
  --accent: var(--glow);
  --cap-font: 600 clamp(1.55rem, 1.1rem + 1.7vw, 2.75rem)/1.16 'Cormorant Garamond', Georgia, serif;
  --cap-spacing: .005em;
  --vignette: rgba(0, 0, 0, .6);
  --ui-font: 'IBM Plex Sans', system-ui, sans-serif;
  --mono: 'IBM Plex Mono', ui-monospace, monospace;
  color-scheme: dark;
}
body[data-style="collodion"] {
  --bg: #1a1410; --bg-2: #1a1410;
  --ink: #f1e7d0; --ui: #eadfca; --muted: #bcae95; --line: rgba(241, 231, 208, .28);
  --scrim: rgba(18, 13, 9, .66);
  --cap-font: italic 400 clamp(1.45rem, 1.05rem + 1.5vw, 2.45rem)/1.22 'Old Standard TT', Georgia, serif;
  --vignette: rgba(10, 6, 3, .62);
}
body[data-style="animatic"] {
  --bg: #ece4d6; --bg-2: #ece4d6;
  --ink: #241d17; --ui: #2b231c; --muted: #463c33; --line: rgba(43, 35, 28, .32);
  --scrim: rgba(236, 228, 214, .82);
  --accent: #b5442c;
  --cap-font: 500 clamp(1.9rem, 1.35rem + 2vw, 3.3rem)/1.08 'Caveat', 'Segoe Print', cursive;
  --vignette: rgba(80, 60, 40, .22);
  color-scheme: light;
}
body[data-style="anime"] {
  --bg: #5c96c4; --bg-2: #eca0aa;
  --ink: #ffffff; --ui: #16192a; --muted: #11152a; --line: rgba(22, 25, 42, .34);
  --scrim: rgba(18, 22, 44, .6);
  --cap-font: 500 clamp(1.35rem, 1rem + 1.35vw, 2.2rem)/1.3 'IBM Plex Sans', system-ui, sans-serif;
  --cap-spacing: .01em;
  --vignette: rgba(30, 20, 60, .2);
  color-scheme: light;
}
body.rare { --accent: #ffd76a; }

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: linear-gradient(var(--bg), var(--bg) 40%, var(--bg-2) 82%);
  background-color: var(--bg);
  color: var(--ui);
  font: 400 1rem/1.45 var(--ui-font);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  transition: background-color .2s;
}
button, input { font: inherit; color: inherit; }
a { color: inherit; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

/* ---------- stage: the frame ---------- */
.stage { position: fixed; inset: 0; overflow: hidden; cursor: pointer; touch-action: none; user-select: none; -webkit-user-select: none; }
.face-wrap {
  --fh: min(100svh, max(125vw, 78svh));
  position: absolute; left: 50%; top: 0;
  height: var(--fh); aspect-ratio: 4 / 5;
  transform: translate(calc(-50% + var(--hx, 0px)), var(--hy, 0px));
  -webkit-mask-image: linear-gradient(to bottom, transparent, #000 3%, #000 72%, transparent 97%), linear-gradient(to right, transparent 2%, #000 20%, #000 80%, transparent 98%);
  -webkit-mask-composite: source-in;
  mask-image: linear-gradient(to bottom, transparent, #000 3%, #000 72%, transparent 97%), linear-gradient(to right, transparent 2%, #000 20%, #000 80%, transparent 98%);
  mask-composite: intersect;
  opacity: 0;
  transition: opacity .6s ease;
}
body.ready .face-wrap { opacity: 1; }
#face { display: block; width: 100%; height: 100%; will-change: filter; }
.face-fallback { position: absolute; left: 50%; top: 0; height: 100svh; transform: translateX(-50%); }

.vignette { position: absolute; inset: 0; pointer-events: none; background: radial-gradient(ellipse 70% 72% at 50% 42%, transparent 55%, var(--vignette)); }
.grain { position: absolute; inset: -10%; pointer-events: none; background-size: 192px 192px; mix-blend-mode: overlay; }
body.still .grain { opacity: .08 !important; }

/* bokeh: out-of-focus lights in the take's glow */
.bokeh { position: absolute; inset: 0; pointer-events: none; opacity: 0; mix-blend-mode: screen; }
body[data-style="animatic"] .bokeh, body[data-style="anime"] .bokeh { mix-blend-mode: normal; }
.bokeh i {
  position: absolute; width: var(--s); height: var(--s); margin: calc(var(--s) / -2) 0 0 calc(var(--s) / -2);
  border-radius: 50%;
  background: radial-gradient(circle, color-mix(in srgb, var(--accent) 16%, transparent) 0 56%, color-mix(in srgb, var(--accent) 34%, transparent) 66%, transparent 72%);
  filter: blur(1.5px);
}
.bokeh[data-shape="anamorphic"] i { width: calc(var(--s) * .55); height: var(--s); border-radius: 50% / 50%; }
.bokeh[data-shape="anamorphic"] i::after {
  content: ''; position: absolute; left: -260%; right: -260%; top: 50%; height: 1px;
  background: linear-gradient(90deg, transparent, color-mix(in srgb, var(--accent) 55%, transparent), transparent);
}
.bokeh[data-shape="hex"] i { border-radius: 0; clip-path: polygon(25% 4%, 75% 4%, 100% 50%, 75% 96%, 25% 96%, 0 50%); }

/* the thought: floats in front of the face */
.caption {
  position: absolute; left: 50%; bottom: calc(var(--bar-h) + 4.5svh);
  transform: translateX(-50%);
  width: min(88vw, 21em);
  margin: 0; text-align: center;
  font: var(--cap-font); letter-spacing: var(--cap-spacing);
  color: var(--ink);
  text-wrap: balance;
  isolation: isolate;
  cursor: default;
  transition: opacity .26s ease;
}
.caption.fading { opacity: 0; }
.caption::before {
  content: ''; position: absolute; z-index: -1; inset: -1.1em -1.4em;
  background: radial-gradient(closest-side, var(--scrim), transparent);
  pointer-events: none;
}
body:not([data-style="animatic"]) .caption { text-shadow: 0 1px 2px rgba(0, 0, 0, .75), 0 2px 18px rgba(0, 0, 0, .55); }
body[data-style="anime"] .caption { text-shadow: 0 0 2px #12162b, 0 1px 3px #12162b, 0 0 16px rgba(18, 22, 44, .55); }
.caption .ch { white-space: pre-wrap; }
.cap-link { font: 500 1rem/1 var(--ui-font); display: inline-block; margin-left: .5em; padding: .45em .8em; border: 1px solid currentColor; border-radius: 999px; text-decoration: none; vertical-align: middle; text-shadow: none; }

/* autofocus brackets */
.brackets { position: fixed; left: var(--bx, 30%); top: var(--by, 20%); width: var(--bw, 40%); height: var(--bh, 50%); pointer-events: none; transition: left .38s cubic-bezier(.2, .8, .2, 1), top .38s cubic-bezier(.2, .8, .2, 1), width .38s cubic-bezier(.2, .8, .2, 1), height .38s cubic-bezier(.2, .8, .2, 1); }
.brackets i { position: absolute; width: 18px; height: 18px; border: 0 solid var(--accent); opacity: .85; }
.brackets i:nth-child(1) { left: 0; top: 0; border-left-width: 1.5px; border-top-width: 1.5px; }
.brackets i:nth-child(2) { right: 0; top: 0; border-right-width: 1.5px; border-top-width: 1.5px; }
.brackets i:nth-child(3) { left: 0; bottom: 0; border-left-width: 1.5px; border-bottom-width: 1.5px; }
.brackets i:nth-child(4) { right: 0; bottom: 0; border-right-width: 1.5px; border-bottom-width: 1.5px; }
body.still .brackets { transition: none; }

.blackout { position: fixed; inset: 0; background: #000; opacity: 0; pointer-events: none; }
.blackout.on { opacity: 1; }

/* ---------- HUD ---------- */
.hud {
  position: fixed; left: 0; right: 0; top: 0; z-index: 3;
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: max(12px, env(safe-area-inset-top)) 18px 0;
  font: 400 .875rem/1.2 var(--mono); color: var(--muted);
  pointer-events: none;
}
.hud-left { display: flex; align-items: center; gap: 4px; min-width: 0; }
.hud button { pointer-events: auto; }
.take { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.frame { white-space: nowrap; flex-shrink: 0; }
.director { margin-left: 10px; padding: 2px 8px; border: 1px solid var(--line); border-radius: 999px; color: var(--ui); white-space: nowrap; }
.rec { width: 32px; height: 32px; padding: 0; border: 0; background: none; display: grid; place-items: center; cursor: pointer; border-radius: 50%; }
.rec span { width: 10px; height: 10px; border-radius: 50%; background: #e5484d; }
.rec.off span { background: transparent; box-shadow: inset 0 0 0 1.5px var(--muted); }
@media (prefers-reduced-motion: no-preference) {
  body:not(.still) .rec:not(.off) span { animation: rec 1.6s steps(1) infinite; }
  @keyframes rec { 50% { opacity: .25; } }
}

/* ---------- signature + controls ---------- */
.bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 3;
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px 18px;
  padding: 28px 18px max(14px, env(safe-area-inset-bottom));
  background: linear-gradient(to top, color-mix(in srgb, var(--bg-2) 94%, transparent) 40%, transparent);
}
.sign { margin: 0; font-size: 1rem; color: var(--ui); transition: color .3s; }
.sign .name { font-weight: 500; }
.sign .role { color: var(--muted); }
.sign a { color: var(--ui); text-decoration-color: color-mix(in srgb, var(--accent) 70%, transparent); text-underline-offset: 3px; text-decoration-thickness: 1.5px; }
body.seen .sign a, body.final .sign a { color: var(--accent); }
body[data-style="animatic"].seen .sign a, body[data-style="animatic"].final .sign a { color: #8f2f1c; }
body[data-style="anime"].seen .sign a, body[data-style="anime"].final .sign a { color: #16192a; text-decoration-color: #16192a; }

.controls { display: flex; flex-wrap: wrap; gap: 8px; }
.controls button {
  min-height: 40px; padding: 0 14px;
  border: 1px solid var(--line); border-radius: 999px;
  background: color-mix(in srgb, var(--bg-2) 55%, transparent);
  color: var(--ui); font-size: .875rem; cursor: pointer;
}
.controls button:hover { border-color: var(--ui); }
.controls button.icon { width: 40px; padding: 0; display: grid; place-items: center; }
.controls button[aria-pressed="true"] { border-color: var(--ui); background: color-mix(in srgb, var(--ui) 14%, transparent); }
#motion { display: inline-flex; align-items: center; gap: 10px; }
#motion .sw { position: relative; width: 30px; height: 18px; border-radius: 999px; background: color-mix(in srgb, var(--ui) 25%, transparent); }
#motion .sw::after { content: ''; position: absolute; left: 2px; top: 2px; width: 14px; height: 14px; border-radius: 50%; background: var(--ui); }
#motion[aria-checked="true"] .sw { background: color-mix(in srgb, var(--accent) 80%, transparent); }
#motion[aria-checked="true"] .sw::after { transform: translateX(12px); }
@media (prefers-reduced-motion: no-preference) { #motion .sw::after { transition: transform .18s ease; } }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
body[data-style="animatic"] :focus-visible, body[data-style="anime"] :focus-visible { outline-color: var(--ui); }

@media (max-width: 640px) {
  .bar { padding: 22px 14px max(12px, env(safe-area-inset-bottom)); gap: 8px; }
  .sign { font-size: .95rem; }
  .controls { gap: 6px; }
  .controls button { padding: 0 12px; }
  #motion .lbl { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
  #motion { padding: 0 10px; }
  .caption { bottom: calc(var(--bar-h) + 3svh); }
  .hud { padding-left: 10px; padding-right: 14px; }
}

/* ---------- «Як це знято» ---------- */
.bd {
  width: min(960px, calc(100vw - 24px)); max-height: calc(100svh - 24px);
  padding: 10px; border: 1px solid #3a352e; border-radius: 14px;
  background: #121110; color: #ece7dd;
  color-scheme: dark;
}
.bd::backdrop { background: rgba(5, 4, 3, .72); }
.bd-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
.bd-fig { margin: 0; background: #000; border-radius: 8px; overflow: hidden; }
.bd-img { display: block; width: 100%; height: auto; max-height: calc(100svh - 26px); object-fit: contain; }
.bd-side { padding: 26px 26px 22px; display: flex; flex-direction: column; gap: 12px; }
.bd h2 { margin: 0; font: 600 1.6rem/1.1 'Cormorant Garamond', Georgia, serif; }
.bd-count { margin: 0; font: .875rem/1 var(--mono); color: #b4ab9c; }
.bd-cap { margin: 0; min-height: 4.4em; line-height: 1.5; }
.bd-scrub { display: grid; gap: 6px; font-size: .875rem; color: #b4ab9c; }
.bd-range { width: 100%; accent-color: var(--glow); }
.bd-nodes { margin: 4px 0 0; padding-left: 1.3em; font: .875rem/1.7 var(--mono); color: #cfc7b8; }
.bd-actions { margin-top: auto; display: flex; flex-wrap: wrap; gap: 8px; }
.bd-actions button { min-height: 40px; padding: 0 16px; border-radius: 999px; border: 1px solid #5b544a; background: transparent; color: #ece7dd; cursor: pointer; }
.bd-actions button:hover, .bd-actions button[aria-pressed="true"] { border-color: #ece7dd; }
.bd :focus-visible { outline-color: var(--glow); }
@media (max-width: 720px) {
  .bd-grid { grid-template-columns: 1fr; }
  .bd-img { max-height: 46svh; }
  .bd-side { padding: 18px; }
}

body.failed .face-wrap { opacity: 1; }
