:root {
    --bg: #0a0a0f;
    --card-bg: rgba(255,255,255,0.04);
    --border: rgba(255,255,255,0.15);
    --cyan: #00ffcc;
    --magenta: #bc13fe;
    --orange: #ff6600;
    --red: #ff2244;
    --gold: #ffd700;
    --text: #ffffff;
    --subtext: rgba(255,255,255,0.55);
    --header-h-desktop: 64px;
    --header-h-mobile: 56px;
}

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

html, body {
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
    font-family: 'Outfit', sans-serif;
    background: var(--bg);
    color: var(--text);
    touch-action: none;
}

.screen { 
    display: none; 
    flex-direction: column; 
    width: 100%; 
    height: 100%; 
}
.screen.active { display: flex; }

/* ==================== HUD HEADER ==================== */
.header {
    width: 100%;
    height: var(--header-h-desktop);
    background: rgba(12, 14, 20, 0.85);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border);
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    padding: 0 16px;
    z-index: 10;
    flex-shrink: 0;
    pointer-events: auto; /* Overriding previous pointer-events: none */
}

/* Left: Hub Button */
.nav-left { display: flex; align-items: center; min-width: 140px; }
.home-btn {
    text-decoration: none;
    color: var(--subtext);
    font-weight: 600;
    font-size: 0.85rem;
    padding: 8px 16px;
    border-radius: 10px;
    background: var(--card-bg);
    border: 1px solid var(--border);
    transition: all 0.2s;
    cursor: pointer;
    display: inline-block;
}
.home-btn:hover { color: var(--text); border-color: var(--cyan); }

/* Center: Level & Ink Info */
.header-center {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}
.header-title {
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--cyan);
    text-transform: uppercase;
    letter-spacing: 1px;
}
.level-ink-stack {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    width: 100%;
}
.level-info {
    font-size: clamp(11px, 2.5vw, 14px);
    font-weight: 700;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
}
.level-label {
    font-size: 9px;
    color: var(--subtext);
    text-transform: uppercase;
    margin-right: 4px;
    font-weight: 500;
}
#levelName { color: var(--cyan); }

.ink-info {
    display: flex;
    align-items: center;
    gap: 8px;
}
.ink-label { font-size: 9px; color: var(--subtext); font-weight: 700; }
.ink-bar-bg {
    width: 120px;
    height: 6px;
    background: rgba(255,255,255,0.1);
    border-radius: 3px;
    overflow: hidden;
}
.ink-bar {
    height: 100%;
    width: 100%;
    background: linear-gradient(90deg, var(--cyan), var(--magenta));
    transition: width 0.1s;
}

/* Right: Controls */
.header-right, .header-controls {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    min-width: 100px;
}
.icon-btn {
    width: 44px;
    height: 44px;
    border-radius: 10px;
    background: var(--card-bg);
    border: 1px solid var(--border);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 1.1rem;
    transition: all 0.2s;
}
.icon-btn:hover { border-color: var(--cyan); background: rgba(255,255,255,0.08); }
.icon-btn.hidden { display: none !important; }

/* ==================== SCREENS ==================== */
#screenMenu {
    background: radial-gradient(circle at 30% 20%, rgba(0,255,204,0.05) 0%, transparent 40%), var(--bg);
    padding-bottom: 40px;
    overflow-y: auto;
}
.game-title {
    margin-top: 40px;
    font-size: clamp(2rem, 8vw, 3.5rem);
    text-align: center;
    text-transform: uppercase;
    line-height: 1;
}
.game-title span { color: var(--cyan); font-weight: 700; }
.subtitle { color: var(--subtext); text-align: center; margin-top: 10px; font-size: 0.9rem; }

.level-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
    gap: 12px;
    width: 100%;
    max-width: 600px;
    margin: 30px auto;
    padding: 0 20px;
}
.level-card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 16px;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s;
}
.level-card:hover { border-color: var(--cyan); transform: translateY(-2px); }
.level-card.locked { opacity: 0.4; pointer-events: none; }
.lc-num { font-size: 1.2rem; font-weight: 700; color: var(--cyan); }
.lc-name { font-size: 0.7rem; color: var(--subtext); margin: 4px 0; }

/* ==================== GAME AREA ==================== */
.canvas-wrapper {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #000;
    position: relative;
    overflow: hidden;
}
#gameCanvas {
    max-width: 100%;
    max-height: 100%;
    cursor: crosshair;
}

.controls-bar {
    height: 64px;
    background: rgba(12, 14, 20, 0.9);
    border-top: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 0 10px;
    flex-shrink: 0;
    z-index: 10;
}
.ctrl-btn {
    padding: 8px 16px;
    border-radius: 10px;
    background: var(--card-bg);
    border: 1px solid var(--border);
    color: var(--text);
    font-weight: 600;
    font-size: 0.85rem;
    cursor: pointer;
    white-space: nowrap;
}
.ctrl-btn.active { background: rgba(0,255,204,0.15); border-color: var(--cyan); color: var(--cyan); }
.ctrl-btn.play-active { background: rgba(0,255,100,0.15); border-color: #00ff88; color: #00ff88; }
.hint-btn { border-color: var(--gold); color: var(--gold); }

/* ==================== OVERLAYS ==================== */
.overlay {
    position: absolute;
    inset: 0;
    background: rgba(10,10,15,0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    backdrop-filter: blur(8px);
}
.overlay.hidden { display: none; }
.overlay-box {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 24px;
    padding: 30px;
    text-align: center;
    width: 90%;
    max-width: 320px;
}
.btn {
    padding: 12px;
    border-radius: 12px;
    border: none;
    font-weight: 700;
    cursor: pointer;
    width: 100%;
    margin-top: 10px;
}
.btn.primary { background: var(--cyan); color: #000; }
.btn.secondary { background: var(--card-bg); border: 1px solid var(--border); color: #fff; }

/* ==================== MOBILE ==================== */
@media (max-width: 600px) {
    .header {
        height: var(--header-h-mobile);
        grid-template-columns: auto 1fr auto;
        padding: 0 10px;
    }
    .nav-left { min-width: 80px; }
    .header-right { min-width: 80px; }
    .home-btn { padding: 6px 10px; font-size: 0.75rem; }
    .home-btn::before { content: '←'; }
    .home-btn { font-size: 0; }
    .home-btn::after { content: ' Hub'; font-size: 0.75rem; }

    .ink-bar-bg { width: 80px; }
    
    .icon-btn { width: 40px; height: 40px; font-size: 1rem; }
    
    .controls-bar {
        height: 56px;
        gap: 6px;
    }
    .ctrl-btn { padding: 6px 8px; font-size: 11px; }
}
