/* Fullscreen portrait canvas; no scrolling, no tap highlights, no text select.
   The canvas is sized in JS (DPR-aware). Layers above it:
     #touch - in-game controls (visible only while body.playing)
     #hud   - pause button
     #menu  - start/pause/game-over overlay
   body.playing and body.scheme-follow drive what's interactive. */
html,
body {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    background: #222222;
    font-family: Arial, sans-serif;
    touch-action: none;
    -webkit-user-select: none;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

#game {
    display: block;
    position: fixed;
    inset: 0;
    cursor: default;
}
body.cursor-idle, body.cursor-idle * { cursor: none !important; }

/* ---- Touch layer ---- */
#touch {
    position: fixed;
    inset: 0;
    pointer-events: none;
    display: none;
}
body.playing #touch {
    display: block;
}
/* No touchscreen anywhere = keyboard play; the touch layer (slider/buttons)
   and the Controls scheme row are meaningless there. Touchscreen laptops
   match (any-pointer: coarse), so they keep both. */
@media not all and (any-pointer: coarse) {
    #touch,
    #label-scheme,
    #row-scheme {
        display: none !important;
    }
}
.touch-btn {
    position: fixed;
    bottom: 2.5vh;
    width: 17vh;
    height: 17vh;
    max-width: 130px;
    max-height: 130px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.16);
    border: 2px solid rgba(255, 255, 255, 0.35);
    color: rgba(255, 255, 255, 0.85);
    font-size: 5vh;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: auto;
    touch-action: none;
}
.touch-btn:active {
    background: rgba(255, 255, 255, 0.32);
}
#btn-left {
    left: 3vw;
}
#btn-right {
    left: calc(3vw + 18vh);
}
#btn-jump {
    right: 3vw;
}
#follow-zone {
    position: fixed;
    inset: 0;
    pointer-events: none;
    touch-action: none;
}
/* Slider scheme: a short track in each bottom corner, one per thumb. A
   track's full length = one slime's wall-to-net range, so strokes stay
   short. The knob mirrors the finger (or the slime when idle); dragging up
   past the lift threshold holds jump. Raised off the bottom edge on purpose -
   touches that start at the very bottom get eaten by the OS home gesture,
   which no Mini App API can block. */
.slider-track {
    position: fixed;
    bottom: 9vh;
    width: 42vw;
    height: 64px; /* full-size invisible hit zone; the drawn pill is slimmer */
    pointer-events: none;
    touch-action: none;
    display: none;
}
#slider-left {
    left: 4vw;
}
#slider-right {
    right: 4vw;
}
.slider-track::before {
    content: "";
    position: absolute;
    left: 0;
    right: 0;
    top: 50%;
    transform: translateY(-50%);
    height: 36px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.12);
    border: 2px solid rgba(255, 255, 255, 0.3);
}
body.scheme-slider .slider-track {
    display: block;
    pointer-events: auto;
}
body.scheme-slider #btn-left,
body.scheme-slider #btn-right,
body.scheme-slider #btn-jump {
    display: none;
}
.slider-knob {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.28);
    border: 2px solid rgba(255, 255, 255, 0.5);
    color: rgba(255, 255, 255, 0.85);
    font-size: 22px;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none; /* the track owns the pointer; the knob is visual */
}
.slider-knob.lifted {
    background: rgba(255, 255, 255, 0.5);
    transform: translate(-50%, -80%);
}
/* Short viewports (landscape phones, chat-overlay iframes): shrink the bars
   so they sit in the sand below the floor instead of on the slimes. */
@media (max-height: 520px) {
    .slider-track {
        bottom: 3vh;
        height: 48px;
    }
    .slider-track::before {
        height: 26px;
    }
    .slider-knob {
        width: 44px;
        height: 44px;
        font-size: 16px;
    }
}
/* Follow scheme: the whole screen tracks the finger; ◀ ▶ hide, JUMP stays. */
body.scheme-follow #follow-zone {
    pointer-events: auto;
}
body.scheme-follow #btn-left,
body.scheme-follow #btn-right {
    display: none;
}
/* JUMP must float above the follow zone to stay pressable. */
#btn-jump {
    z-index: 2;
}

/* ---- HUD ---- */
#hud {
    position: fixed;
    inset: 0;
    pointer-events: none;
}
/* ---- Menu ---- */
#menu {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(12, 22, 34, 0.88);
    z-index: 10;
}
body.playing #menu {
    display: none;
}
#menu-card {
    width: min(92vw, 420px);
    max-height: 94vh;
    overflow-y: auto;
    text-align: center;
    color: #eaf2f8;
    padding: 12px 8px;
}
#menu-card h1 {
    margin: 4px 0 10px;
    font-size: 30px;
}
#menu-result {
    margin: 0 0 10px;
    font-size: 19px;
    font-weight: bold;
    color: #ffd166;
}
/* ---- Challenge (async PvP) box ---- */
#challenge-box {
    margin: 4px 0 6px;
    padding: 10px 12px;
    border: 2px solid #ffd166;
    border-radius: 14px;
    background: rgba(255, 209, 102, 0.08);
}
#challenge-info {
    margin: 0 0 10px;
    font-size: 14px;
    color: #ffd166;
}
#btn-challenge {
    padding: 12px 30px;
    border-radius: 999px;
    border: none;
    background: #e8590c;
    color: #ffffff;
    font-size: 17px;
    font-weight: bold;
}

.menu-label {
    margin: 12px 0 6px;
    font-size: 12px;
    letter-spacing: 2px;
    text-transform: uppercase;
    color: #9fb3c8;
}
.menu-row {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
}
.menu-row button {
    padding: 9px 16px;
    border-radius: 999px;
    border: 2px solid #3c5a75;
    background: #16283a;
    color: #eaf2f8;
    font-size: 15px;
}
.menu-row button.selected {
    border-color: #63b3ed;
    background: #234a68;
}
#row-skins button {
    padding: 6px;
    line-height: 0;
    border-radius: 14px;
}
#row-skins canvas {
    width: 40px;
    height: 40px;
}
.menu-actions {
    margin-top: 18px;
    display: flex;
    gap: 10px;
    justify-content: center;
}
.menu-actions button {
    padding: 12px 34px;
    border-radius: 999px;
    border: none;
    background: #2f9e44;
    color: #ffffff;
    font-size: 18px;
    font-weight: bold;
}
#btn-resume {
    background: #3c5a75;
}
.menu-hint {
    margin-top: 16px;
    font-size: 12px;
    color: #7d93a8;
}
@media (max-height: 720px) {
    #menu-card { padding: 6px 8px; }
    #menu-card h1 { margin: 0 0 5px; font-size: 26px; }
    .menu-label { margin: 7px 0 4px; }
    .menu-row { gap: 6px; }
    .menu-row button { padding: 7px 13px; font-size: 13px; }
    #row-skins button { padding: 4px; border-radius: 11px; }
    #row-skins canvas { width: 34px; height: 34px; }
    .keys-row { margin-bottom: 4px; }
    .key-btn { padding: 5px 8px; }
    .menu-actions { margin-top: 10px; }
    .menu-actions button { padding: 9px 28px; font-size: 16px; }
    .menu-hint { margin: 7px 0 0; font-size: 11px; line-height: 1.25; }
}
/* ---- Keyboard remap (desktop rows) ---- */
.keys-row {
    display: flex;
    gap: 8px;
    justify-content: center;
    align-items: center;
    margin-bottom: 8px;
}
.keys-who {
    width: 28px;
    font-size: 13px;
    color: #9fb3c8;
    text-align: right;
}
.key-btn {
    min-width: 64px;
    padding: 7px 10px;
    border-radius: 10px;
    border: 2px solid #3c5a75;
    background: #16283a;
    color: #eaf2f8;
    font-size: 13px;
}
.key-btn.capturing {
    border-color: #ffd166;
    color: #ffd166;
}
#btn-keys-reset {
    margin-top: 2px;
    padding: 6px 14px;
    border-radius: 999px;
    border: none;
    background: #3c5a75;
    color: #eaf2f8;
    font-size: 12px;
}

.hidden {
    display: none !important;
}

/* ---- Live PvP overlays ---- */
/* Matchmaking card: sits over the idle court while you wait for an opponent
   (body.playing is on, so the menu is hidden; this floats above the touch
   layer but below nothing else that matters). */
#live-overlay {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(12, 22, 34, 0.72);
    z-index: 12;
}
#live-card {
    text-align: center;
    color: #eaf2f8;
    padding: 18px 26px;
    border: 2px solid #63b3ed;
    border-radius: 16px;
    background: rgba(22, 40, 58, 0.96);
    max-width: 86vw;
}
#live-status {
    margin: 0 0 14px;
    font-size: 17px;
    font-weight: bold;
}
#btn-live-cancel {
    padding: 10px 30px;
    border-radius: 999px;
    border: 2px solid #3c5a75;
    background: #16283a;
    color: #eaf2f8;
    font-size: 15px;
}

/* One-time 3-2-1 (and GO): a big pulse in the middle of the court. */
#countdown {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
    z-index: 12;
    font-size: min(34vw, 190px);
    font-weight: bold;
    color: #ffd166;
    text-shadow: 0 4px 24px rgba(0, 0, 0, 0.55);
}
#countdown.tick {
    animation: countdown-pulse 0.9s ease-out;
}
@keyframes countdown-pulse {
    0% {
        transform: scale(1.35);
        opacity: 0;
    }
    18% {
        opacity: 1;
    }
    100% {
        transform: scale(0.92);
        opacity: 0.85;
    }
}

#live-overlay.hidden,
#countdown.hidden {
    display: none;
}

/* ---- Live PvP rematch box (menu) + name labels (in game) ---- */
#rematch-box {
    margin: 4px 0 6px;
    padding: 10px 12px;
    border: 2px solid #63b3ed;
    border-radius: 14px;
    background: rgba(99, 179, 237, 0.08);
}
#rematch-info {
    margin: 0 0 10px;
    font-size: 14px;
    color: #63b3ed;
}
#btn-rematch {
    padding: 12px 30px;
    border-radius: 999px;
    border: none;
    background: #2b6cb0;
    color: #ffffff;
    font-size: 17px;
    font-weight: bold;
}
#btn-rematch:disabled {
    opacity: 0.5;
}

#live-labels {
    position: fixed;
    top: calc(var(--game-top-inset, 0px) + 8px);
    left: 0;
    right: 0;
    display: flex;
    justify-content: space-between;
    padding: 0 14px;
    pointer-events: none;
    z-index: 6;
    font-size: 13px;
    font-weight: bold;
    color: #eaf2f8;
    text-shadow: 0 1px 4px rgba(0, 0, 0, 0.7);
}
#live-labels .me {
    color: #ffd166;
}
#live-labels.hidden {
    display: none;
}

/* ---- ?dev=1 connection overlay ---- */
#dev-hud {
    position: fixed;
    top: calc(var(--game-top-inset, 0px) + 34px);
    left: 8px;
    padding: 5px 8px;
    border-radius: 8px;
    background: rgba(0, 0, 0, 0.55);
    color: #9fd0a4;
    font-family: monospace;
    font-size: 11px;
    line-height: 1.5;
    white-space: pre;
    pointer-events: none;
    z-index: 15;
}
#dev-hud.hidden {
    display: none;
}

/* ---- Playgram match scoring (solo build additions) ---- */
#scorebar {
    position: fixed;
    top: calc(8px + var(--game-top-inset, 0px));
    left: 50%;
    transform: translateX(-50%);
    z-index: 5;
    display: flex;
    gap: 12px;
    padding: 5px 14px;
    border-radius: 999px;
    background: rgba(10, 16, 26, 0.72);
    border: 1px solid rgba(255, 255, 255, 0.18);
    color: #fff;
    font-weight: 800;
    font-size: 14px;
    font-variant-numeric: tabular-nums;
    pointer-events: none;
}
#scorebar.hidden { display: none; }
#sb-score { color: #ffd24a; }
#score-toast {
    position: fixed;
    top: 22%;
    left: 50%;
    transform: translateX(-50%);
    z-index: 6;
    color: #ffd24a;
    font-weight: 900;
    font-size: 30px;
    text-shadow: 0 2px 8px rgba(0, 0, 0, 0.7);
    pointer-events: none;
}
#score-toast.hidden { display: none; }
#score-toast.pop { animation: score-pop 1.1s ease-out; }
@keyframes score-pop {
    0% { opacity: 0; transform: translateX(-50%) translateY(12px) scale(0.8); }
    18% { opacity: 1; transform: translateX(-50%) translateY(0) scale(1.06); }
    75% { opacity: 1; }
    100% { opacity: 0; transform: translateX(-50%) translateY(-14px) scale(1); }
}

/* ---- Landscape gate ---- */
#rotate {
    position: fixed;
    inset: 0;
    z-index: 99;
    display: grid;
    place-items: center;
    padding: 20px;
    text-align: center;
    background: #0a1018;
    color: #fff;
}
#rotate.hidden { display: none; }
#rotate .rotate-phone {
    width: 34px;
    height: 58px;
    margin: 0 auto 18px;
    border: 3px solid #ffd24a;
    border-radius: 8px;
    box-shadow: 0 0 24px rgba(255, 210, 74, 0.25);
    animation: rotate-tilt 1.7s ease-in-out infinite;
}
#rotate h3 { margin: 0 0 6px; font-size: 19px; letter-spacing: 0.08em; }
#rotate p { margin: 0; opacity: 0.7; font-size: 13px; }
@keyframes rotate-tilt {
    0%, 20% { transform: rotate(0); }
    55%, 100% { transform: rotate(-90deg); }
}

/* ---- Top score bar ---- */
#topbar {
    position: fixed;
    top: calc(1.5vh + var(--game-top-inset, 0px));
    left: 50%;
    transform: translateX(-50%);
    z-index: 5;
    display: flex;
    align-items: stretch;
    gap: 8px;
    pointer-events: none;
}
#scorebar {
    position: static;
    top: auto;
    left: auto;
    transform: none;
}
