:root {
    --bg-dark: #0f172a;
    --primary: #3b82f6;
    --primary-hover: #2563eb;
    --danger: #ef4444;
    --danger-hover: #dc2828;
    --success: #22c55e;
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --card-bg: rgba(30, 41, 59, 0.7);
    --border: rgba(255, 255, 255, 0.1);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Outfit', sans-serif;
    user-select: none;
}

body {
    background-color: var(--bg-dark);
    color: var(--text-main);
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    overflow: hidden;
}

#game-container {
    position: relative;
    width: 100%;
    max-width: 1024px;
    height: 100%;
    max-height: 600px;
    background: #000;
    box-shadow: 0 0 40px rgba(0, 0, 0, 0.5);
    overflow: hidden;
}

canvas {
    display: block;
    width: 100%;
    height: 100%;
    image-rendering: optimizeSpeed;
}

/* UI Layer */
#ui-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none; /* Let clicks pass to canvas unless on UI elements */
}

.screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    background: rgba(15, 23, 42, 0.85);
    backdrop-filter: blur(8px);
    transition: opacity 0.4s ease, transform 0.4s ease;
    opacity: 0;
    pointer-events: none;
    transform: scale(1.05);
}

.screen.active {
    opacity: 1;
    pointer-events: auto;
    transform: scale(1);
}

.screen.hidden {
    display: none;
}

h1, h2 {
    font-size: 3rem;
    font-weight: 800;
    margin-bottom: 1rem;
    text-align: center;
    background: linear-gradient(to right, #60a5fa, #c084fc);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    text-shadow: 0px 4px 20px rgba(96, 165, 250, 0.3);
}

p {
    font-size: 1.2rem;
    color: var(--text-muted);
    margin-bottom: 2rem;
    text-align: center;
}

/* Character Selection */
.character-selection {
    margin-bottom: 2rem;
    text-align: center;
}

.character-selection h3 {
    margin-bottom: 1rem;
    font-weight: 600;
    color: var(--text-main);
}

.cards {
    display: flex;
    gap: 1.5rem;
    justify-content: center;
}

.char-card {
    background: var(--card-bg);
    border: 2px solid var(--border);
    border-radius: 16px;
    padding: 1.5rem;
    width: 200px;
    cursor: pointer;
    transition: all 0.3s ease;
}

.char-card:hover {
    transform: translateY(-5px);
    border-color: rgba(255, 255, 255, 0.3);
    box-shadow: 0 10px 25px rgba(0,0,0,0.3);
}

.char-card.selected {
    border-color: var(--primary);
    background: rgba(59, 130, 246, 0.15);
    box-shadow: 0 0 20px rgba(59, 130, 246, 0.4);
}

.char-icon {
    font-size: 4rem;
    margin-bottom: 1rem;
    filter: drop-shadow(0 4px 6px rgba(0,0,0,0.4));
}

.char-card h4 {
    font-size: 1.2rem;
    margin-bottom: 0.5rem;
}

.char-card p {
    font-size: 0.9rem;
    margin-bottom: 0;
}

/* Buttons */
button {
    padding: 1rem 3rem;
    font-size: 1.2rem;
    font-weight: 800;
    border: none;
    border-radius: 50px;
    background: var(--primary);
    color: white;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(59, 130, 246, 0.4);
    text-transform: uppercase;
    letter-spacing: 1px;
}

button:hover:not(:disabled) {
    background: var(--primary-hover);
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(59, 130, 246, 0.6);
}

button:disabled {
    background: #475569;
    color: #94a3b8;
    cursor: not-allowed;
    box-shadow: none;
}

button.danger-btn {
    background: var(--danger);
    box-shadow: 0 4px 15px rgba(239, 68, 68, 0.4);
    font-size: 1.5rem;
    padding: 1.5rem 4rem;
    animation: pulse 1.5s infinite;
}

button.danger-btn:hover {
    background: var(--danger-hover);
    box-shadow: 0 6px 25px rgba(239, 68, 68, 0.7);
}

button.secondary-btn {
    background: transparent;
    border: 2px solid var(--primary);
    color: var(--primary);
}

button.secondary-btn:hover {
    background: rgba(59, 130, 246, 0.1);
}

@keyframes pulse {
    0% { transform: scale(1); box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.7); }
    70% { transform: scale(1.05); box-shadow: 0 0 0 15px rgba(239, 68, 68, 0); }
    100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(239, 68, 68, 0); }
}

/* HUD */
#hud {
    flex-direction: row;
    justify-content: space-between;
    align-items: flex-start;
    padding: 1.5rem;
    background: transparent;
    backdrop-filter: none;
}

.health-bar-container {
    width: 250px;
    height: 20px;
    background: rgba(0, 0, 0, 0.5);
    border: 2px solid var(--border);
    border-radius: 10px;
    overflow: hidden;
}

#health-fill {
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, #22c55e, #10b981);
    transition: width 0.2s ease, background 0.3s ease;
}

.progress-container {
    display: flex;
    align-items: center;
    gap: 1rem;
    font-weight: 600;
    text-transform: uppercase;
    font-size: 0.9rem;
    letter-spacing: 1px;
    color: rgba(255,255,255,0.9);
}

.progress-track {
    width: 300px;
    height: 8px;
    background: rgba(0, 0, 0, 0.5);
    border-radius: 4px;
    position: relative;
    overflow: hidden;
}

#progress-fill {
    position: absolute;
    top: 0;
    left: 0;
    height: 100%;
    width: 0%;
    background: var(--primary);
    box-shadow: 0 0 10px var(--primary);
}

/* Mobile Controls */
#mobile-controls {
    position: absolute;
    bottom: 2rem;
    left: 0;
    width: 100%;
    display: flex;
    justify-content: space-between;
    padding: 0 2rem;
    pointer-events: none;
}

#mobile-controls button {
    pointer-events: auto;
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(5px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    padding: 1rem 2rem;
    border-radius: 12px;
    font-size: 1rem;
}

#mobile-controls button:active {
    background: rgba(255, 255, 255, 0.2);
    transform: scale(0.95);
}

.confetti {
    font-size: 5rem;
    margin-bottom: 1rem;
    animation: bounce 1s infinite alternate;
}

@keyframes bounce {
    from { transform: translateY(0); }
    to { transform: translateY(-20px); }
}

@media (max-width: 768px) {
    .cards { flex-direction: column; }
    .char-card { width: 100%; padding: 1rem; display: flex; align-items: center; gap: 1rem; text-align: left; }
    .char-icon { margin-bottom: 0; font-size: 2.5rem; }
    #hud { flex-direction: column; gap: 1rem; }
    .progress-track { width: 200px; }
    #mobile-controls { display: flex; } /* Shown on mobile implicitly via JS if needed, but handled by media query maybe? We will handle visibility via JS */
}

/* Puzzle Screen */
.clues-container {
    background: rgba(0, 0, 0, 0.4);
    padding: 1.5rem;
    border-radius: 12px;
    margin-bottom: 2rem;
    max-width: 450px;
    width: 100%;
}

.clue {
    margin-bottom: 0.8rem;
    font-size: 1.1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid rgba(255,255,255,0.1);
    padding-bottom: 0.5rem;
}

.clue-code {
    font-weight: 800;
    letter-spacing: 5px;
    color: var(--primary);
}

.clue-text {
    font-size: 0.9rem;
    color: var(--text-muted);
}

.code-inputs {
    display: flex;
    gap: 1rem;
    margin-bottom: 2rem;
}

.code-inputs input {
    width: 60px;
    height: 70px;
    font-size: 2.5rem;
    text-align: center;
    font-weight: 800;
    border: 2px solid var(--primary);
    border-radius: 12px;
    background: rgba(15, 23, 42, 0.8);
    color: white;
    outline: none;
}

.code-inputs input:focus {
    box-shadow: 0 0 15px rgba(59, 130, 246, 0.5);
}

.wrong-animation {
    animation: shake 0.5s;
}

@keyframes shake {
    0% { transform: translateX(0); }
    25% { transform: translateX(-10px); }
    50% { transform: translateX(10px); }
    75% { transform: translateX(-10px); }
    100% { transform: translateX(0); }
}
