:root {
    --bg-primary: #060a14;
    --bg-secondary: #0a0e1a;
    --bg-card: rgba(12, 18, 38, 0.9);
    --accent-cyan: #00d4ff;
    --accent-blue: #4da6ff;
    --accent-orange: #ff6b35;
    --accent-red: #ff3b3b;
    --accent-green: #3bff6b;
    --text-primary: #e6edf3;
    --text-secondary: #8b949e;
    --text-muted: #484f58;
    --font-display: 'Space Grotesk', sans-serif;
    --font-mono: 'JetBrains Mono', monospace;
    --panel-bg: linear-gradient(165deg, rgba(12,18,38,0.95), rgba(8,12,28,0.98));
    --panel-border: rgba(0,212,255,0.1);
    --card-hover-bg: rgba(0,212,255,0.06);
    --overlay-bg: rgba(0,0,0,0.7);
    --hud-gradient: linear-gradient(180deg, rgba(4,6,16,0.95) 0%, rgba(4,6,16,0.6) 50%, rgba(4,6,16,0.1) 80%, transparent 100%);
    --btn-main-bg: linear-gradient(135deg, rgba(0,212,255,0.12), rgba(0,180,255,0.06), rgba(0,212,255,0.1));
    --btn-main-border: rgba(0,212,255,0.5);
    --btn-sec-bg: rgba(255,255,255,0.015);
    --btn-sec-border: rgba(255,255,255,0.1);
    --hud-btn-bg: rgba(0,0,0,0.5);
    --hud-btn-border: rgba(255,255,255,0.12);
    --footer-bg: linear-gradient(180deg, transparent 0%, rgba(4,6,14,0.8) 30%, rgba(4,6,14,0.97) 100%);
    --footer-border: rgba(0,212,255,0.06);
    --win-bg: linear-gradient(165deg, rgba(12,24,18,0.95), rgba(8,16,12,0.98));
    --win-border: rgba(59,255,107,0.15);
    --charge-bar-bg: rgba(255,255,255,0.06);
    --charge-bar-border: rgba(0,212,255,0.2);
    --key-badge-bg: rgba(0,212,255,0.1);
    --key-badge-border: rgba(0,212,255,0.3);
    --cube-type-border: rgba(255,255,255,0.05);
    --level-card-bg: linear-gradient(135deg, rgba(0,212,255,0.03), rgba(0,180,255,0.01));
    --level-card-border: rgba(0,212,255,0.08);
    --msg-border: rgba(0,212,255,0.2);
    --scanline-color: rgba(0,0,0,0.025);
}

/* ═══ LIGHT THEME ═══ */
[data-theme="light"] {
    --bg-primary: #e8edf5;
    --bg-secondary: #d8dfe9;
    --bg-card: rgba(255, 255, 255, 0.92);
    --accent-cyan: #0090b8;
    --accent-blue: #2a7fd4;
    --accent-orange: #d45520;
    --accent-red: #cc2222;
    --accent-green: #1aa84a;
    --text-primary: #1a2030;
    --text-secondary: #4a5568;
    --text-muted: #718096;
    --panel-bg: linear-gradient(165deg, rgba(255,255,255,0.95), rgba(240,244,252,0.98));
    --panel-border: rgba(0,144,184,0.2);
    --card-hover-bg: rgba(0,144,184,0.08);
    --overlay-bg: rgba(255,255,255,0.75);
    --hud-gradient: linear-gradient(180deg, rgba(232,237,245,0.95) 0%, rgba(232,237,245,0.7) 50%, rgba(232,237,245,0.1) 80%, transparent 100%);
    --btn-main-bg: linear-gradient(135deg, rgba(0,144,184,0.1), rgba(0,144,184,0.05), rgba(0,144,184,0.08));
    --btn-main-border: rgba(0,144,184,0.5);
    --btn-sec-bg: rgba(0,0,0,0.03);
    --btn-sec-border: rgba(0,0,0,0.12);
    --hud-btn-bg: rgba(255,255,255,0.7);
    --hud-btn-border: rgba(0,0,0,0.15);
    --footer-bg: linear-gradient(180deg, transparent 0%, rgba(232,237,245,0.85) 30%, rgba(232,237,245,0.97) 100%);
    --footer-border: rgba(0,144,184,0.15);
    --win-bg: linear-gradient(165deg, rgba(230,250,240,0.96), rgba(240,255,245,0.98));
    --win-border: rgba(26,168,74,0.25);
    --charge-bar-bg: rgba(0,0,0,0.08);
    --charge-bar-border: rgba(0,144,184,0.3);
    --key-badge-bg: rgba(0,144,184,0.08);
    --key-badge-border: rgba(0,144,184,0.25);
    --cube-type-border: rgba(0,0,0,0.08);
    --level-card-bg: linear-gradient(135deg, rgba(0,144,184,0.04), rgba(0,144,184,0.01));
    --level-card-border: rgba(0,144,184,0.15);
    --msg-border: rgba(0,144,184,0.25);
    --scanline-color: transparent;
}

[data-theme="light"] #title-screen {
    background:
        radial-gradient(ellipse at 30% 20%, rgba(0,144,184,0.08) 0%, transparent 40%),
        radial-gradient(ellipse at 70% 15%, rgba(42,127,212,0.06) 0%, transparent 35%),
        radial-gradient(ellipse at 50% 50%, rgba(0,144,184,0.03) 0%, transparent 60%),
        linear-gradient(180deg, #e8edf5 0%, #d8dfe9 40%, #cdd5e3 60%, #e0e7f0 80%, #e8edf5 100%);
}

[data-theme="light"] #title-screen::before {
    background:
        repeating-linear-gradient(0deg, transparent, transparent 2px, rgba(0,144,184,0.015) 2px, rgba(0,144,184,0.015) 3px),
        repeating-linear-gradient(90deg, transparent, transparent 2px, rgba(0,144,184,0.01) 2px, rgba(0,144,184,0.01) 3px);
}

[data-theme="light"] #title-screen::after {
    background: conic-gradient(from 0deg at 50% 50%, transparent 0deg, rgba(0,144,184,0.015) 60deg, transparent 120deg, rgba(0,144,184,0.01) 240deg, transparent 360deg);
}

[data-theme="light"] .title-ambient-glow {
    background:
        radial-gradient(circle at 15% 85%, rgba(0,144,184,0.05) 0%, transparent 30%),
        radial-gradient(circle at 85% 80%, rgba(42,127,212,0.03) 0%, transparent 25%),
        radial-gradient(circle at 50% 20%, rgba(0,144,184,0.02) 0%, transparent 40%);
}

[data-theme="light"] .game-title {
    background: linear-gradient(135deg, #1a2030 0%, #0090b8 25%, #2a7fd4 50%, #0090b8 75%, #1a2030 100%);
    background-size: 200% auto;
    -webkit-background-clip: text;
    background-clip: text;
}

[data-theme="light"] .title-magnet {
    filter: drop-shadow(0 0 30px rgba(0,144,184,0.4)) drop-shadow(0 0 60px rgba(0,144,184,0.1));
}

[data-theme="light"] .win-box h2 {
    background: linear-gradient(135deg, #1a2030 20%, #1aa84a 50%, #15803d 100%);
    -webkit-background-clip: text;
    background-clip: text;
}

[data-theme="light"] .win-box {
    border-color: var(--win-border);
    background: var(--win-bg);
}

[data-theme="light"] .title-version {
    color: rgba(0,144,184,0.4);
}

/* ═══ THEME TOGGLE BUTTON ═══ */
.theme-toggle {
    position: fixed;
    top: 14px;
    right: 14px;
    z-index: 100;
    width: 44px;
    height: 44px;
    border-radius: 12px;
    border: 1px solid var(--hud-btn-border);
    background: var(--hud-btn-bg);
    backdrop-filter: blur(10px);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    transition: all 0.35s cubic-bezier(0.22, 0.61, 0.36, 1);
    padding: 0;
    line-height: 1;
}

.theme-toggle:hover {
    border-color: var(--accent-cyan);
    background: var(--card-hover-bg);
    box-shadow: 0 0 20px rgba(0,144,184,0.15);
    transform: scale(1.08);
}

.theme-toggle:active {
    transform: scale(0.95);
}

.theme-icon-light { display: none; }
.theme-icon-dark { display: inline; }

[data-theme="light"] .theme-icon-light { display: inline; }
[data-theme="light"] .theme-icon-dark { display: none; }

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

body {
    background: var(--bg-primary);
    color: var(--text-primary);
    font-family: var(--font-display);
    overflow: hidden;
    height: 100vh;
    width: 100vw;
}

#game-wrapper {
    width: 100%;
    height: 100vh;
    position: relative;
}

/* Screens */
.screen {
    position: absolute;
    inset: 0;
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 10;
}
.screen.active { display: flex; }

/* Title Screen */
#title-screen {
    background: 
        radial-gradient(ellipse at 30% 20%, rgba(0,212,255,0.12) 0%, transparent 40%),
        radial-gradient(ellipse at 70% 15%, rgba(77,100,255,0.08) 0%, transparent 35%),
        radial-gradient(ellipse at 50% 50%, rgba(0,180,220,0.04) 0%, transparent 60%),
        radial-gradient(ellipse at 20% 80%, rgba(77,166,255,0.05) 0%, transparent 40%),
        radial-gradient(ellipse at 80% 70%, rgba(255,107,53,0.04) 0%, transparent 40%),
        radial-gradient(ellipse at 50% 100%, rgba(0,80,120,0.15) 0%, transparent 50%),
        linear-gradient(180deg, #020408 0%, #040810 20%, #060c18 40%, #0a1020 60%, #081018 80%, #040810 100%);
    flex-direction: column;
    overflow: hidden;
}

#title-screen::before {
    content: '';
    position: absolute;
    inset: 0;
    background: 
        repeating-linear-gradient(0deg, transparent, transparent 2px, rgba(0,212,255,0.008) 2px, rgba(0,212,255,0.008) 3px),
        repeating-linear-gradient(90deg, transparent, transparent 2px, rgba(0,212,255,0.005) 2px, rgba(0,212,255,0.005) 3px);
    pointer-events: none;
    animation: gridShift 20s linear infinite;
}

@keyframes gridShift {
    0% { transform: translate(0, 0); }
    100% { transform: translate(3px, 3px); }
}

#title-screen::after {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: conic-gradient(from 0deg at 50% 50%, transparent 0deg, rgba(0,212,255,0.02) 60deg, transparent 120deg, rgba(0,180,255,0.015) 240deg, transparent 360deg);
    animation: rotateNebula 30s linear infinite;
    pointer-events: none;
}

@keyframes rotateNebula {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

.title-particles {
    position: absolute;
    inset: 0;
    pointer-events: none;
}

.title-content {
    text-align: center;
    z-index: 2;
    animation: fadeSlideUp 1s cubic-bezier(0.22, 0.61, 0.36, 1);
    position: relative;
}

.title-content::before {
    content: '';
    position: absolute;
    top: -40px;
    left: 50%;
    transform: translateX(-50%);
    width: 300px;
    height: 1px;
    background: linear-gradient(90deg, transparent, rgba(0,212,255,0.4), transparent);
    animation: lineGlow 3s ease-in-out infinite;
}

.title-content::after {
    content: '';
    position: absolute;
    bottom: -30px;
    left: 50%;
    transform: translateX(-50%);
    width: 200px;
    height: 1px;
    background: linear-gradient(90deg, transparent, rgba(0,212,255,0.3), transparent);
    animation: lineGlow 3s ease-in-out infinite reverse;
}

@keyframes lineGlow {
    0%, 100% { opacity: 0.3; width: 200px; }
    50% { opacity: 1; width: 350px; }
}

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

.title-magnet {
    font-size: 5.5rem;
    margin-bottom: 20px;
    animation: magnetFloat 4s ease-in-out infinite;
    filter: drop-shadow(0 0 60px rgba(0,212,255,0.7)) drop-shadow(0 0 120px rgba(0,212,255,0.2));
    position: relative;
    display: inline-block;
}

@keyframes magnetFloat {
    0%, 100% { transform: translateY(0) rotate(-8deg) scale(1); }
    25% { transform: translateY(-10px) rotate(0deg) scale(1.02); }
    50% { transform: translateY(-18px) rotate(8deg) scale(1.05); }
    75% { transform: translateY(-8px) rotate(3deg) scale(1.02); }
}

.game-title {
    font-size: 4.2rem;
    font-weight: 700;
    letter-spacing: 12px;
    background: linear-gradient(135deg, #ffffff 0%, #c8e8ff 25%, var(--accent-cyan) 50%, #80c0ff 75%, #ffffff 100%);
    background-size: 200% auto;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 8px;
    text-shadow: none;
    animation: titleShine 6s linear infinite, titleGlow 4s ease-in-out infinite alternate;
    position: relative;
}

@keyframes titleShine {
    0% { background-position: 200% center; }
    100% { background-position: -200% center; }
}

@keyframes titleGlow {
    0% { filter: drop-shadow(0 0 20px rgba(0,212,255,0.3)) drop-shadow(0 4px 8px rgba(0,0,0,0.5)); }
    100% { filter: drop-shadow(0 0 50px rgba(0,212,255,0.6)) drop-shadow(0 4px 12px rgba(0,0,0,0.3)); }
}

.game-subtitle {
    font-size: 1.1rem;
    color: var(--accent-cyan);
    letter-spacing: 8px;
    margin-bottom: 6px;
    font-weight: 600;
    text-transform: uppercase;
    text-shadow: 0 0 20px rgba(0,212,255,0.3);
    animation: fadeSlideUp 1.2s cubic-bezier(0.22, 0.61, 0.36, 1);
}

.game-subtitle-en {
    font-size: 0.85rem;
    color: var(--text-secondary);
    letter-spacing: 4px;
    margin-bottom: 44px;
    text-transform: uppercase;
    font-style: italic;
    opacity: 0.7;
    animation: fadeSlideUp 1.4s cubic-bezier(0.22, 0.61, 0.36, 1);
}

.title-buttons {
    display: flex;
    flex-direction: column;
    gap: 14px;
    align-items: center;
    animation: fadeSlideUp 1.6s cubic-bezier(0.22, 0.61, 0.36, 1);
}

.btn-main {
    background: var(--btn-main-bg);
    border: 2px solid var(--btn-main-border);
    color: var(--accent-cyan);
    font-family: var(--font-display);
    font-size: 1.1rem;
    font-weight: 600;
    padding: 14px 48px;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.4s cubic-bezier(0.22, 0.61, 0.36, 1);
    letter-spacing: 3px;
    min-width: 260px;
    position: relative;
    overflow: hidden;
    backdrop-filter: blur(8px);
}

.btn-main::before {
    content: '';
    position: absolute;
    top: -2px;
    left: -100%;
    width: 60%;
    height: calc(100% + 4px);
    background: linear-gradient(90deg, transparent, rgba(0,212,255,0.15), transparent);
    transition: left 0.6s cubic-bezier(0.22, 0.61, 0.36, 1);
}

.btn-main:hover::before {
    left: 120%;
}

.btn-main:hover {
    background: linear-gradient(135deg, rgba(0,212,255,0.22), rgba(0,180,255,0.12));
    box-shadow: 0 0 50px rgba(0,212,255,0.25), 0 0 100px rgba(0,212,255,0.08), inset 0 0 30px rgba(0,212,255,0.06);
    transform: translateY(-3px);
    border-color: var(--accent-cyan);
    text-shadow: 0 0 15px rgba(0,212,255,0.5);
}

.btn-main:active {
    transform: translateY(-1px) scale(0.98);
    box-shadow: 0 0 25px rgba(0,212,255,0.2);
}

.btn-secondary {
    background: var(--btn-sec-bg);
    border: 1px solid var(--btn-sec-border);
    color: var(--text-secondary);
    font-family: var(--font-display);
    font-size: 0.9rem;
    font-weight: 500;
    padding: 10px 36px;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.4s cubic-bezier(0.22, 0.61, 0.36, 1);
    min-width: 260px;
    backdrop-filter: blur(6px);
    position: relative;
    overflow: hidden;
}

.btn-secondary::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, transparent 30%, rgba(0,212,255,0.04) 100%);
    opacity: 0;
    transition: opacity 0.3s;
}

.btn-secondary:hover::before { opacity: 1; }

.btn-secondary:hover {
    border-color: rgba(0,212,255,0.35);
    color: var(--text-primary);
    background: rgba(0,212,255,0.06);
    box-shadow: 0 0 30px rgba(0,212,255,0.08), inset 0 0 15px rgba(0,212,255,0.02);
    transform: translateY(-2px);
}

/* Panels */
.panel-box {
    background: var(--panel-bg);
    backdrop-filter: blur(30px);
    border: 1px solid var(--panel-border);
    border-radius: 18px;
    padding: 40px;
    max-width: 640px;
    width: 92%;
    max-height: 85vh;
    overflow-y: auto;
    animation: fadeSlideUp 0.5s cubic-bezier(0.22, 0.61, 0.36, 1);
    box-shadow: 0 25px 80px rgba(0,0,0,0.6), 0 0 50px rgba(0,212,255,0.04), inset 0 1px 0 rgba(255,255,255,0.03);
    position: relative;
}

.panel-box::before {
    content: '';
    position: absolute;
    top: 0;
    left: 10%;
    right: 10%;
    height: 1px;
    background: linear-gradient(90deg, transparent, rgba(0,212,255,0.3), transparent);
    border-radius: 1px;
}

.panel-box h2 {
    font-size: 1.7rem;
    margin-bottom: 24px;
    text-align: center;
    color: var(--accent-cyan);
    text-shadow: 0 0 20px rgba(0,212,255,0.2);
}

.panel-box h3 {
    font-size: 1rem;
    margin: 20px 0 12px;
    color: var(--text-primary);
}

/* Controls Grid */
.controls-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin-bottom: 20px;
}

.control-item {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.key-badge {
    background: var(--key-badge-bg);
    border: 1px solid var(--key-badge-border);
    color: var(--accent-cyan);
    padding: 4px 10px;
    border-radius: 6px;
    font-family: var(--font-mono);
    font-size: 0.72rem;
    white-space: nowrap;
    min-width: 80px;
    text-align: center;
}

/* Cube Types */
.cube-types {
    margin-top: 16px;
}

.cube-type {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 10px 0;
    font-size: 0.85rem;
    color: var(--text-secondary);
    border-bottom: 1px solid var(--cube-type-border);
}

.cube-preview {
    width: 32px;
    height: 32px;
    border-radius: 6px;
    flex-shrink: 0;
}
.cube-preview.light { background: rgba(0,212,255,0.3); border: 2px solid var(--accent-cyan); }
.cube-preview.medium { background: rgba(77,166,255,0.3); border: 2px solid var(--accent-blue); }
.cube-preview.heavy { background: rgba(255,107,53,0.3); border: 2px solid var(--accent-orange); }

/* Level Cards */
.level-cards {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 24px;
}

.level-card {
    background: var(--level-card-bg);
    border: 1px solid var(--level-card-border);
    border-radius: 14px;
    padding: 18px 22px;
    cursor: pointer;
    transition: all 0.4s cubic-bezier(0.22, 0.61, 0.36, 1);
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: relative;
    overflow: hidden;
    backdrop-filter: blur(4px);
}

.level-card::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 3px;
    background: linear-gradient(180deg, var(--accent-cyan), rgba(0,212,255,0.3));
    opacity: 0;
    transition: opacity 0.3s, width 0.3s;
    border-radius: 0 2px 2px 0;
}

.level-card::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(90deg, rgba(0,212,255,0.04) 0%, transparent 50%);
    opacity: 0;
    transition: opacity 0.3s;
}

.level-card:hover::after { opacity: 1; }

.level-card:hover::before {
    opacity: 1;
}

.level-card:hover {
    border-color: rgba(0,212,255,0.35);
    background: linear-gradient(135deg, rgba(0,212,255,0.08), rgba(0,180,255,0.03));
    transform: translateX(10px);
    box-shadow: 0 4px 30px rgba(0,212,255,0.1), 0 0 60px rgba(0,212,255,0.03);
}

.level-card:hover::before {
    width: 4px;
}

.level-card.locked {
    opacity: 0.4;
    pointer-events: none;
}

/* Level Actions Row */
.level-actions {
    display: flex;
    gap: 12px;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
}

.btn-export {
    position: relative;
    overflow: hidden;
}

.btn-export:hover {
    border-color: var(--accent-cyan) !important;
    color: var(--accent-cyan) !important;
    box-shadow: 0 0 25px rgba(0,212,255,0.15), inset 0 0 15px rgba(0,212,255,0.04);
}

.export-toast {
    position: fixed;
    bottom: 60px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: linear-gradient(135deg, rgba(0,212,255,0.15), rgba(0,180,255,0.08));
    border: 1px solid rgba(0,212,255,0.4);
    color: var(--accent-cyan);
    padding: 10px 24px;
    border-radius: 12px;
    font-family: var(--font-mono);
    font-size: 0.8rem;
    letter-spacing: 1px;
    backdrop-filter: blur(12px);
    z-index: 200;
    opacity: 0;
    transition: all 0.4s cubic-bezier(0.22, 0.61, 0.36, 1);
    pointer-events: none;
    white-space: nowrap;
}

.export-toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

.level-card-info h4 {
    font-size: 1rem;
    margin-bottom: 2px;
}

.level-card-info p {
    font-size: 0.78rem;
    color: var(--text-muted);
}

.level-card-best {
    font-family: var(--font-mono);
    font-size: 0.75rem;
    color: var(--accent-cyan);
}

/* Game Canvas */
#game-canvas {
    display: block;
    width: 100%;
    height: 100%;
    cursor: crosshair;
    image-rendering: auto;
}

#game-canvas.grabbing {
    cursor: grabbing !important;
}

#game-canvas.grab-hover {
    cursor: grab !important;
}

/* HUD */
.game-hud {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    padding: 14px 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--hud-gradient);
    pointer-events: none;
    z-index: 20;
    border-bottom: 1px solid rgba(0,212,255,0.04);
}

.game-hud * { pointer-events: auto; }

.hud-left, .hud-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

.hud-level {
    font-weight: 700;
    font-size: 1rem;
    color: var(--accent-cyan);
    text-shadow: 0 0 10px rgba(0,212,255,0.4), 0 0 20px rgba(0,212,255,0.15);
    letter-spacing: 1px;
    position: relative;
    animation: holoFlicker 4s ease-in-out infinite;
}

.hud-level::after {
    content: attr(data-text);
    position: absolute;
    left: 0;
    top: 0;
    color: rgba(0,212,255,0.15);
    clip-path: inset(0 0 60% 0);
    animation: holoGlitch 6s ease-in-out infinite;
}

@keyframes holoFlicker {
    0%, 94%, 100% { opacity: 1; }
    95% { opacity: 0.8; }
    96% { opacity: 1; }
    97% { opacity: 0.85; transform: translateX(0); }
    97.5% { opacity: 1; transform: translateX(1px); }
    98% { transform: translateX(0); }
}

@keyframes holoGlitch {
    0%, 90%, 100% { transform: translateX(0); opacity: 0; }
    92% { transform: translateX(-2px); opacity: 0.3; }
    94% { transform: translateX(2px); opacity: 0.2; }
    96% { transform: translateX(0); opacity: 0; }
}

.hud-timer {
    font-family: var(--font-mono);
    font-size: 0.9rem;
    color: var(--text-secondary);
    text-shadow: 0 0 6px rgba(0,212,255,0.15);
}

.hud-center {
    display: flex;
    align-items: center;
    gap: 10px;
}

.hud-charge-label {
    font-size: 0.72rem;
    color: var(--text-secondary);
    white-space: nowrap;
    font-family: var(--font-mono);
    letter-spacing: 0.5px;
    text-transform: uppercase;
}

.hud-charge-bar {
    width: 180px;
    height: 12px;
    background: var(--charge-bar-bg);
    border-radius: 6px;
    overflow: visible;
    border: 1px solid var(--charge-bar-border);
    box-shadow: inset 0 1px 3px rgba(0,0,0,0.3), 0 0 8px rgba(0,212,255,0.05);
    position: relative;
}

.hud-charge-fill {
    height: 100%;
    width: 100%;
    background: linear-gradient(90deg, var(--accent-cyan), var(--accent-blue));
    border-radius: 4px;
    transition: width 0.15s;
    box-shadow: 0 0 8px rgba(0,212,255,0.3);
    position: relative;
}

.hud-charge-fill.charge-critical {
    animation: chargeHeatHaze 0.5s ease-in-out infinite;
}

.hud-charge-fill.charge-critical::after {
    content: '';
    position: absolute;
    inset: -3px;
    background: linear-gradient(90deg, transparent, rgba(255,60,60,0.3), transparent);
    border-radius: 6px;
    animation: heatWave 0.3s ease-in-out infinite alternate;
    pointer-events: none;
}

@keyframes chargeHeatHaze {
    0%, 100% { filter: blur(0px) brightness(1); }
    25% { filter: blur(0.5px) brightness(1.3); }
    50% { filter: blur(0px) brightness(0.9); }
    75% { filter: blur(0.3px) brightness(1.2); }
}

@keyframes heatWave {
    0% { transform: scaleY(0.8) translateY(-1px); opacity: 0.5; }
    100% { transform: scaleY(1.3) translateY(1px); opacity: 0.8; }
}

.hud-held {
    font-size: 0.78rem;
    font-family: var(--font-mono);
    color: var(--accent-cyan);
}

.hud-btn {
    background: var(--hud-btn-bg);
    border: 1px solid var(--hud-btn-border);
    color: var(--text-secondary);
    width: 38px;
    height: 38px;
    border-radius: 10px;
    cursor: pointer;
    font-size: 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.25s cubic-bezier(0.22, 0.61, 0.36, 1);
    backdrop-filter: blur(8px);
}

.hud-btn:hover {
    border-color: var(--accent-cyan);
    color: var(--text-primary);
    background: rgba(0,212,255,0.1);
    box-shadow: 0 0 15px rgba(0,212,255,0.15);
    transform: scale(1.05);
}

/* Game Message */
.game-msg {
    position: absolute;
    inset: 0;
    background: var(--overlay-bg);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 25;
}

.game-msg.hidden { display: none; }

.msg-content {
    background: var(--bg-card);
    border: 1px solid var(--msg-border);
    border-radius: 14px;
    padding: 30px 40px;
    text-align: center;
    max-width: 400px;
    animation: fadeSlideUp 0.3s ease;
}

.msg-content h3 {
    font-size: 1.3rem;
    color: var(--accent-cyan);
    margin-bottom: 8px;
}

.msg-content p {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 16px;
    line-height: 1.6;
}

/* Win Screen */
.win-box {
    text-align: center;
    border: 1px solid var(--win-border);
    background: var(--win-bg);
}

.win-box::before {
    background: linear-gradient(90deg, transparent, rgba(59,255,107,0.3), transparent) !important;
}

.win-icon {
    font-size: 4.5rem;
    margin-bottom: 16px;
    animation: magnetFloat 2.5s ease-in-out infinite;
    filter: drop-shadow(0 0 40px rgba(59,255,107,0.5)) drop-shadow(0 0 80px rgba(59,255,107,0.15));
}

.win-box h2 {
    font-size: 2.2rem;
    color: var(--accent-green);
    text-shadow: 0 0 30px rgba(59,255,107,0.3);
    background: linear-gradient(135deg, #ffffff 20%, #90ffb0 50%, var(--accent-green) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.win-box p {
    font-size: 1rem;
    color: var(--text-secondary);
    margin: 8px 0;
}

.win-buttons {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-top: 24px;
    align-items: center;
}

/* Footer */
#footer {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 12px 20px;
    text-align: center;
    background: var(--footer-bg);
    border-top: 1px solid var(--footer-border);
    z-index: 50;
    font-size: 0.75rem;
    color: var(--text-muted);
    overflow: hidden;
}

#footer::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 1px;
    background: linear-gradient(90deg, transparent 10%, rgba(0,212,255,0.2) 30%, rgba(0,212,255,0.4) 50%, rgba(0,212,255,0.2) 70%, transparent 90%);
    animation: footerLine 4s ease-in-out infinite;
}

@keyframes footerLine {
    0%, 100% { opacity: 0.5; }
    50% { opacity: 1; }
}

.footer-sep { margin: 0 10px; opacity: 0.3; }

#footer a {
    color: var(--accent-cyan);
    text-decoration: none;
    transition: all 0.3s;
    position: relative;
}

#footer a::after {
    content: '';
    position: absolute;
    bottom: -2px;
    left: 0;
    width: 0;
    height: 1px;
    background: var(--accent-cyan);
    transition: width 0.3s;
}

#footer a:hover::after { width: 100%; }

#footer a:hover {
    color: #fff;
    text-shadow: 0 0 10px rgba(0,212,255,0.6);
}

/* Responsive */
/* Scrollbar styling */
.panel-box::-webkit-scrollbar {
    width: 6px;
}
.panel-box::-webkit-scrollbar-track {
    background: rgba(0,0,0,0.2);
    border-radius: 3px;
}
.panel-box::-webkit-scrollbar-thumb {
    background: rgba(0,212,255,0.2);
    border-radius: 3px;
}
.panel-box::-webkit-scrollbar-thumb:hover {
    background: rgba(0,212,255,0.35);
}

.title-ambient-glow {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 1;
    background: 
        radial-gradient(circle at 15% 85%, rgba(0,212,255,0.06) 0%, transparent 30%),
        radial-gradient(circle at 85% 80%, rgba(0,150,255,0.04) 0%, transparent 25%),
        radial-gradient(circle at 50% 20%, rgba(0,212,255,0.03) 0%, transparent 40%);
    animation: ambientShift 8s ease-in-out infinite alternate;
}

@keyframes ambientShift {
    0% { opacity: 0.6; transform: scale(1); }
    50% { opacity: 1; transform: scale(1.05); }
    100% { opacity: 0.7; transform: scale(0.98); }
}

.title-version {
    font-family: var(--font-mono);
    font-size: 0.65rem;
    color: rgba(0,212,255,0.3);
    letter-spacing: 3px;
    text-transform: uppercase;
    margin-bottom: 32px;
    animation: fadeSlideUp 1.5s cubic-bezier(0.22, 0.61, 0.36, 1);
}

@media (max-width: 768px) {
    .game-title { font-size: 2.4rem; letter-spacing: 4px; }
    .game-subtitle { font-size: 0.95rem; }
    .title-magnet { font-size: 3.5rem; }
    .btn-main { min-width: 220px; font-size: 0.95rem; padding: 12px 32px; }
    .btn-secondary { min-width: 220px; }
    .panel-box { padding: 24px; }
    .controls-grid { grid-template-columns: 1fr; }
    .hud-center { display: none; }
    .game-hud { padding: 8px 12px; }
}

/* ═══ KEYBOARD SHORTCUTS OVERLAY ═══ */
.shortcuts-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.75);
    backdrop-filter: blur(8px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 30;
    animation: shortcutsFadeIn 0.25s cubic-bezier(0.22, 0.61, 0.36, 1);
}

.shortcuts-overlay.hidden {
    display: none;
}

@keyframes shortcutsFadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.shortcuts-panel {
    background: linear-gradient(165deg, rgba(12, 18, 38, 0.97), rgba(8, 12, 28, 0.99));
    border: 1px solid rgba(0, 212, 255, 0.2);
    border-radius: 16px;
    padding: 28px 32px 20px;
    max-width: 520px;
    width: 90%;
    box-shadow: 0 25px 80px rgba(0, 0, 0, 0.7), 0 0 60px rgba(0, 212, 255, 0.08), inset 0 1px 0 rgba(255, 255, 255, 0.04);
    animation: fadeSlideUp 0.3s cubic-bezier(0.22, 0.61, 0.36, 1);
    position: relative;
    overflow: hidden;
}

.shortcuts-panel::before {
    content: '';
    position: absolute;
    top: 0;
    left: 10%;
    right: 10%;
    height: 1px;
    background: linear-gradient(90deg, transparent, rgba(0, 212, 255, 0.4), transparent);
}

.shortcuts-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding-bottom: 12px;
    border-bottom: 1px solid rgba(0, 212, 255, 0.08);
}

.shortcuts-title {
    font-family: var(--font-display);
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--accent-cyan);
    letter-spacing: 1px;
    text-shadow: 0 0 15px rgba(0, 212, 255, 0.3);
}

.shortcuts-close {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: var(--text-secondary);
    width: 30px;
    height: 30px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.85rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.shortcuts-close:hover {
    background: rgba(255, 60, 60, 0.15);
    border-color: rgba(255, 60, 60, 0.4);
    color: #ff5555;
}

.shortcuts-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.shortcut-section h4 {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 8px;
    letter-spacing: 1px;
    text-transform: uppercase;
}

.shortcut-row {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.72rem;
    color: var(--text-secondary);
    margin-bottom: 5px;
    flex-wrap: wrap;
}

.shortcut-row span {
    margin-left: auto;
    text-align: right;
    color: var(--text-muted);
    font-size: 0.68rem;
}

.shortcuts-panel kbd,
.shortcuts-footer kbd,
.title-shortcut-hint kbd {
    background: var(--key-badge-bg);
    border: 1px solid var(--key-badge-border);
    color: var(--accent-cyan);
    padding: 2px 7px;
    border-radius: 5px;
    font-family: var(--font-mono);
    font-size: 0.65rem;
    font-weight: 500;
    display: inline-block;
    min-width: 22px;
    text-align: center;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3), inset 0 -1px 0 rgba(0, 0, 0, 0.2);
    line-height: 1.4;
}

.shortcuts-footer {
    margin-top: 16px;
    padding-top: 12px;
    border-top: 1px solid rgba(0, 212, 255, 0.06);
    text-align: center;
    font-size: 0.68rem;
    color: var(--text-muted);
    font-family: var(--font-mono);
    letter-spacing: 0.5px;
}

/* Title screen shortcut hint */
.title-shortcut-hint {
    margin-top: 20px;
    font-size: 0.7rem;
    color: var(--text-muted);
    font-family: var(--font-mono);
    letter-spacing: 0.5px;
    opacity: 0.6;
    animation: fadeSlideUp 2s cubic-bezier(0.22, 0.61, 0.36, 1);
    transition: opacity 0.3s;
}

.title-shortcut-hint:hover {
    opacity: 1;
}

/* Light theme overrides for shortcuts */
[data-theme="light"] .shortcuts-overlay {
    background: rgba(255, 255, 255, 0.8);
}

[data-theme="light"] .shortcuts-panel {
    background: linear-gradient(165deg, rgba(255, 255, 255, 0.97), rgba(240, 244, 252, 0.99));
    border-color: rgba(0, 144, 184, 0.25);
    box-shadow: 0 25px 80px rgba(0, 0, 0, 0.15), 0 0 40px rgba(0, 144, 184, 0.05);
}

[data-theme="light"] .shortcuts-panel::before {
    background: linear-gradient(90deg, transparent, rgba(0, 144, 184, 0.4), transparent);
}

[data-theme="light"] .shortcuts-close:hover {
    background: rgba(255, 60, 60, 0.1);
}

/* Pause overlay */
.pause-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 28;
    animation: shortcutsFadeIn 0.2s ease;
}

.pause-overlay.hidden {
    display: none;
}

.pause-text {
    font-family: var(--font-display);
    font-size: 3rem;
    font-weight: 700;
    color: var(--accent-cyan);
    letter-spacing: 12px;
    text-shadow: 0 0 40px rgba(0, 212, 255, 0.5), 0 0 80px rgba(0, 212, 255, 0.2);
    text-transform: uppercase;
    animation: pausePulse 2s ease-in-out infinite;
}

@keyframes pausePulse {
    0%, 100% { opacity: 0.8; transform: scale(1); }
    50% { opacity: 1; transform: scale(1.03); }
}

.pause-subtitle {
    font-family: var(--font-mono);
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-top: 12px;
    letter-spacing: 2px;
    text-align: center;
}

@media (max-width: 768px) {
    .shortcuts-grid {
        grid-template-columns: 1fr;
        gap: 12px;
    }

    .shortcuts-panel {
        padding: 20px 22px 16px;
        max-width: 90%;
    }

    .pause-text {
        font-size: 2rem;
        letter-spacing: 8px;
    }
}

@media (max-width: 480px) {
    .game-title { font-size: 1.8rem; }
}