* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background: #101418;
    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;
}

canvas {
    width: 100%;
    height: auto;
    aspect-ratio: 1024 / 640;
    image-rendering: pixelated;
    outline: none;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
}

/* --- fullscreen ⛶ (touch devices only; desktop stays exactly as it was) */
.fs-btn {
    display: none;
    position: absolute;
    left: 8px;
    bottom: 8px;
    z-index: 10;
    width: 44px;
    height: 44px;
    align-items: center;
    justify-content: center;
    padding: 0;
    font: 20px/1 Verdana, Geneva, Tahoma, sans-serif;
    color: #e8e2d2;
    background: rgba(16, 20, 24, 0.55);
    border: 1px solid rgba(232, 226, 210, 0.35);
    border-radius: 6px;
    cursor: pointer;
    -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
}

@media (pointer: coarse) {
    .fs-btn { display: flex; }
}

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

.frame:fullscreen canvas {
    width: min(100vw, 160vh);   /* 160vh = 100vh × 1024/640 — contain, no letterbox mapping tricks */
    height: auto;
    max-width: 100%;
}

/* theater mode: automatic on touch devices (shell.js adds the class on load
   and also uses it as the no-fullscreen-API fallback). The frame is pinned
   to the VISIBLE viewport — shell.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;
    z-index: 50;
    max-width: none;
    height: 100vh;   /* fallback; shell.js pins this to visualViewport.height */
    height: 100dvh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #000;
    padding: env(safe-area-inset-top) env(safe-area-inset-right)
             env(safe-area-inset-bottom) env(safe-area-inset-left);
}

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 shell.js) */
.a2hs-hint {
    pointer-events: none;
    position: fixed;
    left: 50%;
    transform: translateX(-50%);
    bottom: calc(env(safe-area-inset-bottom, 0px) + 10px);
    z-index: 60;
    display: flex;
    align-items: center;
    gap: 2px;
    max-width: calc(100vw - 16px);
    padding: 2px 2px 2px 14px;
    background: rgba(16, 20, 24, 0.94);
    border: 1px solid rgba(232, 226, 210, 0.35);
    border-radius: 8px;
    color: #e8e2d2;
    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: #e8e2d2;
    font-size: 16px;
    line-height: 1;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

/* --- "rotate your phone" hint: coarse pointer + portrait only */
.rotate-hint {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 90;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    text-align: center;
    background: rgba(16, 20, 24, 0.97);
    color: #f4f2ec;
}

.rotate-hint b {
    font: bold 24px Georgia, serif;
    letter-spacing: 1px;
}

.rotate-hint span {
    font-size: 11px;
    color: #8fa2b5;
}

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

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

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

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