:root {
  --bg: #0b0d12;
  --bg-raised: #151821;
  --bg-hover: #1e2230;
  --line: #262b3a;
  --text: #eef0f5;
  --text-dim: #a2a8b8;
  --text-faint: #6b7183;
  --accent: #ff6a3d;
  --accent-text: #1a0b05;
  --ok: #46c46e;
  --bad: #ff5f5f;
  --radius: 10px;
  --gutter: clamp(16px, 4vw, 56px);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 var(--font);
  min-height: 100vh;
  overflow-x: hidden;
}
a { color: inherit; text-decoration: none; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
img { display: block; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
code { font-size: 0.9em; background: var(--bg-raised); padding: 2px 6px; border-radius: 4px; word-break: break-all; }
.muted { color: var(--text-dim); }
.pad { padding: 0 var(--gutter); }
.grow { flex: 1; }
.ok { color: var(--ok); }
.bad { color: var(--bad); }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 6px; }

/* ---------- header ---------- */
#topbar {
  position: fixed; inset: 0 0 auto 0; z-index: 20;
  display: flex; align-items: center; gap: clamp(12px, 3vw, 32px);
  padding: 12px var(--gutter);
  padding-top: max(12px, env(safe-area-inset-top));
  background: linear-gradient(to bottom, rgba(11, 13, 18, 0.95), rgba(11, 13, 18, 0.6) 70%, transparent);
  backdrop-filter: blur(6px);
}
#topbar[hidden], body.playing #topbar { display: none; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 18px; white-space: nowrap; }
.brand img { width: 30px; height: 30px; }
#topbar nav { display: flex; gap: 4px; }
#topbar nav a { padding: 6px 12px; border-radius: 8px; color: var(--text-dim); font-weight: 500; white-space: nowrap; }
#topbar nav a:hover { color: var(--text); }
#topbar nav a.on { color: var(--text); background: rgba(255, 255, 255, 0.08); }
.search {
  margin-left: auto; display: flex; align-items: center; gap: 8px;
  background: rgba(255, 255, 255, 0.07); border: 1px solid transparent; border-radius: 999px;
  padding: 6px 14px; width: min(280px, 30vw);
}
.search:focus-within { border-color: var(--line); background: rgba(255, 255, 255, 0.1); }
.search svg { width: 18px; height: 18px; color: var(--text-dim); flex: none; }
.search input { background: none; border: 0; outline: 0; width: 100%; min-width: 0; }
.avatar {
  display: inline-grid; place-items: center; flex: none;
  width: 34px; height: 34px; border-radius: 8px;
  font-weight: 700; color: #fff; text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}
.avatar.big { width: clamp(84px, 14vw, 128px); height: clamp(84px, 14vw, 128px); border-radius: 16px; font-size: clamp(36px, 6vw, 56px); }
.avatar.ghost { background: var(--bg-raised); color: var(--text-dim); border: 2px dashed var(--line); text-shadow: none; }

#view { min-height: 100vh; }
.page { padding-bottom: 64px; }
body.playing .page { padding: 0; }
.spacer-top { height: 90px; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 20px; border-radius: 8px; border: 0;
  background: rgba(255, 255, 255, 0.14); color: var(--text);
  font-weight: 600; white-space: nowrap; transition: background 0.15s;
}
.btn:hover { background: rgba(255, 255, 255, 0.22); }
.btn.primary { background: var(--accent); color: var(--accent-text); }
.btn.primary:hover { background: #ff8457; }
.btn.subtle { background: none; color: var(--text-dim); border: 1px solid var(--line); }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn svg { width: 20px; height: 20px; }
.icon-btn {
  display: inline-grid; place-items: center;
  width: 44px; height: 44px; border-radius: 50%;
  background: none; border: 0; color: var(--text);
}
.icon-btn:hover { background: rgba(255, 255, 255, 0.12); }
.icon-btn svg { width: 26px; height: 26px; }
.actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }

/* ---------- profiles ---------- */
.profiles { min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 32px; padding: 32px var(--gutter); text-align: center; }
.profiles h1 { font-size: clamp(26px, 4vw, 44px); font-weight: 600; }
.profile-grid { display: flex; flex-wrap: wrap; justify-content: center; gap: clamp(16px, 3vw, 32px); }
.profile { background: none; border: 0; display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 8px; border-radius: 16px; color: var(--text-dim); }
.profile:hover, .profile:focus-visible { color: var(--text); }
.profile:hover .avatar, .profile:focus-visible .avatar { box-shadow: 0 0 0 3px var(--text); }
.profile-name { font-size: 17px; }
.profile-remove { font-size: 13px; color: var(--bad); }
.profile-form { display: flex; flex-direction: column; gap: 16px; align-items: center; width: min(360px, 100%); }
.profile-form input { width: 100%; padding: 12px 16px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg-raised); font-size: 17px; outline: 0; }
.profile-form input:focus { border-color: var(--accent); }
.swatches { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }
.swatch { width: 32px; height: 32px; border-radius: 50%; border: 3px solid transparent; }
.swatch.on { border-color: var(--text); }
.form-actions { display: flex; gap: 10px; }

/* ---------- hero & detail headers ---------- */
.hero, .detail { position: relative; overflow: hidden; }
.hero { min-height: min(78vh, 720px); display: flex; align-items: flex-end; }
.hero-bg { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; object-position: center 20%; }
.hero-shade {
  position: absolute; inset: 0;
  background:
    linear-gradient(to top, var(--bg) 0%, rgba(11, 13, 18, 0.6) 35%, transparent 70%),
    linear-gradient(to right, rgba(11, 13, 18, 0.85) 0%, rgba(11, 13, 18, 0.2) 55%, transparent 80%);
}
.hero-body { position: relative; padding: 0 var(--gutter) 150px; max-width: 760px; display: flex; flex-direction: column; gap: 14px; }
.hero h1 { font-size: clamp(32px, 5.5vw, 64px); font-weight: 800; letter-spacing: -0.02em; text-shadow: 0 2px 20px rgba(0, 0, 0, 0.5); }
.hero .overview { font-size: clamp(15px, 1.4vw, 18px); color: #d9dce4; margin: 0; }
.meta { color: var(--text-dim); margin: 0; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.clamp { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }

.detail { min-height: min(70vh, 640px); display: flex; align-items: flex-end; }
.detail-body { position: relative; display: flex; gap: clamp(20px, 3vw, 40px); align-items: flex-end; padding: 110px var(--gutter) 40px; width: 100%; }
.detail-poster { width: clamp(130px, 18vw, 240px); flex: none; border-radius: var(--radius); overflow: hidden; box-shadow: 0 10px 40px rgba(0, 0, 0, 0.6); }
.detail-info { display: flex; flex-direction: column; gap: 14px; max-width: 760px; min-width: 0; }
.detail-info h1 { font-size: clamp(28px, 4.5vw, 52px); font-weight: 800; letter-spacing: -0.02em; }
.detail-info .overview { margin: 0; color: #d9dce4; font-size: 16px; }
.detail-info .bar { flex-basis: 100%; max-width: 360px; position: static; height: 4px; }

/* ---------- rows & cards ---------- */
.rows { position: relative; z-index: 1; display: flex; flex-direction: column; gap: 28px; }
.rows.overlap { margin-top: -110px; }
.row h2 { font-size: 19px; font-weight: 650; padding: 0 var(--gutter); margin-bottom: 10px; }
.row h2 a:hover .more { color: var(--accent); }
.more { font-size: 13px; color: var(--text-faint); font-weight: 500; margin-left: 8px; }
.row-scroll {
  display: grid; grid-auto-flow: column; justify-content: start; gap: 12px;
  overflow-x: auto; scroll-snap-type: x mandatory; scroll-padding: 0 var(--gutter);
  padding: 4px var(--gutter) 10px; scrollbar-width: none;
}
.row-scroll::-webkit-scrollbar { display: none; }
.row-scroll > .card { scroll-snap-align: start; }
.row-scroll > .poster { width: clamp(120px, 14vw, 180px); }
.row-scroll > .wide { width: clamp(220px, 24vw, 340px); }

.card { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.card .frame { position: relative; border-radius: var(--radius); overflow: hidden; transition: transform 0.18s, box-shadow 0.18s; }
.card:hover .frame, .card:focus-visible .frame { transform: scale(1.04); box-shadow: 0 8px 30px rgba(0, 0, 0, 0.5); }
.card:focus-visible { outline: none; }
.card:focus-visible .frame { outline: 3px solid var(--accent); outline-offset: 2px; }
.card-title { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-sub { font-size: 13px; color: var(--text-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: -4px; min-height: 1em; }

.art {
  position: relative; width: 100%;
  background: linear-gradient(145deg, hsl(var(--h) 45% 32%), hsl(calc(var(--h) + 40) 50% 16%));
  display: grid; place-items: center;
}
.art.tall { aspect-ratio: 2 / 3; }
.art.wide { aspect-ratio: 16 / 9; }
.art img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.art-fallback { padding: 12px; text-align: center; font-weight: 700; font-size: 15px; color: rgba(255, 255, 255, 0.85); overflow-wrap: anywhere; }

.bar { position: absolute; left: 0; right: 0; bottom: 0; height: 4px; background: rgba(255, 255, 255, 0.25); }
.bar i { display: block; height: 100%; background: var(--accent); }
.badge {
  position: absolute; top: 8px; right: 8px; min-width: 24px; height: 24px; padding: 0 6px;
  border-radius: 12px; display: grid; place-items: center;
  background: rgba(0, 0, 0, 0.7); color: #fff; font-size: 12px; font-weight: 700;
}
.badge svg { width: 14px; height: 14px; color: var(--ok); }
.badge.count { background: var(--accent); color: var(--accent-text); }
.play-hint {
  position: absolute; inset: 0; display: grid; place-items: center;
  background: rgba(0, 0, 0, 0.35); opacity: 0; transition: opacity 0.15s;
}
.play-hint svg { width: 46px; height: 46px; padding: 10px; border-radius: 50%; background: rgba(0, 0, 0, 0.55); border: 2px solid rgba(255, 255, 255, 0.85); }
.card:hover .play-hint, .card:focus-visible .play-hint, .episode-thumb:hover .play-hint, .episode-thumb:focus-visible .play-hint { opacity: 1; }

/* ---------- grid pages ---------- */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; padding: 96px var(--gutter) 20px; flex-wrap: wrap; }
.page-head h1 { font-size: clamp(26px, 3.5vw, 36px); font-weight: 750; }
.sort { display: flex; align-items: center; gap: 8px; color: var(--text-dim); font-size: 14px; }
.sort select { background: var(--bg-raised); border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(clamp(110px, 14vw, 170px), 1fr)); gap: 24px 14px; padding: 0 var(--gutter); }
.grid.wide-grid { grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
.section-title { font-size: 19px; padding: 24px var(--gutter) 12px; }

/* ---------- episodes ---------- */
.episodes { padding: 0 var(--gutter); }
.season-tabs { display: flex; gap: 6px; overflow-x: auto; padding: 4px 2px 14px; border-bottom: 1px solid var(--line); scrollbar-width: none; }
.tab { padding: 8px 16px; border-radius: 999px; border: 1px solid var(--line); background: none; color: var(--text-dim); font-weight: 600; white-space: nowrap; }
.tab:hover { color: var(--text); }
.tab.on { background: var(--text); color: var(--bg); border-color: var(--text); }
.episode-list { list-style: none; margin: 0; padding: 0; }
.episode { display: grid; grid-template-columns: clamp(140px, 22vw, 260px) 1fr auto; gap: clamp(12px, 2vw, 24px); align-items: center; padding: 16px 0; border-bottom: 1px solid var(--line); }
.episode-thumb { position: relative; border-radius: 8px; overflow: hidden; }
.episode-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.episode h3 { font-size: 16px; font-weight: 600; }
.ep-num { color: var(--text-faint); }
.episode p { margin: 6px 0 0; color: var(--text-dim); font-size: 14px; }
.episode.watched h3 { color: var(--text-dim); }
.watch-toggle { color: var(--text-faint); border: 2px solid var(--line); width: 38px; height: 38px; }
.watch-toggle svg { width: 18px; height: 18px; }
.watch-toggle.on { color: var(--ok); border-color: var(--ok); }

/* ---------- empty / settings ---------- */
.empty { min-height: 70vh; display: flex; flex-direction: column; justify-content: center; gap: 14px; padding: 110px var(--gutter) 40px; max-width: 760px; }
.empty h1 { font-size: 30px; }
.empty p { margin: 0; }
.empty .btn { align-self: flex-start; }
.errors { background: rgba(255, 95, 95, 0.08); border: 1px solid rgba(255, 95, 95, 0.3); color: #ffb3b3; border-radius: 8px; padding: 10px 14px; font-size: 13px; display: flex; flex-direction: column; gap: 4px; }
.errors summary { cursor: pointer; font-weight: 600; }
.settings { padding: 96px var(--gutter) 0; max-width: 820px; display: flex; flex-direction: column; gap: 20px; }
.settings h1 { font-size: 32px; }
.panel { background: var(--bg-raised); border: 1px solid var(--line); border-radius: 14px; padding: 20px; display: flex; flex-direction: column; gap: 12px; align-items: flex-start; }
.panel h2 { font-size: 18px; }
.panel p { margin: 0; }
.lib-list { margin: 0; padding-left: 18px; display: flex; flex-direction: column; gap: 6px; }
.steps { margin: 0; padding-left: 20px; display: flex; flex-direction: column; gap: 4px; color: var(--text-dim); }
.steps a, .panel a:not(.btn) { color: var(--accent); }
.key-form { display: flex; gap: 8px; width: 100%; flex-wrap: wrap; }
.key-form input { flex: 1; min-width: 200px; padding: 10px 14px; border-radius: 8px; border: 1px solid var(--line); background: var(--bg); font-family: ui-monospace, monospace; font-size: 13px; outline: 0; }
.key-form input:focus { border-color: var(--accent); }

.loading { display: grid; place-items: center; min-height: 60vh; }
.spin { width: 44px; height: 44px; border-radius: 50%; border: 4px solid rgba(255, 255, 255, 0.15); border-top-color: var(--accent); animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

#toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); z-index: 50;
  background: var(--bg-hover); border: 1px solid var(--line); padding: 10px 18px; border-radius: 10px;
  opacity: 0; pointer-events: none; transition: opacity 0.2s, transform 0.2s;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- player ---------- */
.player { position: fixed; inset: 0; background: #000; z-index: 30; overflow: hidden; user-select: none; -webkit-user-select: none; }
.player video { width: 100%; height: 100%; object-fit: contain; background: #000; display: block; }
.player.idle { cursor: none; }
.p-top, .p-bottom { position: absolute; left: 0; right: 0; transition: opacity 0.25s; }
.player.idle .p-top, .player.idle .p-bottom { opacity: 0; pointer-events: none; }
.p-top {
  top: 0; display: flex; align-items: center; gap: 12px;
  padding: max(14px, env(safe-area-inset-top)) var(--gutter) 40px;
  background: linear-gradient(to bottom, rgba(0, 0, 0, 0.75), transparent);
}
.p-title { display: flex; flex-direction: column; min-width: 0; }
.p-title b { font-size: 18px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.p-title span { color: var(--text-dim); font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.p-bottom {
  bottom: 0; padding: 50px var(--gutter) max(14px, env(safe-area-inset-bottom));
  background: linear-gradient(to top, rgba(0, 0, 0, 0.85), transparent);
}
.p-scrub { position: relative; height: 24px; display: flex; align-items: center; }
.p-track { position: absolute; left: 0; right: 0; height: 5px; border-radius: 3px; background: rgba(255, 255, 255, 0.2); overflow: hidden; transition: height 0.15s; }
.p-scrub:hover .p-track { height: 8px; }
.p-avail { position: absolute; top: 0; bottom: 0; left: 0; width: 0; background: rgba(255, 255, 255, 0.25); }
.p-fill { position: absolute; top: 0; bottom: 0; left: 0; width: 0; background: var(--accent); }
.p-range { position: relative; width: 100%; margin: 0; height: 24px; background: transparent; -webkit-appearance: none; appearance: none; cursor: pointer; }
.p-range::-webkit-slider-runnable-track { background: transparent; height: 24px; }
.p-range::-moz-range-track { background: transparent; }
.p-range::-webkit-slider-thumb { -webkit-appearance: none; width: 16px; height: 16px; margin-top: 4px; border-radius: 50%; background: var(--accent); border: 0; opacity: 0; transition: opacity 0.15s; }
.p-range::-moz-range-thumb { width: 16px; height: 16px; border-radius: 50%; background: var(--accent); border: 0; opacity: 0; }
.p-scrub:hover .p-range::-webkit-slider-thumb, .p-range:focus-visible::-webkit-slider-thumb { opacity: 1; }
.p-scrub:hover .p-range::-moz-range-thumb { opacity: 1; }
.p-range:focus-visible { outline: none; }
.p-tip { position: absolute; bottom: 28px; transform: translateX(-50%); background: rgba(0, 0, 0, 0.85); padding: 3px 8px; border-radius: 6px; font-size: 13px; font-variant-numeric: tabular-nums; pointer-events: none; }
.p-controls { display: flex; align-items: center; gap: 4px; margin-top: 4px; }
.p-time { font-variant-numeric: tabular-nums; color: #dfe2ea; font-size: 14px; margin-left: 10px; white-space: nowrap; }
.p-vol { display: flex; align-items: center; }
.p-volume { width: 0; opacity: 0; transition: width 0.2s, opacity 0.2s; accent-color: var(--accent); }
.p-vol:hover .p-volume, .p-volume:focus-visible { width: 90px; opacity: 1; }
.p-center { position: absolute; inset: 0; display: none; place-items: center; pointer-events: none; }
.player.loading .p-center { display: grid; }
.p-bigplay {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: 88px; height: 88px; border-radius: 50%; border: 0;
  background: rgba(0, 0, 0, 0.6); color: #fff; display: grid; place-items: center;
}
.p-bigplay svg { width: 44px; height: 44px; margin-left: 4px; }
.p-bigplay[hidden] { display: none; }
.p-menu-wrap { position: relative; }
.p-menu { position: absolute; right: 0; bottom: 52px; min-width: 240px; background: rgba(20, 22, 30, 0.97); border: 1px solid var(--line); border-radius: 10px; padding: 6px; display: flex; flex-direction: column; }
.p-menu[hidden] { display: none; }
.p-menu-title { padding: 6px 12px; font-size: 12px; color: var(--text-faint); text-transform: uppercase; letter-spacing: 0.05em; }
.p-menu button { background: none; border: 0; text-align: left; padding: 9px 12px; border-radius: 6px; }
.p-menu button:hover { background: var(--bg-hover); }
.p-menu button.on { color: var(--accent); font-weight: 600; }
.p-upnext {
  position: absolute; right: var(--gutter); bottom: 120px; z-index: 2;
  background: rgba(20, 22, 30, 0.95); border: 1px solid var(--line); border-radius: 14px;
  padding: 18px 20px; display: flex; flex-direction: column; gap: 10px; max-width: min(380px, calc(100vw - 32px));
}
.p-upnext[hidden], .p-error[hidden] { display: none; }
.upnext-label { color: var(--text-dim); font-size: 13px; }
.upnext-title { font-weight: 650; font-size: 17px; }
.p-error { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; text-align: center; padding: 24px; background: rgba(0, 0, 0, 0.7); }

/* ---------- small screens ---------- */
@media (max-width: 700px) {
  #topbar { flex-wrap: wrap; gap: 10px; }
  .brand-name { display: none; }
  #topbar nav { order: 3; width: 100%; }
  #topbar nav a { padding: 4px 10px; }
  .search { width: auto; flex: 1; }
  .spacer-top, .page-head, .settings, .empty { padding-top: 120px; }
  .page-head { padding-top: 120px; }
  .hero-body { padding-bottom: 120px; }
  .detail-body { flex-direction: column; align-items: flex-start; padding-top: 130px; }
  .detail-poster { width: 120px; }
  .episode { grid-template-columns: 130px 1fr auto; align-items: start; }
  .episode p { display: none; }
  .p-vol, .p-back10, .p-fwd10 { display: none; }
}
