:root {
  --bg: #14171c;
  --bg2: #1c2027;
  --card: #232832;
  --card2: #2b313d;
  --line: #353c49;
  --text: #eef1f5;
  --muted: #9aa3b2;
  --red: #e53935;
  --red-d: #b71c1c;
  --green: #2e9d4a;
  --green-d: #1b6e31;
  --gold: #f9c33c;
  --blue: #3d8bfd;
  --accent: #e53935;   /* club colour, set from the branding */
  --on-accent: #fff;
  --radius: 14px;
  --shadow: 0 6px 24px rgba(0, 0, 0, .35);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.4;
  min-height: 100vh;
  -webkit-tap-highlight-color: transparent;
}
a { color: inherit; }
button, input, select { font: inherit; color: inherit; }
img { max-width: 100%; }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .6em; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.05rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.hidden { display: none !important; }
.row { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; }
.spread { justify-content: space-between; }
.grow { flex: 1; }
.center { text-align: center; }
.num { font-variant-numeric: tabular-nums; }

/* ------------------------------------------------------------ top bar */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 1rem;
  padding: .55rem 1rem; padding-top: max(.55rem, env(safe-area-inset-top));
  background: rgba(20, 23, 28, .92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: .5rem; text-decoration: none; font-weight: 800; font-size: 1.2rem; letter-spacing: .02em; min-width: 0; }
.brand img.logo { width: auto; max-width: 96px; height: 32px; object-fit: contain; }
.brand span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 16rem; }
.mainnav { display: flex; gap: .25rem; margin-left: auto; overflow-x: auto; }
.mainnav a {
  text-decoration: none; padding: .45rem .8rem; border-radius: 999px; color: var(--muted); white-space: nowrap; font-weight: 600;
}
.mainnav a.active { background: var(--card2); color: var(--text); }
body.in-game .topbar { display: none; }
.auth-menu { display: inline-flex; align-items: center; gap: .3rem; flex: none; border: 1px solid var(--line); background: var(--card2); color: var(--text);
  border-radius: 999px; padding: .2rem .55rem .2rem .25rem; cursor: pointer; min-height: 2.4rem; }
.auth-menu[hidden] { display: none; }
.sso-menu { padding: .2rem .6rem; font-size: 1.1rem; }
body.login-required .mainnav, body.login-required .auth-menu { display: none; }
.login { max-width: 30rem; margin: 3rem auto; text-align: center; padding: 2rem 1.5rem; }
.login-icon { font-size: 3rem; }
.login .remember { margin: 1.2rem 0; }
.auth-menu .avatars .avatar { border-color: var(--card2); }
.auth-menu .more { font-weight: 800; font-size: .85rem; }
.auth-menu .lock { font-size: .95rem; }
.auth-menu .count { display: none; font-weight: 800; }
@media (max-width: 600px) {
  .auth-menu { padding: .2rem .5rem; gap: .2rem; }
  .auth-menu .avatars, .auth-menu .more { display: none; }
  .auth-menu .count { display: inline; }
}
@media (max-width: 430px) {
  .topbar { gap: .35rem; padding-left: .45rem; padding-right: .45rem; }
  .mainnav { gap: 0; }
  .mainnav a { padding: .4rem .38rem; font-size: .85rem; }
  body.has-auth .brand { display: none; }
}

main { max-width: 1100px; margin: 0 auto; padding: 1rem; padding-bottom: 4rem; outline: none; }
body.in-game main { max-width: none; padding: .5rem; padding-bottom: .5rem; }

/* ------------------------------------------------------------ elements */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  border: 1px solid var(--line); background: var(--card2); color: var(--text);
  border-radius: 10px; padding: .6rem 1rem; cursor: pointer; font-weight: 600;
  text-decoration: none; user-select: none; transition: transform .05s, background .15s, opacity .15s;
}
.btn:hover { background: #343b48; }
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.disabled { opacity: .45; pointer-events: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.primary:hover { background: var(--accent); filter: brightness(1.12); }
.btn.success { background: var(--green); border-color: var(--green); color: #fff; }
.btn.danger { background: transparent; border-color: var(--red); color: #ff6b67; }
.btn.ghost { background: transparent; }
.btn.big { padding: 1rem 1.4rem; font-size: 1.15rem; border-radius: 14px; }
.btn.block { width: 100%; }
.btn.icon { padding: .5rem .7rem; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; }
.card + .card { margin-top: 1rem; }
.section { margin: 1.4rem 0; }
.section-title { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: .6rem; }
.section-title h2 { margin: 0; }

.grid { display: grid; gap: .8rem; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
.grid.small { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
/* cards side by side in a grid: no stacking margin, equal heights per row */
.grid > .card, .stat-tiles > .stat { margin-top: 0; height: 100%; }

label.field { display: flex; flex-direction: column; gap: .3rem; font-size: .9rem; color: var(--muted); }
input[type=text], input[type=number], input[type=search], select {
  background: var(--bg2); border: 1px solid var(--line); border-radius: 10px; padding: .6rem .7rem; color: var(--text); min-width: 0;
}
input:focus, select:focus, .btn:focus-visible { outline: 2px solid var(--blue); outline-offset: 1px; }
input[type=color] { width: 3rem; height: 2.4rem; border: 1px solid var(--line); border-radius: 8px; background: var(--bg2); padding: 2px; }
.check { display: flex; align-items: center; gap: .5rem; cursor: pointer; color: var(--text); }
.check input { width: 1.2rem; height: 1.2rem; accent-color: var(--accent); }
.form-grid { display: grid; gap: .8rem; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); align-items: end; }

.badge { display: inline-block; font-size: .72rem; font-weight: 700; padding: .12rem .5rem; border-radius: 999px; background: var(--card2); color: var(--muted); vertical-align: middle; }
.badge.red { background: rgba(229, 57, 53, .18); color: #ff7b77; }
.badge.green { background: rgba(46, 157, 74, .2); color: #6fdc8c; }
.badge.gold { background: rgba(249, 195, 60, .18); color: var(--gold); }

.empty { text-align: center; color: var(--muted); padding: 2rem 1rem; border: 1px dashed var(--line); border-radius: var(--radius); }

/* ------------------------------------------------------------ avatar */
.avatar {
  --size: 40px;
  width: var(--size); height: var(--size); border-radius: 50%; flex: none;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--c, #555); color: #fff; font-weight: 800; font-size: calc(var(--size) * .42);
  overflow: hidden; border: 2px solid var(--c, #555); text-transform: uppercase;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
.avatar.xl { --size: 120px; }
.avatar.lg { --size: 64px; }
.avatar.sm { --size: 28px; }
.avatar.emoji { background: var(--bg2); font-size: calc(var(--size) * .58); text-transform: none; }

/* ------------------------------------------------------------ home */
.hero { display: flex; flex-wrap: wrap; gap: 1rem; align-items: center; justify-content: space-between;
  background: radial-gradient(circle at 85% 30%, color-mix(in srgb, var(--accent) 25%, transparent), transparent 55%), var(--card);
  border: 1px solid var(--line); border-radius: 18px; padding: 1.4rem; }
.hero.has-banner { min-height: 11rem; align-items: flex-end;
  background: linear-gradient(to top, rgba(20, 23, 28, .88), rgba(20, 23, 28, .25) 70%), var(--banner) center / cover no-repeat, var(--card); }
.hero.has-banner .muted { color: #d5dae2; }
.hero.has-banner h1 { text-shadow: 0 2px 10px rgba(0, 0, 0, .6); }
.hero h1 { font-size: 1.9rem; margin-bottom: .3rem; }
.tile { cursor: pointer; text-align: left; display: flex; flex-direction: column; gap: .3rem; transition: border-color .15s, transform .1s; }
.tile:hover { border-color: var(--accent); }
.tile:active { transform: scale(.98); }
.tile .tile-title { font-weight: 800; font-size: 1.1rem; }
.tile .tile-sub { color: var(--muted); font-size: .9rem; }
.cat-beginner { --cat: var(--blue); }
.cat-classic { --cat: var(--red); }
.cat-party { --cat: var(--gold); }
.cat-practice { --cat: var(--green); }
.tile .cat-dot { width: .6rem; height: .6rem; border-radius: 50%; background: var(--cat); display: inline-block; margin-right: .4rem; }

.list { display: flex; flex-direction: column; gap: .5rem; }
.list-item { display: flex; align-items: center; gap: .8rem; padding: .7rem .9rem; background: var(--card); border: 1px solid var(--line); border-radius: 12px; text-decoration: none; }
a.list-item:hover { border-color: #4a5262; }
.avatars { display: flex; }
.avatars .avatar { margin-left: -8px; border-color: var(--card); }
.avatars .avatar:first-child { margin-left: 0; }

/* ------------------------------------------------------------ setup */
.mode-grid { display: grid; gap: .6rem; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); }
.mode-card { cursor: pointer; border: 2px solid var(--line); background: var(--card); border-radius: 12px; padding: .8rem; text-align: left; }
.mode-card.selected { border-color: var(--cat); background: var(--card2); }
.mode-card .name { font-weight: 800; }
.mode-card .short { color: var(--muted); font-size: .85rem; }
.chips { display: flex; flex-wrap: wrap; gap: .5rem; }
.chip { display: inline-flex; align-items: center; gap: .45rem; padding: .3rem .8rem .3rem .3rem; background: var(--card2); border: 2px solid transparent; border-radius: 999px; cursor: pointer; font-weight: 600; }
.chip.selected { border-color: var(--green); opacity: .5; }
.order-list .list-item { padding: .5rem .7rem; }
.order-list .pos { width: 1.6rem; text-align: center; font-weight: 800; color: var(--muted); }
.sticky-actions { position: sticky; bottom: 0; padding: .8rem 0; background: linear-gradient(transparent, var(--bg) 35%); }

/* ------------------------------------------------------------ game */
.game { display: flex; flex-direction: column; gap: .5rem; min-height: calc(100vh - 1rem); min-height: calc(100dvh - 1rem); }
.game-head { display: flex; align-items: center; gap: .5rem; flex-wrap: nowrap; min-width: 0; }
.game-head .title { font-weight: 800; }
.game-head .info { color: var(--muted); font-size: .9rem; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.game-head .tools { margin-left: auto; display: flex; gap: .35rem; flex: none; }

.board { display: grid; gap: .5rem; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
.board.many { grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); }
.pcard {
  position: relative; background: var(--card); border: 2px solid var(--line); border-radius: var(--radius);
  padding: .6rem .7rem; display: flex; flex-direction: column; gap: .2rem; transition: border-color .2s, transform .2s, opacity .2s;
  overflow: hidden;
}
.pcard::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 5px; background: var(--c); opacity: .9; }
.pcard.current { border-color: var(--c); box-shadow: 0 0 0 1px var(--c), var(--shadow); }
.pcard.out { opacity: .4; }
.pcard .who { display: flex; align-items: center; gap: .5rem; min-width: 0; }
.pcard .who .name { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pcard .score { font-size: 3rem; font-weight: 900; line-height: 1; font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.board.many .pcard .score { font-size: 2.2rem; }
.board.many .pcard { padding: .45rem .6rem; }
.pcard .meta { display: flex; gap: .7rem; flex-wrap: wrap; color: var(--muted); font-size: .82rem; }
.pcard .meta b { color: var(--text); font-weight: 700; }
.pcard .last { font-size: .82rem; color: var(--muted); min-height: 1.1em; }
.pcard .checkout { display: flex; gap: .3rem; flex-wrap: wrap; }
.pcard .checkout span { background: rgba(46, 157, 74, .2); color: #7fe39a; border-radius: 6px; padding: .05rem .4rem; font-weight: 700; font-size: .85rem; font-family: var(--mono); }
.pcard .legs { position: absolute; right: .6rem; top: .5rem; display: flex; gap: .3rem; }
.pcard .legs .badge { font-size: .8rem; }
.pcard .rank { position: absolute; right: .6rem; top: .5rem; }
.progress { height: 8px; background: var(--bg2); border-radius: 99px; overflow: hidden; }
.progress > div { height: 100%; background: var(--c, var(--green)); border-radius: 99px; transition: width .3s; }
.lives { font-size: 1.1rem; letter-spacing: .1em; }

.target-banner { margin-top: .5rem; text-align: center; font-weight: 800; font-size: 1.1rem; padding: .4rem; border-radius: 10px; background: var(--bg2); border: 1px solid var(--line); }

.cricket-table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.cricket-table th, .cricket-table td { text-align: center; padding: .15rem .2rem; border-bottom: 1px solid var(--line); }
.cricket-table th.num { font-size: 1.15rem; width: 4rem; background: var(--bg2); }
.cricket-table th.num.closed { color: var(--muted); text-decoration: line-through; }
.cricket-table td.cur { background: rgba(255, 255, 255, .04); }
.mark { font-size: 1.35rem; font-weight: 900; line-height: 1; color: var(--c, var(--text)); }
.mark.m0 { opacity: .15; }
.cricket-table .pts { font-size: 1.4rem; font-weight: 900; }

.visit-bar { display: flex; align-items: center; gap: .5rem; }
.visit-bar .slot { flex: 1; text-align: center; background: var(--bg2); border: 1px solid var(--line); border-radius: 10px; padding: .45rem 0; font-weight: 800; font-size: 1.25rem; font-family: var(--mono); min-height: 2.6rem; }
.visit-bar .slot.filled { background: var(--card2); }
.visit-bar .slot.next { border-color: var(--c, var(--blue)); }
.visit-bar .sum { min-width: 4.2rem; text-align: right; font-weight: 900; font-size: 1.6rem; font-variant-numeric: tabular-nums; }

.pad { display: grid; gap: .35rem; grid-template-columns: repeat(5, 1fr); user-select: none; }
.pad button {
  border: 0; border-radius: 10px; padding: 0; height: clamp(2.4rem, 6.2vh, 4.2rem); font-size: 1.3rem; font-weight: 800;
  background: var(--card2); color: var(--text); cursor: pointer; touch-action: manipulation; font-variant-numeric: tabular-nums;
  transition: background .1s, transform .05s;
}
.pad button:active { transform: scale(.95); background: #3d4554; }
.pad button.target { background: #2f4a37; box-shadow: inset 0 0 0 2px var(--green); }
.pad button.dim { opacity: .45; }
.pad .mod { background: #3a2a2a; }
.pad .mod.on { background: var(--red); color: #fff; }
.pad .mod.triple.on { background: var(--green); }
.pad .miss { background: #2a2f38; color: var(--muted); }
.pad .undo { background: #3b3324; color: var(--gold); }
.pad .wide2 { grid-column: span 2; }
.pad.disabled { opacity: .5; pointer-events: none; }

.numpad { display: grid; gap: .35rem; grid-template-columns: repeat(3, 1fr); }
.numpad button { border: 0; border-radius: 10px; height: clamp(2.8rem, 7.5vh, 4.2rem); font-size: 1.5rem; font-weight: 800; background: var(--card2); color: var(--text); cursor: pointer; touch-action: manipulation; }
.numpad button:active { transform: scale(.96); }
.numpad .ok { background: var(--green); color: #fff; }
.numpad .back { color: var(--gold); }
.numpad-display { text-align: center; font-size: 2.4rem; font-weight: 900; font-variant-numeric: tabular-nums; padding: .2rem; min-height: 3.2rem; }
.numpad-display.invalid { color: #ff6b67; }
.quick { display: grid; grid-template-columns: repeat(6, 1fr); gap: .35rem; }
.quick button { border: 1px solid var(--line); border-radius: 8px; background: var(--bg2); padding: .45rem 0; font-weight: 700; cursor: pointer; color: var(--text); }

.seg { display: inline-flex; background: var(--bg2); border: 1px solid var(--line); border-radius: 10px; padding: 3px; }
.seg button:disabled { opacity: .4; cursor: not-allowed; }
.seg button { border: 0; background: transparent; padding: .35rem .8rem; border-radius: 8px; color: var(--muted); font-weight: 700; cursor: pointer; }
.seg button.on { background: var(--card2); color: var(--text); }

.input-area { margin-top: auto; display: flex; flex-direction: column; gap: .45rem; }
.history { font-size: .85rem; color: var(--muted); max-height: 7.5rem; overflow-y: auto; }
.history div { display: flex; gap: .5rem; padding: .1rem 0; border-bottom: 1px solid rgba(255, 255, 255, .04); }
.history .h-name { font-weight: 700; color: var(--text); min-width: 5rem; }
.history .h-darts { font-family: var(--mono); flex: 1; }
.history .h-score { font-weight: 800; color: var(--text); }
.history .bust { color: #ff6b67; }

/* the visit history sits below the pad on phones and next to the board on wide screens */
.side-history { display: none; }
.pcard .who .nem, .cricket-table .nem { font-size: .95rem; filter: drop-shadow(0 0 4px rgba(229, 57, 53, .7)); }

/* tablet portrait: the input fills the screen below the board */
@media (min-width: 700px) and (orientation: portrait) {
  .game { height: calc(100vh - 1rem); height: calc(100dvh - 1rem); }
  .game-body { flex: 1; display: flex; flex-direction: column; min-height: 0; }
  .board-area { flex: none; max-height: 45%; overflow-y: auto; }
  .input-area { flex: 1; min-height: 0; margin-top: .6rem; }
  .pad { flex: 1; grid-auto-rows: 1fr; min-height: 20rem; gap: .5rem; }
  .pad button { height: auto; font-size: 1.9rem; border-radius: 14px; }
  .pcard .score { font-size: 4rem; }
  .board.many .pcard .score { font-size: 2.8rem; }
  .visit-bar .slot { font-size: 1.6rem; padding: .7rem 0; }
  .visit-bar .sum { font-size: 2rem; }
  .visit-card { flex: 1; display: flex; flex-direction: column; min-height: 0; }
  .numpad { flex: 1; grid-auto-rows: 1fr; gap: .5rem; }
  .numpad button { height: auto; min-height: 3.6rem; font-size: 2rem; }
  .quick button { padding: .8rem 0; font-size: 1.15rem; }
  .input-history .history { max-height: 5.5rem; }
}

/* landscape (tablet, desktop, phones on the side): board left, input right,
   the keypad uses the full height of the screen */
@media (min-width: 640px) and (orientation: landscape) {
  .game { height: calc(100vh - 1rem); height: calc(100dvh - 1rem); }
  .game-body { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(0, 1fr) minmax(340px, 1.2fr); gap: .8rem; }
  .board-area { display: flex; flex-direction: column; gap: .5rem; min-height: 0; overflow-y: auto; }
  .board-area .target-banner { margin-top: 0; font-size: 1.35rem; }
  .side-history { display: flex; flex: 1; min-height: 4rem; flex-direction: column; }
  .side-history .history { flex: 1; max-height: none; font-size: .95rem; }
  .input-history { display: none; }
  .input-area { margin-top: 0; min-height: 0; height: 100%; gap: .5rem; }
  .pad { flex: 1; min-height: 0; grid-template-rows: repeat(6, 1fr); gap: clamp(.3rem, 1vh, .6rem); }
  .pad button { height: auto; font-size: clamp(1.3rem, 4.4vh, 2.5rem); border-radius: 14px; }
  .visit-bar .slot { font-size: clamp(1.2rem, 4vh, 2rem); padding: clamp(.3rem, 1.2vh, .8rem) 0; }
  .visit-bar .sum { font-size: clamp(1.5rem, 5vh, 2.6rem); min-width: 5rem; }
  .pcard { padding: .7rem .9rem; }
  .pcard .score { font-size: clamp(3rem, 12vh, 7.5rem); }
  .board.many .pcard .score { font-size: clamp(2.2rem, 7vh, 4.5rem); }
  .board.n2 { grid-template-columns: 1fr 1fr; }
  .board.n1 .pcard .score { font-size: clamp(4rem, 18vh, 10rem); }
  .pcard .who .name { font-size: 1.1rem; }
  .pcard .meta, .pcard .last { font-size: .92rem; }
  .pcard .checkout span { font-size: 1.05rem; }
  .visit-card { flex: 1; display: flex; flex-direction: column; min-height: 0; }
  .numpad { flex: 1; min-height: 0; grid-auto-rows: 1fr; gap: clamp(.3rem, 1vh, .6rem); }
  .numpad button { height: auto; font-size: clamp(1.4rem, 4.6vh, 2.4rem); }
  .numpad-display { font-size: clamp(1.8rem, 6vh, 3rem); min-height: 0; padding: 0; }
  .quick button { padding: clamp(.3rem, 1.2vh, .75rem) 0; font-size: clamp(.95rem, 2.4vh, 1.2rem); }
  .cricket-table th, .cricket-table td { padding: clamp(.1rem, .9vh, .5rem) .2rem; }
  .cricket-table th.num { font-size: clamp(1.1rem, 3.6vh, 1.7rem); }
  .mark { font-size: clamp(1.3rem, 4.4vh, 2.3rem); }
  .cricket-table .pts { font-size: clamp(1.3rem, 4vh, 2.1rem); }
}
@media (min-width: 1500px) and (orientation: landscape) {
  .game-body { grid-template-columns: minmax(0, 1fr) 760px; }
}
/* big touch targets in the game header on tablets */
@media (pointer: coarse) and (min-width: 640px) {
  .game-head .btn.icon { min-width: 3rem; min-height: 3rem; font-size: 1.2rem; }
  .game-head .title { font-size: 1.15rem; }
  .seg button { padding: .6rem 1.1rem; font-size: 1rem; }
}

/* TV / board mode: no input, huge numbers */
.tv .input-area { display: none; }
.game.tv .game-body { display: block; }
.tv .pcard .score { font-size: clamp(3rem, 9vw, 7rem); }
.tv .board.many .pcard .score { font-size: clamp(2.4rem, 6vw, 5rem); }
.tv .pcard .who .name { font-size: 1.4rem; }
.tv .target-banner { font-size: 1.6rem; }

/* flash effects */
.flash-bust { animation: flash-red .6s; }
.flash-good { animation: flash-green .6s; }
@keyframes flash-red { 0% { box-shadow: inset 0 0 0 999px rgba(229, 57, 53, .35); } 100% { box-shadow: none; } }
@keyframes flash-green { 0% { box-shadow: inset 0 0 0 999px rgba(46, 157, 74, .35); } 100% { box-shadow: none; } }

/* ------------------------------------------------------------ toasts / modal */
#toasts { position: fixed; left: 50%; top: 1rem; transform: translateX(-50%); z-index: 100; display: flex; flex-direction: column; gap: .5rem; align-items: center; pointer-events: none; width: min(92vw, 520px); }
.toast { background: var(--card2); border: 1px solid var(--line); border-radius: 12px; padding: .7rem 1rem; box-shadow: var(--shadow); font-weight: 700; animation: toast-in .25s ease-out; text-align: center; }
.toast.error { border-color: var(--red); }
.toast.bust { background: var(--red-d); border-color: var(--red); font-size: 1.3rem; }
.toast.big { background: linear-gradient(135deg, #b71c1c, #e53935 40%, #f9c33c); font-size: 1.8rem; font-weight: 900; padding: 1rem 1.6rem; }
.toast.good { background: var(--green-d); border-color: var(--green); font-size: 1.15rem; }
@keyframes toast-in { from { opacity: 0; transform: translateY(-10px) scale(.96); } to { opacity: 1; transform: none; } }

.modal-backdrop { position: fixed; inset: 0; background: rgba(0, 0, 0, .65); z-index: 90; display: flex; align-items: center; justify-content: center; padding: 1rem; animation: fade .2s; }
.modal { background: var(--card); border: 1px solid var(--line); border-radius: 18px; width: min(560px, 100%); max-height: calc(100vh - 2rem); overflow-y: auto; padding: 1.2rem; box-shadow: var(--shadow); }
.modal.wide { width: min(860px, 100%); }
.modal h2 { margin-top: 0; }
.modal-actions { display: flex; gap: .5rem; justify-content: flex-end; flex-wrap: wrap; margin-top: 1rem; }
@keyframes fade { from { opacity: 0; } }

.winner { text-align: center; }
.winner .trophy { font-size: 3.5rem; line-height: 1; }
.winner .avatar { margin: .5rem auto; }
.winner h2 { font-size: 1.8rem; margin: .3rem 0; }
.ranking { list-style: none; padding: 0; margin: 1rem 0; text-align: left; }
.ranking li { display: flex; align-items: center; gap: .6rem; padding: .45rem .3rem; border-bottom: 1px solid var(--line); }
.ranking .place { width: 1.8rem; font-weight: 900; text-align: center; }

.confetti { position: fixed; inset: 0; pointer-events: none; z-index: 95; overflow: hidden; }
.confetti i { position: absolute; top: -12px; width: 9px; height: 14px; opacity: .9; animation: fall linear forwards; }
@keyframes fall { to { transform: translateY(110vh) rotate(720deg); } }

/* ------------------------------------------------------------ tables / stats */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; font-size: .92rem; }
table.data th, table.data td { padding: .5rem .55rem; border-bottom: 1px solid var(--line); text-align: right; white-space: nowrap; }
table.data th { color: var(--muted); font-weight: 600; font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; }
table.data th:first-child, table.data td:first-child { text-align: left; }
table.data tr.clickable { cursor: pointer; }
table.data tr.clickable:hover td { background: rgba(255, 255, 255, .03); }
.stat-tiles { display: grid; gap: .6rem; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); }
.stat { background: var(--bg2); border: 1px solid var(--line); border-radius: 12px; padding: .7rem; }
.stat .v { font-size: 1.5rem; font-weight: 900; font-variant-numeric: tabular-nums; }
.stat .l { color: var(--muted); font-size: .8rem; }
.profile-head { display: flex; gap: 1.2rem; align-items: center; flex-wrap: wrap; }
.avatar-edit { position: relative; cursor: pointer; border: 0; background: none; padding: 0; border-radius: 50%; }
.avatar-edit .cam { position: absolute; right: 0; bottom: 0; background: var(--card2); border: 1px solid var(--line); border-radius: 50%; width: 2.2rem; height: 2.2rem; display: flex; align-items: center; justify-content: center; font-size: 1.1rem; }
.trend svg { width: 100%; height: 140px; display: block; }
.tabs { display: flex; gap: .3rem; flex-wrap: wrap; margin-bottom: .8rem; }
.tabs button { border: 1px solid var(--line); background: var(--card); color: var(--muted); padding: .4rem .8rem; border-radius: 999px; font-weight: 700; cursor: pointer; }
.tabs button.on { background: var(--text); color: var(--bg); border-color: var(--text); }

@media (max-width: 600px) {
  .topbar { gap: .5rem; padding-left: .6rem; padding-right: .6rem; }
  .brand span { display: none; }
  .mainnav a { padding: .4rem .5rem; font-size: .92rem; }
  main { padding: .7rem; }
  .pcard .score { font-size: 2.5rem; }
  .game-head .title { font-size: .95rem; }
  .game-head .btn.icon { padding: .4rem .55rem; }
  .hero h1 { font-size: 1.5rem; }
}
/* ------------------------------------------------------------ PIN pad */
.pin-dialog { text-align: center; max-width: 380px; margin: 0 auto; }
.pin-dialog .avatar { margin: 0 auto .5rem; }
.pin-dialog h2 { margin-bottom: .2rem; }
.pin-lock { font-size: 2.6rem; }
.pin-dots { display: flex; justify-content: center; gap: 1rem; margin: 1rem 0 .3rem; }
.pin-dots span { width: 1.2rem; height: 1.2rem; border-radius: 50%; border: 2px solid var(--muted); transition: background .1s, border-color .1s; }
.pin-dots span.on { background: var(--text); border-color: var(--text); }
.pin-dots.shake { animation: shake .4s; }
.pin-error { color: #ff6b67; min-height: 1.4em; font-weight: 700; }
.remember { margin: .2rem 0 .4rem; }
.remember-opts { display: flex; flex-wrap: wrap; justify-content: center; gap: .35rem; margin-top: .35rem; }
.remember-opts button { border: 1px solid var(--line); background: var(--bg2); color: var(--muted); border-radius: 999px; padding: .4rem .75rem; font-weight: 700; cursor: pointer; min-height: 2.4rem; }
.remember-opts button.on { background: var(--text); color: var(--bg); border-color: var(--text); }
.pinpad { display: grid; grid-template-columns: repeat(3, 1fr); gap: .55rem; margin-top: .5rem; user-select: none; }
.pinpad button { border: 0; border-radius: 14px; height: clamp(3.6rem, 9vh, 5rem); font-size: 1.8rem; font-weight: 800; background: var(--card2); color: var(--text); cursor: pointer; touch-action: manipulation; }
.pinpad button:active { transform: scale(.95); background: #3d4554; }
.pinpad button.ghost { background: transparent; color: var(--muted); font-size: 1rem; }
.pinpad button.back { color: var(--gold); }
@keyframes shake { 0%, 100% { transform: none; } 20%, 60% { transform: translateX(-10px); } 40%, 80% { transform: translateX(10px); } }

/* ------------------------------------------------------------ profile */
.form-cols { display: grid; gap: .8rem; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.profile-form { display: flex; flex-direction: column; gap: .9rem; }
.profile-form select { width: 100%; }
.emoji-pick { display: flex; flex-wrap: wrap; gap: .35rem; margin-top: .3rem; }
.emoji-pick button { width: 2.8rem; height: 2.8rem; border-radius: 10px; border: 2px solid var(--line); background: var(--bg2); font-size: 1.4rem; cursor: pointer; color: var(--text); font-weight: 800; }
.emoji-pick button:first-child { font-size: .9rem; }
.emoji-pick button.on { border-color: var(--red); background: var(--card2); }
.pin-box { border: 1px solid var(--line); border-radius: 12px; padding: .8rem 1rem; margin: 0; }
.pin-box legend { padding: 0 .4rem; font-weight: 700; }
.pin-input { width: 10rem; }
.pin-input:not(:placeholder-shown) { letter-spacing: .3em; }
.list .pin-input { width: auto; }
input[type=password] { background: var(--bg2); border: 1px solid var(--line); border-radius: 10px; padding: .6rem .7rem; color: var(--text); min-width: 0; }

.profile-layout { display: grid; gap: 1rem; }
.profile-side { display: flex; flex-direction: column; gap: 1rem; min-width: 0; }
.profile-side .card + .card { margin-top: 0; }
.profile-main { min-width: 0; }
.profile-card { text-align: center; }
.profile-card h1 { margin: .5rem 0 .1rem; }
.profile-card .nick { font-size: 1.1rem; }
.profile-card .badges { margin-top: .5rem; display: flex; gap: .3rem; justify-content: center; flex-wrap: wrap; }
.motto { margin: .6rem auto 0; font-style: italic; color: var(--text); max-width: 32rem; quotes: "„" "“"; }
.motto::before { content: open-quote; }
.motto::after { content: close-quote; }
.nemesis h2 { margin-bottom: .8rem; }
.nemesis-duel { display: flex; align-items: center; justify-content: center; gap: 1rem; margin-bottom: .5rem; }
.nemesis-duel .vs { text-align: center; }
.nemesis-duel .record { font-size: 2rem; font-weight: 900; }
.nemesis .list-item { background: var(--bg2); }
.rivals { margin-top: 1rem; padding-top: .8rem; border-top: 1px solid var(--line); display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; }
.h2h { display: flex; align-items: center; gap: .6rem; text-decoration: none; padding: .35rem .2rem; border-bottom: 1px solid var(--line); }
.h2h:last-child { border-bottom: 0; }
.h2h-bar { width: 4.5rem; height: 8px; border-radius: 99px; background: var(--bg2); display: flex; overflow: hidden; flex: none; }
.h2h-bar .w { background: var(--green); }
.h2h-bar .l { background: var(--red); margin-left: auto; }
.nemesis-result { margin-top: .8rem; padding: .6rem .8rem; border-radius: 12px; background: rgba(229, 57, 53, .12); border: 1px solid rgba(229, 57, 53, .4); }
.nemesis-result.won { background: rgba(46, 157, 74, .14); border-color: rgba(46, 157, 74, .5); }
.player-tile { text-decoration: none; flex-wrap: nowrap; }
.player-tile .pname, .admin-row .pname { font-weight: 800; font-size: 1.1rem; }

@media (min-width: 960px) {
  .profile-layout { grid-template-columns: 360px minmax(0, 1fr); align-items: start; }
  .profile-side { position: sticky; top: 4.5rem; max-height: calc(100vh - 5.5rem); overflow-y: auto; }
}

/* ------------------------------------------------------------ admin */
.login-card { max-width: 720px; }
.admin-pick { display: grid; gap: .8rem; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
.admin-choice { display: flex; flex-direction: column; align-items: center; gap: .4rem; padding: 1rem .6rem; border-radius: 14px; border: 2px solid var(--line); background: var(--card2); color: var(--text); cursor: pointer; font-size: 1.05rem; }
.admin-choice:hover, .admin-choice:focus-visible { border-color: var(--gold); }
.admin-tabs { margin: 1rem 0 .8rem; }
.admin-tab > .card + .card { margin-top: 1rem; }
.admin-new { gap: .5rem; }
.admin-new input { flex: 1 1 10rem; min-width: 0; }
.admin-new .pin-input { flex: 0 1 9rem; }
.admin-list { display: grid; gap: .4rem; }
.admin-row { padding: .4rem .5rem .4rem .6rem; gap: .6rem; }
.admin-who { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.admin-row .pname { font-size: 1rem; }
.admin-badges .badge { margin-left: .2rem; }
.admin-row.archived { opacity: .6; }
.admin-actions { display: flex; gap: .3rem; flex: none; }
.btn.icon { padding: .4rem .55rem; min-width: 2.4rem; }
@media (max-width: 560px) {
  .admin-row { flex-wrap: wrap; }
  .admin-who { flex: 1 1 5rem; white-space: normal; }
  .admin-actions { margin-left: auto; }
}
.big-check { font-size: 1.05rem; }
.big-check input { width: 1.5rem; height: 1.5rem; }
.brand-images { display: grid; gap: .8rem; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
.brand-img { display: flex; flex-direction: column; gap: .4rem; }
.brand-img .preview { height: 90px; border: 1px dashed var(--line); border-radius: 10px; background: var(--bg2) center / contain no-repeat; display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: .85rem; }
.brand-img .preview.banner { background-size: cover; }
.brand-img .row { gap: .3rem; }
.color-row { display: flex; gap: .5rem; align-items: center; }
@media (min-width: 960px) {
  .admin-list { grid-template-columns: 1fr 1fr; }
}

/* ------------------------------------------------------------ setup (wide screens) */
.setup-layout { display: grid; gap: 0 1.5rem; }
@media (min-width: 960px) {
  .setup-layout { grid-template-columns: minmax(0, 1.25fr) minmax(320px, 1fr); align-items: start; }
  .setup-side { position: sticky; top: 4rem; max-height: calc(100vh - 4.5rem); overflow-y: auto; }
  .setup-side .section:first-child { margin-top: 0; }
  .setup-side .sticky-actions { padding-bottom: 0; }
}

/* ------------------------------------------------------------ touch devices */
@media (pointer: coarse) {
  .btn { min-height: 2.9rem; }
  .btn.icon { min-width: 2.9rem; }
  input[type=text], input[type=number], input[type=search], input[type=password], select { min-height: 2.9rem; font-size: 1rem; }
  .chip { padding: .45rem 1rem .45rem .45rem; font-size: 1.05rem; }
  .chip .avatar.sm { --size: 34px; }
  .mode-card { padding: 1rem; }
  .tabs button { padding: .6rem 1.1rem; }
  .check input { width: 1.5rem; height: 1.5rem; }
  .list-item { padding: .85rem 1rem; }
  .tile { padding: 1.2rem; }
}
@media (pointer: coarse) and (min-width: 700px) {
  body { font-size: 17px; }
  .mainnav a { padding: .6rem .95rem; }
  .grid.small { grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); }
  .mode-grid { grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); }
}

/* ------------------------------------------------------------ network feedback */
/* thin bar at the top while requests are on their way */
#net-bar {
  position: fixed; top: 0; left: 0; right: 0; height: 3px; z-index: 100; pointer-events: none;
  opacity: 0; transition: opacity .2s; overflow: hidden;
}
#net-bar.on { opacity: 1; }
#net-bar::before {
  content: ""; position: absolute; top: 0; bottom: 0; width: 40%;
  background: linear-gradient(90deg, transparent, var(--gold), var(--red), transparent);
  animation: net-bar 1.1s ease-in-out infinite;
}
@keyframes net-bar { from { left: -40%; } to { left: 100%; } }

/* the button that started a request: spinner, can't be pressed again */
.busy { position: relative; pointer-events: none; cursor: progress; }
.btn.busy:disabled, button.busy:disabled { opacity: 1; }
.busy::after {
  content: ""; position: absolute; inset: 0; margin: auto; width: 1.1em; height: 1.1em;
  border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%;
  animation: spin .7s linear infinite, fade-in .15s .12s both;
}
.btn.busy { color: transparent !important; }
.btn.busy::after { border-color: var(--text); border-right-color: transparent; }
.btn.primary.busy::after, .btn.success.busy::after { border-color: #fff; border-right-color: transparent; }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes fade-in { from { opacity: 0; } }

/* darts / visits entered but not yet confirmed by the server */
.visit-bar .slot.pending { animation: pending-pulse 1s ease-in-out infinite; border-style: dashed; }
@keyframes pending-pulse { 50% { opacity: .55; } }
.numpad-display .sending { display: inline-flex; align-items: center; gap: .5rem; opacity: .7; }
.numpad-display .sending::after {
  content: ""; width: .6em; height: .6em; border: 3px solid currentColor; border-right-color: transparent;
  border-radius: 50%; animation: spin .7s linear infinite;
}
.numpad button:disabled, .quick button:disabled { opacity: .45; cursor: progress; }
.pad .undo.pending, .btn.pending { animation: pending-pulse 1s ease-in-out infinite; }

/* PIN being checked */
.pin-dialog.checking .pin-dots span.on { animation: pending-pulse .8s ease-in-out infinite; }
.pin-dialog.checking .pinpad { opacity: .6; pointer-events: none; }

.toast.slow { border-color: var(--gold); font-weight: 600; }

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