:root {
    --bg-dark: #0F1219;
    --primary: #64748B;
    --secondary: #94A3B8;
    --accent: #38BDF8;
    --text-main: #F8FAFC;
    --glass-bg: rgba(15, 18, 25, 0.7);
    --glass-border: rgba(56, 189, 248, 0.3);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    user-select: none;
    -webkit-user-select: none;
}

body, html {
    width: 100%;
    height: 100%;
    overflow: hidden;
    background-color: var(--bg-dark);
    font-family: 'Inter', sans-serif;
    color: var(--text-main);
    touch-action: none;
}

#game-container {
    position: relative;
    width: 100vw;
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
    background: var(--bg-dark);
}

/* Day/Night Cycle handled in JS via body class or canvas bg, 
   but we'll use layered parallax divs for the backdrop */

.parallax-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-size: cover;
    background-repeat: repeat-x;
    transform: translateZ(0); /* HW Accel */
    transition: filter 2s ease;
}

#bg-sky {
    background: linear-gradient(180deg, #0F1219 0%, #1e293b 100%);
    z-index: 0;
}

.day-mode #bg-sky {
    background: linear-gradient(180deg, #38BDF8 0%, #bae6fd 100%);
}

#bg-back {
    /* Mountains/City silhouette */
    background-image: 
        radial-gradient(circle at 50% 100%, rgba(56,189,248,0.1) 0%, transparent 50%),
        repeating-linear-gradient(90deg, transparent 0, transparent 50px, rgba(100,116,139,0.1) 50px, rgba(100,116,139,0.1) 100px);
    background-size: 200px 100%;
    z-index: 1;
    opacity: 0.5;
}

#bg-mid {
    /* Closer buildings */
    background-image: linear-gradient(0deg, #0F1219 0%, transparent 40%),
                      repeating-linear-gradient(90deg, #1e293b 0, #1e293b 80px, transparent 80px, transparent 150px);
    background-size: 300px 100%;
    background-position: 0 100%;
    z-index: 2;
}

#bg-front {
    /* Immediate background structures */
    background-image: linear-gradient(0deg, #0F1219 0%, transparent 20%),
                      repeating-linear-gradient(90deg, #334155 0, #334155 120px, transparent 120px, transparent 400px);
    background-size: 600px 100%;
    background-position: 0 100%;
    z-index: 3;
}

.day-mode .parallax-layer {
    filter: invert(0.8) hue-rotate(180deg) brightness(1.2);
}

canvas {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 10;
    /* Scaling logic handled in JS to maintain aspect ratio */
}

/* UI Overlay */
#ui-layer {
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    z-index: 20;
    pointer-events: none; /* Let clicks pass to menus/canvas */
}

.hidden { display: none !important; }

/* Menus */
.menu-screen {
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    background: rgba(15, 18, 25, 0.8);
    pointer-events: auto;
    backdrop-filter: blur(5px);
}

.glass-panel {
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    padding: 40px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5), inset 0 0 20px rgba(56, 189, 248, 0.1);
    backdrop-filter: blur(10px);
    max-width: 500px;
    width: 90%;
    color: var(--text-main);
}

.text-center { text-align: center; }
.mt-2 { margin-top: 10px; }
.mt-4 { margin-top: 20px; }

h1.glitch {
    font-size: 3rem;
    font-weight: 900;
    color: var(--accent);
    text-shadow: 0 0 10px var(--accent);
    margin-bottom: 20px;
    position: relative;
    letter-spacing: 2px;
}

h1.glitch::before, h1.glitch::after {
    content: attr(data-text);
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    background: var(--bg-dark);
}

h1.glitch::before {
    left: 2px;
    text-shadow: -1px 0 red;
    animation: glitch-anim-1 2s infinite linear alternate-reverse;
}

h1.glitch::after {
    left: -2px;
    text-shadow: -1px 0 blue;
    animation: glitch-anim-2 3s infinite linear alternate-reverse;
}

@keyframes glitch-anim-1 {
    0% { clip-path: inset(20% 0 80% 0); }
    20% { clip-path: inset(60% 0 10% 0); }
    40% { clip-path: inset(10% 0 50% 0); }
    60% { clip-path: inset(80% 0 5% 0); }
    80% { clip-path: inset(30% 0 40% 0); }
    100% { clip-path: inset(50% 0 30% 0); }
}

@keyframes glitch-anim-2 {
    0% { clip-path: inset(10% 0 60% 0); }
    20% { clip-path: inset(80% 0 5% 0); }
    40% { clip-path: inset(30% 0 20% 0); }
    60% { clip-path: inset(70% 0 10% 0); }
    80% { clip-path: inset(20% 0 50% 0); }
    100% { clip-path: inset(5% 0 80% 0); }
}

.subtitle {
    color: var(--secondary);
    font-size: 1.2rem;
    margin-bottom: 30px;
}

h2 {
    font-size: 2rem;
    color: var(--accent);
    margin-bottom: 20px;
    text-align: center;
    text-shadow: 0 0 5px var(--accent);
}

/* Buttons */
.btn {
    display: inline-block;
    padding: 12px 24px;
    border: none;
    border-radius: 8px;
    font-size: 1.1rem;
    font-weight: 700;
    cursor: pointer;
    font-family: inherit;
    transition: all 0.2s ease;
    text-transform: uppercase;
    letter-spacing: 1px;
    width: 100%;
    margin-bottom: 15px;
}

.btn.primary {
    background: var(--accent);
    color: #000;
    box-shadow: 0 0 15px rgba(56, 189, 248, 0.4);
}

.btn.primary:hover {
    box-shadow: 0 0 25px rgba(56, 189, 248, 0.8);
    transform: translateY(-2px) scale(1.02);
}

.btn.secondary {
    background: rgba(100, 116, 139, 0.2);
    color: var(--text-main);
    border: 1px solid var(--primary);
}

.btn.secondary:hover {
    background: rgba(100, 116, 139, 0.4);
    transform: translateY(-2px);
}

.menu-row {
    display: flex;
    gap: 10px;
}

/* HUD */
#hud {
    position: absolute;
    top: 20px; left: 20px; right: 20px;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
}

.hud-top {
    display: flex;
    gap: 20px;
}

.hud-stat {
    display: flex;
    flex-direction: column;
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    padding: 10px 15px;
    border-radius: 8px;
    backdrop-filter: blur(5px);
}

.hud-label {
    font-size: 0.7rem;
    color: var(--secondary);
    letter-spacing: 1px;
}

.hud-value {
    font-size: 1.4rem;
    font-weight: 900;
    color: var(--accent);
    text-shadow: 0 0 5px var(--accent);
}

#boss-ui {
    background: var(--glass-bg);
    border: 1px solid red;
    padding: 10px;
    border-radius: 8px;
    width: 200px;
    text-align: center;
    box-shadow: 0 0 15px rgba(255, 0, 0, 0.3);
}

.boss-health-bar {
    height: 10px;
    background: #333;
    border-radius: 5px;
    overflow: hidden;
    margin-bottom: 5px;
}

#boss-health-fill {
    height: 100%;
    width: 100%;
    background: red;
    transition: width 0.1s;
    box-shadow: 0 0 10px red;
}

.boss-label {
    font-size: 0.8rem;
    color: red;
    font-weight: bold;
    letter-spacing: 2px;
}

/* Stats / Skins Grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    margin: 20px 0;
}

.stat-box {
    background: rgba(255,255,255,0.05);
    padding: 15px 5px;
    border-radius: 8px;
    display: flex;
    flex-direction: column;
}

.stat-lbl { font-size: 0.7rem; color: var(--secondary); }
.stat-val { font-size: 1.2rem; font-weight: bold; color: var(--accent); }

.coins-total {
    text-align: center;
    font-size: 1.2rem;
    margin-bottom: 20px;
    color: #FEE440;
}

.grid-container {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    max-height: 300px;
    overflow-y: auto;
    padding-right: 5px;
}

.skin-card {
    background: rgba(255,255,255,0.05);
    border: 1px solid var(--primary);
    border-radius: 8px;
    padding: 15px;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s;
    position: relative;
    overflow: hidden;
}

.skin-card:hover { background: rgba(255,255,255,0.1); }
.skin-card.equipped { border-color: var(--accent); box-shadow: 0 0 10px var(--accent); }
.skin-card.locked { opacity: 0.6; }
.skin-card.locked::after {
    content: "🔒";
    position: absolute;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    font-size: 2rem;
}

#leaderboard-list {
    display: flex;
    flex-direction: column;
    gap: 5px;
    max-height: 250px;
    overflow-y: auto;
}

.lb-entry {
    display: flex;
    justify-content: space-between;
    padding: 10px;
    background: rgba(255,255,255,0.05);
    border-radius: 4px;
}
.lb-entry.highlight {
    background: rgba(56, 189, 248, 0.2);
    border-left: 3px solid var(--accent);
}

/* Screen FX */
#screen-flash {
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    background: white;
    opacity: 0;
    pointer-events: none;
    z-index: 50;
    transition: opacity 0.1s;
}

/* Mobile Controls */
#mobile-controls {
    position: absolute;
    bottom: 20px;
    left: 20px; right: 20px;
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    z-index: 30;
    pointer-events: none;
}

.dpad-left, .action-pad-right {
    pointer-events: auto;
    display: flex;
}

.action-row {
    display: flex;
    gap: 20px;
}

.control-btn {
    background: rgba(15, 18, 25, 0.5);
    border: 1px solid var(--glass-border);
    backdrop-filter: blur(5px);
    color: var(--accent);
    font-size: 24px;
    display: flex;
    justify-content: center;
    align-items: center;
    border-radius: 50%;
    box-shadow: 0 4px 15px rgba(0,0,0,0.5);
    outline: none;
}
.control-btn:active {
    background: rgba(56, 189, 248, 0.3);
    transform: scale(0.95);
}
.control-btn.circle { width: 70px; height: 70px; border-radius: 50%; }
.control-btn.square { width: 70px; height: 70px; border-radius: 12px; }

/* Floating Popups */
.floating-popup {
    position: absolute;
    color: #FEE440;
    font-weight: bold;
    font-size: 1.2rem;
    pointer-events: none;
    text-shadow: 0 0 5px rgba(0,0,0,0.8);
    animation: floatUp 1s ease-out forwards;
    z-index: 40;
}

@keyframes floatUp {
    0% { transform: translateY(0) scale(1); opacity: 1; }
    100% { transform: translateY(-50px) scale(1.5); opacity: 0; }
}

@media (min-width: 768px) {
    #mobile-controls { display: none !important; }
}
