/* ==============================================================================
   🏔️ TDS Ultra-Trail 2D Runner — runner.css
   Description : Standalone arcade page for runner.avarre.com.
                 Canvas draws the world; the DOM owns the chrome (HUD, gauges,
                 overlays) so it stays crisp at any device pixel ratio.
   Author      : Éole <hi@eole.me>
   ============================================================================== */

:root {
    --bg: #05070f;
    --panel: #0a0f1e;
    --line: rgba(148, 163, 184, 0.16);
    --muted: #94a3b8;
    --cyan: #38bdf8;
    --purple: #c084fc;
    --gold: #facc15;
    --orange: #fb923c;
    --green: #4ade80;
    --red: #f87171;
    --font-mono: 'Fira Code', ui-monospace, monospace;
    --font-sans: 'Outfit', system-ui, sans-serif;
}

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

body {
    background: var(--bg);
    color: #f8fafc;
    font-family: var(--font-sans);
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 1.25rem 1rem 2rem;
    text-align: center;
    overflow-x: hidden;
    background-image:
        radial-gradient(ellipse 120% 60% at 50% -10%, rgba(56, 189, 248, 0.16) 0%, transparent 65%),
        radial-gradient(ellipse 90% 50% at 85% 105%, rgba(192, 132, 252, 0.12) 0%, transparent 60%);
}

/* ---------- Header ---------------------------------------------------------- */

.page-head { margin-bottom: 1rem; }

h1 {
    font-size: clamp(1.5rem, 4.4vw, 2.4rem);
    font-weight: 900;
    letter-spacing: -0.03em;
    line-height: 1.1;
    background: linear-gradient(100deg, #ffffff 0%, var(--cyan) 45%, var(--purple) 75%, #ffffff 100%);
    background-size: 220% 100%;
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    animation: shimmer 9s linear infinite;
}

@keyframes shimmer {
    to { background-position: -220% 0; }
}

.tagline {
    margin-top: 0.4rem;
    color: var(--muted);
    font-size: 0.92rem;
    font-weight: 500;
}
.tagline b { color: #e2e8f0; font-weight: 700; }

/* ---------- Game frame ------------------------------------------------------ */

#game-container {
    position: relative;
    width: 100%;
    max-width: 960px;
    border-radius: 20px;
    overflow: hidden;
    border: 1px solid rgba(56, 189, 248, 0.28);
    background: #05070f;
    box-shadow:
        0 30px 70px rgba(0, 0, 0, 0.75),
        0 0 60px rgba(56, 189, 248, 0.12),
        inset 0 0 0 1px rgba(255, 255, 255, 0.04);
    transition: box-shadow 0.4s ease;
}

#game-container.is-boosting {
    border-color: rgba(250, 204, 21, 0.6);
    box-shadow:
        0 30px 70px rgba(0, 0, 0, 0.75),
        0 0 90px rgba(250, 204, 21, 0.3);
}

canvas {
    display: block;
    width: 100%;
    height: auto;
    touch-action: manipulation;
    cursor: pointer;
}

/* ---------- HUD ------------------------------------------------------------- */

.hud {
    position: absolute;
    inset: 14px 16px auto;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 0.4rem;
    font-family: var(--font-mono);
    font-size: 0.9rem;
    font-weight: 700;
    pointer-events: none;
    z-index: 10;
}

.hud-item {
    background: rgba(5, 8, 16, 0.62);
    border: 1px solid var(--line);
    padding: 0.35rem 0.75rem;
    border-radius: 999px;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    display: flex;
    align-items: center;
    gap: 0.4rem;
    white-space: nowrap;
    text-shadow: 0 1px 6px rgba(0, 0, 0, 0.8);
}

.hud-item .v { transition: color 0.2s ease; }
#dist-val { color: var(--cyan); }
#deniv-val { color: var(--orange); }
#coffee-val { color: var(--gold); }
#high-val { color: var(--purple); }

.hud-item.pop { animation: pop 0.35s cubic-bezier(0.34, 1.56, 0.64, 1); }
@keyframes pop {
    40% { transform: scale(1.14); }
    to { transform: scale(1); }
}

/* ---------- Bottom strip: caffeine gauge + combo ---------------------------- */

.hud-bottom {
    position: absolute;
    left: 16px;
    right: 16px;
    bottom: 14px;
    display: flex;
    align-items: center;
    gap: 0.7rem;
    z-index: 10;
    pointer-events: none;
}

#boost {
    flex: 0 1 250px;
    background: rgba(5, 8, 16, 0.62);
    border: 1px solid var(--line);
    border-radius: 999px;
    padding: 0.3rem 0.7rem 0.35rem;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    text-align: left;
}

#boost .cap {
    font-family: var(--font-mono);
    white-space: nowrap;
    font-size: 0.6rem;
    letter-spacing: 0.14em;
    color: var(--muted);
    display: flex;
    justify-content: space-between;
}

#boost .track {
    height: 6px;
    margin-top: 0.25rem;
    border-radius: 999px;
    background: rgba(148, 163, 184, 0.18);
    overflow: hidden;
}

#boost .fill {
    height: 100%;
    width: 0;
    border-radius: 999px;
    background: linear-gradient(90deg, var(--orange), var(--gold));
    transition: width 0.18s ease-out;
}

#boost.ready .fill { background: linear-gradient(90deg, var(--gold), #fff7cc, var(--gold)); }
#boost.ready {
    border-color: rgba(250, 204, 21, 0.65);
    animation: readyPulse 1.1s ease-in-out infinite;
}
#boost.ready .cap .hint { color: var(--gold); }

@keyframes readyPulse {
    50% { box-shadow: 0 0 22px rgba(250, 204, 21, 0.45); }
}

#boost.firing .fill { background: linear-gradient(90deg, #fff, var(--gold)); }

#combo {
    margin-left: auto;
    opacity: 0;
    transform: translateY(6px) scale(0.9);
    transition: opacity 0.2s ease, transform 0.2s ease;
    background: rgba(5, 8, 16, 0.62);
    border: 1px solid rgba(192, 132, 252, 0.45);
    border-radius: 12px;
    padding: 0.25rem 0.65rem 0.35rem;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    min-width: 74px;
}

#combo.on { opacity: 1; transform: none; }
#combo.hit { animation: pop 0.3s cubic-bezier(0.34, 1.56, 0.64, 1); }

#combo .x {
    font-family: var(--font-mono);
    font-weight: 700;
    font-size: 1.05rem;
    color: var(--purple);
    line-height: 1;
}

#combo .track {
    height: 3px;
    margin-top: 0.3rem;
    border-radius: 999px;
    background: rgba(192, 132, 252, 0.22);
    overflow: hidden;
}
#combo .fill { height: 100%; width: 100%; background: var(--purple); border-radius: 999px; }

/* ---------- Checkpoint banner ---------------------------------------------- */

#banner {
    position: absolute;
    top: 30%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0.94);
    z-index: 15;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.35s ease, transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
    background: rgba(5, 8, 16, 0.72);
    border: 1px solid rgba(56, 189, 248, 0.5);
    border-radius: 14px;
    padding: 0.7rem 1.6rem 0.8rem;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    box-shadow: 0 0 44px rgba(56, 189, 248, 0.28);
    white-space: nowrap;
}

#banner.show { opacity: 1; transform: translate(-50%, -50%) scale(1); }

#banner .kicker {
    font-family: var(--font-mono);
    font-size: 0.62rem;
    letter-spacing: 0.24em;
    color: var(--cyan);
}
#banner .name { font-size: 1.3rem; font-weight: 800; letter-spacing: -0.01em; margin-top: 0.1rem; }
#banner .sub { font-size: 0.75rem; color: var(--muted); margin-top: 0.15rem; }

#banner.record { border-color: rgba(250, 204, 21, 0.65); box-shadow: 0 0 50px rgba(250, 204, 21, 0.35); }
#banner.record .kicker { color: var(--gold); }

/* ---------- Overlays -------------------------------------------------------- */

.overlay {
    position: absolute;
    inset: 0;
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    padding: 1.5rem;
    background: rgba(4, 6, 13, 0.86);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    z-index: 20;
    animation: fadeIn 0.28s ease;
}

.overlay.show { display: flex; }

@keyframes fadeIn {
    from { opacity: 0; }
}

.overlay h2 {
    font-size: clamp(1.35rem, 4vw, 2.1rem);
    font-weight: 900;
    letter-spacing: -0.02em;
}

#ov-start h2 { color: #fff; }
#ov-over h2 { color: var(--red); text-shadow: 0 0 26px rgba(248, 113, 113, 0.45); }
#ov-pause h2 { color: var(--cyan); }

.overlay .lead { color: var(--muted); font-size: 0.9rem; max-width: 44ch; line-height: 1.5; }
.overlay .lead b { color: #e2e8f0; }

.keys {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.45rem 0.7rem;
    font-size: 0.82rem;
    color: var(--muted);
    max-width: 34rem;
}

.keys span { display: inline-flex; align-items: center; gap: 0.35rem; }

kbd, .key-badge {
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.18);
    border-bottom-width: 2px;
    color: #fff;
    padding: 0.12rem 0.5rem;
    border-radius: 6px;
    font-family: var(--font-mono);
    font-size: 0.74rem;
    font-weight: 700;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(94px, 1fr));
    gap: 0.6rem;
    width: 100%;
    max-width: 560px;
}

.stat-card {
    background: rgba(255, 255, 255, 0.045);
    border: 1px solid rgba(255, 255, 255, 0.09);
    padding: 0.7rem 0.4rem;
    border-radius: 12px;
}

.stat-card .val {
    font-family: var(--font-mono);
    font-size: clamp(0.95rem, 2.6vw, 1.3rem);
    font-weight: 700;
    color: var(--cyan);
}

.stat-card .lbl {
    font-size: 0.64rem;
    letter-spacing: 0.08em;
    color: var(--muted);
    text-transform: uppercase;
    margin-top: 0.25rem;
}

.verdict {
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--gold);
}
.verdict small { display: block; font-weight: 500; font-size: 0.78rem; color: var(--muted); margin-top: 0.15rem; }

.btn {
    background: linear-gradient(135deg, var(--cyan) 0%, #0284c7 100%);
    color: #051018;
    border: none;
    padding: 0.8rem 2rem;
    border-radius: 12px;
    font-size: 1.02rem;
    font-weight: 800;
    font-family: var(--font-sans);
    cursor: pointer;
    box-shadow: 0 10px 28px rgba(56, 189, 248, 0.38);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.btn:hover, .btn:focus-visible {
    transform: translateY(-2px) scale(1.03);
    box-shadow: 0 14px 34px rgba(56, 189, 248, 0.55);
}

.btn.ghost {
    background: transparent;
    color: var(--muted);
    border: 1px solid var(--line);
    box-shadow: none;
    padding: 0.5rem 1.1rem;
    font-size: 0.85rem;
    font-weight: 600;
}
.btn.ghost:hover { color: #fff; transform: none; }

.touch-only { display: none; }

@media (hover: none) and (pointer: coarse), (max-width: 900px) {
    .kbd-only { display: none; }
    .touch-only { display: flex; }
}

/* ---------- Touch pad ------------------------------------------------------- */

#touchpad {
    display: none;
    width: 100%;
    gap: 0.5rem;
    padding: 0.5rem 0.5rem calc(0.5rem + env(safe-area-inset-bottom));
    grid-template-columns: 1fr 1fr;
    grid-template-rows: auto 1fr;
}

.pad-btn {
    -webkit-tap-highlight-color: transparent;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.15rem;
    border-radius: 16px;
    border: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.05);
    color: #e2e8f0;
    font-family: var(--font-sans);
    cursor: pointer;
    padding: 0.6rem;
}

.pad-btn b { font-size: 0.95rem; font-weight: 800; letter-spacing: 0.02em; }
.pad-btn span { font-size: 0.66rem; color: var(--muted); font-weight: 500; }
.pad-btn:active { background: rgba(56, 189, 248, 0.2); border-color: var(--cyan); }

.pad-jump {
    grid-column: 1 / -1;
    background: linear-gradient(180deg, rgba(56, 189, 248, 0.28), rgba(56, 189, 248, 0.12));
    border-color: rgba(56, 189, 248, 0.55);
    min-height: 5rem;
}
.pad-jump i { font-size: clamp(1.8rem, 9vw, 3.2rem); line-height: 0.9; font-style: normal; opacity: 0.45; }
.pad-jump b { font-size: 1.5rem; }
.pad-jump:active { background: linear-gradient(180deg, rgba(56, 189, 248, 0.5), rgba(56, 189, 248, 0.25)); }

.pad-boost { opacity: 0.55; }
.pad-boost.armed {
    opacity: 1;
    border-color: rgba(250, 204, 21, 0.7);
    background: rgba(250, 204, 21, 0.16);
    animation: readyPulse 1.1s ease-in-out infinite;
}
.pad-boost.armed span { color: var(--gold); }

/* ---------- Corner controls ------------------------------------------------- */

.corner {
    position: absolute;
    top: 52px;
    right: 16px;
    display: flex;
    gap: 0.4rem;
    z-index: 12;
}

.icon-btn {
    width: 32px;
    height: 32px;
    border-radius: 10px;
    background: rgba(5, 8, 16, 0.62);
    border: 1px solid var(--line);
    color: #e2e8f0;
    font-size: 0.85rem;
    cursor: pointer;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    transition: border-color 0.2s ease, transform 0.2s ease;
    line-height: 1;
}
.icon-btn:hover { border-color: var(--cyan); transform: translateY(-1px); }

/* ---------- Footer ---------------------------------------------------------- */

.controls {
    margin-top: 0.9rem;
    color: var(--muted);
    font-size: 0.84rem;
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
    gap: 0.4rem 0.8rem;
}

footer { margin-top: 1.4rem; font-size: 0.85rem; color: var(--muted); }
footer a { color: var(--cyan); text-decoration: none; font-weight: 600; }
footer a:hover { text-decoration: underline; }

/* ---------- Responsive ------------------------------------------------------ */

@media (max-width: 900px) {
    body {
        padding: 0;
        min-height: 0;
        height: 100vh;
        height: 100dvh;
        overflow: hidden;
        justify-content: flex-start;
        background-image: none;
    }

    .page-head, footer, .controls { display: none; }

    #game-container {
        width: 100%;
        max-width: none;
        border: 0;
        border-radius: 0;
        box-shadow: none;
    }

    canvas { width: 100%; height: 100%; object-fit: contain; }

    /* The overlays belong to the screen here, not to the canvas box: in portrait
       the canvas is only a third of the viewport. */
    .overlay {
        position: fixed;
        inset: 0;
        overflow-y: auto;
        padding: max(1rem, env(safe-area-inset-top)) 1rem 1rem;
        justify-content: center;
    }
}

@media (max-width: 900px) and (orientation: portrait) {
    #game-container { aspect-ratio: 62 / 52; flex: 0 0 auto; }
    #touchpad { display: grid; flex: 1 1 auto; min-height: 0; }
}

@media (max-width: 900px) and (orientation: landscape) {
    #game-container { flex: 1 1 auto; min-height: 0; height: 100%; }
    #touchpad { display: none; }
    .overlay { gap: 0.5rem; }
    .overlay .lead { display: none; }
}

@media (max-width: 720px) {
    .hud { inset: max(9px, env(safe-area-inset-top)) 10px auto; font-size: 0.72rem; }
    .hud-item { padding: 0.25rem 0.5rem; gap: 0.25rem; }
    .hud-item .lb { display: none; }
    .corner { top: auto; bottom: 9px; right: max(10px, env(safe-area-inset-right)); }
    .hud-bottom { left: 10px; right: 10px; bottom: auto; top: 44px; }
    #boost { flex-basis: 160px; }
    #boost .cap { font-size: 0.52rem; }
    #combo { min-width: 58px; padding: 0.2rem 0.45rem 0.3rem; }
    #banner { padding: 0.5rem 1rem 0.6rem; }
    #banner .name { font-size: 1rem; }
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
    .overlay { gap: 0.75rem; padding: 1rem; }
    .keys { font-size: 0.74rem; }
}

@media (prefers-reduced-motion: reduce) {
    h1 { animation: none; }
    #boost.ready { animation: none; }
    .overlay { animation: none; }
    .hud-item.pop, #combo.hit { animation: none; }
    .btn:hover { transform: none; }
}
