/*
 * O turbo não para na borda do canvas.
 *
 * TurboFX escreve a intensidade (0..1) na variável CSS `--turbo` do
 * #game-container a cada frame. Daqui pra baixo é só CSS: a moldura do jogo
 * acende junto com a turbina, então o efeito "vaza" pra página e a tela
 * inteira parece parte do carro.
 *
 * O brilho vai no <canvas>, não no container: o container é um <div> de
 * largura total, e uma sombra nele viraria uma faixa atravessando a página.
 * O canvas tem exatamente o tamanho do jogo. A variável é herdada do pai,
 * então o JS continua escrevendo num lugar só.
 */

@font-face {
    font-family: 'Cyber Arcade';
    src: url('./assets/fonts/PressStart2P-Regular.ttf') format('truetype');
    font-style: normal;
    font-weight: 400;
    font-display: swap;
}

@font-face {
    font-family: 'Orbitron';
    src: url('./assets/fonts/Orbitron-Variable.ttf') format('truetype');
    font-style: normal;
    font-weight: 400 900;
    font-display: swap;
}

html,
body {
    margin: 0;
    padding: 0;
    background: #05060a;
    color-scheme: dark;
    /* Jogo ocupa a tela toda e nada rola: sem barra, sem "puxar pra
       atualizar" e sem efeito elástico do iOS no meio da corrida. */
    width: 100%;
    height: 100%;
    overflow: hidden;
    overscroll-behavior: none;
    touch-action: none;
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
    -webkit-tap-highlight-color: transparent;
}

#game-container {
    --turbo: 0;
    /* Container com o tamanho exato da tela visível. `dvh` acompanha a
       barra de endereço do celular aparecendo/sumindo (o `vh` comum não). */
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100vh;
    height: 100dvh;
}

#game-container canvas {
    display: block;
    /* Duas sombras: magenta larga e difusa (o calor) e ciano curta e fechada
       (a luz de neon do próprio jogo). Juntas dão profundidade em vez de um
       halo chapado de cor única. */
    box-shadow:
        0 0 calc(10px + var(--turbo) * 80px) calc(var(--turbo) * 8px)
            rgba(255, 45, 85, calc(0.08 + var(--turbo) * 0.5)),
        0 0 calc(4px + var(--turbo) * 26px)
            rgba(0, 229, 255, calc(0.1 + var(--turbo) * 0.35));
}

/* Sombras difusas animadas exigem repintar o canvas no celular. */
.is-touch #game-container canvas {
    box-shadow: none;
}

/* Resgate opcional na tela de resultado, acima do canvas e dos controles. */
.credit-redemption {
    box-sizing: border-box;
    width: min(420px, calc(100vw - 32px));
    max-height: calc(100dvh - 24px);
    overflow: auto;
    padding: 24px;
    border: 1px solid #e9bd77;
    border-radius: 12px;
    background: #091324;
    color: #edf4ff;
    font: 15px/1.5 'Trebuchet MS', sans-serif;
    text-align: center;
    touch-action: pan-y;
}
.credit-redemption::backdrop { background: #020611dc; }
.credit-redemption h2 {
    margin: 0 0 16px;
    color: #ffe6a2;
    font: 12px/1.8 'Cyber Arcade', monospace;
}
.credit-redemption .credit-amount {
    color: #ffdd88;
    font: 12px/1.8 'Cyber Arcade', monospace;
}
.credit-google-button { display: flex; justify-content: center; margin: 18px 0; }
.credit-status { min-height: 2em; color: #b9f0ff; }
.credit-redemption button {
    min-height: 44px;
    margin: 6px 0 0;
    padding: 10px 16px;
    border: 1px solid #69e4f2;
    border-radius: 6px;
    background: #102735;
    color: #c8faff;
    font: inherit;
    cursor: pointer;
    touch-action: manipulation;
}
.credit-redemption button:focus-visible { outline: 2px solid #ffdd88; outline-offset: 3px; }
.credit-redemption button:disabled { opacity: 0.5; cursor: wait; }
.credit-redemption [hidden] { display: none; }
@media (max-height: 400px) {
    .credit-redemption { padding: 14px 20px; }
    .credit-redemption h2, .credit-redemption p { margin: 6px 0; }
    .credit-google-button { margin: 12px 0; }
}


/* =========================================================================
   CELULAR / TABLET
   ========================================================================= */

/* --- Controles de toque (js/input/TouchControls.js) ---------------------- */

#touch-controls {
    --tc-size: clamp(120px, 30vmin, 180px);   /* diâmetro do joystick */
    --tc-turbo: clamp(76px, 18vmin, 100px);   /* alvo confortável para o polegar direito */
    --tc-edge: clamp(14px, 4vmin, 36px);      /* distância da borda da tela */
    position: fixed;
    inset: 0;
    z-index: 100;
    pointer-events: none;      /* só o joystick e o turbo recebem toque */
    font-family: monospace;
}
#touch-controls[hidden] {
    display: none;
}

/* Área do joystick fixo no canto inferior esquerdo. */
#touch-controls .tc-zone {
    position: absolute;
    left: calc(env(safe-area-inset-left, 0px) + var(--tc-edge));
    bottom: calc(env(safe-area-inset-bottom, 0px) + var(--tc-edge));
    width: var(--tc-size);
    height: var(--tc-size);
    pointer-events: auto;
    touch-action: none;
}

#touch-controls .tc-stick {
    position: absolute;
    left: 0;
    bottom: 0;
    box-sizing: border-box;
    width: var(--tc-size);
    height: var(--tc-size);
    border-radius: 50%;
    border: 2px solid rgba(0, 229, 255, 0.5);
    background: radial-gradient(circle, rgba(0, 229, 255, 0.14), rgba(0, 229, 255, 0.03) 70%);
    box-shadow: 0 0 18px rgba(0, 229, 255, 0.25), inset 0 0 18px rgba(0, 229, 255, 0.12);
    opacity: 0.6;
    transition: opacity 0.12s;
    pointer-events: none;
}
#touch-controls .tc-stick.tc-active {
    opacity: 0.85;
}
#touch-controls .tc-stick::before,
#touch-controls .tc-stick::after {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    font-size: 13px;
    color: rgba(170, 239, 255, 0.7);
}
#touch-controls .tc-stick::before {
    content: '↑';
    top: 4px;
}
#touch-controls .tc-stick::after {
    content: '↓';
    bottom: 4px;
}
#touch-controls .tc-arrow {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    font-size: 13px;
    color: rgba(170, 239, 255, 0.7);
}
#touch-controls .tc-arrow-left { left: 4px; }
#touch-controls .tc-arrow-right { right: 4px; }
#touch-controls .tc-stick.tc-throttle {
    border-color: #6cf1df;
    box-shadow: 0 0 18px rgba(65, 239, 199, 0.3);
}
#touch-controls .tc-stick.tc-braking {
    border-color: #ff897d;
    box-shadow: 0 0 18px rgba(255, 100, 90, 0.3);
}
#touch-controls .tc-stick.tc-braking .tc-knob {
    border-color: #ff897d;
    background: radial-gradient(circle at 35% 30%, #ffd1ba, rgba(255, 110, 90, 0.45));
}

#touch-controls .tc-knob {
    position: absolute;
    left: 50%;
    top: 50%;
    width: 42%;
    height: 42%;
    margin: -21% 0 0 -21%;
    border-radius: 50%;
    border: 2px solid #00e5ff;
    background: radial-gradient(circle at 35% 30%, rgba(160, 250, 255, 0.85), rgba(0, 229, 255, 0.35));
    box-shadow: 0 0 14px rgba(0, 229, 255, 0.7);
    will-change: transform;
}

#touch-controls .tc-pedals {
    position: absolute;
    right: calc(env(safe-area-inset-right, 0px) + var(--tc-edge));
    bottom: calc(env(safe-area-inset-bottom, 0px) + var(--tc-edge));
    display: grid;
    grid-template-columns: repeat(2, var(--tc-turbo));
    gap: 10px;
    pointer-events: none;
}
#touch-controls .tc-pedal {
    width: var(--tc-turbo);
    height: var(--tc-turbo);
    padding: 0;
    border-radius: 24%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: 'Cyber Arcade', monospace;
    font-size: clamp(8px, 2vmin, 12px);
    font-weight: normal;
    letter-spacing: 0;
    color: #a9e5ff;
    border: 2px solid #ff39d4;
    background: linear-gradient(135deg, rgba(41, 207, 255, 0.12), rgba(255, 57, 212, 0.17));
    box-shadow: 0 0 12px rgba(255, 57, 212, 0.25), inset 0 0 10px rgba(41, 207, 255, 0.12);
    transition: background 100ms, box-shadow 100ms, color 100ms;
    opacity: 0.7;
    pointer-events: auto;
    touch-action: none;
}
#touch-controls .tc-pedal.tc-active {
    opacity: 1;
    color: #fff;
    background: linear-gradient(135deg, rgba(41, 207, 255, 0.3), rgba(255, 57, 212, 0.45));
    box-shadow: 0 0 20px rgba(255, 57, 212, 0.55), inset 0 0 12px rgba(41, 207, 255, 0.3);
}
#touch-controls .tc-turbo {
    grid-column: 2;
    grid-row: 1;
    height: calc(var(--tc-turbo) * 0.68);
}
#touch-controls .tc-accelerate {
    grid-column: 2;
    grid-row: 2;
    border-color: #60e5c0;
    background: rgba(30, 140, 110, 0.22);
    font-size: clamp(7px, 1.7vmin, 10px);
}
#touch-controls .tc-brake {
    grid-column: 1;
    grid-row: 2;
    border-color: #ff897d;
    background: rgba(160, 55, 45, 0.22);
    line-height: 1.6;
}
#touch-controls .tc-accelerate.tc-active {
    background: rgba(35, 170, 125, 0.55);
    box-shadow: 0 0 18px rgba(65, 239, 199, 0.45);
}
#touch-controls .tc-brake.tc-active {
    background: rgba(190, 65, 50, 0.55);
    box-shadow: 0 0 18px rgba(255, 110, 90, 0.45);
}

/* --- Aviso "gire o celular" ---------------------------------------------- */

#rotate-hint {
    display: none;
}

@media (orientation: portrait) {
    html.is-touch #rotate-hint {
        position: fixed;
        inset: 0;
        z-index: 1000;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 18px;
        background: #05060a;
        color: #00e5ff;
        font-family: monospace;
        font-size: 18px;
        text-align: center;
        line-height: 1.5;
    }
}

#rotate-hint p {
    margin: 0;
}

/* Celular desenhado em CSS que gira de pé pra deitado. */
#rotate-hint .rotate-icon {
    width: 46px;
    height: 76px;
    border: 3px solid #00e5ff;
    border-radius: 9px;
    box-shadow: 0 0 14px rgba(0, 229, 255, 0.6);
    animation: rotate-phone 2.4s ease-in-out infinite;
}

@keyframes rotate-phone {
    0%, 15% { transform: rotate(0deg); }
    55%, 85% { transform: rotate(-90deg); }
    100% { transform: rotate(0deg); }
}
