:root {
    --primary: #a855f7;
    --primary-hover: #c084fc;
    --primary-light: rgba(168, 85, 247, 0.15);
    --primary-lighter: rgba(168, 85, 247, 0.08);
    --accent: #22d3ee;
    --accent-light: rgba(34, 211, 238, 0.15);
    --success: #10b981;
    --warning: #f59e0b;
    --text: #e2e8f0;
    --text-muted: #94a3b8;
    --text-light: #475569;
    --bg: #07060f;
    --bg-secondary: #0e0c1e;
    --surface: #120f24;
    --surface-hover: #1c1835;
    --border: #2a2550;
    --border-light: #1c1835;
    --glass: rgba(12, 10, 25, 0.9);
    --shadow-xs: 0 1px 2px 0 rgb(0 0 0 / 0.5);
    --shadow-sm: 0 1px 3px 0 rgb(0 0 0 / 0.6);
    --shadow: 0 4px 6px -1px rgb(0 0 0 / 0.7);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.7);
    --shadow-xl: 0 20px 40px -5px rgb(0 0 0 / 0.9);
    --shadow-glow: 0 0 25px rgba(168, 85, 247, 0.45), 0 0 50px rgba(168, 85, 247, 0.15);
    --shadow-glow-cyan: 0 0 20px rgba(34, 211, 238, 0.4), 0 0 40px rgba(34, 211, 238, 0.15);
    --radius: 12px;
    --radius-sm: 8px;
    --radius-lg: 16px;
    --radius-xl: 20px;
    --gradient-primary: linear-gradient(-45deg, #1a0533, #0d1040, #071a3a, #1a0533);
    --gradient-accent: linear-gradient(135deg, #a855f7 0%, #22d3ee 100%);
    --gradient-surface: linear-gradient(135deg, #120f24 0%, #1c1835 100%);
}

.dark-mode {
    --primary: #a855f7;
    --primary-hover: #c084fc;
    --primary-light: rgba(168, 85, 247, 0.15);
    --primary-lighter: rgba(168, 85, 247, 0.08);
    --accent: #22d3ee;
    --accent-light: rgba(34, 211, 238, 0.15);
    --success: #10b981;
    --warning: #fbbf24;
    --text: #e2e8f0;
    --text-muted: #94a3b8;
    --text-light: #475569;
    --bg: #07060f;
    --bg-secondary: #0e0c1e;
    --surface: #120f24;
    --surface-hover: #1c1835;
    --border: #2a2550;
    --border-light: #1c1835;
    --glass: rgba(12, 10, 25, 0.9);
    --shadow-xs: 0 1px 2px 0 rgb(0 0 0 / 0.5);
    --shadow-sm: 0 1px 3px 0 rgb(0 0 0 / 0.6);
    --shadow: 0 4px 6px -1px rgb(0 0 0 / 0.7);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.8);
    --shadow-xl: 0 20px 40px -5px rgb(0 0 0 / 0.9);
    --shadow-glow: 0 0 25px rgba(168, 85, 247, 0.45), 0 0 50px rgba(168, 85, 247, 0.15);
    --shadow-glow-cyan: 0 0 20px rgba(34, 211, 238, 0.4), 0 0 40px rgba(34, 211, 238, 0.15);
    --gradient-primary: linear-gradient(-45deg, #1a0533, #0d1040, #071a3a, #1a0533);
    --gradient-accent: linear-gradient(135deg, #a855f7 0%, #22d3ee 100%);
    --gradient-surface: linear-gradient(135deg, #120f24 0%, #1c1835 100%);
}

* {
    box-sizing: border-box;
}

/* Custom scrollbar */
::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--primary); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--primary-hover); }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Segoe UI', system-ui, sans-serif;
    line-height: 1.6;
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--text);
    transition: background 0.3s ease, color 0.3s ease;
    font-weight: 400;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    min-height: 100vh;
}

/* Subtle grid pattern on background */
body::before {
    content: '';
    position: fixed;
    inset: 0;
    background-image:
        linear-gradient(rgba(168, 85, 247, 0.04) 1px, transparent 1px),
        linear-gradient(90deg, rgba(168, 85, 247, 0.04) 1px, transparent 1px);
    background-size: 44px 44px;
    pointer-events: none;
    z-index: 0;
}

/* Purple ambient glow blob top-left */
body::after {
    content: '';
    position: fixed;
    top: -250px;
    left: -250px;
    width: 700px;
    height: 700px;
    background: radial-gradient(circle, rgba(168, 85, 247, 0.07) 0%, transparent 65%);
    pointer-events: none;
    z-index: 0;
}

main, header, footer, #zoneViewer, #popupOverlay {
    position: relative;
    z-index: 1;
}

/* ===================== HEADER ===================== */
@keyframes gradientShift {
    0%   { background-position: 0% 50%; }
    50%  { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}

header {
    background: linear-gradient(-45deg, #1a0533, #0d0d3a, #071a3a, #1a0533);
    background-size: 400% 400%;
    animation: gradientShift 12s ease infinite;
    color: white;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 4px 30px rgba(168, 85, 247, 0.35), 0 1px 0 rgba(168, 85, 247, 0.2);
    border-bottom: 1px solid rgba(168, 85, 247, 0.25);
}

.header-content {
    max-width: 1300px;
    margin: 0 auto;
    padding: 0.875rem 1.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1.25rem;
}

.logo {
    font-size: 1.4rem;
    font-weight: 900;
    background: linear-gradient(135deg, #ffffff 0%, #c084fc 45%, #22d3ee 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    filter: drop-shadow(0 0 10px rgba(168, 85, 247, 0.7));
    text-transform: uppercase;
    letter-spacing: 0.06em;
    white-space: nowrap;
}

/* ===================== SEARCH BAR ===================== */
.search-container {
    display: flex;
    flex: 1;
    max-width: 660px;
    gap: 0.625rem;
}

#searchBar {
    flex: 1;
    min-width: 0;
    padding: 0.625rem 1rem;
    border: 1px solid rgba(168, 85, 247, 0.3);
    border-radius: var(--radius);
    background: rgba(7, 6, 20, 0.85);
    backdrop-filter: blur(20px);
    color: var(--text);
    font-size: 14px;
    outline: none;
    transition: all 0.25s ease;
}

#searchBar:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(168, 85, 247, 0.2), var(--shadow-glow);
    background: rgba(7, 6, 20, 0.95);
}

#searchBar::placeholder {
    color: var(--text-light);
}

#sortOptions, #categoryFilter {
    padding: 0.625rem 0.75rem;
    border: 1px solid rgba(168, 85, 247, 0.3);
    border-radius: var(--radius);
    background: rgba(7, 6, 20, 0.85);
    backdrop-filter: blur(20px);
    color: var(--text-muted);
    font-size: 13px;
    cursor: pointer;
    outline: none;
    transition: all 0.25s ease;
    min-width: 110px;
}

#sortOptions option, #categoryFilter option {
    background: #120f24;
    color: var(--text);
}

#sortOptions:hover, #categoryFilter:hover,
#sortOptions:focus, #categoryFilter:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(168, 85, 247, 0.15), var(--shadow-glow);
    color: var(--text);
}

.control-buttons {
    display: flex;
    gap: 0.5rem;
}

#settings {
    background: rgba(168, 85, 247, 0.12);
    border: 1px solid rgba(168, 85, 247, 0.3);
    color: white;
    font-size: 1.2rem;
    cursor: pointer;
    padding: 0;
    border-radius: var(--radius);
    transition: all 0.25s ease;
    width: 42px;
    height: 42px;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(20px);
    box-shadow: none;
}

#settings:hover {
    background: rgba(168, 85, 247, 0.28);
    border-color: var(--primary);
    box-shadow: var(--shadow-glow);
    transform: translateY(-1px);
}

#settings img {
    transition: transform 0.4s ease;
}

#settings:hover img {
    transform: rotate(40deg);
}

/* ===================== MAIN CONTENT ===================== */
main {
    max-width: 1400px;
    margin: 0 auto;
    padding: 2rem 1.5rem;
    padding-bottom: 6rem;
}

details summary {
    color: var(--text);
    padding: 0.4rem 0;
    user-select: none;
    font-weight: 700;
    letter-spacing: 0.02em;
    text-transform: uppercase;
    font-size: 0.85rem;
    color: var(--text-muted);
}

details summary::-webkit-details-marker {
    color: var(--primary);
}

hr {
    border: none;
    border-top: 1px solid var(--border);
}

#zoneCount {
    margin: 0 0 1.5rem;
    font-size: 13px;
    color: var(--text-muted);
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

#zoneCount::before {
    content: '';
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--primary);
    box-shadow: 0 0 8px var(--primary);
}

#container,
#featuredZones {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(175px, 1fr));
    gap: 1.25rem;
}

/* ===================== GAME CARDS ===================== */
.zone-item {
    background: var(--gradient-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
    cursor: pointer;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1),
                border-color 0.3s ease,
                box-shadow 0.3s ease;
    display: flex;
    flex-direction: column;
    position: relative;
    box-shadow: var(--shadow-sm);
}

.zone-item::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(
        135deg,
        rgba(168, 85, 247, 0.06) 0%,
        rgba(34, 211, 238, 0.04) 100%
    );
    opacity: 0;
    transition: opacity 0.3s ease;
    pointer-events: none;
    z-index: 1;
}

.zone-item:hover {
    transform: translateY(-7px) scale(1.02);
    border-color: var(--accent);
    box-shadow:
        0 0 0 1px rgba(34, 211, 238, 0.3),
        0 0 20px rgba(34, 211, 238, 0.2),
        0 0 40px rgba(168, 85, 247, 0.1),
        var(--shadow-xl);
}

.zone-item:hover::after {
    opacity: 1;
}

.zone-item img {
    width: 100%;
    aspect-ratio: 1;
    object-fit: cover;
    display: block;
    background: var(--surface-hover);
    transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

.no-image-placeholder {
    width: 100%;
    aspect-ratio: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--surface-hover);
    color: var(--text-muted);
    font-size: 13px;
    font-weight: 700;
    letter-spacing: 0.1em;
}

.zone-item:hover img {
    transform: scale(1.08);
}

.zone-item button {
    background: transparent;
    color: var(--text-muted);
    border: 0;
    padding: 0.875rem 0.875rem;
    cursor: pointer;
    font-weight: 600;
    font-size: 13px;
    line-height: 1.4;
    text-align: center;
    transition: color 0.25s ease, text-shadow 0.25s ease, background 0.25s ease;
    min-height: 58px;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    z-index: 2;
    letter-spacing: 0.01em;
}

.zone-item:hover button {
    color: var(--accent);
    text-shadow: 0 0 14px rgba(34, 211, 238, 0.6);
    background: rgba(34, 211, 238, 0.04);
}

/* ===================== ZONE VIEWER ===================== */
@keyframes slideInUp {
    from { transform: translateY(100%); }
    to   { transform: translateY(0); }
}

#zoneViewer {
    position: fixed;
    inset: 0;
    background: var(--bg);
    z-index: 1000;
    display: none;
    flex-direction: column;
    animation: slideInUp 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.zone-header {
    background: linear-gradient(-45deg, #1a0533, #0d0d3a, #071a3a, #1a0533);
    background-size: 400% 400%;
    animation: gradientShift 12s ease infinite;
    color: white;
    padding: 0.75rem 1.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: 0 4px 20px rgba(168, 85, 247, 0.3);
    border-bottom: 1px solid rgba(168, 85, 247, 0.2);
}

.zone-title {
    flex: 1;
    min-width: 0;
}

#zoneName {
    font-size: 1.1rem;
    font-weight: 800;
    margin: 0 0 0.15rem;
    line-height: 1.3;
    background: linear-gradient(135deg, #ffffff 0%, #c084fc 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

#zoneId { display: none; }

#zoneAuthor {
    font-size: 12px;
    color: rgba(34, 211, 238, 0.75);
    text-decoration: none;
    transition: color 0.2s ease, text-shadow 0.2s ease;
    font-weight: 500;
}

#zoneAuthor:hover {
    color: var(--accent);
    text-shadow: 0 0 8px rgba(34, 211, 238, 0.5);
}

.zone-controls {
    display: flex;
    gap: 0.5rem;
}

.zone-controls button {
    background: rgba(168, 85, 247, 0.12);
    border: 1px solid rgba(168, 85, 247, 0.3);
    color: white;
    padding: 0.45rem 0.875rem;
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 13px;
    font-weight: 600;
    transition: all 0.25s ease;
    backdrop-filter: blur(10px);
}

.zone-controls button:hover {
    background: rgba(168, 85, 247, 0.28);
    border-color: var(--primary);
    box-shadow: var(--shadow-glow);
    transform: translateY(-1px);
}

#zoneFrame {
    flex-grow: 1;
    border: none;
    width: 90%;
    height: 90%;
    background: #fff;
    color-scheme: light;
}

/* ===================== POPUP ===================== */
@keyframes fadeIn {
    from { opacity: 0; }
    to   { opacity: 1; }
}

@keyframes slideInScale {
    from { transform: scale(0.92) translateY(16px); opacity: 0; }
    to   { transform: scale(1)    translateY(0);    opacity: 1; }
}

#popupOverlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(14px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    padding: 1rem;
    animation: fadeIn 0.2s ease;
}

.popup {
    background: var(--surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-xl), var(--shadow-glow);
    width: 100%;
    max-width: 520px;
    max-height: 80vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    border: 1px solid rgba(168, 85, 247, 0.35);
    animation: slideInScale 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.popup-header {
    background: linear-gradient(-45deg, #1a0533, #0d0d3a, #071a3a, #1a0533);
    background-size: 400% 400%;
    animation: gradientShift 12s ease infinite;
    color: white;
    padding: 1.1rem 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid rgba(168, 85, 247, 0.2);
}

#popupTitle {
    margin: 0;
    font-size: 1.1rem;
    font-weight: 800;
    background: linear-gradient(135deg, #ffffff 0%, #c084fc 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

#popupClose {
    background: rgba(168, 85, 247, 0.12);
    border: 1px solid rgba(168, 85, 247, 0.3);
    color: white;
    font-size: 1.1rem;
    cursor: pointer;
    padding: 0;
    border-radius: var(--radius);
    transition: all 0.2s ease;
    width: 34px;
    height: 34px;
    display: flex;
    align-items: center;
    justify-content: center;
}

#popupClose:hover {
    background: rgba(244, 63, 94, 0.3);
    border-color: #f43f5e;
    box-shadow: 0 0 14px rgba(244, 63, 94, 0.4);
    transform: scale(1.1);
}

#popupBody {
    padding: 1.5rem;
    overflow-y: auto;
    color: var(--text);
    background: var(--surface);
}

#popupBody input[type="text"],
#popupBody input[type="file"] {
    width: 100%;
    padding: 0.75rem 1rem;
    margin-bottom: 1.25rem;
    border: 1px solid rgba(168, 85, 247, 0.25);
    border-radius: var(--radius);
    background: rgba(0, 0, 0, 0.35);
    color: var(--text);
    font-size: 14px;
    transition: all 0.25s ease;
    outline: none;
}

#popupBody input[type="text"]:focus,
#popupBody input[type="file"]:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(168, 85, 247, 0.15), var(--shadow-glow);
}

#settings-button {
    width: 100%;
    padding: 0.875rem 1rem;
    background: linear-gradient(135deg, #7c3aed, #a855f7);
    color: white;
    border: 0;
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 14px;
    font-weight: 700;
    margin-bottom: 1rem;
    transition: all 0.25s ease;
    box-shadow: var(--shadow-glow);
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

#settings-button:hover {
    background: linear-gradient(135deg, #8b5cf6, #c084fc);
    transform: translateY(-2px);
    box-shadow: 0 0 35px rgba(168, 85, 247, 0.65), var(--shadow-lg);
}

#settings-button:active {
    transform: translateY(0);
}

/* ===================== LOADING OVERLAY ===================== */
#gameLoadingOverlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: #000;
    z-index: 9999;
    align-items: center;
    justify-content: center;
}
#gameLoadingOverlay.active {
    display: flex;
}
#gameLoadingText {
    color: #00ff41;
    font-family: 'Courier New', monospace;
    font-size: 1.4rem;
    font-weight: bold;
    letter-spacing: 0.08em;
    text-shadow: 0 0 10px #00ff41;
}

/* ===================== FOOTER ===================== */
footer {
    background: rgba(7, 6, 15, 0.97);
    border-top: 1px solid rgba(168, 85, 247, 0.18);
    padding: 0.875rem 1rem;
    text-align: center;
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    z-index: 100;
    backdrop-filter: blur(20px);
    box-shadow: 0 -4px 20px rgba(168, 85, 247, 0.1);
}

.panic-links {
    display: flex;
    justify-content: center;
    gap: 0.75rem;
    flex-wrap: wrap;
    margin-bottom: 0.4rem;
}

.panic-links a {
    color: #fff;
    text-decoration: none;
    font-weight: 700;
    font-size: 12px;
    padding: 0.3rem 0.85rem;
    border-radius: var(--radius-sm);
    background: linear-gradient(135deg, #6d28d9, #a855f7);
    border: 1px solid rgba(168, 85, 247, 0.4);
    transition: all 0.15s ease;
    letter-spacing: 0.02em;
}

.panic-links a:hover {
    background: linear-gradient(135deg, #7c3aed, #c084fc);
    box-shadow: 0 0 10px rgba(168, 85, 247, 0.5);
    transform: translateY(-1px);
}

.panic-note {
    font-size: 11px;
    color: rgba(255,255,255,0.4);
    margin: 0 0 0.4rem 0;
    font-style: italic;
}

.footer-links {
    display: flex;
    justify-content: center;
    gap: 1.25rem;
    flex-wrap: wrap;
}

.footer-links a {
    color: var(--text-light);
    text-decoration: none;
    font-weight: 600;
    font-size: 13px;
    transition: all 0.2s ease;
    padding: 0.375rem 0.75rem;
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
}

.footer-links a:hover {
    color: var(--primary);
    border-color: rgba(168, 85, 247, 0.3);
    background: rgba(168, 85, 247, 0.1);
    box-shadow: 0 0 10px rgba(168, 85, 247, 0.2);
    transform: translateY(-1px);
}

/* ===================== RESPONSIVE ===================== */
@media (max-width: 768px) {
    .header-content {
        flex-direction: column;
        gap: 0.75rem;
        padding: 0.875rem 1rem;
    }

    .search-container {
        width: 100%;
        max-width: none;
        flex-wrap: wrap;
    }

    #searchBar { flex: 1 1 100%; }

    #sortOptions, #categoryFilter { flex: 1; min-width: 0; }

    main {
        padding: 1.25rem 1rem;
        padding-bottom: 6.5rem;
    }

    #container,
    #featuredZones {
        grid-template-columns: repeat(auto-fill, minmax(145px, 1fr));
        gap: 1rem;
    }

    .zone-item button {
        padding: 0.75rem;
        min-height: 52px;
        font-size: 12px;
    }

    .footer-links { gap: 0.75rem; }

    /* Zone viewer: stack title and controls vertically */
    .zone-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
        padding: 0.625rem 1rem;
    }

    .zone-controls {
        width: 100%;
        flex-wrap: wrap;
        gap: 0.375rem;
    }

    .zone-controls button {
        flex: 1 1 calc(50% - 0.375rem);
        min-width: 0;
        padding: 0.5rem 0.5rem;
        font-size: 12px;
        text-align: center;
        justify-content: center;
    }

    /* Frame: fill full width on mobile */
    #zoneFrame {
        width: 100%;
        height: 100%;
    }

    /* Loading text: smaller and centered */
    #gameLoadingText {
        font-size: 1rem;
        text-align: center;
        padding: 0 1.5rem;
        word-break: break-all;
    }

    /* Popup: allow more vertical space */
    .popup {
        max-height: 92vh;
    }
}

@media (max-width: 480px) {
    .logo {
        font-size: 1rem;
        letter-spacing: 0.03em;
    }

    #container,
    #featuredZones {
        grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
        gap: 0.875rem;
    }

    .popup { margin: 0.5rem; }

    .zone-item:hover {
        transform: translateY(-4px) scale(1.01);
    }

    /* Stack zone controls to 2×2 on small phones */
    .zone-controls button {
        flex: 1 1 calc(50% - 0.375rem);
        font-size: 11px;
        padding: 0.45rem 0.375rem;
    }

    /* Footer: tighten up */
    .panic-links {
        gap: 0.4rem;
    }

    .panic-links a {
        font-size: 11px;
        padding: 0.25rem 0.6rem;
    }

    .panic-note {
        font-size: 10px;
    }

    main {
        padding-bottom: 7rem;
    }

    #gameLoadingText {
        font-size: 0.875rem;
    }
}
