:root {
    --bg-color: #bae6fd;
    --panel-bg: rgba(255, 255, 255, 0.8);
    --primary: #3b82f6;
    --primary-hover: #60a5fa;
    --secondary: #e2e8f0;
    --secondary-hover: #cbd5e1;
    --accent: #10b981;
    --danger: #ef4444;
    --text: #1e293b;
    --text-muted: #475569;
    --glow: 0 0 15px rgba(255, 255, 255, 0.8);
    --glass-border: 1px solid rgba(255, 255, 255, 0.6);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Outfit', sans-serif;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

html,
body {
    height: 100%;
    width: 100%;
    overflow: hidden;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
}

body {
    background-color: #000;
    color: var(--text);
    display: flex;
    justify-content: center;
    align-items: center;
}

#app-container {
    width: 100%;
    max-width: 480px;
    /* Portrait constraint */
    height: 100%;
    max-height: 900px;
    background: #000;
    position: relative;
    overflow: hidden;
    box-shadow: 0 0 30px rgba(0, 0, 0, 0.2);
    display: flex;
    flex-direction: column;
}

/* Screens */
.screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: none;
    flex-direction: column;
}

.screen.active {
    display: flex;
}

/* Start Menu */
#start-menu {
    background-color: #1a4a2a;
    position: relative;
    justify-content: flex-end;
    align-items: center;
    padding-bottom: max(5%, env(safe-area-inset-bottom));
}

#menu-bg-img {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center top;
    display: block;
}

/* Gradient to fade out the original button graphics in the image */
#menu-footer-gradient {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 45%;
    background: linear-gradient(to bottom,
            transparent 0%,
            rgba(15, 40, 20, 0.55) 40%,
            rgba(10, 30, 15, 0.88) 100%);
    z-index: 1;
}

/* Button container — sits above the gradient */
.menu-buttons {
    position: relative;
    z-index: 2;
    width: 78%;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* Base button style */
.menu-btn {
    width: 100%;
    height: 64px;
    border: none;
    outline: none;
    cursor: pointer;
    border-radius: 50px;
    font-family: 'Outfit', sans-serif;
    font-size: 1.2rem;
    font-weight: 800;
    letter-spacing: 0.02em;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 14px;
    transition: transform 0.12s ease, box-shadow 0.12s ease;
    -webkit-tap-highlight-color: transparent;
}

.menu-btn:active {
    transform: scale(0.95);
}

.btn-icon {
    width: 26px;
    height: 26px;
    flex-shrink: 0;
}

/* New Game — green gradient */
.menu-btn-primary {
    background: linear-gradient(160deg, #5fd96a 0%, #2db340 60%, #1a8a2c 100%);
    color: #fff;
    box-shadow:
        0 6px 20px rgba(45, 179, 64, 0.55),
        inset 0 2px 0 rgba(255, 255, 255, 0.35),
        inset 0 -3px 0 rgba(0, 0, 0, 0.2);
    border: 2px solid rgba(255, 255, 255, 0.3);
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}

.menu-btn-primary:active {
    box-shadow:
        0 2px 8px rgba(45, 179, 64, 0.4),
        inset 0 2px 6px rgba(0, 0, 0, 0.2);
}

/* Settings / Exit — white glass */
.menu-btn-secondary {
    background: rgba(255, 255, 255, 0.92);
    color: #1a3528;
    box-shadow:
        0 4px 16px rgba(0, 0, 0, 0.25),
        inset 0 1px 0 rgba(255, 255, 255, 0.9);
    border: 1.5px solid rgba(255, 255, 255, 0.7);
}

.menu-btn-secondary:active {
    background: rgba(240, 250, 240, 0.95);
    box-shadow: 0 1px 6px rgba(0, 0, 0, 0.2);
}


/* Game Screen */
#game-screen {
    background-color: #2d5a27;
    background-image: url('assets/play.png');
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
}

/* Shared button base */
button {
    border: none;
    outline: none;
    cursor: pointer;
    font-family: 'Outfit', sans-serif;
    font-weight: 700;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

button:active {
    transform: scale(0.95);
}

#game-header {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    padding: max(1.5rem, env(safe-area-inset-top)) 1.5rem 1.5rem 1.5rem;
    z-index: 10;
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    pointer-events: none;
    /* Let clicks through to the game unless on a button */
}

#game-header * {
    pointer-events: auto;
    /* Re-enable clicks for buttons */
}

.header-item.left {
    justify-self: start;
}

.header-item.center {
    justify-self: center;
}

.header-item.right {
    justify-self: end;
}

.stat-badge {
    background: rgba(255, 255, 255, 0.95);
    padding: 6px 16px;
    border-radius: 20px;
    display: flex;
    align-items: center;
    gap: 8px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
    border: 2px solid #fff;
    backdrop-filter: blur(10px);
}

.stat-badge .label {
    font-size: 0.75rem;
    font-weight: 900;
    color: #64748b;
    letter-spacing: 0.05em;
    padding-top: 2px;
}

.stat-badge .value {
    font-size: 1.3rem;
    font-weight: 900;
    color: #1e293b;
    font-variant-numeric: tabular-nums;
}

.quit-btn-icon {
    width: 48px;
    height: 48px;
    background: linear-gradient(135deg, #ff4757 0%, #ff6b81 100%);
    border: 3px solid #fff;
    border-radius: 50%;
    color: white;
    display: flex;
    justify-content: center;
    align-items: center;
    box-shadow: 0 4px 15px rgba(255, 71, 87, 0.5);
    cursor: pointer;
    transition: transform 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.quit-btn-icon:active {
    transform: scale(0.9);
}

.quit-btn-icon svg {
    width: 24px;
    height: 24px;
}


#game-canvas {
    width: 100%;
    flex: 1;
    min-height: 0;
    display: block;
    background: transparent;
}


/* Bottom Controls */
#controls-panel {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 1rem 1rem max(2rem, env(safe-area-inset-bottom)) 1rem;
    width: 100%;
    z-index: 10;
    pointer-events: none;
    /* Let clicks pass through outside the pill */
}

.controls-wrapper {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(15px);
    padding: 12px 24px;
    border-radius: 60px;
    display: flex;
    align-items: center;
    gap: 25px;
    box-shadow:
        0 10px 40px rgba(0, 0, 0, 0.3),
        inset 0 1px 0 rgba(255, 255, 255, 1);
    border: 3px solid #fff;
    pointer-events: auto;
    /* Enable clicks on the pill */
}

.nav-btn {
    width: 52px;
    height: 52px;
    background: #f1f5f9;
    color: #475569;
    border-radius: 50%;
    border: 2px solid #e2e8f0;
    display: flex;
    justify-content: center;
    align-items: center;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
}

.nav-btn:active {
    background: #e2e8f0;
    transform: scale(0.9);
}

.fire-btn {
    width: 90px;
    height: 90px;
    border-radius: 50%;
    background: linear-gradient(135deg, #3b82f6 0%, #1d4ed8 100%);
    border: 4px solid #fff;
    color: white;
    font-size: 3rem;
    font-weight: 900;
    box-shadow:
        0 8px 25px rgba(59, 130, 246, 0.5),
        inset 0 4px 10px rgba(255, 255, 255, 0.2);
    display: flex;
    justify-content: center;
    align-items: center;
    text-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.fire-btn #fire-number {
    line-height: 1;
    font-family: 'Outfit', sans-serif;
}

.fire-btn:active {
    transform: scale(0.92);
}

/* Modals */
.overlay {
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(8px);
    justify-content: center;
    align-items: center;
    z-index: 100;
}

.overlay.hidden {
    display: none !important;
}

.modal {
    background: var(--panel-bg);
    border: var(--glass-border);
    border-radius: 24px;
    padding: 2.5rem 2rem;
    width: 85%;
    text-align: center;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.6);
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    transform: scale(0.9);
    animation: popIn 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

@keyframes popIn {
    to {
        transform: scale(1);
    }
}

.modal h2 {
    font-size: 2.5rem;
    margin-bottom: 0.5rem;
}

.danger-text {
    color: var(--danger);
    text-shadow: 0 0 10px rgba(239, 68, 68, 0.5);
}

.success-text {
    color: var(--accent);
    text-shadow: 0 0 10px rgba(16, 185, 129, 0.5);
}

.final-stats {
    font-size: 1.2rem;
    color: var(--text-muted);
    background: rgba(0, 0, 0, 0.3);
    padding: 1rem;
    border-radius: 12px;
}

.final-stats span {
    color: var(--primary);
    font-weight: 700;
    font-size: 1.5rem;
}

/* Settings Styles */
.settings-group {
    margin: 1.5rem 0;
    text-align: left;
}

.settings-label {
    font-weight: 800;
    font-size: 1.2rem;
    color: var(--text);
    margin-bottom: 0.2rem;
}

.settings-help {
    font-size: 0.9rem;
    color: var(--text-muted);
    margin-bottom: 1.2rem;
}

.radio-group {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
}

.radio-card {
    position: relative;
    cursor: pointer;
}

.radio-card input {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}

.radio-content {
    background: rgba(255, 255, 255, 0.05);
    border: 2px solid rgba(255, 255, 255, 0.1);
    color: var(--text);
    padding: 12px;
    border-radius: 12px;
    text-align: center;
    font-weight: 900;
    font-size: 1.2rem;
    transition: all 0.2s;
}

.radio-card input:checked+.radio-content {
    background: linear-gradient(135deg, #3b82f6 0%, #1d4ed8 100%);
    border-color: #fff;
    color: white;
    box-shadow: 0 4px 12px rgba(29, 78, 216, 0.4);
    transform: translateY(-2px);
}

.radio-card:hover .radio-content {
    background: rgba(255, 255, 255, 0.1);
}

#settings-screen {
    z-index: 2000;
}

.btn-icon {
    pointer-events: none;
}


.level-selector {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: rgba(255, 255, 255, 0.05);
    padding: 10px 20px;
    border-radius: 16px;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

#start-level-display {
    font-size: 2rem;
    font-weight: 900;
    color: var(--text);
    min-width: 60px;
    text-align: center;
}

.level-btn {
    width: 44px;
    height: 44px;
    background: #fff;
    color: #1e293b;
    border: none;
    border-radius: 50%;
    font-size: 1.5rem;
    font-weight: 900;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);
}

.level-btn:active {
    transform: scale(0.9);
}

.level-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}