/* Palette lifted from the renderer (src/slides/*.rs) so the page and the video match. */
:root {
  --ink: #0b0b0b;
  --cream: #f3f1ec;
  --muted: #a9a79f;
  --edge: #2c2c2b;
  --lime: #d4ff3a;
  --pink: #ff4fb0;
  --lavender: #c9b8ff;
  --green: #39d353;
  --orange: #ff6a1f;
  --blue: #2f3bff;
  --g1: #0f1f11; --g2: #17421e; --g3: #226f2f; --g4: #2da040;

  --display: "Archivo", "Arial Black", system-ui, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;

  /* Type scale: 12 / 14 / 16 / 20 / 26 / 34, display set fluidly. */
  --t-label: 0.75rem;
  --t-small: 0.875rem;
  --t-body: 1rem;
  --t-lead: 1.25rem;
  --t-h3: 1.625rem;
  --t-h2: 2.125rem;

  --gutter: 16px;
  /* Side padding that also clears notches / rounded corners in landscape. */
  --pad-l: max(var(--gutter), env(safe-area-inset-left));
  --pad-r: max(var(--gutter), env(safe-area-inset-right));
  --r-lg: 28px;
  --r-md: 16px;
  --r-sm: 10px;
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--ink);
  color: var(--cream);
  font-family: var(--display);
  font-variation-settings: "wdth" 100;
  font-size: var(--t-body);
  line-height: 1.5;
  overflow-x: hidden;
  overflow-x: clip;
  min-height: 100vh;
  min-height: 100svh;
  display: flex;
  flex-direction: column;
}

a { color: inherit; text-underline-offset: 0.2em; }
a:hover { color: var(--lime); }

:focus-visible {
  outline: 3px solid var(--lime);
  outline-offset: 3px;
}

.skip {
  position: absolute; left: var(--gutter); top: -100px;
  background: var(--lime); color: var(--ink);
  padding: 8px 12px; border-radius: var(--r-sm);
  font-family: var(--mono); font-size: var(--t-small); font-weight: 700;
  z-index: 10;
}
.skip:focus { top: 8px; }

[hidden] { display: none !important; }

/* ---------- Header: story bars as the step indicator ---------- */
.top {
  padding: max(14px, env(safe-area-inset-top)) var(--pad-r) 0 var(--pad-l);
  max-width: 1200px; width: 100%; margin: 0 auto;
}
.steps {
  list-style: none; margin: 0; padding: 0;
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px;
}
.steps li { display: flex; flex-direction: column; gap: 8px; }
.steps .bar {
  height: 4px; border-radius: 2px; background: var(--edge);
  transition: background-color .3s;
}
.steps .step-name {
  font-family: var(--mono); font-size: var(--t-label); color: var(--muted);
}
.steps li.is-past .bar, .steps li.is-now .bar { background: var(--cream); }
.steps li.is-now .step-name { color: var(--cream); font-weight: 700; }

.brand {
  order: -1;
  display: flex; align-items: center; gap: 10px;
  margin: 0 0 14px;
  font-family: var(--mono); font-size: var(--t-small); font-weight: 700;
}
.top { display: flex; flex-direction: column; }
.brand-mark { width: 12px; height: 12px; background: var(--cream); border-radius: 2px; }

/* ---------- Layout ---------- */
.layout {
  flex: 1;
  width: 100%; max-width: 1200px; margin: 0 auto;
  padding: 24px var(--pad-r) 40px var(--pad-l);
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 20px;
  align-content: start;
}

.intro h1 {
  margin: 0;
  font-weight: 900;
  font-variation-settings: "wdth" 125;
  font-size: clamp(2.25rem, 10.6vw, 5.75rem);
  line-height: 0.92;
  letter-spacing: -0.02em;
  max-width: 11ch;
  text-wrap: balance;
}
.lede {
  margin: 12px 0 0;
  font-size: clamp(var(--t-body), 4.4vw, var(--t-lead));
  line-height: 1.4;
  max-width: 34ch;
  color: var(--cream);
  font-weight: 500;
}

/* ---------- Panels ---------- */
.panel {
  border: 1px solid var(--edge);
  border-radius: var(--r-lg);
  padding: 20px;
  background: var(--ink);
}

.field { margin: 0 0 20px; border: 0; padding: 0; min-width: 0; }
.field > label, .field > legend {
  display: block; padding: 0; margin: 0 0 8px;
  font-family: var(--mono); font-size: var(--t-small); color: var(--cream);
}

.input-wrap {
  display: flex; align-items: center;
  border: 2px solid var(--edge); border-radius: var(--r-md);
  background: #161615;
  transition: border-color .15s;
}
.input-wrap:focus-within { border-color: var(--lime); }
.at {
  padding-left: 16px;
  font-weight: 800; font-size: var(--t-h3); line-height: 1; color: var(--muted);
  font-variation-settings: "wdth" 125;
  pointer-events: none;
}
.input-wrap input {
  flex: 1; min-width: 0;
  border: 0; background: transparent; color: var(--cream);
  font: inherit; font-weight: 800; font-size: var(--t-h3); line-height: 1.2;
  font-variation-settings: "wdth" 125;
  min-height: 56px;
  padding: 12px 16px 12px 4px;
  border-radius: 0; -webkit-appearance: none; appearance: none;
}
.input-wrap input::placeholder { color: #7a7973; }
.input-wrap input:focus { outline: none; }

.music-grid {
  display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px;
}
.chip {
  position: relative;
  display: flex; flex-direction: column; justify-content: space-between;
  min-height: 64px;
  padding: 10px 14px;
  border-radius: var(--r-md);
  border: 2px solid var(--edge);
  cursor: pointer;
  transition: background-color .15s, color .15s, border-color .15s;
}
.chip input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.chip-name { font-weight: 800; font-size: var(--t-lead); font-variation-settings: "wdth" 115; line-height: 1.1; }
.chip-meta { font-family: var(--mono); font-size: 0.8125rem; color: var(--muted); }
.chip:hover { border-color: #57564f; }
.chip:has(input:focus-visible) { outline: 3px solid var(--cream); outline-offset: 3px; }
.chip:has(input:checked) { color: var(--ink); }
.chip:has(input:checked) .chip-meta { color: rgba(11, 11, 11, .72); }
.chip-lime:has(input:checked) { background: var(--lime); border-color: var(--lime); }
.chip-pink:has(input:checked) { background: var(--pink); border-color: var(--pink); }
.chip-lav:has(input:checked)  { background: var(--lavender); border-color: var(--lavender); }
.chip-off:has(input:checked)  { background: var(--cream); border-color: var(--cream); }

.verify { margin: 0 0 20px; }

/* Turnstile renders a 65 px tall iframe here (flexible: 100% wide, min 300 px);
   reserve the space so nothing jumps. */
.turnstile-slot { min-height: 65px; max-width: 100%; }
.turnstile-slot iframe { display: block; max-width: none; }

.form-msg { margin: 0 0 12px; font-family: var(--mono); font-size: var(--t-small); color: var(--muted); min-height: 1.5em; }
.form-msg.is-error { color: var(--pink); }
.form-msg:empty { display: none; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 56px; padding: 0 28px;
  border-radius: 999px; border: 2px solid transparent;
  font-family: var(--display); font-weight: 900; font-size: var(--t-lead);
  font-variation-settings: "wdth" 125;
  text-decoration: none; cursor: pointer;
  transition: transform .1s, background-color .15s;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--lime); color: var(--ink); }
.btn-primary:hover { background: #e3ff7a; color: var(--ink); }
.btn-secondary { background: transparent; color: var(--cream); border-color: var(--cream); }
.btn-secondary:hover { background: var(--cream); color: var(--ink); }
.btn[disabled] { background: var(--edge); color: #77766f; cursor: not-allowed; }
.form .btn { width: 100%; }

/* ---------- Job summary ---------- */
.job-who { margin: 0; }
.job-login {
  font-weight: 900; font-variation-settings: "wdth" 125;
  font-size: var(--t-h2); line-height: 1;
  overflow-wrap: anywhere;
}
.job-meta { margin: 6px 0 0; font-family: var(--mono); font-size: var(--t-small); color: var(--muted); }
.job-poster {
  margin-top: 20px;
  display: grid; grid-template-columns: 112px minmax(0, 1fr); gap: 16px; align-items: end;
}
.job-poster img {
  width: 112px; height: auto; aspect-ratio: 9 / 16; display: block; object-fit: cover;
  border-radius: var(--r-sm); border: 1px solid var(--edge); background: #161615;
}
.job-actions { display: flex; flex-direction: column; gap: 10px; }
.job-actions .btn {
  width: 100%; padding: 0 16px; min-height: 52px;
  font-size: var(--t-body); font-variation-settings: "wdth" 112; white-space: nowrap;
}
.poster-wait {
  width: 112px; aspect-ratio: 9 / 16;
  border: 2px dashed #3a3a38; border-radius: var(--r-sm);
}
.poster-wait-text { margin: 0; font-size: var(--t-small); color: var(--muted); max-width: 26ch; align-self: center; }

/* ---------- Stage (the coloured slide) ---------- */
.stage {
  position: relative;
  border-radius: var(--r-lg);
  overflow: hidden;
  min-height: 440px;
  container-type: inline-size;
}
.slide {
  display: none;
  position: absolute; inset: 0;
  padding: 24px;
  flex-direction: column;
  color: var(--ink);
}
body[data-state="idle"] .slide-idle,
body[data-state="queued"] .slide-queued,
body[data-state="rendering"] .slide-rendering,
body[data-state="done"] .slide-done,
body[data-state="error"] .slide-error { display: flex; }

.slide-label {
  margin: 0;
  display: flex; align-items: center; gap: 8px;
  font-family: var(--mono); font-size: var(--t-label); font-weight: 700;
}
.slide-label::before { content: ""; width: 10px; height: 10px; background: currentColor; border-radius: 2px; }
.slide-big {
  margin: auto 0 0;
  font-weight: 900; font-variation-settings: "wdth" 125;
  font-size: 52cqi;
  line-height: 0.85; letter-spacing: -0.03em;
  white-space: nowrap;
}
.slide-big small { font-size: 0.36em; letter-spacing: 0; margin-left: 2px; }
.slide-title {
  margin: 12px 0 0;
  font-weight: 800; font-variation-settings: "wdth" 115;
  font-size: var(--t-h3); line-height: 1.1;
}
.slide-foot {
  margin: 20px 0 0; max-width: 32ch;
  font-weight: 600; font-size: var(--t-body); line-height: 1.35;
}

/* idle: echoes the intro slide */
.slide-idle { background: var(--lime); }
.slide-year {
  margin: 18px 0 0;
  font-weight: 900; font-variation-settings: "wdth" 125;
  font-size: 44cqi;
  line-height: 0.82; letter-spacing: -0.04em;
}
.grid {
  margin-top: auto;
  display: grid; grid-template-columns: repeat(7, 22px); gap: 5px;
}
.grid i { width: 22px; height: 22px; border-radius: 4px; background: var(--g4); }
.grid i:nth-child(3n) { background: var(--g2); }
.grid i:nth-child(4n+1) { background: var(--g3); }
.grid i:nth-child(5n+2) { background: var(--ink); }
.grid i:nth-child(7n) { background: #b8e63a; }
.tile {
  position: absolute; right: -18px; bottom: 104px;
  width: 128px; height: 128px; border-radius: 18px;
  background: var(--green); border: 3px solid var(--ink);
  transform: rotate(4deg);
  box-shadow: 6px 6px 0 var(--ink);
}
.slide-idle .slide-foot { font-weight: 800; font-variation-settings: "wdth" 110; font-size: var(--t-lead); }

/* queued: lavender, the queue drawn as blocks */
.slide-queued { background: var(--lavender); }
.queue-row { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 16px; }
.queue-row span { width: 34px; height: 34px; border-radius: 7px; background: var(--ink); }
.queue-row span.is-you { background: var(--pink); border: 3px solid var(--ink); }

/* rendering: the streak slide's blue with lime blocks */
.slide-rendering { background: var(--blue); color: var(--lime); }
.slide-rendering .slide-label { color: var(--cream); }
.slide-rendering .slide-big { font-size: 40cqi; }
.slide-rendering .slide-foot { color: var(--cream); }
.meter {
  margin-top: 18px;
  display: grid; grid-template-columns: repeat(12, 1fr); gap: 5px;
}
.meter span { height: 26px; border-radius: 5px; background: rgba(212, 255, 58, .22); }
.meter span.is-on { background: var(--lime); }

/* done: the video itself */
body .slide-done { background: #000; padding: 0; }
.slide-done video { width: 100%; height: 100%; object-fit: contain; display: block; background: #000; }

/* error: orange, the API message verbatim */
.slide-error { background: var(--orange); }
.slide-error-msg {
  margin: auto 0 0;
  font-weight: 900; font-variation-settings: "wdth" 125;
  font-size: 14cqi;
  line-height: 0.95; letter-spacing: -0.02em;
  overflow-wrap: break-word;
}

/* ---------- Which panels show per state ---------- */
.job { display: none; }
body[data-state="queued"] .form,
body[data-state="rendering"] .form,
body[data-state="done"] .form { display: none; }
body[data-state="queued"] .job,
body[data-state="rendering"] .job,
body[data-state="done"] .job { display: block; }

/* Mobile: once a job exists, the stage comes before the controls. */
body:not([data-state="idle"]) .stage { order: 2; }
body:not([data-state="idle"]) .job,
body:not([data-state="idle"]) .form { order: 3; }
body[data-state="done"] .stage { aspect-ratio: 9 / 16; min-height: 0; }
body[data-state="done"] .job { order: 1; }
body:not([data-state="idle"]) .intro .lede { display: none; }
body:not([data-state="idle"]) .intro h1 { font-size: clamp(2rem, 9vw, 3.5rem); }

/* ---------- Footer ---------- */
.foot {
  width: 100%; max-width: 1200px; margin: 0 auto;
  padding: 24px var(--pad-r) max(32px, calc(16px + env(safe-area-inset-bottom))) var(--pad-l);
  border-top: 1px solid var(--edge);
  display: grid; gap: 16px;
  font-family: var(--mono); font-size: var(--t-label); line-height: 1.6; color: var(--muted);
}
.foot p { margin: 0; }
.foot p, .foot li { overflow-wrap: anywhere; }
.foot-note { color: var(--cream); }
.foot-head { color: var(--cream); margin-bottom: 4px !important; }
.foot li a:last-child { white-space: nowrap; }
.foot ul { margin: 0; padding: 0; list-style: none; display: grid; gap: 4px; }
.foot-repo { display: grid; gap: 4px; align-content: start; }
.foot-built { color: var(--cream); }
.foot-built a { color: var(--lime); }

/* ---------- Phones and tablets (single column) ---------- */
@media (max-width: 899px) {
  .top .brand { margin-bottom: 12px; }
  .steps .step-name { font-size: 0.6875rem; }

  /* Job states: a short heading, no lede. */
  body:not([data-state="idle"]) .intro h1 { font-size: clamp(1.75rem, 8vw, 2.75rem); }

  /* The stage is a compact card sized by its content rather than a fixed 440 px block. */
  .stage { min-height: 0; }
  .slide { position: relative; inset: auto; padding: 20px; }
  .slide-foot { margin-top: 14px; }

  /* idle: a short banner under the form ("2026" on one line). */
  .slide-year { margin-top: 10px; font-size: 27cqi; line-height: 0.85; }
  .slide-year br { display: none; }
  .slide-idle .grid { margin-top: 16px; grid-template-columns: repeat(7, 16px); gap: 4px; }
  .slide-idle .grid i { width: 16px; height: 16px; border-radius: 3px; }
  .tile { right: -16px; bottom: 22px; width: 84px; height: 84px; border-radius: 14px; box-shadow: 4px 4px 0 var(--ink); }
  .slide-idle .slide-foot { font-size: var(--t-body); }

  /* queued / rendering: a status card, not a poster. */
  .slide-big { margin-top: 14px; font-size: 30cqi; }
  .slide-rendering .slide-big { font-size: 28cqi; }
  .queue-row { margin-top: 12px; }
  .queue-row span { width: 28px; height: 28px; border-radius: 6px; }
  .meter span { height: 20px; }

  /* error: message first, then the form. */
  .slide-error-msg { margin-top: 18px; font-size: clamp(1.75rem, 11cqi, 3rem); }

  /* done: the preview fits the screen, 9:16, at most ~70% of the visible viewport tall. */
  body[data-state="done"] .stage {
    width: min(100%, calc(70vh * 9 / 16));
    width: min(100%, calc(70svh * 9 / 16));
    justify-self: center;
  }
  body[data-state="done"] .slide-done { position: absolute; inset: 0; }

  /* Job panel: name + small poster thumbnail on one row, full-width actions below. */
  body[data-state="queued"] .job,
  body[data-state="rendering"] .job,
  body[data-state="done"] .job {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    column-gap: 16px;
    align-items: start;
  }
  .job-who { grid-column: 1; grid-row: 1; }
  .job-meta { grid-column: 1; grid-row: 2; }
  .job-poster { display: contents; }
  .job-poster img, .poster-wait {
    grid-column: 2; grid-row: 1 / span 3;
    width: 64px;
  }
  .poster-wait-text { grid-column: 1; grid-row: 3; margin-top: 12px; align-self: start; }
  .job-actions { grid-column: 1 / -1; grid-row: 4; margin-top: 16px; }
  .job-login { font-size: clamp(1.5rem, 7vw, var(--t-h2)); }
}

/* Narrow phones: keep the 300 px Turnstile iframe inside the panel at 360 px. */
@media (max-width: 399px) {
  :root { --gutter: 12px; }
  .panel { padding: 16px 12px; border-radius: 22px; }
  .chip { padding: 10px 12px; }
  .chip-name { font-size: 1.125rem; }
}

/* Tablets: a centred column, and the chips fit on one row. */
@media (min-width: 600px) and (max-width: 899px) {
  .top, .layout, .foot { max-width: 640px; }
  .intro h1 { font-size: clamp(3rem, 8.6vw, 4.5rem); }
  .music-grid { grid-template-columns: repeat(4, 1fr); }
  .slide-year { font-size: 22cqi; }
}

/* ---------- Desktop ---------- */
@media (min-width: 900px) {
  :root { --gutter: 40px; }
  .layout {
    grid-template-columns: minmax(0, 1fr) 380px;
    grid-template-rows: auto 1fr;
    column-gap: 64px; row-gap: 32px;
    padding-top: 40px;
  }
  .intro { grid-column: 1; grid-row: 1; }
  .form, .job { grid-column: 1; grid-row: 2; align-self: start; max-width: 560px; }
  .stage {
    grid-column: 2; grid-row: 1 / span 2;
    aspect-ratio: 9 / 16; min-height: 0; align-self: start;
  }
  body:not([data-state="idle"]) .stage,
  body[data-state="done"] .job { order: 0; }
  .grid { grid-template-columns: repeat(7, 30px); gap: 6px; }
  .grid i { width: 30px; height: 30px; border-radius: 5px; }
  .intro h1 { font-size: clamp(3.5rem, 6.4vw, 5.75rem); }
  body:not([data-state="idle"]) .intro h1 { font-size: 3.5rem; }
  .music-grid { grid-template-columns: repeat(4, 1fr); }
  .form-row { display: flex; }
  .verify-row { display: flex; gap: 16px; align-items: center; }
  .form .btn { width: auto; }
  .panel { padding: 24px; }
  .slide { padding: 28px; }
  .job-poster { grid-template-columns: 148px minmax(0, 1fr); }
  .job-poster img, .poster-wait { width: 148px; }
  .job-actions .btn { width: auto; align-self: flex-start; padding: 0 28px; }
  .foot {
    grid-template-columns: 1fr 2fr auto; column-gap: 40px; padding-bottom: 32px;
  }
  .foot-repo { text-align: right; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}
