:root {
    --rebound-bg: #050d1a;
    --rebound-bg-2: #071426;
    --rebound-court: #03080f;
    --rebound-cyan: #22d3ee;
    --rebound-cyan-dim: rgba(34, 211, 238, 0.35);
    --rebound-gold: #fbbf24;
    --rebound-gold-dim: rgba(251, 191, 36, 0.35);
    --rebound-text: #e8f4ff;
    --rebound-muted: #8fb3cc;
    --rebound-glass: rgba(7, 20, 38, 0.82);
    --rebound-border: rgba(34, 211, 238, 0.22);
    --rebound-shadow: 0 24px 60px rgba(0, 0, 0, 0.55);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Outfit', 'Segoe UI', system-ui, sans-serif;
    background:
        radial-gradient(at 15% 0%, rgba(34, 211, 238, 0.07) 0px, transparent 55%),
        radial-gradient(at 85% 0%, rgba(251, 191, 36, 0.06) 0px, transparent 55%),
        var(--rebound-bg);
    min-height: 100vh;
    color: var(--rebound-text);
    /* _base.css resets the body padding shorthand on mobile, which would push
       the shell under the fixed .app-header — keep the site's own token. */
    padding-top: var(--app-header-h, 72px);
}

/* ─── Shell ─── */
.game-shell {
    width: 100%;
    max-width: 940px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.rebound-topbar {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.rebound-back-btn {
    display: inline-flex;
    align-items: center;
    padding: 8px 14px;
    background: var(--rebound-glass);
    border: 1px solid var(--rebound-border);
    border-radius: 10px;
    color: var(--rebound-text);
    text-decoration: none;
    font-weight: 600;
    font-size: 0.85rem;
    white-space: nowrap;
    transition: border-color 0.18s ease, background 0.18s ease;
}

.rebound-back-btn:hover {
    border-color: var(--rebound-cyan);
    background: rgba(34, 211, 238, 0.12);
}

.rebound-chips {
    display: flex;
    gap: 6px;
    flex: 1;
    justify-content: center;
    flex-wrap: wrap;
}

.chip {
    display: inline-flex;
    align-items: center;
    padding: 5px 12px;
    border-radius: 999px;
    font-size: 0.72rem;
    font-weight: 800;
    letter-spacing: 1.4px;
    text-transform: uppercase;
    border: 1px solid var(--rebound-border);
    background: rgba(34, 211, 238, 0.08);
    color: var(--rebound-cyan);
}

.chip-diff {
    border-color: rgba(251, 191, 36, 0.3);
    background: rgba(251, 191, 36, 0.1);
    color: var(--rebound-gold);
}

.hud-btn {
    min-width: 44px;
    min-height: 44px;
    margin-left: auto;
    border-radius: 10px;
    border: 1px solid var(--rebound-border);
    background: var(--rebound-glass);
    color: var(--rebound-text);
    font-size: 1rem;
    cursor: pointer;
    transition: border-color 0.18s ease, transform 0.12s ease;
}

.hud-btn:hover {
    border-color: var(--rebound-gold);
    transform: translateY(-1px);
}

/* ─── HUD ─── */
.hud-top {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 14px;
    flex-wrap: wrap;
    padding: 10px 14px;
    background: var(--rebound-glass);
    border: 1px solid var(--rebound-border);
    border-radius: 16px;
    backdrop-filter: blur(6px);
}

.hud-caption {
    font-size: 0.68rem;
    font-weight: 800;
    letter-spacing: 2.4px;
    color: var(--rebound-muted);
    text-transform: uppercase;
}

.score-side {
    display: flex;
    align-items: baseline;
    gap: 8px;
}

.score-name {
    font-size: 0.72rem;
    font-weight: 800;
    letter-spacing: 1.6px;
    color: var(--rebound-muted);
    text-transform: uppercase;
}

.score-digits {
    font-size: 2rem;
    font-weight: 900;
    line-height: 1;
    min-width: 1.1ch;
    text-align: center;
    color: var(--rebound-gold);
    text-shadow: 0 0 18px rgba(251, 191, 36, 0.45);
    font-variant-numeric: tabular-nums;
    display: inline-block;
    transform-origin: 50% 0%;
}

.score-side:first-of-type .score-digits {
    color: var(--rebound-cyan);
    text-shadow: 0 0 18px rgba(34, 211, 238, 0.45);
}

.score-digits.flip {
    animation: scoreFlip 0.34s cubic-bezier(0.2, 0.8, 0.3, 1);
}

@keyframes scoreFlip {
    0% {
        transform: rotateX(-90deg) scale(1.18);
        opacity: 0.2;
    }
    60% {
        transform: rotateX(12deg) scale(1.06);
        opacity: 1;
    }
    100% {
        transform: rotateX(0deg) scale(1);
        opacity: 1;
    }
}

.score-dash {
    color: var(--rebound-muted);
    font-weight: 700;
}

.hud-stat {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 4px 10px;
    border-left: 1px solid rgba(143, 179, 204, 0.18);
}

.hud-label {
    font-size: 0.66rem;
    font-weight: 800;
    letter-spacing: 1.6px;
    color: var(--rebound-muted);
    text-transform: uppercase;
}

.hud-value {
    font-size: 1.1rem;
    font-weight: 800;
    line-height: 1.1;
    font-variant-numeric: tabular-nums;
}

/* ─── Court ─── */
.court-wrap {
    position: relative;
    width: 100%;
    border-radius: 20px;
    overflow: hidden;
    border: 1px solid var(--rebound-border);
    background: var(--rebound-court);
    box-shadow: var(--rebound-shadow), 0 0 46px rgba(34, 211, 238, 0.12);
}

#gameCanvas {
    display: block;
    width: 100%;
    height: auto;
    aspect-ratio: 8 / 5;
    touch-action: none;
    background: var(--rebound-court);
}

.serve-countdown {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    padding: 8px 22px;
    border-radius: 999px;
    border: 1px solid var(--rebound-border);
    background: rgba(3, 8, 15, 0.82);
    color: var(--rebound-gold);
    font-size: 0.86rem;
    font-weight: 900;
    letter-spacing: 4px;
    text-transform: uppercase;
    pointer-events: none;
    z-index: 6;
    animation: servePulse 1s linear;
}

@keyframes servePulse {
    from {
        opacity: 0.35;
        letter-spacing: 6px;
    }
    to {
        opacity: 1;
        letter-spacing: 3px;
    }
}

.match-point {
    position: absolute;
    left: 50%;
    top: 16px;
    transform: translateX(-50%);
    padding: 8px 20px;
    border-radius: 999px;
    background: rgba(251, 191, 36, 0.14);
    border: 1px solid rgba(251, 191, 36, 0.5);
    color: var(--rebound-gold);
    font-size: 0.78rem;
    font-weight: 900;
    letter-spacing: 3px;
    text-transform: uppercase;
    pointer-events: none;
    z-index: 6;
    animation: matchBlink 0.7s ease-in-out infinite alternate;
}

@keyframes matchBlink {
    from {
        opacity: 0.55;
        box-shadow: 0 0 0 rgba(251, 191, 36, 0);
    }
    to {
        opacity: 1;
        box-shadow: 0 0 26px rgba(251, 191, 36, 0.45);
    }
}

/* The site ships no global .hidden utility, so every runtime-toggled
   non-overlay element needs its own rule. */
.chip.hidden,
.serve-countdown.hidden,
.match-point.hidden {
    display: none;
}

/* ─── Overlays ─── */
.overlay {
    position: fixed;
    inset: var(--app-header-h, 72px) 0 0;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    background: rgba(3, 8, 15, 0.9);
    backdrop-filter: blur(9px);
    overflow-y: auto;
    z-index: var(--z-game-overlay, 100);
    padding: 12px;
    cursor: default;
}

.overlay.hidden {
    display: none;
}

.overlay-card {
    background: linear-gradient(150deg, rgba(7, 20, 38, 0.97) 0%, rgba(3, 8, 15, 0.99) 100%);
    border: 1px solid var(--rebound-border);
    border-radius: 24px;
    padding: 32px 30px;
    max-width: min(460px, 92vw);
    width: 100%;
    max-height: calc(100vh - var(--app-header-h, 72px) - 24px);
    max-height: calc(100dvh - var(--app-header-h, 72px) - 24px);
    margin: auto;
    overflow-y: auto;
    text-align: center;
    box-shadow: 0 0 60px rgba(34, 211, 238, 0.14);
    animation: cardIn 0.36s cubic-bezier(0.34, 1.4, 0.64, 1);
}

@keyframes cardIn {
    from {
        opacity: 0;
        transform: scale(0.9) translateY(16px);
    }
    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

.overlay-kicker {
    font-size: 0.72rem;
    font-weight: 800;
    letter-spacing: 2.4px;
    text-transform: uppercase;
    color: var(--rebound-gold);
    margin-bottom: 10px;
}

.overlay-kicker.story {
    color: var(--rebound-cyan);
}

.overlay-card h2 {
    font-size: 2rem;
    font-weight: 900;
    letter-spacing: -0.5px;
    margin-bottom: 8px;
    background: linear-gradient(135deg, #ffffff 10%, var(--rebound-cyan) 90%);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.overlay-sub,
.overlay-card p {
    color: var(--rebound-muted);
    font-size: 0.95rem;
    line-height: 1.55;
    margin-bottom: 16px;
}

.story-card {
    max-width: min(560px, 94vw);
}

.story-body {
    text-align: left;
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 20px;
    padding: 14px 16px;
    border-radius: 14px;
    background: rgba(34, 211, 238, 0.05);
    border: 1px solid rgba(34, 211, 238, 0.16);
}

.story-body p {
    margin-bottom: 0;
    font-size: 0.92rem;
}

.fail-card {
    border-color: rgba(239, 68, 68, 0.32);
    box-shadow: 0 0 60px rgba(239, 68, 68, 0.12);
}

.fail-card h2 {
    background: linear-gradient(135deg, #ffffff 10%, #f87171 90%);
    -webkit-background-clip: text;
    background-clip: text;
}

.victory-card {
    border-color: rgba(251, 191, 36, 0.34);
    box-shadow: 0 0 60px rgba(251, 191, 36, 0.16);
}

.victory-card h2 {
    background: linear-gradient(135deg, #ffffff 5%, var(--rebound-gold) 95%);
    -webkit-background-clip: text;
    background-clip: text;
}

/* ─── Start card controls ─── */
.option-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 12px;
    flex-wrap: wrap;
}

.option-row.hidden {
    display: none;
}

.option-label {
    font-size: 0.7rem;
    font-weight: 800;
    letter-spacing: 2px;
    color: var(--rebound-muted);
    text-transform: uppercase;
}

.option-tabs {
    display: flex;
    gap: 6px;
    background: rgba(34, 211, 238, 0.06);
    border: 1px solid rgba(34, 211, 238, 0.16);
    border-radius: 12px;
    padding: 4px;
}

.option-btn {
    border: none;
    background: transparent;
    color: var(--rebound-muted);
    font-family: inherit;
    font-size: 0.74rem;
    font-weight: 800;
    letter-spacing: 1.2px;
    text-transform: uppercase;
    padding: 9px 14px;
    border-radius: 9px;
    cursor: pointer;
    transition: background 0.16s ease, color 0.16s ease;
}

.option-btn.active {
    background: linear-gradient(135deg, rgba(34, 211, 238, 0.9), rgba(34, 211, 238, 0.6));
    color: #04121c;
    box-shadow: 0 4px 16px rgba(34, 211, 238, 0.3);
}

.mode-hint {
    font-size: 0.82rem;
    color: var(--rebound-gold);
    background: rgba(251, 191, 36, 0.08);
    border: 1px solid rgba(251, 191, 36, 0.24);
    border-radius: 10px;
    padding: 8px 12px;
    margin-bottom: 12px;
    text-align: left;
}

.mode-hint.hidden {
    display: none;
}

.how-to {
    text-align: left;
    background: rgba(34, 211, 238, 0.05);
    border: 1px solid rgba(34, 211, 238, 0.15);
    border-radius: 14px;
    padding: 14px 16px;
    margin-bottom: 16px;
}

.how-to h3 {
    font-size: 0.72rem;
    font-weight: 800;
    letter-spacing: 2px;
    text-transform: uppercase;
    color: var(--rebound-cyan);
    margin-bottom: 10px;
}

.how-to ul {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 7px;
}

.how-to li {
    position: relative;
    padding-left: 16px;
    font-size: 0.85rem;
    line-height: 1.45;
    color: var(--rebound-muted);
}

.how-to li::before {
    content: '';
    position: absolute;
    left: 0;
    top: 8px;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--rebound-gold);
}

.start-meta {
    display: flex;
    justify-content: center;
    gap: 8px;
    flex-wrap: wrap;
    margin-bottom: 16px;
}

.meta-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    border-radius: 999px;
    font-size: 0.7rem;
    font-weight: 800;
    letter-spacing: 1.4px;
    text-transform: uppercase;
    color: var(--rebound-gold);
    border: 1px solid rgba(251, 191, 36, 0.3);
    background: rgba(251, 191, 36, 0.08);
}

.meta-pill strong {
    color: var(--rebound-text);
    font-variant-numeric: tabular-nums;
}

.btn-primary,
.btn-secondary {
    display: block;
    width: 100%;
    padding: 14px 22px;
    border-radius: 14px;
    font-family: inherit;
    font-size: 0.98rem;
    font-weight: 800;
    letter-spacing: 1.6px;
    text-transform: uppercase;
    text-decoration: none;
    text-align: center;
    cursor: pointer;
    transition: transform 0.16s ease, box-shadow 0.16s ease, border-color 0.16s ease;
}

.btn-primary {
    border: none;
    color: #04121c;
    background: linear-gradient(135deg, var(--rebound-gold), #f59e0b);
    box-shadow: 0 8px 26px rgba(251, 191, 36, 0.35);
    margin-bottom: 10px;
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 12px 32px rgba(251, 191, 36, 0.45);
}

.btn-primary:active {
    transform: translateY(0);
}

.btn-secondary {
    background: transparent;
    border: 1px solid var(--rebound-border);
    color: var(--rebound-muted);
    font-size: 0.86rem;
    margin-bottom: 10px;
}

.btn-secondary:hover {
    border-color: var(--rebound-cyan);
    color: var(--rebound-text);
}

.btn-primary:last-child,
.btn-secondary:last-child {
    margin-bottom: 0;
}

/* Keep the primary action visible while a tall phone dialog scrolls. */
#startOverlay .btn-primary,
#prologuePlay,
#playAgainBtn {
    position: sticky;
    bottom: 0;
    z-index: 2;
    box-shadow: 0 -10px 22px rgba(3, 8, 15, 0.92), 0 8px 26px rgba(251, 191, 36, 0.35);
}

/* Short phones: the floating achievements badge would sit on the dialog. */
@media (max-width: 480px) and (max-height: 700px) {
    body:has(.overlay:not(.hidden)) .achievements-button {
        visibility: hidden;
    }
}

.stat-grid {
    display: flex;
    flex-direction: column;
    gap: 6px;
    background: rgba(34, 211, 238, 0.05);
    border: 1px solid rgba(34, 211, 238, 0.15);
    border-radius: 14px;
    padding: 12px 16px;
    margin-bottom: 18px;
    font-size: 0.9rem;
}

.stat-row {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    color: var(--rebound-muted);
}

.stat-row strong {
    color: var(--rebound-gold);
    font-variant-numeric: tabular-nums;
}

/* ─── Bottom hint ─── */
.rebound-bottombar {
    display: flex;
    justify-content: center;
}

.controls-hint {
    font-size: 0.78rem;
    color: var(--rebound-muted);
    text-align: center;
    padding: 6px 12px;
    border-radius: 10px;
    background: rgba(7, 20, 38, 0.6);
    border: 1px solid rgba(143, 179, 204, 0.14);
}

/* ─── Focus ─── */
button:focus-visible,
a:focus-visible,
.option-btn:focus-visible {
    outline: 2px solid var(--rebound-gold);
    outline-offset: 2px;
}

/* ─── Responsive ─── */
@media (max-width: 768px) {
    .game-shell {
        gap: 8px;
    }

    .rebound-back-btn {
        font-size: 0.75rem;
        padding: 6px 10px;
    }

    .rebound-chips {
        order: 3;
        flex-basis: 100%;
    }

    .chip {
        font-size: 0.66rem;
        padding: 4px 10px;
        letter-spacing: 1px;
    }

    .hud-top {
        gap: 8px;
        padding: 8px 10px;
        border-radius: 14px;
    }

    .hud-caption {
        flex-basis: 100%;
        text-align: center;
    }

    .score-digits {
        font-size: 1.5rem;
    }

    .hud-stat {
        padding: 2px 6px;
    }

    .hud-value {
        font-size: 0.95rem;
    }

    .court-wrap {
        border-radius: 14px;
    }

    .overlay {
        padding: 12px;
    }

    .overlay-card {
        padding: 24px 18px;
        max-width: 96vw;
        border-radius: 20px;
    }

    .overlay-card h2 {
        font-size: 1.5rem;
    }

    .story-body {
        padding: 12px;
    }

    .option-row {
        flex-direction: column;
        align-items: stretch;
        gap: 6px;
    }

    .option-tabs {
        justify-content: center;
    }

    .option-btn {
        flex: 1;
        padding: 10px 8px;
        font-size: 0.7rem;
    }

    .serve-countdown {
        font-size: 0.72rem;
        letter-spacing: 3px;
        padding: 6px 16px;
    }

    .match-point {
        font-size: 0.68rem;
        top: 10px;
        padding: 6px 14px;
    }
}

@media (max-width: 480px) {
    .score-digits {
        font-size: 1.3rem;
    }

    .hud-label,
    .score-name {
        font-size: 0.6rem;
        letter-spacing: 1.2px;
    }

    .controls-hint {
        font-size: 0.72rem;
    }

    .overlay-card {
        padding: 20px 14px;
    }
}

/* ─── Reduced motion ─── */
@media (prefers-reduced-motion: reduce) {
    .overlay-card,
    .score-digits.flip,
    .serve-countdown,
    .match-point {
        animation: none;
    }

    .btn-primary,
    .hud-btn,
    .option-btn {
        transition: none;
    }
}
