:root {
    --bg: #F0E6D3;
    --ink: #1A1A2E;
    --teal: #00E5C8;
    --gold: #FFB800;
    --coral: #FF4757;
    --violet: #7C3AED;
    --panel: rgba(255, 248, 240, 0.93);
    --border: 2.5px solid #1A1A2E;
    --shadow: 3px 3px 0px #1A1A2E;
    --radius: 10px;
}
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }
html, body {
    width: 100%; height: 100%; overflow: hidden;
    font-family: 'Chakra Petch', sans-serif;
    background: var(--bg);
    color: var(--ink);
}
canvas { display: block; position: fixed; inset: 0; z-index: 0; }

/* ---- SCREENS ---- */
.screen {
    position: fixed; inset: 0; z-index: 500;
    display: none; flex-direction: column;
    align-items: center; justify-content: center;
    background: rgba(240, 230, 211, 0.88);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
}
.screen.active { display: flex; }

#title-screen .game-title {
    font-family: 'Bungee Shade', cursive;
    font-size: clamp(2.5rem, 7vw, 5.5rem);
    color: var(--teal);
    text-shadow: 3px 3px 0px var(--ink);
    letter-spacing: 2px;
    margin-bottom: 12px;
    animation: titlePulse 2.5s ease-in-out infinite;
}
@keyframes titlePulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.03); }
}
#title-screen .subtitle {
    font-size: 1.15rem; font-weight: 600;
    color: var(--ink); opacity: 0.7;
    margin-bottom: 36px; text-align: center;
    max-width: 400px; padding: 0 20px;
}
#title-screen .high-info {
    font-family: 'Share Tech Mono', monospace;
    font-size: 0.9rem; color: var(--violet);
    margin-top: 18px; opacity: 0.8;
}

/* ---- BUTTONS ---- */
.neo-btn {
    display: inline-block;
    padding: 14px 36px;
    font-family: 'Chakra Petch', sans-serif;
    font-size: 1.1rem; font-weight: 700;
    color: var(--ink);
    background: var(--teal);
    border: var(--border);
    border-radius: 8px;
    box-shadow: var(--shadow);
    cursor: pointer;
    transition: transform 0.08s, box-shadow 0.08s;
    text-transform: uppercase;
    letter-spacing: 1px;
}
.neo-btn:hover { transform: translate(-1px, -1px); box-shadow: 5px 5px 0px var(--ink); }
.neo-btn:active { transform: translate(2px, 2px); box-shadow: 1px 1px 0px var(--ink); }
.neo-btn.danger { background: var(--coral); color: #fff; }
.neo-btn.gold { background: var(--gold); }

/* ---- LEVEL INTRO ---- */
#level-intro {
    background: rgba(26, 26, 46, 0.92);
    color: #fff;
}
#level-intro .lvl-num {
    font-family: 'Bungee Shade', cursive;
    font-size: clamp(3rem, 10vw, 7rem);
    color: var(--teal);
    text-shadow: 3px 3px 0px rgba(0,0,0,0.4);
}
#level-intro .lvl-name {
    font-size: 1.5rem; font-weight: 700;
    margin-top: 8px; color: var(--gold);
    text-transform: uppercase; letter-spacing: 3px;
}

/* ---- LEVEL COMPLETE ---- */
#level-complete .stars {
    font-size: 3.5rem; margin: 16px 0;
    filter: drop-shadow(2px 2px 0px var(--ink));
}
#level-complete .stars span {
    display: inline-block;
    animation: starPop 0.4s ease backwards;
}
#level-complete .stars span:nth-child(2) { animation-delay: 0.15s; }
#level-complete .stars span:nth-child(3) { animation-delay: 0.3s; }
@keyframes starPop {
    0% { transform: scale(0) rotate(-30deg); opacity: 0; }
    100% { transform: scale(1) rotate(0); opacity: 1; }
}
#level-complete .score-line {
    font-family: 'Share Tech Mono', monospace;
    font-size: 1.3rem; margin: 6px 0;
}
.complete-title {
    font-family: 'Bungee Shade', cursive;
    font-size: 2.2rem; color: var(--teal);
    text-shadow: 2px 2px 0px var(--ink);
    margin-bottom: 8px;
}

/* ---- GAME OVER ---- */
#game-over .go-title {
    font-family: 'Bungee Shade', cursive;
    font-size: 2.8rem; color: var(--coral);
    text-shadow: 3px 3px 0px var(--ink);
    margin-bottom: 10px;
}
#game-over .go-sub {
    font-size: 1.1rem; font-weight: 600;
    margin-bottom: 28px; opacity: 0.7;
}

/* ---- HUD ---- */
#hud {
    position: fixed; z-index: 100;
    top: 0; left: 0; right: 0;
    display: none;
    padding: 12px 18px;
    pointer-events: none;
}
#hud.active { display: flex; justify-content: space-between; align-items: flex-start; }
.hud-panel {
    background: var(--panel);
    border: 2px solid var(--ink);
    border-radius: 8px;
    box-shadow: 2px 2px 0px rgba(26,26,46,0.45);
    padding: 6px 14px;
    font-weight: 700; font-size: 0.95rem;
}
.hud-left { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.hud-right { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
#hud-lives { color: var(--coral); font-size: 1.2rem; letter-spacing: 2px; }
#hud-crystals { color: var(--gold); }
#hud-score { font-family: 'Share Tech Mono', monospace; color: var(--violet); }
#hud-level { color: var(--teal); text-transform: uppercase; letter-spacing: 1px; }

/* ---- GRAVITY INDICATOR ---- */
#grav-indicator {
    position: fixed; bottom: 18px; left: 50%;
    transform: translateX(-50%);
    z-index: 100; pointer-events: none;
    transition: transform 0.3s cubic-bezier(.4,2,.6,1);
    display: none;
}
#grav-indicator.active { display: block; }
#grav-indicator svg { width: 36px; height: 36px; }
#grav-indicator.flipped { transform: translateX(-50%) rotate(180deg); }

/* ---- TUTORIAL HINT ---- */
#tutorial-hint {
    position: fixed; bottom: 70px; left: 50%;
    transform: translateX(-50%);
    z-index: 120; pointer-events: none;
    text-align: center;
    background: var(--panel);
    border: var(--border);
    border-radius: 10px;
    box-shadow: var(--shadow);
    padding: 10px 24px;
    font-weight: 700; font-size: 1rem;
    max-width: 420px;
    opacity: 0; transition: opacity 0.4s;
    white-space: pre-line;
}
#tutorial-hint.show { opacity: 1; }

/* ---- FLOATING TEXT ---- */
.float-text {
    position: fixed; z-index: 110;
    pointer-events: none;
    font-family: 'Chakra Petch', sans-serif;
    font-weight: 700; font-size: 1.4rem;
    text-shadow: 2px 2px 0px rgba(26,26,46,0.4);
}

/* ---- DAMAGE FLASH ---- */
#damage-flash {
    position: fixed; inset: 0; z-index: 200;
    background: rgba(255, 71, 87, 0.35);
    pointer-events: none;
    opacity: 0; transition: opacity 0.12s;
}
#damage-flash.show { opacity: 1; }

/* ---- PORTAL LABELS ---- */
.portal-label {
    position: fixed;
    z-index: 110;
    pointer-events: none;
    font-family: 'Bungee Shade', cursive;
    font-size: 1rem;
    color: var(--teal);
    text-shadow: 2px 2px 0px var(--ink);
    text-transform: uppercase;
    text-align: center;
    transform: translate(-50%, -50%);
    white-space: nowrap;
    padding: 4px 12px;
    background: rgba(26, 26, 46, 0.4);
    border-radius: 4px;
    animation: labelFloat 2s ease-in-out infinite;
}

@keyframes labelFloat {
    0%, 100% { transform: translate(-50%, -60%); }
    50% { transform: translate(-50%, -80%); }
}

.portal-label.vibe-jam {
    color: #FFD700;
    font-size: 1.2rem;
    background: rgba(124, 58, 237, 0.3);
    border: 1px solid rgba(255, 215, 0, 0.5);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}

/* ======================================================= */
/* ---- MOBILE TOUCH CONTROLS ---- */
/* ======================================================= */

/* Prevent rubber-banding / pull-to-refresh on mobile */
html, body {
    overscroll-behavior: none;
    touch-action: none;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
}

#touch-controls {
    display: none; /* hidden by default, shown via JS on touch devices */
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 300;
    padding: 0 env(safe-area-inset-right) calc(12px + env(safe-area-inset-bottom)) env(safe-area-inset-left);
    pointer-events: none;
}
#touch-controls.active {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
}

.touch-zone {
    pointer-events: auto;
}

/* ---- D-Pad ---- */
#dpad {
    display: flex;
    gap: 10px;
    padding: 12px 16px;
}
.dpad-btn {
    width: 68px;
    height: 68px;
    border-radius: 50%;
    border: 2.5px solid var(--ink);
    background: rgba(255, 248, 240, 0.82);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    box-shadow: 2px 2px 0px rgba(26,26,46,0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--ink);
    cursor: pointer;
    transition: transform 0.06s, background 0.06s, box-shadow 0.06s;
    -webkit-tap-highlight-color: transparent;
}
.dpad-btn svg {
    width: 30px;
    height: 30px;
}
.dpad-btn.pressed,
.dpad-btn:active {
    transform: scale(0.92) translate(1px, 1px);
    background: var(--teal);
    color: #fff;
    box-shadow: 0px 0px 0px rgba(26,26,46,0.4);
}

/* ---- Flip Button ---- */
.flip-btn {
    width: 88px;
    height: 88px;
    border-radius: 50%;
    border: 3px solid var(--ink);
    background: rgba(0, 229, 200, 0.75);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    box-shadow: 3px 3px 0px rgba(26,26,46,0.45);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    color: var(--ink);
    cursor: pointer;
    margin: 0 16px 12px 0;
    transition: transform 0.06s, background 0.06s, box-shadow 0.06s;
    -webkit-tap-highlight-color: transparent;
}
.flip-btn svg {
    width: 28px;
    height: 28px;
}
.flip-btn span {
    font-family: 'Chakra Petch', sans-serif;
    font-size: 0.65rem;
    font-weight: 700;
    letter-spacing: 1px;
    text-transform: uppercase;
}
.flip-btn.pressed,
.flip-btn:active {
    transform: scale(0.9) translate(2px, 2px);
    background: rgba(0, 229, 200, 1);
    box-shadow: 0px 0px 0px rgba(26,26,46,0.4);
}

/* ======================================================= */
/* ---- MOBILE RESPONSIVE ---- */
/* ======================================================= */

@media (max-width: 768px) {
    #title-screen .game-title {
        font-size: clamp(1.8rem, 9vw, 3.5rem);
    }
    #title-screen .subtitle {
        font-size: 0.95rem;
        margin-bottom: 24px;
        padding: 0 16px;
    }
    .neo-btn {
        padding: 12px 28px;
        font-size: 1rem;
    }
    #hud {
        padding: 8px 10px;
    }
    .hud-panel {
        padding: 4px 10px;
        font-size: 0.8rem;
    }
    #hud-lives {
        font-size: 1rem;
    }
    #level-intro .lvl-num {
        font-size: clamp(2.5rem, 12vw, 5rem);
    }
    #level-intro .lvl-name {
        font-size: 1.1rem;
    }
    .complete-title {
        font-size: 1.6rem;
    }
    #game-over .go-title {
        font-size: 2rem;
    }
    #level-complete .stars {
        font-size: 2.5rem;
    }
    #level-complete .score-line {
        font-size: 1rem;
    }
    #grav-indicator {
        bottom: 110px; /* above touch controls */
    }
    #tutorial-hint {
        bottom: 130px; /* above touch controls */
        font-size: 0.85rem;
        padding: 8px 16px;
        max-width: 320px;
    }
    .portal-label {
        font-size: 0.8rem;
    }
    .portal-label.vibe-jam {
        font-size: 0.95rem;
    }
}

@media (max-width: 420px) {
    #title-screen .game-title {
        font-size: clamp(1.4rem, 10vw, 2.6rem);
    }
    .neo-btn {
        padding: 10px 22px;
        font-size: 0.9rem;
    }
    .dpad-btn {
        width: 58px;
        height: 58px;
    }
    .dpad-btn svg {
        width: 24px;
        height: 24px;
    }
    .flip-btn {
        width: 74px;
        height: 74px;
    }
    .flip-btn svg {
        width: 22px;
        height: 22px;
    }
    .flip-btn span {
        font-size: 0.55rem;
    }
    .hud-panel {
        padding: 3px 8px;
        font-size: 0.72rem;
    }
    .hud-left, .hud-right {
        gap: 6px;
    }
}

/* Landscape small-height optimization */
@media (max-height: 500px) {
    #title-screen .game-title {
        font-size: clamp(1.6rem, 6vw, 2.8rem);
        margin-bottom: 6px;
    }
    #title-screen .subtitle {
        font-size: 0.8rem;
        margin-bottom: 14px;
    }
    .dpad-btn {
        width: 54px;
        height: 54px;
    }
    .flip-btn {
        width: 68px;
        height: 68px;
        margin-bottom: 6px;
    }
    #dpad {
        padding: 6px 12px;
    }
    #grav-indicator {
        bottom: 90px;
    }
    #tutorial-hint {
        bottom: 100px;
    }
}
