:root {
  --bg: #0d1117;
  --panel: #161b22;
  --panel-2: #1f2630;
  --line: #2d3540;
  --text: #f0f3f6;
  --muted: #8b95a3;
  --accent: #19c37d;
  --accent-ink: #04140c;
  --red: #e5484d;
  --amber: #f5a524;
  --radius: 14px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); }
body { font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; overscroll-behavior: none; touch-action: manipulation; -webkit-text-size-adjust: 100%; }
button, input, select { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0 0 .5rem; line-height: 1.15; }
h1 { font-size: 1.6rem; } h2 { font-size: 1.25rem; } h3 { font-size: 1rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .06em; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.small { font-size: .85rem; }

#app { min-height: 100%; max-width: 560px; margin: 0 auto; padding: calc(var(--safe-top) + 12px) 16px calc(var(--safe-bottom) + 20px); }

/* Brand */
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 1.15rem; letter-spacing: -.01em; }
.brand span { color: var(--accent); }
.logo-mark { width: 30px; height: 30px; border-radius: 50%; background:
  radial-gradient(circle, var(--red) 0 16%, var(--accent) 17% 30%, #111 31% 45%, #e9e1c8 46% 58%, var(--red) 59% 70%, #111 71%); box-shadow: 0 0 0 2px #000; }

.topbar { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 16px; min-height: 40px; }
.topbar .title { font-weight: 700; font-size: 1.1rem; }
.icon-btn { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; cursor: pointer; }

/* Buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; width: 100%; padding: 14px 16px; border-radius: var(--radius);
  border: 1px solid var(--line); background: var(--panel-2); font-weight: 650; cursor: pointer; transition: transform .05s, background .15s; }
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn.danger { background: transparent; color: var(--red); border-color: color-mix(in srgb, var(--red) 40%, transparent); }
.btn.ghost { background: transparent; }
.btn:disabled { opacity: .45; pointer-events: none; }
.btn.big { padding: 20px 16px; font-size: 1.1rem; }
.row { display: flex; gap: 10px; }
.row > * { flex: 1; }
.stack { display: grid; gap: 10px; }
.stack-lg { display: grid; gap: 18px; }

/* Cards & forms */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
label.field { display: grid; gap: 6px; font-size: .9rem; color: var(--muted); }
input[type=text], input[type=email], input[type=password], select {
  width: 100%; padding: 13px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--bg); font-size: 16px; }
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.seg { display: flex; background: var(--bg); border: 1px solid var(--line); border-radius: 12px; padding: 3px; gap: 3px; }
.seg button { flex: 1; padding: 10px 6px; border: 0; border-radius: 9px; background: transparent; color: var(--muted); font-weight: 650; cursor: pointer; }
.seg button.on { background: var(--panel-2); color: var(--text); box-shadow: inset 0 0 0 1px var(--line); }
.switch { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.switch input { width: 46px; height: 28px; appearance: none; background: var(--line); border-radius: 99px; position: relative; cursor: pointer; transition: background .15s; }
.switch input::after { content: ''; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; transition: left .15s; }
.switch input:checked { background: var(--accent); }
.switch input:checked::after { left: 21px; }
.banner { padding: 10px 12px; border-radius: 12px; background: color-mix(in srgb, var(--amber) 15%, transparent); border: 1px solid color-mix(in srgb, var(--amber) 40%, transparent); color: #ffd58a; font-size: .85rem; }
.error { color: #ff8b8e; font-size: .9rem; min-height: 1.2em; }

/* Home */
.hero { padding: 22px 18px; border-radius: 20px; background: linear-gradient(140deg, #133a2a, #10161f 65%); border: 1px solid var(--line); }
.mode-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.mode-card { text-align: left; padding: 18px 16px; border-radius: 18px; border: 1px solid var(--line); background: var(--panel); cursor: pointer; display: grid; gap: 6px; }
.mode-card b { font-size: 1.1rem; }
.mode-card .emoji { font-size: 1.7rem; }
.list { display: grid; gap: 8px; }
.list-item { display: flex; align-items: center; gap: 10px; padding: 12px 14px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; }
.list-item .grow { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.avatar { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; background: var(--panel-2); font-weight: 800; color: var(--accent); flex: none; }

/* Game */
.game { display: grid; gap: 10px; }
.scoreboard { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.scoreboard.single { grid-template-columns: 1fr; }
.pcard { position: relative; padding: 10px 12px; border-radius: var(--radius); background: var(--panel); border: 2px solid var(--line); transition: border-color .2s, background .2s; }
.pcard.active { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 9%, var(--panel)); }
.pcard .pname { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding-right: 30px; }
.pcard .legs { position: absolute; top: 9px; right: 10px; background: var(--panel-2); border-radius: 8px; padding: 1px 8px; font-weight: 800; }
.pcard .rem { font-size: 3rem; font-weight: 850; letter-spacing: -.03em; line-height: 1; margin: 4px 0; font-variant-numeric: tabular-nums; }
.pcard .meta { display: flex; justify-content: space-between; color: var(--muted); font-size: .8rem; font-variant-numeric: tabular-nums; }
.checkout { text-align: center; font-weight: 700; color: var(--amber); min-height: 1.4em; letter-spacing: .03em; }
.turn { display: grid; grid-template-columns: repeat(3, 1fr) auto; gap: 8px; align-items: stretch; }
.dart-chip { padding: 10px 4px; text-align: center; border-radius: 12px; border: 1px dashed var(--line); background: var(--panel); font-weight: 800; font-size: 1.1rem; min-height: 48px; cursor: pointer; }
.dart-chip.filled { border-style: solid; background: var(--panel-2); }
.dart-chip.bust { color: var(--red); }
.turn-total { display: grid; place-items: center; padding: 0 12px; border-radius: 12px; background: var(--panel); font-weight: 850; font-size: 1.3rem; min-width: 64px; font-variant-numeric: tabular-nums; }
.status { font-size: .85rem; color: var(--muted); text-align: center; }
.status.bust { color: var(--red); font-weight: 800; font-size: 1rem; }

.cam-wrap { position: relative; width: min(100%, 62vh); aspect-ratio: 1 / 1; margin: 0 auto; background: #000; border-radius: var(--radius); overflow: hidden; }
.cam-wrap video, .cam-wrap canvas { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; }
.cam-wrap canvas { touch-action: none; }
.cam-badge { position: absolute; left: 8px; top: 8px; background: rgba(0,0,0,.6); padding: 4px 10px; border-radius: 99px; font-size: .8rem; display: flex; align-items: center; gap: 6px; }
.cam-badge::before { content: ''; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); animation: pulse 1.4s infinite; }
@keyframes pulse { 50% { opacity: .3; } }

.board-wrap { width: 100%; max-width: 420px; margin: 0 auto; }
svg.dartboard { width: 100%; height: auto; display: block; user-select: none; }
svg.dartboard.tappable { cursor: crosshair; }
.db-surround { fill: #0a0a0a; }
.db-black { fill: #1b1b1b; } .db-cream { fill: #eadfbf; } .db-red { fill: #d8343a; } .db-green { fill: #16935a; }
.dartboard path { stroke: #9aa0a6; stroke-width: .6; }
.db-num { fill: #fff; font: 700 17px system-ui, sans-serif; text-anchor: middle; dominant-baseline: central; pointer-events: none; }
.db-highlight { fill: rgba(245,165,36,.35); stroke: var(--amber) !important; stroke-width: 2.5 !important; pointer-events: none; }
.db-marker circle { fill: #00e5ff; stroke: #000; stroke-width: 2; }
.db-marker.bot circle { fill: #ffd400; }
.db-marker text { fill: #fff; stroke: #000; stroke-width: 3px; paint-order: stroke; font: 800 14px system-ui; text-anchor: middle; }
.db-marker { pointer-events: none; animation: pop .25s ease-out; transform-box: fill-box; transform-origin: center; }
@keyframes pop { from { transform: scale(2.2); opacity: 0; } }

.keypad { display: grid; gap: 6px; }
.keypad .nums { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.keypad button { padding: 13px 0; border-radius: 10px; border: 1px solid var(--line); background: var(--panel); font-weight: 750; font-size: 1.05rem; cursor: pointer; }
.keypad button:active { background: var(--panel-2); }
.keypad .mult button.on { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.keypad .mult { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.keypad .extra { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }

.controls { display: grid; grid-template-columns: 1fr 1fr 1.4fr; gap: 8px; }
.controls .btn { padding: 13px 8px; }

/* Calibration */
.cal-step { display: flex; align-items: center; gap: 10px; }
.cal-dot { width: 22px; height: 22px; border-radius: 50%; border: 2px solid #fff; display: grid; place-items: center; font-size: .7rem; font-weight: 800; }

/* Results */
table.stats { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
table.stats th, table.stats td { padding: 8px 6px; border-bottom: 1px solid var(--line); text-align: right; }
table.stats th:first-child, table.stats td:first-child { text-align: left; color: var(--muted); font-weight: 500; }
table.stats thead th { color: var(--text); font-weight: 750; }
.winner { text-align: center; padding: 24px 12px; }
.winner .trophy { font-size: 3rem; }

/* Modal & toast */
.modal-back { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: grid; align-items: end; z-index: 50; animation: fade .15s; }
.modal { background: var(--panel); border-top-left-radius: 22px; border-top-right-radius: 22px; padding: 18px 16px calc(var(--safe-bottom) + 18px); max-width: 560px; width: 100%; margin: 0 auto; max-height: 92vh; overflow: auto; animation: up .2s ease-out; }
@keyframes fade { from { opacity: 0; } } @keyframes up { from { transform: translateY(30px); opacity: .5; } }
#toast { position: fixed; left: 50%; bottom: calc(var(--safe-bottom) + 24px); transform: translateX(-50%) translateY(20px); background: #222b36; border: 1px solid var(--line); padding: 10px 16px; border-radius: 12px; opacity: 0; transition: .2s; pointer-events: none; z-index: 60; max-width: 90vw; text-align: center; }
#toast.show { opacity: 1; transform: translateX(-50%); }
.flash { animation: flash .6s; } @keyframes flash { 30% { background: color-mix(in srgb, var(--accent) 35%, var(--panel)); } }

@media (min-width: 900px) {
  #app { max-width: 1100px; }
  .game.wide { grid-template-columns: 1fr 1fr; align-items: start; column-gap: 20px; }
}

/* Camera view (v2): video is drawn into the canvas so it can be zoomed/panned */
.hidden-video { opacity: 0; pointer-events: none; width: 2px !important; height: 2px !important; }
.cam-wrap canvas { cursor: grab; }
.zoom-ctl { position: absolute; right: 8px; bottom: 8px; display: grid; gap: 6px; }
.zbtn { width: 40px; height: 40px; border-radius: 10px; border: 1px solid rgba(255,255,255,.2); background: rgba(0,0,0,.55); color: #fff; font-size: 1.2rem; cursor: pointer; }
.quality { font-size: .9rem; padding: 8px 12px; border-radius: 10px; background: var(--panel); border: 1px solid var(--line); }
.quality:empty { display: none; }
.quality.good { border-color: color-mix(in srgb, var(--accent) 50%, transparent); }
.quality.ok { border-color: color-mix(in srgb, var(--amber) 50%, transparent); }
.quality.bad { border-color: color-mix(in srgb, var(--red) 50%, transparent); }
.cal-dot.inline { display: inline-grid; width: 18px; height: 18px; vertical-align: middle; margin: 0 2px 0 6px; color: #000; }
details summary { cursor: pointer; }

/* Splash screen (shown on every launch, fades out once the app is ready) */
#splash { position: fixed; inset: 0; z-index: 1000; display: grid; place-items: center;
  background: radial-gradient(120% 70% at 50% 38%, #133a2a 0%, #10161f 55%, var(--bg) 100%);
  transition: opacity .45s ease, visibility .45s; animation: splash-failsafe 0s 8s forwards; }
#splash.hide { opacity: 0; visibility: hidden; pointer-events: none; }
.splash-inner { display: grid; justify-items: center; gap: 14px; margin-top: -6vh; }
.splash-icon { width: 112px; height: 112px; border-radius: 26px; box-shadow: 0 12px 40px rgba(0,0,0,.45), 0 0 0 1px var(--line);
  animation: splash-pop .6s cubic-bezier(.2,.9,.3,1.2) both; }
.splash-word { font-weight: 800; font-size: 2rem; letter-spacing: -.02em; color: var(--text); animation: splash-rise .5s .15s ease-out both; }
.splash-word span { color: var(--accent); }
.splash-word small { font-size: .55em; font-weight: 700; color: var(--muted); margin-left: 1px; }
.splash-tag { margin-top: -8px; color: var(--muted); font-size: .95rem; letter-spacing: .02em; animation: splash-rise .5s .25s ease-out both; }
.splash-bar { width: 132px; height: 4px; margin-top: 10px; border-radius: 99px; background: var(--line); overflow: hidden; animation: splash-rise .5s .3s ease-out both; }
.splash-bar i { display: block; width: 40%; height: 100%; border-radius: inherit; background: var(--accent); animation: splash-load 1.1s .35s ease-in-out infinite; }
.splash-ver { position: absolute; left: 0; right: 0; bottom: calc(var(--safe-bottom) + 24px); text-align: center; color: var(--muted); font-size: .78rem; opacity: .75; letter-spacing: .03em; }
@keyframes splash-pop { from { opacity: 0; transform: scale(.82); } to { opacity: 1; transform: none; } }
@keyframes splash-rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes splash-load { 0% { transform: translateX(-110%); } 100% { transform: translateX(260%); } }
@keyframes splash-failsafe { to { opacity: 0; visibility: hidden; } } /* never block the app if something goes wrong */
@media (prefers-reduced-motion: reduce) {
  .splash-icon, .splash-word, .splash-tag, .splash-bar { animation: none; }
  .splash-bar i { animation: none; width: 100%; opacity: .6; }
}

/* Version line at the bottom of the Home page */
.app-version { text-align: center; color: var(--muted); font-size: .75rem; opacity: .7; margin: 6px 0 0; letter-spacing: .03em; }

/* ---------- v2.6: Home menu, friends, profile ---------- */
.menu-btn { justify-content: flex-start; text-align: left; padding: 16px; font-size: 1.02rem; }
.menu-btn .mi { font-size: 1.3rem; width: 28px; text-align: center; }
.menu-btn .grow { flex: 1; }
.menu-btn .chev { color: var(--muted); font-size: 1.3rem; line-height: 1; }
.menu-btn.primary .chev { color: var(--accent-ink); }
.badge { display: inline-grid; place-items: center; min-width: 22px; height: 22px; padding: 0 7px; border-radius: 999px;
  background: var(--red); color: #fff; font-size: .78rem; font-weight: 800; line-height: 1; }
.badge[hidden] { display: none; }
.btn.sm { width: auto; flex: 0 0 auto; padding: 8px 12px; font-size: .85rem; border-radius: 10px; }
.section-h { margin: 0; display: flex; align-items: center; gap: 8px; font-size: 1rem; }
.mode-card.soon { opacity: .5; cursor: default; }
.profile-head { display: flex; align-items: center; gap: 14px; }
.avatar.lg { width: 60px; height: 60px; font-size: 1.6rem; }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(90px, 1fr)); gap: 8px; }
.stat-grid > div { background: var(--panel-2); border: 1px solid var(--line); border-radius: 12px; padding: 10px; display: grid; gap: 2px; text-align: center; }
.stat-grid b { font-size: 1.25rem; }
.stat-grid span { color: var(--muted); font-size: .75rem; }

/* ---------- v2.7: legal links ---------- */
.legal-links { text-align: center; margin: 0; }
.legal-links a, .card a, form a { color: var(--accent); }

/* ---------- v2.7.1: detection test mode ---------- */
.test-badge { margin: 6px 0 0; padding: 6px 10px; border-radius: 10px; color: #ffd58a;
  background: color-mix(in srgb, var(--amber) 14%, transparent); border: 1px solid color-mix(in srgb, var(--amber) 40%, transparent); }

/* ---------- v2.7.3: live detection results ---------- */
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.live-table { min-width: 640px; }
.live-table td, .live-table th { white-space: nowrap; }
.live-table tr.pending td { color: var(--muted); }
.live-table tr.new td { animation: liveIn 1.6s ease-out; }
@keyframes liveIn { from { background: color-mix(in srgb, var(--accent) 30%, transparent); } to { background: transparent; } }
.live-table .ok { color: var(--accent); font-weight: 700; }
.live-table .bad { color: var(--red); font-weight: 700; }
.live-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); margin: 0 2px 1px 4px; animation: livePulse 1.6s infinite; }
@keyframes livePulse { 50% { opacity: .3; } }
@media (prefers-reduced-motion: reduce) { .live-table tr.new td, .live-dot { animation: none; } }
@media (min-width: 900px) { #app:has(.live) { max-width: 1100px; } }
.live-table th, .live-table td { text-align: left; }
