/* -------------------------------------------------------------
 * Stack Tower - Master CSS Stylesheet (Hyper-Polished Edition)
 * Modern Glassmorphism, Responsive UI, Dynamic Themes & Glow FX
 * ------------------------------------------------------------- */

@import url('https://fonts.googleapis.com/css2?family=Outfit:wght@400;600;700;800;900&display=swap');

:root {
    --font-main: 'Outfit', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    --primary-color: #6366F1;
    --primary-hover: #4F46E5;
    --accent-gold: #F59E0B;
    --accent-pink: #EC4899;
    --accent-teal: #14B8A6;
    
    --glass-bg: rgba(255, 255, 255, 0.28);
    --glass-border: rgba(255, 255, 255, 0.5);
    --glass-shadow: 0 12px 40px 0 rgba(31, 38, 135, 0.18);
    --text-color: #0F172A;
    --bg-gradient: linear-gradient(180deg, #EAF6FF 0%, #CDEBFF 100%);

    /* Modal Close Button Colors */
    --close-btn-bg: rgba(0, 0, 0, 0.08);
    --close-btn-color: #0F172A;
}

/* Background Theme Presets */
body[data-theme="sky"] {
    --bg-gradient: linear-gradient(180deg, #EAF6FF 0%, #BEE3FE 100%);
    --text-color: #0F172A;
    --close-btn-bg: rgba(0, 0, 0, 0.08);
    --close-btn-color: #0F172A;
}

body[data-theme="night"] {
    --bg-gradient: linear-gradient(180deg, #0F172A 0%, #1E1B4B 100%);
    --text-color: #F8FAFC;
    --glass-bg: rgba(30, 41, 59, 0.65);
    --glass-border: rgba(255, 255, 255, 0.15);
    --glass-shadow: 0 12px 40px 0 rgba(0, 0, 0, 0.5);
    --close-btn-bg: rgba(255, 255, 255, 0.15);
    --close-btn-color: #F8FAFC;
}

body[data-theme="snow"] {
    --bg-gradient: linear-gradient(180deg, #DCEEFF 0%, #B3D8FD 100%);
    --text-color: #0F172A;
    --close-btn-bg: rgba(0, 0, 0, 0.08);
    --close-btn-color: #0F172A;
}

body[data-theme="neon"] {
    --bg-gradient: linear-gradient(180deg, #18002E 0%, #03001E 100%);
    --text-color: #F0ABFC;
    --glass-bg: rgba(45, 10, 80, 0.55);
    --glass-border: rgba(236, 72, 153, 0.45);
    --primary-color: #D946EF;
    --glass-shadow: 0 12px 40px 0 rgba(217, 70, 239, 0.25);
    --close-btn-bg: rgba(236, 72, 153, 0.25);
    --close-btn-color: #F0ABFC;
}

body[data-theme="minimal"] {
    --bg-gradient: linear-gradient(180deg, #F8FAFC 0%, #E2E8F0 100%);
    --text-color: #334155;
    --close-btn-bg: rgba(0, 0, 0, 0.08);
    --close-btn-color: #334155;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
}

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    font-family: var(--font-main);
    background: var(--bg-gradient);
    color: var(--text-color);
    transition: background 0.6s ease, color 0.6s ease;
}

/* Outer Flex Wrapper for Responsive Centering */
#app-container {
    width: 100vw;
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
}

/* Fixed Aspect-Ratio Game Frame */
#game-frame {
    position: relative;
    width: 100%;
    height: 100%;
    max-width: 480px;
    max-height: 900px;
    box-shadow: 0 24px 60px rgba(0, 0, 0, 0.22);
    overflow: hidden;
    background: transparent;
}

@media (min-width: 520px) and (min-height: 700px) {
    #game-frame {
        height: 92vh;
        border-radius: 32px;
        border: 4px solid var(--glass-border);
    }
}

/* HTML5 Canvas */
#game-canvas {
    width: 100%;
    height: 100%;
    display: block;
    touch-action: none;
}

/* UI Overlay Common Container */
.ui-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    align-items: center;
    padding: 24px;
    z-index: 10;
    pointer-events: none;
}

.ui-overlay > * {
    pointer-events: auto;
}

.hidden {
    display: none !important;
}

/* Glassmorphism Panel Base */
.glass-panel {
    background: var(--glass-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--glass-border);
    box-shadow: var(--glass-shadow);
    border-radius: 28px;
    padding: 32px;
    text-align: center;
}

/* -------------------------------------------------------------
 * HUD (In-Game Header)
 * ------------------------------------------------------------- */
#game-hud {
    padding: 20px 24px;
}

.hud-top-bar {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
}

.score-box {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
}

.score-label {
    font-size: 0.75rem;
    font-weight: 800;
    letter-spacing: 2px;
    text-transform: uppercase;
    opacity: 0.7;
}

.score-value {
    font-size: 3.2rem;
    font-weight: 900;
    line-height: 1;
    text-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
}

.best-box {
    align-items: flex-end;
}

.best-box .score-value {
    font-size: 1.8rem;
    color: var(--accent-gold);
}

/* Combo Badge Overlay */
.combo-badge {
    position: absolute;
    top: 96px;
    left: 50%;
    transform: translateX(-50%);
    background: linear-gradient(135deg, #F59E0B 0%, #EC4899 100%);
    color: #FFFFFF;
    padding: 10px 24px;
    border-radius: 24px;
    font-size: 1.15rem;
    font-weight: 900;
    box-shadow: 0 8px 24px rgba(245, 158, 11, 0.45);
    letter-spacing: 1px;
}

.combo-badge.bounce {
    animation: comboPulse 0.45s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes comboPulse {
    0% { transform: translateX(-50%) scale(0.6); }
    50% { transform: translateX(-50%) scale(1.3); }
    100% { transform: translateX(-50%) scale(1); }
}

/* Buttons */
.btn {
    border: none;
    outline: none;
    cursor: pointer;
    font-family: var(--font-main);
    font-weight: 900;
    border-radius: 18px;
    transition: transform 0.18s cubic-bezier(0.175, 0.885, 0.32, 1.275), box-shadow 0.18s ease, background 0.2s ease;
    display: inline-flex;
    justify-content: center;
    align-items: center;
    gap: 12px;
}

.btn:active {
    transform: scale(0.93) !important;
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--accent-pink) 100%);
    color: #FFFFFF;
    padding: 18px 36px;
    font-size: 1.3rem;
    box-shadow: 0 12px 28px rgba(99, 102, 241, 0.4);
    width: 100%;
}

.btn-primary:hover {
    transform: translateY(-3px);
    box-shadow: 0 16px 32px rgba(99, 102, 241, 0.5);
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.85);
    color: #0F172A;
    padding: 14px 24px;
    font-size: 1.05rem;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.08);
    width: 100%;
}

body[data-theme="night"] .btn-secondary {
    background: rgba(255, 255, 255, 0.15);
    color: #F8FAFC;
}

.btn-secondary:hover {
    transform: translateY(-2px);
}

.btn-icon {
    width: 48px;
    height: 48px;
    border-radius: 16px;
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    font-size: 1.3rem;
    color: inherit;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}

/* -------------------------------------------------------------
 * Main Menu Screen
 * ------------------------------------------------------------- */
#main-menu {
    justify-content: center;
    background: rgba(255, 255, 255, 0.04);
}

.menu-card {
    width: 100%;
    max-width: 400px;
    display: flex;
    flex-direction: column;
    gap: 22px;
    animation: menuSlideUp 0.6s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes menuSlideUp {
    0% { opacity: 0; transform: translateY(30px); }
    100% { opacity: 1; transform: translateY(0); }
}

.game-title {
    font-size: 3.5rem;
    font-weight: 900;
    letter-spacing: -1.5px;
    line-height: 0.95;
    background: linear-gradient(135deg, #4F46E5 0%, #EC4899 50%, #F59E0B 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    margin-bottom: 6px;
}

.game-subtitle {
    font-size: 0.9rem;
    font-weight: 800;
    opacity: 0.75;
    letter-spacing: 3px;
    text-transform: uppercase;
}

.high-score-banner {
    background: rgba(245, 158, 11, 0.15);
    border: 1px solid rgba(245, 158, 11, 0.4);
    padding: 12px 18px;
    border-radius: 16px;
    font-size: 1.05rem;
    font-weight: 900;
    color: var(--accent-gold);
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
}

.menu-btn-group {
    display: flex;
    flex-direction: column;
    gap: 14px;
    margin-top: 8px;
}

/* -------------------------------------------------------------
 * Modals & Screens
 * ------------------------------------------------------------- */
.modal-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(10px);
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
    z-index: 20;
}

.modal-card {
    width: 100%;
    max-width: 420px;
    max-height: 85vh;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 22px;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-title {
    font-size: 1.8rem;
    font-weight: 900;
}

/* Close Modal Button (Theme Adaptive) */
.close-modal-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 1px solid var(--glass-border);
    background: var(--close-btn-bg);
    color: var(--close-btn-color);
    font-size: 1.25rem;
    font-weight: 900;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: all 0.25s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.close-modal-btn:hover {
    transform: scale(1.15) rotate(90deg);
    background: var(--primary-color);
    color: #FFFFFF;
    box-shadow: 0 6px 18px rgba(99, 102, 241, 0.4);
}

/* Theme Selector Grid */
.theme-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
}

.theme-option {
    padding: 14px;
    border-radius: 18px;
    border: 2px solid transparent;
    background: rgba(255, 255, 255, 0.35);
    cursor: pointer;
    text-align: center;
    font-weight: 800;
    transition: all 0.2s ease;
}

.theme-option.active {
    border-color: var(--primary-color);
    background: rgba(99, 102, 241, 0.2);
    box-shadow: 0 0 16px rgba(99, 102, 241, 0.3);
}

.theme-option .preview-swatch {
    height: 40px;
    border-radius: 12px;
    margin-bottom: 8px;
}

/* Achievements List */
.achievements-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.achievement-card {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 14px 18px;
    border-radius: 18px;
    background: rgba(255, 255, 255, 0.3);
    border: 1px solid var(--glass-border);
    text-align: left;
}

.achievement-card.unlocked {
    background: rgba(16, 185, 129, 0.18);
    border-color: rgba(16, 185, 129, 0.5);
}

.ach-icon {
    font-size: 2rem;
}

.ach-info {
    flex: 1;
}

.ach-title {
    font-weight: 900;
    font-size: 1rem;
}

.ach-desc {
    font-size: 0.85rem;
    opacity: 0.8;
}

.ach-status {
    font-size: 0.75rem;
    font-weight: 900;
    padding: 5px 10px;
    border-radius: 10px;
    background: rgba(0, 0, 0, 0.1);
}

.achievement-card.unlocked .ach-status {
    background: #10B981;
    color: #FFFFFF;
}

/* Game Over Stats Grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 14px;
    margin: 10px 0;
}

.stat-card {
    background: rgba(255, 255, 255, 0.4);
    padding: 16px;
    border-radius: 18px;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.new-best-badge {
    display: inline-block;
    background: #10B981;
    color: #FFFFFF;
    font-size: 0.85rem;
    font-weight: 900;
    padding: 6px 14px;
    border-radius: 14px;
    letter-spacing: 1px;
    margin-bottom: 8px;
    animation: pulse 1s infinite alternate;
}

@keyframes pulse {
    0% { transform: scale(1); }
    100% { transform: scale(1.08); }
}
