:root {
  color-scheme: light;
  --surface-0: #f3f3f1;
  --surface-1: #fcfcfb;
  --border: #e4e3de;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #77766f;
  --series: #2a78d6;
  --series-soft: #b7d3f6;
  --up: #008300;
  --down: #c13232;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --surface-0: #111110;
    --surface-1: #1a1a19;
    --border: #2c2c2a;
    --text-primary: #f0efec;
    --text-secondary: #c3c2b7;
    --text-muted: #9a998f;
    --series: #3987e5;
    --series-soft: #1c3d66;
    --up: #2fb52f;
    --down: #e66767;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  background: var(--surface-0);
  color: var(--text-primary);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-variant-numeric: tabular-nums;
}
main, footer { max-width: 560px; margin: 0 auto; padding: 0 12px; }
footer { padding: 16px 12px 32px; font-size: 13px; }
.muted { color: var(--text-muted); }
.center { text-align: center; }
a { color: var(--series); }

/* Top bar */
.bar {
  position: sticky; top: 0; z-index: 1;
  display: flex; align-items: center; gap: 4px;
  max-width: 560px; margin: 0 auto; padding: 8px 4px;
  background: var(--surface-0);
}
.bar h1 { flex: 1; margin: 0 8px; font-size: 22px; font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.icon-btn {
  width: 44px; height: 44px; border: 0; border-radius: 22px;
  background: transparent; color: var(--text-primary); font-size: 26px; line-height: 1;
}
.icon-btn:active { background: var(--border); }
.spin { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Cards */
.card { background: var(--surface-1); border: 1px solid var(--border); border-radius: 14px; margin-bottom: 12px; }

/* Stat tiles */
.tiles { display: grid; grid-template-columns: repeat(3, 1fr); padding: 14px 4px; }
.tile { text-align: center; }
.tile .label { font-size: 13px; color: var(--text-secondary); }
.tile .value { font-size: 30px; font-weight: 650; line-height: 1.15; }
.tile .delta { font-size: 13px; color: var(--text-muted); }

/* Delta arrows: direction carried by arrow + sign, color is secondary */
.up { color: var(--up); }
.down { color: var(--down); }

/* Site list */
.sites { list-style: none; margin: 0; padding: 0; }
.sites li + li { border-top: 1px solid var(--border); }
.site {
  display: grid; grid-template-columns: 1fr 84px 56px; align-items: center; gap: 10px;
  padding: 12px 14px; min-height: 64px; color: inherit; text-decoration: none;
}
.site:active { background: var(--surface-0); }
.site .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.site .sub { font-size: 13px; color: var(--text-secondary); }
.site .week { text-align: right; font-size: 24px; font-weight: 650; line-height: 1.1; }
.site .week small { display: block; font-size: 11px; font-weight: 400; color: var(--text-muted); }
.spark { width: 84px; height: 28px; display: block; }
.spark path { fill: none; stroke: var(--series); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.spark .area { fill: var(--series-soft); stroke: none; opacity: .6; }

/* Detail chart */
.chart-card { padding: 14px; }
.chart-card h2, .list-card h2 { margin: 0 0 8px; font-size: 15px; font-weight: 600; color: var(--text-secondary); }
.chart { position: relative; }
.chart svg { width: 100%; height: 140px; display: block; touch-action: pan-y; }
.chart .bar-mark { fill: var(--series); }
.chart .bar-mark.active { fill: var(--text-primary); }
.chart .grid { stroke: var(--border); stroke-width: 1; }
.chart .axis { font-size: 11px; fill: var(--text-muted); }
.tip {
  position: absolute; top: -6px; transform: translateX(-50%);
  padding: 3px 8px; border-radius: 6px; font-size: 13px; white-space: nowrap; pointer-events: none;
  background: var(--text-primary); color: var(--surface-1);
}

/* Ranked lists */
.list-card { padding: 14px; }
.rank { list-style: none; margin: 0; padding: 0; }
.rank li { position: relative; display: flex; gap: 8px; padding: 7px 0; font-size: 15px; }
.rank .label { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank .count { font-weight: 600; }
.rank .meter { position: absolute; left: 0; bottom: 2px; height: 3px; border-radius: 2px; background: var(--series); opacity: .55; }

/* Login */
.login { padding-top: 20vh; text-align: center; }
.login form { display: flex; flex-direction: column; gap: 10px; max-width: 300px; margin: 0 auto; }
.login input, .login button {
  font: inherit; padding: 12px 14px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface-1); color: var(--text-primary);
}
.login button { background: var(--series); color: #fff; border: 0; font-weight: 600; }
.error { color: var(--down); }
