/* cpumemory — gwern/algorithmica-style minimal theme: off-white background,
   dark serif text, thin rules instead of boxed panels, dotted-underline
   lookup terms, and stacked hover popups for rabbit-holing. */

:root {
  --bg: #fffefc;
  --panel: #f7f6f2;
  --panel2: #f0eee8;
  --text: #16130f;
  --muted: #6e6a63;
  --accent: #385170;
  --accent2: #8a5a2b;
  --green: #2f6b3a;
  --red: #8e3b3b;
  --border: #d9d5cc;
  --code-bg: #f4f2ec;
  --mark: #eee9dd;
  --serif: "EB Garamond", "ET Book", "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 19px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--serif);
  line-height: 1.6;
}

#layout { display: flex; min-height: 100vh; }

/* ---------- sidebar ---------- */
#sidebar {
  width: 280px;
  flex: 0 0 280px;
  border-right: 1px solid var(--border);
  padding: 1.4rem 1.1rem;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  font-family: var(--sans);
  background: var(--bg);
}
#brand h1 {
  margin: 0;
  font-size: 1.05rem;
  letter-spacing: 0.02em;
  font-family: var(--serif);
  font-weight: 700;
}
#brand .sub { color: var(--muted); font-size: 0.74rem; margin: 0.35rem 0; line-height: 1.45; }
#brand a { color: var(--accent); text-decoration: none; border-bottom: 1px dotted var(--accent); }
#brand a:hover { border-bottom-style: solid; }

#search {
  width: 100%;
  margin: 0.6rem 0;
  padding: 0.4rem 0.55rem;
  border-radius: 3px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 0.8rem;
  font-family: var(--sans);
}
#search:focus { outline: 1px solid var(--accent); }
#search-results {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 3px;
  margin-bottom: 0.6rem;
  max-height: 40vh;
  overflow-y: auto;
  font-size: 0.78rem;
}
#search-results a {
  display: block;
  padding: 0.35rem 0.55rem;
  color: var(--text);
  text-decoration: none;
  border-bottom: 1px solid var(--border);
}
#search-results a:hover { background: var(--mark); }
#search-results .kind { color: var(--muted); font-size: 0.68rem; margin-right: 0.4rem; }

#toc { font-size: 0.8rem; }
#toc a {
  display: block;
  color: var(--text);
  text-decoration: none;
  padding: 0.18rem 0.4rem;
  border-left: 2px solid transparent;
}
#toc a:hover { background: var(--panel); }
#toc a.active { border-left-color: var(--accent); color: var(--accent); background: var(--panel); }
#toc .lvl2 { padding-left: 1.3rem; color: var(--muted); font-size: 0.75rem; }
#toc .lvl2.active { color: var(--accent); }
#sidebar-foot { margin-top: 1rem; border-top: 1px solid var(--border); padding-top: 0.7rem; }
#sidebar-foot .sub { color: var(--muted); font-size: 0.72rem; }

/* ---------- content ---------- */
#content {
  flex: 1;
  max-width: 760px;
  padding: 2.4rem 3rem 6rem;
  margin: 0 auto;
}
#content h1 {
  font-size: 1.65rem;
  font-weight: 700;
  border-bottom: 1px solid var(--text);
  padding-bottom: 0.4rem;
  line-height: 1.25;
}
#content h2 { font-size: 1.25rem; margin-top: 2.4rem; font-weight: 700; }
#content h3 { font-size: 1.02rem; margin-top: 1.9rem; font-weight: 700; font-style: italic; }
#content h2 .sec-num, #content h1 .sec-num { color: var(--muted); margin-right: 0.5rem; font-weight: 400; }

a { color: var(--accent); }
#content a:not(.pdf-link) {
  text-decoration: none;
  border-bottom: 1px dotted var(--accent);
}
#content a:not(.pdf-link):hover { border-bottom-style: solid; }

.pdf-link {
  font-size: 0.62rem;
  font-family: var(--sans);
  color: var(--muted);
  text-decoration: none;
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 0.08rem 0.35rem;
  margin-left: 0.6rem;
  vertical-align: middle;
  white-space: nowrap;
  font-weight: 400;
  font-style: normal;
}
.pdf-link:hover { color: var(--accent); border-color: var(--accent); }

p { margin: 0.9rem 0; }
ul, ol { padding-left: 1.4rem; }
li { margin: 0.35rem 0; }

dfn, dfn.demo {
  font-style: normal;
  cursor: help;
  border-bottom: 1px dotted var(--muted);
  color: inherit;
}
dfn:hover { border-bottom-color: var(--accent); color: var(--accent); }

code {
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 0.02rem 0.28rem;
  font-size: 0.82em;
  font-family: var(--mono);
}
pre {
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 0.8rem 1rem;
  overflow-x: auto;
  font-size: 0.78rem;
  line-height: 1.5;
}
pre code { background: none; border: none; padding: 0; }

/* callouts — thin left rule, no fill */
.note, .key, .warn {
  border-left: 2px solid var(--accent);
  padding: 0.1rem 1rem;
  margin: 1.1rem 0;
  font-size: 0.92rem;
}
.key { border-left-color: var(--green); }
.warn { border-left-color: var(--accent2); }
.note .tag, .key .tag, .warn .tag {
  display: block;
  font-family: var(--sans);
  font-size: 0.64rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted);
  margin: 0.5rem 0 0.1rem;
}

/* collapsible deep dives */
details.deep {
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  margin: 1.1rem 0;
}
details.deep > summary {
  cursor: pointer;
  padding: 0.5rem 0.2rem;
  font-size: 0.88rem;
  color: var(--accent);
  user-select: none;
  font-family: var(--sans);
}
details.deep > .body { padding: 0 0.2rem 0.8rem; font-size: 0.93rem; }

/* figures + tables */
figure {
  margin: 1.6rem 0;
  padding: 0;
  text-align: center;
}
figure img { max-width: 100%; }
figure svg { max-width: 100%; height: auto; }
figcaption {
  color: var(--muted);
  font-size: 0.78rem;
  margin-top: 0.5rem;
  text-align: center;
  font-family: var(--sans);
}

table.data {
  border-collapse: collapse;
  margin: 1.2rem auto;
  font-size: 0.84rem;
  font-family: var(--sans);
}
table.data th, table.data td {
  border: none;
  border-bottom: 1px solid var(--border);
  padding: 0.32rem 0.7rem;
  text-align: right;
}
table.data th {
  border-bottom: 2px solid var(--text);
  text-align: center;
  font-weight: 600;
}
table.data td.l, table.data th.l { text-align: left; }

/* svg diagram common styles */
.d-box { fill: var(--panel); stroke: var(--border); }
.d-box-hi { fill: var(--mark); stroke: var(--accent); }
.d-txt { fill: var(--text); font-size: 12px; font-family: var(--sans); }
.d-txt-mut { fill: var(--muted); font-size: 11px; font-family: var(--sans); }
.d-line { stroke: var(--muted); stroke-width: 1.2; fill: none; }
.d-line-hi { stroke: var(--accent); stroke-width: 1.6; fill: none; }

/* interactive widgets */
.widget {
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 1rem;
  margin: 1.4rem 0;
  font-family: var(--sans);
  background: var(--panel);
}
.widget h4 {
  margin: 0 0 0.6rem;
  font-size: 0.72rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.1em;
}
.widget label { font-size: 0.8rem; color: var(--muted); margin-right: 0.5rem; }
.widget input[type=range] { width: 220px; vertical-align: middle; }
.widget .readout { font-family: var(--mono); font-size: 0.82rem; color: var(--green); }
.widget button {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 0.3rem 0.8rem;
  cursor: pointer;
  font-size: 0.8rem;
  margin-right: 0.4rem;
  font-family: var(--sans);
}
.widget button:hover { border-color: var(--accent); color: var(--accent); }
.widget .out {
  margin-top: 0.7rem;
  font-family: var(--mono);
  font-size: 0.8rem;
  white-space: pre-wrap;
}

/* chapter nav footer */
.chap-nav {
  display: flex;
  justify-content: space-between;
  margin-top: 3rem;
  border-top: 1px solid var(--border);
  padding-top: 1rem;
  font-family: var(--sans);
}
.chap-nav a { color: var(--accent); text-decoration: none; font-size: 0.85rem; }
.chap-nav a:hover { text-decoration: underline; }

/* ---------- stacked hover popups (gwern-style) ---------- */
.popup {
  position: absolute;
  z-index: 50;
  max-width: 420px;
  background: var(--bg);
  border: 1px solid var(--text);
  padding: 0.75rem 0.95rem;
  box-shadow: 3px 3px 0 rgba(22, 19, 15, 0.12);
  font-size: 0.84rem;
  line-height: 1.55;
}
.popup .popup-title {
  font-weight: 700;
  margin-bottom: 0.3rem;
  font-size: 0.9rem;
}
.popup .popup-body p:first-child { margin-top: 0; }
.popup .popup-body p:last-child { margin-bottom: 0; }
.popup .popup-foot {
  margin-top: 0.55rem;
  padding-top: 0.45rem;
  border-top: 1px solid var(--border);
  font-size: 0.72rem;
  font-family: var(--sans);
  color: var(--muted);
}
.popup .popup-foot a { color: var(--muted); }
.popup .popup-foot a:hover { color: var(--accent); }
.popup .backlinks { margin-top: 0.3rem; }
.popup .backlinks a { margin-right: 0.55rem; white-space: nowrap; }
.popup .popup-pin {
  float: right;
  cursor: pointer;
  color: var(--muted);
  font-family: var(--sans);
  font-size: 0.7rem;
  border: none;
  background: none;
  padding: 0 0 0 0.5rem;
}
.popup .popup-pin:hover { color: var(--accent); }
.popup.pinned { border-width: 2px; }

/* section-preview popups */
.popup.xref { max-width: 480px; max-height: 320px; overflow-y: auto; }
.popup.xref .popup-body h1, .popup.xref .popup-body h2, .popup.xref .popup-body h3 {
  font-size: 1rem;
  margin: 0.2rem 0 0.5rem;
  border: none;
  padding: 0;
}

@media (max-width: 900px) {
  #layout { flex-direction: column; }
  #sidebar { position: static; width: 100%; flex: none; height: auto; }
  #content { padding: 1rem 1.2rem 4rem; }
}
