:root {
    color-scheme: dark;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    background: #111827;
    color: #f8fafc;
}

* {
    box-sizing: border-box;
}

html,
body {
    width: 100%;
    height: 100%;
    margin: 0;
    overflow: hidden;
    overscroll-behavior: none;
}

body {
    display: grid;
    place-items: center;
    min-height: 100dvh;
    padding:
        env(safe-area-inset-top)
        env(safe-area-inset-right)
        env(safe-area-inset-bottom)
        env(safe-area-inset-left);
    background:
        radial-gradient(circle at 50% 35%, rgba(37, 99, 235, 0.16), transparent 45%),
        #111827;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
}

button {
    font: inherit;
}

#game-shell {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    width: min(
        800px,
        100%,
        calc(
            (100dvh - 58px - env(safe-area-inset-top) - env(safe-area-inset-bottom)) * 4 / 3
        )
    );
    padding: 4px;
}

#game-stage {
    position: relative;
    width: 100%;
    aspect-ratio: 4 / 3;
}

canvas {
    display: block;
    width: 100%;
    height: 100%;
    background: #0f172a;
    border: 1px solid rgba(148, 163, 184, 0.18);
    border-radius: 10px;
    box-shadow:
        0 0 20px rgba(0, 0, 0, 0.55),
        0 0 45px rgba(59, 130, 246, 0.18);
    touch-action: none;
    -webkit-touch-callout: none;
}

#ui-layer {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 28px;
    text-align: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 140ms ease;
}

#ui-layer.visible {
    opacity: 1;
}

#ui-layer.interactive {
    pointer-events: auto;
    cursor: pointer;
}

.overlay-panel {
    width: min(520px, 94%);
    padding: 28px 30px;
    border: 1px solid rgba(148, 163, 184, 0.25);
    border-radius: 16px;
    background: rgba(15, 23, 42, 0.88);
    box-shadow: 0 20px 70px rgba(0, 0, 0, 0.45);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}

#main-title {
    margin: 0 0 12px;
    font-size: clamp(2.3rem, 7vw, 4rem);
    font-weight: 900;
    line-height: 1;
    letter-spacing: 0.04em;
    color: #67e8f9;
    text-shadow: 0 0 25px rgba(34, 211, 238, 0.34);
}

#sub-text {
    margin: 0;
    color: #e2e8f0;
    font-size: clamp(1rem, 2.8vw, 1.25rem);
    font-weight: 700;
    white-space: pre-line;
}

#detail-text {
    margin: 14px 0 0;
    color: #94a3b8;
    font-size: clamp(0.8rem, 2.2vw, 0.95rem);
    line-height: 1.55;
    white-space: pre-line;
}

#ui-action {
    min-width: 150px;
    margin-top: 20px;
    padding: 11px 18px;
    border: 1px solid rgba(103, 232, 249, 0.6);
    border-radius: 999px;
    color: #ecfeff;
    background: rgba(8, 145, 178, 0.32);
    font-weight: 800;
    cursor: pointer;
}

#ui-action:hover,
#ui-action:focus-visible {
    background: rgba(8, 145, 178, 0.55);
    outline: 2px solid #67e8f9;
    outline-offset: 2px;
}

#ui-action[hidden] {
    display: none;
}

#control-bar {
    display: flex;
    justify-content: center;
    gap: 7px;
    width: 100%;
    min-height: 42px;
}

.control-button {
    min-width: 86px;
    padding: 8px 12px;
    border: 1px solid rgba(148, 163, 184, 0.28);
    border-radius: 8px;
    color: #cbd5e1;
    background: rgba(30, 41, 59, 0.9);
    font-size: 0.86rem;
    font-weight: 750;
    cursor: pointer;
}

.control-button:hover,
.control-button:focus-visible {
    color: #ffffff;
    border-color: rgba(103, 232, 249, 0.7);
    background: #334155;
    outline: none;
}

#game-shell:fullscreen {
    width: 100vw;
    height: 100dvh;
    padding:
        max(8px, env(safe-area-inset-top))
        max(8px, env(safe-area-inset-right))
        max(8px, env(safe-area-inset-bottom))
        max(8px, env(safe-area-inset-left));
    justify-content: center;
    background: #111827;
}

#game-shell:fullscreen #game-stage {
    width: min(100%, calc((100dvh - 62px) * 4 / 3));
}

@media (pointer: coarse) {
    .control-button {
        min-height: 44px;
    }
}

@media (max-width: 520px) {
    #game-shell {
        gap: 6px;
        padding: 2px;
    }

    #ui-layer {
        padding: 14px;
    }

    #control-bar {
        gap: 4px;
    }

    .control-button {
        min-width: 0;
        flex: 1 1 0;
        padding-inline: 6px;
        font-size: 0.78rem;
    }

    .overlay-panel {
        padding: 22px 18px;
    }
}

@media (prefers-reduced-motion: reduce) {
    #ui-layer {
        transition: none;
    }
}