:root {
  --bg: #fafaf9; --card: #fff; --fg: #1c1917; --muted: #78716c; --line: #e7e5e4;
  --accent: #16a34a; --accent-soft: #dcfce7; --err: #b91c1c; --err-soft: #fee2e2;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #0c0a09; --card: #1c1917; --fg: #f5f5f4; --muted: #a8a29e; --line: #292524;
    --accent: #22c55e; --accent-soft: #14532d; --err: #fca5a5; --err-soft: #450a0a; }
}
* { box-sizing: border-box; }
body {
  margin: 0 auto; max-width: 640px; padding: 16px 16px calc(32px + env(safe-area-inset-bottom));
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg); color: var(--fg);
}
h1 { font-size: 1.6rem; margin: 4px 0 2px; }
h2 { margin: 0 0 4px; font-size: 1.2rem; }
h3 { font-size: .95rem; margin: 0 0 8px; }
.muted { color: var(--muted); }
.top { margin-bottom: 12px; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.me { color: var(--muted); font-size: .9rem; }
button { font: inherit; cursor: pointer; }
button.link { background: none; border: 0; padding: 0; color: var(--accent); text-decoration: underline; }
.banner { background: #fef9c3; color: #713f12; padding: 8px 12px; border-radius: 8px; font-size: .85rem; margin-bottom: 12px; }
@media (prefers-color-scheme: dark) { .banner { background: #422006; color: #fde68a; } }

.submit { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 14px; margin-bottom: 14px; }
.big {
  width: 100%; padding: 16px; border: 0; border-radius: 12px; font-size: 1.15rem; font-weight: 600;
  background: var(--accent); color: #fff; -webkit-tap-highlight-color: transparent;
}
.big:active { transform: scale(.98); }
.big:disabled { opacity: .6; }
.hint { margin: 8px 0 4px; font-size: .85rem; color: var(--muted); text-align: center; }
details { margin-top: 6px; font-size: .9rem; }
summary { color: var(--muted); cursor: pointer; }
textarea { width: 100%; margin: 8px 0; padding: 8px; border-radius: 8px; border: 1px solid var(--line); background: var(--bg); color: var(--fg); font: 14px/1.4 ui-monospace, monospace; }
#submit-paste { padding: 8px 16px; border-radius: 8px; border: 1px solid var(--accent); background: none; color: var(--accent); font-weight: 600; }
.today { margin-top: 10px; font-size: .85rem; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.chip { padding: 2px 8px; border-radius: 999px; border: 1px solid var(--line); color: var(--muted); text-decoration: none; }
a.chip:hover { border-color: var(--accent); color: var(--fg); }
.chip.done { background: var(--accent-soft); border-color: transparent; color: var(--fg); }

.toast { position: sticky; top: 8px; z-index: 5; padding: 10px 12px; border-radius: 10px; margin-bottom: 12px;
  background: var(--accent-soft); font-size: .9rem; box-shadow: 0 2px 10px rgba(0,0,0,.08); }
.toast.err { background: var(--err-soft); color: var(--err); }

.tabs { display: flex; flex-direction: column; gap: 10px; }
.tab-label { display: block; margin-bottom: 4px; font-size: .7rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.tab-row { display: flex; flex-wrap: wrap; gap: 6px; }
.tabs button, .seg button {
  white-space: nowrap; padding: 7px 12px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--card); color: var(--fg); font-size: .9rem;
}
.tabs button.on, .seg button.on { background: var(--fg); color: var(--bg); border-color: var(--fg); }
.controls { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin: 10px 0; }
select { font: inherit; font-size: .9rem; padding: 6px 8px; border-radius: 8px; border: 1px solid var(--line); background: var(--card); color: var(--fg); }
.seg { display: flex; gap: 4px; }

table { width: 100%; border-collapse: collapse; background: var(--card); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
th, td { padding: 9px 8px; text-align: left; border-bottom: 1px solid var(--line); }
tr:last-child td { border-bottom: 0; }
th { font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.strong { font-weight: 700; }
.rank { width: 2.2em; text-align: center; }
td.name { font-weight: 500; }
td.name.is-me::after { content: " (you)"; color: var(--muted); font-weight: 400; font-size: .85em; }
tr.dim td { color: var(--muted); }
.note { font-size: .8rem; color: var(--muted); }
.empty { text-align: center; padding: 24px 0; }

.day { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 12px; margin-bottom: 10px; }
.day-game { display: flex; flex-wrap: wrap; gap: 6px; align-items: baseline; margin-bottom: 6px; font-size: .9rem; }
.gname { min-width: 6.5em; font-weight: 600; }
.res { padding: 2px 8px; border-radius: 999px; background: var(--bg); border: 1px solid var(--line); }
.res.win { background: var(--accent-soft); border-color: transparent; }

dialog { border: 0; border-radius: 14px; padding: 20px; width: min(92vw, 360px); background: var(--card); color: var(--fg); }
dialog::backdrop { background: rgba(0,0,0,.4); }
dialog input { width: 100%; padding: 12px; font-size: 1rem; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); color: var(--fg); margin: 8px 0 12px; }
dialog menu { margin: 0; padding: 0; }
.nowrap { white-space: nowrap; }

/* Drifting emoji background */
.bg-layer { position: fixed; inset: 0; overflow: hidden; pointer-events: none; z-index: -1; }
.bg-emoji {
  position: absolute; opacity: .12; user-select: none; will-change: transform;
  animation: drift 60s ease-in-out infinite alternate;
}
@media (prefers-color-scheme: dark) { .bg-emoji { opacity: .09; } }
@keyframes drift {
  from { transform: translate(0, 0) rotate(0deg); }
  to   { transform: translate(var(--dx), var(--dy)) rotate(var(--rot)); }
}

/* Streaks, profile, daily recap */
.controls[hidden] { display: none; }
.streak { font-size: .8rem; font-weight: 600; color: #ea580c; white-space: nowrap; }
.plink { background: none; border: 0; padding: 0; font: inherit; color: inherit; text-align: left; cursor: pointer; }
.plink:hover { text-decoration: underline; }
.daynav { display: flex; align-items: center; justify-content: center; gap: 16px; margin: 12px 0; }
.daynav button { width: 36px; height: 36px; border-radius: 50%; border: 1px solid var(--line); background: var(--card); color: var(--fg); font-size: 1.2rem; line-height: 1; }
.daynav button:disabled { opacity: .35; cursor: default; }
.game-h { margin: 16px 0 6px; }
main h3 { margin-top: 16px; }
.back { margin: 10px 0 0; }
.ptitle { margin: 6px 0 10px; font-size: 1.4rem; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 4px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 10px 8px; text-align: center; }
.stat b { display: block; font-size: 1.25rem; }
.stat span { font-size: .75rem; color: var(--muted); }
#h2h { width: 100%; margin-bottom: 10px; }

/* Trend charts */
.trend { display: flex; align-items: center; gap: 4px; margin-top: 2px; }
.trend svg { display: block; }
.trend .up { color: var(--accent); font-size: .7rem; }
.trend .down { color: var(--err); font-size: .7rem; }
.h2h-bar { display: flex; height: 12px; border-radius: 6px; overflow: hidden; background: var(--line); margin: 4px 0 2px; }
.h2h-bar .a { background: var(--accent); }
.h2h-bar .t { background: var(--muted); opacity: .5; }
.h2h-bar .b { background: #6366f1; }
.h2h-legend { display: flex; justify-content: space-between; font-size: .8rem; color: var(--muted); margin-bottom: 10px; }

/* Profile button (top right) */
.avatar-btn { display: flex; flex-direction: column; align-items: center; gap: 3px; background: none; border: 0; padding: 0; color: var(--fg); -webkit-tap-highlight-color: transparent; }
.avatar {
  width: 48px; height: 48px; border-radius: 50%; display: grid; place-items: center;
  background: var(--accent); color: #fff; font-size: 1.35rem; font-weight: 700;
  border: 3px solid var(--card); box-shadow: 0 0 0 2px var(--accent), 0 2px 8px rgba(0,0,0,.2);
  transition: transform .12s;
}
.avatar-btn:hover .avatar, .avatar-btn:focus-visible .avatar { transform: scale(1.07); }
.avatar-btn:active .avatar { transform: scale(.95); }
.avatar-btn.active .avatar { box-shadow: 0 0 0 3px var(--fg), 0 2px 8px rgba(0,0,0,.2); }
.avatar-label { font-size: .7rem; font-weight: 600; color: var(--muted); }

/* Result detail popover */
.has-tip { cursor: help; border-bottom: 1px dotted var(--muted); }
[data-tip]:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 3px; }
.tip {
  position: fixed; z-index: 50; max-width: min(280px, calc(100vw - 16px)); padding: 10px 12px;
  background: var(--card); color: var(--fg); border: 1px solid var(--line); border-radius: 12px;
  box-shadow: 0 8px 24px rgba(0,0,0,.18); font-size: .85rem; pointer-events: none;
}
.tip-head { margin-bottom: 6px; }
.tip table { border: 0; border-radius: 0; background: none; width: auto; }
.tip td { padding: 2px 8px 2px 0; border: 0; }
.tip-mark { letter-spacing: 1px; }
.tip-grid { font-size: 1.05rem; line-height: 1.25; letter-spacing: 1px; }
.tip-legend { margin-top: 6px; font-size: .75rem; color: var(--muted); }
.tip-note { margin-top: 6px; font-size: .8rem; color: var(--muted); }

/* Luck marks, form gauge, hot streak */
.luck { font-size: .85em; }
.hotb { font-size: .8rem; font-weight: 700; color: #ca8a04; white-space: nowrap; }
.tip-vs { margin-bottom: 6px; font-weight: 600; }
.tip-vs.up { color: var(--accent); }
.tip-vs.down { color: var(--muted); }
.hot-row { margin: 10px 0 0; padding: 8px 12px; border-radius: 12px; background: #fef9c3; color: #713f12; font-size: .9rem; }
@media (prefers-color-scheme: dark) { .hot-row { background: #422006; color: #fde68a; } .hotb { color: #fbbf24; } }
.form { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 12px; margin-top: 10px; }
.form-head { display: flex; justify-content: space-between; align-items: baseline; }
.form-head .up { color: var(--accent); font-weight: 700; font-size: 1.2rem; }
.form-head .down { color: var(--muted); font-weight: 700; font-size: 1.2rem; }
.gauge { position: relative; height: 10px; margin: 10px 0 4px; border-radius: 6px; background: linear-gradient(90deg, #94a3b8, var(--line) 50%, var(--accent)); }
.gauge .mid { position: absolute; left: 50%; top: -3px; bottom: -3px; width: 2px; background: var(--fg); opacity: .4; }
.gauge .dot { position: absolute; top: 50%; width: 18px; height: 18px; margin: -9px 0 0 -9px; border-radius: 50%; background: var(--fg); border: 3px solid var(--card); box-shadow: 0 1px 4px rgba(0,0,0,.35); }
.gauge-scale { display: flex; justify-content: space-between; font-size: .7rem; color: var(--muted); }
.form .note { margin: 8px 0 0; }

/* Win % view */
.wr-pick { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; padding: 8px 12px; border: 2px solid var(--accent); border-radius: 12px; background: var(--accent-soft); }
.wr-pick span { font-weight: 700; font-size: .9rem; white-space: nowrap; }
#wr-game { flex: 1; min-width: 0; font-weight: 600; }
td.wr { position: relative; min-width: 76px; }
td.wr .wbar { position: absolute; left: 6px; top: 7px; bottom: 7px; background: var(--accent-soft); border-radius: 6px; max-width: calc(100% - 12px); }
td.wr .wval { position: relative; }
.wr-matrix { table-layout: fixed; }
.wr-matrix th, .wr-matrix td { padding: 7px 3px; font-size: .8rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.wr-matrix th { font-size: .65rem; }
.wr-matrix .wr-game-cell, .wr-matrix th:first-child { width: 34px; text-align: center; font-size: 1rem; }

/* Weekly recap, badges, rivalries */
.wk-grid { display: grid; gap: 10px; margin-top: 4px; }
.wk-card { display: flex; gap: 12px; align-items: center; background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; }
.wk-emoji { font-size: 1.8rem; line-height: 1; width: 36px; text-align: center; }
.wk-title { font-size: .72rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.wk-who { font-size: 1.1rem; font-weight: 700; }
.wk-who .plink { font-weight: 700; }
.wk-sub { font-size: .85rem; color: var(--muted); }
.wk-copy { margin-top: 12px; }
.badges { display: flex; flex-wrap: wrap; gap: 6px; }
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 4px 10px; border-radius: 999px; border: 1px dashed var(--line); color: var(--muted); font-size: .82rem; opacity: .7; }
.badge.got { border: 1px solid var(--accent); background: var(--accent-soft); color: var(--fg); opacity: 1; font-weight: 600; }
.badge small { color: var(--muted); }
.rival { display: flex; gap: 10px; align-items: flex-start; padding: 8px 0; border-bottom: 1px solid var(--line); }
.rival .re { font-size: 1.4rem; width: 32px; text-align: center; }
.badge-line { font-size: .75rem; line-height: 1.2; white-space: nowrap; }
.pg-table th, .pg-table td { padding: 8px 4px; font-size: .85rem; }
.pg-table th { font-size: .65rem; white-space: normal; line-height: 1.15; vertical-align: bottom; }
.pg-table .trend svg { width: 72px; height: auto; }
.sub { font-size: .75rem; padding-top: 8px; }

/* profile history */
.hist-day h4 { margin: 14px 0 6px; font-size: .8rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.hist-item { padding: 8px 0; border-bottom: 1px solid var(--line); }
.hist-top { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; flex-wrap: wrap; font-size: .9rem; }
.hist-top .hplace { margin-left: auto; font-size: .8rem; white-space: nowrap; }
.hchips { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.hchip { font-size: .75rem; padding: 1px 7px; border-radius: 999px; background: var(--bg); border: 1px solid var(--line); }
.hgrid { margin-top: 6px; font-size: .8rem; line-height: 1.15; letter-spacing: 1px; overflow-wrap: anywhere; }
.hnote { font-size: .75rem; margin-top: 4px; }
