:root {
  --bg: #14171c;
  --surface: #1c2027;
  --surface-2: #242a33;
  --line: #2e353f;
  --text: #e7ebf0;
  --muted: #9aa4b2;
  --accent: #4f9dff;
  --accent-ink: #06101f;
  --good: #37c871;
  --warn: #ffb020;
  --radius: 12px;
  --gap: 14px;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.5rem; margin: 0 0 1rem; }
h2 { font-size: 1.1rem; }
img { max-width: 100%; display: block; }

/* nav */
.topnav {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 6px;
  padding: 10px 8px;
  background: var(--surface); border-bottom: 1px solid var(--line);
  overflow-x: auto;
}
.topnav nav { display: flex; gap: 2px; }
.topnav nav a {
  color: var(--muted); padding: 6px 8px; border-radius: 8px; white-space: nowrap; font-size: .93rem;
}
.topnav nav a:hover { color: var(--text); text-decoration: none; background: var(--surface-2); }
.topnav nav a.on { color: var(--accent-ink); background: var(--accent); }
.topnav .settings { color: var(--muted); font-size: 1.2rem; }
.topnav .settings.on { color: var(--accent); }
.navright { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.profileswitch { position: relative; }
.profileswitch > summary { list-style: none; cursor: pointer; color: var(--muted); font-size: .9rem;
  padding: 4px 10px; border: 1px solid var(--line); border-radius: 999px; white-space: nowrap; }
.profileswitch > summary::-webkit-details-marker { display: none; }
.profileswitch[open] > summary { color: var(--text); border-color: var(--accent); }
.pmenu { position: absolute; right: 0; top: calc(100% + 6px); z-index: 30; background: var(--surface);
  border: 1px solid var(--line); border-radius: 10px; padding: 6px; min-width: 150px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .4); display: flex; flex-direction: column; gap: 4px; }
.pmenu form { margin: 0; }
.pmenu button { width: 100%; text-align: left; background: none; border: none; color: var(--text);
  padding: 7px 10px; border-radius: 7px; cursor: pointer; }
.pmenu button:hover { background: var(--surface-2); border-color: transparent; }
.pmenu button.active { color: var(--accent); font-weight: 700; }

main { max-width: 900px; margin: 0 auto; padding: 20px 12px 16px; }
html, body { overflow-x: hidden; }

/* viewer-tag filter bar */
.filterbar { display: flex; align-items: center; gap: 6px; flex-wrap: wrap;
  padding: 8px 16px; background: var(--surface); border-bottom: 1px solid var(--line); }
.filterbar form { margin: 0; display: inline-flex; }
.filterbar .sep { width: 1px; align-self: stretch; background: var(--line); margin: 2px 4px; }
.filterbar .fl, .tagedit .fl, .filtergroup .fl { color: var(--muted); font-size: .75rem;
  text-transform: uppercase; letter-spacing: .05em; margin-right: 2px; }
.chip { padding: 3px 12px; border-radius: 20px; border: 1px solid var(--line);
  color: var(--muted); font-size: .85rem; background: transparent; cursor: pointer; font-family: inherit; }
.chip:hover { text-decoration: none; border-color: var(--accent); color: var(--text); }
.chip.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }

/* tag management (settings) + editors */
.taglist { display: flex; flex-wrap: wrap; gap: 8px; }
.tagrow { display: inline-flex; align-items: center; gap: 4px; background: var(--surface-2);
  border: 1px solid var(--line); border-radius: 20px; padding: 3px 4px 3px 12px; }
.tagrow form { margin: 0; }
.tagrow button { padding: 0 6px; border: none; background: none; color: var(--muted); font-size: .9rem; }
.tagrow button:hover { color: #ff9a9a; }
.tagedit { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.addform { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }
.addform .tagpick { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }

/* viewer chips — tappable toggle pills (show page auto-saves; add form submits with Add) */
.viewerchip { cursor: pointer; user-select: none; display: inline-flex; align-items: center;
  padding: 4px 12px; border-radius: 999px; border: 1px solid var(--line);
  color: var(--muted); font-size: .82rem; transition: background .12s, border-color .12s, color .12s; }
.viewerchip input { position: absolute; opacity: 0; width: 0; height: 0; }
.viewerchip:hover { border-color: var(--accent); color: var(--text); }
.viewerchip:has(input:checked) { background: var(--accent); color: var(--accent-ink);
  border-color: var(--accent); font-weight: 600; }
.viewerchip:has(input:checked) > span::before { content: "✓ "; }

/* Available cards */
.cards { display: flex; flex-direction: column; gap: var(--gap); }
.card {
  display: grid; grid-template-columns: 64px 1fr auto; gap: 14px; align-items: center;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 12px;
}
.card .poster img, .card .poster .noposter { width: 64px; height: 96px; border-radius: 8px; object-fit: cover; }
.noposter {
  display: grid; place-items: center; background: var(--surface-2);
  color: var(--muted); font-size: 1.6rem; font-weight: 700;
}
.card .meta { min-width: 0; }
.card .meta h3 { margin: 0 0 4px; font-size: 1.05rem; color: var(--text); }
.card .meta .next { margin: 0; font-weight: 600; }
.card .meta .sub { margin: 2px 0 0; color: var(--muted); font-size: .88rem; }
.card .meta .sub strong { color: var(--warn); }

button, .btn {
  font: inherit; cursor: pointer; border: 1px solid var(--line);
  background: var(--surface-2); color: var(--text);
  padding: 9px 14px; border-radius: 10px;
}
button:hover, .btn:hover { border-color: var(--accent); }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 700; }
/* muted rounded pill (Sync now, View stats, Watch, …) */
.pill { display: inline-block; background: var(--surface-2); color: var(--text);
  border: 1px solid var(--line); border-radius: 999px; padding: 7px 15px;
  font: inherit; font-weight: 600; cursor: pointer; white-space: nowrap; }
.pill:hover { border-color: var(--accent); color: var(--accent); text-decoration: none; }
.watch-next button {
  background: rgba(79, 157, 255, 0.12); color: var(--accent);
  border: 1px solid rgba(79, 157, 255, 0.35);
  border-radius: 999px; padding: 7px 15px; font-weight: 600; white-space: nowrap;
}
.watch-next button:hover { background: rgba(79, 157, 255, 0.22); border-color: var(--accent); }
.watch-next button:disabled { opacity: .6; }

.empty { color: var(--muted); text-align: center; padding: 3rem 1rem; }

/* section headers (Continue watching / Not started) */
.grouphdr { display: flex; align-items: center; gap: 8px; margin: 22px 0 4px;
  font-size: .8rem; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.grouphdr:first-child { margin-top: 4px; }
.grouphdr span { background: var(--surface-2); border-radius: 20px; padding: 1px 8px;
  font-size: .75rem; letter-spacing: 0; }

/* Upcoming */
.datehdr {
  position: sticky; top: 54px; background: var(--bg);
  margin: 18px 0 6px; padding: 4px 0; color: var(--accent);
  border-bottom: 1px solid var(--line); font-size: .95rem;
}
.datehdr .dh-rel { color: var(--muted); font-weight: 400; }
.uprow { display: flex; gap: 12px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line); }
.upposter img, .upposter .noposter { width: 38px; height: 57px; border-radius: 6px; object-fit: cover; display: block; }
.upposter .noposter { display: grid; place-items: center; background: var(--surface-2); color: var(--muted); font-weight: 700; }
.upmeta { min-width: 0; }
.upline { display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; }
.upline a { color: var(--text); font-weight: 600; }
.scode { font-variant-numeric: tabular-nums; color: var(--muted); font-weight: 600; min-width: 58px; }
.eptitle { color: var(--muted); font-size: .85rem; }

/* Shows toolbar: search (always visible) + collapsible filter panel */
.showstoolbar { margin-bottom: 16px; }
.showstoolbar #showsearch { margin-bottom: 10px; }
details.showfilters { border: 1px solid var(--line); border-radius: 10px; padding: 2px 12px; background: var(--surface); }
details.showfilters > summary { list-style: none; cursor: pointer; color: var(--muted);
  font-size: .78rem; text-transform: uppercase; letter-spacing: .05em; padding: 8px 0; }
details.showfilters > summary::-webkit-details-marker { display: none; }
details.showfilters > summary::before { content: "▸  "; }
details.showfilters[open] > summary::before { content: "▾  "; }
.filtergroup { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; padding: 6px 0 10px; }
.filtergroup .fl { min-width: 60px; }

/* Shows grid */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 14px; }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.tile img, .tile .noposter { width: 100%; aspect-ratio: 2/3; }
.tile .cap { padding: 8px 10px; }
.tile .cap b { display: block; font-size: .92rem; }
.tile .cap small { color: var(--muted); }
.badge { display: inline-block; font-size: .7rem; padding: 1px 6px; border-radius: 6px; background: var(--surface-2); color: var(--muted); }
.badge.arch { background: #3a2e12; color: var(--warn); }

/* Show page */
.showhead { display: flex; gap: 18px; margin-bottom: 20px; flex-wrap: wrap; }
.showhead .poster img, .showhead .poster .noposter { width: 120px; aspect-ratio: 2/3; border-radius: 10px; }
img.zoomable { cursor: zoom-in; }

/* full-screen poster lightbox */
.lightbox { position: fixed; inset: 0; z-index: 100; display: flex; align-items: center;
  justify-content: center; padding: 20px; background: rgba(0,0,0,.9); cursor: zoom-out;
  animation: lb-in .12s ease; }
.lightbox img { max-width: 100%; max-height: 100%; border-radius: 8px;
  box-shadow: 0 10px 40px rgba(0,0,0,.6); }
@keyframes lb-in { from { opacity: 0; } to { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .lightbox { animation: none; } }
.showhead .info { flex: 1; min-width: 220px; }
.showhead .info h1 { margin-bottom: 4px; }
.showhead .actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.showhead .actions button, .showhead .actions .btn {
  padding: 5px 12px; font-size: .82rem; border-radius: 999px; }
.progress { color: var(--muted); }
/* collapsible season sections (native details/summary, collapsed by default) */
details.season { border-bottom: 1px solid var(--line); }
details.season > summary {
  list-style: none; cursor: pointer; display: flex; align-items: baseline; gap: 10px;
  padding: 11px 2px; font-size: 1.05rem; font-weight: 700; }
details.season > summary::-webkit-details-marker { display: none; }
details.season > summary::before { content: "▸"; color: var(--muted); font-size: .8rem; }
details.season[open] > summary::before { content: "▾"; }
details.season > summary:hover { color: var(--accent); }
.seasoncount { color: var(--muted); font-weight: 400; font-size: .85rem; }
.seasonactions { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; margin: 2px 0 12px; }
.seasonactions form { margin: 0; }
.seasonactions button { padding: 4px 11px; font-size: .78rem; border-radius: 999px; }
.specialstoggle { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-weight: 400; font-size: .8rem; }
.eplist { list-style: none; margin: 0; padding: 0; }
.eplist li { display: flex; align-items: center; gap: 10px; padding: 7px 0; border-bottom: 1px solid var(--line); }
.eplist .code { font-variant-numeric: tabular-nums; color: var(--muted); min-width: 54px; }
.eplist .et { flex: 1; }
.eplist .ea { color: var(--muted); font-size: .82rem; }
.eplist form { margin: 0; }
/* custom on-brand checkbox (episode toggles + specials toggles) — CSS only, no JS */
.chk {
  appearance: none; -webkit-appearance: none; -moz-appearance: none;
  width: 22px; height: 22px; flex: none; vertical-align: middle; cursor: pointer;
  border: 2px solid var(--line); border-radius: 6px; background: transparent;
  background-repeat: no-repeat; background-position: center; background-size: 14px;
  transition: background-color .12s ease, border-color .12s ease;
}
.chk:hover { border-color: var(--accent); }
.chk:checked {
  background-color: var(--accent); border-color: var(--accent);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2306101f' stroke-width='3.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M4 12l5 5L20 6'/%3E%3C/svg%3E");
}
.chk:disabled { opacity: .5; cursor: default; }
.chk:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.watched .et { color: var(--muted); }

/* Search */
.searchbar { display: flex; gap: 8px; margin-bottom: 18px; }
.searchbar input { flex: 1; }
input[type=text], input[type=password], input[type=search] {
  font: inherit; padding: 10px 12px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--surface); color: var(--text); width: 100%;
}
.result { display: grid; grid-template-columns: 60px 1fr auto; gap: 14px; align-items: center;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; margin-bottom: 12px; }
.result img, .result .noposter { width: 60px; height: 90px; border-radius: 8px; }
.result .ov { color: var(--muted); font-size: .85rem; margin: 4px 0 0;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

/* stats + login + settings */
.statgrid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 14px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; text-align: center; }
.stat .n { font-size: 2rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat .l { color: var(--muted); font-size: .85rem; }
.center { max-width: 340px; margin: 8vh auto; }
.err { color: #ff8080; }
.notice { background: #3a2e12; color: var(--warn); padding: 10px 14px; border-radius: 10px; margin-bottom: 16px; }

.foot { max-width: 900px; margin: 0 auto; padding: 20px 16px; color: var(--muted);
  font-size: .78rem; display: flex; flex-wrap: wrap; align-items: center;
  justify-content: space-between; gap: 12px; border-top: 1px solid var(--line); }
.foot > span { flex: 1 1 240px; min-width: 0; }
.foot a { color: var(--muted); }
.foot .logout { flex: none; border: 1px solid var(--line); border-radius: 999px;
  padding: 5px 16px; color: var(--muted); white-space: nowrap; }
.foot .logout:hover { border-color: var(--accent); color: var(--text); text-decoration: none; }

@media (max-width: 520px) {
  .card { grid-template-columns: 54px 1fr; }
  .card .poster img, .card .poster .noposter { width: 54px; height: 81px; }
  .watch-next { grid-column: 1 / -1; }
  .watch-next button { width: 100%; }
}
