@layer reset, base, components;

@layer reset {
    *, *::before, *::after {
        box-sizing: border-box;
    }
    * {  margin: 0;  }
    img, picture, video, canvas, svg {
        display: block;
        max-width: 100%;
        height: auto;
    }
    input, button, textarea, select {
        font: inherit;
        color: inherit;
    }
    :root {  color-scheme: light dark;  }
    
    /* Prevent horizontal overflow */
    html {
        overflow-x: hidden;
    }
}

@layer base {
    :root {
        --bg: #F1BE7A;
        --ink: #1A1A1A;
    }

    /* System preference for dark mode */
    @media (prefers-color-scheme: dark) {
        :root {
            --bg: #1A1A1A;
            --ink: #F1BE7A;
        }
    }

    /* Explicit dark theme override */
    [data-theme="dark"] {
        --bg: #1A1A1A;
        --ink: #F1BE7A;
    }

    /* Explicit light theme override */
    [data-theme="light"] {
        --bg: #F1BE7A;
        --ink: #1A1A1A;
    }

    html, body {
        height: 100%;
        font-size: clamp(16px, calc(12px + 0.6vw), 20px);
    }
    body {
        background: var(--bg);
        color: var(--ink);
        font-family:
            'JetBrains Mono', ui-monospace,
            SFMono-Regular, Menlo, Monaco, /* Mac */
            'Cascadia Code', 'Cascadia Mono', Consolas, /* Windows */
            'Ubuntu Mono', 'DejaVu Sans Mono', 'Liberation Mono', 'Noto Sans Mono', /* Linux */
            monospace;
        line-height: 1.5;
        -webkit-font-smoothing: antialiased;
        display: flex;
        flex-direction: column;
        min-height: 100vh;
        overflow-x: hidden;
    }

    :where(h1, h2, h3) {
        line-height: 1.2;
        font-weight: 700;
    }
    h1 {  font-size: 6rem;  }
    h2 {  font-size: 2.5rem;  }
    h3 {  font-size: 1.75rem;  }

    p { 
        margin-block: 2rem; 
        word-wrap: break-word;
        overflow-wrap: break-word;
        hyphens: auto;
    }

    /* Link styling for better readability */
    a {
        color: #0066CC;
        text-decoration: underline;
        transition: color 0.2s ease;
        word-wrap: break-word;
        overflow-wrap: break-word;
    }

    a:hover {
        color: #004499;
    }

    a:visited {
        color: #663399;
    }

    /* System preference for dark mode link colors */
    @media (prefers-color-scheme: dark) {
        a {
            color: #66B3FF;
        }

        a:hover {
            color: #99CCFF;
        }

        a:visited {
            color: #CC99FF;
        }
    }

    /* Explicit dark theme override */
    [data-theme="dark"] a {
        color: #66B3FF;
    }

    [data-theme="dark"] a:hover {
        color: #99CCFF;
    }

    [data-theme="dark"] a:visited {
        color: #CC99FF;
    }

    /* Explicit light theme override */
    [data-theme="light"] a {
        color: #0066CC;
    }

    [data-theme="light"] a:hover {
        color: #004499;
    }

    [data-theme="light"] a:visited {
        color: #663399;
    }
}

@layer components {
    .nowrap {
        display: inline-block;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    header {
        background: var(--bg);
        padding: 1rem clamp(1rem, 4vw, 2rem) 2.5rem clamp(1rem, 4vw, 2rem);
        position: relative;
    }

    header::after {
        content: '';
        position: absolute;
        bottom: 0;
        left: 0;
        right: 0;
        height: 50px;
        background-image: url("../images/meander_light_mode.svg");
        background-repeat: repeat-x;
        background-size: 106.75px 50px;
    }

    /* System preference for dark mode */
    @media (prefers-color-scheme: dark) {
        header::after {
            background-image: url("../images/meander_dark_mode.svg");
            background-size: 106.75px 50px;
        }
    }

    /* Explicit dark theme override */
    [data-theme="dark"] header::after {
        background-image: url("../images/meander_dark_mode.svg");
        background-size: 106.75px 50px;
    }

    /* Explicit light theme override */
    [data-theme="light"] header::after {
        background-image: url("../images/meander_light_mode.svg");
        background-size: 106.75px 50px;
    }

    nav {
        display: flex;
        justify-content: space-between;
        align-items: center;
        max-width: 1200px;
        margin: 0 auto;
        flex-wrap: wrap;
        gap: 1rem;
    }

    .nav-links {
        display: flex;
        gap: clamp(1rem, 3vw, 2rem);
        flex-wrap: wrap;
    }

    .nav-links a {
        color: var(--ink);
        text-decoration: none;
        font-weight: 500;
        transition: opacity 0.2s ease;
    }

    .nav-links a:hover {
        opacity: 0.7;
    }

    .logo {
        font-size: 70px;
        font-weight: 700;
    }

    .logo-img {
        height: clamp(40px, 10vw, 70px);
        width: auto;
    }

    .logo a {
        color: inherit;
        text-decoration: none;
    }

    .logo a:visited {
        color: inherit;
    }

    main {
        padding: clamp(1rem, 4vw, 2rem);
        max-width: 1200px;
        margin-left: auto;
        margin-right: auto;
        flex: 1;
        width: 100%;
        box-sizing: border-box;
    }

    .multi-level-title {
        display: flex;
        flex-direction: column;
        line-height: 1;
        margin-bottom: 2rem;
        position: relative;
        max-width: 400px;
        margin-left: auto;
        margin-right: auto;
    }

    .title-top {
        color: var(--ink);
        text-decoration: none;
        font-weight: 500;
        font-size: 1.2rem;
        margin-bottom: 0.5rem;
        text-align: left;
    }

    .title-main {
        font-size: clamp(4rem, 15vw, 132px);
        font-weight: 700;
        margin: 0;
        text-align: center;
    }

    .title-bottom {
        color: var(--ink);
        text-decoration: none;
        font-weight: 500;
        font-size: 1.2rem;
        margin-top: 0.5rem;
        text-align: right;
    }

    .theme-toggle {
        display: flex;
        align-items: center;
        margin-left: 2rem;
    }

    .theme-switch {
        position: relative;
        display: inline-block;
        width: 60px;
        height: 34px;
    }

    .theme-switch input {
        opacity: 0;
        width: 0;
        height: 0;
    }

    .slider {
        position: absolute;
        cursor: pointer;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background-color: var(--ink);
        transition: 0.4s;
        border-radius: 34px;
    }

    .slider:before {
        position: absolute;
        content: "";
        height: 26px;
        width: 26px;
        left: 4px;
        bottom: 4px;
        background-color: var(--bg);
        transition: 0.4s;
        border-radius: 50%;
    }

    input:checked + .slider {
        background-color: var(--ink);
    }

    input:checked + .slider:before {
        transform: translateX(26px);
    }

    .slider:hover {
        opacity: 0.8;
    }

    footer {
        padding: 2rem;
        max-width: 1200px;
        margin-left: auto;
        margin-right: auto;
        position: relative;
    }

    footer::before {
        content: '';
        position: absolute;
        top: 0;
        left: 50%;
        transform: translateX(-50%);
        width: 100vw;
        height: 1px;
        background-color: var(--ink);
    }

    .footer-content {
        display: grid;
        grid-template-columns: 1fr auto 1fr;
        align-items: center;
        gap: 1rem;
    }

    .footer-logo {
        height: 30px;
        width: auto;
    }

    .footer-copyright {
        justify-self: center;
        grid-column: 2;
        font-size: 0.9rem;
        color: var(--ink);
    }

    .partner-logos {
        display: flex;
        gap: clamp(1rem, 4vw, 2rem);
        align-items: center;
        flex-wrap: wrap;
        justify-content: center;
        width: 100%;
        max-width: 100%;
        box-sizing: border-box;
    }

    .partner-logo {
        height: 70px;
        width: auto;
        max-width: 100%;
    }

    /* Mobile-specific styles */
    @media (max-width: 768px) {
        /* Ensure paragraph spacing is preserved on mobile */
        p { 
            margin-block: 2rem !important; 
        }
        header {
            padding: 1rem clamp(1rem, 4vw, 2rem) 3rem clamp(1rem, 4vw, 2rem);
            position: relative;
        }
        
        nav {
            display: block !important;
            position: relative;
            width: 100%;
            justify-content: flex-start !important;
            align-items: flex-start !important;
            margin: 0 !important;
        }
        
        .logo {
            display: inline-block !important;
            margin: 0 !important;
            position: relative;
            z-index: 2;
            text-align: left !important;
        }
        
        .theme-toggle {
            position: absolute;
            top: 0;
            right: 0;
            margin: 0;
            z-index: 2;
        }
        
        .nav-links {
            display: flex;
            flex-direction: row;
            justify-content: center;
            width: 100%;
            gap: 1.5rem;
            margin-top: 1.5rem;
            padding-top: 0.5rem;
        }
        
        .nav-links a {
            font-size: 0.9rem;
        }
        
        .theme-switch {
            width: 50px;
            height: 28px;
        }
        
        .slider:before {
            height: 20px;
            width: 20px;
            left: 4px;
            bottom: 4px;
        }
        
        input:checked + .slider:before {
            transform: translateX(22px);
        }
        
        .multi-level-title {
            max-width: 100%;
        }
        
        .title-top {
            font-size: 1rem;
            text-align: center;
            transform: translateX(-4rem);
        }
        
        .title-bottom {
            font-size: 1rem;
            text-align: center;
            transform: translateX(4rem);
        }
        
        .partner-logos {
            display: grid !important;
            grid-template-columns: 1fr !important;
            gap: 1rem !important;
            justify-items: center !important;
        }
        
        .partner-logo {
            height: 70px;
        }
        
        footer {
            padding: clamp(1rem, 4vw, 2rem);
        }
        
        /* Force footer layout on mobile - override any layer issues */
        footer .footer-content {
            display: flex !important;
            flex-direction: row !important;
            justify-content: space-between !important;
            align-items: center !important;
            width: 100% !important;
            gap: 1rem !important;
            grid-template-columns: none !important;
        }
        
        footer .footer-logo {
            order: 1 !important;
            flex-shrink: 0 !important;
            margin: 0 !important;
            padding: 0 !important;
            grid-column: unset !important;
            justify-self: unset !important;
        }
        
        footer .footer-copyright {
            order: 2 !important;
            flex-shrink: 0 !important;
            margin: 0 !important;
            padding: 0 !important;
            text-align: right !important;
            grid-column: unset !important;
            justify-self: unset !important;
        }
    }
    
    /* Very small screens */
    @media (max-width: 480px) {
        header {
            padding: 1rem 1rem 3.5rem 1rem;
        }
        
        .nav-links {
            flex-direction: row;
            gap: 0.75rem;
            width: 100%;
            justify-content: center;
            margin-top: 1rem;
            flex-wrap: wrap;
        }
        
        .nav-links a {
            font-size: 0.8rem;
            text-align: center;
            min-width: 44px; /* Minimum touch target size */
            padding: 0.25rem 0.5rem;
        }
        
        .title-main {
            font-size: clamp(3rem, 20vw, 4rem);
        }
        
        .theme-switch {
            width: 44px; /* Minimum touch target size */
            height: 24px;
        }
        
        .slider:before {
            height: 18px;
            width: 18px;
            left: 3px;
            bottom: 3px;
        }
        
        input:checked + .slider:before {
            transform: translateX(20px);
        }
    }
}
