/* CSS Reset & Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    /* Primary Brand Colors */
    --natural: #F4E9D5;
    --white: #FFFFFF;
    --black: #1A1A1A;

    /* Natural Secondary */
    --fire-red: #ED5D29;
    --dusk-pink: #F8C6C0;
    --land-green: #7F9C7E;
    --ocean-blue: #2E52A0;
    --sky-blue: #C1E1DC;
    --sand-yellow: #D8B76A;
    --stone-cream: #CEC0A3;

    /* Digital Supporting */
    --digital-fire-red: #FF3300;
    --digital-dusk-pink: #FFCDFF;
    --digital-land-green: #4F994C;
    --digital-ocean-blue: #0A67DE;
    --digital-sky-blue: #ACEFFF;
    --digital-yellow: #FFCA00;
    --digital-stone: #837052;

    /* Semantic Colors */
    --text-primary: var(--black);
    --text-secondary: #4A4A4A;
    --text-light: #6B6B6B;
    --bg-primary: var(--white);
    --bg-secondary: var(--natural);
    --bg-tertiary: var(--sky-blue);
    --accent-primary: var(--digital-fire-red);
    --accent-secondary: var(--digital-ocean-blue);
    --border-color: var(--stone-cream);

    /* Shadows */
    --shadow-sm: 0 1px 3px 0 rgba(26, 26, 26, 0.08);
    --shadow-md: 0 4px 6px -1px rgba(26, 26, 26, 0.12);
    --shadow-lg: 0 10px 20px -3px rgba(26, 26, 26, 0.15);

    /* Typography */
    --font-display: 'Instrument Serif', Georgia, serif;
    --font-body: 'Space Grotesk', -apple-system, BlinkMacSystemFont, sans-serif;
    --font-mono: 'Roboto Mono', 'Courier New', monospace;
}

html {
    scroll-behavior: smooth;
    /* Base font size for rem calculations - scales with user preferences */
    font-size: 100%;
}

body {
    font-family: var(--font-body);
    line-height: 1.6;
    color: var(--text-primary);
    background: var(--bg-primary);
    overflow-x: hidden;
    letter-spacing: -0.02em;
    /* Ensure minimum font size on mobile */
    font-size: clamp(0.9375rem, 0.875rem + 0.3vw, 1rem);
}

/* Responsive images and media by default */
img, video, iframe, embed, object {
    max-width: 100%;
    height: auto;
    display: block;
}

/* Prevent layout shift with aspect ratio for images */
img {
    height: auto;
}

/* Responsive tables */
table {
    width: 100%;
    overflow-x: auto;
    display: block;
}

/* Utility: Prevent text overflow */
.text-balance {
    text-wrap: balance;
}

/* Ensure long words don't break layout */
p, li, h1, h2, h3, h4, h5, h6 {
    overflow-wrap: break-word;
    word-wrap: break-word;
    hyphens: auto;
}

/* Typography */
h1, h2, h3, h4, h5, h6 {
    font-weight: 600;
    line-height: 1.2;
    margin-bottom: 1rem;
    color: var(--text-primary);
    letter-spacing: -0.01em;
}

h1 {
    font-family: var(--font-display);
    /* Fluid typography: min 2rem, max 3rem */
    font-size: clamp(2rem, 1.5rem + 2.5vw, 3rem);
    font-weight: 400;
    letter-spacing: -0.01em;
    line-height: 1.1;
}

h2 {
    /* Fluid typography: min 1.5rem, max 2rem */
    font-size: clamp(1.5rem, 1.25rem + 1.25vw, 2rem);
    margin-top: 2rem;
    font-weight: 600;
}

h3 {
    /* Fluid typography: min 1.25rem, max 1.5rem */
    font-size: clamp(1.25rem, 1.125rem + 0.625vw, 1.5rem);
    margin-top: 1.5rem;
    font-weight: 600;
}

h4 {
    /* Fluid typography: min 1.125rem, max 1.25rem */
    font-size: clamp(1.125rem, 1.0625rem + 0.3125vw, 1.25rem);
    margin-top: 1.25rem;
    font-weight: 600;
}

p {
    margin-bottom: 1rem;
    line-height: 1.8;
}

a {
    color: var(--accent-secondary);
    text-decoration: none;
    transition: color 0.2s ease, opacity 0.2s ease;
}

a:hover {
    color: var(--ocean-blue);
    text-decoration: underline;
}

strong {
    font-weight: 600;
    color: var(--text-primary);
}

em {
    font-style: italic;
    color: var(--text-secondary);
}

code {
    background: var(--natural);
    padding: 0.2rem 0.5rem;
    border-radius: 0.25rem;
    font-family: var(--font-mono);
    font-size: 0.9em;
    color: var(--ocean-blue);
    border: 1px solid var(--stone-cream);
}

/* Header & Navigation */
header {
    position: sticky;
    top: 0;
    z-index: 1000;
    background: rgba(255, 255, 255, 0.98);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border-color);
    box-shadow: var(--shadow-sm);
}

.header-content {
    max-width: 1200px;
    margin: 0 auto;
    /* Responsive padding using clamp */
    padding: clamp(0.75rem, 0.5rem + 1vw, 1.25rem) clamp(1rem, 0.5rem + 2vw, 2rem);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.logo {
    font-size: clamp(1.25rem, 1.125rem + 0.625vw, 1.5rem);
    font-weight: 700;
    color: var(--black);
    font-family: var(--font-display);
    letter-spacing: -0.02em;
}

nav ul {
    display: flex;
    list-style: none;
    gap: clamp(1rem, 0.5rem + 2vw, 2.5rem);
}

nav a {
    color: var(--text-primary);
    font-weight: 500;
    transition: color 0.2s ease;
    text-decoration: none;
    font-size: clamp(0.875rem, 0.8125rem + 0.3125vw, 0.95rem);
    /* Ensure adequate touch target size */
    padding: 0.5rem 0.25rem;
    display: inline-block;
}

nav a:hover,
nav a.active {
    color: var(--accent-secondary);
    text-decoration: none;
}

.mobile-menu-toggle {
    display: none;
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-primary);
    /* Ensure minimum 44x44px touch target */
    min-width: 44px;
    min-height: 44px;
    padding: 0.5rem;
    margin-left: auto;
}

/* Hero Section */
.hero {
    background: var(--natural);
    color: var(--black);
    /* Responsive padding using clamp */
    padding: clamp(3rem, 2rem + 5vw, 8rem) clamp(1rem, 0.5rem + 2vw, 2rem);
    text-align: center;
    position: relative;
    overflow: hidden;
}

.hero::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background:
        radial-gradient(circle at 20% 50%, rgba(237, 93, 41, 0.08) 0%, transparent 50%),
        radial-gradient(circle at 80% 50%, rgba(46, 82, 160, 0.08) 0%, transparent 50%);
    pointer-events: none;
}

.hero-content {
    max-width: 900px;
    margin: 0 auto;
    position: relative;
    z-index: 1;
}

.hero h1 {
    color: var(--black);
    /* Fluid typography for hero heading: min 2rem, max 4rem */
    font-size: clamp(2rem, 1.25rem + 3.75vw, 4rem);
    margin-bottom: 1.5rem;
    animation: fadeInUp 0.8s ease;
    font-family: var(--font-display);
    font-weight: 400;
    line-height: 1.1;
    /* Allow wrapping on small screens */
    white-space: normal;
    /* Prevent orphaned words */
    text-wrap: balance;
}

.hero .tagline {
    /* Fluid typography: min 1.125rem, max 1.5rem */
    font-size: clamp(1.125rem, 1rem + 0.625vw, 1.5rem);
    margin-bottom: 1rem;
    opacity: 0.85;
    animation: fadeInUp 0.8s ease 0.2s backwards;
    font-weight: 500;
    color: var(--text-secondary);
}

.hero .subtitle {
    /* Fluid typography: min 0.9375rem, max 1.1rem */
    font-size: clamp(0.9375rem, 0.875rem + 0.3125vw, 1.1rem);
    opacity: 0.75;
    max-width: 700px;
    margin: 0 auto clamp(2rem, 1.5rem + 2vw, 3rem);
    animation: fadeInUp 0.8s ease 0.4s backwards;
    line-height: 1.7;
    color: var(--text-secondary);
}

/* Desktop: display subtitle in one line */
@media (min-width: 48em) {
    .hero .subtitle {
        white-space: nowrap;
    }
}

.hero-cta {
    display: inline-block;
    background: var(--accent-primary);
    color: var(--white);
    /* Responsive padding */
    padding: clamp(0.875rem, 0.75rem + 0.625vw, 1.125rem) clamp(1.5rem, 1rem + 2vw, 2.5rem);
    border-radius: 0.375rem;
    font-weight: 600;
    box-shadow: var(--shadow-lg);
    transition: transform 0.2s ease, box-shadow 0.2s ease, background-color 0.2s ease;
    animation: fadeInUp 0.8s ease 0.6s backwards;
    font-size: clamp(0.9375rem, 0.875rem + 0.3125vw, 1rem);
    /* Ensure minimum touch target */
    min-height: 44px;
}

.hero-cta:hover {
    transform: translateY(-2px);
    box-shadow: 0 20px 30px -5px rgba(255, 51, 0, 0.3);
    text-decoration: none;
    background: var(--fire-red);
    color: var(--white);
}

/* Main Container */
.container {
    max-width: 1400px;
    margin: 0 auto;
    /* Responsive padding */
    padding: clamp(2rem, 1.5rem + 2vw, 4rem) clamp(1rem, 0.5rem + 2vw, 2rem);
    display: grid;
    /* Flexible sidebar width using minmax */
    grid-template-columns: minmax(240px, 280px) 1fr;
    gap: clamp(2rem, 1.5rem + 2vw, 4rem);
}

/* Sidebar Glossary */
.glossary-sidebar {
    position: sticky;
    top: 120px;
    align-self: start;
    background: var(--stone-cream);
    /* Responsive padding */
    padding: clamp(1.25rem, 1rem + 1vw, 2rem);
    border-radius: 0.5rem;
    max-height: calc(100vh - 140px);
    overflow-y: auto;
    box-shadow: var(--shadow-sm);
}

.glossary-sidebar h3 {
    font-size: 1.1rem;
    margin-bottom: 1.5rem;
    color: var(--black);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-size: 0.85rem;
}

.glossary-item {
    margin-bottom: 1.25rem;
    padding-bottom: 1.25rem;
    border-bottom: 1px solid rgba(26, 26, 26, 0.15);
}

.glossary-item:last-child {
    border-bottom: none;
}

.glossary-term {
    font-weight: 600;
    color: var(--black);
    font-size: 0.9rem;
    font-family: var(--font-mono);
    margin-bottom: 0.25rem;
}

.glossary-definition {
    font-size: 0.85rem;
    color: var(--text-secondary);
    line-height: 1.6;
}

/* Main Content */
.main-content {
    min-width: 0;
}

section {
    margin-bottom: 5rem;
    animation: fadeIn 0.6s ease;
}

section:target {
    scroll-margin-top: 120px;
}

.section-header {
    padding-bottom: 1.25rem;
    border-bottom: 3px solid var(--black);
    margin-bottom: 2.5rem;
}

.section-number {
    color: var(--fire-red);
    font-weight: 700;
    font-size: 0.9rem;
    font-family: var(--font-mono);
    display: block;
    margin-bottom: 0.5rem;
}

.section-header h2 {
    margin-top: 0;
    margin-bottom: 0;
}

/* Highlight Boxes */
.highlight-box {
    background: var(--natural);
    border-left: 4px solid var(--fire-red);
    /* Responsive padding */
    padding: clamp(1.25rem, 1rem + 1vw, 2rem);
    margin: clamp(1.5rem, 1rem + 2vw, 2.5rem) 0;
    border-radius: 0.25rem;
    box-shadow: var(--shadow-sm);
}

.highlight-box h4 {
    color: var(--fire-red);
    margin-top: 0;
    font-weight: 700;
}

.highlight-box p:last-child {
    margin-bottom: 0;
}

/* Lists */
ul, ol {
    margin: 1.5rem 0 1.5rem 2rem;
}

li {
    margin-bottom: 0.75rem;
    line-height: 1.8;
}

li strong {
    color: var(--black);
}

/* Case Studies */
.case-study {
    background: var(--white);
    border: 2px solid var(--stone-cream);
    border-radius: 0.5rem;
    /* Responsive padding */
    padding: clamp(1.5rem, 1rem + 2vw, 2.5rem);
    margin: clamp(1.5rem, 1rem + 2vw, 2.5rem) 0;
    box-shadow: var(--shadow-md);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.case-study:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

.case-study h4 {
    color: var(--ocean-blue);
    margin-top: 0;
    font-weight: 700;
    font-size: 1.35rem;
    margin-bottom: 1rem;
}

.case-study p:last-child {
    margin-bottom: 0;
}

/* FAQ Section */
.faq-item {
    margin-bottom: 1rem;
    border: 2px solid var(--border-color);
    border-radius: 0.5rem;
    overflow: hidden;
    transition: border-color 0.2s ease;
}

.faq-item:hover {
    border-color: var(--digital-ocean-blue);
}

.faq-question {
    background: var(--natural);
    /* Responsive padding with minimum touch target */
    padding: clamp(1rem, 0.875rem + 0.625vw, 1.25rem) clamp(1.25rem, 1rem + 1vw, 1.75rem);
    cursor: pointer;
    font-weight: 600;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: background 0.2s ease;
    color: var(--black);
    /* Ensure minimum 44px touch target */
    min-height: 44px;
}

.faq-question:hover {
    background: var(--sand-yellow);
}

.faq-question::after {
    content: '+';
    font-size: 1.75rem;
    color: var(--fire-red);
    transition: transform 0.3s ease;
    font-weight: 400;
}

.faq-answer {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease;
}

.faq-answer-content {
    /* Responsive padding */
    padding: clamp(1.25rem, 1rem + 1vw, 1.75rem);
    background: var(--white);
}

.faq-answer-content p:last-child,
.faq-answer-content ul:last-child {
    margin-bottom: 0;
}

.faq-item.active .faq-question::after {
    transform: rotate(45deg);
}

.faq-item.active .faq-answer {
    max-height: 1500px;
}

/* Footer */
footer {
    background: var(--black);
    color: var(--natural);
    /* Responsive padding */
    padding: clamp(2.5rem, 2rem + 2vw, 4rem) clamp(1rem, 0.5rem + 2vw, 2rem);
    margin-top: clamp(3rem, 2rem + 4vw, 6rem);
}

.footer-content {
    max-width: 1200px;
    margin: 0 auto;
    text-align: center;
}

.footer-links {
    display: flex;
    justify-content: center;
    gap: clamp(1.25rem, 1rem + 1.5vw, 2.5rem);
    margin-bottom: 2rem;
    flex-wrap: wrap;
}

.footer-links a {
    color: var(--natural);
    opacity: 0.9;
    transition: opacity 0.2s ease, color 0.2s ease;
    font-weight: 500;
    /* Ensure adequate touch target */
    padding: 0.5rem 0.25rem;
    display: inline-block;
}

.footer-links a:hover {
    opacity: 1;
    color: var(--white);
    text-decoration: none;
}

footer p {
    color: var(--natural);
    opacity: 0.8;
}

/* Animations */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(30px); }
    to { opacity: 1; transform: translateY(0); }
}

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

/* Print Styles */
@media print {
    header, footer, .glossary-sidebar, .hero-cta {
        display: none;
    }

    .container {
        grid-template-columns: 1fr;
    }

    section {
        page-break-inside: avoid;
    }

    a {
        text-decoration: none;
        color: var(--text-primary);
    }

    .hero {
        background: white;
        padding: 2rem;
    }
}

/* Responsive Design - Mobile-First Enhancements */

/* Ultra-wide screens (> 1600px) - prevent content from stretching too much */
@media (min-width: 100em) {
    .container {
        max-width: 1600px;
    }

    .hero-content {
        max-width: 1000px;
    }

    body {
        font-size: 1.0625rem;
    }
}

/* Large tablets and small desktops (900px-1200px) */
@media (min-width: 56.25em) and (max-width: 75em) {
    .container {
        grid-template-columns: 220px 1fr;
        gap: 2.5rem;
    }
}

/* Tablets in landscape (768px-899px) */
@media (min-width: 48em) and (max-width: 56.24em) {
    .container {
        grid-template-columns: 200px 1fr;
        gap: 2rem;
    }

    nav ul {
        gap: 1.5rem;
    }
}

/* Tablets and below (< 768px) */
@media (max-width: 47.99em) {
    .container {
        grid-template-columns: 1fr;
        gap: 2rem;
    }

    .glossary-sidebar {
        display: none;
    }

    /* Mobile navigation */
    nav {
        position: static;
    }

    nav ul {
        position: fixed;
        top: 75px;
        left: -100%;
        width: 100%;
        height: calc(100vh - 75px);
        background: var(--white);
        flex-direction: column;
        padding: 2rem;
        box-shadow: var(--shadow-lg);
        transition: left 0.3s ease;
        gap: 0;
        border-top: 2px solid var(--border-color);
        overflow-y: auto;
        z-index: 999;
        margin: 0;
    }

    nav ul li {
        width: 100%;
        border-bottom: 1px solid var(--border-color);
    }

    nav ul li:last-child {
        border-bottom: none;
    }

    nav a {
        width: 100%;
        padding: 1rem;
        /* Ensure minimum 44px touch target */
        min-height: 44px;
        display: flex;
        align-items: center;
    }

    nav ul.active {
        left: 0;
    }

    .mobile-menu-toggle {
        display: block;
    }

    /* Improve readability on smaller screens */
    section {
        margin-bottom: 3rem;
    }
}

/* Small mobile devices (< 640px) */
@media (max-width: 39.99em) {
    /* Ultra-compact adjustments for very small screens */
    body {
        font-size: 0.9375rem;
    }

    .section-header {
        padding-bottom: 1rem;
        margin-bottom: 1.5rem;
    }

    /* Optimize images and media for mobile */
    img {
        max-width: 100%;
        height: auto;
    }

    /* Prevent overflow on small screens */
    pre, code {
        word-wrap: break-word;
        overflow-wrap: break-word;
    }

    /* Reduce list indentation on mobile */
    ul, ol {
        margin-left: 1.5rem;
    }
}

/* Extra small devices (< 375px) */
@media (max-width: 23.43em) {
    /* Further optimize for very small screens */
    .footer-links {
        flex-direction: column;
        gap: 0.75rem;
    }

    .faq-question {
        font-size: 0.9375rem;
    }
}

/* Landscape orientation optimizations */
@media (max-height: 600px) and (orientation: landscape) {
    .hero {
        padding-top: 2rem;
        padding-bottom: 2rem;
    }

    nav ul {
        height: auto;
        max-height: calc(100vh - 75px);
    }
}

/* Accessibility */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

:focus-visible {
    outline: 2px solid var(--accent-secondary);
    outline-offset: 2px;
}

/* Scrollbar Styling */
.glossary-sidebar::-webkit-scrollbar {
    width: 6px;
}

.glossary-sidebar::-webkit-scrollbar-track {
    background: rgba(26, 26, 26, 0.1);
    border-radius: 3px;
}

.glossary-sidebar::-webkit-scrollbar-thumb {
    background: var(--digital-stone);
    border-radius: 3px;
}

.glossary-sidebar::-webkit-scrollbar-thumb:hover {
    background: var(--ocean-blue);
}

/* Reduce motion for users who prefer it */
@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;
    }
}

/* Hover states only for devices that support hover */
@media (hover: hover) and (pointer: fine) {
    .hero-cta:hover {
        transform: translateY(-2px);
    }

    .case-study:hover {
        transform: translateY(-2px);
    }

    .faq-question:hover {
        background: var(--sand-yellow);
    }
}

/* Improved touch interaction for touch devices */
@media (hover: none) and (pointer: coarse) {
    /* Remove hover animations on touch devices */
    .hero-cta:hover {
        transform: none;
    }

    .case-study:hover {
        transform: none;
    }

    /* Add active states instead */
    .hero-cta:active {
        transform: scale(0.98);
    }

    nav a:active,
    .faq-question:active {
        background: var(--sand-yellow);
    }
}
