/* ==============================================
   Systems Manual Style (IBM Graphic Design Guide era, 1969-1987)
   ============================================== */

/* Design Tokens */
:root {
    /* Colors - Paper & Ink (refined for better contrast) */
    --paper: #fafafa;
    --paper-warm: #f8f8f8;
    --ink: #111113;
    --ink-muted: #27272a;
    --ink-faint: #52525b;
    --ink-subtle: #a1a1aa;

    /* Signal Colors (rare, classification only - slightly muted for elegance) */
    --sig-blue: #1d4ed8;
    --sig-red: #b91c1c;
    --sig-yellow: #a16207;
    --sig-green: #15803d;
    
    /* Signal Tints - very subtle backgrounds for signal elements */
    --tint-blue: #eff6ff;
    --tint-red: #fef2f2;
    --tint-yellow: #fefce8;
    --tint-green: #f0fdf4;

    /* Rule colors */
    --rule-primary: var(--ink);
    --rule-faint: #d4d4d8;
    --rule-subtle: #e4e4e7;

    /* Typography */
    --font-sans: ui-sans-serif, system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
    --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;

    /* Layout */
    --max-width: 880px;
    --margin-col: 44px;
    --cell-size: 22px;
    
    /* Spacing rhythm (8px base) */
    --space-xs: 4px;
    --space-sm: 8px;
    --space-md: 16px;
    --space-lg: 24px;
    --space-xl: 48px;
    --space-2xl: 80px;
}

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

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

body {
    font-family: var(--font-mono);
    font-size: 0.875rem; /* 14px - increased for readability */
    line-height: 1.75;
    background: var(--paper);
    color: var(--ink);
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    letter-spacing: -0.01em;
}

/* Typography Roles */
.label {
    font-family: var(--font-sans);
    font-size: 0.6875rem; /* 11px */
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.2em;
    color: var(--ink-faint);
}

.heading-1 {
    font-family: var(--font-sans);
    font-size: 1.75rem; /* 28px - larger, more presence */
    font-weight: 600;
    color: var(--ink);
    letter-spacing: -0.025em;
    line-height: 1.25;
}

.heading-2 {
    font-family: var(--font-sans);
    font-size: 1.375rem; /* 22px - slightly larger */
    font-weight: 600;
    color: var(--ink);
    letter-spacing: -0.02em;
    line-height: 1.3;
}

.heading-3 {
    font-family: var(--font-sans);
    font-size: 1.0625rem; /* 17px */
    font-weight: 600;
    color: var(--ink);
    margin: var(--space-sm) 0 -8px;
    letter-spacing: -0.015em;
    line-height: 1.4;
}

.data {
    font-family: var(--font-mono);
    font-size: 0.875rem; /* 14px */
    line-height: 1.7;
    color: var(--ink);
}

.data-muted {
    font-family: var(--font-mono);
    font-size: 0.875rem; /* 14px */
    line-height: 1.7;
    color: var(--ink-muted);
}

/* Rules */
.rule-primary {
    height: 2px;
    width: 100%;
    background: var(--ink);
    margin-bottom: var(--space-lg);
}

.rule-secondary {
    height: 1px;
    width: 100%;
    background: var(--ink-faint);
}

.rule-faint {
    height: 1px;
    width: 100%;
    background: var(--rule-faint);
}

/* Hairline rule for subtle divisions */
.rule-hairline {
    height: 1px;
    width: 100%;
    background: var(--rule-subtle);
}

/* 8-bar Motif */
.bars-motif {
    display: grid;
    width: 18px;
    gap: 3px;
    transition: transform 0.2s ease-out, opacity 0.2s ease-out;
}

.bar {
    height: 2px;
    background: var(--ink);
    transform-origin: left center;
    transition: transform 0.15s ease-out, opacity 0.15s ease-out;
}

/* Staggered animation for bars when becoming sticky */
.section-margin.is-sticky .bar:nth-child(1) { transition-delay: 0ms; }
.section-margin.is-sticky .bar:nth-child(2) { transition-delay: 15ms; }
.section-margin.is-sticky .bar:nth-child(3) { transition-delay: 30ms; }
.section-margin.is-sticky .bar:nth-child(4) { transition-delay: 45ms; }
.section-margin.is-sticky .bar:nth-child(5) { transition-delay: 60ms; }
.section-margin.is-sticky .bar:nth-child(6) { transition-delay: 75ms; }
.section-margin.is-sticky .bar:nth-child(7) { transition-delay: 90ms; }
.section-margin.is-sticky .bar:nth-child(8) { transition-delay: 105ms; }

/* Animation when entering sticky state */
@keyframes barSlideIn {
    from {
        transform: scaleX(0);
        opacity: 0;
    }
    to {
        transform: scaleX(1);
        opacity: 1;
    }
}

.section-margin.is-sticky .bars-motif .bar {
    animation: barSlideIn 0.25s ease-out forwards;
}

.section-margin.is-sticky .bars-motif .bar:nth-child(1) { animation-delay: 0ms; }
.section-margin.is-sticky .bars-motif .bar:nth-child(2) { animation-delay: 20ms; }
.section-margin.is-sticky .bars-motif .bar:nth-child(3) { animation-delay: 40ms; }
.section-margin.is-sticky .bars-motif .bar:nth-child(4) { animation-delay: 60ms; }
.section-margin.is-sticky .bars-motif .bar:nth-child(5) { animation-delay: 80ms; }
.section-margin.is-sticky .bars-motif .bar:nth-child(6) { animation-delay: 100ms; }
.section-margin.is-sticky .bars-motif .bar:nth-child(7) { animation-delay: 120ms; }
.section-margin.is-sticky .bars-motif .bar:nth-child(8) { animation-delay: 140ms; }

/* Section number animation */
.section-number {
    transition: opacity 0.2s ease-out, transform 0.2s ease-out;
}

.section-margin.is-sticky .section-number {
    animation: fadeSlideIn 0.3s ease-out 0.1s forwards;
    opacity: 0;
}

@keyframes fadeSlideIn {
    from {
        opacity: 0;
        transform: translateY(-4px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Layout - Manual Sheet */
.manual-page {
    min-height: 100vh;
    background: var(--paper);
}

.manual-sheet {
    max-width: var(--max-width);
    margin: 0 auto;
    padding: var(--space-2xl) var(--space-xl);
}

.manual-grid {
    display: grid;
    grid-template-columns: var(--margin-col) 1fr;
    gap: var(--space-lg);
}

/* Header */
.doc-header {
    padding-bottom: var(--space-xl);
    margin-bottom: var(--space-xl);
}

.doc-header .manual-grid {
    align-items: start;
    grid-template-columns: 60px 1fr;
}

/* Header margin device - tall registration mark */
.doc-header .section-margin {
    position: static;
    padding-top: 2px;
}

.bars-motif-tall {
    width: 36px;
    gap: 5px;
}

.bars-motif-tall .bar {
    height: 4px;
}

/* Header content area */
.doc-header-content {
    padding-left: 4px;
}

.doc-title-block {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: var(--space-xl);
}

.doc-title {
    font-family: var(--font-sans);
    font-size: 2.5rem; /* 40px - commanding presence */
    font-weight: 700;
    color: var(--ink);
    margin-top: 2px;
    letter-spacing: -0.04em;
    line-height: 1.05;
}

.doc-meta {
    text-align: right;
    flex-shrink: 0;
    padding-top: 2px;
}

.doc-id {
    font-family: var(--font-mono);
    font-size: 0.6875rem; /* 11px */
    color: var(--ink-muted);
    letter-spacing: 0.06em;
}

.doc-subtitle {
    font-family: var(--font-sans);
    font-size: 1.0625rem; /* 17px */
    color: var(--ink-muted);
    max-width: 540px;
    line-height: 1.55;
    margin-top: var(--space-lg);
}

.tech-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-top: var(--space-xl);
    font-family: var(--font-mono);
    font-size: 0.6875rem; /* 11px */
    color: var(--ink-faint);
    text-transform: uppercase;
    letter-spacing: 0.1em;
}

.tech-badge span {
    color: var(--ink);
    font-weight: 600;
}

/* Navigation */
.doc-nav {
    position: sticky;
    top: 0;
    z-index: 100;
    background: rgba(250, 250, 250, 0.97);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--rule-faint);
    margin: 0 calc(-1 * var(--space-xl));
    padding: 0 var(--space-xl);
}

.nav-inner {
    max-width: var(--max-width);
    margin: 0 auto;
    display: flex;
    overflow-x: auto;
    scrollbar-width: none;
    gap: 2px;
    scroll-behavior: smooth;
}

.nav-inner::-webkit-scrollbar {
    display: none;
}

.nav-item {
    font-family: var(--font-sans);
    font-size: 0.6875rem; /* 11px */
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--ink-subtle);
    text-decoration: none;
    padding: 14px var(--space-md);
    white-space: nowrap;
    border-bottom: 2px solid transparent;
    transition: color 0.12s ease, border-color 0.12s ease, background 0.12s ease;
}

.nav-item:hover {
    color: var(--ink);
    background: rgba(0, 0, 0, 0.02);
}

.nav-item:focus {
    outline: none;
    background: rgba(29, 78, 216, 0.05);
}

.nav-item.active {
    color: var(--ink);
    border-bottom-color: var(--ink);
    background: transparent;
}

.nav-item.active:focus,
.nav-item.active:hover {
    color: var(--ink);
    border-bottom-color: var(--ink);
    background: transparent;
}

/* Sections */
section {
    margin-bottom: var(--space-2xl);
    padding-bottom: var(--space-xl);
    scroll-margin-top: 70px;
}

/* First section needs extra top margin to clear the sticky nav */
#terminal-basics {
    margin-top: var(--space-xl);
}

section:not(:last-of-type) {
    border-bottom: 1px solid var(--rule-subtle);
}

.section-margin {
    padding-top: 2px;
    position: sticky;
    top: 60px; /* Below the sticky nav */
    align-self: start; /* Prevent grid stretching */
    height: fit-content;
}

.section-number {
    font-family: var(--font-mono);
    font-size: 0.875rem; /* 14px - more prominent */
    color: var(--ink);
    margin-top: var(--space-md);
    font-weight: 700;
    letter-spacing: 0.03em;
    /* Creates a strong visual anchor */
}

/* Section number with decorative bar */
.section-number::before {
    content: '';
    display: block;
    width: 20px;
    height: 2px;
    background: var(--ink);
    margin-bottom: 6px;
}

.section-header {
    margin-bottom: var(--space-lg);
}

.section-header .label {
    margin-bottom: 8px;
    display: inline-block;
}

.section-content {
    display: flex;
    flex-direction: column;
    gap: var(--space-lg);
}

.section-content p {
    font-family: var(--font-mono);
    font-size: 0.875rem; /* 14px - improved readability */
    line-height: 1.8;
    color: var(--ink-muted);
    max-width: 640px;
}

.section-content p strong {
    color: var(--ink);
    font-weight: 600;
}

.section-content code {
    background: white;
    border: 1px solid var(--rule-faint);
    padding: 0.1em 0.45em;
    font-size: 0.875em;
    border-radius: 2px;
}

/* Reset code styling inside pre blocks (needs higher specificity than .section-content code) */
.section-content pre code,
.code-block code {
    background: transparent;
    border: none;
    padding: 0;
    font-size: inherit;
    border-radius: 0;
}

/* Demo Container - Editorial style with refined presence */
.demo-container {
    border: 1px solid var(--ink-faint);
    border-top: 2px solid var(--ink);
    margin: var(--space-lg) 0;
    background: white;
}

.demo-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px var(--space-lg);
    border-bottom: 1px solid var(--rule-faint);
    background: var(--paper);
}

.demo-title {
    font-family: var(--font-sans);
    font-size: 0.75rem; /* 12px */
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.14em;
    color: var(--ink);
}

.demo-controls {
    display: flex;
    gap: 6px;
    align-items: center;
}

.demo-btn {
    font-family: var(--font-mono);
    font-size: 0.75rem; /* 12px */
    color: var(--ink-muted);
    background: white;
    border: 1px solid var(--rule-faint);
    padding: 6px 14px;
    cursor: pointer;
    transition: all 0.12s ease;
    position: relative;
}

.demo-btn:hover {
    border-color: var(--ink);
    color: var(--ink);
    background: var(--paper);
}

.demo-btn:focus {
    outline: none;
    border-color: var(--sig-blue);
    box-shadow: 0 0 0 2px rgba(29, 78, 216, 0.15);
}

.demo-btn.active {
    background: var(--ink);
    border-color: var(--ink);
    color: white;
}

.demo-btn:active {
    transform: translateY(1px);
}

.demo-body {
    padding: var(--space-lg);
    background: white;
}

/* View Mode Toggle */
.view-mode-toggle {
    display: flex;
    border: 1px solid var(--rule-faint);
    overflow: hidden;
}

.view-mode-btn {
    font-family: var(--font-mono);
    font-size: 0.6875rem; /* 11px */
    color: var(--ink-faint);
    background: white;
    border: none;
    padding: 5px 12px;
    cursor: pointer;
    transition: all 0.15s ease;
}

.view-mode-btn:hover {
    color: var(--ink);
}

.view-mode-btn.active {
    background: var(--ink);
    color: white;
}

/* Terminal Grid */
.terminal-grid {
    display: inline-grid;
    gap: 1px;
    background: var(--rule-faint);
    padding: 1px;
    border: 1px solid var(--rule-faint);
}

.terminal-cell {
    width: var(--cell-size);
    height: var(--cell-size);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem; /* 12px */
    font-weight: 500;
    background: white;
    cursor: pointer;
    transition: background 0.08s ease, transform 0.08s ease;
    position: relative;
}

.terminal-cell:hover {
    background: #f0f4f8;
    transform: scale(1.05);
    z-index: 1;
}

.terminal-cell.highlight {
    outline: 2px solid var(--sig-blue);
    outline-offset: -1px;
    z-index: 1;
    background: var(--tint-blue);
}

.terminal-cell.selected {
    outline: 2px solid var(--sig-green);
    outline-offset: -1px;
    z-index: 2;
    background: var(--tint-green);
}

.terminal-cell.changed {
    animation: cellChange 0.4s ease-out;
}

@keyframes cellChange {
    0% { 
        background: var(--sig-green); 
        transform: scale(1.1);
    }
    100% { 
        background: white; 
        transform: scale(1);
    }
}

/* Cell Detail Panel */
.cell-detail-panel {
    margin-top: var(--space-lg);
    padding: var(--space-lg);
    border: 1px solid var(--rule-faint);
    background: var(--paper);
    display: none;
    animation: fadeIn 0.2s ease-out;
}

.cell-detail-panel.visible {
    display: block;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.cell-detail-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--space-md);
    padding-bottom: var(--space-sm);
    border-bottom: 1px solid var(--rule-faint);
}

.cell-detail-title {
    font-family: var(--font-sans);
    font-size: 0.75rem; /* 12px */
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--ink-faint);
}

.cell-detail-coords {
    font-family: var(--font-mono);
    font-size: 0.8125rem; /* 13px */
    color: var(--sig-blue);
    font-weight: 600;
}

.cell-detail-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
}

@media (max-width: 600px) {
    .cell-detail-grid {
        grid-template-columns: 1fr;
    }
}

.cell-detail-field {
    padding: 14px var(--space-md);
    background: white;
    border: 1px solid var(--rule-faint);
}

.cell-detail-label {
    font-family: var(--font-sans);
    font-size: 0.6875rem; /* 11px */
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--ink-subtle);
    margin-bottom: 6px;
}

.cell-detail-value {
    font-family: var(--font-mono);
    font-size: 0.8125rem; /* 13px */
    color: var(--ink);
    display: flex;
    align-items: center;
    gap: var(--space-sm);
}

.cell-detail-color {
    width: 20px;
    height: 20px;
    border: 1px solid var(--rule-faint);
}

/* Memory Layout */
.memory-layout {
    margin-top: var(--space-md);
    padding: var(--space-md);
    border: 1px solid var(--rule-faint);
    background: var(--paper);
}

.memory-layout-title {
    font-family: var(--font-sans);
    font-size: 0.6875rem; /* 11px */
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--ink-subtle);
    margin-bottom: var(--space-sm);
}

.memory-arrays {
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
}

.memory-array-row {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
}

.memory-array-label {
    width: 54px;
    font-family: var(--font-mono);
    font-size: 0.75rem; /* 12px */
    color: var(--ink-faint);
    text-align: right;
    font-weight: 500;
}

.memory-array-cells {
    display: flex;
    gap: 3px;
}

.memory-array-cell {
    width: 34px;
    height: 26px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: var(--font-mono);
    font-size: 0.6875rem; /* 11px */
    background: white;
    border: 1px solid var(--rule-faint);
    transition: all 0.1s ease;
    font-weight: 500;
}

.memory-array-cell.highlight {
    border-color: var(--sig-blue);
    background: var(--tint-blue);
}

.memory-array-cell.char { color: var(--sig-blue); }
.memory-array-cell.fg { color: var(--sig-green); }
.memory-array-cell.bg { color: var(--sig-yellow); }
.memory-array-cell.attr { color: var(--sig-red); }

/* Flow Diagrams */
.diagram {
    border: 1px solid var(--rule-faint);
    padding: var(--space-xl);
    margin: var(--space-lg) 0;
    overflow-x: auto;
    background: var(--paper);
}

.flow-diagram {
    display: flex;
    align-items: center;
    gap: 12px;
    justify-content: center;
    flex-wrap: wrap;
}

.flow-box {
    padding: 14px var(--space-lg);
    border: 1px solid var(--rule-faint);
    text-align: center;
    min-width: 120px;
    background: white;
    transition: all 0.12s ease;
}

.flow-box:hover {
    border-color: var(--ink);
    transform: translateY(-2px);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}

.flow-box-title {
    font-family: var(--font-sans);
    font-size: 0.6875rem; /* 11px */
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--ink-subtle);
    margin-bottom: 4px;
}

.flow-box-content {
    font-family: var(--font-mono);
    font-size: 0.875rem; /* 14px */
    color: var(--ink);
    font-weight: 600;
}

.flow-arrow {
    color: var(--ink-subtle);
    font-size: 1.125rem;
}

/* Code Blocks */
.code-block {
    border: 1px solid var(--rule-faint);
    border-left: 3px solid var(--sig-blue);
    margin: var(--space-lg) 0;
    overflow: hidden;
    background: white;
}

.code-header {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    padding: 10px var(--space-md);
    border-bottom: 1px solid var(--rule-faint);
    background: var(--paper);
}

.code-lang {
    font-family: var(--font-sans);
    font-size: 0.625rem; /* 10px */
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: white;
    padding: 4px 10px;
    background: var(--sig-blue);
}

.code-header a {
    font-family: var(--font-mono);
    font-size: 0.75rem; /* 12px */
    color: var(--ink-subtle);
    text-decoration: none;
    transition: color 0.15s ease;
}

.code-header a:hover {
    color: var(--sig-blue);
}

pre {
    padding: var(--space-lg);
    overflow-x: auto;
    font-size: 0.8125rem; /* 13px - better readability */
    line-height: 1.75;
    background: white;
    margin: 0;
}

code {
    font-family: var(--font-mono);
}

/* Syntax Highlighting - IBM palette colors */
.token-keyword { color: var(--sig-blue); font-weight: 500; }
.token-string { color: var(--sig-green); }
.token-number { color: var(--sig-yellow); }
.token-comment { color: var(--ink-subtle); font-style: italic; }
.token-type { color: var(--sig-blue); font-weight: 500; opacity: 0.85; }
.token-const { color: var(--ink); font-weight: 600; }
.token-fn { color: var(--ink-muted); font-weight: 600; }

/* Byte Display */
.byte-display {
    display: flex;
    flex-direction: column;
    gap: var(--space-lg);
}

.byte-row {
    display: flex;
    align-items: center;
    gap: var(--space-lg);
}

.byte-label {
    width: 100px;
    font-family: var(--font-sans);
    font-size: 0.75rem; /* 12px */
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--ink-faint);
    text-align: right;
}

.bytes {
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
}

.byte {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    font-family: var(--font-mono);
    font-size: 0.75rem; /* 12px */
    font-weight: 600;
    border: 1px solid var(--rule-faint);
    background: white;
    transition: transform 0.1s ease;
}

.byte:hover {
    transform: scale(1.05);
}

.byte.esc {
    background: var(--ink);
    color: white;
    border-color: var(--ink);
}

.byte.bracket {
    background: var(--sig-blue);
    color: white;
    border-color: var(--sig-blue);
}

.byte.param {
    background: var(--sig-yellow);
    color: white;
    border-color: var(--sig-yellow);
}

.byte.command {
    background: var(--sig-green);
    color: white;
    border-color: var(--sig-green);
}

.byte.text {
    background: var(--paper);
    border-color: var(--rule-faint);
}

.byte.flag {
    background: var(--sig-red);
    color: white;
    border-color: var(--sig-red);
}

.byte-explanation {
    font-family: var(--font-mono);
    font-size: 0.8125rem; /* 13px */
    color: var(--ink-muted);
    line-height: 1.6;
}

/* Struct Visualization */
.struct-viz {
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-width: 580px;
}

.struct-field {
    display: flex;
    border: 1px solid var(--rule-faint);
    background: white;
}

.field-name {
    width: 100px;
    padding: 14px var(--space-md);
    background: var(--paper);
    border-right: 1px solid var(--rule-faint);
    font-family: var(--font-mono);
    font-size: 0.875rem; /* 14px */
    font-weight: 600;
    color: var(--sig-blue);
}

.field-value {
    flex: 1;
    padding: 14px var(--space-md);
    font-family: var(--font-mono);
    font-size: 0.8125rem; /* 13px */
    color: var(--ink-muted);
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    line-height: 1.5;
}

.field-type {
    font-family: var(--font-sans);
    font-size: 0.5625rem; /* 9px */
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--ink-subtle);
    padding: 3px 8px;
    background: var(--paper);
    border: 1px solid var(--rule-faint);
}

/* Bit Field */
.bit-labels {
    display: flex;
    gap: 3px;
    margin-bottom: 4px;
}

.bit-label {
    width: 30px;
    text-align: center;
    font-family: var(--font-mono);
    font-size: 0.6875rem; /* 11px */
    color: var(--ink-subtle);
    font-weight: 500;
}

.bit-field {
    display: flex;
    gap: 3px;
}

.bit {
    width: 30px;
    height: 34px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: var(--font-mono);
    font-size: 0.8125rem; /* 13px */
    font-weight: 600;
    border: 1px solid var(--rule-faint);
    background: white;
    cursor: pointer;
    transition: all 0.1s ease;
    user-select: none;
}

.bit:hover {
    border-color: var(--sig-blue);
    background: var(--tint-blue);
    transform: scale(1.08);
}

.bit:focus {
    outline: none;
    border-color: var(--sig-blue);
    box-shadow: 0 0 0 2px rgba(29, 78, 216, 0.2);
}

.bit.on {
    background: var(--sig-blue);
    color: white;
    border-color: var(--sig-blue);
}

.bit.on:hover {
    background: #1e3a8a; /* Darker variant of sig-blue */
    transform: scale(1.08);
}

/* ANSI Builder */
.ansi-builder {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-lg);
}

@media (max-width: 800px) {
    .ansi-builder {
        grid-template-columns: 1fr;
    }
}

.builder-panel {
    border: 1px solid var(--rule-faint);
    padding: var(--space-lg);
    background: white;
}

.builder-title {
    font-family: var(--font-sans);
    font-size: 0.75rem; /* 12px */
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--ink-faint);
    margin-bottom: var(--space-md);
    padding-bottom: var(--space-sm);
    border-bottom: 1px solid var(--rule-faint);
}

.color-picker-grid {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    gap: 6px;
    margin-bottom: var(--space-lg);
}

.color-swatch {
    aspect-ratio: 1;
    border: 2px solid transparent;
    cursor: pointer;
    transition: transform 0.1s ease, box-shadow 0.1s ease;
}

.color-swatch:hover {
    transform: scale(1.15);
    z-index: 1;
}

.color-swatch:focus {
    outline: none;
    box-shadow: 0 0 0 2px var(--sig-blue);
}

.color-swatch.selected {
    border-color: var(--ink);
    outline: 2px solid white;
    box-shadow: 0 0 0 3px var(--ink);
}

.attr-toggles {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.attr-toggle {
    font-family: var(--font-mono);
    font-size: 0.75rem; /* 12px */
    padding: 6px 14px;
    background: white;
    border: 1px solid var(--rule-faint);
    cursor: pointer;
    transition: all 0.1s ease;
    user-select: none;
}

.attr-toggle:hover {
    border-color: var(--ink);
    background: var(--paper);
}

.attr-toggle:focus {
    outline: none;
    border-color: var(--sig-blue);
    box-shadow: 0 0 0 2px rgba(29, 78, 216, 0.15);
}

.attr-toggle.active {
    background: var(--ink);
    border-color: var(--ink);
    color: white;
}

.attr-toggle.active:hover {
    background: #27272a;
}

.output-preview {
    padding: var(--space-lg);
    background: var(--paper);
    border: 1px solid var(--rule-faint);
    font-size: 1.375rem; /* 22px */
    text-align: center;
    min-height: 80px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: var(--space-md);
}

.ansi-output {
    font-family: var(--font-mono);
    font-size: 0.75rem; /* 12px */
    padding: var(--space-md);
    background: var(--ink);
    word-break: break-all;
    color: #6ee7b7; /* Soft green on dark background */
}

/* Diff Visualization */
.diff-main-area {
    display: flex;
    flex-direction: column;
    gap: var(--space-lg);
}

.diff-buffers-row {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    gap: 12px;
    align-items: start;
}

@media (max-width: 800px) {
    .diff-buffers-row {
        grid-template-columns: 1fr;
    }
}

.buffer-panel {
    border: 1px solid var(--rule-faint);
    padding: var(--space-md);
    position: relative;
    background: white;
}

.buffer-title {
    font-family: var(--font-sans);
    font-size: 0.75rem; /* 12px */
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--ink-faint);
    margin-bottom: var(--space-md);
}

.diff-arrow-container {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-xl) 6px;
}

.diff-arrow {
    font-size: 1.25rem;
    color: var(--ink-subtle);
}

.state-machine-viz {
    display: flex;
    gap: var(--space-lg);
    flex-wrap: wrap;
    padding: 12px var(--space-lg);
    border: 1px solid var(--rule-faint);
    background: var(--paper);
}

.state-item {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.state-label {
    font-family: var(--font-sans);
    font-size: 0.6875rem; /* 11px */
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--ink-subtle);
}

.state-value {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    font-family: var(--font-mono);
    font-size: 0.8125rem; /* 13px */
    color: var(--ink);
    font-weight: 500;
}

.state-color-swatch {
    width: 16px;
    height: 16px;
    border: 1px solid var(--rule-faint);
}

.diff-output-panel {
    border: 1px solid var(--rule-faint);
    padding: var(--space-md);
    background: white;
}

.diff-output-title {
    font-family: var(--font-sans);
    font-size: 0.75rem; /* 12px */
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--ink-faint);
    margin-bottom: var(--space-sm);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.ansi-stream {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    padding: var(--space-md);
    background: var(--ink);
    min-height: 56px;
    max-height: 120px;
    overflow-y: auto;
    font-family: var(--font-mono);
    font-size: 0.75rem; /* 12px */
}

.ansi-token {
    padding: 3px 7px;
    white-space: nowrap;
}

.ansi-token.esc { background: var(--ink); color: white; }
.ansi-token.move { background: var(--sig-blue); color: white; }
.ansi-token.fg { background: var(--sig-green); color: white; }
.ansi-token.bg { background: var(--sig-yellow); color: white; }
.ansi-token.char { background: rgba(255,255,255,0.15); color: white; }
.ansi-token.reset { background: #52525b; color: white; }
.ansi-token.skip {
    background: transparent;
    color: rgba(255,255,255,0.35);
    font-style: italic;
    border: 1px dashed rgba(255,255,255,0.2);
}

.byte-comparison {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin-top: var(--space-md);
}

.byte-comparison-item {
    padding: var(--space-md);
    border: 1px solid var(--rule-faint);
    text-align: center;
    background: white;
}

.byte-comparison-label {
    font-family: var(--font-sans);
    font-size: 0.6875rem; /* 11px */
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--ink-subtle);
    margin-bottom: 6px;
}

.byte-comparison-value {
    font-family: var(--font-mono);
    font-size: 1.125rem; /* 18px */
    font-weight: 700;
}

.byte-comparison-value.naive { color: var(--sig-red); }
.byte-comparison-value.optimized { color: var(--sig-green); }

.diff-stats {
    display: flex;
    gap: var(--space-lg);
    flex-wrap: wrap;
    padding: 12px var(--space-lg);
    border: 1px solid var(--rule-faint);
    font-family: var(--font-mono);
    font-size: 0.8125rem; /* 13px */
    background: var(--paper);
    margin-top: var(--space-md);
}

.diff-stat {
    display: flex;
    gap: var(--space-sm);
    color: var(--ink-muted);
}

.diff-stat-value {
    color: var(--sig-green);
    font-weight: 600;
}

/* Game Loop */
.gameloop-container {
    display: flex;
    flex-direction: column;
    gap: var(--space-lg);
}

.gameloop-viz {
    border: 1px solid var(--rule-faint);
    padding: var(--space-lg);
    background: white;
}

.frame-timeline {
    position: relative;
    height: 80px;
    margin-bottom: var(--space-lg);
}

.timeline-axis {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 1px;
    background: var(--rule-faint);
}

.timeline-label {
    position: absolute;
    bottom: -18px;
    font-family: var(--font-mono);
    font-size: 0.6875rem; /* 11px */
    color: var(--ink-subtle);
    transform: translateX(-50%);
}

.timeline-label.left { left: 0; transform: none; }
.timeline-label.right { right: 0; transform: none; }

.frame-marker {
    position: absolute;
    bottom: 1px;
    width: 3px;
    background: var(--sig-blue);
    transition: all 0.15s ease-out;
}

.frame-marker.active {
    background: var(--sig-green);
}

.frame-detail {
    border: 1px solid var(--rule-faint);
    padding: var(--space-md);
    background: var(--paper);
}

.frame-detail-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--space-md);
}

.frame-detail-title {
    font-family: var(--font-sans);
    font-size: 0.75rem; /* 12px */
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--ink-faint);
}

.frame-timing {
    font-family: var(--font-mono);
    font-size: 0.8125rem; /* 13px */
    color: var(--sig-blue);
    font-weight: 600;
}

.phase-pipeline {
    display: flex;
    align-items: center;
    gap: 0;
    overflow-x: auto;
    padding: 4px 0;
}

.phase-box {
    flex-shrink: 0;
    padding: 10px 14px;
    border: 1px solid var(--rule-faint);
    font-family: var(--font-mono);
    font-size: 0.75rem; /* 12px */
    color: var(--ink-faint);
    text-align: center;
    min-width: 90px;
    transition: all 0.15s ease;
    background: white;
}

.phase-box.active {
    background: var(--sig-blue);
    border-color: var(--sig-blue);
    color: white;
}

.phase-box.done {
    background: var(--tint-green);
    border-color: var(--sig-green);
    color: var(--sig-green);
}

.phase-arrow {
    flex-shrink: 0;
    width: 16px;
    height: 1px;
    background: var(--rule-faint);
    position: relative;
}

.phase-arrow::after {
    content: '';
    position: absolute;
    right: 0;
    top: -3px;
    border: 4px solid transparent;
    border-left-color: var(--rule-faint);
}

.phase-arrow.active {
    background: var(--sig-blue);
}

.phase-arrow.active::after {
    border-left-color: var(--sig-blue);
}

.timing-breakdown {
    margin-top: var(--space-md);
    padding-top: var(--space-md);
    border-top: 1px solid var(--rule-faint);
    opacity: 0;
    transition: opacity 0.2s ease;
}

.timing-breakdown.visible {
    opacity: 1;
}

.timing-bar-container {
    display: flex;
    height: 24px;
    background: var(--paper);
    border: 1px solid var(--rule-faint);
    margin-bottom: var(--space-sm);
    overflow: hidden;
}

.timing-bar {
    height: 100%;
    transition: width 0.3s ease-out;
}

.timing-bar.timing-work {
    background: var(--sig-blue);
    width: 0%;
}

.timing-bar.timing-wait {
    background: var(--rule-subtle);
    border-left: 1px dashed var(--rule-faint);
    width: 0%;
}

.timing-labels {
    display: flex;
    gap: var(--space-lg);
    font-family: var(--font-mono);
    font-size: 0.75rem; /* 12px */
    margin-bottom: var(--space-sm);
}

.timing-label {
    color: var(--ink-muted);
}

.timing-label.timing-total {
    margin-left: auto;
    color: var(--ink-faint);
}

.timing-formula {
    font-family: var(--font-mono);
    font-size: 0.75rem; /* 12px */
    color: var(--ink-faint);
    padding: var(--space-sm) var(--space-md);
    background: var(--paper);
    border: 1px solid var(--rule-faint);
    text-align: center;
}

.timing-formula .highlight {
    color: var(--sig-blue);
    font-weight: 600;
}

.gameloop-controls {
    display: flex;
    gap: var(--space-md);
    flex-wrap: wrap;
    align-items: center;
}

.loop-btn {
    font-family: var(--font-mono);
    font-size: 0.8125rem; /* 13px */
    padding: var(--space-sm) var(--space-lg);
    background: white;
    border: 1px solid var(--rule-faint);
    color: var(--ink-muted);
    cursor: pointer;
    transition: all 0.12s ease;
}

.loop-btn:hover {
    border-color: var(--ink);
    color: var(--ink);
    background: var(--paper);
}

.loop-btn:focus {
    outline: none;
    border-color: var(--sig-blue);
    box-shadow: 0 0 0 2px rgba(29, 78, 216, 0.15);
}

.loop-btn:active {
    transform: translateY(1px);
}

.loop-btn.active {
    background: var(--sig-green);
    border-color: var(--sig-green);
    color: white;
}

.loop-btn.active:hover {
    background: #166534; /* Darker variant of sig-green */
}

.loop-status {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: var(--space-lg);
    font-family: var(--font-mono);
    font-size: 0.8125rem; /* 13px */
}

.status-item {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    color: var(--ink-faint);
}

.status-value {
    color: var(--ink);
    font-weight: 600;
}

.status-value.running { 
    color: var(--sig-green);
}

.status-value.idle { color: var(--ink-subtle); }

/* Grapheme Demo */
.grapheme-demo {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.grapheme-example {
    display: flex;
    align-items: center;
    gap: var(--space-lg);
    padding: var(--space-lg);
    border: 1px solid var(--rule-faint);
    background: white;
}

.grapheme-char {
    font-size: 2.75rem; /* 44px - larger for clarity */
    min-width: 70px;
    text-align: center;
    line-height: 1;
}

.grapheme-breakdown {
    flex: 1;
}

.grapheme-label {
    font-family: var(--font-sans);
    font-size: 0.75rem; /* 12px */
    font-weight: 600;
    color: var(--ink-muted);
    margin-bottom: var(--space-sm);
}

.codepoints {
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
}

.codepoint {
    font-family: var(--font-mono);
    font-size: 0.75rem; /* 12px */
    padding: 5px 10px;
    border: 1px solid var(--rule-faint);
}

.codepoint.base { 
    border-color: var(--sig-blue); 
    color: var(--sig-blue);
    background: var(--tint-blue);
}
.codepoint.modifier { 
    border-color: var(--sig-red); 
    color: var(--sig-red);
    background: var(--tint-red);
}
.codepoint.zwj { 
    border-color: var(--sig-yellow); 
    color: var(--sig-yellow);
    background: var(--tint-yellow);
}

.cell-encoding {
    display: flex;
    gap: 4px;
    margin-top: var(--space-md);
}

.encoded-cell {
    width: 72px;
    height: 48px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--rule-faint);
    font-family: var(--font-mono);
    font-size: 0.6875rem; /* 11px */
}

.encoded-cell.start {
    border-color: var(--sig-green);
    background: var(--tint-green);
}

.encoded-cell.continuation {
    border-color: var(--sig-yellow);
    background: var(--tint-yellow);
}

.cell-type {
    font-size: 0.5625rem; /* 9px */
    color: var(--ink-subtle);
    margin-top: 2px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* Architecture Layers */
.layer-stack {
    display: flex;
    flex-direction: column;
    gap: 0;
    max-width: 680px;
}

.layer-wrapper {
    position: relative;
}

.layer {
    display: flex;
    border: 1px solid var(--rule-faint);
    transition: all 0.12s ease;
    background: white;
}

.layer:hover {
    border-color: var(--ink);
    transform: translateX(4px);
}

.layer.hot-path {
    border-color: var(--sig-yellow);
    border-width: 2px;
}

.layer.hot-path::before {
    content: 'HOT';
    position: absolute;
    right: 14px;
    top: 50%;
    transform: translateY(-50%);
    font-family: var(--font-sans);
    font-size: 0.5625rem; /* 9px */
    font-weight: 700;
    letter-spacing: 0.1em;
    color: var(--sig-yellow);
    background: var(--tint-yellow);
    padding: 4px 8px;
}

.layer-lang {
    width: 60px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: var(--font-sans);
    font-size: 0.625rem; /* 10px */
    font-weight: 700;
    letter-spacing: 0.08em;
}

/* Language badges use slightly muted versions of brand colors
   for better integration with the IBM palette */
.layer-lang.ts { background: #2563eb; color: white; } /* Closer to sig-blue family */
.layer-lang.zig { background: #b45309; color: white; } /* Warm amber, closer to sig-yellow family */
.layer-lang.terminal { background: var(--ink); color: white; }

.layer-content {
    flex: 1;
    padding: 14px var(--space-md);
}

.layer-title {
    font-family: var(--font-sans);
    font-size: 0.875rem; /* 14px */
    font-weight: 600;
    color: var(--ink);
    margin-bottom: 4px;
}

.layer-desc {
    font-family: var(--font-mono);
    font-size: 0.8125rem; /* 13px */
    color: var(--ink-muted);
    line-height: 1.55;
}

.ffi-boundary {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    padding: var(--space-sm) 0;
    margin: var(--space-sm) 0;
}

.ffi-boundary-line {
    flex: 1;
    height: 2px;
    background: linear-gradient(90deg, transparent, var(--sig-red) 20%, var(--sig-red) 80%, transparent);
}

.ffi-boundary-label {
    font-family: var(--font-sans);
    font-size: 0.625rem; /* 10px */
    font-weight: 700;
    letter-spacing: 0.12em;
    color: var(--sig-red);
    padding: 4px 12px;
    border: 1px solid var(--sig-red);
    white-space: nowrap;
    background: var(--tint-red);
    border-radius: 2px;
}

.layer-arrow {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: var(--space-sm);
    padding: var(--space-xs) 0;
    margin-left: 32px;
}

.layer-arrow-line {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    color: var(--ink-faint);
    font-size: 0.875rem; /* 14px */
}

.layer-arrow-down { color: var(--sig-blue); }
.layer-arrow-up { color: var(--sig-green); }

.layer-arrow-labels {
    display: flex;
    gap: var(--space-md);
    font-family: var(--font-mono);
    font-size: 0.625rem; /* 10px */
}

.layer-arrow-label { color: var(--ink-faint); }
.layer-arrow-label.down { color: var(--sig-blue); }
.layer-arrow-label.up { color: var(--sig-green); }

/* Input Demo */
.key-listener {
    padding: var(--space-xl);
    border: 2px dashed var(--rule-faint);
    text-align: center;
    cursor: pointer;
    transition: border-color 0.12s ease, background 0.12s ease;
    background: white;
}

.key-listener:hover {
    border-color: var(--ink-faint);
    background: var(--paper);
}

.key-listener:focus {
    outline: none;
    border-color: var(--sig-blue);
    border-style: solid;
    background: #f0f7ff;
    box-shadow: inset 0 0 0 2px rgba(29, 78, 216, 0.1);
}

.key-listener-prompt {
    font-family: var(--font-mono);
    font-size: 0.8125rem; /* 13px */
    color: var(--ink-faint);
}

.key-display {
    margin-top: var(--space-lg);
    font-family: var(--font-mono);
    font-size: 1.625rem; /* 26px */
    color: var(--sig-blue);
    min-height: 40px;
    font-weight: 600;
}

.input-flow {
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
    margin-top: var(--space-lg);
}

.input-stage {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    padding: var(--space-md);
    border: 1px solid var(--rule-faint);
    transition: all 0.15s ease;
    background: white;
}

.input-stage.active {
    border-color: var(--sig-green);
    background: var(--tint-green);
}

.stage-icon {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--rule-faint);
    font-family: var(--font-mono);
    font-size: 0.875rem; /* 14px */
    font-weight: 700;
    background: var(--paper);
}

.stage-content { flex: 1; }

.stage-name {
    font-family: var(--font-sans);
    font-size: 0.8125rem; /* 13px */
    font-weight: 600;
    color: var(--ink);
    margin-bottom: 4px;
}

.stage-data {
    font-family: var(--font-mono);
    font-size: 0.8125rem; /* 13px */
    color: var(--ink-muted);
}

.byte-arrival-viz {
    display: flex;
    gap: 4px;
    align-items: center;
    flex-wrap: wrap;
}

.arriving-byte {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 30px;
    font-family: var(--font-mono);
    font-size: 0.6875rem; /* 11px */
    border: 1px solid var(--rule-faint);
    background: white;
    color: var(--ink-faint);
    transition: all 0.15s ease;
}

.arriving-byte.arrived {
    background: var(--sig-blue);
    border-color: var(--sig-blue);
    color: white;
}

.arriving-byte.esc-byte {
    background: var(--sig-red);
    border-color: var(--sig-red);
    color: white;
}

.parser-state-viz {
    margin-top: var(--space-md);
    padding: var(--space-md);
    border: 1px solid var(--rule-faint);
    background: var(--paper);
}

.parser-state-title {
    font-family: var(--font-sans);
    font-size: 0.6875rem; /* 11px */
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--ink-subtle);
    margin-bottom: var(--space-sm);
}

.parser-states {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

.parser-state {
    font-family: var(--font-mono);
    font-size: 0.6875rem; /* 11px */
    padding: 5px 12px;
    border: 1px solid var(--rule-faint);
    color: var(--ink-faint);
    transition: all 0.15s ease;
}

.parser-state.active {
    background: var(--sig-blue);
    border-color: var(--sig-blue);
    color: white;
}

.mouse-demo-area {
    margin-top: var(--space-lg);
    padding: var(--space-lg);
    border: 1px solid var(--rule-faint);
    text-align: center;
    position: relative;
    min-height: 100px;
    background: white;
}

.mouse-demo-title {
    font-family: var(--font-sans);
    font-size: 0.75rem; /* 12px */
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--ink-subtle);
    margin-bottom: var(--space-sm);
}

.mouse-demo-output {
    font-family: var(--font-mono);
    font-size: 0.8125rem; /* 13px */
    color: var(--ink);
}

.mouse-indicator {
    position: absolute;
    width: 8px;
    height: 8px;
    background: var(--sig-blue);
    border-radius: 50%;
    transform: translate(-50%, -50%);
    pointer-events: none;
}

/* FFI Flow */
.ffi-flow {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    gap: 16px;
    align-items: start;
}

@media (max-width: 800px) {
    .ffi-flow {
        grid-template-columns: 1fr;
    }

    .ffi-arrow {
        text-align: center;
        padding: 8px 0;
    }
}

.ffi-side {
    border: 1px solid var(--rule-faint);
    overflow: hidden;
}

.ffi-label {
    padding: 8px 14px;
    border-bottom: 1px solid var(--rule-faint);
    font-family: var(--font-mono);
    font-size: 10px;
    color: var(--ink-faint);
}

.ffi-label a {
    color: var(--ink-faint);
    text-decoration: none;
}

.ffi-label a:hover {
    color: var(--ink);
}

.ffi-arrow {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    color: var(--ink-faint);
    padding-top: 50px;
}

/* Gotcha/Info Boxes - subtle tints derived from signal colors */
.gotcha-box {
    display: flex;
    gap: var(--space-md);
    padding: var(--space-lg);
    border: 1px solid var(--rule-faint);
    border-left: 4px solid var(--sig-blue);
    margin: var(--space-lg) 0;
    background: var(--tint-blue);
}

.gotcha-box.warning {
    border-left-color: var(--sig-yellow);
    background: var(--tint-yellow);
}

.gotcha-box.error {
    border-left-color: var(--sig-red);
    background: var(--tint-red);
}

.gotcha-icon {
    font-size: 0.875rem; /* 14px */
    min-width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--rule-faint);
    font-family: var(--font-mono);
    font-weight: 700;
    background: var(--paper);
}

.gotcha-content { flex: 1; }

.gotcha-title {
    font-family: var(--font-sans);
    font-size: 0.8125rem; /* 13px */
    font-weight: 600;
    color: var(--ink);
    margin-bottom: 6px;
}

.gotcha-text {
    font-family: var(--font-mono);
    font-size: 0.8125rem; /* 13px */
    color: var(--ink-muted);
    line-height: 1.75;
}

.gotcha-text code {
    background: var(--paper);
    padding: 2px 6px;
    border: 1px solid var(--rule-faint);
    font-size: 0.9em;
}

/* Lifecycle Diagram */
.lifecycle-container {
    display: grid;
    grid-template-columns: 1fr 260px;
    gap: 20px;
    align-items: start;
}

@media (max-width: 800px) {
    .lifecycle-container {
        grid-template-columns: 1fr;
    }
}

.lifecycle-diagram {
    display: flex;
    flex-direction: column;
    gap: 0;
}

.lifecycle-stage {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 14px 16px;
    border: 1px solid var(--rule-faint);
    cursor: pointer;
    transition: all 0.12s ease;
    position: relative;
    background: white;
}

.lifecycle-stage:hover {
    border-color: var(--ink);
    background: var(--paper);
}

.lifecycle-stage:focus {
    outline: none;
    border-color: var(--sig-blue);
}

.lifecycle-stage.active {
    border-color: var(--sig-green);
    border-width: 2px;
    background: var(--tint-green);
}

.lifecycle-stage.animating {
    border-color: var(--sig-blue);
    border-width: 2px;
    background: var(--tint-blue);
}

.stage-number {
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--rule-faint);
    font-family: var(--font-mono);
    font-size: 11px;
    font-weight: 600;
}

.stage-info { flex: 1; }

.stage-title {
    font-family: var(--font-sans);
    font-size: 11px;
    font-weight: 500;
    color: var(--ink);
}

.stage-detail {
    font-family: var(--font-mono);
    font-size: 10px;
    color: var(--ink-faint);
    margin-top: 2px;
}

.stage-output {
    font-family: var(--font-mono);
    font-size: 9px;
    color: var(--sig-green);
    margin-top: 4px;
}

.stage-trigger {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    font-family: var(--font-mono);
    font-size: 9px;
    color: var(--sig-yellow);
    background: var(--tint-yellow);
    padding: 2px 8px;
}

.lifecycle-connector {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-left: 30px;
    padding: 4px 0;
}

.lifecycle-connector-line {
    width: 1px;
    height: 10px;
    background: var(--rule-faint);
}

.lifecycle-connector-label {
    font-family: var(--font-mono);
    font-size: 9px;
    color: var(--ink-faint);
    font-style: italic;
}

.lifecycle-sidebar {
    border: 1px solid var(--rule-faint);
    padding: 14px;
}

.lifecycle-sidebar-title {
    font-family: var(--font-sans);
    font-size: 9px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.15em;
    color: var(--ink-faint);
    margin-bottom: 10px;
}

.lifecycle-phase-link {
    padding: 8px 10px;
    border: 1px solid var(--rule-faint);
    margin-bottom: 6px;
}

.lifecycle-phase-link-title {
    font-family: var(--font-mono);
    font-size: 10px;
    font-weight: 500;
    color: var(--ink);
    margin-bottom: 2px;
}

.lifecycle-phase-link-desc {
    font-family: var(--font-mono);
    font-size: 9px;
    color: var(--ink-faint);
}

/* Hit Grid */
#hit-grid .terminal-cell,
#scissor-hit-grid .terminal-cell {
    font-size: 10px;
}

#hit-info,
#scissor-hit-info {
    font-family: var(--font-mono);
}

/* File Map */
.file-map {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.file-category {
    border: 1px solid var(--rule-faint);
}

.category-title {
    padding: 10px 16px;
    border-bottom: 1px solid var(--rule-faint);
    font-family: var(--font-sans);
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.15em;
    color: var(--ink);
}

.category-title a {
    color: var(--sig-blue);
    text-decoration: none;
}

.category-title a:hover {
    text-decoration: underline;
}

.file-list {
    padding: 6px 0;
}

.file-item {
    display: flex;
    padding: 8px 16px;
    gap: 16px;
    transition: background 0.1s;
}

.file-item:hover {
    background: rgba(0, 0, 0, 0.02);
}

.file-name {
    min-width: 180px;
    font-family: var(--font-mono);
    font-size: 11px;
    font-weight: 500;
}

.file-name a {
    color: var(--sig-yellow);
    text-decoration: none;
}

.file-name a:hover {
    text-decoration: underline;
}

.file-desc {
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--ink-muted);
}

/* Footer */
.doc-footer {
    border-top: 1px solid var(--rule-faint);
    padding-top: var(--space-xl);
    margin-top: var(--space-2xl);
    text-align: center;
}

.doc-footer p {
    font-family: var(--font-mono);
    font-size: 0.8125rem; /* 13px */
    color: var(--ink-faint);
    line-height: 1.7;
}

.doc-footer a {
    color: var(--ink-muted);
    text-decoration: none;
    transition: color 0.15s ease;
}

.doc-footer a:hover {
    color: var(--sig-blue);
}

/* Select styling */
select {
    font-family: var(--font-mono);
    font-size: 0.75rem; /* 12px */
    padding: 5px var(--space-sm);
    background: white;
    border: 1px solid var(--rule-faint);
    color: var(--ink-muted);
    cursor: pointer;
    transition: border-color 0.15s ease;
}

select:hover {
    border-color: var(--ink-faint);
    color: var(--ink);
}

select:focus {
    outline: none;
    border-color: var(--sig-blue);
}

/* Mobile adjustments */
@media (max-width: 700px) {
    :root {
        --space-xl: 32px;
        --space-2xl: 48px;
        --cell-size: 20px;
    }

    .manual-sheet {
        padding: var(--space-xl) var(--space-md);
    }

    .manual-grid {
        grid-template-columns: minmax(0, 1fr);
        gap: var(--space-md);
    }

    /* Prevent grid items from expanding beyond column width */
    .manual-grid > * {
        min-width: 0;
    }

    .section-margin {
        display: none;
    }
    
    /* Header mobile layout */
    .doc-header .manual-grid {
        grid-template-columns: 32px minmax(0, 1fr);
        gap: var(--space-md);
    }
    
    .doc-header .section-margin {
        display: block;
        padding-top: 4px;
    }
    
    .bars-motif-tall {
        width: 24px;
        gap: 4px;
    }
    
    .bars-motif-tall .bar {
        height: 3px;
    }
    
    .doc-header-content {
        padding-left: 0;
    }
    
    .doc-title-block {
        flex-direction: column;
        gap: var(--space-md);
    }
    
    .doc-title {
        font-size: 2rem;
    }
    
    .doc-meta {
        text-align: left;
    }
    
    .doc-subtitle {
        margin-top: var(--space-md);
    }
    
    .tech-badge {
        margin-top: var(--space-lg);
    }

    .doc-nav {
        margin: 0 calc(-1 * var(--space-md));
        padding: 0 var(--space-md);
    }
    
    .nav-item {
        padding: 12px var(--space-sm);
        font-size: 0.625rem;
    }

    .demo-body {
        padding: var(--space-md);
        overflow-x: auto;
    }
    
    .demo-header {
        flex-wrap: wrap;
        gap: var(--space-sm);
        padding: var(--space-sm) var(--space-md);
    }
    
    .demo-title {
        font-size: 0.6875rem;
        width: 100%;
    }
    
    .demo-controls {
        width: 100%;
        flex-wrap: wrap;
    }
    
    .heading-2 {
        font-size: 1.25rem; /* 20px */
    }
    
    .flow-diagram {
        justify-content: flex-start;
    }
    
    .flow-box {
        min-width: 80px;
        padding: 10px var(--space-sm);
    }
    
    .flow-box-content {
        font-size: 0.75rem;
    }
    
    .flow-box-title {
        font-size: 0.5625rem;
    }
    
    .flow-arrow {
        font-size: 0.875rem;
    }
    
    /* Terminal grid */
    .terminal-grid {
        max-width: 100%;
        overflow-x: auto;
    }
    
    /* Code blocks */
    .code-block {
        margin-left: calc(-1 * var(--space-md));
        margin-right: calc(-1 * var(--space-md));
        border-left: none;
        border-right: none;
    }
    
    pre {
        padding: var(--space-md);
        font-size: 0.75rem;
    }
    
    /* ANSI builder */
    .ansi-builder {
        grid-template-columns: 1fr;
    }
    
    .color-picker-grid {
        grid-template-columns: repeat(8, 1fr);
        gap: 4px;
    }
    
    /* Byte display */
    .byte-row {
        flex-direction: column;
        align-items: flex-start;
        gap: var(--space-sm);
    }
    
    .byte-label {
        width: auto;
        text-align: left;
    }
    
    .byte {
        width: 28px;
        height: 28px;
        font-size: 0.6875rem;
    }
    
    /* Struct viz */
    .struct-field {
        flex-direction: column;
    }
    
    .field-name {
        width: 100%;
        border-right: none;
        border-bottom: 1px solid var(--rule-faint);
        padding: var(--space-sm) var(--space-md);
    }
    
    .field-value {
        flex-wrap: wrap;
    }
    
    /* Bit field */
    .bit-labels,
    .bit-field {
        flex-wrap: wrap;
    }
    
    .bit-label,
    .bit {
        width: 26px;
    }
    
    .bit {
        height: 30px;
        font-size: 0.75rem;
    }
    
    /* Grapheme examples */
    .grapheme-example {
        flex-direction: column;
        align-items: flex-start;
        gap: var(--space-md);
    }
    
    .grapheme-char {
        font-size: 2rem;
        min-width: auto;
    }
    
    .codepoint {
        font-size: 0.6875rem;
        padding: 4px 6px;
    }
    
    /* Diff buffers */
    .diff-buffers-row {
        grid-template-columns: 1fr;
    }
    
    .diff-arrow-container {
        padding: var(--space-sm) 0;
        transform: rotate(90deg);
    }
    
    /* Layer stack */
    .layer-content {
        padding: 10px var(--space-sm);
    }
    
    .layer-title {
        font-size: 0.8125rem;
    }
    
    .layer-desc {
        font-size: 0.75rem;
    }
    
    .layer.hot-path::before {
        position: static;
        display: block;
        margin-top: var(--space-xs);
        transform: none;
    }
    
    /* Phase pipeline */
    .phase-pipeline {
        flex-wrap: nowrap;
        overflow-x: auto;
        padding-bottom: var(--space-sm);
    }
    
    .phase-box {
        min-width: 70px;
        padding: 8px 10px;
        font-size: 0.6875rem;
    }
    
    /* Gameloop controls */
    .gameloop-controls {
        flex-direction: column;
        align-items: stretch;
    }
    
    .loop-status {
        margin-left: 0;
        margin-top: var(--space-sm);
        justify-content: space-between;
    }
    
    /* Memory layout */
    .memory-array-row {
        flex-wrap: wrap;
    }
    
    .memory-array-label {
        width: 100%;
        text-align: left;
        margin-bottom: var(--space-xs);
    }
    
    .memory-array-cells {
        flex-wrap: wrap;
    }
    
    .memory-array-cell {
        width: 28px;
        height: 22px;
        font-size: 0.625rem;
    }
    
    /* Cell detail panel */
    .cell-detail-grid {
        grid-template-columns: 1fr;
    }
    
    .cell-detail-value {
        flex-wrap: wrap;
        font-size: 0.75rem;
    }

    /* Prevent page-level horizontal scroll */
    .manual-page {
        overflow-x: hidden;
    }

    /* Contain game loop visualization so it doesn't expand the page */
    .gameloop-viz {
        overflow-x: auto;
    }

    /* File map: reduce min-width so file items don't overflow */
    .file-name {
        min-width: 120px;
    }

    .file-item {
        flex-wrap: wrap;
    }
}
