@import url('https://fonts.googleapis.com/css2?family=Orbitron:wght@400;700;900&family=Rajdhani:wght@400;600&display=swap');

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

html,
body {
    overflow: hidden;
}

:root {
    --danger: #ff2d2d;
    --warning: #ffaa00;
    --safe: #00e5a0;
    --hud-bg: rgba(0, 0, 0, 0.55);
    --hud-border: rgba(255, 255, 255, 0.12);
    --glow-safe: 0 0 12px rgba(0, 229, 160, 0.7);
    --glow-danger: 0 0 12px rgba(255, 45, 45, 0.8);
    --glow-warn: 0 0 12px rgba(255, 170, 0, 0.7);
}

.webgl {
    position: fixed;
    top: 0;
    left: 0;
    outline: none;
    z-index: 1;
}

/* ── HUD WRAPPER ─────────────────────────────── */
#hud {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 10;
    pointer-events: none;
    user-select: none;
    padding: 18px 24px;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    gap: 16px;
}

/* ── TIMER BLOCK ─────────────────────────────── */
#timer-block {
    display: flex;
    flex-direction: column;
    align-items: center;
    background: var(--hud-bg);
    border: 1px solid var(--hud-border);
    backdrop-filter: blur(10px);
    border-radius: 8px;
    padding: 10px 28px;
    min-width: 160px;
    position: relative;
    overflow: hidden;
}

#timer-block::before {
    content: 'TIME';
    font-family: 'Rajdhani', sans-serif;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 3px;
    color: rgba(255, 255, 255, 0.45);
    display: block;
    margin-bottom: 2px;
}

#timer {
    font-family: 'Orbitron', monospace;
    font-size: 38px;
    font-weight: 900;
    color: var(--safe);
    text-shadow: var(--glow-safe);
    letter-spacing: 2px;
    line-height: 1;
    transition: color 0.3s, text-shadow 0.3s;
}

#timer.warn {
    color: var(--warning);
    text-shadow: var(--glow-warn);
    animation: pulse-warn 0.6s ease-in-out infinite alternate;
}

#timer.danger {
    color: var(--danger);
    text-shadow: var(--glow-danger);
    animation: pulse-danger 0.3s ease-in-out infinite alternate;
}

/* ── SPEED BLOCK ─────────────────────────────── */
#speed-block {
    display: flex;
    flex-direction: column;
    align-items: center;
    background: var(--hud-bg);
    border: 1px solid var(--hud-border);
    backdrop-filter: blur(10px);
    border-radius: 8px;
    padding: 10px 22px;
    min-width: 130px;
}

#speed-block::before {
    content: 'SPEED';
    font-family: 'Rajdhani', sans-serif;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 3px;
    color: rgba(255, 255, 255, 0.45);
    display: block;
    margin-bottom: 2px;
}

#speed-display {
    font-family: 'Orbitron', monospace;
    font-size: 30px;
    font-weight: 700;
    color: #ffffff;
    letter-spacing: 1px;
    line-height: 1;
}

#speed-bar-wrap {
    width: 100%;
    height: 4px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 2px;
    margin-top: 8px;
    overflow: hidden;
}

#speed-bar {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, var(--safe), #00c4ff);
    border-radius: 2px;
    transition: width 0.1s linear;
    box-shadow: 0 0 8px rgba(0, 196, 255, 0.6);
}

/* ── CONTROL HINT ─────────────────────────────── */
#hint {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 10;
    pointer-events: none;
    user-select: none;
    display: flex;
    align-items: center;
    gap: 12px;
    background: var(--hud-bg);
    border: 1px solid var(--hud-border);
    backdrop-filter: blur(10px);
    border-radius: 999px;
    padding: 8px 20px;
    animation: fade-in 1.5s ease 0.5s both;
}

.hint-key {
    font-family: 'Orbitron', monospace;
    font-size: 11px;
    font-weight: 700;
    color: #fff;
    background: rgba(255, 255, 255, 0.15);
    border: 1px solid rgba(255, 255, 255, 0.25);
    border-radius: 4px;
    padding: 3px 10px;
    letter-spacing: 1px;
    animation: tap-animation 0.5s infinite;
}

@keyframes tap-animation {

    0%,
    100% {
        transform: scale(1);
        background: rgba(255, 255, 255, 0.2);
    }

    50% {
        transform: scale(0.8);
        background: rgba(255, 255, 255, 0.5);
    }
}

.hint-label {
    font-family: 'Rajdhani', sans-serif;
    font-size: 13px;
    font-weight: 600;
    color: rgba(255, 255, 255, 0.6);
    letter-spacing: 1px;
}

/* ── MOBILE GAS BUTTON ───────────────────────────── */
#mobile-gas-btn {
    display: none; /* Hidden on desktop by default */
    position: fixed;
    bottom: 40px;
    right: 40px;
    z-index: 15;
    width: 100px;
    height: 100px;
    border-radius: 50%;
    background: rgba(0, 229, 160, 0.2);
    border: 2px solid rgba(0, 229, 160, 0.5);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;
    touch-action: manipulation;
    transition: transform 0.15s, background 0.15s, box-shadow 0.15s;
    box-shadow: var(--glow-safe);
}

#mobile-gas-btn .gas-icon {
    font-size: 28px;
    line-height: 1;
}

#mobile-gas-btn .gas-label {
    font-family: 'Orbitron', monospace;
    font-size: 11px;
    font-weight: 700;
    color: #fff;
    letter-spacing: 2px;
}

#mobile-gas-btn:active,
#mobile-gas-btn.pressed {
    transform: scale(0.9);
    background: rgba(0, 229, 160, 0.45);
    box-shadow: 0 0 24px rgba(0, 229, 160, 0.9);
}

/* Show on mobile / touch devices */
@media (max-width: 768px) {
    #mobile-gas-btn {
        display: flex;
    }

    #hint {
        display: none; /* Hide spacebar hint on mobile */
    }
}

/* Also show if device has coarse pointer (touch screen) */
@media (pointer: coarse) {
    #mobile-gas-btn {
        display: flex;
    }

    #hint {
        display: none;
    }
}

/* ── TRAIN WARNING OVERLAY ─────────────────────── */
#train-warning {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 9;
    pointer-events: none;
    user-select: none;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.3s;
}

#train-warning.active {
    opacity: 1;
}

#train-warning-inner {
    font-family: 'Orbitron', monospace;
    font-size: 22px;
    font-weight: 900;
    color: var(--danger);
    letter-spacing: 6px;
    text-shadow: var(--glow-danger);
    animation: flicker 0.25s step-start infinite;
    border: 2px solid var(--danger);
    padding: 12px 36px;
    background: rgba(255, 30, 30, 0.08);
    border-radius: 4px;
}

/* Red vignette border when crossing closed */
#vignette {
    position: fixed;
    inset: 0;
    z-index: 8;
    pointer-events: none;
    box-shadow: inset 0 0 0 0 rgba(255, 30, 30, 0);
    transition: box-shadow 0.5s ease;
}

#vignette.active {
    box-shadow: inset 0 0 80px 20px rgba(255, 30, 30, 0.35);
    animation: vignette-pulse 1s ease-in-out infinite alternate;
}

/* ── KEYFRAMES ─────────────────────────────────── */
@keyframes pulse-warn {
    from {
        opacity: 1;
    }

    to {
        opacity: 0.65;
    }
}

@keyframes pulse-danger {
    from {
        opacity: 1;
        transform: scale(1);
    }

    to {
        opacity: 0.7;
        transform: scale(0.97);
    }
}

@keyframes blink {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0;
    }
}

@keyframes flicker {
    0% {
        opacity: 1;
    }

    33% {
        opacity: 0.6;
    }

    66% {
        opacity: 0.9;
    }

    100% {
        opacity: 0.5;
    }
}

@keyframes vignette-pulse {
    from {
        box-shadow: inset 0 0 80px 20px rgba(255, 30, 30, 0.25);
    }

    to {
        box-shadow: inset 0 0 100px 30px rgba(255, 30, 30, 0.45);
    }
}

@keyframes fade-in {
    from {
        opacity: 0;
        transform: translateX(-50%) translateY(8px);
    }

    to {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }
}

/* ── GAME OVER PANEL ─────────────────────────────── */
#game-over-panel {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.5s ease;
}

#game-over-panel.show {
    opacity: 1;
    pointer-events: auto;
}

#game-over-panel .panel-content {
    background: rgba(0, 0, 0, 0.6);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 16px;
    padding: 40px 60px;
    text-align: center;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.6);
    transform: translateY(20px);
    transition: transform 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

#game-over-panel.show .panel-content {
    transform: translateY(0);
}

#game-over-panel h1 {
    font-family: 'Orbitron', monospace;
    font-size: 42px;
    color: var(--danger);
    text-shadow: var(--glow-danger);
    margin-bottom: 5px;
    letter-spacing: 4px;
}

#game-over-panel.win h1 {
    color: var(--safe);
    text-shadow: var(--glow-safe);
}

#game-over-panel h2 {
    font-family: 'Orbitron', monospace;
    font-size: 24px;
    color: #fff;
    margin-bottom: 20px;
    letter-spacing: 2px;
}

#game-over-panel .time-info {
    font-family: 'Rajdhani', sans-serif;
    font-size: 24px;
    color: #ccc;
    margin-bottom: 30px;
    letter-spacing: 1px;
}

#game-over-panel button {
    font-family: 'Orbitron', monospace;
    font-size: 18px;
    font-weight: 700;
    color: #fff;
    background: linear-gradient(90deg, var(--safe), #00c4ff);
    border: none;
    border-radius: 8px;
    padding: 12px 32px;
    cursor: pointer;
    box-shadow: var(--glow-safe);
    transition: transform 0.2s, box-shadow 0.2s;
    outline: none;
}

#game-over-panel button:hover {
    transform: scale(1.05);
    box-shadow: 0 0 20px rgba(0, 229, 160, 0.9);
}

#game-over-panel button:active {
    transform: scale(0.95);
}

/* ── CREDITS TOGGLE BUTTON ───────────────────────── */
#credits-toggle {
    position: fixed;
    bottom: 18px;
    left: 18px;
    z-index: 20;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--hud-bg);
    border: 1px solid var(--hud-border);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    color: rgba(255, 255, 255, 0.6);
    font-size: 16px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.3s, color 0.3s, transform 0.2s, box-shadow 0.3s;
    outline: none;
}

#credits-toggle:hover {
    background: rgba(0, 229, 160, 0.15);
    color: var(--safe);
    box-shadow: var(--glow-safe);
    transform: scale(1.1);
}

#credits-toggle.active {
    background: rgba(0, 229, 160, 0.2);
    color: var(--safe);
    box-shadow: var(--glow-safe);
}

/* ── CREDITS PANEL ───────────────────────────────── */
#credits-panel {
    position: fixed;
    bottom: 62px;
    left: 18px;
    z-index: 20;
    background: rgba(0, 0, 0, 0.7);
    border: 1px solid var(--hud-border);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    border-radius: 12px;
    padding: 16px 20px;
    max-width: 340px;
    opacity: 0;
    pointer-events: none;
    transform: translateY(10px) scale(0.95);
    transition: opacity 0.35s ease, transform 0.35s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

#credits-panel.show {
    opacity: 1;
    pointer-events: auto;
    transform: translateY(0) scale(1);
}

.credits-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 12px;
    padding-bottom: 8px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.credits-icon {
    font-size: 16px;
}

.credits-title {
    font-family: 'Orbitron', monospace;
    font-size: 11px;
    font-weight: 700;
    color: var(--safe);
    letter-spacing: 2px;
    text-transform: uppercase;
}

.credits-list {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.credits-list li {
    font-family: 'Rajdhani', sans-serif;
    font-size: 12px;
    color: rgba(255, 255, 255, 0.55);
    line-height: 1.4;
    display: flex;
    align-items: baseline;
    gap: 8px;
}

.credit-type {
    font-family: 'Orbitron', monospace;
    font-size: 8px;
    font-weight: 700;
    color: #fff;
    background: rgba(0, 229, 160, 0.2);
    border: 1px solid rgba(0, 229, 160, 0.3);
    border-radius: 3px;
    padding: 2px 6px;
    letter-spacing: 1px;
    flex-shrink: 0;
    line-height: 1;
}

.credits-list li a {
    color: rgba(0, 229, 160, 0.8);
    text-decoration: none;
    transition: color 0.2s;
}

.credits-list li a:hover {
    color: var(--safe);
    text-decoration: underline;
}