@font-face {
  font-family: "Fraunces";
  src: url("/fonts/fraunces-latin-wght-normal.woff2") format("woff2");
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Fraunces";
  src: url("/fonts/fraunces-latin-wght-italic.woff2") format("woff2");
  font-weight: 100 900;
  font-style: italic;
  font-display: swap;
}
@font-face {
  font-family: "Figtree";
  src: url("/fonts/figtree-latin-wght-normal.woff2") format("woff2");
  font-weight: 300 900;
  font-style: normal;
  font-display: swap;
}

:root {
  --bg: #150f1e;
  --surface: #211829;
  --surface-2: #2c2137;
  --line: #3b2d48;
  --text: #f3eef8;
  --muted: #a99bb8;
  --amber: #f4b942;
  --amber-ink: #2a1a00;
  --lav: #b9a4e8;
  --teal: #5fd0c4;
  --green: #8fbf9f;
  --coral: #ff7b6b;
  --tab-h: 62px;
  --display: "Fraunces", Georgia, "Times New Roman", serif;
  --body: "Figtree", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { background: var(--bg); }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 400 16px/1.45 var(--body);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}
body.locked { overflow: hidden; }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
img { display: block; max-width: 100%; }
h1, h2, h3, p { margin: 0; }

:focus-visible { outline: 2px solid var(--amber); outline-offset: 2px; }

/* ---------- Page frame ---------- */
.page {
  max-width: 640px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top, 0px) + 18px) 16px calc(var(--tab-h) + env(safe-area-inset-bottom, 0px) + 28px);
}
.page.bare { padding-bottom: 40px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.page-head h1 {
  font: 600 34px/1.05 var(--display);
  letter-spacing: -0.015em;
}
.sub { color: var(--muted); font-size: 14px; }

/* ---------- Controls ---------- */
.search-box { position: relative; margin-bottom: 12px; }
.search-box svg { position: absolute; left: 14px; top: 50%; translate: 0 -50%; width: 20px; height: 20px; color: var(--muted); pointer-events: none; }
.search-box input {
  width: 100%; min-height: 50px; padding: 0 44px 0 44px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px; outline: none;
}
.search-box input::placeholder { color: var(--muted); }
.search-box input:focus { border-color: var(--amber); }
.search-box .clear {
  position: absolute; right: 4px; top: 50%; translate: 0 -50%; width: 44px; height: 44px;
  background: none; border: 0; color: var(--muted); font-size: 22px; line-height: 1;
}

.seg {
  display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 4px;
  padding: 4px; background: var(--surface); border-radius: 12px; margin-bottom: 12px;
}
.seg button {
  position: relative; min-height: 40px; border: 0; border-radius: 9px; background: none; color: var(--muted); font-weight: 600;
}
.seg button[aria-pressed="true"] { background: var(--amber); color: var(--amber-ink); }
.seg .dot { position: absolute; top: 7px; right: 10px; width: 8px; height: 8px; border-radius: 50%; background: var(--coral); }

.pills { display: flex; gap: 8px; overflow-x: auto; margin: 0 -16px 16px; padding: 0 16px 2px; scrollbar-width: none; }
.pills::-webkit-scrollbar { display: none; }
.pill {
  flex: none; min-height: 38px; padding: 0 16px; border-radius: 999px;
  background: none; border: 1px solid var(--line); color: var(--muted); font-weight: 600;
}
.pill[aria-pressed="true"] { border-color: var(--amber); color: var(--amber); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 46px; padding: 0 20px; border-radius: 12px; border: 1px solid transparent;
  background: var(--amber); color: var(--amber-ink); font-weight: 700;
}
.btn.block { width: 100%; }
.btn.ghost { background: none; border-color: var(--line); color: var(--text); }
.btn.quiet { background: none; color: var(--muted); font-weight: 600; }
.btn.danger { background: none; color: var(--coral); font-weight: 600; }
.btn.small { min-height: 38px; padding: 0 14px; font-size: 14px; border-radius: 10px; }
.btn[disabled] { opacity: 0.5; cursor: default; }

/* ---------- Poster grid (search) ---------- */
.grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px 10px; }
@media (min-width: 520px) { .grid { grid-template-columns: repeat(4, 1fr); } }
.tile { display: block; padding: 0; border: 0; background: none; text-align: left; min-width: 0; }
.poster {
  position: relative; aspect-ratio: 2 / 3; border-radius: 8px; overflow: hidden;
  background: var(--surface-2);
}
.poster img { width: 100%; height: 100%; object-fit: cover; }
.poster .noimg {
  display: grid; place-items: center; height: 100%; padding: 8px; text-align: center;
  font: italic 500 14px/1.2 var(--display); color: var(--muted);
}
.tile .flag {
  position: absolute; left: 6px; bottom: 6px; padding: 2px 8px; border-radius: 999px;
  font-size: 12px; font-weight: 700; background: var(--bg); color: var(--lav);
}
.flag.watching { color: var(--teal); }
.flag.watched { color: var(--green); }
.tile .t {
  margin-top: 8px; font-size: 14px; font-weight: 600; line-height: 1.25;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.tile .y { font-size: 13px; color: var(--muted); }

.more { display: flex; justify-content: center; margin-top: 22px; }

/* ---------- Queue rows with a ticket stub ---------- */
.group-title { font: 600 20px/1.2 var(--display); margin: 22px 0 10px; }
.group-title:first-child { margin-top: 4px; }
.rows { display: grid; gap: 12px; }
.row {
  position: relative; overflow: hidden; display: grid; grid-template-columns: 72px 1fr 68px; gap: 12px;
  padding: 12px 0 12px 12px; background: var(--surface); border-radius: 14px;
}
.row .poster { width: 72px; }
.row .main {
  display: flex; flex-direction: column; align-items: flex-start; gap: 4px; min-width: 0;
  padding: 0; border: 0; background: none; text-align: left;
}
.row .name {
  font: 600 18px/1.2 var(--display);
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.row .line { font-size: 14px; color: var(--muted); }
.row .actions { margin-top: auto; padding-top: 6px; }
.stub {
  position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  border-left: 2px dashed var(--line); text-align: center; padding: 0 6px;
}
.stub::before, .stub::after {
  content: ""; position: absolute; left: -7px; width: 16px; height: 16px; border-radius: 50%; background: var(--bg);
}
.stub::before { top: -20px; }
.stub::after { bottom: -20px; }
.stub .mon { font-size: 13px; font-weight: 600; color: var(--amber); }
.stub .day { font: 600 30px/1 var(--display); }
.stub .sub2 { font-size: 12px; color: var(--muted); font-weight: 600; margin-top: 2px; }
.stub .word { font: italic 500 16px/1.15 var(--display); color: var(--muted); }
.stub svg { width: 24px; height: 24px; color: var(--green); }

.chip {
  display: inline-flex; align-items: center; min-height: 22px; padding: 0 9px; border-radius: 999px;
  font-size: 12px; font-weight: 700; background: var(--surface-2); color: var(--lav);
}
.chip.watching { color: var(--teal); }
.chip.watched { color: var(--green); }
.chip.new { background: var(--coral); color: #2b0a06; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }

.empty { text-align: center; padding: 56px 20px; }
.empty h2 { font: 600 24px/1.2 var(--display); margin-bottom: 8px; }
.empty p { color: var(--muted); margin-bottom: 20px; }
.err { color: var(--coral); text-align: center; padding: 24px 0; }
.skeleton .poster { animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.55; } }

/* ---------- Tab bar ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  background: rgba(21, 15, 30, 0.92); -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
  border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom, 0px);
}
.tabbar .inner { max-width: 640px; margin: 0 auto; display: grid; grid-template-columns: repeat(4, 1fr); }
.tab {
  position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  height: var(--tab-h); background: none; border: 0; color: var(--muted); font-size: 12px; font-weight: 600;
}
.tab svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tab[aria-current="page"] { color: var(--amber); }
.tab .badge {
  position: absolute; top: 8px; left: calc(50% + 6px); min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px;
  background: var(--coral); color: #2b0a06; font-size: 11px; font-weight: 800; display: grid; place-items: center;
}

/* ---------- Detail sheet ---------- */
.scrim {
  position: fixed; inset: 0; z-index: 30; background: rgba(10, 6, 16, 0.62);
  opacity: 0; transition: opacity 0.22s ease;
}
.scrim.open { opacity: 1; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 31; max-width: 600px; margin: 0 auto;
  max-height: 90dvh; overflow-y: auto; overscroll-behavior: contain;
  background: var(--surface); border-radius: 24px 24px 0 0;
  padding: 10px 18px calc(env(safe-area-inset-bottom, 0px) + 22px);
  transform: translateY(100%); transition: transform 0.26s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.sheet.open { transform: none; }
.grab { width: 40px; height: 4px; border-radius: 2px; background: var(--line); margin: 0 auto 14px; }
.d-top { display: grid; grid-template-columns: 104px 1fr; gap: 16px; }
.d-top .poster { width: 104px; }
.d-title { font: 600 26px/1.1 var(--display); letter-spacing: -0.01em; }
.d-facts { display: grid; gap: 3px; margin-top: 8px; color: var(--muted); font-size: 14px; }
.d-next { margin-top: 12px; padding: 10px 12px; border-radius: 10px; background: var(--surface-2); font-size: 14px; }
.d-next strong { color: var(--amber); }
.tagline { font: italic 400 16px/1.3 var(--display); color: var(--muted); margin-top: 14px; }
.overview { margin-top: 12px; }
.d-actions { display: grid; gap: 10px; margin-top: 18px; }
.d-section { font: 600 19px/1.2 var(--display); margin: 22px 0 8px; }
/* Release / watched dates */
.dates { display: grid; gap: 6px; margin-top: 16px; font-size: 15px; }
.drow { display: grid; grid-template-columns: 116px 1fr; gap: 10px; align-items: center; min-height: 32px; }
.dk { color: var(--muted); }
.dv { font-weight: 600; }
.dcell { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; font-weight: 600; }
.dcell input[type="date"] {
  min-height: 40px; padding: 0 10px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; color: var(--text); color-scheme: dark;
}
.linkish { padding: 6px 4px; border: 0; background: none; color: var(--amber); font-weight: 600; font-size: 14px; }

/* Seasons and episodes */
.seasons { display: grid; }
.season { border-top: 1px solid var(--line); }
.season-head {
  display: flex; align-items: center; gap: 8px; width: 100%; min-height: 54px; padding: 8px 0;
  border: 0; background: none; text-align: left;
}
.season-head .sname { flex: 1; min-width: 0; font: 600 17px/1.2 var(--display); }
.season-head .smeta { flex: none; color: var(--muted); font-size: 14px; text-align: right; }
.chev { display: flex; width: 22px; height: 22px; color: var(--muted); transition: rotate 0.18s ease; }
.chev svg { width: 22px; height: 22px; }
.season.open .chev { rotate: 90deg; }
.season-body { padding: 0 0 12px; }
.season-actions { margin: 2px 0 8px; }
.ep { display: flex; align-items: flex-start; gap: 4px; padding: 4px 0; }
.ep-body { flex: 1; min-width: 0; padding: 9px 0 6px; }
.ep-title { font-weight: 600; line-height: 1.25; }
.ep-sub { font-size: 13px; color: var(--muted); margin-top: 1px; }
.ep-sub.got { color: var(--green); }
.ep.future .ep-title { color: var(--muted); font-weight: 500; }
.tick { position: relative; flex: none; width: 44px; height: 44px; padding: 0; border: 0; background: none; color: transparent; }
.tick::before { content: ""; position: absolute; inset: 8px; border-radius: 50%; border: 2px solid var(--muted); }
.tick svg { position: absolute; inset: 12px; width: 20px; height: 20px; }
.tick[aria-pressed="true"] { color: var(--amber-ink); }
.tick[aria-pressed="true"]::before { background: var(--amber); border-color: var(--amber); }
.tick[disabled] { opacity: 0.35; cursor: default; }

/* Confirm dialog */
.dlg-scrim { z-index: 60; }
.dialog {
  position: fixed; z-index: 61; left: 50%; top: 50%; translate: -50% -50%; width: min(90vw, 360px);
  padding: 22px 20px 20px; background: var(--surface-2); border-radius: 18px; box-shadow: 0 24px 64px rgba(0, 0, 0, 0.55); outline: none;
}
.dialog h2 { font: 600 22px/1.2 var(--display); margin-bottom: 8px; }
.dialog p { color: var(--muted); margin-bottom: 20px; }
.dlg-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.btn.warn { background: var(--coral); color: #2b0a06; }

/* ---------- Forms / account ---------- */
.card { background: var(--surface); border-radius: 14px; padding: 16px; margin-bottom: 16px; }
.card h2 { font: 600 20px/1.2 var(--display); margin-bottom: 12px; }
.field { display: grid; gap: 6px; margin-bottom: 12px; }
.field label { font-size: 14px; font-weight: 600; color: var(--muted); }
.field input {
  min-height: 48px; padding: 0 14px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 12px; outline: none;
}
.field input:focus { border-color: var(--amber); }
.field .hint { font-size: 13px; color: var(--muted); }
.check { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; min-height: 44px; }
.check input { width: 20px; height: 20px; accent-color: var(--amber); }
.form-err { color: var(--coral); font-size: 14px; margin: -4px 0 12px; }
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 16px; }
.stat { background: var(--surface); border-radius: 14px; padding: 14px; }
.stat b { display: block; font: 600 34px/1 var(--display); }
.stat span { font-size: 14px; color: var(--muted); }
.bars { display: grid; grid-template-columns: repeat(6, 1fr); gap: 10px; align-items: end; height: 120px; margin-top: 4px; }
.bar { display: flex; flex-direction: column; justify-content: flex-end; height: 100%; }
.bar .stack { display: flex; flex-direction: column; justify-content: flex-end; border-radius: 6px; overflow: hidden; min-height: 3px; background: var(--surface-2); }
.bar .m { background: var(--lav); }
.bar .t { background: var(--teal); }
.bar-labels { display: grid; grid-template-columns: repeat(6, 1fr); gap: 10px; text-align: center; font-size: 12px; color: var(--muted); margin-top: 6px; }
.legend { display: flex; gap: 16px; margin-top: 12px; font-size: 13px; color: var(--muted); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; }
.users { display: grid; }
.user { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 12px 0; border-top: 1px solid var(--line); }
.user:first-child { border-top: 0; padding-top: 0; }
.user .who { min-width: 0; }
.user .who b { display: block; overflow: hidden; text-overflow: ellipsis; }
.user .who span { font-size: 13px; color: var(--muted); }
.user .btns { display: flex; gap: 6px; flex: none; }
.credit { font-size: 12px; color: var(--muted); text-align: center; margin: 22px 8px 0; }

/* ---------- Login ---------- */
.login { min-height: 100dvh; display: grid; align-content: center; max-width: 380px; margin: 0 auto; padding: 24px 20px; }
.wordmark { font: 600 64px/1 var(--display); letter-spacing: -0.03em; margin-bottom: 6px; }
.wordmark i { font-style: italic; color: var(--amber); font-weight: 500; }
.login p.sub { margin-bottom: 28px; }

/* ---------- Toast ---------- */
#toast {
  position: fixed; left: 50%; bottom: calc(var(--tab-h) + env(safe-area-inset-bottom, 0px) + 16px); z-index: 50;
  translate: -50% 0; max-width: min(90vw, 420px); padding: 11px 16px; border-radius: 12px;
  background: var(--text); color: var(--bg); font-weight: 600; font-size: 14px;
  opacity: 0; pointer-events: none; transition: opacity 0.2s ease;
}
#toast.show { opacity: 1; }

@media (min-width: 700px) {
  .sheet { bottom: 5dvh; border-radius: 24px; }
}
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

/* ---------- Additions ---------- */
.linkbtn { display: block; padding: 0; margin: 0; border: 0; background: none; color: inherit; text-align: left; min-width: 0; }
.row > .linkbtn { width: 72px; align-self: start; }
.tab .ico { display: flex; }
.seg button[disabled] { opacity: 0.4; cursor: default; }
.login .page-head { display: block; }
[hidden] { display: none !important; }
