:root {
  color-scheme: dark;
  font-family: system-ui, sans-serif;
  background: #111014;
  color: #f6f3fa;
  --surface: #1b1921;
  --border: #36313e;
  --muted: #b6aebf;
  --accent: #dfc7ff;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; }
.site-header {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: 1rem clamp(1rem, 5vw, 3.5rem);
  border-bottom: 1px solid var(--border);
  font-weight: 650;
}
.brand-icon, .stage-icon {
  display: grid;
  place-items: center;
  border-radius: .6rem;
  width: 2rem;
  height: 2rem;
  color: #241436;
  background: var(--accent);
  font-size: .85rem;
}
main { width: min(100% - 2rem, 56rem); margin: clamp(2rem, 6vw, 4.5rem) auto 5rem; }
h1 { margin: 0 0 1.4rem; font-size: clamp(2rem, 5vw, 3.6rem); letter-spacing: -.06em; line-height: 1.05; }
h2 { font-size: 1rem; margin: 0 0 .8rem; font-weight: 650; }
.composer { padding: 1rem; background: var(--surface); border: 1px solid var(--border); border-radius: 1rem; }
.composer > label { display: block; font-size: .9rem; font-weight: 650; margin-bottom: .65rem; }
textarea {
  display: block;
  width: 100%;
  min-height: 7.5rem;
  padding: .85rem;
  resize: vertical;
  font: inherit;
  color: inherit;
  background: #141218;
  border: 1px solid var(--border);
  border-radius: .65rem;
}
textarea::placeholder { color: #a79caf; }
.actions, .output-actions { display: flex; align-items: center; gap: .75rem; margin-top: .85rem; }
.actions { justify-content: space-between; flex-wrap: wrap; }
.modes { display: flex; flex-wrap: wrap; gap: .2rem; min-width: 0; margin: 0; padding: .2rem; border: 1px solid var(--border); border-radius: .7rem; }
.modes label { position: relative; cursor: pointer; }
.modes input, .sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
.modes span { display: block; padding: .6rem .7rem; border-radius: .45rem; color: var(--muted); font-size: .82rem; }
.modes input:checked + span { color: #fff; background: #3e3250; }
.modes input:focus-visible + span, :is(button, a, textarea):focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.modes:disabled { opacity: .65; }
button, .button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .65rem;
  min-height: 2.75rem;
  padding: .55rem 1rem;
  border-radius: .65rem;
  border: 1px solid var(--border);
  background: var(--surface);
  color: inherit;
  font: inherit;
  font-size: .9rem;
  font-weight: 650;
  text-decoration: none;
  cursor: pointer;
}
.primary { background: var(--accent); border-color: transparent; color: #261636; }
:is(button, .button):hover { filter: brightness(1.12); }
button:disabled { opacity: .58; cursor: default; }
.muted, .error { font-size: .85rem; margin: .7rem 0 0; }
.muted { color: var(--muted); }
.error { color: #ffadbd; overflow-wrap: anywhere; }
.result, .history { margin-top: 2rem; }
.stage {
  position: relative;
  display: grid;
  place-items: center;
  isolation: isolate;
  overflow: hidden;
  aspect-ratio: 16 / 9;
  border: 1px solid var(--border);
  border-radius: 1rem;
  background: #16121c;
}
.dot-grid {
  position: absolute;
  z-index: -1;
  inset: 0;
  background: radial-gradient(circle, #aa82d9 1px, transparent 1.6px) 0 0 / 16px 16px;
  mask-image: radial-gradient(ellipse, transparent 12%, #000 65%);
  opacity: .23;
}
.stage.is-busy .dot-grid { animation: pulse 2s ease-in-out infinite alternate; }
@keyframes pulse { to { opacity: .6; transform: scale(1.035); } }
.stage-status { padding: 1rem; display: grid; justify-items: center; text-align: center; overflow-wrap: anywhere; min-width: 0; }
.stage-status p { margin: .5rem 0 0; color: var(--muted); }
.stage-icon { background: #30263c; color: var(--accent); }
.percentage { font-size: clamp(1.8rem, 7vw, 3.5rem); font-weight: 650; font-variant-numeric: tabular-nums; }
.stage > video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; background: #000; }
.output-actions { justify-content: flex-end; }
.output-actions:has(> :not([hidden])) { margin-top: .85rem; }
.output-actions { margin-top: 0; }
#history { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--border); }
#history:empty { border: 0; }
#history li { padding: .65rem 0; border-bottom: 1px solid var(--border); }
.history-entry { display: flex; align-items: center; gap: .85rem; color: inherit; text-decoration: none; }
a.history-entry:hover .job-title { text-decoration: underline; }
.history-thumb { width: 5rem; flex: 0 0 5rem; aspect-ratio: 16 / 9; object-fit: cover; border-radius: .4rem; background: var(--surface); }
.job-title { display: block; overflow-wrap: anywhere; }
.job-meta { display: block; color: var(--muted); font-size: .8rem; margin-top: .18rem; }
@media (max-width: 480px) {
  .stage { aspect-ratio: 1; }
  .actions > button { width: 100%; }
}
@media (prefers-reduced-motion: reduce) {
  .stage.is-busy .dot-grid { animation: none; }
}
