/* ═══════════════════════════════════════
   Gate Runner 3D — UI Stylesheet
   ═══════════════════════════════════════ */

:root {
    --c-bg:       #06060f;
    --c-card:     rgba(12, 10, 32, 0.88);
    --c-border:   rgba(139, 92, 246, 0.18);
    --c-purple:   #8b5cf6;
    --c-cyan:     #00e5ff;
    --c-pink:     #ff6ec7;
    --c-gold:     #ffd700;
    --c-red:      #ff4757;
    --c-green:    #22c55e;
    --safe-top:   env(safe-area-inset-top, 0px);
    --safe-bot:   env(safe-area-inset-bottom, 0px);
    --font-game:  'Orbitron', 'Segoe UI', system-ui, sans-serif;
    --font-ui:    'Inter', 'Segoe UI', system-ui, sans-serif;
}

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

html, body {
    height: 100%;
    min-height: 100dvh;
    background: var(--c-bg);
    overflow: hidden;
    font-family: var(--font-ui);
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
    color: #fff;
}

canvas {
    display: block;
    position: fixed;
    inset: 0;
    width: 100% !important;
    height: 100% !important;
}

/* ──── IN-GAME HUD ──── */
#ui-overlay {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 10;
}

#score-display {
    position: absolute;
    top: calc(var(--safe-top) + 10px);
    left: 50%;
    transform: translateX(-50%);
    font-family: var(--font-game);
    font-size: 34px;
    font-weight: 900;
    color: #fff;
    text-shadow: 0 0 24px rgba(139,92,246,0.7), 0 2px 8px rgba(0,0,0,0.6);
    letter-spacing: 2px;
    opacity: 0;
    transition: opacity .4s;
}

#multiplier-display {
    position: absolute;
    top: calc(var(--safe-top) + 50px);
    left: 50%;
    transform: translateX(-50%);
    font-family: var(--font-game);
    color: var(--c-gold);
    font-size: 16px;
    font-weight: 700;
    text-shadow: 0 0 14px rgba(255,215,0,0.5);
    opacity: 0;
    transition: opacity .4s;
}

#level-display {
    position: absolute;
    top: calc(var(--safe-top) + 14px);
    right: 16px;
    font-family: var(--font-game);
    color: var(--c-cyan);
    font-size: 11px;
    font-weight: 700;
    text-shadow: 0 0 10px rgba(0,229,255,0.5);
    letter-spacing: 1px;
    opacity: 0;
    transition: opacity .4s;
}

.visible { opacity: 1 !important; }

/* ──── DISTANCE BAR ──── */
#distance-bar {
    position: absolute;
    bottom: calc(var(--safe-bot) + 14px);
    left: 50%;
    transform: translateX(-50%);
    width: 140px;
    height: 3px;
    background: rgba(255,255,255,0.06);
    border-radius: 2px;
    overflow: hidden;
    opacity: 0;
    transition: opacity .4s;
}

#distance-fill {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, var(--c-purple), var(--c-cyan));
    border-radius: 2px;
    transition: width .3s;
}

/* ══════════════════════════════════════
   START SCREEN
   ══════════════════════════════════════ */
#start-screen {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: radial-gradient(ellipse at 50% 25%, #160a38 0%, #0a0a22 55%, var(--c-bg) 100%);
    z-index: 100;
    pointer-events: all;
    transition: opacity .7s, transform .7s;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: calc(var(--safe-top) + 16px) 16px calc(var(--safe-bot) + 16px);
}

#start-screen.hidden {
    opacity: 0;
    transform: scale(1.08);
    pointer-events: none;
}

/* Animated stars */
.bg-stars {
    position: fixed;
    inset: 0;
    background-image:
        radial-gradient(1px 1px at 10% 20%, rgba(255,255,255,0.5) 50%, transparent 100%),
        radial-gradient(1px 1px at 30% 65%, rgba(255,255,255,0.35) 50%, transparent 100%),
        radial-gradient(1px 1px at 55% 10%, rgba(255,255,255,0.4) 50%, transparent 100%),
        radial-gradient(1px 1px at 70% 40%, rgba(255,255,255,0.3) 50%, transparent 100%),
        radial-gradient(1px 1px at 85% 75%, rgba(255,255,255,0.45) 50%, transparent 100%),
        radial-gradient(1px 1px at 45% 85%, rgba(255,255,255,0.25) 50%, transparent 100%),
        radial-gradient(1.5px 1.5px at 20% 50%, rgba(139,92,246,0.4) 50%, transparent 100%),
        radial-gradient(1.5px 1.5px at 80% 20%, rgba(0,229,255,0.3) 50%, transparent 100%);
    animation: starsDrift 25s linear infinite;
    pointer-events: none;
}

@keyframes starsDrift {
    0%   { transform: translateY(0); }
    100% { transform: translateY(-30px); }
}

/* Glow orbs */
.bg-glow {
    position: fixed;
    border-radius: 50%;
    filter: blur(80px);
    pointer-events: none;
    opacity: 0.3;
}
.bg-glow--1 {
    width: 300px; height: 300px;
    background: var(--c-purple);
    top: -80px; left: -60px;
    animation: glowFloat1 8s ease-in-out infinite;
}
.bg-glow--2 {
    width: 250px; height: 250px;
    background: var(--c-cyan);
    bottom: -60px; right: -60px;
    animation: glowFloat2 10s ease-in-out infinite;
}

@keyframes glowFloat1 {
    0%, 100% { transform: translate(0, 0); }
    50% { transform: translate(30px, 20px); }
}
@keyframes glowFloat2 {
    0%, 100% { transform: translate(0, 0); }
    50% { transform: translate(-25px, -15px); }
}

/* Menu wrapper */
.menu-wrapper {
    position: relative;
    z-index: 2;
    width: min(400px, 88vw);
    display: flex;
    flex-direction: column;
    align-items: center;
}

/* ── Title ── */
.title-block {
    text-align: center;
    margin-bottom: 24px;
}

.title-sub {
    font-family: var(--font-game);
    font-size: 10px;
    font-weight: 500;
    letter-spacing: 8px;
    color: rgba(255,255,255,0.3);
    margin-bottom: 6px;
}

#start-screen h1 {
    font-family: var(--font-game);
    font-size: 44px;
    font-weight: 900;
    line-height: 1;
    letter-spacing: 4px;
    background: linear-gradient(135deg, var(--c-cyan) 0%, var(--c-purple) 45%, var(--c-pink) 80%, var(--c-gold) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    filter: drop-shadow(0 0 28px rgba(139,92,246,0.4));
    animation: titleGlow 3s ease-in-out infinite;
}

@keyframes titleGlow {
    0%, 100% { filter: drop-shadow(0 0 28px rgba(139,92,246,0.4)); }
    50%      { filter: drop-shadow(0 0 40px rgba(139,92,246,0.65)); }
}

.title-line {
    margin: 10px auto 0;
    width: 60px;
    height: 2px;
    border-radius: 1px;
    background: linear-gradient(90deg, transparent, var(--c-purple), transparent);
}

/* ── Mode Picker ── */
.mode-picker {
    display: flex;
    gap: 10px;
    width: 100%;
    margin-bottom: 20px;
}

.mode-card {
    flex: 1;
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 14px 8px 12px;
    border-radius: 14px;
    background: rgba(255,255,255,0.03);
    border: 1.5px solid rgba(255,255,255,0.06);
    cursor: pointer;
    transition: all .25s;
    text-align: center;
}

.mode-card input { display: none; }

.mode-card:has(input:checked) {
    background: rgba(139,92,246,0.12);
    border-color: rgba(139,92,246,0.45);
    box-shadow: 0 0 24px rgba(139,92,246,0.2), inset 0 0 16px rgba(139,92,246,0.06);
}

.mode-card:active {
    transform: scale(0.97);
}

.mode-icon {
    font-size: 22px;
    line-height: 1;
}

.mode-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.mode-name {
    font-family: var(--font-game);
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 1px;
    color: #fff;
}

.mode-desc {
    font-size: 10px;
    color: rgba(255,255,255,0.35);
    line-height: 1.3;
}

/* ── Start Button ── */
#start-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    width: 100%;
    padding: 18px 0;
    font-family: var(--font-game);
    font-size: 20px;
    font-weight: 900;
    letter-spacing: 6px;
    color: #fff;
    background: linear-gradient(135deg, #6c5ce7, #a855f7, #7c3aed);
    border: none;
    border-radius: 16px;
    cursor: pointer;
    transition: all .25s;
    box-shadow:
        0 6px 32px rgba(108,92,231,0.45),
        inset 0 1px 0 rgba(255,255,255,0.15),
        inset 0 -2px 0 rgba(0,0,0,0.2);
    position: relative;
    overflow: hidden;
}

#start-btn .btn-icon {
    font-size: 16px;
}

#start-btn::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(105deg, transparent 40%, rgba(255,255,255,0.12) 45%, rgba(255,255,255,0.12) 55%, transparent 60%);
    animation: btnShine 3s ease-in-out infinite;
}

@keyframes btnShine {
    0%   { transform: translateX(-120%); }
    30%  { transform: translateX(120%); }
    100% { transform: translateX(120%); }
}

#start-btn:active {
    transform: scale(0.97);
    box-shadow: 0 3px 18px rgba(108,92,231,0.35);
}

/* ── Controls Hint ── */
.controls-hint {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    margin-top: 16px;
    font-size: 11px;
    color: rgba(255,255,255,0.35);
    letter-spacing: 0.5px;
}

.hint-dot {
    width: 3px;
    height: 3px;
    border-radius: 50%;
    background: rgba(255,255,255,0.25);
}

/* ── Stats Drawer ── */
.stats-toggle {
    margin-top: 18px;
    padding: 10px 20px;
    background: rgba(139, 92, 246, 0.08);
    border: 1px solid rgba(139, 92, 246, 0.25);
    border-radius: 10px;
    color: rgba(255,255,255,0.6);
    font-size: 12px;
    font-weight: 600;
    font-family: var(--font-ui);
    letter-spacing: 0.5px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: all .25s;
    box-shadow: 0 0 12px rgba(139,92,246,0.08);
}
.stats-toggle:hover,
.stats-toggle:active {
    background: rgba(139, 92, 246, 0.15);
    border-color: rgba(139, 92, 246, 0.4);
    color: rgba(255,255,255,0.85);
    box-shadow: 0 0 20px rgba(139,92,246,0.15);
}

.privacy-link {
    display: inline-block;
    margin-top: 14px;
    font-size: 10px;
    color: rgba(255,255,255,0.25);
    letter-spacing: 0.5px;
    transition: color .2s;
}
.privacy-link:hover,
.privacy-link:active {
    color: rgba(255,255,255,0.5);
}

.toggle-arrow {
    font-size: 8px;
    transition: transform .3s;
}

.menu-wrapper.show-stats .toggle-arrow {
    transform: rotate(180deg);
}

.stats-drawer {
    width: 100%;
    max-height: 0;
    overflow: hidden;
    transition: max-height .4s ease, opacity .3s;
    opacity: 0;
}

.menu-wrapper.show-stats .stats-drawer {
    max-height: 400px;
    opacity: 1;
    margin-top: 12px;
}

/* ── Info Grid ── */
.info-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    width: 100%;
}

.info-panel {
    padding: 10px 10px 8px;
    border-radius: 10px;
    background: rgba(0,0,0,0.3);
    border: 1px solid rgba(255,255,255,0.04);
}

.info-title {
    font-family: var(--font-game);
    font-size: 8px;
    letter-spacing: 2px;
    text-transform: uppercase;
    color: rgba(255,255,255,0.3);
    margin-bottom: 6px;
}

.info-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 3px 0;
    font-size: 10px;
    border-top: 1px solid rgba(255,255,255,0.03);
}

.info-panel .info-row:first-of-type { border-top: none; }

.info-row span:first-child { color: rgba(255,255,255,0.3); }
.info-row span:last-child  {
    color: rgba(255,255,255,0.65);
    text-align: right;
    max-width: 58%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ══════════════════════════════════════
   GAME OVER SCREEN
   ══════════════════════════════════════ */
#game-over-screen {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(6,6,15,0.92);
    z-index: 100;
    pointer-events: all;
    opacity: 0;
    visibility: hidden;
    transition: opacity .4s;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    padding: var(--safe-top) 16px var(--safe-bot);
}

#game-over-screen.visible {
    opacity: 1;
    visibility: visible;
}

.go-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
}

.go-badge {
    font-family: var(--font-game);
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 5px;
    color: var(--c-red);
    text-shadow: 0 0 20px rgba(255,71,87,0.4);
    margin-bottom: 8px;
}

#game-over-screen h2,
#final-score {
    font-family: var(--font-game);
    font-size: 68px;
    font-weight: 900;
    color: var(--c-gold);
    text-shadow: 0 0 40px rgba(255,215,0,0.4);
    line-height: 1;
    margin-bottom: 4px;
}

#high-score {
    font-size: 13px;
    color: rgba(255,255,255,0.35);
    margin-bottom: 24px;
}

.go-btn-row {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    justify-content: center;
    max-width: 340px;
}

.go-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 14px 24px;
    font-family: var(--font-game);
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 1px;
    color: #fff;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    transition: all .2s;
    pointer-events: all;
    position: relative;
}

.go-btn .btn-icon { font-size: 14px; }

.go-btn--green {
    background: linear-gradient(135deg, #22c55e, #16a34a);
    box-shadow: 0 4px 20px rgba(34,197,94,0.35);
}

.go-btn--red {
    background: linear-gradient(135deg, #ff4757, #e63946);
    box-shadow: 0 4px 20px rgba(255,71,87,0.35);
}

.go-btn--ghost {
    background: rgba(255,255,255,0.06);
    border: 1px solid rgba(255,255,255,0.1);
}

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

.go-btn .btn-sub {
    display: block;
    position: absolute;
    bottom: 3px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 7px;
    font-weight: 500;
    font-family: var(--font-ui);
    opacity: 0.5;
    letter-spacing: 0.5px;
}

.go-btn--green { padding-bottom: 18px; }

/* ── Benchmark Summary ── */
#benchmark-summary.bm-summary {
    margin: 10px 0 8px;
    width: min(320px, 86vw);
    padding: 10px 12px;
    border-radius: 10px;
    background: rgba(255,255,255,0.04);
    border: 1px solid rgba(255,255,255,0.05);
}

.bm-title {
    font-family: var(--font-game);
    font-size: 8px;
    letter-spacing: 2px;
    text-transform: uppercase;
    color: rgba(255,255,255,0.35);
    margin-bottom: 4px;
}

.bm-metrics {
    color: rgba(255,255,255,0.6);
    font-size: 11px;
    line-height: 1.4;
}

/* ══════════════════════════════════════
   AD OVERLAY
   ══════════════════════════════════════ */
#ad-overlay {
    position: fixed;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: rgba(6,6,15,0.96);
    z-index: 200;
    pointer-events: all;
    opacity: 0;
    visibility: hidden;
    transition: opacity .4s;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

#ad-overlay.visible { opacity: 1; visibility: visible; }

#ad-overlay .ad-hint {
    color: rgba(255,255,255,0.3);
    font-size: 11px;
    margin-bottom: 14px;
    letter-spacing: 2px;
    text-transform: uppercase;
}

#ad-banner-link {
    display: block;
    max-width: 360px;
    width: 85%;
    border-radius: 14px;
    overflow: hidden;
    box-shadow: 0 0 30px rgba(108,92,231,0.25);
    pointer-events: all;
    cursor: pointer;
    transition: transform .3s;
}

#ad-banner-link:active { transform: scale(0.98); }

#ad-banner-link img { width: 100%; height: auto; display: block; }

#ad-continue-hint {
    color: rgba(255,255,255,0.25);
    font-size: 10px;
    margin-top: 16px;
    letter-spacing: 0.5px;
}

/* ══════════════════════════════════════
   COUNTDOWN
   ══════════════════════════════════════ */
#countdown-overlay {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(6,6,15,0.65);
    z-index: 300;
    pointer-events: none;
    opacity: 0;
    visibility: hidden;
    transition: opacity .2s;
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}

#countdown-overlay.visible { opacity: 1; visibility: visible; }

#countdown-num {
    font-family: var(--font-game);
    font-size: 100px;
    font-weight: 900;
    color: #fff;
    text-shadow: 0 0 60px rgba(139,92,246,0.8), 0 0 120px rgba(139,92,246,0.3);
    animation: cdPop .6s ease-out;
}

@keyframes cdPop {
    0%   { transform: scale(2.2); opacity: 0; }
    50%  { transform: scale(0.9); opacity: 1; }
    100% { transform: scale(1); opacity: 1; }
}

/* ══════════════════════════════════════
   GATE POPUP
   ══════════════════════════════════════ */
#gate-popup {
    position: absolute;
    top: 38%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0);
    font-family: var(--font-game);
    font-size: 46px;
    font-weight: 900;
    pointer-events: none;
    z-index: 50;
}

#gate-popup.show {
    animation: popupAnim .8s ease-out forwards;
}

@keyframes popupAnim {
    0%   { transform: translate(-50%, -50%) scale(0); opacity: 1; }
    30%  { transform: translate(-50%, -50%) scale(1.4); opacity: 1; }
    100% { transform: translate(-50%, -80%) scale(0.9); opacity: 0; }
}

/* ══════════════════════════════════════
   RESPONSIVE
   ══════════════════════════════════════ */

/* Small phones */
@media (max-height: 680px) {
    .title-block { margin-bottom: 16px; }
    #start-screen h1 { font-size: 34px; }
    .title-sub { font-size: 8px; letter-spacing: 6px; }
    .mode-card { padding: 10px 6px 8px; }
    .mode-icon { font-size: 18px; }
    #start-btn { padding: 14px 0; font-size: 17px; }
    .controls-hint { margin-top: 10px; }
    #final-score { font-size: 54px; }
}

/* Tablets & Desktop */
@media (min-width: 768px) {
    .menu-wrapper { width: min(580px, 80vw); }
    #start-screen h1 { font-size: 56px; letter-spacing: 6px; }
    .title-sub { font-size: 12px; letter-spacing: 10px; }
    .mode-card { padding: 18px 12px 14px; }
    .mode-name { font-size: 14px; }
    .mode-desc { font-size: 12px; }
    #start-btn { padding: 22px 0; font-size: 24px; border-radius: 18px; }
    .controls-hint { font-size: 12px; gap: 12px; }
    #score-display { font-size: 42px; }
    #final-score { font-size: 80px; }
    .go-btn { padding: 16px 30px; font-size: 14px; }
}
