/* ═══════════════════════════════════════════════════════════
   RSMS-Site Design System — Cognitive Load Estimator
   Stack: Vanilla CSS | System Fonts | Zero Dependencies
   ═══════════════════════════════════════════════════════════ */

/* ── §1: Design Tokens ──────────────────────────────────── */
:root {
    /* Spacing Scale */
    --space-1: 0.25rem;
    --space-2: 0.5rem;
    --space-3: 0.75rem;
    --space-4: 1rem;
    --space-6: 1.5rem;
    --space-8: 2rem;
    --space-12: 3rem;
    --space-16: 4rem;
    --space-24: 6rem;
    --space-32: 8rem;

    /* Typography Scale */
    --text-xs: clamp(0.7rem, 0.65rem + 0.2vw, 0.75rem);
    --text-sm: clamp(0.8rem, 0.75rem + 0.2vw, 0.875rem);
    --text-base: clamp(0.95rem, 0.9rem + 0.2vw, 1.05rem);
    --text-lg: clamp(1.15rem, 1rem + 0.5vw, 1.3rem);
    --text-xl: clamp(1.5rem, 1.2rem + 1.5vw, 2.25rem);
    --text-2xl: clamp(2rem, 1.5rem + 2.5vw, 3.5rem);
    --text-display: clamp(2.5rem, 1.5rem + 5vw, 5rem);

    --leading-tight: 1.1;
    --leading-normal: 1.6;
    --leading-relaxed: 1.8;

    /* Color System — Dark First */
    --surface-base: hsl(220 15% 8%);
    --surface-raised: hsl(220 14% 12%);
    --surface-overlay: hsl(220 13% 16%);

    --text-primary: hsl(220 10% 93%);
    --text-secondary: hsl(220 8% 60%);
    --text-muted: hsl(220 6% 40%);

    --accent: hsl(160 65% 45%);
    --accent-hover: hsl(160 65% 52%);
    --accent-subtle: hsl(160 65% 45% / 0.12);

    --border: hsl(220 10% 20%);
    --border-subtle: hsl(220 10% 15%);

    /* Semantic Status Colors */
    --status-low: hsl(160 65% 45%);
    --status-medium: hsl(45 90% 55%);
    --status-high: hsl(0 75% 55%);

    /* Motion Tokens */
    --duration-fast: 150ms;
    --duration-normal: 250ms;
    --duration-slow: 400ms;
    --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
    --ease-in-out: cubic-bezier(0.65, 0, 0.35, 1);

    /* Layout */
    --content-width: 72rem;
    --content-narrow: 48rem;
    --nav-height: 3.5rem;
}

/* ── §2: Reset ──────────────────────────────────────────── */
*,
*::before,
*::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    font-size: 100%;
    -webkit-text-size-adjust: 100%;
    scroll-behavior: smooth;
}

body {
    font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
    font-size: var(--text-base);
    line-height: var(--leading-normal);
    color: var(--text-primary);
    background-color: var(--surface-base);
    min-height: 100dvh;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Subtle grid background for depth */
body::before {
    content: '';
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: -1;
    background-image:
        linear-gradient(hsl(220 10% 20% / 0.3) 1px, transparent 1px),
        linear-gradient(90deg, hsl(220 10% 20% / 0.3) 1px, transparent 1px);
    background-size: 48px 48px;
}

/* Hide decorative pseudo-elements on mobile — position:fixed
   with z-index:-1 renders unreliably on mobile browsers */
@media (max-width: 768px) {
    body::before,
    body::after {
        display: none;
    }
}

/* Top radial glow */
body::after {
    content: '';
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: -1;
    background: radial-gradient(
        ellipse 60% 30% at 50% 0%,
        hsl(160 40% 15% / 0.3),
        transparent
    );
}

img { max-width: 100%; display: block; }
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }
ul, ol { list-style: none; }

h1, h2, h3, h4 {
    line-height: var(--leading-tight);
    color: var(--text-primary);
    letter-spacing: -0.02em;
}

h1 { font-size: var(--text-2xl); font-weight: 800; }
h2 { font-size: var(--text-xl); font-weight: 700; }
h3 { font-size: var(--text-lg); font-weight: 600; }

/* Focus styles */
:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* ── §3: Layout ─────────────────────────────────────────── */
.page-wrapper {
    display: flex;
    flex-direction: column;
    min-height: 100dvh;
}

.container {
    width: 100%;
    max-width: var(--content-width);
    margin-inline: auto;
    padding-inline: var(--space-6);
}

.container--narrow {
    max-width: var(--content-narrow);
}

main {
    flex: 1;
    padding-block: var(--space-12);
}

/* ── §4: Navigation ─────────────────────────────────────── */
.site-nav {
    position: sticky;
    top: 0;
    z-index: 100;
    height: var(--nav-height);
    background: hsl(220 15% 8% / 0.92);
    border-bottom: 1px solid var(--border-subtle);
}

@supports (backdrop-filter: blur(1px)) {
    .site-nav {
        background: hsl(220 15% 8% / 0.7);
        backdrop-filter: blur(16px) saturate(1.3);
        -webkit-backdrop-filter: blur(16px) saturate(1.3);
    }
}

.site-nav .container {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 100%;
}

.nav-logo {
    font-size: var(--text-sm);
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.01em;
    white-space: nowrap;
}

.nav-logo span {
    color: var(--accent);
}

.nav-links {
    display: flex;
    align-items: center;
    gap: var(--space-1);
}

.nav-links a {
    font-size: var(--text-sm);
    font-weight: 500;
    color: var(--text-secondary);
    padding: var(--space-1) var(--space-3);
    border-radius: 4px;
    transition: color var(--duration-fast) ease,
                background var(--duration-fast) ease;
}

.nav-links a:hover,
.nav-links a[aria-current="page"] {
    color: var(--text-primary);
    background: var(--surface-overlay);
}

.nav-links a[aria-current="page"] {
    color: var(--accent);
}

/* Mobile nav toggle */
.nav-toggle {
    display: none;
    background: none;
    border: none;
    color: var(--text-primary);
    cursor: pointer;
    padding: var(--space-2);
}

.nav-toggle svg {
    width: 24px;
    height: 24px;
    stroke: currentColor;
    stroke-width: 2;
    fill: none;
}

@media (max-width: 768px) {
    .nav-toggle {
        display: block;
    }

    .nav-links {
        display: none;
        position: absolute;
        top: var(--nav-height);
        left: 0;
        right: 0;
        flex-direction: column;
        background: var(--surface-raised);
        border-bottom: 1px solid var(--border);
        padding: var(--space-4);
        gap: var(--space-1);
    }

    .nav-links.is-open {
        display: flex;
    }

    .nav-links a {
        padding: var(--space-3) var(--space-4);
        width: 100%;
    }
}

/* ── §5: Footer ─────────────────────────────────────────── */
.site-footer {
    padding-block: var(--space-8);
    border-top: 1px solid var(--border-subtle);
    background: var(--surface-raised);
}

.footer-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: var(--space-4);
}

.footer-links {
    display: flex;
    gap: var(--space-6);
}

.footer-links a {
    font-size: var(--text-sm);
    color: var(--text-secondary);
    transition: color var(--duration-fast) ease;
}

.footer-links a:hover {
    color: var(--text-primary);
}

.footer-copy {
    font-size: var(--text-xs);
    color: var(--text-muted);
}

@media (max-width: 768px) {
    .footer-content {
        flex-direction: column;
        text-align: center;
    }
}

/* ── §6: Buttons ────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    font-size: var(--text-sm);
    font-weight: 600;
    padding: var(--space-3) var(--space-6);
    border-radius: 6px;
    border: none;
    cursor: pointer;
    transition: transform var(--duration-fast) var(--ease-out),
                background var(--duration-fast) ease,
                opacity var(--duration-fast) ease;
    text-decoration: none;
}

.btn:active {
    transform: scale(0.97);
}

.btn-primary {
    background: var(--accent);
    color: hsl(220 15% 8%);
}

.btn-primary:hover {
    background: var(--accent-hover);
    color: hsl(220 15% 8%);
}

.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--border);
}

.btn-ghost:hover {
    background: var(--surface-overlay);
    color: var(--text-primary);
}

.btn-large {
    font-size: var(--text-base);
    padding: var(--space-4) var(--space-8);
}

/* ── §7: Cards ──────────────────────────────────────────── */
.card {
    padding: var(--space-6);
    background: var(--surface-raised);
    border-radius: 2px;
    border-top: 1px solid hsl(0 0% 100% / 0.06);
    transition: background var(--duration-fast) ease;
}

.card:hover {
    background: var(--surface-overlay);
}

.card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 300px), 1fr));
    gap: var(--space-6);
}

.card-icon {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--accent-subtle);
    color: var(--accent);
    border-radius: 8px;
    margin-bottom: var(--space-4);
    font-size: var(--text-lg);
}

.card-title {
    font-size: var(--text-lg);
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: var(--space-2);
}

.card-description {
    font-size: var(--text-sm);
    color: var(--text-secondary);
    line-height: var(--leading-normal);
}

/* ── §8: Badge ──────────────────────────────────────────── */
.badge {
    display: inline-flex;
    align-items: center;
    font-size: var(--text-xs);
    font-weight: 600;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    padding: var(--space-1) var(--space-3);
    border-radius: 9999px;
}

.badge--low {
    background: hsl(160 65% 45% / 0.15);
    color: var(--status-low);
}

.badge--medium {
    background: hsl(45 90% 55% / 0.15);
    color: var(--status-medium);
}

.badge--high {
    background: hsl(0 75% 55% / 0.15);
    color: var(--status-high);
}

/* ── §9: Forms ──────────────────────────────────────────── */
.form-group {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
}

.form-label {
    font-size: var(--text-sm);
    font-weight: 500;
    color: var(--text-secondary);
}

.form-input,
.form-select,
.form-textarea {
    font-family: inherit;
    font-size: var(--text-base);
    color: var(--text-primary);
    background: var(--surface-base);
    border: 1px solid var(--border);
    padding: var(--space-3) var(--space-4);
    border-radius: 6px;
    transition: border-color var(--duration-fast) ease;
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-subtle);
}

.form-input::placeholder,
.form-textarea::placeholder {
    color: var(--text-muted);
}

.form-textarea {
    resize: vertical;
    min-height: 120px;
}

.form-select {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23666' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right var(--space-4) center;
    padding-right: var(--space-8);
    cursor: pointer;
}

.form-hint {
    font-size: var(--text-xs);
    color: var(--text-muted);
}

.form-error {
    font-size: var(--text-xs);
    color: var(--status-high);
}

/* ── §10: Tool Page ─────────────────────────────────────── */
.tool-section {
    max-width: var(--content-narrow);
    margin-inline: auto;
}

.tool-inputs {
    display: grid;
    gap: var(--space-6);
    margin-block: var(--space-8);
}

.tool-result {
    display: none;
    padding: var(--space-8);
    background: var(--surface-raised);
    border-radius: 2px;
    border-top: 1px solid hsl(0 0% 100% / 0.06);
    margin-top: var(--space-8);
}

.tool-result.is-visible {
    display: block;
}

.result-score {
    font-size: var(--text-2xl);
    font-weight: 800;
    margin-bottom: var(--space-2);
}

.result-classification {
    margin-bottom: var(--space-6);
}

.result-explanation {
    padding-top: var(--space-6);
    border-top: 1px solid var(--border-subtle);
}

.result-explanation h3 {
    margin-bottom: var(--space-4);
}

.explanation-item {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    padding: var(--space-2) 0;
    font-size: var(--text-sm);
    color: var(--text-secondary);
}

.explanation-item span:last-child {
    font-weight: 600;
    color: var(--text-primary);
    font-variant-numeric: tabular-nums;
}

/* ── §11: Hero Section ──────────────────────────────────── */
.hero {
    min-height: 70vh;
    display: grid;
    place-items: center;
    padding: var(--space-16) var(--space-6);
    text-align: center;
}

.hero-content {
    max-width: 50ch;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-6);
}

.hero-eyebrow {
    font-size: var(--text-xs);
    font-weight: 500;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--accent);
}

.hero-title {
    font-size: var(--text-display);
    font-weight: 800;
    line-height: var(--leading-tight);
    letter-spacing: -0.03em;
    color: var(--text-primary);
}

.hero-description {
    font-size: var(--text-lg);
    color: var(--text-secondary);
    line-height: var(--leading-normal);
    max-width: 40ch;
}

.hero-actions {
    display: flex;
    gap: var(--space-4);
    flex-wrap: wrap;
    justify-content: center;
}

/* ── §12: Content Sections ──────────────────────────────── */
.section {
    padding-block: var(--space-12);
}

.section-header {
    text-align: center;
    margin-bottom: var(--space-8);
}

.section-header p {
    color: var(--text-secondary);
    margin-top: var(--space-3);
    max-width: 50ch;
    margin-inline: auto;
}

/* ── §13: FAQ ───────────────────────────────────────────── */
.faq-list {
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
    max-width: var(--content-narrow);
    margin-inline: auto;
}

.faq-item {
    background: var(--surface-raised);
    border-radius: 2px;
    border-top: 1px solid hsl(0 0% 100% / 0.04);
    overflow: hidden;
}

.faq-question {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: var(--space-4) var(--space-6);
    background: none;
    border: none;
    color: var(--text-primary);
    font-family: inherit;
    font-size: var(--text-base);
    font-weight: 600;
    text-align: left;
    cursor: pointer;
    transition: background var(--duration-fast) ease;
}

.faq-question:hover {
    background: var(--surface-overlay);
}

.faq-question::after {
    content: '+';
    font-size: var(--text-lg);
    font-weight: 300;
    color: var(--text-muted);
    transition: transform var(--duration-normal) var(--ease-out);
    flex-shrink: 0;
    margin-left: var(--space-4);
}

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

.faq-answer {
    max-height: 0;
    overflow: hidden;
    transition: max-height var(--duration-normal) var(--ease-out);
}

.faq-answer-inner {
    padding: 0 var(--space-6) var(--space-6);
    font-size: var(--text-sm);
    color: var(--text-secondary);
    line-height: var(--leading-normal);
}

/* ── §14: Contact Form ──────────────────────────────────── */
.contact-form {
    display: grid;
    gap: var(--space-6);
    max-width: var(--content-narrow);
    margin-inline: auto;
}

.contact-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-6);
}

@media (max-width: 768px) {
    .contact-grid {
        grid-template-columns: 1fr;
    }
}

.form-success {
    display: none;
    padding: var(--space-6);
    background: var(--accent-subtle);
    border-radius: 6px;
    text-align: center;
    color: var(--accent);
    font-weight: 500;
}

.form-success.is-visible {
    display: block;
}

/* ── §15: Content Pages (Privacy, Terms, About) ─────────── */
.content-page {
    max-width: var(--content-narrow);
    margin-inline: auto;
}

.content-page h2 {
    margin-top: var(--space-8);
    margin-bottom: var(--space-4);
    font-size: var(--text-lg);
}

.content-page p {
    color: var(--text-secondary);
    line-height: var(--leading-relaxed);
    margin-bottom: var(--space-4);
}

.content-page ul {
    margin-bottom: var(--space-4);
    padding-left: var(--space-6);
}

.content-page li {
    color: var(--text-secondary);
    line-height: var(--leading-normal);
    margin-bottom: var(--space-2);
    position: relative;
}

.content-page li::before {
    content: '·';
    position: absolute;
    left: calc(-1 * var(--space-4));
    color: var(--accent);
    font-weight: 700;
}

/* ── §16: How It Works ──────────────────────────────────── */
.formula-block {
    background: var(--surface-raised);
    padding: var(--space-6);
    border-radius: 2px;
    border-left: 3px solid var(--accent);
    margin-block: var(--space-6);
    font-family: 'Courier New', Courier, monospace;
    font-size: var(--text-base);
    color: var(--text-primary);
    overflow-x: auto;
}

.variable-table {
    width: 100%;
    border-collapse: collapse;
    margin-block: var(--space-6);
}

.variable-table th,
.variable-table td {
    padding: var(--space-3) var(--space-4);
    text-align: left;
    border-bottom: 1px solid var(--border-subtle);
    font-size: var(--text-sm);
}

.variable-table th {
    color: var(--text-muted);
    font-weight: 500;
    font-size: var(--text-xs);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.variable-table td {
    color: var(--text-secondary);
}

/* Mobile: stack table rows as cards */
@media (max-width: 768px) {
    .variable-table,
    .variable-table thead,
    .variable-table tbody,
    .variable-table tr,
    .variable-table th,
    .variable-table td {
        display: block;
    }

    .variable-table thead {
        position: absolute;
        width: 1px;
        height: 1px;
        overflow: hidden;
        clip: rect(0, 0, 0, 0);
    }

    .variable-table tr {
        background: var(--surface-raised);
        border-radius: 2px;
        padding: var(--space-4);
        margin-bottom: var(--space-4);
        border-bottom: none;
    }

    .variable-table td {
        padding: var(--space-1) 0;
        border-bottom: none;
        display: flex;
        justify-content: space-between;
        align-items: baseline;
        gap: var(--space-3);
    }

    .variable-table td::before {
        content: attr(data-label);
        font-size: var(--text-xs);
        font-weight: 500;
        color: var(--text-muted);
        text-transform: uppercase;
        letter-spacing: 0.05em;
        flex-shrink: 0;
    }
}

.threshold-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 200px), 1fr));
    gap: var(--space-4);
    margin-block: var(--space-6);
}

.threshold-item {
    padding: var(--space-4);
    background: var(--surface-raised);
    border-radius: 2px;
    text-align: center;
}

.threshold-item .threshold-label {
    font-size: var(--text-xs);
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    margin-bottom: var(--space-1);
}

.threshold-item .threshold-value {
    font-size: var(--text-lg);
    font-weight: 700;
    color: var(--text-primary);
}

/* ── §17: Ad Slots (CLS-Safe) ───────────────────────────── */
.ad-slot {
    min-height: 250px;
    contain: layout style;
    background: var(--surface-raised);
    border-radius: 2px;
    margin-block: var(--space-8);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

/* ── §18: Reduced Motion ────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

/* Adaptive: lower-end devices */
@media (max-resolution: 1.5dppx) {
    :root {
        --duration-normal: 0ms;
        --duration-slow: 150ms;
    }

    body::before,
    body::after {
        display: none;
    }
}

/* ── §19: Light Mode ────────────────────────────────────── */
@media (prefers-color-scheme: light) {
    :root {
        --surface-base: hsl(220 15% 97%);
        --surface-raised: hsl(220 14% 100%);
        --surface-overlay: hsl(220 13% 95%);

        --text-primary: hsl(220 15% 10%);
        --text-secondary: hsl(220 8% 45%);
        --text-muted: hsl(220 6% 65%);

        --border: hsl(220 10% 88%);
        --border-subtle: hsl(220 10% 92%);

        --accent: hsl(160 65% 38%);
        --accent-hover: hsl(160 65% 32%);
        --accent-subtle: hsl(160 65% 38% / 0.1);
    }

    .site-nav {
        background: hsl(220 15% 97% / 0.92);
    }

    @supports (backdrop-filter: blur(1px)) {
        .site-nav {
            background: hsl(220 15% 97% / 0.7);
        }
    }

    body::before {
        background-image:
            linear-gradient(hsl(220 10% 88% / 0.4) 1px, transparent 1px),
            linear-gradient(90deg, hsl(220 10% 88% / 0.4) 1px, transparent 1px);
    }

    body::after {
        background: radial-gradient(
            ellipse 60% 30% at 50% 0%,
            hsl(160 40% 90% / 0.4),
            transparent
        );
    }
}

/* ── §20: Print ─────────────────────────────────────────── */
@media print {
    body::before,
    body::after,
    .site-nav,
    .site-footer,
    .ad-slot {
        display: none !important;
    }

    body {
        background: white;
        color: black;
    }
}
