/* ══════════════════════════════════════════════════════════════
   μ — warm editorial stylesheet
   ══════════════════════════════════════════════════════════════ */

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

:root {
    --paper:      #f7f4ee;
    --paper-deep: #efeade;
    --ink:        #1c1917;
    --ink-soft:   #44403c;
    --accent:     #8b1a1a;
    --accent-soft:#c04040;
    --rule:       #a89c80;
    --rule-soft:  #c8bda3;
    --highlight:  #c8b572;
    --code-bg:    #faf9f5;
    --paper-end:  #f0ece4;
}

@media (prefers-color-scheme: dark) {
    :root {
        --paper:      #1a1a1e;
        --paper-deep: #222226;
        --ink:        #e8e4de;
        --ink-soft:   #a8a29e;
        --accent:     #e05252;
        --accent-soft:#f07070;
        --rule:       #4a4540;
        --rule-soft:  #3a3632;
        --highlight:  #c8b572;
        --code-bg:    #262628;
        --paper-end:  #16161a;
    }

    .masthead {
        background: rgba(255,255,255,0.02);
    }

    pre {
        border-color: var(--rule);
        box-shadow: 0 1px 3px rgba(0,0,0,0.2);
    }

    .hero-chart-hint {
        background: rgba(26, 26, 30, 0.9);
    }
}

html { 
    font-size: 15px;
    background-color: var(--paper);
}

body {
    font-family: 'Newsreader', Georgia, serif;
    font-optical-sizing: auto;
    background: linear-gradient(180deg, var(--paper) 0%, var(--paper-end) 100%);
    color: var(--ink);
    font-size: 16.5px;
    line-height: 1.55;
    font-weight: 400;
    margin: 0;
    padding: 0;
    min-height: 100vh;
}

.page {
    max-width: 960px;
    margin: 0 auto;
    padding: 64px 56px 96px;
    position: relative;
}

/* ── Typography ─────────────────────────────────────────────── */
p, ol, ul, dl { font-size: 16.5px; line-height: 1.55; margin: 0 0 12px; }
li  { margin-bottom: 0.3rem; }
ol, ul { padding-left: 1.6rem; }

a {
    color: var(--accent);
    text-decoration: none;
    border-bottom: 1px dotted var(--accent-soft);
}
a:hover { color: var(--accent-soft); }

strong { font-weight: 600; }

/* ── Headings ───────────────────────────────────────────────── */
h1 {
    font-family: 'Fraunces', serif;
    font-variation-settings: "opsz" 144, "SOFT" 30, "WONK" 1;
    font-weight: 350;
    font-size: 58px;
    line-height: 1.02;
    letter-spacing: -0.02em;
    margin: 0 0 18px;
    color: var(--ink);
}
h1::after {
    content: '';
    display: block;
    width: 60px;
    height: 2px;
    background: var(--accent);
    margin-top: 14px;
}

.subtitle {
    font-family: 'Newsreader', serif;
    font-size: 20px;
    line-height: 1.4;
    font-style: italic;
    font-weight: 300;
    color: var(--ink-soft);
    max-width: 640px;
    margin: 0 0 36px;
}

h2 {
    font-family: 'Fraunces', serif;
    font-variation-settings: "opsz" 72, "SOFT" 20, "WONK" 0;
    font-weight: 500;
    font-size: 28px;
    letter-spacing: -0.01em;
    margin: 56px 0 8px;
    color: var(--ink);
}

h3 {
    font-family: 'Fraunces', serif;
    font-variation-settings: "opsz" 24;
    font-weight: 600;
    font-size: 17px;
    letter-spacing: 0.02em;
    text-transform: uppercase;
    margin: 28px 0 10px;
    color: var(--accent);
}

/* ── Accent rule under title ────────────────────────────────── */
.title-rule {
    display: none;
}

/* ── Masthead (info bar) ────────────────────────────────────── */
.masthead {
    border-top: 3px double var(--ink);
    border-bottom: 1px solid var(--ink);
    padding: 14px 12px 16px;
    margin-bottom: 0;
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    font-family: 'JetBrains Mono', monospace;
    font-size: 10.5px;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    color: var(--ink-soft);
    background: rgba(0,0,0,0.015);
    border-radius: 2px;
}
.masthead .seal {
    font-family: 'Fraunces', serif;
    font-variation-settings: "SOFT" 50, "WONK" 1;
    font-weight: 600;
    font-size: 13px;
    letter-spacing: 0.04em;
    text-transform: none;
    color: var(--ink);
}

/* ── Navigation strip (below masthead) ─────────────────────── */
.nav-strip,
.toc-strip {
    margin: 0;
    padding: 10px 0 12px;
    margin-bottom: 36px;
    display: flex;
    flex-wrap: wrap;
    gap: 0;
    font-family: 'JetBrains Mono', monospace;
    font-size: 10.5px;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    border: none;
    line-height: 1.8;
}
.nav-strip a,
.toc-strip a {
    font-family: 'JetBrains Mono', monospace;
    font-size: 10.5px;
    color: var(--ink-soft);
    background-image: none;
    border-bottom: none;
    white-space: nowrap;
    letter-spacing: 0.14em;
}
.nav-strip a:hover,
.toc-strip a:hover { color: var(--accent); }
.nav-strip a.active,
.toc-strip a.active { color: var(--accent); font-weight: 500; }
.nav-strip a + a::before,
.toc-strip a + a::before {
    content: " · ";
    color: var(--rule);
}

/* ── Code ───────────────────────────────────────────────────── */
code {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.82rem;
    background: var(--code-bg);
    padding: 0.1em 0.35em;
    border-radius: 2px;
}
pre {
    background: var(--code-bg);
    border: 1px solid #ddd8cc;
    border-left: 3px solid var(--accent);
    padding: 1rem 1.2rem;
    overflow-x: auto;
    scrollbar-width: thin;
    font-size: 0.82rem;
    line-height: 1.55;
    margin: 1rem 0 1.4rem 0;
    white-space: pre-wrap;
    word-wrap: break-word;
    box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}
pre::-webkit-scrollbar {
    height: 6px;
}
pre::-webkit-scrollbar-thumb {
    background: var(--rule);
    border-radius: 3px;
}
pre code {
    font-family: 'JetBrains Mono', monospace;
    background: none;
    padding: 0;
    border-radius: 0;
}
pre code.hljs { background: var(--code-bg); padding: 0; }
.hljs { background: var(--code-bg); }

/* ── Tables ─────────────────────────────────────────────────── */
.table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin: 1rem 0 1.4rem 0;
}
table {
    border-collapse: collapse;
    font-size: 15px;
    width: 100%;
    margin: 0;
}
th, td {
    padding: 0.5rem 0.8rem;
    text-align: left;
    border-bottom: 1px solid var(--rule-soft);
}
thead th {
    border-bottom: 2px solid var(--ink);
    font-family: 'JetBrains Mono', monospace;
    font-weight: 400;
    font-size: 10.5px;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--ink-soft);
}
tbody tr:last-child td { border-bottom: 2px solid var(--ink); }
td code { font-size: 0.8rem; }

/* ── Divider ────────────────────────────────────────────────── */
hr {
    border: none;
    border-top: 1px solid var(--rule-soft);
    margin: 2.5rem 0;
}

/* ── Function entry (stdlib pages) ─────────────────────────── */
.fn-name { font-family: 'JetBrains Mono', monospace; font-size: 0.9rem; font-weight: 600; color: var(--ink); }
.fn-def  { font-family: 'JetBrains Mono', monospace; font-size: 0.85rem; color: var(--ink-soft); }

/* ── Footer / Colophon ─────────────────────────────────────── */
footer.site-footer,
.colophon {
    margin-top: 56px;
    text-align: center;
    font-family: 'JetBrains Mono', monospace;
    font-size: 10px;
    letter-spacing: 0.2em;
    text-transform: uppercase;
    color: var(--ink-soft);
    padding-top: 24px;
    border-top: 3px double var(--ink);
}
footer.site-footer a {
    color: var(--accent);
    border-bottom: none;
}
footer.site-footer a:hover { color: var(--accent-soft); }

/* ── Example cards (math ↔ μ) ───────────────────────────────── */
.example-card {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0;
    margin: 1.4rem 0 2rem 0;
    border: 1px solid var(--rule);
    border-radius: 0;
    overflow: hidden;
}

.example-card .math-col {
    padding: 1.2rem 1.4rem;
    background: var(--paper);
    border-right: 1px solid var(--rule);
    display: flex;
    flex-direction: column;
    justify-content: center;
    min-width: 0;
    overflow: hidden;
}

.example-card .code-col {
    padding: 0;
    background: var(--code-bg);
    min-width: 0;
    overflow: hidden;
}

.example-card .code-col pre {
    margin: 0;
    border-left: none;
    border: none;
    border-radius: 0;
    height: 100%;
    box-sizing: border-box;
    overflow-x: auto;
    scrollbar-width: thin;
    white-space: pre-wrap;
    word-wrap: break-word;
}

.example-card .math-label {
    font-family: 'JetBrains Mono', monospace;
    font-size: 10px;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--ink-soft);
    margin-bottom: 0.6rem;
}

.katex-display {
    margin: 0.4rem 0 0 0 !important;
    overflow: hidden !important;
}
.katex-display > .katex,
.katex-display > .katex > .katex-html {
    overflow: hidden !important;
    max-width: 100%;
}

/* ═───────────────────────────────────────────────────────────
   μ Syntax Highlighting — subtle warm tones (light mode)
   ═─────────────────────────────────────────────────────────── */
.hljs                         { background: var(--code-bg) !important; color: var(--ink); }

/* Comments: muted gray-green */
.hljs-comment                 { color: #8a8a7a; font-style: italic; }

/* Numbers: warm amber-brown */
.hljs-number, .hljs-literal   { color: #9a7a3a; }

/* Strings: muted olive */
.hljs-string                  { color: #6a8a4a; }

/* Operators (+ - * % etc): subtle brown, not red */
.hljs-keyword                 { color: #7a6a5a; }

/* Built-ins (sqrt, mean, etc): slightly darker than operators */
.hljs-built_in                { color: #6a5a4a; }

/* Lambda params and variables: inherit body color */
.hljs-variable, .hljs-params  { color: var(--ink); }

/* Kill all blue/purple/teal — fall back to body colour */
.hljs-section, .hljs-title,
.hljs-name, .hljs-selector-tag,
.hljs-deletion, .hljs-subst,
.hljs-formula, .hljs-link,
.hljs-quote, .hljs-selector-id,
.hljs-selector-class,
.hljs-attribute, .hljs-attr,
.hljs-type, .hljs-regexp,
.hljs-template-variable,
.hljs-symbol, .hljs-bullet,
.hljs-addition                { color: var(--ink); font-weight: normal; font-style: normal; }

/* ═───────────────────────────────────────────────────────────
   μ Syntax Highlighting — DARK MODE (high contrast)
   ═─────────────────────────────────────────────────────────── */
@media (prefers-color-scheme: dark) {
  /* Comments: lighter gray-green for readability */
  .hljs-comment                 { color: #a0a090; font-style: italic; }

  /* Numbers: brighter amber/gold */
  .hljs-number, .hljs-literal   { color: #d4a85a; }

  /* Strings: lighter olive-green */
  .hljs-string                  { color: #8ab86a; }

  /* Operators: soft warm tan (readable on dark) */
  .hljs-keyword                 { color: #c4a88a; }

  /* Built-ins: slightly muted but still warm */
  .hljs-built_in                { color: #b8987a; }

  /* Variables/params: normal ink color */
  .hljs-variable, .hljs-params  { color: var(--ink); }
}

.example-note {
    font-size: 14px;
    color: var(--ink-soft);
    margin: -0.8rem 0 1.6rem 0;
    font-style: italic;
}

.domain-heading {
    font-family: 'JetBrains Mono', monospace;
    font-weight: 500;
    font-size: 11px;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    color: var(--accent);
    margin-top: 56px;
    margin-bottom: 4px;
    padding-top: 24px;
    border-top: 1px solid var(--rule-soft);
}

/* ── Hero Chart Section ─────────────────────────────────────── */
.hero-chart-section {
    margin: 36px 0 48px;
    text-align: center;
}

.hero-3d-wrapper {
    position: relative;
    width: 100%;
    max-width: 600px;
    height: 400px;
    margin: 0 auto;
    background: var(--paper-deep);
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.08);
    overflow: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
}

.hero-chart-hint {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-family: 'JetBrains Mono', monospace;
    font-size: 12px;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--ink-soft);
    background: rgba(241, 234, 217, 0.9);
    padding: 8px 16px;
    border-radius: 4px;
    pointer-events: none;
    z-index: 10;
    opacity: 0.8;
}

.hero-chart-loading {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-family: 'JetBrains Mono', monospace;
    font-size: 12px;
    color: var(--ink-soft);
}

.hero-chart-error {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-family: 'JetBrains Mono', monospace;
    font-size: 12px;
    color: var(--accent);
}

.hero-3d-plot {
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
}

.hero-3d-plot canvas {
    cursor: grab;
    display: block;
    width: 100%;
    height: 100%;
}

.hero-3d-plot canvas:active {
    cursor: grabbing;
}

.hero-chart-caption {
    font-family: 'Newsreader', serif;
    font-size: 14px;
    font-style: italic;
    color: var(--ink-soft);
    margin-top: 12px;
    max-width: 600px;
    margin-left: auto;
    margin-right: auto;
}

/* ── Wide-screen enhancements ──────────────────────────────── */
@media (min-width: 1200px) {
    .plot-live-container,
    .example-3d-container {
        margin-left: -40px;
        margin-right: -40px;
        max-width: calc(100% + 80px);
    }
    .hero-3d-wrapper {
        max-width: 720px;
        height: 480px;
        margin: 0 auto;
    }
    .plot-live-container,
    .example-3d-container {
        max-width: 720px;
        height: 480px;
    }
}

@media (min-width: 1400px) {
    .page {
        max-width: 1080px;
        padding: 72px 72px 120px;
    }
    .hero-3d-wrapper {
        max-width: 740px;
        height: 500px;
    }
}

/* ── Responsive ─────────────────────────────────────────────── */
@media (max-width: 960px)  { .page { padding: 48px 32px 72px; } }
@media (max-width: 900px)  { .example-card { grid-template-columns: 1fr; } .example-card .math-col { border-right: none; border-bottom: 1px solid var(--rule); } }
@media (max-width: 700px)  {
    .page { padding: 32px 16px 48px; }
    .masthead { flex-direction: column; gap: 8px; }
    .masthead span:last-child { display: none; }
}
@media (max-width: 480px)  {
    h1 { font-size: 40px; }
    .subtitle { font-size: 17px; }
    h2 { font-size: 22px; margin-top: 40px; }
    .hero-3d-wrapper { height: 300px; }
    .example-3d-container { height: 250px; }
}

/* ── Live Plot Containers (for plots.html) ─────────────────────────── */
.plot-live-container {
    width: 100%;
    max-width: 600px;
    height: 400px;
    margin: 24px auto 36px;
    background: var(--paper-deep);
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.08);
    overflow: hidden;
    position: relative;
}

.plot-2d-wrapper {
    width: 100%;
    height: 100%;
    position: relative;
}

.plot-loading, .plot-error {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-family: 'JetBrains Mono', monospace;
    font-size: 12px;
}

.plot-loading { color: var(--ink-soft); }
.plot-error { color: var(--accent); }

/* ── Example Page 3D Plot Containers ─────────────────────────────── */
.example-3d-container {
    width: 100%;
    max-width: 600px;
    height: 400px;
    margin: 24px auto 36px;
    background: var(--paper-deep);
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.08);
    overflow: hidden;
}

.example-3d-loading {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-family: 'JetBrains Mono', monospace;
    font-size: 12px;
    color: var(--ink-soft);
}

.example-3d-error {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-family: 'JetBrains Mono', monospace;
    font-size: 12px;
    color: var(--accent);
}

.example-3d-plot canvas {
    cursor: grab;
}

.example-3d-plot canvas:active {
    cursor: grabbing;
}
