/* ============================================================
   Dart Scorer — mobile-first dark UI
   ============================================================ */
:root {
  --bg: #0f1115;
  --bg-2: #161a22;
  --surface: #1c212c;
  --surface-2: #232a37;
  --line: #2c3442;
  --txt: #eef2f8;
  --txt-dim: #97a1b3;
  --txt-faint: #8a93a3;
  --accent: #ff4d4d;        /* dart red */
  --accent-2: #2bd47a;       /* board green */
  --accent-3: #ffcf3f;       /* bull gold */
  --accent-grad: linear-gradient(135deg, #ff5d5d 0%, #ff8a3d 100%);
  --good: #2bd47a;
  --warn: #ffcf3f;
  --bad: #ff5d5d;
  --radius: 16px;
  --radius-sm: 11px;
  --shadow: 0 8px 30px rgba(0,0,0,.45);
  --tap: 56px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --maxw: 560px;
  font-size: 16px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  background:
    radial-gradient(1200px 600px at 50% -10%, #1a2030 0%, var(--bg) 55%) fixed;
  color: var(--txt);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
  touch-action: manipulation;
}
#app {
  max-width: var(--maxw);
  margin: 0 auto;
  min-height: 100%;
  display: flex;
  flex-direction: column;
  padding: calc(var(--safe-t) + 8px) 12px calc(var(--safe-b) + 12px);
}
button { font-family: inherit; color: inherit; cursor: pointer; }
h1,h2,h3 { margin: 0; font-weight: 750; letter-spacing: -.01em; }
.muted { color: var(--txt-dim); }
.center { text-align: center; }

/* ---------- App bar ---------- */
.appbar {
  display: flex; align-items: center; gap: 10px;
  padding: 4px 2px 12px;
}
.appbar .title { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; }
.appbar .title h1 { font-size: 1.18rem; }
.logo {
  width: 34px; height: 34px; border-radius: 9px; flex: none;
  background: var(--accent-grad);
  display: grid; place-items: center; font-size: 1.1rem;
  box-shadow: 0 4px 14px rgba(255,93,93,.35);
}
.appbar .sub { font-size: .78rem; color: var(--txt-dim); }
.iconbtn {
  width: 42px; height: 42px; flex: none;
  border-radius: 11px; border: 1px solid var(--line);
  background: var(--surface); font-size: 1.1rem;
  display: grid; place-items: center;
}
.iconbtn:active { transform: scale(.94); }

/* ---------- Cards / generic ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}
.card + .card { margin-top: 12px; }
.section-label {
  font-size: .72rem; text-transform: uppercase; letter-spacing: .12em;
  color: var(--txt-dim); margin: 0 0 10px 2px; font-weight: 700;
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: var(--tap); padding: 0 18px;
  border-radius: var(--radius-sm); border: 1px solid var(--line);
  background: var(--surface-2); font-size: 1rem; font-weight: 650;
  width: 100%;
}
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--accent-grad); border-color: transparent; color: #1a0d08; font-weight: 800; }
.btn.ghost { background: transparent; }
.btn.danger { background: #2a1620; border-color: #5c2336; color: #ff90a8; }
.btn.sm { min-height: 44px; font-size: .9rem; padding: 0 12px; width: auto; }
.btn:disabled { opacity: .4; pointer-events: none; }
.btn-row { display: flex; gap: 10px; }
.btn-row > * { flex: 1; }

/* ---------- Segmented tabs (mode switch) ---------- */
.segment {
  display: grid; grid-auto-flow: column; grid-auto-columns: 1fr;
  gap: 4px; padding: 4px; background: var(--bg-2);
  border: 1px solid var(--line); border-radius: 13px;
}
.segment button {
  border: none; background: transparent; color: var(--txt-dim);
  min-height: 46px; border-radius: 10px; font-weight: 700; font-size: .92rem;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px;
}
.segment button .s { font-size: .66rem; font-weight: 600; opacity: .8; }
.segment button[aria-selected="true"] {
  background: var(--surface-2); color: var(--txt);
  box-shadow: inset 0 0 0 1px var(--line), 0 2px 8px rgba(0,0,0,.3);
}
.segment.small button { min-height: 40px; font-size: .85rem; }

/* ---------- Setup screen ---------- */
.field { margin-bottom: 14px; }
.field > label { display:block; font-size:.82rem; color: var(--txt-dim); margin: 0 0 6px 2px; font-weight: 650; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  border: 1px solid var(--line); background: var(--bg-2); color: var(--txt-dim);
  border-radius: 999px; padding: 9px 15px; font-weight: 650; font-size: .92rem; min-height: 42px;
}
.chip[aria-pressed="true"] { background: var(--surface-2); color: var(--txt); border-color: #46506280; }
.chip.accent[aria-pressed="true"] { background: rgba(255,93,93,.16); color: #ffb3b3; border-color: #ff5d5d66; }

.players-list { display: flex; flex-direction: column; gap: 10px; }
.player-row { display: flex; align-items: center; gap: 10px; }
.player-row .dot { width: 12px; height: 12px; border-radius: 50%; flex: none; }
.player-row input {
  flex: 1; min-height: var(--tap); border-radius: var(--radius-sm);
  border: 1px solid var(--line); background: var(--bg-2); color: var(--txt);
  padding: 0 14px; font-size: 1rem;
}
.player-row input:focus { outline: 2px solid var(--accent); outline-offset: 0; }
.player-row .rm { width: 44px; height: 44px; flex: none; border-radius: 11px; border: 1px solid var(--line); background: var(--surface-2); color: var(--txt-dim); }

.toggle-row { display:flex; align-items:center; justify-content: space-between; gap: 12px; padding: 12px 2px; border-bottom: 1px solid var(--line); }
.toggle-row:last-child { border-bottom: none; }
.toggle-row .lbl { font-weight: 600; }
.toggle-row .lbl small { display:block; color: var(--txt-dim); font-weight: 500; font-size: .76rem; margin-top: 2px; }
.switch { position: relative; width: 52px; height: 30px; flex: none; }
.switch input { opacity: 0; width: 100%; height: 100%; margin: 0; }
.switch .track { position: absolute; inset: 0; background: var(--surface-2); border:1px solid var(--line); border-radius: 999px; transition: background .15s; }
.switch .track::after { content:""; position:absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: var(--txt-dim); transition: transform .15s, background .15s; }
.switch input:checked + .track { background: rgba(43,212,122,.25); border-color: #2bd47a66; }
.switch input:checked + .track::after { transform: translateX(22px); background: var(--good); }

.stepper { display: flex; align-items: center; gap: 0; border:1px solid var(--line); border-radius: 11px; overflow: hidden; }
.stepper button { width: 46px; height: 46px; background: var(--surface-2); border: none; font-size: 1.3rem; font-weight: 700; }
.stepper .val { min-width: 46px; text-align: center; font-weight: 750; font-size: 1.05rem; }

/* ---------- Game screen ---------- */
.scoreboard { display: flex; flex-direction: column; gap: 10px; margin-bottom: 12px; }

/* X01 / clock / countup player cards */
.pcard {
  display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 12px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px;
  padding: 12px 14px; position: relative; overflow: hidden;
}
.pcard.active { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent), 0 8px 24px rgba(255,77,77,.18); }
.pcard.active::before { content:""; position:absolute; left:0; top:0; bottom:0; width:4px; background: var(--accent-grad); }
.pcard .pinfo { min-width: 0; }
.pcard .pname { font-weight: 750; font-size: 1.02rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pcard .pmeta { font-size: .74rem; color: var(--txt-dim); margin-top: 2px; }
.pcard .pscore { font-variant-numeric: tabular-nums; font-weight: 850; font-size: 2.1rem; line-height: 1; letter-spacing: -.02em; }
.pcard .pscore.sm { font-size: 1.5rem; }
.pcard .avatar { width: 38px; height: 38px; border-radius: 11px; display:grid; place-items:center; font-weight:800; color:#0c0f14; }
.pcard .legs { display:flex; gap:4px; margin-top: 4px; }
.pcard .legs i { width: 8px; height: 8px; border-radius: 50%; background: var(--line); }
.pcard .legs i.on { background: var(--accent-3); }
.pcard.winner { opacity: .55; }
.tag { font-size:.64rem; font-weight:800; text-transform:uppercase; letter-spacing:.08em; padding:2px 7px; border-radius:6px; background: var(--surface-2); color: var(--txt-dim); }
.tag.crown { background: rgba(255,207,63,.18); color: var(--accent-3); }

/* Cricket scoreboard — horizontally scrollable with a sticky target column,
   so 5–6 players (and Full Cricket's 21 rows) stay readable on a 360px screen. */
.cricket-board { background: var(--surface); border:1px solid var(--line); border-radius: 14px; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.cricket-grid { display: grid; min-width: 100%; }
.cricket-grid .ch, .cricket-grid .cc { padding: 8px 4px; text-align:center; border-bottom: 1px solid var(--line); }
.cricket-grid .sticky { position: sticky; left: 0; z-index: 1; background: var(--surface); }
.cricket-grid .target { font-weight: 800; font-size: 1rem; text-align:left; padding-left: 10px; }
.cricket-grid .phead { font-weight: 750; font-size: .8rem; padding: 8px 4px; display:flex; flex-direction:column; align-items:center; gap:1px; min-width: 0; }
.cricket-grid .phead .pn { white-space:nowrap; overflow:hidden; text-overflow:ellipsis; max-width: 100%; }
.cricket-grid .phead.active { color: var(--accent); }
.cricket-grid .phead .pclosed { font-size:.62rem; color: var(--txt-dim); font-weight:600; }
.cricket-grid .marks { font-size: 1.15rem; font-weight: 800; min-height: 1.3em; letter-spacing: 1px; }
.cricket-grid .marks .closed { color: var(--good); }
.cricket-grid .pts { font-variant-numeric: tabular-nums; font-weight: 800; font-size: 1.05rem; white-space:nowrap; }
.cricket-grid .ptlabel { font-size:.72rem; color: var(--txt-dim); font-weight:700; text-align:left; padding-left:10px; }

/* ---------- Turn / input ---------- */
.turnbar {
  display:flex; align-items:center; justify-content:space-between; gap: 10px;
  background: var(--bg-2); border:1px solid var(--line); border-radius: 13px; padding: 10px 12px; margin-bottom: 10px;
}
.darts { display:flex; gap: 8px; }
.dart-slot {
  min-width: 60px; height: 46px; padding: 0 10px; border-radius: 10px;
  border: 1px dashed var(--line); background: var(--surface);
  display:flex; align-items:center; justify-content:center; font-weight: 750; font-size: .98rem;
  color: var(--txt-dim);
}
.dart-slot.filled { border-style: solid; color: var(--txt); border-color: #46506280; }
.dart-slot.bust { color: var(--bad); border-color: var(--bad); }
.turn-total { text-align:right; }
.turn-total .n { font-size: 1.5rem; font-weight: 850; font-variant-numeric: tabular-nums; line-height:1; }
.turn-total .l { font-size: .68rem; color: var(--txt-dim); text-transform:uppercase; letter-spacing:.1em; }

.checkout {
  display:flex; align-items:center; gap: 10px; margin-bottom: 10px;
  background: linear-gradient(135deg, rgba(43,212,122,.14), rgba(43,212,122,.04));
  border:1px solid #2bd47a44; border-radius: 12px; padding: 10px 14px;
  font-weight: 700; min-height: 0;
}
.checkout .co-label { font-size:.7rem; text-transform:uppercase; letter-spacing:.1em; color: var(--good); font-weight:800; }
.checkout .co-route { font-size: 1.05rem; letter-spacing:.02em; }
.checkout.none { background: var(--bg-2); border-color: var(--line); color: var(--txt-dim); font-weight:600; }

/* input area */
.input-wrap { margin-top: auto; }
.input-tabs { margin-bottom: 10px; }

/* Spreadsheet-style score grid (Single / Double / Treble columns) */
.grid-pad { border: 1px solid var(--line); border-radius: 13px; overflow: hidden; background: var(--bg-2); }
.gp-head { display: grid; grid-template-columns: repeat(3, 1fr); }
.gp-head span { text-align: center; font-size: .66rem; text-transform: uppercase; letter-spacing: .09em; color: var(--txt-dim); font-weight: 800; padding: 8px 0 6px; }
.gp-body { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; padding: 8px; max-height: 48vh; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.gp {
  min-height: 46px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--surface); font-weight: 800; font-size: 1.02rem; font-variant-numeric: tabular-nums;
  color: var(--txt);
}
.gp:active { transform: scale(.95); background: var(--surface-2); }
.gp.d { color: #9fe9c2; border-color: #2bd47a40; }
.gp.t { color: #ffb3b3; border-color: #ff5d5d40; }
.gp.bull { color: var(--accent-3); border-color: #ffcf3f55; background: rgba(255,207,63,.07); }
.gp.miss { color: var(--txt-dim); }

/* Number pad (legacy) */
.pad { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
.pad button {
  min-height: 52px; border-radius: 12px; border:1px solid var(--line);
  background: var(--surface); font-size: 1.05rem; font-weight: 750; font-variant-numeric: tabular-nums;
}
.pad button:active { transform: scale(.95); background: var(--surface-2); }
.pad button.zero { grid-column: span 1; }
.mult-row { display:grid; grid-template-columns: repeat(3,1fr); gap: 8px; margin-bottom: 10px; }
.mult-row button {
  min-height: 50px; border-radius: 12px; border:1px solid var(--line); background: var(--bg-2);
  font-weight: 800; font-size: 1rem; color: var(--txt-dim);
}
.mult-row button[aria-pressed="true"] { color: var(--txt); }
.mult-row button.d[aria-pressed="true"] { background: rgba(43,212,122,.2); border-color:#2bd47a88; color:#9fe9c2; }
.mult-row button.t[aria-pressed="true"] { background: rgba(255,93,93,.2); border-color:#ff5d5d88; color:#ffb3b3; }
.mult-row button.s[aria-pressed="true"] { background: var(--surface-2); border-color:#46506288; color: var(--txt); }
.special-row { display:grid; grid-template-columns: repeat(3,1fr); gap:8px; margin-top: 8px; }
.special-row button { min-height: 50px; border-radius:12px; border:1px solid var(--line); background: var(--surface); font-weight:750; }
.special-row button.bull { color: var(--accent-3); }

/* action buttons row */
.actions { display: grid; grid-template-columns: 1fr 1.3fr; gap: 10px; margin-top: 10px; }
.actions .undo { background: var(--surface-2); }

/* ---------- Dartboard SVG ---------- */
.board-wrap { display:flex; flex-direction: column; align-items:center; }
.dartboard { width: min(86vw, 360px); height: auto; display:block; touch-action: manipulation; }
.dartboard .seg { cursor: pointer; transition: filter .08s, opacity .08s; outline: none; }
.dartboard .seg:active { filter: brightness(1.6); }
.dartboard .seg.flash { filter: brightness(2); }
.dartboard .seg:focus-visible { stroke: #fff; stroke-width: 2.5; filter: brightness(1.3); }
.dartboard text { font-weight: 800; fill: #fff; font-size: 13px; pointer-events: none; user-select: none; }
.board-hint { font-size:.74rem; color: var(--txt-dim); margin-top: 8px; text-align:center; }

/* ---------- Stats / history ---------- */
.stat-grid { display:grid; grid-template-columns: repeat(2,1fr); gap: 10px; }
.stat {
  background: var(--bg-2); border:1px solid var(--line); border-radius: 12px; padding: 12px 14px;
}
.stat .v { font-size: 1.5rem; font-weight: 850; font-variant-numeric: tabular-nums; }
.stat .k { font-size: .72rem; color: var(--txt-dim); text-transform:uppercase; letter-spacing:.08em; margin-top:2px; }
.history-item {
  display:flex; align-items:center; gap: 12px; padding: 12px 4px; border-bottom: 1px solid var(--line);
}
.history-item:last-child { border-bottom:none; }
.history-item .hmode { width: 44px; height:44px; border-radius:11px; background: var(--surface-2); display:grid; place-items:center; font-size:1.3rem; flex:none; }
.history-item .hmain { flex:1; min-width:0; }
.history-item .hwin { font-weight: 750; }
.history-item .hsub { font-size:.76rem; color: var(--txt-dim); margin-top:2px; }

/* ---------- Win overlay ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 50; display:grid; place-items:center;
  background: rgba(7,9,13,.78); backdrop-filter: blur(6px); padding: 20px;
  animation: fade .2s ease;
}
@keyframes fade { from { opacity:0 } to { opacity:1 } }
.overlay .panel {
  width: 100%; max-width: 420px; background: var(--surface); border:1px solid var(--line);
  border-radius: 20px; padding: 24px; text-align:center; box-shadow: var(--shadow);
}
.overlay .trophy { font-size: 3rem; }
.overlay h2 { font-size: 1.6rem; margin: 8px 0 2px; }
.overlay .win-sub { color: var(--txt-dim); margin-bottom: 16px; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--safe-b) + 18px); transform: translateX(-50%) translateY(20px);
  background: var(--surface-2); border:1px solid var(--line); color: var(--txt);
  padding: 12px 18px; border-radius: 12px; font-weight: 700; box-shadow: var(--shadow);
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 60; max-width: 90vw; text-align:center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.bust { border-color: var(--bad); color: #ffb3b3; }
.toast.win { border-color: var(--accent-3); color: var(--accent-3); }

/* ---------- misc ---------- */
.empty { text-align:center; color: var(--txt-dim); padding: 40px 10px; }
.empty .big { font-size: 2.4rem; margin-bottom: 8px; }
.spacer { flex: 1; }
.fine { font-size:.72rem; color: var(--txt-faint); text-align:center; margin-top: 14px; }
.row-between { display:flex; align-items:center; justify-content:space-between; gap: 10px; }
hr.sep { border:none; border-top:1px solid var(--line); margin: 16px 0; }

@media (min-width: 520px) {
  .dartboard { width: 380px; }
}

/* ---------- accessibility helpers / late additions ---------- */
.sr-only {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* Mode picker: 3 across, wraps to two rows for the six modes */
.segment.modes { grid-auto-flow: row; grid-template-columns: repeat(3, 1fr); }
.segment.modes button { min-height: 54px; font-size: .82rem; padding: 4px 2px; }
.segment.modes button .s { font-size: .6rem; }

/* Leg pips wrap; collapse to a count when there are many legs */
.pcard .legs { flex-wrap: wrap; }
.legnum { font-variant-numeric: tabular-nums; color: var(--txt-dim); font-weight: 800; }

/* Visible keyboard focus for all interactive controls */
.btn:focus-visible, .iconbtn:focus-visible, .chip:focus-visible, .pad button:focus-visible,
.mult-row button:focus-visible, .special-row button:focus-visible, .segment button:focus-visible,
.stepper button:focus-visible, .switch input:focus-visible + .track, .player-row .rm:focus-visible,
.history-item:focus-visible {
  outline: 3px solid var(--accent-3); outline-offset: 2px;
}
