body {
    margin: 0;
    padding: 0;
    background-image: url('background.jpg');
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    font-family: 'Press Start 2P', 'Courier New', monospace;
    color: white;
    min-height: 100vh;
    overflow-x: auto;
    overflow-y: hidden;
    display: flex;
    flex-direction: column;
}

.game-container {
    display: flex;
    flex-direction: column;
    flex-grow: 1;
    padding: 20px;
    box-sizing: border-box;
}

.game-header {
    text-align: center;
    margin-bottom: 20px;
}

h1 {
    color: #00ff41;
    text-shadow: 0 0 10px #00ff41;
    margin: 0;
    font-size: 24px;
}

.main-content {
    display: flex;
    gap: 30px;
    justify-content: center;
    align-items: stretch;
    flex-wrap: wrap;
    padding: 10px;
    flex-grow: 1;
}

.settings-panel {
    background: rgba(0, 0, 0, 0.8);
    border: 2px solid #00ff41;
    border-radius: 10px;
    padding: 20px;
    min-width: 250px;
    max-width: 300px;
    box-shadow: 0 0 20px rgba(0, 255, 65, 0.3);
}

.settings-panel h3 {
    margin: 0 0 20px 0;
    color: #00ff41;
    text-align: center;
    font-size: 14px;
}

.setting-group {
    margin-bottom: 20px;
}

.setting-group label {
    display: block;
    margin-bottom: 8px;
    font-size: 10px;
    color: #ccc;
}

.volume-slider {
    width: 100%;
    height: 6px;
    background: #333;
    border-radius: 3px;
    outline: none;
    margin-bottom: 5px;
    -webkit-appearance: none;
}

.volume-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 18px;
    height: 18px;
    background: #00ff41;
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 0 10px rgba(0, 255, 65, 0.5);
}

.volume-slider::-moz-range-thumb {
    width: 18px;
    height: 18px;
    background: #00ff41;
    border-radius: 50%;
    cursor: pointer;
    border: none;
    box-shadow: 0 0 10px rgba(0, 255, 65, 0.5);
}

.setting-group span {
    font-size: 10px;
    color: #00ff41;
    text-align: right;
    display: block;
}

.setting-button {
    background: rgba(0, 255, 65, 0.1);
    border: 1px solid #00ff41;
    color: #00ff41;
    padding: 8px 12px;
    margin: 5px;
    border-radius: 5px;
    font-family: inherit;
    font-size: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
    width: calc(50% - 10px);
}

.setting-button:hover {
    background: rgba(0, 255, 65, 0.3);
    box-shadow: 0 0 10px rgba(0, 255, 65, 0.5);
}

.setting-button.muted {
    background: rgba(255, 0, 0, 0.2);
    border-color: #ff4444;
    color: #ff4444;
}

.controls-info {
    margin-top: 20px;
    padding-top: 20px;
    border-top: 1px solid #333;
}

.controls-info h4 {
    margin: 0 0 15px 0;
    font-size: 10px;
    color: #00ff41;
    text-align: center;
}

.controls-grid {
    display: grid;
    grid-template-columns: 1fr 2fr;
    gap: 8px;
    font-size: 8px;
}

.controls-grid span:nth-child(odd) {
    color: #00ff41;
    text-align: right;
    padding-right: 10px;
}

.controls-grid span:nth-child(even) {
    color: #ccc;
}

.game-area {
    display: flex;
    justify-content: center;
    align-items: center;
    flex-grow: 1;
    flex-shrink: 1;
    min-width: 300px;
    position: relative;
    min-height: 300px;
}

#gameCanvas {
    border: 2px solid #00ff41;
    border-radius: 10px;
    box-shadow: 0 0 20px rgba(0, 255, 65, 0.3);
    background: transparent;
    outline: none;
    width: 100%;
    height: auto;
    display: block;
    touch-action: none; /* Let the game handle all touch gestures (drag-to-move); no scroll/zoom */
}

.leaderboard {
    position: absolute;
    top: 10px;
    right: 10px;
    background: rgba(0, 0, 0, 0.6);
    color: #fff;
    padding: 10px 12px;
    border-radius: 6px;
    max-width: 260px;
    font-family: "Press Start 2P", Arial, sans-serif;
    z-index: 50;
}

.leaderboard h3 {
    margin: 0 0 8px 0;
    font-size: 14px;
}

.leaderboard ol {
    margin: 0;
    padding-left: 20px;
    font-size: 12px;
}

.leaderboard li {
    margin-bottom: 4px;
    list-style: decimal; /* Use browser numbering only; we do not add numbers in text */
}

#gameCanvas:focus {
    border-color: #ffff00;
    box-shadow: 0 0 30px rgba(255, 255, 0, 0.6);
    animation: focusPulse 2s infinite;
}

@keyframes focusPulse {
    0%, 100% {
        box-shadow: 0 0 30px rgba(255, 255, 0, 0.6);
    }
    50% {
        box-shadow: 0 0 40px rgba(255, 255, 0, 0.8);
    }
}

/* Touch Controls
   Movement and shooting are handled entirely by dragging on the canvas
   (drag-to-move + auto-fire, see InputSystem.js). The only on-screen touch
   control is a pause button, since the settings panel is hidden on touch. */
.touch-pause {
    display: none; /* Shown only on touch devices via the media query below */
    position: absolute;
    top: 10px;
    right: 10px;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background-color: rgba(0, 255, 65, 0.25);
    border: 2px solid #00ff41;
    color: #fff;
    font-size: 20px;
    line-height: 1;
    cursor: pointer;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    box-shadow: 0 0 10px rgba(0, 255, 65, 0.5);
    z-index: 100;
}

.touch-pause:active {
    background-color: rgba(0, 255, 65, 0.5);
}

/* Show touch UI only on touch devices / small screens. */
@media (hover: none) and (pointer: coarse), (max-width: 1024px) {
    .touch-pause {
        display: block;
    }
    .leaderboard {
        top: 64px; /* Make room for the pause button in the top-right corner */
    }
    .controls-info { /* Keyboard controls info is irrelevant on touch devices */
        display: none;
    }
    .settings-panel { display: none; }
}

/* Responsive design */
@media (max-width: 1200px) {
    .main-content {
        flex-direction: column;
        align-items: center;
    }
    
    .settings-panel {
        max-width: 90%; /* Keep this for smaller desktops */
        margin-bottom: 20px;
    }
}

/* iPad Pro, iPad Air, iPad Mini in Landscape */
@media (max-width: 1024px) and (orientation: landscape) {
    .main-content {
        flex-direction: row; /* Side-by-side for landscape */
        align-items: flex-start;
        justify-content: space-around; /* Better spacing */
    }
    .game-area {
        order: 1; /* Game area first */
        flex-grow: 1;
    }
    #gameCanvas { width: 95vw; height: auto; }
    .settings-panel {
        order: 2; /* Settings panel second */
        max-width: 280px; /* Fixed width for settings in landscape */
        min-width: 220px;
        margin-bottom: 0;
    }
    h1 {
        font-size: 20px;
    }
}

/* iPad Pro, iPad Air, iPad Mini in Portrait */
@media (max-width: 768px) and (orientation: portrait) {
    .main-content {
        flex-direction: column;
        align-items: center;
    }
    .game-area {
        order: 1;
        width: 100%;
    }
    #gameCanvas { width: 95vw; height: auto; }
    .settings-panel {
        order: 2;
        width: 90%; /* Wider settings panel in portrait */
        max-width: 500px; /* Cap width */
        margin-top: 20px;
    }
     h1 {
        font-size: 20px;
    }
}

@media (max-width: 600px) {
    .game-container {
        padding: 10px;
    }
    
    h1 {
        font-size: 18px;
    }
    
    .settings-panel {
        min-width: auto;
        width: 100%;
    }
}

/* Orientation Blocker */
#orientation-blocker {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0,0,0,0.9);
    color: white;
    z-index: 200; /* Highest z-index */
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
    font-size: 20px;
    padding: 20px;
    box-sizing: border-box;
}

/* Modal for player name input */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0,0,0,0.6);
    z-index: 150;
}

.modal.hidden {
    display: none;
}

.modal .modal-content {
    background: rgba(0, 0, 0, 0.95);
    border: 2px solid #00ff41;
    border-radius: 10px;
    padding: 20px;
    width: 90%;
    max-width: 420px;
    color: #fff;
    text-align: center;
    box-shadow: 0 0 20px rgba(0, 255, 65, 0.4);
}

.modal .modal-content h3 {
    margin-top: 0;
    color: #00ff41;
}

#playerNameInput {
    width: 100%;
    padding: 10px;
    margin: 10px 0 20px;
    border-radius: 6px;
    border: 1px solid #00ff41;
    background: rgba(0,0,0,0.5);
    color: #00ff41;
    font-family: 'Press Start 2P', Arial, sans-serif;
}

.modal-actions {
    display: flex;
    gap: 10px;
    justify-content: center;
}

@media (orientation: portrait) and (max-width: 1024px) { /* Target iPads in portrait */
    /* Consider if you want to show this for all portrait scenarios or just touch devices */
    /* For now, showing for iPads in portrait */
    #orientation-blocker {
        display: flex;
    }
    .game-container { /* Optionally hide game when blocker is shown */
        display: none;
    }
}

.setting-dropdown {
    width: 100%;
    padding: 8px;
    border-radius: 5px;
    border: 1px solid #00ff41;
    background-color: rgba(0, 0, 0, 0.5); /* Semi-transparent background */
    color: #00ff41;
    font-family: 'Press Start 2P', Arial, sans-serif;
    font-size: 10px;
    margin-bottom: 10px;
    -webkit-appearance: none; /* Remove default dropdown arrow on WebKit */
    -moz-appearance: none;    /* Remove default dropdown arrow on Firefox */
    appearance: none;
    background-image: url('data:image/svg+xml;charset=US-ASCII,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%22292.4%22%20height%3D%22292.4%22%3E%3Cpath%20fill%3D%22%2300ff41%22%20d%3D%22M287%2C114.7L159.2%2C242.5c-4.5%2C4.5-10.6%2C6.7-16.7%2C6.7s-12.2-2.2-16.7-6.7L5.4%2C114.7c-9-9-9-23.5%2C0-32.5s23.5-9%2C32.5%2C0l118.8%2C118.7l118.7-118.7c9-9%2C23.5-9%2C32.5%2C0S296%2C105.7%2C287%2C114.7z%22%2F%3E%3C%2Fsvg%3E'); /* Custom arrow */
    background-repeat: no-repeat;
    background-position: right 10px center;
    background-size: 12px;
}

.setting-dropdown:focus {
    outline: none;
    border-color: #ffff00;
    box-shadow: 0 0 10px rgba(255, 255, 0, 0.5);
}

.setting-dropdown option {
    background-color: #333; /* Background for options in dropdown */
    color: #00ff41;
}

/* ---- Phase 3: start screen, pause menu, achievement toasts ---- */

.start-content {
    max-width: 480px;
}

.start-title {
    color: #00ff41;
    font-size: 28px;
    letter-spacing: 3px;
    margin: 0 0 6px 0;
    text-shadow: 0 0 14px rgba(0, 255, 65, 0.7);
}

.start-best {
    color: #ffd700;
    font-size: 12px;
    min-height: 16px;
    margin: 4px 0 14px 0;
}

.difficulty-row {
    display: flex;
    gap: 10px;
    justify-content: center;
    margin-bottom: 18px;
}

.diff-btn {
    background: rgba(0, 255, 65, 0.08);
    border: 1px solid #00ff41;
    color: #00ff41;
    padding: 12px 18px;
    min-width: 90px;
    cursor: pointer;
    font-family: inherit;
    font-size: 13px;
    border-radius: 6px;
}

.diff-btn.selected {
    background: rgba(0, 255, 65, 0.35);
    box-shadow: 0 0 12px rgba(0, 255, 65, 0.6);
    font-weight: bold;
}

.diff-btn[data-diff="hard"].selected {
    border-color: #ff4444;
    color: #ff4444;
    background: rgba(255, 68, 68, 0.25);
    box-shadow: 0 0 12px rgba(255, 68, 68, 0.6);
}

.big-btn {
    background: rgba(0, 255, 65, 0.2);
    border: 2px solid #00ff41;
    color: #00ff41;
    padding: 16px 30px;
    min-height: 52px; /* comfortable tap target */
    font-size: 16px;
    font-family: inherit;
    cursor: pointer;
    border-radius: 8px;
    width: 100%;
}

.big-btn:hover {
    background: rgba(0, 255, 65, 0.4);
    box-shadow: 0 0 14px rgba(0, 255, 65, 0.6);
}

.pause-actions {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.pause-actions .setting-button {
    width: 100%;
    min-height: 44px;
}

/* Achievement toasts (top-center stack) */
#achievementToasts {
    position: fixed;
    top: 14px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 200;
    display: flex;
    flex-direction: column;
    gap: 8px;
    pointer-events: none;
}

.achievement-toast {
    background: rgba(0, 0, 0, 0.92);
    border: 1px solid #ffd700;
    border-radius: 8px;
    color: #fff;
    padding: 10px 18px;
    box-shadow: 0 0 16px rgba(255, 215, 0, 0.45);
    display: flex;
    flex-direction: column;
    gap: 2px;
    animation: toast-in 0.35s ease-out;
    font-size: 12px;
}

.achievement-toast strong {
    color: #ffd700;
}

.achievement-toast.leaving {
    transition: opacity 0.5s ease, transform 0.5s ease;
    opacity: 0;
    transform: translateY(-12px);
}

@keyframes toast-in {
    from { opacity: 0; transform: translateY(-16px); }
    to   { opacity: 1; transform: translateY(0); }
}
