/* ============================================
   Process Dynamics & Control - Beautiful Styles
   ============================================ */

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

/* ============================================
   THEME TOKENS
   Light is the default theme (.theme-light values live on :root).
   Dark theme overrides every token under [data-theme="dark"].
   ============================================ */

:root {
    color-scheme: light;

    /* Brand — deep teal, tuned so it is legible as text on white (4.8:1)
       and as a solid fill behind white text. */
    --primary: #0f766e;
    --primary-light: #0f766e;
    --primary-dark: #115e59;
    --primary-glow: rgba(15, 118, 110, 0.22);

    /* Text placed on top of a solid brand/success fill */
    --on-primary: #ffffff;
    --on-success: #ffffff;

    /* Accent colors */
    --accent: #7c3aed;
    --accent-light: #7c3aed;
    --accent-dark: #6d28d9;

    /* Success/Warning/Danger — all meet WCAG AA as text and as fills */
    --success: #047857;
    --success-light: #047857;
    --warning: #b45309;
    --danger: #b91c1c;
    --danger-light: #dc2626;

    /* Backgrounds — cool neutral base, layered light-to-dark for depth */
    --bg-primary: #f6f8fa;
    --bg-secondary: #eef2f6;
    --bg-card: #ffffff;
    --bg-card-hover: #f8fafc;
    --bg-surface: #ffffff;
    --bg-nav: rgba(255, 255, 255, 0.85);
    --bg-code: #f1f5f9;
    --bg-overlay: #f8fafc;

    /* Ambient background glows */
    --bg-glow-1: rgba(15, 118, 110, 0.07);
    --bg-glow-2: rgba(124, 58, 237, 0.06);

    /* Text colors — slate ramp, each step a real contrast tier */
    --text-primary: #0f172a;
    --text-secondary: #475569;
    --text-muted: #64748b;
    --text-dim: #94a3b8;

    /* Borders and dividers */
    --border: #dbe2ea;
    --border-light: #e8edf3;
    --border-glow: rgba(15, 118, 110, 0.35);

    /* Gradients */
    --gradient-primary: linear-gradient(135deg, #0f766e, #14b8a6);
    --gradient-warm: linear-gradient(135deg, #b45309, #dc2626);
    --gradient-cool: linear-gradient(135deg, #0891b2, #2563eb);
    --gradient-card: linear-gradient(145deg, #ffffff, #f8fafc);

    /* Shadows — soft, layered, low-opacity (no harsh black) */
    --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06), 0 1px 3px rgba(15, 23, 42, 0.04);
    --shadow-md: 0 2px 6px rgba(15, 23, 42, 0.06), 0 6px 16px rgba(15, 23, 42, 0.06);
    --shadow-lg: 0 4px 12px rgba(15, 23, 42, 0.07), 0 16px 40px rgba(15, 23, 42, 0.08);
    --shadow-glow: 0 0 20px rgba(15, 118, 110, 0.18);

    /* SVG illustration materials (pipes, jackets, vessels) */
    --metal-1: #94a3b8;
    --metal-2: #cbd5e1;
    --metal-3: #64748b;
    --jacket-1: #cbd5e1;
    --jacket-2: #94a3b8;

    /* Chart chrome — read by js/chart.js at render time */
    --chart-grid: #e6ebf1;
    --chart-zero: #cbd5e1;
    --chart-axis: #64748b;
    --chart-legend-bg: rgba(255, 255, 255, 0.92);
    --chart-legend-border: #e2e8f0;
    --chart-tooltip-bg: rgba(255, 255, 255, 0.97);
    --chart-tooltip-border: #cbd5e1;
    --chart-tooltip-text: #0f172a;
    --chart-hover-line: #94a3b8;
    --chart-btn-bg: rgba(248, 250, 252, 0.9);
    --chart-btn-active-bg: rgba(15, 118, 110, 0.14);

    /* Theme switch knob — needs a real edge to read against the tinted track */
    --toggle-knob: #ffffff;
    --toggle-knob-shadow: 0 0 0 1px rgba(180, 83, 9, 0.18),
                          0 1px 1px rgba(15, 23, 42, 0.14),
                          0 2px 5px rgba(15, 23, 42, 0.13);

    /* Border radius */
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 24px;

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

/* ============================================
   DARK THEME — "Deep space" palette (ported from v4)
   ============================================ */

[data-theme="dark"] {
    color-scheme: dark;

    /* Brand — sky blue reads bright on the near-black ground */
    --primary: #0ea5e9;
    --primary-light: #38bdf8;
    --primary-dark: #0284c7;
    --primary-glow: rgba(56, 189, 248, 0.3);

    /* On the dark theme the brand fills are bright, so on-color text goes dark
       to keep contrast (white on #0ea5e9 is only 2.6:1). */
    --on-primary: #04141f;
    --on-success: #04140d;

    /* Accent colors */
    --accent: #8b5cf6;
    --accent-light: #a78bfa;
    --accent-dark: #7c3aed;

    /* Success/Warning/Danger */
    --success: #10b981;
    --success-light: #34d399;
    --warning: #f59e0b;
    --danger: #ef4444;
    --danger-light: #f87171;

    /* Backgrounds - Deep space theme */
    --bg-primary: #0a0f1a;
    --bg-secondary: #111827;
    --bg-card: #1e293b;
    --bg-card-hover: #273548;
    --bg-surface: #1e293b;
    --bg-nav: rgba(10, 15, 26, 0.9);
    --bg-code: #0f172a;
    --bg-overlay: #0f172a;

    /* Ambient background glows */
    --bg-glow-1: rgba(56, 189, 248, 0.08);
    --bg-glow-2: rgba(139, 92, 246, 0.08);

    /* Text colors */
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --text-dim: #475569;

    /* Borders and dividers */
    --border: rgba(51, 65, 85, 0.8);
    --border-light: rgba(71, 85, 105, 0.5);
    --border-glow: rgba(56, 189, 248, 0.4);

    /* Gradients */
    --gradient-primary: linear-gradient(135deg, #0ea5e9, #8b5cf6);
    --gradient-warm: linear-gradient(135deg, #f59e0b, #ef4444);
    --gradient-cool: linear-gradient(135deg, #06b6d4, #3b82f6);
    --gradient-card: linear-gradient(145deg, #1e293b, #0f172a);

    /* Shadows */
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.5);
    --shadow-glow: 0 0 20px rgba(56, 189, 248, 0.3);

    /* SVG illustration materials */
    --metal-1: #475569;
    --metal-2: #64748b;
    --metal-3: #334155;
    --jacket-1: #334155;
    --jacket-2: #1e293b;

    /* Chart chrome */
    --chart-grid: #1e293b;
    --chart-zero: #334155;
    --chart-axis: #94a3b8;
    --chart-legend-bg: rgba(30, 41, 59, 0.85);
    --chart-legend-border: #334155;
    --chart-tooltip-bg: rgba(15, 23, 42, 0.95);
    --chart-tooltip-border: #334155;
    --chart-tooltip-text: #e2e8f0;
    --chart-hover-line: #64748b;
    --chart-btn-bg: rgba(15, 23, 42, 0.85);
    --chart-btn-active-bg: rgba(56, 189, 248, 0.25);

    /* Light knob on a dark track — mirrors the light theme's white knob */
    --toggle-knob: #cbd5e1;
    --toggle-knob-shadow: 0 0 0 1px rgba(0, 0, 0, 0.3),
                          0 1px 1px rgba(0, 0, 0, 0.4),
                          0 2px 6px rgba(0, 0, 0, 0.35);
}

html {
    scroll-behavior: smooth;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
    overflow-x: hidden;
}

/* Background pattern */
body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background:
        radial-gradient(ellipse at 20% 20%, var(--bg-glow-1) 0%, transparent 50%),
        radial-gradient(ellipse at 80% 80%, var(--bg-glow-2) 0%, transparent 50%);
    pointer-events: none;
    z-index: -1;
}

/* ============================================
   NAVBAR
   ============================================ */

.navbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 1000;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1.5rem;
    background: var(--bg-nav);
    backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
}

.nav-brand {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--primary-light);
    text-decoration: none;
}

.nav-brand i {
    font-size: 1.5rem;
    background: var(--gradient-primary);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.nav-links {
    display: flex;
    gap: 0.25rem;
}

.nav-links a {
    color: var(--text-secondary);
    text-decoration: none;
    padding: 0.5rem 1rem;
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
    font-weight: 500;
    transition: all var(--transition-normal);
    position: relative;
}

.nav-links a:hover {
    color: var(--text-primary);
    background: var(--bg-surface);
}

.nav-links a.active {
    color: var(--primary-light);
    background: color-mix(in srgb, var(--primary) 10%, transparent);
    border: 1px solid color-mix(in srgb, var(--primary) 20%, transparent);
}

.nav-links a.active::after {
    content: '';
    position: absolute;
    bottom: -1px;
    left: 50%;
    transform: translateX(-50%);
    width: 60%;
    height: 2px;
    background: var(--primary);
    border-radius: 1px;
}

/* Mobile menu button */
.mobile-menu-btn {
    display: none;
    background: none;
    border: none;
    color: var(--text-primary);
    font-size: 1.25rem;
    cursor: pointer;
    padding: 0.5rem;
    border-radius: var(--radius-sm);
    transition: background var(--transition-fast);
}

.mobile-menu-btn:hover {
    background: var(--bg-surface);
}

/* ============================================
   HERO SECTION
   ============================================ */

.hero {
    min-height: auto;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 7rem 1.5rem 1rem;
    gap: 0;
    max-width: 900px;
    margin: 0 auto;
    text-align: center;
}

.hero-content {
    flex: 1;
    max-width: 720px;
}

.hero-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    background: color-mix(in srgb, var(--primary) 10%, transparent);
    color: var(--primary-light);
    border: 1px solid color-mix(in srgb, var(--primary) 30%, transparent);
    border-radius: 999px;
    font-size: 0.8rem;
    font-weight: 600;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    margin-bottom: 1.5rem;
    animation: pulse-glow 2s ease-in-out infinite;
}

@keyframes pulse-glow {
    0%, 100% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--primary) 40%, transparent); }
    50% { box-shadow: 0 0 20px 5px color-mix(in srgb, var(--primary) 20%, transparent); }
}

.hero h1 {
    font-size: 3.5rem;
    font-weight: 800;
    line-height: 1.1;
    margin-bottom: 1.25rem;
}

.gradient-text {
    background: var(--gradient-primary);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.hero-subtitle {
    font-size: 1.1rem;
    color: var(--text-secondary);
    margin-bottom: 2rem;
    margin-left: auto;
    margin-right: auto;
    max-width: 520px;
    line-height: 1.8;
}

.course-cta {
    display: inline-flex;
    align-items: center;
    gap: 0.65rem;
    padding: 0.9rem 1.75rem;
    margin-bottom: 2.25rem;
    background: var(--gradient-primary);
    color: var(--on-primary);
    border-radius: 999px;
    font-size: 1rem;
    font-weight: 700;
    text-decoration: none;
    box-shadow: 0 10px 30px color-mix(in srgb, var(--primary) 35%, transparent);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.course-cta:hover {
    transform: translateY(-2px);
    box-shadow: 0 14px 38px color-mix(in srgb, var(--primary) 50%, transparent);
}

.course-cta .cta-icon {
    font-size: 1.15rem;
}

.course-cta .cta-ext {
    font-size: 0.85rem;
    opacity: 0.85;
}

.hero-stats {
    display: flex;
    gap: 2.5rem;
    justify-content: center;
}

.stat {
    display: flex;
    flex-direction: column;
}

.stat-number {
    font-size: 1.75rem;
    font-weight: 700;
    background: var(--gradient-primary);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.stat-label {
    font-size: 0.8rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* Hero Visual */
.hero-visual {
    flex: 1;
    position: relative;
    height: 350px;
}

.floating-card {
    position: absolute;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 1rem 1.5rem;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-md);
    font-weight: 600;
    animation: float 6s ease-in-out infinite;
    backdrop-filter: blur(10px);
}

.floating-card i {
    font-size: 1.25rem;
}

.card-1 { top: 10%; left: 10%; animation-delay: 0s; color: var(--primary-light); }
.card-2 { top: 45%; right: 5%; animation-delay: -2s; color: var(--accent-light); }
.card-3 { bottom: 10%; left: 20%; animation-delay: -4s; color: var(--success); }

@keyframes float {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-15px); }
}

/* ============================================
   SECTION STYLES
   ============================================ */

.section-title {
    text-align: center;
    font-size: 2rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
    background: var(--gradient-primary);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.section-subtitle {
    text-align: center;
    color: var(--text-secondary);
    margin-bottom: 3rem;
}

/* ============================================
   EXAMPLE CARDS
   ============================================ */

.examples-section {
    padding: 4rem 1.5rem;
    max-width: 1200px;
    margin: 0 auto;
}

.examples-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    gap: 1.5rem;
}

.example-card {
    background: var(--gradient-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 2rem;
    text-decoration: none;
    color: var(--text-primary);
    transition: all var(--transition-normal);
    position: relative;
    overflow: hidden;
}

.example-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: var(--gradient-primary);
    transform: scaleX(0);
    transition: transform var(--transition-normal);
}

.example-card:hover {
    border-color: var(--primary);
    transform: translateY(-6px);
    box-shadow: var(--shadow-glow);
}

.example-card:hover::before {
    transform: scaleX(1);
}

.example-card:hover .card-arrow {
    opacity: 1;
    transform: translateX(0);
}

.card-icon {
    width: 60px;
    height: 60px;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    color: white;
    margin-bottom: 1.25rem;
    box-shadow: var(--shadow-md);
}

.example-card h3 {
    font-size: 1.25rem;
    font-weight: 700;
    margin-bottom: 0.75rem;
}

.example-card p {
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin-bottom: 1.25rem;
    line-height: 1.7;
}

.card-tags {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.tag {
    padding: 0.25rem 0.75rem;
    background: var(--bg-surface);
    border: 1px solid var(--border-light);
    border-radius: 999px;
    font-size: 0.75rem;
    color: var(--text-secondary);
    font-weight: 500;
}

.card-arrow {
    position: absolute;
    top: 2rem;
    right: 2rem;
    color: var(--primary-light);
    opacity: 0;
    transform: translateX(-8px);
    transition: all var(--transition-normal);
}

/* ============================================
   CONCEPTS
   ============================================ */

.concepts-section {
    padding: 4rem 1.5rem;
    max-width: 1200px;
    margin: 0 auto;
}

.concepts-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 1.5rem;
}

.concept-item {
    background: var(--gradient-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 1.5rem;
    text-align: center;
    transition: all var(--transition-normal);
}

.concept-item:hover {
    border-color: var(--primary);
    transform: translateY(-4px);
}

.concept-item i {
    font-size: 2rem;
    background: var(--gradient-primary);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 1rem;
}

.concept-item h4 {
    font-size: 1rem;
    margin-bottom: 0.5rem;
}

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

/* ============================================
   EXAMPLE PAGE LAYOUT
   ============================================ */

.example-page {
    padding-top: 4.5rem;
    min-height: 100vh;
}

.page-header {
    padding: 1.5rem 1.5rem 0.5rem;
    max-width: 1400px;
    margin: 0 auto;
}

.page-header h1 {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 0.25rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.page-header p {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.page-layout {
    display: grid;
    grid-template-columns: 320px 1fr;
    gap: 1.5rem;
    padding: 1rem 1.5rem 2rem;
    max-width: 1400px;
    margin: 0 auto;
}

/* ============================================
   CONTROL PANEL
   ============================================ */

.control-panel {
    background: var(--gradient-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.25rem;
    height: fit-content;
    position: sticky;
    top: 5rem;
    max-height: calc(100vh - 6rem);
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;
}

.control-panel::-webkit-scrollbar {
    width: 6px;
}

.control-panel::-webkit-scrollbar-track {
    background: transparent;
}

.control-panel::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
}

.panel-section {
    margin-bottom: 1.25rem;
    padding-bottom: 1.25rem;
    border-bottom: 1px solid var(--border-light);
}

.panel-section:last-child {
    margin-bottom: 0;
    padding-bottom: 0;
    border-bottom: none;
}

.panel-section h3 {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--text-muted);
    margin-bottom: 0.75rem;
    font-weight: 600;
}

/* ============================================
   SLIDERS
   ============================================ */

.slider-group {
    margin-bottom: 1rem;
}

.slider-group:last-child {
    margin-bottom: 0;
}

.slider-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem;
}

.slider-label {
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-primary);
}

.slider-value {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--primary-light);
    background: color-mix(in srgb, var(--primary) 10%, transparent);
    padding: 0.2rem 0.6rem;
    border-radius: var(--radius-sm);
    font-family: 'JetBrains Mono', 'Courier New', monospace;
    min-width: 60px;
    text-align: center;
}

input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 6px;
    border-radius: 3px;
    background: var(--bg-surface);
    outline: none;
    cursor: pointer;
    transition: background var(--transition-fast);
}

input[type="range"]:hover {
    background: var(--border);
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--primary);
    cursor: pointer;
    border: 3px solid var(--bg-card);
    box-shadow: 0 0 0 2px var(--primary), var(--shadow-sm);
    transition: all var(--transition-fast);
}

input[type="range"]::-webkit-slider-thumb:hover {
    transform: scale(1.2);
    box-shadow: 0 0 0 2px var(--primary-light), var(--shadow-glow);
}

input[type="range"]::-moz-range-thumb {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--primary);
    cursor: pointer;
    border: 3px solid var(--bg-card);
    box-shadow: 0 0 0 2px var(--primary);
}

/* ============================================
   PRESET BUTTONS
   ============================================ */

.preset-buttons {
    display: flex;
    gap: 0.4rem;
    flex-wrap: wrap;
}

.preset-btn {
    padding: 0.45rem 0.8rem;
    border-radius: var(--radius-sm);
    font-size: 0.75rem;
    font-weight: 600;
    cursor: pointer;
    border: 1px solid var(--border);
    background: var(--bg-surface);
    color: var(--text-secondary);
    transition: all var(--transition-fast);
}

.preset-btn:hover {
    border-color: var(--primary);
    color: var(--text-primary);
    background: color-mix(in srgb, var(--primary) 10%, transparent);
}

.preset-btn.active {
    background: var(--primary);
    border-color: var(--primary);
    color: white;
    box-shadow: 0 0 12px var(--primary-glow);
}

/* ============================================
   SETPOINT STEP BUTTONS
   ============================================ */

.step-buttons {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.4rem;
}

.step-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.35rem;
    padding: 0.5rem 0.5rem;
    border-radius: var(--radius-sm);
    font-size: 0.75rem;
    font-weight: 700;
    cursor: pointer;
    border: 1px solid color-mix(in srgb, var(--success) 35%, transparent);
    background: color-mix(in srgb, var(--success) 10%, transparent);
    color: var(--success-light);
    transition: all var(--transition-fast);
    font-family: 'JetBrains Mono', 'Courier New', monospace;
}

.step-btn:hover {
    background: var(--success);
    border-color: var(--success);
    color: var(--on-success);
    transform: translateY(-1px);
    box-shadow: 0 0 12px color-mix(in srgb, var(--success) 40%, transparent);
}

.step-btn:active {
    transform: translateY(0) scale(0.97);
}

.hint {
    margin-top: 0.6rem;
    font-size: 0.7rem;
    color: var(--text-muted);
    line-height: 1.5;
}

/* ============================================
   SIMULATION CONTROLS
   ============================================ */

.sim-controls {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.run-pause-btn {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.75rem 1rem;
    border-radius: var(--radius-md);
    font-size: 0.9rem;
    font-weight: 700;
    cursor: pointer;
    border: none;
    background: var(--gradient-primary);
    color: white;
    transition: all var(--transition-normal);
    box-shadow: var(--shadow-md);
}

.run-pause-btn:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-glow);
}

.run-pause-btn.running {
    background: linear-gradient(135deg, var(--warning), var(--danger));
    animation: pulse-run 1.5s ease-in-out infinite;
}

@keyframes pulse-run {
    0%, 100% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--danger) 40%, transparent); }
    50% { box-shadow: 0 0 20px 5px color-mix(in srgb, var(--danger) 20%, transparent); }
}

.run-pause-btn i {
    font-size: 1rem;
}

.reset-btn {
    padding: 0.75rem 1rem;
    border-radius: var(--radius-md);
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    border: 1px solid var(--border);
    background: var(--bg-surface);
    color: var(--text-secondary);
    transition: all var(--transition-fast);
}

.reset-btn:hover {
    border-color: var(--danger);
    color: var(--danger);
    background: color-mix(in srgb, var(--danger) 10%, transparent);
}

/* Speed Controls */
.speed-controls {
    display: flex;
    gap: 0.35rem;
    margin-top: 0.75rem;
}

.speed-controls label {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
    display: block;
    margin-bottom: 0.5rem;
    width: 100%;
}

.speed-btn {
    flex: 1;
    padding: 0.5rem 0.4rem;
    border-radius: var(--radius-sm);
    font-size: 0.75rem;
    font-weight: 700;
    cursor: pointer;
    border: 1px solid var(--border);
    background: var(--bg-surface);
    color: var(--text-secondary);
    transition: all var(--transition-fast);
    font-family: 'JetBrains Mono', 'Courier New', monospace;
}

.speed-btn:hover {
    border-color: var(--primary);
    color: var(--text-primary);
}

.speed-btn.active {
    background: var(--primary);
    border-color: var(--primary);
    color: white;
    box-shadow: 0 0 10px var(--primary-glow);
}

/* ============================================
   TANK SCHEMATIC (SVG)
   ============================================ */

.tank-schematic-container {
    background: var(--gradient-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1rem;
    margin-bottom: 1rem;
}

.tank-schematic-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.75rem;
}

.tank-schematic-header h3 {
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
    font-weight: 600;
}

.live-indicator {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--success);
}

.live-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--success);
    animation: blink 1s ease-in-out infinite;
}

@keyframes blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.3; }
}

.tank-svg-wrapper {
    background: var(--bg-overlay);
    border-radius: var(--radius-md);
    padding: 0.5rem;
    border: 1px solid var(--border-light);
}

#tank-svg {
    width: 100%;
    height: auto;
    max-height: 300px;
}

/* Inflow / outflow arrows scale about their own centre instead of the SVG
   origin (0,0), which made them fly across the schematic at low flow. */
#inflow-arrow,
#outflow-arrow {
    transform-box: view-box;
}
#inflow-arrow { transform-origin: 59px 88px; }
#outflow-arrow { transform-origin: 269px 366px; }

/* Animated process streams on the CSTR schematics: the dashed centre-line
   crawls in the direction of flow so every inflow/outflow is demonstrated. */
.flow-line {
    stroke-linecap: round;
    animation: flow-dash 1s linear infinite;
}
@keyframes flow-dash {
    to { stroke-dashoffset: -24; }
}
@media (prefers-reduced-motion: reduce) {
    .flow-line { animation: none; }
}

/* ============================================
   CHART CONTAINER
   ============================================ */

.chart-container {
    background: var(--gradient-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.25rem;
}

.chart-tabs {
    display: flex;
    gap: 0.25rem;
    margin-bottom: 1rem;
    background: var(--bg-surface);
    padding: 0.25rem;
    border-radius: var(--radius-md);
}

.chart-tab {
    flex: 1;
    padding: 0.6rem 0.75rem;
    border-radius: var(--radius-sm);
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    transition: all var(--transition-fast);
}

.chart-tab.active {
    background: var(--primary);
    color: white;
    box-shadow: var(--shadow-sm);
}

.chart-tab:hover:not(.active) {
    background: color-mix(in srgb, var(--primary) 10%, transparent);
    color: var(--text-primary);
}

.chart-plot {
    width: 100%;
    height: 350px;
    border-radius: var(--radius-md);
    overflow: hidden;
}

.chart-plot.stacked {
    height: 240px;
}

.chart-caption {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin: 0.7rem 0 0.35rem;
}

.chart-caption:first-child {
    margin-top: 0;
}

.tag-pv, .tag-mv, .tag-err {
    font-size: 0.58rem;
    font-weight: 700;
    letter-spacing: 0.05em;
    padding: 0.1rem 0.4rem;
    border-radius: 999px;
    text-transform: uppercase;
}

.tag-pv {
    background: color-mix(in srgb, var(--primary) 15%, transparent);
    color: var(--primary);
    border: 1px solid color-mix(in srgb, var(--primary) 35%, transparent);
}

.tag-mv {
    background: color-mix(in srgb, var(--primary) 15%, transparent);
    color: var(--primary);
    border: 1px solid color-mix(in srgb, var(--primary) 35%, transparent);
}

.tag-err {
    background: color-mix(in srgb, var(--danger-light) 15%, transparent);
    color: var(--danger);
    border: 1px solid color-mix(in srgb, var(--danger-light) 35%, transparent);
}

/* ============================================
   METRICS
   ============================================ */

.metrics-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
    gap: 0.75rem;
    margin-top: 1rem;
}

.metric-card {
    background: var(--bg-surface);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-md);
    padding: 0.75rem;
    text-align: center;
    transition: all var(--transition-fast);
}

.metric-card:hover {
    border-color: var(--primary);
    transform: translateY(-2px);
}

.metric-label {
    font-size: 0.65rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    margin-bottom: 0.35rem;
}

.metric-value {
    font-size: 1rem;
    font-weight: 700;
    background: var(--gradient-primary);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    font-family: 'JetBrains Mono', 'Courier New', monospace;
}

/* ============================================
   FORMULA & INFO BOXES
   ============================================ */

.formula-box {
    background: color-mix(in srgb, var(--primary) 5%, transparent);
    border: 1px solid color-mix(in srgb, var(--primary) 20%, transparent);
    border-radius: var(--radius-md);
    padding: 0.75rem;
    text-align: center;
    font-family: 'JetBrains Mono', 'Courier New', monospace;
    font-size: 0.8rem;
    color: var(--primary-light);
    line-height: 1.8;
}

.formula-box .formula-label {
    font-family: 'Inter', sans-serif;
    font-size: 0.65rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
    display: block;
    margin-bottom: 0.4rem;
}

.info-box {
    background: color-mix(in srgb, var(--primary) 5%, transparent);
    border: 1px solid color-mix(in srgb, var(--primary) 20%, transparent);
    border-radius: var(--radius-md);
    padding: 0.75rem;
    font-size: 0.8rem;
    color: var(--text-secondary);
    line-height: 1.7;
}

.info-box strong {
    color: var(--primary-light);
}

/* Status Badge */
.status-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.4rem 0.9rem;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 600;
}

.status-badge.overdamped {
    background: color-mix(in srgb, var(--primary) 15%, transparent);
    color: var(--primary);
    border: 1px solid color-mix(in srgb, var(--primary) 30%, transparent);
}

.status-badge.underdamped {
    background: color-mix(in srgb, var(--warning) 15%, transparent);
    color: var(--warning);
    border: 1px solid color-mix(in srgb, var(--warning) 30%, transparent);
}

.status-badge.critical {
    background: color-mix(in srgb, var(--success) 15%, transparent);
    color: var(--success);
    border: 1px solid color-mix(in srgb, var(--success) 30%, transparent);
}

/* ============================================
   FOOTER
   ============================================ */

.footer {
    text-align: center;
    padding: 2rem 1.5rem;
    color: var(--text-muted);
    font-size: 0.85rem;
    border-top: 1px solid var(--border);
    background: var(--bg-secondary);
}

/* ============================================
   RESPONSIVE - MOBILE
   ============================================ */

@media (max-width: 1024px) {
    .page-layout {
        grid-template-columns: 1fr;
    }

    .control-panel {
        position: static;
        max-height: none;
    }

    .hero {
        flex-direction: column;
        text-align: center;
        padding-top: 5rem;
        gap: 2rem;
        min-height: auto;
    }

    .hero h1 {
        font-size: 2.5rem;
    }

    .hero-subtitle {
        margin-left: auto;
        margin-right: auto;
    }

    .hero-stats {
        justify-content: center;
    }

    .hero-visual {
        display: none;
    }
}

@media (max-width: 768px) {
    .navbar {
        padding: 0.75rem 1rem;
    }

    .nav-links {
        display: none;
        position: absolute;
        top: 100%;
        left: 0;
        right: 0;
        background: var(--bg-nav);
        backdrop-filter: blur(20px);
        flex-direction: column;
        padding: 0.5rem;
        border-bottom: 1px solid var(--border);
        box-shadow: var(--shadow-lg);
    }

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

    .nav-links a {
        padding: 0.75rem 1rem;
    }

    .mobile-menu-btn {
        display: block;
        /* push the menu button and the theme switch together to the right,
           instead of letting space-between strand the menu mid-bar */
        margin-left: auto;
    }

    .hero h1 {
        font-size: 2rem;
    }

    .hero-stats {
        flex-direction: column;
        gap: 1rem;
    }

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

    .page-header h1 {
        font-size: 1.25rem;
    }

    .chart-plot {
        height: 280px;
    }

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

    .sim-controls {
        flex-wrap: wrap;
    }

    .run-pause-btn {
        width: 100%;
    }

    .speed-controls {
        width: 100%;
    }
}

@media (max-width: 480px) {
    .hero h1 {
        font-size: 1.75rem;
    }

    .section-title {
        font-size: 1.5rem;
    }

    .chart-tabs {
        flex-wrap: wrap;
    }

    .chart-tab {
        flex: none;
        min-width: calc(50% - 0.25rem);
    }

    .metrics-row {
        grid-template-columns: 1fr 1fr;
    }

    .metric-card {
        padding: 0.5rem;
    }

    .metric-value {
        font-size: 0.85rem;
    }
}

/* ============================================
   CSTR THERMAL RUNAWAY
   ============================================ */

#cstr-svg {
    width: 100%;
    height: auto;
    max-height: 300px;
}

#cstr-agitator {
    transform-box: view-box;
    transform-origin: 200px 285px;
    animation: cstr-spin 2s linear infinite;
}

@keyframes cstr-spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

.solve-btn {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.7rem 1rem;
    border-radius: var(--radius-md);
    border: 1px solid color-mix(in srgb, var(--primary) 40%, transparent);
    background: color-mix(in srgb, var(--primary) 12%, transparent);
    color: var(--primary-light);
    font-size: 0.85rem;
    font-weight: 700;
    cursor: pointer;
    transition: all var(--transition-normal);
}

.solve-btn:hover {
    background: var(--primary);
    color: var(--on-primary);
    box-shadow: var(--shadow-glow);
    transform: translateY(-1px);
}

.solve-btn i {
    font-size: 0.95rem;
}

.select-control {
    width: 100%;
    padding: 0.5rem 0.6rem;
    border-radius: var(--radius-sm);
    background: var(--bg-surface);
    border: 1px solid var(--border);
    color: var(--text-primary);
    font-family: 'Inter', sans-serif;
    font-size: 0.78rem;
    cursor: pointer;
    transition: border-color var(--transition-fast);
}

.select-control:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 2px color-mix(in srgb, var(--primary) 20%, transparent);
}

.select-control option {
    background: var(--bg-card);
    color: var(--text-primary);
}

.num-input {
    width: 94px;
    text-align: center;
    background: color-mix(in srgb, var(--primary) 10%, transparent);
    border: 1px solid color-mix(in srgb, var(--primary) 25%, transparent);
    border-radius: var(--radius-sm);
    color: var(--primary-light);
    font-family: 'JetBrains Mono', 'Courier New', monospace;
    font-size: 0.75rem;
    font-weight: 600;
    padding: 0.22rem 0.3rem;
    transition: border-color var(--transition-fast);
}

.num-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 2px color-mix(in srgb, var(--primary) 20%, transparent);
}

.num-input::-webkit-outer-spin-button,
.num-input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.num-input[type=number] {
    -moz-appearance: textfield;
}

.check-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.8rem;
    color: var(--text-secondary);
    cursor: pointer;
    margin-bottom: 0.5rem;
    user-select: none;
}

.check-row input[type="checkbox"] {
    width: 16px;
    height: 16px;
    flex: none;
    accent-color: var(--primary);
    cursor: pointer;
}

.solver-status {
    margin-top: 0.6rem;
    padding: 0.55rem 0.65rem;
    background: var(--bg-overlay);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-sm);
    font-family: 'JetBrains Mono', 'Courier New', monospace;
    font-size: 0.66rem;
    line-height: 1.7;
    color: var(--text-secondary);
    word-break: break-word;
}

.solver-status strong {
    color: var(--primary-light);
}

.readout-row {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-top: 0.6rem;
}

.readout-chip {
    flex: 1 1 auto;
    min-width: 76px;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 0.4rem 0.5rem;
    background: var(--bg-surface);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-sm);
    transition: border-color var(--transition-fast);
}

.readout-chip:hover {
    border-color: var(--primary);
}

.rc-label {
    font-size: 0.58rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
}

.rc-value {
    font-family: 'JetBrains Mono', 'Courier New', monospace;
    font-size: 0.82rem;
    font-weight: 700;
    color: var(--primary-light);
}

/* Hub node for CSTR */
.node-cstr {
    top: 42%;
    left: 0;
    animation-delay: -1s;
}

.node-cstrctl {
    top: 42%;
    right: 0;
    animation-delay: -3s;
}

.node-cascade {
    top: 10%;
    left: 0;
    animation-delay: -5s;
}

.node-split {
    top: 10%;
    right: 0;
    animation-delay: -7s;
}

/* Open/Closed loop mode tabs + dual PID sections */
.mode-tabs {
    display: inline-flex;
    gap: 0.4rem;
    margin-top: 0.7rem;
}

.mode-tab {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.4rem 0.9rem;
    border-radius: 999px;
    font-size: 0.78rem;
    font-weight: 600;
    text-decoration: none;
    color: var(--text-secondary);
    background: var(--bg-surface);
    border: 1px solid var(--border);
    transition: all var(--transition-fast);
}

.mode-tab:hover {
    border-color: var(--primary);
    color: var(--text-primary);
}

.mode-tab.active {
    background: var(--primary);
    border-color: var(--primary);
    color: var(--on-primary);
    box-shadow: 0 0 12px var(--primary-glow);
}

.pid-temp-section {
    border-left: 3px solid color-mix(in srgb, var(--danger) 60%, transparent);
    padding-left: 0.75rem;
}

.pid-conc-section {
    border-left: 3px solid color-mix(in srgb, var(--primary) 60%, transparent);
    padding-left: 0.75rem;
}

.pid-temp-section h3 {
    color: var(--danger);
}

.pid-conc-section h3 {
    color: var(--primary);
}

#cstrc-svg {
    width: 100%;
    height: auto;
    max-height: 320px;
}

#cstrc-agitator {
    transform-box: view-box;
    transform-origin: 335px 285px;
    animation: cstr-spin 2s linear infinite;
}

/* ============================================
   ANIMATIONS
   ============================================ */

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

.example-card {
    animation: fadeIn 0.5s ease forwards;
}

.example-card:nth-child(1) { animation-delay: 0.1s; }
.example-card:nth-child(2) { animation-delay: 0.2s; }
.example-card:nth-child(3) { animation-delay: 0.3s; }

/* Scrollbar styling */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg-primary);
}

::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* ============================================
   INSTITUTION BRANDING
   ============================================ */

.nav-institution {
    display: flex;
    flex-direction: column;
    line-height: 1.2;
    margin-right: auto;
    margin-left: 0.85rem;
    padding-left: 0.85rem;
    border-left: 1px solid var(--border);
}

.nav-institution .ni-lab {
    font-size: 0.82rem;
    font-weight: 800;
    color: var(--primary-light);
    letter-spacing: 0.02em;
}

.nav-institution .ni-school {
    font-size: 0.6rem;
    color: var(--text-muted);
    letter-spacing: 0.01em;
}

.institution-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.6rem 1.25rem;
    margin-bottom: 1.25rem;
    background: linear-gradient(135deg, color-mix(in srgb, var(--primary) 12%, transparent), color-mix(in srgb, var(--primary) 12%, transparent));
    border: 1px solid color-mix(in srgb, var(--primary) 35%, transparent);
    border-radius: 999px;
    box-shadow: 0 0 24px color-mix(in srgb, var(--primary) 15%, transparent);
}

.institution-badge > i {
    font-size: 1.5rem;
    color: var(--primary-light);
}

.institution-badge .inst-text {
    text-align: left;
    display: flex;
    flex-direction: column;
    line-height: 1.25;
}

.institution-badge .inst-lab {
    font-weight: 800;
    font-size: 1rem;
    color: var(--text-primary);
    letter-spacing: 0.02em;
}

.institution-badge .inst-school {
    font-size: 0.72rem;
    color: var(--text-secondary);
}

.page-institution {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--primary-light);
    background: color-mix(in srgb, var(--primary) 8%, transparent);
    border: 1px solid color-mix(in srgb, var(--primary) 25%, transparent);
    border-radius: 999px;
    padding: 0.3rem 0.85rem;
    margin-bottom: 0.6rem;
}

.footer-inst {
    color: var(--text-secondary);
    margin-bottom: 0.4rem;
}

.footer-inst strong {
    color: var(--primary-light);
}

.footer-inst i {
    color: var(--primary-light);
    margin-right: 0.35rem;
}

@media (max-width: 900px) {
    .nav-institution {
        display: none;
    }
}

@media (max-width: 480px) {
    .institution-badge {
        padding: 0.5rem 0.9rem;
        gap: 0.5rem;
    }
    .institution-badge > i {
        font-size: 1.15rem;
    }
    .institution-badge .inst-lab {
        font-size: 0.85rem;
    }
    .institution-badge .inst-school {
        font-size: 0.62rem;
    }
    .page-institution {
        font-size: 0.68rem;
    }
}

/* ============================================
   CENTRAL HUB / CONSTELLATION
   ============================================ */

.hub-section {
    padding: 1rem 1.5rem 4rem;
    max-width: 1000px;
    margin: 0 auto;
}

.hub {
    position: relative;
    width: 100%;
    max-width: 860px;
    height: 620px;
    margin: 0 auto;
}

.hub-lines {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 1;
    overflow: visible;
}

.hub-lines line {
    stroke: color-mix(in srgb, var(--primary) 28%, transparent);
    stroke-width: 2;
    stroke-dasharray: 8 8;
    animation: hub-dash 30s linear infinite;
}

@keyframes hub-dash {
    to { stroke-dashoffset: -400; }
}

.hub-lines .flow-dot {
    fill: var(--primary);
    filter: drop-shadow(0 0 6px color-mix(in srgb, var(--primary) 90%, transparent));
}

/* Central core */
.hub-core {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 170px;
    height: 170px;
    border-radius: 50%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.35rem;
    text-align: center;
    background: radial-gradient(circle at 35% 30%, var(--bg-card) 0%, var(--bg-primary) 75%);
    border: 2px solid color-mix(in srgb, var(--primary) 50%, transparent);
    box-shadow: 0 0 50px color-mix(in srgb, var(--primary) 35%, transparent), inset 0 0 30px color-mix(in srgb, var(--primary) 12%, transparent);
    z-index: 3;
    animation: core-float 7s ease-in-out infinite;
}

@keyframes core-float {
    0%, 100% { transform: translate(-50%, -50%) scale(1); }
    50% { transform: translate(-50%, -50%) scale(1.035); }
}

.hub-core::before,
.hub-core::after {
    content: '';
    position: absolute;
    inset: -10px;
    border-radius: 50%;
    border: 1px solid color-mix(in srgb, var(--primary) 45%, transparent);
    animation: hub-ring 3.5s ease-out infinite;
}

.hub-core::after {
    animation-delay: 1.75s;
}

@keyframes hub-ring {
    0% { transform: scale(0.85); opacity: 0.9; }
    100% { transform: scale(1.7); opacity: 0; }
}

.hub-core i {
    font-size: 2.1rem;
    background: var(--gradient-primary);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.hub-core span {
    font-weight: 800;
    font-size: 1rem;
    letter-spacing: 0.04em;
}

.hub-core small {
    color: var(--text-muted);
    font-size: 0.66rem;
    text-transform: uppercase;
    letter-spacing: 0.12em;
}

/* Floating nodes */
.node-wrap {
    position: absolute;
    z-index: 2;
    animation: float 6s ease-in-out infinite;
}

.node-pid {
    top: 0;
    left: 50%;
    margin-left: -120px;
    animation-delay: 0s;
}

.node-fopdt {
    bottom: 0;
    left: 0;
    animation-delay: -2s;
}

.node-second {
    bottom: 0;
    right: 0;
    animation-delay: -4s;
}

.hub-node {
    display: flex;
    align-items: center;
    gap: 0.85rem;
    width: 240px;
    padding: 1rem 1.1rem;
    background: var(--bg-nav);
    backdrop-filter: blur(14px);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    text-decoration: none;
    color: var(--text-primary);
    box-shadow: var(--shadow-md);
    transition: transform 0.3s ease, border-color 0.3s ease, box-shadow 0.3s ease;
}

.hub-node:hover {
    transform: translateY(-6px) scale(1.06);
    border-color: var(--primary);
    box-shadow: var(--shadow-glow);
}

.hub-node-icon {
    flex: none;
    width: 46px;
    height: 46px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--on-primary);
    font-size: 1.2rem;
    box-shadow: var(--shadow-sm);
}

.hub-node-body h3 {
    font-size: 0.95rem;
    font-weight: 700;
    margin-bottom: 0.1rem;
}

.hub-node-body p {
    font-size: 0.72rem;
    color: var(--text-muted);
}

.node-tags {
    display: flex;
    gap: 0.3rem;
    margin-top: 0.35rem;
    flex-wrap: wrap;
}

.node-tags span {
    font-size: 0.6rem;
    padding: 0.1rem 0.45rem;
    border-radius: 999px;
    background: var(--bg-surface);
    color: var(--text-secondary);
    border: 1px solid var(--border-light);
}

/* Hub responsive */
@media (max-width: 900px) {
    .hub {
        height: 560px;
    }
    .hub-node {
        width: 210px;
    }
    .node-pid {
        margin-left: -105px;
    }
}

@media (max-width: 768px) {
    .hub-section {
        padding: 0.5rem 1rem 3rem;
    }
    .hub {
        height: auto;
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 1rem;
    }
    .hub-lines {
        display: none;
    }
    .hub-core {
        position: relative;
        top: auto;
        left: auto;
        transform: none;
        margin: 0 auto 0.5rem;
        animation: none;
    }
    .node-wrap {
        position: relative;
        top: auto;
        left: auto;
        right: auto;
        bottom: auto;
        margin: 0;
        animation: none;
    }
    .hub-node {
        width: 100%;
        max-width: 360px;
    }
    .hub-node:hover {
        transform: translateY(-4px) scale(1.02);
    }
    .hero {
        padding-top: 5.5rem;
    }
}

/* ============================================
   PARAMETER / EQUATION DOCUMENTATION
   ============================================ */

.docs-section {
    padding: 2.5rem 1.5rem 3rem;
    max-width: 1400px;
    margin: 0 auto;
}

.docs-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
    gap: 1.25rem;
    margin-top: 1.5rem;
}

.docs-card {
    background: var(--gradient-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.25rem 1.4rem;
}

.docs-card h3 {
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--primary-light);
    margin-bottom: 0.85rem;
}

.docs-card p {
    font-size: 0.82rem;
    color: var(--text-secondary);
    line-height: 1.7;
    margin-bottom: 0.6rem;
}

.docs-card strong {
    color: var(--text-primary);
}

.equation {
    font-family: 'Cambria Math', 'Latin Modern Math', Georgia, serif;
    font-size: 0.95rem;
    line-height: 2.05;
    color: var(--text-primary);
    background: var(--bg-code);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-md);
    padding: 0.8rem 1rem;
    margin-bottom: 0.75rem;
    overflow-x: auto;
}

.equation:last-child {
    margin-bottom: 0;
}

.equation .eq-label {
    display: block;
    font-family: 'Inter', sans-serif;
    font-size: 0.66rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
    margin-bottom: 0.35rem;
}

.equation .eq-note {
    display: block;
    font-family: 'Inter', sans-serif;
    font-size: 0.72rem;
    color: var(--text-muted);
    margin-top: 0.35rem;
}

.param-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.78rem;
}

.param-table th,
.param-table td {
    text-align: left;
    padding: 0.42rem 0.5rem;
    border-bottom: 1px solid var(--border-light);
    vertical-align: top;
}

.param-table th {
    color: var(--text-muted);
    font-size: 0.64rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 600;
}

.param-table td.sym {
    font-family: 'JetBrains Mono', 'Courier New', monospace;
    color: var(--primary-light);
    white-space: nowrap;
}

.param-table td.def {
    font-family: 'JetBrains Mono', 'Courier New', monospace;
    color: var(--text-secondary);
    white-space: nowrap;
}

.param-table tr:last-child td {
    border-bottom: none;
}

.badge-eq {
    display: inline-block;
    font-size: 0.62rem;
    font-weight: 700;
    padding: 0.08rem 0.4rem;
    border-radius: 999px;
    margin-left: 0.35rem;
    vertical-align: middle;
}

.badge-eq.two-dof { background: color-mix(in srgb, var(--primary) 15%, transparent); color: var(--primary); border: 1px solid color-mix(in srgb, var(--primary) 35%, transparent); }
.badge-eq.windup { background: color-mix(in srgb, var(--warning) 15%, transparent); color: var(--warning); border: 1px solid color-mix(in srgb, var(--warning) 35%, transparent); }
.badge-eq.noise { background: color-mix(in srgb, var(--success) 15%, transparent); color: var(--success); border: 1px solid color-mix(in srgb, var(--success) 35%, transparent); }
.badge-eq.filter { background: color-mix(in srgb, var(--primary) 15%, transparent); color: var(--primary); border: 1px solid color-mix(in srgb, var(--primary) 35%, transparent); }

@media (max-width: 768px) {
    .docs-section { padding: 1.5rem 1rem 2rem; }
    .equation { font-size: 0.86rem; }
}

/* ============================================
   THEME SWITCH
   A visible two-position switch: sun (light) on the left,
   moon (dark) on the right, with a knob that slides between.
   Markup order is moon-then-sun, so the row is reversed to
   put the sun first.
   ============================================ */
.theme-toggle {
    position: relative;
    display: inline-flex;
    flex-direction: row-reverse;
    align-items: center;
    justify-content: space-between;
    width: 62px;
    height: 32px;
    padding: 0 9px;
    flex-shrink: 0;
    /* The track is tinted with whichever mode is active, so the knob always
       has a coloured ground to sit on rather than white-on-white. */
    border: 1px solid color-mix(in srgb, var(--warning) 35%, var(--border));
    border-radius: 999px;
    background: color-mix(in srgb, var(--warning) 16%, var(--bg-card));
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    transition: background-color var(--transition-normal), border-color var(--transition-normal);
}

/* the sliding knob */
.theme-toggle::before {
    content: '';
    position: absolute;
    top: 3px;
    left: 3px;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: var(--toggle-knob);
    box-shadow: var(--toggle-knob-shadow);
    transition: transform var(--transition-normal), background-color var(--transition-normal);
}

[data-theme="dark"] .theme-toggle {
    border-color: color-mix(in srgb, var(--primary) 45%, var(--border));
    background: color-mix(in srgb, var(--primary) 22%, var(--bg-card));
}

[data-theme="dark"] .theme-toggle::before {
    transform: translateX(30px);
}

/* Both icons stay visible; the active one is highlighted */
.theme-toggle .icon-sun,
.theme-toggle .icon-moon {
    position: relative;
    z-index: 1;
    display: inline-block;
    font-size: 0.72rem;
    line-height: 1;
    opacity: 0.42;
    transition: color var(--transition-normal), opacity var(--transition-normal);
}

/* the side the knob currently sits on is the active one */
.theme-toggle .icon-sun { color: var(--warning); opacity: 1; }
.theme-toggle .icon-moon { color: var(--text-secondary); }

[data-theme="dark"] .theme-toggle .icon-sun { color: var(--text-secondary); opacity: 0.42; }
[data-theme="dark"] .theme-toggle .icon-moon { color: var(--primary-light); opacity: 1; }

.theme-toggle:hover {
    border-color: var(--border-glow);
    box-shadow: var(--shadow-glow);
}

.theme-toggle:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

/* Navbar placement — nudge the switch off the menu links */
.navbar {
    gap: 0.5rem;
}

.navbar > .theme-toggle {
    margin-left: 0.25rem;
}

/* ============================================
   THEME TRANSITION
   Scoped to surfaces that actually change colour, so we
   don't pay for a transition on every element in the tree.
   ============================================ */
body,
.navbar,
.card,
.hub-node,
.hub-core,
.equation,
.status-badge,
.tag,
.step-btn,
.solve-btn,
.mode-tab,
input,
select,
textarea {
    transition: background-color var(--transition-normal),
                border-color var(--transition-normal),
                color var(--transition-normal);
}

/* ============================================
   CASCADE / SPLIT-RANGE MODE SELECTOR
   (shares the .speed-btn visual language)
   ============================================ */

.mode-controls {
    display: flex;
    gap: 0.35rem;
    margin-top: 0.75rem;
    flex-wrap: wrap;
}

.mode-controls > .mode-label {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
    display: block;
    margin-bottom: 0.5rem;
    width: 100%;
}

.mode-btn {
    flex: 1;
    min-width: 7rem;
    padding: 0.5rem 0.4rem;
    border-radius: var(--radius-sm);
    font-size: 0.75rem;
    font-weight: 700;
    cursor: pointer;
    border: 1px solid var(--border);
    background: var(--bg-surface);
    color: var(--text-secondary);
    transition: all var(--transition-fast);
    font-family: 'JetBrains Mono', 'Courier New', monospace;
}

.mode-btn:hover {
    border-color: var(--primary);
    color: var(--text-primary);
}

.mode-btn.active {
    background: var(--primary);
    border-color: var(--primary);
    color: white;
    box-shadow: 0 0 10px var(--primary-glow);
}

/* A loop that is bypassed by the current mode (e.g. the inner jacket loop in
   single-loop mode) is dimmed but still readable. */
.panel-section.is-bypassed {
    opacity: 0.45;
    filter: saturate(0.4);
}

.panel-section.is-bypassed::after {
    content: 'bypassed in this mode';
    display: block;
    margin-top: 0.6rem;
    font-size: 0.65rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--warning, #fbbf24);
    font-family: 'JetBrains Mono', 'Courier New', monospace;
}

@media (prefers-reduced-motion: reduce) {
    .theme-toggle::before,
    body,
    .navbar,
    .card,
    .hub-node,
    .hub-core,
    .equation,
    .status-badge,
    .tag,
    .step-btn,
    .solve-btn,
    .mode-tab,
    .mode-btn,
    input,
    select,
    textarea {
        transition: none;
    }
}
