:root {
  --bg: #f6f5f1;
  --surface: #ffffff;
  --surface-2: #efeee9;
  --text: #1c1d1f;
  --muted: #6a6c70;
  --line: #e2e0d9;
  --accent: #1f7a5a;
  --accent-soft: #e1f0e9;
  --up: #b4362a;
  --down: #1f7a5a;
  --promo: #8a5a00;
  --promo-soft: #fbefd6;
  --focus: #2f6fd6;
  --s0: #1f7a5a; --s1: #2f6fd6; --s2: #c2541b; --s3: #8a4fc2; --s4: #b3902a; --s5: #c23d74;
  --radius: 12px;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.05);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16181c;
    --surface: #1f2227;
    --surface-2: #282c32;
    --text: #e9e9ea;
    --muted: #9b9ea4;
    --line: #33373e;
    --accent: #4cc493;
    --accent-soft: #1d3a2f;
    --up: #f07a6c;
    --down: #4cc493;
    --promo: #f0c060;
    --promo-soft: #3a3020;
    --focus: #7aa7f5;
    --s0: #4cc493; --s1: #7aa7f5; --s2: #f08a52; --s3: #b88cf0; --s4: #e0c060; --s5: #f07aa8;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: env(safe-area-inset-bottom);
}
a { color: inherit; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
[hidden] { display: none !important; }

.wrap { max-width: 860px; margin: 0 auto; padding: 16px; }

/* ---------- header ---------- */
.top {
  position: sticky; top: 0; z-index: 5;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
  padding-top: env(safe-area-inset-top);
}
.top-inner { max-width: 860px; margin: 0 auto; padding: 10px 16px; display: flex; align-items: center; gap: 16px; }
.brand { font-weight: 700; text-decoration: none; letter-spacing: -0.01em; }
.tabs { display: flex; gap: 4px; flex: 1; }
.tabs a { text-decoration: none; padding: 6px 12px; border-radius: 999px; color: var(--muted); font-weight: 500; }
.tabs a[aria-current="page"] { background: var(--surface-2); color: var(--text); }
.icon-btn { background: none; border: 0; color: var(--muted); font: inherit; font-size: 0.85rem; cursor: pointer; padding: 6px; }

/* ---------- controls ---------- */
.controls { display: grid; gap: 8px; grid-template-columns: 1fr; margin-bottom: 12px; }
@media (min-width: 640px) { .controls { grid-template-columns: 1fr 200px 200px; } }
input[type="search"], input[type="password"], select {
  width: 100%; font: inherit; color: var(--text);
  background: var(--surface); border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 12px; min-height: 44px;
}
select { appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 32px; }
.btn {
  font: inherit; font-weight: 600; border: 0; border-radius: 10px; min-height: 44px; padding: 10px 16px;
  background: var(--accent); color: #fff; cursor: pointer;
}
@media (prefers-color-scheme: dark) { .btn { color: #0d1f18; } }
.summary-line { margin: 4px 2px 12px; font-size: 0.9rem; color: var(--muted); display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.linkish { background: none; border: 0; padding: 0; font: inherit; color: var(--accent); cursor: pointer; text-decoration: underline; }

/* ---------- cards / lists ---------- */
.list { list-style: none; margin: 0; padding: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.list > li + li { border-top: 1px solid var(--line); }
.row { display: flex; gap: 12px; align-items: center; padding: 12px 14px; text-decoration: none; min-height: 60px; }
.row:hover { background: var(--surface-2); }
.row-main { flex: 1; min-width: 0; }
.row-title { font-weight: 600; overflow-wrap: anywhere; }
.row-sub { font-size: 0.85rem; color: var(--muted); }
.row-end { text-align: right; flex-shrink: 0; }
.price { font-weight: 700; font-variant-numeric: tabular-nums; }
.price.big { font-size: 1.6rem; letter-spacing: -0.01em; }

.badge { display: inline-block; font-size: 0.72rem; font-weight: 600; padding: 1px 7px; border-radius: 999px; vertical-align: 1px; white-space: nowrap; }
.badge.pref { background: var(--accent-soft); color: var(--accent); }
.badge.promo { background: var(--promo-soft); color: var(--promo); }
.badge.best { background: var(--accent); color: #fff; }
@media (prefers-color-scheme: dark) { .badge.best { color: #0d1f18; } }
.chg.up { color: var(--up); }
.chg.down { color: var(--down); }

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin-bottom: 16px; }
.panel h2 { font-size: 1rem; margin: 0 0 12px; }
h1 { font-size: 1.45rem; line-height: 1.25; margin: 4px 0 4px; letter-spacing: -0.01em; overflow-wrap: anywhere; }
.back { display: inline-block; margin: 0 0 8px; color: var(--muted); text-decoration: none; font-size: 0.9rem; }
.facts { display: flex; flex-wrap: wrap; gap: 6px 14px; color: var(--muted); font-size: 0.9rem; margin-bottom: 16px; }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 16px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; }
.stat-label { font-size: 0.75rem; color: var(--muted); }
.stat-value { font-weight: 700; font-size: 1.1rem; font-variant-numeric: tabular-nums; }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; margin: 0 -16px; padding: 0 16px; }
table { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
th, td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 0.75rem; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
td.r, th.r { text-align: right; }
tr:last-child td { border-bottom: 0; }
tr.best td:first-child { box-shadow: inset 3px 0 0 var(--accent); padding-left: 10px; }

/* ---------- chart ---------- */
.chart svg { width: 100%; height: auto; display: block; overflow: visible; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .axis { fill: var(--muted); font-size: 11px; }
.chart .series { fill: none; stroke-width: 2.25; stroke-linejoin: round; }
.chart .dot { stroke: var(--surface); stroke-width: 1.5; }
.chart .dot.promo { stroke: var(--promo); stroke-width: 2; }
.legend { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; font: inherit; font-size: 0.85rem;
  border: 1px solid var(--line); background: var(--surface); color: var(--text);
  border-radius: 999px; padding: 4px 10px; cursor: pointer; min-height: 32px;
}
.chip[aria-pressed="false"] { opacity: 0.45; }
.swatch { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.c0 { stroke: var(--s0); fill: var(--s0); background: var(--s0); }
.c1 { stroke: var(--s1); fill: var(--s1); background: var(--s1); }
.c2 { stroke: var(--s2); fill: var(--s2); background: var(--s2); }
.c3 { stroke: var(--s3); fill: var(--s3); background: var(--s3); }
.c4 { stroke: var(--s4); fill: var(--s4); background: var(--s4); }
.c5 { stroke: var(--s5); fill: var(--s5); background: var(--s5); }
.chart .series.c0, .chart .series.c1, .chart .series.c2, .chart .series.c3, .chart .series.c4, .chart .series.c5 { fill: none; }

/* ---------- states ---------- */
.empty, .error, .loading { text-align: center; padding: 32px 16px; color: var(--muted); }
.error { color: var(--up); }
.loading::after { content: "…"; }
.keybox { max-width: 420px; margin: 40px auto; }
.keybox form { display: grid; gap: 10px; }
.keybox p { color: var(--muted); font-size: 0.92rem; }
.nowrap { white-space: nowrap; }

/* ---------- promos ---------- */
.was { color: var(--muted); font-size: 0.85em; font-weight: 400; margin-right: 2px; }
.stat-sub { font-size: 0.75rem; margin-top: 2px; }
.note { font-size: 0.88rem; margin: 12px 0 0; padding: 10px 12px; border-radius: 10px; }
.promo-note { background: var(--promo-soft); color: var(--text); }
