/* Bowling — a 3D lane on the phone (js/bowling.js). Theme-aware like the other game pages:
   tokens on :root, redefined under body.dark-theme. The lane itself is an indoor alley, the
   same in both themes; the cards, HUD and score sheet follow the theme. */
:root {
    --bw-accent: #4f46e5;
    --bw-accent-2: #db2777;
    --bw-page-bg: #f5f3ff;
    --bw-card-bg: #ffffff;
    --bw-card-border: #e0e0f0;
    --bw-muted: #64748b;
    --bw-shadow: 0 10px 30px rgba(30, 27, 75, .14);
    --bw-stage-bg: #0f0d24;
    --bw-overlay: rgba(15, 13, 36, .55);
    --bw-cell: #f8fafc;
    --bw-cell-cur: #eef2ff;
    --bw-strike: #db2777;
    --bw-spare: #4f46e5;
}

body.dark-theme {
    --bw-accent: #818cf8;
    --bw-accent-2: #f472b6;
    --bw-page-bg: #0b0a1a;
    --bw-card-bg: #1b1a33;
    --bw-card-border: #34325a;
    --bw-muted: #a5a8c4;
    --bw-shadow: 0 10px 30px rgba(0, 0, 0, .45);
    --bw-stage-bg: #05040f;
    --bw-overlay: rgba(5, 4, 15, .62);
    --bw-cell: #232144;
    --bw-cell-cur: #2e2b63;
    --bw-strike: #f472b6;
    --bw-spare: #a5b4fc;
}

/* 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. */
.bw-body, body.bw-body#page-top {
    font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
    background: var(--bw-page-bg);
    color: var(--text-color);
    min-height: 100vh;
    overflow-x: clip;
}
body.bw-max { overflow: hidden; }
.bw-main { padding-top: 96px; padding-bottom: 40px; }
.bw-game .container, .bw-hero .container { max-width: 760px; }

/* ---- hero ---- */
.bw-hero { text-align: center; padding: 4px 0 12px; }
.bw-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; }
.bw-hero-icon { width: 46px; height: 46px; border-radius: 14px; display: inline-grid; place-items: center; font-size: 22px; color: #fff; background: linear-gradient(135deg, #4f46e5, #db2777); box-shadow: var(--bw-shadow); }
.bw-lead { max-width: 600px; margin: 0 auto; color: var(--bw-muted); font-size: 1rem; line-height: 1.55; }

/* ---- the stage: the 3D lane fills it ---- */
.bw-stage {
    --bw-h: clamp(440px, calc(100vh - 150px), 760px);
    position: relative;
    height: var(--bw-h);
    width: 100%;
    margin: 0 auto;
    background: var(--bw-stage-bg);
    border-radius: 18px;
    overflow: hidden;
    box-shadow: var(--bw-shadow);
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
    -webkit-tap-highlight-color: transparent;
    outline: none;
}
@supports (height: 100svh) {
    .bw-stage { --bw-h: clamp(440px, calc(100svh - 150px), 760px); }
}
.bw-stage:focus-visible { box-shadow: 0 0 0 3px var(--bw-accent), var(--bw-shadow); }
@media (max-width: 575.98px) {
    .bw-stage { width: calc(100% + 24px); margin: 0 -12px; border-radius: 0; }
}
.bw-canvas { position: absolute; inset: 0; display: block; width: 100%; height: 100%; touch-action: none; cursor: grab; }
.bw-stage[data-phase="rolling"] .bw-canvas, .bw-stage[data-phase="sweep"] .bw-canvas { cursor: default; }

/* real full screen, and the iPhone fallback that just covers the window */
.bw-stage:fullscreen { width: 100%; height: 100%; border-radius: 0; margin: 0; }
.bw-stage:-webkit-full-screen { width: 100%; height: 100%; border-radius: 0; margin: 0; }
.bw-stage.is-max { position: fixed; inset: 0; z-index: 1052; width: 100vw; height: 100vh; margin: 0; border-radius: 0; }
@supports (height: 100dvh) { .bw-stage.is-max { height: 100dvh; } }

/* ---- HUD: who is bowling (top left) and the standing pins (top right) ---- */
.bw-hud { position: absolute; left: 10px; right: 10px; top: 10px; z-index: 2; display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; pointer-events: none; }
.bw-hud[hidden] { display: none; }
.bw-who { display: flex; align-items: center; gap: 8px; padding: 6px 12px 6px 8px; border-radius: 14px; background: rgba(10, 9, 30, .62); color: #fff; max-width: 62%; backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px); }
.bw-who-text { display: flex; flex-direction: column; line-height: 1.15; min-width: 0; }
.bw-who-text strong { font-size: 1rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bw-who-text small { font-size: .78rem; opacity: .85; white-space: nowrap; }
.bw-dot { width: 18px; height: 18px; flex: none; border-radius: 50%; background: radial-gradient(circle at 35% 30%, rgba(255, 255, 255, .7), transparent 45%), var(--c, #4f46e5); box-shadow: 0 1px 3px rgba(0, 0, 0, .45); }
.bw-rack { display: grid; grid-template-columns: repeat(8, 9px); grid-auto-rows: 11px; gap: 0; padding: 8px 10px; border-radius: 14px; background: rgba(10, 9, 30, .62); backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px); margin-right: 50px; }
.bw-pin { width: 12px; height: 12px; border-radius: 50%; background: #fff; box-shadow: 0 0 0 2px rgba(255, 255, 255, .15); transition: background .2s, opacity .2s; }
.bw-pin.is-down { background: transparent; box-shadow: inset 0 0 0 2px rgba(255, 255, 255, .35); opacity: .7; }
/* pin rows: 7-10 / 4-6 / 2-3 / 1 laid out on an 8-column grid */
.bw-pin[data-pin="6"] { grid-column: 1 / span 2; } .bw-pin[data-pin="7"] { grid-column: 3 / span 2; } .bw-pin[data-pin="8"] { grid-column: 5 / span 2; } .bw-pin[data-pin="9"] { grid-column: 7 / span 2; }
.bw-pin[data-pin="3"] { grid-column: 2 / span 2; } .bw-pin[data-pin="4"] { grid-column: 4 / span 2; } .bw-pin[data-pin="5"] { grid-column: 6 / span 2; }
.bw-pin[data-pin="1"] { grid-column: 3 / span 2; } .bw-pin[data-pin="2"] { grid-column: 5 / span 2; }
.bw-pin[data-pin="0"] { grid-column: 4 / span 2; }
.bw-pin { justify-self: center; }

.bw-tools { position: absolute; right: 10px; top: 10px; z-index: 4; display: flex; flex-direction: column; gap: 8px; }
.bw-round { width: 42px; height: 42px; border-radius: 50%; border: 0; display: grid; place-items: center; background: rgba(10, 9, 30, .62); color: #fff; font-size: 16px; cursor: pointer; touch-action: manipulation; backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px); }
.bw-round:hover, .bw-round:focus-visible { background: rgba(79, 70, 229, .85); }
.bw-round:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }
.bw-round[hidden], .bw-round span[hidden] { display: none; }

/* ---- big messages over the lane ---- */
.bw-banner { position: absolute; left: 50%; top: 38%; z-index: 2; transform: translate(-50%, -50%) scale(.9); margin: 0; padding: 10px 22px; border-radius: 18px; max-width: 92%; text-align: center; color: #fff; font-weight: 900; font-size: clamp(1.4rem, 7vw, 2.6rem); line-height: 1.15; letter-spacing: .02em; text-shadow: 0 3px 12px rgba(0, 0, 0, .55); background: rgba(10, 9, 30, .55); opacity: 0; pointer-events: none; transition: opacity .25s, transform .25s; }
.bw-banner.is-on { opacity: 1; transform: translate(-50%, -50%) scale(1); }
.bw-banner small { display: block; font-size: .5em; font-weight: 700; letter-spacing: 0; opacity: .9; }
.bw-banner.is-strike { background: linear-gradient(135deg, rgba(219, 39, 119, .9), rgba(79, 70, 229, .9)); }
.bw-banner.is-spare { background: linear-gradient(135deg, rgba(79, 70, 229, .9), rgba(14, 165, 233, .9)); }
.bw-speed { position: absolute; left: 12px; bottom: 12px; z-index: 2; margin: 0; padding: 4px 10px; border-radius: 10px; background: rgba(10, 9, 30, .55); color: #fff; font-weight: 700; font-size: .9rem; opacity: 0; transition: opacity .3s; pointer-events: none; }
.bw-speed.is-on { opacity: 1; }
.bw-swipe { position: absolute; left: 50%; bottom: 14px; z-index: 2; transform: translateX(-50%); margin: 0; padding: 8px 14px; border-radius: 999px; background: rgba(10, 9, 30, .6); color: #fff; font-weight: 700; font-size: .95rem; white-space: nowrap; pointer-events: none; }
.bw-swipe[hidden] { display: none; }
.bw-swipe-icon { display: inline-block; animation: bw-swipe 1.6s ease-in-out infinite; }
@keyframes bw-swipe { 0%, 15% { transform: translateY(6px); opacity: .4; } 60% { transform: translateY(-8px); opacity: 1; } 100% { transform: translateY(-8px); opacity: 0; } }
.bw-skip { position: absolute; right: 12px; bottom: 14px; z-index: 3; min-height: 44px; padding: 8px 14px; border: 0; border-radius: 999px; background: rgba(10, 9, 30, .7); color: #fff; font-weight: 700; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; }
.bw-skip[hidden] { display: none; }
.bw-loading { position: absolute; inset: 0; z-index: 1; display: grid; place-items: center; margin: 0; color: #c7d2fe; font-weight: 700; }
.bw-loading[hidden] { display: none; }

/* ---- overlays (setup, game over) ---- */
.bw-overlay { position: absolute; inset: 0; z-index: 5; display: flex; align-items: center; justify-content: center; padding: 14px; background: var(--bw-overlay); backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px); overflow-y: auto; touch-action: manipulation; }
.bw-overlay[hidden] { display: none; }
.bw-card { width: 100%; max-width: 360px; margin: auto; display: flex; flex-direction: column; gap: 10px; padding: 18px 16px; border-radius: 18px; background: var(--bw-card-bg); border: 1px solid var(--bw-card-border); box-shadow: var(--bw-shadow); color: var(--text-color); text-align: center; }
.bw-card h2 { font-weight: 800; font-size: 1.4rem; margin: 0; }
.bw-modes { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; padding: 4px; border-radius: 14px; background: var(--bw-page-bg); border: 1px solid var(--bw-card-border); }
.bw-mode { min-height: 52px; padding: 6px 8px; border: 0; border-radius: 10px; background: transparent; color: inherit; font-weight: 700; font-size: .92rem; line-height: 1.2; display: flex; align-items: center; justify-content: center; gap: 7px; cursor: pointer; touch-action: manipulation; text-align: left; }
.bw-mode small { display: block; font-weight: 500; font-size: .74rem; color: var(--bw-muted); }
.bw-mode[aria-checked="true"] { background: var(--bw-accent); color: #fff; }
.bw-mode[aria-checked="true"] small { color: rgba(255, 255, 255, .85); }
body.dark-theme .bw-mode[aria-checked="true"] { color: #0b0a1a; }
body.dark-theme .bw-mode[aria-checked="true"] small { color: rgba(11, 10, 26, .75); }
.bw-opt { display: flex; flex-direction: column; gap: 6px; }
.bw-opt[hidden] { display: none; }
.bw-label { font-weight: 700; font-size: .92rem; color: var(--bw-muted); }
.bw-chips { display: flex; gap: 6px; justify-content: center; }
.bw-chip { flex: 1; min-height: 44px; border-radius: 12px; border: 1px solid var(--bw-card-border); background: var(--bw-page-bg); color: inherit; font-weight: 700; cursor: pointer; touch-action: manipulation; }
.bw-chip[aria-checked="true"] { background: var(--bw-accent); border-color: var(--bw-accent); color: #fff; }
body.dark-theme .bw-chip[aria-checked="true"] { color: #0b0a1a; }
.bw-names { display: grid; gap: 6px; }
.bw-name { display: flex; align-items: center; gap: 8px; }
.bw-name input { flex: 1; min-width: 0; min-height: 44px; padding: 6px 10px; border-radius: 10px; border: 1px solid var(--bw-card-border); background: var(--bw-page-bg); color: inherit; font-size: 1rem; }
.bw-name input:focus { outline: 2px solid var(--bw-accent); outline-offset: 1px; }
.bw-mode:focus-visible, .bw-chip:focus-visible, .bw-btn:focus-visible { outline: 2px solid var(--bw-accent); outline-offset: 2px; }

.bw-btn { min-height: 48px; padding: 8px 14px; border-radius: 12px; border: 1px solid var(--bw-card-border); background: var(--bw-card-bg); color: inherit; font-weight: 700; font-size: 1rem; display: inline-flex; align-items: center; justify-content: center; gap: 8px; cursor: pointer; touch-action: manipulation; }
.bw-btn:hover { border-color: var(--bw-accent); }
.bw-btn[hidden] { display: none; }
.bw-btn-primary { background: var(--bw-accent); border-color: var(--bw-accent); color: #fff; }
body.dark-theme .bw-btn-primary { color: #0b0a1a; }
.bw-btn-ghost { background: transparent; border-color: transparent; color: var(--bw-muted); }
.bw-over-icon { width: 54px; height: 54px; margin: 0 auto; border-radius: 50%; display: grid; place-items: center; font-size: 24px; color: #fff; background: linear-gradient(135deg, #f59e0b, #db2777); }
.bw-over-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.bw-over-list li { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-radius: 12px; background: var(--bw-page-bg); font-weight: 700; text-align: left; }
.bw-over-list li .bw-n { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bw-over-list li strong { font-size: 1.15rem; }
.bw-over-list li.is-win { background: linear-gradient(135deg, rgba(245, 158, 11, .22), rgba(219, 39, 119, .18)); }
.bw-over-sub { margin: 0; color: var(--bw-muted); font-size: .92rem; }
.bw-over-sub:empty { display: none; }

.bw-actions { display: flex; justify-content: center; margin: 14px 0 10px; }
.bw-actions .bw-btn { min-width: 180px; }

/* ---- the score sheet ---- */
.bw-sheet { display: grid; gap: 8px; }
.bw-row { padding: 8px; border-radius: 14px; background: var(--bw-card-bg); border: 1px solid var(--bw-card-border); box-shadow: 0 2px 8px rgba(0, 0, 0, .04); }
.bw-row.is-cur { border-color: var(--bw-accent); box-shadow: 0 0 0 1px var(--bw-accent); }
.bw-row-head { display: flex; align-items: center; gap: 8px; margin: 0 2px 6px; font-weight: 700; }
.bw-row-head .bw-dot { width: 14px; height: 14px; }
.bw-row-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bw-row-tag { font-size: .75rem; font-weight: 600; color: var(--bw-muted); }
.bw-row-total { font-size: 1.15rem; font-weight: 800; }
.bw-frames { display: grid; grid-template-columns: repeat(9, minmax(0, 1fr)) minmax(0, 1.45fr); gap: 2px; }
.bw-fr { border-radius: 6px; background: var(--bw-cell); overflow: hidden; min-width: 0; }
.bw-fr.is-cur { background: var(--bw-cell-cur); box-shadow: inset 0 0 0 2px var(--bw-accent); }
.bw-fr-n { display: block; text-align: center; font-size: .6rem; line-height: 1.4; color: var(--bw-muted); }
.bw-marks { display: flex; justify-content: flex-end; height: 16px; }
.bw-marks span { flex: 0 0 50%; display: grid; place-items: center; font-size: .72rem; font-weight: 800; line-height: 1; }
.bw-fr.is-tenth .bw-marks span { flex-basis: 33.33%; }
.bw-marks span + span { box-shadow: inset 1px 0 0 var(--bw-card-border), inset 0 -1px 0 var(--bw-card-border); }
.bw-marks .is-x { color: var(--bw-strike); }
.bw-marks .is-s { color: var(--bw-spare); }
.bw-cum { display: block; height: 20px; text-align: center; font-size: .82rem; font-weight: 800; line-height: 20px; font-variant-numeric: tabular-nums; }
.bw-record { margin: 12px 0 0; text-align: center; color: var(--bw-muted); font-size: .9rem; }
.bw-record:empty { display: none; }
.bw-reset-wrap { text-align: center; margin: 2px 0 12px; }
.bw-link { border: 0; background: none; padding: 6px; color: var(--bw-muted); font-size: .85rem; text-decoration: underline; cursor: pointer; }

/* ---- help ---- */
.bw-help { margin: 8px auto 0; padding: 12px 14px; border-radius: 14px; background: var(--bw-card-bg); border: 1px solid var(--bw-card-border); }
.bw-help summary { font-weight: 700; cursor: pointer; min-height: 32px; }
.bw-help ul { margin: 10px 0 4px; padding-left: 20px; line-height: 1.55; }
.bw-help li { margin-bottom: 4px; }
.bw-powered { text-align: center; color: var(--bw-muted); font-size: .85rem; margin: 22px 0 0; }
.bw-powered a { color: var(--bw-accent); }

@media (max-width: 420px) {
    .bw-main { padding-top: 88px; }
    .bw-mode { font-size: .86rem; gap: 5px; padding: 6px 5px; }
    .bw-marks span { font-size: .66rem; }
    .bw-cum { font-size: .74rem; }
    .bw-row { padding: 6px; }
}
@media (prefers-reduced-motion: reduce) {
    .bw-swipe-icon { animation: none; }
    .bw-banner { transition: none; }
}
