:root {
    --primary: #fc2651;
    --primary-hover: #e91e47;
    --primary-light: rgba(252, 38, 81, 0.1);
    --primary-lighter: rgba(252, 38, 81, 0.05);
    --accent: #8b5cf6;
    --accent-light: rgba(139, 92, 246, 0.1);
    --success: #10b981;
    --warning: #f59e0b;
    --text: #1a1a1a;
    --text-muted: #6b7280;
    --text-light: #9ca3af;
    --bg: #ffffff;
    --bg-secondary: #f8fafc;
    --surface: #ffffff;
    --surface-hover: #f1f5f9;
    --border: #e2e8f0;
    --border-light: #f1f5f9;
    --glass: rgba(255, 255, 255, 0.8);
    --shadow-xs: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-sm: 0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1);
    --shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
    --shadow-xl: 0 20px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.1);
    --shadow-glow: 0 0 20px rgba(252, 38, 81, 0.3);
    --radius: 12px;
    --radius-sm: 8px;
    --radius-lg: 16px;
    --radius-xl: 20px;
    --gradient-primary: linear-gradient(135deg, #fc2651 0%, #e91e47 100%);
    --gradient-accent: linear-gradient(135deg, #8b5cf6 0%, #7c3aed 100%);
    --gradient-surface: linear-gradient(135deg, #ffffff 0%, #f8fafc 100%);
}

.dark-mode {
    --primary: #fc2651;
    --primary-hover: #ff4d75;
    --primary-light: rgba(252, 38, 81, 0.15);
    --primary-lighter: rgba(252, 38, 81, 0.08);
    --accent: #a855f7;
    --accent-light: rgba(168, 85, 247, 0.15);
    --success: #34d399;
    --warning: #fbbf24;
    --text: #f1f5f9;
    --text-muted: #94a3b8;
    --text-light: #64748b;
    --bg: #0f172a;
    --bg-secondary: #1e293b;
    --surface: #1e293b;
    --surface-hover: #334155;
    --border: #334155;
    --border-light: #475569;
    --glass: rgba(30, 41, 59, 0.8);
    --shadow-xs: 0 1px 2px 0 rgb(0 0 0 / 0.4);
    --shadow-sm: 0 1px 3px 0 rgb(0 0 0 / 0.5), 0 1px 2px -1px rgb(0 0 0 / 0.5);
    --shadow: 0 4px 6px -1px rgb(0 0 0 / 0.5), 0 2px 4px -2px rgb(0 0 0 / 0.5);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.6), 0 4px 6px -4px rgb(0 0 0 / 0.6);
    --shadow-xl: 0 20px 25px -5px rgb(0 0 0 / 0.7), 0 8px 10px -6px rgb(0 0 0 / 0.7);
    --shadow-glow: 0 0 20px rgba(252, 38, 81, 0.4);
    --gradient-primary: linear-gradient(135deg, #fc2651 0%, #ff4d75 100%);
    --gradient-accent: linear-gradient(135deg, #a855f7 0%, #9333ea 100%);
    --gradient-surface: linear-gradient(135deg, #1e293b 0%, #334155 100%);
}

* {
    box-sizing: border-box;
}

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: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    font-weight: 400;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

header {
    background: var(--gradient-primary);
    color: white;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: var(--shadow-lg);
    backdrop-filter: blur(20px);
}

.header-content {
    max-width: 1200px;
    margin: 0 auto;
    padding: 1.25rem 1rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1.5rem;
}

.logo {
    font-size: 1.75rem;
    font-weight: 800;
    letter-spacing: -0.02em;
    background: linear-gradient(135deg, #ffffff 0%, rgba(255, 255, 255, 0.8) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.search-container {
    display: flex;
    flex: 1;
    max-width: 500px;
    gap: 0.75rem;
}

#searchBar {
    flex: 1;
    padding: 0.875rem 1rem;
    border: 0;
    border-radius: var(--radius);
    background: var(--glass);
    backdrop-filter: blur(20px);
    color: var(--text);
    font-size: 15px;
    outline: none;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: var(--shadow-sm);
}

#searchBar:focus {
    background: var(--text);
    box-shadow: 0 0 0 3px rgba(252, 38, 81, 0.25), var(--shadow);
    transform: translateY(-1px);
    color: var(--glass);
}

#searchBar::placeholder {
    color: var(--text-muted);
}

#sortOptions {
    padding: 0.875rem 1rem;
    border: 0;
    border-radius: var(--radius);
    background: var(--glass);
    backdrop-filter: blur(20px);
    color: var(--text-muted);
    font-size: 15px;
    cursor: pointer;
    outline: none;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    min-width: 130px;
    box-shadow: var(--shadow-sm);
}

#sortOptions:hover {
    background: var(--text);
    transform: translateY(-1px);
    box-shadow: var(--shadow);
    color: var(--glass);
}

.control-buttons {
    display: flex;
    gap: 0.5rem;
}

#settings {
    background: rgba(255, 255, 255, 0.1);
    border: 0;
    color: white;
    font-size: 1.2rem;
    cursor: pointer;
    padding: 0.75rem;
    border-radius: var(--radius);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(20px);
}

#settings:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: translateY(-1px);
    box-shadow: var(--shadow);
}

main {
    max-width: 1200px;
    margin: 0 auto;
    padding: 2rem 1rem;
}

#zoneCount {
    margin: 0 0 1.5rem;
    font-size: 14px;
    color: var(--text-muted);
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

#zoneCount::before {
    content: '';
    width: 4px;
    height: 4px;
    border-radius: 50%;
    background: var(--primary);
}

#container,
#featuredZones {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 1.5rem;
}

.zone-item {
    background: var(--gradient-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
    cursor: pointer;
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    flex-direction: column;
    position: relative;
    box-shadow: var(--shadow-sm);
}

.zone-item:hover {
    transform: translateY(-8px) scale(1.02);
    box-shadow: var(--shadow-xl);
    border-color: var(--primary);
}

.zone-item:hover::before {
    opacity: 1;
}

.zone-item::before {
    content: '';
    position: absolute;
    inset: 0;
    background: var(--primary-light);
    opacity: 0;
    transition: opacity 0.4s ease;
    pointer-events: none;
    z-index: 1;
}

.zone-item img {
    width: 100%;
    aspect-ratio: 1;
    object-fit: cover;
    display: block;
    background: var(--border-light);
    transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

.zone-item:hover img {
    transform: scale(1.05);
}

.zone-item button {
    background: transparent;
    color: var(--text);
    border: 0;
    padding: 1.25rem 1rem;
    cursor: pointer;
    font-weight: 600;
    font-size: 14px;
    line-height: 1.4;
    text-align: center;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    min-height: 70px;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    z-index: 2;
}

.zone-item:hover button {
    color: var(--primary);
    background: rgba(252, 38, 81, 0.05);
}

#zoneViewer {
    position: fixed;
    inset: 0;
    background: var(--bg);
    z-index: 1000;
    display: none;
    flex-direction: column;
    animation: slideInUp 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes slideInUp {
    from {
        transform: translateY(100%);
    }
    to {
        transform: translateY(0);
    }
}

.zone-header {
    background: var(--gradient-primary);
    color: white;
    padding: 1rem 1.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: var(--shadow-lg);
}

.zone-title {
    flex: 1;
    min-width: 0;
}

#zoneName {
    font-size: 1.25rem;
    font-weight: 700;
    margin: 0 0 0.25rem;
    line-height: 1.3;
}

#zoneId {
    display: none;
}

#zoneAuthor {
    font-size: 14px;
    color: rgba(255, 255, 255, 0.8);
    text-decoration: none;
    transition: all 0.2s ease;
    font-weight: 500;
}

#zoneAuthor:hover {
    color: white;
    text-decoration: underline;
}

.zone-controls {
    display: flex;
    gap: 0.75rem;
}

.zone-controls button {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.3);
    color: white;
    padding: 0.625rem 1rem;
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    backdrop-filter: blur(20px);
}

.zone-controls button:hover {
    background: rgba(255, 255, 255, 0.2);
    border-color: rgba(255, 255, 255, 0.5);
    transform: translateY(-1px);
    box-shadow: var(--shadow);
}

#zoneFrame {
    flex-grow: 1;
    border: none;
    width: 90%;
    height: 90%;
}

#popupOverlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(8px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    padding: 1rem;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

.popup {
    background: var(--surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-xl);
    width: 100%;
    max-width: 520px;
    max-height: 80vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    border: 1px solid var(--border);
    animation: slideInScale 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes slideInScale {
    from {
        transform: scale(0.9) translateY(20px);
        opacity: 0;
    }
    to {
        transform: scale(1) translateY(0);
        opacity: 1;
    }
}

.popup-header {
    background: var(--gradient-primary);
    color: white;
    padding: 1.25rem 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

#popupTitle {
    margin: 0;
    font-size: 1.25rem;
    font-weight: 700;
}

#popupClose {
    background: rgba(255, 255, 255, 0.1);
    border: 0;
    color: white;
    font-size: 1.25rem;
    cursor: pointer;
    padding: 0.5rem;
    border-radius: var(--radius);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    line-height: 1;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(20px);
}

#popupClose:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: scale(1.1);
}

#popupBody {
    padding: 1.5rem;
    overflow-y: auto;
    color: var(--text);
}

#popupBody input[type="text"],
#popupBody input[type="file"] {
    width: 100%;
    padding: 0.875rem 1rem;
    margin-bottom: 1.25rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-secondary);
    color: var(--text);
    font-size: 15px;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    outline: none;
}

#popupBody input[type="text"]:focus,
#popupBody input[type="file"]:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(252, 38, 81, 0.1);
    transform: translateY(-1px);
}

#settings-button {
    width: 100%;
    padding: 0.875rem 1rem;
    background: var(--gradient-primary);
    color: white;
    border: 0;
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 15px;
    font-weight: 600;
    margin-bottom: 1rem;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: var(--shadow-sm);
}

#settings-button:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

#settings-button:active {
    transform: translateY(0);
}

footer {
    background: var(--bg-secondary);
    border-top: 1px solid var(--border);
    padding: 2rem 1rem;
    margin-top: 3rem;
    text-align: center;
}

.footer-links {
    display: flex;
    justify-content: center;
    gap: 2rem;
    flex-wrap: wrap;
}

.footer-links a {
    color: var(--primary);
    text-decoration: none;
    font-weight: 600;
    font-size: 15px;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    padding: 0.5rem 1rem;
    border-radius: var(--radius);
}

.footer-links a:hover {
    color: var(--primary-hover);
    background: var(--primary-light);
    transform: translateY(-1px);
}

@media (max-width: 768px) {
    .header-content {
        flex-direction: column;
        gap: 1rem;
        padding: 1rem;
    }

    .search-container {
        width: 100%;
        max-width: none;
    }

    main {
        padding: 1.5rem 1rem;
    }

    #container,
    #featuredZones {
        grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
        gap: 1.25rem;
    }

    .zone-item button {
        padding: 1rem 0.75rem;
        min-height: 65px;
        font-size: 13px;
    }

    .footer-links {
        gap: 1.5rem;
    }
}

@media (max-width: 480px) {
    #container,
    #featuredZones {
        grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
        gap: 1rem;
    }

    .popup {
        margin: 0.5rem;
    }

    .zone-item:hover {
        transform: translateY(-4px) scale(1.01);
    }
}