/* ===================================================================
   Lang Notes — additions on top of the Hull Notes stylesheet (style.css,
   copied unchanged). Only new components live here; every colour comes
   from the tokens defined in style.css, so light/dark mode just work.
   =================================================================== */
:root { --stage-w: clamp(340px, 30vw, 480px); --sheet-h: min(54vh, 520px); --paper: #fbf3e1; --paper-2: #e9ddc2; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { --paper: #2c2a25; --paper-2: #3a362e; } }
:root[data-theme="dark"] { --paper: #2c2a25; --paper-2: #3a362e; }

/* ---------------- sidebar: sections of the open chapter, upcoming chapters */
.toc-secs { margin: 2px 0 8px 30px; border-left: 1px solid var(--border); }
.toc-secs a { display: flex; gap: 6px; padding: 3px 8px; font-size: 12.5px; line-height: 1.35; color: var(--text-2); border-left: 2px solid transparent; margin-left: -1px; }
.toc-secs a span { color: var(--muted); min-width: 26px; font-variant-numeric: tabular-nums; flex: none; }
.toc-secs a:hover { color: var(--text); text-decoration: none; }
.toc-secs a.cur { border-left-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.toc-secs a.done span::after { content: ' ✓'; color: var(--good); }
.toc-ch.soon { opacity: .5; cursor: default; }
.toc-ch.soon:hover { background: none; color: var(--text-2); }
.soon-tag { flex: none; font-size: 10.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); border: 1px solid var(--border-2); border-radius: 99px; padding: 0 6px; }
.ch-card.soon { opacity: .55; }
.ch-card.soon:hover { transform: none; box-shadow: none; }
.pn.soon { opacity: .55; }
.home-how { margin-bottom: 8px; }

/* ---------------- page layout with the fold stage */
@media (min-width: 1180px) {
  body.has-stage .main { margin-right: calc(var(--stage-w) + 28px); padding-left: 34px; padding-right: 34px; }
  body.has-stage.stage-min .main { margin-right: 0; }
  body.focus.has-stage .main { margin-left: max(24px, calc((100vw - var(--stage-w) - 28px - 900px) / 2)); margin-right: calc(var(--stage-w) + 28px) !important; max-width: 900px; }
  body.focus.has-stage.stage-min .main { margin-left: auto; margin-right: auto !important; }
}
@media (max-width: 1179px) {
  body.has-stage .main { padding-bottom: calc(var(--sheet-h) + 48px); }
  body.has-stage.stage-min .main { padding-bottom: 110px; }
}

/* ---------------- the stage */
.stage { position: fixed; z-index: 30; top: calc(var(--top) + 14px); right: 14px; bottom: 14px; width: var(--stage-w); display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-hover); overflow: hidden; }
.stage[hidden], .stage [hidden] { display: none !important; }
.st-bar { display: flex; align-items: center; gap: 6px; padding: 8px 8px 8px 14px; border-bottom: 1px solid var(--border); flex: none; }
.st-grip { flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: flex-start; background: none; border: 0; padding: 0; color: var(--text); font: inherit; text-align: left; cursor: default; }
.st-kicker { font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; color: var(--eyebrow); line-height: 1.3; }
.st-title { font-size: 15px; font-weight: 600; line-height: 1.3; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.st-tabs button { padding: 4px 10px; font-size: 12.5px; }
.st-tabs button:disabled { opacity: .4; cursor: not-allowed; }
.st-follow { font-size: 15px; opacity: .45; filter: grayscale(1); }
.st-follow.on { opacity: 1; filter: none; background: var(--accent-soft); }
.st-min { font-size: 14px; }
.st-body { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.st-view { position: relative; flex: 1 1 auto; min-height: 210px; background: radial-gradient(120% 90% at 50% 35%, var(--surface) 0%, var(--surface-2) 70%, var(--surface-3) 140%); overflow: hidden; }
.st-canvas, .st-canvas canvas { position: absolute; inset: 0; width: 100% !important; height: 100% !important; display: block; touch-action: none; }
.st-cp { position: absolute; inset: 0; padding: 14px 14px 8px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; background: var(--surface); overflow: auto; }
.st-cp .cp-svg { width: auto; height: auto; max-width: 100%; max-height: calc(100% - 30px); flex: 0 1 auto; }
.st-nocp { color: var(--muted); font-size: 14px; max-width: 30ch; text-align: center; }
.st-msg { position: absolute; left: 12px; right: 12px; bottom: 12px; background: var(--warn-soft); color: var(--text); border: 1px solid color-mix(in srgb, var(--warn) 30%, transparent); border-radius: 10px; padding: 8px 12px; font-size: 13px; line-height: 1.45; z-index: 2; }
.st-body > .st-msg { position: static; margin: 14px; }
.st-legend { position: absolute; left: 10px; top: 10px; display: flex; flex-direction: column; gap: 2px; font-size: 11.5px; background: color-mix(in srgb, var(--surface) 82%, transparent); backdrop-filter: blur(6px); border: 1px solid var(--border); border-radius: 10px; padding: 6px 9px; max-width: 46%; pointer-events: none; }
.stage.tab-cp .st-legend { display: none; }
.st-legend span { display: flex; align-items: center; gap: 6px; line-height: 1.35; }
.st-legend i { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.st-viewbtns { position: absolute; right: 10px; top: 10px; display: flex; flex-direction: column; gap: 6px; }
.st-viewbtns button { width: 32px; height: 32px; border-radius: 9px; border: 1px solid var(--border); background: color-mix(in srgb, var(--surface) 85%, transparent); backdrop-filter: blur(6px); color: var(--text-2); font-size: 15px; cursor: pointer; }
.st-viewbtns button:hover { color: var(--text); border-color: var(--border-2); }
.st-viewbtns button.on { color: var(--accent-ink); border-color: var(--accent); background: var(--accent-soft); }
.st-light { position: absolute; top: 10px; right: 50px; z-index: 3; width: min(260px, calc(100% - 64px)); max-height: calc(100% - 20px); overflow-y: auto; background: color-mix(in srgb, var(--surface) 94%, transparent); backdrop-filter: blur(10px); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow-hover); padding: 10px 12px; display: flex; flex-direction: column; gap: 8px; font-size: 12.5px; }
.stage.tab-cp .st-light { display: none; }
.st-light-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.st-light-head b { font-size: 13px; }
.st-light-head .muted { font-size: 11px; }
.st-light-mode { display: flex; }
.st-light-mode button { flex: 1; padding: 4px 8px; font-size: 12px; }
.st-sl { display: grid; grid-template-columns: 1fr auto; gap: 0 8px; color: var(--text-2); }
.st-sl output { font-variant-numeric: tabular-nums; font-weight: 600; color: var(--text); }
.st-sl input { grid-column: 1 / -1; width: 100%; accent-color: var(--accent); margin: 2px 0 0; }
.st-light-row { display: flex; flex-wrap: wrap; gap: 4px; }
.st-light .off { opacity: .45; }
.st-light-foot { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.st-hint { position: absolute; left: 0; right: 0; bottom: 6px; text-align: center; font-size: 11px; color: var(--muted); pointer-events: none; }
.st-step { padding: 9px 14px 2px; flex: none; }
.st-count { font-size: 12px; color: var(--muted); }
.st-count b { color: var(--text-2); }
.st-phase { color: var(--accent-ink); font-weight: 600; }
.st-approx { color: var(--warn); border-bottom: 1px dotted var(--warn); cursor: help; }
.st-steptitle { font-weight: 600; font-size: 15px; line-height: 1.35; margin-top: 1px; }
.st-text { font-size: 13.5px; color: var(--text-2); line-height: 1.5; max-height: 4.6em; overflow-y: auto; }
.st-scrub { width: calc(100% - 28px); margin: 6px 14px 2px; accent-color: var(--accent); flex: none; }
.st-ctl { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 4px 12px 8px; flex-wrap: wrap; flex: none; }
.st-play { display: flex; gap: 4px; }
.st-play button { width: 36px; height: 36px; border-radius: 50%; border: 1px solid var(--border-2); background: var(--surface); color: var(--text); font-size: 14px; cursor: pointer; display: grid; place-items: center; }
.st-play button:hover { background: var(--surface-2); }
.st-play .st-pp { background: var(--accent); border-color: var(--accent); color: #fff; width: 42px; height: 42px; margin-top: -3px; font-size: 16px; }
.st-play .st-pp:hover { filter: brightness(1.08); background: var(--accent); }
.st-toggles { display: flex; flex-wrap: wrap; gap: 4px; justify-content: flex-end; }
.st-tg { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; color: var(--text-2); border: 1px solid var(--border); border-radius: 99px; padding: 2px 9px 2px 6px; cursor: pointer; user-select: none; background: var(--surface); }
.st-tg:has(input:checked) { background: var(--accent-soft); border-color: color-mix(in srgb, var(--accent) 35%, transparent); color: var(--accent-ink); }
.st-tg input { margin: 0; accent-color: var(--accent); width: 13px; height: 13px; }
.st-tg[hidden] { display: none; }
.st-steps { display: flex; gap: 6px; overflow-x: auto; padding: 8px 12px 10px; border-top: 1px solid var(--border); flex: none; scrollbar-width: thin; }
.st-steps button { flex: none; display: inline-flex; align-items: center; gap: 6px; max-width: 220px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font: 500 12px var(--font); color: var(--text-2); background: var(--surface-2); border: 1px solid var(--border); border-radius: 99px; padding: 3px 10px 3px 4px; cursor: pointer; }
.st-steps button span { display: inline-grid; place-items: center; min-width: 19px; height: 19px; border-radius: 99px; background: var(--surface); font-size: 11px; font-variant-numeric: tabular-nums; color: var(--muted); }
.st-steps button.done span { background: var(--good-soft); color: var(--good); }
.st-steps button.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent-ink); }
.st-steps button.on span { background: var(--accent); color: #fff; }
.st-foot { display: flex; justify-content: space-between; gap: 10px; padding: 7px 14px; border-top: 1px solid var(--border); font-size: 11.5px; color: var(--muted); flex: none; }
.st-foot b { color: var(--text-2); font-weight: 600; }
.st-src { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.st-src a { color: inherit; text-decoration: underline; text-decoration-color: var(--border-2); }

/* minimized: a pill in the bottom-right corner */
.stage.min { top: auto; bottom: 14px; height: auto; width: min(340px, calc(100vw - 28px)); }
.stage.min .st-body, .stage.min .st-tabs, .stage.min .st-follow { display: none; }
.stage.min .st-bar { border-bottom: 0; }
.stage.min .st-grip { cursor: pointer; }

@media (max-width: 1179px) {
  .stage { top: auto; left: calc(var(--side) + 14px); right: 14px; bottom: 12px; width: auto; height: var(--sheet-h); }
  .stage .st-grip { cursor: pointer; }
  .st-body { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(250px, 1fr); grid-template-rows: auto auto auto 1fr auto; }
  .st-view { grid-column: 1; grid-row: 1 / 6; min-height: 0; }
  .st-step { grid-column: 2; grid-row: 1; }
  .st-scrub { grid-column: 2; grid-row: 2; }
  .st-ctl { grid-column: 2; grid-row: 3; justify-content: flex-start; }
  .st-toggles { justify-content: flex-start; }
  .st-steps { grid-column: 2; grid-row: 4; flex-wrap: wrap; align-content: flex-start; overflow-y: auto; border-top: 0; }
  .st-foot { grid-column: 2; grid-row: 5; }
  .stage.min { left: auto; right: 14px; }
}
@media (max-width: 900px) {
  .stage { left: 8px; right: 8px; bottom: 8px; }
}
@media (max-width: 640px) {
  :root { --sheet-h: min(47vh, 430px); }
  .st-body { display: flex; }
  .st-view { min-height: 140px; }
  .st-hint, .st-viewbtns button[data-v="top"] { display: none; }
  .st-step { padding-top: 6px; }
  .st-steptitle { font-size: 14px; }
  .st-play button { width: 32px; height: 32px; }
  .st-play .st-pp { width: 38px; height: 38px; }
  .st-text { max-height: 3em; }
  .st-steps { flex-wrap: nowrap; }
  .st-foot { display: none; }
  .st-tabs button { padding: 4px 8px; }
}

/* ---------------- fold cards in the text */
.fold-card { display: flex; align-items: center; gap: 14px; justify-content: space-between; border: 1px solid var(--border); border-radius: 14px; padding: 12px 14px; margin: 18px 0; background: linear-gradient(135deg, var(--surface-2), var(--surface) 70%); transition: border-color .2s, box-shadow .2s; }
.fold-card.on-stage { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.fk-main { display: flex; gap: 14px; min-width: 0; flex: 1; align-items: flex-start; }
.fk-icon { width: 66px; height: 66px; flex: none; border-radius: 10px; background: var(--surface); border: 1px solid var(--border); padding: 3px; display: grid; place-items: center; }
.fk-icon svg { width: 100%; height: 100%; }
.fk-icon .pi-a { fill: var(--paper); stroke: var(--border-2); }
.fk-icon .pi-b { fill: var(--accent-soft); stroke: var(--accent); }
.fk-info { min-width: 0; }
.fk-kicker { font-size: 11px; text-transform: uppercase; letter-spacing: .07em; font-weight: 700; color: var(--eyebrow); }
.fk-title { font-weight: 600; font-size: 1.02rem; line-height: 1.3; }
.fk-cap { font-size: 14px; color: var(--text-2); line-height: 1.5; margin-top: 2px; }
.fk-cap > *:first-child { margin-top: 0; } .fk-cap > *:last-child { margin-bottom: 0; }
.fk-steps { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 7px; }
.fk-steps:empty { display: none; }
.fk-step { font: 500 11.5px var(--font); color: var(--text-2); background: var(--surface); border: 1px solid var(--border-2); border-radius: 99px; padding: 1px 9px; cursor: pointer; }
.fk-step:hover { border-color: var(--accent); color: var(--accent-ink); }
.fk-actions { flex: none; align-self: center; }
.fold-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 12px; }
.fold-grid .fold-card { margin: 0; flex-direction: column; align-items: stretch; }
.fold-grid .fk-actions { align-self: flex-start; }
.fold-grid .fk-steps { display: none; }
.fold-link { color: var(--accent-ink); border-bottom: 1px dashed color-mix(in srgb, var(--accent) 60%, transparent); cursor: pointer; }
.fold-link:hover { text-decoration: none; border-bottom-style: solid; }
.fold-link::after { content: '▶'; font-size: .62em; margin-left: .3em; vertical-align: .15em; }
@media (max-width: 560px) { .fold-card { flex-direction: column; align-items: stretch; } .fk-actions { align-self: flex-start; } .fk-icon { width: 52px; height: 52px; } }

/* ---------------- crease patterns and figures (SVG) */
.cp-svg { display: block; width: 100%; height: auto; }
.cp-paper { fill: var(--paper); }
.cp-svg line, .fig line, .fig path, .fig polyline, .fig polygon, .fig circle, .fig rect { vector-effect: non-scaling-stroke; }
.cp-svg line { stroke-linecap: round; }
.cp-b { stroke: var(--text); stroke-width: 2; fill: none; }
.cp-v { stroke: var(--accent); stroke-width: 1.6; stroke-dasharray: 6 4; fill: none; }
.cp-m { stroke: var(--bad); stroke-width: 1.6; stroke-dasharray: 9 3 2 3; fill: none; }
.cp-f { stroke: var(--muted); stroke-width: 1.2; fill: none; }
.cp-x { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 2 3; fill: none; }
.cp-now { stroke: var(--s2); stroke-width: 4; stroke-linecap: round; opacity: .9; }
.cp-svg .cp-dim { opacity: .18; }
.cp-svg .cp-focus { stroke-width: 2.6; }
.cp-legend .lg-focus { border-top: 3px solid var(--text); }
.reg { stroke: none; fill-opacity: .3; }
.reg-1 { fill: var(--s1); } .reg-2 { fill: var(--s2); } .reg-3 { fill: var(--s3); } .reg-4 { fill: var(--s4); }
.reg-5 { fill: var(--s5); } .reg-6 { fill: var(--s6); } .reg-7 { fill: var(--s7); } .reg-8 { fill: var(--s8); }
.reg-label { font: 600 4.2px var(--font); fill: var(--text); text-anchor: middle; dominant-baseline: middle; paint-order: stroke; stroke: var(--paper); stroke-width: 1px; stroke-linejoin: round; }
.cp-legend { display: flex; flex-wrap: wrap; justify-content: center; gap: 4px 14px; font-size: 11.5px; color: var(--muted); }
.cp-legend span { display: inline-flex; align-items: center; gap: 6px; }
.cp-legend i { display: inline-block; width: 22px; height: 0; border-top: 2px solid var(--text); }
.cp-legend .lg-v { border-top: 2px dashed var(--accent); }
.cp-legend .lg-m { border-top: 2px dotted var(--bad); }
.cp-legend .lg-f { border-top: 1.5px solid var(--muted); }
.cp-legend .lg-now { border-top: 4px solid var(--s2); border-radius: 2px; }
.cp-figure { margin: 18px auto; max-width: 380px; text-align: center; }
.cp-holder { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 14px; display: flex; flex-direction: column; align-items: center; gap: 8px; }
.cp-figure figcaption, .fig figcaption { font-size: 13px; color: var(--muted); margin-top: 6px; line-height: 1.45; text-align: center; }

/* author figures: <figure class="fig"><svg viewBox="0 0 100 100">…</svg><figcaption>…</figcaption></figure> */
.fig { margin: 18px auto; max-width: 420px; }
.fig.wide { max-width: 640px; }
.fig.row { max-width: 720px; display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; align-items: end; }
.fig.row figcaption { grid-column: 1 / -1; }
.fig svg { display: block; width: 100%; height: auto; overflow: visible; }
.fig .paper { fill: var(--paper); stroke: var(--text); stroke-width: 1.6; }
.fig .paper-2 { fill: var(--paper-2); stroke: var(--text); stroke-width: 1.2; }
.fig .ink { stroke: var(--text); stroke-width: 1.4; fill: none; }
.fig .thin { stroke: var(--muted); stroke-width: 1; fill: none; }
.fig .accent { stroke: var(--accent); stroke-width: 2; fill: none; }
.fig .hot { stroke: var(--s2); stroke-width: 2.4; fill: none; }
.fig .dot { fill: var(--text); }
.fig .dot-accent { fill: var(--accent); }
.fig text, .fig .lbl { font: 500 5px var(--font); fill: var(--text-2); }
.fig .lbl-sm { font: 500 3.8px var(--font); fill: var(--muted); }
.fig .lbl-b { font: 700 5.2px var(--font); fill: var(--text); }
.fig .mid { text-anchor: middle; }
.fig .end { text-anchor: end; }
.fig .sub { font-size: 3.6px; fill: var(--muted); }
.fig .arrow { stroke: var(--s2); stroke-width: 1.6; fill: none; marker-end: url(#arrowhead); }
.fig-cap-row { display: flex; justify-content: space-around; font-size: 12.5px; color: var(--muted); }

/* ---------------- chapter widgets (interactive figures defined in a chapter's `widgets`) */
.widget { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 14px 16px; margin: 18px 0; }
.widget .w-head { font-weight: 600; margin-bottom: 6px; display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.widget .w-head small { font-weight: 400; color: var(--muted); }
.widget .w-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(200px, 260px); gap: 16px; align-items: start; }
@media (max-width: 720px) { .widget .w-grid { grid-template-columns: 1fr; } }
.widget .w-ctl { display: flex; flex-direction: column; gap: 10px; font-size: 14px; }
.widget .w-ctl label { display: flex; flex-direction: column; gap: 2px; color: var(--text-2); }
.widget .w-ctl input[type=range] { accent-color: var(--accent); width: 100%; }
.widget .w-ctl output, .widget .w-val { font-variant-numeric: tabular-nums; font-weight: 600; color: var(--text); }
.widget .w-out { font-size: 14px; color: var(--text-2); }
.widget .w-out b { color: var(--text); font-variant-numeric: tabular-nums; }
.widget svg { display: block; width: 100%; height: auto; }
.widget .kpis { margin-top: 4px; }

@media print { .stage, .fold-card .fk-actions, .st-steps { display: none !important; } body.has-stage .main { margin-right: 0; padding-bottom: 0; } }
