/* Pool tracker — phone first. Everything is sized for a thumb in a pub. */

:root {
  --bg: #0d1310;
  --bg-raise: #151e18;
  --surface: #1a2620;
  --surface-2: #213029;
  --line: #2c3f35;
  --text: #e9f1ec;
  --muted: #8ba296;
  --me: #46c2ff;
  --me-dim: #1d5878;
  --opp: #ffb13d;
  --opp-dim: #6d4b17;
  --felt: #2fbf71;
  --loss: #ff6b6b;
  --radius: 16px;
  --radius-lg: 22px;
  --tap: 56px;
  --pad: 16px;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 17px;
  line-height: 1.35;
  -webkit-tap-highlight-color: transparent;
  padding-bottom: calc(28px + env(safe-area-inset-bottom));
}

/* ------------------------------------------------------------ top bar */

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(10px + env(safe-area-inset-top)) var(--pad) 10px;
  background: rgba(13, 19, 16, 0.92);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}

.brand {
  margin: 0;
  font-size: 19px;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.topbar-actions { display: flex; align-items: center; gap: 8px; }

.chip {
  display: inline-flex;
  align-items: center;
  min-height: 40px;
  text-decoration: none;
  padding: 8px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 15px;
  font-weight: 600;
}

.chip-primary { background: var(--felt); border-color: var(--felt); color: #05281a; }

main { padding: var(--pad); display: grid; gap: 14px; max-width: 560px; margin: 0 auto; }

.view { display: grid; gap: 14px; }
.view[hidden] { display: none; }

/* ------------------------------------------------------------ scoreboard */

.scoreboard {
  position: relative;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 8px;
  padding: 18px 16px 34px;
  border-radius: var(--radius-lg);
  background: linear-gradient(160deg, #1d4d36 0%, #163528 55%, #15211b 100%);
  border: 1px solid var(--line);
}

.side { display: grid; justify-items: center; gap: 2px; min-width: 0; }

.side-name {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.side-me .side-name { color: var(--me); }
.side-opp .side-name { color: var(--opp); }

.side-score { font-size: 54px; font-weight: 800; line-height: 1; font-variant-numeric: tabular-nums; }

.score-dash { font-size: 28px; color: var(--muted); }

.scoreboard-meta {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 12px;
  margin: 0;
  text-align: center;
  font-size: 13px;
  color: #bcd3c6;
}

/* ------------------------------------------------------------ blocks */

.block { display: grid; gap: 10px; }

.block-title {
  margin: 0;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--muted);
}

.hint { font-weight: 500; letter-spacing: 0; text-transform: none; color: var(--muted); opacity: 0.85; }

.pair { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.pair-slim { grid-template-columns: 1fr 1fr auto; }

.pick {
  min-height: 92px;
  padding: 10px 8px;
  border: 2px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 22px;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  /* No colour transition: the selected side must read instantly in a dim pub. */
  transition: transform 0.08s ease;
}

.pick:active { transform: scale(0.97); }

.pair-slim .pick { min-height: var(--tap); font-size: 17px; }
.pair-slim .pick-none { font-size: 14px; padding: 0 14px; color: var(--muted); }

.pick-me[aria-pressed="true"] { background: var(--me-dim); border-color: var(--me); color: #d9f2ff; }
.pick-opp[aria-pressed="true"] { background: var(--opp-dim); border-color: var(--opp); color: #ffe9c7; }
.pick-none[aria-pressed="true"] { background: var(--surface-2); border-color: var(--muted); color: var(--text); }

/* ------------------------------------------------------------ extras */

.extras {
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg-raise);
}

.extras summary {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 32px;
  cursor: pointer;
  list-style: none;
}

.extras summary::-webkit-details-marker { display: none; }
.extras summary::after { content: "+"; margin-left: auto; font-size: 20px; color: var(--muted); }
.extras[open] summary::after { content: "–"; }

.extras-count {
  min-width: 22px;
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--felt);
  color: #06281a;
  font-size: 12px;
  font-weight: 800;
  text-align: center;
}

.extra-list { display: grid; gap: 10px; padding-top: 12px; }

.extra-row {
  display: grid;
  gap: 4px;
  width: 100%;
  padding: 12px 14px;
  border: 1.5px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  text-align: left;
}

.extra-row[aria-pressed="true"] { background: #15402c; border-color: var(--felt); }
.extra-row:disabled { opacity: 0.45; }

.extra-head { display: flex; align-items: center; gap: 10px; }
.extra-label { font-size: 16px; font-weight: 700; }

.extra-mark {
  margin-left: auto;
  width: 24px;
  height: 24px;
  border-radius: 999px;
  border: 1.5px solid var(--line);
  display: grid;
  place-items: center;
  font-size: 13px;
  font-weight: 800;
  color: transparent;
}

.extra-row[aria-pressed="true"] .extra-mark {
  background: var(--felt);
  border-color: var(--felt);
  color: #05281a;
}

.extra-blurb { font-size: 14px; color: #cfe2d7; }
.extra-qualifies { font-size: 13px; color: var(--muted); }

/* ------------------------------------------------------------ save */

.save {
  min-height: 66px;
  border: none;
  border-radius: var(--radius);
  background: var(--felt);
  color: #05281a;
  font: inherit;
  font-size: 20px;
  font-weight: 800;
  letter-spacing: 0.01em;
}

.save:disabled { background: var(--surface-2); color: var(--muted); }
.save:not(:disabled):active { transform: scale(0.985); }

/* ------------------------------------------------------------ games list */

.games { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }

.game-row {
  display: grid;
  grid-template-columns: 30px 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
}

.game-seq { color: var(--muted); font-size: 14px; font-variant-numeric: tabular-nums; }
.game-text { font-size: 15px; min-width: 0; }
.game-text b { font-weight: 700; }
.game-text .won-me { color: var(--me); }
.game-text .won-opp { color: var(--opp); }
.game-tags { display: block; font-size: 12px; color: var(--muted); margin-top: 2px; }

.undo {
  min-width: 44px;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 18px;
}

.empty { margin: 0; color: var(--muted); font-size: 14px; }

/* ------------------------------------------------------------ stats */

.card {
  display: grid;
  gap: 10px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.card.headline { background: linear-gradient(165deg, #1d4d36, #16211c); }

.card-label {
  margin: 0;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
}

.card.headline .card-label { color: #a9cbb9; }

.h2h { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 8px; }
.h2h-side { display: grid; justify-items: center; gap: 2px; min-width: 0; }

.h2h-name {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
}

.name-a { color: var(--me); }
.name-b { color: var(--opp); }
.h2h-wins { font-size: 44px; font-weight: 800; line-height: 1; font-variant-numeric: tabular-nums; }
.h2h-meta { margin: 0; text-align: center; font-size: 14px; color: #c6ddd0; }

.bar { height: 10px; border-radius: 999px; background: var(--opp); overflow: hidden; }
.bar-fill { height: 100%; background: var(--me); border-radius: 999px 0 0 999px; }

/* Ten results have to fit one line on a 390px phone, so the dots flex down. */
.form-strip { display: flex; gap: 5px; }

.form-dot {
  flex: 1 1 0;
  min-width: 0;
  max-width: 34px;
  aspect-ratio: 1;
  border-radius: 9px;
  display: grid;
  place-items: center;
  font-size: 13px;
  font-weight: 800;
}

.form-dot.a { background: var(--me-dim); color: var(--me); border: 1px solid var(--me); }
.form-dot.b { background: var(--opp-dim); color: var(--opp); border: 1px solid var(--opp); }

.card-note { margin: 0; font-size: 13px; color: var(--muted); }

.stat-rows { display: grid; gap: 1px; }

.stat-row {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: baseline;
  gap: 10px;
  padding: 9px 0;
  border-bottom: 1px solid var(--line);
}

.stat-row:last-child { border-bottom: none; }
.stat-row dt { font-size: 15px; color: #cfe2d7; }
.stat-row dd { margin: 0; font-size: 16px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat-row dd .sub { font-size: 13px; font-weight: 500; color: var(--muted); }

.split-wrap { overflow-x: auto; }

.split { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }

.split th,
.split td {
  padding: 9px 6px;
  border-bottom: 1px solid var(--line);
  text-align: right;
  font-size: 15px;
}

.split tr:last-child th,
.split tr:last-child td { border-bottom: none; }

.split th[scope="col"] { font-size: 12px; letter-spacing: 0.04em; text-transform: uppercase; color: var(--muted); }
.split th[scope="col"].name-a { color: var(--me); }
.split th[scope="col"].name-b { color: var(--opp); }

.split th[scope="row"] { text-align: left; font-weight: 700; font-size: 14px; }
.split .split-corner { text-align: left; }
.split td { font-weight: 700; }
.split td .sub { font-size: 12px; font-weight: 500; color: var(--muted); }

.glossary { margin: 2px 0 0; display: grid; gap: 2px; }
.glossary dt { font-size: 13px; font-weight: 700; color: #cfe2d7; }
.glossary dd { margin: 0 0 8px; font-size: 13px; color: var(--muted); }
.glossary dd:last-child { margin-bottom: 0; }

.nights { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }

.night-row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: center;
  gap: 10px;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--bg-raise);
}

.night-date { font-size: 15px; }
.night-score { font-size: 16px; font-weight: 700; font-variant-numeric: tabular-nums; }

.pill {
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.04em;
}

.pill.won-a { background: var(--me-dim); color: #d9f2ff; }
.pill.won-b { background: var(--opp-dim); color: #ffe9c7; }
.pill.draw { background: var(--surface-2); color: var(--muted); }

/* ------------------------------------------------------------ sheet */

.sheet {
  width: min(460px, calc(100% - 24px));
  margin: auto auto 12px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--bg-raise);
  color: var(--text);
}

.sheet::backdrop { background: rgba(0, 0, 0, 0.6); }
.sheet-title { margin: 0 0 14px; font-size: 18px; }
.opponent-list { list-style: none; margin: 0 0 12px; padding: 0; display: grid; gap: 8px; max-height: 45vh; overflow-y: auto; }

.opponent-list button {
  width: 100%;
  min-height: var(--tap);
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 17px;
  font-weight: 600;
  text-align: left;
}

.opponent-list button[aria-current="true"] { border-color: var(--opp); color: var(--opp); }

.sheet-add { display: grid; grid-template-columns: 1fr auto; gap: 8px; margin-bottom: 10px; }

.sheet-add input {
  min-height: var(--tap);
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 17px;
}

.ghost {
  min-height: var(--tap);
  padding: 0 18px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 16px;
  font-weight: 600;
}

.ghost.wide { width: 100%; }

/* ------------------------------------------------------------ toast */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom));
  z-index: 10;
  transform: translateX(-50%);
  margin: 0;
  max-width: calc(100% - 32px);
  padding: 12px 18px;
  border-radius: 999px;
  background: #e9f1ec;
  color: #0d1310;
  font-size: 15px;
  font-weight: 700;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
}

.toast.is-error { background: var(--loss); color: #2a0a0a; }

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