/* Dark, quiet, Apple-like: near-black canvas, raised graphite panels, one blue accent.
 * The demo loop sits behind the uploads in emphasis; Generate is the only filled control.
 */

:root {
  --color-paper: #000;
  --color-paper-2: #141416;
  --color-paper-3: #1f1f22;
  --color-rule: #2c2c2f;
  --color-neutral: #6e6e73;
  --color-muted: #a1a1a6;
  --color-ink: #f5f5f7;
  --color-accent: #0a84ff;
  --color-accent-soft: rgb(10 132 255 / 0.16);
  --color-on-accent: #fff;
  --color-focus: #409cff;
  --color-danger: #ff6961;
  --color-danger-soft: rgb(255 69 58 / 0.14);
  --color-success: #30d158;
  --color-success-soft: rgb(48 209 88 / 0.14);
  --color-scrim: rgb(0 0 0 / 0.6);
  --color-glass: rgb(22 22 24 / 0.72);

  --font-sans: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI Variable", "Segoe UI",
    Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-display: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI Variable Display",
    "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;

  --text-xs: 0.8125rem;
  --text-sm: 0.9375rem;
  --text-md: 1.0625rem;
  --text-lg: 1.25rem;
  --text-xl: 1.625rem;
  --text-2xl: clamp(1.875rem, 2.4vw + 1rem, 2.75rem);
  --text-display: clamp(2.5rem, 5vw + 0.5rem, 4.5rem);

  --space-2xs: 0.25rem;
  --space-xs: 0.5rem;
  --space-sm: 0.75rem;
  --space-md: 1rem;
  --space-lg: 1.5rem;
  --space-xl: 2rem;
  --space-2xl: 3rem;
  --space-3xl: 4.5rem;
  --space-4xl: 7rem;

  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 22px;
  --radius-pill: 999px;
  --rule: 1px solid var(--color-rule);
  --shadow-float: 0 1px 2px rgb(0 0 0 / 0.4), 0 12px 32px rgb(0 0 0 / 0.5);

  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --ease-in: cubic-bezier(0.55, 0, 1, 0.45);
  --ease-in-out: cubic-bezier(0.65, 0, 0.35, 1);
  --dur-fast: 120ms;
  --dur-med: 220ms;

  --measure: 64ch;
  --page: 1120px;
  --studio: 1360px;
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
/* Layout classes set `display`; the attribute must still win. */
[hidden] { display: none !important; }
html, body { overflow-x: clip; }
html { -webkit-text-size-adjust: 100%; scroll-padding-top: 6rem; }
body {
  margin: 0;
  background: var(--color-paper);
  color: var(--color-ink);
  font: 400 var(--text-md)/1.55 var(--font-sans);
  -webkit-font-smoothing: antialiased;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}
main { flex: 1; }
img, video { max-width: 100%; display: block; }
h1, h2, h3 {
  font-family: var(--font-display);
  font-style: normal;
  font-weight: 650;
  letter-spacing: -0.025em;
  line-height: 1.08;
  margin: 0;
  overflow-wrap: anywhere;
  min-width: 0;
}
p { margin: 0; }
a { color: inherit; text-underline-offset: 0.2em; text-decoration-thickness: 1px; }
a:hover { color: var(--color-accent); }
:focus-visible { outline: 2px solid var(--color-focus); outline-offset: 3px; border-radius: 4px; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--color-muted); }
.small { font-size: var(--text-sm); }
.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
}

/* Nav · N5 floating pill */
.nav {
  position: sticky;
  top: var(--space-sm);
  z-index: 20;
  margin: var(--space-sm) auto 0;
  width: min(100% - 2 * var(--space-sm), var(--studio));
  display: flex;
  align-items: center;
  gap: var(--space-md);
  padding: var(--space-xs) var(--space-xs) var(--space-xs) var(--space-lg);
  background: var(--color-glass);
  backdrop-filter: saturate(1.6) blur(16px);
  -webkit-backdrop-filter: saturate(1.6) blur(16px);
  border: var(--rule);
  border-radius: var(--radius-pill);
  box-shadow: var(--shadow-float);
}
.wordmark {
  font: 700 var(--text-lg)/1 var(--font-display);
  letter-spacing: -0.04em;
  text-decoration: none;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: var(--space-xs);
}
.wordmark svg { width: 22px; height: 22px; }
.wordmark .mark { fill: var(--color-accent); }
.wordmark .glyph { fill: var(--color-on-accent); }
.nav-links { display: flex; gap: var(--space-lg); margin-inline-start: auto; align-items: center; }
.nav-links a { text-decoration: none; font-size: var(--text-sm); white-space: nowrap; color: var(--color-muted); }
.nav-links a:hover, .nav-links a[aria-current="page"] { color: var(--color-ink); }
.nav-links a.btn, .nav-links a.btn:hover { color: var(--btn-fg); }
@media (max-width: 640px) {
  .nav { padding-inline-start: var(--space-md); gap: var(--space-sm); }
  .nav-links { gap: var(--space-md); }
  .nav-links .hide-sm { display: none; }
}

/* Buttons: filled ink primary, outlined secondary, pill radius */
.btn {
  --btn-bg: var(--color-ink);
  --btn-fg: var(--color-paper);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-xs);
  min-height: 44px;
  padding: 0 1.25rem;
  border: 1px solid var(--btn-bg);
  border-radius: var(--radius-pill);
  background: var(--btn-bg);
  color: var(--btn-fg);
  font: 600 var(--text-sm)/1 var(--font-sans);
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
  transition: opacity var(--dur-fast) var(--ease-out), transform var(--dur-fast) var(--ease-out);
}
.btn:hover { color: var(--btn-fg); opacity: 0.86; }
.btn:active { transform: translateY(1px); }
.btn[disabled], .btn[aria-disabled="true"] { opacity: 0.4; cursor: not-allowed; transform: none; }
.btn[data-state="loading"] { cursor: progress; opacity: 0.7; }
.btn[data-state="loading"]::before {
  content: ""; width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid currentColor; border-right-color: transparent;
  animation: spin 700ms linear infinite;
}
.btn-accent { --btn-bg: var(--color-accent); --btn-fg: var(--color-on-accent); }
.btn-ghost { --btn-bg: transparent; --btn-fg: var(--color-ink); border-color: var(--color-rule); }
.btn-ghost:hover { --btn-fg: var(--color-ink); background: var(--color-paper-2); opacity: 1; }
.btn-sm { min-height: 36px; padding: 0 0.9rem; }
.btn-wide { width: 100%; }
@keyframes spin { to { transform: rotate(360deg); } }


/* A text-weight button, for actions that sit among nav links */
.link {
  border: 0; padding: 0; background: none; cursor: pointer;
  font: inherit; font-size: var(--text-sm); color: var(--color-muted); white-space: nowrap;
}
.link:hover { color: var(--color-ink); }

/* Gremlin's live state, in the nav */
.status {
  display: inline-flex; align-items: center; gap: var(--space-xs);
  font-size: var(--text-xs); color: var(--color-muted); white-space: nowrap;
}
.status .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--color-neutral); flex: none; }
.status[data-tone="ready"] .dot { background: var(--color-success); }
.status[data-tone="local"] .dot { background: var(--color-accent); }
.status[data-tone="blocked"] .dot { background: var(--color-danger); }
@media (max-width: 640px) { .status [data-status-text] { display: none; } }
/* The smallest phones keep the mark, the status dot and both links on one line. */
@media (max-width: 380px) { .wordmark-text { display: none; } .nav-links { gap: var(--space-sm); } }

/* App surfaces */
.wrap { width: min(100% - 2 * var(--space-lg), var(--page)); margin-inline: auto; }
.page-head { padding-block: var(--space-2xl) var(--space-xl); display: grid; gap: var(--space-xs); }
.page-head h1 { font-size: var(--text-2xl); }
.card { border: var(--rule); border-radius: var(--radius-lg); padding: var(--space-xl); background: var(--color-paper); }
.card h2 { font-size: var(--text-lg); }
.field { display: grid; gap: var(--space-xs); }
.field label, .label { font-weight: 600; font-size: var(--text-sm); }
.input, textarea.input {
  width: 100%;
  min-height: 44px;
  padding: 0.65rem 0.9rem;
  border: 1px solid var(--color-rule);
  border-radius: var(--radius-sm);
  background: var(--color-paper);
  color: var(--color-ink);
  font: inherit;
  font-size: var(--text-sm);
}
textarea.input { min-height: 8rem; resize: vertical; line-height: 1.5; }
.input:hover { border-color: var(--color-neutral); }
.input:focus-visible { outline: 2px solid var(--color-focus); outline-offset: 0; border-color: transparent; }
.input[aria-invalid="true"] { border-color: var(--color-danger); }
.hint { font-size: var(--text-xs); color: var(--color-muted); }
.center-text { text-align: center; }
.stack { display: grid; gap: var(--space-lg); }
.stack-sm { display: grid; gap: var(--space-sm); }
.row { display: flex; flex-wrap: wrap; gap: var(--space-sm); align-items: center; }
.spread { justify-content: space-between; }
.center { justify-content: center; }
.notice {
  border-radius: var(--radius-sm);
  padding: var(--space-sm) var(--space-md);
  font-size: var(--text-sm);
  background: var(--color-paper-2);
}
.notice[data-tone="error"] { background: var(--color-danger-soft); color: var(--color-danger); }

/* Studio: the two uploads side by side, one Generate below */
.studio { width: min(100% - 2 * var(--space-lg), 1080px); margin: var(--space-xl) auto var(--space-2xl); display: grid; gap: var(--space-md); }
.studio-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: var(--space-md);
  align-items: stretch;
}
@media (max-width: 720px) { .studio-grid { grid-template-columns: minmax(0, 1fr); } }
.panel {
  border: var(--rule); border-radius: var(--radius-lg); background: var(--color-paper);
  padding: var(--space-lg); display: grid; gap: var(--space-sm); min-width: 0; align-content: start;
}
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-sm); min-height: 36px; }
.panel-head h2 { font-size: var(--text-lg); }
/* Two lines for either card's help, so both upload areas start level. */
.panel > .hint { min-height: 3.1em; }
.preview { max-height: 46vh; width: auto; max-width: 100%; border-radius: var(--radius-md); }
.drop {
  display: grid; place-content: center; text-align: center; gap: var(--space-xs);
  min-height: 18rem; padding: var(--space-xl);
  border: 1.5px dashed var(--color-rule); border-radius: var(--radius-md);
  background: var(--color-paper-2); cursor: pointer; color: var(--color-muted);
  transition: border-color var(--dur-fast) var(--ease-out);
}
.drop:hover, .drop.is-over { border-color: var(--color-accent); color: var(--color-ink); }
.drop:focus-within { outline: 2px solid var(--color-focus); outline-offset: 2px; }
.drop strong { color: var(--color-ink); }
@media (max-width: 720px) { .drop { min-height: 10rem; } }
.pick-wrap { display: grid; place-items: center; background: var(--color-paper-2); border-radius: var(--radius-md); }
.picker {
  position: relative; width: fit-content; max-width: 100%;
  border-radius: var(--radius-md); overflow: hidden; cursor: crosshair;
  touch-action: manipulation;
}
.picker img { max-height: 56vh; width: auto; max-width: 100%; }
.picker .tap { pointer-events: none; }
/* A detected subject over the tap image: a real button, so it can be chosen by keyboard too. */
.candidate {
  position: absolute; padding: 0; margin: 0; cursor: pointer;
  border: 2px dashed oklch(99% 0 0 / 0.9); border-radius: var(--radius-sm);
  background: transparent; box-shadow: 0 0 0 1px oklch(19% 0.01 60 / 0.5);
}
.candidate:hover { background: oklch(99% 0 0 / 0.12); }
.candidate[aria-pressed="true"] { border-style: solid; border-color: var(--color-accent); box-shadow: 0 0 0 1px var(--color-accent-soft); }
.choose-side { display: grid; gap: var(--space-xs); }
.choose-side h3 { font-size: var(--text-md); }
.tap {
  position: absolute; width: 22px; height: 22px; border-radius: 50%;
  border: 2px solid var(--color-paper); background: var(--color-accent);
  box-shadow: 0 0 0 4px var(--color-accent-soft); translate: -50% -50%;
}
.generate { display: grid; gap: var(--space-sm); padding-top: var(--space-md); border-top: var(--rule); }
.generate .btn { min-height: 52px; font-size: var(--text-md); }
.generate-bar { width: min(100%, 34rem); margin-inline: auto; border-top: 0; padding-top: var(--space-sm); }
.progress { height: 4px; border-radius: 4px; background: var(--color-paper-3); overflow: hidden; }
.progress > div { height: 100%; background: var(--color-accent); width: 0; transition: width var(--dur-med) var(--ease-out); }

/* Video */
.narrow { width: min(100% - 2 * var(--space-lg), 760px); margin-inline: auto; padding-bottom: var(--space-2xl); }
.player { border-radius: var(--radius-lg); overflow: hidden; background: var(--color-paper-3); margin-inline: auto; width: fit-content; max-width: 100%; }
.player video { max-height: 70vh; width: auto; }

/* History */
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 200px), 1fr)); gap: var(--space-md); }
.thumb { text-decoration: none; display: grid; gap: var(--space-xs); min-width: 0; }
.thumb .frame {
  aspect-ratio: 1; border-radius: var(--radius-md); background: var(--color-paper-2); border: var(--rule);
  overflow: hidden; display: grid; place-items: center; color: var(--color-muted); font-size: var(--text-sm);
  padding: var(--space-sm); text-align: center;
}
.thumb .frame:has(img) { padding: 0; }
.thumb .frame img { width: 100%; height: 100%; object-fit: cover; }
.thumb:hover .frame { border-color: var(--color-neutral); }
.thumb:focus-visible { outline: none; }
.thumb:focus-visible .frame { outline: 2px solid var(--color-focus); outline-offset: 2px; }
.badge {
  display: inline-block; padding: 0.15rem 0.55rem; border-radius: var(--radius-pill);
  font-size: var(--text-xs); font-weight: 600; background: var(--color-paper-2); color: var(--color-muted);
}
.badge[data-tone="success"] { background: var(--color-success-soft); color: var(--color-success); }
.badge[data-tone="error"] { background: var(--color-danger-soft); color: var(--color-danger); }
.badge[data-tone="active"] { background: var(--color-accent-soft); color: var(--color-accent); }
.empty { text-align: center; padding: var(--space-3xl) var(--space-md); color: var(--color-muted); display: grid; gap: var(--space-md); justify-items: center; }
.more { margin-top: var(--space-xl); }

/* Studio intro, consent, footer and the terms page */
.intro { display: grid; gap: var(--space-xs); max-width: 60rem; padding-block: var(--space-sm) var(--space-xs); }
.intro h1 { font-size: var(--text-2xl); }
.check { display: flex; gap: var(--space-sm); align-items: flex-start; font-size: var(--text-xs); color: var(--color-muted); }
.check input { margin-top: 0.1rem; width: 18px; height: 18px; accent-color: var(--color-accent); flex: none; }
.footer {
  width: min(100% - 2 * var(--space-lg), var(--studio)); margin: var(--space-xl) auto 0;
  padding-block: var(--space-lg); border-top: var(--rule);
  display: flex; flex-wrap: wrap; gap: var(--space-xs) var(--space-lg); justify-content: space-between;
  font-size: var(--text-xs); color: var(--color-muted);
}
.footer a { white-space: nowrap; }
.prose h2 { font-size: var(--text-lg); margin: var(--space-xl) 0 var(--space-sm); }
.prose p, .prose li { color: var(--color-ink); max-width: var(--measure); }
.prose ul { padding-left: 1.2rem; margin: 0 0 var(--space-md); display: grid; gap: var(--space-xs); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 1ms !important; animation-iteration-count: 1 !important; transition-duration: 1ms !important; }
}

/* Dashboard: headline, a quiet demo loop, two large uploads, consent and Generate */
.studio { width: min(100% - 2 * var(--space-lg), 980px); margin-top: var(--space-2xl); gap: var(--space-lg); }
.hero { display: grid; gap: var(--space-xs); text-align: center; justify-items: center; }
.hero h1 { font-size: clamp(2rem, 3.4vw + 1rem, 3.25rem); letter-spacing: -0.035em; font-weight: 700; max-width: 18ch; }
.hero p { font-size: var(--text-lg); }
.demo {
  margin: 0 auto; width: min(100%, 420px); border-radius: var(--radius-lg); overflow: hidden;
  border: var(--rule); opacity: 0.78; aspect-ratio: 2 / 1; background: var(--color-paper-2);
}
.demo video { width: 100%; height: 100%; object-fit: cover; pointer-events: none; }
.panel { background: var(--color-paper-2); border-color: transparent; padding: var(--space-md); }
.panel-head { padding-inline: var(--space-xs); }
.panel-head h2 { font-size: var(--text-md); font-weight: 600; letter-spacing: -0.01em; }
.drop {
  min-height: 20rem; border: 1.5px dashed var(--color-rule); background: var(--color-paper-3);
  transition: border-color var(--dur-fast) var(--ease-out), background var(--dur-fast) var(--ease-out);
}
.drop strong { font-size: var(--text-lg); font-weight: 600; }
.drop .small { max-width: 30ch; margin-inline: auto; }
.drop:hover, .drop.is-over { border-color: var(--color-accent); background: rgb(10 132 255 / 0.06); }
.drop-icon {
  width: 44px; height: 44px; margin: 0 auto var(--space-xs); fill: none; stroke: var(--color-accent);
  stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round;
}
.pick-wrap { background: var(--color-paper-3); min-height: 20rem; }
@media (max-width: 720px) { .drop, .pick-wrap { min-height: 12rem; } }
.generate-bar { display: grid; gap: var(--space-md); width: min(100%, 30rem); margin-inline: auto; padding: 0; }
.btn-lg { min-height: 54px; font-size: var(--text-md); font-weight: 600; }
.btn-accent[disabled] { --btn-bg: var(--color-paper-3); --btn-fg: var(--color-neutral); border-color: var(--color-paper-3); opacity: 1; }
.check { font-size: var(--text-xs); line-height: 1.45; }
.usage-row { display: flex; flex-wrap: wrap; gap: var(--space-xs) var(--space-sm); justify-content: center; align-items: center; text-align: center; }

/* The usage counter and its note: hover or focus on a pointer, tap on touch */
.usage { position: relative; display: inline-flex; }
.usage-chip {
  border: var(--rule); border-radius: var(--radius-pill); background: var(--color-paper-2); color: var(--color-muted);
  font: 500 var(--text-xs)/1 var(--font-sans); padding: 0.45rem 0.75rem; cursor: help; white-space: nowrap;
}
.usage-chip:hover, .usage-chip[aria-expanded="true"] { color: var(--color-ink); border-color: var(--color-neutral); }
.tooltip {
  position: absolute; bottom: calc(100% + 10px); left: 50%; translate: -50% 4px; z-index: 30;
  width: max-content; max-width: min(18rem, 80vw); padding: var(--space-sm) var(--space-md);
  border-radius: var(--radius-md); background: var(--color-paper-3); border: var(--rule); box-shadow: var(--shadow-float);
  font-size: var(--text-xs); line-height: 1.45; color: var(--color-muted); text-align: left;
  opacity: 0; visibility: hidden; pointer-events: none;
  transition: opacity var(--dur-fast) var(--ease-out), translate var(--dur-fast) var(--ease-out), visibility var(--dur-fast);
}
.tooltip strong { display: block; color: var(--color-ink); font-weight: 600; margin-bottom: 2px; }
.usage:hover .tooltip, .usage-chip:focus-visible + .tooltip, .usage-chip[aria-expanded="true"] + .tooltip {
  opacity: 1; visibility: visible; translate: -50% 0;
}

/* Progress: every real stage with what it does; the current one explains itself */
.stages { list-style: none; margin: 0; padding: 0; display: grid; gap: 0; }
.stage { display: grid; grid-template-columns: 22px 1fr auto; gap: 0 var(--space-sm); padding: var(--space-sm) 0; color: var(--color-neutral); }
.stage + .stage { border-top: var(--rule); }
.stage::before {
  content: ""; width: 12px; height: 12px; margin-top: 0.35em; border-radius: 50%;
  border: 2px solid currentColor; grid-row: span 2;
}
.stage-name { font-weight: 500; }
.stage-time { font: 500 var(--text-xs)/1.9 var(--font-mono); color: var(--color-neutral); }
.stage-note { grid-column: 2 / -1; font-size: var(--text-sm); color: var(--color-muted); display: none; }
.stage[data-state="done"] { color: var(--color-muted); }
.stage[data-state="done"]::before { background: var(--color-success); border-color: var(--color-success); }
.stage[data-state="current"] { color: var(--color-ink); }
.stage[data-state="current"] .stage-name { font-weight: 600; }
.stage[data-state="current"] .stage-note { display: block; margin-top: var(--space-2xs); }
.stage[data-state="current"]::before { border-color: var(--color-accent); background: var(--color-accent); animation: pulse 1.6s var(--ease-in-out) infinite; }
.progress-head { display: flex; justify-content: space-between; align-items: baseline; gap: var(--space-md); flex-wrap: wrap; }
.progress-head h2 { font-size: var(--text-lg); }
.elapsed { font-size: var(--text-2xl); color: var(--color-ink); }
.explain { border-radius: var(--radius-md); background: var(--color-paper-3); padding: var(--space-md); font-size: var(--text-sm); color: var(--color-muted); display: grid; gap: var(--space-2xs); }
.explain strong { color: var(--color-ink); font-weight: 600; }
.card { background: var(--color-paper-2); border-color: transparent; }
