/* ============================================================================
   RESEARCH PAGE — CANONICAL STYLESHEET
   Amir Mohamad Askari · research portfolio
   ----------------------------------------------------------------------------
   Copy this file VERBATIM into every research project folder. Do not edit it
   per project. Every visual difference between pages must come from which
   components the HTML uses — never from changed CSS.

   Column counts are controlled from the HTML with `.cols-N` utility classes.
   Legacy per-project aliases (wheat-metrics, disaster-switcher, lung-switcher…)
   are kept at the bottom of each block so older pages keep rendering.
   ========================================================================== */

/* ===== 1. DESIGN TOKENS ================================================== */
:root {
    --bg: #050508;
    --surface: #0c0d14;
    --surface-card: #121420;
    --border: rgba(255, 255, 255, 0.06);
    --border-hover: rgba(255, 255, 255, 0.12);
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --accent: #6366f1;
    --accent-glow: rgba(99, 102, 241, 0.15);
    --champion: #10b981;
    --champion-glow: rgba(16, 185, 129, 0.1);
    --font-sans: 'Plus Jakarta Sans', -apple-system, sans-serif;
    --font-mono: 'JetBrains Mono', monospace;

    /* Aliases — older pages referenced these names. Defined so they resolve. */
    --accent-green: var(--champion);
    --border-color: var(--border);
}

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

body {
    background-color: var(--bg);
    color: var(--text-primary);
    font-family: var(--font-sans);
    line-height: 1.7;
    -webkit-font-smoothing: antialiased;
    padding-bottom: 60px;
}

[hidden] { display: none !important; }

#scroll-progress {
    position: fixed;
    top: 0; left: 0;
    width: 0%;
    height: 2px;
    background: var(--accent);
    z-index: 9999;
    transition: width 0.1s linear;
}

/* ===== 2. HERO =========================================================== */
.hero-section {
    position: relative;
    max-width: 1200px;
    margin: 0 auto;
    padding: 80px 40px 40px 40px;
}
.hero-accent-blur {
    position: absolute;
    top: 0; left: 50%;
    transform: translateX(-50%);
    width: 600px; height: 250px;
    background: radial-gradient(circle, rgba(99, 102, 241, 0.08) 0%, rgba(0, 0, 0, 0) 70%);
    z-index: -1;
    pointer-events: none;
}
.hero-meta {
    margin-bottom: 20px;
    color: var(--accent);
    font-family: var(--font-mono);
    font-size: 0.8rem;
    font-weight: 600;
    letter-spacing: 3px;
    text-transform: uppercase;
}
h1 {
    max-width: 900px;
    margin-bottom: 20px;
    font-size: 3.5rem;
    font-weight: 800;
    line-height: 1.15;
    letter-spacing: -0.04em;
    background: linear-gradient(180deg, #ffffff 0%, #a5b4fc 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}
.hero-subtitle {
    max-width: 700px;
    margin-bottom: 32px;
    color: var(--text-secondary);
    font-size: 1.25rem;
    font-weight: 400;
}

/* ===== 3. LINK BUTTONS =================================================== */
.btn-group { display: flex; flex-wrap: wrap; align-items: center; gap: 20px; }

.btn-modern-primary {
    display: inline-flex;
    align-items: center;
    gap: 12px;
    padding: 16px 32px;
    border-radius: 8px;
    background: var(--text-primary);
    color: var(--bg);
    font-size: 1.05rem;
    font-weight: 600;
    text-decoration: none;
    transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}
.btn-modern-primary i { font-size: 1.8rem; }
.btn-modern-primary:hover {
    transform: translateY(-2px);
    background: #ffffff;
    box-shadow: 0 12px 30px rgba(255, 255, 255, 0.1);
}

.btn-modern-secondary {
    display: inline-flex;
    align-items: center;
    gap: 12px;
    padding: 16px 28px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.045);
    color: var(--text-primary);
    font-size: 1.05rem;
    font-weight: 600;
    text-decoration: none;
    transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}
.btn-modern-secondary:hover {
    transform: translateY(-2px);
    border-color: var(--border-hover);
    background: rgba(255, 255, 255, 0.07);
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.22);
}

/* ===== 4. LAYOUT ========================================================= */
.main-layout { max-width: 1200px; margin: 0 auto; padding: 0 40px; }

/* ===== 5. SECTION + ON/OFF ACCORDION ===================================== */
.section { position: relative; padding: 50px 0; border-bottom: none; scroll-margin-top: 24px; }
.section::after {
    content: "";
    position: absolute;
    bottom: 0; left: 0;
    width: 0%; height: 1px;
    background: var(--border);
    transition: width 0.8s cubic-bezier(0.16, 1, 0.3, 1);
}
.section.revealed::after { width: 100%; }

.section-collapsible { position: relative; display: block; }

/* Guide bar — injected by script.js above the first collapsible section. */
.accordion-guide {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    margin: 30px 0 4px 0;
    padding: 14px 18px;
    border: 1px solid var(--border);
    border-radius: 18px;
    background: linear-gradient(135deg, rgba(99, 102, 241, 0.10), rgba(255, 255, 255, 0.018) 42%, rgba(16, 185, 129, 0.05));
    color: var(--text-secondary);
    overflow: hidden;
}
.accordion-guide::before {
    content: "";
    position: absolute;
    inset: 0;
    background: radial-gradient(circle at 16% 50%, rgba(99, 102, 241, 0.12), transparent 28%);
    pointer-events: none;
}
.accordion-guide-main,
.accordion-guide-hint { position: relative; z-index: 1; }
.accordion-guide-main {
    display: inline-flex;
    align-items: center;
    gap: 12px;
    color: var(--text-primary);
    font-family: var(--font-mono);
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: 1.5px;
    text-transform: uppercase;
}
.accordion-guide-main i { color: var(--accent); }
.accordion-guide-hint { color: var(--text-secondary); font-size: 0.86rem; }

.section-header {
    position: relative;
    display: grid;
    grid-template-columns: 1fr auto;
    align-items: center;
    gap: 28px;
    padding: 18px 0 18px 24px;
    border-radius: 18px;
    cursor: pointer;
    user-select: none;
    isolation: isolate;
    transition: background 0.24s ease;
}
.section-header::before {
    content: "";
    position: absolute;
    left: 0; top: 16px; bottom: 16px;
    width: 3px;
    border-radius: 999px;
    background: linear-gradient(180deg, var(--accent), rgba(99, 102, 241, 0.18));
    opacity: 0.72;
    box-shadow: 0 0 0 rgba(99, 102, 241, 0);
    transition: opacity 0.24s ease, box-shadow 0.24s ease;
}
.section-header:hover,
.section-header:focus-visible {
    background: linear-gradient(90deg, rgba(99, 102, 241, 0.075), rgba(255, 255, 255, 0.018) 62%, rgba(255, 255, 255, 0));
    outline: none;
}
.section-header:hover::before,
.section-header:focus-visible::before,
.section.expanded .section-header::before {
    opacity: 1;
    box-shadow: 0 0 28px rgba(99, 102, 241, 0.42);
}
.section-header:hover .panel-header-content h2,
.section-header:focus-visible .panel-header-content h2 { color: #ffffff; }

/* The ON/OFF switch. */
.section-header .chevron {
    position: relative;
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    justify-content: flex-start;
    width: 64px; height: 36px;
    padding: 3px;
    border: 1px solid rgba(255, 255, 255, 0.10);
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.045);
    box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.35);
    transition: background 0.28s ease, border-color 0.28s ease, box-shadow 0.28s ease;
}
.section-header .chevron::before {
    content: "";
    width: 28px; height: 28px;
    border-radius: 50%;
    background: linear-gradient(180deg, #ffffff, #cbd5e1);
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.35);
    transform: translateX(0);
    transition: transform 0.32s cubic-bezier(0.16, 1, 0.3, 1), background 0.28s ease;
}
.section-header .chevron::after {
    content: "OFF";
    position: absolute;
    right: 9px; top: 50%;
    transform: translateY(-50%);
    color: rgba(255, 255, 255, 0.42);
    font-family: var(--font-mono);
    font-size: 0.52rem;
    font-weight: 800;
    letter-spacing: 0.7px;
    pointer-events: none;
}
.section-header .chevron i,
.section-header .chevron .accordion-action-text { display: none; }
.section-header:hover .chevron,
.section-header:focus-visible .chevron {
    border-color: rgba(99, 102, 241, 0.35);
    box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.35), 0 0 28px rgba(99, 102, 241, 0.12);
}
.section.expanded .section-header .chevron {
    border-color: rgba(129, 140, 248, 0.58);
    background: linear-gradient(135deg, var(--accent), #818cf8);
    box-shadow: 0 0 30px rgba(99, 102, 241, 0.22);
}
.section.expanded .section-header .chevron::before {
    transform: translateX(28px);
    background: linear-gradient(180deg, #ffffff, #eef2ff);
}
.section.expanded .section-header .chevron::after {
    content: "ON";
    left: 10px; right: auto;
    color: rgba(255, 255, 255, 0.88);
}

.section-body {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.56s cubic-bezier(0.16, 1, 0.3, 1);
}
.section-body-inner {
    padding-top: 24px;
    padding-bottom: 10px;
    opacity: 0;
    transform: translateY(-6px);
    transition: opacity 0.28s ease 0.08s, transform 0.28s ease 0.08s;
}
.section.expanded .section-body-inner { opacity: 1; transform: translateY(0); }

.panel-tag {
    display: block;
    margin-bottom: 10px;
    color: var(--accent);
    font-family: var(--font-mono);
    font-size: 0.75rem;
    letter-spacing: 2px;
    text-transform: uppercase;
}
h2 {
    margin-bottom: 10px;
    font-size: 2rem;
    font-weight: 700;
    letter-spacing: -0.03em;
    transition: color 0.3s;
}
.panel-desc { color: var(--text-secondary); font-size: 1rem; }
.panel-header-content { min-width: 0; }

/* ===== 6. METRICS ======================================================== */
.metrics-strip {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    align-items: stretch;
    padding: 24px 0;
    border-bottom: 1px solid var(--border);
}
.metrics-strip.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.metrics-strip.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.metrics-strip.cols-5 { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.metrics-strip.cols-6 { grid-template-columns: repeat(6, minmax(0, 1fr)); }

.metric-block {
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    min-width: 0;
    min-height: 118px;
    padding: 0 20px;
}
.metric-block:first-child { padding-left: 0; }
.metric-block:last-child { padding-right: 0; }

.metric-label {
    display: flex;
    align-items: flex-start;
    min-height: 42px;
    margin-bottom: 8px;
    color: var(--text-muted);
    font-size: 0.75rem;
    font-weight: 600;
    line-height: 1.45;
    letter-spacing: 1.5px;
    text-transform: uppercase;
}
.metric-value {
    margin-top: 2px;
    color: var(--text-primary);
    font-family: var(--font-sans);
    font-size: clamp(1.8rem, 3vw, 2.5rem);
    font-weight: 700;
    line-height: 1;
    letter-spacing: -0.04em;
    white-space: nowrap;
}
.metric-value.champion-color { color: var(--champion); }
.compact-k { font-family: var(--font-mono); letter-spacing: -0.06em; }

/* Non-numeric metric: a tool/stack name, optionally with a brand icon. */
.metric-tech-value {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: clamp(1.15rem, 2vw, 1.65rem);
    line-height: 1.1;
    letter-spacing: -0.04em;
    white-space: nowrap;
}
.metric-tech-value i { font-size: 1.25rem; }
.metric-devicon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px; height: 34px;
    font-size: 1.75rem !important;
    line-height: 1;
}

/* Secondary strip of stack/tooling labels. */
.tool-metrics-strip {
    margin: 0 auto 34px;
    grid-template-columns: repeat(6, minmax(0, 1fr));
}
.tool-metrics-strip .metric-block { min-height: 118px; }
.tool-metrics-strip .tool-value {
    color: var(--text-primary);
    font-size: clamp(1.05rem, 1.35vw, 1.65rem);
    line-height: 1.1;
    overflow-wrap: anywhere;
}

/* Inline KPI cards used inside sections. */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 18px;
    margin: 24px 0;
}
.kpi-card {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    min-height: 118px;
    padding: 20px;
    border: 1px solid var(--border);
    border-radius: 14px;
    background: rgba(255, 255, 255, 0.025);
}
.kpi-label {
    min-height: 34px;
    color: var(--text-muted);
    font-family: var(--font-mono);
    font-size: 0.68rem;
    line-height: 1.4;
    letter-spacing: 1.2px;
    text-transform: uppercase;
}
.kpi-value {
    color: var(--text-primary);
    font-size: 1.85rem;
    font-weight: 800;
    line-height: 1;
    white-space: nowrap;
}
.kpi-value.good { color: var(--champion); }

/* Legacy metric aliases. */
.metrics-strip.wheat-metrics { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.metrics-strip.wheat-metrics-six { grid-template-columns: repeat(6, minmax(0, 1fr)); align-items: end; }
.metrics-strip.wheat-metrics-six .metric-block { min-height: 130px; justify-content: flex-end; }
.metrics-strip.wheat-metrics-six .metric-label { align-items: flex-end; }
.metrics-strip.wheat-metrics-six .metric-value { margin-top: 14px; }
.box-office-metrics .metric-label,
.disaster-metrics .metric-label { min-height: 42px; }

/* ===== 7. TAB SWITCHER (top-level project areas) ========================= */
.notebook-switcher {
    position: sticky;
    top: 14px;
    z-index: 50;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
    margin: 34px 0 20px;
    padding: 10px;
    border: 1px solid var(--border);
    border-radius: 18px;
    background: rgba(12, 13, 20, 0.84);
    backdrop-filter: blur(18px);
    box-shadow: 0 24px 60px rgba(0, 0, 0, 0.24);
}
.notebook-switcher.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.notebook-switcher.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.notebook-switcher.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.notebook-switcher.cols-5 { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.notebook-switcher.cols-6 { grid-template-columns: repeat(6, minmax(0, 1fr)); }
.notebook-switcher.cols-7 { grid-template-columns: repeat(7, minmax(0, 1fr)); }
.notebook-switcher.cols-8 { grid-template-columns: repeat(8, minmax(0, 1fr)); }

.notebook-tab {
    appearance: none;
    padding: 14px 16px;
    border: 1px solid transparent;
    border-radius: 12px;
    background: transparent;
    color: var(--text-secondary);
    font-family: var(--font-sans);
    font-size: 0.96rem;
    font-weight: 700;
    letter-spacing: 0.2px;
    text-transform: none;
    cursor: pointer;
    transition: background 0.25s ease, color 0.25s ease, border-color 0.25s ease, transform 0.25s ease;
}
.notebook-tab i { margin-right: 8px; }
.notebook-tab:hover {
    border-color: var(--border);
    background: rgba(255, 255, 255, 0.035);
    color: var(--text-primary);
}
.notebook-tab.active {
    border-color: rgba(99, 102, 241, 0.34);
    background: linear-gradient(135deg, rgba(99, 102, 241, 0.22), rgba(16, 185, 129, 0.08));
    color: #fff;
    box-shadow: 0 0 34px rgba(99, 102, 241, 0.10);
}

.notebook-panel { display: none; }
.notebook-panel.active { display: block; }

/* Legacy switcher aliases. */
.notebook-switcher.box-office-switcher { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.notebook-switcher.disaster-switcher,
.notebook-switcher.deployment-tabs { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.notebook-switcher.lung-switcher { grid-template-columns: repeat(7, minmax(0, 1fr)); z-index: 120; }

/* ===== 8. SUB-TABS (inside a single section) ============================= */
.training-model-tabs {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 10px;
    margin-bottom: 24px;
    padding: 12px;
    border: 1px solid var(--border-color);
    border-radius: 14px;
    background: rgba(15, 16, 26, 0.82);
}
.training-model-tabs.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.training-model-tabs.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.training-model-tabs.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.training-model-tabs.cols-5 { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.training-model-tabs.cols-6 { grid-template-columns: repeat(6, minmax(0, 1fr)); }

.training-model-tab {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    min-height: 54px;
    border: 1px solid transparent;
    border-radius: 10px;
    background: transparent;
    color: var(--text-muted);
    font: 800 0.86rem var(--font-sans);
    cursor: pointer;
    transition: border-color 0.2s ease, color 0.2s ease, background 0.2s ease, transform 0.2s ease;
}
.training-model-tab:hover,
.training-model-tab.active {
    transform: translateY(-1px);
    border-color: rgba(99, 102, 241, 0.45);
    background: linear-gradient(135deg, rgba(99, 102, 241, 0.22), rgba(16, 185, 129, 0.08));
    color: var(--text-primary);
}
.training-model-panel { display: none; padding-top: 4px; }
.training-model-panel.active { display: block; }

.model-panel-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    margin-bottom: 22px;
}
.model-panel-heading h3 {
    margin: 8px 0 0;
    color: var(--text-primary);
    font-size: clamp(1.55rem, 2.4vw, 2.6rem);
    line-height: 1.1;
}
.model-score {
    min-width: 150px;
    padding: 16px 18px;
    border: 1px solid rgba(99, 102, 241, 0.26);
    border-radius: 12px;
    background: rgba(99, 102, 241, 0.08);
    text-align: center;
}
.model-score span {
    display: block;
    color: var(--text-muted);
    font-family: var(--font-mono);
    font-size: 0.72rem;
    letter-spacing: 0.18em;
    text-transform: uppercase;
}
.model-score strong {
    display: block;
    margin-top: 6px;
    color: var(--accent-green);
    font-family: var(--font-mono);
    font-size: 2rem;
    line-height: 1;
}
.model-detail-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 14px;
    margin-bottom: 22px;
}
.model-detail-card {
    padding: 18px;
    border: 1px solid var(--border-color);
    border-radius: 12px;
    background: rgba(16, 18, 30, 0.78);
}
.model-detail-card strong { display: block; margin-bottom: 8px; color: var(--text-primary); }
.model-detail-card span { color: var(--text-secondary); line-height: 1.55; }
.compact-model-table { margin-bottom: 22px; }

/* Jump pills that link into a sub-tab. */
.subsection-menu { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 12px; }
.subsection-menu.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.subsection-menu.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.subsection-menu.cols-5 { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.subsection-pill {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    min-height: 54px;
    padding: 12px 14px;
    border: 1px solid rgba(99, 102, 241, 0.25);
    border-radius: 12px;
    background: linear-gradient(135deg, rgba(99, 102, 241, 0.13), rgba(16, 185, 129, 0.05));
    color: var(--text-primary);
    font-size: 0.86rem;
    font-weight: 800;
    text-decoration: none;
    transition: transform 0.2s ease, border-color 0.2s ease, background 0.2s ease;
}
.subsection-pill:hover {
    transform: translateY(-2px);
    border-color: rgba(99, 102, 241, 0.45);
    background: linear-gradient(135deg, rgba(99, 102, 241, 0.2), rgba(16, 185, 129, 0.08));
}

/* ===== 9. PROSE + DEPENDENCIES =========================================== */
.overview-text { max-width: 900px; color: var(--text-secondary); }

.dependency-list { display: flex; flex-direction: column; gap: 4px; }
.dependency-row {
    display: flex;
    align-items: flex-start;
    gap: 14px;
    padding: 12px 0;
    border-bottom: 1px solid var(--border);
}
.dependency-row:last-child { border-bottom: none; }
.dep-icon {
    width: 24px;
    margin-top: 3px;
    color: var(--text-primary);
    font-size: 1.2rem;
    text-align: center;
}
.dependency-row strong { display: block; margin-bottom: 4px; font-size: 1.05rem; font-weight: 600; }
.dependency-row span { color: var(--text-secondary); font-size: 0.88rem; line-height: 1.5; }

/* Compact chip row of library names. */
.library-strip { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 24px; }
.library-strip span {
    display: inline-flex;
    align-items: center;
    min-height: 34px;
    padding: 7px 12px;
    border: 1px solid rgba(99, 102, 241, 0.22);
    border-radius: 8px;
    background: rgba(99, 102, 241, 0.08);
    color: var(--text-secondary);
    font-family: var(--font-mono);
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.4px;
}

/* ===== 10. NUMBERED PIPELINE (vertical timeline) ========================= */
.timeline-flow { position: relative; padding-left: 28px; }
.flow-node {
    position: relative;
    display: flex;
    align-items: flex-start;
    gap: 18px;
    padding-bottom: 24px;
}
.flow-node:last-child { padding-bottom: 0; }
.flow-dot {
    position: absolute;
    left: -28px; top: 7px;
    z-index: 1;
    width: 10px; height: 10px;
    border-radius: 50%;
    background: var(--accent);
}
.flow-node::before {
    content: "";
    position: absolute;
    left: -24px; top: 22px;
    width: 1px; height: calc(100% - 12px);
    background: var(--border);
}
.flow-node:last-child::before { display: none; }
.flow-content { display: flex; gap: 16px; }
.flow-step {
    min-width: 24px;
    color: var(--text-muted);
    font-family: var(--font-mono);
    font-size: 0.85rem;
    font-weight: 600;
}
.flow-content strong { display: block; margin-bottom: 4px; color: var(--text-primary); font-size: 1rem; font-weight: 600; }
.flow-content span { color: var(--text-secondary); font-size: 0.85rem; }

/* ===== 11. HORIZONTAL ARCHITECTURE FLOW ================================== */
.architecture-flow {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr) auto minmax(0, 1fr) auto minmax(0, 1fr);
    align-items: stretch;
    gap: 14px;
    margin: 26px 0;
}
.architecture-flow .flow-step {
    display: flex;
    flex-direction: column;
    gap: 8px;
    min-width: 0;
    padding: 22px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--surface-card);
    font-family: var(--font-sans);
}
.architecture-flow .flow-step span {
    color: var(--accent);
    font-family: var(--font-mono);
    font-size: 0.76rem;
    font-weight: 800;
    letter-spacing: 1px;
}
.architecture-flow .flow-step strong { color: var(--text-primary); font-size: 1rem; }
.architecture-flow .flow-step p { color: var(--text-secondary); font-size: 0.88rem; line-height: 1.55; }
.architecture-flow .flow-arrow {
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
}

/* ===== 12. THEORY / TECH / NOTE CARDS ==================================== */
.theory-split { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }
.theory-split.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.theory-split.cols-4,
.theory-split.lung-system-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.theory-block {
    min-width: 0;
    padding: 30px;
    border: 1px solid var(--border);
    border-radius: 14px;
    background: var(--surface-card);
    overflow: hidden;
    transition: border-color 0.2s;
}
.theory-block:hover { border-color: var(--border-hover); }
.theory-card-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    margin-bottom: 20px;
}
.theory-title { font-size: 1.15rem; font-weight: 600; }
.theory-badge {
    padding: 4px 10px;
    border-radius: 4px;
    background: var(--accent-glow);
    color: var(--accent);
    font-family: var(--font-mono);
    font-size: 0.68rem;
    font-weight: 500;
}
.theory-badge.champion-badge { background: var(--champion-glow); color: var(--champion); }
.theory-math-container {
    max-width: 100%;
    margin-bottom: 20px;
    padding: 20px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: rgba(0, 0, 0, 0.2);
    overflow-x: auto;
    white-space: normal;
}
.theory-math-container mjx-container { max-width: 100%; overflow-x: auto; overflow-y: hidden; }
.theory-math-container code { color: var(--accent); font-family: var(--font-mono); line-height: 1.7; white-space: normal; }
.theory-explanation { margin-bottom: 12px; color: var(--text-secondary); font-size: 0.9rem; line-height: 1.6; }

.tech-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 24px; }
.tech-grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.tech-card {
    min-width: 0;
    padding: 26px;
    border: 1px solid var(--border);
    border-radius: 14px;
    background: var(--surface-card);
    overflow: hidden;
}
.tech-card:hover { border-color: var(--border-hover); }
.tech-card h3 { margin-bottom: 12px; color: var(--text-primary); font-size: 1.12rem; }
.tech-card p, .tech-card li { color: var(--text-secondary); font-size: 0.92rem; line-height: 1.65; }
.tech-card ul { margin-top: 10px; padding-left: 18px; }
.tech-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 14px;
    padding: 5px 10px;
    border-radius: 6px;
    background: var(--accent-glow);
    color: var(--accent);
    font-family: var(--font-mono);
    font-size: 0.68rem;
}

.note-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 20px; margin-top: 22px; }
.note-grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.note-card {
    min-width: 0;
    padding: 22px;
    border: 1px solid var(--border);
    border-radius: 14px;
    background: var(--surface-card);
    overflow: hidden;
}
.note-card strong { display: block; margin-bottom: 8px; color: var(--text-primary); }
.note-card span { color: var(--text-secondary); font-size: 0.9rem; line-height: 1.6; }

.formula-box {
    margin-top: 24px;
    padding: 24px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: linear-gradient(135deg, rgba(99, 102, 241, 0.08), rgba(16, 185, 129, 0.04));
    color: var(--text-secondary);
    overflow-x: auto;
}
.formula-box p { margin-bottom: 12px; }
.formula-line {
    color: var(--text-secondary);
    font-family: var(--font-mono);
    font-size: 0.9rem;
    line-height: 1.7;
    overflow-x: auto;
    overflow-wrap: anywhere;
    white-space: normal;
}

/* ===== 13. TABLES ======================================================== */
.matrix-table-container {
    min-width: 0;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--surface-card);
    overflow: hidden;
    overflow-x: auto;
}
table { width: 100%; border-collapse: collapse; font-size: 0.9rem; text-align: left; }
th {
    padding: 16px 24px;
    border-bottom: 1px solid var(--border);
    background: rgba(255, 255, 255, 0.02);
    color: var(--text-muted);
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 1px;
    text-transform: uppercase;
}
td { padding: 16px 24px; border-bottom: 1px solid var(--border); color: var(--text-secondary); }
tr:last-child td { border-bottom: none; }
tr:hover td { background: rgba(255, 255, 255, 0.01); color: var(--text-primary); }
td code {
    padding: 3px 8px;
    border-radius: 4px;
    background: var(--accent-glow);
    color: var(--accent);
    font-family: var(--font-mono);
    font-size: 0.85rem;
}
.data-table td, .data-table th { vertical-align: top; }
.pipeline-table td:nth-child(1) { width: 190px; }
.pipeline-table td:nth-child(2) { width: 220px; }
.compact-param-table td:nth-child(1) { width: 230px; }
.compact-param-table td:nth-child(2) { width: 260px; }

.taxonomy-tag {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 4px;
    background: rgba(255, 255, 255, 0.06);
    color: var(--text-primary);
    font-size: 0.75rem;
    font-weight: 500;
}
.taxonomy-tag.target-style { background: var(--champion-glow); color: var(--champion); font-weight: 600; }
.target-row-highlight td { background: rgba(16, 185, 129, 0.02); }

/* ===== 14. CODE SANDBOX ================================================== */
.terminal-panel {
    min-width: 0;
    border: 1px solid var(--border);
    border-radius: 14px;
    background: #07080d;
    overflow: hidden;
}
.terminal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 24px;
    border-bottom: 1px solid var(--border);
    background: rgba(255, 255, 255, 0.02);
}
.terminal-dots { display: flex; gap: 6px; }
.terminal-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--border); }
.terminal-title { color: var(--text-muted); font-family: var(--font-mono); font-size: 0.75rem; }
.terminal-body {
    padding: 30px;
    color: #cbd5e1;
    font-family: var(--font-mono);
    font-size: 0.85rem;
    line-height: 1.65;
    overflow-x: auto;
    overflow-y: visible;
    max-height: none;
}
.terminal-body pre { margin: 0; min-width: max-content; white-space: pre; }

.code-comment { color: #475569; font-style: italic; }
.code-keyword { color: #f43f5e; font-weight: 500; }
.code-fn { color: #38bdf8; }
.code-str { color: #10b981; }
.code-num { color: #fbbf24; }

/* Two-up code layout — wraps instead of scrolling. */
.implementation-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-items: stretch;
    gap: 24px;
}
.implementation-grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.terminal-panel.implementation-code { max-width: 100%; margin: 0; overflow: hidden; }
.terminal-panel.implementation-code .terminal-body.compact-code {
    padding: 24px 26px;
    overflow-x: auto;
    overflow-y: visible;
}
.terminal-panel.implementation-code .terminal-body.compact-code pre,
.terminal-body.code-mini pre {
    margin: 0;
    min-width: 0;
    font-size: 0.82rem;
    line-height: 1.72;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    word-break: normal;
}
.terminal-panel.code-showcase { max-width: 980px; margin-left: auto; margin-right: auto; }
.code-mini { max-height: none; overflow: visible; }

/* Inline code inside prose. */
.executive-summary-box code,
.overview-text code,
.flow-content code,
.panel-desc code,
.tech-card code,
.note-card code,
.synthesis-gradient-box code,
.architecture-flow code,
.formula-box code,
.code-pill {
    padding: 2px 6px;
    border-radius: 4px;
    background: var(--accent-glow);
    color: var(--accent);
    font-family: var(--font-mono);
    font-size: 0.85em;
}

/* ===== 15. VISUALIZATIONS + LIGHTBOX ===================================== */
.viz-display-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    justify-content: center;
    gap: 24px;
}
.viz-display-grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); align-items: start; }
.viz-display-grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.viz-display-grid.four { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.viz-display-grid.single-centered { grid-template-columns: minmax(0, 820px); }

.viz-wrapper-card {
    min-width: 0;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--surface-card);
    overflow: hidden;
    cursor: pointer;
    will-change: transform;
    transition: transform 0.3s cubic-bezier(0.25, 0.8, 0.25, 1), box-shadow 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
}
.viz-wrapper-card:hover {
    transform: translateY(-8px);
    box-shadow: 0 16px 32px rgba(0, 0, 0, 0.5), 0 0 0 1px rgba(255, 255, 255, 0.1);
}
.viz-wrapper-card img {
    display: block;
    width: 100%;
    height: auto;
    max-height: 280px;
    margin-left: auto;
    margin-right: auto;
    background: #0a0b10;
    object-fit: contain;
    transition: transform 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
}
.viz-wrapper-card:hover img { transform: scale(1.02); }
.viz-wrapper-card.big-viz { width: 100%; max-width: 820px; margin-left: auto; margin-right: auto; }
.viz-wrapper-card.big-viz img { max-height: 520px; }
.viz-display-grid.two .viz-wrapper-card.big-viz { max-width: 100%; }

/* Caption below the image. */
.viz-meta-text {
    position: relative;
    z-index: 2;
    padding: 15px;
    border-top: 1px solid var(--border);
    background: var(--surface-card);
    color: var(--text-secondary);
    font-size: 0.88rem;
    font-weight: 600;
    text-align: center;
}
/* Caption above the image. */
.viz-title {
    position: relative;
    z-index: 2;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 54px;
    padding: 15px;
    border-bottom: 1px solid var(--border);
    background: var(--surface-card);
    color: var(--text-secondary);
    font-size: 0.88rem;
    font-weight: 700;
    text-align: center;
}

/* Dense gallery of small EDA figures on white backgrounds. */
.eda-gallery { align-items: start; }
.eda-gallery .viz-wrapper-card img,
.eda-compact-grid .viz-wrapper-card img {
    max-height: 300px;
    background: #ffffff;
    object-fit: contain;
}

.lightbox-overlay {
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: rgba(0, 0, 0, 0.95);
    backdrop-filter: blur(10px);
    z-index: 10000;
}
.lightbox-overlay.active { display: flex; }
.lightbox-wrapper { position: relative; max-width: 90%; max-height: 90%; }
.lightbox-wrapper img {
    max-width: 100%;
    max-height: 90vh;
    border-radius: 8px;
    box-shadow: 0 24px 48px rgba(0, 0, 0, 0.8);
}
.lightbox-close {
    position: absolute;
    top: -40px; right: 0;
    color: white;
    font-size: 1.5rem;
    cursor: pointer;
}

/* ===== 16. RESULTS / RANKING ============================================= */
.engine-insights-stack { display: flex; flex-direction: column; gap: 4px; margin-bottom: 32px; }
.insight-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: 32px;
    padding: 12px 0;
    border-bottom: 1px solid var(--border);
}
.insight-row:last-child { border-bottom: none; }
.insight-row.rank-leader { border-bottom-color: rgba(16, 185, 129, 0.25); }
.insight-left-meta { display: flex; align-items: center; gap: 20px; min-width: 0; }
.insight-rank-index {
    flex: 0 0 86px;
    width: 86px; min-width: 86px;
    color: var(--text-muted);
    font-family: var(--font-mono);
    font-size: 0.9rem;
    font-weight: 700;
    white-space: nowrap;
}
.rank-leader .insight-rank-index { color: var(--champion); }
.insight-model-identity strong { display: block; color: var(--text-primary); font-size: 1.1rem; font-weight: 600; }
.insight-model-identity span { color: var(--text-secondary); font-size: 0.85rem; }
.insight-score-metrics {
    display: grid;
    grid-template-columns: repeat(2, minmax(118px, 1fr));
    align-items: start;
    gap: 28px;
    min-width: 320px;
    text-align: right;
}
.insight-score-item { display: flex; flex-direction: column; align-items: flex-end; min-width: 118px; }
.insight-score-label {
    display: block;
    min-height: 20px;
    color: var(--text-muted);
    font-size: 0.68rem;
    font-weight: 600;
    line-height: 1.35;
    letter-spacing: 1px;
    text-transform: uppercase;
}
.insight-score-value {
    margin-top: 6px;
    color: var(--text-primary);
    font-family: var(--font-mono);
    font-size: 1.3rem;
    font-weight: 700;
    line-height: 1;
    white-space: nowrap;
}
.insight-score-value.accuracy-highlight,
.insight-score-value.loss-highlight { color: var(--champion); }

/* Staged/phased results (training phases, pipeline stages). */
.phase-stack { display: flex; flex-direction: column; gap: 0; margin-bottom: 28px; }
.phase-row {
    display: grid;
    grid-template-columns: 115px minmax(0, 1fr) 430px;
    align-items: center;
    gap: 28px;
    padding: 18px 0;
    border-bottom: 1px solid var(--border);
}
.phase-row:last-child { border-bottom: none; }
.phase-row.rank-leader { border-bottom-color: rgba(16, 185, 129, 0.25); }
.phase-index { color: var(--text-muted); font-family: var(--font-mono); font-weight: 700; white-space: nowrap; }
.phase-row.rank-leader .phase-index { color: var(--champion); }
.phase-main { min-width: 0; }
.phase-main strong { display: block; margin-bottom: 4px; color: var(--text-primary); font-size: 1.08rem; }
.phase-main span { display: block; color: var(--text-secondary); font-size: 0.88rem; line-height: 1.55; }
.phase-metrics { display: grid; grid-template-columns: repeat(3, minmax(105px, 1fr)); gap: 20px; text-align: right; }
.phase-metric-label {
    display: block;
    min-height: 20px;
    color: var(--text-muted);
    font-family: var(--font-mono);
    font-size: 0.66rem;
    line-height: 1.35;
    letter-spacing: 1.2px;
    text-transform: uppercase;
}
.phase-metric-value {
    display: block;
    margin-top: 6px;
    color: var(--text-primary);
    font-family: var(--font-mono);
    font-size: 1.28rem;
    font-weight: 800;
    line-height: 1;
    white-space: nowrap;
}
.phase-metric-value.good { color: var(--champion); }

/* ===== 17. SUMMARY BLOCKS ================================================ */
.executive-summary-box {
    padding: 16px 24px;
    border-left: 2px solid var(--border);
    background: transparent;
    color: var(--text-secondary);
    font-size: 0.92rem;
}
.executive-summary-box strong { color: var(--text-primary); }

.synthesis-gradient-box {
    padding: 30px;
    border: 1px solid rgba(99, 102, 241, 0.24);
    border-radius: 14px;
    background: linear-gradient(135deg, rgba(99, 102, 241, 0.14), rgba(16, 185, 129, 0.08), rgba(255, 255, 255, 0.018));
    color: var(--text-secondary);
}
.synthesis-gradient-box p { margin-bottom: 12px; font-size: 0.95rem; color: var(--text-secondary); }
.synthesis-gradient-box p:last-child { margin-bottom: 0; }
.synthesis-gradient-box strong { color: var(--text-primary); }
.synthesis-gradient-box ul { padding-left: 20px; color: var(--text-secondary); }
.synthesis-gradient-box li { margin-bottom: 8px; }

/* ===== 18. FOOTER ======================================================== */
/* Icons only — no boxes, no borders, no backgrounds on desktop. */
.portfolio-footer-gate {
    display: flex;
    justify-content: center;
    margin-top: 40px;
    padding: 40px 0;
    border-top: 1px solid var(--border);
}
.contact-icons { display: flex; flex-wrap: wrap; align-items: center; gap: 24px; }
.icon-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    font-size: 1.25rem;
    text-decoration: none;
    transition: color 0.2s ease, transform 0.2s ease;
}
.icon-link:hover { color: var(--accent); transform: translateY(-2px); }

.editorial-credits {
    margin-top: 40px;
    color: var(--text-muted);
    font-family: var(--font-mono);
    font-size: 0.8rem;
    letter-spacing: 0.5px;
    text-align: center;
}

/* ===== 19. REVEAL ANIMATION ============================================== */
.stagger-child {
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.55s ease, transform 0.55s ease;
}
.stagger-child.revealed { opacity: 1; transform: translateY(0); }

/* ===== 20. RESPONSIVE ==================================================== */
@media (max-width: 1200px) {
    .notebook-switcher.cols-5,
    .notebook-switcher.cols-6,
    .notebook-switcher.cols-7,
    .notebook-switcher.cols-8,
    .notebook-switcher.lung-switcher { grid-template-columns: repeat(3, minmax(0, 1fr)); }

    .tool-metrics-strip,
    .viz-display-grid.four,
    .subsection-menu,
    .training-model-tabs,
    .model-detail-grid,
    .implementation-grid.cols-3,
    .theory-split.cols-3,
    .theory-split.cols-4,
    .theory-split.lung-system-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 1100px) {
    .kpi-grid,
    .note-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .tech-grid,
    .tech-grid.cols-3,
    .viz-display-grid.three,
    .notebook-switcher.cols-4,
    .notebook-switcher.disaster-switcher,
    .notebook-switcher.deployment-tabs,
    .architecture-flow { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .architecture-flow .flow-arrow { display: none; }
    .phase-row { grid-template-columns: 1fr; }
    .phase-metrics { max-width: none; text-align: left; }
}

@media (max-width: 1024px) {
    h1 { font-size: 2.5rem; }
    .section { padding: 40px 0; }
    .metrics-strip,
    .metrics-strip.cols-3,
    .metrics-strip.cols-4,
    .metrics-strip.cols-5,
    .metrics-strip.cols-6,
    .metrics-strip.wheat-metrics { grid-template-columns: repeat(2, 1fr); gap: 16px; }
    .metrics-strip.wheat-metrics-six { grid-template-columns: repeat(3, 1fr); }
    .theory-split { grid-template-columns: 1fr; }
    .metric-block { min-height: 106px; }
    .metric-label { min-height: 32px; }
}

@media (max-width: 980px) {
    .implementation-grid,
    .viz-display-grid.two,
    .viz-display-grid.single-centered,
    .notebook-switcher.box-office-switcher { grid-template-columns: 1fr; }
    .compact-param-table td:nth-child(1),
    .compact-param-table td:nth-child(2) { width: auto; }
}

/* ---- Phone layer: removes overflow and turns strips into cards. -------- */
@media (max-width: 760px) {
    html, body { width: 100%; max-width: 100%; overflow-x: clip; }
    body { padding-bottom: 34px; }
    body * { min-width: 0; }
    img, svg, video, canvas { max-width: 100%; }

    .hero-section, .main-layout {
        width: 100%; max-width: 100%;
        padding-left: clamp(16px, 5vw, 22px);
        padding-right: clamp(16px, 5vw, 22px);
    }
    .hero-section { padding-top: 52px; padding-bottom: 28px; }
    .hero-accent-blur { width: 88vw; max-width: 360px; height: 210px; }
    .hero-meta { max-width: 100%; font-size: 0.68rem; line-height: 1.9; letter-spacing: 2.4px; overflow-wrap: anywhere; }
    h1 { max-width: 100%; font-size: clamp(2rem, 10.2vw, 2.85rem); line-height: 1.12; overflow-wrap: anywhere; }
    h2, .model-panel-heading h3 { font-size: clamp(1.35rem, 7vw, 2rem); line-height: 1.16; overflow-wrap: anywhere; }
    .hero-subtitle, .panel-desc, .overview-text, .theory-explanation,
    .synthesis-gradient-box, .executive-summary-box {
        max-width: 100%; font-size: 0.96rem; line-height: 1.72; overflow-wrap: anywhere;
    }

    .btn-group { display: grid; grid-template-columns: 1fr; gap: 12px; width: 100%; align-items: stretch; }
    .btn-modern-primary, .btn-modern-secondary {
        width: 100%; min-height: 56px; padding: 14px 18px;
        justify-content: center; font-size: 0.98rem; text-align: center;
    }

    .section { padding: 30px 0; scroll-margin-top: 14px; }
    .accordion-guide { flex-direction: column; align-items: flex-start; gap: 6px; margin-top: 24px; padding: 14px 16px; border-radius: 14px; }
    .accordion-guide-hint { font-size: 0.82rem; }
    .section-header { grid-template-columns: minmax(0, 1fr) 54px; gap: 10px; padding: 16px 0 16px 16px; border-radius: 14px; }
    .panel-tag { font-size: 0.68rem; letter-spacing: 1.6px; line-height: 1.45; overflow-wrap: anywhere; }
    .section-header .chevron { width: 54px; height: 32px; justify-self: end; }
    .section-header .chevron::before { width: 24px; height: 24px; }
    .section.expanded .section-header .chevron::before { transform: translateX(22px); }
    .section-header .chevron::after { right: 7px; font-size: 0.48rem; }
    .section.expanded .section-header .chevron::after { left: 8px; }
    .section-body-inner { padding-top: 18px; }

    /* Metric strips become bordered cards. */
    .metrics-strip,
    .metrics-strip.cols-3, .metrics-strip.cols-4, .metrics-strip.cols-5, .metrics-strip.cols-6,
    .metrics-strip.wheat-metrics, .metrics-strip.wheat-metrics-six,
    .lung-metrics, .tool-metrics-strip, .kpi-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
        gap: 12px; padding: 18px 0; align-items: stretch;
    }
    .metrics-strip { border-bottom-color: rgba(255, 255, 255, 0.08); }
    .metric-block, .kpi-card {
        min-height: auto; padding: 16px;
        border: 1px solid var(--border); border-radius: 14px;
        background: rgba(255, 255, 255, 0.025);
        justify-content: space-between;
    }
    .metric-block:first-child, .metric-block:last-child { padding-left: 16px; padding-right: 16px; }
    .metric-label, .kpi-label {
        min-height: auto; margin-bottom: 12px; align-items: flex-start;
        font-size: 0.64rem; line-height: 1.35; letter-spacing: 1px;
    }
    .metric-value, .kpi-value {
        margin-top: 0; font-size: clamp(1.35rem, 8.5vw, 2rem);
        line-height: 1.05; white-space: normal; overflow-wrap: anywhere;
    }
    .tool-metrics-strip { margin-bottom: 24px; }
    .tool-metrics-strip .tool-value { font-size: clamp(0.86rem, 3.8vw, 1.05rem); overflow-wrap: normal; word-break: keep-all; }
    .metric-tech-value { gap: 8px; font-size: clamp(1.05rem, 5.7vw, 1.42rem); white-space: nowrap; }

    /* Top tabs become a horizontal scroll rail so they stay reachable. */
    .notebook-switcher {
        position: sticky !important; top: 8px !important; z-index: 120 !important;
        display: flex !important;
        grid-template-columns: none !important;
        align-items: stretch;
        gap: 8px !important;
        width: 100%;
        max-height: none !important;
        margin: 16px 0 14px !important;
        padding: 7px !important;
        border-radius: 15px;
        overflow-x: auto !important;
        overflow-y: hidden !important;
        overscroll-behavior-x: contain;
        scroll-snap-type: x proximity;
        scrollbar-width: none;
        -ms-overflow-style: none;
        touch-action: pan-x pan-y;
    }
    .notebook-switcher::-webkit-scrollbar { display: none; }
    .notebook-tab {
        flex: 0 0 auto;
        width: auto; min-width: 122px; min-height: 46px;
        display: inline-flex; align-items: center; justify-content: center; gap: 7px;
        padding: 10px 13px !important;
        border-radius: 11px;
        font-size: 0.79rem !important; line-height: 1.15;
        white-space: nowrap !important;
        scroll-snap-align: center;
    }
    .notebook-tab i { flex: 0 0 auto; margin-right: 0 !important; font-size: 0.9rem; }

    .training-model-tabs, .subsection-menu {
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
        gap: 8px; padding: 8px; overflow: visible;
    }
    .training-model-tab, .subsection-pill {
        min-height: 48px; padding: 10px 9px;
        font-size: 0.76rem; line-height: 1.25;
        white-space: normal; text-align: center;
    }

    /* Every multi-column block collapses to one column. */
    .theory-split, .tech-grid, .tech-grid.cols-3, .implementation-grid, .implementation-grid.cols-3,
    .model-detail-grid, .note-grid, .note-grid.cols-2,
    .viz-display-grid, .viz-display-grid.two, .viz-display-grid.three,
    .viz-display-grid.four, .viz-display-grid.single-centered,
    .eda-gallery, .eda-compact-grid, .architecture-flow {
        grid-template-columns: 1fr !important; gap: 16px;
    }

    .theory-block, .note-card, .tech-card, .model-detail-card, .terminal-panel,
    .matrix-table-container, .viz-wrapper-card, .synthesis-gradient-box,
    .executive-summary-box, .formula-box { max-width: 100%; border-radius: 13px; }
    .theory-block, .note-card, .tech-card, .model-detail-card,
    .synthesis-gradient-box, .formula-box { padding: 20px; }
    .theory-card-header { flex-direction: column; align-items: flex-start; gap: 10px; }
    .theory-badge, .tech-badge { max-width: 100%; line-height: 1.35; white-space: normal; }

    .dependency-row { gap: 12px; padding: 14px 0; }
    .dep-icon { width: 22px; flex: 0 0 22px; }
    .dependency-row strong, .dependency-row span,
    .flow-content strong, .flow-content span,
    .model-detail-card span, .note-card span { overflow-wrap: anywhere; }

    .timeline-flow { padding-left: 20px; }
    .flow-node { gap: 12px; padding-bottom: 20px; }
    .flow-dot { left: -20px; }
    .flow-node::before { left: -16px; }
    .flow-content { gap: 10px; }
    .flow-step { min-width: 22px; font-size: 0.76rem; }

    .insight-row, .phase-row { grid-template-columns: 1fr !important; gap: 14px; padding: 16px 0; }
    .insight-rank-index { width: auto; min-width: auto; flex: 0 0 auto; }
    .insight-left-meta { flex-direction: column; align-items: flex-start; gap: 4px; }
    .insight-score-metrics, .phase-metrics {
        width: 100%; min-width: 0; max-width: none;
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
        gap: 10px; text-align: left;
    }
    .phase-metrics > div {
        padding: 12px;
        border: 1px solid var(--border); border-radius: 10px;
        background: rgba(255, 255, 255, 0.025);
    }
    .phase-metric-label { min-height: auto; font-size: 0.62rem; }
    .phase-metric-value { font-size: 1rem; white-space: normal; overflow-wrap: anywhere; }

    .model-panel-heading { flex-direction: column; align-items: stretch; gap: 14px; }
    .model-score { width: 100%; min-width: 0; padding: 14px; }
    .model-score strong { font-size: 1.7rem; }

    .terminal-header { padding: 12px 14px; gap: 10px; }
    .terminal-title { min-width: 0; text-align: right; overflow-wrap: anywhere; }
    .terminal-body,
    .terminal-panel.code-showcase .terminal-body,
    .terminal-panel.implementation-code .terminal-body.compact-code {
        max-width: 100%; padding: 18px 16px;
        font-size: 0.76rem; line-height: 1.72;
        overflow-x: auto; overflow-y: visible;
    }
    .terminal-body pre, .terminal-body code,
    .terminal-panel .terminal-body pre,
    .terminal-panel.implementation-code .terminal-body.compact-code pre,
    .terminal-body.code-mini pre {
        max-width: 100%; min-width: 0 !important;
        white-space: pre-wrap !important;
        overflow-wrap: anywhere !important;
        word-break: normal !important;
    }
    td code, .executive-summary-box code, .overview-text code, .flow-content code,
    .panel-desc code, .tech-card code, .note-card code, .synthesis-gradient-box code,
    .formula-box code, .code-pill { white-space: normal; overflow-wrap: anywhere; }

    .theory-math-container, .formula-line {
        max-width: 100%; padding: 16px; font-size: 0.82rem;
        overflow-x: auto; overflow-y: hidden;
    }

    /* Tables restack as labelled cards using data-label from script.js. */
    .matrix-table-container { border: 0; background: transparent; overflow: visible; }
    .matrix-table-container table, .matrix-table-container thead, .matrix-table-container tbody,
    .matrix-table-container th, .matrix-table-container td, .matrix-table-container tr,
    table.data-table, table.data-table thead, table.data-table tbody,
    table.data-table th, table.data-table td, table.data-table tr { display: block; width: 100%; }
    .matrix-table-container thead, table.data-table thead {
        position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0;
        overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
    }
    .matrix-table-container tbody, table.data-table tbody { display: grid; gap: 12px; }
    .matrix-table-container tr, table.data-table tr {
        border: 1px solid var(--border); border-radius: 13px;
        background: var(--surface-card); overflow: hidden;
    }
    .matrix-table-container tr:hover td, table.data-table tr:hover td { background: transparent; }
    .matrix-table-container td, table.data-table td {
        display: grid; grid-template-columns: minmax(92px, 34%) minmax(0, 1fr);
        align-items: start; gap: 12px;
        padding: 13px 15px; border-bottom: 1px solid var(--border);
        color: var(--text-secondary); text-align: left; overflow-wrap: anywhere;
    }
    .matrix-table-container td:last-child, table.data-table td:last-child { border-bottom: none; }
    .matrix-table-container td::before, table.data-table td::before {
        content: attr(data-label);
        color: var(--text-muted); font-family: var(--font-mono);
        font-size: 0.64rem; font-weight: 700; line-height: 1.45;
        letter-spacing: 0.08em; text-transform: uppercase;
    }
    .pipeline-table td:nth-child(1), .pipeline-table td:nth-child(2),
    .compact-param-table td:nth-child(1), .compact-param-table td:nth-child(2) { width: auto; }

    .viz-wrapper-card img,
    .viz-wrapper-card.big-viz img,
    .eda-gallery .viz-wrapper-card img,
    .eda-compact-grid .viz-wrapper-card img {
        width: 100%; height: auto; max-height: 340px; object-fit: contain;
    }
    .viz-meta-text, .viz-title {
        min-height: auto; padding: 13px;
        font-size: 0.8rem; line-height: 1.45; overflow-wrap: anywhere;
    }

    /* Footer: icons get a tap target on phones, still no visible box.
       The row must stay on ONE line at every phone width -- a contact icon
       wrapping to a second line reads as a broken footer. `nowrap` plus a
       fluid gap and a shrinkable icon box keeps all six on one row without
       ever overflowing the viewport. */
    .portfolio-footer-gate { margin-top: 26px; padding: 30px 12px; }
    .contact-icons {
        flex-wrap: nowrap;
        width: 100%;
        justify-content: center;
        gap: clamp(4px, 2.2vw, 16px);
    }
    .icon-link {
        flex: 0 1 auto;
        width: auto;
        min-width: 36px;
        height: 44px;
        font-size: clamp(0.92rem, 4.2vw, 1.15rem);
    }
    .editorial-credits { margin-top: 20px; padding: 0 18px; line-height: 1.6; overflow-wrap: anywhere; }

    .lightbox-overlay { padding: 16px; }
    .lightbox-wrapper, .lightbox-overlay img, #lightboxImage { max-width: 94vw; max-height: 82vh; }
    .lightbox-close {
        position: fixed; top: 14px; right: 16px; z-index: 10001;
        display: inline-flex; align-items: center; justify-content: center;
        width: 42px; height: 42px;
        border: 1px solid rgba(255, 255, 255, 0.2); border-radius: 999px;
        background: rgba(0, 0, 0, 0.45);
    }
}

@media (max-width: 640px) {
    h1 { font-size: 2.2rem; }
    .section { padding: 32px 0; }
    .metric-block, .metric-label { min-height: auto; }
}

@media (max-width: 380px) {
    .metrics-strip,
    .metrics-strip.cols-3, .metrics-strip.cols-4, .metrics-strip.cols-5, .metrics-strip.cols-6,
    .metrics-strip.wheat-metrics, .metrics-strip.wheat-metrics-six,
    .lung-metrics, .tool-metrics-strip, .kpi-grid,
    .training-model-tabs, .subsection-menu,
    .insight-score-metrics, .phase-metrics { grid-template-columns: 1fr !important; }
    .notebook-switcher { display: flex !important; grid-template-columns: none !important; }
    .notebook-tab { min-width: 112px; padding-inline: 11px !important; font-size: 0.76rem !important; }
    .matrix-table-container td, table.data-table td { grid-template-columns: 1fr; gap: 6px; }
}
/* Last-resort footer floor. Scoped well below the common phone widths (375 and
   360 keep the roomier 36px icons) so it only engages on genuinely tiny
   viewports, where it is the difference between one row and an overflow. */
@media (max-width: 340px) {
    .portfolio-footer-gate { padding-left: 8px; padding-right: 8px; }
    .contact-icons { gap: 3px; }
    .icon-link { min-width: 28px; font-size: 0.9rem; }
}

@media (prefers-reduced-motion: reduce) {
    .section-collapsible, .section-header, .section-header::before, .section-header::after,
    .section-header .chevron, .section-header .chevron::before, .section-header .chevron::after,
    .section-body, .section-body-inner, .stagger-child,
    .viz-wrapper-card, .viz-wrapper-card img, .notebook-tab, .training-model-tab {
        transition: none !important;
    }
}
