* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    background: #0a0a1a;
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
    font-family: 'Courier New', 'Consolas', monospace;
    user-select: none;
    -webkit-user-select: none;
}

#back-to-games {
    position: fixed;
    top: max(12px, env(safe-area-inset-top));
    left: max(12px, env(safe-area-inset-left));
    z-index: 10;
    padding: 8px 12px;
    border: 2px solid #4a4a8e;
    background: #1a1a2e;
    color: #c0c0ff;
    font-size: 13px;
    font-weight: bold;
    letter-spacing: 1px;
    text-decoration: none;
    box-shadow: 0 0 12px rgba(80, 60, 180, 0.25);
}

#back-to-games:hover,
#back-to-games:focus-visible {
    background: #3a3a6e;
    border-color: #ff6b9d;
    color: #fff;
}

#back-to-games:focus-visible {
    outline: 3px solid #ffcc88;
    outline-offset: 2px;
}

#sound-toggle {
    position: fixed;
    right: max(12px, env(safe-area-inset-right));
    bottom: max(12px, env(safe-area-inset-bottom));
    z-index: 10;
    padding: 8px 12px;
    border: 2px solid #4a4a8e;
    background: #1a1a2e;
    color: #c0c0ff;
    font: bold 13px 'Courier New', monospace;
    letter-spacing: 1px;
    cursor: pointer;
    box-shadow: 0 0 12px rgba(80, 60, 180, 0.25);
}

#sound-toggle:hover,
#sound-toggle:focus-visible {
    background: #3a3a6e;
    border-color: #ff6b9d;
    color: #fff;
}

#sound-toggle:focus-visible {
    outline: 3px solid #ffcc88;
    outline-offset: 2px;
}

/* Keep the navigation controls out of the canvas menu on phone landscape. */
@media (max-height: 500px) and (orientation: landscape) {
    #back-to-games {
        top: max(6px, env(safe-area-inset-top));
        left: 50%;
        transform: translateX(-50%);
        padding: 5px 9px;
        font-size: 11px;
        white-space: nowrap;
    }
}

#game-wrapper {
    position: relative;
    border: 4px solid #3a2a5e;
    box-shadow: 0 0 40px rgba(100, 60, 160, 0.3), inset 0 0 20px rgba(0,0,0,0.5);
}

#game-canvas {
    display: block;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
    cursor: crosshair;
    touch-action: none;
}

/* === MODALS === */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
    animation: fadeIn 0.2s ease;
}

.modal.hidden {
    display: none;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.modal-content {
    background: #1a1a2e;
    border: 4px solid #4a4a8e;
    padding: 30px 40px;
    text-align: center;
    color: #c0c0ff;
    min-width: 320px;
    max-width: 420px;
    max-height: calc(100dvh - 16px);
    overflow-y: auto;
    box-shadow: 0 0 30px rgba(80, 60, 180, 0.4);
}

@media (max-width: 480px) {
    .modal-content {
        min-width: unset;
        width: 90vw;
        max-width: 90vw;
        padding: 20px 16px;
    }
    .modal-content h2 {
        font-size: 18px;
    }
    .modal-content input {
        width: 100%;
        font-size: 16px;
    }
    .modal-content button {
        padding: 14px 18px;
        font-size: 16px;
        min-width: 90px;
    }
    #levelup-choices button {
        font-size: 14px;
        padding: 14px 12px;
    }
}

.modal-content h2 {
    margin-bottom: 20px;
    font-size: 22px;
    color: #ff6b9d;
    text-shadow: 0 0 10px rgba(255, 107, 157, 0.4);
    letter-spacing: 2px;
}

.modal-content p {
    margin-bottom: 12px;
    font-size: 14px;
    line-height: 1.5;
}

.modal-content input {
    background: #0a0a1a;
    border: 2px solid #4a4a8e;
    color: #c0c0ff;
    padding: 10px 16px;
    font-family: 'Courier New', monospace;
    font-size: 18px;
    width: 220px;
    text-align: center;
    margin-bottom: 15px;
    outline: none;
    letter-spacing: 2px;
}

.modal-content input:focus {
    border-color: #ff6b9d;
    box-shadow: 0 0 10px rgba(255, 107, 157, 0.3);
}

.modal-buttons {
    display: flex;
    gap: 10px;
    justify-content: center;
    margin-top: 10px;
}

.modal-content button {
    background: #2a2a4e;
    border: 2px solid #4a4a8e;
    color: #c0c0ff;
    padding: 10px 22px;
    font-family: 'Courier New', monospace;
    font-size: 15px;
    cursor: pointer;
    letter-spacing: 1px;
    transition: all 0.15s ease;
}

.modal-content button:hover {
    background: #3a3a6e;
    border-color: #6a6aae;
    transform: scale(1.03);
}

.modal-content button.danger {
    background: #3a1a1a;
    border-color: #8e4a4a;
    color: #ff8888;
}

.modal-content button.danger:hover {
    background: #5a2a2a;
    border-color: #ae6a6a;
}

.feedback {
    margin-top: 12px;
    font-size: 13px;
    min-height: 20px;
    color: #ffaa44;
}

#levelup-choices {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 10px;
}

#levelup-choices button {
    width: 100%;
    padding: 10px 16px;
    font-size: 13px;
    text-align: left;
}

#levelup-info {
    color: #aa88ff;
    font-size: 13px;
    margin-bottom: 5px;
}

#save-warning {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 8px;
    color: #fff;
    background: #70202e;
    font-size: 12px;
}

.modal-content button:focus-visible {
    outline: 3px solid #ffcc88;
    outline-offset: 2px;
}

@media (max-height: 500px) {
    .modal-content { padding: 12px 16px; }
    .modal-content h2 { margin-bottom: 8px; font-size: 18px; }
    .modal-content p { margin-bottom: 6px; }
    #levelup-choices { gap: 4px; }
    #levelup-choices button { padding: 8px 10px; }
}
