/* Tokens from replica/design/tokens.json. Light values are checked (contrast.py). */
:root {
  --bg: #ffffff; --surface: #f6f7f9; --border: #e3e6ea; --border-input: #7b8490;
  --text: #14171c; --text-muted: #5b6470; --accent: #2f5bea; --on-accent: #ffffff;
  --focus: #2f5bea; --highlight: #ffd23f; --danger: #c62f2f; --success: #1f7a4d;
  --radius-sm: 6px; --radius-md: 10px; --radius-pill: 999px;
  --shadow-card: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.10);
  --fast: 120ms; --base: 200ms; --ease: cubic-bezier(.2,.8,.2,1);
  --max-width: 1200px;
}
/* Dark values are not in tokens.json yet and are not contrast-checked. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #18181b; --surface: #202024; --border: #3f3f46; --border-input: #8b8b94;
    --text: #fafafa; --text-muted: #a1a1aa; --accent: #60a5fa; --on-accent: #0b1220;
    --focus: #60a5fa; --highlight: #facc15; --danger: #f87171; --success: #4ade80;
    --shadow-card: none;
  }
}
:root[data-theme="dark"] {
  --bg: #18181b; --surface: #202024; --border: #3f3f46; --border-input: #8b8b94;
  --text: #fafafa; --text-muted: #a1a1aa; --accent: #60a5fa; --on-accent: #0b1220;
  --focus: #60a5fa; --highlight: #facc15; --danger: #f87171; --success: #4ade80;
  --shadow-card: none;
}

* { box-sizing: border-box; }
body { margin: 0; font: 15px/1.5 Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
       background: var(--bg); color: var(--text); }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
button, select, input { font: inherit; }
button { min-height: 36px; padding: 6px 14px; border-radius: var(--radius-pill); cursor: pointer;
         border: 1px solid var(--accent); background: var(--accent); color: var(--on-accent); font-weight: 600;
         transition: filter var(--fast) var(--ease); }
button:hover { filter: brightness(.95); }
button:disabled { opacity: .5; cursor: default; }
button.ghost { background: var(--surface); color: var(--text); border-color: var(--border); }
button.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
select, input[type="text"], input[type="number"] { padding: 4px 8px; border: 1px solid var(--border-input);
         border-radius: var(--radius-sm); background: var(--bg); color: var(--text); }
input[type="checkbox"], input[type="range"] { accent-color: var(--accent); }

.topbar { border-bottom: 1px solid var(--border); background: var(--bg); position: sticky; top: 0; z-index: 2; }
.topbar-inner { max-width: var(--max-width); margin: 0 auto; padding: 12px 16px; display: flex; gap: 12px; align-items: center; }
.topbar a { color: var(--text); text-decoration: none; font-weight: 700; font-size: 18px; }
.crumbs { color: var(--text-muted); font-size: 13px; }

main { max-width: var(--max-width); margin: 0 auto; padding: 16px; }
.muted { color: var(--text-muted); font-size: 13px; }
.bad { color: var(--danger); }
.good { color: var(--success); }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.stack { display: flex; flex-direction: column; gap: 12px; }
h1 { font-size: 24px; margin: 8px 0 4px; }
h2 { font-size: 18px; margin: 0 0 8px; }
.card { background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-md);
        padding: 12px; box-shadow: var(--shadow-card); }

/* Progress bar (S03, S06) */
.progress { height: 6px; background: var(--border); border-radius: var(--radius-pill); overflow: hidden; width: 100%; max-width: 360px; }
.progress > div { height: 100%; background: var(--accent); width: 0; transition: width var(--base) var(--ease); }

/* Clip grid (S04) */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.clip-card { display: flex; flex-direction: column; gap: 8px; padding: 0; overflow: hidden; }
.clip-card img { width: 100%; aspect-ratio: 9 / 16; object-fit: cover; background: #000; display: block; }
.clip-card .body { padding: 0 12px 12px; display: flex; flex-direction: column; gap: 6px; }
.clip-card .title { font-weight: 600; }
.badge { display: inline-block; padding: 2px 8px; border-radius: var(--radius-pill); background: var(--surface);
         border: 1px solid var(--border); font-size: 12px; color: var(--text-muted); }

/* Project cards (S01) */
.project-list { display: grid; gap: 8px; list-style: none; padding: 0; margin: 0; }
.project-list li a { display: flex; justify-content: space-between; gap: 8px; padding: 12px; border-radius: var(--radius-md);
                     border: 1px solid var(--border); color: var(--text); text-decoration: none; background: var(--bg); }
.project-list li a:hover { background: var(--surface); }

/* Editor (S05) */
.editor { display: grid; gap: 16px; grid-template-columns: minmax(0, 1fr); }
@media (min-width: 900px) { .editor { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); } }
.player { width: 100%; max-width: 520px; background: #000; border-radius: var(--radius-md); display: block; }
.subs { min-height: 2.4em; text-align: center; font-weight: 600; max-width: 520px; margin: 6px 0; }
.words { line-height: 2; }
.w { padding: 0 2px; border-radius: 4px; cursor: pointer; }
.w:hover { outline: 1px dashed var(--text-muted); }
.w.filler { background: var(--highlight); color: #14171c; }
.w.cut { text-decoration: line-through; opacity: .45; }
.w.selected { outline: 2px solid var(--focus); }
.kbd { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; border: 1px solid var(--border);
       border-radius: var(--radius-sm); padding: 0 4px; background: var(--surface); }
.hist-row { display: flex; justify-content: space-between; gap: 8px; align-items: center; padding: 8px 0; border-top: 1px solid var(--border); flex-wrap: wrap; }
.hist-row:first-child { border-top: none; }

/* Forms */
label.opt { color: var(--text-muted); font-size: 13px; display: inline-flex; gap: 6px; align-items: center; }
.slider-wrap { width: 100%; max-width: 360px; }
/* Crop window over the frame: the dark surround is a shadow outside the box. */
.crop-box { position: absolute; box-sizing: border-box; border: 2px solid var(--accent); border-radius: 4px;
  box-shadow: 0 0 0 999px rgba(0, 0, 0, 0.45); touch-action: none; }

@media (max-width: 600px) {
  main { padding: 12px; }
  h1 { font-size: 20px; }
}

/* --- accounts: login page, topbar controls, admin screen --- */
.account { margin-left: auto; display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.account a { font-size: 13px; font-weight: 400; text-decoration: none; }
.account a:hover { text-decoration: underline; }

.login-page { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
.login-box { width: 100%; max-width: 360px; }
.login-box h1 { margin: 0; font-size: 24px; }
.login-box label, .narrow label { font-size: 13px; color: var(--text-muted); margin-bottom: -6px; }
.login-box input, .narrow input { width: 100%; padding: 8px; border: 1px solid var(--border-input);
       border-radius: var(--radius-sm); background: var(--bg); color: var(--text); }
.login-box button[type="submit"] { margin-top: 4px; }

.narrow { max-width: 420px; }
.stack.tight { gap: 2px; }
.secret { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 16px;
       padding: 6px 10px; background: var(--surface); border: 1px solid var(--border);
       border-radius: var(--radius-sm); user-select: all; }
.hist-row .badge { margin-left: 6px; }
