/* =====================================================================
   Psyditor styles. Reads only SEMANTIC tokens from tokens.css.
   Order: base → layout helpers → components (alphabetical-ish by role)
   → landing sections → app views. Class names follow BEM-lite:
   .block, .block__part, .block--variant.
   ===================================================================== */

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }
body {
  margin: 0;
  background: var(--color-bg);
  color: var(--color-text);
  font: 400 var(--text-body) / var(--leading-body) var(--font-family);
  font-variation-settings: "wdth" 100;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { margin: 0; text-wrap: balance; }
p { margin: 0; text-wrap: pretty; }
a { color: inherit; }
img, svg { display: block; max-width: 100%; }
[hidden] { display: none !important; }

/* Keyboard focus is always visible, in a colour that is not the action red. */
:focus-visible { outline: 3px solid var(--color-focus); outline-offset: 3px; border-radius: 4px; }

/* Hidden from the eye, still read by screen readers and still focusable. */
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.skip { position: absolute; left: var(--space-4); top: -100px; z-index: var(--z-toast); background: var(--color-highlight); color: var(--color-on-highlight); padding: var(--space-2) var(--space-4); border-radius: var(--radius-sm); }
.skip:focus { top: var(--space-4); }

/* ---------- Layout helpers ---------- */
.wrap { width: 100%; max-width: var(--content-max); margin-inline: auto; padding-inline: var(--gutter); }
.row { display: flex; flex-wrap: wrap; gap: var(--space-3); align-items: center; }
.section { padding-block: clamp(var(--space-16), 10vw, var(--space-24)); }
.muted { color: var(--color-text-muted); }

/* ---------- Type ---------- */
/* Display: condensed width + heavy weight, the look of a reel caption. */
.display, .h1, .h2, .steps h3, .features dt, .logo {
  font-variation-settings: "wdth" 62;
  font-weight: 850;
  letter-spacing: -0.01em;
  line-height: var(--leading-tight);
  text-transform: uppercase;
}
.display { font-size: var(--size-3xl); }
.h1 { font-size: var(--size-2xl); }
.h2 { font-size: var(--size-2xl); margin-bottom: var(--space-8); }
.h3 { font-size: var(--size-lg); font-weight: 700; }
.lede { font-size: var(--size-lg); color: var(--color-text-muted); max-width: 52ch; }
.fine { font-size: var(--size-sm); color: var(--color-text-muted); }

/* The highlighted word: a chartreuse plate, slightly tilted, like the reels. */
mark {
  background: var(--color-highlight);
  color: var(--color-on-highlight);
  padding: 0 0.12em;
  border-radius: 0.08em;
  display: inline-block;
  transform: rotate(-2deg);
}

/* ---------- Buttons ---------- */
/* One button vocabulary everywhere: default, hover, active, focus, disabled, busy. */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
  min-height: 44px;                                   /* touch target */
  padding: var(--space-3) var(--space-6);
  border: 1px solid transparent; border-radius: var(--radius-pill);
  background: var(--color-action); color: var(--color-on-action);
  font: 650 var(--size-md) var(--font-family); text-decoration: none; cursor: pointer;
  transition: background var(--dur-fast) var(--ease-out), transform var(--dur-fast) var(--ease-out);
}
.btn:hover { background: var(--color-action-hover); }
.btn:active { transform: scale(0.97); }
/* Disabled: neutral, not a dimmed red, so it never reads as an error. */
.btn:disabled { background: var(--color-surface-raised); color: var(--color-text-muted); cursor: not-allowed; transform: none; }
.btn[aria-busy="true"] { cursor: progress; opacity: 0.75; }
.btn--ghost { background: transparent; color: var(--color-text); border-color: var(--color-border); }
.btn--ghost:hover { background: var(--color-surface-raised); }
.btn--sm { min-height: 36px; padding: var(--space-2) var(--space-4); font-size: var(--size-sm); }
.btn--lg { min-height: 54px; padding: var(--space-4) var(--space-8); font-size: var(--size-lg); }
.btn--block { width: 100%; }

/* Text-styled control (nav links, "show password", "log out"). */
.link {
  background: none; border: 0; padding: var(--space-2); color: var(--color-text-muted);
  font: 500 var(--size-sm) var(--font-family); text-decoration: none; cursor: pointer;
}
.link:hover { color: var(--color-text); }

/* ---------- Top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: var(--z-sticky);
  display: flex; align-items: center; justify-content: space-between; gap: var(--space-4);
  padding: var(--space-3) var(--gutter);
  background: color-mix(in oklch, var(--color-bg) 85%, transparent);
  backdrop-filter: blur(12px);                       /* keeps the bar readable over the moving hero */
  border-bottom: 1px solid var(--color-border);
}
.topbar__nav { display: flex; align-items: center; gap: var(--space-2); }
.logo { display: inline-flex; align-items: center; gap: var(--space-2); font-size: var(--size-xl); text-decoration: none; text-transform: lowercase; }
.logo--sm { font-size: var(--size-lg); }
/* The brand mark: "ditor" sits on the tilted plate, the signature used everywhere a word matters. */
.logo { gap: 0.04em; }
.logo mark { margin-left: 0.02em; }

/* The REC light: a red dot that breathes. */
.rec { width: 0.55em; height: 0.55em; border-radius: 50%; background: var(--color-action); box-shadow: 0 0 0.6em var(--color-action); animation: rec 1.6s var(--ease-out) infinite; }
@keyframes rec { 50% { opacity: 0.35; box-shadow: none; } }
@media (prefers-reduced-motion: reduce) { .rec { animation: none; } }

/* ---------- Forms ---------- */
.form { display: grid; gap: var(--space-4); margin-top: var(--space-6); }
.field { display: grid; gap: var(--space-2); }
.field label { font-size: var(--size-sm); font-weight: 600; }
.field input, .field textarea {
  width: 100%; min-height: 48px; padding: var(--space-3) var(--space-4);
  background: var(--color-surface); color: var(--color-text);
  border: 1px solid var(--color-border); border-radius: var(--radius-sm);
  font: inherit; transition: border-color var(--dur-fast) var(--ease-out);
}
.field textarea { resize: vertical; }
.field input::placeholder, .field textarea::placeholder { color: var(--color-text-muted); }
.field input:focus-visible, .field textarea:focus-visible { outline: none; border-color: var(--color-focus); box-shadow: 0 0 0 3px color-mix(in oklch, var(--color-focus) 30%, transparent); }
.field input[aria-invalid="true"] { border-color: var(--color-danger); }
.field__help { font-size: var(--size-xs); color: var(--color-text-muted); }
.field__help--error { color: var(--color-danger); }
/* Password input with a "Show" button sitting inside it. */
.field__pw { position: relative; }
.field__pw input { padding-right: 4.5rem; }
.field__pw .link { position: absolute; right: var(--space-2); top: 50%; transform: translateY(-50%); }
.form__error { color: var(--color-danger); font-size: var(--size-sm); min-height: 1.2em; }
.form__error:empty { display: none; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: var(--space-6); z-index: var(--z-toast); transform: translateX(-50%);
  padding: var(--space-3) var(--space-6); border-radius: var(--radius-pill);
  background: var(--color-text); color: var(--color-bg); font-weight: 600;
  animation: rise var(--dur-base) var(--ease-out);
}
@keyframes rise { from { opacity: 0; transform: translate(-50%, 12px); } }

/* =====================================================================
   Landing
   ===================================================================== */
.hero {
  display: grid; grid-template-columns: 1.25fr 0.75fr; gap: var(--space-12); align-items: center;
  padding-block: clamp(var(--space-12), 8vw, var(--space-24));
}
.hero__copy { display: grid; gap: var(--space-6); }
/* First-load choreography: the headline rises, then the phone; content is visible without it. */
.hero__copy > * { animation: enter var(--dur-slow) var(--ease-out) both; }
.hero__copy > :nth-child(2) { animation-delay: 80ms; }
.hero__copy > :nth-child(3) { animation-delay: 160ms; }
.phone { animation: enter var(--dur-slow) 240ms var(--ease-out) both; }
@keyframes enter { from { opacity: 0; transform: translateY(24px); filter: blur(6px); } }

/* The phone mock. Its screen is a 9:16 reel. */
.phone { margin: 0; justify-self: center; width: min(320px, 78vw); padding: 10px; border-radius: 44px; background: var(--color-surface-raised); box-shadow: 0 40px 80px -30px color-mix(in oklch, var(--color-key) 45%, transparent), inset 0 0 0 1px var(--color-border); transform: rotate(3deg); }
/* The drawn speaker is lit by the key-light token. */
.phone__person .key { stop-color: var(--color-key); }
.phone__person .rim { stroke: var(--color-key); }
/* A reel is always dark video, whatever the page theme. */
.phone__screen { position: relative; color: oklch(0.98 0 0); aspect-ratio: 9 / 16; border-radius: 34px; overflow: hidden; background: oklch(0.12 0.01 155); }
.phone__person { position: absolute; inset: 0; width: 100%; height: 100%; }
.phone__rec { position: absolute; top: 18px; left: 18px; display: flex; align-items: center; gap: 6px; font-size: var(--size-xs); font-variant-numeric: tabular-nums; }
.phone__caption {
  position: absolute; left: 8%; right: 8%; bottom: 22%;
  text-align: center; font-variation-settings: "wdth" 62; font-weight: 900; font-size: 1.9rem; line-height: 1;
  text-transform: uppercase; text-shadow: 0 3px 12px oklch(0 0 0 / 0.6);
}
.phone__caption mark { font-size: 1.15em; }
.phone__caption.is-new { animation: pop var(--dur-base) var(--ease-out); }
@keyframes pop { from { transform: scale(0.86); opacity: 0; } }
.phone__bar { position: absolute; left: 18px; right: 18px; bottom: 18px; height: 3px; border-radius: 2px; background: oklch(1 0 0 / 0.2); overflow: hidden; }
.phone__bar i { display: block; height: 100%; width: 100%; background: var(--color-text); transform-origin: left; animation: play 12s linear infinite; }
@keyframes play { from { transform: scaleX(0); } }
@media (prefers-reduced-motion: reduce) { .phone__bar i { animation: none; } }

/* Ticker: two identical halves scroll left by 50% for a seamless loop. */
.ticker { overflow: hidden; border-block: 1px solid var(--color-border); background: var(--color-action); color: var(--color-on-action); }
.ticker__track { display: flex; width: max-content; animation: ticker 40s linear infinite; }
.ticker span { padding: var(--space-4) var(--space-6); font-variation-settings: "wdth" 62; font-weight: 800; font-size: var(--size-xl); text-transform: uppercase; white-space: nowrap; }
.ticker span::after { content: "●"; margin-left: var(--space-12); font-size: 0.5em; vertical-align: middle; }
@keyframes ticker { to { transform: translateX(-50%); } }
@media (prefers-reduced-motion: reduce) { .ticker__track { animation: none; } }

/* Steps: a real sequence, so big numerals earn their place. */
.steps { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: var(--space-8); }
.steps li { display: grid; gap: var(--space-3); align-content: start; }
.steps__n { font-variation-settings: "wdth" 62; font-weight: 900; font-size: 5rem; line-height: 0.8; color: var(--color-action); }
.steps h3 { font-size: var(--size-xl); }
.steps p { color: var(--color-text-muted); }

/* Features as editorial rows: a big word, then what it means. Not a card grid. */
.features { margin: 0; display: grid; }
.features > div { display: grid; grid-template-columns: minmax(140px, 1fr) 2fr; gap: var(--space-6); padding-block: var(--space-6); border-top: 1px solid var(--color-border); align-items: baseline; }
.features > div:last-child { border-bottom: 1px solid var(--color-border); }
.features dt { font-size: var(--size-2xl); transition: color var(--dur-base) var(--ease-out); }
.features > div:hover dt { color: var(--color-highlight); }
.features dd { margin: 0; color: var(--color-text-muted); font-size: var(--size-lg); max-width: 55ch; }

/* Pricing: one drenched block. */
.price { display: flex; flex-wrap: wrap; align-items: end; justify-content: space-between; gap: var(--space-8); }
.price { background: var(--color-surface); border-radius: var(--radius-lg); padding: clamp(var(--space-8), 6vw, var(--space-16)); margin-block: var(--space-12); }
.price .h2 { font-size: var(--size-3xl); margin-bottom: var(--space-4); }

/* FAQ with native <details>: keyboard and screen-reader friendly for free. */
.faq { display: grid; max-width: 760px; }
.faq details { border-top: 1px solid var(--color-border); }
.faq details:last-child { border-bottom: 1px solid var(--color-border); }
.faq summary { padding: var(--space-4) 0; font-weight: 650; font-size: var(--size-lg); cursor: pointer; list-style: none; display: flex; justify-content: space-between; gap: var(--space-4); }
.faq summary::after { content: "+"; color: var(--color-action); transition: transform var(--dur-base) var(--ease-out); }
.faq details[open] summary::after { transform: rotate(45deg); }
.faq p { padding-bottom: var(--space-4); color: var(--color-text-muted); max-width: 65ch; }

.footer { display: flex; flex-wrap: wrap; justify-content: space-between; gap: var(--space-4); padding-block: var(--space-8); border-top: 1px solid var(--color-border); font-size: var(--size-sm); }

/* =====================================================================
   App views
   ===================================================================== */
#app { padding-block: var(--space-12) var(--space-24); }
.auth { max-width: var(--form-max); margin-inline: auto; display: grid; gap: var(--space-2); }
.auth__links { margin-top: var(--space-6); display: flex; flex-wrap: wrap; justify-content: space-between; gap: var(--space-3); font-size: var(--size-sm); color: var(--color-text-muted); }
.auth__links a { color: var(--color-text); }

.studio { display: grid; gap: var(--space-8); }
.upload { display: grid; gap: var(--space-4); max-width: 720px; }

/* The drop target: big, obvious, one tap on a phone. */
.drop {
  display: grid; justify-items: center; gap: var(--space-2); text-align: center;
  padding: clamp(var(--space-8), 6vw, var(--space-12)) var(--space-6);
  border: 2px dashed var(--color-border); border-radius: var(--radius-md);
  background: var(--color-surface); cursor: pointer;
  transition: border-color var(--dur-fast) var(--ease-out), background var(--dur-fast) var(--ease-out);
}
.drop:hover, .drop.is-over { border-color: var(--color-action); background: var(--color-surface-raised); }
.drop:focus-within { outline: 3px solid var(--color-focus); outline-offset: 3px; }
.drop.is-ready { border-style: solid; border-color: var(--color-success); }
.drop strong { font-size: var(--size-lg); }
.drop__icon { width: 52px; height: 52px; border-radius: 50%; background: var(--color-action); position: relative; }
.drop__icon::after { content: ""; position: absolute; inset: 0; margin: auto; width: 0; height: 0; border-left: 16px solid var(--color-on-action); border-block: 10px solid transparent; translate: 3px 0; }
.drop.is-ready .drop__icon { background: var(--color-success); }

.progress { height: 8px; border-radius: var(--radius-pill); background: var(--color-surface-raised); overflow: hidden; }
.progress i { display: block; height: 100%; width: 100%; background: var(--color-action); transform: scaleX(0); transform-origin: left; transition: transform var(--dur-fast) linear; }

.reels { display: grid; gap: var(--space-2); }
.reels .h2 { margin-bottom: 0; }
.reels__grid { list-style: none; margin: var(--space-4) 0 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: var(--space-6); }
.reel { display: grid; gap: var(--space-3); }
.reel__screen { aspect-ratio: 9 / 16; border-radius: var(--radius-md); overflow: hidden; background: var(--color-surface); display: grid; place-items: center; text-align: center; padding: var(--space-4); }
.reel__screen video { width: 100%; height: 100%; object-fit: cover; }
.reel__screen:has(video) { padding: 0; background: #000; }
.reel__title { font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.reel__meta { font-size: var(--size-sm); color: var(--color-text-muted); }
.reel__actions { display: flex; gap: var(--space-2); }
.reel__actions .btn { flex: 1; }
.reel__state { display: grid; gap: var(--space-3); justify-items: center; color: var(--color-text-muted); font-size: var(--size-sm); }
.reel__state--failed { color: var(--color-danger); }
/* Making-in-progress: a sweeping shimmer conveys "working" without a spinner in the middle. */
.reel__screen--busy { background: linear-gradient(110deg, var(--color-surface) 30%, var(--color-surface-raised) 50%, var(--color-surface) 70%) 0 0 / 300% 100%; animation: sweep 1.8s linear infinite; }
@keyframes sweep { to { background-position: -150% 0; } }
@media (prefers-reduced-motion: reduce) { .reel__screen--busy { animation: none; } }

.empty { padding: var(--space-8); border: 1px dashed var(--color-border); border-radius: var(--radius-md); display: grid; gap: var(--space-2); max-width: 720px; }

/* New reel: their own video beside the few things we need. */
.new { display: grid; grid-template-columns: minmax(220px, 340px) minmax(0, 460px); gap: clamp(var(--space-8), 5vw, var(--space-16)); justify-content: center; align-items: start; }
.new__preview { margin: 0; display: grid; gap: var(--space-2); position: sticky; top: var(--space-24); }
.new__preview video { width: 100%; aspect-ratio: 9 / 16; object-fit: cover; border-radius: var(--radius-lg); background: #000; transform: rotate(-2deg); box-shadow: 0 40px 80px -30px color-mix(in oklch, var(--color-key) 45%, transparent); }
.new__preview figcaption { font-size: var(--size-sm); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.new__form { display: grid; gap: var(--space-4); }
.new__form [data-slot="account"] { display: grid; gap: var(--space-4); }
.new__form [data-slot="fields"] { display: grid; gap: var(--space-4); }
.new__form .link { justify-self: start; padding-inline: 0; }

/* Your style: a quiet line with the palette as swatches, a way to change it, and the optional reference reel. */
.style { display: grid; gap: var(--space-3); margin-block: var(--space-4); max-width: 720px; }
.style[hidden], .style__panel[hidden] { display: none; }
.style__line { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); margin: 0; font-size: var(--size-sm); }
.style__line .link { padding-inline: var(--space-2); text-decoration: underline; text-underline-offset: 3px; }
.swatches { display: inline-flex; }
.swatches i { width: 1rem; height: 1rem; border-radius: 50%; border: 2px solid var(--color-bg); margin-left: -0.3rem; box-shadow: 0 0 0 1px var(--color-border); }
.swatches i:first-child { margin-left: 0; }
.style__panel { display: grid; gap: var(--space-3); padding: var(--space-4); border: 1px solid var(--color-border); border-radius: var(--radius-md); background: var(--color-surface); }
.style__list { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: var(--space-2); }
.chip { display: inline-flex; align-items: center; gap: var(--space-2); min-height: 36px; padding: var(--space-2) var(--space-4); border-radius: 999px;
  border: 1px solid var(--color-border); background: var(--color-surface-raised); color: var(--color-text); font: 500 var(--size-sm) var(--font-family); cursor: pointer; }
.chip:hover { border-color: var(--color-text-muted); }
.chip:focus-visible, .style__line .link:focus-visible { outline: 2px solid var(--color-focus); outline-offset: 2px; }
/* The reference field is the one thing a first-time creator is shown here, so it stands as its own block. */
.ref--open { padding: var(--space-4); border: 1px dashed var(--color-border); border-radius: var(--radius-md); }
.ref__alt { display: flex; align-items: center; gap: var(--space-2); min-width: 0; }
.ref__alt .muted { font-size: var(--size-sm); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- Small screens ---------- */
@media (max-width: 820px) {
  .hero { grid-template-columns: 1fr; }
  .phone { transform: none; }
  .new { grid-template-columns: 1fr; }
  .new__preview { position: static; width: min(220px, 60vw); justify-self: center; }
  .features > div { grid-template-columns: 1fr; gap: var(--space-2); }
  .topbar__nav .link:not([href="#login"]):not([data-action]) { display: none; }  /* keep the bar to essentials */
}

/* The new-reel form: a plain checkbox row, and the own-pictures file input. */
.check { display: flex; align-items: flex-start; gap: var(--space-2); font-size: var(--size-sm); cursor: pointer; }
.check input { margin-top: 0.2em; accent-color: var(--color-key); }
.field input[type="file"] { font-size: var(--size-sm); max-width: 100%; }
.ref textarea { width: 100%; }
