/* Ping-pong — two players on one phone, or against the phone (js/ping-pong.js).
   Tokens on :root, redefined under body.dark-theme; the canvas reads the --pp-* colours,
   so a theme switch repaints the table too. */
:root {
    --pp-accent: #15803d;
    --pp-page-bg: #f1f5f9;
    --pp-card-bg: #ffffff;
    --pp-card-border: #e2e8f0;
    --pp-muted: #64748b;
    --pp-shadow: 0 10px 30px rgba(15, 23, 42, .12);
    --pp-floor: #d8c8ab;
    --pp-floor-2: rgba(120, 86, 40, .12);
    --pp-table: #15784f;
    --pp-table-edge: #0b4a31;
    --pp-line: #ffffff;
    --pp-net: #1f2937;
    --pp-ball: #f97316;
    --pp-red: #dc2626;
    --pp-red-dark: #7f1d1d;
    --pp-blue: #2563eb;
    --pp-blue-dark: #1e3a8a;
    --pp-wood: #c58b4f;
    --pp-score: #ffffff;
    --pp-overlay: rgba(241, 245, 249, .72);
}

body.dark-theme {
    --pp-accent: #4ade80;
    --pp-page-bg: #0b1120;
    --pp-card-bg: #1e293b;
    --pp-card-border: #334155;
    --pp-muted: #94a3b8;
    --pp-shadow: 0 10px 30px rgba(0, 0, 0, .45);
    --pp-floor: #1a1f2b;
    --pp-floor-2: rgba(255, 255, 255, .035);
    --pp-table: #0f5f3e;
    --pp-table-edge: #06301f;
    --pp-line: #e5e7eb;
    --pp-net: #0b0f17;
    --pp-ball: #fb923c;
    --pp-red: #ef4444;
    --pp-red-dark: #7f1d1d;
    --pp-blue: #3b82f6;
    --pp-blue-dark: #1e3a8a;
    --pp-wood: #a8743f;
    --pp-score: #ffffff;
    --pp-overlay: rgba(7, 11, 20, .7);
}

/* 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. */
.pp-body, body.pp-body#page-top {
    font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
    background: var(--pp-page-bg);
    color: var(--text-color);
    min-height: 100vh;
    overflow-x: clip;
}
body.pp-playing { overscroll-behavior: none; }
body.pp-max { overflow: hidden; }

.pp-main { padding-top: 92px; padding-bottom: 32px; }

/* ---- hero ---- */
.pp-hero { text-align: center; padding: 4px 0 12px; }
.pp-hero h1 { font-weight: 800; font-size: clamp(1.6rem, 4vw, 2.3rem); margin-bottom: 6px; }
.pp-hero-icon { color: var(--pp-accent); }
.pp-lead { max-width: 640px; margin: 0 auto; color: var(--pp-muted); font-size: 1rem; line-height: 1.55; }

/* ---- the stage: a portrait floor with the table, as tall as the window allows ---- */
.pp-stage {
    --pp-h: min(90vh, calc(100vh - 84px));
    position: relative;
    height: var(--pp-h);
    min-height: 440px;
    width: min(100%, calc(var(--pp-h) * .56));
    margin: 0 auto;
    background: var(--pp-floor);
    border-radius: 18px;
    overflow: hidden;
    box-shadow: var(--pp-shadow);
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
    -webkit-tap-highlight-color: transparent;
}
@supports (height: 100svh) {
    .pp-stage { --pp-h: min(90svh, calc(100svh - 84px)); }
}
@media (max-width: 575.98px) {
    .pp-stage { border-radius: 0; width: 100%; }
}

.pp-canvas {
    position: absolute;
    inset: 0;
    display: block;
    width: 100%;
    height: 100%;
    touch-action: none;
    cursor: crosshair;
}

.pp-sr {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
    border: 0;
}

/* real fullscreen, and the iPhone fallback that just covers the window */
.pp-stage:fullscreen { width: 100%; height: 100%; max-height: none; min-height: 0; border-radius: 0; }
.pp-stage:-webkit-full-screen { width: 100%; height: 100%; max-height: none; min-height: 0; border-radius: 0; }
.pp-stage.is-max {
    position: fixed;
    inset: 0;
    z-index: 1052;          /* over the site header (1050), under the site's dialogs (1055) */
    width: 100vw;
    height: 100vh;
    min-height: 0;
    border-radius: 0;
    margin: 0;
}
@supports (height: 100dvh) {
    .pp-stage.is-max { height: 100dvh; }
}

/* ---- HUD: two round buttons by the net, out on the floor beside the table ---- */
.pp-hud[hidden] { display: none; }
.pp-round {
    position: absolute;
    top: var(--pp-mid-y, 50%);
    transform: translateY(-50%);
    z-index: 2;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 1px solid var(--pp-card-border);
    background: var(--pp-card-bg);
    color: var(--text-color);
    display: grid;
    place-items: center;
    font-size: 15px;
    opacity: .85;
    box-shadow: 0 2px 8px rgba(0, 0, 0, .18);
    touch-action: manipulation;
    cursor: pointer;
}
.pp-round:hover, .pp-round:focus-visible { opacity: 1; }
.pp-round-left { left: var(--pp-side-x, 4px); }
.pp-round-right { right: var(--pp-side-x, 4px); }
.pp-round span[hidden] { display: none; }

/* ---- overlays (start, pause, game over) ---- */
.pp-overlay {
    position: absolute;
    inset: 0;
    z-index: 3;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 14px;
    padding: 16px;
    background: var(--pp-overlay);
    backdrop-filter: blur(3px);
    -webkit-backdrop-filter: blur(3px);
    touch-action: manipulation;
    overflow-y: auto;
}
.pp-overlay[hidden] { display: none; }
.pp-card {
    width: 100%;
    max-width: 340px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 18px 16px;
    border-radius: 18px;
    background: var(--pp-card-bg);
    border: 1px solid var(--pp-card-border);
    box-shadow: var(--pp-shadow);
    text-align: center;
    color: var(--text-color);
}
.pp-card h2 { font-weight: 800; font-size: 1.45rem; margin: 0; }
.pp-hint { margin: 0; color: var(--pp-muted); font-size: .92rem; line-height: 1.45; }
.pp-red-text { color: var(--pp-red); }
.pp-blue-text { color: var(--pp-blue); }

.pp-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 46px;
    padding: 10px 14px;
    border-radius: 12px;
    border: 1px solid var(--pp-card-border);
    background: var(--pp-page-bg);
    color: var(--text-color);
    font-weight: 700;
    font-size: 1rem;
    cursor: pointer;
    touch-action: manipulation;
    transition: border-color .15s, transform .1s;
}
.pp-btn:hover { border-color: var(--pp-accent); }
.pp-btn:active { transform: scale(.98); }
.pp-btn[hidden] { display: none; }
.pp-btn-primary { background: var(--pp-accent); border-color: var(--pp-accent); color: #fff; }
body.dark-theme .pp-btn-primary { color: #052e16; }
.pp-btn-ghost { background: transparent; }

.pp-sets { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; padding: 4px; border-radius: 12px; background: var(--pp-page-bg); border: 1px solid var(--pp-card-border); }
.pp-chip {
    min-height: 40px;
    border: 0;
    border-radius: 9px;
    background: transparent;
    color: var(--pp-muted);
    font-weight: 700;
    font-size: .92rem;
    cursor: pointer;
    touch-action: manipulation;
}
.pp-chip.is-on { background: var(--pp-card-bg); color: var(--text-color); box-shadow: 0 1px 4px rgba(0, 0, 0, .15); }

.pp-ai { display: flex; flex-direction: column; gap: 6px; padding-top: 2px; }
.pp-ai-label { font-weight: 700; font-size: .95rem; }
.pp-ai-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

.pp-switches { display: flex; justify-content: center; gap: 18px; flex-wrap: wrap; }
.pp-switch { display: inline-flex; align-items: center; justify-content: center; gap: 8px; margin: 2px 0 0; min-height: 32px; font-size: .92rem; color: var(--pp-muted); cursor: pointer; }
.pp-switch[hidden] { display: none; }
.pp-switch input { width: 18px; height: 18px; accent-color: var(--pp-accent); }
.pp-record { margin: 0; font-size: .82rem; color: var(--pp-muted); }

.pp-over-title[data-side="bottom"], .pp-mirror[data-side="bottom"] { color: var(--pp-red); }
.pp-over-title[data-side="top"], .pp-mirror[data-side="top"] { color: var(--pp-blue); }

/* in 2-player mode the top player gets an upside-down copy of the message */
.pp-mirror {
    display: none;
    margin: 0;
    transform: rotate(180deg);
    font-weight: 800;
    font-size: 1.45rem;
    color: var(--text-color);
    text-align: center;
}
.pp-stage.is-2p .pp-mirror { display: block; }

@media (max-height: 640px) {
    .pp-card { gap: 7px; padding: 14px 12px; }
    .pp-btn { min-height: 42px; padding: 8px 12px; }
    .pp-card h2 { font-size: 1.25rem; }
}

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