:root {
    --mars-red: #ff4d00;
    --mars-dark: #1a0a05;
    --neon-blue: #00f2ff;
    --hud-bg: rgba(26, 10, 5, 0.85);
    --font-mono: 'Courier New', Courier, monospace;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

body {
    background: var(--mars-dark);
    color: var(--mars-red);
    font-family: var(--font-mono);
    overflow: hidden;
    height: 100vh;
    width: 100vw;
    text-transform: uppercase;
}

/* CRT & Starfield Effects */
#crt-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(rgba(18, 16, 16, 0) 50%, rgba(0, 0, 0, 0.25) 50%), linear-gradient(90deg, rgba(255, 0, 0, 0.06), rgba(0, 255, 0, 0.02), rgba(0, 0, 255, 0.06));
    background-size: 100% 2px, 3px 100%;
    pointer-events: none;
    z-index: 999;
}

#stars {
    position: fixed;
    width: 100%;
    height: 100%;
    z-index: 0;
    pointer-events: none;
}

/* Slim Persistent Header */
.hud-header {
    position: fixed;
    top: 0;
    width: 100%;
    z-index: 1000;
    padding: 10px 20px;
    height: 50px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid rgba(255, 77, 0, 0.3);
    background: rgba(26, 10, 5, 0.95);
    backdrop-filter: blur(10px);
}

.status-panel {
    display: flex;
    align-items: center;
    gap: 8px;
}

.status-led {
    width: 8px;
    height: 8px;
    background-color: #00ff00;
    border-radius: 50%;
    box-shadow: 0 0 8px #00ff00;
    animation: led-pulse 1.5s infinite;
}

@keyframes led-pulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.3; transform: scale(0.8); }
}

.glitch {
    position: relative;
    color: var(--mars-red);
    font-size: 0.7rem;
}

.glitch::before, .glitch::after {
    content: attr(data-text);
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
}

.glitch::before {
    left: 2px;
    text-shadow: -2px 0 var(--neon-blue);
    clip: rect(44px, 450px, 56px, 0);
    animation: glitch-anim 5s infinite linear alternate-reverse;
}

.glitch::after {
    left: -2px;
    text-shadow: -2px 0 #fff;
    clip: rect(44px, 450px, 56px, 0);
    animation: glitch-anim2 5s infinite linear alternate-reverse;
}

@keyframes glitch-anim {
    0% { clip: rect(31px, 9999px, 94px, 0); }
    20% { clip: rect(62px, 9999px, 42px, 0); }
    40% { clip: rect(16px, 9999px, 78px, 0); }
    60% { clip: rect(87px, 9999px, 12px, 0); }
    80% { clip: rect(53px, 9999px, 66px, 0); }
    100% { clip: rect(24px, 9999px, 85px, 0); }
}

@keyframes glitch-anim2 {
    0% { clip: rect(65px, 9999px, 100px, 0); }
    20% { clip: rect(2px, 9999px, 48px, 0); }
    40% { clip: rect(75px, 9999px, 15px, 0); }
    60% { clip: rect(33px, 9999px, 72px, 0); }
    80% { clip: rect(89px, 9999px, 5px, 0); }
    100% { clip: rect(12px, 9999px, 90px, 0); }
}

.scanline {
    width: 100%;
    height: 100px;
    z-index: 1000;
    background: linear-gradient(0deg, rgba(0, 0, 0, 0) 0%, rgba(255, 77, 0, 0.1) 50%, rgba(0, 0, 0, 0) 100%);
    opacity: 0.1;
    position: absolute;
    bottom: 100%;
    animation: scanline 8s linear infinite;
    pointer-events: none;
}

@keyframes scanline {
    0% { bottom: 100%; }
    100% { bottom: -100px; }
}

/* Hero Section */
#hero {
    height: 100vh;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
    padding: 60px 20px 60px 20px;
    transition: transform 0.8s ease-in-out;
    overflow-y: auto;
}

h1 {
    font-size: clamp(1.5rem, 7vw, 4rem);
    margin-bottom: 10px;
    letter-spacing: clamp(2px, 1.5vw, 10px);
    width: 100%;
    overflow-wrap: break-word;
}

.typewriter {
    font-size: clamp(0.65rem, 2vw, 0.9rem);
    margin-bottom: 20px;
    color: var(--neon-blue);
    min-height: 1.2em;
    max-width: 90%;
}

.briefing {
    background: rgba(255, 77, 0, 0.05);
    border: 1px solid rgba(255, 77, 0, 0.3);
    padding: clamp(15px, 5vw, 30px);
    margin: 10px auto 20px auto;
    width: 100%;
    max-width: 500px;
    text-align: center;
    font-size: clamp(0.65rem, 2.5vw, 0.85rem);
    backdrop-filter: blur(5px);
}

.briefing h3 {
    color: var(--neon-blue);
    margin-bottom: 10px;
    font-size: clamp(0.9rem, 3vw, 1.1rem);
    letter-spacing: 2px;
}

.briefing ul {
    list-style: none;
    padding: 0;
}

.briefing li {
    margin-bottom: 8px;
    line-height: 1.4;
    border-bottom: 1px solid rgba(255, 77, 0, 0.1);
    padding-bottom: 8px;
}

.briefing li:last-child {
    border-bottom: none;
}

.highlight {
    color: var(--neon-blue);
    font-weight: bold;
}

.main-actions {
    display: flex;
    flex-direction: column;
    gap: 15px;
    width: 100%;
    max-width: 300px;
    margin: 0 auto;
    align-items: center;
}

.btn-primary {
    background: transparent;
    color: var(--neon-blue);
    border: 1px solid var(--neon-blue);
}

.btn-primary:hover {
    background: var(--neon-blue);
    color: var(--mars-dark);
    box-shadow: 0 0 20px var(--neon-blue);
}

.btn-secondary {
    background: transparent;
    color: var(--mars-red);
    border: 1px solid var(--mars-red);
}

.btn-secondary:hover {
    background: var(--mars-red);
    color: var(--mars-dark);
    box-shadow: 0 0 20px var(--mars-red);
}

.btn-primary, .btn-secondary {
    padding: 15px 20px;
    font-family: inherit;
    font-size: 0.9rem;
    cursor: pointer;
    position: relative;
    overflow: hidden;
    transition: 0.3s;
    width: 100%;
}

.mars-horizon {
    position: absolute;
    bottom: 0;
    width: 100%;
    height: 30vh;
    background: radial-gradient(circle at 50% 100%, #ff4d00 0%, #1a0a05 70%);
    opacity: 0.4;
    z-index: -1;
}

/* Game Styles */
#game-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: #050201;
    z-index: 200;
}

#game-canvas {
    width: 100%;
    height: 100%;
    display: block;
}

.game-hud {
    position: absolute;
    top: 60px;
    left: 15px;
    color: var(--neon-blue);
    font-size: clamp(0.65rem, 2vw, 0.8rem);
    z-index: 210;
    display: flex;
    flex-direction: column;
    gap: 6px;
    pointer-events: none;
}

.fuel-container {
    display: flex;
    align-items: center;
    gap: 8px;
}

.fuel-bar-outer {
    width: clamp(80px, 20vw, 120px);
    height: 10px;
    border: 1px solid var(--neon-blue);
    padding: 1px;
    background: rgba(0, 242, 255, 0.1);
}

#fuel-bar-inner {
    height: 100%;
    width: 100%;
    background: var(--neon-blue);
    transition: width 0.1s linear, background-color 0.3s ease;
    box-shadow: 0 0 10px var(--neon-blue);
}

.low-fuel {
    animation: critical-pulse 0.5s infinite alternate;
}

@keyframes critical-pulse {
    from { opacity: 1; filter: brightness(1); }
    to { opacity: 0.5; filter: brightness(1.5); }
}

.warning-fuel {
    background-color: #ffea00 !important;
    box-shadow: 0 0 10px #ffea00 !important;
}

.status-line {
    margin-top: 5px;
    font-weight: bold;
}

.status-ok { color: #00ff00; text-shadow: 0 0 10px #00ff00; }
.status-warn { color: #ff4d00; text-shadow: 0 0 10px #ff4d00; }

.stat-error { color: #ff4d00; }
.stat-ok { color: #00ff00; }

#game-overlay {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    background: var(--hud-bg);
    padding: clamp(20px, 5vw, 40px);
    border: 1px solid var(--mars-red);
    z-index: 220;
    width: 90%;
    max-width: 400px;
}

#game-submsg {
    color: var(--neon-blue);
    font-size: 0.85rem;
    margin: 15px 0 25px 0;
    line-height: 1.5;
    border-top: 1px solid rgba(0, 242, 255, 0.2);
    padding-top: 15px;
}

.rating-perfect { color: #00ff00; font-weight: bold; text-shadow: 0 0 10px #00ff00; }
.rating-good { color: var(--neon-blue); }
.rating-rough { color: #ffea00; }

.hidden { display: none !important; }

.controls-hint {
    position: absolute;
    bottom: 60px;
    width: 100%;
    text-align: center;
    font-size: 0.65rem;
    opacity: 0.6;
    animation: blink 2s infinite;
    pointer-events: none;
    transition: all 0.5s cubic-bezier(0.4, 0, 0.2, 1);
    color: var(--neon-blue);
    text-shadow: 0 0 10px rgba(0, 242, 255, 0.5);
    z-index: 215;
}

.controls-hint.pre-launch {
    bottom: 50%;
    transform: translateY(50%);
    font-size: 1.2rem;
    opacity: 1;
    letter-spacing: 4px;
}

@keyframes blink {
    0%, 100% { opacity: 0.2; }
    50% { opacity: 0.8; }
}

/* Persistent Footer */
.persistent-footer {
    position: fixed;
    bottom: 0;
    width: 100%;
    height: 45px;
    padding: 0 15px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: rgba(26, 10, 5, 0.95);
    border-top: 1px solid rgba(255, 77, 0, 0.1);
    z-index: 1000;
}

.credit-link {
    color: var(--mars-red);
    text-decoration: none;
    font-size: 0.6rem;
    letter-spacing: 1px;
    opacity: 0.7;
    transition: 0.3s;
}

.credit-link:hover {
    opacity: 1;
    text-shadow: 0 0 5px var(--mars-red);
}

.footer-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

.footer-btn {
    background: transparent;
    border: 1px solid rgba(255, 77, 0, 0.4);
    color: var(--mars-red);
    font-family: inherit;
    font-size: 0.55rem;
    padding: 4px 6px;
    cursor: pointer;
    letter-spacing: 1px;
    transition: 0.3s;
}

.info-btn {
    background: transparent;
    border: 1px solid var(--neon-blue);
    color: var(--neon-blue);
    width: 22px;
    height: 22px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 0.7rem;
    display: flex;
    justify-content: center;
    align-items: center;
}

/* Legal Modal */
.modal {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0, 0, 0, 0.95);
    z-index: 2000;
    display: flex;
    justify-content: center;
    align-items: center;
}

.modal-content {
    background: var(--mars-dark);
    border: 1px solid var(--mars-red);
    padding: 30px;
    max-width: 500px;
    width: 90%;
    position: relative;
    max-height: 80vh;
    overflow-y: auto;
}

/* Leaderboard Screen */
#leaderboard-screen {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: var(--mars-dark);
    z-index: 1500;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 60px 15px;
}

.leaderboard-container {
    width: 100%;
    max-width: 900px;
    background: rgba(26, 10, 5, 0.95);
    border: 1px solid var(--mars-red);
    padding: 40px 20px;
    position: relative;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 0 30px rgba(255, 77, 0, 0.2);
}

.close-leaderboard {
    position: absolute;
    top: 15px;
    right: 15px;
    background: rgba(255, 77, 0, 0.1);
    border: 1px solid var(--mars-red);
    color: var(--mars-red);
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 1.5rem;
    cursor: pointer;
    transition: 0.3s;
    line-height: 1;
    z-index: 100;
}

.close-leaderboard:hover {
    background: var(--mars-red);
    color: var(--mars-dark);
    box-shadow: 0 0 15px var(--mars-red);
}

.boards-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 50px;
    margin-top: 20px;
}

.board h3 {
    color: var(--neon-blue);
    font-size: 0.9rem;
    margin-bottom: 15px;
    border-bottom: 1px solid rgba(0, 242, 255, 0.3);
    padding-bottom: 8px;
    text-align: center;
}

.board ul {
    list-style: none !important;
    padding: 0 !important;
    margin: 0;
}

.board li {
    display: flex;
    justify-content: space-between;
    padding: 10px 0;
    border-bottom: 1px solid rgba(255, 77, 0, 0.1);
    font-size: 0.8rem;
}

/* High Score Modal */
.high-score-content {
    border-color: var(--neon-blue);
    text-align: center;
    padding: 40px 20px;
}

#qualifying-list {
    margin: 15px 0;
    line-height: 1.4;
}

.input-container {
    margin: 30px auto;
    display: flex;
    justify-content: center;
    width: 100%;
}

#player-initials {
    background: transparent;
    border: 2px solid var(--neon-blue);
    color: var(--neon-blue);
    font-family: inherit;
    font-size: clamp(1.8rem, 10vw, 2.5rem);
    text-align: center;
    width: 140px;
    padding: 12px;
    text-transform: uppercase;
    letter-spacing: 5px;
    outline: none;
    box-shadow: 0 0 15px rgba(0, 242, 255, 0.1);
}

#player-initials:focus {
    border-color: #fff;
    box-shadow: 0 0 20px rgba(0, 242, 255, 0.3);
}

/* Desktop Styles */
@media (min-width: 601px) {
    .main-actions { flex-direction: row; max-width: 500px; }
    .btn-primary, .btn-secondary { width: auto; flex: 1; }
    .logo { font-size: 1.5rem; }
    .glitch { font-size: 0.8rem; }
}
