:root {
  --bg: oklch(0.19 0.012 60);
  --bg-raised: oklch(0.235 0.014 60);
  --bg-sunk: oklch(0.155 0.01 60);
  --line: oklch(0.32 0.015 60);
  --text: oklch(0.93 0.015 80);
  --text-dim: oklch(0.72 0.02 75);
  --text-faint: oklch(0.56 0.02 70);
  --amber: oklch(0.78 0.15 70);
  --amber-deep: oklch(0.66 0.15 55);
  --amber-ink: oklch(0.22 0.04 60);
  --red: oklch(0.68 0.17 28);
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --display: 'Fraunces', Georgia, serif;
  --body: 'Instrument Sans', system-ui, sans-serif;
  --gutter: clamp(16px, 4vw, 48px);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 var(--body);
  -webkit-font-smoothing: antialiased;
  min-height: 100dvh;
}
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--amber); outline-offset: 2px; }
code, kbd { font-family: ui-monospace, 'SF Mono', Menlo, monospace; font-size: 0.85em; background: var(--bg-sunk); padding: 0.1em 0.35em; border-radius: 4px; }

/* ---- wordmark & buttons ---- */
.wordmark {
  font: 800 clamp(2.6rem, 8vw, 4.2rem)/0.95 var(--display);
  font-variation-settings: 'opsz' 144;
  letter-spacing: -0.035em;
  margin: 0;
}
.wordmark span { color: var(--amber); font-style: italic; font-weight: 600; }
.wordmark--small { font-size: 1.6rem; }

.btn {
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 0.55em 1.15em;
  cursor: pointer;
  font-weight: 600;
  background: none;
  transition: background 0.2s var(--ease), border-color 0.2s var(--ease), transform 0.15s var(--ease);
}
.btn:active { transform: scale(0.97); }
.btn--primary { background: var(--amber); color: var(--amber-ink); }
.btn--primary:hover { background: oklch(0.83 0.14 75); }
.btn--primary:disabled { opacity: 0.5; cursor: progress; }
.btn--ghost { border-color: var(--line); color: var(--text-dim); }
.btn--ghost:hover { border-color: var(--text-faint); color: var(--text); }
.btn--danger { color: var(--red); border-color: color-mix(in oklch, var(--red) 40%, transparent); }
.error { color: var(--red); min-height: 1.5em; margin: 0.4rem 0 0; font-size: 0.92rem; }

/* ---- login ---- */
.login { min-height: 100dvh; display: grid; place-items: center; padding: var(--gutter); }
.login__form { display: grid; gap: 0.9rem; width: min(340px, 100%); }
.login__form .wordmark { margin-bottom: 1.2rem; }
.login__form input {
  background: var(--bg-sunk); border: 1px solid var(--line); border-radius: 10px; padding: 0.8rem 1rem;
}

/* ---- layout ---- */
.app { min-height: 100dvh; }
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 1.1rem var(--gutter);
  border-bottom: 1px solid var(--line);
}
.count { color: var(--amber); font-variant-numeric: tabular-nums; }
.stage { max-width: 1120px; padding: clamp(2rem, 6vw, 4.5rem) var(--gutter) 4rem; }

/* ---- magnet input ---- */
.zap__label {
  display: block;
  font: 600 clamp(1.7rem, 4.5vw, 2.8rem)/1.1 var(--display);
  letter-spacing: -0.02em;
  margin-bottom: 1.1rem;
}
.zap__row { display: flex; gap: 0.6rem; }
.zap__input {
  flex: 1; min-width: 0;
  background: var(--bg-sunk);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 1rem 1.15rem;
  font-family: ui-monospace, 'SF Mono', Menlo, monospace;
  font-size: 0.92rem;
  transition: border-color 0.2s var(--ease);
}
.zap__input:focus { border-color: var(--amber-deep); outline: none; }
.zap__input[aria-invalid='true'] { border-color: var(--red); }
.btn--zap { border-radius: 14px; padding-inline: 1.8rem; font-size: 1.05rem; }

.empty { margin-top: 3rem; max-width: 60ch; color: var(--text-dim); }
.empty p { margin: 0 0 0.8rem; }

/* ---- session ---- */
.session { margin-top: clamp(2rem, 5vw, 3.5rem); animation: rise 0.6s var(--ease) both; }
@keyframes rise { from { opacity: 0; transform: translateY(12px); } }
.session__head { display: flex; justify-content: space-between; gap: 1rem; align-items: flex-start; flex-wrap: wrap; }
.session__actions { display: flex; gap: 0.5rem; }
.eyebrow { margin: 0 0 0.3rem; color: var(--amber); font-size: 0.8rem; font-weight: 600; letter-spacing: 0.12em; text-transform: uppercase; }
.title { margin: 0; font: 600 clamp(1.25rem, 3vw, 1.75rem)/1.2 var(--display); overflow-wrap: anywhere; max-width: 40ch; }

.steps { list-style: none; display: flex; gap: 0; padding: 0; margin: 1.6rem 0 1.2rem; font-size: 0.85rem; color: var(--text-faint); }
.steps li { flex: 1; padding-top: 0.6rem; border-top: 2px solid var(--line); transition: color 0.3s, border-color 0.3s; }
.steps li.done { color: var(--text-dim); border-color: var(--amber-deep); }
.steps li.now { color: var(--text); border-color: var(--amber); }

.filepick { display: flex; flex-wrap: wrap; gap: 0.4rem 1rem; align-items: center; margin-bottom: 1.2rem; }
.filepick label { color: var(--text-dim); font-size: 0.9rem; }
.filepick select {
  flex: 1; min-width: 0; max-width: 100%;
  background: var(--bg-sunk); border: 1px solid var(--line); border-radius: 10px; padding: 0.55rem 0.8rem;
}

.meter { position: relative; height: 6px; background: var(--bg-sunk); border-radius: 99px; overflow: hidden; }
.meter__fill { position: absolute; inset: 0 auto 0 0; width: 0; background: var(--amber-deep); opacity: 0.55; transition: width 0.8s var(--ease); }
.meter__buffer { position: absolute; inset: 0 auto 0 0; width: 0; background: var(--amber); transition: width 0.8s var(--ease); }

.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 1rem; margin: 1rem 0 0; }
.stats div { min-width: 0; }
.stats dt { color: var(--text-faint); font-size: 0.78rem; letter-spacing: 0.06em; text-transform: uppercase; }
.stats dd { margin: 0.15rem 0 0; font-variant-numeric: tabular-nums; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---- player ---- */
.player { margin-top: 1.6rem; position: relative; }
.player video {
  display: block; width: 100%; aspect-ratio: 16 / 9; background: oklch(0.1 0.005 60);
  border-radius: 12px 12px 0 0;
}
.player.dragging video { outline: 2px dashed var(--amber); outline-offset: -8px; }
.player__msg {
  position: absolute; inset: 0 0 auto 0; aspect-ratio: 16 / 9;
  display: grid; place-items: center; text-align: center; padding: 2rem;
  color: var(--text-dim); pointer-events: none;
}
.controls {
  display: flex; align-items: center; gap: 0.75rem;
  background: var(--bg-raised); padding: 0.55rem 0.8rem; border-radius: 0 0 12px 12px;
}
.ctl { width: 36px; height: 36px; display: grid; place-items: center; border: 0; background: none; cursor: pointer; border-radius: 8px; color: var(--text); flex: none; }
.ctl:hover { background: var(--bg-sunk); }
.ctl svg { width: 20px; height: 20px; fill: currentColor; }
.ctl .i-pause { display: none; }
.playing .ctl .i-pause { display: block; }
.playing .ctl .i-play { display: none; }
.time { font-variant-numeric: tabular-nums; font-size: 0.85rem; color: var(--text-dim); flex: none; }
.seek { flex: 1; min-width: 60px; accent-color: var(--amber); }
.volume { width: 80px; accent-color: var(--amber); flex: none; }
.hint { color: var(--text-faint); font-size: 0.85rem; margin: 0.7rem 0 0; }

.ctl-menu { position: relative; }
.menu {
  position: absolute; bottom: calc(100% + 8px); right: 0; z-index: 5;
  background: var(--bg-raised); border: 1px solid var(--line); border-radius: 10px;
  padding: 0.4rem; min-width: 220px; max-height: 50vh; overflow: auto;
}
.menu h3 { margin: 0.4rem 0.6rem 0.2rem; font-size: 0.72rem; letter-spacing: 0.1em; text-transform: uppercase; color: var(--text-faint); }
.menu button { display: block; width: 100%; text-align: left; border: 0; background: none; padding: 0.45rem 0.6rem; border-radius: 6px; cursor: pointer; }
.menu button:hover { background: var(--bg-sunk); }
.menu button[aria-checked='true'] { color: var(--amber); }
.menu button[aria-checked='true']::before { content: '● '; }

video::cue { background: oklch(0.1 0 0 / 0.72); color: var(--text); font-family: var(--body); }

/* ---- library drawer ---- */
.library {
  position: fixed; inset: 0 0 0 auto; width: min(420px, 100%);
  background: var(--bg-raised); border-left: 1px solid var(--line);
  padding: 1.1rem var(--gutter) 1.5rem;
  display: flex; flex-direction: column;
  transform: translateX(100%); transition: transform 0.45s var(--ease);
  z-index: 10; overflow-y: auto;
}
.library.open { transform: none; }
.library__head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1rem; }
.library__head h2 { margin: 0; font: 600 1.4rem var(--display); }
.library__list { list-style: none; margin: 0; padding: 0; }
.library__list li { padding: 0.9rem 0; border-bottom: 1px solid var(--line); }
.lib__name { font-weight: 600; overflow-wrap: anywhere; }
.lib__meta { color: var(--text-faint); font-size: 0.82rem; margin: 0.15rem 0 0.6rem; font-variant-numeric: tabular-nums; }
.lib__meta .kept { color: var(--amber); }
.lib__bar { height: 3px; background: var(--bg-sunk); border-radius: 99px; margin-bottom: 0.6rem; overflow: hidden; }
.lib__bar span { display: block; height: 100%; background: var(--amber-deep); }
.lib__actions { display: flex; gap: 0.4rem; flex-wrap: wrap; }
.lib__actions .btn { padding: 0.35em 0.9em; font-size: 0.85rem; }
.library__empty { color: var(--text-faint); }
.library__logout { margin-top: auto; align-self: flex-start; }
.library__list:empty + .library__empty { display: block; }

@media (max-width: 640px) {
  .zap__row { flex-direction: column; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .volume { display: none; }
  .controls { gap: 0.4rem; padding: 0.45rem; }
  .player video, .player__msg { border-radius: 8px 8px 0 0; }
}

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