:root {
  --bg: #f4f2ee;
  --surface: #ffffff;
  --surface-2: #f0ede7;
  --text: #1d1b19;
  --muted: #6b655d;
  --line: #ddd7cd;
  --accent: #c8102e;
  --accent-ink: #ffffff;
  --done: #2e7d4f;
  --warn-bg: #fff4d6;
  --warn-ink: #6b4e00;
  --shadow: 0 1px 2px rgba(0,0,0,.06), 0 4px 16px rgba(0,0,0,.05);
  --photo-bg: #ffffff;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #141312;
    --surface: #1e1c1a;
    --surface-2: #282522;
    --text: #efebe5;
    --muted: #a39c92;
    --line: #37332e;
    --accent: #ff4a5f;
    --accent-ink: #1a0005;
    --done: #5cc98a;
    --warn-bg: #3a2f10;
    --warn-ink: #f3d98c;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 4px 16px rgba(0,0,0,.3);
    --photo-bg: #efedea;
  }
}
:root[data-theme="dark"] {
  --bg: #141312;
  --surface: #1e1c1a;
  --surface-2: #282522;
  --text: #efebe5;
  --muted: #a39c92;
  --line: #37332e;
  --accent: #ff4a5f;
  --accent-ink: #1a0005;
  --done: #5cc98a;
  --warn-bg: #3a2f10;
  --warn-ink: #f3d98c;
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 4px 16px rgba(0,0,0,.3);
  --photo-bg: #efedea;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
.wrap { max-width: 1180px; margin: 0 auto; padding: 0 16px; }

/* "Open in Chrome" notice */
.browser-note {
  background: var(--warn-bg); color: var(--warn-ink); border-bottom: 1px solid var(--line);
  padding: 10px 16px; font-size: 14px; display: flex; gap: 8px 14px; align-items: center; justify-content: center; flex-wrap: wrap;
}
.browser-note[hidden] { display: none; }
.browser-note .btn { color: var(--text); }

/* Header */
header.top { padding: 28px 0 8px; }
.brand { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.brand h1 { font-size: 26px; line-height: 1.2; margin: 0; letter-spacing: -.01em; }
.brand .spacer { flex: 1; }
.stats { display: flex; gap: 18px; flex-wrap: wrap; color: var(--muted); margin: 6px 0 0; font-size: 14px; }
.stats b { color: var(--text); font-variant-numeric: tabular-nums; }
.views { display: flex; gap: 4px; margin: 14px 0 0; border-bottom: 1px solid var(--line); }
.view {
  background: none; border: none; border-bottom: 3px solid transparent; margin-bottom: -1px;
  padding: 8px 14px; cursor: pointer; color: var(--muted); font-size: 16px; font-weight: 600;
}
.view[aria-current=true] { color: var(--text); border-bottom-color: var(--accent); }
.view span { font-size: 12px; font-weight: 600; background: var(--surface-2); border: 1px solid var(--line); border-radius: 999px; padding: 0 8px; margin-left: 4px; }
.chip.buy { color: var(--warn-ink); background: var(--warn-bg); border-color: transparent; }
.dlg-head .move { margin-top: 8px; }

/* Toolbar */
.toolbar {
  display: flex; gap: 8px; flex-wrap: wrap; align-items: center;
  padding: 14px 0; position: sticky; top: 0; background: var(--bg); z-index: 5;
  border-bottom: 1px solid var(--line);
}
.toolbar input[type=search] { flex: 1 1 220px; min-width: 0; }
input[type=search], input[type=text], input[type=password], input[type=number], input[type=date], select, textarea {
  background: var(--surface); border: 1px solid var(--line); border-radius: 8px;
  padding: 8px 10px; min-width: 0;
}
textarea { width: 100%; resize: vertical; min-height: 70px; }
.btn {
  background: var(--surface); border: 1px solid var(--line); border-radius: 8px;
  padding: 8px 12px; cursor: pointer; white-space: nowrap;
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
.btn.small { padding: 4px 9px; font-size: 13px; }
.btn.warn { background: var(--warn-bg); color: var(--warn-ink); border-color: transparent; font-weight: 600; }
.btn:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, .card:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}

/* Grid */
.grid {
  display: grid; gap: 14px; padding: 18px 0 40px;
  grid-template-columns: repeat(auto-fill, minmax(min(250px, 100%), 1fr));
}
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px;
  box-shadow: var(--shadow); overflow: hidden; cursor: pointer; text-align: left;
  display: flex; flex-direction: column; padding: 0;
  transition: transform .12s ease, border-color .12s ease;
}
.card:hover { transform: translateY(-2px); border-color: var(--muted); }
.card .band { height: 6px; background: var(--fig); }
.card .body { padding: 14px 16px 16px; display: flex; flex-direction: column; gap: 8px; flex: 1; }
.card .row1 { display: flex; align-items: center; gap: 12px; }
.mono {
  width: 56px; height: 56px; border-radius: 10px; flex: none; overflow: hidden;
  display: grid; place-items: center; font-size: 26px; background: var(--photo-bg);
  border: 1px solid color-mix(in srgb, var(--fig) 45%, var(--line));
}
.mono img { width: 100%; height: 100%; object-fit: contain; padding: 3px; }
.thumb {
  display: block; position: relative; aspect-ratio: 4 / 3; overflow: hidden;
  background: var(--photo-bg); border-bottom: 1px solid var(--line);
}
.thumb img { display: block; width: 100%; height: 100%; object-fit: contain; padding: 10px; transition: transform .2s ease; }
.card:hover .thumb img { transform: scale(1.04); }
.thumb .fallback, .mono .fallback { display: none; }
.thumb.noimg .fallback { position: absolute; inset: 0; display: grid; place-items: center; font-size: 64px; background: color-mix(in srgb, var(--fig) 16%, var(--surface-2)); }
.mono.noimg { background: color-mix(in srgb, var(--fig) 22%, var(--surface-2)); }
.mono.noimg .fallback { display: block; }
.thumb.noimg img, .mono.noimg img { display: none; }
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(220px, 100%), 1fr)); gap: 12px; margin: 0 0 18px; }
.gallery figure, .fromto figure { margin: 0; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: var(--photo-bg); }
.gallery img { display: block; width: 100%; aspect-ratio: 4 / 3; object-fit: contain; padding: 8px; }
.gallery figcaption, .fromto figcaption { font-size: 12px; color: var(--muted); background: var(--surface); padding: 6px 10px; border-top: 1px solid var(--line); }
.fromto { display: flex; align-items: center; gap: 10px; margin: 0 0 14px; }
.fromto figure { flex: 1 1 0; max-width: 200px; }
.fromto img { display: block; width: 100%; aspect-ratio: 4 / 3; object-fit: contain; padding: 6px; }
.fromto .arrow { font-size: 22px; color: var(--muted); }
.myphoto { display: flex; flex-direction: column; gap: 10px; margin: 0 0 18px; padding-bottom: 16px; border-bottom: 1px solid var(--line); }
.myphoto img { max-width: min(360px, 100%); max-height: 320px; object-fit: contain; border-radius: 10px; border: 1px solid var(--line); align-self: flex-start; }
.photo-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.card .h { font-size: 18px; font-weight: 700; line-height: 1.2; }
.card .sub { color: var(--muted); font-size: 13px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  font-size: 12px; padding: 2px 8px; border-radius: 999px;
  background: var(--surface-2); border: 1px solid var(--line); color: var(--muted);
}
.chip.on { color: var(--done); border-color: color-mix(in srgb, var(--done) 50%, var(--line)); }
.chip.custom { color: var(--accent); }
.chip.combine { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 50%, var(--line)); font-weight: 600; }
.chip.team { color: var(--text); border-color: color-mix(in srgb, var(--fig) 55%, var(--line)); background: color-mix(in srgb, var(--fig) 14%, var(--surface)); }
.group-h {
  grid-column: 1 / -1; margin: 14px 0 -4px; font-size: 13px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .06em; color: var(--muted);
  display: flex; align-items: center; gap: 8px;
}
.group-h:first-child { margin-top: 0; }
.group-h span { font-weight: 600; background: var(--surface-2); border: 1px solid var(--line); border-radius: 999px; padding: 0 8px; font-size: 12px; }
.group-h::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.mates { display: flex; flex-wrap: wrap; gap: 8px; }
.progress-mini { margin-top: auto; font-size: 12px; color: var(--muted); }
.bar { height: 4px; background: var(--surface-2); border-radius: 4px; overflow: hidden; margin-top: 4px; }
.bar > i { display: block; height: 100%; background: var(--done); width: 0; }
.empty { color: var(--muted); padding: 40px 0; text-align: center; grid-column: 1 / -1; }

/* Detail dialog */
dialog {
  border: none; padding: 0; background: var(--surface); color: var(--text);
  width: min(880px, calc(100vw - 20px)); max-height: calc(100vh - 20px);
  border-radius: 14px; box-shadow: 0 20px 60px rgba(0,0,0,.35);
}
dialog::backdrop { background: rgba(0,0,0,.55); }
.dlg { display: flex; flex-direction: column; max-height: calc(100vh - 20px); }
.dlg-head {
  padding: 18px 20px 0; border-top: 6px solid var(--fig);
  display: flex; gap: 14px; align-items: flex-start;
}
.dlg-head h2 { margin: 0; font-size: 22px; line-height: 1.2; }
.dlg-head .sub { color: var(--muted); font-size: 14px; }
.dlg-head .x { margin-left: auto; }
.dlg-head > div { min-width: 0; }
.dlg-head .move { white-space: normal; text-align: left; }
.dlg-head, .tabs { flex: none; }
.tabs { display: flex; gap: 2px; padding: 12px 20px 0; border-bottom: 1px solid var(--line); overflow-x: auto; }
.tab {
  background: none; border: none; border-bottom: 2px solid transparent;
  padding: 8px 12px; cursor: pointer; color: var(--muted); white-space: nowrap;
}
.tab[aria-selected=true] { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }
.dlg-body { padding: 18px 20px 22px; overflow-y: auto; }
.facts { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(170px, 100%), 1fr)); gap: 10px 18px; margin: 0 0 18px; }
.facts div { border-left: 3px solid var(--fig); padding-left: 10px; }
.facts dt { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.facts dd { margin: 0; font-weight: 600; }
h3 { font-size: 15px; margin: 18px 0 8px; }
ul.plain { margin: 0; padding-left: 20px; }
ul.plain li { margin: 2px 0; }

.note {
  background: var(--warn-bg); color: var(--warn-ink); border-radius: 8px;
  padding: 10px 12px; font-size: 14px; margin: 0 0 14px;
}
.pics { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 0 0 14px; }
.pics-label { font-size: 13px; color: var(--muted); }
a.btn { text-decoration: none; color: var(--text); }
.steps-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.steps-head .bar { flex: 1 1 120px; height: 6px; margin: 0; }
.steps-head .count { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
ol.steps { list-style: none; margin: 0; padding: 0; counter-reset: s; }
ol.steps li {
  counter-increment: s; display: grid; grid-template-columns: 34px 1fr; gap: 10px;
  padding: 10px 0; border-bottom: 1px solid var(--line);
}
ol.steps li:last-child { border-bottom: none; }
ol.steps label { display: contents; cursor: pointer; }
ol.steps .num {
  width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center;
  background: var(--surface-2); border: 1px solid var(--line); font-weight: 700; font-size: 13px;
}
ol.steps .num::before { content: counter(s); }
ol.steps input { position: absolute; opacity: 0; pointer-events: none; }
ol.steps input:checked ~ .num { background: var(--done); border-color: var(--done); color: var(--surface); }
ol.steps input:checked ~ .num::before { content: "\2713"; }
ol.steps input:checked ~ .txt .main { color: var(--muted); text-decoration: line-through; text-decoration-color: color-mix(in srgb, var(--muted) 50%, transparent); }
ol.steps input:focus-visible ~ .num { outline: 2px solid var(--accent); outline-offset: 2px; }
.txt .tip { display: block; font-size: 13px; color: var(--warn-ink); background: var(--warn-bg); border-radius: 6px; padding: 4px 8px; margin-top: 6px; }
.conf { font-size: 12px; color: var(--muted); margin-top: 12px; }

.sources li { margin: 6px 0; }
.sources .kind { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin-right: 6px; }

.form { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(200px, 100%), 1fr)); gap: 12px 16px; }
.form label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.form label.check { flex-direction: row; align-items: center; gap: 8px; color: var(--text); font-size: 14px; }
.form .full { grid-column: 1 / -1; }
.form-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 14px; flex-wrap: wrap; }
.saved { font-size: 13px; color: var(--done); align-self: center; margin-right: auto; opacity: 0; transition: opacity .2s; }
.saved.show { opacity: 1; }
.lookup { display: flex; flex-wrap: wrap; gap: 10px 12px; align-items: flex-end; padding: 12px; border: 1px dashed var(--line); border-radius: 8px; background: var(--surface-2); }
.lookup label { flex: 1 1 140px; }
.lookup label[hidden] { display: none; }
.lookup label.btn { flex: none; flex-direction: row; color: var(--text); font-size: inherit; }
.lookup.find { margin: 0 0 16px; }
.choices { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(250px, 100%), 1fr)); gap: 10px; }
.choices[hidden] { display: none; }
.choice {
  display: flex; gap: 10px; align-items: flex-start; text-align: left; padding: 10px; font: inherit;
  border: 1px solid var(--line); border-radius: 8px; background: var(--surface); color: var(--text); cursor: pointer;
}
.choice:hover, .choice:focus-visible { border-color: var(--accent); }
.choice[aria-pressed=true] { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.choice:disabled { cursor: default; }
.choice:disabled:not([aria-pressed=true]) { opacity: .45; }
.choice img, .choice .ph { width: 88px; height: 88px; object-fit: contain; background: var(--photo-bg); border-radius: 6px; flex: none; }
.choice .ph { display: grid; place-items: center; font-size: 34px; }
.choice .sub { display: block; font-size: 12px; color: var(--muted); margin-top: 2px; }
.choices .none { grid-column: 1 / -1; justify-self: start; white-space: normal; text-align: left; max-width: 100%; }
.price-results { margin: 0 0 22px; padding-bottom: 16px; border-bottom: 1px solid var(--line); }
.price-results h3 { margin-top: 0; }
h3 .checked { font-weight: 400; font-size: 12px; color: var(--muted); margin-left: 6px; }
.offers { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.offers a {
  display: flex; gap: 12px; align-items: center; padding: 10px 12px;
  border: 1px solid var(--line); border-radius: 8px; background: var(--surface); color: var(--text); text-decoration: none;
}
.offers a:hover { border-color: var(--fig); }
.offers li:first-child a { border-color: color-mix(in srgb, var(--done) 60%, var(--line)); }
.offers .o-price { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; min-width: 86px; }
.offers .o-body { flex: 1; min-width: 0; font-size: 14px; }
.offers .o-title { display: block; font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.offers .o-go { color: var(--muted); }
.toast {
  position: fixed; left: 50%; bottom: 20px; transform: translate(-50%, 20px); z-index: 20;
  max-width: min(520px, calc(100vw - 32px)); padding: 10px 16px; border-radius: 10px;
  background: var(--text); color: var(--bg); font-size: 14px; box-shadow: var(--shadow);
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.lookup .lookup-msg { flex: 1 1 100%; font-size: 13px; color: var(--muted); display: flex; gap: 10px; align-items: center; }
.lookup .lookup-msg.err { color: var(--accent); }
.lookup .lookup-msg img { width: 56px; height: 56px; object-fit: contain; background: var(--photo-bg); border-radius: 6px; flex: none; }

footer { color: var(--muted); font-size: 13px; padding: 10px 0 40px; border-top: 1px solid var(--line); }

@media (max-width: 560px) {
  .brand h1 { font-size: 22px; }
  .dlg-head, .tabs, .dlg-body { padding-left: 14px; padding-right: 14px; }
}
@media print {
  header.top, .toolbar, .grid, footer, .tabs, .dlg-head .x, .steps-head .btn { display: none !important; }
  dialog { position: static; box-shadow: none; width: 100%; max-height: none; }
  .dlg, .dlg-body { max-height: none; overflow: visible; }
  body { background: #fff; }
}

/* ---- Website additions (appended by tools/extract-figures.js) ---- */

/* Save status in the toolbar */
.save-state { font-size: 13px; color: var(--muted); white-space: nowrap; }
.save-state.ok { color: var(--done); }
.save-state.err { color: var(--warn-ink); background: var(--warn-bg); border-radius: 8px; padding: 6px 10px; font-weight: 600; cursor: pointer; border: none; }

/* Sign-in page */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.login form {
  width: min(380px, 100%); background: var(--surface); border: 1px solid var(--line); border-radius: 14px;
  box-shadow: var(--shadow); padding: 26px 24px 22px; display: flex; flex-direction: column; gap: 14px;
  border-top: 6px solid var(--accent);
}
.login h1 { font-size: 22px; line-height: 1.2; margin: 0; }
.login p { margin: 0; color: var(--muted); font-size: 14px; }
.login label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.login .btn.primary { padding: 10px 12px; }
.login .btn:disabled { opacity: .6; cursor: default; }
.login .msg { min-height: 1.4em; font-size: 13px; color: var(--muted); }
.login .msg.err { color: var(--accent); }
.boot { color: var(--muted); padding: 60px 0; text-align: center; grid-column: 1 / -1; }

/* Toolbar: on a computer the filters sit in the row; on a phone they fold behind "Filters" */
.tool-more { display: contents; }
.filters-btn { display: none; }

/* "Scan the box" in Add a figure */
.scan { display: flex; flex-wrap: wrap; gap: 10px 12px; align-items: center; padding: 12px;
  border: 1px solid color-mix(in srgb, var(--accent) 40%, var(--line)); border-radius: 8px; background: var(--surface); }
.scan .btn { font-weight: 600; }
.scan .lookup-msg { flex: 1 1 220px; font-size: 13px; color: var(--muted); }
.scan .lookup-msg.err { color: var(--accent); }
.scan img { width: 56px; height: 56px; object-fit: cover; border-radius: 6px; flex: none; }

/* Sources tab: paste your own video link */
.add-video { display: flex; gap: 8px; flex-wrap: wrap; margin: 0 0 14px; }
.add-video input { flex: 1 1 260px; }
.sources .chip { margin-left: 4px; }

/* Phones */
@media (max-width: 640px) {
  header.top { padding: 14px 0 4px; }
  .brand { gap: 8px; }
  .brand h1 { font-size: 20px; flex: 1 1 100%; }
  .brand .spacer { display: none; }
  .brand .btn { padding: 5px 10px; font-size: 13px; }
  .views { margin-top: 10px; }
  .view { padding: 8px 10px; font-size: 15px; }
  .stats { gap: 6px 12px; font-size: 13px; }

  .toolbar { gap: 6px; padding: 8px 0; }
  .toolbar input[type=search] { flex: 1 1 100%; }
  .filters-btn { display: inline-block; }
  .tool-more { display: none; }
  .toolbar.open .tool-more { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; flex: 1 1 100%; order: 5; }
  .toolbar .btn { padding: 7px 11px; }
  .toolbar #addBtn { flex: 1 1 auto; }
  .save-state { font-size: 12px; }
  /* 16px text stops iPhones zooming in when a field is tapped */
  input, select, textarea { font-size: 16px; }

  /* Cards become rows: photo on the left, details on the right */
  .grid { grid-template-columns: 1fr; gap: 10px; padding: 12px 0 30px; }
  .card { display: grid; grid-template-columns: 108px 1fr; }
  .card .band { grid-column: 1 / -1; height: 4px; }
  .card .thumb { aspect-ratio: auto; min-height: 108px; border-bottom: none; border-right: 1px solid var(--line); }
  .card .thumb img { padding: 6px; }
  .card:hover { transform: none; }
  .card:hover .thumb img { transform: none; }
  .thumb.noimg .fallback { font-size: 40px; }
  .card .body { padding: 10px 12px 12px; gap: 6px; }
  .card .h { font-size: 16px; }
  .group-h { margin-top: 8px; }

  /* A figure opens full screen */
  dialog { width: 100vw; max-width: 100vw; height: 100dvh; max-height: 100dvh; margin: 0; border-radius: 0; }
  .dlg { height: 100%; max-height: 100dvh; }
  .dlg-body { flex: 1; }
  .dlg-head { padding-top: 12px; gap: 10px; }
  .dlg-head h2 { font-size: 19px; }
  .dlg-head .mono { width: 44px; height: 44px; }
  .tabs { padding-top: 6px; }
  .tab { padding: 10px 12px; }
  .gallery { grid-template-columns: 1fr 1fr; gap: 8px; }
  .fromto figure { max-width: none; }
  .lookup .btn, .scan .btn { flex: 1 1 auto; }
  .pics .btn { flex: 1 1 auto; text-align: center; }
  ol.steps li { padding: 12px 0; }
  .offers .o-price { min-width: 70px; font-size: 18px; }
  .toast { bottom: 12px; }
}
