/* ============================================
   ZCAT Racer — UI homologada con Flappy ZCAT / Survival
   
   Screens (loading, home, gameover) use ZCAT neobrutalism.
   Gameplay (HUD, canvas, touch, countdown) keeps its own theme.
   ============================================ */

/* ============================================
   ZCAT DESIGN TOKENS
   ============================================ */
:root {
    /* ZCAT Design System — shared with Flappy & Survival */
    --bg-dark: #f0f2f5;
    --bg-card: #ffffff;
    --bg-cream: #FFFDF0;
    --bg-pink: #FFF0F3;
    --border-charcoal: #2D3748;
    --ton-blue: #0098EA;
    --cute-pink: #FF6B8B;
    --cute-yellow: #FFD166;
    --text-primary: #2D3748;
    --text-secondary: rgba(45, 55, 72, 0.8);
    --text-muted: rgba(45, 55, 72, 0.5);
    --font-display: 'Fredoka', system-ui, -apple-system, sans-serif;
    --font-sans: 'Quicksand', system-ui, -apple-system, sans-serif;

    /* Gameplay-only tokens (HUD, countdown, etc.) */
    --game-bg: #04080f;
    --game-accent: #f7c948;
    --game-accent-glow: rgba(247, 201, 72, 0.3);
    --game-text: #e8edf3;
    --game-text-dim: rgba(255,255,255,0.5);
    --game-danger: #ff4757;
    --game-success: #2ed573;
    --font-pixel: 'Press Start 2P', monospace;
    --font-racing: 'Orbitron', monospace;
    --font-ui: 'Inter', -apple-system, sans-serif;
    --radius: 16px;
    --radius-sm: 10px;
}

/* ============================================
   BASE / RESET
   ============================================ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
    width: 100%; height: 100%;
    overflow: hidden;
    background: var(--bg-dark);
    font-family: var(--font-sans);
    color: var(--text-primary);
    -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;
}

/* ============================================
   OVERLAYS — ZCAT neobrutalism system
   ============================================ */
.zcat-overlay {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(45, 55, 72, 0.55);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    animation: fadeIn 0.25s ease;
}

.zcat-overlay.hidden {
    display: none !important;
}

/* Home overlay is opaque to hide the canvas during load */
#start-screen {
    background: var(--bg-dark);
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
}

.overlay-content {
    text-align: center;
    padding: 20px;
    max-width: 360px;
    width: 95%;
}

/* Meme card — neobrutalism matching Flappy/Survival */
.meme-card {
    background: var(--bg-card);
    border: 4px solid var(--border-charcoal);
    border-radius: 32px;
    box-shadow: 8px 8px 0px var(--border-charcoal);
    padding: 22px 20px 18px;
    position: relative;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    align-items: center;
}

/* ============================================
   LOADING SCREEN — light web style
   ============================================ */
#loading-screen {
    background: var(--bg-cream);
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
}

.loading-spinner {
    width: 48px;
    height: 48px;
    border: 4px solid var(--bg-pink);
    border-top-color: var(--ton-blue);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin-bottom: 16px;
}
@keyframes spin { to { transform: rotate(360deg); } }

.loading-text {
    font-family: var(--font-display);
    font-size: 16px;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: 0.5px;
}

/* ============================================
   HOME SCREEN — game title & card
   ============================================ */
.game-title {
    font-family: var(--font-display);
    font-size: 36px;
    font-weight: 900;
    line-height: 1.1;
    color: var(--text-primary);
    margin-bottom: 14px;
}

.title-highlight {
    color: var(--ton-blue);
    display: inline-block;
    transform: rotate(-2deg);
    background: var(--bg-pink);
    padding: 2px 12px;
    border: 3px solid var(--border-charcoal);
    border-radius: 12px;
    margin-top: 4px;
    box-shadow: 2px 2px 0px var(--border-charcoal);
}

.wojak-preview {
    margin: 8px 0 14px;
    animation: float 2.5s ease-in-out infinite;
}

.wojak-preview-img {
    width: 72px;
    height: 72px;
    border-radius: 22px;
    border: 4px solid var(--border-charcoal);
    box-shadow: 4px 4px 0px var(--border-charcoal);
    object-fit: cover;
    object-position: center top;
    background: var(--bg-cream);
}

.welcome-user {
    font-family: var(--font-display);
    font-size: 13px;
    font-weight: 700;
    color: var(--text-secondary);
    margin-bottom: 12px;
    background: var(--bg-pink);
    display: inline-block;
    padding: 6px 14px;
    border-radius: 99px;
    border: 2px solid var(--border-charcoal);
}

/* Best Score Card */
.best-score-card {
    background: var(--bg-cream);
    border: 3px solid var(--border-charcoal);
    border-radius: 20px;
    padding: 10px 16px;
    margin-bottom: 14px;
    width: 100%;
    max-width: 250px;
    display: inline-block;
    box-shadow: 3px 3px 0px var(--border-charcoal);
}

.bsc-label {
    font-family: var(--font-display);
    font-size: 11px;
    font-weight: 700;
    color: var(--text-secondary);
    letter-spacing: 0.5px;
    display: block;
    margin-bottom: 2px;
}

.bsc-value {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    font-family: var(--font-display);
    font-size: 26px;
    font-weight: 900;
    color: var(--cute-pink);
}

/* How To Play */
.how-to-play {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin: 0 0 14px;
    align-items: center;
    width: 100%;
}

.htp-tip {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 14px;
    background: var(--bg-pink);
    border: 2px solid var(--border-charcoal);
    border-radius: 14px;
    font-size: 13px;
    color: var(--text-primary);
    font-weight: 700;
    width: 90%;
    max-width: 270px;
    text-align: left;
    box-shadow: 2px 2px 0px var(--border-charcoal);
    font-family: var(--font-sans);
}

.htp-icon {
    font-size: 18px;
    flex-shrink: 0;
}

/* ============================================
   BUTTONS — matching neobrutalism
   ============================================ */
.game-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 13px 28px;
    font-family: var(--font-display);
    font-size: 16px;
    font-weight: 800;
    color: var(--text-primary);
    background: #ffffff;
    border: 4px solid var(--border-charcoal);
    border-radius: 20px;
    cursor: pointer;
    transition: all 0.1s ease;
    box-shadow: 4px 4px 0px var(--border-charcoal);
    margin: 5px;
    width: 90%;
    max-width: 260px;
    text-decoration: none;
}

.game-btn:active {
    transform: translate(2px, 2px);
    box-shadow: 2px 2px 0px var(--border-charcoal);
}

.game-btn.primary-ton {
    background: var(--cute-yellow);
    box-shadow: 4px 4px 0px var(--border-charcoal);
}

.game-btn.secondary {
    background: #ffffff;
    border: 3px solid var(--border-charcoal);
    box-shadow: 3px 3px 0px var(--border-charcoal);
    font-size: 14px;
    border-radius: 16px;
    padding: 10px 20px;
}

.game-btn.secondary:active {
    transform: translate(1px, 1px);
    box-shadow: 2px 2px 0px var(--border-charcoal);
}

.game-btn.pulse {
    animation: btnPulse 2s infinite;
}

/* ============================================
   GAME OVER / RACE COMPLETE SCREENS
   ============================================ */
.gameover-wojak {
    margin-bottom: 14px;
    animation: wobble 1s ease-in-out;
}

.gameover-wojak-img {
    width: 90px;
    height: 90px;
    border-radius: 28px;
    border: 4px solid var(--border-charcoal);
    object-fit: cover;
    box-shadow: 4px 4px 0px var(--border-charcoal);
}

.gameover-title {
    font-family: var(--font-display);
    font-size: 38px;
    font-weight: 900;
    color: var(--cute-pink);
    margin-bottom: 18px;
}

.gameover-stats {
    display: flex;
    justify-content: center;
    gap: 8px;
    margin-bottom: 14px;
    width: 100%;
}

.stat {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: 10px 6px;
    background: var(--bg-cream);
    border: 3px solid var(--border-charcoal);
    border-radius: 18px;
    flex: 1;
    min-width: 62px;
    box-shadow: 2px 2px 0px var(--border-charcoal);
}

.stat-label {
    font-size: 9px;
    color: var(--text-secondary);
    text-transform: uppercase;
    font-weight: 700;
    font-family: var(--font-display);
    letter-spacing: 0.5px;
}

.stat-value {
    font-family: var(--font-display);
    font-size: 18px;
    font-weight: 900;
    color: var(--text-primary);
    white-space: nowrap;
}

.stat-value.coins-value {
    color: var(--cute-pink);
}

.total-coins-bar {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px 18px;
    background: var(--bg-pink);
    border: 3px dashed var(--border-charcoal);
    border-radius: 16px;
    font-size: 13px;
    color: var(--text-primary);
    font-weight: 700;
    margin-bottom: 14px;
    font-family: var(--font-sans);
}

.total-coins-value {
    font-family: var(--font-display);
    font-weight: 900;
    color: var(--cute-pink);
}

.achievement-banner {
    background: var(--cute-yellow);
    border: 3px solid var(--border-charcoal);
    padding: 10px 16px;
    border-radius: 14px;
    margin-bottom: 16px;
    font-family: var(--font-display);
    font-size: 13px;
    font-weight: 900;
    color: var(--text-primary);
    animation: achievementPop 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    box-shadow: 3px 3px 0px var(--border-charcoal);
}

/* ==================================================
   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;
    }
}

/* ============================================
   IN-GAME HUD — keeps dark racing theme
   ============================================ */
#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(--game-accent);
    letter-spacing: 0.5px;
    opacity: 0.85;
    margin-top: -1px;
}
.best-inline.visible {
    display: block;
}

/* ============================================
   COUNTDOWN OVERLAY (in-game)
   ============================================ */
#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(--game-accent);
    text-shadow: 0 0 60px var(--game-accent-glow), 0 6px 0 rgba(0,0,0,0.5);
    animation: countdown-pulse 0.5s ease-out;
}
#countdown-text.go {
    color: var(--game-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(--game-accent);
    text-shadow: 0 0 30px var(--game-accent-glow);
    background: rgba(0,0,0,0.75);
    padding: 10px 24px;
    border-radius: 12px;
    border: 2px solid var(--game-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; }

/* ---- 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);
}

/* ============================================
   ANIMATIONS
   ============================================ */
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes float {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-8px); }
}

@keyframes wobble {
    0%, 100% { transform: rotate(-2deg); }
    50% { transform: rotate(2deg); }
}

@keyframes btnPulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.02); }
}

@keyframes achievementPop {
    0% { transform: scale(0.7); opacity: 0; }
    100% { transform: scale(1); opacity: 1; }
}

/* ---- Responsive ---- */
@media (max-height: 600px) {
    .game-title { font-size: 28px; }
    .wojak-preview-img { width: 80px; max-height: 80px; }
    .how-to-play { margin-bottom: 10px; }
}
