* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background: #000;
    min-height: 100vh;
    overscroll-behavior: none;
}

body {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 12px;
    font-family: Verdana, Geneva, Tahoma, sans-serif;
}

.frame {
    position: relative;
    width: 100%;
    max-width: 1024px;
    line-height: 0;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
}

canvas {
    width: 100%;
    height: auto;
    image-rendering: pixelated;
    touch-action: none;
    /* the cursor is hidden by script during play only */
    outline: none;
}

/* In portrait, this fills the space below the game and accepts the same
   hold/drag/two-finger controls without a hand covering the playfield. */
#portrait-controls {
    display: none;
    width: 100%;
    flex: 1 1 auto;
    min-height: 0;
    touch-action: none;
    background: #000;
    -webkit-tap-highlight-color: transparent;
}

/* fullscreen / theater toggle (game.js hides it during live play) */
#fs-btn {
    position: absolute;
    top: 8px;
    right: 8px;
    z-index: 20;
    width: 40px;
    height: 40px;
    padding: 0;
    background: rgba(11, 18, 32, 0.65);
    color: #7ce0ff;
    border: 1px solid #2d5bff;
    border-radius: 6px;
    font-size: 20px;
    line-height: 1;
    cursor: pointer;
    transition: opacity 0.25s;
}

#fs-btn.hidden {
    opacity: 0;
    pointer-events: none;
}

/* real element fullscreen (Android, desktop): letterbox the canvas */
.frame:fullscreen {
    display: flex;
    align-items: center;
    justify-content: center;
    background: #000;
    max-width: none;
}

.frame:fullscreen canvas {
    width: min(100vw, 160vh);
    height: min(100vh, 62.5vw);
}

/* theater mode: automatic on touch devices (game.js adds the class on load
   and also uses it as the no-fullscreen-API fallback). The frame is pinned
   to the VISIBLE viewport — game.js tracks visualViewport.height against
   Safari's collapsing chrome — and the canvas letterboxes inside it. */
html:has(> body.theater) {
    height: 100%;
    min-height: 0;
    overflow: hidden;
}

body.theater {
    min-height: 0;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
}

body.theater .frame {
    position: fixed;
    inset: 0;
    z-index: 30;
    max-width: none;
    height: 100vh;   /* fallback; game.js pins this to visualViewport.height */
    height: 100dvh;
    background: #000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: env(safe-area-inset-top, 0px) env(safe-area-inset-right, 0px)
             env(safe-area-inset-bottom, 0px) env(safe-area-inset-left, 0px);
}

body.theater .frame canvas {
    width: auto;
    height: 100%;
    aspect-ratio: 1024 / 640;
    max-width: 100%;
    max-height: 100%;
}

body.theater .under { display: none; }

/* one-time iOS "Add to Home Screen" strip (injected by game.js) */
.a2hs-hint {
    pointer-events: none;
    position: fixed;
    left: 50%;
    transform: translateX(-50%);
    bottom: calc(env(safe-area-inset-bottom, 0px) + 10px);
    z-index: 35;
    display: flex;
    align-items: center;
    gap: 2px;
    max-width: calc(100vw - 16px);
    padding: 2px 2px 2px 14px;
    background: rgba(11, 18, 32, 0.92);
    border: 1px solid #2d5bff;
    border-radius: 8px;
    color: #7ce0ff;
    font: 12px/1.4 Verdana, Geneva, Tahoma, sans-serif;
}

.a2hs-hint .a2hs-close {
    pointer-events: auto;
    flex: none;
    width: 44px;
    height: 44px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    color: #7ce0ff;
    font-size: 16px;
    line-height: 1;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

@media (pointer: coarse) and (orientation: portrait) {
    body.theater .frame {
        flex-direction: column;
        align-items: center;
        justify-content: flex-start;
    }

    body.theater .frame canvas {
        flex: 0 0 auto;
    }

    #portrait-controls { display: block; }
}

.under {
    width: 100%;
    max-width: 1024px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    flex-wrap: wrap;
    font-size: 10px;
    color: #666;
    line-height: 1.6;
}

.under a {
    color: #4899ea;
    text-decoration: none;
    white-space: nowrap;
}

.under a:hover { text-decoration: underline; }
