:root {
    color-scheme: dark;
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-right: env(safe-area-inset-right, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --safe-left: env(safe-area-inset-left, 0px);
}

* { box-sizing: border-box; }

html, body {
    width: 100%;
    height: 100%;
    margin: 0;
    overflow: hidden;
    overscroll-behavior: none;
    background: #03050a;
    font-family: "Courier New", monospace;
    touch-action: none;
}

body {
    display: grid;
    place-items: center;
}

#game-container {
    position: relative;
    width: min(100vw, calc(100dvh * 16 / 9));
    height: min(100dvh, calc(100vw * 9 / 16));
    max-width: 100vw;
    max-height: 100dvh;
    overflow: hidden;
    background: #05070d;
    box-shadow: 0 0 40px rgba(0, 220, 255, .18);
}

canvas {
    display: block;
    width: 100%;
    height: 100%;
    background: #05070d;
    image-rendering: pixelated;
}

#mobile-controls {
    display: none;
    position: absolute;
    inset: 0;
    pointer-events: none;
    padding: calc(10px + var(--safe-top)) calc(12px + var(--safe-right)) calc(10px + var(--safe-bottom)) calc(12px + var(--safe-left));
    align-items: flex-end;
    justify-content: space-between;
}

.control-cluster {
    display: flex;
    align-items: flex-end;
    gap: clamp(7px, 1.5vw, 14px);
    pointer-events: auto;
}

.control-btn {
    width: clamp(48px, 9.2vw, 72px);
    height: clamp(48px, 9.2vw, 72px);
    border: 2px solid rgba(61, 235, 255, .85);
    border-radius: 50%;
    color: #eaffff;
    background: radial-gradient(circle at 35% 30%, rgba(40, 200, 225, .38), rgba(4, 22, 31, .62));
    box-shadow: inset 0 0 14px rgba(0, 225, 255, .18), 0 0 12px rgba(0, 220, 255, .18);
    font: 700 clamp(16px, 2.8vw, 24px)/1 "Courier New", monospace;
    user-select: none;
    -webkit-user-select: none;
    touch-action: none;
    backdrop-filter: blur(3px);
    transition: transform .06s, background .06s, box-shadow .06s;
}

.control-btn.compact {
    width: clamp(42px, 7.5vw, 60px);
    height: clamp(42px, 7.5vw, 60px);
    margin-bottom: clamp(35px, 5.5vw, 48px);
}

.control-btn.action { border-color: rgba(255, 82, 203, .9); }
.control-btn.dash { font-size: clamp(10px, 1.9vw, 15px); }
.control-btn.shoot { color: #fff3a8; }
.control-btn.jump { margin-bottom: clamp(34px, 5vw, 46px); }
.control-btn.is-pressed {
    transform: scale(.88);
    background: rgba(75, 240, 255, .55);
    box-shadow: inset 0 0 18px rgba(255,255,255,.35), 0 0 22px rgba(0, 230, 255, .55);
}

#rotate-overlay {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 100;
    place-items: center;
    padding: 24px;
    background:
        radial-gradient(circle at 50% 35%, rgba(0, 205, 255, .13), transparent 35%),
        #03050a;
    color: #eefcff;
    text-align: center;
}

.rotate-card {
    display: grid;
    gap: 12px;
    max-width: 340px;
    padding: 28px;
    border: 1px solid rgba(0, 225, 255, .55);
    background: rgba(5, 13, 22, .92);
    box-shadow: 0 0 35px rgba(0, 220, 255, .18);
}
.rotate-card strong { font-size: 20px; }
.rotate-card span { color: #9bb8c2; font-size: 14px; line-height: 1.45; }
.phone-icon { font-size: 52px; color: #3de8ff; text-shadow: 0 0 18px #00d9ff; }

#fullscreen-hint {
    display: none;
    position: absolute;
    z-index: 20;
    top: calc(10px + var(--safe-top));
    right: calc(10px + var(--safe-right));
    border: 1px solid rgba(255,255,255,.4);
    border-radius: 5px;
    padding: 8px 11px;
    color: #dffcff;
    background: rgba(0,0,0,.58);
    font: 700 11px "Courier New", monospace;
}

[hidden] { display: none !important; }

.is-mobile #mobile-controls { display: flex; }
.is-mobile.is-portrait #rotate-overlay { display: grid; }
.is-mobile.is-landscape:not(.is-fullscreen) #fullscreen-hint:not([hidden]) { display: block; }

@media (orientation: landscape) and (max-height: 480px) {
    .is-mobile .control-btn { opacity: .78; }
}

#game-status {
    position: absolute; inset: 0; z-index: 50; display: grid; place-items: center;
    color: #9ef6ff; background: #05070d; font: 700 18px "Courier New", monospace;
    letter-spacing: .08em; text-align: center; padding: 24px;
}
#game-status.error { color: #ff7188; white-space: pre-line; }

/* v5: alkuvalikko, loppuvalikko ja uudelleenkäynnistys */
.game-menu {
    position: absolute;
    inset: 0;
    z-index: 40;
    display: grid;
    place-items: center;
    padding: clamp(16px, 3vw, 32px);
    background:
        linear-gradient(rgba(2, 5, 10, .78), rgba(2, 5, 10, .9)),
        repeating-linear-gradient(90deg, rgba(40, 220, 245, .035) 0 1px, transparent 1px 48px);
    overflow: auto;
    touch-action: pan-y;
}

.menu-panel {
    width: min(760px, 94%);
    padding: clamp(18px, 3vw, 34px);
    border: 1px solid rgba(61, 235, 255, .58);
    background: rgba(4, 12, 20, .94);
    box-shadow: 0 0 34px rgba(0, 220, 255, .2), inset 0 0 24px rgba(0, 220, 255, .05);
    text-align: center;
}

.menu-kicker {
    margin: 0 0 4px;
    color: #51e8ff;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: .34em;
}

.menu-panel h1,
.menu-panel h2 {
    margin: 0;
    color: #f2fdff;
    font-size: clamp(28px, 5vw, 54px);
    line-height: 1;
    text-shadow: 0 0 18px rgba(61, 235, 255, .45);
}

.menu-copy {
    max-width: 620px;
    margin: 14px auto 20px;
    color: #abc8d1;
    font-size: clamp(12px, 1.8vw, 16px);
    line-height: 1.5;
}

.difficulty-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
}

.difficulty-grid button,
.end-actions button {
    border: 1px solid rgba(61, 235, 255, .5);
    border-radius: 4px;
    padding: 14px 16px;
    color: #ecfdff;
    background: linear-gradient(180deg, rgba(21, 68, 82, .72), rgba(8, 24, 32, .9));
    font-family: "Courier New", monospace;
    cursor: pointer;
    touch-action: manipulation;
}

.difficulty-grid button {
    display: grid;
    gap: 5px;
    min-height: 78px;
    text-align: left;
}

.difficulty-grid button strong {
    color: #5cecff;
    font-size: 16px;
}

.difficulty-grid button span {
    color: #a8c5ce;
    font-size: 12px;
    line-height: 1.35;
}

.difficulty-grid button:hover,
.difficulty-grid button:focus-visible,
.end-actions button:hover,
.end-actions button:focus-visible {
    outline: none;
    border-color: #6af0ff;
    background: linear-gradient(180deg, rgba(31, 105, 120, .9), rgba(9, 36, 45, .95));
    box-shadow: 0 0 18px rgba(61, 235, 255, .23);
}

.difficulty-grid .recommended {
    border-color: rgba(255, 92, 214, .72);
    box-shadow: inset 0 0 16px rgba(255, 92, 214, .08);
}

.difficulty-grid .recommended strong {
    color: #ff76df;
}

.controls-help {
    margin: 18px 0 0;
    color: #789aa4;
    font-size: 11px;
    line-height: 1.4;
}

.end-panel {
    width: min(620px, 94%);
}

.end-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.end-actions button {
    min-height: 52px;
    font-weight: 700;
}

.end-actions .primary-action {
    border-color: rgba(89, 255, 155, .72);
    color: #caffdc;
}

.end-actions .secondary-action {
    border-color: rgba(255, 92, 214, .58);
    color: #ffd0f5;
}

.ui-blocking #mobile-controls {
    display: none !important;
}

@media (max-width: 700px), (max-height: 520px) {
    .game-menu {
        align-items: start;
        padding: 10px;
    }

    .menu-panel {
        width: 100%;
        padding: 14px;
    }

    .menu-panel h1,
    .menu-panel h2 {
        font-size: clamp(24px, 7vw, 38px);
    }

    .menu-copy {
        margin: 8px auto 12px;
    }

    .difficulty-grid {
        gap: 7px;
    }

    .difficulty-grid button {
        min-height: 58px;
        padding: 9px 11px;
    }

    .difficulty-grid button strong {
        font-size: 13px;
    }

    .difficulty-grid button span,
    .controls-help {
        font-size: 9px;
    }

    .controls-help {
        margin-top: 10px;
    }
}

@media (max-width: 520px) {
    .difficulty-grid,
    .end-actions {
        grid-template-columns: 1fr;
    }
}


/* level-selector-tool */
.level-selector {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    align-items: center;
    gap: 8px 14px;
    margin: 0 0 14px;
    padding: 12px;
    border: 1px solid rgba(61, 235, 255, .32);
    background: rgba(6, 23, 31, .72);
    text-align: left;
}
.level-selector label {
    color: #5cecff;
    font-size: 13px;
    font-weight: 700;
    letter-spacing: .08em;
}
.level-selector select {
    min-width: 0;
    width: 100%;
    min-height: 42px;
    border: 1px solid rgba(61, 235, 255, .58);
    border-radius: 4px;
    padding: 8px 36px 8px 11px;
    color: #ecfdff;
    background: #071923;
    font: 700 13px "Courier New", monospace;
    cursor: pointer;
    touch-action: manipulation;
}
.level-selector select:focus-visible {
    outline: 2px solid rgba(92, 236, 255, .7);
    outline-offset: 2px;
}
.level-selector span {
    grid-column: 1 / -1;
    color: #789aa4;
    font-size: 11px;
    line-height: 1.35;
}
@media (max-width: 700px), (max-height: 520px) {
    .level-selector {
        grid-template-columns: 1fr;
        gap: 6px;
        margin-bottom: 9px;
        padding: 8px;
    }
    .level-selector span { display: none; }
    .level-selector select {
        min-height: 36px;
        padding-top: 6px;
        padding-bottom: 6px;
    }
}


/* Gyroxen: language and storage notice */
.language-selector {
    display: grid;
    grid-template-columns: auto minmax(120px, 1fr);
    align-items: center;
    gap: 12px;
    margin: 0 0 10px;
    padding: 9px 12px;
    border: 1px solid rgba(255, 69, 111, .32);
    background: rgba(18, 7, 18, .66);
}
.language-selector label {
    color: #ff6f9b;
    font: 700 13px "Courier New", monospace;
    letter-spacing: .08em;
}
.language-selector select {
    min-height: 38px;
    border: 1px solid rgba(255, 91, 139, .58);
    border-radius: 4px;
    padding: 7px 10px;
    color: #fff4f8;
    background: #1a0b14;
    font: 700 13px "Courier New", monospace;
}
.storage-notice {
    position: fixed;
    inset: 0;
    z-index: 10000;
    display: grid;
    place-items: center;
    padding: 18px;
    background: rgba(0, 3, 8, .84);
    backdrop-filter: blur(6px);
}
.storage-notice[hidden] { display: none; }
.storage-card {
    width: min(560px, 100%);
    border: 1px solid rgba(71, 229, 255, .62);
    box-shadow: 0 0 36px rgba(40, 208, 255, .18);
    padding: 24px;
    color: #eafcff;
    background: linear-gradient(145deg, rgba(7, 22, 31, .98), rgba(19, 7, 20, .98));
    font-family: "Courier New", monospace;
}
.storage-card h2 { margin: 0 0 12px; color: #62ecff; }
.storage-card p { margin: 0 0 18px; line-height: 1.55; color: #b8d5db; }
.storage-card button {
    min-width: 140px;
    min-height: 42px;
    border: 1px solid #5deaff;
    color: #031016;
    background: #5deaff;
    font: 800 14px "Courier New", monospace;
    cursor: pointer;
}
@media (max-width: 700px), (max-height: 520px) {
    .language-selector { padding: 6px 8px; margin-bottom: 7px; }
    .language-selector select { min-height: 34px; }
    .storage-card { padding: 16px; }
}
