:root {
  color-scheme: light dark;
  --bg: #f3f4f7;
  --surface: #ffffff;
  --surface-2: #eceff3;
  --border: #d9dde4;
  --text: #171a21;
  --muted: #5d6576;
  --accent: #3b6cf6;
  --accent-ink: #ffffff;
  --ok: #15783a;      --ok-bg: #e3f5ea;
  --warn: #8f5b00;    --warn-bg: #fff2d6;
  --same: #007070;    --same-bg: #d4f7f7;   /* turquoise, between --info (new barcode) and --ok (stored): a new barcode whose film is already owned */
  --danger: #c22f2f;  --danger-bg: #fde7e7;
  --info: #2a5bd7;    --info-bg: #e6edff;
  --conf-lo: #e8221e; --conf-mid: #e69500; --conf-hi: #3fae5a;   /* the edge of a confidence pill slides along these three colours (0 %, 50 %, 100 % sure) */
  --k4: #7a3fd0;
  --bd: #1f6fd0;
  --dvd: #616a78;
  --radius: 12px;
  --shadow: 0 1px 2px rgb(0 0 0 / .06), 0 4px 14px rgb(0 0 0 / .05);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
/* Appearance (theme.js): no attribute = Auto, the device decides; data-theme="light" / "dark" is the person's choice and beats it.
   The dark palette is written twice (for the device's setting and for the choice): tests/test_theme.py checks that the two are identical. */
:root[data-theme="light"] { color-scheme: light; }
:root[data-theme="dark"] { color-scheme: dark; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0d1015;
    --surface: #161a21;
    --surface-2: #1e232c;
    --border: #2a303b;
    --text: #e6e9ef;
    --muted: #9aa3b5;
    --accent: #6b93ff;
    --accent-ink: #0b1020;
    --ok: #52c885;      --ok-bg: #12291c;
    --warn: #f0b64a;    --warn-bg: #2d2410;
    --same: #5fdddd;    --same-bg: #0b2828;
    --danger: #ff7b7b;  --danger-bg: #301717;
    --info: #86a6ff;    --info-bg: #17223f;
    --conf-lo: #ff4040; --conf-mid: #ffae2e; --conf-hi: #5bd68a;
    --k4: #b58cff;
    --bd: #6aa8ff;
    --dvd: #a3acbb;
    --shadow: 0 1px 2px rgb(0 0 0 / .4);
  }
}
:root[data-theme="dark"] {
  --bg: #0d1015;
  --surface: #161a21;
  --surface-2: #1e232c;
  --border: #2a303b;
  --text: #e6e9ef;
  --muted: #9aa3b5;
  --accent: #6b93ff;
  --accent-ink: #0b1020;
  --ok: #52c885;      --ok-bg: #12291c;
  --warn: #f0b64a;    --warn-bg: #2d2410;
  --same: #5fdddd;    --same-bg: #0b2828;
  --danger: #ff7b7b;  --danger-bg: #301717;
  --info: #86a6ff;    --info-bg: #17223f;
  --conf-lo: #ff4040; --conf-mid: #ffae2e; --conf-hi: #5bd68a;
  --k4: #b58cff;
  --bd: #6aa8ff;
  --dvd: #a3acbb;
  --shadow: 0 1px 2px rgb(0 0 0 / .4);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.45;
  padding-bottom: env(safe-area-inset-bottom);
}
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
a { color: var(--accent); }
h2, h3 { margin: 0; line-height: 1.25; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 16px; justify-content: space-between;
  padding: 10px max(16px, env(safe-area-inset-left));
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.brand { font-weight: 800; font-size: 1.2rem; letter-spacing: .01em; color: var(--text); text-decoration: none; display: flex; align-items: center; gap: 8px; }
.brand::before { content: ""; width: 18px; height: 18px; border-radius: 50%; background: radial-gradient(circle, var(--surface) 0 2px, var(--accent) 2.5px 5px, var(--surface) 5.5px 6px, var(--accent) 6.5px); }
.tabs { display: flex; gap: 4px; background: var(--surface-2); padding: 4px; border-radius: 999px; }
.tabs a { padding: 6px 20px; border-radius: 999px; text-decoration: none; color: var(--muted); font-weight: 600; }
.tabs a[aria-current="page"] { background: var(--accent); color: var(--accent-ink); }

main { max-width: 1120px; margin: 0 auto; padding: 20px 16px 48px; }

/* ---------- buttons & inputs ---------- */
.btn {
  appearance: none; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 0 16px;
  font: inherit; font-weight: 600; color: var(--text);
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); background: var(--accent); }
.btn.danger { color: var(--danger); }
.btn.small { min-height: 34px; padding: 0 12px; font-size: .9rem; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 60%, transparent); outline-offset: 2px; }

input, select {
  font: inherit; color: var(--text);
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  min-height: 44px; padding: 0 12px; width: 100%;
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }

/* ---------- scan view ---------- */
.segmented { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; background: var(--surface-2); padding: 4px; border-radius: 14px; max-width: 480px; }
.segmented a { text-align: center; padding: 10px 0; border-radius: 10px; text-decoration: none; color: var(--muted); font-weight: 700; }
.segmented a[aria-selected="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.hint { color: var(--muted); margin: 10px 2px 16px; }

.scan-form { display: flex; gap: 8px; max-width: 720px; }
.scan-form input { font-size: 1.35rem; min-height: 56px; letter-spacing: .04em; font-variant-numeric: tabular-nums; flex: 1; min-width: 0; }
.scan-form .btn { min-height: 56px; }

#scan-result { margin-top: 20px; max-width: 820px; display: grid; gap: 12px; }

.banner {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 12px 14px; border-radius: var(--radius); font-weight: 600;
  background: var(--info-bg); color: var(--info);
}
.banner.ok { background: var(--ok-bg); color: var(--ok); }
.banner.warn { background: var(--warn-bg); color: var(--warn); }
.banner.same { background: var(--same-bg); color: var(--same); }
.banner.error { background: var(--danger-bg); color: var(--danger); }
.banner .sub { font-weight: 400; display: block; opacity: .9; }
/* The banner is an item of the result grid: without min-width 0 one unbreakable line (the verdict) would make the whole column wider than the screen. */
.banner { min-width: 0; }
.banner > div { min-width: 0; flex: 1; }
/* Check mode's line in the top banner: what the list of similar discs found (see verdictLine in app.js). One line, ellipsis; it is there from the start, so nothing moves. */
.verdict { display: flex; gap: 8px; align-items: center; margin-top: 4px; min-height: 1.5em; font-weight: 600; }
.verdict .text { min-width: 0; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.verdict.same .text { font-weight: 700; }
.verdict.jump { cursor: pointer; }
.verdict .go { flex: none; opacity: .8; }
.verdict::before { content: ""; flex: none; width: 10px; height: 10px; border-radius: 50%; box-sizing: border-box; background: currentColor; opacity: .85; }   /* filled = the same film, ring = related, dotted = nothing */
.verdict.related::before { background: none; border: 2px solid currentColor; }
.verdict.none::before { background: none; border: 2px dotted currentColor; }
.verdict.busy::before, .verdict.failed::before, .verdict.unknown::before { content: none; }
.verdict.busy, .verdict.failed, .verdict.unknown { font-weight: 400; }
.verdict .mini-spinner { width: 12px; height: 12px; border-radius: 50%; border: 2px solid currentColor; border-right-color: transparent; animation: spin .8s linear infinite; flex: none; }
.verdict:not(.busy) .mini-spinner { display: none; }
.spinner { width: 18px; height: 18px; border-radius: 50%; border: 3px solid currentColor; border-right-color: transparent; animation: spin .8s linear infinite; flex: none; margin-top: 2px; }
@keyframes spin { to { transform: rotate(360deg); } }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { font-size: .85rem; padding: 3px 10px; border-radius: 999px; background: var(--surface-2); color: var(--muted); }
.chip.ok { background: var(--ok-bg); color: var(--ok); }
.chip.error { background: var(--danger-bg); color: var(--danger); }

.check-line { display: flex; align-items: center; gap: 10px; font-weight: 600; min-height: 44px; }
.check-line input { width: 20px; min-height: 20px; height: 20px; accent-color: var(--accent); }
.check-line .muted { font-weight: 400; color: var(--muted); }
.bulk-line { margin: 6px 2px 0; }
/* On a wide screen (a desktop, or a phone held sideways) the Scan tab is one column, as wide as the result and centred under the header's
   tabs: the mode selector and the bulk-scan toggle on one row, the description of the mode above the barcode field, then the result.
   Held upright (up to 720px wide) the elements stay stacked as they are. The space between the rows comes from margins, not from a grid
   gap, so a row with nothing in it (a viewer has no mode selector, Check mode no bulk toggle) takes no room at all. */
@media (min-width: 721px) {
  #view-scan {
    max-width: 820px; margin-inline: auto;
    display: grid; grid-template-columns: auto minmax(0, 1fr); column-gap: 16px; align-items: center;
    grid-template-areas: "modes bulk" "hint hint" "form form" "result result";
  }
  #scan-modes { grid-area: modes; width: 300px; margin-bottom: 12px; }
  #bulk-line { grid-area: bulk; justify-self: end; margin: 0 0 12px; font-size: .92rem; }   /* (so that its line is one line at 820px) */
  #mode-hint { grid-area: hint; margin: 0 2px 8px; }
  #scan-form { grid-area: form; max-width: none; }
  #scan-result { grid-area: result; max-width: none; }
}

/* ---------- disc card ---------- */
.card {
  display: grid; grid-template-columns: 96px 1fr; gap: 16px;
  padding: 14px; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow);
}
.card h3 { font-size: 1.15rem; overflow-wrap: anywhere; }
.card .body { min-width: 0; display: grid; gap: 8px; align-content: start; }
.card .raw { color: var(--muted); font-size: .85rem; overflow-wrap: anywhere; }
.card .actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 4px; }
.card .actions .spacer { flex: 1; }
.card.candidate .from { display: flex; align-items: center; gap: 8px; font-size: .85rem; color: var(--muted); }
.card.candidate .from strong { color: var(--text); }

/* a source that is only asked when its button is pressed */
.ondemand { display: contents; }
.card.ondemand-card { grid-template-columns: 1fr; }
.card.ondemand-card .from { font-size: .85rem; color: var(--muted); }
.card.ondemand-card .from strong { color: var(--text); }
.card .note { color: var(--muted); overflow-wrap: anywhere; }
.card .note.error { color: var(--danger); }

.cover, .cover-ph {
  width: 96px; aspect-ratio: 2 / 3; border-radius: 8px; object-fit: cover;
  background: var(--surface-2); border: 1px solid var(--border);
}
.cover-ph { display: grid; place-items: center; color: var(--muted); font-size: .7rem; text-align: center; }
.cover-ph svg { width: 34px; height: 34px; opacity: .45; }

.badges { display: flex; flex-wrap: wrap; gap: 6px; }
.badge { display: inline-flex; align-items: center; gap: 4px; font-size: .78rem; font-weight: 800; letter-spacing: .03em; padding: 2px 8px; border-radius: 6px; border: 1.5px solid currentColor; }
.badge.k4 { color: var(--k4); }
.badge.bluray { color: var(--bd); }
.badge.dvd { color: var(--dvd); }
.badge.ripped { color: var(--ok); background: var(--ok-bg); border-color: transparent; }
.badge.notripped { color: var(--muted); border-style: dashed; font-weight: 600; }

.facts { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 6px 16px; margin: 0; }
.facts div { min-width: 0; }
.facts dt { font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.facts dd { margin: 0; overflow-wrap: anywhere; }
.facts dd.mono { font-variant-numeric: tabular-nums; letter-spacing: .03em; white-space: nowrap; }
.facts .none { color: var(--muted); }

.format-pick { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.format-pick label { font-size: .85rem; color: var(--warn); font-weight: 700; }
.format-pick select { width: auto; min-height: 36px; }

/* ---------- library ---------- */
.toolbar { display: grid; grid-template-columns: minmax(0, 2fr) repeat(4, minmax(0, 1fr)); gap: 8px; }
@media (min-width: 721px) and (max-width: 1240px) {   /* five controls do not fit one row here without cutting the words of the selects ("Gerippt oder nicht"): the search takes the first row, the four selects share the second */
  .toolbar { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .toolbar .lib-search-row { grid-column: 1 / -1; }
}
.lib-search-row { display: flex; gap: 8px; min-width: 0; }
.lib-search-row input { flex: 1; min-width: 0; }
.lib-search-row .btn { flex: none; white-space: nowrap; }
.stats { color: var(--muted); margin: 10px 2px 12px; }
/* The header row owns the space around it: the stats text and the buttons may share a line or wrap onto two, and the list must
   never touch the last of them (the stats' own margin only gave that gap while everything fit on one line). */
.lib-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; margin: 10px 0 12px; }
.lib-head .stats { margin: 0 0 0 2px; }
.downloads { display: flex; flex-wrap: wrap; gap: 8px; }
.downloads .btn { text-decoration: none; }
.ripped-mark { font-weight: 800; color: var(--ok); }
dialog input:disabled, dialog select:disabled { color: var(--text); -webkit-text-fill-color: var(--text); opacity: 1; background: var(--surface-2); }
dialog input:disabled::placeholder { color: transparent; }   /* (no example text where nothing can be typed) */
#lib-list { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.row {
  --cols: 52px minmax(200px, 3fr) 88px 64px 64px minmax(90px, 1.3fr) minmax(80px, 1fr) 116px 66px;   /* (116px: an IMDb id has up to 12 characters, about 114px) */
  display: grid; grid-template-columns: var(--cols); align-items: center; gap: 0 12px;
  padding: 8px 14px; border-top: 1px solid var(--border);
}
.row.head { border-top: 0; background: var(--surface-2); font-size: .78rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding-block: 4px; }
.row.head button { all: unset; cursor: pointer; padding: 8px 0; font-weight: 700; }
.row.head button:hover, .row.head [aria-sort] button { color: var(--text); }
.row.head [aria-sort="ascending"] button::after { content: " ▲"; font-size: .7em; }
.row.head [aria-sort="descending"] button::after { content: " ▼"; font-size: .7em; }
.row.item { cursor: pointer; }
.row.item:hover { background: color-mix(in srgb, var(--accent) 6%, transparent); }
.row .thumb, .row .thumb-ph { width: 40px; aspect-ratio: 2 / 3; border-radius: 4px; object-fit: cover; background: var(--surface-2); border: 1px solid var(--border); display: block; }
.row .title { min-width: 0; }
.row .title strong { display: block; overflow-wrap: anywhere; }
.row .title small { color: var(--muted); font-variant-numeric: tabular-nums; }
.row .num { font-variant-numeric: tabular-nums; }
.row .txt { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .dim { color: var(--muted); }
.row .meta { display: none; }
/* Between a phone held sideways and a small laptop the table has no room for every column: the studio and the country step aside
   (the sort menu still sorts by them), so that the id and the switch keep theirs and the row never grows wider than the list. */
@media (min-width: 721px) and (max-width: 1000px) {
  .row { --cols: 52px minmax(160px, 1fr) 80px 56px 56px 116px 66px; gap: 0 10px; }
  .row .c-wide { display: none; }
}
.imdb-link { font-weight: 700; font-size: .85rem; text-decoration: none; }

.switch { position: relative; display: inline-block; width: 44px; height: 26px; }
.switch input { position: absolute; inset: 0; width: 100%; height: 100%; min-height: 0; opacity: 0; margin: 0; cursor: pointer; z-index: 1; }
.switch span { position: absolute; inset: 0; background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px; transition: background .15s; }
.switch span::after { content: ""; position: absolute; top: 2px; left: 2px; width: 20px; height: 20px; border-radius: 50%; background: var(--muted); transition: transform .15s, background .15s; }
.switch input:checked + span { background: var(--ok-bg); border-color: var(--ok); }
.switch input:checked + span::after { transform: translateX(18px); background: var(--ok); }
.switch input:focus-visible + span { outline: 3px solid color-mix(in srgb, var(--accent) 60%, transparent); outline-offset: 2px; }

.empty { text-align: center; color: var(--muted); padding: 48px 16px; }
.more { text-align: center; margin-top: 16px; }

/* ---------- dialogs ---------- */
dialog {
  color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 16px;
  --pad: 20px;
  padding: var(--pad);
  width: min(640px, calc(100vw - 24px)); max-height: calc(100dvh - 24px); overflow: auto;
  box-shadow: 0 20px 60px rgb(0 0 0 / .35);
}
#dialog-title:focus { outline: none; }  /* the heading takes focus when the dialog opens (see index.html) */
dialog::backdrop { background: rgb(5 8 14 / .55); backdrop-filter: blur(2px); }
dialog h2 { margin-bottom: 14px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 14px; }
.form-grid label { display: grid; gap: 4px; font-size: .85rem; font-weight: 700; color: var(--muted); min-width: 0; }
.form-grid label input, .form-grid label select { font-weight: 400; }
/* a choice that does not apply (no link, so no term) stays where it is, greyed out: the layout never changes with what was typed or ticked */
.form-grid label.is-off { opacity: .5; }
.form-grid label.is-off select { cursor: not-allowed; }
.form-grid .span-2 { grid-column: 1 / -1; }
.form-grid .check { display: flex; align-items: center; gap: 10px; align-self: end; min-height: 44px; color: var(--text); font-size: 1rem; }
.form-grid .check input { width: 20px; height: 20px; min-height: 0; accent-color: var(--accent); }
.form-grid input[aria-invalid="true"], .form-grid select[aria-invalid="true"] { border-color: var(--danger); }
.cover-row { display: grid; grid-template-columns: 1fr 48px; gap: 10px; align-items: center; }
.cover-preview { width: 48px; height: 72px; border-radius: 6px; background: var(--surface-2); border: 1px solid var(--border); overflow: hidden; display: block; }
.cover-preview img { width: 100%; height: 100%; object-fit: cover; display: block; }
.dialog-meta { color: var(--muted); font-size: .85rem; margin: 14px 0 0; min-height: 1em; }
.form-error { background: var(--danger-bg); color: var(--danger); padding: 10px 12px; border-radius: 10px; font-weight: 600; margin: 12px 0 0; }
.dialog-actions {
  display: flex; gap: 8px; align-items: center;
  position: sticky; bottom: calc(-1 * var(--pad));
  margin: 16px calc(-1 * var(--pad)) calc(-1 * var(--pad)); padding: 12px var(--pad) var(--pad);
  background: var(--surface); border-top: 1px solid var(--border);
}
.dialog-actions .spacer { flex: 1; }

.camera-last { margin: 12px 0 0; padding: 8px 12px; border-radius: 10px; font-weight: 600; overflow-wrap: anywhere; background: var(--ok-bg); color: var(--ok); }
.camera-last.warn { background: var(--warn-bg); color: var(--warn); }

.camera-box { position: relative; border-radius: 12px; overflow: hidden; background: #000; aspect-ratio: 4 / 3; }
.camera-box video { width: 100%; height: 100%; object-fit: cover; display: block; }
.reticle { position: absolute; left: 8%; right: 8%; top: 32%; bottom: 32%; border: 2px solid rgb(255 255 255 / .85); border-radius: 10px; box-shadow: 0 0 0 999px rgb(0 0 0 / .35); }
.reticle::after { content: ""; position: absolute; left: 4%; right: 4%; top: 50%; height: 2px; background: rgb(255 70 70 / .9); }
/* A phone held sideways is only about 370px high: the picture (4:3, as wide as the dialog) was taller than the screen and the dialog had to be
   scrolled to reach the reticle and the status. So the picture takes the height of the screen, and the status, the last report and the button go
   to its right: everything is in view at once. (Upright, and on anything taller than 560px, nothing changes.) */
@media (orientation: landscape) and (max-height: 560px) {
  #camera-dialog { width: min(760px, calc(100vw - 24px)); }
  #camera-dialog[open] {
    display: grid; grid-template-columns: minmax(0, 1fr) 176px; grid-template-rows: auto auto 1fr; gap: 0 16px;
    grid-template-areas: "picture report" "picture status" "picture close";
  }
  #camera-dialog .camera-box { grid-area: picture; aspect-ratio: auto; height: calc(100dvh - 24px - 2 * var(--pad) - 2px); }   /* (the dialog's own maximum height, less its padding and border) */
  #camera-dialog .camera-last { grid-area: report; margin: 0 0 10px; }
  #camera-dialog #camera-status { grid-area: status; margin: 0; }
  #camera-dialog .dialog-actions { grid-area: close; align-self: end; position: static; margin: 0; padding: 0; border: 0; background: none; }
  #camera-dialog .dialog-actions .spacer { display: none; }
  #camera-dialog .dialog-actions .btn { flex: 1; }
}

#toast {
  position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px);
  max-width: min(92vw, 520px); padding: 12px 18px; border-radius: 12px; font-weight: 600;
  background: var(--text); color: var(--bg); opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 50;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.error { background: var(--danger); color: #fff; }

/* ---------- Check mode: similar discs ---------- */
.similar { display: grid; gap: 12px; }
.similar:empty { display: none; }   /* (Enter and Rip mode: nothing to list yet, and the result grid's gap must not leave a blank line at the bottom) */
.similar h3 { font-size: 1rem; margin: 6px 2px -4px; }
.sim-list { list-style: none; margin: 0; padding: 0; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.sim-row { display: grid; grid-template-columns: 44px minmax(0, 1fr); gap: 12px; align-items: start; padding: 10px 14px; border-top: 1px solid var(--border); }
.sim-row:first-child { border-top: 0; }
.sim-row.open { cursor: pointer; }
.sim-row.open:hover { background: color-mix(in srgb, var(--accent) 6%, transparent); }
.sim-row .thumb, .sim-row .thumb-ph { width: 44px; aspect-ratio: 2 / 3; border-radius: 4px; object-fit: cover; background: var(--surface-2); border: 1px solid var(--border); display: block; }
.sim-main { min-width: 0; display: grid; gap: 4px; justify-items: start; }
.sim-main strong { overflow-wrap: anywhere; }
.sim-meta { color: var(--muted); font-size: .88rem; overflow-wrap: anywhere; }
.sim-note { color: var(--muted); margin: 2px; }
.sim-why { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.pill.conf { background: none; color: var(--muted); border: 1px solid var(--border); border-left: 8px solid var(--conf-mid); font-weight: 600; }
/* The edge says how sure Jev is: the colour slides red - amber - green with the percentage (similarRow sets --sure-from / --sure-to / --sure-pct). Mixed in
   oklab so the middle of each stretch does not turn muddy; a browser without it keeps the amber edge above. */
@supports (color: color-mix(in oklab, red, blue)) {
  .pill.conf { border-left-color: color-mix(in oklab, var(--sure-to) var(--sure-pct), var(--sure-from)); }
}
.jev-note { margin: 0 2px; }
.jev-panel { margin: 0 0 16px; }
.jev-panel .jev-head { display: flex; gap: 8px; align-items: center; justify-content: space-between; }
.jev-panel .jev-head h3 { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.jev-panel .jev-head .btn { flex: none; }
.pill.reason { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); }
.pill.reason.box { background: var(--info-bg); color: var(--info); border-color: transparent; }
.badge.threed { color: var(--info); }

/* ---------- small screens ---------- */
@media (max-width: 720px) {
  main { padding-top: 14px; }
  .toolbar { grid-template-columns: 1fr 1fr; }
  .toolbar .lib-search-row { grid-column: 1 / -1; }
  .toolbar #lib-imdb, .toolbar #lib-sort { grid-column: 1 / -1; }
  .scan-form { flex-wrap: wrap; }
  .scan-form input { flex-basis: 100%; order: -1; }   /* (the field on a row of its own; the left camera button is first in the markup, so it starts the row under it) */
  .scan-form .btn.primary { flex: 1; }
  #scan-modes { margin-inline: auto; }   /* (it stops growing at 480px: from about 512px up it sits in the middle, like the tabs above it) */
  .card { grid-template-columns: 76px 1fr; gap: 12px; }
  .cover, .cover-ph { width: 76px; }
  .row.head { display: none; }
  .row.item {
    grid-template-columns: 44px 1fr auto; grid-template-areas: "thumb title ripped" "thumb meta ripped";
    gap: 2px 12px; padding: 12px 14px;
  }
  .row.item > .c-thumb { grid-area: thumb; align-self: start; }
  .row.item > .title { grid-area: title; }
  .row.item > .meta { grid-area: meta; display: block; color: var(--muted); font-size: .88rem; }
  .row.item > .c-ripped { grid-area: ripped; }
  .row.item > .c-hide { display: none; }
  .form-grid { grid-template-columns: 1fr 1fr; }
  dialog { --pad: 16px; }
}
@media (max-width: 420px) {
  .form-grid { grid-template-columns: 1fr; }
  .facts { grid-template-columns: 1fr 1fr; }
  .facts .wide { grid-column: 1 / -1; }
}
/* ---------- language, account, sign-in ---------- */
.topbar-tools { display: flex; align-items: center; gap: 8px; }
.small-select { width: auto; min-height: 34px; padding: 0 8px; font-size: .9rem; }
/* The appearance control in the header (theme.js): a <select> laid invisibly over an icon, so it is as small as a button and still opens the native picker. */
.theme-pick { --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Ccircle cx='12' cy='12' r='9' fill='none' stroke='black' stroke-width='2'/%3E%3Cpath d='M12 3a9 9 0 0 1 0 18z'/%3E%3C/svg%3E"); position: relative; flex: none; width: 36px; height: 34px; display: grid; place-items: center;
  color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 10px; }
.theme-pick[data-choice="light"] { --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Ccircle cx='12' cy='12' r='4'/%3E%3Cpath fill='none' stroke='black' stroke-width='2' stroke-linecap='round' d='M12 2.5v3M12 18.5v3M2.5 12h3M18.5 12h3M5.3 5.3l2.1 2.1M16.6 16.6l2.1 2.1M5.3 18.7l2.1-2.1M16.6 7.4l2.1-2.1'/%3E%3C/svg%3E"); }
.theme-pick[data-choice="dark"] { --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M20.5 14.6A8.6 8.6 0 0 1 9.4 3.5 8.6 8.6 0 1 0 20.5 14.6z'/%3E%3C/svg%3E"); }
.theme-pick::before { content: ""; width: 18px; height: 18px; background: currentColor; -webkit-mask: var(--icon) center / contain no-repeat; mask: var(--icon) center / contain no-repeat; pointer-events: none; }
.theme-pick select { position: absolute; inset: 0; width: 100%; height: 100%; min-height: 0; padding: 0; opacity: 0; cursor: pointer; }
.theme-pick:focus-within { outline: 2px solid var(--accent); outline-offset: 1px; }
.stack { display: grid; gap: 12px; }
.stack label { display: grid; gap: 4px; font-size: .85rem; font-weight: 700; color: var(--muted); min-width: 0; }
.stack label input, .stack label select { font-weight: 400; }
.stack h3 { font-size: 1rem; }
.stack small { font-weight: 400; }
.muted { color: var(--muted); }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .9rem; }
.login-card { max-width: 420px; margin: 8vh auto 0; padding: 24px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.login-card h1 { margin: 0 0 14px; font-size: 1.4rem; }
.login-notice { background: var(--warn-bg); color: var(--warn); padding: 12px 14px; border-radius: 10px; font-weight: 600; margin-bottom: 14px; }
.login-card .hint { margin-top: 0; }
.login-card .form-error { margin: 0; }
dialog.modal { width: min(520px, calc(100vw - 24px)); }
dialog.modal h2:focus { outline: none; }  /* the heading takes the focus when the dialog opens (see modal() in common.js) */
dialog.modal h3 { margin-top: 18px; }
dialog.modal input.mono { width: 100%; }

/* ---------- administration ---------- */
.page-title { margin: 0 0 14px; font-size: 1.4rem; }
.admin-tabs { grid-template-columns: repeat(4, 1fr); max-width: 640px; margin-bottom: 16px; }
.admin-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin-bottom: 14px; display: grid; gap: 10px; }
.admin-card h2 { font-size: 1.05rem; }
.admin-card p { margin: 0; }
.admin-card .hint { margin: 0; font-size: .9rem; }
.admin-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; }
.admin-row .spacer { flex: 1; }
.admin-row .btn.small { text-decoration: none; }
.user-name { font-size: 1.05rem; }
.pill { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: .78rem; font-weight: 700; }
.pill.admin { background: var(--info-bg); color: var(--info); }
.pill.viewer { background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); }
.pill.locked { background: var(--warn-bg); color: var(--warn); }
.switch-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 4px 16px; }
.source-row { padding: 10px 0; border-top: 1px solid var(--border); }
.source-row:first-of-type { border-top: 0; }
.source-text { display: grid; gap: 2px; min-width: 0; }
.source-note { font-size: .92rem; }
.note.error { color: var(--danger); }
.backup-row { padding: 6px 0; border-top: 1px solid var(--border); }
.danger-zone { border-color: var(--danger); }
.danger-zone h2 { color: var(--danger); }
.admin-card .form-grid { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }

/* The header goes onto two rows (brand + tools, then the tabs) up to 760px: with the appearance control the admin's three German tabs need 756px for one row.
   From 761px, a phone held sideways included, it stays one row (`test_the_header_never_makes_the_page_scroll_sideways`). */
@media (max-width: 760px) {
  .topbar { flex-wrap: wrap; gap: 8px 12px; }
  .topbar .tabs { order: 3; flex: 1 1 100%; min-width: 0; justify-content: center; }
  .topbar .tabs a { padding: 6px 12px; }
  .topbar-tools { margin-left: auto; }
}

@media (max-width: 720px) {
  .login-card { margin-top: 3vh; padding: 18px; }
  .admin-tabs { grid-template-columns: repeat(2, 1fr); }
}

@media (prefers-reduced-motion: reduce) { *, ::before, ::after { animation: none !important; transition: none !important; } }
