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

:root {
    --primary: #00d4ff;
    --primary-dim: #0088aa;
    --accent: #ff6b35;
    --danger: #ff3355;
    --success: #00ff88;
    --warning: #ffaa00;
    --shield-color: #00aaff;
    --health-color: #ff4466;
    --energy-color: #ffcc00;
    --crystal-color: #00ffcc;
    --bg-dark: #0a0e1a;
    --bg-panel: rgba(10, 14, 30, 0.85);
    --border-color: rgba(0, 212, 255, 0.3);
    --text: #e0e8ff;
    --text-dim: #7888aa;
    --glass: rgba(10, 20, 40, 0.7);
    --glass-border: rgba(0, 180, 255, 0.2);

    --safe-t: env(safe-area-inset-top, 0px);
    --safe-b: env(safe-area-inset-bottom, 0px);
    --safe-l: env(safe-area-inset-left, 0px);
    --safe-r: env(safe-area-inset-right, 0px);

    --gap: clamp(10px, 2.2vh, 24px);
    --pad: clamp(10px, 3vh, 40px);
    --fs-base: clamp(12px, min(1.05vw + 0.55vh, 2.1vh), 17px);
}

html, body {
    width: 100%;
    height: 100%;
    max-width: 100%;
    overflow: hidden;
    overscroll-behavior: none;
    background: var(--bg-dark);
    font-family: 'Segoe UI', 'Helvetica Neue', Arial, sans-serif;
    color: var(--text);
    font-size: var(--fs-base);
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
    -webkit-tap-highlight-color: transparent;
}

body {
    position: fixed;
    inset: 0;
    overflow: hidden;
}

/* Immersive (pseudo-fullscreen) mode used where the Fullscreen API is
   unavailable: the page is already edge to edge, so just harden it. */
html.is-fullscreen,
html.is-fullscreen body {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    overscroll-behavior: none;
}

button, select, input {
    font-family: inherit;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

button:focus-visible,
select:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

canvas#gameCanvas {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: block;
    z-index: 0;
    touch-action: none;
}

.screen {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: none;
    justify-content: center;
    align-items: center;
    padding: calc(var(--pad) * 0.6 + var(--safe-t)) calc(var(--pad) * 0.6 + var(--safe-r)) calc(var(--pad) * 0.6 + var(--safe-b)) calc(var(--pad) * 0.6 + var(--safe-l));
    overflow: hidden;
    touch-action: pan-y;
    z-index: 100;
}

.screen.active {
    display: flex;
}

.menu-bg {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: radial-gradient(ellipse at 50% 30%, rgba(0, 40, 80, 0.6) 0%, rgba(10, 14, 26, 0.95) 70%);
    z-index: -1;
}

.overlay-bg {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(5, 8, 18, 0.8);
    z-index: -1;
}

/* margin:auto keeps the block centred but never clips its top edge when it overflows */
.menu-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--gap);
    padding: 0;
    margin: auto;
    width: 100%;
    max-width: 100%;
    max-height: 100%;
    overflow-y: auto;
    overflow-x: hidden;
    overscroll-behavior: contain;
    touch-action: pan-y;
    scrollbar-width: thin;
    scrollbar-color: var(--border-color) transparent;
}

.menu-content::-webkit-scrollbar {
    width: 4px;
}

.menu-content::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 2px;
}

.menu-content > * {
    flex: 0 0 auto;
    max-width: 100%;
}

.menu-content.compact {
    gap: clamp(8px, 1.8vh, 16px);
}

.menu-content.scrollable {
    max-width: 760px;
    width: 100%;
}

.title-group {
    text-align: center;
    margin-bottom: 4px;
}

.game-title {
    font-size: clamp(30px, min(13vw, 9vh), 96px);
    font-weight: 900;
    letter-spacing: clamp(3px, min(3.2vw, 2.2vh), 16px);
    color: #fff;
    text-shadow: 0 0 40px rgba(0, 180, 255, 0.5), 0 0 80px rgba(0, 100, 200, 0.3);
    line-height: 1;
    white-space: nowrap;
}

.title-accent {
    color: var(--primary);
    text-shadow: 0 0 30px rgba(0, 212, 255, 0.6), 0 0 60px rgba(0, 150, 255, 0.4);
}

.game-subtitle {
    font-size: clamp(9px, min(3.4vw, 1.9vh), 18px);
    letter-spacing: clamp(2px, min(1.6vw, 1.2vh), 10px);
    color: var(--text-dim);
    margin-top: 8px;
    text-align: center;
}

.screen-title {
    font-size: clamp(20px, min(7vw, 4.2vh), 40px);
    font-weight: 700;
    letter-spacing: clamp(2px, min(1.2vw, 0.9vh), 5px);
    color: var(--primary);
    text-shadow: 0 0 20px rgba(0, 180, 255, 0.3);
    margin-bottom: 4px;
    text-align: center;
}

.gameover-title {
    color: var(--danger);
    text-shadow: 0 0 20px rgba(255, 50, 80, 0.4);
}

.menu-buttons {
    display: flex;
    flex-direction: column;
    gap: clamp(7px, 1.5vh, 12px);
    width: min(300px, 84vw);
}

.menu-stats {
    font-size: clamp(10px, min(3.2vw, 1.6vh), 15px);
    color: var(--text-dim);
    letter-spacing: 2px;
    text-align: center;
}

.btn {
    padding: clamp(8px, 1.9vh, 16px) clamp(14px, 4vw, 36px);
    border: none;
    border-radius: 6px;
    font-size: clamp(11px, min(3.4vw, 1.9vh), 17px);
    font-weight: 600;
    letter-spacing: clamp(1.5px, min(1vw, 0.8vh), 3px);
    cursor: pointer;
    transition: transform 0.15s ease, box-shadow 0.2s ease, background 0.2s ease, border-color 0.2s ease;
    text-transform: uppercase;
    position: relative;
    overflow: hidden;
    width: 100%;
    touch-action: manipulation;
}

.btn::after {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.1), transparent);
    transition: left 0.4s;
}

.btn:hover::after {
    left: 100%;
}

.btn:active {
    transform: scale(0.97);
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary), #0088cc);
    color: #001a22;
    box-shadow: 0 0 20px rgba(0, 180, 255, 0.3);
}

.btn-primary:hover {
    transform: scale(1.03);
    box-shadow: 0 0 30px rgba(0, 180, 255, 0.5);
}

.btn-secondary {
    background: var(--glass);
    color: var(--text);
    border: 1px solid var(--glass-border);
}

.btn-secondary:hover {
    background: rgba(0, 180, 255, 0.15);
    border-color: var(--primary);
}

.btn-danger {
    background: rgba(255, 50, 80, 0.15);
    color: var(--danger);
    border: 1px solid rgba(255, 50, 80, 0.3);
}

.btn-danger:hover {
    background: rgba(255, 50, 80, 0.25);
}

.btn-back {
    padding: clamp(7px, 1.4vh, 11px) clamp(14px, 4vw, 26px);
    background: transparent;
    color: var(--text-dim);
    border: 1px solid rgba(255,255,255,0.15);
    border-radius: 6px;
    font-size: clamp(10px, min(3vw, 1.7vh), 15px);
    letter-spacing: 2px;
    cursor: pointer;
    width: auto;
    touch-action: manipulation;
}

.btn-back:hover {
    border-color: var(--primary);
    color: var(--primary);
}

.gameover-stats {
    width: min(320px, 86vw);
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.stat-row {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    padding: clamp(4px, 1vh, 7px) 12px;
    background: rgba(255,255,255,0.03);
    border-radius: 4px;
    font-size: clamp(10px, min(3.1vw, 1.7vh), 15px);
    letter-spacing: 1px;
}

.stat-row span:last-child {
    color: var(--primary);
    font-weight: 600;
}

.stat-row.highlight {
    border-top: 1px solid var(--border-color);
    margin-top: 4px;
}

.stat-row.highlight span:last-child {
    color: var(--warning);
}

.respawn-content {
    text-align: center;
}

.respawn-label {
    font-size: 18px;
    letter-spacing: 4px;
    color: var(--text-dim);
    margin-bottom: 16px;
}

.respawn-count {
    font-size: clamp(40px, min(18vw, 12vh), 80px);
    font-weight: 900;
    color: var(--primary);
    text-shadow: 0 0 30px rgba(0, 180, 255, 0.5);
}

.settings-list {
    width: min(340px, 88vw);
    display: flex;
    flex-direction: column;
    gap: clamp(6px, 1.3vh, 10px);
}

.setting-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    padding: clamp(6px, 1.3vh, 11px) clamp(10px, 3vw, 16px);
    background: rgba(255,255,255,0.03);
    border-radius: 6px;
    border: 1px solid rgba(255,255,255,0.05);
}

.setting-row span {
    font-size: clamp(10px, min(3.1vw, 1.7vh), 15px);
    letter-spacing: 1px;
}

.toggle-btn {
    padding: clamp(4px, 1vh, 7px) clamp(10px, 3vw, 18px);
    border: 1px solid rgba(255,255,255,0.2);
    border-radius: 4px;
    background: transparent;
    color: var(--text-dim);
    font-size: clamp(9px, min(2.8vw, 1.5vh), 12px);
    font-weight: 600;
    letter-spacing: 2px;
    cursor: pointer;
    transition: all 0.2s;
    flex: 0 0 auto;
}

.toggle-btn.active {
    background: rgba(0, 212, 255, 0.15);
    border-color: var(--primary);
    color: var(--primary);
}

.setting-select {
    padding: clamp(4px, 1vh, 7px) clamp(8px, 2.5vw, 12px);
    border: 1px solid rgba(255,255,255,0.2);
    border-radius: 4px;
    background: var(--bg-dark);
    color: var(--text);
    font-size: clamp(9px, min(2.8vw, 1.5vh), 12px);
    letter-spacing: 1px;
    cursor: pointer;
    flex: 0 0 auto;
    max-width: 55%;
}

.setting-select:focus {
    outline: none;
    border-color: var(--primary);
}

.mode-cards {
    display: flex;
    gap: clamp(8px, 1.6vw, 16px);
    flex-wrap: wrap;
    justify-content: center;
    max-width: 800px;
}

.mode-card {
    width: clamp(150px, 40vw, 220px);
    padding: clamp(10px, 2.4vh, 24px) clamp(10px, 3vw, 16px);
    background: var(--glass);
    border: 1px solid var(--glass-border);
    border-radius: 10px;
    text-align: center;
    cursor: pointer;
    transition: transform 0.25s, background 0.25s, border-color 0.25s;
    touch-action: manipulation;
}

.mode-card:hover {
    border-color: var(--primary);
    background: rgba(0, 180, 255, 0.1);
    transform: translateY(-3px);
}

.mode-icon {
    font-size: clamp(22px, min(7vw, 4.4vh), 38px);
    margin-bottom: 6px;
    color: var(--primary);
    line-height: 1;
}

.mode-card h3 {
    font-size: clamp(12px, min(3.6vw, 2vh), 17px);
    letter-spacing: 2px;
    margin-bottom: 6px;
}

.mode-card p {
    font-size: clamp(10px, min(3vw, 1.6vh), 13px);
    color: var(--text-dim);
    line-height: 1.5;
}

.help-grid {
    display: flex;
    flex-direction: column;
    gap: var(--gap);
    margin-bottom: 8px;
    width: 100%;
}

.help-section h3 {
    font-size: clamp(12px, min(3.6vw, 2vh), 17px);
    letter-spacing: 3px;
    color: var(--primary);
    margin-bottom: 10px;
    padding-bottom: 6px;
    border-bottom: 1px solid var(--border-color);
}

.help-item {
    font-size: clamp(10px, min(3.1vw, 1.7vh), 14px);
    color: var(--text-dim);
    margin-bottom: 6px;
    padding-left: 6px;
}

.help-step {
    font-size: clamp(10px, min(3.1vw, 1.7vh), 14px);
    color: var(--text-dim);
    margin-bottom: 6px;
    padding-left: 6px;
}

.key {
    display: inline-block;
    padding: 2px 8px;
    background: rgba(0, 180, 255, 0.1);
    border: 1px solid rgba(0, 180, 255, 0.2);
    border-radius: 3px;
    color: var(--primary);
    font-size: clamp(9px, min(2.6vw, 1.4vh), 12px);
    font-weight: 600;
    letter-spacing: 1px;
    margin-right: 8px;
    min-width: 56px;
    text-align: center;
}

.wave-announce {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 50;
    text-align: center;
    pointer-events: none;
    width: 100%;
    padding: 0 12px;
}

.wave-text {
    font-size: clamp(24px, min(9vw, 7vh), 52px);
    font-weight: 900;
    letter-spacing: clamp(3px, 1.6vw, 8px);
    color: var(--primary);
    text-shadow: 0 0 40px rgba(0, 180, 255, 0.6);
    animation: waveIn 2s ease-out forwards;
}

.boss-announce {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 50;
    text-align: center;
    pointer-events: none;
    width: 100%;
    padding: 0 12px;
}

.boss-warn {
    font-size: clamp(12px, min(4vw, 2.2vh), 20px);
    letter-spacing: clamp(3px, 1.6vw, 8px);
    color: var(--danger);
    animation: bossFlash 0.5s ease infinite alternate;
}

.boss-announce-name {
    font-size: clamp(18px, min(7vw, 4.6vh), 38px);
    font-weight: 900;
    letter-spacing: clamp(2px, 1.2vw, 4px);
    color: var(--danger);
    text-shadow: 0 0 30px rgba(255, 50, 80, 0.6);
    animation: waveIn 2.5s ease-out forwards;
}

.toast {
    position: fixed;
    left: 50%;
    bottom: calc(16px + var(--safe-b));
    transform: translate(-50%, 12px);
    z-index: 300;
    max-width: min(90vw, 420px);
    padding: 10px 16px;
    background: rgba(10, 14, 30, 0.94);
    border: 1px solid var(--glass-border);
    border-radius: 8px;
    color: var(--text);
    font-size: clamp(10px, min(3.1vw, 1.7vh), 14px);
    letter-spacing: 1px;
    text-align: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease, transform 0.25s ease;
}

.toast.show {
    opacity: 1;
    transform: translate(-50%, 0);
}

@keyframes waveIn {
    0% { opacity: 0; transform: scale(0.5); }
    20% { opacity: 1; transform: scale(1.1); }
    80% { opacity: 1; transform: scale(1); }
    100% { opacity: 0; transform: scale(1); }
}

@keyframes bossFlash {
    0% { opacity: 0.6; }
    100% { opacity: 1; }
}
