:root {
  --bg: #f6f5f2; --card: #ffffff; --text: #1d1d1b; --muted: #6b6a66; --line: #e3e1da;
  --accent: #2f6fdf; --accent-text: #ffffff; --ok-bg: #e6f3dc; --ok: #2d6a10;
  --info-bg: #e3eefc; --info: #174f9c; --warn-bg: #faefd9; --warn: #7a4a07;
  --bad-bg: #fbe6e6; --bad: #9b2727; --radius: 14px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161a; --card: #1e2127; --text: #f0efea; --muted: #a3a29d; --line: #30333a;
    --accent: #5b93f0; --accent-text: #0b1220; --ok-bg: #213316; --ok: #a9d98a;
    --info-bg: #182a45; --info: #9cc3f7; --warn-bg: #3a2a10; --warn: #f2c77a;
    --bad-bg: #3d1818; --bad: #f3a3a3;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 17px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
main { max-width: 640px; margin: 0 auto; padding: max(16px, env(safe-area-inset-top)) 16px 48px; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
h1 { font-size: 24px; margin: 8px 0 0; font-weight: 600; }
h2 { font-size: 19px; margin: 32px 0 8px; font-weight: 600; }
.hint { color: var(--muted); margin: 8px 0; }
.error { color: var(--bad); background: var(--bad-bg); padding: 10px 12px; border-radius: 10px; }
.brand { text-align: center; margin: 40px 0 12px; }
#login .hint { text-align: center; }
label { display: block; font-weight: 600; margin: 16px 0 6px; }
input {
  width: 100%; font: inherit; font-size: 18px; padding: 14px 16px; border-radius: var(--radius);
  border: 1.5px solid var(--line); background: var(--card); color: var(--text);
}
input:focus { outline: none; border-color: var(--accent); }
#q { font-size: 19px; padding: 16px 18px; margin-top: 8px; }
button { font: inherit; cursor: pointer; border: none; border-radius: var(--radius); }
.primary { background: var(--accent); color: var(--accent-text); font-weight: 600; padding: 12px 18px; min-height: 48px; }
.primary:disabled { opacity: .6; }
.big { width: 100%; margin-top: 24px; font-size: 19px; min-height: 56px; }
.link { background: none; color: var(--accent); padding: 8px; }
.top { display: flex; justify-content: space-between; align-items: center; color: var(--muted); }
.list { list-style: none; margin: 0; padding: 0; }
.item {
  display: flex; align-items: center; gap: 14px; padding: 12px; margin: 10px 0;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
}
.poster { width: 56px; height: 84px; border-radius: 8px; object-fit: cover; background: var(--line); flex-shrink: 0; }
.meta { flex: 1; min-width: 0; }
.title { font-weight: 600; overflow-wrap: anywhere; }
.sub { color: var(--muted); font-size: 15px; }
.chip { display: inline-block; font-size: 14px; font-weight: 600; padding: 6px 10px; border-radius: 999px; white-space: nowrap; }
.chip.ready { background: var(--ok-bg); color: var(--ok); }
.chip.downloading, .chip.requested { background: var(--info-bg); color: var(--info); }
.chip.searching, .chip.waiting { background: var(--warn-bg); color: var(--warn); }
.chip.declined, .chip.blocked { background: var(--bad-bg); color: var(--bad); }
.bar { height: 6px; background: var(--line); border-radius: 3px; margin-top: 8px; overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--accent); }
#toast {
  position: fixed; left: 50%; bottom: max(24px, env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 12px 18px; border-radius: 999px; font-weight: 600;
  max-width: calc(100% - 32px); text-align: center;
}

/* ---------- v1.2: details sheet, rows, seasons ---------- */
body.noscroll { overflow: hidden; }
.tappable { cursor: pointer; }
.tappable:focus-visible, .card:focus-visible, button:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.more { color: var(--accent); font-weight: 600; font-size: 15px; white-space: nowrap; }
.side { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }
.watch { color: var(--accent); font-weight: 600; font-size: 15px; text-decoration: none; white-space: nowrap; }
.small { font-size: 13px; }
.center { text-align: center; }
.pad { padding: 24px 16px; }
h3 { font-size: 17px; margin: 24px 0 6px; font-weight: 600; }

/* Horizontal poster rows */
.row { display: flex; gap: 12px; overflow-x: auto; padding: 4px 2px 10px; scroll-snap-type: x proximity;
  -webkit-overflow-scrolling: touch; scrollbar-width: thin; }
.card { position: relative; flex: 0 0 112px; display: flex; flex-direction: column; justify-content: flex-start; align-self: flex-start; scroll-snap-align: start; background: none; padding: 0; color: var(--text);
  text-align: left; border-radius: 10px; }
.card-img { width: 112px; height: 168px; border-radius: 10px; object-fit: cover; background: var(--line); display: block; }
.card-title { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
  font-size: 14px; font-weight: 600; margin-top: 6px; line-height: 1.25; }
.card-badge { position: absolute; top: 6px; right: 6px; min-width: 24px; height: 24px; border-radius: 12px;
  font-size: 14px; font-weight: 700; display: flex; align-items: center; justify-content: center; padding: 0 6px; }
.card-badge.ready { background: var(--ok-bg); color: var(--ok); }
.card-badge.requested, .card-badge.partial, .card-badge.downloading { background: var(--info-bg); color: var(--info); }
.card-badge.blocked { background: var(--bad-bg); color: var(--bad); }

/* Details sheet: full screen on phones, centred panel on wider screens */
#sheet { position: fixed; inset: 0; z-index: 10; background: rgba(0, 0, 0, .55); display: flex; justify-content: center; align-items: flex-end; }
.sheet-body { position: relative; width: 100%; max-width: 680px; height: 100%; overflow-y: auto; background: var(--bg);
  padding: 0 16px max(32px, env(safe-area-inset-bottom)); overscroll-behavior: contain; }
@media (min-width: 720px) {
  #sheet { align-items: center; padding: 24px; }
  .sheet-body { height: auto; max-height: 100%; border-radius: 18px; }
}
.close { position: sticky; top: max(10px, env(safe-area-inset-top)); float: right; z-index: 2; margin: 10px 0 -46px;
  width: 40px; height: 40px; border-radius: 20px; background: rgba(0, 0, 0, .6); color: #fff; font-size: 18px; }
.hero { margin: 0 -16px; position: relative; }
.backdrop { width: 100%; aspect-ratio: 16 / 9; object-fit: cover; display: block; background: var(--line);
  -webkit-mask-image: linear-gradient(#000 60%, transparent); mask-image: linear-gradient(#000 60%, transparent); }
.head { display: flex; gap: 14px; align-items: flex-end; padding: 0 16px; }
.backdrop + .head { margin-top: -64px; position: relative; }
.hero:not(:has(.backdrop)) .head { padding-top: 64px; }
.big-poster { width: 96px; height: 144px; box-shadow: 0 4px 16px rgba(0, 0, 0, .35); }
.head-text { flex: 1; min-width: 0; padding-bottom: 4px; }
.d-title { margin: 0 0 4px; font-size: 22px; line-height: 1.2; }
.actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin: 16px 0 4px; }
.secondary { display: inline-flex; align-items: center; min-height: 44px; padding: 10px 16px; border-radius: var(--radius);
  border: 1.5px solid var(--line); color: var(--text); text-decoration: none; font-weight: 600; background: var(--card); }
.tagline { font-style: italic; color: var(--muted); margin: 12px 0 0; }
.overview { margin: 10px 0; }
.asked { margin: 10px 0; font-weight: 600; }

/* Seasons and episodes */
.seasons .season { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); margin: 8px 0; }
.season-row { display: flex; align-items: center; gap: 12px; padding: 12px; min-height: 64px; }
.tick { width: 26px; height: 26px; flex-shrink: 0; accent-color: var(--accent); padding: 0; margin: 0; }
.tick-spacer { width: 26px; flex-shrink: 0; }
.caret { color: var(--muted); font-size: 22px; width: 14px; transition: transform .15s; }
.caret.open { transform: rotate(90deg); }
.episodes { border-top: 1px solid var(--line); padding: 4px 12px 8px 50px; }
.episode { display: flex; align-items: flex-start; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.episode:last-child { border-bottom: none; }
.episode .title { font-weight: 500; }
.ep-overview { color: var(--muted); font-size: 14px; display: -webkit-box; -webkit-line-clamp: 1; -webkit-box-orient: vertical;
  overflow: hidden; cursor: pointer; }
.ep-overview.open { -webkit-line-clamp: unset; }
button.small { background: var(--accent); color: var(--accent-text); font-weight: 600; padding: 8px 14px; min-height: 36px; font-size: 15px; }
.chip.upcoming, .chip.partial { background: var(--line); color: var(--muted); }
.chip.partial { background: var(--info-bg); color: var(--info); }
.pickbar { position: sticky; bottom: max(12px, env(safe-area-inset-bottom)); margin-top: 12px; }
.pickbar .primary { width: 100%; min-height: 52px; box-shadow: 0 6px 20px rgba(0, 0, 0, .3); }

/* Long statuses wrap instead of squeezing the title */
.item .meta { flex: 1 1 50%; }
.item > .chip, .side { max-width: 46%; }
.item > .chip, .side .chip { white-space: normal; text-align: center; line-height: 1.25; }
.season-row .chip { max-width: 45%; white-space: normal; text-align: center; line-height: 1.25; }
img.noimg { background: var(--line); }
