/* Darts — a dartboard on a post in the park, 3D (js/darts.js, rules in js/darts-rules.js).
   Theme-aware like the other game pages: tokens on :root, redefined under body.dark-theme. The 3D scene itself is
   the park in daylight in both themes; only the page and the HUD follow the theme. */
:root {
    --dr-accent: #15803d;
    --dr-accent-2: #b91c1c;
    --dr-accent-soft: #dcfce7;
    --dr-page-bg: #f4f7f2;
    --dr-card-bg: #ffffff;
    --dr-card-border: #dfe6dc;
    --dr-muted: #5f6b63;
    --dr-shadow: 0 10px 30px rgba(20, 60, 30, .12);
    --dr-hud-bg: rgba(255, 255, 255, .86);
    --dr-hud-text: #0f172a;
    --dr-hud-border: rgba(15, 23, 42, .1);
    --dr-stage-bg: #bcd8ec;
    --dr-gold: #facc15;
}

body.dark-theme {
    --dr-accent: #4ade80;
    --dr-accent-2: #f87171;
    --dr-accent-soft: #14301f;
    --dr-page-bg: #0d1410;
    --dr-card-bg: #18221c;
    --dr-card-border: #2c3a31;
    --dr-muted: #9fb1a5;
    --dr-shadow: 0 10px 30px rgba(0, 0, 0, .45);
    --dr-hud-bg: rgba(15, 23, 20, .84);
    --dr-hud-text: #f1f5f9;
    --dr-hud-border: rgba(255, 255, 255, .12);
    --dr-stage-bg: #22313a;
}

/* clip, not hidden: the site-wide `body { overflow-x: hidden }` makes <body> a scroll
   container that never scrolls, which silently kills any position: sticky inside. */
.dr-body, body.dr-body#page-top {
    font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
    background: var(--dr-page-bg);
    color: var(--text-color);
    min-height: 100vh;
    overflow-x: clip;
}
body.dr-max { overflow: hidden; }
.dr-main { padding-top: 96px; padding-bottom: 36px; }
.dr-game .container, .dr-hero .container { max-width: 820px; }

/* ---- hero ---- */
.dr-hero { text-align: center; padding: 4px 0 10px; }
.dr-hero h1 { font-weight: 800; font-size: clamp(1.6rem, 5vw, 2.3rem); margin: 0 0 6px; display: inline-flex; align-items: center; gap: 12px; }
.dr-hero-icon { width: 46px; height: 46px; border-radius: 14px; display: inline-grid; place-items: center; font-size: 22px; color: #fff; background: linear-gradient(135deg, #16a34a, #b91c1c); box-shadow: var(--dr-shadow); }
.dr-lead { max-width: 600px; margin: 0 auto; color: var(--dr-muted); font-size: 1rem; line-height: 1.55; }

/* ---- setup ---- */
.dr-setup { max-width: 560px; margin: 8px auto 16px; padding: 16px; border-radius: 18px; background: var(--dr-card-bg); border: 1px solid var(--dr-card-border); box-shadow: var(--dr-shadow); }
.dr-setup[hidden], .dr-play[hidden] { display: none; }
.dr-h2 { font-size: 1.15rem; font-weight: 800; margin: 0 0 10px; text-align: center; }
.dr-chips { display: grid; gap: 6px; padding: 5px; margin: 0 0 12px; border-radius: 16px; background: var(--dr-page-bg); border: 1px solid var(--dr-card-border); }
.dr-chips-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.dr-chips-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); margin: 0; flex: 1; }
.dr-chips-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
@media (max-width: 420px) { .dr-chips-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.dr-chip { min-height: 48px; padding: 6px 6px; border: 0; border-radius: 12px; background: transparent; color: inherit; font-weight: 700; font-size: .95rem; line-height: 1.15; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; cursor: pointer; touch-action: manipulation; }
.dr-chip small { font-weight: 500; font-size: .74rem; color: var(--dr-muted); }
.dr-chip-wide { flex-direction: row; gap: 8px; }
.dr-chip[aria-checked="true"] { background: var(--dr-accent); color: #fff; }
body.dark-theme .dr-chip[aria-checked="true"] { color: #062611; }
.dr-chip[aria-checked="true"] small { color: inherit; opacity: .85; }
.dr-chip:focus-visible { outline: 2px solid var(--dr-accent); outline-offset: 2px; }
.dr-row { display: flex; align-items: center; gap: 10px; margin: 0 0 12px; }
.dr-row[hidden] { display: none; }
.dr-label { font-weight: 700; font-size: .9rem; color: var(--dr-muted); min-width: 64px; }
.dr-names { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin: 0 0 12px; }
.dr-names label { display: flex; align-items: center; gap: 8px; min-width: 0; font-size: .85rem; color: var(--dr-muted); }
.dr-names input { flex: 1; min-width: 0; height: 44px; padding: 6px 10px; border-radius: 10px; border: 1px solid var(--dr-card-border); background: var(--dr-page-bg); color: var(--text-color); font-size: 1rem; font-weight: 600; }
.dr-names input:focus { outline: 2px solid var(--dr-accent); outline-offset: 1px; }
.dr-names .dr-dot { flex: none; }
@media (max-width: 420px) { .dr-names { grid-template-columns: 1fr; } }

.dr-switch { position: relative; display: flex; align-items: center; gap: 10px; margin: 0 0 14px; font-weight: 600; font-size: .92rem; cursor: pointer; user-select: none; min-height: 44px; }
.dr-switch[hidden] { display: none; }
.dr-switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.dr-switch-track { position: relative; width: 46px; height: 26px; flex: none; border-radius: 999px; background: var(--dr-card-border); transition: background .15s; }
.dr-switch-track::after { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, .3); transition: transform .15s; }
.dr-switch input:checked + .dr-switch-track { background: var(--dr-accent); }
.dr-switch input:checked + .dr-switch-track::after { transform: translateX(20px); }
.dr-switch input:focus-visible + .dr-switch-track { outline: 2px solid var(--dr-accent); outline-offset: 2px; }

.dr-btn { min-height: 48px; padding: 8px 16px; border-radius: 12px; border: 1px solid var(--dr-card-border); background: var(--dr-card-bg); color: inherit; font-weight: 700; font-size: .98rem; display: inline-flex; align-items: center; justify-content: center; gap: 8px; cursor: pointer; touch-action: manipulation; box-shadow: 0 2px 6px rgba(0, 0, 0, .05); }
.dr-btn:hover:not(:disabled) { border-color: var(--dr-accent); }
.dr-btn:focus-visible { outline: 2px solid var(--dr-accent); outline-offset: 2px; }
.dr-btn-primary { background: var(--dr-accent); border-color: var(--dr-accent); color: #fff; }
body.dark-theme .dr-btn-primary { color: #062611; }
.dr-start { width: 100%; font-size: 1.08rem; min-height: 54px; }
.dr-resume { margin: 10px 0 0; text-align: center; }
.dr-resume .dr-btn { width: 100%; }
.dr-record { margin-top: 12px; font-size: .86rem; color: var(--dr-muted); text-align: center; line-height: 1.6; }
.dr-record:empty { display: none; }
.dr-record strong { color: var(--text-color); }

/* ---- the stage ---- */
.dr-stage {
    --dr-h: min(72vh, 640px);
    position: relative;
    height: var(--dr-h);
    min-height: 380px;
    margin: 4px auto 12px;
    border-radius: 18px;
    overflow: hidden;
    background: var(--dr-stage-bg);
    box-shadow: var(--dr-shadow);
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
    -webkit-tap-highlight-color: transparent;
    color: var(--dr-hud-text);
}
@supports (height: 100svh) { .dr-stage { --dr-h: min(72svh, 640px); } }
@media (max-width: 575.98px) {
    .dr-game .container { padding-left: 12px; padding-right: 12px; }
    .dr-stage { margin-left: -12px; margin-right: -12px; border-radius: 0; }
}
.dr-canvas-host { position: absolute; inset: 0; touch-action: none; cursor: crosshair; }
.dr-canvas-host canvas { display: block; width: 100%; height: 100%; touch-action: none; }
.dr-stage:fullscreen { width: 100%; height: 100%; margin: 0; border-radius: 0; }
.dr-stage:-webkit-full-screen { width: 100%; height: 100%; margin: 0; border-radius: 0; }
.dr-stage.is-max { position: fixed; inset: 0; z-index: 1052; width: 100vw; height: 100vh; min-height: 0; margin: 0; border-radius: 0; }
@supports (height: 100dvh) { .dr-stage.is-max { height: 100dvh; } }

/* HUD */
.dr-hud-top { position: absolute; top: 10px; left: 10px; z-index: 2; min-width: 132px; max-width: calc(100% - 76px); padding: 8px 12px 9px; border-radius: 14px; background: var(--dr-hud-bg); border: 1px solid var(--dr-hud-border); box-shadow: 0 4px 14px rgba(0, 0, 0, .14); pointer-events: none; backdrop-filter: blur(4px); }
.dr-who { display: flex; align-items: center; gap: 7px; font-weight: 700; font-size: .9rem; line-height: 1.2; white-space: nowrap; overflow: hidden; }
.dr-who-name { overflow: hidden; text-overflow: ellipsis; }
.dr-who-round { color: var(--dr-muted); font-weight: 600; font-size: .78rem; }
.dr-dot { width: 12px; height: 12px; border-radius: 50%; flex: none; background: #e11d48; box-shadow: 0 0 0 2px rgba(255, 255, 255, .7); }
.dr-big { font-size: 2.3rem; font-weight: 800; line-height: 1.05; font-variant-numeric: tabular-nums; letter-spacing: -.01em; }
.dr-big small { font-size: .9rem; font-weight: 700; color: var(--dr-muted); margin-left: 4px; }
.dr-checkout { margin-top: 2px; font-weight: 800; font-size: .92rem; color: var(--dr-accent); white-space: nowrap; }
.dr-checkout[hidden] { display: none; }

.dr-hud-btns { position: absolute; top: 10px; right: 10px; z-index: 3; display: flex; flex-direction: column; gap: 8px; }
.dr-round { width: 44px; height: 44px; border-radius: 50%; border: 1px solid var(--dr-hud-border); background: var(--dr-hud-bg); color: var(--dr-hud-text); display: grid; place-items: center; font-size: 16px; cursor: pointer; touch-action: manipulation; box-shadow: 0 2px 8px rgba(0, 0, 0, .18); }
.dr-round:focus-visible { outline: 2px solid var(--dr-accent); outline-offset: 2px; }
.dr-round [hidden] { display: none; }

.dr-hud-bottom { position: absolute; left: 0; right: 0; bottom: 10px; z-index: 2; display: flex; flex-direction: column; align-items: center; gap: 6px; pointer-events: none; padding: 0 10px; }
.dr-hint { margin: 0; padding: 4px 12px; border-radius: 999px; background: rgba(0, 0, 0, .5); color: #fff; font-size: .82rem; font-weight: 600; text-align: center; max-width: 100%; min-height: 1.6em; }
.dr-hint:empty { visibility: hidden; }
.dr-turn { display: flex; align-items: center; gap: 6px; padding: 6px; border-radius: 14px; background: var(--dr-hud-bg); border: 1px solid var(--dr-hud-border); box-shadow: 0 4px 14px rgba(0, 0, 0, .14); }
.dr-slot { min-width: 64px; height: 36px; padding: 0 6px; display: inline-grid; place-items: center; border-radius: 9px; background: rgba(127, 127, 127, .14); font-weight: 800; font-size: .95rem; font-variant-numeric: tabular-nums; white-space: nowrap; }
.dr-slot small { font-weight: 600; font-size: .72rem; opacity: .75; margin-left: 3px; }
.dr-slot.is-next { box-shadow: inset 0 0 0 2px var(--dr-gold); }
.dr-slot.is-miss { color: var(--dr-muted); }
.dr-slot.is-bust { color: var(--dr-accent-2); text-decoration: line-through; }
.dr-turn-total { min-width: 46px; height: 36px; display: inline-grid; place-items: center; border-radius: 9px; background: var(--dr-accent); color: #fff; font-weight: 800; font-size: 1rem; padding: 0 8px; font-variant-numeric: tabular-nums; }
body.dark-theme .dr-turn-total { color: #062611; }

.dr-toast { position: absolute; left: 50%; top: auto; bottom: 150px; z-index: 4; transform: translate(-50%, 0) scale(.9); padding: 10px 22px; border-radius: 16px; background: rgba(0, 0, 0, .72); color: #fff; font-weight: 800; font-size: clamp(1.4rem, 7vw, 2.4rem); text-align: center; white-space: nowrap; opacity: 0; pointer-events: none; transition: opacity .18s, transform .18s; }
.dr-toast.is-on { opacity: 1; transform: translate(-50%, 0) scale(1); }
.dr-toast small { display: block; font-size: .5em; font-weight: 700; opacity: .85; }
.dr-toast.is-bust { background: rgba(185, 28, 28, .9); }
.dr-toast.is-gold { background: rgba(161, 98, 7, .92); }

.dr-say { position: absolute; z-index: 3; left: 10px; top: 128px; max-width: min(240px, 66%); padding: 7px 11px; border-radius: 14px 14px 14px 4px; background: #fffbea; color: #3f2d12; font-weight: 700; font-size: .82rem; box-shadow: 0 4px 14px rgba(0, 0, 0, .2); pointer-events: none; }
.dr-say[hidden] { display: none; }
.dr-say b { color: #92400e; }

.dr-power { position: absolute; right: 10px; top: 116px; z-index: 2; width: 44px; padding: 6px 0; display: flex; flex-direction: column; align-items: center; gap: 6px; border-radius: 12px; background: var(--dr-hud-bg); border: 1px solid var(--dr-hud-border); pointer-events: none; }
.dr-power[hidden] { display: none; }
.dr-power-label { font-size: .62rem; font-weight: 800; text-transform: uppercase; letter-spacing: .02em; writing-mode: vertical-rl; transform: rotate(180deg); }
.dr-power-bar { position: relative; width: 12px; height: 110px; border-radius: 6px; background: linear-gradient(to top, #60a5fa, #22c55e 45%, #22c55e 60%, #ef4444); }
.dr-power-zone { position: absolute; left: -3px; right: -3px; bottom: 44%; height: 19%; border: 2px solid #fff; border-radius: 4px; }
.dr-power-mark { position: absolute; left: -6px; right: -6px; height: 4px; border-radius: 2px; background: var(--dr-hud-text); bottom: 50%; transition: bottom .25s; }

.dr-over { position: absolute; inset: 0; z-index: 6; display: grid; place-items: center; padding: 16px; background: rgba(0, 0, 0, .35); }
.dr-over[hidden] { display: none; }
.dr-over-card { width: min(100%, 360px); padding: 20px 18px; border-radius: 18px; background: var(--dr-card-bg); color: var(--text-color); border: 1px solid var(--dr-card-border); box-shadow: var(--dr-shadow); text-align: center; }
.dr-over-icon { font-size: 34px; color: #eab308; }
.dr-over-card h2 { font-size: 1.4rem; font-weight: 800; margin: 6px 0; }
.dr-over-card p { color: var(--dr-muted); margin: 0 0 14px; line-height: 1.5; }
.dr-over-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.dr-error { position: absolute; inset: 0; display: grid; place-items: center; padding: 20px; text-align: center; font-weight: 700; }
.dr-error[hidden] { display: none; }

/* ---- scoreboard ---- */
.dr-scores { display: grid; gap: 6px; max-width: 560px; margin: 0 auto 12px; }
.dr-prow { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 14px; background: var(--dr-card-bg); border: 1px solid var(--dr-card-border); }
.dr-prow.is-cur { border-color: var(--dr-accent); box-shadow: 0 0 0 1px var(--dr-accent) inset; }
.dr-prow-name { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dr-prow-meta { display: block; font-size: .78rem; font-weight: 500; color: var(--dr-muted); }
.dr-prow-score { font-size: 1.5rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.dr-cricket { width: 100%; border-collapse: separate; border-spacing: 0; border-radius: 14px; overflow: hidden; background: var(--dr-card-bg); border: 1px solid var(--dr-card-border); font-variant-numeric: tabular-nums; }
.dr-cricket th, .dr-cricket td { padding: 6px 4px; text-align: center; border-bottom: 1px solid var(--dr-card-border); }
.dr-cricket tr:last-child td, .dr-cricket tr:last-child th { border-bottom: 0; }
.dr-cricket thead th { font-size: .8rem; max-width: 80px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dr-cricket thead th.is-cur { color: var(--dr-accent); }
.dr-cricket tbody th { font-weight: 800; background: var(--dr-page-bg); width: 54px; }
.dr-cricket td { font-size: 1.15rem; font-weight: 800; }
.dr-cricket td.is-closed { color: var(--dr-accent); }
.dr-cricket .dr-pts td { font-size: 1.05rem; }
.dr-actions { display: flex; justify-content: center; gap: 8px; margin: 0 0 16px; }

/* ---- help ---- */
.dr-help { max-width: 640px; margin: 8px auto 0; padding: 12px 16px; border-radius: 16px; background: var(--dr-card-bg); border: 1px solid var(--dr-card-border); }
.dr-help summary { font-weight: 700; cursor: pointer; min-height: 32px; display: flex; align-items: center; gap: 8px; }
.dr-help ul { margin: 10px 0 0; padding-left: 20px; line-height: 1.55; }
.dr-help li { margin-bottom: 6px; }
.dr-powered { text-align: center; margin: 18px 0 0; color: var(--dr-muted); font-size: .85rem; }
.dr-powered a { color: inherit; }

@media (prefers-reduced-motion: reduce) {
    .dr-toast, .dr-power-mark { transition: none; }
}
