/* ===== Reset & Variables ===== */
:root {
    --bg: #0a0e1a;
    --card-bg: #1a1f35;
    --border: rgba(148, 163, 184, 0.12);
    --text: #f1f5f9;
    --text-dim: #94a3b8;
    --text-muted: #64748b;
    --blue: #3b82f6;
    --cyan: #06b6d4;
    --green: #10b981;
    --yellow: #f59e0b;
    --red: #ef4444;
    --purple: #8b5cf6;
    --gradient: linear-gradient(135deg, #3b82f6, #06b6d4);
}

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

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

/* ===== Canvas ===== */
#gameCanvas {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
    display: none;
}

#heroCanvas {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    z-index: 0;
}

/* ===== Overlays ===== */
.overlay {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(10, 14, 26, 0.6);
    backdrop-filter: blur(8px);
}

.overlay.hidden { display: none; }

/* ===== Menu Card ===== */
.menu-card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 24px;
    padding: 48px;
    text-align: center;
    max-width: 460px;
    width: 90%;
    box-shadow: 0 20px 60px rgba(0,0,0,0.5), 0 0 80px rgba(59,130,246,0.08);
    animation: fadeInUp 0.5s ease;
}

@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

.menu-logo {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    margin-bottom: 12px;
}

.logo-icon {
    width: 40px; height: 40px;
    color: var(--blue);
}

.menu-logo h1 {
    font-size: 1.8rem;
    font-weight: 800;
    letter-spacing: -0.03em;
}

.accent { color: var(--cyan); }

.menu-tagline {
    font-size: 1rem;
    color: var(--text-dim);
    margin-bottom: 28px;
    line-height: 1.5;
}

.menu-instructions {
    background: rgba(0,0,0,0.25);
    border-radius: 12px;
    padding: 20px;
    margin-bottom: 28px;
}

.key-row {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    margin-bottom: 12px;
}

.key {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px; height: 36px;
    background: rgba(255,255,255,0.08);
    border: 1px solid rgba(255,255,255,0.15);
    border-radius: 8px;
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--text);
}

.key-or {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin: 0 6px;
}

.menu-instructions p {
    font-size: 0.85rem;
    color: var(--text-dim);
    line-height: 1.5;
}

/* ===== Buttons ===== */
.btn-play {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    background: var(--gradient);
    color: white;
    border: none;
    border-radius: 12px;
    padding: 14px 36px;
    font-family: inherit;
    font-size: 1.05rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 20px rgba(59,130,246,0.35);
}

.btn-play:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 30px rgba(59,130,246,0.5);
}

.btn-play:active {
    transform: translateY(0);
}

/* ===== HUD ===== */
.hud {
    position: fixed;
    top: 0; left: 0; right: 0;
    z-index: 50;
    pointer-events: none;
}

.hud.hidden { display: none; }

.hud-top {
    display: flex;
    justify-content: space-between;
    align-items: stretch;
    padding: 12px 20px;
    background: linear-gradient(to bottom, rgba(10,14,26,0.9) 60%, transparent);
}

.hud-order, .hud-score, .hud-level {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
}

.hud-label {
    font-size: 0.65rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.hud-target {
    font-size: 1.1rem;
    font-weight: 800;
    color: var(--cyan);
    padding: 4px 16px;
    background: rgba(6,182,212,0.12);
    border: 1px solid rgba(6,182,212,0.25);
    border-radius: 8px;
}

.hud-value {
    font-family: 'JetBrains Mono', monospace;
    font-size: 1.3rem;
    font-weight: 700;
    color: var(--text);
}

.hud-temp {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 20px 8px;
}

.temp-label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--cyan);
    min-width: 80px;
}

.temp-bar-bg {
    flex: 1;
    height: 8px;
    background: rgba(255,255,255,0.08);
    border-radius: 4px;
    overflow: hidden;
}

.temp-bar-fill {
    height: 100%;
    width: 0%;
    border-radius: 4px;
    background: var(--gradient);
    transition: width 0.3s ease, background 0.5s ease;
}

.temp-bar-fill.warn {
    background: linear-gradient(90deg, var(--yellow), var(--yellow));
}

.temp-bar-fill.danger {
    background: linear-gradient(90deg, var(--red), #ff6b6b);
    animation: pulse-bar 0.5s ease infinite;
}

@keyframes pulse-bar {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}

/* ===== Result Cards ===== */
.result-card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 24px;
    padding: 40px 48px;
    text-align: center;
    max-width: 400px;
    width: 90%;
    box-shadow: 0 20px 60px rgba(0,0,0,0.5);
    animation: fadeInUp 0.4s ease;
}

.result-icon {
    width: 64px; height: 64px;
    border-radius: 50%;
    background: rgba(16,185,129,0.15);
    color: var(--green);
    font-size: 2rem;
    font-weight: 900;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 16px;
    border: 2px solid rgba(16,185,129,0.3);
}

.result-icon.fail {
    background: rgba(239,68,68,0.15);
    color: var(--red);
    border-color: rgba(239,68,68,0.3);
}

.result-card h2 {
    font-size: 1.5rem;
    font-weight: 800;
    margin-bottom: 8px;
}

.result-msg {
    font-size: 0.9rem;
    color: var(--text-dim);
    margin-bottom: 20px;
    line-height: 1.5;
}

.result-stats {
    display: flex;
    gap: 16px;
    justify-content: center;
    margin: 20px 0 24px;
}

.result-stat {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 12px 16px;
    background: rgba(0,0,0,0.2);
    border-radius: 10px;
    min-width: 80px;
}

.result-label {
    font-size: 0.65rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.result-value {
    font-family: 'JetBrains Mono', monospace;
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--cyan);
}

/* ===== Wrong Storage Alert ===== */
.wrong-alert {
    position: fixed;
    top: 100px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 60;
    background: rgba(239,68,68,0.9);
    color: white;
    font-weight: 700;
    font-size: 0.95rem;
    padding: 12px 28px;
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(239,68,68,0.4);
    animation: shake 0.4s ease;
}

.wrong-alert.hidden { display: none; }

@keyframes shake {
    0%, 100% { transform: translateX(-50%) rotate(0); }
    25% { transform: translateX(-50%) rotate(-2deg); }
    75% { transform: translateX(-50%) rotate(2deg); }
}

/* ===== Touch Controls ===== */
.touch-controls {
    position: fixed;
    bottom: 30px;
    left: 30px;
    z-index: 50;
}

.touch-controls.hidden { display: none; }

.touch-dpad {
    display: grid;
    grid-template-columns: 60px 60px 60px;
    grid-template-rows: 60px 60px 60px;
    gap: 4px;
}

.touch-btn {
    background: rgba(255,255,255,0.1);
    border: 1px solid rgba(255,255,255,0.15);
    border-radius: 12px;
    color: white;
    font-size: 1.2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.touch-btn:active {
    background: rgba(59,130,246,0.3);
    border-color: var(--blue);
}

.touch-btn.up { grid-column: 2; grid-row: 1; }
.touch-btn.left { grid-column: 1; grid-row: 2; }
.touch-btn.right { grid-column: 3; grid-row: 2; }
.touch-btn.down { grid-column: 2; grid-row: 3; }

/* ===== Responsive ===== */
@media (max-width: 640px) {
    .menu-card { padding: 32px 24px; }
    .menu-logo h1 { font-size: 1.4rem; }
    .key { width: 30px; height: 30px; font-size: 0.7rem; }
    .hud-top { padding: 8px 12px; }
    .hud-target { font-size: 0.9rem; }
    .result-stats { flex-direction: column; align-items: center; }
}