/* =========================================
   1. VARIABLES — Minimalist Premium Indie
   ========================================= */
:root {
    --bg-dark:    #0B0F19; /* Deep slate */
    --bg-panel:   #151C2C; /* Slightly lighter slate */
    --bg-card:    #1E293B; /* Card background */
    --primary:    #6366F1; /* Indigo */
    --primary-dark: #4F46E5;
    --accent:     #38BDF8; /* Light Blue */
    --text-main:  #F8FAFC;
    --text-muted: #94A3B8;
    --success:    #10B981;
    --warning:    #F59E0B;
    --danger:     #F43F5E;
    --header-h:   64px;
    --radius-sm:  8px;
    --radius-md:  12px;
    --radius-lg:  16px;
    --shadow-sm:  0 2px 0 rgba(0,0,0,0.2);
    --shadow-md:  0 4px 0 rgba(0,0,0,0.25);
    --shadow-btn: 0 4px 0 rgba(0,0,0,0.3);
}

html {
    color-scheme: dark;
}

/* =========================================
   2. RESET & LAYOUT
   ========================================= */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}

body {
    background-color: var(--bg-dark);
    color: var(--text-main);
    font-family: 'Outfit', sans-serif;
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100dvh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.font-mono {
    font-family: 'JetBrains Mono', monospace;
}

/* =========================================
   3. BACKGROUND STACK
   ========================================= */
.dynamic-bg {
    position: fixed;
    inset: 0;
    z-index: -3;
    background-size: cover;
    background-position: center;
    opacity: 0.15;
    transition: background-image 0.4s ease-in-out;
}

.bg-pattern {
    position: fixed;
    inset: 0;
    z-index: -2;
    background-image: radial-gradient(var(--bg-panel) 1px, transparent 1px);
    background-size: 24px 24px;
    opacity: 0.3;
    pointer-events: none;
}

/* =========================================
   4. APP SHELL
   ========================================= */
#app { width: 100%; height: 100%; display: flex; flex-direction: column; }

.top-bar {
    height: var(--header-h);
    background: var(--bg-panel);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    z-index: 50;
    flex-shrink: 0;
    box-shadow: 0 2px 10px rgba(0,0,0,0.2);
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 800;
    font-size: 1.25rem;
    letter-spacing: 1px;
    color: var(--text-main);
}

.game-tag {
    color: var(--accent);
    margin-left: 4px;
}

.coins-wrapper {
    display: flex;
    align-items: center;
}

.coins-display {
    display: flex;
    align-items: center;
    gap: 6px;
    background: var(--bg-dark);
    padding: 6px 12px;
    border-radius: 20px;
    font-family: 'JetBrains Mono', monospace;
    font-weight: 700;
    color: var(--warning);
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.2);
}

.icon {
    width: 20px; height: 20px;
    display: inline-block; vertical-align: middle; flex-shrink: 0;
}

/* =========================================
   5. SCREENS
   ========================================= */
.screen {
    flex: 1;
    display: flex;
    flex-direction: column;
    width: 100%;
    position: absolute;
    top: var(--header-h); bottom: 0; left: 0;
    opacity: 0;
    pointer-events: none;
    transform: translateY(10px);
    transition: opacity 0.3s ease, transform 0.3s ease;
    overflow: hidden;
}
.screen.active {
    opacity: 1;
    pointer-events: all;
    transform: translateY(0);
    z-index: 10;
}

/* =========================================
   6. SCREEN: MENU
   ========================================= */
#screen-menu {
    justify-content: center;
    align-items: center;
    overflow-y: auto;
}

.menu-content {
    text-align: center;
    width: 100%;
    max-width: 320px;
    padding: 20px;
}

.game-title {
    font-size: 3.5rem;
    font-weight: 800;
    line-height: 1;
    margin-bottom: 8px;
    color: var(--text-main);
    text-shadow: 0 4px 0 var(--primary-dark);
}

.game-subtitle {
    font-size: 1rem;
    font-weight: 600;
    color: var(--accent);
    letter-spacing: 2px;
    text-transform: uppercase;
    margin-bottom: 40px;
}

.main-nav {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

/* =========================================
   7. SCREEN: LEVELS
   ========================================= */
#screen-levels { height: 100%; display: flex; flex-direction: column; }

.screen-header {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 0 20px;
    height: 60px;
    flex-shrink: 0;
    background: var(--bg-panel);
    z-index: 5;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}

.screen-header h2 {
    font-weight: 800;
    font-size: 1.25rem;
    letter-spacing: 1px;
}

#levels-container {
    flex: 1;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
    grid-auto-rows: max-content;
    align-content: start;
    gap: 16px;
    padding: 20px;
    padding-bottom: 100px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    width: 100%;
    max-width: 800px;
    margin: 0 auto;
}

.level-card {
    position: relative;
    aspect-ratio: 1 / 1;
    min-height: 100px;
    background: var(--bg-card);
    border-radius: var(--radius-md);
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    contain: layout style paint;
    content-visibility: auto;
    contain-intrinsic-size: 100px;
    box-shadow: var(--shadow-md);
    overflow: hidden;
    transition: transform 0.1s ease, box-shadow 0.1s ease;
}
.level-card:active { 
    transform: translateY(2px);
    box-shadow: var(--shadow-sm);
}
.level-card:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.level-card img {
    width: 100%; height: 100%;
    object-fit: cover;
    display: block;
    opacity: 0;
    transition: opacity 0.3s ease;
}
.level-card img.loaded { opacity: 1; }

.level-overlay {
    position: absolute; inset: 0; z-index: 2;
    display: flex; justify-content: center; align-items: center;
    background: rgba(15, 23, 42, 0.6);
    color: white;
    font-size: 1.5rem; font-weight: 800;
    pointer-events: none;
}

.level-card.locked {
    background: var(--bg-panel);
    cursor: not-allowed;
    box-shadow: none;
}
.level-card.locked img { display: none; }
.level-card.locked .level-overlay { background: transparent; color: var(--text-muted); }
.level-card.locked:active { transform: none; box-shadow: none; }

.level-card.completed {
    border: 2px solid var(--success);
}

/* =========================================
   8. SCREEN: GAME — HUD
   ========================================= */
.hud {
    padding: 0 16px;
    height: 60px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--bg-panel);
    flex-shrink: 0;
    z-index: 20;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}

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

.hud-stat .value {
    font-size: 1.1rem;
    font-weight: 800;
    color: var(--text-main);
}

.canvas-wrapper {
    flex: 1;
    position: relative;
    overflow: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1;
    touch-action: none;
}

canvas { max-width: 100%; max-height: 100%; object-fit: contain; }

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

.btn-hud-action {
    width: 44px; height: 44px; min-height: 44px;
    border-radius: var(--radius-sm);
    border: none;
    background: var(--bg-card); 
    color: var(--text-main);
    cursor: pointer;
    display: flex; justify-content: center; align-items: center;
    touch-action: manipulation;
    box-shadow: var(--shadow-sm);
    transition: transform 0.1s, box-shadow 0.1s, background 0.1s;
    flex-shrink: 0;
}
.btn-hud-action:active { 
    transform: translateY(2px); 
    box-shadow: none;
    background: var(--bg-panel);
}
.btn-hud-action.gold { color: var(--warning); }
.btn-hud-action:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* =========================================
   9. BUTTONS (Flat 2.0)
   ========================================= */
.btn {
    border: none; outline: none;
    padding: 0 24px;
    height: 56px; min-height: 48px;
    border-radius: var(--radius-md);
    font-family: 'Outfit', sans-serif;
    font-weight: 800; font-size: 1.1rem;
    letter-spacing: 1px;
    cursor: pointer;
    display: flex; justify-content: center; align-items: center; gap: 12px;
    text-decoration: none;
    touch-action: manipulation;
    position: relative;
    transition: transform 0.1s, box-shadow 0.1s, background 0.1s;
    box-shadow: var(--shadow-btn);
    width: 100%;
}
.btn:active { 
    transform: translateY(4px); 
    box-shadow: none;
}
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.btn-primary { 
    background: var(--primary); 
    color: #fff; 
    box-shadow: 0 4px 0 var(--primary-dark);
}
.btn-primary:active { box-shadow: 0 0 0 var(--primary-dark); }

.btn-secondary { 
    background: var(--bg-card); 
    color: var(--text-main); 
    box-shadow: 0 4px 0 #0F172A;
}
.btn-secondary:active { box-shadow: 0 0 0 #0F172A; }

.btn-danger { 
    background: var(--danger); 
    color: #fff; 
    box-shadow: 0 4px 0 #BE123C;
}
.btn-danger:active { box-shadow: 0 0 0 #BE123C; }

.btn-icon {
    width: 44px; height: 44px; min-height: 44px;
    border-radius: var(--radius-sm);
    border: none;
    background: var(--bg-card); 
    color: var(--text-main);
    cursor: pointer;
    display: flex; justify-content: center; align-items: center;
    touch-action: manipulation;
    box-shadow: var(--shadow-sm);
    transition: transform 0.1s, box-shadow 0.1s;
}
.btn-icon:active { 
    transform: translateY(2px); 
    box-shadow: none;
}
.btn-icon:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* =========================================
   10. MODALS
   ========================================= */
.modal-backdrop {
    position: fixed; inset: 0;
    background: rgba(11, 15, 25, 0.85);
    display: flex; justify-content: center; align-items: center;
    z-index: 100; opacity: 1;
    transition: opacity 0.2s;
}
.modal-backdrop.hidden { opacity: 0; pointer-events: none; }

.modal-content {
    background: var(--bg-panel);
    padding: 32px 24px;
    border-radius: var(--radius-lg);
    text-align: center; 
    width: 90%; max-width: 360px;
    box-shadow: 0 10px 25px rgba(0,0,0,0.5);
    transform: scale(1);
    transition: transform 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
.modal-backdrop.hidden .modal-content {
    transform: scale(0.9);
}

.modal-content h3 {
    font-weight: 800;
    font-size: 1.5rem; 
    margin-bottom: 12px;
    letter-spacing: 1px;
}

.modal-content p {
    color: var(--text-muted);
    margin-bottom: 24px;
    font-size: 1rem;
}

.modal-actions {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.text-danger { color: var(--danger); }
.text-success { color: var(--success); }

.victory-reward {
    display: flex; align-items: center; justify-content: center; gap: 8px; 
    margin-bottom: 24px;
    font-size: 1.5rem;
    font-weight: 800;
    color: var(--warning);
}
.icon-coin {
    width: 28px; height: 28px;
}

/* =========================================
   11. SETTINGS
   ========================================= */
.settings-list { padding: 24px; display: flex; flex-direction: column; gap: 16px; }
.setting-item {
    display: flex; justify-content: space-between; align-items: center;
    background: var(--bg-card);
    padding: 16px 20px; min-height: 56px;
    border-radius: var(--radius-md);
    color: var(--text-main); font-size: 1.1rem; font-weight: 600;
}

/* Toggle Switch */
.toggle-switch {
    position: relative;
    display: inline-block;
    width: 50px;
    height: 28px;
}
.toggle-switch input { 
    opacity: 0;
    width: 0;
    height: 0;
}
.slider {
    position: absolute;
    cursor: pointer;
    top: 0; left: 0; right: 0; bottom: 0;
    background-color: var(--bg-panel);
    transition: .2s;
    border-radius: 34px;
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.2);
}
.slider:before {
    position: absolute;
    content: "";
    height: 20px;
    width: 20px;
    left: 4px;
    bottom: 4px;
    background-color: var(--text-muted);
    transition: .2s;
    border-radius: 50%;
}
input:checked + .slider {
    background-color: var(--primary);
}
input:checked + .slider:before {
    transform: translateX(22px);
    background-color: #fff;
}

/* =========================================
   12. LOADING
   ========================================= */
.loading-overlay {
    position: absolute; inset: 0;
    background: var(--bg-dark); z-index: 30;
    display: flex; justify-content: center; align-items: center;
}
.loading-overlay.hidden { display: none; }

.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid rgba(255,255,255,0.1);
    border-left-color: var(--primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* =========================================
   13. SKELETON
   ========================================= */
.skeleton { background: var(--bg-panel); position: relative; overflow: hidden; }
.skeleton::after {
    content: ''; position: absolute; inset: 0;
    transform: translateX(-100%);
    background-image: linear-gradient(
        90deg, transparent 0, rgba(255,255,255,0.05) 20%, rgba(255,255,255,0.08) 60%, transparent
    );
    animation: shimmer 2s infinite;
}
@keyframes shimmer { 100% { transform: translateX(100%); } }

/* =========================================
   15. SCROLLBAR
   ========================================= */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-thumb { background: var(--bg-card); border-radius: 4px; }
::-webkit-scrollbar-track { background: transparent; }

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}
