/* ===================================
   CSS Reset and Base Styles
   =================================== */

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    /* Color Palette - Order to Chaos gradient */
    --color-order: #1e3a8a;
    --color-order-light: #3b82f6;
    --color-transition: #8b5cf6;
    --color-chaos: #dc2626;
    --color-chaos-light: #f97316;

    /* Neutral colors */
    --color-bg-primary: #ffffff;
    --color-bg-secondary: #f8fafc;
    --color-bg-dark: #0f172a;
    --color-text-primary: #1e293b;
    --color-text-secondary: #475569;
    --color-text-light: #94a3b8;
    --color-border: #e2e8f0;

    /* Typography */
    --font-primary: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    --font-secondary: Georgia, 'Times New Roman', serif;

    /* Spacing */
    --spacing-xs: 0.5rem;
    --spacing-sm: 1rem;
    --spacing-md: 2rem;
    --spacing-lg: 4rem;
    --spacing-xl: 6rem;

    /* Transitions */
    --transition-fast: 0.2s ease;
    --transition-normal: 0.3s ease;
    --transition-slow: 0.5s ease;
}

html {
    scroll-behavior: smooth;
    font-size: 16px;
}

body {
    font-family: var(--font-primary);
    line-height: 1.6;
    color: var(--color-text-primary);
    background-color: var(--color-bg-primary);
    overflow-x: hidden;
}

/* ===================================
   Accessibility
   =================================== */

.skip-link {
    position: absolute;
    top: -40px;
    left: 0;
    background: var(--color-order);
    color: white;
    padding: var(--spacing-xs) var(--spacing-sm);
    text-decoration: none;
    z-index: 100;
}

.skip-link:focus {
    top: 0;
}

/* Focus styles for keyboard navigation */
a:focus,
button:focus {
    outline: 3px solid var(--color-order-light);
    outline-offset: 2px;
}
/* ===========================
   Navigation (All devices)
   =========================== */

nav {
    position: sticky;
    top: 0;
    z-index: 50;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--color-border);
}

/* Base nav list */
.nav-list {
    list-style: none;
    display: flex;
    gap: var(--spacing-sm);
    padding: var(--spacing-sm);
    margin: 0;
    justify-content: center;
}

/* Links */
.nav-list a {
    white-space: nowrap;
    text-decoration: none;
    color: var(--color-text-primary);
    padding: var(--spacing-xs) var(--spacing-sm);
    border-radius: 999px; /* pill style */
    font-weight: 500;
    transition: background var(--transition-fast), color var(--transition-fast);
}

.nav-list a:hover {
    background: var(--color-order);
    color: white;
}

/* ===========================
   Mobile & Tablet
   =========================== */

/* Right-side fade */
nav::after {
    content: "";
    position: absolute;
    top: 0;
    right: 0;
    width: 48px;
    height: 100%;
    pointer-events: none;
    background: linear-gradient(
        to left,
        rgba(255, 255, 255, 0.95),
        rgba(255, 255, 255, 0)
    );
}

/* Left-side fade (only when scrolled) */
nav::before {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    width: 48px;
    height: 100%;
    pointer-events: none;
    background: linear-gradient(
        to right,
        rgba(255, 255, 255, 0.95),
        rgba(255, 255, 255, 0)
    );
}


@media (max-width: 768px) {

    .nav-list {
        justify-content: flex-start;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none; /* Firefox */
    }

    .nav-list::-webkit-scrollbar {
        display: none; /* Chrome/Safari */
    }
}

/* ===================================
   Container
   =================================== */

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 var(--spacing-sm);
}

/* ===================================
   Hero Section
   =================================== */

.hero-section {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    background: linear-gradient(135deg, var(--color-order) 0%, var(--color-transition) 50%, var(--color-chaos) 100%);
    color: white;
    text-align: center;
    padding: var(--spacing-lg) var(--spacing-sm);
    position: relative;
    overflow: hidden;
}

.hero-content {
    z-index: 2;
    max-width: 800px;
}

.hero-title {
    font-size: clamp(3rem, 10vw, 6rem);
    font-weight: 800;
    letter-spacing: -0.02em;
    margin-bottom: var(--spacing-sm);
    animation: fadeInUp 1s ease;
}

.hero-subtitle {
    font-size: clamp(1.25rem, 3vw, 2rem);
    font-weight: 300;
    margin-bottom: var(--spacing-sm);
    animation: fadeInUp 1s ease 0.2s backwards;
}

.hero-description {
    font-size: clamp(1rem, 2vw, 1.25rem);
    opacity: 0.9;
    animation: fadeInUp 1s ease 0.4s backwards;
}

.hero-image-container {
    position: absolute;
    inset: 0;
    z-index: 1;
    opacity: 0.2;
}

.hero-image {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(30px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ===================================
   Section Styles
   =================================== */

section {
    padding: var(--spacing-xl) 0;
}

section h2 {
    font-size: clamp(2rem, 5vw, 3rem);
    margin-bottom: var(--spacing-md);
    color: var(--color-order);
    text-align: center;
}

.section-intro {
    text-align: center;
    font-size: 1.125rem;
    color: var(--color-text-secondary);
    max-width: 700px;
    margin: 0 auto var(--spacing-lg);
}

/* ===================================
   Definition Section
   =================================== */

.definition-section {
    background: var(--color-bg-secondary);
}

.definition-card {
    background: white;
    border-radius: 12px;
    padding: var(--spacing-md);
    margin-bottom: var(--spacing-md);
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

.definition-card h3 {
    font-size: 1.75rem;
    color: var(--color-order);
    margin-bottom: var(--spacing-sm);
}

.definition-card h4 {
    font-size: 1.375rem;
    color: var(--color-transition);
    margin-bottom: var(--spacing-sm);
}

.definition-content {
    display: grid;
    gap: var(--spacing-md);
    align-items: center;
}

.definition-text {
    line-height: 1.8;
}

.definition-text p {
    margin-bottom: var(--spacing-sm);
}

.definition-text strong {
    color: var(--color-order);
    font-weight: 600;
}

.definition-image img {
    width: 100%;
    height: auto;
    border-radius: 8px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

blockquote {
    border-left: 4px solid var(--color-order);
    padding-left: var(--spacing-sm);
    margin: var(--spacing-md) 0;
    font-style: italic;
    color: var(--color-text-secondary);
    font-family: var(--font-secondary);
}

.formula {
    background: var(--color-bg-secondary);
    padding: var(--spacing-sm);
    border-radius: 8px;
    font-family: 'Courier New', monospace;
    text-align: center;
    font-size: 1.125rem;
    margin: var(--spacing-sm) 0;
}

/* ===================================
   Personal Section
   =================================== */

.personal-section {
    background: linear-gradient(to bottom, white, var(--color-bg-secondary));
}

.personal-content {
    max-width: 800px;
    margin: 0 auto;
}

.personal-reflection h3 {
    font-size: 1.75rem;
    color: var(--color-order);
    margin-bottom: var(--spacing-sm);
}

.personal-reflection h4 {
    font-size: 1.375rem;
    color: var(--color-transition);
    margin-top: var(--spacing-md);
    margin-bottom: var(--spacing-sm);
}

.personal-reflection p {
    margin-bottom: var(--spacing-sm);
    line-height: 1.8;
}

.personal-insight {
    background: var(--color-order);
    color: white;
    padding: var(--spacing-md);
    border-radius: 8px;
    font-size: 1.125rem;
    font-style: italic;
    margin-top: var(--spacing-md);
    text-align: center;
}

/* ===================================
   Visual Section
   =================================== */

.visual-section {
    background: var(--color-bg-primary);
}

.visual-grid {
    display: grid;
    gap: var(--spacing-md);
}

.visual-item {
    background: white;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    transition: transform var(--transition-normal), box-shadow var(--transition-normal);
}

.visual-item:hover {
    transform: translateY(-8px);
    box-shadow: 0 12px 24px rgba(0, 0, 0, 0.15);
}

.visual-item img {
    width: 100%;
    height: 300px;
    object-fit: cover;
}

.visual-item figcaption {
    padding: var(--spacing-md);
}

.visual-item h3 {
    font-size: 1.375rem;
    color: var(--color-order);
    margin-bottom: var(--spacing-xs);
}

.visual-item p {
    color: var(--color-text-secondary);
}

/* ===================================
   Derivatives Section
   =================================== */

.derivatives-section {
    background: var(--color-bg-secondary);
}

.derivatives-grid {
    display: grid;
    gap: var(--spacing-md);
    margin-bottom: var(--spacing-lg);
}

.derivative-card {
    background: white;
    padding: var(--spacing-md);
    border-radius: 8px;
    border-left: 4px solid var(--color-order);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.derivative-card h3 {
    font-size: 1.25rem;
    color: var(--color-order);
    margin-bottom: var(--spacing-xs);
}

.derivative-card p {
    color: var(--color-text-secondary);
    margin-bottom: var(--spacing-xs);
}

.example {
    font-style: italic;
    color: var(--color-text-light);
    font-size: 0.9375rem;
}

.context-exploration {
    background: white;
    padding: var(--spacing-md);
    border-radius: 12px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

.context-exploration h3 {
    font-size: 1.75rem;
    color: var(--color-order);
    margin-bottom: var(--spacing-md);
    text-align: center;
}

.context-list {
    display: grid;
    gap: var(--spacing-md);
}

.context-item {
    padding: var(--spacing-sm);
    border-left: 3px solid var(--color-transition);
    background: var(--color-bg-secondary);
    border-radius: 4px;
}

.context-item h4 {
    font-size: 1.125rem;
    margin-bottom: var(--spacing-xs);
    color: var(--color-order);
}

.context-item p {
    color: var(--color-text-secondary);
    font-size: 0.9375rem;
}

/* ===================================
   Reflection Section
   =================================== */

.reflection-section {
    background: linear-gradient(135deg, var(--color-order) 0%, var(--color-bg-dark) 100%);
    color: white;
}

.reflection-section h2 {
    color: white;
}

.reflection-content {
    max-width: 800px;
    margin: 0 auto;
}

.reflection-text {
    font-size: 1.125rem;
    line-height: 1.8;
    margin-bottom: var(--spacing-md);
}

.reflection-quote {
    background: rgba(255, 255, 255, 0.1);
    padding: var(--spacing-md);
    border-radius: 8px;
    margin: var(--spacing-lg) 0;
    border-left: 4px solid var(--color-chaos-light);
}

.reflection-quote blockquote {
    border-left: none;
    padding-left: 0;
    color: white;
    font-size: 1.25rem;
    font-style: italic;
}

.reflection-signature {
    text-align: center;
    font-style: italic;
    font-size: 1.125rem;
    margin-top: var(--spacing-lg);
    opacity: 0.8;
}

/* ===================================
   Footer
   =================================== */

footer {
    background: var(--color-bg-dark);
    color: var(--color-text-light);
    padding: var(--spacing-md) 0;
    text-align: center;
}

footer p {
    margin-bottom: var(--spacing-xs);
}

.footer-note {
    font-size: 0.875rem;
    opacity: 0.7;
}

/* ===================================
   Responsive Design - Mobile First
   =================================== */

/* Small devices (landscape phones, 576px and up) */
@media (min-width: 576px) {
    .visual-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .derivatives-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* Medium devices (tablets, 768px and up) */
@media (min-width: 768px) {
    .definition-content {
        grid-template-columns: 1fr 1fr;
    }

    .definition-content.reverse {
        direction: rtl;
    }

    .definition-content.reverse > * {
        direction: ltr;
    }

    .context-list {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* Large devices (desktops, 992px and up) */
@media (min-width: 992px) {
    .visual-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .derivatives-grid {
        grid-template-columns: repeat(3, 1fr);
    }

    .context-list {
        grid-template-columns: repeat(3, 1fr);
    }
}

/* Extra large devices (large desktops, 1200px and up) */
@media (min-width: 1200px) {
    .container {
        padding: 0 var(--spacing-md);
    }
}

/* ===================================
   Print Styles
   =================================== */

@media print {
    nav,
    footer {
        display: none;
    }

    .hero-section {
        min-height: auto;
        page-break-after: always;
    }

    section {
        page-break-inside: avoid;
    }

    img {
        max-width: 100%;
        page-break-inside: avoid;
    }
}


/* ===================================
   Reduced Motion
   =================================== */

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

.veritasium-section { padding: 4rem 0; }
.veritasium-frame { margin: 2rem 0; border-radius: 12px; overflow: hidden; }
.veritasium-note { margin-top: 1.5rem; opacity: 0.9; font-style: italic; }

.simulation-section { padding: 4rem 0; }
.geogebra-frame { margin-top: 1.5rem; border-radius: 12px; overflow: hidden; }
.simulation-note { margin-top: 1.5rem; opacity: 0.9; }

.embed {
    width: 100%;
    max-width: 100%;
    overflow: hidden;
    border-radius: 12px;
}

.embed iframe {
    width: 100%;
    height: 100%;
    display: block;
}

/* YouTube: 16:9 */
.embed-video {
    aspect-ratio: 16 / 9;
}

/* GeoGebra: taller, interactive */
.embed-ggb {
    aspect-ratio: 4 / 3;
}

/* Mobile tweak */
@media (max-width: 480px) {
    .embed-ggb {
        aspect-ratio: 1 / 1;
    }
}