/* The stats & sync panel (web/game/ui/statspanel.js).
   Mobile first: one column from 320 px up, no horizontal scroll. Tokens come
   from /styles.css (--ink, --muted, --blaze, --amber, --heat, --display);
   the glass matches game.css's .glass-strong. Buttons reuse .btn. */

.so-stats {
  box-sizing: border-box;
  width: 100%;
  max-width: 440px;
  max-height: 100%;
  margin: 0 auto;
  padding: 18px 16px 20px;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  touch-action: pan-y;
  -webkit-user-select: text;
  user-select: text;
  color: var(--ink);
  font-family: var(--display);
  text-align: left;
  background: rgba(10, 11, 13, 0.8);
  -webkit-backdrop-filter: blur(22px) saturate(150%);
  backdrop-filter: blur(22px) saturate(150%);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 24px;
  box-shadow: 0 30px 80px -30px rgba(0, 0, 0, 0.8);
}
.so-stats *, .so-stats *::before, .so-stats *::after { box-sizing: border-box; }
@media (min-width: 520px) { .so-stats { padding: 22px 24px 24px; } }

/* ── head ───────────────────────────────────────────────────────── */
.so-stats-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.so-stats-title { margin: 0; font-size: 20px; font-weight: 900; letter-spacing: 0.02em; line-height: 1.2; }
.so-stats-title:focus { outline: none; }
.so-stats-title:focus-visible { outline: 2px solid var(--amber); outline-offset: 4px; border-radius: 6px; }
.so-stats-close {
  flex: none; width: 44px; height: 44px; border-radius: 50%; cursor: pointer;
  font: 900 17px var(--display); color: var(--ink);
  background: rgba(255, 255, 255, 0.05); border: 1px solid rgba(255, 255, 255, 0.12);
}
.so-stats-close:hover { background: rgba(255, 255, 255, 0.1); }
.so-stats-today { margin: 4px 0 14px; font-size: 13px; font-weight: 800; color: var(--muted); overflow-wrap: anywhere; }

/* ── the four numbers ──────────────────────────────────────────── */
.so-stats-numbers {
  list-style: none; margin: 0 0 18px; padding: 0;
  display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px;
}
.so-stats-numbers li {
  min-width: 0; display: grid; gap: 5px; justify-items: center; align-content: start; text-align: center;
  padding: 11px 2px 9px; border-radius: 14px;
  background: rgba(255, 255, 255, 0.04); border: 1px solid rgba(255, 255, 255, 0.07);
}
.so-stats-big { display: inline-flex; align-items: baseline; gap: 2px; }
.so-stats-value { font-size: clamp(22px, 7vw, 30px); font-weight: 900; line-height: 1; font-variant-numeric: tabular-nums; }
.so-stats-flame { font-size: 15px; line-height: 1; }
@media (max-width: 359px) {
  .so-stats { padding-left: 12px; padding-right: 12px; }
  .so-stats-numbers { gap: 4px; }
  .so-stats-numbers .so-stats-label { font-size: 9px; letter-spacing: 0.03em; }
}
.so-stats-label {
  font-size: 10px; font-weight: 900; letter-spacing: 0.08em; line-height: 1.25;
  text-transform: uppercase; color: var(--muted); overflow-wrap: anywhere;
}

/* ── medal distribution ────────────────────────────────────────── */
.so-stats-subtitle {
  margin: 0 0 8px; font-size: 11px; font-weight: 900; letter-spacing: 0.2em;
  text-transform: uppercase; color: var(--muted);
}
.so-stats-chart { list-style: none; margin: 0 0 16px; padding: 0; display: grid; gap: 4px; }
.so-stats-row {
  display: grid; grid-template-columns: 6.2em minmax(0, 1fr) 2.6em auto; align-items: center; gap: 8px;
  min-height: 30px; padding: 3px 8px; border-radius: 10px; font-size: 13px; font-weight: 800;
}
.so-stats-row-name { display: inline-flex; align-items: center; gap: 7px; white-space: nowrap; }
.so-stats-dot { flex: none; width: 11px; height: 11px; border-radius: 50%; }
.so-stats-bar { height: 10px; border-radius: 999px; background: rgba(255, 255, 255, 0.07); overflow: hidden; }
.so-stats-fill { display: block; width: 0; height: 100%; border-radius: inherit; transition: width 0.5s var(--ease, ease); }
.so-stats-count { text-align: right; font-variant-numeric: tabular-nums; }
.so-stats-row.gold .so-stats-dot, .so-stats-row.gold .so-stats-fill { background: linear-gradient(90deg, #fff1b8, #f0a51e); }
.so-stats-row.silver .so-stats-dot, .so-stats-row.silver .so-stats-fill { background: linear-gradient(90deg, #ffffff, #9aa3ae); }
.so-stats-row.bronze .so-stats-dot, .so-stats-row.bronze .so-stats-fill { background: linear-gradient(90deg, #f4c3a0, #b4703f); }
.so-stats-row.none .so-stats-dot, .so-stats-row.none .so-stats-fill { background: rgba(255, 255, 255, 0.3); }
.so-stats-row.is-today { background: rgba(255, 176, 31, 0.1); box-shadow: inset 0 0 0 1px rgba(255, 176, 31, 0.5); }
.so-stats-tag {
  font-size: 9px; font-weight: 900; letter-spacing: 0.14em; text-transform: uppercase;
  padding: 3px 7px; border-radius: 999px; color: #000; background: var(--heat);
}

/* ── next road + share ─────────────────────────────────────────── */
.so-stats-next {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px;
  margin: 0; padding: 14px 0 0;
  border-top: 1px solid var(--hairline, rgba(255, 255, 255, 0.08));
}
.so-stats-next-text { margin: 0; display: grid; gap: 3px; }
.so-stats-clock {
  font-size: 28px; font-weight: 900; line-height: 1.05; letter-spacing: 0.02em; font-variant-numeric: tabular-nums;
  color: var(--amber);
  background: var(--heat); -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent;
}
.so-stats-share-wrap { display: grid; gap: 4px; justify-items: end; }
.so-stats-share { min-width: 128px; }
.so-stats-share[aria-disabled="true"] { opacity: 0.5; pointer-events: auto; cursor: not-allowed; box-shadow: none; }
.so-stats-hint { font-size: 12px; font-weight: 700; color: var(--muted); }

/* ── play on another device ────────────────────────────────────── */
.so-stats-sync {
  display: grid; gap: 10px; justify-items: center;
  margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--hairline, rgba(255, 255, 255, 0.08));
}
.so-stats-sync .so-stats-subtitle { justify-self: stretch; margin: 0; }
.so-stats-explain { justify-self: stretch; margin: 0; font-family: var(--body, system-ui, sans-serif); font-size: 13px; line-height: 1.45; color: var(--muted); }
.so-stats-qr {
  width: min(100%, 280px); aspect-ratio: 1; border-radius: 16px; overflow: hidden; background: #ffffff;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.1), 0 18px 40px -22px rgba(255, 95, 31, 0.7);
}
.so-stats-qr svg { display: block; width: 100%; height: 100%; }
.so-stats-qr.is-empty { aspect-ratio: auto; background: none; box-shadow: none; text-align: center; }
.so-stats-copy { width: 100%; max-width: 280px; }
.so-stats-status { margin: 0; min-height: 1.3em; font-size: 13px; font-weight: 800; color: var(--amber); text-align: center; }
.so-stats-status:empty { min-height: 0; }
.so-stats-link {
  width: 100%; min-width: 0; padding: 10px 12px; border-radius: 10px;
  font: 600 12px var(--mono, ui-monospace, monospace); color: var(--ink);
  background: rgba(255, 255, 255, 0.06); border: 1px solid rgba(255, 255, 255, 0.16);
}

@media (prefers-reduced-motion: reduce) {
  .so-stats-fill { transition: none; }
}
@media (forced-colors: active) {
  .so-stats-clock { background: none; -webkit-text-fill-color: CanvasText; color: CanvasText; }
  .so-stats-fill, .so-stats-dot { background: CanvasText !important; }
  .so-stats-row.is-today { outline: 2px solid Highlight; }
}
