/* =========================================================================
   CocoaCool Play — game screen. Board is a responsive square; on touch it
   sits above a Game Boy–style control deck (dpad + A). The result screen
   lives outside the stage and scrolls with the page.
   ========================================================================= */

.game-page {
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 20px 14px 36px;
}

.game-top {
    width: 100%;
    max-width: 560px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 14px;
}
.game-top .brand img {
    height: auto; width: auto;
    max-height: 44px; max-width: 44vw;
    object-fit: contain;
    display: block;
}
.game-top__how { font-weight: 600; white-space: nowrap; }
.lbl-short { display: none; }

/* Shell = stage + (on touch) the control deck, stacked and centred. */
.game-shell {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
}
/* The stage + control deck only exist while a run is going. On the intro
   and result screens the shell is hidden and the .game-screen panel flows
   with the page (scrolls with the window, no fixed-height box). */
body:not(.is-playing) .game-shell { display: none; }

/* The square stage ------------------------------------------------- */
.stage {
    position: relative;
    width: min(92vw, 560px);
    aspect-ratio: 1 / 1;
    border-radius: 22px;
    overflow: hidden;
    box-shadow: var(--shadow);
    background: linear-gradient(#cfeaf4 0%, #cfeaf4 55%, #efd9c2 55%, #efd9c2 100%);
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
    -webkit-tap-highlight-color: transparent;
}
.stage canvas {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    display: block;
}

/* HUD ----------------------------------------------------------- */
.hud {
    position: absolute;
    top: 14px; left: 16px; right: 16px;
    display: flex;
    justify-content: space-between;
    font-weight: 800;
    color: var(--ink);
    text-shadow: 0 1px 0 rgba(255,255,255,.6);
    pointer-events: none;
    font-variant-numeric: tabular-nums;
}
.hud .score { font-size: 1.5rem; }
.hud .best  { font-size: .95rem; opacity: .7; align-self: center; }

/* Overlays that sit ON the stage (start / loading) ------------- */
.overlay {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    gap: 12px;
    padding: 22px;
    background: rgba(251, 246, 236, .82);
    backdrop-filter: blur(3px);
    -webkit-backdrop-filter: blur(3px);
    overflow-y: auto;
}
.overlay > * { flex-shrink: 0; }
.overlay[hidden] { display: none; }
.overlay h2, .game-screen h2 { margin: 0; font-size: 1.8rem; }
.overlay p, .game-screen p { margin: 0; color: var(--ink-soft); max-width: 34ch; }
.overlay .key-hint, .game-screen .key-hint {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-size: .9rem;
    color: var(--muted);
}
.keycap {
    display: inline-block;
    padding: 4px 12px;
    border-radius: 8px;
    background: var(--white);
    box-shadow: inset 0 -2px 0 var(--line), 0 1px 3px rgba(0,0,0,.1);
    font-weight: 700;
    font-size: .82rem;
}

/* Intro + result screens — normal flow, scroll with the window --- */
.game-screen {
    width: 100%;
    max-width: 520px;
    margin: 8px auto 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 14px;
    padding: 8px 4px 4px;
}
#ov-over { display: none; }                              /* intro shows by default */
body.is-playing #ov-intro, body.is-playing #ov-over { display: none; }
body.is-result  #ov-intro { display: none; }
body.is-result  #ov-over  { display: flex; }
.game-screen .final-score {
    font-size: 3rem;
    font-weight: 800;
    color: var(--pink-deep);
    line-height: 1;
}
.game-screen .btn-row {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    justify-content: center;
}
/* Kill the 300ms tap delay / double-tap-zoom on the result-screen buttons —
   it's a common cause of a "dead" first tap on the Redeem link. */
.game-screen .btn-row .btn { touch-action: manipulation; }

.spin {
    width: 34px; height: 34px;
    border-radius: 50%;
    border: 4px solid var(--line);
    border-top-color: var(--pink-deep);
    animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.game-tips {
    margin-top: 18px;
    font-size: .88rem;
    color: var(--muted);
    text-align: center;
    max-width: 460px;
}

.toast {
    position: fixed;
    left: 50%; bottom: 24px;
    transform: translateX(-50%) translateY(20px);
    background: var(--ink);
    color: #fff;
    padding: 12px 20px;
    border-radius: 999px;
    font-weight: 600;
    font-size: .9rem;
    opacity: 0;
    transition: opacity .2s ease, transform .2s ease;
    pointer-events: none;
    z-index: 50;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---- Arcade name entry (result screen) ----------------------- */
.hs-entry {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
}
.hs-entry[hidden] { display: none; }
.hs-entry label {
    font-size: .82rem;
    font-weight: 600;
    color: var(--ink-soft);
}
.hs-entry__row { display: flex; gap: 8px; }
#hs-name {
    width: 8ch;
    padding: 10px 14px;
    font: 700 1.4rem/1 ui-monospace, "SF Mono", Menlo, Consolas, monospace;
    letter-spacing: .2em;
    text-indent: .2em;               /* offset the trailing letter-spacing so 4 chars sit centred */
    text-transform: uppercase;
    text-align: center;
    color: var(--ink);
    background: var(--white);
    border: 2px solid var(--line);
    border-radius: 10px;
}
#hs-name:focus { outline: none; border-color: var(--pink-deep); }
.hs-entry__msg {
    min-height: 1.1em;
    font-size: .8rem;
    color: var(--muted);
}

/* ---- Global leaderboard (intro + result) -------------------- */
.leaderboard { width: 100%; max-width: 340px; }
.leaderboard__h {
    margin: 0 0 6px;
    font-size: .78rem;
    font-weight: 800;
    letter-spacing: .02em;
    text-transform: uppercase;
    color: var(--ink-soft);
    text-align: center;
}
.leaderboard__list {
    list-style: none;
    margin: 0;
    padding: 0;
    counter-reset: lb;
}
.leaderboard__list li {
    counter-increment: lb;
    display: grid;
    grid-template-columns: 1.4em 1fr auto;
    gap: 4px 8px;
    align-items: baseline;
    padding: 4px 8px;
    border-radius: 8px;
    font-size: .86rem;
    font-variant-numeric: tabular-nums;
}
.leaderboard__list li::before {
    content: counter(lb);
    font-size: .76rem;
    font-weight: 700;
    color: var(--muted);
}
.leaderboard__list li:nth-child(odd) { background: rgba(26, 26, 26, .04); }
.leaderboard__list li.is-me { background: var(--pink-deep); color: #fff; }
.leaderboard__list li.is-me::before { color: rgba(255, 255, 255, .8); }
.leaderboard__name { font-weight: 700; letter-spacing: .06em; }
.leaderboard__score { font-weight: 700; }
.leaderboard__co {
    grid-column: 2 / 4;
    font-size: .72rem;
    color: var(--muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.leaderboard__list li.is-me .leaderboard__co { color: rgba(255, 255, 255, .85); }
.leaderboard__empty {
    display: block !important;
    padding: 6px;
    font-size: .82rem;
    color: var(--muted);
}
.leaderboard__empty::before { content: none !important; }

/* ---- Game Boy control deck (jump / steer / dpad on touch) --- */
.gb-deck {
    width: min(94vw, 560px);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    padding: 16px 20px;
    border-radius: 22px;
    background: #2a2320;
    box-shadow: 0 10px 24px rgba(0,0,0,.22), inset 0 1px 0 rgba(255,255,255,.06);
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
    -webkit-tap-highlight-color: transparent;
    touch-action: none;
}
.gb-deck[hidden] { display: none; }

.gb-dpad {
    display: grid;
    grid-template-columns: repeat(3, 52px);
    grid-template-rows: repeat(3, 52px);
    gap: 6px;
    flex: none;
}
.gb-btn, .gb-a {
    border: 0;
    display: grid;
    place-items: center;
    line-height: 1;
    cursor: pointer;
    touch-action: none;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}
.gb-btn {
    width: 52px; height: 52px;
    font-size: 1.3rem;
    border-radius: 12px;
    background: #9c8b7c;             /* lighter tan — stands out on the dark deck */
    color: #fffaf2;
    text-shadow: 0 1px 1px rgba(0, 0, 0, .35);
    box-shadow: 0 3px 0 #4a3f39, inset 0 1px 0 rgba(255, 255, 255, .22);
}
.gb-btn:active { background: #b8a798; transform: translateY(2px); box-shadow: 0 1px 0 #4a3f39; }
.gb-btn--up    { grid-area: 1 / 2 / 2 / 3; }
.gb-btn--left  { grid-area: 2 / 1 / 3 / 2; }
.gb-btn--right { grid-area: 2 / 3 / 3 / 4; }
.gb-btn--down  { grid-area: 3 / 2 / 4 / 3; }

.gb-a {
    width: 84px; height: 84px;
    border-radius: 50%;
    font-weight: 800;
    font-size: 1.5rem;
    background: var(--pink-deep, #d6337e);
    color: #fff;
    box-shadow: 0 4px 0 #8f1f52;
    flex: none;
}
.gb-a:active { transform: translateY(3px); box-shadow: 0 1px 0 #8f1f52; }

/* jump games: Up doubles as jump (a lot of players reach for it), so keep it
   lit alongside A — only Left / Right / Down are the dim silhouette. */
.gb-deck[data-mode="action"] .gb-btn--left,
.gb-deck[data-mode="action"] .gb-btn--right,
.gb-deck[data-mode="action"] .gb-btn--down { opacity: .3; pointer-events: none; }
.gb-deck[data-mode="action"] { justify-content: space-around; }
/* steer / dpad games don't use A — keep the pad, dim the A silhouette */
.gb-deck[data-mode="dir"] .gb-a { opacity: .32; pointer-events: none; }

/* First-run hint: pulse the control(s) that actually do something so a new
   player knows where to press. `.is-hint` is added on the first run and
   removed on first touch (see main.js). */
@keyframes gb-hint-pulse {
    0%, 100% { transform: scale(1);    filter: brightness(1); }
    50%      { transform: scale(1.12); filter: brightness(1.4); }
}
.gb-deck.is-hint[data-scheme="jump"]  .gb-a,
.gb-deck.is-hint[data-scheme="jump"]  .gb-btn--up,
.gb-deck.is-hint[data-scheme="steer"] .gb-btn--left,
.gb-deck.is-hint[data-scheme="steer"] .gb-btn--right,
.gb-deck.is-hint[data-scheme="dpad"]  .gb-btn {
    animation: gb-hint-pulse .7s ease-in-out 3;
}
@media (prefers-reduced-motion: reduce) {
    .gb-deck.is-hint .gb-a, .gb-deck.is-hint .gb-btn { animation: none; }
}

/* Desktop: keyboard + mouse, no deck. */
@media (hover: hover) and (pointer: fine) {
    .gb-deck { display: none; }
}

/* ---- On-screen pad (only the beat lane-bar now) ------------- */
.pad {
    position: absolute;
    left: 0; right: 0; bottom: 0;
    display: flex;
    justify-content: space-between;
    padding: 14px;
    pointer-events: none;
}
.pad[hidden] { display: none; }
.pad__btn {
    pointer-events: auto;
    width: 76px; height: 76px;
    border: 0;
    border-radius: 50%;
    background: rgba(26, 26, 26, .16);
    color: #fff;
    font-size: 1.6rem;
    line-height: 1;
    display: grid;
    place-items: center;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    touch-action: none;
}
.pad__btn:active { background: rgba(26, 26, 26, .34); }
@media (hover: hover) and (pointer: fine) {
    .pad { display: none; }
}

/* ---- Lane bar (beat): four wide zones along the bottom edge -- */
.pad--lanes { padding: 0; gap: 3px; }
.pad--lanes .pad__btn {
    flex: 1 1 25%;
    width: auto; height: 78px;
    border-radius: 16px 16px 0 0;
    background: rgba(26, 26, 26, .18);
    font-size: 1.1rem; font-weight: 700;
}

/* ---- Aim / slice: crosshair over the board ------------------ */
.stage[data-controls="aim"],
.stage[data-controls="slice"] { cursor: crosshair; }
.stage[data-controls="aim"] .overlay,
.stage[data-controls="slice"] .overlay { cursor: default; }

/* =========================================================================
   Touch layout: lock the play screen to the viewport (no scroll / shake
   during play), fit stage + deck on one screen. The result screen releases
   the lock so it scrolls normally.
   ========================================================================= */
@media (hover: none), (pointer: coarse) {
    .lbl-full { display: none; }
    .lbl-short { display: inline; }

    /* Viewport is locked only during actual play. The intro and result
       screens scroll with the window. */
    body.is-game { overscroll-behavior: none; }
    body.is-game.is-playing { overflow: hidden; }
    body.is-game.is-playing .game-page {
        height: 100dvh;
        overflow: hidden;
        padding: 8px 8px 12px;
    }
    body.is-game.is-playing .game-top { margin-bottom: 6px; }
    body.is-game.is-playing .game-shell { flex: 1; justify-content: center; gap: 10px; }
    body.is-game.is-playing .stage { width: min(94vw, 54vh, 460px); }
    body.is-game.is-playing .game-tips { display: none; }

    .gb-dpad { grid-template-columns: repeat(3, 15vw); grid-template-rows: repeat(3, 15vw); }
    .gb-btn { width: 15vw; height: 15vw; max-width: 60px; max-height: 60px; }
    .gb-a { width: 22vw; height: 22vw; max-width: 92px; max-height: 92px; }
}

/* =========================================================================
   Landscape on a handheld: lay it out like a real console — dpad column,
   screen in the middle, action button column. (`.gb-deck` is display:contents
   so its dpad + A become direct flex items of the shell and can be reordered
   around the stage.)
   ========================================================================= */
@media (orientation: landscape) and (hover: none),
       (orientation: landscape) and (pointer: coarse) {
    body.is-game.is-playing .game-top { display: none; }
    body.is-game.is-playing .game-page { padding: 6px 10px; }

    body.is-game.is-playing .game-shell {
        flex-direction: row;
        flex-wrap: nowrap;
        align-items: center;
        justify-content: center;
        gap: min(4vw, 40px);
    }
    body.is-game.is-playing .gb-deck { display: contents; }
    body.is-game.is-playing .gb-dpad { order: -1; flex: none; }
    body.is-game.is-playing .stage   { order: 0;  width: min(86vh, 58vw); }
    body.is-game.is-playing .gb-a    { order: 1;  flex: none; }

    /* size the controls off the short (vertical) axis */
    .gb-dpad { grid-template-columns: repeat(3, 14vh); grid-template-rows: repeat(3, 14vh); gap: 5px; }
    .gb-btn  { width: 14vh; height: 14vh; max-width: 62px; max-height: 62px; font-size: 1.2rem; }
    .gb-a    { width: 22vh; height: 22vh; max-width: 100px; max-height: 100px; }

    /* Combo toast: park it in the top-right corner, clear of the centred
       stage, instead of dead-centre where it covers the play area. */
    .toast {
        top: 12px;
        bottom: auto;
        left: auto;
        right: 12px;
        transform: translateX(0) translateY(-20px);
        max-width: 44vw;
        text-align: center;
    }
    .toast.show { transform: translateX(0) translateY(0); }
}
