:root {
  --paper: #EEF1F6;
  --surface: #FFFFFF;
  --ink: #1A2233;
  --muted: #5B6780;
  --line: #D6DCE7;
  --chip: #E2E7EF;
  --cobalt: #2E45E6;
  --cobalt-ink: #2236C4;
  --stage: #1B2130;
  --stage-2: #252C3D;
  --stage-line: #343C50;
  --stage-text: #E8ECF4;
  --stage-muted: #9AA4B8;
  --ok: #1F7F54;
  --warn: #9A5B08;
  --err: #BF3129;

  --r-lg: 20px;
  --r-md: 12px;

  --font-display: 'Bricolage Grotesque', ui-sans-serif, system-ui, sans-serif;
  --font-body: 'Instrument Sans', ui-sans-serif, system-ui, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 15px/1.55 var(--font-body);
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--cobalt); outline-offset: 2px; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

/* ---------- Top bar ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  max-width: 1480px; margin: 0 auto;
  padding: 16px clamp(16px, 3vw, 32px) 0;
}
.brand {
  display: inline-flex; align-items: center; gap: 10px;
  color: var(--ink); text-decoration: none;
  font: 700 19px/1 var(--font-display); letter-spacing: -0.01em;
}
.brand-mark { width: 30px; height: 30px; color: var(--cobalt); }
.topbar-note { margin: 0; color: var(--muted); font-size: 13.5px; }

/* ---------- Layout ---------- */
.layout {
  display: grid;
  grid-template-columns: minmax(0, 540px) minmax(0, 1fr);
  grid-template-areas: "intro stage" "steps stage";
  grid-template-rows: auto 1fr;
  column-gap: clamp(28px, 3.5vw, 56px);
  max-width: 1480px; margin: 0 auto;
  padding: 0 clamp(16px, 3vw, 32px) 48px;
  align-items: start;
}
.intro { grid-area: intro; padding: 40px 0 0; }
.intro h1 {
  margin: 0 0 14px;
  font: 700 clamp(32px, 3.6vw, 46px)/1.02 var(--font-display);
  letter-spacing: -0.03em;
  max-width: 13ch;
}
.intro p { margin: 0; color: var(--muted); font-size: 16px; max-width: 48ch; }
.controls { grid-area: steps; min-width: 0; }
.controls[inert] { opacity: 0.5; }

/* ---------- Steps: a numbered thread ---------- */
.steps { list-style: none; margin: 36px 0 0; padding: 0; }
.step { position: relative; padding: 0 0 40px 50px; }
.step::before {
  content: ""; position: absolute; left: 15px; top: 40px; bottom: 6px;
  width: 2px; background: var(--line); border-radius: 1px;
}
.step:last-child::before { display: none; }
.step-head { display: flex; align-items: center; gap: 16px; margin: 0 0 16px -50px; }
.step-num {
  flex: none; width: 32px; height: 32px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--surface); border: 2px solid var(--cobalt); color: var(--cobalt);
  font: 700 15px/1 var(--font-display);
}
.step h2 { margin: 0; font: 700 22px/1.15 var(--font-display); letter-spacing: -0.02em; }

/* ---------- Fields ---------- */
.field { border: 0; margin: 0 0 20px; padding: 0; min-width: 0; }
.field > legend, .text > span, .text > legend {
  display: block; padding: 0; margin: 0 0 8px;
  font-weight: 600; font-size: 13.5px;
}
.text { display: block; border: 0; margin: 0; padding: 0; min-width: 0; }
.text em { font-style: normal; font-weight: 400; color: var(--muted); }
.field.two { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.narrow { max-width: 260px; margin: 0 0 20px; }
.text input[type=text], .text select {
  width: 100%; height: 44px; padding: 0 12px;
  border: 1px solid var(--line); border-radius: var(--r-md);
  background: var(--surface);
}
.text select { appearance: auto; }
.text input[type=text]::placeholder { color: #98A2B6; }
.sub { margin-top: 12px; }
.hint { margin: 8px 0 0; font-size: 13px; color: var(--muted); }

/* Segmented control */
.seg {
  display: flex; gap: 2px; padding: 4px;
  background: var(--chip); border-radius: var(--r-md);
}
.seg label { position: relative; flex: 1 1 0; min-width: 0; }
.seg input { position: absolute; inset: 0; margin: 0; opacity: 0; cursor: pointer; }
.seg span {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  min-height: 42px; padding: 6px 8px; border-radius: 9px;
  font-weight: 600; font-size: 14px; line-height: 1.2; text-align: center;
  color: var(--muted); transition: background .15s, color .15s;
}
.seg small { font-weight: 500; font-size: 11.5px; opacity: .8; }
.seg-sm span { min-height: 38px; }
.seg input:checked + span {
  background: var(--surface); color: var(--ink);
  box-shadow: 0 1px 2px rgba(26, 34, 51, .14), 0 0 0 1px rgba(26, 34, 51, .05);
}
.seg input:focus-visible + span { outline: 2px solid var(--cobalt); outline-offset: 1px; }

/* Swatches */
.swatches { display: flex; flex-wrap: wrap; gap: 10px; }
.swatch {
  position: relative; width: 36px; height: 36px; border-radius: 50%;
  background: var(--c); cursor: pointer;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .14);
}
.swatch input[type=radio] { position: absolute; inset: 0; margin: 0; opacity: 0; cursor: pointer; }
.swatch:has(input[type=radio]:checked) { box-shadow: 0 0 0 2px var(--paper), 0 0 0 4px var(--ink); }
.swatch:has(input:focus-visible) { outline: 2px solid var(--cobalt); outline-offset: 5px; }
.swatch-bg {
  width: 48px; height: 48px; border-radius: 13px;
  background:
    radial-gradient(circle at 28% 30%, var(--g) 0, transparent 62%),
    linear-gradient(135deg, var(--a), var(--b));
}
.swatch-custom { background: conic-gradient(#ff5a5a, #ffd23f, #5ee07a, #3fc6e0, #5a6bff, #e05ad6, #ff5a5a); }
.swatch-custom input[type=color] {
  position: absolute; inset: 0; width: 100%; height: 100%;
  opacity: 0; border: 0; padding: 0; cursor: pointer;
}

/* Drop zone and file card */
.drop {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 30px 20px; text-align: center; cursor: pointer;
  background: var(--surface); border: 1.5px dashed #B3BDCE; border-radius: var(--r-lg);
  transition: border-color .15s, background .15s;
}
.drop:hover, .drop.is-over { border-color: var(--cobalt); background: #F5F6FF; }
.drop:focus-within { outline: 2px solid var(--cobalt); outline-offset: 2px; }
.drop-icon { width: 28px; height: 28px; color: var(--cobalt); margin-bottom: 6px; }
.drop-title { font: 700 17px/1.2 var(--font-display); }
.drop-sub { font-size: 13.5px; color: var(--muted); }
.file-card {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 14px; background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--r-md);
}
.file-icon { flex: none; width: 22px; height: 22px; color: var(--cobalt); }
.file-text { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.file-text strong { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.file-text span { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }

/* Buttons */
.btn-primary {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 50px; padding: 0 22px; border: 0; border-radius: var(--r-md);
  background: var(--cobalt); color: #fff; text-decoration: none;
  font-weight: 600; font-size: 15.5px; cursor: pointer;
  transition: background .15s;
}
.btn-primary:hover { background: var(--cobalt-ink); }
.btn-primary:disabled { background: #3A4258; color: #8F98AE; cursor: not-allowed; }
.btn-secondary {
  height: 44px; padding: 0 18px; border-radius: var(--r-md);
  border: 1.5px solid var(--cobalt); background: var(--surface); color: var(--cobalt);
  font-weight: 600; cursor: pointer;
}
.btn-secondary:hover:not(:disabled) { background: #F5F6FF; }
.btn-secondary:disabled { border-color: var(--line); color: #98A2B6; cursor: not-allowed; }
.btn-quiet {
  display: inline-flex; align-items: center; height: 38px; padding: 0 14px;
  border: 1px solid var(--line); border-radius: 10px; background: var(--surface);
  font-weight: 600; font-size: 14px; cursor: pointer;
}
.btn-quiet:hover { border-color: #A9B4C7; }
.file-btn { position: relative; }
.file-btn:focus-within { outline: 2px solid var(--cobalt); outline-offset: 2px; }
.btn-ghost {
  height: 50px; padding: 0 18px; border-radius: var(--r-md);
  border: 1px solid var(--stage-line); background: transparent; color: var(--stage-text);
  font-weight: 600; cursor: pointer;
}
.btn-ghost:hover { background: rgba(255, 255, 255, .05); }
.link {
  padding: 0; border: 0; background: none; cursor: pointer;
  color: var(--cobalt); font-weight: 600; text-decoration: underline; text-underline-offset: 3px;
}
.link-light { color: var(--stage-text); }

/* Status text */
.status { margin: 10px 0 0; font-size: 13.5px; color: var(--muted); }
.status[data-kind=error] { color: var(--err); }
.status[data-kind=warn] { color: var(--warn); }
.status[data-kind=ok] { color: var(--ok); }

/* Photos */
.thumbs { list-style: none; margin: 12px 0; padding: 0; display: flex; flex-wrap: wrap; gap: 8px; }
.thumb { position: relative; width: 64px; height: 64px; border-radius: 10px; overflow: hidden; background: var(--chip); }
.thumb img { display: block; width: 100%; height: 100%; object-fit: cover; }
.thumb-remove {
  position: absolute; top: 3px; right: 3px; width: 22px; height: 22px;
  display: grid; place-items: center; padding: 0;
  border: 0; border-radius: 50%; background: rgba(10, 14, 24, .75); color: #fff;
  font-size: 15px; line-height: 1; cursor: pointer;
}
.range { display: flex; align-items: center; gap: 12px; font-size: 13.5px; font-weight: 600; }
.range input { flex: 1; accent-color: var(--cobalt); }
.cover-thumb { display: flex; align-items: center; gap: 12px; margin-top: 10px; }
.cover-thumb img { width: 56px; height: 56px; border-radius: 50%; object-fit: cover; }

/* Checkbox and switch */
.check, .switch { display: flex; align-items: center; gap: 10px; cursor: pointer; }
.check { font-size: 14.5px; }
.check input { width: 18px; height: 18px; margin: 0; accent-color: var(--cobalt); }
.switch { position: relative; margin: 0 0 20px; font-weight: 600; }
.switch input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.switch-track {
  flex: none; position: relative; width: 42px; height: 24px; border-radius: 12px;
  background: #C3CAD7; transition: background .15s;
}
.switch-track::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px;
  border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0, 0, 0, .2);
  transition: transform .15s;
}
.switch input:checked + .switch-track { background: var(--cobalt); }
.switch input:checked + .switch-track::after { transform: translateX(18px); }
.switch input:focus-visible + .switch-track { outline: 2px solid var(--cobalt); outline-offset: 2px; }

/* Progress bars */
.bar { height: 6px; border-radius: 3px; background: rgba(255, 255, 255, .14); overflow: hidden; }
.bar span { display: block; width: 0; height: 100%; border-radius: inherit; background: var(--cobalt); transition: width .2s; }
.bar-light { margin-top: 12px; background: var(--chip); }

/* Caption editor */
#capGenerate { margin: 2px 0 0; }
.cap-look { margin-top: 24px; }
.cap-editor { margin-top: 24px; padding-top: 20px; border-top: 1px solid var(--line); }
.cap-editor h3 { margin: 0; font: 700 17px/1.2 var(--font-display); letter-spacing: -0.01em; }
.cap-lines {
  list-style: none; margin: 14px 0 0; padding: 0 4px 0 0;
  display: flex; flex-direction: column; gap: 6px;
  max-height: 440px; overflow: auto;
}
.cap-line { display: grid; grid-template-columns: 54px 1fr; gap: 8px; align-items: start; }
.cap-time {
  height: 38px; border: 0; border-radius: 8px; cursor: pointer;
  background: var(--chip); color: var(--muted);
  font-weight: 600; font-size: 12.5px; font-variant-numeric: tabular-nums;
}
.cap-time:hover { background: var(--cobalt); color: #fff; }
.cap-text {
  width: 100%; min-height: 38px; padding: 8px 10px; resize: none; overflow: hidden;
  border: 1px solid var(--line); border-radius: 8px; background: var(--surface);
  font-size: 14.5px; line-height: 1.4;
}

/* ---------- Stage: the preview monitor ---------- */
.stage {
  grid-area: stage;
  position: sticky; top: 16px;
  height: calc(100dvh - 88px); min-height: 560px;
  margin-top: 24px; padding: 20px;
  display: flex; flex-direction: column; gap: 14px;
  background: var(--stage); color: var(--stage-text);
  border-radius: 28px;
}
.screen-wrap { flex: 1; min-height: 0; display: grid; place-items: center; }
.screen {
  position: relative; overflow: hidden; border-radius: 16px; background: #000;
  box-shadow: 0 0 0 1px var(--stage-line), 0 30px 60px -24px rgba(0, 0, 0, .7);
}
.screen canvas, .screen video { display: block; width: 100%; height: 100%; background: #000; }
.screen video { object-fit: contain; }
.screen-empty {
  position: absolute; inset: 0; margin: 0; padding: 24px;
  display: grid; place-items: center; text-align: center;
  font: 600 15px/1.4 var(--font-body); color: #fff;
  background: rgba(10, 14, 24, .3);
}
.transport { display: flex; align-items: center; gap: 12px; }
.play {
  flex: none; width: 44px; height: 44px; border: 0; border-radius: 50%;
  display: grid; place-items: center; cursor: pointer;
  background: #fff; color: var(--stage);
}
.play:disabled { opacity: .3; cursor: not-allowed; }
.play svg { width: 20px; height: 20px; }
.play[data-state=paused] .i-pause, .play[data-state=playing] .i-play { display: none; }
#scrub { flex: 1; min-width: 0; accent-color: #fff; }
.time { min-width: 88px; text-align: right; font-size: 13px; color: var(--stage-muted); font-variant-numeric: tabular-nums; }

.export { display: flex; flex-direction: column; gap: 10px; }
.export > .btn-primary { width: 100%; }
.export > .btn-primary.is-quiet { background: transparent; color: var(--stage-text); box-shadow: inset 0 0 0 1px var(--stage-line); }
.export > .btn-primary.is-quiet:hover { background: rgba(255, 255, 255, .05); }
.export-note { margin: 0; text-align: center; font-size: 12.5px; color: var(--stage-muted); }
.render-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-top: 8px; font-size: 13.5px; }
.result { padding: 16px; background: var(--stage-2); border-radius: 16px; }
.result-title { margin: 0; font: 700 18px/1.2 var(--font-display); }
.result-size { margin: 4px 0 14px; font-size: 12.5px; color: var(--stage-muted); word-break: break-all; }
.result-actions { display: flex; gap: 10px; }
.result-actions .btn-primary { flex: 1; }
.result-note { margin: 12px 0 0; font-size: 13px; color: #F2CB72; }
.error {
  margin: 0; padding: 10px 12px; border-radius: 10px;
  font-size: 13.5px; color: #FFB1AA; background: rgba(255, 120, 110, .1);
}

.code-field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 600; color: var(--stage-muted); }
.code-field input {
  height: 42px; padding: 0 12px; border-radius: 10px;
  border: 1px solid var(--stage-line); background: var(--stage-2); color: var(--stage-text);
}
.code-field input::placeholder { color: #6F7890; }
.result-link { margin: 12px 0 0; font-size: 13px; color: var(--stage-muted); word-break: break-all; }
.result-link a { color: var(--stage-text); }
.server-note { margin: 0; font-size: 12.5px; color: var(--stage-muted); text-align: center; }

.footer {
  max-width: 1480px; margin: 0 auto;
  padding: 8px clamp(16px, 3vw, 32px) 36px;
  font-size: 13px; color: var(--muted);
}
.footer p { margin: 0; max-width: 70ch; }
.footer a { color: var(--ink); }

/* ---------- Smaller screens ---------- */
@media (max-width: 980px) {
  .layout { grid-template-columns: minmax(0, 1fr); grid-template-areas: "intro" "stage" "steps"; grid-template-rows: auto; }
  .intro { padding-top: 28px; }
  .stage { position: relative; top: auto; height: auto; min-height: 0; margin-top: 22px; padding: 14px; border-radius: 22px; }
  .screen-wrap { flex: none; height: min(48vh, 520px); }
  .topbar-note { display: none; }
}
@media (max-width: 560px) {
  .field.two { grid-template-columns: 1fr; }
  .step { padding-left: 0; }
  .step::before { display: none; }
  .step-head { margin-left: 0; }
  .seg span { font-size: 13.5px; padding: 6px 4px; }
  .result-actions { flex-direction: column; }
  .btn-ghost { height: 44px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; }
}
.server-note { margin: 10px 0 0; text-align: left; word-break: break-all; }
.server-note a { color: var(--stage-text); }
.unlock { display: flex; align-items: flex-end; gap: 10px; margin-top: 14px; }
.unlock .text { flex: 1; }
.unlock .btn-secondary { flex: none; }
@media (max-width: 560px) { .unlock { flex-direction: column; align-items: stretch; } }

/* Audio parts */
.parts { list-style: none; margin: 10px 0 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.part {
  display: grid; grid-template-columns: 26px 1fr auto auto; gap: 8px; align-items: center;
  padding: 8px 10px; background: var(--surface); border: 1px solid var(--line); border-radius: 10px;
}
.part-num { font-size: 12px; font-weight: 700; color: var(--muted); text-align: center; }
.part-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; }
.part-time { font-size: 12.5px; color: var(--muted); font-variant-numeric: tabular-nums; }
.part-btns { display: flex; gap: 2px; }
.part-btns button {
  width: 28px; height: 28px; padding: 0; border: 0; border-radius: 7px; cursor: pointer;
  background: var(--chip); color: var(--muted); font-size: 13px; line-height: 1;
}
.part-btns button:hover:not(:disabled) { background: var(--cobalt); color: #fff; }
.part-btns button:disabled { opacity: .35; cursor: not-allowed; }
.parts-actions { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-top: 10px; }
.parts-actions .hint { margin: 0; }

/* Background music and gap */
.music-field { margin-top: 18px; padding-top: 18px; border-top: 1px solid var(--line); }
.music-field > legend { margin-bottom: 10px; }
.music-row { display: flex; align-items: center; gap: 12px; margin-top: 10px; font-size: 14px; }
.music-row .part-name { flex: 1; }
#musicSettings { margin-top: 14px; display: flex; flex-direction: column; gap: 12px; }
.range-val { min-width: 56px; text-align: right; font-size: 12.5px; color: var(--muted); font-variant-numeric: tabular-nums; font-weight: 500; }
#gapField { margin-top: 14px; }
