/* Shared by the host page and the viewer page: design tokens and the common components.
   Page-specific rules go in host/host.css and viewer/watch.css. No inline styles anywhere: the
   Content-Security-Policy forbids them, so every look a script needs is a class here or there. */

:root {
  /* colours: a dark theatre */
  --bg: #090a0f;
  --surface: #11131b;
  --surface-2: #171a25;
  --surface-3: #1f2331;
  --border: #252a3a;
  --border-2: #31374b;
  --text: #eceef4;
  --muted: #a0a6b6;
  --faint: #848b9f;
  --accent: #e0a43a;          /* warm marquee gold */
  --accent-2: #e2574c;        /* curtain red */
  --accent-soft: rgba(224, 164, 58, .16);
  --on-accent: #17120a;
  --ok: #34c368;
  --ok-soft: rgba(52, 195, 104, .16);
  --warn: #f2a33a;
  --err: #f0506e;
  --err-soft: rgba(240, 80, 110, .16);

  /* shape and depth */
  --radius: 14px;
  --radius-sm: 9px;
  --radius-xs: 7px;
  --shadow: 0 20px 60px rgba(0, 0, 0, .55);

  /* spacing */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
  --gutter: 28px;

  /* type */
  --font: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --text-sm: 12.5px;
  --text-md: 14px;
  --text-lg: 19px;

  /* the card grid: portrait posters */
  --card-min: 168px;
  --poster-ratio: 2 / 3;

  color-scheme: dark;
}

* { box-sizing: border-box; }
html { scrollbar-color: var(--border-2) var(--bg); scrollbar-width: thin; }
body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(1100px 480px at 85% -10%, rgba(224, 164, 58, .08), transparent 60%),
    radial-gradient(900px 400px at -10% 0%, rgba(226, 87, 76, .06), transparent 60%),
    var(--bg);
  background-attachment: fixed;
  color: var(--text);
  font: var(--text-md)/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
img { max-width: 100%; }
svg.icon { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.mono { font-family: var(--font-mono); }
.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

@keyframes rise { from { opacity: 0; transform: translateY(6px); } }
@keyframes pop { from { opacity: 0; transform: scale(.98); } }
@keyframes shimmer { to { background-position: -150% 0; } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse { 50% { opacity: .35; } }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}

/* ---- top bar ---- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; gap: var(--space-4); align-items: center; flex-wrap: wrap;
  padding: 14px var(--gutter);
  background: rgba(9, 10, 15, .8);
  backdrop-filter: blur(18px) saturate(140%);
  border-bottom: 1px solid var(--border);
}
.topbar .spacer { flex: 1; }
.brand { display: flex; align-items: center; gap: 10px; font-size: var(--text-lg); font-weight: 650; letter-spacing: -.02em; color: var(--text); text-decoration: none; }
.brand b { font-weight: 650; background: linear-gradient(90deg, var(--accent), var(--accent-2)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.logo { display: grid; place-items: center; width: 32px; height: 32px; border-radius: var(--radius-sm); background: linear-gradient(135deg, var(--accent), var(--accent-2)); box-shadow: 0 6px 20px rgba(224, 164, 58, .3); }
.logo svg { width: 15px; height: 15px; fill: #fff; stroke: none; }

/* ---- page layout ---- */
.page { padding: var(--space-5) var(--gutter) 60px; }
.section-title { margin: 0 0 var(--space-3); color: var(--faint); font-size: 11px; font-weight: 650; letter-spacing: .1em; text-transform: uppercase; }

/* ---- buttons ---- */
.btn {
  display: inline-flex; gap: var(--space-2); align-items: center; justify-content: center;
  height: 40px; padding: 0 18px;
  border: 1px solid var(--border-2); border-radius: 11px;
  background: var(--surface-2); font-weight: 600; white-space: nowrap; cursor: pointer;
  text-decoration: none; color: var(--text);
  transition: background .15s, border-color .15s, filter .15s;
}
.btn:hover { background: var(--surface-3); }
.btn.primary { border: 0; background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: var(--on-accent); box-shadow: 0 8px 24px rgba(224, 164, 58, .25); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; }
.btn.danger { border-color: rgba(240, 80, 110, .4); background: transparent; color: #fda4b4; }
.btn.danger:hover { background: var(--err-soft); }
.btn.small { height: 30px; padding: 0 12px; font-size: var(--text-sm); border-radius: 8px; }
.btn.icon-only { width: 40px; padding: 0; }
.btn.small.icon-only { width: 30px; }
.btn.on { border-color: var(--accent); color: var(--accent); }
.btn:disabled { opacity: .55; cursor: default; filter: none; }

/* ---- inputs and selects ---- */
.input, select, textarea {
  width: 100%; height: 38px; padding: 0 12px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  outline: none; transition: border-color .15s, box-shadow .15s;
}
textarea { height: auto; min-height: 80px; padding: 10px 12px; resize: vertical; }
select { cursor: pointer; }
.input::placeholder, textarea::placeholder { color: var(--faint); }
.input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }
.field { display: flex; flex-direction: column; gap: 6px; }
.field > span { color: var(--muted); font-size: var(--text-sm); }
.check { display: inline-flex; gap: var(--space-2); align-items: center; cursor: pointer; }
.check input { accent-color: var(--accent); }

/* ---- chips ---- */
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex; gap: 6px; align-items: center; height: 28px; padding: 0 10px;
  border: 1px solid var(--border); border-radius: 999px; background: var(--surface-2);
  color: var(--muted); font-size: var(--text-sm); font-weight: 600; white-space: nowrap; cursor: pointer;
}
.chip:hover { color: var(--text); border-color: var(--border-2); }
.chip.on { border-color: transparent; background: var(--accent-soft); color: #f6d9a4; }
.chip button { display: grid; place-items: center; width: 18px; height: 18px; padding: 0; border: 0; border-radius: 5px; background: none; color: inherit; opacity: .7; cursor: pointer; }
.chip button:hover { opacity: 1; background: rgba(255, 255, 255, .1); }
.badge { display: inline-block; padding: 2px 8px; border-radius: var(--radius-xs); background: rgba(9, 10, 15, .72); font-size: 11.5px; font-weight: 650; }
.badge.accent { background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: var(--on-accent); }
.badge.ok { background: var(--ok-soft); color: #9ae6b4; }

/* ---- tabs ---- */
.tabs { display: inline-grid; grid-auto-flow: column; grid-auto-columns: max-content; gap: 2px; padding: 3px; background: var(--surface); border: 1px solid var(--border); border-radius: 11px; }
.tabs button, .tabs a { padding: 6px 14px; border: 0; border-radius: 8px; background: none; color: var(--muted); font-size: var(--text-sm); font-weight: 600; text-decoration: none; cursor: pointer; white-space: nowrap; }
.tabs button:hover, .tabs a:hover { color: var(--text); }
.tabs .on, .tabs [aria-selected="true"] { background: var(--surface-3); color: var(--text); box-shadow: inset 0 0 0 1px var(--border-2); }

/* ---- the card grid: portrait posters ---- */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(var(--card-min), 1fr)); gap: 22px 18px; }
.card { min-width: 0; cursor: pointer; outline: none; animation: rise .35s ease both; }
.card.kept { animation: none; }
.poster {
  position: relative; aspect-ratio: var(--poster-ratio); overflow: hidden;
  border-radius: var(--radius); background: var(--surface-2);
  box-shadow: 0 0 0 1px var(--border);
  transition: transform .2s ease, box-shadow .2s ease;
}
.card:hover .poster { transform: translateY(-3px); box-shadow: 0 0 0 1px var(--border-2), var(--shadow); }
.card:focus-visible .poster { box-shadow: 0 0 0 2px var(--accent), var(--shadow); }
.poster img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.poster::after { content: ""; position: absolute; inset: 0; background: linear-gradient(180deg, rgba(0, 0, 0, .3), transparent 25%, transparent 70%, rgba(0, 0, 0, .6)); pointer-events: none; }
.poster .placeholder { position: absolute; inset: 0; display: grid; place-items: center; padding: var(--space-3); background: linear-gradient(135deg, #241a12, #10202a); color: rgba(255, 255, 255, .78); font-size: 15px; font-weight: 650; text-align: center; }
.poster .badge { position: absolute; z-index: 1; }
.poster .badge.tl { top: 8px; left: 8px; }
.poster .badge.tr { top: 8px; right: 8px; }
.poster .badge.bl { bottom: 8px; left: 8px; }
.poster .badge.br { bottom: 8px; right: 8px; }
.card.missing .poster { opacity: .5; }
.card.seen .poster img { filter: saturate(.6) brightness(.8); }
.card h4 { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; margin: 10px 2px 2px; font-size: var(--text-md); font-weight: 600; line-height: 1.35; }
.card .sub { margin: 0 2px; color: var(--muted); font-size: var(--text-sm); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.skeleton .poster { background: linear-gradient(100deg, var(--surface-2) 30%, var(--surface-3) 50%, var(--surface-2) 70%); background-size: 300% 100%; animation: shimmer 1.3s linear infinite; }
.skeleton .line { height: 12px; margin: 12px 2px 0; border-radius: 6px; background: var(--surface-2); }
.skeleton .line.short { width: 55%; }
.empty { padding: 60px 20px; color: var(--muted); text-align: center; }

/* ---- dialogs (native <dialog>) ---- */
dialog.dialog {
  width: min(640px, calc(100vw - 32px)); max-height: 90vh; padding: 0;
  border: 1px solid var(--border-2); border-radius: 18px;
  background: var(--surface); color: var(--text); box-shadow: var(--shadow); overflow: auto;
}
dialog.dialog[open] { animation: pop .2s ease; }
dialog.dialog.wide { width: min(1000px, calc(100vw - 32px)); }
dialog.dialog::backdrop { background: rgba(3, 4, 7, .78); }
.dialog header { display: flex; gap: var(--space-3); align-items: center; padding: 18px 22px; border-bottom: 1px solid var(--border); }
.dialog header h2 { flex: 1; margin: 0; font-size: 17px; font-weight: 650; }
.dialog .body { padding: 18px 22px; }
.dialog footer { display: flex; gap: var(--space-2); justify-content: flex-end; padding: 14px 22px; border-top: 1px solid var(--border); }

/* ---- the dialog player ---- */
dialog.player {
  width: min(1400px, 94vw); max-height: 94vh; padding: 0;
  border: 1px solid var(--border-2); border-radius: 18px;
  background: var(--surface); color: var(--text); box-shadow: var(--shadow); overflow: hidden;
}
dialog.player[open] { display: grid; grid-template-columns: minmax(0, 1fr) 320px; animation: pop .22s ease; }
dialog.player.bare[open] { grid-template-columns: minmax(0, 1fr); }
/* A plain dark backdrop: a blurred one is redrawn under the video every frame. */
dialog.player::backdrop { background: rgba(3, 4, 7, .92); }
body:has(dialog.player[open]) .topbar { backdrop-filter: none; }
.stage { position: relative; display: grid; place-items: center; min-height: 320px; background: #000; }
.stage video { width: 100%; max-height: 94vh; aspect-ratio: 16 / 9; background: #000; }
.stage .close { position: absolute; top: 10px; right: 10px; z-index: 2; }
.stage .spinner { position: absolute; width: 38px; height: 38px; border: 3px solid rgba(255, 255, 255, .2); border-top-color: #fff; border-radius: 50%; animation: spin .9s linear infinite; }
.player-info { display: flex; flex-direction: column; gap: var(--space-3); padding: 20px; overflow: auto; border-left: 1px solid var(--border); }
.player-info h3 { margin: 0; font-size: 17px; font-weight: 650; }
.live-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--accent-2); animation: pulse 1.4s ease-in-out infinite; }

/* ---- toasts ---- */
.toasts { position: fixed; z-index: 50; right: 22px; bottom: 22px; display: flex; flex-direction: column; gap: 10px; }
.toast { max-width: 360px; padding: 12px 16px; border: 1px solid var(--border-2); border-radius: 12px; background: var(--surface-2); box-shadow: var(--shadow); animation: rise .25s ease; }
.toast.ok { border-color: rgba(52, 195, 104, .4); }
.toast.err { border-color: rgba(240, 80, 110, .45); }
.toast button { margin-left: 12px; padding: 0; border: 0; background: none; color: var(--accent); font-weight: 600; text-decoration: underline; cursor: pointer; }

/* ---- narrow screens ---- */
@media (max-width: 760px) {
  :root { --gutter: 16px; --card-min: 132px; }
  .topbar { padding: 10px var(--gutter); gap: var(--space-3); }
  dialog.player[open] { grid-template-columns: minmax(0, 1fr); width: 100vw; max-width: 100vw; border-radius: 0; }
  .player-info { border-left: 0; border-top: 1px solid var(--border); }
  .toasts { left: 16px; right: 16px; bottom: 16px; }
  .toast { max-width: none; }
}

/* ---- the API reference page (Redoc) ---- */
/* Redoc's "made by" link would show its maker's logo; docs.js never lets that image load: hide the link. */
.api-ref a[href^="https://redocly.com"] { display: none; }
