:root {
    --bg-color: #111;
    --ui-color: rgba(255, 255, 255, 0.8);
}

body, html {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    background-color: var(--bg-color);
    overflow: hidden;
    font-family: 'Courier New', Courier, monospace;
    user-select: none;
    -webkit-user-select: none;
}

#game-container {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
}

/* 
   The canvas wrapper ensures the aspect ratio is respected 
   while the canvas inside is low-res and scaled up.
*/
#canvas-wrapper {
    position: relative;
    width: 100%;
    height: 100%;
    max-width: 56.25vh; /* 9:16 aspect ratio constraint based on height */
    background: #000;
    box-shadow: 0 0 20px rgba(0,0,0,0.5);
}

#canvas-wrapper canvas {
    display: block;
    width: 100%;
    height: 100%;
    /* CRITICAL FOR PS1 LOOK: Keep pixels sharp when scaling up */
    image-rendering: -moz-crisp-edges;
    image-rendering: -webkit-crisp-edges;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
}

#ui-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: auto; /* Allow UI children to receive touches on Android WebViews */
}


/* HUD (bitmap/strip assets) */
/* HUD (bitmap/strip assets) */
#hud {
    position: absolute;
    top: 10px;
    left: 10px; /* Align Left */
    transform: none; /* Remove center transform */
    z-index: 1500;
    pointer-events: none;
    display: flex;
    flex-direction: column; /* Stack bar and text */
    align-items: flex-start; /* Align children left */
}

#hp-text {
    margin-top: 4px;
    margin-left: 2px;
    height: 24px; /* Reserve space */
    display: block;
    /* Fallback font styles if bitmap fails */
    color: #fff;
    font-size: 20px;
    font-weight: bold;
    text-shadow: 2px 2px 0 #000;
}

#hp-bar {
    display: block;
    width: auto;
    height: auto;
    image-rendering: -moz-crisp-edges;
    image-rendering: -webkit-crisp-edges;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
}

/* Bitmap font canvases */
.bitmap-text-canvas {
    display: block;
    image-rendering: -moz-crisp-edges;
    image-rendering: -webkit-crisp-edges;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
    pointer-events: none;
}

#debug-info {
    position: absolute;
    top: 75px;
    left: 10px;
    color: #fff;
    font-size: 12px;
    text-shadow: 1px 1px 0 #000;
    pointer-events: none;
}

#wave-announcement {
    position: absolute;
    top: 35%;
    left: 0;
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    pointer-events: none;
    opacity: 0;
    transform: scale(0.5);
    transition: opacity 0.3s, transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    z-index: 999;
z-index: 999;
    letter-spacing: 4px;
}

#wave-announcement.visible {
    opacity: 1;
    transform: scale(1.0);
}
/* Controls Layout */
/* Controls Layout */
#left-touch-zone {
    position: absolute;
    top: 0;
    left: 0;
    width: 50%;
    height: 100%;
    z-index: 10;
    touch-action: none;
    pointer-events: auto; /* CRITICAL: Re-enable events blocked by #ui-layer */
    /* Debug visualization (optional, keep transparent for prod) */
    /* background: rgba(255, 0, 0, 0.1); */ 
}

#joystick-visual {
    position: absolute;
    width: 120px;
    height: 120px;
    border: 2px dashed rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    pointer-events: none;
    display: none; /* Hidden until touched */
    box-sizing: border-box;
}

#joystick-knob {
    width: 50px;
    height: 50px;
    background: rgba(255, 255, 255, 0.5);
    border-radius: 50%;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    box-shadow: 0 0 10px rgba(255,255,255,0.2);
}
#controls-right {
    position: absolute;
    bottom: 20px;
    right: 20px;
    width: 240px;
    height: 220px;
    pointer-events: none; /* Container passes events, buttons catch them */
    /* 3D Context */
    perspective: 1000px;
    z-index: 1000;
}

.btn-group {
    position: relative;
    width: 100%;
    height: 100%;
    pointer-events: auto;
    transform-style: preserve-3d;
    /* Default Persona-ish Angle */
    transform: rotateX(15deg) rotateY(-15deg) rotateZ(5deg);
    /* Entrance Animation */
    animation: p5-ui-slam 0.8s cubic-bezier(0.22, 1, 0.36, 1) forwards;
    animation-delay: 0.5s; /* Wait for load */
    opacity: 0; /* Start hidden */
}

@keyframes p5-ui-slam {
    0% {
        opacity: 0;
        transform: translate3d(100px, 100px, 200px) rotateX(40deg) rotateY(-40deg) scale(1.5);
    }
    60% {
        opacity: 1;
        transform: translate3d(-10px, -10px, 0) rotateX(10deg) rotateY(-10deg) scale(0.95);
    }
    100% {
        opacity: 1;
        /* This final state will be overridden by inline styles from DevTools if used */
        transform: rotateX(15deg) rotateY(-15deg) rotateZ(5deg) scale(1.0);
    }
}
.action-btn {
    position: absolute;
    background-color: transparent;
    border: none;
    border-radius: 0;
    color: transparent;
    display: block;
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
    touch-action: manipulation;
    backdrop-filter: none;
    font-size: 0;
    /* Herculean Bounce Back Animation */
    transition: transform 0.35s cubic-bezier(0.175, 0.885, 0.32, 1.6), filter 0.2s;
    image-rendering: -moz-crisp-edges;
    image-rendering: -webkit-crisp-edges;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
}

.action-btn:active, .action-btn.pressed {
    /* Instant Impact */
    transition: transform 0.03s ease-out, filter 0.03s;
    transform: scale(0.82) translateY(5px);
    filter: brightness(1.4) contrast(1.15) drop-shadow(0 0 8px rgba(255, 255, 255, 0.5));
}

/* Attack: x0 y10 w60 h62 -> 2x: x0 y20 w120 h124 */
#btn-attack {
    left: 0px;
    top: 20px;
    width: 120px;
    height: 124px;
    background-image: url('https://i.postimg.cc/9QQ67HyP/1attack.png');
    border: none;
    z-index: 50; /* 1attack.png - Top Layer */
}

/* Jump: x13 y60 w52 h37 -> 2x: x26 y120 w104 h74 */
#btn-jump {
    left: 26px;
    top: 120px;
    width: 104px;
    height: 74px;
    background-image: url('https://i.postimg.cc/GmmWynvz/2jump.png');
    border: none;
    z-index: 20; /* 2jump.png - 4th Layer */
}

/* Dash: x56 y0 w53 h39 -> 2x: x112 y0 w106 h78 */
#btn-dodge {
    left: 112px;
    top: 0px;
    width: 106px;
    height: 78px;
    background-image: url('https://i.postimg.cc/kgg0bPWT/3dash.png');
    border: none;
    z-index: 40; /* 3dash.png - 2nd Layer */
}

/* Lock: x55 y34 w43 h29 -> 2x: x110 y68 w86 h58 */
#btn-lockon {
    left: 110px;
    top: 68px;
    width: 86px;
    height: 58px;
    background-image: url('https://i.postimg.cc/FHHMLX0P/4lockon.png');
    border: none;
    z-index: 30; /* 4lockon.png - 3rd Layer */
}

/* Block: x42 y53 w56 h42 -> 2x: x84 y106 w112 h84 */
#btn-guard {
    left: 84px;
    top: 106px;
    width: 112px;
    height: 84px;
    background-image: url('https://i.postimg.cc/g22CZb3S/5block.png');
    border: none;
    z-index: 10; /* 5block.png - Bottom Layer */
}
/* Mobile specific adjustments */
@media (max-width: 600px) {
    #canvas-wrapper {
        max-width: 100%;
    }
}

/* --- DEV TOOLS --- */
#flux-devtools {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 9999;
}

#flux-devtools-toggle {
    position: absolute;
    top: 10px;
    right: 10px;
    width: 40px;
    height: 40px;
    background: #333;
    color: #fff;
    border-radius: 5px;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    pointer-events: auto;
    font-size: 20px;
    border: 1px solid #555;
    box-shadow: 0 2px 5px rgba(0,0,0,0.5);
box-shadow: 0 2px 5px rgba(0,0,0,0.5);
}

#btn-restart {
    position: absolute;
    top: 10px;
    right: 60px; /* Left of devtools toggle */
    width: 40px;
    height: 40px;
    background: #333;
    color: #fff;
    border-radius: 5px;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    pointer-events: auto;
    font-size: 24px;
    border: 1px solid #555;
    box-shadow: 0 2px 5px rgba(0,0,0,0.5);
    z-index: 2000;
}
#btn-restart:active {
    background: #555;
    transform: scale(0.95);
}

#flux-devtools-panel {
        position: absolute;
        top: 60px;
        right: 10px;
        width: 280px;
        background: rgba(0, 0, 0, 0.9);
        backdrop-filter: blur(5px);
        border: 1px solid #444;
        border-radius: 5px;
        padding: 10px;
        pointer-events: auto;
        color: #eee;
        font-family: monospace;
        font-size: 12px;
        max-height: 80vh;
        overflow-y: auto;
        box-shadow: 0 4px 10px rgba(0,0,0,0.5);
    }
#flux-devtools-panel.collapsed {
    height: auto !important;
    max-height: 38px !important;
    overflow: hidden !important;
    background: rgba(0, 0, 0, 0.6) !important;
    border-bottom: 1px solid #444;
}
#flux-devtools-panel.collapsed .dev-group,
#flux-devtools-panel.collapsed .dev-row {
    display: none !important;
}
.dev-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
    padding-bottom: 5px;
    border-bottom: 1px solid #444;
    font-weight: bold;
    color: #fff;
}

#dev-copy-btn {
    background: #444;
    border: none;
    color: white;
    padding: 2px 8px;
    cursor: pointer;
    font-size: 10px;
    border-radius: 3px;
}
#dev-copy-btn:hover { background: #666; }

.dev-group {
    margin-bottom: 15px;
}

.dev-group-title {
    color: #aaa;
    margin-bottom: 5px;
    text-transform: uppercase;
    font-size: 10px;
}

.dev-row {
    display: flex;
    align-items: center;
    margin-bottom: 4px;
}

.dev-row label {
    width: 20px;
    color: #888;
}

.dev-row input[type="range"] {
    flex: 1;
    margin: 0 8px;
    cursor: pointer;
}

.dev-row input[type="number"] {
    width: 50px;
    background: #222;
    border: 1px solid #444;
    color: #fff;
    padding: 2px;
    font-family: monospace;
font-size: 11px;
}
#flux-devtools-panel select {
    flex: 1;
    background: rgba(0,0,0,0.6);
    color: #eee;
    border: 1px solid #444;
    border-radius: 4px;
    padding: 2px 6px;
    font-size: 11px;
}

.dev-row.fx-row label {
    width: 120px;
    font-size: 10px;
    color: #aaa;
}

/* --- DEVTOOLS: EFFECTS LAB EXTENSIONS --- */
.dev-details {
    border: 1px solid #333;
    border-radius: 6px;
    padding: 6px;
    margin: 8px 0;
    background: rgba(255,255,255,0.03);
}
.dev-details > summary {
    cursor: pointer;
    list-style: none;
    font-size: 11px;
    color: #eee;
    user-select: none;
}
.dev-details > summary::-webkit-details-marker { display: none; }
.dev-details.dev-details-small > summary {
    font-size: 10px;
    color: #ddd;
}

.dev-btn {
    flex: 1;
    padding: 6px 8px;
    border-radius: 6px;
    border: 1px solid #555;
    background: #333;
    color: #fff;
    font-size: 10px;
    cursor: pointer;
}
.dev-btn:active { transform: scale(0.98); }
.dev-btn-neutral { background: #333; border-color:#555; }
.dev-btn-good { background: #2f4a33; border-color:#3e6a46; }
.dev-btn-danger { background: #4a2f2f; border-color:#6a3e3e; }

.dev-textarea {
    width: 100%;
    min-height: 140px;
    margin-top: 8px;
    padding: 8px;
    border-radius: 6px;
    border: 1px solid #444;
    background: rgba(0,0,0,0.65);
    color: #eee;
    font-family: monospace;
    font-size: 10px;
}

.dev-trace {
    margin-top: 8px;
    border: 1px solid #333;
    border-radius: 6px;
    padding: 6px;
    max-height: 220px;
    overflow-y: auto;
    background: rgba(0,0,0,0.45);
    font-size: 10px;
    color: #ddd;
}
.dev-trace-line {
    padding: 2px 0;
    border-bottom: 1px solid rgba(255,255,255,0.05);
}

#flux-devtools-panel input[type='color'] {
    width: 42px;
    height: 22px;
    padding: 0;
    border: 1px solid #444;
    background: transparent;
}
#flux-devtools-panel input[type='color'] {
    width: 42px;
    height: 22px;
    padding: 0;
    border: 1px solid #444;
    background: transparent;
}

/* --- GAME OVER SCREEN --- */
#game-over-screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 3000;
    opacity: 0;
    pointer-events: none;
    transition: opacity 1.5s ease-in;
}

#game-over-screen.active {
    opacity: 1;
    pointer-events: auto;
}

.go-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
}

.go-text {
    /* Container for "GAME OVER" bitmap */
    margin-bottom: 40px;
    display: flex;
    justify-content: center;
    align-items: center;
min-height: 60px; /* Reserve space */
    height: auto;
    gap: 4px; /* Spacing between letters */
    flex-wrap: wrap;
}

.go-letter {
    opacity: 0;
    transform: translateY(-50px);
    animation: go-drop-in 0.6s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

@keyframes go-drop-in {
    0% { opacity: 0; transform: translateY(-100px) scale(0.5); }
    60% { opacity: 1; transform: translateY(10px) scale(1.2); }
    100% { opacity: 1; transform: translateY(0) scale(1.0); }
}

#game-over-screen.active .go-text {
    /* Activation handled by children animations */
}

.go-restart {
    /* Container for "TRY AGAIN" bitmap */
    cursor: pointer;
    
    /* Slow fade-in ("Dinner in") after delay */
    transition: opacity 2.0s ease, transform 2.0s ease-out;
    transition-delay: 2.2s; /* Wait for GAME OVER text (approx 1.5s) + pause */
    
    opacity: 0;
    transform: translateY(30px);
    
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 10px;
    height: 40px; /* Reserve space */
}

#game-over-screen.active .go-restart {
    opacity: 1;
    transform: translateY(0);
}

.go-restart:active {
    /* Interaction override: Snappy response */
    transition: transform 0.1s, filter 0.1s;
    transition-delay: 0s;
    
    transform: scale(0.95) translateY(0);
    filter: brightness(1.2);
}

#loading-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: #000;
    color: #fff;
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 9999;
    font-family: 'Courier New', Courier, monospace;
    font-size: 20px;
    letter-spacing: 4px;
    pointer-events: none;
    transition: opacity 0.5s ease-out;
}
/* Ensure canvas inside loader is centered */
#loading-overlay canvas {
    display: block;
    image-rendering: pixelated;
}

/* --- SHARD SELECTION UI --- */
#shard-selection-ui {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.92);
    z-index: 4000;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

#shard-selection-ui.active {
    opacity: 1;
    pointer-events: auto;
}

.shard-ui-title {
    color: #fff;
    font-size: 24px;
    margin-bottom: 30px;
    text-shadow: 0 0 10px rgba(255,255,255,0.5);
    letter-spacing: 2px;
    text-transform: uppercase;
    border-bottom: 2px solid #fff;
    padding-bottom: 5px;
}

#shard-card-list {
    display: flex;
    flex-direction: column;
    gap: 15px;
    width: 85%;
    max-width: 360px;
}

.shard-card {
    background: #1a1a1a;
    border: 2px solid #444;
    border-radius: 4px;
    padding: 12px;
    cursor: pointer;
    transition: transform 0.1s, border-color 0.1s, background 0.1s;
    position: relative;
    overflow: hidden;
    
    /* Entrance Animation */
    opacity: 0;
    transform: translateY(20px);
}

#shard-selection-ui.active .shard-card {
    animation: shard-card-enter 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

#shard-selection-ui.active .shard-card:nth-child(1) { animation-delay: 0.1s; }
#shard-selection-ui.active .shard-card:nth-child(2) { animation-delay: 0.2s; }
#shard-selection-ui.active .shard-card:nth-child(3) { animation-delay: 0.3s; }

@keyframes shard-card-enter {
    to { opacity: 1; transform: translateY(0); }
}

.shard-card:active {
    transform: scale(0.98);
}

/* Rarity Styles */
.shard-card.tier-common { border-color: #44aaff; box-shadow: 0 0 5px rgba(68, 170, 255, 0.1); }
.shard-card.tier-rare { border-color: #ffffaa; box-shadow: 0 0 8px rgba(255, 255, 170, 0.2); }
.shard-card.tier-epic { border-color: #ff4444; box-shadow: 0 0 12px rgba(255, 68, 68, 0.3); }

.shard-card:hover {
    background: #252525;
}
.shard-card.tier-common:hover { border-color: #77ccff; }
.shard-card.tier-rare:hover { border-color: #ffffdd; }
.shard-card.tier-epic:hover { border-color: #ff7777; }

.shard-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
    border-bottom: 1px solid rgba(255,255,255,0.1);
    padding-bottom: 5px;
}

.shard-name {
    /* Bitmap font replaces text */
    display: flex;
    align-items: center;
}

.shard-tier {
    /* Bitmap font replaces text */
    padding: 2px 4px;
    background: rgba(0,0,0,0.5);
    border-radius: 2px;
    display: flex;
    align-items: center;
}

.shard-tags {
    display: flex;
    gap: 5px;
    margin-bottom: 8px;
    flex-wrap: wrap;
}

.shard-tag {
    background: rgba(255,255,255,0.1);
    padding: 2px 5px;
    border-radius: 2px;
    display: flex;
    align-items: center;
}

.shard-desc {
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    min-height: 16px;
}

.shard-btn {
    background: rgba(255,255,255,0.1);
    text-align: center;
    padding: 8px;
    border-radius: 2px;
    transition: background 0.2s, color 0.2s;
    display: flex;
    justify-content: center;
    align-items: center;
}
.shard-card:hover .shard-btn {
    background: #fff;
    color: #000;
}


/* --- Sphere Grid UI --- */
#sphere-grid-ui {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.92);
    z-index: 4100;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    align-items: center;
    padding-top: 28px;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease;
}

#sphere-grid-ui.active {
    opacity: 1;
    pointer-events: auto;
}

.grid-ui-title {
    color: #fff;
    font-size: 22px;
    margin-bottom: 10px;
    letter-spacing: 2px;
    text-transform: uppercase;
    border-bottom: 2px solid #fff;
    padding-bottom: 6px;
}

#sphere-grid-top {
    width: 90%;
    max-width: 380px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}

#sphere-grid-move, #sphere-grid-currency {
    color: #fff;
    font-size: 14px;
}

#sphere-grid-canvas {
    width: 90%;
    max-width: 360px;
    height: auto;
    image-rendering: pixelated;
    border: 2px solid #333;
    background: rgba(0,0,0,0.35);
}

#sphere-grid-info {
    width: 90%;
    max-width: 360px;
    margin-top: 10px;
    padding: 10px;
    border: 2px solid #222;
    background: rgba(0,0,0,0.35);
}

#grid-node-name { margin-bottom: 6px; }
#grid-node-cost { margin-bottom: 6px; opacity: 0.95; }
#grid-node-desc { opacity: 0.9; }

#sphere-grid-actions {
    width: 90%;
    max-width: 360px;
    display: flex;
    gap: 10px;
    margin-top: 10px;
}

.grid-btn {
    flex: 1;
    height: 48px;
    display: flex;
    justify-content: center;
    align-items: center;
    background: #111;
    border: 2px solid #444;
    border-radius: 4px;
    cursor: pointer;
    user-select: none;
}

.grid-btn:active {
    transform: scale(0.98);
    border-color: #888;
}
