#gameRoot {
    position: relative;
    width: 100%;
    height: calc(100vh - 120px);
    min-height: 520px;
    border-radius: 16px;
    overflow: hidden;
    background: #1a1c1e;
    border: 2px solid rgba(255, 255, 255, 0.08);
}

#gameCanvas {
    display: block;
    width: 100%;
    height: 100%;
}

#hud {
    position: absolute;
    top: 12px;
    left: 12px;
    right: 56px;
    pointer-events: none;
    z-index: 5;
}

.keys-strip {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 8px;
    min-height: 1.4rem;
}

.keys-empty {
    color: rgba(255, 255, 255, 0.45);
    font-size: 0.85rem;
    font-weight: 600;
}

.key-badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 3px 9px 3px 7px;
    border-radius: 999px;
    font-size: 0.85rem;
    font-weight: 800;
    background: rgba(0, 0, 0, 0.45);
    border: 2px solid rgba(255, 255, 255, 0.15);
}

.key-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    box-shadow: 0 0 6px currentColor;
}

.key-badge.key-red { color: #ff6666; border-color: rgba(255, 68, 68, 0.55); }
.key-badge.key-red .key-dot { background: #ff4444; }

.key-badge.key-blue { color: #88bbff; border-color: rgba(68, 136, 255, 0.55); }
.key-badge.key-blue .key-dot { background: #4488ff; }

.key-badge.key-green { color: #88ffaa; border-color: rgba(68, 221, 119, 0.55); }
.key-badge.key-green .key-dot { background: #44dd77; }

.key-badge.key-yellow { color: #ffe566; border-color: rgba(255, 221, 68, 0.55); }
.key-badge.key-yellow .key-dot { background: #ffdd44; }

.key-badge.key-purple { color: #dd99ff; border-color: rgba(187, 102, 255, 0.55); }
.key-badge.key-purple .key-dot { background: #bb66ff; }

.hud-row {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    font-size: 1.1rem;
    font-weight: 700;
    text-shadow: 0 2px 8px rgba(0, 0, 0, 0.8);
}

.alarm-status {
    margin-top: 10px;
    padding: 8px 14px;
    border-radius: 10px;
    font-weight: 700;
    font-size: 0.95rem;
    display: inline-block;
}

.alarm-safe { background: rgba(0, 176, 111, 0.35); color: #b8ffd8; }
.alarm-warning { background: rgba(245, 205, 48, 0.35); color: #fff3b0; }
.alarm-danger { background: rgba(255, 77, 77, 0.55); color: #fff; animation: alarmPulse 0.5s infinite alternate; }
.alarm-hop { background: rgba(0, 162, 255, 0.45); color: #d4f0ff; }

@keyframes alarmPulse {
    from { opacity: 1; transform: scale(1); }
    to { opacity: 0.85; transform: scale(1.02); }
}

#gameRoot.alarm-warning {
    box-shadow: inset 0 0 0 3px rgba(245, 205, 48, 0.5);
}

#gameRoot.alarm-danger {
    box-shadow: inset 0 0 0 4px rgba(255, 77, 77, 0.75);
    animation: borderFlash 0.4s infinite alternate;
}

@keyframes borderFlash {
    from { box-shadow: inset 0 0 0 4px rgba(255, 77, 77, 0.6); }
    to { box-shadow: inset 0 0 0 6px rgba(255, 0, 0, 0.95); }
}

.game-rules {
    text-align: left;
    color: var(--text-muted, #b8bcc4);
    font-size: 0.9rem;
    margin: 0 0 16px;
    padding-left: 1.2rem;
    line-height: 1.7;
}

.panel-danger h2 {
    color: #ff4d4d;
}

.overlay .panel {
    max-width: 400px;
}

#hint {
    margin-top: 8px;
    color: rgba(255, 255, 255, 0.7);
    font-size: 0.9rem;
}

.overlay {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.65);
    z-index: 10;
}

.overlay.hidden {
    display: none;
}

.overlay .panel {
    background: var(--bg-card, #2d2f33);
    padding: 28px;
    border-radius: 16px;
    max-width: 360px;
    width: 90%;
    text-align: center;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
}

.overlay h2 {
    margin-bottom: 10px;
    color: var(--accent-blue, #00A2FF);
}

.overlay p {
    color: var(--text-muted, #b8bcc4);
    margin-bottom: 16px;
}

.skin-label {
    display: block;
    margin-bottom: 8px;
    font-weight: 600;
}

.skin-picker {
    display: flex;
    gap: 8px;
    justify-content: center;
    margin-bottom: 16px;
}

.skin-btn {
    padding: 8px 16px;
    border-radius: 10px;
    border: 2px solid transparent;
    background: #383b40;
    color: white;
    font-family: inherit;
    font-weight: 600;
    cursor: pointer;
}

.skin-btn.active {
    border-color: var(--accent-blue, #00A2FF);
}

.theme-picker {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-bottom: 16px;
}

.theme-btn {
    padding: 10px 8px;
    border-radius: 10px;
    border: 2px solid transparent;
    background: #383b40;
    color: white;
    font-family: inherit;
    font-weight: 600;
    font-size: 0.85rem;
    cursor: pointer;
    text-align: center;
}

.theme-btn[data-theme="doom"] { background: linear-gradient(135deg, #4a4038, #2a2420); }
.theme-btn[data-theme="castle"] { background: linear-gradient(135deg, #6a6a72, #4a4a52); }
.theme-btn[data-theme="tech"] { background: linear-gradient(135deg, #1a3050, #0a1828); color: #88ddff; }
.theme-btn[data-theme="lava"] { background: linear-gradient(135deg, #662211, #2a0a08); color: #ffaa66; }

.theme-btn.active {
    border-color: #ffe566;
    box-shadow: 0 0 12px rgba(255, 229, 102, 0.35);
}

.music-picker,
.radio-picker {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 8px;
    margin-bottom: 10px;
}

.radio-picker {
    grid-template-columns: 1fr;
    margin-bottom: 14px;
}

.radio-picker.hidden {
    display: none;
}

.music-mode-btn,
.radio-btn {
    padding: 8px 6px;
    border-radius: 10px;
    border: 2px solid transparent;
    background: #2a2d32;
    color: white;
    font-family: inherit;
    font-weight: 600;
    font-size: 0.8rem;
    cursor: pointer;
}

.music-mode-btn.active,
.radio-btn.active {
    border-color: #ff66cc;
    background: #3a2840;
}

.music-volume-row {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 16px;
    font-size: 0.85rem;
    font-weight: 600;
}

.music-volume-row input[type="range"] {
    flex: 1;
    accent-color: #ff66cc;
}

.music-preview-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 2px solid #ff66cc;
    background: #2a2d32;
    color: #ff66cc;
    cursor: pointer;
    font-size: 0.85rem;
}

.music-toggle-btn {
    position: absolute;
    top: 12px;
    right: 12px;
    z-index: 9;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: 2px solid rgba(255, 255, 255, 0.2);
    background: rgba(0, 0, 0, 0.55);
    font-size: 1.2rem;
    cursor: pointer;
    pointer-events: auto;
}

.overlay input {
    width: 100%;
    padding: 12px;
    border-radius: 10px;
    border: 2px solid rgba(255, 255, 255, 0.12);
    background: #232527;
    color: white;
    font-family: inherit;
    font-size: 1rem;
    margin-bottom: 12px;
}

.overlay .btn {
    width: 100%;
    margin-bottom: 8px;
}

.start-panel #startBtn {
    margin-top: auto;
}

.score-msg {
    min-height: 1.2em;
    font-size: 0.9rem;
    color: var(--accent-green, #00B06F);
}

#mobileControls {
    display: none;
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 8;
}

#joystick {
    position: absolute;
    left: 24px;
    bottom: 24px;
    width: 120px;
    height: 120px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.12);
    border: 2px solid rgba(255, 255, 255, 0.25);
    pointer-events: auto;
    touch-action: none;
}

#joystickKnob {
    position: absolute;
    width: 48px;
    height: 48px;
    left: 36px;
    top: 36px;
    border-radius: 50%;
    background: rgba(0, 162, 255, 0.85);
}

#jumpBtn {
    position: absolute;
    right: 24px;
    bottom: 36px;
    width: 80px;
    height: 80px;
    border-radius: 50%;
    border: none;
    background: var(--accent-green, #00B06F);
    color: white;
    font-family: inherit;
    font-weight: 700;
    font-size: 1rem;
    pointer-events: auto;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
}

.rot-btn {
    position: absolute;
    right: 120px;
    bottom: 48px;
    width: 52px;
    height: 52px;
    border-radius: 50%;
    border: none;
    background: rgba(255, 255, 255, 0.15);
    color: white;
    font-family: inherit;
    font-weight: 700;
    font-size: 1.4rem;
    pointer-events: auto;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.35);
}

#rotLeftBtn {
    right: 178px;
}

#rotRightBtn {
    right: 116px;
}

@media (max-width: 768px), (pointer: coarse) {
    #gameRoot {
        height: calc(100vh - 80px);
    }

    #startScreen {
        padding: 12px;
    }

    .start-panel {
        width: min(92vw, 92vh);
        max-width: min(92vw, 92vh);
        aspect-ratio: 1 / 1;
        max-height: min(92vw, 92vh);
        padding: 16px;
        display: flex;
        flex-direction: column;
        gap: 10px;
        overflow-y: auto;
    }

    .start-panel h2 {
        margin-bottom: 2px;
        font-size: 1.55rem;
        line-height: 1.1;
    }

    .start-panel p {
        margin-bottom: 6px;
        font-size: 0.95rem;
        line-height: 1.35;
    }

    .start-panel .game-rules {
        margin-bottom: 8px;
        font-size: 0.85rem;
        line-height: 1.45;
    }

    .start-panel .skin-label {
        margin-bottom: 4px;
    }

    .start-panel .theme-picker,
    .start-panel .skin-picker,
    .start-panel .music-picker,
    .start-panel .radio-picker,
    .start-panel .music-volume-row {
        margin-bottom: 8px;
    }

    .start-panel #startBtn {
        position: sticky;
        bottom: 0;
        margin: 6px 0 0;
        z-index: 2;
    }

    #mobileControls {
        display: block;
    }

    #hint {
        display: none;
    }
}

.score-popup {
    position: absolute;
    left: 50%;
    top: 42%;
    transform: translate(-50%, -50%) scale(0.6);
    font-size: 2rem;
    font-weight: 800;
    color: #ffe566;
    text-shadow: 0 0 12px #ff8800, 0 2px 8px #000;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.12s, transform 0.2s;
    z-index: 6;
}

.score-popup.show {
    opacity: 1;
    transform: translate(-50%, -60%) scale(1);
}

.game-toast {
    position: absolute;
    bottom: 18%;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.72);
    color: #b8ffd8;
    padding: 8px 16px;
    border-radius: 8px;
    font-weight: 700;
    opacity: 0;
    transition: opacity 0.2s;
    z-index: 6;
    pointer-events: none;
}

.game-toast.show {
    opacity: 1;
}

.arcade-overlay {
    background: radial-gradient(circle at center, #1a1033 0%, #050208 70%);
}

.arcade-panel {
    background: #0a0a12;
    border: 4px solid #ff2fd6;
    box-shadow: 0 0 30px rgba(255, 47, 214, 0.35), inset 0 0 40px rgba(0, 255, 255, 0.06);
    padding: 28px 24px;
    max-width: 420px;
    width: 92%;
    text-align: center;
    font-family: 'Courier New', Courier, monospace;
    color: #ffe566;
    position: relative;
}

.arcade-panel::before {
    content: '';
    position: absolute;
    inset: 0;
    background: repeating-linear-gradient(
        0deg,
        transparent,
        transparent 2px,
        rgba(255, 255, 255, 0.03) 2px,
        rgba(255, 255, 255, 0.03) 4px
    );
    pointer-events: none;
}

.arcade-kicker {
    color: #00ffff;
    letter-spacing: 0.4em;
    margin: 0 0 4px;
    font-size: 0.85rem;
}

.arcade-title {
    margin: 0 0 12px;
    font-size: 2rem;
    color: #ff2fd6;
    text-shadow: 0 0 10px #ff2fd6, 0 0 20px #ff2fd6;
    letter-spacing: 0.15em;
}

.arcade-score-label {
    margin: 0;
    font-size: 0.8rem;
    color: #00ffff;
    letter-spacing: 0.2em;
}

.arcade-score {
    margin: 4px 0 16px;
    font-size: 2.8rem;
    font-weight: 800;
    color: #ffe566;
    text-shadow: 0 0 12px #ffaa00;
}

.arcade-label {
    margin: 0 0 8px;
    font-size: 0.75rem;
    letter-spacing: 0.25em;
    color: #ff88cc;
}

.arcade-initials {
    display: flex;
    justify-content: center;
    gap: 12px;
    margin-bottom: 10px;
}

.arcade-letter {
    width: 52px;
    height: 58px;
    line-height: 58px;
    font-size: 2rem;
    font-weight: 800;
    background: #111;
    border: 3px solid #444;
    color: #888;
}

.arcade-letter.active {
    border-color: #00ffff;
    color: #ffe566;
    box-shadow: 0 0 14px rgba(0, 255, 255, 0.5);
    animation: blinkLetter 0.8s step-end infinite;
}

@keyframes blinkLetter {
    50% { opacity: 0.55; }
}

.arcade-hint {
    font-size: 0.72rem;
    color: #888;
    margin: 0 0 14px;
}

.arcade-btn {
    display: block;
    width: 100%;
    margin: 8px 0;
    padding: 12px;
    border: 2px solid #00ffff;
    background: transparent;
    color: #00ffff;
    font-family: inherit;
    font-weight: 800;
    font-size: 0.95rem;
    letter-spacing: 0.1em;
    cursor: pointer;
}

.arcade-btn:hover {
    background: rgba(0, 255, 255, 0.12);
}

.arcade-btn-dim {
    border-color: #666;
    color: #aaa;
}

.arcade-msg {
    min-height: 1.2em;
    color: #00ff88;
    font-size: 0.85rem;
    margin: 4px 0;
}

.arcade-top {
    list-style: none;
    padding: 0;
    margin: 12px 0;
    text-align: left;
    font-size: 0.82rem;
    color: #ccc;
    border-top: 1px solid #333;
    padding-top: 10px;
}

.arcade-top li {
    padding: 3px 0;
}

.arcade-top span {
    color: #ff2fd6;
    display: inline-block;
    width: 1.5em;
}

.arcade-link {
    display: inline-block;
    margin-top: 8px;
    color: #888;
    font-size: 0.85rem;
}
