/* Scorekeeper — light by default, a selected dark theme via the OS or the toggle (html[data-theme]). */
:root {
  color-scheme: light;
  --bg: #f3f2ee;
  --card: #fcfcfb;
  --raised: #ffffff;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #6f6d68;
  --axis-ink: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --line: rgba(11, 11, 11, 0.1);
  --wash: rgba(11, 11, 11, 0.05);
  --accent: #1c5cab;
  --accent-ink: #ffffff;
  --accent-wash: rgba(42, 120, 214, 0.12);
  --good: #0ca30c;
  --good-ink: #006300;
  --bad: #d03b3b;
  --bad-ink: #b02a2a;
  --draw: #898781;
  --shadow: 0 1px 2px rgba(11, 11, 11, 0.06), 0 4px 16px rgba(11, 11, 11, 0.06);
  /* Player identity: the validated categorical palette (dataviz skill), light steps. */
  --c1: #2a78d6; --c2: #eb6834; --c3: #1baf7a; --c4: #eda100;
  --c5: #e87ba4; --c6: #008300; --c7: #4a3aa7; --c8: #e34948;
  /* Text on each player fill, picked per mode for contrast. */
  --on-c1: #fff; --on-c2: #0b0b0b; --on-c3: #0b0b0b; --on-c4: #0b0b0b;
  --on-c5: #0b0b0b; --on-c6: #fff; --on-c7: #fff; --on-c8: #0b0b0b;
  --accent-fill: #1c5cab;
  --accent-text: #1c5cab;
  --lost: #898781;
  --drawn: #c3c2b7;
  --radius: 16px;
  --tabbar-h: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --bg: #0d0d0d; --card: #1a1a19; --raised: #232321;
    --ink: #ffffff; --ink-2: #c3c2b7; --muted: #a3a29c; --axis-ink: #898781;
    --grid: #2c2c2a; --axis: #383835; --line: rgba(255, 255, 255, 0.1); --wash: rgba(255, 255, 255, 0.06);
    --accent: #3987e5; --accent-ink: #ffffff; --accent-wash: rgba(57, 135, 229, 0.18);
    --good-ink: #2fbf2f; --bad-ink: #f07575;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
    --c1: #3987e5; --c2: #d95926; --c3: #199e70; --c4: #c98500;
    --c5: #d55181; --c6: #008300; --c7: #9085e9; --c8: #e66767;
    --on-c1: #0b0b0b; --on-c2: #0b0b0b; --on-c3: #0b0b0b; --on-c4: #0b0b0b;
    --on-c5: #0b0b0b; --on-c6: #fff; --on-c7: #0b0b0b; --on-c8: #0b0b0b;
    --accent-fill: #2b6cc4; --accent-text: #8ab8f2; --lost: #7d7b75; --drawn: #4a4945;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0d0d0d; --card: #1a1a19; --raised: #232321;
  --ink: #ffffff; --ink-2: #c3c2b7; --muted: #a3a29c; --axis-ink: #898781;
  --grid: #2c2c2a; --axis: #383835; --line: rgba(255, 255, 255, 0.1); --wash: rgba(255, 255, 255, 0.06);
  --accent: #3987e5; --accent-ink: #ffffff; --accent-wash: rgba(57, 135, 229, 0.18);
  --good-ink: #2fbf2f; --bad-ink: #f07575;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
  --c1: #3987e5; --c2: #d95926; --c3: #199e70; --c4: #c98500;
  --c5: #d55181; --c6: #008300; --c7: #9085e9; --c8: #e66767;
  --on-c1: #0b0b0b; --on-c2: #0b0b0b; --on-c3: #0b0b0b; --on-c4: #0b0b0b;
  --on-c5: #0b0b0b; --on-c6: #fff; --on-c7: #0b0b0b; --on-c8: #0b0b0b;
  --accent-fill: #2b6cc4; --accent-text: #8ab8f2; --lost: #7d7b75; --drawn: #4a4945;
}

*, *::before, *::after { box-sizing: border-box; }
html { background: var(--bg); }
body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--ink);
  font-size: 16px;
  line-height: 1.4;
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: inherit; }
h1, h2, h3, p { margin: 0; }
svg { display: block; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

#view {
  max-width: 680px;
  margin: 0 auto;
  padding: calc(var(--safe-t) + 12px) 16px calc(var(--tabbar-h) + var(--safe-b) + 28px);
  outline: none;
}
.boot { padding: 40vh 0; text-align: center; color: var(--muted); }

/* ---- top of each page ---- */
.page-head { display: flex; align-items: center; gap: 8px; min-height: 48px; margin-bottom: 12px; }
.page-head h1 { font-size: 26px; font-weight: 750; letter-spacing: -0.02em; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.page-head .sub { color: var(--ink-2); font-size: 14px; }
.brand { display: flex; align-items: center; gap: 8px; }
.brand svg { width: 28px; height: 28px; }
.brand h1 { line-height: 1.1; }
.board-tag { display: block; font-size: 13px; font-weight: 600; color: var(--ink-2); text-decoration: none; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.board-name { font-size: 17px; min-width: 0; overflow-wrap: anywhere; }
.reset-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.reset-row p { margin-top: 2px; }
.reset-row .btn { flex: none; }
.icon-btn {
  width: 44px; height: 44px; flex: none; border: 0; background: transparent; border-radius: 12px;
  display: grid; place-items: center; color: var(--ink);
}
.icon-btn:hover { background: var(--wash); }
.icon-btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ---- tab bar ---- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: grid; grid-template-columns: repeat(5, 1fr); align-items: center;
  height: calc(var(--tabbar-h) + var(--safe-b)); padding: 0 max(8px, env(safe-area-inset-left)) var(--safe-b) max(8px, env(safe-area-inset-right));
  background: color-mix(in srgb, var(--card) 88%, transparent);
  -webkit-backdrop-filter: saturate(1.6) blur(16px); backdrop-filter: saturate(1.6) blur(16px);
  border-top: 1px solid var(--line);
}
.tabbar a {
  display: flex; flex-direction: column; align-items: center; gap: 2px; justify-content: center;
  height: 100%; text-decoration: none; color: var(--muted); font-size: 11px; font-weight: 600;
}
.tabbar a 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-text); }
.tabbar a[aria-current="page"] svg { stroke-width: 2.3; }
.tab-log {
  justify-self: center; width: 58px; height: 58px; margin-top: -26px; border-radius: 50%; border: 4px solid var(--bg);
  background: var(--accent-fill); color: var(--accent-ink); display: grid; place-items: center;
  box-shadow: 0 6px 18px rgba(28, 92, 171, 0.35); transition: transform 0.15s ease;
}
.tab-log:active { transform: scale(0.94); }
.tab-log svg { width: 28px; height: 28px; fill: none; stroke: currentColor; stroke-width: 2.6; stroke-linecap: round; }
body.no-tabs .tabbar { display: none; }

/* ---- cards & sections ---- */
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; margin-bottom: 14px; box-shadow: var(--shadow);
}
.card.flush { padding: 6px 0; }
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.card.flush .card-head { padding: 10px 16px 4px; margin: 0; }
.card-head h2 { font-size: 17px; font-weight: 700; }
.card-head .sub { font-size: 13px; color: var(--ink-2); }
.card-head a, .link-btn {
  font-size: 14px; font-weight: 600; color: var(--accent-text); text-decoration: none; background: none; border: 0; padding: 8px 0; min-height: 44px;
}
.card-head a { padding: 12px 10px; margin: -12px -10px; display: inline-block; min-height: 0; min-width: 48px; text-align: right; }
.card-head > div { min-width: 0; }
.card-head h2, .card-head .sub { overflow-wrap: anywhere; }
.section-title { font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin: 20px 4px 8px; }
.muted { color: var(--muted); }
.ink-2 { color: var(--ink-2); }
.small { font-size: 13px; }
.stack { display: grid; gap: 12px; }
.row-gap { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* ---- hero & tiles ---- */
.hero { text-align: center; padding: 22px 16px 18px; }
.hero .label { font-size: 14px; color: var(--ink-2); font-weight: 600; }
.hero .value { font-size: 56px; line-height: 1.05; font-weight: 750; letter-spacing: -0.03em; margin: 6px 0 4px; }
.hero .detail { font-size: 15px; color: var(--ink-2); }
.versus { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 8px; }
.versus .side { display: flex; flex-direction: column; align-items: center; gap: 6px; min-width: 0; text-decoration: none; }
.versus .side .name { font-weight: 700; font-size: 15px; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.versus .score { font-size: clamp(34px, 12vw, 52px); font-weight: 750; letter-spacing: -0.03em; white-space: nowrap; }
@media (max-width: 360px) { .versus .avatar.lg { --size: 44px; } }
.versus .score .dash { color: var(--axis); margin: 0 4px; }

.tiles { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-bottom: 14px; }
.tiles.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.tiles.three .tile { padding: 12px 10px; }
.tiles.three .tile .value { font-size: 19px; }
@media (min-width: 560px) { .tiles:not(.three) { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.tile { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; min-width: 0; box-shadow: var(--shadow); }
.tile .label { font-size: 13px; color: var(--ink-2); }
.tile .value { font-size: 22px; font-weight: 700; margin-top: 2px; display: flex; align-items: center; gap: 6px; min-width: 0; }
.tile .value .txt { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tile .detail { font-size: 13px; color: var(--muted); margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---- avatars & pills ---- */
.avatar {
  --size: 36px; --pc: var(--c1);
  width: var(--size); height: var(--size); flex: none; border-radius: 50%;
  display: inline-grid; place-items: center; background: var(--pc); color: var(--on, #fff);
  font-weight: 700; font-size: calc(var(--size) * 0.4); line-height: 1; user-select: none;
  box-shadow: 0 0 0 2px var(--card);
}
.avatar.emoji { font-size: calc(var(--size) * 0.52); }
.avatar.sm { --size: 28px; }
.avatar.lg { --size: 56px; }
.avatar.xl { --size: 76px; }
.pill {
  display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: 6px;
  font-size: 12px; font-weight: 800; flex: none;
}
.pill.W { background: color-mix(in srgb, var(--good) 18%, transparent); color: var(--good-ink); }
.pill.L { background: color-mix(in srgb, var(--bad) 16%, transparent); color: var(--bad-ink); }
.pill.D { background: var(--wash); color: var(--ink-2); }
.form { display: inline-flex; gap: 3px; }
.badge { font-size: 11px; font-weight: 700; padding: 2px 7px; border-radius: 99px; background: var(--accent-wash); color: var(--accent-text); vertical-align: middle; }
.badge.sample { background: color-mix(in srgb, #eda100 22%, transparent); color: var(--ink); }
.delta { font-size: 13px; font-weight: 700; font-variant-numeric: tabular-nums; }
.delta.up { color: var(--good-ink); }
.delta.down { color: var(--bad-ink); }

/* ---- lists ---- */
.list { list-style: none; margin: 0; padding: 0; }
.list > li + li { border-top: 1px solid var(--line); }
.item {
  display: flex; align-items: center; gap: 12px; width: 100%; min-height: 60px; padding: 10px 16px;
  text-align: left; background: none; border: 0; text-decoration: none; color: inherit;
}
button.item:hover, a.item:hover { background: var(--wash); }
.item .main { flex: 1; min-width: 0; }
.item .title { font-weight: 600; display: flex; gap: 6px; align-items: baseline; min-width: 0; }
.item .title .txt { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .title .vs-name { flex: 0 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .title .vs { flex: none; color: var(--muted); font-weight: 500; font-size: 14px; }
.item .meta { display: block; font-size: 13px; color: var(--ink-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-top: 1px; }
.item .end { text-align: right; flex: none; display: flex; flex-direction: column; align-items: flex-end; gap: 2px; }
.item .chev { width: 18px; height: 18px; flex: none; color: var(--axis); fill: none; stroke: currentColor; stroke-width: 2; }
.sport-ico { width: 40px; height: 40px; border-radius: 12px; background: var(--wash); display: grid; place-items: center; font-size: 20px; flex: none; }
.day-head { font-size: 13px; font-weight: 700; color: var(--muted); padding: 14px 16px 6px; }
.game-line { display: flex; align-items: baseline; gap: 6px; min-width: 0; }
.game-line .w { font-weight: 700; }
.game-line .l { color: var(--ink-2); }
.game-line .verb { color: var(--muted); font-size: 14px; flex: none; }
.game-line .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.score-badge { font-weight: 700; font-variant-numeric: tabular-nums; font-size: 15px; white-space: nowrap; }

/* ---- leaderboard ---- */
.board { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.board th { font-size: 12px; font-weight: 600; color: var(--muted); text-align: right; padding: 6px 8px; }
.board th:first-child, .board td:first-child { text-align: center; width: 28px; padding-left: 12px; }
.board th:nth-child(2) { text-align: left; }
.board td { padding: 10px 8px; text-align: right; border-top: 1px solid var(--line); white-space: nowrap; }
.board th { white-space: nowrap; }
.board td:last-child, .board th:last-child { padding-right: 16px; }
.board tr[data-href] { cursor: pointer; }
.board tr[data-href]:hover td { background: var(--wash); }
.board .who { display: flex; align-items: center; gap: 10px; text-align: left; min-width: 0; }
.board .who .nm { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.board td:nth-child(2) { width: 100%; max-width: 0; }
.board .who > div { min-width: 0; overflow: hidden; }
.board .rank { font-weight: 700; color: var(--muted); }
.board .rating { font-weight: 700; }
@media (max-width: 420px) { .board .hide-sm { display: none; } }
@media (max-width: 380px) { .board .form { display: none; } }

/* ---- split bar ---- */
.split { display: flex; gap: 2px; height: 12px; margin: 4px 0 8px; }
.split > span { border-radius: 2px; min-width: 4px; position: relative; }
/* Chart marks are thin; their hit area isn't. */
.split > span[tabindex]::after, .hrec .bars span::after { content: ""; position: absolute; inset: -16px 0; }
.split > span:first-child { border-radius: 6px 2px 2px 6px; }
.split > span:last-child { border-radius: 2px 6px 6px 2px; }
.split > span:only-child { border-radius: 6px; }
.split.thin { height: 6px; margin: 6px 0 0; }
.split-labels { display: flex; justify-content: space-between; font-size: 13px; color: var(--ink-2); gap: 8px; }
.split-labels span { overflow-wrap: anywhere; min-width: 0; }
.split-labels b { color: var(--ink); }

/* ---- controls ---- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 48px; padding: 0 20px;
  border-radius: 14px; border: 1px solid transparent; font-weight: 650; font-size: 16px; text-decoration: none;
  background: var(--wash); color: var(--ink); transition: transform 0.12s ease, opacity 0.12s;
}
.btn:active { transform: scale(0.98); }
.btn.primary { background: var(--accent-fill); color: var(--accent-ink); }
.btn.ghost { background: transparent; border-color: var(--line); }
.btn.danger { background: transparent; color: var(--bad-ink); border-color: color-mix(in srgb, var(--bad) 40%, transparent); }
.btn.block { width: 100%; }
.btn.sm { min-height: 44px; padding: 0 14px; font-size: 14px; border-radius: 12px; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }
.btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 16px 6px; margin: 0 -16px; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
.chips::-webkit-scrollbar { display: none; }
.chips.wrap { flex-wrap: wrap; overflow: visible; margin: 0; padding: 0; }
.chip {
  flex: none; display: inline-flex; align-items: center; gap: 6px; min-height: 44px; padding: 0 14px; border-radius: 99px;
  border: 1px solid var(--line); background: var(--card); font-size: 15px; font-weight: 550; white-space: nowrap; color: var(--ink);
  max-width: 100%; overflow: hidden; text-overflow: ellipsis;
}
.chip[aria-pressed="true"] { background: var(--ink); color: var(--card); border-color: var(--ink); }
.chip.add { border-style: dashed; color: var(--ink-2); }
.chip .avatar { --size: 24px; box-shadow: none; margin-left: -6px; }

.seg { display: flex; background: var(--wash); border-radius: 12px; padding: 3px; gap: 2px; }
.seg button {
  flex: 1; min-height: 44px; border: 0; background: transparent; border-radius: 9px; font-size: 14px; font-weight: 600; color: var(--ink-2);
}
.seg button[aria-pressed="true"] { background: var(--card); color: var(--ink); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12); }

.filters { display: flex; gap: 8px; align-items: center; margin-bottom: 12px; flex-wrap: wrap; }
.filters .chips { flex: 1 1 100%; }
.filters > .seg { flex: 1 1 100%; }
select.select {
  min-height: 44px; border-radius: 12px; border: 1px solid var(--line); background: var(--card); padding: 0 32px 0 12px; font-size: 16px;
  appearance: none; -webkit-appearance: none; max-width: 100%; min-width: 0; text-overflow: ellipsis;
  background-image: linear-gradient(45deg, transparent 50%, var(--ink-2) 50%), linear-gradient(135deg, var(--ink-2) 50%, transparent 50%);
  background-position: calc(100% - 17px) 55%, calc(100% - 12px) 55%; background-size: 5px 5px; background-repeat: no-repeat;
}

.field { display: grid; gap: 6px; margin-bottom: 14px; }
.field > span { font-size: 14px; font-weight: 600; color: var(--ink-2); }
.field .hint { font-size: 13px; color: var(--muted); font-weight: 400; }
.input, textarea.input {
  width: 100%; min-height: 48px; border-radius: 12px; border: 1px solid var(--line); background: var(--raised);
  padding: 10px 14px; font-size: 16px;
}
textarea.input { min-height: 80px; resize: vertical; max-width: 100%; }
/* iOS gives date inputs an intrinsic width that ignores width: 100% and pushes the panel sideways. */
input.input[type="datetime-local"] { -webkit-appearance: none; appearance: none; display: block; min-width: 0; max-width: 100%; }
input.input[type="datetime-local"]::-webkit-date-and-time-value { text-align: left; }
.input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.input[aria-invalid="true"] { border-color: var(--bad); }
.error { color: var(--bad-ink); font-size: 14px; font-weight: 600; min-height: 0; }
.error:empty { display: none; }

.switch { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 52px; padding: 4px 0; cursor: pointer; }
.switch .txt { display: grid; }
.switch .txt b { font-weight: 600; }
.switch .txt small { color: var(--muted); font-size: 13px; }
.switch input { appearance: none; -webkit-appearance: none; width: 50px; height: 30px; border-radius: 99px; background: var(--axis); position: relative; flex: none; transition: background 0.15s; margin: 0; }
.switch input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; transition: transform 0.15s; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3); }
.switch input:checked { background: var(--good); }
.switch input:checked::after { transform: translateX(20px); }

.swatches { display: flex; flex-wrap: wrap; gap: 10px; }
.swatch { width: 40px; height: 40px; border-radius: 50%; border: 0; background: var(--pc); box-shadow: 0 0 0 2px var(--card); }
.swatch[aria-pressed="true"] { box-shadow: 0 0 0 2px var(--card), 0 0 0 4px var(--ink); }

/* ---- log form ---- */
.lineup { display: grid; grid-template-columns: 1fr 40px 1fr; gap: 8px; align-items: stretch; margin-bottom: 14px; }
.slot {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; min-height: 104px; padding: 10px 6px;
  border-radius: 16px; border: 1px solid var(--line); background: var(--raised); min-width: 0;
}
.slot .nm { font-weight: 700; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.slot .ph { color: var(--muted); font-weight: 600; }
.slot.empty { border-style: dashed; }
.swap { align-self: center; width: 40px; height: 40px; border-radius: 50%; border: 1px solid var(--line); background: var(--card); display: grid; place-items: center; }
.swap svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.winners { display: grid; grid-template-columns: 1fr auto 1fr; gap: 8px; margin-bottom: 6px; }
.winners.nodraw { grid-template-columns: 1fr 1fr; }
.win-btn {
  min-height: 56px; border-radius: 14px; border: 2px solid var(--line); background: var(--raised); font-weight: 700; font-size: 16px;
  padding: 6px 10px; display: flex; align-items: center; justify-content: center; gap: 8px; min-width: 0;
}
.win-btn .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.win-btn.draw { padding: 6px 14px; font-weight: 600; color: var(--ink-2); }
.win-btn[aria-pressed="true"] { border-color: var(--pc, var(--ink)); background: color-mix(in srgb, var(--pc, var(--ink)) 12%, var(--raised)); color: var(--ink); }
.win-btn .crown { font-size: 18px; }
.scores { display: grid; grid-template-columns: 1fr auto 1fr; gap: 8px; align-items: center; }
.stepper { display: flex; align-items: center; border: 1px solid var(--line); border-radius: 14px; background: var(--raised); min-width: 0; }
.stepper button { width: 44px; height: 52px; border: 0; background: none; font-size: 22px; color: var(--ink-2); flex: none; }
.stepper input { width: 100%; min-width: 0; border: 0; background: none; text-align: center; font-size: 22px; font-weight: 700; height: 52px; padding: 0; font-variant-numeric: tabular-nums; }
.stepper input:focus { outline: none; }
.stepper:focus-within { outline: 2px solid var(--accent); outline-offset: -1px; }
.scores .vs { color: var(--muted); font-weight: 600; font-size: 14px; }
.more-toggle { margin: 4px 0 10px; }
.when-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 48px; padding: 0 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--raised); }
.when-row[hidden] { display: none; }
.when-value { font-weight: 600; }

/* ---- sheets (dialog) ---- */
dialog.sheet {
  position: fixed; inset: auto 0 0 0; margin: 0 auto; width: 100%; max-width: 560px; max-height: calc(100dvh - 24px - var(--safe-t));
  border: 0; padding: 0; border-radius: 22px 22px 0 0; background: var(--card); color: var(--ink);
  box-shadow: 0 -8px 40px rgba(0, 0, 0, 0.25); overflow: hidden; display: flex; flex-direction: column;
}
dialog.sheet:not([open]) { display: none; }
dialog.sheet:focus { outline: none; }
dialog.sheet::backdrop { background: rgba(0, 0, 0, 0.42); }
dialog.sheet[open] { animation: sheet-in 0.24s cubic-bezier(0.2, 0.9, 0.3, 1); }
@keyframes sheet-in { from { transform: translateY(40px); opacity: 0; } }
@media (min-width: 640px) {
  dialog.sheet { inset: 0; margin: auto; border-radius: 22px; max-height: min(86dvh, 820px); }
}
.sheet-head { display: flex; align-items: center; gap: 8px; padding: 10px 8px 6px 20px; flex: none; }
.sheet-head h2 { flex: 1; font-size: 19px; font-weight: 750; }
/* flex-basis auto, not 0: iOS Safari sizes a column flexbox from the basis, so `flex: 1`
   collapsed the body to a sliver. Auto keeps the content height, and min-height 0 lets it scroll. */
.sheet-body {
  padding: 4px 20px 16px; overflow-x: hidden; overflow-y: auto; overscroll-behavior: contain;
  flex: 1 1 auto; min-height: 0; -webkit-overflow-scrolling: touch;
}
/* The log panel scrolls vertically only. */
.log-sheet .sheet-body { touch-action: pan-y pinch-zoom; }
.log-sheet .sheet-body > form { min-width: 0; max-width: 100%; }
.sheet-foot { padding: 12px 20px calc(12px + var(--safe-b)); border-top: 1px solid var(--line); flex: none; display: flex; gap: 10px; background: var(--card); }
.sheet-foot { flex-wrap: wrap; }
.sheet-foot .error { flex: 1 1 100%; margin: 0 0 -2px; }
.sheet-foot .btn { flex: 1; min-width: 0; padding: 0 12px; }
@media (max-width: 360px) { .sheet-foot .btn:not(.icon-only) svg { display: none; } }
.grabber { width: 40px; height: 5px; border-radius: 3px; background: var(--axis); margin: 8px auto 0; flex: none; }
@media (min-width: 640px) { .grabber { display: none; } }

/* ---- toasts ---- */
#toasts { position: fixed; left: 0; right: 0; bottom: calc(var(--tabbar-h) + var(--safe-b) + 14px); z-index: 50; display: grid; justify-items: center; gap: 8px; pointer-events: none; padding: 0 12px; }
body.no-tabs #toasts { bottom: calc(var(--safe-b) + 16px); }
.toast {
  pointer-events: auto; display: flex; align-items: center; gap: 12px; max-width: 520px; width: 100%;
  background: var(--ink); color: var(--card); border-radius: 14px; padding: 10px 10px 10px 16px; box-shadow: 0 8px 28px rgba(0, 0, 0, 0.25);
  animation: toast-in 0.2s ease-out;
}
.toast.error { background: var(--bad-ink); color: #fff; }
.toast .msg { flex: 1; font-size: 15px; font-weight: 550; min-width: 0; }
.toast button { flex: none; background: transparent; border: 0; color: inherit; font-weight: 800; padding: 0 10px; min-height: 40px; text-decoration: underline; text-underline-offset: 3px; }
@keyframes toast-in { from { transform: translateY(12px); opacity: 0; } }

/* ---- empty & welcome ---- */
.empty { text-align: center; padding: 28px 20px; }
.empty .big { font-size: 44px; }
.empty h2 { font-size: 20px; margin: 8px 0 6px; }
.empty p { color: var(--ink-2); margin-bottom: 16px; }
.empty .actions { display: grid; gap: 10px; max-width: 320px; margin: 0 auto; }
.welcome { max-width: 440px; margin: 0 auto; padding-top: 6vh; }
.welcome-back { margin: -6vh 0 12px; }
.welcome-back .link-btn { padding-left: 0; }
.welcome .logo { display: block; width: 72px; height: 72px; margin: 0 auto 14px; border-radius: 18px; }
.welcome h1 { font-size: 34px; text-align: center; font-weight: 800; letter-spacing: -0.03em; }
.welcome .lead { text-align: center; color: var(--ink-2); margin: 8px 0 26px; font-size: 17px; }
.welcome .steps { display: flex; justify-content: center; gap: 6px; margin-bottom: 18px; }
.welcome .steps i { width: 26px; height: 5px; border-radius: 3px; background: var(--axis); }
.welcome .steps i.on { background: var(--accent); }
.welcome .added { display: flex; flex-wrap: wrap; gap: 8px; margin: -4px 0 16px; }
.banner {
  display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-radius: 14px; margin-bottom: 14px;
  background: var(--accent-wash); font-size: 15px;
}
.banner .msg { flex: 1; }
.banner.sample { background: color-mix(in srgb, #eda100 18%, var(--card)); }

/* ---- detail sheet ---- */
.result-big { text-align: center; padding: 6px 0 14px; }
.result-big .versus .score { font-size: 44px; }
.result-big .what { color: var(--ink-2); margin-top: 8px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 8px 16px; font-size: 15px; margin: 6px 0 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; text-align: right; }
.note { background: var(--wash); border-radius: 12px; padding: 12px 14px; white-space: pre-wrap; overflow-wrap: anywhere; margin-bottom: 14px; }

/* ---- charts ---- */
.chart { position: relative; }
.chart .plot { position: relative; width: 100%; }
.chart svg { overflow: visible; touch-action: pan-y; user-select: none; -webkit-user-select: none; }
.chart svg:focus { outline: none; }
.chart svg:focus-visible { outline: 2px solid var(--accent); outline-offset: 4px; border-radius: 4px; }
.chart .tick { fill: var(--axis-ink); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .dlabel { fill: var(--ink-2); font-size: 12px; font-weight: 600; paint-order: stroke; stroke: var(--card); stroke-width: 4px; stroke-linejoin: round; }
.chart .zero-label { fill: var(--ink-2); font-size: 11px; font-weight: 600; paint-order: stroke; stroke: var(--card); stroke-width: 4px; stroke-linejoin: round; }
.chart .gridline { stroke: var(--grid); stroke-width: 1; shape-rendering: crispEdges; }
.chart .baseline { stroke: var(--axis); stroke-width: 1; shape-rendering: crispEdges; }
.chart .series { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .crosshair { stroke: var(--axis-ink); stroke-width: 1; shape-rendering: crispEdges; }
.chart .dot { stroke: var(--card); stroke-width: 2; }
.chart .leader { stroke: var(--axis); stroke-width: 1; }
.chart .bar { transition: opacity 0.12s; }
.chart.hovering .bar:not(.on) { opacity: 0.45; }
.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; margin: 0 0 10px; font-size: 13px; color: var(--ink-2); }
.legend .key { display: inline-flex; align-items: center; gap: 6px; overflow-wrap: anywhere; max-width: 100%; }
.legend .key i { width: 14px; height: 2px; border-radius: 1px; background: var(--k); display: inline-block; }
.legend .key i.box { height: 10px; width: 10px; border-radius: 3px; }
.legend button.key { border: 1px solid var(--line); background: var(--card); border-radius: 99px; padding: 0 12px; min-height: 44px; color: var(--ink-2); font-size: 13px; }
.legend button.key[aria-pressed="true"] { color: var(--ink); border-color: var(--ink-2); font-weight: 600; }
.legend button.key[aria-pressed="false"] i { background: var(--drawn); }
.tip {
  position: absolute; z-index: 5; pointer-events: none; min-width: 120px; max-width: 240px;
  background: var(--raised); color: var(--ink); border: 1px solid var(--line); border-radius: 10px;
  padding: 8px 10px; font-size: 13px; box-shadow: 0 6px 20px rgba(0, 0, 0, 0.16);
}
.tip .t-head { color: var(--ink-2); font-size: 12px; margin-bottom: 4px; }
.tip .t-row { display: flex; align-items: center; gap: 8px; }
.tip .t-row i { width: 12px; height: 2px; background: var(--k); flex: none; border-radius: 1px; }
.tip .t-row b { font-variant-numeric: tabular-nums; }
.tip .t-row span { color: var(--ink-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tip .t-note { color: var(--ink-2); margin-top: 4px; }
.data-table { margin-top: 8px; font-size: 13px; }
.data-table summary { color: var(--accent-text); font-weight: 600; cursor: pointer; min-height: 44px; display: flex; align-items: center; list-style: none; }
.data-table summary::-webkit-details-marker { display: none; }
.data-table summary::before { content: "▸"; margin-right: 6px; transition: transform 0.15s; }
.data-table[open] summary::before { transform: rotate(90deg); }
.data-table .scroll { max-height: 260px; overflow: auto; border: 1px solid var(--line); border-radius: 10px; }
.data-table table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.data-table th, .data-table td { padding: 6px 10px; text-align: right; border-bottom: 1px solid var(--line); white-space: nowrap; }
.data-table th:first-child, .data-table td:first-child { text-align: left; }
.data-table th { position: sticky; top: 0; background: var(--card); color: var(--ink-2); font-weight: 600; }
.chart-note { font-size: 13px; color: var(--muted); padding: 12px 0 4px; }

/* opponent record bars */
.hrec { display: grid; gap: 10px; }
.hrec .r { display: grid; grid-template-columns: minmax(0, 1fr) minmax(60px, 40%) auto; gap: 10px; align-items: center; text-decoration: none; color: inherit; min-height: 44px; }
.hrec .who { display: flex; align-items: center; gap: 8px; min-width: 0; font-size: 14px; font-weight: 600; }
.hrec .who span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hrec .bars { display: flex; gap: 2px; height: 14px; }
.hrec .bars span { border-radius: 2px; min-width: 3px; position: relative; }
.hrec .bars span:last-child { border-radius: 2px 4px 4px 2px; }
.hrec .val { font-size: 13px; color: var(--ink-2); font-variant-numeric: tabular-nums; min-width: 52px; text-align: right; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
@media (min-width: 720px) {
  #view { padding-top: calc(var(--safe-t) + 24px); }
}

/* ---- owner dashboard ---- */
body.admin #view { max-width: 960px; }
body.admin .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
@media (min-width: 700px) { body.admin .tiles { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
body.admin .tile .value { font-size: 24px; }
body.admin .tile .detail { white-space: normal; }
#view.refreshing { opacity: 0.6; transition: opacity 0.2s; }
.admin-table td { padding: 9px 16px; }
.admin-table tr:first-child td { border-top: 0; }
