/* lucien.ch — base styles */

@font-face { font-family: "NewCM"; src: url("fonts/NewCM10-Regular.woff2") format("woff2"); font-weight: 400; font-style: normal; font-display: swap; }
@font-face { font-family: "NewCM"; src: url("fonts/NewCM10-Italic.woff2") format("woff2"); font-weight: 400; font-style: italic; font-display: swap; }
@font-face { font-family: "NewCM"; src: url("fonts/NewCM10-Bold.woff2") format("woff2"); font-weight: 700; font-style: normal; font-display: swap; }
@font-face { font-family: "NewCM"; src: url("fonts/NewCM10-BoldItalic.woff2") format("woff2"); font-weight: 700; font-style: italic; font-display: swap; }
/* Typst's default math font, so MathML matches the PDF on every OS. */
@font-face { font-family: "NewCMMath"; src: url("fonts/NewCMMath-Regular.woff2") format("woff2"); font-display: block; }

:root {
  --fg: #1d1d1f;
  --muted: #6b6b70;
  --bg: #fdfcf9;
  --accent: #1f5fa8;
  --rule: #e4e2dc;
  --measure: 40rem;
}
@media (prefers-color-scheme: dark) {
  :root { --fg: #e8e6e1; --muted: #9a9893; --bg: #16161a; --accent: #8db8ea; --rule: #2c2c31; }
  /* Typst frames are drawn in black; invert them on dark backgrounds. */
  .diagram svg, .svg-math svg { filter: invert(0.92) hue-rotate(180deg); }
}

* { box-sizing: border-box; }
html { font-size: 112.5%; }
body {
  margin: 0; color: var(--fg); background: var(--bg);
  font-family: "NewCM", "Latin Modern Roman", Georgia, serif;
  line-height: 1.55; text-rendering: optimizeLegibility;
}
main, .site-header, .site-footer { max-width: var(--measure); margin: 0 auto; padding: 0 1.25rem; }
main { padding-bottom: 3rem; }

math { font-family: "NewCMMath", "Latin Modern Math", "STIX Two Math", math; }
math[display="block"] { margin: 1em 0; overflow-x: auto; overflow-y: hidden; padding: 0.1em 0; }

a { color: var(--accent); text-decoration-thickness: 0.06em; text-underline-offset: 0.15em; }
h1 { font-size: 2rem; line-height: 1.2; margin: 1.5rem 0 0.5rem; }
h2 { font-size: 1.4rem; margin-top: 2rem; }
h3 { font-size: 1.15rem; }
code, pre { font-family: ui-monospace, "DejaVu Sans Mono", Menlo, monospace; font-size: 0.85em; }
pre { overflow-x: auto; padding: 0.8em 1em; background: color-mix(in srgb, var(--fg) 5%, transparent); border-radius: 6px; }
figure { margin: 1.5em 0; text-align: center; }
figcaption { color: var(--muted); font-size: 0.9em; margin-top: 0.4em; }
blockquote { margin: 1em 0; padding-left: 1em; border-left: 3px solid var(--rule); color: var(--muted); }
table { border-collapse: collapse; margin: 1em auto; }
td, th { padding: 0.3em 0.7em; border-bottom: 1px solid var(--rule); }

.site-header { display: flex; justify-content: space-between; align-items: baseline; padding-top: 1.25rem; padding-bottom: 0.5rem; border-bottom: 1px solid var(--rule); }
.site-title { font-weight: 700; color: var(--fg); text-decoration: none; font-size: 1.15rem; }
.site-header nav a { margin-left: 1.1rem; color: var(--muted); text-decoration: none; }
.site-header nav a:hover { color: var(--accent); }
.site-footer { color: var(--muted); font-size: 0.85rem; padding-top: 1rem; padding-bottom: 2rem; border-top: 1px solid var(--rule); }

.meta { color: var(--muted); font-size: 0.9rem; margin-top: 0; }
.tag { color: var(--muted); text-decoration: none; }
.status { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.05em; padding: 0.1em 0.45em; border-radius: 3px; border: 1px solid var(--rule); }
.status.seedling { color: #8a6d00; } .status.budding { color: #3c7d2a; } .status.evergreen { color: #1b6b52; }

.list { list-style: none; padding: 0; }
.list li { margin: 0.9em 0; }
.list time { color: var(--muted); font-variant-numeric: tabular-nums; margin-right: 0.4em; font-size: 0.9em; }
.list .summary { margin: 0.15em 0 0; color: var(--muted); font-size: 0.92em; }
.lede { font-size: 1.15rem; }

/* overflow-x: auto also clips vertically, so leave room for labels that overhang the frame. */
.diagram, .svg-math { margin: 1.5em 0; padding: 0.75em 0; overflow-x: auto; }
.diagram svg, .svg-math svg { margin: 0 auto; max-width: 100%; height: auto; }

.backlinks { margin-top: 3rem; padding-top: 1rem; border-top: 1px solid var(--rule); font-size: 0.95rem; }
.backlinks h2 { font-size: 1rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); margin-top: 0; }
.garden-graph { height: 360px; margin: 1rem 0; border: 1px solid var(--rule); border-radius: 6px; }
.local-graph { height: 220px; margin: 1rem 0; border: 1px solid var(--rule); border-radius: 6px; }
.local-graph:empty, .garden-graph:empty { display: none; }

/* Hover previews and inline windows (assets/hover.js) */
.hover-card {
  position: absolute; z-index: 50; max-height: 22rem; overflow: auto;
  padding: 0.9rem 1.1rem; font-size: 0.92rem; line-height: 1.5;
  background: var(--bg); color: var(--fg); border: 1px solid var(--rule); border-radius: 8px;
  box-shadow: 0 8px 28px rgb(0 0 0 / 0.14);
}
.hover-card > :first-child { margin-top: 0; }
.hover-card > :last-child { margin-bottom: 0; }
.hover-card .hover-title, .window .hover-title { font-weight: 700; font-size: 1.05rem; margin-bottom: 0.2rem; }
.hover-card .meta { margin-bottom: 0.5rem; }
.hover-card figure, .hover-card .diagram { margin: 0.5em 0; }
.window-toggle {
  font: inherit; font-size: 0.75em; line-height: 1; vertical-align: 0.15em;
  margin-left: 0.15em; padding: 0.1em 0.35em; cursor: pointer;
  color: var(--muted); background: none; border: 1px solid var(--rule); border-radius: 4px;
}
.window-toggle:hover, .window-toggle[aria-expanded="true"] { color: var(--accent); border-color: var(--accent); }
.window {
  margin: 0.5rem 0 1rem; padding: 0.75rem 1rem; font-size: 0.95em;
  border-left: 3px solid var(--accent); background: color-mix(in srgb, var(--fg) 3%, transparent);
}
.window .window-open { display: inline-block; margin-top: 0.4rem; font-size: 0.9em; }

/* Equation numbers (lib/base.typ) */
.equation { display: flex; align-items: center; gap: 1rem; }
.equation > math { flex: 1; }
.equation > .eq-num { color: var(--muted); font-variant-numeric: tabular-nums; }

/* Sidenotes (lib/base.typ): footnotes in the margin, Tufte style.
   Narrow screens: the number is a toggle that unfolds the note below the line. */
:root { --sn-w: 15rem; --sn-gap: 2.25rem; }
section[role="doc-endnotes"] { display: none; }
.sidenote-number { cursor: pointer; color: var(--accent); padding: 0 0.1em; }
.sidenote-number sup, .sidenote-mark { font-size: 0.7em; line-height: 0; font-variant-numeric: lining-nums; }
.sidenote-number:has(+ .sidenote-toggle:focus-visible) { outline: 2px solid var(--accent); outline-offset: 1px; border-radius: 2px; }
.sidenote-toggle { position: absolute; opacity: 0; width: 1px; height: 1px; margin: 0; pointer-events: none; }
.sidenote {
  display: none; float: left; clear: both; width: 100%; margin: 0.5rem 0 0.75rem; padding: 0.5rem 0.9rem;
  font-size: 0.85rem; line-height: 1.45; text-align: left; color: var(--fg);
  border-left: 3px solid var(--accent); background: color-mix(in srgb, var(--fg) 3%, transparent);
}
.sidenote-mark { color: var(--muted); margin-right: 0.15em; }
.sidenote-toggle:checked + .sidenote { display: block; }
.sidenote math { font-size: 1em; }
/* Previews of other pages (hover.js) strip ids, so their toggles would be dead. */
.hover-card .sidenote, .window .sidenote { display: none !important; }
.hover-card .sidenote-number, .window .sidenote-number { pointer-events: none; color: inherit; }

/* Wide screens: notes sit in the right margin beside the line that cites them,
   and the column shifts left so text and margin are centred together. */
@media (min-width: 1100px) {
  html:not(.editing) body:has(.sidenote) :is(main, .site-header, .site-footer) {
    margin-left: max(0px, calc((100% - var(--measure) - var(--sn-gap) - var(--sn-w)) / 2));
  }
  html:not(.editing) .sidenote {
    display: block; float: right; clear: right; width: var(--sn-w); padding: 0; border: 0; background: none;
    margin: 0.3rem calc(-1 * (var(--sn-w) + var(--sn-gap))) 0.6rem 0; color: var(--muted);
  }
  html:not(.editing) .sidenote-number { cursor: default; }
  html:not(.editing) .sidenote-toggle { display: none; }
}

/* Edit in place (edit.js): the editor docks on the right and the page reflows. */
:root { --edit-w: min(46vw, 760px); --edit-ease: cubic-bezier(0.2, 0.8, 0.2, 1); }
html { transition: padding 360ms var(--edit-ease); }
html.editing { padding-right: var(--edit-w); }
.edit-dock {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 50; width: var(--edit-w);
  transform: translateX(100%); transition: transform 360ms var(--edit-ease);
  background: var(--bg); box-shadow: -18px 0 40px rgb(20 20 30 / 0.12);
}
html.editing .edit-dock { transform: none; }
.edit-dock iframe { display: block; width: 100%; height: 100%; border: 0; }
.edit-dock-handle { position: absolute; z-index: 1; top: 0; bottom: 0; left: -5px; width: 10px; cursor: col-resize; touch-action: none; }
.edit-dock-handle:hover { background: linear-gradient(to right, transparent 4px, var(--accent) 4px, var(--accent) 6px, transparent 6px); }
html.edit-resizing, html.edit-resizing .edit-dock { transition: none; }
html.edit-resizing .edit-dock iframe { pointer-events: none; }
html.edit-resizing { cursor: col-resize; user-select: none; }
.edit-tab {
  position: fixed; right: 0; top: 50%; z-index: 40; display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: 12px 8px; border: 0; border-radius: 10px 0 0 10px; cursor: pointer;
  background: var(--fg); color: var(--bg); font: 600 13px/1 system-ui, sans-serif; letter-spacing: 0.04em;
  transform: translate(calc(100% - 6px), -50%); opacity: 0.55; transition: transform 200ms var(--edit-ease), opacity 200ms;
}
.edit-tab:hover, .edit-tab:focus-visible { transform: translate(0, -50%); opacity: 1; }
.edit-tab svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.edit-tab span { writing-mode: vertical-rl; }
html.editing .edit-tab { opacity: 0; pointer-events: none; }
@media (max-width: 760px) {
  html.editing { padding-right: 0; padding-bottom: 58vh; }
  .edit-dock { top: auto; left: 0; width: auto; height: 58vh; transform: translateY(100%); box-shadow: 0 -12px 30px rgb(0 0 0 / 0.15); }
  .edit-dock-handle { display: none; }
  .edit-tab { top: auto; bottom: 16px; right: 16px; flex-direction: row; padding: 10px 14px; border-radius: 999px; transform: none; opacity: 0.9; }
  .edit-tab:hover, .edit-tab:focus-visible { transform: none; }
  .edit-tab span { writing-mode: horizontal-tb; }
}
@media (prefers-reduced-motion: reduce) { html, .edit-dock, .edit-tab { transition: none; } }

/* Search (search.js): a header button and an overlay with live results. */
.search-open {
  margin-left: 1.1rem; padding: 0.15em 0.35em 0.15em 0.6em; border: 1px solid var(--rule); border-radius: 999px;
  background: transparent; color: var(--muted); font: inherit; cursor: pointer; display: inline-flex; align-items: center; gap: 0.5em;
}
.search-open:hover { color: var(--accent); border-color: var(--accent); }
.search-open kbd, .search-dialog kbd {
  font: 0.72em/1 system-ui, sans-serif; padding: 0.3em 0.45em; border-radius: 6px;
  background: color-mix(in srgb, var(--fg) 7%, transparent); color: var(--muted);
}
.search-dialog {
  width: min(40rem, calc(100% - 2rem)); max-height: min(34rem, calc(100% - 6rem)); margin: 12vh auto auto; padding: 0;
  border: 1px solid var(--rule); border-radius: 14px; background: var(--bg); color: var(--fg);
  box-shadow: 0 30px 80px rgb(0 0 0 / 0.28); overflow: hidden; display: none; flex-direction: column;
}
.search-dialog[open] { display: flex; animation: search-in 160ms ease-out; }
@keyframes search-in { from { opacity: 0; transform: translateY(-8px) scale(0.98); } }
.search-dialog::backdrop { background: rgb(10 10 20 / 0.3); backdrop-filter: blur(3px); }
.search-box { display: flex; align-items: center; gap: 0.7rem; padding: 0.9rem 1.1rem; border-bottom: 1px solid var(--rule); }
.search-box svg { width: 1.15rem; height: 1.15rem; flex: none; fill: none; stroke: var(--muted); stroke-width: 2; stroke-linecap: round; }
.search-box input {
  flex: 1; min-width: 0; border: 0; outline: 0; background: transparent; color: var(--fg); font: inherit; font-size: 1.1rem;
}
.search-box input::-webkit-search-cancel-button { display: none; }
.search-results { list-style: none; margin: 0; padding: 0.4rem; overflow-y: auto; }
.search-results:empty { display: none; }
.search-results a { display: grid; grid-template-columns: 1fr auto; gap: 0.15rem 1rem; padding: 0.6rem 0.8rem; border-radius: 9px; color: inherit; text-decoration: none; }
.search-results li[aria-selected="true"] a { background: color-mix(in srgb, var(--accent) 12%, transparent); }
.search-title { font-weight: 600; }
.search-where { font: 0.75em/1.9 system-ui, sans-serif; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }
.search-excerpt { grid-column: 1 / -1; color: var(--muted); font-size: 0.9em; line-height: 1.45; }
.search-excerpt mark { background: color-mix(in srgb, var(--accent) 22%, transparent); color: var(--fg); border-radius: 2px; padding: 0 0.1em; }
.search-note { margin: 0; padding: 0.55rem 1.1rem; border-top: 1px solid var(--rule); color: var(--muted); font: 0.78rem/1.4 system-ui, sans-serif; }
@media (max-width: 600px) {
  .search-open kbd { display: none; }
  .search-dialog { margin-top: 1rem; max-height: calc(100% - 2rem); }
}
@media (prefers-reduced-motion: reduce) { .search-dialog[open] { animation: none; } }
