/* ============================================
   CSS RESET & BASE STYLES
   ============================================ */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
    overflow-x: hidden;
}

/* Import Google Fonts */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap');

body {
    /* font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', sans-serif; */
    /* background: #0E1B2B; */
    /* color: #E5ECF5; */
    overflow-x: hidden;
    /* background-image: ...; Keep or remove? detailed background might be nice, but home is simpler. Let's comment specifically and see. */
    /* background-image:
        radial-gradient(circle at 20% 50%, rgba(47, 109, 181, 0.15) 0%, transparent 50%),
        radial-gradient(circle at 80% 80%, rgba(123, 63, 228, 0.1) 0%, transparent 50%); */
    min-height: 100vh;
    /* padding-top: 6rem; Removed for sticky nav */
    line-height: 1.6;
}

/* Prevent media from overflowing and help layout shrink properly */
img,
picture,
video,
svg {
    max-width: 100%;
    height: auto;
    display: block;
}

/* ============================================
   COLORS & DESIGN TOKENS
   ============================================ */
:root {
    /* Base Colors - In-Game Clash of Clans Dark Theme */
    --background: #0E1B2B;
    --foreground: #E5ECF5;
    --card: #162A44;
    --card-foreground: #E5ECF5;
    --primary: #F2C94C;
    --primary-foreground: #2A1A00;
    --secondary: #2F6DB5;
    --secondary-foreground: #FFFFFF;
    --muted: #132238;
    --muted-foreground: #B6C2D9;
    --border: #2F6DB5;
    --input: #132238;

    /* Accent Colors - In-Game Rarity & Elements */
    --teal: #4DA3FF;
    --orange: #FF8C42;
    --green: #10B981;
    --purple: #7B3FE4;
    --gold: #F2C94C;
    --gold-dark: #D4A017;
    --gold-light: #FFD95A;
    --red: #E63946;
    --blue-navbar: #1E5AA8;
    --blue-light: #4DA3FF;
    --blue-dark: #0B1420;

    /* Text Colors */
    --text-primary: #E5ECF5;
    --text-secondary: #B6C2D9;
    --text-muted: #7A8DA6;

    /* Hover State Colors */
    --card-hover: #1A3351;
    --border-hover: #F2C94C;

    /* Gradients */
    --gradient-gold: linear-gradient(135deg, var(--gold-light), var(--gold));
    --gradient-blue: linear-gradient(135deg, var(--blue-navbar), var(--secondary));
    --gradient-navbar: linear-gradient(180deg, #1E5AA8, #1A4F94);
    --gradient-purple: linear-gradient(135deg, #9D6FFF, var(--purple));
    --gradient-card: linear-gradient(135deg, #162A44, #1A3351);

    /* Shadows - Darker for depth */
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.35);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 8px 20px rgba(0, 0, 0, 0.45);
    --shadow-xl: 0 12px 30px rgba(0, 0, 0, 0.5);
    --shadow-gold: 0 0 12px rgba(242, 201, 76, 0.4);
    --shadow-gold-lg: 0 0 20px rgba(242, 201, 76, 0.5);

    /* Animation Timing */
    --transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
    --transition-base: 250ms cubic-bezier(0.4, 0, 0.2, 1);
    --transition-slow: 350ms cubic-bezier(0.4, 0, 0.2, 1);
    --ease-out: cubic-bezier(0, 0, 0.2, 1);
    --ease-in-out: cubic-bezier(0.4, 0, 0.2, 1);

    /* Blur Effects */
    --blur-sm: 8px;
    --blur-md: 12px;
    --blur-lg: 16px;

    /* Spacing Scale */
    --space-xs: 0.25rem;
    --space-sm: 0.5rem;
    --space-md: 1rem;
    --space-lg: 1.5rem;
    --space-xl: 2rem;

    /* Border Radius */
    --radius-sm: 0.375rem;
    --radius-md: 0.5rem;
    --radius-lg: 0.75rem;
    --radius-xl: 1rem;
    --radius-full: 9999px;
}

/* ============================================
   ROOT CONTAINER
   ============================================ */
#root {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    overflow-x: hidden;
}

/* ============================================
   HEADER
   ============================================ */
.header {
    position: relative;
    overflow: hidden;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border-color);
    padding: 1.5rem 1rem;
}

.header::before {
    display: none;
}

.header::after {
    content: '';
    position: absolute;
    bottom: 0;
    right: 25%;
    width: 24rem;
    height: 24rem;
    background: hsla(174, 77%, 47%, 0.2);
    filter: blur(3rem);
    opacity: 0.1;
}

.header-content {
    position: relative;
    max-width: 80rem;
    margin: 0 auto;
}

.header-inner {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
}

.header-logo {
    width: 5rem;
    height: 5rem;
    filter: drop-shadow(0 25px 50px rgba(0, 0, 0, 0.5));
}

@media (min-width: 768px) {
    .header-logo {
        width: 6rem;
        height: 6rem;
    }
}

.header-text {
    text-align: center;
}

.header-title {
    font-size: 2rem;
    font-weight: bold;
    background: linear-gradient(135deg, hsl(48, 100%, 70%), hsl(45, 100%, 60%));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    letter-spacing: 0.05em;
    margin-bottom: 0.5rem;
}

@media (min-width: 768px) {
    .header-title {
        font-size: 3rem;
    }
}

.header-subtitle {
    font-size: 0.875rem;
    color: var(--muted-foreground);
    font-weight: 500;
    letter-spacing: 0.05em;
}

@media (min-width: 768px) {
    .header-subtitle {
        font-size: 1rem;
    }
}

/* ============================================
   SCROLLBAR STYLING
   ============================================ */
::-webkit-scrollbar {
    width: 0.5rem;
    height: 0.5rem;
}

::-webkit-scrollbar-track {
    background: var(--background);
}

::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 0.25rem;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--muted);
}

/* ============================================
   TOP NAVIGATION (DROPDOWN EXTENSION)
   ============================================ */
.top-nav {
    background: hsla(210, 25%, 12%, 0.7);
    /* Semi-transparent */
    backdrop-filter: blur(var(--blur-md));
    /* Blur effect */
    -webkit-backdrop-filter: blur(var(--blur-md));
    border-bottom: 1px solid var(--border);
    padding: 0 1rem;
    display: flex;
    justify-content: center;
    align-items: center;
    position: fixed;
    /* Fixed to viewport */
    top: 0;
    left: 0;
    width: 100%;
    z-index: 1000;
    box-shadow: var(--shadow-sm);
    transition: background var(--transition-base);
}

.nav-list {
    list-style: none;
    display: flex;
    gap: 2rem;
    margin: 0;
    padding: 0;
    justify-content: center;
    /* Center the links */
    align-items: center;
    height: 3.5rem;
    /* Fixed height for top bar */
}

.nav-item {
    position: relative;
    height: 100%;
    display: flex;
    align-items: center;
}

.nav-item>a,
.nav-item>span {
    color: var(--muted-foreground);
    text-decoration: none;
    font-weight: 600;
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 0 0.5rem;
    height: 100%;
    display: flex;
    align-items: center;
    cursor: pointer;
    transition: all var(--transition-base);
    position: relative;
}

.nav-item>a::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%) scaleX(0);
    width: 80%;
    height: 2px;
    background: var(--gradient-gold);
    transition: transform var(--transition-base);
}

.nav-item:hover>a,
.nav-item:hover>span,
.nav-item>a:hover {
    color: var(--gold-light);
    text-shadow: 0 0 8px hsla(45, 100%, 60%, 0.3);
}

.nav-item>a:hover::after,
.nav-item>a.active::after {
    transform: translateX(-50%) scaleX(1);
}

.nav-item>a.active {
    color: var(--gold);
}

/* ============================================
   SUB NAVIGATION
   ============================================ */
.sub-nav {
    background: rgba(22, 27, 37, 0.95);
    /* Match var(--bg-panel) with opacity */
    backdrop-filter: blur(var(--blur-sm));
    -webkit-backdrop-filter: blur(var(--blur-sm));
    border-bottom: 1px solid var(--border);
    padding: 0 1rem;
    display: flex;
    justify-content: center;
    align-items: center;
    height: 3rem;
    /* Slightly taller */
    position: sticky;
    /* Changed from fixed to sticky */
    top: 94px;
    /* Approx height of global navbar */
    left: 0;
    width: 100%;
    z-index: 99;
    /* Below navbar (z-100) */
    box-shadow: var(--shadow-sm);
    margin-top: -1px;
    /* Connect border */
}

@media (max-width: 768px) {
    .sub-nav {
        top: 0;
        position: relative;
        justify-content: flex-start;
        height: auto;
        min-height: 3.5rem;
        padding-top: 0.5rem;
        padding-bottom: 0.5rem;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        z-index: 101;
        /* Ensure above others if overlap occurs */
    }

    .sub-nav::-webkit-scrollbar {
        display: none;
    }

    .sub-nav-list {
        height: auto;
        padding: 0;
        margin: 0;
        gap: 1rem;
        display: flex;
        align-items: center;
    }

    .sub-nav-item>a {
        padding: 0.5rem 1rem;
        font-size: 0.9rem;
        white-space: nowrap;
        height: auto;
        display: block;
    }
}

/* .sub-nav-container removed as it was empty */

.sub-nav-list {
    height: 100%;
}

.sub-nav-item>a {
    font-size: 0.8rem;
    color: var(--muted-foreground);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 0 1rem;
    height: 100%;
    display: flex;
    align-items: center;
    transition: all var(--transition-base);
    position: relative;
}

.sub-nav-item>a::before {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 2px;
    background: var(--gradient-gold);
    transform: scaleX(0);
    transition: transform var(--transition-base);
}

.sub-nav-item>a:hover {
    color: var(--gold-light);
    background: rgba(255, 255, 255, 0.05);
}

.sub-nav-item>a:hover::before {
    transform: scaleX(1);
}

/* Dropdown Menu */
.dropdown-menu {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 0 0 0.5rem 0.5rem;
    /* Rounded bottom corners */
    min-width: 200px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    padding: 0.5rem 0;
    z-index: 1001;
}

.nav-item:hover>.dropdown-menu {
    display: block;
    animation: fadeIn 0.2s ease;
}

.dropdown-menu li {
    position: relative;
}

/* Dropdown Links */
.dropdown-menu a,
.dropdown-menu span {
    display: flex;
    align-items: center;
    justify-content: space-between;
    /* For submenu arrows */
    padding: 0.75rem 1.5rem;
    color: var(--foreground);
    text-decoration: none;
    font-size: 0.9rem;
    transition: background 0.2s ease, color 0.2s ease;
    cursor: pointer;
}

.dropdown-menu a:hover,
.dropdown-menu li:hover>span {
    background: hsla(210, 20%, 20%, 0.5);
    color: var(--gold);
}

/* Nested Dropdown (Submenu) */
.dropdown-submenu>.dropdown-menu {
    top: 0;
    left: 100%;
    border-radius: 0.5rem;
    margin-left: 5px;
    /* Slight gap */
}

.dropdown-menu li:hover>.dropdown-menu {
    display: block;
}

/* Submenu Indicator */
.dropdown-submenu>span::after,
.dropdown-submenu>a::after {
    content: '›';
    font-weight: bold;
    margin-left: 0.5rem;
}

@media (max-width: 768px) {

    /* Simple mobile stacked fallback for now, complex mobile menu requires JS/Checkboxes */
    .top-nav {
        height: auto;
        padding: 0.5rem 0;
        display: flex;
        justify-content: center;
        align-items: center;
    }

    .nav-list {
        flex-direction: row;
        display: flex;
        height: auto;
        gap: 1rem;
        flex-wrap: wrap;
        justify-content: center;
    }

    .nav-item {
        height: auto;
        width: auto;
        flex-direction: row;
        align-items: center;
    }

    .nav-item>a,
    .nav-item>span {
        width: 100%;
        padding: 0.75rem 1rem;
    }

    .dropdown-menu {
        position: static;
        box-shadow: none;
        border: none;
        background: rgba(0, 0, 0, 0.2);
        width: 100%;
        display: none;
        /* Keep hidden by default */
    }

    .nav-item:hover>.dropdown-menu {
        display: block;
    }

    .dropdown-submenu>.dropdown-menu {
        position: static;
        margin-left: 1rem;
        border-left: 1px solid var(--border);
    }
}

/* ============================================
   WIKI GALLERY TABLE STYLES
   ============================================ */
.wiki-gallery-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    margin-bottom: 2rem;
    background: var(--bg-card);
    border-radius: 0.5rem;
    overflow: hidden;
    border: 1px solid var(--border-color);
}

.wiki-gallery-table th,
.wiki-gallery-table td {
    border: none;
    border-bottom: 1px solid var(--border-color);
    padding: 1rem;
    vertical-align: middle;
}

.wiki-gallery-table th {
    background: var(--bg-panel);
    color: var(--gold);
    text-transform: uppercase;
    font-size: 0.85rem;
    font-weight: 700;
    letter-spacing: 0.05em;
    text-align: left;
}

.wiki-gallery-table td img {
    width: 100px;
    height: 100px;
    object-fit: contain;
    display: block;
    margin: 0 auto;
    transition: transform var(--transition-base), filter var(--transition-base);
}

.wiki-gallery-table td img:hover {
    transform: scale(1.15);
    filter: drop-shadow(0 4px 12px rgba(0, 0, 0, 0.4));
}

.wiki-gallery-table tr:last-child td {
    border-bottom: none;
}

.wiki-gallery-table tr:hover td {
    background: hsla(210, 30%, 15%, 0.7);
    transition: background var(--transition-base);
}

@media (max-width: 600px) {

    .wiki-gallery-table th,
    .wiki-gallery-table td {
        padding: 0.4rem;
        font-size: 0.8rem;
    }

    .wiki-gallery-table th:first-child,
    .wiki-gallery-table td:first-child {
        width: 50px;
        padding-left: 0.1rem;
        padding-right: 0.1rem;
    }

    .wiki-gallery-table td img {
        width: 45px;
        height: 45px;
    }

    .code-cell {
        font-size: 0.75rem;
        padding: 0.2rem;
    }
}

@media (max-width: 450px) {
    .wiki-gallery-table {
        table-layout: fixed;
        /* Force fixed column widths */
        width: 100%;
        display: table;
        /* Ensure table display */
    }

    .wiki-gallery-table th,
    .wiki-gallery-table td {
        padding: 0.15rem;
        font-size: 0.7rem;
        word-wrap: break-word;
        /* Allow long words to break */
        overflow-wrap: break-word;
    }

    /* Column 1: Image - Fixed 40px */
    .wiki-gallery-table th:nth-child(1),
    .wiki-gallery-table td:nth-child(1) {
        width: 40px !important;
        min-width: 40px !important;
        max-width: 40px !important;
        padding: 0;
    }

    /* Column 2: Code - Fixed 55px */
    .wiki-gallery-table th:nth-child(2),
    .wiki-gallery-table td:nth-child(2) {
        width: 55px !important;
        min-width: 55px !important;
        max-width: 55px !important;
        padding: 0;
    }

    /* Column 3: Name - Auto/Compact */
    .wiki-gallery-table th:nth-child(3),
    .wiki-gallery-table td:nth-child(3) {
        /* Let it take natural space but squeeze if needed */
        width: 25%;
    }

    /* Column 4: Turn off description or make it very small if strictly needed? 
       No, just let it fill rest. 
    */

    .wiki-gallery-table td img {
        width: 35px;
        height: 35px;
        margin: 0 auto;
    }

    .code-cell {
        font-size: 0.6rem !important;
        padding: 0 !important;
        word-break: break-all;
    }
}

@media (max-width: 375px) {

    /* Hide Description Column (4th) */
    .wiki-gallery-table th:nth-child(4),
    .wiki-gallery-table td:nth-child(4) {
        display: none;
    }

    /* Give more space to Name since Description is gone */
    .wiki-gallery-table th:nth-child(3),
    .wiki-gallery-table td:nth-child(3) {
        width: auto;
        /* Allow it to fill remaining space */
    }
}

/* ============================================
   FOOTER STYLES
   ============================================ */
.wiki-footer {
    text-align: center;
    padding: 2rem;
    margin-top: 4rem;
    border-top: 1px solid var(--border-color);
    color: var(--muted-foreground);
    background: var(--bg-card);
}

.wiki-footer a {
    color: var(--primary);
    text-decoration: none;
    transition: color 0.2s;
}

.wiki-footer a:hover {
    color: var(--gold-light);
    text-decoration: underline;
}

.code-cell {
    text-align: center;
    font-family: 'Courier New', monospace;
    font-size: 0.9em;
    color: var(--muted-foreground);
    background-color: rgba(0, 0, 0, 0.2);
    padding: 0.5rem;
    border-radius: 4px;
}