:root {
  color-scheme: dark;
  --bg: #0e0f13;
  --surface: #17191f;
  --surface-2: #1f222a;
  --border: #2a2e37;
  --text: #e8eaef;
  --muted: #9097a5;
  --accent: #6c8cff;
  --accent-hover: #869fff;
  --ok: #3ecf8e;
  --warn: #f5b84b;
  --danger: #ff6b6b;
  --radius: 12px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 15px;
  line-height: 1.5;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }  /* class display rules must not beat the hidden attribute */
body { margin: 0; background: var(--bg); color: var(--text); min-height: 100vh; }
a { color: inherit; text-decoration: none; }
h1 { font-size: 1.6rem; font-weight: 650; letter-spacing: -.01em; margin: 0; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }

/* ---------- header ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  padding: .85rem clamp(1rem, 4vw, 2.5rem);
  background: rgb(14 15 19 / .85); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: .55rem; font-weight: 700; font-size: 1.05rem; }
.brand-mark {
  width: 28px; height: 28px; border-radius: 8px; display: grid; place-items: center;
  background: linear-gradient(135deg, var(--accent), #a66cff);
}
.brand-mark svg { width: 14px; height: 14px; fill: #fff; margin-left: 2px; }
.topbar nav { display: flex; align-items: center; gap: .4rem; }
.nav-link { color: var(--muted); padding: .45rem .8rem; border-radius: 8px; }
.nav-link:hover, .nav-link.active { color: var(--text); background: var(--surface-2); }

main { max-width: 1180px; margin: 0 auto; padding: 2rem clamp(1rem, 4vw, 2.5rem) 4rem; }
.page-head { display: flex; align-items: end; justify-content: space-between; gap: 1rem; margin-bottom: 1.5rem; }
.subtle { color: var(--muted); margin: .25rem 0 0; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: .45rem;
  font: inherit; font-weight: 550; padding: .55rem 1rem; border-radius: 9px;
  border: 1px solid transparent; cursor: pointer; transition: background .15s, border-color .15s;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-ghost { background: transparent; color: var(--muted); border-color: var(--border); }
.btn-ghost:hover { color: var(--text); background: var(--surface-2); }
.btn-danger:hover { color: var(--danger); border-color: var(--danger); background: transparent; }

/* ---------- library grid ---------- */
.grid { list-style: none; padding: 0; margin: 0; display: grid; gap: 1.5rem 1.25rem;
        grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); }
.card { display: block; }
.thumb {
  position: relative; aspect-ratio: 16 / 9; border-radius: var(--radius); overflow: hidden;
  background: var(--surface-2); border: 1px solid var(--border);
}
.thumb img { width: 100%; height: 100%; object-fit: cover; transition: transform .25s; }
.card:hover .thumb img { transform: scale(1.04); }
.duration {
  position: absolute; right: .5rem; bottom: .5rem; font-size: .75rem; font-weight: 600;
  padding: .1rem .4rem; border-radius: 5px; background: rgb(0 0 0 / .75);
}
.thumb-state { position: absolute; inset: 0; display: grid; place-content: center; gap: .6rem;
               text-align: center; color: var(--muted); font-size: .85rem; padding: 1rem; }
.meter { height: 4px; width: 140px; border-radius: 99px; background: var(--border); overflow: hidden; }
.meter > span { display: block; height: 100%; background: var(--accent); transition: width .4s; }
.card-title { margin: .65rem 0 0; font-weight: 600; overflow-wrap: anywhere;
              display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.card-meta { color: var(--muted); font-size: .85rem; margin-top: .15rem; }
.pill { font-size: .72rem; font-weight: 600; padding: .1rem .5rem; border-radius: 99px; margin-left: .35rem; }
.pill.failed { color: var(--danger); background: rgb(255 107 107 / .12); }
.pill.processing, .pill.queued { color: var(--warn); background: rgb(245 184 75 / .12); }

.empty { text-align: center; padding: 5rem 1rem; border: 1px dashed var(--border); border-radius: var(--radius); color: var(--muted); }
.empty p { margin: 0 0 1.25rem; }

/* ---------- upload ---------- */
.narrow { max-width: 680px; margin: 0 auto; }
.dropzone {
  display: grid; place-items: center; gap: .5rem; text-align: center; cursor: pointer;
  padding: 3.5rem 1.5rem; margin-top: 1.5rem; border-radius: var(--radius);
  border: 2px dashed var(--border); background: var(--surface); transition: border-color .15s, background .15s;
}
.dropzone:hover, .dropzone.over { border-color: var(--accent); background: rgb(108 140 255 / .06); }
.dropzone:focus-within { border-color: var(--accent); }
.dropzone.disabled { pointer-events: none; opacity: .5; }
.dropzone svg { width: 40px; height: 40px; stroke: var(--accent); fill: none; stroke-width: 1.6; }
.dropzone strong { font-size: 1.05rem; }
.dropzone small { color: var(--muted); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.job { margin-top: 1.25rem; padding: 1.1rem 1.25rem; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--border); }
.job-row { display: flex; justify-content: space-between; gap: 1rem; align-items: baseline; }
.job-name { font-weight: 600; overflow-wrap: anywhere; }
.job-pct { font-variant-numeric: tabular-nums; font-weight: 600; }
.job .meter { width: 100%; height: 6px; margin: .75rem 0 .5rem; }
.job-detail { color: var(--muted); font-size: .85rem; font-variant-numeric: tabular-nums; }
.job.error { border-color: rgb(255 107 107 / .5); }
.job-actions { margin-top: .9rem; }

/* ---------- watch ---------- */
.player { border-radius: var(--radius); overflow: hidden; background: #000; aspect-ratio: 16 / 9; display: grid; place-items: center; }
.player > * { grid-area: 1 / 1; }
.player video { width: 100%; height: 100%; display: block; }
.player .state { color: var(--muted); text-align: center; display: grid; gap: .75rem; justify-items: center; }
.watch-head { display: flex; justify-content: space-between; align-items: start; gap: 1rem; flex-wrap: wrap; margin-top: 1.25rem; }
.chips { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: .5rem; }
.chip { font-size: .8rem; color: var(--muted); background: var(--surface-2); border: 1px solid var(--border); padding: .15rem .6rem; border-radius: 99px; }
.chip.live { color: var(--ok); }
.watch-actions { display: flex; align-items: center; gap: .6rem; }
select {
  font: inherit; color: var(--text); background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 9px; padding: .5rem 2rem .5rem .8rem; cursor: pointer; appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: right 1rem center, right .7rem center; background-size: 5px 5px; background-repeat: no-repeat;
}
.spinner { width: 28px; height: 28px; border-radius: 50%; border: 3px solid var(--border); border-top-color: var(--accent); animation: spin .9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 600px) {
  .page-head { flex-direction: column; align-items: start; }
  .watch-actions { width: 100%; }
  .watch-actions select { flex: 1; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
