/* Layout: a dark catalog-style top bar spanning the width, a warm sand page beneath it, a sticky
   filter rail, and a grid of rounded cards led by a 2:3 poster tile (or an earth-tone initials
   tile when there is no poster). Blue carries links and primary actions; earth tones carry status. */
:root {
  --bg: #EFE9DF;
  --surface: #FFFCF7;
  --surface-2: #E6DED1;
  --fg: #22262B;
  --muted: #6B6F6A;
  --line: #DCD3C4;
  --bar: #1C2B3A;
  --bar-fg: #F3EEE6;
  --bar-muted: #A9B4BF;
  --accent: #1E7BE8;
  --accent-ink: #FFFFFF;
  --accent-soft: #DCEBFD;
  --want: #B8862B;      --want-soft: #F5E7C8;
  --watching: #BE5A3A;  --watching-soft: #F7DCD1;
  --done: #6E7F3C;      --done-soft: #E2E8CC;
  --star: #D89B2B;
  --danger: #B3261E;
  --tile-a: #C96A45;    --tile-b: #B8862B;   /* initials tile gradient */
  --shadow: 0 1px 2px rgba(34,38,43,.05), 0 8px 20px rgba(34,38,43,.06);
  --radius: 12px;
  --display: "Plus Jakarta Sans", "Segoe UI", Helvetica, Arial, sans-serif;
  --body: "Figtree", "Segoe UI", Helvetica, Arial, sans-serif;
  --mono: "IBM Plex Mono", "SFMono-Regular", Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #151A20; --surface: #1E252E; --surface-2: #2A323C; --fg: #EDE6DA; --muted: #A39D93; --line: #343D48;
    --bar: #0F161E; --bar-fg: #EDE6DA; --bar-muted: #8A96A3;
    --accent: #5AA2F5; --accent-ink: #0B1520; --accent-soft: #1B3350;
    --want: #D9A94A; --want-soft: #3A2E14; --watching: #E07A58; --watching-soft: #3D241A; --done: #9DB05C; --done-soft: #2A3318;
    --star: #F0B445; --danger: #F2B8B5; --tile-a: #A65237; --tile-b: #8E6A1E;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 10px 26px rgba(0,0,0,.35);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #151A20; --surface: #1E252E; --surface-2: #2A323C; --fg: #EDE6DA; --muted: #A39D93; --line: #343D48;
  --bar: #0F161E; --bar-fg: #EDE6DA; --bar-muted: #8A96A3;
  --accent: #5AA2F5; --accent-ink: #0B1520; --accent-soft: #1B3350;
  --want: #D9A94A; --want-soft: #3A2E14; --watching: #E07A58; --watching-soft: #3D241A; --done: #9DB05C; --done-soft: #2A3318;
  --star: #F0B445; --danger: #F2B8B5; --tile-a: #A65237; --tile-b: #8E6A1E;
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 10px 26px rgba(0,0,0,.35);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--fg); font-family: var(--body); font-size: 15px; line-height: 1.5; -webkit-font-smoothing: antialiased; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }
button { font: inherit; }
h1, h2, h3 { font-family: var(--display); letter-spacing: -0.01em; }

/* Top bar */
.bar { background: var(--bar); color: var(--bar-fg); position: sticky; top: 0; z-index: 8; }
.bar-in {
  max-width: 1180px; margin: 0 auto; height: 56px; display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px));
}
.brand { display: inline-flex; align-items: center; gap: 10px; color: var(--bar-fg); font-family: var(--display); font-weight: 800; font-size: 19px; letter-spacing: -0.01em; }
.brand:hover { text-decoration: none; }
.brand-mark { width: 26px; height: 26px; border-radius: 7px; background: var(--accent); position: relative; flex: none; }
.brand-mark::after { content: ""; position: absolute; left: 10px; top: 7px; border-left: 10px solid #fff; border-top: 6px solid transparent; border-bottom: 6px solid transparent; }
.bar-right { display: flex; align-items: center; gap: 8px; }
.bbtn { height: 34px; padding: 0 12px; border-radius: 8px; border: 1px solid rgba(255,255,255,.18); background: rgba(255,255,255,.08); color: var(--bar-fg); font-size: 13.5px; font-weight: 600; cursor: pointer; }
.bbtn:hover { background: rgba(255,255,255,.14); }
.bbtn.ghost { background: transparent; }
.bbtn .role { color: var(--bar-muted); font-weight: 500; font-size: 12px; text-transform: capitalize; }

.wrap {
  max-width: 1180px; margin: 0 auto;
  padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px));
  padding-block: 24px 48px;
}

/* Masthead */
.mast { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 12px 24px; margin-bottom: 18px; }
.mast h1 { font-weight: 800; font-size: clamp(28px, 4.5vw, 40px); line-height: 1.05; margin: 0; text-wrap: balance; }
.mast .sub { color: var(--muted); font-size: 14px; margin: 6px 0 0; }
.mast .sub b { color: var(--fg); font-weight: 600; }
.mine { font-family: var(--mono); font-size: 12.5px; color: var(--muted); display: flex; gap: 14px; flex-wrap: wrap; }
.mine span { display: inline-flex; align-items: center; gap: 6px; }
.mine i { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.mine .q i { background: var(--want); }
.mine .w i { background: var(--watching); }
.mine .d i { background: var(--done); }

/* Filter rail */
.rail {
  position: sticky; top: 56px; z-index: 5; background: var(--bg); padding-block: 10px; margin-bottom: 18px;
  border-bottom: 1px solid var(--line); display: flex; flex-wrap: wrap; gap: 10px 12px; align-items: center;
}
.rail input[type="search"] { flex: 1 1 220px; min-width: 0; height: 38px; padding: 0 14px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); color: var(--fg); font: inherit; font-size: 14px; }
.rail select { height: 38px; padding: 0 10px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); color: var(--fg); font: inherit; font-size: 14px; max-width: 100%; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { height: 32px; padding: 0 12px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); color: var(--muted); font-size: 13px; font-weight: 600; cursor: pointer; }
.chip:hover { color: var(--fg); }
.chip[aria-pressed="true"] { background: var(--fg); color: var(--bg); border-color: var(--fg); }
.rail-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.btn { height: 38px; padding: 0 16px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); color: var(--fg); font-size: 13.5px; font-weight: 700; cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: var(--fg); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.07); }
.btn.danger { border-color: var(--danger); color: var(--danger); background: transparent; }
.btn.danger:hover { background: var(--danger); color: #fff; }
.btn:disabled { opacity: .5; cursor: default; }
.link-btn { background: none; border: 0; padding: 0; color: var(--accent); font-size: 13px; font-weight: 600; cursor: pointer; }
.link-btn:hover { text-decoration: underline; }
.count { font-family: var(--mono); font-size: 12.5px; color: var(--muted); margin-left: auto; }
.menu { position: relative; display: inline-block; }
.menu-list { position: absolute; right: 0; top: calc(100% + 6px); background: var(--surface); color: var(--fg); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow); min-width: 190px; z-index: 9; display: flex; flex-direction: column; overflow: hidden; }
.menu-list a, .menu-list button { display: block; width: 100%; text-align: left; padding: 10px 14px; border: 0; background: none; color: var(--fg); font-size: 13.5px; cursor: pointer; }
.menu-list a:hover, .menu-list button:hover { background: var(--surface-2); text-decoration: none; }

/* Cards */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 16px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; display: flex; flex-direction: column; gap: 10px; min-width: 0; position: relative; }
.top { display: flex; justify-content: space-between; align-items: center; gap: 8px; min-height: 24px; }
.kind { font-family: var(--mono); font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.kind b { color: var(--fg); font-weight: 500; }
.tools { font-family: var(--mono); font-size: 11px; color: var(--muted); display: flex; gap: 8px; align-items: center; }
.pill { font-size: 11.5px; font-weight: 700; padding: 3px 9px; border-radius: 999px; display: inline-flex; align-items: center; gap: 5px; }
.pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.pill.want { color: var(--want); background: var(--want-soft); }
.pill.watching { color: var(--watching); background: var(--watching-soft); }
.pill.done { color: var(--done); background: var(--done-soft); }

.head { display: grid; grid-template-columns: 86px 1fr; gap: 14px; align-items: start; }
.poster, .tile { width: 86px; aspect-ratio: 2 / 3; border-radius: 8px; display: block; flex: none; }
.poster { object-fit: cover; border: 1px solid var(--line); background: var(--surface-2); }
.tile { background: linear-gradient(160deg, var(--tile-a), var(--tile-b)); color: #FFF8EE; font-family: var(--display); font-weight: 800; font-size: 26px; letter-spacing: .02em; display: flex; align-items: center; justify-content: center; text-shadow: 0 1px 2px rgba(0,0,0,.2); }
.head-text { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.card h2 { font-weight: 800; font-size: 20px; line-height: 1.15; margin: 0; text-wrap: balance; }
.orig { color: var(--muted); font-size: 13px; margin: -4px 0 0; }
.meta { font-family: var(--mono); font-size: 12.5px; color: var(--muted); display: flex; flex-wrap: wrap; gap: 4px 0; }
.meta span + span::before { content: "·"; margin: 0 7px; }
.plat { align-self: flex-start; font-size: 12px; font-weight: 700; padding: 3px 9px; border-radius: 999px; background: var(--surface-2); color: var(--fg); }
.plat.netflix { background: var(--accent-soft); color: var(--accent); }
.syn { margin: 0; font-size: 14px; line-height: 1.5; }
.note { margin: 0; font-size: 12.5px; color: var(--muted); border-top: 1px dashed var(--line); padding-top: 8px; }
.tags { display: flex; flex-wrap: wrap; gap: 6px; }
.tag { font-size: 12px; padding: 3px 9px; border-radius: 999px; border: 1px solid var(--line); color: var(--muted); }
.tag b { color: var(--fg); font-weight: 600; }
.tag.party { border-color: var(--watching); color: var(--watching); font-weight: 600; }
.tag.party::before { content: "▶ "; font-size: 10px; }
.links { display: flex; gap: 14px; flex-wrap: wrap; font-size: 13.5px; font-weight: 700; }
.links a::after { content: " ↗"; font-weight: 400; opacity: .7; }

/* Group ratings */
.group { border-top: 1px solid var(--line); padding-top: 10px; display: flex; flex-direction: column; gap: 6px; }
.avg { display: flex; align-items: baseline; gap: 8px; font-family: var(--mono); font-size: 12.5px; color: var(--muted); }
.avg b { font-family: var(--display); font-size: 20px; font-weight: 800; color: var(--fg); }
.avg .s { color: var(--star); letter-spacing: 1px; }
.friends { display: flex; flex-wrap: wrap; gap: 5px; }
.friend { font-size: 12px; padding: 2px 8px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface-2); color: var(--muted); display: inline-flex; gap: 5px; align-items: center; }
.friend b { color: var(--fg); font-weight: 600; }
.friend .s { color: var(--star); }
.friend.want { border-color: var(--want); }
.friend.watching { border-color: var(--watching); }
.friend.done { border-color: var(--done); }
.friend.is-me { background: var(--surface); border-style: dashed; }
.cmts { list-style: none; margin: 2px 0 0; padding: 0; display: flex; flex-direction: column; gap: 3px; font-size: 13px; color: var(--muted); }
.cmts b { color: var(--fg); font-weight: 600; }
.cmts li::before { content: "“"; color: var(--line); }
.cmts li::after { content: "”"; color: var(--line); }

/* My controls */
.note-in { font: inherit; font-size: 13px; color: var(--fg); background: var(--bg); border: 1px dashed var(--line); border-radius: 8px; padding: 7px 10px; min-width: 0; }
.note-in:focus { border-style: solid; }
.note-in:disabled { opacity: .6; }
.stars { display: flex; align-items: center; gap: 2px; }
.stars button { width: 28px; height: 28px; border: 0; background: none; color: var(--line); font-size: 21px; line-height: 1; cursor: pointer; padding: 0; }
.stars button.on, .stars:hover button.hover { color: var(--star); }
.stars .lbl { font-family: var(--mono); font-size: 11.5px; color: var(--muted); margin-left: 6px; }
.stars.off button { cursor: default; }
.status { display: grid; grid-template-columns: repeat(3, 1fr); margin-top: auto; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.status button { height: 34px; border: 0; background: transparent; color: var(--muted); font-size: 12.5px; font-weight: 600; cursor: pointer; border-right: 1px solid var(--line); }
.status button:last-child { border-right: 0; }
.status button:hover { color: var(--fg); background: var(--surface-2); }
.status button:disabled { cursor: default; color: var(--muted); background: transparent; }
.status button[aria-pressed="true"][data-s="want"] { background: var(--want-soft); color: var(--want); }
.status button[aria-pressed="true"][data-s="watching"] { background: var(--watching-soft); color: var(--watching); }
.status button[aria-pressed="true"][data-s="done"] { background: var(--done-soft); color: var(--done); }

/* Reorder tools (editing on, list order) */
.handle { cursor: grab; color: var(--muted); font-size: 15px; user-select: none; }
.mv { border: 1px solid var(--line); border-radius: 6px; background: var(--surface); color: var(--muted); width: 24px; height: 22px; line-height: 1; cursor: pointer; padding: 0; font-size: 13px; }
.mv:hover { color: var(--fg); border-color: var(--fg); }
.card[draggable="true"] { cursor: grab; }
.card.dragging { opacity: .45; }
.card.over { outline: 2px dashed var(--accent); outline-offset: 2px; }

.empty { color: var(--muted); padding: 40px 0; text-align: center; grid-column: 1 / -1; }
.foot { margin-top: 28px; color: var(--muted); font-size: 12.5px; max-width: 70ch; }
.offscreen { position: fixed; left: -9999px; top: 0; }
.toast { position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%); background: var(--fg); color: var(--bg); padding: 9px 16px; border-radius: 10px; font-size: 13px; font-weight: 600; z-index: 20; opacity: 0; transition: opacity .2s; pointer-events: none; max-width: calc(100% - 32px); }
.toast.show { opacity: 1; }

/* TMDB search inside the add/edit dialog */
.tmdb-box { display: flex; flex-direction: column; gap: 8px; padding: 10px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); }
.tmdb-row { display: flex; gap: 8px; }
.tmdb-row input { flex: 1; min-width: 0; font: inherit; font-size: 14px; color: var(--fg); background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; }
.tmdb-results { display: flex; flex-direction: column; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: var(--surface); max-height: 260px; overflow-y: auto; }
.tmdb-hit { display: grid; grid-template-columns: 40px 1fr; gap: 10px; align-items: center; padding: 8px 10px; border: 0; border-bottom: 1px solid var(--line); background: none; color: var(--fg); text-align: left; cursor: pointer; font: inherit; }
.tmdb-hit:last-child { border-bottom: 0; }
.tmdb-hit:hover { background: var(--surface-2); }
.tmdb-hit img, .tmdb-hit .mini { width: 40px; height: 60px; border-radius: 4px; object-fit: cover; background: var(--surface-2); display: block; }
.tmdb-hit b { font-weight: 700; }
.tmdb-hit .m { font-family: var(--mono); font-size: 11.5px; color: var(--muted); }
.tmdb-hit .o { font-size: 12.5px; color: var(--muted); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.credit { font-size: 11.5px; margin-top: 8px; }

/* Sign-in gate */
.gate { display: flex; justify-content: center; padding-block: 24px; }
.gate-card { width: min(420px, 100%); background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 24px; display: flex; flex-direction: column; gap: 12px; }
.gate h1 { margin: 0; font-size: 26px; }

/* Dialogs & forms */
.dlg { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); color: var(--fg); padding: 0; box-shadow: var(--shadow); width: min(440px, calc(100% - 32px)); }
.dlg.wide { width: min(700px, calc(100% - 32px)); }
.dlg::backdrop { background: rgba(20, 24, 30, .55); }
.dlg-body { padding: 22px; display: flex; flex-direction: column; gap: 12px; }
.dlg h2 { font-weight: 800; font-size: 22px; margin: 0; }
.dlg h3 { font-size: 15px; margin: 6px 0 0; }
.hint { margin: 0; color: var(--muted); font-size: 13.5px; }
.err { margin: 0; color: var(--danger); font-size: 13.5px; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.field { display: flex; flex-direction: column; gap: 4px; font-size: 12.5px; color: var(--muted); min-width: 0; }
.field span { font-weight: 600; letter-spacing: .02em; }
.field input, .field select, .field textarea { font: inherit; font-size: 14px; color: var(--fg); background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; min-width: 0; width: 100%; }
.field textarea { resize: vertical; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 12px; }
.span2 { grid-column: span 2; }
.dlg-actions { display: flex; gap: 8px; justify-content: flex-end; align-items: center; margin-top: 4px; flex-wrap: wrap; }
.grow { flex: 1; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); }
.tab { background: none; border: 0; padding: 8px 12px; font-weight: 700; color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tab[aria-selected="true"] { color: var(--fg); border-bottom-color: var(--accent); }
.people-list { display: flex; flex-direction: column; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.person { display: grid; grid-template-columns: 1fr auto auto auto; gap: 8px; align-items: center; padding: 8px 12px; border-bottom: 1px solid var(--line); font-size: 13.5px; }
.person:last-child { border-bottom: 0; }
.person b { font-weight: 700; }
.person .u { color: var(--muted); font-family: var(--mono); font-size: 12px; }
.person select { font: inherit; font-size: 13px; padding: 4px 6px; border-radius: 6px; border: 1px solid var(--line); background: var(--bg); color: var(--fg); }
.person .link-btn.danger { color: var(--danger); }

@media (prefers-reduced-motion: reduce) { .toast { transition: none; } }
@media (max-width: 600px) {
  .grid { grid-template-columns: 1fr; }
  .rail { position: static; }
  .count { margin-left: 0; width: 100%; }
  .form-grid { grid-template-columns: 1fr; }
  .span2 { grid-column: span 1; }
  .person { grid-template-columns: 1fr auto; }
  .brand span:not(.brand-mark) { font-size: 17px; }
}
