/* ============================================
   REKT RACER — Wojak Arcade Theme v4
   CSS Rotation for forced landscape on mobile
   ============================================ */

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

:root {
    --bg-darkest: #04080f;
    --bg-dark: #0a1422;
    --bg-card: #0f1c2e;
    --accent: #f7c948;
    --accent-hover: #ffd666;
    --accent-glow: rgba(247, 201, 72, 0.3);
    --text: #e8edf3;
    --text-dim: rgba(255,255,255,0.5);
    --text-muted: rgba(255,255,255,0.3);
    --danger: #ff4757;
    --success: #2ed573;
    --font-pixel: 'Press Start 2P', monospace;
    --font-ui: 'Inter', -apple-system, sans-serif;
    --font-racing: 'Orbitron', monospace;
    --radius: 16px;
    --radius-sm: 10px;
}

html, body {
    width: 100%; height: 100%;
    overflow: hidden;
    background: var(--bg-darkest);
    color: var(--text);
    font-family: var(--font-ui);
    -webkit-user-select: none;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    overscroll-behavior: none;
    position: fixed;
    inset: 0;
}

.hidden { display: none !important; }

body, canvas, button, .touch-zone {
    -webkit-touch-callout: none;
}

/* ---- Screens (loading / start / gameover) ---- */
.screen {
    position: fixed; inset: 0; z-index: 100;
    display: flex; align-items: center; justify-content: center;
    background: linear-gradient(160deg, var(--bg-darkest) 0%, #0b1929 40%, var(--bg-dark) 100%);
}

.screen-content {
    text-align: center;
    padding: 24px 20px;
    max-width: 360px;
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
}

/* ---- Loading ---- */
.loader {
    width: 48px; height: 48px;
    border: 4px solid rgba(255,255,255,0.1);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin-bottom: 16px;
}
@keyframes spin { to { transform: rotate(360deg); } }

.loading-text {
    font-family: var(--font-pixel);
    font-size: 11px;
    color: var(--accent);
    letter-spacing: 3px;
    animation: pulse-text 1.5s ease-in-out infinite;
}
@keyframes pulse-text { 0%,100%{opacity:0.5} 50%{opacity:1} }

/* ---- Game Title ---- */
.game-title {
    font-family: var(--font-pixel);
    font-size: 38px;
    font-weight: 700;
    color: var(--accent);
    text-shadow: 0 0 40px var(--accent-glow), 4px 4px 0 rgba(0,0,0,0.4);
    line-height: 1.1;
}
.title-accent {
    display: block;
    font-size: 28px;
    color: white;
    margin-top: 4px;
    text-shadow: 0 0 20px rgba(255,255,255,0.15), 3px 3px 0 rgba(0,0,0,0.4);
}

.start-icon {
    margin: 12px 0;
    filter: drop-shadow(0 4px 20px rgba(247, 201, 72, 0.2));
}
.start-card-img {
    width: 140px;
    height: auto;
    border-radius: var(--radius);
    animation: car-bounce 2s ease-in-out infinite;
}
@keyframes car-bounce {
    0%,100% { transform: translateY(0) scale(1); }
    50% { transform: translateY(-6px) scale(1.03); }
}

.welcome-user {
    font-size: 13px;
    color: var(--text-dim);
    font-weight: 600;
    margin-bottom: 12px;
}

/* ---- Best Score Card (matches other games) ---- */
.best-score-card {
    background: var(--bg-card);
    border: 2px solid rgba(247, 201, 72, 0.2);
    border-radius: var(--radius);
    padding: 12px 20px;
    margin-bottom: 16px;
    width: 100%;
    max-width: 250px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.3);
}
.bsc-label {
    font-family: var(--font-pixel);
    font-size: 7px;
    color: var(--text-dim);
    letter-spacing: 2px;
    display: block;
    margin-bottom: 6px;
}
.bsc-value {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    font-family: var(--font-racing);
    font-size: 30px;
    font-weight: 900;
    color: var(--accent);
}

/* ---- How To Play ---- */
.how-to-play {
    display: flex;
    gap: 16px;
    margin-bottom: 20px;
    flex-wrap: wrap;
    justify-content: center;
}
.htp-tip {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    font-size: 11px;
    color: var(--text-dim);
    font-weight: 600;
}
.htp-icon { font-size: 22px; }

/* ---- Buttons ---- */
.btn-play {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    width: 100%;
    max-width: 260px;
    height: 54px;
    background: linear-gradient(135deg, var(--accent) 0%, #e6b800 100%);
    color: var(--bg-darkest);
    border: none;
    border-radius: var(--radius);
    font-family: var(--font-ui);
    font-size: 18px;
    font-weight: 900;
    cursor: pointer;
    text-transform: uppercase;
    letter-spacing: 1px;
    box-shadow: 0 4px 0 #c9a200, 0 6px 20px var(--accent-glow);
    transition: transform 0.1s, box-shadow 0.1s;
    margin-bottom: 10px;
}
.btn-play:active {
    transform: translateY(3px);
    box-shadow: 0 1px 0 #c9a200, 0 2px 10px var(--accent-glow);
}
.btn-play.pulse { animation: btn-pulse 2s ease-in-out infinite; }
@keyframes btn-pulse {
    0%,100% { box-shadow: 0 4px 0 #c9a200, 0 6px 20px var(--accent-glow); }
    50% { box-shadow: 0 4px 0 #c9a200, 0 6px 35px var(--accent-glow); }
}

.btn-secondary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    width: 100%;
    max-width: 260px;
    height: 44px;
    background: rgba(255,255,255,0.06);
    color: var(--text-dim);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: var(--radius-sm);
    font-family: var(--font-ui);
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
    text-decoration: none;
    transition: background 0.2s;
}
.btn-secondary:hover { background: rgba(255,255,255,0.1); }

/* ==================================================
   GAME WRAPPER — Forces landscape via CSS rotation
   
   When phone is portrait (tall > wide), we rotate the
   entire game container 90deg so the game always 
   renders in landscape. The player just tilts the 
   phone sideways — zero extra steps.
   ================================================== */
#game-wrapper {
    position: fixed;
    inset: 0;
    z-index: 10;
    overflow: hidden;
}

#game-container {
    position: absolute;
    top: 0; left: 0;
    width: 100%;
    height: 100%;
    background: #72D7EE;
}

#game-canvas {
    display: block;
    touch-action: none;
}

/* PORTRAIT MODE: rotate container to force landscape */
@media (orientation: portrait) {
    #game-container {
        /* Swap dimensions: width becomes viewport height, height becomes viewport width */
        width: 100vh;
        height: 100vw;
        /* Rotate 90deg clockwise */
        transform: rotate(90deg);
        /* Reposition: after rotation, origin is top-left, so translate to fit */
        transform-origin: top left;
        top: 0;
        left: 100vw;
    }
}

/* ---- HUD ---- */
#hud {
    position: absolute;
    top: 0; left: 0; right: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 12px;
    z-index: 20;
    pointer-events: none;
}
#hud > * { pointer-events: auto; }

.back-btn {
    font-family: var(--font-pixel);
    font-size: 8px;
    color: rgba(255,255,255,0.7);
    background: rgba(0,0,0,0.5);
    padding: 6px 10px;
    border-radius: 8px;
    letter-spacing: 1px;
    border: 1px solid rgba(255,255,255,0.15);
    cursor: pointer;
    transition: background 0.2s;
}
.back-btn:active { background: rgba(0,0,0,0.7); }

#time-display, #speed-display {
    background: rgba(0,0,0,0.6);
    border-radius: 8px;
    padding: 3px 10px;
    text-align: center;
}
.score-label {
    display: block;
    font-family: var(--font-pixel);
    font-size: 6px;
    color: rgba(255,255,255,0.5);
    letter-spacing: 1px;
}
.score-value {
    font-family: var(--font-racing);
    font-size: 18px;
    font-weight: 900;
    color: white;
}

/* Best time inline (inside time-display) */
.best-inline {
    display: none; /* hidden until populated by JS */
    font-family: var(--font-racing);
    font-size: 9px;
    font-weight: 600;
    color: var(--accent);
    letter-spacing: 0.5px;
    opacity: 0.85;
    margin-top: -1px;
}
.best-inline.visible {
    display: block;
}
#countdown-overlay {
    position: absolute; inset: 0;
    z-index: 50;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0,0,0,0.6);
    pointer-events: none;
}
#countdown-text {
    font-family: var(--font-pixel);
    font-size: 80px;
    font-weight: 900;
    color: var(--accent);
    text-shadow: 0 0 60px var(--accent-glow), 0 6px 0 rgba(0,0,0,0.5);
    animation: countdown-pulse 0.5s ease-out;
}
#countdown-text.go {
    color: var(--success);
    font-size: 50px;
    text-shadow: 0 0 40px rgba(46, 213, 115, 0.5), 0 4px 0 rgba(0,0,0,0.5);
    animation: countdown-bounce 0.5s ease-out;
}
@keyframes countdown-pulse {
    0% { transform: scale(1.5); opacity: 0; }
    100% { transform: scale(1); opacity: 1; }
}
@keyframes countdown-bounce {
    0% { transform: scale(0.5); opacity: 0; }
    50% { transform: scale(1.2); }
    100% { transform: scale(1); opacity: 1; }
}

/* ---- Final Lap ---- */
#final-lap-overlay {
    position: absolute; inset: 0;
    z-index: 40;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
}
.final-lap-text {
    font-family: var(--font-pixel);
    font-size: 18px;
    font-weight: 700;
    color: var(--accent);
    text-shadow: 0 0 30px var(--accent-glow);
    background: rgba(0,0,0,0.75);
    padding: 10px 24px;
    border-radius: 12px;
    border: 2px solid var(--accent);
    animation: final-lap-flash 0.6s ease-in-out infinite alternate;
}
@keyframes final-lap-flash {
    0% { opacity: 0.7; transform: scale(0.95); }
    100% { opacity: 1; transform: scale(1.05); }
}

/* ==================================================
   TOUCH CONTROLS — Full-width zones
   Bottom 40% of the (rotated) game container
   ================================================== */
#touch-controls {
    position: absolute;
    bottom: 0; left: 0; right: 0;
    height: 40%;
    display: flex;
    z-index: 25;
    pointer-events: none;
}
.touch-zone {
    flex: 1;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    padding-bottom: 16px;
    pointer-events: auto;
    -webkit-touch-callout: none;
    touch-action: none;
}
.touch-zone.active {
    background: rgba(255,255,255,0.08);
}
.zone-label {
    font-size: 28px;
    opacity: 0.25;
    pointer-events: none;
    transition: opacity 0.1s;
}
.touch-zone.active .zone-label { opacity: 0.7; }
.touch-zone-brake { flex: 0.6; }
.touch-zone-brake .zone-label { font-size: 20px; }

/* ---- Game Over ---- */
.gameover-wojak { margin-bottom: 8px; }
.gameover-wojak-img {
    width: 100px;
    height: auto;
    filter: drop-shadow(0 4px 20px rgba(0,0,0,0.5));
    animation: wojak-shake 0.5s ease-in-out;
}
@keyframes wojak-shake {
    0%,100% { transform: rotate(0); }
    20% { transform: rotate(-10deg); }
    40% { transform: rotate(10deg); }
    60% { transform: rotate(-5deg); }
    80% { transform: rotate(5deg); }
}

.gameover-title {
    font-family: var(--font-pixel);
    font-size: 22px;
    font-weight: 700;
    color: var(--danger);
    margin-bottom: 12px;
    text-shadow: 0 0 20px rgba(255, 71, 87, 0.3);
}

.achievement-banner {
    background: linear-gradient(135deg, var(--accent), #e6b800);
    color: var(--bg-darkest);
    font-family: var(--font-pixel);
    font-size: 9px;
    font-weight: 700;
    padding: 8px 20px;
    border-radius: 20px;
    margin-bottom: 12px;
    animation: achievement-glow 1.5s ease-in-out infinite;
}
@keyframes achievement-glow {
    0%,100% { box-shadow: 0 0 10px var(--accent-glow); }
    50% { box-shadow: 0 0 25px var(--accent-glow); }
}

.gameover-stats {
    display: flex;
    gap: 8px;
    width: 100%;
    margin-bottom: 12px;
}
.stat {
    flex: 1;
    background: var(--bg-card);
    border: 1px solid rgba(255,255,255,0.08);
    border-radius: var(--radius-sm);
    padding: 10px 8px;
    text-align: center;
}
.stat-label {
    display: block;
    font-size: 10px;
    color: var(--text-dim);
    font-weight: 700;
    margin-bottom: 4px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.stat-value {
    font-family: var(--font-racing);
    font-size: 22px;
    font-weight: 900;
    color: var(--accent);
}
.coins-value { color: var(--success); }

.last-lap-bar, .total-coins-bar {
    background: rgba(255,255,255,0.06);
    border: 1px solid rgba(255,255,255,0.08);
    border-radius: 20px;
    padding: 6px 16px;
    font-size: 12px;
    font-weight: 700;
    color: var(--text-dim);
    margin-bottom: 8px;
    width: 100%;
    max-width: 260px;
    text-align: center;
}
.total-coins-value {
    color: var(--accent);
    font-weight: 900;
}

/* ---- Sound Toggle (inside game-container) ---- */
#sound-toggle {
    position: fixed;
    top: 8px; right: 8px;
    z-index: 200;
    width: 32px; height: 32px;
    border-radius: 50%;
    border: 1px solid rgba(255,255,255,0.15);
    background: rgba(0,0,0,0.55);
    font-size: 14px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(4px);
}

/* ---- Responsive ---- */
@media (max-height: 600px) {
    .game-title { font-size: 30px; }
    .title-accent { font-size: 22px; }
    .start-car { font-size: 44px; margin: 8px 0; }
    .how-to-play { margin-bottom: 12px; }
}
