*, *::before, *::after {
    box-sizing: border-box;
}

body {
    margin: 0;
    background: #1d1e20;
    color: #dadadb;
    font-family: system-ui, -apple-system, sans-serif;
    font-size: 18px;
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
}

#wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
    padding: 24px;
}

header {
    text-align: center;
}

h1 {
    margin: 0 0 4px;
    font-size: 1.25rem;
    font-weight: 700;
    color: #dadadb;
    letter-spacing: -0.01em;
}

header p {
    margin: 0;
    font-size: 0.875rem;
    color: #9b9c9d;
}

#game-container {
    position: relative;
}

#canv {
    display: block;
    border-radius: 8px;
    border: 1px solid #333333;
    background: #1d1e20;
    touch-action: none;
    max-width: 100%; /* prevents mobile browser auto-zoom on load */
}

#fps-counter {
    position: absolute;
    bottom: 10px;
    right: 14px;
    font-size: 0.68rem;
    font-family: monospace;
    color: #414244;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    pointer-events: none;
    user-select: none;
}

#fps {
    color: #9b9c9d;
}

#controls {
    display: flex;
    align-items: center;
    gap: 24px;
    font-size: 0.8125rem;
    color: #9b9c9d;
}

.player-controls {
    display: flex;
    align-items: center;
    gap: 6px;
}

.player-label {
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    margin-right: 6px;
}

.player-controls[data-player="1"] .player-label { color: #FF6B2B; }
.player-controls[data-player="2"] .player-label { color: #2979ff; }

kbd {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: #2e2e33;
    border: 1px solid #333333;
    border-radius: 4px;
    padding: 2px 7px;
    font-size: 0.75rem;
    font-family: system-ui, sans-serif;
    color: #c4c4c5;
    min-width: 26px;
    line-height: 1.4;
}

.controls-divider {
    width: 1px;
    height: 20px;
    background: #333333;
}

/* ── Touch control zones (hidden on desktop) ─────────────────── */

.touch-zone {
    display: none;
}

.touch-btn {
    background: #1d1e20;
    border: none;
    border-radius: 8px;
    color: #dadadb;
    font-size: 1.8rem;
    font-family: inherit;
    width: 30%;
    height: 75px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.touch-btn:active {
    background: #2e2e33;
}

/* Centre button doubles as player label */
#touch-p1 .touch-jump { color: #FF6B2B; font-size: 1.1rem; font-weight: 700; letter-spacing: 0.04em; }
#touch-p2 .touch-jump { color: #2979ff; font-size: 1.1rem; font-weight: 700; letter-spacing: 0.04em; }

/* ── Mobile layout (touch devices) ──────────────────────────── */

@media (pointer: coarse) {
    html {
        height: 100dvh;
    }

    body {
        overflow: hidden;
        height: 100dvh;
        min-height: 100dvh;
        align-items: stretch;
        justify-content: stretch;
    }

    #wrapper {
        width: 100%;
        height: 100%;
        gap: 0;
        padding: 0;
        justify-content: space-between;
        align-items: stretch;
        user-select: none;
        -webkit-user-select: none;
    }

    header {
        padding: 8px 0 4px;
        flex-shrink: 0;
    }

    header h1 {
        font-size: 1.4rem;
        margin-bottom: 2px;
    }

    header p {
        display: block;
        font-size: 0.85rem;
    }

    #controls {
        display: none;
    }

    .touch-zone {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 10px 12px;
        background: #1d1e20;
        flex-shrink: 0;
    }

    #touch-p2 {
        transform: rotate(180deg);
        border-bottom: 1px solid #333333;
    }

    #touch-p1 {
        border-top: 1px solid #333333;
    }

    #game-container {
        flex: 1;
        display: flex;
        align-items: center;
        justify-content: center;
        min-height: 0;
        padding: 8px;
    }

    #canv {
        /* Two touch zones at 75px + 20px padding each = 190px.
           Header ~32px. Container padding 16px. Total ~238px. */
        --canvas-size: min(calc(100vw - 16px), calc(100dvh - 254px));
        width: var(--canvas-size);
        height: var(--canvas-size);
        border-radius: 4px;
    }

    #fps-counter {
        display: none;
    }
}

@media (max-width: 680px) and (pointer: fine) {
    #canv {
        width: 100%;
        height: auto;
    }

    #controls {
        flex-direction: column;
        gap: 12px;
    }

    .controls-divider {
        width: 32px;
        height: 1px;
    }
}
