:root {
    --green: #00FF7F;
    --red:   #E63946;
    --cyan:  #69D2E7;
    --gold:  #FFD166;
    --ink:   #070c18;
    --ink-2: #101828;
    --text:  #E8EEF7;
    --muted: rgba(232,238,247,.6);
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    height: 100%;
    overflow: hidden;
}

body {
    font-family: 'Orbitron', system-ui, sans-serif;
    background: radial-gradient(120% 90% at 50% 0%, #16213c 0%, var(--ink) 65%);
    color: var(--text);
    display: flex;
    align-items: center;
    justify-content: center;
    touch-action: none;
    -webkit-user-select: none;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

.game-container {
    position: relative;
    width: 100vw;
    height: 100dvh;
    display: flex;
    align-items: center;
    justify-content: center;
}

.screen {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.hidden { display: none !important; }

/* ---------------- panels (menu / game over) ---------------- */
.panel {
    width: min(92vw, 560px);
    padding: clamp(1.4rem, 4vw, 2.5rem);
    text-align: center;
    background: linear-gradient(180deg, rgba(20,29,51,.92), rgba(7,12,24,.95));
    border: 1px solid rgba(105,210,231,.22);
    border-radius: 18px;
    box-shadow: 0 0 0 1px rgba(0,0,0,.4), 0 30px 80px -20px rgba(0,255,127,.25);
    animation: rise .45s cubic-bezier(.2,.9,.3,1) both;
}

@keyframes rise {
    from { opacity: 0; transform: translateY(14px) scale(.98); }
}

.logo {
    margin: 0 0 .35rem;
    font-size: clamp(1.7rem, 7vw, 2.9rem);
    font-weight: 800;
    line-height: 1.05;
    letter-spacing: -.02em;
    color: var(--green);
    text-shadow: 0 0 24px rgba(0,255,127,.55);
}
.logo span {
    display: block;
    color: var(--red);
    text-shadow: 0 0 24px rgba(230,57,70,.55);
}

.crash {
    margin: 0 0 .4rem;
    font-size: clamp(1.9rem, 8vw, 3rem);
    font-weight: 800;
    color: var(--red);
    text-shadow: 0 0 26px rgba(230,57,70,.6);
}

.tagline {
    margin: 0 0 1.5rem;
    font-size: clamp(.8rem, 2.6vw, .95rem);
    font-weight: 400;
    color: var(--muted);
}

.record {
    display: inline-block;
    margin-bottom: 1rem;
    padding: .35rem .85rem;
    font-size: .75rem;
    letter-spacing: .12em;
    color: var(--ink);
    background: var(--gold);
    border-radius: 999px;
    animation: pop .5s cubic-bezier(.2,1.4,.4,1) both;
}
@keyframes pop { from { transform: scale(.6); opacity: 0; } }

.bests {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: .6rem;
    margin-bottom: 1.6rem;
}
.best {
    padding: .7rem .4rem;
    background: rgba(105,210,231,.07);
    border: 1px solid rgba(105,210,231,.16);
    border-radius: 11px;
}
.best .k {
    display: block;
    margin-bottom: .3rem;
    font-size: .58rem;
    letter-spacing: .13em;
    text-transform: uppercase;
    color: var(--muted);
}
.best b {
    font-size: clamp(1rem, 4.4vw, 1.4rem);
    font-weight: 600;
    color: var(--text);
}
.best i { font-style: normal; font-size: .75em; color: var(--muted); }
.bests.big b { color: var(--green); }

.alltime {
    margin: -.6rem 0 1.4rem;
    font-size: .72rem;
    font-weight: 400;
    color: var(--muted);
}
.alltime b { color: var(--text); font-weight: 600; }

.row { display: flex; gap: .7rem; justify-content: center; flex-wrap: wrap; }

.cta, .ghost {
    padding: .85rem 2rem;
    font-family: inherit;
    font-size: clamp(.85rem, 3vw, 1rem);
    font-weight: 700;
    letter-spacing: .06em;
    border-radius: 11px;
    cursor: pointer;
    transition: transform .14s ease, box-shadow .2s ease, filter .2s ease;
    touch-action: manipulation;
}
.cta {
    color: #04130a;
    background: linear-gradient(135deg, var(--green), #46e6b0);
    border: none;
    box-shadow: 0 0 28px rgba(0,255,127,.35);
}
.cta:hover:not(:disabled) { transform: translateY(-2px); box-shadow: 0 0 40px rgba(0,255,127,.55); }
.cta:active:not(:disabled) { transform: translateY(0); }
.cta:disabled { filter: grayscale(.7); opacity: .6; cursor: progress; }

.ghost {
    color: var(--text);
    background: transparent;
    border: 1px solid rgba(232,238,247,.25);
}
.ghost:hover { background: rgba(232,238,247,.08); }

.keys {
    margin: 1.5rem 0 0;
    padding: 0;
    list-style: none;
    font-size: .68rem;
    font-weight: 400;
    line-height: 2;
    color: var(--muted);
}
kbd {
    display: inline-block;
    min-width: 1.5em;
    padding: .12em .4em;
    font-family: inherit;
    font-size: .95em;
    color: var(--text);
    background: rgba(232,238,247,.1);
    border: 1px solid rgba(232,238,247,.2);
    border-radius: 5px;
}
.touch-only { display: none; }
body.touch-device .touch-only { display: list-item; }

.back-link {
    display: inline-block;
    margin-top: 1.2rem;
    font-size: .68rem;
    font-weight: 400;
    color: var(--muted);
    text-decoration: none;
}
.back-link:hover { color: var(--green); }

/* ---------------- HUD ---------------- */
.hud {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    z-index: 10;
    display: flex;
    align-items: center;
    gap: clamp(.5rem, 3vw, 1.6rem);
    padding: .5rem clamp(.6rem, 3vw, 1.1rem);
    padding-top: calc(.5rem + env(safe-area-inset-top));
    background: linear-gradient(180deg, rgba(7,12,24,.92), rgba(7,12,24,0));
    pointer-events: none;
}
.stat { line-height: 1.1; }
.stat .k {
    display: block;
    font-size: .52rem;
    letter-spacing: .14em;
    text-transform: uppercase;
    color: var(--muted);
}
.stat b {
    font-size: clamp(.85rem, 3.4vw, 1.15rem);
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}
#score { color: var(--green); text-shadow: 0 0 12px rgba(0,255,127,.5); }
#coins { color: var(--gold); }

.combo { position: relative; min-width: 62px; }
.combo b { color: var(--muted); transition: color .2s; }
.combo.hot b {
    color: var(--gold);
    text-shadow: 0 0 14px rgba(255,209,102,.7);
}
.combo-bar {
    display: block;
    height: 3px;
    margin-top: 3px;
    background: rgba(232,238,247,.14);
    border-radius: 2px;
    overflow: hidden;
}
.combo-bar i {
    display: block;
    height: 100%;
    background: var(--gold);
    transform-origin: left;
    transform: scaleX(0);
}

.corner-actions {
    position: absolute;
    top: calc(.5rem + env(safe-area-inset-top));
    right: clamp(.6rem, 3vw, 1.1rem);
    z-index: 30;
    display: flex;
    gap: .4rem;
}
.icon-btn {
    width: 34px;
    height: 34px;
    font-size: .9rem;
    line-height: 1;
    color: var(--text);
    background: rgba(232,238,247,.08);
    border: 1px solid rgba(232,238,247,.16);
    border-radius: 9px;
    cursor: pointer;
    transition: background .18s;
    touch-action: manipulation;
}
.icon-btn:hover { background: rgba(232,238,247,.18); }

/* ---------------- canvas ---------------- */
#game-canvas {
    display: block;
    border-radius: 2px;
    background: var(--ink);
    box-shadow: 0 0 60px -10px rgba(230,57,70,.4), 0 0 0 1px rgba(105,210,231,.15);
}

/* ---------------- mobile controls ---------------- */
#mobile-controls {
    display: none;
    position: absolute;
    left: 0;
    right: 0;
    bottom: calc(3vh + env(safe-area-inset-bottom));
    justify-content: space-between;
    padding: 0 6vw;
    z-index: 20;
    pointer-events: none;
}
body.touch-device #mobile-controls { display: flex; }
#mobile-controls button {
    width: 74px;
    height: 74px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 0 8px;
    font-family: inherit;
    font-size: 2.6rem;
    font-weight: 700;
    color: var(--ink);
    background: rgba(0,255,127,.45);
    border: 2px solid var(--green);
    border-radius: 50%;
    pointer-events: auto;
    touch-action: manipulation;
    backdrop-filter: blur(4px);
}
#mobile-controls button:active { background: rgba(0,255,127,.85); transform: scale(.94); }

@media (prefers-reduced-motion: reduce) {
    * { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
