:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface-2: #eef1f5;
  --line: #dde2e9;
  --text: #121821;
  --muted: #5b6573;
  --accent: #2563eb;
  --accent-soft: #e3ecff;
  --ok: #138a4b;
  --ok-soft: #dcf5e7;
  --warn: #a15c00;
  --warn-soft: #fdf0d9;
  --bad: #c22a33;
  --bad-soft: #fde3e4;
  --reuse: #7c3aed;
  --reuse-soft: #efe7ff;
  --viewer-bg: radial-gradient(120% 90% at 50% 10%, #ffffff 0%, #e6eaf0 70%);
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 8px 24px rgba(16, 24, 40, .06);
  --mono: 'JetBrains Mono', ui-monospace, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0d1117;
    --surface: #151b23;
    --surface-2: #1b232d;
    --line: #2a3441;
    --text: #e8edf3;
    --muted: #94a1b2;
    --accent: #5b9dff;
    --accent-soft: #17273f;
    --ok: #4ad38a;
    --ok-soft: #12301f;
    --warn: #f3b44f;
    --warn-soft: #33260f;
    --bad: #ff6b72;
    --bad-soft: #3a171a;
    --reuse: #b28cff;
    --reuse-soft: #261b3d;
    --viewer-bg: radial-gradient(120% 90% at 50% 10%, #1d2632 0%, #0f141b 70%);
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .25);
  }
}
:root[data-theme="dark"] {
  --bg: #0d1117; --surface: #151b23; --surface-2: #1b232d; --line: #2a3441; --text: #e8edf3; --muted: #94a1b2;
  --accent: #5b9dff; --accent-soft: #17273f; --ok: #4ad38a; --ok-soft: #12301f; --warn: #f3b44f; --warn-soft: #33260f;
  --bad: #ff6b72; --bad-soft: #3a171a; --reuse: #b28cff; --reuse-soft: #261b3d;
  --viewer-bg: radial-gradient(120% 90% at 50% 10%, #1d2632 0%, #0f141b 70%);
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { overflow-x: hidden; }
body {
  background: var(--bg); color: var(--text);
  font: 15px/1.5 Inter, system-ui, -apple-system, 'Segoe UI', sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0; line-height: 1.2; letter-spacing: -0.01em; }
button { font: inherit; color: inherit; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 16px;
  padding: 10px 24px; background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--text); white-space: nowrap; }
.brand:hover { text-decoration: none; }
.brand-mark {
  width: 26px; height: 26px; border-radius: 7px;
  background: conic-gradient(from 210deg, var(--accent), var(--reuse), var(--accent));
  box-shadow: inset 0 0 0 6px var(--bg);
}
.brand-text { font-size: 15px; }
.brand-text span { color: var(--muted); }
.tabs { display: flex; gap: 4px; margin-left: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs a {
  padding: 7px 12px; border-radius: 9px; color: var(--muted); font-weight: 500; font-size: 14px;
}
.tabs a:hover { background: var(--surface-2); text-decoration: none; color: var(--text); }
.tabs a.active { background: var(--accent-soft); color: var(--accent); }
.lang { display: flex; border: 1px solid var(--line); border-radius: 9px; overflow: hidden; }
.lang button { border: 0; background: transparent; padding: 6px 10px; font-size: 13px; font-weight: 600; cursor: pointer; color: var(--muted); }
.lang button.active { background: var(--text); color: var(--bg); }

main { max-width: 1440px; margin: 0 auto; padding: 24px; }

/* ---------- home ---------- */
.hero { display: grid; grid-template-columns: 1.3fr 1fr; gap: 24px; align-items: end; margin: 8px 0 28px; }
.hero h1 { font-size: clamp(26px, 3.4vw, 40px); font-weight: 700; }
.hero p { color: var(--muted); max-width: 62ch; margin: 10px 0 0; }
.hero-facts { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.fact { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.fact b { display: block; font-size: 20px; font-variant-numeric: tabular-nums; }
.fact span { color: var(--muted); font-size: 12.5px; }

.group { margin: 26px 0 8px; }
.group-head { display: flex; align-items: baseline; gap: 10px; margin-bottom: 12px; }
.group-head h2 { font-size: 18px; }
.group-head small { color: var(--muted); }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px; }
.card {
  display: flex; flex-direction: column; gap: 10px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; color: var(--text); box-shadow: var(--shadow); transition: transform .15s, border-color .15s;
}
.card:hover { text-decoration: none; transform: translateY(-2px); border-color: var(--accent); }
.card h3 { font-size: 16px; }
.card p { margin: 0; color: var(--muted); font-size: 13.5px; }
.card-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: auto; padding-top: 10px; border-top: 1px solid var(--line); }
.card-stats div { font-size: 12px; color: var(--muted); }
.card-stats b { display: block; color: var(--text); font-size: 14.5px; font-variant-numeric: tabular-nums; }
.card-icon { height: 74px; border-radius: 10px; background: var(--surface-2); display: grid; place-items: center; overflow: hidden; }
.card-icon svg { width: 100%; height: 100%; }

/* ---------- badges ---------- */
.badge { display: inline-flex; align-items: center; gap: 5px; font-size: 11.5px; font-weight: 600; padding: 2px 8px; border-radius: 999px; white-space: nowrap; }
.b-ok { background: var(--ok-soft); color: var(--ok); }
.b-warn { background: var(--warn-soft); color: var(--warn); }
.b-bad { background: var(--bad-soft); color: var(--bad); }
.b-reuse { background: var(--reuse-soft); color: var(--reuse); }
.b-muted { background: var(--surface-2); color: var(--muted); }
.b-accent { background: var(--accent-soft); color: var(--accent); }

/* ---------- detail ---------- */
.switcher { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 6px; margin: -6px 0 16px; scrollbar-width: none; }
.switcher::-webkit-scrollbar { display: none; }
.switcher a { flex: none; padding: 6px 11px; border-radius: 999px; border: 1px solid var(--line); color: var(--muted); font-size: 13px; background: var(--surface); }
.switcher a:hover { text-decoration: none; color: var(--text); }
.switcher a.active { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }

.detail { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(360px, 1fr); gap: 20px; align-items: start; }
.viewer-wrap {
  min-width: 0;
  position: sticky; top: 72px;
  border-radius: var(--radius); overflow: hidden; border: 1px solid var(--line);
  background: var(--viewer-bg); height: calc(100vh - 110px); min-height: 460px;
}
#viewer { position: absolute; inset: 0; }
#viewer canvas { display: block; width: 100%; height: 100%; touch-action: none; cursor: grab; }
#viewer canvas:active { cursor: grabbing; }
.viewer-ui {
  position: absolute; left: 12px; right: 12px; bottom: 12px;
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  background: color-mix(in srgb, var(--surface) 88%, transparent); backdrop-filter: blur(8px);
  border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px;
}
.viewer-ui label { font-size: 13px; font-weight: 600; white-space: nowrap; }
.viewer-ui input[type=range] { flex: 1; min-width: 140px; accent-color: var(--accent); }
.vbtn { border: 1px solid var(--line); background: var(--surface); border-radius: 8px; padding: 6px 10px; font-size: 13px; cursor: pointer; }
.vbtn:hover { border-color: var(--accent); }
.vbtn.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.viewer-hint { position: absolute; top: 12px; left: 12px; font-size: 12px; color: var(--muted); background: color-mix(in srgb, var(--surface) 80%, transparent); padding: 4px 9px; border-radius: 8px; border: 1px solid var(--line); }
.viewer-fallback { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); padding: 24px; text-align: center; }

.panel { display: flex; flex-direction: column; gap: 16px; }
.panel-head h1 { font-size: 24px; margin: 6px 0 6px; }
.panel-head p { margin: 0; color: var(--muted); }
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 11px 13px; }
.stat span { font-size: 12px; color: var(--muted); display: block; }
.stat b { font-size: 18px; font-variant-numeric: tabular-nums; }
.stat small { display: block; color: var(--muted); font-size: 12px; margin-top: 2px; }

.budget { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 12px 13px; }
.budget-top { display: flex; justify-content: space-between; font-size: 13px; margin-bottom: 8px; gap: 8px; flex-wrap: wrap; }
.bar { position: relative; height: 10px; background: var(--surface-2); border-radius: 999px; overflow: visible; }
.bar-fill { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 999px; background: var(--accent); }
.bar-band { position: absolute; top: -4px; bottom: -4px; border-left: 2px dashed var(--ok); border-right: 2px dashed var(--ok); background: color-mix(in srgb, var(--ok) 12%, transparent); }
.bar-scale { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); margin-top: 6px; font-family: var(--mono); }

.box { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 14px; }
.box h3 { font-size: 14px; margin-bottom: 8px; }
.proscons { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.proscons ul { margin: 0; padding-left: 18px; font-size: 13.5px; }
.proscons li { margin: 4px 0; }
.pros h3 { color: var(--ok); }
.risks h3 { color: var(--warn); }

.bom { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.bom th { text-align: left; color: var(--muted); font-weight: 500; font-size: 12px; padding: 6px 8px; border-bottom: 1px solid var(--line); }
.bom td { padding: 9px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
.bom tr.row { cursor: pointer; }
.bom tr.row:hover td { background: var(--surface-2); }
.bom tr.row.sel td { background: var(--accent-soft); }
.bom td.q { font-family: var(--mono); color: var(--muted); white-space: nowrap; width: 1%; }
.bom td.p { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; width: 1%; }
.bom .pname { font-weight: 600; }
.bom .pcat { font-size: 12px; color: var(--muted); }
.bom tr.stores-row td { background: var(--surface-2); padding: 10px 12px 14px; }
.bom tfoot td { font-weight: 700; border-bottom: 0; }

.stores { display: grid; gap: 6px; }
.store {
  display: grid; grid-template-columns: minmax(0, 1fr) auto auto; gap: 10px; align-items: center;
  background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px;
}
.store-name { font-weight: 600; font-size: 13.5px; color: var(--text); }
.store-meta { font-size: 12px; color: var(--muted); display: flex; gap: 6px; flex-wrap: wrap; align-items: center; margin-top: 2px; }
.cc { font-family: var(--mono); font-size: 11px; padding: 1px 5px; border-radius: 5px; background: var(--surface-2); color: var(--muted); }
.store-price { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; white-space: nowrap; }
.store-price small { display: block; font-weight: 400; color: var(--muted); font-size: 11.5px; }
.store-go { padding: 6px 10px; border-radius: 8px; background: var(--accent); color: #fff; font-size: 12.5px; font-weight: 600; white-space: nowrap; }
.store-go:hover { text-decoration: none; filter: brightness(1.08); }
.store.cheapest { border-color: var(--ok); box-shadow: inset 3px 0 0 var(--ok); }
.store-note { font-size: 12px; color: var(--muted); }
.part-desc { font-size: 13px; color: var(--muted); margin: 0 0 10px; }
.alts { font-size: 12.5px; margin: 8px 0 0; color: var(--muted); }
.alts a { margin-right: 8px; }
.empty-stores { font-size: 13px; color: var(--muted); }

/* ---------- compare ---------- */
.page-head { margin: 4px 0 20px; }
.page-head h1 { font-size: 26px; }
.page-head p { color: var(--muted); margin: 6px 0 0; max-width: 70ch; }
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.cmp { width: 100%; border-collapse: collapse; font-size: 13.5px; min-width: 860px; }
.cmp th, .cmp td { padding: 11px 12px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
.cmp th { font-size: 12px; color: var(--muted); font-weight: 500; background: var(--surface-2); position: sticky; top: 0; }
.cmp td.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.cmp tr:last-child td { border-bottom: 0; }
.cmp a.cname { font-weight: 600; color: var(--text); }
.chart { margin-top: 22px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; }
.chart h2 { font-size: 16px; margin-bottom: 4px; }
.chart > p { color: var(--muted); font-size: 13px; margin: 0 0 14px; }
.crow { display: grid; grid-template-columns: 220px 1fr 110px; gap: 12px; align-items: center; padding: 6px 0; font-size: 13px; }
.crow .cl { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ctrack { position: relative; height: 18px; }
.cband { position: absolute; top: -3px; bottom: -3px; background: color-mix(in srgb, var(--ok) 14%, transparent); border-left: 1px dashed var(--ok); border-right: 1px dashed var(--ok); }
.cbar { position: absolute; left: 0; top: 3px; height: 12px; border-radius: 0 4px 4px 0; background: var(--accent); }
.cbar.reuse { background: var(--reuse); }
.cbar.over { background: var(--bad); }
.cv { text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- shops ---------- */
.shops-tools { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 18px; }
.search { flex: 1; min-width: 220px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); color: var(--text); font: inherit; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 6px 11px; font-size: 13px; cursor: pointer; color: var(--muted); }
.chip.on { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
.shop-cat { margin: 22px 0 10px; font-size: 15px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.shop-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(420px, 1fr)); gap: 14px; }
.pcard { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 15px; }
.pcard h3 { font-size: 15px; margin-bottom: 4px; }
.pcard-top { display: flex; justify-content: space-between; gap: 8px; align-items: start; }
.pcard .uses { font-size: 12px; color: var(--muted); margin: 8px 0 0; }

.foot { max-width: 1440px; margin: 10px auto 30px; padding: 0 24px; color: var(--muted); font-size: 12.5px; }
.tip {
  position: fixed; z-index: 50; pointer-events: none; transform: translate(12px, 12px);
  background: var(--text); color: var(--bg); font-size: 12.5px; padding: 6px 9px; border-radius: 8px; max-width: 260px;
  box-shadow: var(--shadow);
}
.tip b { display: block; }
.tip span { opacity: .75; }

@media (max-width: 1080px) {
  .detail { grid-template-columns: minmax(0, 1fr); }
  .viewer-wrap { position: relative; top: 0; height: 58vh; min-height: 360px; }
  .hero { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
  main { padding: 16px; }
  .topbar { padding: 10px 16px; gap: 10px; flex-wrap: wrap; }
  .brand-text span { display: none; }
  .tabs { order: 3; width: 100%; margin-left: 0; overflow-x: auto; }
  .lang { margin-left: auto; }
  .hero-facts { grid-template-columns: 1fr 1fr 1fr; }
  .fact b { font-size: 16px; }
  .proscons { grid-template-columns: 1fr; }
  .stats { grid-template-columns: 1fr 1fr; }
  .shop-grid { grid-template-columns: 1fr; }
  .store { grid-template-columns: 1fr auto; }
  .store-go { grid-column: 1 / -1; text-align: center; }
  .crow { grid-template-columns: 1fr 80px; }
  .crow .ctrack { grid-column: 1 / -1; order: 3; }
  .viewer-ui { left: 8px; right: 8px; bottom: 8px; padding: 8px; gap: 6px 8px; }
  .viewer-ui input[type=range] { min-width: 0; flex-basis: 50%; }
  .vbtn { padding: 5px 8px; font-size: 12px; }
  .viewer-hint { display: none; }
  .foot { padding: 0 16px; }
}

.group-note { color: var(--muted); font-size: 13.5px; margin: -4px 0 14px; max-width: 90ch; }
.group-rec { background: color-mix(in srgb, var(--ok) 6%, transparent); border: 1px solid color-mix(in srgb, var(--ok) 35%, transparent); border-radius: calc(var(--radius) + 4px); padding: 16px; }
.card-rec { border-color: color-mix(in srgb, var(--ok) 40%, var(--line)); }
.card-top { border: 2px solid var(--ok); box-shadow: 0 0 0 4px color-mix(in srgb, var(--ok) 15%, transparent), var(--shadow); }
.b-top { background: var(--ok); color: #fff; }
