:root {
    --bg-primary: #0b0d14;
    --bg-panel: rgba(11, 13, 20, 0.75);
    --accent-primary: #00f3ff; /* Cyan */
    --accent-secondary: #bc13fe; /* Purple */
    --accent-warning: #ffb800; /* Amber */
    --accent-danger: #ff2a2a; /* Red */
    --accent-success: #00ff9d; /* Green */
    --text-primary: #ffffff;
    --text-dim: rgba(255, 255, 255, 0.6);
    --hud-border: 1px solid rgba(0, 243, 255, 0.3);
    --hud-glow: 0 0 10px rgba(0, 243, 255, 0.2);
    --clip-corner: polygon(
        12px 0, 100% 0, 
        100% calc(100% - 12px), calc(100% - 12px) 100%, 
        0 100%, 0 12px
    );
    --accent-scrap: #bc13fe;
    --accent-supply: #00ff9d;
    --accent-valuable: #00f3ff;
    --accent-power: #ffb800;
    --accent-weapon: #ff2a2a;
}

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

body {
    font-family: 'Orbitron', sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    overflow: hidden;
    touch-action: none;
}

#loading-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: var(--bg-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    transition: opacity 0.5s ease;
}

#loading-screen.fade-out {
    opacity: 0;
}

.loading-content {
    text-align: center;
    color: var(--accent-primary);
}

.loading-content h1 {
    font-size: 2.5rem;
    margin-bottom: 1rem;
    text-shadow: 0 0 20px var(--accent-primary);
}

.loading-highscores {
    margin-top: 16px;
    max-width: 260px;
    margin-left: auto;
    margin-right: auto;
    text-align: left;
    font-family: 'Share Tech Mono', monospace;
    color: var(--text-primary);
}

.spinner {
    width: 60px;
    height: 60px;
    border: 4px solid rgba(0, 243, 255, 0.2);
    border-top: 4px solid var(--accent-primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 1rem;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

#game-canvas {
    position: fixed;
    inset: 0;
    width: 100vw;
    height: 100vh;
    z-index: 1;
}

#energy-canvas {
    position: fixed;
    inset: 0;
    width: 100vw;
    height: 100vh;
    z-index: 2;
    pointer-events: none;
    opacity: 0.4;
}

.damage-flash {
    position: fixed;
    inset: 0;
    background: radial-gradient(circle, transparent 50%, rgba(255, 0, 0, 0.4) 100%);
    opacity: 0;
    pointer-events: none;
    z-index: 99;
    transition: opacity 0.1s ease;
    mix-blend-mode: overlay;
}

.damage-flash.active {
    opacity: 1;
    animation: flashShake 0.3s cubic-bezier(.36,.07,.19,.97) both;
}

@keyframes flashShake {
    0% { transform: translate(0, 0); opacity: 1; }
    20% { transform: translate(-5px, 5px); }
    40% { transform: translate(5px, -5px); }
    60% { transform: translate(-5px, 5px); }
    80% { transform: translate(5px, -5px); }
    100% { transform: translate(0, 0); opacity: 0; }
}

.ui-overlay {
    position: fixed;
    inset: 0;
    z-index: 10;
    pointer-events: none;
    padding: 24px;
}

.ui-overlay > * {
    pointer-events: auto;
}

/* HUD Top Right Cluster */
.hud-top-right {
    position: absolute;
    top: 24px;
    right: 24px;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 8px;
    z-index: 10;
}

.scoreboard {
    position: relative;
    top: auto;
    right: auto;
    padding: 12px 24px;
    background: var(--bg-panel);
    border: var(--hud-border);
    box-shadow: var(--hud-glow);
    clip-path: var(--clip-corner);
    backdrop-filter: blur(8px);
    font-family: 'Share Tech Mono', monospace;
    font-size: 1.2rem;
    letter-spacing: 2px;
    text-transform: uppercase;
    display: flex;
    align-items: center;
    gap: 16px;
}

.scoreboard span {
    color: var(--accent-warning);
    font-weight: bold;
    font-family: 'Orbitron', sans-serif;
}

.combo-display {
    position: relative;
    top: auto;
    right: auto;
    padding: 4px 12px;
    background: linear-gradient(90deg, var(--accent-secondary), transparent);
    border-left: 4px solid var(--text-primary);
    font-size: 1rem;
    font-weight: 900;
    letter-spacing: 1px;
    opacity: 0;
    transform: translateX(20px);
    transition: all 0.3s ease-out;
    text-shadow: 0 0 8px var(--accent-secondary);
}

.combo-display.active {
    opacity: 1;
    transform: translateX(0);
}

.time-indicator {
    position: relative;
    top: auto;
    right: auto;
    padding: 8px 16px;
    background: var(--bg-panel);
    border: var(--hud-border);
    clip-path: polygon(0 0, 100% 0, 100% 100%, 10px 100%);
    font-family: 'Share Tech Mono', monospace;
    color: var(--text-dim);
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    gap: 8px;
}

.time-icon {
    color: var(--accent-warning);
}

/* Minimap - Top Left */
.minimap {
    position: absolute;
    top: 24px;
    left: 24px;
    width: 180px;
    height: 180px;
    border-radius: 50%;
    border: 2px solid rgba(255, 255, 255, 0.1);
    background: rgba(0, 0, 0, 0.8);
    overflow: hidden;
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.5);
}

.minimap::after {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: 50%;
    border: 2px solid var(--accent-primary);
    box-shadow: inset 0 0 20px rgba(0, 243, 255, 0.2);
    pointer-events: none;
}

.minimap::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 0;
    right: 0;
    height: 1px;
    background: rgba(0, 243, 255, 0.3);
    z-index: 5;
}

#minimap-canvas {
    width: 100%;
    height: 100%;
    opacity: 0.8;
}

/* Bottom Center Status Cluster */
.hud-bottom-center {
    position: absolute;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    width: 100%;
    pointer-events: none;
}

.status-bar-container {
    display: flex;
    align-items: center;
    gap: 16px;
    pointer-events: auto;
}

.health-bar {
    position: relative;
    top: auto;
    right: auto;
    width: 300px;
    height: 16px;
    background: rgba(0, 0, 0, 0.8);
    border: 1px solid rgba(255, 255, 255, 0.2);
    transform: skewX(-20deg);
    padding: 2px;
}

.health-fill {
    height: 100%;
    background: linear-gradient(90deg, #ff2a2a, #ff0000);
    box-shadow: 0 0 10px rgba(255, 42, 42, 0.5);
    transition: width 0.2s ease;
}

.boost-bar-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    margin-bottom: 8px;
    transition: opacity 0.3s ease;
    width: 300px;
    opacity: 0;
}

.boost-label {
    font-family: 'Share Tech Mono', monospace;
    color: var(--accent-power);
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 2px;
    text-shadow: 0 0 5px var(--accent-power);
}

.boost-bar {
    width: 100%;
    height: 4px;
    background: rgba(0, 0, 0, 0.6);
    border: 1px solid rgba(255, 184, 0, 0.3);
    transform: skewX(-20deg);
}

.boost-fill {
    height: 100%;
    background: var(--accent-power);
    box-shadow: 0 0 8px var(--accent-power);
    width: 100%;
    transition: width 0.1s linear;
}

.ammo-display {
    position: relative;
    bottom: auto;
    right: auto;
    display: flex;
    align-items: center;
    gap: 8px;
    font-family: 'Orbitron', sans-serif;
    font-size: 1.2rem;
    font-weight: bold;
    color: var(--accent-primary);
    text-shadow: 0 0 8px var(--accent-primary);
}

.ammo-display .low-ammo {
    animation: pulseAmmo 0.5s infinite alternate;
}

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

.ammo-icon {
    font-size: 0.8rem;
    color: var(--text-dim);
}

/* Inventory Strip */
.inventory {
    position: relative;
    bottom: auto;
    left: auto;
    transform: none;
    display: flex;
    gap: 6px;
    padding: 8px;
    background: var(--bg-panel);
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    clip-path: polygon(20px 0, 100% 0, 100% 100%, 0 100%, 0 20px);
    pointer-events: auto;
}

.inventory-slot {
    width: 50px;
    height: 50px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.1);
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    transition: all 0.2s ease;
}

.inventory-slot:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: var(--accent-primary);
    transform: translateY(-2px);
}

.inventory-slot[data-group="scrap"] { border-bottom: 2px solid var(--accent-scrap); }
.inventory-slot[data-group="supply"] { border-bottom: 2px solid var(--accent-supply); }
.inventory-slot[data-group="valuable"] { border-bottom: 2px solid var(--accent-valuable); }
.inventory-slot[data-group="power"] { border-bottom: 2px solid var(--accent-power); }
.inventory-slot[data-group="weapon"] { border-bottom: 2px solid var(--accent-weapon); }

.inventory-slot-icon {
    font-family: "Font Awesome 6 Free";
    font-weight: 900;
    font-size: 1.2rem;
    color: var(--text-primary);
}

.inventory-slot-count {
    position: absolute;
    top: 2px;
    right: 2px;
    font-family: 'Share Tech Mono', monospace;
    font-size: 0.7rem;
    color: var(--accent-primary);
}

/* Quests */
.quest-panel {
    position: absolute;
    top: 240px;
    left: 24px;
    right: auto;
    width: 240px;
    background: linear-gradient(90deg, rgba(6, 9, 20, 0.9), transparent);
    border-left: 2px solid var(--accent-warning);
    padding: 12px 16px;
    font-family: 'Share Tech Mono', monospace;
}

.quest-title {
    color: var(--accent-warning);
    text-transform: uppercase;
    font-size: 0.9rem;
    margin-bottom: 4px;
}

.quest-progress {
    height: 4px;
    background: rgba(255, 255, 255, 0.1);
    margin-top: 8px;
}

.quest-progress-fill {
    background: var(--accent-warning);
    box-shadow: 0 0 8px var(--accent-warning);
}

/* Notifications & Messages */
.notification {
    position: absolute;
    top: 100px;
    left: 50%;
    transform: translateX(-50%);
    font-family: 'Orbitron', sans-serif;
    background: rgba(0, 0, 0, 0.8);
    border: 1px solid var(--accent-primary);
    color: var(--accent-primary);
    box-shadow: 0 0 20px rgba(0, 243, 255, 0.2);
    text-transform: uppercase;
    letter-spacing: 2px;
    padding: 12px 24px;
    border-radius: 4px;
    z-index: 100;
    opacity: 0;
    transition: opacity 0.3s ease;
    pointer-events: none;
}

.notification.show {
    opacity: 1;
}

.wave-indicator {
    position: absolute;
    top: 24px;
    left: 50%;
    transform: translateX(-50%);
    font-family: 'Orbitron', sans-serif;
    font-size: 1.8rem;
    color: var(--accent-danger);
    background: transparent;
    text-shadow: 0 0 20px var(--accent-danger);
    font-style: italic;
    text-transform: uppercase;
    letter-spacing: 4px;
    opacity: 0;
    transition: opacity 0.5s ease;
    pointer-events: none;
    z-index: 60;
}

.wave-indicator.show {
    opacity: 1;
}

.power-up-indicator {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translateX(-50%) translateY(-50%);
    font-family: 'Orbitron', sans-serif;
    font-size: 1.5rem;
    color: var(--accent-success);
    text-shadow: 0 0 20px var(--accent-success);
    text-transform: uppercase;
    letter-spacing: 2px;
    opacity: 0;
    transition: opacity 0.3s ease;
    pointer-events: none;
    z-index: 50;
}

.speaker-toggle {
    padding: 0;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--bg-panel);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: var(--text-dim);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s ease;
}

.speaker-toggle:hover {
    border-color: var(--accent-primary);
    color: var(--accent-primary);
    box-shadow: 0 0 10px rgba(0, 243, 255, 0.4);
}

.speaker-toggle.muted {
    color: var(--accent-danger);
    border-color: var(--accent-danger);
    box-shadow: 0 0 10px rgba(255, 42, 42, 0.4);
}

.speaker-toggle i {
    pointer-events: none;
}

.instructions-toggle {
    position: absolute;
    bottom: 24px;
    right: 24px; 
    left: auto;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--bg-panel);
    border: 1px solid rgba(255, 255, 255, 0.2);
    font-family: 'Share Tech Mono', monospace;
    color: var(--accent-primary);
    font-size: 1.2rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    z-index: 100; /* Ensure above everything */
}

.instructions-panel {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) translateX(200%);
    width: 600px;
    background: var(--bg-panel);
    border: var(--hud-border);
    box-shadow: var(--hud-glow);
    clip-path: var(--clip-corner);
    backdrop-filter: blur(12px);
    padding: 20px;
    transition: transform 0.3s cubic-bezier(0.4, 0.0, 0.2, 1);
    z-index: 90;
}

.instructions-panel.open {
    transform: translate(-50%, -50%);
}

.controls-panel {
    bottom: 140px; /* Moved up slightly */
}

.control-btn {
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    background: rgba(0, 0, 0, 0.6);
    clip-path: polygon(10px 0, 100% 0, 100% calc(100% - 10px), calc(100% - 10px) 100%, 0 100%, 0 10px);
}

.control-btn:active {
    border-color: var(--accent-primary);
    box-shadow: 0 0 15px var(--accent-primary);
}

.highscore-panel {
    padding: 8px 12px;
    background: var(--bg-panel);
    border: var(--hud-border);
    box-shadow: var(--hud-glow);
    clip-path: var(--clip-corner);
    backdrop-filter: blur(8px);
    font-family: 'Share Tech Mono', monospace;
    font-size: 0.8rem;
    min-width: 200px;
}

.highscore-panel-title {
    color: var(--accent-secondary);
    text-transform: uppercase;
    letter-spacing: 2px;
    margin-bottom: 4px;
}

.highscore-list,
.highscore-list-live {
    list-style: none;
    margin: 0;
    padding: 0;
    font-family: 'Share Tech Mono', monospace;
    font-size: 0.8rem;
}

.highscore-list li,
.highscore-list-live li {
    display: flex;
    justify-content: space-between;
    gap: 8px;
    padding: 2px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.highscore-list li:last-child,
.highscore-list-live li:last-child {
    border-bottom: none;
}

.game-over-overlay {
    position: fixed;
    inset: 0;
    background:
        radial-gradient(circle at 50% 20%, rgba(0, 243, 255, 0.12), transparent 60%),
        rgba(0, 0, 0, 0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.game-over-overlay.visible {
    opacity: 1;
    pointer-events: auto;
}

.game-over-panel {
    width: 420px;
    background: var(--bg-panel);
    border: var(--hud-border);
    box-shadow: 0 0 40px rgba(0, 243, 255, 0.35);
    clip-path: var(--clip-corner);
    backdrop-filter: blur(12px);
    padding: 24px;
    text-align: center;
}

.game-over-title {
    font-size: 1.6rem;
    letter-spacing: 4px;
    color: var(--accent-danger);
    margin-bottom: 8px;
    text-shadow: 0 0 20px var(--accent-danger);
}

.final-score {
    font-family: 'Share Tech Mono', monospace;
    font-size: 1rem;
    margin-bottom: 16px;
    color: var(--accent-warning);
}

.highscore-form {
    margin-top: 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    text-align: left;
}

.highscore-form label {
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-dim);
}

.highscore-form input[type="text"] {
    background: rgba(0, 0, 0, 0.7);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: var(--text-primary);
    padding: 6px 8px;
    font-family: 'Share Tech Mono', monospace;
    font-size: 0.9rem;
}

.highscore-buttons {
    margin-top: 16px;
    display: flex;
    justify-content: center;
    gap: 12px;
}

.highscore-btn {
    padding: 6px 16px;
    border-radius: 999px;
    border: 1px solid var(--accent-primary);
    background: transparent;
    color: var(--accent-primary);
    font-family: 'Share Tech Mono', monospace;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.highscore-btn.primary {
    border-color: var(--accent-success);
    color: var(--accent-success);
}

.highscore-btn:hover {
    background: rgba(0, 243, 255, 0.12);
    box-shadow: 0 0 15px rgba(0, 243, 255, 0.35);
}

.highscore-error {
    margin-top: 4px;
    min-height: 18px;
    font-size: 0.75rem;
    color: var(--accent-danger);
}
