/* borie.pro — all site styling lives here. Structural HTML only elsewhere. */

/* Neutral, professional greyscale. One near-neutral accent, used sparingly. */
:root, :root[data-theme="light"] {
  --bg: #ffffff;
  --fg: #18181b;         /* zinc-900 */
  --muted: #71717a;      /* zinc-500 */
  --accent: #3f3f46;     /* zinc-700 — links, hover */
  --border: #e4e4e7;     /* zinc-200 */
  --code-bg: #f4f4f5;    /* zinc-100 */
  --card-bg: #fafafa;    /* zinc-50  */
  --measure: 42rem;      /* article reading width */
  --measure-wide: 60rem; /* home / listing width  */
}

/* Dark values: applied by the browser default (prefers-color-scheme) AND, with
   higher specificity, when the toggle sets data-theme="dark". */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121316;
    --fg: #e7e7ea;
    --muted: #a1a1aa;    /* zinc-400 */
    --accent: #d4d4d8;   /* zinc-300 */
    --border: #2a2b30;
    --code-bg: #1b1c20;
    --card-bg: #17181c;
  }
}
:root[data-theme="dark"] {
  --bg: #121316;
  --fg: #e7e7ea;
  --muted: #a1a1aa;
  --accent: #d4d4d8;
  --border: #2a2b30;
  --code-bg: #1b1c20;
  --card-bg: #17181c;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, sans-serif;
  line-height: 1.65;
  font-size: 18px;
}

/* Layout */
.site-header,
.content,
.site-footer {
  width: 100%;
  max-width: var(--measure);
  margin-inline: auto;
  padding-inline: 1.25rem;
}

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding-block: 1.5rem;
}

.site-title {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  font-weight: 700;
  font-size: 1.15rem;
  letter-spacing: -0.01em;
  text-decoration: none;
  color: var(--fg);
}
.site-mark { width: 26px; height: 26px; flex: none; }

/* Header nav (pushes itself and the toggle to the right) */
.site-nav {
  margin-left: auto;
  color: var(--muted);
  text-decoration: none;
  font-weight: 600;
  font-size: 0.95rem;
}
.site-nav:hover { color: var(--fg); }

/* Theme toggle (top-right of the header) */
.theme-toggle {
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.2rem;
  height: 2.2rem;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: color 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}
.theme-toggle:hover {
  color: var(--fg);
  border-color: var(--muted);
  background: var(--card-bg);
}
.theme-toggle:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.theme-toggle .icon { display: block; width: 18px; height: 18px; }

/* Show the icon for the theme you can switch TO: moon in light, sun in dark. */
.theme-toggle .icon-sun { display: none; }
.theme-toggle .icon-moon { display: block; }
:root[data-theme="dark"] .theme-toggle .icon-sun { display: block; }
:root[data-theme="dark"] .theme-toggle .icon-moon { display: none; }
/* No-JS fallback: reflect the system preference when no choice is stored. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) .theme-toggle .icon-sun { display: block; }
  :root:not([data-theme]) .theme-toggle .icon-moon { display: none; }
}

.content { padding-block: 1rem 3rem; }

.site-footer {
  border-top: 1px solid var(--border);
  padding-block: 1.5rem;
  color: var(--muted);
  font-size: 0.85rem;
}

/* Links */
a { color: var(--accent); text-decoration-thickness: 1px; text-underline-offset: 2px; }
a:hover { text-decoration: none; }

/* Typography */
h1, h2, h3 { line-height: 1.25; letter-spacing: -0.015em; }
h1 { font-size: 2rem; margin: 0 0 0.5rem; }
h2 { font-size: 1.4rem; margin: 2rem 0 0.75rem; }
h3 { font-size: 1.15rem; margin: 1.75rem 0 0.5rem; }

/* Mini-heading (####): an editorial separator between named sub-topics
   inside a section. Centered, small, muted — quieter than a title, louder
   than bold text. See DESIGN.md. */
h4 {
  margin: 2.4rem 0 0.9rem;
  text-align: center;
  font-size: 0.95rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  color: var(--muted);
}
p, ul, ol, blockquote, pre { margin: 0 0 1.15rem; }

code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.9em;
  background: var(--code-bg);
  padding: 0.15em 0.4em;
  border-radius: 4px;
}

pre {
  background: var(--code-bg);
  padding: 1rem 1.15rem;
  border-radius: 8px;
  overflow-x: auto;
}
pre code { background: none; padding: 0; font-size: 0.85rem; }

/* Syntax highlighting (build-time, see DESIGN.md): soft pastels so code
   gets color without breaking the greyscale identity. */
.c-kw  { color: #8839a8; }  /* keywords — muted plum   */
.c-str { color: #38784b; }  /* strings  — sage green   */
.c-com { color: #8f9096; font-style: italic; }  /* comments */
.c-ann { color: #a2652c; }  /* annotations — soft amber */
.c-num { color: #2b6cab; }  /* numbers — dusty blue    */
.c-typ { color: #33667d; }  /* types — steel teal      */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .c-kw  { color: #cda9dd; }
  :root:not([data-theme="light"]) .c-str { color: #a8c8a5; }
  :root:not([data-theme="light"]) .c-com { color: #7f8087; }
  :root:not([data-theme="light"]) .c-ann { color: #d6b088; }
  :root:not([data-theme="light"]) .c-num { color: #99bede; }
  :root:not([data-theme="light"]) .c-typ { color: #92bccd; }
}
:root[data-theme="dark"] .c-kw  { color: #cda9dd; }
:root[data-theme="dark"] .c-str { color: #a8c8a5; }
:root[data-theme="dark"] .c-com { color: #7f8087; }
:root[data-theme="dark"] .c-ann { color: #d6b088; }
:root[data-theme="dark"] .c-num { color: #99bede; }
:root[data-theme="dark"] .c-typ { color: #92bccd; }

blockquote {
  margin-inline: 0;
  padding: 0.25rem 0 0.25rem 1.15rem;
  border-left: 3px solid var(--border);
  color: var(--muted);
  font-style: italic;
}

hr { border: none; border-top: 1px solid var(--border); margin: 2.5rem 0; }

/* Callouts — standardized Markdown blocks (`> [!TYPE]`), see DESIGN.md.
   Deliberately unlike blockquotes: strong foreground, not muted italic. */
.callout {
  margin: 2.25rem 0;
  padding: 1.1rem 1.4rem;
  border-left: 4px solid var(--fg);
  border-radius: 0 8px 8px 0;
  background: var(--card-bg);
}
.callout p { margin: 0; }
.callout p + p { margin-top: 0.6rem; }

/* KEY — the one sentence the article defends. Large and bold, nothing else. */
.callout-key {
  font-size: 1.25rem;
  font-weight: 650;
  line-height: 1.45;
  letter-spacing: -0.01em;
}

/* DRAFT — review-time notes, visually unmistakable, gone before going live. */
.callout-draft {
  border-left-style: dashed;
  border-left-color: var(--muted);
  background: transparent;
  color: var(--muted);
  font-size: 0.95rem;
}
.callout-draft::before {
  content: "DRAFT NOTE";
  display: block;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.15em;
  margin-bottom: 0.35rem;
}

/* Draft variant tabs ([[variants]] blocks, see DESIGN.md). CSS-only. */
.variants {
  margin: 1.75rem 0;
  border: 1px dashed var(--muted);
  border-radius: 10px;
  padding: 0.85rem 1.15rem 0.5rem;
}
.variants::before {
  content: "DRAFT VARIANTS";
  display: block;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.15em;
  color: var(--muted);
  margin-bottom: 0.55rem;
}
.variants > input { display: none; }
.variants > label {
  display: inline-block;
  padding: 0.18rem 0.8rem;
  margin: 0 0.4rem 0.7rem 0;
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
}
.variants > input:checked + label { color: var(--fg); border-color: var(--fg); }
.variants .variant { display: none; }
.variants > input:nth-of-type(1):checked ~ .v1,
.variants > input:nth-of-type(2):checked ~ .v2,
.variants > input:nth-of-type(3):checked ~ .v3,
.variants > input:nth-of-type(4):checked ~ .v4 { display: block; }

img { max-width: 100%; height: auto; }

/* Raster images in articles (screenshots, photos): detach from the page.
   Inlined SVG diagrams are <svg>, not <img>, so they are unaffected. */
.post-body img {
  border: 1px solid var(--border);
  border-radius: 8px;
}

/* Inlined article SVGs (build.js inlines local .svg images so they inherit the
   theme via currentColor / CSS variables). Scale like images. */
.post-body svg { max-width: 100%; height: auto; }

/* Article annexes (see README.md/DESIGN.md): autonomous mini-chapters on a
   companion page at /<slug>/annexes/. In-article references use .annex-ref;
   the companion page itself uses .annexes-* and .annex-chapter. */

/* In-article reference: a normal link plus a dotted underline (so it reads
   as "opens an annex" at a glance) and a CSS-only hover tooltip showing the
   annex summary — no JS. */
.annex-ref {
  position: relative;
  text-decoration: underline dotted;
  text-decoration-color: var(--muted);
  text-underline-offset: 3px;
}
.annex-ref:hover { text-decoration-color: var(--fg); }

.annex-ref::after,
.annex-ref::before {
  position: absolute;
  left: 50%;
  bottom: 100%;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.12s ease, transform 0.12s ease;
}
.annex-ref::after {
  content: attr(data-summary);
  transform: translateX(-50%) translateY(4px);
  margin-bottom: 10px;
  width: max-content;
  max-width: min(34ch, 80vw);
  white-space: pre-line;
  background: var(--card-bg);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.55rem 0.75rem;
  font-size: 0.85rem;
  font-style: normal;
  font-weight: 400;
  line-height: 1.45;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.16);
  z-index: 60;
}
.annex-ref::before {
  content: "";
  transform: translateX(-50%) translateY(4px);
  border: 6px solid transparent;
  border-top-color: var(--border);
  z-index: 61;
}
.annex-ref:hover::after,
.annex-ref:hover::before {
  opacity: 1;
  visibility: visible;
  transform: translateX(-50%) translateY(0);
}

/* Companion page intro + table of contents. */
.annexes-intro { color: var(--muted); }
.annexes-toc {
  margin: 1.5rem 0 2.5rem;
  padding: 1rem 1.25rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card-bg);
}
.annexes-toc ul { list-style: none; margin: 0; padding: 0; }
.annexes-toc li { margin: 0 0 0.9rem; }
.annexes-toc li:last-child { margin-bottom: 0; }
.annexes-toc a { font-weight: 600; }
.annexes-toc-summary {
  margin: 0.2rem 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

/* Each annex is an autonomous chapter, visually set apart from ordinary
   prose with a dashed left border — distinct from both the blockquote
   (thin solid) and the callout (thick solid) — plus an uppercase ANNEX
   kicker, same idiom as the DRAFT NOTE / DRAFT VARIANTS labels. Subtle and
   greyscale on purpose: the reader should always know they left the
   article, without it feeling like a warning. */
.annex-chapter {
  margin: 2.75rem 0;
  padding-left: 1.25rem;
  border-left: 3px dashed var(--border);
}
.annex-chapter::before {
  content: "ANNEX";
  display: block;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.15em;
  color: var(--muted);
  margin-bottom: 0.5rem;
}
.annex-chapter h2 { margin-top: 0; }
.annex-summary { color: var(--muted); }

/* Home / listing page is wider than an article's reading column. */
.page-index .site-header,
.page-index .content,
.page-index .site-footer { max-width: var(--measure-wide); }

/* Short blog pitch above the article list */
.site-intro {
  color: var(--muted);
  max-width: 46rem;
  margin: 0 0 2.25rem;
}

/* Static pages (page: true): the leading portrait floats top-right and
   the opening paragraphs wrap around it. max-width keeps it reasonable
   on narrow screens without a media query. */
.page-static .post-body > p:first-child { margin: 0; }
.page-static .post-body > p:first-child img {
  float: right;
  width: 240px;
  max-width: 45%;
  margin: 0.35rem 0 1.25rem 1.5rem;
  border-radius: 14px;
}
.page-static .post-body::after { content: ""; display: block; clear: both; }

/* Article listing (home page) — responsive grid of squarish cards */
.page-title { margin-bottom: 1.5rem; }

.post-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: 1fr;   /* one column on narrow screens */
  gap: 1.15rem;
}

/* Two columns once there is room for them. */
@media (min-width: 40rem) {
  .post-list { grid-template-columns: repeat(2, 1fr); }
}

.post-item { margin: 0; }

.post-card {
  position: relative;
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 11rem;
  padding: 1.4rem 1.5rem;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--card-bg);
  color: var(--fg);
  text-decoration: none;
  transition: border-color 0.15s ease, transform 0.15s ease, box-shadow 0.15s ease;
}

/* Per-article glyph (front matter `card:`), top-right, quiet until hover */
.post-icon {
  position: absolute;
  top: 1.1rem;
  right: 1.2rem;
  width: 32px;
  height: 32px;
  color: var(--muted);
}
.post-icon svg { width: 100%; height: 100%; }
.post-card:hover .post-icon { color: var(--fg); }
.post-card:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.07);
}

/* Card date, only rendered when build/config.json sets showDates: true */
.post-date {
  display: block;
  margin-bottom: 0.5rem;
  color: var(--muted);
  font-size: 0.8rem;
  font-variant-numeric: tabular-nums;
}

.post-name {
  margin: 0 0 0.5rem;
  padding-right: 2.6rem; /* keep clear of the floating card glyph */
  font-size: 1.25rem;
  font-weight: 600;
  line-height: 1.25;
  letter-spacing: -0.015em;
}
.post-card:hover .post-name { color: var(--accent); }

.post-desc {
  margin: 0;
  color: var(--muted);
  font-size: 0.95rem;
  /* keep cards tidy: cap the summary at a few lines */
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* Single article */
.post-header { margin-bottom: 1.75rem; }
.post-header .post-title { margin: 0 0 0.35rem; }
.post-meta { color: var(--muted); font-size: 0.85rem; }

.back { margin-top: 3rem; padding-top: 1.25rem; border-top: 1px solid var(--border); }

/* Review annotations (drafts only — review.js is never injected on
   published pages). Marker-yellow highlights are deliberate: a draft tool
   should look like a draft tool, and it never ships. */
:root {
  --rnote-bg: rgba(240, 200, 60, 0.32);
  --rnote-bg-hover: rgba(240, 200, 60, 0.5);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --rnote-bg: rgba(240, 200, 60, 0.18);
    --rnote-bg-hover: rgba(240, 200, 60, 0.32);
  }
}
:root[data-theme="dark"] {
  --rnote-bg: rgba(240, 200, 60, 0.18);
  --rnote-bg-hover: rgba(240, 200, 60, 0.32);
}

mark.rnote {
  background: var(--rnote-bg);
  color: inherit;
  border-bottom: 1px dashed var(--muted);
  cursor: pointer;
  border-radius: 2px;
}
mark.rnote:hover { background: var(--rnote-bg-hover); }

.rnote-block {
  outline: 2px dashed var(--rnote-bg-hover);
  outline-offset: 8px;
  cursor: pointer;
}

.rnote-pill,
.rnote-handle {
  position: absolute;
  z-index: 40;
  font: 600 0.78rem/1 inherit;
  font-family: inherit;
  color: var(--fg);
  background: var(--card-bg);
  border: 1px solid var(--muted);
  border-radius: 999px;
  padding: 0.3rem 0.7rem;
  cursor: pointer;
}
.rnote-pill { transform: translateX(-50%); }
.rnote-handle { padding: 0.15rem 0.55rem; font-size: 1rem; color: var(--muted); }
.rnote-pill:hover, .rnote-handle:hover { border-color: var(--fg); color: var(--fg); }

.rnote-popover {
  position: absolute;
  z-index: 50;
  max-width: 22rem;
  background: var(--card-bg);
  border: 1px dashed var(--muted);
  border-radius: 8px;
  padding: 0.75rem 0.9rem;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.18);
  font-size: 0.9rem;
}
.rnote-popover-label {
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 0.4rem;
}
.rnote-popover-text { white-space: pre-wrap; margin-bottom: 0.6rem; }
.rnote-input {
  width: 100%;
  box-sizing: border-box;
  background: var(--bg);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.45rem;
  font: inherit;
  font-size: 0.9rem;
  margin-bottom: 0.55rem;
  resize: vertical;
}
.rnote-btn {
  font: 600 0.8rem/1 inherit;
  font-family: inherit;
  color: var(--fg);
  background: transparent;
  border: 1px solid var(--muted);
  border-radius: 6px;
  padding: 0.35rem 0.7rem;
  cursor: pointer;
  margin-right: 0.4rem;
}
.rnote-btn:hover { border-color: var(--fg); }
.rnote-btn-muted { color: var(--muted); }
.rnote-btn-danger:hover { color: #c0392b; border-color: #c0392b; }

.rnote-orphans {
  margin-top: 2.5rem;
  border: 1px dashed var(--muted);
  border-radius: 8px;
  padding: 0.9rem 1.1rem;
}
.rnote-orphan {
  padding: 0.5rem 0;
  border-top: 1px solid var(--border);
  font-size: 0.9rem;
}
.rnote-orphan:first-of-type { border-top: none; }
.rnote-orphan em { color: var(--muted); display: block; margin-bottom: 0.25rem; }
.rnote-orphan .rnote-btn { margin-top: 0.4rem; }

/* Fausses pubs CodeWorks (emplacements deployes seulement si
   build/config.json dit "ads": true). Chaque emplacement occupe des le
   depart la taille exacte de sa banniere : la reserve est visible pendant
   le chargement volontairement lent, et aucune ligne de texte ne saute
   quand la pub arrive. */
.ad-band {
  width: 728px;
  max-width: 100%;
  aspect-ratio: 728 / 90;
  margin: 1.25rem auto;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}
.ad-band-bottom { margin-block: 2rem 0.5rem; }
.ad-link { display: block; line-height: 0; }
.ad-link svg { display: block; max-width: 100%; height: auto; }

/* La reserve : le rectangle nu, sans texte, qui tient dans les deux
   themes. Il garde la place, il ne raconte rien. */
.ad-band:not(.ad-filled),
.ad-rail:not(.ad-filled) {
  background: var(--card-bg);
  border: 1px dashed var(--border);
  border-radius: 8px;
}

/* Croix de fermeture, volontairement rustique comme sur les vrais sites.
   Elle retire la pub et sa reserve jusqu'au rechargement de la page. */
.ad-close {
  position: absolute;
  top: 0;
  right: 0;
  z-index: 2;
  width: 16px;
  height: 16px;
  padding: 0;
  font: 700 10px/14px system-ui, sans-serif;
  color: #3a3a3a;
  background: #dcdcdc;
  border: 1px solid #9a9a9a;
  border-radius: 0;
  cursor: pointer;
}
.ad-close:hover { background: #c0c0c0; }

/* Rails lateraux. L'ecart se mesure depuis la BANDE horizontale (728px,
   donc plus large que la colonne de lecture) : cales sur la colonne, ils
   venaient toucher les bannieres du haut et du bas. Gouttiere large, et
   rien du tout si l'ecran ne peut pas loger l'ensemble au large. */
.ad-rail { display: none; }
@media (min-width: 1360px) {
  .ad-rail {
    display: flex;
    align-items: center;
    justify-content: center;
    position: fixed;
    top: 96px;
    width: 160px;
    height: 600px;
  }
  /* 364px de demi-bande + 72px de gouttiere + 160px de rail */
  .ad-rail-left { left: calc(50% - 596px); }
  .ad-rail-right { left: calc(50% + 436px); }
  /* L'accueil a une colonne plus large (60rem) : ses rails attendent
     d'avoir la place, sinon ils ne sortent pas. */
  .page-index .ad-rail { display: none; }
}
@media (min-width: 1620px) {
  .page-index .ad-rail { display: flex; }
  .page-index .ad-rail-left { left: calc(50% - 712px); }
  .page-index .ad-rail-right { left: calc(50% + 552px); }
}
@media (max-width: 820px) {
  .ad-band { min-height: 0; }
}

/* Marqueur de revision : le dernier commit de l'article dans le repo
   public (github.com/dborie/blog), en lien discret sous le titre. */
.post-rev {
  display: inline-block;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.72rem;
  color: var(--muted);
  text-decoration: none;
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 0.05rem 0.45rem;
  margin-top: 0.15rem;
}
.post-rev:hover { color: var(--fg); border-color: var(--muted); }
