:root {
    --color-bg: #0a0a12;
    --color-bg-subtle: #12121f;
    --color-surface: #1a1a2e;
    --color-surface-raised: #252542;
    --color-border: #3a3a5c;
    --color-text: #e8e8f0;
    --color-text-muted: #8888a8;
    --color-accent: #7b68ee;
    --color-accent-glow: rgba(123, 104, 238, 0.5);
    --color-crystal: #00d4ff;
    --color-crystal-glow: rgba(0, 212, 255, 0.6);
    --color-danger: #ff4466;
    --color-danger-glow: rgba(255, 68, 102, 0.5);
    --color-success: #44ff88;
    --color-gold: #ffd700;
    --color-path-visited: rgba(255, 100, 120, 0.35);
    --font-display: 'Cinzel', serif;
    --font-body: 'Crimson Text', Georgia, serif;
    --tile-size: 32px;
    --transition-fast: 150ms ease;
    --transition-normal: 300ms ease;
}

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

html, body {
    height: 100%;
    overflow: hidden;
}

body {
    font-family: var(--font-body);
    background: var(--color-bg);
    color: var(--color-text);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: 
        radial-gradient(ellipse at 20% 20%, rgba(123, 104, 238, 0.08) 0%, transparent 50%),
        radial-gradient(ellipse at 80% 80%, rgba(0, 212, 255, 0.06) 0%, transparent 50%),
        linear-gradient(180deg, var(--color-bg) 0%, var(--color-bg-subtle) 100%);
    pointer-events: none;
    z-index: -1;
}

#app {
    display: flex;
    flex-direction: column;
    height: 100%;
    max-width: 900px;
    margin: 0 auto;
    padding: 1rem;
}

#header {
    text-align: center;
    padding: 0.5rem 0 1rem;
    flex-shrink: 0;
}

#header h1 {
    font-family: var(--font-display);
    font-size: clamp(1.5rem, 6vw, 2.5rem);
    font-weight: 700;
    letter-spacing: 0.3em;
    color: var(--color-text);
    text-shadow: 
        0 0 20px var(--color-accent-glow),
        0 0 40px var(--color-accent-glow);
    margin-bottom: 0.25rem;
}

#header .subtitle {
    font-size: 0.9rem;
    color: var(--color-text-muted);
    font-style: italic;
    letter-spacing: 0.1em;
}

#main {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    min-height: 0;
}

#game-container {
    position: relative;
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: 8px;
    overflow: hidden;
    min-height: 500px;
    box-shadow: 
        inset 0 0 60px rgba(0, 0, 0, 0.5),
        0 4px 20px rgba(0, 0, 0, 0.3);
}

#game-canvas {
    width: 100%;
    height: 100%;
}

#game-canvas canvas {
    display: block;
    max-width: 100%;
    max-height: 100%;
    margin: auto;
}

#game-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(10, 10, 18, 0.92);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    backdrop-filter: blur(4px);
}

#game-overlay.hidden {
    display: none;
}

#overlay-content {
    text-align: center;
    padding: 2rem;
    max-width: 90%;
}

#overlay-title {
    font-family: var(--font-display);
    font-size: 2rem;
    margin-bottom: 1rem;
    letter-spacing: 0.15em;
}

#overlay-title.victory {
    color: var(--color-success);
    text-shadow: 0 0 30px rgba(68, 255, 136, 0.5);
}

#overlay-title.defeat {
    color: var(--color-danger);
    text-shadow: 0 0 30px var(--color-danger-glow);
}

#overlay-message {
    color: var(--color-text-muted);
    margin-bottom: 1.5rem;
    font-size: 1.1rem;
}

#results-display {
    display: flex;
    gap: 2rem;
    justify-content: center;
    margin-bottom: 1.5rem;
}

#results-display.hidden {
    display: none;
}

.result-stat {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.stat-label {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.15em;
    color: var(--color-text-muted);
}

.stat-value {
    font-family: var(--font-display);
    font-size: 2rem;
    color: var(--color-gold);
    text-shadow: 0 0 10px rgba(255, 215, 0, 0.4);
}

#overlay-buttons {
    display: flex;
    gap: 1rem;
    justify-content: center;
    flex-wrap: wrap;
}

.btn {
    font-family: var(--font-display);
    font-size: 0.9rem;
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    transition: all var(--transition-fast);
    letter-spacing: 0.1em;
    text-transform: uppercase;
}

.btn-primary {
    background: var(--color-accent);
    color: white;
    box-shadow: 0 0 20px var(--color-accent-glow);
}

.btn-primary:hover {
    background: #8b7bee;
    box-shadow: 0 0 30px var(--color-accent-glow);
    transform: translateY(-2px);
}

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

.btn-secondary {
    background: transparent;
    color: var(--color-text);
    border: 1px solid var(--color-border);
}

.btn-secondary:hover {
    background: var(--color-surface-raised);
    border-color: var(--color-accent);
}

.btn-small {
    font-size: 0.75rem;
    padding: 0.5rem 1rem;
    background: var(--color-surface-raised);
    color: var(--color-text-muted);
    border: 1px solid var(--color-border);
}

.btn-small:hover {
    color: var(--color-text);
    border-color: var(--color-text-muted);
}

.btn.hidden {
    display: none;
}

#controls-container {
    flex-shrink: 0;
    display: flex;
    justify-content: center;
    padding: 0.5rem 0;
}

#d-pad {
    display: grid;
    grid-template-columns: repeat(3, 60px);
    grid-template-rows: repeat(3, 60px);
    gap: 4px;
}

.d-btn {
    background: var(--color-surface-raised);
    border: 1px solid var(--color-border);
    border-radius: 8px;
    color: var(--color-text);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-fast);
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

.d-btn svg {
    width: 24px;
    height: 24px;
    fill: currentColor;
}

.d-btn:hover {
    background: var(--color-accent);
    border-color: var(--color-accent);
    box-shadow: 0 0 15px var(--color-accent-glow);
}

.d-btn:active, .d-btn.active {
    background: var(--color-accent);
    transform: scale(0.95);
}

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

#status-bar {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 2rem;
    padding: 0.75rem;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: 6px;
}

.status-item {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.status-label {
    font-size: 0.65rem;
    text-transform: uppercase;
    letter-spacing: 0.15em;
    color: var(--color-text-muted);
}

.status-value {
    font-family: var(--font-display);
    font-size: 1.25rem;
    color: var(--color-crystal);
}

#footer {
    flex-shrink: 0;
    text-align: center;
    padding: 0.75rem 0;
    color: var(--color-text-muted);
    font-size: 0.8rem;
    font-style: italic;
}

#loading-screen {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--color-bg);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    transition: opacity 0.5s ease;
}

#loading-screen.hidden {
    opacity: 0;
    pointer-events: none;
}

.loader {
    text-align: center;
}

.crystal {
    width: 40px;
    height: 40px;
    margin: 0 auto 1rem;
    background: linear-gradient(135deg, var(--color-crystal), var(--color-accent));
    border-radius: 50%;
    animation: pulse 1.5s ease-in-out infinite;
    box-shadow: 0 0 30px var(--color-crystal-glow);
}

@keyframes pulse {
    0%, 100% { 
        transform: scale(1); 
        box-shadow: 0 0 30px var(--color-crystal-glow);
    }
    50% { 
        transform: scale(1.1); 
        box-shadow: 0 0 50px var(--color-crystal-glow);
    }
}

.loader p {
    font-family: var(--font-display);
    letter-spacing: 0.1em;
    color: var(--color-text-muted);
}

@media (min-width: 768px) {
    #controls-container {
        display: none;
    }
    
    #app {
        padding: 2rem;
        max-width: 1000px;
    }
    
    #game-container {
        min-height: 700px;
    }
}

@media (max-height: 600px) {
    #header {
        padding: 0.25rem 0 0.5rem;
    }
    
    #header h1 {
        font-size: 1.25rem;
    }
    
    #header .subtitle {
        display: none;
    }
    
    #d-pad {
        grid-template-columns: repeat(3, 50px);
        grid-template-rows: repeat(3, 50px);
    }
    
    #footer {
        display: none;
    }
}

@media (max-height: 500px) {
    #controls-container {
        position: fixed;
        bottom: 10px;
        right: 10px;
        padding: 0;
    }
    
    #d-pad {
        grid-template-columns: repeat(3, 40px);
        grid-template-rows: repeat(3, 40px);
        opacity: 0.8;
    }
}
