/* Flipper — a 3D pinball table on the phone (js/flipper.js, physics in js/flipper-table.js).
   Theme-aware like the other game pages: tokens on :root, redefined under body.dark-theme. The cabinet
   and the table are a night scene in both themes; the cards, scores and help follow the theme. */
:root {
    --fp-accent: #6d28d9;
    --fp-accent-2: #db2777;
    --fp-accent-soft: #ede9fe;
    --fp-page-bg: #f5f3ff;
    --fp-card-bg: #ffffff;
    --fp-card-border: #e2dcf5;
    --fp-muted: #5f5a78;
    --fp-shadow: 0 10px 30px rgba(46, 16, 101, .16);
    --fp-cab: #120a24;
    --fp-cab-2: #241444;
    --fp-overlay: rgba(14, 8, 30, .55);
    --fp-dmd: #ff9a1f;
    --fp-gold: #f59e0b;
}

body.dark-theme {
    --fp-accent: #a78bfa;
    --fp-accent-2: #f472b6;
    --fp-accent-soft: #241a3d;
    --fp-page-bg: #0c0918;
    --fp-card-bg: #191430;
    --fp-card-border: #33295a;
    --fp-muted: #aaa3c8;
    --fp-shadow: 0 10px 30px rgba(0, 0, 0, .5);
    --fp-cab: #07040f;
    --fp-cab-2: #140b2b;
    --fp-overlay: rgba(6, 3, 14, .64);
    --fp-gold: #fbbf24;
}

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

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

/* ---- the stage: display on top, the 3D table below ---- */
.fp-stage {
    --fp-h: clamp(500px, calc(100vh - 120px), 940px);
    position: relative;
    height: var(--fp-h);
    width: 100%;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    background: radial-gradient(120% 70% at 50% 0%, var(--fp-cab-2), var(--fp-cab) 70%);
    border-radius: 18px;
    overflow: hidden;
    box-shadow: var(--fp-shadow);
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
    -webkit-tap-highlight-color: transparent;
    outline: none;
}
@supports (height: 100svh) {
    .fp-stage { --fp-h: clamp(500px, calc(100svh - 120px), 940px); }
}
.fp-stage:focus-visible { box-shadow: 0 0 0 3px var(--fp-accent), var(--fp-shadow); }
@media (max-width: 575.98px) {
    .fp-stage { width: calc(100% + 24px); margin: 0 -12px; border-radius: 0; }
}
.fp-stage:fullscreen { width: 100%; height: 100%; border-radius: 0; margin: 0; }
.fp-stage:-webkit-full-screen { width: 100%; height: 100%; border-radius: 0; margin: 0; }
.fp-stage.is-max { position: fixed; inset: 0; z-index: 1052; width: 100vw; height: 100vh; margin: 0; border-radius: 0; }
@supports (height: 100dvh) { .fp-stage.is-max { height: 100dvh; } }

.fp-top { flex: none; display: flex; align-items: center; gap: 8px; padding: 8px 8px 6px 10px; background: linear-gradient(180deg, #05030b, #0d0820); border-bottom: 2px solid #2b1a52; }
.fp-dmd { flex: 1 1 auto; min-width: 0; max-width: 460px; aspect-ratio: 32 / 9; margin: 0 auto; display: block; border-radius: 8px; background: #120700; box-shadow: inset 0 0 0 2px #2a1607, 0 0 18px rgba(255, 140, 20, .12); }
.fp-tools { flex: none; display: flex; gap: 6px; }
.fp-round { width: 42px; height: 42px; border-radius: 50%; border: 1px solid rgba(255, 255, 255, .14); display: grid; place-items: center; background: rgba(255, 255, 255, .08); color: #fff; font-size: 16px; cursor: pointer; touch-action: manipulation; }
.fp-round:hover, .fp-round:focus-visible { background: rgba(124, 58, 237, .85); }
.fp-round:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }
.fp-round span[hidden] { display: none; }

.fp-view { position: relative; flex: 1 1 auto; min-height: 0; overflow: hidden; touch-action: none; }
.fp-canvas { position: absolute; inset: 0; display: block; width: 100%; height: 100%; touch-action: none; }

/* touch zones flash when touched, a hint of where the flippers listen */
.fp-zone { position: absolute; top: 0; bottom: 0; width: 50%; z-index: 1; pointer-events: none; opacity: 0; transition: opacity .25s; display: flex; align-items: flex-end; justify-content: center; padding-bottom: 34%; }
.fp-zone span { font-size: .78rem; font-weight: 700; color: rgba(255, 255, 255, .8); background: rgba(10, 6, 24, .5); padding: 3px 10px; border-radius: 999px; }
.fp-zone-l { left: 0; background: linear-gradient(90deg, rgba(167, 139, 250, .16), transparent); }
.fp-zone-r { right: 0; background: linear-gradient(270deg, rgba(167, 139, 250, .16), transparent); }
.fp-zone.is-on { opacity: 1; }
.fp-stage[data-phase="play"].is-fresh .fp-zone { opacity: 1; }
.fp-zone.is-hit { opacity: 1; transition: none; }
@media (hover: hover) and (pointer: fine) { .fp-zone { display: none; } }

.fp-banner { position: absolute; left: 50%; top: 36%; 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.3rem, 6.5vw, 2.3rem); line-height: 1.15; letter-spacing: .02em; text-shadow: 0 3px 12px rgba(0, 0, 0, .55); background: linear-gradient(135deg, rgba(109, 40, 217, .88), rgba(219, 39, 119, .88)); opacity: 0; pointer-events: none; transition: opacity .25s, transform .25s; }
.fp-banner.is-on { opacity: 1; transform: translate(-50%, -50%) scale(1); }
.fp-banner small { display: block; font-size: .5em; font-weight: 700; letter-spacing: 0; opacity: .92; }

.fp-hint { position: absolute; left: 12px; right: 78px; bottom: 12px; z-index: 2; margin: 0; padding: 8px 12px; border-radius: 14px; background: rgba(10, 6, 24, .72); color: #fff; font-weight: 700; font-size: .9rem; line-height: 1.25; pointer-events: none; }
.fp-hint[hidden] { display: none; }

/* the plunger handle over the shooter lane (bottom right) */
.fp-plunger { position: absolute; right: 8px; bottom: 8px; z-index: 3; width: 60px; height: 104px; border-radius: 18px; background: rgba(10, 6, 24, .55); border: 1px solid rgba(255, 255, 255, .14); touch-action: none; cursor: grab; display: block; }
.fp-plunger[hidden] { display: none; }
.fp-plunger:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }
.fp-plunger-track { position: absolute; left: 50%; top: 10px; bottom: 10px; width: 8px; margin-left: -5px; border-radius: 6px; background: rgba(255, 255, 255, .12); overflow: hidden; }
.fp-plunger-fill { position: absolute; left: 0; right: 0; top: 0; height: 0; background: linear-gradient(180deg, #fde047, #f97316 60%, #ef4444); }
.fp-plunger-knob { position: absolute; left: 50%; top: 8px; width: 46px; height: 38px; margin-left: -23px; border-radius: 14px; display: grid; place-items: center; color: #1e0b3a; font-size: 18px; background: linear-gradient(180deg, #fef3c7, #f59e0b); box-shadow: 0 4px 10px rgba(0, 0, 0, .4); transform: translateY(var(--fp-pull, 0px)); }
.fp-plunger.is-ready .fp-plunger-knob { animation: fp-pulse 1.4s ease-in-out infinite; }
@keyframes fp-pulse { 0%, 100% { box-shadow: 0 4px 10px rgba(0, 0, 0, .4), 0 0 0 0 rgba(253, 224, 71, .7); } 50% { box-shadow: 0 4px 10px rgba(0, 0, 0, .4), 0 0 0 10px rgba(253, 224, 71, 0); } }

.fp-nudge { position: absolute; left: 50%; bottom: 10px; z-index: 3; width: 48px; height: 48px; margin-left: -24px; border-radius: 50%; border: 1px solid rgba(255, 255, 255, .2); background: rgba(10, 6, 24, .6); color: #fde68a; font-size: 18px; display: grid; place-items: center; cursor: pointer; touch-action: manipulation; }
.fp-nudge:active { transform: scale(.94); }
.fp-nudge:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }
.fp-nudge[hidden] { display: none; }
.fp-stage.is-wide .fp-nudge { left: auto; right: 22px; bottom: 18px; margin-left: 0; width: 54px; height: 54px; }
.fp-nudge.is-warn { background: rgba(220, 38, 38, .8); color: #fff; }

.fp-ai { position: absolute; left: 50%; top: 10px; z-index: 3; transform: translateX(-50%); display: flex; align-items: center; gap: 6px; padding: 5px 6px 5px 12px; border-radius: 999px; background: rgba(10, 6, 24, .72); color: #fff; font-weight: 700; font-size: .85rem; white-space: nowrap; }
.fp-ai[hidden] { display: none; }
.fp-chipbtn { min-height: 36px; min-width: 44px; padding: 4px 10px; border-radius: 999px; border: 1px solid rgba(255, 255, 255, .25); background: rgba(255, 255, 255, .1); color: #fff; font-weight: 800; cursor: pointer; touch-action: manipulation; display: inline-flex; align-items: center; gap: 5px; }
.fp-chipbtn[aria-pressed="true"] { background: #fde047; color: #1e0b3a; border-color: #fde047; }

/* wide screens: the room beside the cabinet shows the controls and the mission list */
.fp-side { position: absolute; top: 16px; z-index: 2; width: var(--fp-side-w, 220px); padding: 12px 14px; border-radius: 14px; background: rgba(10, 6, 24, .62); border: 1px solid rgba(167, 139, 250, .22); color: #ede9fe; font-size: .88rem; line-height: 1.35; pointer-events: none; }
.fp-side[hidden] { display: none; }
.fp-side-l { left: 16px; }
.fp-side-r { right: 16px; }
.fp-side h3 { font-size: .8rem; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; color: #c4b5fd; margin: 0 0 8px; }
.fp-keys { list-style: none; margin: 0; padding: 0; display: grid; gap: 7px; }
.fp-keys li { display: flex; flex-direction: column; gap: 2px; }
.fp-keys kbd { display: inline-block; min-width: 24px; padding: 1px 6px; border-radius: 6px; background: #2e2257; border: 1px solid #4c3d86; color: #fff; font: 700 .78rem system-ui, sans-serif; text-align: center; }
.fp-missions { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.fp-missions li { display: flex; align-items: center; gap: 8px; padding: 5px 8px; border-radius: 10px; background: rgba(255, 255, 255, .05); }
.fp-missions li b { flex: 1; min-width: 0; font-weight: 700; font-size: .82rem; }
.fp-missions li small { color: #c4b5fd; font-variant-numeric: tabular-nums; }
.fp-missions li i, .fp-missions li svg { width: 14px; color: #6b5fa0; }
.fp-missions li.is-done { opacity: .7; }
.fp-missions li.is-done i, .fp-missions li.is-done svg { color: #4ade80; }
.fp-missions li.is-cur { background: rgba(167, 139, 250, .22); box-shadow: inset 0 0 0 1px rgba(196, 181, 253, .5); }
.fp-missions li.is-cur i, .fp-missions li.is-cur svg { color: #fde047; }
.fp-mhint { margin: 8px 0 0; color: #ddd6fe; font-size: .8rem; }
.fp-loading { position: absolute; inset: 0; z-index: 4; display: grid; place-items: center; margin: 0; padding: 20px; text-align: center; color: #ddd6fe; font-weight: 700; background: var(--fp-cab); }
.fp-loading[hidden] { display: none; }
.fp-sr { position: absolute; width: 1px; height: 1px; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

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

.fp-btn { min-height: 48px; padding: 8px 14px; border-radius: 12px; border: 1px solid var(--fp-card-border); background: var(--fp-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; }
.fp-btn:hover { border-color: var(--fp-accent); }
.fp-btn[hidden] { display: none; }
.fp-btn-primary { background: var(--fp-accent); border-color: var(--fp-accent); color: #fff; }
body.dark-theme .fp-btn-primary { color: #12081f; }
.fp-btn-ghost { background: transparent; border-color: transparent; color: var(--fp-muted); }
.fp-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); }
.fp-over-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.fp-over-list li { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-radius: 12px; background: var(--fp-page-bg); font-weight: 700; text-align: left; }
.fp-over-list li .fp-n { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fp-over-list li strong { font-size: 1.1rem; font-variant-numeric: tabular-nums; }
.fp-over-list li.is-win { background: linear-gradient(135deg, rgba(245, 158, 11, .22), rgba(219, 39, 119, .18)); }
.fp-over-sub { margin: 0; color: var(--fp-muted); font-size: .92rem; }
.fp-over-sub:empty { display: none; }

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

/* ---- scores of the current game ---- */
.fp-board { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 8px; }
.fp-board:empty { display: none; }
.fp-pl { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 14px; background: var(--fp-card-bg); border: 1px solid var(--fp-card-border); min-width: 0; }
.fp-pl.is-cur { border-color: var(--fp-accent); box-shadow: 0 0 0 1px var(--fp-accent); }
.fp-dot { width: 14px; height: 14px; flex: none; border-radius: 50%; background: var(--c, #6d28d9); }
.fp-pl-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.2; }
.fp-pl-name { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.fp-pl-ball { font-size: .78rem; color: var(--fp-muted); }
.fp-pl-score { margin-left: auto; font-weight: 800; font-size: 1.1rem; font-variant-numeric: tabular-nums; }

/* ---- records ---- */
.fp-records { margin: 16px auto 0; padding: 12px 14px; border-radius: 14px; background: var(--fp-card-bg); border: 1px solid var(--fp-card-border); }
.fp-h2 { font-size: 1.05rem; font-weight: 800; margin: 0 0 8px; display: flex; align-items: center; gap: 8px; }
.fp-h2 svg, .fp-h2 i { color: var(--fp-gold); }
.fp-best { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; counter-reset: fp; }
.fp-best li { counter-increment: fp; display: flex; align-items: center; gap: 10px; padding: 6px 10px; border-radius: 10px; background: var(--fp-page-bg); font-weight: 600; }
.fp-best li::before { content: counter(fp); width: 22px; height: 22px; flex: none; border-radius: 50%; display: grid; place-items: center; font-size: .75rem; font-weight: 800; color: #fff; background: var(--fp-accent); }
body.dark-theme .fp-best li::before { color: #12081f; }
.fp-best li .fp-n { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fp-best li small { color: var(--fp-muted); font-weight: 500; }
.fp-best li strong { font-variant-numeric: tabular-nums; }
.fp-best li.is-empty { color: var(--fp-muted); font-weight: 500; }
.fp-best li.is-empty::before { display: none; }
.fp-vs { margin: 8px 0 0; color: var(--fp-muted); font-size: .9rem; }
.fp-vs:empty { display: none; }
.fp-reset-wrap { text-align: center; margin: 6px 0 0; }
.fp-link { border: 0; background: none; padding: 6px; color: var(--fp-muted); font-size: .85rem; text-decoration: underline; cursor: pointer; }

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

@media (max-width: 420px) {
    .fp-main { padding-top: 88px; }
    .fp-mode { font-size: .8rem; }
    .fp-round { width: 38px; height: 38px; font-size: 15px; }
    .fp-tools { gap: 4px; }
    .fp-top { padding: 6px 6px 5px 8px; }
}
@media (min-width: 900px) {
    .fp-game .container { max-width: 860px; }
}
@media (prefers-reduced-motion: reduce) {
    .fp-banner, .fp-zone { transition: none; }
    .fp-plunger.is-ready .fp-plunger-knob { animation: none; }
}
