/* symlet - dark is an instrument panel, light is clean paper. */
:root {
  --bg: #0c1117;
  --side: #090d12;
  --panel: #141c26;
  --raise: #1c2633;
  --line: #243040;
  --hair: #1a232e;
  --grid: rgba(110, 150, 180, 0.05);
  --ink: #e9eef4;
  --dim: #8c99a7;
  --amber: #e3ad5a;
  --cyan: #52c5b6;
  --rose: #e2718a;
  --ghost: #4f5e6c;
  --shadow: rgba(0, 0, 0, 0.5);
  --radius: 11px;
  --kw: #e3ad5a; --st: #8fcf7c; --cm: #6a7886; --nm: #52c5b6; --fn: #7cabe0; --pp: #e2718a;
  --sans: "Inter", "IBM Plex Sans", "Segoe UI", "Helvetica Neue", Roboto, Arial, sans-serif;
  --mono: "IBM Plex Mono", "SF Mono", Menlo, Consolas, "DejaVu Sans Mono", monospace;
  --bg-glow: radial-gradient(1200px 600px at 84% -10%, rgba(82, 197, 182, 0.045), transparent 60%),
             radial-gradient(1000px 520px at 6% -2%, rgba(227, 173, 90, 0.025), transparent 58%);
  font-size: 17px;
}
:root[data-theme="light"] {
  --bg: #f5f3ec;
  --side: #ebe7dd;
  --panel: #fffefb;
  --raise: #fffefb;
  --line: #d8d4c9;
  --hair: #e6e2d8;
  --grid: rgba(45, 95, 120, 0.07);
  --ink: #171b20;
  --dim: #566069;
  --amber: #a85d16;
  --cyan: #0d6f66;
  --rose: #b32945;
  --ghost: #9aa0a7;
  --shadow: rgba(40, 52, 64, 0.11);
  --kw: #a85d16; --st: #2f7d32; --cm: #8a9099; --nm: #0d6f66; --fn: #3454a8; --pp: #b32945;
  --bg-glow: none;
}
* { box-sizing: border-box; }
html { background: var(--bg); }
body {
  margin: 0; color: var(--ink); background: var(--bg-glow), var(--bg); background-attachment: fixed;
  font-family: var(--sans); font-variant-numeric: tabular-nums; line-height: 1.58;
  -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
  display: grid; grid-template-columns: 276px 1fr; grid-template-rows: auto auto 1fr; min-height: 100vh;
}
::selection { background: var(--amber); color: #0c1117; }
a { color: var(--amber); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 3px; text-decoration-thickness: 1px; }
:focus-visible { outline: 2px solid var(--cyan); outline-offset: 2px; border-radius: 3px; }
.mast { font-family: var(--mono); font-size: 1.9rem; color: var(--ink); font-weight: 600; letter-spacing: -0.03em; }
.mast b { color: var(--amber); font-weight: 600; }

/* ---- sidebar ---- */
#contents {
  grid-row: 1 / 4; background: var(--side); border-right: 1px solid var(--line);
  padding: 24px 16px 28px; position: sticky; top: 0; height: 100vh; overflow-y: auto; align-self: start;
  display: flex; flex-direction: column; gap: 2px;
}
#contents::-webkit-scrollbar { width: 9px; }
#contents::-webkit-scrollbar-thumb { background: var(--line); border-radius: 5px; border: 2px solid var(--side); }
#contents .tagline { font-family: var(--mono); font-size: 0.72rem; letter-spacing: 0.08em; color: var(--ghost); margin: 2px 2px 0; }
#contents .tools { margin: 14px 0 10px; }
#contents .part { font-family: var(--mono); color: var(--ghost); font-size: 0.7rem; letter-spacing: 0.16em; text-transform: uppercase; margin: 18px 2px 5px; }
#contents a.ch { color: var(--dim); font-size: 0.95rem; padding: 5px 10px; border-radius: 7px; line-height: 1.35; transition: color 0.12s, background 0.12s; }
#contents a.ch:hover { color: var(--ink); background: color-mix(in srgb, var(--panel) 60%, transparent); text-decoration: none; }
#contents a.ch.here { color: var(--ink); background: var(--panel); box-shadow: inset 2px 0 0 var(--cyan); }
#contents a.sec { font-family: var(--mono); color: var(--dim); font-size: 0.8rem; line-height: 1.4; margin-left: 14px; padding: 3px 10px; border-radius: 6px; transition: color 0.12s, background 0.12s; }
#contents a.sec:hover { color: var(--amber); text-decoration: none; }
#contents a.sec.on { color: var(--ink); background: color-mix(in srgb, var(--panel) 80%, transparent); box-shadow: inset 2px 0 0 var(--amber); }
h3[id], [data-nav], .jump { scroll-margin-top: 16px; }
#theme {
  font-family: var(--mono); font-size: 0.78rem; letter-spacing: 0.04em; padding: 5px 12px;
  background: transparent; border: 1px solid var(--line); border-radius: 7px; color: var(--dim);
}
#theme:hover { color: var(--ink); border-color: var(--cyan); }

/* ---- topbar (mobile only) ---- */
#topbar { display: none; }
#backdrop { display: none; }

/* ---- main column ---- */
main { grid-column: 2; max-width: 1000px; padding: 32px 44px 28px; min-width: 0; }
h1 { font-size: clamp(1.8rem, 1.4rem + 1.6vw, 2.3rem); font-weight: 650; letter-spacing: -0.025em; margin: 4px 0 10px; line-height: 1.12; }
h2 { font-size: 1.42rem; font-weight: 640; letter-spacing: -0.015em; margin: 0 0 8px; }
h2 small { font-family: var(--mono); font-weight: normal; color: var(--dim); font-size: 0.82rem; margin-left: 12px; letter-spacing: 0; }
h3 { font-family: var(--mono); font-size: 0.82rem; font-weight: normal; letter-spacing: 0.1em; text-transform: uppercase; color: var(--cyan); margin: 22px 0 8px; }
section { margin: 40px 0 0; padding-top: 22px; border-top: 1px solid var(--line); scroll-margin-top: 16px; }
p.lede { font-size: clamp(1.08rem, 1rem + 0.5vw, 1.22rem); color: var(--ink); margin: 0 0 20px; max-width: 68ch; line-height: 1.55; }
p { max-width: 70ch; line-height: 1.68; }

/* ---- controls ---- */
.row { display: flex; gap: 14px; flex-wrap: wrap; align-items: center; margin: 12px 0; min-height: 42px; }
.row label { font-family: var(--mono); color: var(--dim); font-size: 0.78rem; letter-spacing: 0.04em; }
.row .note { display: inline-block; min-width: 11ch; }
.row .pair { display: inline-flex; align-items: center; gap: 14px; }   /* a label and its slider, kept on one line together */
select, button, input[type=file], input[type=text], input[type=search], input[type=number] {
  font: inherit; font-size: 0.98rem; color: var(--ink); background: var(--panel);
  border: 1px solid var(--line); border-radius: 8px; padding: 8px 14px; cursor: pointer;
  transition: border-color 0.12s, background 0.12s, transform 0.04s;
}
button:hover, select:hover { border-color: var(--amber); }
button:active { transform: translateY(1px); }
/* a pressed button is drawn heavier with a hairline of its own color, which leaves its width alone, so the buttons beside it stay where they are */
button.on { background: var(--amber); color: #15120a; border-color: var(--amber); -webkit-text-stroke: 0.4px currentColor; }
input[type=text], input[type=search], input[type=number] { cursor: text; }
input[type=range] { -webkit-appearance: none; appearance: none; width: 150px; height: 4px; padding: 0; background: var(--line); border: none; border-radius: 3px; cursor: pointer; }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 18px; height: 18px; border-radius: 50%; background: var(--cyan); border: 2px solid var(--bg); box-shadow: 0 1px 4px var(--shadow); cursor: pointer; }
input[type=range]:disabled { opacity: 0.35; cursor: default; }
input[type=range]::-moz-range-thumb { width: 16px; height: 16px; border-radius: 50%; background: var(--cyan); border: 2px solid var(--bg); cursor: pointer; }

/* ---- figures ---- */
canvas { display: block; width: 100%; height: auto; border-radius: var(--radius); border: 1px solid var(--line);
  background-color: var(--panel); box-shadow: 0 1px 2px var(--shadow);
  background-image: linear-gradient(var(--grid) 1px, transparent 1px), linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 26px 26px; }
.band { margin: 12px 0; }
.band .tag { font-family: var(--mono); min-height: 1.4em; display: flex; justify-content: space-between; gap: 12px; color: var(--dim); font-size: 0.76rem; padding: 0 2px 5px; }
.band .tag span.n { color: var(--ink); white-space: nowrap; }
.band .tag span:last-child { text-align: right; }
.twin { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.twin h2 { font-family: var(--mono); font-size: 0.82rem; font-weight: normal; letter-spacing: 0.08em; text-transform: uppercase; color: var(--cyan); margin: 0 0 6px; }
.note { font-family: var(--mono); color: var(--dim); font-size: 0.78rem; }
.hint { color: var(--dim); font-size: 0.92rem; margin: 6px 0 0; }
figure.fig { margin: 24px 0 28px; max-width: 760px; }
figure.fig svg { display: block; width: 100%; height: auto; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 1px 2px var(--shadow); }
figure.fig canvas { min-height: 170px; }
figure.fig figcaption { font-size: 0.92rem; color: var(--dim); margin-top: 10px; line-height: 1.55; max-width: 66ch; }
figure.fig text { font-family: var(--mono); font-weight: 500; font-size: 18px; fill: var(--dim); }
@media (max-width: 600px) { figure.fig text { font-size: 34px; } }
.f-cyan { fill: var(--cyan); } .f-amber { fill: var(--amber); } .f-ink { fill: var(--ink); } .f-panel2 { fill: var(--raise); }
figure.fig text.f-cyan { fill: var(--cyan); } figure.fig text.f-amber { fill: var(--amber); } figure.fig text.f-ink { fill: var(--ink); }
.s-cyan { stroke: var(--cyan); fill: none; } .s-amber { stroke: var(--amber); fill: none; } .s-ink { stroke: var(--ink); fill: none; } .s-dim { stroke: var(--ghost); fill: none; }
.tile { fill: color-mix(in srgb, var(--cyan) 12%, transparent); stroke: var(--cyan); stroke-width: 1; }
.scroll-x { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.scroll-x table { min-width: 620px; }

/* ---- pictures ---- */
canvas.pic { background-image: none; background-color: #05070a; touch-action: none; cursor: crosshair; }
p.note.say { min-height: 3.2em; margin: 10px 2px 12px; font-size: 0.82rem; line-height: 1.6; max-width: none; }
p.note.say b { color: var(--amber); font-weight: 500; }
.row label.filebtn { font-family: var(--sans); font-size: 0.98rem; letter-spacing: 0; color: var(--ink); background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 8px 14px; cursor: pointer; transition: border-color 0.12s; }
.row label.filebtn:hover { border-color: var(--amber); }
.row label.filebtn.on { background: var(--amber); color: #15120a; border-color: var(--amber); -webkit-text-stroke: 0.4px currentColor; }
.filebtn input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.lab { display: grid; grid-template-columns: minmax(0, 1.9fr) minmax(250px, 1fr); gap: 18px; align-items: start; margin: 12px 0; }
.lab h3 { margin-top: 0; }
.stack { max-width: 700px; }
.mixrow { display: grid; grid-template-columns: 8.6em 1fr 3.6em; gap: 10px; align-items: center; min-height: 40px; }
.mixrow label { font-family: var(--mono); font-size: 0.78rem; color: var(--dim); }
.mixrow input[type=range] { width: 100%; }
.mixrow .note { text-align: right; }
.thumbs { display: grid; grid-template-columns: repeat(5, 1fr); gap: 10px; margin: 14px 0 6px; }
.thumb { padding: 6px 6px 8px; text-align: left; display: block; min-width: 0; }
.thumb canvas { border-radius: 6px; margin-bottom: 7px; cursor: pointer; }
.thumb b { display: block; font-size: 0.82rem; font-weight: 600; }
.thumb span { display: block; font-family: var(--mono); font-size: 0.68rem; color: var(--dim); margin-top: 1px; }
canvas.map { image-rendering: pixelated; }
.thumbs.four { grid-template-columns: repeat(4, 1fr); max-width: 900px; }
.thumb.on { border-color: var(--amber); box-shadow: inset 0 0 0 1px var(--amber); }
@media (max-width: 900px) {
  .lab { grid-template-columns: 1fr; }
  .thumbs { grid-template-columns: repeat(5, 148px); overflow-x: auto; padding-bottom: 8px; }
  .thumbs.four { grid-template-columns: repeat(2, 1fr); overflow-x: visible; }
}
.kgrid { display: grid; grid-template-columns: repeat(3, 64px); gap: 6px; margin: 4px 0 6px; }
.kgrid input { width: 64px; padding: 8px 2px; text-align: center; font-family: var(--mono); font-size: 0.95rem; }

/* ---- darkroom chapters ---- */
.trio { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; margin: 14px 0; max-width: 900px; }
.trio h3 { margin: 0 0 6px; }
.trio canvas.pic { cursor: default; touch-action: auto; }
canvas.still { cursor: default; touch-action: auto; }
.zones { display: grid; grid-template-columns: repeat(11, 1fr); max-width: 760px; margin: 18px 0 8px; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.zones span { font-family: var(--mono); font-size: 0.86rem; text-align: center; padding: 18px 0 16px; }
.swatch { display: inline-block; width: 46px; height: 26px; border-radius: 6px; border: 1px solid var(--line); vertical-align: middle; }
ol.steps { max-width: 68ch; padding-left: 1.4em; margin: 10px 0 16px; }
ol.steps li { margin: 0 0 0.7em; line-height: 1.64; padding-left: 4px; }
ol.steps li::marker { font-family: var(--mono); color: var(--amber); }
.sliders { display: grid; grid-template-columns: 1fr 5.6em; gap: 2px 12px; align-items: center; margin: 8px 0 12px; max-width: 460px; }
.sliders label { grid-column: 1 / -1; margin-top: 8px; font-family: var(--mono); font-size: 0.78rem; color: var(--dim); letter-spacing: 0.04em; }
.sliders input[type=range] { width: 100%; min-width: 90px; }
.sliders .note { text-align: right; color: var(--ink); }
.lab .row { margin: 8px 0; }
@media (max-width: 700px) { .trio { grid-template-columns: 1fr; max-width: 420px; } .zones span { font-size: 0.7rem; padding: 14px 0 12px; } }

/* ---- footer / pager ---- */
footer { grid-column: 2; border-top: 1px solid var(--line); padding: 20px 44px 34px; margin: 28px 0 0; align-self: end; }
footer .brand { font-family: var(--mono); font-size: 0.82rem; color: var(--dim); }
footer .brand b { color: var(--ink); font-weight: 600; }
footer .brand a { color: var(--amber); }
footer .brand .sep { margin: 0 0.5em; color: var(--ghost); }
.pager { grid-column: 2; display: flex; justify-content: space-between; gap: 20px; padding: 16px 44px 8px; max-width: 1000px; font-size: 1rem; }
.pager a { display: inline-flex; align-items: center; gap: 6px; padding: 10px 16px; border: 1px solid var(--line); border-radius: 9px; background: var(--panel); color: var(--ink); box-shadow: 0 1px 2px var(--shadow); }
.pager a:hover { border-color: var(--amber); text-decoration: none; }
ul.clips { list-style: none; padding: 0; margin: 0 0 14px; display: flex; gap: 10px; flex-wrap: wrap; }
ul.clips button { padding: 6px 12px; }

/* ---- code ---- */
pre, code { font-family: var(--mono); }
pre { font-size: 0.85rem; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 15px 18px; overflow-x: auto; line-height: 1.6; margin: 10px 0; box-shadow: 0 1px 2px var(--shadow); }
pre.math { font-size: 0.9rem; color: var(--ink); line-height: 1.62; }
pre.math b { color: var(--amber); font-weight: normal; }
pre.math i { color: var(--cyan); font-style: normal; }
p code, li code, dd code { background: var(--panel); border: 1px solid var(--line); border-radius: 5px; padding: 0.5px 5px; font-size: 0.9em; }
.kw { color: var(--kw); } .st { color: var(--st); } .cm { color: var(--cm); font-style: italic; } .nm { color: var(--nm); } .fn { color: var(--fn); } .pp { color: var(--pp); }
.code { margin: 14px 0; }
.code .tabs { display: flex; gap: 3px; }
.code .tabs button { font-family: var(--mono); font-size: 0.78rem; padding: 5px 13px; border-radius: 8px 8px 0 0; border-bottom: none; color: var(--dim); background: transparent; }
.code .tabs button.on { color: var(--ink); background: var(--panel); border-color: var(--line); }
.code pre { margin-top: 0; border-top-left-radius: 0; }

/* ---- prose furniture ---- */
.aside { border-left: 3px solid var(--cyan); background: color-mix(in srgb, var(--cyan) 7%, transparent); padding: 10px 18px; margin: 16px 0; color: var(--dim); max-width: 72ch; font-size: 0.96rem; border-radius: 0 8px 8px 0; }
.aside b { color: var(--ink); font-weight: 600; }
aside.sidenote { border: 1px solid color-mix(in srgb, var(--amber) 38%, var(--line)); border-left: 4px solid var(--amber); background: color-mix(in srgb, var(--amber) 7%, var(--panel)); border-radius: 0 var(--radius) var(--radius) 0; padding: 14px 20px 8px; margin: 26px 0 30px; max-width: 68ch; }
aside.sidenote .tag { display: block; font-family: var(--mono); font-size: 0.72rem; letter-spacing: 0.16em; text-transform: uppercase; color: var(--amber); }
aside.sidenote h4 { margin: 3px 0 8px; font-size: 1.1rem; font-weight: 640; letter-spacing: -0.01em; }
aside.sidenote p { font-size: 0.98rem; line-height: 1.64; margin: 0 0 0.75em; color: var(--ink); max-width: none; }
aside.sidenote p b { font-weight: 640; }
.readout { font-family: var(--mono); min-height: 4.6em; font-size: 0.85rem; color: var(--ink); background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 16px; margin: 10px 0; box-shadow: 0 1px 2px var(--shadow); display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 7px 20px; }
.readout b { color: var(--amber); font-weight: normal; }
.readout .bad { color: var(--rose); } .readout .good { color: var(--cyan); }
dl { display: grid; grid-template-columns: max-content 1fr; gap: 9px 24px; max-width: 80ch; }
dt { font-family: var(--mono); font-size: 0.88rem; color: var(--amber); } dd { margin: 0; }
table { border-collapse: collapse; font-size: 0.94rem; margin: 10px 0; width: 100%; }
td, th { text-align: left; padding: 8px 14px; border-bottom: 1px solid var(--hair); vertical-align: top; }
tbody tr:hover { background: color-mix(in srgb, var(--panel) 50%, transparent); }
th { font-family: var(--mono); font-size: 0.76rem; letter-spacing: 0.05em; color: var(--dim); font-weight: normal; border-bottom-color: var(--line); }

/* ---- mobile ---- */
@media (max-width: 900px) {
  :root { font-size: 16px; }
  body { display: block; }
  #contents { position: fixed; left: 0; top: 0; width: 290px; max-width: 86vw; transform: translateX(-100%);
    transition: transform 0.22s ease; z-index: 30; box-shadow: 0 0 40px var(--shadow); }
  #contents.open { transform: none; }
  #backdrop.show { display: block; position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 20; }
  #topbar { display: flex; align-items: center; gap: 14px; padding: 11px 16px; position: sticky; top: 0; z-index: 15;
    background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line); }
  #topbar .mast { font-size: 1.5rem; }
  #topbar .spacer { flex: 1; }
  #topbar button { font-family: var(--mono); font-size: 0.82rem; padding: 7px 12px; border-radius: 8px; }
  #menu::before { content: "\2630"; margin-right: 7px; }
  main { grid-column: 1; padding: 18px 16px 28px; max-width: 100%; }
  footer, .pager { grid-column: 1; padding-left: 16px; padding-right: 16px; }
  section, h3[id], [data-nav], .jump { scroll-margin-top: 64px; }
  .pager { flex-wrap: wrap; }
  .pager a { flex: 1; min-width: 44%; justify-content: center; }
  .twin { grid-template-columns: 1fr; }
}
@media (max-width: 600px) {
  .row input[type=range] { width: 118px; }
  .row .note { min-width: 8ch; }
  p.note.say { min-height: 4.8em; }
  .band .tag { flex-direction: column; gap: 1px; }
  .band .tag span.n { white-space: normal; }
  .band .tag span:last-child { text-align: left; min-height: 1.3em; }
  dl { grid-template-columns: 1fr; gap: 2px; }
  dt { margin-top: 12px; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
