:root {
  color-scheme: light;
  --bg: #faf6f1;
  --surface: #fffdfa;
  --ink: #2a1d14;
  --ink-2: #6b5a4c;
  --muted: #8f7f71;
  --line: #eadfd3;
  --accent: #8a4b22;
  --accent-ink: #fffaf4;
  --accent-soft: #f3e4d3;
  --bar: #d6c6b6;
  --nodata: #e6e3df;
  --map-lo: #e8cba6;
  --map-hi: #4f260e;
  --danger: #b3261e;
  --radius: 16px;
  --shadow: 0 1px 2px rgb(60 30 10 / .06), 0 4px 16px rgb(60 30 10 / .06);
  --tabbar-h: 64px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #16120f;
    --surface: #211b16;
    --ink: #f3ebe2;
    --ink-2: #c4b5a6;
    --muted: #978776;
    --line: #3a2f26;
    --accent: #d99256;
    --accent-ink: #1d130b;
    --accent-soft: #3a2a1d;
    --bar: #54463a;
    --nodata: #2c2520;
    --map-lo: #4a3628;
    --map-hi: #f6c48f;
    --danger: #f2827a;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #16120f; --surface: #211b16; --ink: #f3ebe2; --ink-2: #c4b5a6; --muted: #978776; --line: #3a2f26;
  --accent: #d99256; --accent-ink: #1d130b; --accent-soft: #3a2a1d; --bar: #54463a; --nodata: #2c2520;
  --map-lo: #4a3628; --map-hi: #f6c48f; --danger: #f2827a; --shadow: none;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
h2 { font-size: 1.5rem; margin: 8px 0 16px; letter-spacing: -.01em; }
h3 { font-size: 1rem; }
.sub { margin: 2px 0 12px; color: var(--ink-2); font-size: .875rem; }
.note { margin: 12px 0 0; color: var(--ink-2); font-size: .875rem; }
button, input, select { font: inherit; color: inherit; }

/* ---------- Auth ---------- */
.auth { min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; }
.auth-card { width: 100%; max-width: 400px; }
.brand-big { text-align: center; margin-bottom: 24px; }
.brand-big h1 { font-size: 2rem; margin: 12px 0 8px; letter-spacing: -.02em; }
.brand-accent { color: var(--accent); }
.brand-big p { color: var(--ink-2); margin: 0; }
form label { display: block; font-size: .875rem; font-weight: 600; color: var(--ink-2); margin-bottom: 12px; }
form input, form select {
  display: block; width: 100%; margin-top: 4px; padding: 12px 14px;
  border: 1px solid var(--line); border-radius: 12px; background: var(--surface); color: var(--ink);
  font-weight: 400; font-size: 1rem;
}
form input:focus, form select:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-color: transparent; }
.error { color: var(--danger); font-size: .875rem; min-height: 1.2em; margin: 4px 0 12px; }

.btn {
  border: 1px solid var(--line); background: var(--surface); border-radius: 999px;
  padding: 12px 20px; font-weight: 600; cursor: pointer;
}
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); width: 100%; }
.btn.danger { color: var(--danger); }
.btn:disabled { opacity: .6; cursor: default; }
.link-btn { background: none; border: 0; color: var(--ink-2); text-decoration: underline; cursor: pointer; padding: 8px; font-size: .875rem; }
.link-btn:disabled { opacity: .4; text-decoration: none; cursor: default; }

.seg { display: flex; background: var(--accent-soft); border-radius: 999px; padding: 4px; margin-bottom: 20px; }
.seg button {
  flex: 1; border: 0; background: none; padding: 10px; border-radius: 999px; font-weight: 600;
  color: var(--ink-2); cursor: pointer;
}
.seg button[aria-selected="true"], .seg button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.seg.small { margin: 0; flex: none; }
.seg.small button { padding: 6px 12px; font-size: .875rem; }

/* ---------- Shell ---------- */
.topbar {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px; background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; }
.icon-btn { border: 0; background: none; padding: 0; cursor: pointer; }
.avatar {
  display: grid; place-items: center; width: 36px; height: 36px; border-radius: 50%;
  background: var(--accent); color: var(--accent-ink); font-weight: 700;
}
.views { max-width: 720px; margin: 0 auto; padding: 8px 16px calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 24px); }
.tabbar {
  position: fixed; inset: auto 0 0 0; z-index: 5; display: flex; justify-content: space-around;
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface); border-top: 1px solid var(--line);
}
.tabbar a {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--muted); text-decoration: none; font-size: .75rem; font-weight: 600;
}
.tabbar svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tabbar a[aria-current="page"] { color: var(--accent); }

.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; margin-bottom: 16px; box-shadow: var(--shadow);
}

/* ---------- Today ---------- */
.counter-wrap { text-align: center; padding: 8px 0 16px; }
.eyebrow { margin: 0; color: var(--ink-2); font-size: .875rem; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; }
.counter { display: flex; flex-direction: column; align-items: center; margin: 4px 0 16px; }
.count { font-size: clamp(5rem, 28vw, 8rem); font-weight: 800; line-height: 1; letter-spacing: -.04em; font-variant-numeric: tabular-nums; }
.count.bump { animation: bump .35s ease; }
@keyframes bump { 40% { transform: scale(1.12); } }
.count-label { color: var(--ink-2); font-weight: 600; }

.cup-btn {
  position: relative; width: 200px; height: 200px; border-radius: 50%; border: 0; cursor: pointer;
  background: var(--accent); color: var(--accent-ink); display: inline-grid; place-items: center;
  box-shadow: 0 10px 30px rgb(138 75 34 / .35), inset 0 -6px 0 rgb(0 0 0 / .12);
  transition: transform .1s ease;
  touch-action: manipulation; user-select: none;
}
.cup-btn:active { transform: scale(.95); }
.cup-btn:focus-visible { outline: 3px solid var(--ink); outline-offset: 4px; }
.cup-btn svg { width: 104px; height: 104px; margin-top: -18px; fill: none; stroke: currentColor; stroke-width: 6; stroke-linecap: round; stroke-linejoin: round; }
.cup-btn .cup, .cup-btn .saucer { fill: currentColor; stroke: none; }
.cup-btn .steam path { stroke-width: 4; opacity: .8; animation: steam 2.4s ease-in-out infinite; }
.cup-btn .steam path:nth-child(2) { animation-delay: .4s; }
.cup-btn .steam path:nth-child(3) { animation-delay: .8s; }
@keyframes steam { 0%, 100% { transform: translateY(2px); opacity: .25; } 50% { transform: translateY(-3px); opacity: .9; } }
.cup-btn .plus { position: absolute; bottom: 30px; font-weight: 800; font-size: 1.05rem; }
.floaty { position: absolute; left: 50%; top: 10px; font-weight: 800; font-size: 1.4rem; pointer-events: none; animation: floaty .9s ease-out forwards; color: var(--accent); }
@keyframes floaty { to { transform: translate(-50%, -70px); opacity: 0; } }
.today-actions { margin-top: 12px; }
.quip { color: var(--ink-2); min-height: 1.4em; margin: 4px 0 0; }
.pending { color: var(--muted); font-size: .875rem; }

.ticker { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; text-align: center; }
.ticker-num { display: block; font-size: 1.75rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.ticker-label { color: var(--ink-2); font-size: .8125rem; }

/* ---------- Stats ---------- */
.tiles { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; margin-bottom: 16px; }
@media (min-width: 560px) { .tiles { grid-template-columns: repeat(4, 1fr); } }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); }
.tile .v { font-size: 1.75rem; font-weight: 800; font-variant-numeric: tabular-nums; line-height: 1.1; }
.tile .k { color: var(--ink-2); font-size: .8125rem; font-weight: 600; }
.tile .d { color: var(--muted); font-size: .75rem; }

.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 16px; }
.filters select {
  flex: 1; min-width: 0; padding: 8px 12px; border: 1px solid var(--line); border-radius: 999px;
  background: var(--surface); font-size: .875rem;
}

.chart { width: 100%; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart text, .map text { fill: var(--muted); font-size: 11px; }
.chart .grid line { stroke: var(--line); }
.chart .axis path, .chart .axis line { stroke: none; }
.chart .bar { fill: var(--bar); }
.chart .bar.hi { fill: var(--accent); }
.chart .bar.dim { opacity: .45; }
.chart .line { fill: none; stroke: var(--accent); stroke-width: 2; }
.chart .area { fill: var(--accent); opacity: .1; }
.chart .label { fill: var(--ink-2); font-size: 12px; }
.chart .label.hi { fill: var(--ink); font-weight: 700; }
.chart .value { fill: var(--ink-2); font-size: 12px; font-variant-numeric: tabular-nums; }
.chart .hit { fill: transparent; cursor: default; }
.chart .cross { stroke: var(--muted); stroke-dasharray: 3 3; }
.chart .dot { fill: var(--accent); stroke: var(--surface); stroke-width: 2; }

.map { width: 100%; aspect-ratio: 2 / 1.05; touch-action: pan-y; }
.map svg { width: 100%; height: 100%; display: block; }
.map .country { fill: var(--nodata); stroke: var(--surface); stroke-width: .5; }
.map .country:hover, .map .country.active { stroke: var(--ink); stroke-width: 1.2; }
.map .country.mine { stroke: var(--ink); stroke-width: 1.4; stroke-dasharray: 2 1.5; }
.legend { display: flex; align-items: center; gap: 8px; font-size: .75rem; color: var(--ink-2); margin-top: 8px; }
.legend .ramp { flex: 1; max-width: 220px; height: 10px; border-radius: 5px; background: linear-gradient(90deg, var(--map-lo), var(--map-hi)); }
.legend .nd { display: inline-block; width: 10px; height: 10px; border-radius: 2px; background: var(--nodata); margin-left: 8px; vertical-align: -1px; }

.rank { width: 100%; border-collapse: collapse; font-size: .9375rem; }
.rank th { text-align: left; color: var(--muted); font-size: .75rem; font-weight: 600; padding: 4px 0 8px; }
.rank td { padding: 8px 0; border-top: 1px solid var(--line); font-variant-numeric: tabular-nums; }
.rank td:first-child { width: 2em; color: var(--muted); }
.rank .num { text-align: right; }
.rank tr.mine td { font-weight: 700; }

.compare-row { display: grid; grid-template-columns: minmax(6em, 40%) 1fr 2.5em; gap: 8px; align-items: center; margin: 8px 0; font-size: .875rem; }
.compare-row .lbl { color: var(--ink-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.compare-row .track { height: 14px; }
.compare-row .fill { height: 100%; border-radius: 0 4px 4px 0; background: var(--bar); min-width: 2px; }
.compare-row.you .fill { background: var(--accent); }
.compare-row.you .lbl { color: var(--ink); font-weight: 700; }
.compare-row .val { text-align: right; font-variant-numeric: tabular-nums; color: var(--ink); font-weight: 600; }

/* ---------- Overlays ---------- */
.tooltip {
  position: fixed; z-index: 20; pointer-events: none; background: var(--ink); color: var(--bg);
  padding: 8px 10px; border-radius: 8px; font-size: .8125rem; line-height: 1.35; max-width: 220px;
  box-shadow: 0 4px 16px rgb(0 0 0 / .2);
}
.tooltip b { display: block; }
.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 16px); transform: translateX(-50%);
  z-index: 30; background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 999px; font-size: .875rem;
  max-width: calc(100vw - 32px);
}
dialog {
  border: 0; border-radius: var(--radius); padding: 20px; width: min(420px, calc(100vw - 32px));
  background: var(--surface); color: var(--ink);
}
dialog::backdrop { background: rgb(0 0 0 / .4); }
dialog h2 { margin: 0 0 4px; font-size: 1.25rem; }
dialog .row { display: flex; gap: 8px; justify-content: flex-end; }
dialog .row .btn.primary { width: auto; }
dialog hr { border: 0; border-top: 1px solid var(--line); margin: 16px 0; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
