/*
=============================================================================
  ECHO SWING - STYLE SHEET (2026 STANDARDS)
  Architecture: Custom Properties > Base > Layout > Components > Utilities
  Compliance: WCAG 2.2 AAA (High Contrast Defaults)
=============================================================================
*/

/* --- 1. SETTINGS & VARIABLES --- */
:root {
    /* -- COLORS (Neon Palette) -- */
    --color-bg: #050510;
    --color-text-primary: #ffffff;
    --color-text-secondary: rgba(255, 255, 255, 0.7);
    --color-text-muted: rgba(255, 255, 255, 0.4);

    /* Accents (Enhanced for Contrast) */
    --color-neon-blue: #00f3ff;
    /* 14.6:1 on Black (AAA) */
    --color-neon-pink: #ff40ff;
    /* Lightened from #ff00ff for better legibility */
    --color-gold: #FFD700;
    /* 15.6:1 on Black (AAA) */
    --color-silver: #e0e0e0;
    --color-danger: #ff4444;
    --color-success: #00ff00;

    /* Difficulty Colors */
    --color-stable: #00f3ff;
    --color-unstable: #ffae00;
    --color-decay: #ff40ff;
    /* Matches neon-pink */
    --color-critical: #ff0000;

    /* -- SPACING (Logical) -- */
    --space-xs: 4px;
    --space-sm: 8px;
    --space-md: 16px;
    --space-lg: 24px;
    --space-xl: 32px;

    /* -- TYPOGRAPHY -- */
    --font-heading: 'Orbitron', system-ui, sans-serif;
    --font-body: 'Orbitron', system-ui, sans-serif;
    /* Monospace feeling */

    /* Fluid Type: Min 1rem, Max 1.2rem based on viewport */
    --text-xs: 0.75rem;
    --text-sm: 0.875rem;
    --text-base: clamp(1rem, 2vw, 1.2rem);
    --text-lg: clamp(1.2rem, 3vw, 1.5rem);
    --text-xl: clamp(2rem, 5vw, 3rem);
    --text-2xl: clamp(2.5rem, 6vw, 3.5rem);

    /* -- EFFECTS -- */
    --shadow-neon-blue: 0 0 10px rgba(0, 243, 255, 0.5);
    --shadow-neon-pink: 0 0 10px rgba(255, 0, 255, 0.5);
    --shadow-gold: 0 0 10px rgba(255, 215, 0, 0.5);
    --backdrop-blur: blur(15px);
    /* -- Z-INDEX LAYERS -- */
    --z-background: 0;
    --z-ui-layer: 100;
    --z-ui-interactive: 200;
    --z-hud: 500;
    --z-modal: 1000;
    --z-overlay: 9999;
}

/* --- 2. BASE --- */
*,
*::before,
*::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html,
body {
    position: fixed;
    inset: 0;
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    background-color: var(--color-bg);
    color: var(--color-text-primary);
    font-family: var(--font-body);
    overflow: hidden;
    overscroll-behavior: none;
    touch-action: none;
    -webkit-user-select: none;
    user-select: none;
}

/* --- 3. LAYOUT --- */
#game-canvas {
    display: block;
    width: 100%;
    height: 100%;
    position: absolute;
    top: 0;
    left: 0;
    z-index: var(--z-background);
    /* Background layer */
    transition: filter 0.5s ease, transform 0.5s ease;
}

#game-canvas.blur-bg {
    filter: blur(8px) brightness(0.6);
    transform: scale(1.05);
}

#ui-layer {
    position: absolute;
    inset: 0;
    /* Top/Left/Right/Bottom 0 */
    pointer-events: none;
    display: grid;
    place-items: center;
    z-index: var(--z-ui-layer);
}

/* Screen Containers */
.screen {
    display: none;
    text-align: center;
    width: 100%;
    max-width: 600px;
    padding: var(--space-md);
}

/* --- Start Screen Specifics --- */
#start-screen h1 {
    font-size: clamp(4rem, 15vw, 9rem);
    font-weight: 900;
    margin-bottom: var(--space-md);
    /* Reduced from xl to make room */

    /* Glitch Aesthetic (Foundation) */
    color: white;
    text-shadow: 4px 0 var(--color-neon-pink), -4px 0 var(--color-neon-blue);

    letter-spacing: -0.05em;
    line-height: 1.1;
    text-transform: uppercase;

    /* Ensure padding for shadow */
    padding: 10px;
}

.game-logo {
    width: 100px;
    height: 100px;
    margin-bottom: var(--space-lg);
    animation: floatLogo 3s ease-in-out infinite;

    /* Explicit Transparency Force */
    background: transparent;
    border: none;
    box-shadow: none;
    border-radius: 0;
    outline: none;
}

@keyframes floatLogo {

    0%,
    100% {
        transform: translateY(0);
    }

    50% {
        transform: translateY(-5px);
    }
}

#start-screen .pulsate-text {
    font-size: var(--text-lg);
    /* Smaller text as requested */
    margin-bottom: 40px;
    /* Reduced gap */
    letter-spacing: 2px;
    font-weight: 900;
    color: var(--color-neon-blue);
    text-transform: uppercase;
    text-shadow: 0 0 10px var(--color-neon-blue);
    /* Static shadow base */
    animation: pulsate 1.5s infinite ease-in-out alternate;
}

.menu-buttons {
    display: flex;
    flex-direction: column;
    gap: var(--space-md);
    width: 100%;
    max-width: 260px;
    margin: 0 auto;
}

.menu-buttons button,
.menu-buttons .neo-btn {
    pointer-events: auto;
    position: relative;
    z-index: var(--z-ui-interactive);
}

@keyframes pulsate {
    0% {
        transform: scale(1);
        opacity: 0.8;
    }

    100% {
        transform: scale(1.1);
        opacity: 1;
    }
}

.screen.active {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    pointer-events: auto;
    animation: fadeIn 0.3s ease-out;
}

#game-over.active {
    background: rgba(0, 0, 0, 0.4);
    /* Glassmorphism Base */
    height: 100%;
    /* Restore explicit Grid centering (2026 Standard) */
    display: grid;
    place-items: center;
    align-content: center;
    gap: 2px;
    backdrop-filter: blur(5px);
    z-index: var(--z-modal);
}

/* GAME UI FIX: Prevent Jump caused by Transform/Flex Centering */
#game-ui.active {
    width: 100%;
    height: 100%;
    max-width: none;
    justify-content: flex-start;
    animation: none;
    /* Disable layout-shifting animation on container */
}

#game-ui.active #hud {
    animation: fadeInHud 0.5s ease-out;
    /* Custom anim */
}

/* HUD (Heads Up Display) */
#hud {
    position: absolute;
    top: max(20px, env(safe-area-inset-top));
    left: 0;
    width: 100%;
    /* Standardized Centering (No Transform) */
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-xs);
    z-index: var(--z-hud);
    pointer-events: none;
}

/* Semantics Reset */
.hud-stats,
#hud-row,
#hud-row dd {
    margin: 0;
    padding: 0;
}

#hud-row {
    display: flex;
    gap: var(--space-lg);
}

/* A11y Utility */
.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* --- 4. COMPONENTS --- */

/* Buttons (Neo-Brutalism / Glass) */
.neo-btn {
    background: transparent;
    border: 2px solid var(--color-gold);
    color: var(--color-gold);
    padding: 10px 24px;
    font-family: var(--font-heading);
    font-size: var(--text-lg);
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 0 10px rgba(255, 215, 0, 0.1);
    border-radius: var(--radius-sm);
    pointer-events: auto;
    text-transform: uppercase;
    position: relative;
    overflow: hidden;
}

/* Secondary / White Variant */
/* Secondary / White Variant - Removed Unused */

/* Pink Variant */
.neo-btn.btn-pink {
    border-color: var(--color-neon-pink);
    color: #ffffff;
    text-shadow: 0 0 5px var(--color-neon-pink);
    box-shadow: 0 0 10px rgba(255, 64, 255, 0.2);
}

/* Hover (Mouse Only - Prevents Sticky Mobile Hover) */
@media (hover: hover) {
    .neo-btn.btn-pink:hover {
        background: var(--color-neon-pink);
        color: var(--color-bg);
        box-shadow: 0 0 25px var(--color-neon-pink);
    }
}

/* Active (Touch Feedback) */
.neo-btn.btn-pink:active {
    background: var(--color-neon-pink);
    color: var(--color-bg);
    box-shadow: 0 0 15px var(--color-neon-pink);
    transform: scale(0.98);
}

/* 2026 Standard: Auto-lock background interactions when modal is active */
:root:has(dialog[open]) .menu-buttons .neo-btn,
:root:has(dialog[open]) #game-canvas,
:root:has(dialog[open]) #game-over.active {
    pointer-events: none !important;
    user-select: none;
}

:root:has(dialog[open]) .neo-btn:not(.overlay .neo-btn):hover,
:root:has(dialog[open]) .neo-btn:not(.overlay .neo-btn):active {
    background: transparent !important;
    color: inherit !important;
    box-shadow: none !important;
    transform: none !important;
}

/* Input Fields (Neon) */
.neon-input {
    background: rgba(0, 0, 0, 0.4);
    border: 1px solid var(--color-neon-blue);
    border-radius: var(--radius-sm);
    color: white;
    font-family: var(--font-heading);
    font-size: 1.5rem;
    text-align: center;
    padding: 15px;
    width: 100%;
    margin-bottom: 20px;
    outline: none;
    box-shadow: 0 0 10px rgba(0, 243, 255, 0.2);
    transition: all 0.3s ease;
    text-transform: uppercase;
    appearance: none;
    -webkit-appearance: none;
}

.neon-input:focus {
    background: rgba(0, 243, 255, 0.1);
    box-shadow: 0 0 20px rgba(0, 243, 255, 0.5);
    transform: scale(1.02);
}

.neon-input::placeholder {
    color: rgba(255, 255, 255, 0.3);
}

/* Stats Box (The Glass Card) */
.stats-card {
    margin: 2px auto;
    width: 100%;
    max-width: 340px;
    background: rgba(20, 20, 35, 0.65);
    backdrop-filter: var(--backdrop-blur);
    -webkit-backdrop-filter: var(--backdrop-blur);
    padding: 10px;
    border-radius: var(--radius-lg);

    /* Subtle Borders */
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-top: 1px solid rgba(255, 255, 255, 0.2);

    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.6);
    display: flex;
    flex-direction: column;
    gap: 6px;
    position: relative;
    overflow: hidden;
}

.game-over__score-wrapper {
    width: 100%;
    display: flex;
    justify-content: center;
}

/* Stats Box Glow Gradient */
.stats-card::before {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: radial-gradient(circle, rgba(0, 243, 255, 0.03) 0%, transparent 60%);
    pointer-events: none;
}

/* Hero Score Section */
.stats-card__hero {
    text-align: center;
    margin-bottom: var(--space-xs);
    position: relative;
    z-index: 2;
}

.stats-card__label {
    font-size: 0.7rem;
    color: var(--color-text-secondary);
    letter-spacing: 3px;
    text-transform: uppercase;
    margin-bottom: 2px;
}

.stats-card__value--large {
    font-size: 3rem;
    font-weight: 900;
    color: var(--color-text-primary);
    line-height: 0.9;
    text-shadow: var(--shadow-neon-blue);
    letter-spacing: 2px;
}

.stats-card__breakdown {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: var(--space-sm);
    font-size: var(--text-sm);
    color: var(--color-text-secondary);
    margin-top: var(--space-sm);
    font-family: monospace;
}

/* Economy Grid */
.stats-card__grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    background: rgba(0, 0, 0, 0.25);
    padding: 10px;
    border-radius: var(--radius-md);
    border: 1px solid rgba(255, 255, 255, 0.03);
}

.stats-card__item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}

.stats-card__label--small {
    font-size: 0.7rem;
    color: var(--color-gold);
    letter-spacing: 1px;
    opacity: 0.9;
}

.stats-card__value--small {
    font-size: 1.4rem;
    font-weight: 700;
    color: white;
    display: flex;
    align-items: center;
    gap: 4px;
}

.icon-sm {
    width: 20px;
    height: 20px;
    vertical-align: middle;
    object-fit: contain;
}

/* Footer & Other Text */
.stats-card__footer {
    text-align: center;
    font-size: var(--text-sm);
    color: var(--color-text-muted);
    border-top: 1px solid rgba(255, 255, 255, 0.05);
    padding-top: 6px;
    margin-top: 2px;
}

.stats-card__value--footer {
    color: white;
    font-weight: bold;
    margin-left: 5px;
    font-size: 1.1rem;
}

.stats-card__value--footer.new-record {
    color: var(--color-gold);
    text-shadow: var(--shadow-gold);
}

/* Glitch Text (Encouragement) */
.glitch-text {
    font-size: var(--text-lg);
    font-weight: bold;
    color: var(--color-neon-blue);
    position: relative;
    /* Basic glitch effect via text-shadow */
    text-shadow: 2px 0 var(--color-neon-pink), -2px 0 var(--color-neon-blue);
}

/* --- 5. UTILITIES & ANIMATIONS --- */
/* .text-center - Removed Unused */

.hidden {
    display: none !important;
}

/* Icons */
.icon-sm {
    width: 20px;
    height: 20px;
    vertical-align: middle;
    border-radius: 50%;
    box-shadow: 0 0 5px rgba(255, 255, 255, 0.2);
}

/* HUD Specifics */
#hud-score {
    font-size: 2.5rem;
    text-shadow: 0 0 5px black;
    font-weight: 900;
}

.hud-item {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: bold;
    font-size: 1.2rem;
}

/* Status Text Colors */
.stable {
    color: var(--color-stable);
    text-shadow: 0 0 10px var(--color-stable);
}

.unstable {
    color: var(--color-unstable);
    text-shadow: 0 0 10px var(--color-unstable);
}

.decay {
    color: var(--color-decay);
    text-shadow: 0 0 10px var(--color-decay);
}

.critical {
    color: var(--color-critical);
    text-shadow: 0 0 20px var(--color-critical);
    animation: pulseCritical 0.5s infinite alternate;
}

/* Anim: Pulse */
@keyframes pulseCritical {
    from {
        opacity: 0.8;
    }

    to {
        opacity: 1;
        text-shadow: 0 0 10px var(--color-critical);
    }
}

/* Anim: Blink (Retry) */
.blink-retry {
    margin: 10px 0;
    font-size: 1.1rem;
    color: var(--color-neon-blue);
    animation: blink 2s infinite ease-in-out;
}

@keyframes blink {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.3;
    }
}

/* Anim: Fade In */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes fadeInHud {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* --- 6. OVERLAYS (Rules, etc) --- */
/* --- 6. OVERLAYS (Native Dialog) --- */
dialog.overlay {
    /* Reset Native Styles */
    background: transparent;
    border: none;
    padding: 0;
    margin: auto;
    color: var(--color-text-primary);
    overflow: visible;

    /* Layering Fix */
    position: fixed;
    z-index: var(--z-overlay);
    inset: 0;

    /* Fix: Explicit sizing so margin:auto works */
    width: 90%;
    max-width: 500px;
    height: fit-content;
    /* Ensure it doesn't stretch weirdly */
}

dialog.overlay::backdrop {
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
    animation: fadeIn 0.3s ease-out;
}

dialog.overlay[open] {
    animation: fadeIn 0.3s ease-out;
}

.overlay__card {
    background: rgba(20, 20, 35, 0.65);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-top: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: var(--radius-lg);
    padding: 12px;
    text-align: center;

    /* Fix: Fill the dialog container */
    width: 100%;
    max-width: none;

    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(10px);
    position: relative;
    overflow: hidden;
}

.overlay__card::before {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: radial-gradient(circle, rgba(0, 243, 255, 0.05) 0%, transparent 60%);
    pointer-events: none;
}

/* --- RULES LAYOUT --- */
.overlay__rules {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin: 15px 0;
}

.overlay__rule-group {
    background: rgba(255, 255, 255, 0.05);
    padding: 10px;
    border-radius: var(--radius-sm);
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.overlay__rule-group h3 {
    font-size: 0.85rem;
    margin-bottom: 8px;
    color: var(--color-gold);
    text-align: left;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    padding-bottom: 4px;
}

/* Controls Grid (3 Cols) */
.overlay__grid--3 {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 8px;
}

.overlay__control {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}

.key-action {
    font-size: 0.9rem;
    font-weight: 900;
    color: var(--color-neon-blue);
    border: 1px solid var(--color-neon-blue);
    padding: 4px 8px;
    border-radius: 6px;
    box-shadow: 0 0 5px rgba(0, 243, 255, 0.2);
    width: 100%;
}

/* Semantics: Modifiers */
.key-action--tap {
    color: #fff;
    border-color: var(--color-unstable);
}

.key-action--hold {
    color: #fff;
    border-color: var(--color-stable);
}

.key-action--release {
    color: #fff;
    border-color: var(--color-critical);
}

.key-desc {
    font-size: 0.65rem;
    color: var(--color-text-secondary);
}

/* Split Row (2 Cols) - Removed unused .rules-split */

/* Mini Grids */
.overlay__grid--3 {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
}

.overlay__grid--3,
.overlay__grid--4 {
    /* Reset List */
    margin: 0;
    padding: 0;
    list-style: none;

    display: grid;
    gap: 6px;
}

.overlay__grid--3 {
    grid-template-columns: repeat(3, 1fr);
}

.overlay__grid--4 {
    grid-template-columns: repeat(4, 1fr);
}

.overlay__mini-box {
    background: rgba(0, 0, 0, 0.3);
    border-radius: var(--radius-sm);
    padding: 6px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    font-size: 0.75rem;
    border: 1px solid rgba(255, 255, 255, 0.05);
}


/* --- MEDIA QUERIES (Consolidated) --- */
@media (max-width: 400px) {
    .overlay__grid--4 {
        grid-template-columns: repeat(2, 1fr);
    }
}

.rule-list li {
    font-size: 0.75rem;
    color: var(--color-text-secondary);
    line-height: 1.5;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    padding: 4px 0;
}

.rule-list li:last-child {
    border-bottom: none;
}

.rule-list strong {
    color: var(--color-text-primary);
}

/* Leaderboard Grid */
.stat-row {
    display: grid;
    grid-template-columns: 50px 1fr 80px;
    gap: 10px;
    padding: 12px 10px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    align-items: center;
    font-family: var(--font-heading);
    font-size: 1rem;
    text-align: left;
}

.stat-row:last-child {
    border-bottom: none;
}

.stat-row.highlight {
    background: rgba(0, 243, 255, 0.1);
    border: 1px solid var(--color-neon-blue);
    border-radius: 8px;
    box-shadow: 0 0 10px rgba(0, 243, 255, 0.2);
}

.leaderboard-name-container {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    letter-spacing: 1px;
}

.leaderboard-edit-btn,
.leaderboard-delete-btn {
    cursor: pointer;
    margin-left: 8px;
    font-size: 0.8em;
    opacity: 0.7;
}

.leaderboard-edit-btn:hover,
.leaderboard-delete-btn:hover {
    opacity: 1;
    transform: scale(1.1);
}

/* Revive Error Shake */
.shake {
    animation: shake 0.5s cubic-bezier(.36, .07, .19, .97) both;
}

@keyframes shake {

    10%,
    90% {
        transform: translate3d(-1px, 0, 0);
    }

    20%,
    80% {
        transform: translate3d(2px, 0, 0);
    }

    30%,
    50%,
    70% {
        transform: translate3d(-4px, 0, 0);
    }

    40%,
    60% {
        transform: translate3d(4px, 0, 0);
    }
}

/* --- UTILITIES (Refactored 2026) --- */
.w-full {
    width: 100%;
}

/* .w-auto - Removed Unused */

.mb-15 {
    margin-bottom: 15px;
}

.mt-20 {
    margin-top: 20px;
}

.d-block {
    display: block;
}

/* JS Injected Revive Button */
.btn-revive-heavy {
    width: 100%;
    margin: 4px 0;
    font-size: 0.9rem;
    padding: 12px;
    background: rgba(50, 255, 100, 0.1);
    border-color: #00ff00;
    opacity: 0.3;
    pointer-events: none;
    transition: all 0.5s;
}

/* Active state handled by opacity change in JS or modifier, 
   but JS uses direct property manipulation for now regarding disabled state.
   We will strictly set base styles here. */

.text-neon-blue {
    color: var(--color-neon-blue);
}

.text-gold {
    color: var(--color-gold);
}

.text-white {
    color: #ffffff;
}

.font-2rem {
    font-size: 2rem;
}

.font-1-8rem {
    font-size: 1.8rem;
}

.font-1-2rem {
    font-size: 1.2rem;
}

.filter-gray {
    filter: grayscale(1);
}

/* Specific Overrides */
#game-over .retry-text {
    margin: 15px 0;
}

.share-btn-custom {
    width: auto;
    padding: 10px 30px;
}

#game-over .encourage-header {
    margin: 0 0 4px 0;
}

.new-record-glow {
    text-shadow: 0 0 10px var(--color-neon-pink);
}