:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --surface-2: #f0efec;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --accent: #2a78d6;
  --accent-ink: #ffffff;
  --series-1: #2a78d6; --series-2: #eb6834; --series-3: #1baf7a; --series-4: #eda100;
  --series-5: #e87ba4; --series-6: #008300; --series-7: #4a3aa7; --series-8: #e34948;
  --radius: 12px;
  --font: system-ui, -apple-system, "Segoe UI", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --surface-2: #262624;
    --ink: #ffffff;
    --ink-2: #c3c2b7;
    --muted: #898781;
    --grid: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, 0.10);
    --accent: #3987e5;
    --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70; --series-4: #c98500;
    --series-5: #d55181; --series-6: #008300; --series-7: #9085e9; --series-8: #e66767;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d; --surface: #1a1a19; --surface-2: #262624;
  --ink: #ffffff; --ink-2: #c3c2b7; --muted: #898781;
  --grid: #2c2c2a; --axis: #383835; --border: rgba(255, 255, 255, 0.10); --accent: #3987e5;
  --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70; --series-4: #c98500;
  --series-5: #d55181; --series-6: #008300; --series-7: #9085e9; --series-8: #e66767;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--page);
  color: var(--ink);
  font: 16px/1.4 var(--font);
  -webkit-text-size-adjust: 100%;
}
a { color: inherit; }
button { font: inherit; color: inherit; }

.topbar {
  position: sticky; top: 0; z-index: 10;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
}
.brand { font-weight: 650; text-decoration: none; font-size: 15px; color: var(--ink-2); }
.crumbs { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; font-size: 17px; font-weight: 600; }
.crumbs a { text-decoration: none; color: var(--accent); }
.crumbs .sep { color: var(--muted); }
.crumbs span.cur { color: var(--ink); }

.view { max-width: 960px; margin: 0 auto; padding: 16px 16px calc(32px + env(safe-area-inset-bottom)); outline: none; }
.view.loading > * { opacity: 0.5; transition: opacity .15s; }

h2 { font-size: 20px; margin: 4px 0 12px; }
h3 { font-size: 13px; font-weight: 650; text-transform: uppercase; letter-spacing: .04em; color: var(--ink-2); margin: 20px 0 8px; }
.muted { color: var(--muted); }
.sub { color: var(--ink-2); font-size: 14px; }

/* Lists of tappable rows */
.list { display: grid; gap: 8px; }
.grid { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
.card {
  display: block; text-decoration: none;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 14px;
  min-height: 56px;
}
a.card:active, button.card:active { background: var(--surface-2); }
.card .title { font-weight: 600; }
.card .meta { color: var(--ink-2); font-size: 13px; margin-top: 2px; }
.card.stale { opacity: .62; }
.row { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.price { font-variant-numeric: tabular-nums; font-weight: 650; white-space: nowrap; }

.search {
  width: 100%; padding: 12px 14px; font-size: 16px;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); color: var(--ink); margin-bottom: 12px;
}
.toggle-link {
  background: none; border: 0; color: var(--accent); padding: 10px 0; cursor: pointer; font-size: 15px;
}

/* Facets */
.facet { margin-bottom: 14px; }
.facet-label { font-size: 13px; font-weight: 650; color: var(--ink-2); margin-bottom: 6px; display: flex; justify-content: space-between; }
.facet-label button { background: none; border: 0; color: var(--accent); font-size: 13px; padding: 0 2px; cursor: pointer; }
.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; scrollbar-width: none; }
.chips.wrap { flex-wrap: wrap; overflow: visible; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: 0 0 auto;
  border: 1px solid var(--border); background: var(--surface);
  border-radius: 999px; padding: 8px 14px; min-height: 40px;
  font-size: 14px; cursor: pointer; white-space: nowrap;
}
.chip .n { color: var(--muted); font-size: 12px; margin-left: 4px; }
.chip[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.chip[aria-pressed="true"] .n { color: var(--accent-ink); opacity: .8; }
.switch { display: flex; align-items: center; gap: 10px; font-size: 14px; color: var(--ink-2); margin: 4px 0 14px; }
.switch input { width: 20px; height: 20px; }
.count-line { font-size: 14px; color: var(--ink-2); margin: 6px 0 10px; }

.badges { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.badge { font-size: 12px; border-radius: 6px; padding: 2px 8px; background: var(--surface-2); color: var(--ink-2); }

/* Item result */
.item-head { margin-bottom: 8px; }
.item-head .name { font-size: 18px; font-weight: 650; }
.latest { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); }
.latest .card { padding: 12px 14px; }
.dist { display: flex; align-items: center; gap: 8px; font-size: 14px; font-weight: 600; }
.key { width: 14px; height: 3px; border-radius: 2px; flex: 0 0 auto; background: var(--muted); }
.big { font-size: 30px; font-weight: 700; margin: 4px 0 0; letter-spacing: -0.01em; }
.big small { font-size: 14px; font-weight: 500; color: var(--ink-2); margin-left: 6px; }
.range { font-size: 13px; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.tone { font-size: 13px; color: var(--ink-2); margin-top: 6px; }
.ago-old { color: var(--muted); }

.chart-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 8px 8px; }
.chart-box { position: relative; height: 320px; }
.controls { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 10px; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.seg button { border: 0; background: var(--surface); padding: 8px 12px; min-height: 38px; font-size: 14px; cursor: pointer; }
.seg button + button { border-left: 1px solid var(--border); }
.seg button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); }
.legend { display: flex; flex-wrap: wrap; gap: 6px; margin: 4px 4px 10px; }
.legend .chip { min-height: 34px; padding: 6px 12px; display: inline-flex; align-items: center; gap: 8px; }
.legend .chip[aria-pressed="false"] { opacity: .45; }
.legend .chip[aria-pressed="true"] { background: var(--surface); color: var(--ink); border-color: var(--axis); }

table.data { width: 100%; border-collapse: collapse; font-size: 14px; font-variant-numeric: tabular-nums; }
table.data th, table.data td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--grid); }
table.data td.num, table.data th.num { text-align: right; }

.msg { padding: 24px 0; color: var(--ink-2); }
.err { color: #d03b3b; }
.recent { margin-bottom: 8px; }

@media (min-width: 720px) {
  .chart-box { height: 380px; }
}
.nowrap { white-space: nowrap; }
.legend .chip { white-space: normal; text-align: left; max-width: 100%; }
.latest.compact { gap: 6px; }
.latest.compact .card { padding: 10px 12px; min-height: 0; }
.latest.compact .dist { font-weight: 600; }
.big-sm { font-size: 20px; }

/* Account menu */
.topline { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.acct { position: relative; }
.acct-btn {
  border: 1px solid var(--border); background: var(--surface); border-radius: 999px;
  padding: 6px 12px; font-size: 14px; cursor: pointer; max-width: 50vw;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.acct-menu {
  position: absolute; right: 0; top: calc(100% + 6px); min-width: 220px; z-index: 20;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(0,0,0,.18); padding: 6px; display: grid;
}
.acct-menu .who { padding: 8px 10px; font-size: 13px; color: var(--ink-2); border-bottom: 1px solid var(--grid); margin-bottom: 4px; }
.acct-menu a, .acct-menu button {
  display: block; text-align: left; padding: 10px; border-radius: 8px; text-decoration: none;
  background: none; border: 0; font-size: 15px; cursor: pointer; width: 100%;
}
.acct-menu a:hover, .acct-menu button:hover { background: var(--surface-2); }

/* Forms */
.narrow { max-width: 440px; }
.form { display: grid; gap: 14px; margin: 8px 0 16px; }
.form label { display: grid; gap: 6px; font-size: 14px; font-weight: 600; color: var(--ink-2); }
.form input, .form select {
  font: inherit; font-size: 16px; padding: 11px 12px; border-radius: 10px;
  border: 1px solid var(--axis); background: var(--surface); color: var(--ink); width: 100%;
}
.form .inline { display: flex; gap: 8px; }
.form .inline input { flex: 1; }
.form .check { display: flex; align-items: center; gap: 10px; font-weight: 500; }
.form .check input { width: 20px; height: 20px; }
.btn {
  font: inherit; font-size: 15px; font-weight: 600; padding: 11px 16px; min-height: 44px;
  border-radius: 10px; border: 1px solid var(--axis); background: var(--surface); color: var(--ink); cursor: pointer;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.danger { color: #d03b3b; border-color: #d03b3b; }
.btn:disabled { opacity: .5; cursor: default; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0; }
.form-error { color: #d03b3b; background: rgba(208,59,59,.08); border-radius: 10px; padding: 10px 12px; margin: 8px 0; }
.form-ok { color: var(--ink); background: rgba(12,163,12,.10); border-radius: 10px; padding: 10px 12px; margin: 8px 0; }
.notice { background: var(--surface-2); border-radius: 10px; padding: 10px 12px; margin: 8px 0 12px; font-size: 14px; }
.secret { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 15px; user-select: all; }
.tag { font-size: 11px; font-weight: 650; text-transform: uppercase; letter-spacing: .04em; border-radius: 6px; padding: 2px 7px; background: var(--surface-2); color: var(--ink-2); }
.tag.admin { background: var(--accent); color: var(--accent-ink); }
.tag.off { background: #d03b3b; color: #fff; }
.tag.warn { background: #fab219; color: #0b0b0b; }
.events { font-size: 13px; }
.events td { vertical-align: top; }
[hidden] { display: none !important; }
