:root {
  --bg: #0b1220;
  --surface: #131c2e;
  --surface-2: #1a2540;
  --line: #243252;
  --text: #e8eef7;
  --muted: #93a1bd;
  --accent: #38bdf8;
  --green: #34d399;
  --amber: #fbbf24;
  --radius: 12px;
  --tap: 44px;
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.45;
  -webkit-text-size-adjust: 100%;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: rgba(11, 18, 32, 0.96);
  border-bottom: 1px solid var(--line);
  padding: 10px 14px 0;
  backdrop-filter: blur(6px);
}

.brand { display: flex; align-items: center; gap: 10px; }
.brand-icon { width: 38px; height: 38px; border-radius: 9px; }
.brand h1 { font-size: 18px; margin: 0; letter-spacing: 0.2px; }
.subtitle { margin: 0; color: var(--muted); font-size: 12px; }

.tabs { display: flex; gap: 4px; margin-top: 8px; }
.tab {
  flex: 1;
  min-height: var(--tap);
  background: none;
  border: none;
  border-bottom: 3px solid transparent;
  color: var(--muted);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }

main { padding: 14px; padding-bottom: 70px; max-width: 860px; margin: 0 auto; }

.foot {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 14px calc(8px + env(safe-area-inset-bottom));
  background: rgba(11, 18, 32, 0.96);
  border-top: 1px solid var(--line);
  font-size: 12px;
  color: var(--muted);
}
.offline-badge {
  color: var(--green);
  border: 1px solid var(--green);
  border-radius: 999px;
  padding: 2px 10px;
  font-weight: 600;
}

/* ---------- catalog ---------- */
.controls { display: grid; gap: 10px; margin-bottom: 12px; }
.search {
  width: 100%;
  min-height: var(--tap);
  font-size: 16px;
  padding: 10px 12px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
}
.filter-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.filter-row select, .sort-row select {
  width: 100%;
  min-height: var(--tap);
  font-size: 14px;
  padding: 8px 10px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
}
.sort-row { display: flex; gap: 10px; align-items: center; }
.sort-row label { color: var(--muted); font-size: 13px; white-space: nowrap; }
.count { color: var(--muted); font-size: 13px; margin: 6px 0 10px; }

.card {
  display: block;
  width: 100%;
  text-align: left;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  margin-bottom: 10px;
  color: var(--text);
  cursor: pointer;
}
.card:active { background: var(--surface-2); }
.card-top { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.card-model { font-weight: 700; font-size: 16px; }
.card-mfr { color: var(--muted); font-size: 13px; }
.card-specs { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-top: 8px; font-size: 13px; }
.card-specs b { color: var(--accent); font-weight: 700; }
.chip {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  color: var(--muted);
  white-space: nowrap;
}

/* ---------- detail ---------- */
.back {
  min-height: var(--tap);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--accent);
  font-size: 15px;
  font-weight: 600;
  padding: 8px 16px;
  margin-bottom: 12px;
  cursor: pointer;
}
.detail-head { margin-bottom: 4px; }
.detail-head h2 { margin: 0 0 4px; font-size: 22px; word-break: break-word; }
.detail-head .mfr { color: var(--muted); }
.stat-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin: 12px 0;
}
.stat {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 8px;
  text-align: center;
}
.stat .v { font-size: 18px; font-weight: 700; color: var(--accent); }
.stat .l { font-size: 11px; color: var(--muted); margin-top: 2px; }
.section {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  margin-bottom: 10px;
}
.section h3 { margin: 0 0 8px; font-size: 14px; text-transform: uppercase; letter-spacing: 0.6px; color: var(--muted); }
.kv { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 12px; font-size: 14px; }
.kv .k { color: var(--muted); }
.kv .v { text-align: right; word-break: break-word; }
.kv .full { grid-column: 1 / -1; }
.note { font-size: 13px; color: var(--muted); }
a { color: var(--accent); }
details.specs { margin-top: 6px; }
details.specs summary { cursor: pointer; color: var(--accent); font-size: 14px; min-height: var(--tap); display: inline-flex; align-items: center; }
.specs-table { font-size: 12px; width: 100%; border-collapse: collapse; margin-top: 6px; }
.specs-table td { border-top: 1px solid var(--line); padding: 4px 6px; vertical-align: top; word-break: break-word; }
.specs-table td:first-child { color: var(--muted); white-space: nowrap; }

/* ---------- sim ---------- */
.sim-note {
  background: var(--surface);
  border: 1px solid var(--line);
  border-left: 3px solid var(--amber);
  border-radius: var(--radius);
  padding: 10px 12px;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 12px;
}
.curve-pick { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 12px; }
.curve-toggle {
  min-height: var(--tap);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  padding: 6px 4px;
}
.curve-toggle.on { color: var(--text); border-color: var(--accent); background: var(--surface-2); }
.chart-wrap {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 8px;
  margin-bottom: 12px;
}
canvas.chart { width: 100%; height: 300px; display: block; }
.legend { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; font-size: 12px; }
.legend .swatch { display: inline-block; width: 18px; height: 4px; border-radius: 2px; margin-right: 4px; vertical-align: middle; }
.slice { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 12px; }
.slice label { font-size: 13px; color: var(--muted); display: grid; gap: 4px; }
.slice input {
  min-height: var(--tap);
  font-size: 16px;
  padding: 8px 10px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  width: 100%;
}
.slice-results { font-size: 13px; }
.slice-results table { width: 100%; border-collapse: collapse; }
.slice-results td, .slice-results th { border-top: 1px solid var(--line); padding: 6px; text-align: right; font-variant-numeric: tabular-nums; }
.slice-results th { color: var(--muted); font-weight: 600; font-size: 12px; }
.slice-results td:first-child, .slice-results th:first-child { text-align: left; }
.curve-stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin-bottom: 12px; }

/* ---------- about ---------- */
.about h2 { font-size: 18px; margin: 18px 0 6px; }
.about p, .about li { font-size: 14px; color: var(--text); }
.about .note, .about p.note { color: var(--muted); font-size: 13px; }
.about ul { padding-left: 20px; }

.loading, .error { text-align: center; padding: 40px 16px; color: var(--muted); }
.error { color: #f87171; }

@media (min-width: 640px) {
  .filter-row { grid-template-columns: repeat(4, 1fr); }
  .controls { grid-template-columns: 2fr 1fr; }
  .controls .search { grid-column: 1 / -1; }
}
