/* Layout: fixed left rail of saved comparisons; workspace with search, summary, and either ranked cards or a side-by-side grid. Dark by default; the sidebar toggle switches to light. */
:root {
  --bg: #0f1116;
  --panel: #161921;
  --raise: #1e222c;
  --ink: #e8eaf0;
  --muted: #8e95a5;
  --line: #2a2f3b;
  --accent: #36c5d6;
  --accent-ink: #06181b;
  --imdb: #f5c518;
  --rt: #fa320a;
  --rt-rotten: #74a73f;
  --mc-good: #54b91f;
  --mc-mid: #f0b400;
  --mc-bad: #e5372e;
  --best: #1c3a2a;
  --best-ink: #8fe0ae;
  --danger: #ff7a6b;
  --warn-bg: #2a2410;
  --warn-line: #6b5a1c;
  --warn-ink: #f5c518;
  --display: "Bahnschrift", "DIN Alternate", "Arial Narrow", sans-serif;
  --body: "Segoe UI Variable Text", "Segoe UI", system-ui, sans-serif;
  --mono: "Cascadia Mono", Consolas, ui-monospace, monospace;
  color-scheme: dark;
}
:root[data-theme="light"] {
  --bg: #f1f2f5; --panel: #ffffff; --raise: #f6f7f9; --ink: #161922; --muted: #5e6575; --line: #dcdfe6;
  --accent: #0b8796; --accent-ink: #ffffff; --best: #e2f4e8; --best-ink: #1d6a3a; --danger: #b3261e;
  --warn-bg: #fff6d6; --warn-line: #e3c766; --warn-ink: #7a5800;
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--ink); font: 15px/1.45 var(--body); }
a { color: var(--accent); }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.app { display: grid; grid-template-columns: 250px minmax(0, 1fr); height: 100%; }
.rail-toggle { display: none; }


/* rail */
.rail { background: var(--panel); border-right: 1px solid var(--line); padding: 18px 14px; display: flex; flex-direction: column; gap: 12px; min-height: 0; }
/* The wordmark is sized by app.js to fill the rail's width exactly. */
.brand { display: flex; align-items: center; gap: 10px; font-family: var(--display); letter-spacing: .06em; font-stretch: condensed; }
.brand img { width: 38px; height: 38px; flex: none; }
.brand span { display: inline-block; flex: none; white-space: nowrap; font-size: 1.6rem; line-height: 1; font-weight: 600; }
.brand b { color: var(--accent); font-weight: 700; margin-left: .22em; }
.brand-wrap { display: flex; flex-direction: column; gap: 4px; }
.byline { padding-left: 48px; font-size: .75rem; letter-spacing: .04em; color: var(--muted); }

.rail-foot { margin-top: auto; display: flex; gap: 8px; }
.rail-foot .settings-btn { flex: 1; margin-top: 0; }
.theme-btn { flex: none; width: 42px; display: inline-flex; align-items: center; justify-content: center; padding: 0; color: var(--ink); }
.theme-btn svg { width: 22px; height: 22px; flex: none; }
.theme-btn .moon { display: none; }
:root[data-theme="light"] .theme-btn .sun { display: none; }
:root[data-theme="light"] .theme-btn .moon { display: block; }
.rail-head { font-family: var(--display); font-size: .8rem; letter-spacing: .14em; text-transform: uppercase; color: var(--muted); margin-top: 6px; }
.comp-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 3px; overflow-y: auto; flex: 1; min-height: 0; }
.comp-item { width: 100%; text-align: left; background: none; border: 1px solid transparent; color: var(--ink); padding: 8px 10px; border-radius: 6px; cursor: pointer; font: inherit; display: grid; grid-template-columns: minmax(0,1fr) auto; gap: 2px 8px; }
.comp-item:hover { background: var(--raise); }
.comp-item[aria-current="true"] { background: var(--raise); border-color: var(--accent); }
.comp-item b { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.comp-item small { color: var(--muted); font-size: .78rem; grid-column: 1 / -1; }
.thumbs { display: flex; gap: 2px; grid-column: 1/-1; }
.thumbs img { width: 18px; height: 27px; object-fit: cover; border-radius: 2px; background: var(--line); }
.rail-empty { color: var(--muted); font-size: .88rem; padding: 4px 2px; }
.settings-btn { margin-top: auto; }

/* buttons */
.btn { font: inherit; font-weight: 600; border-radius: 6px; padding: 8px 14px; cursor: pointer; border: 1px solid transparent; }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.primary:disabled { opacity: .6; cursor: progress; }
.btn.ghost { background: transparent; color: var(--ink); border-color: var(--line); }
.btn.ghost:hover { border-color: var(--muted); }
.btn.small { padding: 5px 10px; font-size: .88rem; }
.btn.danger { color: var(--danger); }
.link-btn { background: none; border: none; padding: 0; color: var(--accent); font: inherit; cursor: pointer; }
.link-btn:hover { text-decoration: underline; }

/* main */
.main { overflow-y: auto; padding: 22px 28px 60px; min-width: 0; }
@media (max-width: 760px) { .main { padding: 16px; } }
.work { display: flex; flex-direction: column; gap: 14px; max-width: 1400px; }
.head-row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.comp-name { flex: 1 1 300px; min-width: 0; font-family: var(--display); font-size: 2rem; font-weight: 600; letter-spacing: .02em; background: transparent; color: var(--ink); border: none; border-bottom: 1px dashed transparent; padding: 2px 0; }
.comp-name:hover { border-bottom-color: var(--line); }
.comp-name:focus { outline: none; border-bottom-color: var(--accent); }
.del-zone { display: inline-flex; gap: 8px; align-items: center; font-size: .9rem; }

/* search */
.search { position: relative; }
.search-row { display: flex; gap: 8px; flex-wrap: wrap; }
.search-row input, .search-row select, .toolbar select, .key-form input, .field input {
  font: inherit; color: var(--ink); background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 9px 12px;
}
#q { flex: 1 1 320px; min-width: 0; font-size: 1.02rem; }
#qy { width: 80px; }
.search-row input:focus, .key-form input:focus, .field input:focus { outline: none; border-color: var(--accent); }
.results { position: absolute; z-index: 20; left: 0; right: 0; top: calc(100% + 6px); background: var(--panel); border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 12px 40px rgb(0 0 0 / .35); max-height: 60vh; overflow-y: auto; padding: 6px; }
.res { display: grid; grid-template-columns: 40px minmax(0,1fr) auto; gap: 12px; align-items: center; padding: 6px 8px; border-radius: 6px; cursor: pointer; }
.res:hover, .res.sel { background: var(--raise); }
.res img, .res .noimg { width: 40px; height: 60px; object-fit: cover; border-radius: 3px; background: var(--line); }
.res b { display: block; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.res small { color: var(--muted); }
.res .tag { font-size: .8rem; color: var(--muted); }
.res .tag.ok { color: var(--best-ink); }
.res-note { padding: 10px; color: var(--muted); }
.res-more { display: block; width: 100%; margin-top: 4px; }

/* summary */
.summary { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 10px; }
.sum { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; min-width: 0; }
.sum span { display: block; font-family: var(--display); font-size: .74rem; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); }
.sum b { display: block; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sum i { font-style: normal; font-family: var(--mono); font-size: .85rem; color: var(--muted); }

/* toolbar */
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; color: var(--muted); font-size: .9rem; }
.ctl { display: inline-flex; gap: 8px; align-items: center; }
.toolbar select { padding: 5px 8px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.seg button { font: inherit; font-size: .88rem; background: transparent; color: var(--muted); border: none; padding: 5px 12px; cursor: pointer; }
.seg button + button { border-left: 1px solid var(--line); }
.seg button[aria-pressed="true"] { background: var(--raise); color: var(--ink); font-weight: 600; }

/* cards */
.cards { display: flex; flex-direction: column; gap: 10px; }
.card { display: grid; grid-template-columns: 2rem 120px minmax(0,1fr) 230px; gap: 18px; padding: 16px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; align-items: start; }
.card.lead { border-color: var(--best-ink); }
.rank { font-family: var(--display); font-size: 1.9rem; font-weight: 700; color: var(--muted); text-align: right; line-height: 1; font-variant-numeric: tabular-nums; }
.card.lead .rank { color: var(--best-ink); }
.poster { width: 120px; aspect-ratio: 2/3; max-width: 100%; border-radius: 6px; object-fit: cover; background: var(--raise); display: block; }
.poster.ph { display: flex; align-items: flex-end; padding: 8px; color: #fff; font-family: var(--display); font-weight: 700; font-size: .95rem; line-height: 1.05; background: hsl(var(--h) 40% 30%); overflow-wrap: anywhere; }
.info { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.title { font-size: 1.25rem; font-weight: 700; margin: 0; text-wrap: balance; }
.title small { font-weight: 400; color: var(--muted); }
.kind { font-size: .7rem; letter-spacing: .1em; text-transform: uppercase; border: 1px solid var(--line); border-radius: 4px; padding: 1px 6px; color: var(--muted); vertical-align: middle; margin-left: 6px; }
.kind.series { color: var(--accent); border-color: var(--accent); }
.meta { display: flex; flex-wrap: wrap; gap: 4px 14px; color: var(--muted); font-size: .9rem; }
.meta b { color: var(--ink); font-weight: 600; }
.plot { margin: 2px 0 0; max-width: 78ch; }
.plot-label { font-family: var(--display); font-size: .72rem; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); display: flex; gap: 10px; align-items: baseline; }
.plot-label .link-btn { font-family: var(--body); letter-spacing: 0; text-transform: none; font-size: .82rem; }
.credits { margin: 0; font-size: .92rem; }
.credits b { font-weight: 600; }
.extra { margin: 0; font-size: .85rem; color: var(--muted); }

.scores { display: flex; flex-direction: column; gap: 10px; }
.score { display: grid; grid-template-columns: minmax(0,1fr) auto; gap: 3px 8px; align-items: baseline; }
.score .src { font-size: .8rem; color: var(--muted); }
.score .val { font-family: var(--mono); font-size: 1.15rem; font-variant-numeric: tabular-nums; }
.score .val small { font-size: .75rem; color: var(--muted); }
.score .bar { grid-column: 1 / -1; height: 5px; border-radius: 3px; background: var(--raise); overflow: hidden; }
.score .bar i { display: block; height: 100%; }
.score .sub2 { grid-column: 1/-1; font-size: .75rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.score.best .src::after { content: "BEST"; margin-left: 6px; font-size: .65rem; letter-spacing: .1em; color: var(--best-ink); background: var(--best); padding: 1px 5px; border-radius: 3px; }
.avg { border-top: 1px solid var(--line); padding-top: 8px; }
.mc { display: inline-block; min-width: 2.2em; text-align: center; color: #111; border-radius: 4px; padding: 0 4px; font-weight: 700; }
.actions { display: flex; gap: 6px; flex-wrap: wrap; }
.actions a, .actions button { font: inherit; font-size: .82rem; font-weight: 600; color: var(--ink); background: transparent; border: 1px solid var(--line); border-radius: 5px; padding: 3px 9px; text-decoration: none; cursor: pointer; }
.actions a:hover, .actions button:hover { border-color: var(--muted); }
.actions .rm:hover { color: var(--danger); border-color: var(--danger); }

@media (max-width: 1050px) {
  .card { grid-template-columns: 100px minmax(0,1fr); }
  .rank { display: none; }
  .poster { width: 100px; }
  .scores { grid-column: 1 / -1; display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
  .avg { border-top: none; padding-top: 0; }
  .actions { grid-column: 1/-1; }
}

/* side-by-side */
/* The grid scrolls both ways inside its own box so the header row and label column stay frozen. */
.grid-wrap { overflow: auto; max-height: calc(100vh - 48px); border: 1px solid var(--line); border-radius: 10px; background: var(--panel); }
.cmp thead th, .cmp thead td { position: sticky; top: 0; z-index: 2; background: var(--raise); border-bottom: 2px solid var(--line); box-shadow: 0 6px 10px -8px rgb(0 0 0 / .45); }
.cmp thead th.corner { left: 0; z-index: 3; vertical-align: bottom; }
.cmp .head-cell .poster { width: 96px; max-width: 96px; }
.cmp .head-title { margin-top: 8px; font-size: .95rem; line-height: 1.3; }
.cmp .head-title span { color: var(--muted); }
table.cmp { border-collapse: collapse; min-width: 100%; }
.cmp th, .cmp td { border-bottom: 1px solid var(--line); padding: 10px 12px; text-align: left; vertical-align: top; font-size: .9rem; }
.cmp td { min-width: 210px; max-width: 280px; border-left: 1px solid var(--line); }
.cmp th { position: sticky; left: 0; background: var(--panel); z-index: 1; font-family: var(--display); font-size: .74rem; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); font-weight: 400; white-space: nowrap; }
.cmp tr:last-child th, .cmp tr:last-child td { border-bottom: none; }
.cmp td.best { background: var(--best); color: var(--best-ink); font-weight: 600; }
.cmp .num { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.cmp .plotcell { font-size: .86rem; line-height: 1.5; }

.empty { background: var(--panel); border: 1px dashed var(--line); border-radius: 10px; padding: 40px 20px; text-align: center; color: var(--muted); }

/* empty state */
.empty-all { max-width: 640px; margin: 6vh auto 0; display: flex; flex-direction: column; gap: 12px; }
.empty-all h1 { font-family: var(--display); font-weight: 600; font-size: 2.2rem; margin: 0; }
.key-form { display: flex; gap: 8px; flex-wrap: wrap; }
.key-form input { flex: 1 1 260px; min-width: 0; font-family: var(--mono); }
.empty-all { align-items: flex-start; }
.msg { min-height: 1.3em; margin: 0; font-size: .9rem; }
.msg.err { color: var(--danger); }
.msg.ok { color: var(--best-ink); }

/* dialog */
dialog { background: var(--panel); color: var(--ink); border: 1px solid var(--line); border-radius: 12px; padding: 0; width: min(560px, calc(100% - 32px)); }
dialog::backdrop { background: rgb(0 0 0 / .5); }
.dlg { padding: 22px; display: flex; flex-direction: column; gap: 12px; }
.dlg h2 { margin: 0; font-family: var(--display); font-weight: 600; }
.field { display: flex; flex-direction: column; gap: 5px; font-weight: 600; }
.field input { font-family: var(--mono); font-weight: 400; }
.sub { font-weight: 400; font-size: .85rem; color: var(--muted); margin: 0; }
code { font-family: var(--mono); font-weight: 400; font-size: .85rem; background: var(--raise); padding: 6px 8px; border-radius: 5px; overflow-wrap: anywhere; }
.key-status { background: var(--raise); border: 1px solid var(--line); border-radius: 8px; padding: 12px 14px; display: flex; flex-direction: column; gap: 6px; }
.key-status b { font-weight: 600; }
.key-status p { margin: 0; font-size: .9rem; color: var(--muted); }
.key-status .pill { align-self: flex-start; font-size: .72rem; letter-spacing: .1em; text-transform: uppercase; padding: 2px 8px; border-radius: 4px; background: var(--best); color: var(--best-ink); font-weight: 600; }
.key-status .pill.own { background: transparent; border: 1px solid var(--accent); color: var(--accent); }
.key-status .link-btn { align-self: flex-start; font-size: .88rem; }
.own-key { border: 1px solid var(--line); border-radius: 8px; padding: 10px 14px; }
.own-key summary { cursor: pointer; font-weight: 600; }
.own-key[open] summary { margin-bottom: 10px; }
.key-where { margin: 10px 0 0; }

/* Key problems: a notice above the search, and the choices at the top of Settings. */
.key-notice, .key-alert { border: 1px solid var(--warn-line); background: var(--warn-bg); border-radius: 10px; padding: 12px 14px; display: flex; flex-direction: column; gap: 6px; }
.key-notice b, .key-alert b { color: var(--warn-ink); font-weight: 700; }
.key-notice p, .key-alert p { margin: 0; font-size: .92rem; }
.key-notice .row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 4px; }
.key-alert ol { margin: 2px 0 0; padding-left: 1.3em; display: flex; flex-direction: column; gap: 6px; font-size: .92rem; }
.steps { margin: 0 0 12px; padding-left: 1.3em; display: flex; flex-direction: column; gap: 6px; font-size: .92rem; }
/* Parts that only apply to the desktop app or only to the website. */
:root:not([data-mode="web"]) [data-only="web"],
:root[data-mode="web"] [data-only="desktop"] { display: none !important; }
.data-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.dlg-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.grow { flex: 1; }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 8px; display: flex; gap: 14px; align-items: center; z-index: 50; max-width: calc(100% - 32px); box-shadow: 0 8px 30px rgb(0 0 0 / .3); }
.toast.err { background: var(--danger); color: #fff; }
.toast button { background: none; border: none; color: inherit; font: inherit; font-weight: 700; text-decoration: underline; cursor: pointer; }
.spin { display: inline-block; width: 12px; height: 12px; border: 2px solid var(--muted); border-top-color: transparent; border-radius: 50%; animation: sp .8s linear infinite; vertical-align: -1px; }
@keyframes sp { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spin { animation: none; } }

/* ---------- phones and narrow windows ---------- */
@media (max-width: 760px) {
  .app { grid-template-columns: minmax(0,1fr); height: auto; }
  /* Compact header: logo; New + Settings + theme on one row; the list folds away. */
  .rail {
    display: grid; grid-template-columns: minmax(0,1fr) auto; gap: 10px; padding: 14px 16px 12px;
    border-right: none; border-bottom: 1px solid var(--line);
    grid-template-areas: "brand brand" "new foot" "toggle toggle" "list list";
  }
  .brand-wrap { grid-area: brand; }
  #new-comp { grid-area: new; }
  .rail-foot { grid-area: foot; margin: 0; }
  .rail-foot .settings-btn { flex: none; }
  .rail-head { display: none; }
  .rail-toggle {
    grid-area: toggle; display: flex; align-items: center; justify-content: space-between; gap: 8px;
    font: inherit; font-weight: 600; color: var(--ink); background: var(--raise); border: 1px solid var(--line);
    border-radius: 6px; padding: 10px 12px; min-height: 44px; cursor: pointer; text-align: left;
  }
  .rail-toggle span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .rail-toggle .chev { color: var(--muted); transition: transform .15s; }
  .rail.open .rail-toggle .chev { transform: rotate(180deg); }
  .rail .comp-list { grid-area: list; display: none; max-height: 50vh; }
  .rail.open .comp-list { display: flex; }

  .main { padding: 16px 16px 48px; }
  .comp-name { font-size: 1.5rem; flex-basis: 100%; }
  .summary { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .sum { padding: 8px 10px; }
  .sum b { font-size: .92rem; }
  .sum i { font-size: .78rem; }

  /* Side by side: a slim label column so two films fit across. */
  .cmp th { white-space: normal; width: 84px; min-width: 84px; max-width: 84px; padding: 10px 8px; font-size: .66rem; letter-spacing: .08em; }
  .cmp td { min-width: 148px; max-width: 200px; padding: 10px; font-size: .86rem; }
  .cmp .head-cell .poster { width: 64px; max-width: 64px; }
  .cmp .head-title { font-size: .86rem; }
  .grid-wrap { max-height: calc(100dvh - 24px); }
}

/* Touch screens: no iOS zoom on focus (needs 16px text) and thumb-sized targets. */
@media (pointer: coarse) {
  input:not(.comp-name), select, textarea { font-size: 16px !important; }
  .btn, .toolbar select, .search-row select, .search-row input { min-height: 44px; }
  .seg button { min-height: 42px; padding: 8px 14px; }
  .actions a, .actions button { min-height: 38px; padding: 8px 12px; display: inline-flex; align-items: center; }
  .plot-label .link-btn, .key-status .link-btn { padding: 10px 0; }
  .comp-item { padding: 10px 12px; }
  .res { padding: 8px; }
}
