:root {
  --bg: #faf8f5;
  --surface: #ffffff;
  --text: #1c1917;
  --muted: #6b645c;
  --line: #e7e2db;
  --accent: #d9480f;
  --accent-text: #ffffff;
  --good: #1f7a3a;
  --good-bg: #e7f5ec;
  --bad: #a8321f;
  --chip: #f1ede7;
  --radius: 12px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #151311;
    --surface: #1f1c19;
    --text: #f2eee9;
    --muted: #a39b91;
    --line: #34302b;
    --accent: #ff7a3d;
    --accent-text: #1a0d05;
    --good: #6fd08c;
    --good-bg: #173222;
    --bad: #ff8a73;
    --chip: #2a2622;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

.wrap { max-width: 1100px; margin: 0 auto; padding: 0 16px; }

.top { border-bottom: 1px solid var(--line); background: var(--surface); padding: 24px 0 16px; }
.brand { font-size: 1.6rem; font-weight: 800; color: var(--text); text-decoration: none; letter-spacing: -0.02em; }
.brand span { color: var(--accent); }
.tagline { margin: 4px 0 16px; color: var(--muted); }

.search { display: flex; gap: 8px; }
.search input {
  flex: 1; min-width: 0; padding: 12px 14px; font: inherit;
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--bg); color: var(--text);
}
.search input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.search button {
  padding: 0 20px; font: inherit; font-weight: 600; cursor: pointer;
  border: 0; border-radius: var(--radius); background: var(--accent); color: var(--accent-text);
}
.search button:disabled { opacity: 0.6; cursor: wait; }

.controls { display: flex; flex-wrap: wrap; gap: 8px 20px; margin-top: 12px; color: var(--muted); font-size: 0.92rem; }
.controls label { display: inline-flex; align-items: center; gap: 6px; }
.controls select { font: inherit; padding: 2px 6px; border-radius: 6px; border: 1px solid var(--line); background: var(--bg); color: var(--text); }

.shops { display: flex; flex-wrap: wrap; gap: 8px; margin: 20px 0 8px; }
.shop-chip { font-size: 0.85rem; padding: 4px 10px; border-radius: 999px; background: var(--chip); color: var(--muted); }
.shop-chip.ok b { color: var(--text); }
.shop-chip.err { color: var(--bad); }
.shop-chip.loading::after { content: " …"; }

.summary { color: var(--muted); margin: 8px 0 16px; min-height: 1.5em; }

.results { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 16px; padding-bottom: 24px; }
@media (max-width: 400px) { .results { grid-template-columns: 1fr; } }

.card {
  display: grid; grid-template-columns: 96px 1fr; gap: 14px; padding: 14px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
}
.card.unavailable { opacity: 0.7; }
.cover { width: 96px; aspect-ratio: 2 / 3; border-radius: 6px; overflow: hidden; background: var(--chip); }
.cover img { width: 100%; height: 100%; object-fit: cover; display: block; }
.body { min-width: 0; }
.title { margin: 0; font-size: 1rem; line-height: 1.3; }
.meta { margin: 2px 0 6px; color: var(--muted); font-size: 0.85rem; }
.best { margin: 0 0 8px; font-weight: 700; font-size: 1.15rem; }
.best small { font-weight: 400; color: var(--muted); font-size: 0.8rem; }

.offers { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.offers li { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: baseline; gap: 2px 8px; font-size: 0.9rem; }
.offers li > span:first-child { min-width: 0; }
.offers a { color: var(--text); text-decoration: none; border-bottom: 1px dotted var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.offers a:hover { color: var(--accent); border-color: var(--accent); }
.offers .price { font-variant-numeric: tabular-nums; white-space: nowrap; }
.offers .price s { color: var(--muted); font-size: 0.8rem; margin-right: 4px; }
.offers li.cheapest .price { color: var(--good); font-weight: 700; }
.offers li.out a, .offers li.out .price { color: var(--muted); }
.tag { font-size: 0.72rem; padding: 0 5px; border-radius: 4px; margin-left: 4px; background: var(--chip); color: var(--muted); white-space: nowrap; }
.tag.pre { background: var(--good-bg); color: var(--good); }

.empty { color: var(--text); max-width: 640px; padding: 16px 0 48px; }
.empty h2 { font-size: 1.1rem; }
.muted { color: var(--muted); font-size: 0.9rem; }
.error { color: var(--bad); }

.nav { display: flex; gap: 16px; margin: 6px 0 0; font-size: 0.95rem; }
.nav a { color: var(--muted); text-decoration: none; padding-bottom: 2px; border-bottom: 2px solid transparent; }
.nav a:hover { color: var(--text); }
.nav a[aria-current="page"] { color: var(--text); border-color: var(--accent); font-weight: 600; }

.filters { display: grid; gap: 10px; }
.filter-q {
  width: 100%; padding: 12px 14px; font: inherit;
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--bg); color: var(--text);
}
.filter-q:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.filter-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 18px; color: var(--muted); font-size: 0.92rem; }
.filter-row label { display: inline-flex; align-items: center; gap: 6px; }
.filter-row select, .filter-row input[type="number"] {
  font: inherit; padding: 3px 6px; border-radius: 6px;
  border: 1px solid var(--line); background: var(--bg); color: var(--text);
}
.filter-row select { max-width: 220px; }
.range { display: inline-flex; align-items: center; gap: 4px; }
.range input { width: 78px; }
.link-button { font: inherit; background: none; border: 0; padding: 0; color: var(--accent); cursor: pointer; text-decoration: underline; }

.more-wrap { display: flex; justify-content: center; padding: 0 0 48px; }
.more {
  font: inherit; font-weight: 600; padding: 10px 22px; cursor: pointer;
  border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); color: var(--text);
}
.more:hover { border-color: var(--accent); color: var(--accent); }
.results > p.muted { grid-column: 1 / -1; }

/* ---- series cards ---- */
.series-card {
  display: grid; grid-template-columns: 96px 1fr; gap: 14px; padding: 14px; text-align: left;
  font: inherit; color: inherit; cursor: pointer;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  transition: border-color 0.12s ease, transform 0.12s ease;
}
.series-card:hover { border-color: var(--accent); }
.series-card:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.series-card.unavailable { opacity: 0.7; }
.chips { display: flex; flex-wrap: wrap; gap: 4px; margin: 0; }
.chips .tag { margin-left: 0; }
.tag.sale { background: var(--good-bg); color: var(--good); }

.manual { margin: 0 0 12px; font-size: 0.9rem; color: var(--muted); }
.manual a { color: var(--accent); }
.nothing { grid-column: 1 / -1; }

/* ---- series dialog ---- */
.series-dialog {
  width: min(760px, calc(100vw - 32px)); max-height: calc(100vh - 48px); padding: 0;
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--surface); color: var(--text);
}
.series-dialog::backdrop { background: rgb(0 0 0 / 0.45); }
.dialog-body { position: relative; max-height: calc(100vh - 48px); overflow-y: auto; padding: 20px; }
.dialog-close {
  position: sticky; top: 0; float: right; width: 36px; height: 36px; margin: -8px -8px 0 8px;
  font-size: 1.5rem; line-height: 1; cursor: pointer; border-radius: 50%;
  border: 1px solid var(--line); background: var(--surface); color: var(--text);
}
.dialog-close:hover { border-color: var(--accent); color: var(--accent); }
.dialog-header { display: grid; grid-template-columns: 96px 1fr; gap: 16px; margin-bottom: 16px; }
.dialog-title { margin: 0; font-size: 1.3rem; line-height: 1.25; }
.dialog-header .manual { margin: 8px 0 0; }

.editions { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.edition { border-top: 1px solid var(--line); padding-top: 10px; }
.edition.unavailable .volume, .edition.unavailable .edition-best { color: var(--muted); }
.edition-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 10px; }
.volume { font-weight: 700; }
.edition-best { margin-left: auto; font-weight: 700; white-space: nowrap; }
.edition-title { margin: 0 0 4px; color: var(--muted); font-size: 0.82rem; }
.edition .offers { margin-top: 4px; }

@media (max-width: 480px) {
  .dialog-body { padding: 16px; }
  .dialog-header { grid-template-columns: 72px 1fr; gap: 12px; }
  .dialog-header .cover { width: 72px; }
}
