:root {
  --bg: #14181f;
  --panel: #1d222b;
  --panel-2: #262c37;
  --line: #333b48;
  --text: #eef1f5;
  --muted: #98a2b3;
  --accent: #e8463a;
  --accent-2: #2e9e5b;
  --warn: #f2b33d;
  --radius: 14px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100dvh;
  padding-bottom: calc(64px + var(--safe-b));
  -webkit-tap-highlight-color: transparent;
}
a { color: inherit; }
button { font: inherit; color: inherit; }

.top {
  position: sticky; top: 0; z-index: 5;
  padding: calc(env(safe-area-inset-top, 0px) + 10px) 16px 10px;
  background: var(--bg); border-bottom: 1px solid var(--line);
}
.brand { display: inline-flex; align-items: center; gap: 8px; font-weight: 700; text-decoration: none; font-size: 18px; }

main { max-width: 640px; margin: 0 auto; padding: 16px; }
h1 { font-size: 22px; margin: 4px 0 14px; }
h2 { font-size: 15px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 22px 0 10px; }

.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
  display: grid; grid-template-columns: repeat(4, 1fr);
  background: var(--panel); border-top: 1px solid var(--line);
  padding-bottom: var(--safe-b);
}
.tabs a { text-align: center; padding: 14px 4px; text-decoration: none; color: var(--muted); font-weight: 600; }
.tabs a.active { color: var(--text); box-shadow: inset 0 3px 0 var(--accent); }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.stack > * + * { margin-top: 10px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.spacer { flex: 1; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 48px; padding: 0 18px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--panel-2); font-weight: 600; cursor: pointer; text-decoration: none;
  touch-action: manipulation;
}
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.green { background: var(--accent-2); border-color: var(--accent-2); color: #fff; }
.btn.ghost { background: transparent; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .45; cursor: default; }

body.logged-out .tabs { display: none; }
.field { display: grid; gap: 6px; }
.field > span { font-size: 13px; color: var(--muted); font-weight: 600; }
input[type=text], input[type=password] {
  width: 100%; min-height: 48px; padding: 0 14px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--bg); color: var(--text); font-size: 16px;
}
input[type=text]:focus, input[type=password]:focus { outline: 2px solid var(--accent); outline-offset: 0; }

/* Player picker */
.pick { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 12px; background: var(--panel-2); border: 1px solid transparent; }
.pick.on { border-color: var(--accent); }
.pick .name { flex: 1; font-weight: 600; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pick .order { width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; background: var(--line); font-weight: 700; font-size: 14px; flex: none; }
.pick.on .order { background: var(--accent); color: #fff; }
.pick-toggle { all: unset; flex: 1; display: flex; align-items: center; gap: 10px; cursor: pointer; min-height: 40px; min-width: 0; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; flex: none; }
.seg button { border: 0; background: transparent; padding: 8px 10px; font-size: 13px; font-weight: 700; color: var(--muted); cursor: pointer; min-width: 44px; }
.seg button.on { background: var(--text); color: var(--bg); }

/* Scoreboard */
.board { display: grid; gap: 8px; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); }
.player { background: var(--panel); border: 2px solid var(--line); border-radius: var(--radius); padding: 10px 12px; position: relative; }
.player.current { border-color: var(--accent); background: #2a1f22; }
.player.winner { border-color: var(--accent-2); }
.player .pname { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding-right: 30px; }
.player .rest { font-size: 44px; font-weight: 800; line-height: 1.05; font-variant-numeric: tabular-nums; }
.player .meta { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.player .mode { position: absolute; top: 10px; right: 10px; font-size: 11px; font-weight: 800; color: var(--muted); border: 1px solid var(--line); border-radius: 6px; padding: 1px 5px; }
.player .co { font-size: 12px; color: var(--warn); font-weight: 700; min-height: 1.4em; }

.turnbar { margin: 14px 0 6px; display: flex; align-items: baseline; gap: 10px; }
.turnbar .who { font-weight: 800; font-size: 18px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.visit-sum { font-size: 34px; font-weight: 800; font-variant-numeric: tabular-nums; }

.slots { display: grid; grid-template-columns: repeat(3, 1fr) auto; gap: 6px; align-items: center; margin-bottom: 8px; }
.slot {
  min-height: 44px; border-radius: 10px; border: 1px dashed var(--line); display: grid; place-items: center;
  font-weight: 800; font-size: 18px; font-variant-numeric: tabular-nums; color: var(--muted);
}
.slot.filled { border-style: solid; background: var(--panel-2); color: var(--text); }
.slot.next { border-color: var(--accent); border-style: solid; }
.slot-status { font-weight: 700; font-size: 14px; color: var(--muted); padding-left: 6px; min-width: 76px; text-align: right; }
.good { color: var(--accent-2); }
.bad { color: var(--accent); }

.mult { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-bottom: 6px; }
.mult button {
  min-height: 46px; border-radius: 10px; border: 1px solid var(--line); background: transparent;
  font-weight: 800; font-size: 15px; cursor: pointer; touch-action: manipulation;
}
.mult button.on { background: var(--text); color: var(--bg); border-color: var(--text); }
.mult button:nth-child(2).on { background: var(--accent-2); border-color: var(--accent-2); color: #fff; }
.mult button:nth-child(3).on { background: var(--accent); border-color: var(--accent); color: #fff; }

.numpad { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.numpad button {
  min-height: 52px; border-radius: 10px; border: 1px solid var(--line); background: var(--panel-2);
  font-size: 20px; font-weight: 700; cursor: pointer; touch-action: manipulation; user-select: none; padding: 0;
}
.numpad button:active:not(:disabled) { background: var(--line); }
.numpad button.alt { background: transparent; font-size: 16px; }
.numpad button.ok { background: var(--accent-2); border-color: var(--accent-2); color: #fff; font-size: 18px; }
.numpad button:disabled { opacity: .35; cursor: default; }
.mult button:disabled { opacity: .35; cursor: default; }
.icon-btn {
  display: inline-grid; place-items: center; color: var(--muted);
  min-width: 40px; min-height: 40px; border-radius: 10px; border: 1px solid var(--line);
  background: transparent; cursor: pointer; font-size: 16px; touch-action: manipulation;
}
.icon-btn:active { background: var(--panel-2); color: var(--accent); }
table.compact th, table.compact td { padding: 6px 4px; }
table.compact td:first-child { white-space: normal; word-break: break-word; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.darts-detail { font-size: 11px; color: var(--muted); font-weight: 600; }

.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 12px; }

/* Lists */
.list { display: grid; gap: 8px; }
.item { display: block; text-decoration: none; }
.item .title { font-weight: 700; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { font-size: 12px; color: var(--muted); font-weight: 600; }
td.num, th.num { text-align: right; }
.badge { display: inline-block; font-size: 11px; font-weight: 800; padding: 2px 6px; border-radius: 6px; background: var(--accent-2); color: #fff; vertical-align: 1px; }
.bust { color: var(--accent); text-decoration: line-through; }

.empty-state { text-align: center; padding: 28px 10px; color: var(--muted); }

.banner { text-align: center; padding: 18px; border-radius: var(--radius); background: linear-gradient(135deg, #1f5a3a, #2e9e5b); margin-bottom: 12px; }
.banner .big { font-size: 26px; font-weight: 800; }

#toast {
  position: fixed; left: 50%; bottom: calc(80px + var(--safe-b)); transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 999px; font-weight: 700;
  z-index: 20; max-width: calc(100% - 32px); text-align: center; box-shadow: 0 6px 24px rgba(0,0,0,.4);
}
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.6); z-index: 30; display: flex; align-items: flex-end; justify-content: center; }
.modal .sheet {
  background: var(--panel); width: 100%; max-width: 520px; border-radius: 18px 18px 0 0;
  padding: 20px 16px calc(20px + var(--safe-b)); border: 1px solid var(--line);
}
.modal h3 { margin: 0 0 6px; font-size: 20px; }
.modal .choices { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 14px 0 10px; }
@media (min-width: 600px) { .modal { align-items: center; } .modal .sheet { border-radius: 18px; } }
