html, body {
    margin: 0;
    min-height: 100%;
    background: #101826;
    color: #d8e3f5;
    font-family: "Courier New", monospace;
    overscroll-behavior: none;
}

body {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 18px;
    box-sizing: border-box;
}

.frame {
    position: relative;
    width: min(100%, 1024px);
    aspect-ratio: 16 / 10;
    background: #05070c;
    border: 4px solid #2f4772;
    box-shadow: 0 16px 40px rgba(0, 0, 0, 0.38);
}

canvas {
    display: block;
    width: 100%;
    height: 100%;
    image-rendering: pixelated;
    background: #7ec7f0;
    touch-action: none;
    -webkit-user-select: none;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

.fs-btn {
    position: absolute;
    top: 6.8%;
    right: 6px;
    width: 34px;
    height: 34px;
    padding: 0;
    border: 2px solid rgba(255, 255, 255, 0.55);
    background: rgba(8, 12, 22, 0.55);
    color: #d8e3f5;
    font-size: 18px;
    line-height: 1;
    cursor: pointer;
    opacity: 0.7;
    z-index: 5;
}

.fs-btn:hover { opacity: 1; }

.rotate-hint {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 40;
    align-items: center;
    justify-content: center;
    background: rgba(5, 7, 12, 0.92);
    color: #ffd23f;
    font: bold 26px "Courier New", monospace;
    text-align: center;
    pointer-events: none;
}

@media (pointer: coarse) and (orientation: portrait) {
    .rotate-hint { display: flex; }
}

/* phones in landscape: fit the whole canvas in the viewport, hide chrome */
@media (pointer: coarse) and (orientation: landscape) and (max-height: 520px) {
    body { padding: 5px; gap: 5px; justify-content: flex-start; }
    .under { display: none; }
    .frame {
        border-width: 2px;
        width: min(100%, calc((100vh - 14px) * 1.6));
    }
}

/* fullscreen: letterbox the 16:10 canvas instead of stretching */
.frame:fullscreen {
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: #000;
}

.frame:fullscreen canvas {
    width: min(100vw, 160vh);
    height: auto;
    aspect-ratio: 1024 / 640;
}

/* 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 {
    padding: 0;
    min-height: 0;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
}

body.theater .frame {
    position: fixed;
    inset: 0;
    width: auto;
    height: 100vh;   /* fallback; game.js pins this to visualViewport.height */
    height: 100dvh;
    aspect-ratio: auto;
    border: none;
    background: #000;
    box-shadow: none;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 30;
    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 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(16, 24, 38, 0.94);
    border: 2px solid #2f4772;
    border-radius: 8px;
    color: #d8e3f5;
    font: 12px/1.4 "Courier New", monospace;
}

.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: #d8e3f5;
    font-size: 16px;
    line-height: 1;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

body.theater .fs-btn,
.frame:fullscreen .fs-btn {
    top: max(6.8%, env(safe-area-inset-top));
    right: max(6px, env(safe-area-inset-right));
}

.under {
    width: min(100%, 1024px);
    display: flex;
    justify-content: space-between;
    gap: 18px;
    font-size: 13px;
    line-height: 1.4;
    color: #9fb0c8;
}

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

.under a:hover {
    color: #ffffff;
}

@media (max-width: 720px) {
    body { padding: 10px; justify-content: flex-start; }
    .under { flex-direction: column; gap: 4px; }
}
