@font-face {
  font-family: 'Source Sans 3';
  src: url('/fonts/source-sans-3-latin-wght-normal.woff2') format('woff2');
  font-weight: 200 900;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'Source Code Pro';
  src: url('/fonts/source-code-pro-latin-400-normal.woff2') format('woff2');
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: 'Source Code Pro';
  src: url('/fonts/source-code-pro-latin-600-normal.woff2') format('woff2');
  font-weight: 600;
  font-display: swap;
}

:root {
  --bg: #1E1E1E;
  --surface: #252526;
  --panel: #2D2D30;
  --raised: #3E3E42;
  --border: #3F3F46;
  --text: #E0E0E0;
  --muted: #9E9E9E;
  --accent: #C93C3C;
  --accent-hover: #D94848;
  --accent-text: #EB6363;
  --on-accent: #FFFFFF;
  --ok: #4CAF50;
  --shade: rgba(0, 0, 0, 0.35);
  --sans: 'Source Sans 3', system-ui, sans-serif;
  --mono: 'Source Code Pro', ui-monospace, monospace;
  color-scheme: dark;
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #F3F3F3;
    --surface: #FFFFFF;
    --panel: #EBEBEB;
    --raised: #DCDCDC;
    --border: #D0D0D0;
    --text: #1E1E1E;
    --muted: #5F5F5F;
    --accent: #B83232;
    --accent-hover: #A12A2A;
    --accent-text: #A82D2D;
    --on-accent: #FFFFFF;
    --ok: #2E7D32;
    --shade: rgba(0, 0, 0, 0.12);
    color-scheme: light;
  }
}
:root[data-theme="light"] {
  --bg: #F3F3F3;
  --surface: #FFFFFF;
  --panel: #EBEBEB;
  --raised: #DCDCDC;
  --border: #D0D0D0;
  --text: #1E1E1E;
  --muted: #5F5F5F;
  --accent: #B83232;
  --accent-hover: #A12A2A;
  --accent-text: #A82D2D;
  --on-accent: #FFFFFF;
  --ok: #2E7D32;
  --shade: rgba(0, 0, 0, 0.12);
  color-scheme: light;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 400 15px/1.5 var(--sans);
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
code, pre, kbd, samp { font-family: var(--mono); }
a { color: var(--accent-text); text-decoration: none; }
a:hover { text-decoration: underline; }
img { display: block; max-width: 100%; }
[hidden] { display: none !important; }
h1, h2, h3 { margin: 0; line-height: 1.2; font-weight: 600; }
h1 { font-size: 30px; }
h2 { font-size: 20px; }
h3 { font-size: 16px; }
p { margin: 0; }
.mono { font-family: var(--mono); font-size: 13px; }
.muted { color: var(--muted); }

/* ---------- header ---------- */

.top {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}
.top-inner {
  max-width: 1320px;
  margin: 0 auto;
  padding: 0 24px;
  height: 56px;
  display: flex;
  align-items: center;
  gap: 28px;
}
.brand { color: var(--text); font-weight: 700; font-size: 19px; letter-spacing: -0.01em; }
.brand span { color: var(--accent); }
.brand:hover { text-decoration: none; }
.nav { display: flex; gap: 4px; flex: 1; }
.nav a {
  color: var(--muted);
  padding: 6px 10px;
  border-radius: 6px;
  font-weight: 500;
}
.nav a:hover { color: var(--text); text-decoration: none; background: var(--panel); }
.nav a.on { color: var(--text); }
.icon-btn {
  width: 34px; height: 34px;
  display: grid; place-items: center;
  background: none; border: 1px solid transparent; border-radius: 6px;
  cursor: pointer; color: var(--muted);
}
.icon-btn:hover { color: var(--text); background: var(--panel); }
.icon-btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; }
.i-moon { display: none; }
:root[data-theme="light"] .i-sun { display: none; }
:root[data-theme="light"] .i-moon { display: block; }
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) .i-sun { display: none; }
  :root:not([data-theme="dark"]) .i-moon { display: block; }
}

.view { max-width: 1320px; margin: 0 auto; padding: 28px 24px 64px; }
.view.wide { max-width: none; padding: 0 0 64px; }

/* ---------- controls ---------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 36px; padding: 0 16px;
  border-radius: 6px; border: 1px solid var(--border);
  background: var(--panel); color: var(--text);
  font-weight: 600; font-size: 14px;
  cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--raised); text-decoration: none; }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn.danger { color: var(--accent-text); }
.btn.danger.solid { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.small { height: 30px; padding: 0 11px; font-size: 13px; }
.btn.ghost { background: none; border-color: transparent; color: var(--muted); }
.btn.ghost:hover { color: var(--text); background: var(--panel); }
.btn svg { width: 15px; height: 15px; fill: currentColor; }

.field { display: grid; gap: 6px; }
.field > span { font-size: 13px; color: var(--muted); font-weight: 500; }
.input, select.input, textarea.input {
  width: 100%;
  height: 36px;
  padding: 0 11px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  outline: none;
}
textarea.input { height: auto; min-height: 90px; padding: 9px 11px; resize: vertical; line-height: 1.45; }
textarea.input.links { font-family: var(--mono); font-size: 13px; min-height: 150px; }
.input:focus { border-color: var(--accent); }
.input.mono { font-family: var(--mono); font-size: 13px; }
select.input { padding-right: 28px; cursor: pointer; }

.check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-size: 14px; }
.check input { accent-color: var(--accent); width: 16px; height: 16px; margin: 0; }

/* filter rows are the one place pills are used */
.tabs { display: inline-flex; gap: 4px; padding: 3px; background: var(--surface); border: 1px solid var(--border); border-radius: 999px; }
.tabs button {
  border: 0; background: none; color: var(--muted);
  padding: 4px 13px; border-radius: 999px; cursor: pointer; font-weight: 500; font-size: 14px;
}
.tabs button:hover { color: var(--text); }
.tabs button.on { background: var(--raised); color: var(--text); }

.toast {
  position: fixed; left: 24px; bottom: 24px; z-index: 50;
  max-width: min(440px, calc(100vw - 48px));
  background: var(--panel); border: 1px solid var(--border); border-radius: 6px;
  padding: 10px 14px; font-size: 14px;
  box-shadow: 0 6px 20px var(--shade);
}
.toast.err { border-color: var(--accent); }

.empty {
  border: 1px dashed var(--border); border-radius: 8px;
  padding: 36px 24px; color: var(--muted);
}
.empty h2 { color: var(--text); margin-bottom: 6px; }
.empty .btn { margin-top: 16px; }

.err-line { color: var(--accent-text); font-size: 14px; min-height: 20px; }

/* ---------- sign in ---------- */

.signin {
  min-height: 100vh; display: grid; place-items: center; padding: 24px;
}
.signin form {
  width: 100%; max-width: 340px;
  display: grid; gap: 14px;
}
.signin .brand { font-size: 26px; margin-bottom: 6px; }

/* ---------- library ---------- */

.lib-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 22px; }
.lib-head .search { flex: 1 1 260px; max-width: 380px; }
.lib-head select { width: auto; min-width: 150px; }
.lib-count { margin-left: auto; color: var(--muted); }

.section-title { display: flex; align-items: baseline; gap: 10px; margin: 0 0 12px; }
.section-title .mono { color: var(--muted); }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(156px, 1fr));
  gap: 24px 18px;
}
.card { display: block; color: var(--text); min-width: 0; }
.card:hover { text-decoration: none; }
.poster {
  aspect-ratio: 2 / 3;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
  position: relative;
}
.poster img { width: 100%; height: 100%; object-fit: cover; }
.poster .fallback {
  position: absolute; inset: 0; padding: 14px;
  display: flex; align-items: flex-end;
  font-weight: 600; font-size: 16px; line-height: 1.25; color: var(--muted);
}
.card:hover .poster { border-color: var(--muted); }
.card .name { margin-top: 8px; font-weight: 600; font-size: 14px; line-height: 1.3; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card .meta { color: var(--muted); font-family: var(--mono); font-size: 12px; margin-top: 2px; }
.tag {
  position: absolute; left: 8px; top: 8px;
  font-family: var(--mono); font-size: 11px;
  background: var(--surface); color: var(--muted);
  border: 1px solid var(--border); border-radius: 4px; padding: 1px 6px;
}

.row-scroll {
  display: grid; grid-auto-flow: column;
  grid-auto-columns: minmax(250px, 300px);
  gap: 16px; overflow-x: auto; padding-bottom: 8px; margin-bottom: 34px;
  scrollbar-width: thin;
}
.wide-card { display: block; color: var(--text); min-width: 0; }
.wide-card:hover { text-decoration: none; }
.thumb {
  aspect-ratio: 16 / 9; position: relative;
  background: var(--surface); border: 1px solid var(--border); border-radius: 6px; overflow: hidden;
}
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.thumb .fallback { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); font-weight: 600; padding: 12px; text-align: center; }
.wide-card:hover .thumb { border-color: var(--muted); }
.bar { position: absolute; left: 0; right: 0; bottom: 0; height: 3px; background: var(--shade); }
.bar i { display: block; height: 100%; background: var(--accent); }
.wide-card .name { margin-top: 7px; font-weight: 600; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.wide-card .meta { color: var(--muted); font-family: var(--mono); font-size: 12px; }

/* ---------- title page ---------- */

.backdrop {
  width: 100%; aspect-ratio: 32 / 9; max-height: 420px;
  background: var(--surface); border-bottom: 1px solid var(--border);
  overflow: hidden;
}
.backdrop img { width: 100%; height: 100%; object-fit: cover; object-position: center 30%; }
.detail { max-width: 1320px; margin: 0 auto; padding: 28px 24px 0; display: grid; grid-template-columns: 220px 1fr; gap: 32px; }
.detail .poster { width: 220px; }
.detail.has-backdrop .poster { margin-top: -110px; box-shadow: 0 10px 30px var(--shade); }
.detail h1 { margin-bottom: 8px; }
.facts span + span::before { content: '·'; margin: 0 9px; }
.detail.no-poster { grid-template-columns: 1fr; }
.field-row { display: flex; flex-wrap: wrap; gap: 14px 16px; align-items: end; }
.field-row .field { min-width: 200px; }
.field-row .field.narrow { min-width: 0; width: 150px; }
.facts { display: flex; flex-wrap: wrap; gap: 6px 0; color: var(--muted); font-family: var(--mono); font-size: 13px; margin-bottom: 16px; }
.overview { max-width: 760px; color: var(--text); margin-bottom: 22px; }
.actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.resume-note { color: var(--muted); font-size: 13px; font-family: var(--mono); }

.episodes { max-width: 1320px; margin: 40px auto 0; padding: 0 24px; }
.episodes-head { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; margin-bottom: 16px; }
.ep-list { display: grid; gap: 0; border-top: 1px solid var(--border); }
.ep {
  display: grid; grid-template-columns: 200px 1fr auto; gap: 18px; align-items: center;
  padding: 14px 0; border-bottom: 1px solid var(--border); color: var(--text);
}
.ep:hover { text-decoration: none; }
a.ep:hover .thumb { border-color: var(--muted); }
.ep .num { font-family: var(--mono); font-size: 12px; color: var(--muted); }
.ep .ep-name { font-weight: 600; margin: 1px 0 4px; }
.ep .ep-over { color: var(--muted); font-size: 14px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.ep.off { opacity: 0.55; }
.ep .state { font-family: var(--mono); font-size: 12px; color: var(--muted); white-space: nowrap; }
.ep .state.done { color: var(--ok); }

/* ---------- player ---------- */

.watch { max-width: 1320px; margin: 0 auto; padding: 20px 24px 0; }
.watch-top { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; min-width: 0; }
.watch-top .where { min-width: 0; }
.watch-top .where .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.watch-top .where .sub { color: var(--muted); font-family: var(--mono); font-size: 12px; }
.stage {
  position: relative; width: 100%; aspect-ratio: 16 / 9; max-height: calc(100vh - 190px);
  background: #000; border-radius: 6px; overflow: hidden;
}
.stage video, .stage iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; background: #000; }
.stage .stage-msg { position: absolute; inset: 0; display: grid; place-items: center; color: #BDBDBD; padding: 24px; text-align: center; }
.watch-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-top: 14px; }
.watch-bar .spacer { flex: 1; }
.up-next {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  margin-top: 14px; padding: 12px 14px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 6px;
}
.up-next .count { font-family: var(--mono); color: var(--muted); }

/* ---------- manage ---------- */

.admin-head { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; margin-bottom: 22px; }
.admin-head h1 { margin-right: auto; }
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 20px; }
.panel + .panel { margin-top: 18px; }
.panel > h2 { margin-bottom: 4px; }
.panel > .muted { margin-bottom: 16px; font-size: 14px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 16px; }
.form-grid .full { grid-column: 1 / -1; }
.form-actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-top: 18px; }

.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th { text-align: left; font-weight: 500; color: var(--muted); font-size: 12px; font-family: var(--mono); padding: 8px 10px; border-bottom: 1px solid var(--border); }
.table td { padding: 9px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table tr:hover td { background: var(--panel); color: var(--text); }
.table .mini-poster { width: 34px; aspect-ratio: 2/3; border-radius: 3px; background: var(--panel); object-fit: cover; }
.table .grow { width: 100%; }
.table .nowrap { white-space: nowrap; }
.table .link-cell { max-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-family: var(--mono); font-size: 12px; color: var(--muted); }
.table-wrap { overflow-x: auto; }
.link-row { display: flex; gap: 8px; }
.link-row select { width: auto; }
.ep-name-cell { max-width: 240px; overflow: hidden; text-overflow: ellipsis; }

.results { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 16px; margin-top: 16px; }
.result { background: none; border: 0; padding: 0; text-align: left; cursor: pointer; color: var(--text); min-width: 0; }
.result .poster { border-radius: 4px; }
.result:hover .poster { border-color: var(--muted); }
.result .name { font-weight: 600; font-size: 13px; margin-top: 6px; line-height: 1.3; }
.result .meta { color: var(--muted); font-family: var(--mono); font-size: 11px; }

.split { display: grid; grid-template-columns: 180px 1fr; gap: 24px; }
.split .poster { width: 180px; }

.confirm { display: inline-flex; align-items: center; gap: 8px; font-size: 14px; }

.seasons { display: flex; flex-wrap: wrap; gap: 8px 18px; margin: 10px 0 4px; }

/* ---------- narrow ---------- */

@media (max-width: 760px) {
  .top-inner { padding: 0 16px; gap: 14px; }
  .nav a { padding: 6px 7px; }
  .view { padding: 20px 16px 48px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 18px 12px; }
  .lib-head .search { max-width: none; }
  .lib-count { margin-left: 0; width: 100%; }
  .backdrop { aspect-ratio: 16 / 9; }
  .detail { grid-template-columns: 1fr; padding: 20px 16px 0; gap: 18px; }
  .detail .poster { width: 120px; }
  .detail.has-backdrop .poster { margin-top: -70px; }
  .episodes { padding: 0 16px; }
  .ep { grid-template-columns: 112px 1fr; gap: 12px; }
  .ep .state { grid-column: 2; }
  .ep .ep-over { -webkit-line-clamp: 2; font-size: 13px; }
  .watch { padding: 12px 0 0; }
  .watch-top, .watch-bar, .up-next { margin-left: 16px; margin-right: 16px; }
  .stage { border-radius: 0; }
  .form-grid { grid-template-columns: 1fr; }
  .split { grid-template-columns: 1fr; }
  .split .poster { width: 120px; }
  .panel { padding: 16px; }
  .toast { left: 16px; bottom: 16px; }
  .row-scroll { grid-auto-columns: minmax(220px, 78vw); }
  /* episode rows stack instead of squashing the link boxes */
  .ep-table thead { display: none; }
  .ep-table, .ep-table tbody, .ep-table tr, .ep-table td { display: block; width: 100%; }
  .ep-table tr { padding: 10px 0; border-bottom: 1px solid var(--border); }
  .ep-table tr:last-child { border-bottom: 0; }
  .ep-table td { border: 0; padding: 3px 0; }
  .ep-table tr:hover td { background: none; }
  .ep-table .ep-name-cell { max-width: none; }
  .ep-table .ep-name-cell:empty { display: none; }
  .link-row { flex-wrap: wrap; }
  .link-row .input { flex: 1 1 100%; }
}
