:root {
  color-scheme: dark;
  --bg: #0f1110;
  --surface: #1b1f1d;
  --surface-2: #262b28;
  --line: #303732;
  --text: #f1f4f1;
  --muted: #a4aea8;
  --accent: #8fd37f;
  --on-accent: #10210d;
  --danger: #ff9d94;
  --placeholder-a: #2b382f;
  --placeholder-b: #18201b;
  --top: 56px;
  --sun: block;
  --moon: none;
  font-family: system-ui, -apple-system, "Segoe UI", "Malgun Gothic", "Apple SD Gothic Neo", sans-serif;
}
/* Light colours: when the device asks for them, or when the viewer picked them with the theme button. */
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    color-scheme: light;
    --bg: #ffffff;
    --surface: #f1f3f1;
    --surface-2: #e4e8e4;
    --line: #d5dad6;
    --text: #0f1110;
    --muted: #5c655f;
    --accent: #2c7a35;
    --on-accent: #ffffff;
    --danger: #b3261e;
    --placeholder-a: #dde5dd;
    --placeholder-b: #c9d4ca;
    --sun: none;
    --moon: block;
  }
}
:root[data-theme="light"] {
  color-scheme: light;
  --bg: #ffffff;
  --surface: #f1f3f1;
  --surface-2: #e4e8e4;
  --line: #d5dad6;
  --text: #0f1110;
  --muted: #5c655f;
  --accent: #2c7a35;
  --on-accent: #ffffff;
  --danger: #b3261e;
  --placeholder-a: #dde5dd;
  --placeholder-b: #c9d4ca;
  --sun: none;
  --moon: block;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { background: var(--bg); color: var(--text); }
body { margin: 0; min-height: 100vh; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* Top bar */
#top {
  position: sticky; top: 0; z-index: 10;
  height: var(--top); padding: 0 16px;
  display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: 16px;
  background: var(--bg);
}
.brand { display: flex; align-items: center; gap: 8px; text-decoration: none; font-size: 19px; font-weight: 700; letter-spacing: -.5px; white-space: nowrap; padding: 8px; border-radius: 8px; }
.brand svg { width: 32px; height: 24px; stroke: none; }
.brand svg rect { fill: var(--accent); }
.brand svg path { fill: var(--on-accent); }
#search-form { display: flex; justify-self: center; width: min(600px, 100%); height: 40px; }
#search { flex: 1; min-width: 0; padding: 0 16px; background: var(--bg); border: 1px solid var(--line); border-right: 0; border-radius: 20px 0 0 20px; outline: none; }
#search:focus { border-color: var(--accent); }
#search-form button { width: 60px; display: grid; place-items: center; background: var(--surface); border: 1px solid var(--line); border-radius: 0 20px 20px 0; }
#search-form button:hover { background: var(--surface-2); }
#search-form svg { width: 20px; height: 20px; }
.actions { display: flex; align-items: center; gap: 4px; justify-self: end; }
.icon { display: flex; align-items: center; gap: 8px; height: 40px; min-width: 40px; padding: 0 8px; justify-content: center; background: none; border: 0; border-radius: 20px; }
.icon:hover { background: var(--surface-2); }
.icon.labelled { padding: 0 14px 0 10px; font-size: 14px; font-weight: 500; }
#theme .sun { display: var(--sun); }
#theme .moon { display: var(--moon); }
.icon.busy svg { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .icon.busy svg { animation: none; } }

/* Login */
#login { max-width: 400px; margin: 0 auto; padding: 8vh 24px 48px; }
#login h1 { font-size: 40px; letter-spacing: -1.5px; line-height: 1.15; margin: 10px 0; }
.eyebrow { color: var(--accent); font-size: 13px; font-weight: 600; letter-spacing: .5px; margin: 0; }
.muted { color: var(--muted); font-size: 15px; line-height: 1.6; margin: 0; }
#login form { margin-top: 28px; }
#login label { display: block; color: var(--muted); font-size: 14px; margin: 18px 0; }
#login input { display: block; width: 100%; margin-top: 8px; padding: 13px 14px; background: var(--surface); color: var(--text); border: 1px solid var(--line); border-radius: 10px; outline: none; }
#login input:focus { border-color: var(--accent); }
.primary { width: 100%; margin-top: 8px; padding: 13px 16px; background: var(--accent); color: var(--on-accent); border: 0; border-radius: 22px; font-weight: 700; }
.primary:hover { filter: brightness(1.08); }
.primary:disabled { opacity: .6; cursor: wait; }
#login-error, #play-error { color: var(--danger); font-size: 14px; line-height: 1.5; min-height: 1.5em; }
#play-error:empty { display: none; }

/* Home */
#home { padding: 0 24px 56px; max-width: 2200px; margin: 0 auto; }
#chips { position: sticky; top: var(--top); z-index: 5; display: flex; gap: 12px; padding: 12px 0; overflow-x: auto; scrollbar-width: none; background: var(--bg); }
#chips::-webkit-scrollbar { display: none; }
#chips:empty { display: none; }
.chip { flex: none; height: 32px; padding: 0 12px; background: var(--surface-2); border: 0; border-radius: 8px; font-size: 14px; font-weight: 500; white-space: nowrap; }
.chip:hover { filter: brightness(1.15); }
.chip[aria-pressed="true"] { background: var(--text); color: var(--bg); }
.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin: 8px 0 16px; min-height: 36px; }
#count { margin: 0; color: var(--muted); font-size: 14px; }
.sort { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 14px; }
.sort select { height: 36px; padding: 0 10px; background: var(--surface); color: var(--text); border: 1px solid var(--line); border-radius: 8px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 36px 16px; }

.card { display: block; min-width: 0; text-decoration: none; border-radius: 12px; }
.thumb { position: relative; aspect-ratio: 16 / 9; display: grid; place-items: center; overflow: hidden; border-radius: 12px; background: linear-gradient(135deg, var(--placeholder-a), var(--placeholder-b)); transition: border-radius .15s; }
.thumb::before { content: ""; border-style: solid; border-width: 13px 0 13px 22px; border-color: transparent transparent transparent var(--muted); opacity: .6; }
.thumb img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.card:hover .thumb { border-radius: 0; }
.dur { position: absolute; right: 8px; bottom: 8px; padding: 1px 5px; background: rgba(0, 0, 0, .8); color: #fff; border-radius: 5px; font-size: 12px; font-weight: 600; line-height: 18px; font-variant-numeric: tabular-nums; }
.seen { position: absolute; left: 0; right: 0; bottom: 0; height: 4px; background: rgba(255, 255, 255, .35); }
.seen i { display: block; height: 100%; background: var(--accent); }
.thumb.part .dur { bottom: 10px; }
.info { padding: 12px 2px 0; }
.card h3 { margin: 0 0 4px; font-size: 16px; font-weight: 600; line-height: 22px; overflow-wrap: anywhere; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; line-clamp: 2; overflow: hidden; }
.meta { margin: 0; color: var(--muted); font-size: 14px; line-height: 20px; }

#empty { padding: 72px 20px; text-align: center; color: var(--muted); }
#empty h2 { margin: 0 0 8px; color: var(--text); font-size: 20px; }
#empty p { margin: 0; font-size: 14px; }

/* Watch */
#watch { display: grid; grid-template-columns: minmax(0, 1fr) 400px; gap: 24px; max-width: 1760px; margin: 0 auto; padding: 16px 24px 56px; }
.player { width: 100%; aspect-ratio: 16 / 9; max-height: calc(100vh - var(--top) - 150px); background: #000; border-radius: 12px; overflow: hidden; }
.player video { display: block; width: 100%; height: 100%; background: #000; }
.details { padding-top: 12px; }
#playing-title { margin: 0 0 8px; font-size: 20px; font-weight: 700; line-height: 28px; overflow-wrap: anywhere; }
.watch-row { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 8px 16px; }
.watch-actions { display: flex; align-items: center; flex-wrap: wrap; gap: 8px 16px; }
.pill { display: flex; align-items: center; gap: 6px; height: 36px; padding: 0 16px 0 12px; background: var(--surface-2); border: 0; border-radius: 18px; font-size: 14px; font-weight: 600; font-variant-numeric: tabular-nums; }
.pill:hover { filter: brightness(1.12); }
.pill svg { width: 20px; height: 20px; }
.pill[aria-pressed="true"] svg { fill: currentColor; }
.switch { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 14px; cursor: pointer; }
.switch input { appearance: none; -webkit-appearance: none; width: 36px; height: 20px; margin: 0; border-radius: 10px; background: var(--surface-2); border: 1px solid var(--line); position: relative; cursor: pointer; transition: background .15s; }
.switch input::before { content: ""; position: absolute; top: 2px; left: 2px; width: 14px; height: 14px; border-radius: 50%; background: var(--muted); transition: transform .15s, background .15s; }
.switch input:checked { background: var(--accent); border-color: var(--accent); }
.switch input:checked::before { transform: translateX(16px); background: var(--on-accent); }
.note { margin: 16px 0 0; padding: 12px; background: var(--surface); border-radius: 12px; color: var(--muted); font-size: 13px; line-height: 1.5; }
#next-list { display: grid; gap: 8px; }
.card.compact { display: grid; grid-template-columns: 168px minmax(0, 1fr); gap: 8px; border-radius: 8px; }
.card.compact .thumb { border-radius: 8px; }
.card.compact:hover .thumb { border-radius: 8px; }
.card.compact .thumb::before { border-width: 9px 0 9px 15px; }
.card.compact .dur { right: 4px; bottom: 4px; }
.card.compact .thumb.part .dur { bottom: 7px; }
.card.compact .info { padding: 0 4px 0 0; }
.card.compact h3 { font-size: 14px; line-height: 20px; }
.card.compact .meta { font-size: 12px; line-height: 18px; }

@media (max-width: 1000px) {
  #watch { grid-template-columns: minmax(0, 1fr); gap: 20px; padding: 0 0 40px; }
  .player { border-radius: 0; max-height: none; }
  .details, #next { padding-left: 16px; padding-right: 16px; }
}
@media (max-width: 1000px) and (orientation: portrait) {
  .player { position: sticky; top: var(--top); z-index: 4; }
}
@media (max-width: 1000px) and (orientation: landscape) and (max-height: 520px) {
  .player { aspect-ratio: auto; height: calc(100vh - var(--top)); }
}
@media (max-width: 700px) {
  #top { padding: 0 8px; gap: 8px; }
  .icon.labelled { padding: 0 8px; }
  .icon.labelled span { display: none; }
  #home { padding: 0 0 40px; }
  #chips, .toolbar { padding-left: 12px; padding-right: 12px; }
  .grid { grid-template-columns: minmax(0, 1fr); gap: 24px; }
  .grid .thumb, .grid .card:hover .thumb { border-radius: 0; }
  .grid .info { padding: 12px 12px 0; }
  #search-form button { width: 48px; }
}
@media (max-width: 480px) {
  .brand span { display: none; }
  .card.compact { grid-template-columns: 44% minmax(0, 1fr); }
}
