/* ==========================================================================
   B65 — b65.ch
   One stylesheet for index.html and post.html.
   Change --accent-h to reskin the whole site.
   ========================================================================== */

@font-face {
  font-family: 'IBM Plex Mono';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('fonts/ibm-plex-mono-400.woff2') format('woff2');
}
@font-face {
  font-family: 'IBM Plex Mono';
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url('fonts/ibm-plex-mono-500.woff2') format('woff2');
}
@font-face {
  font-family: 'IBM Plex Mono';
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url('fonts/ibm-plex-mono-600.woff2') format('woff2');
}
@font-face {
  font-family: 'IBM Plex Sans';
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
  src: url('fonts/ibm-plex-sans-variable.woff2') format('woff2');
}

:root {
  --accent-h: 30;                                   /* Rust / terracotta */

  --accent:        oklch(0.58 0.15 var(--accent-h));
  --accent-strong: oklch(0.50 0.15 var(--accent-h));
  --accent-dark:   oklch(0.42 0.15 var(--accent-h));
  --accent-line:   oklch(0.85 0.06 var(--accent-h));
  --accent-wash:   oklch(0.94 0.03 var(--accent-h));
  --accent-tint-a: oklch(0.94 0.010 var(--accent-h));
  --accent-tint-b: oklch(0.90 0.020 var(--accent-h));

  --paper:   oklch(0.985 0.006 95);
  --surface: #fff;
  --wash:    oklch(0.96 0.008 95);
  --line:    oklch(0.91 0.008 95);
  --line-soft: oklch(0.93 0.008 95);

  --ink:     oklch(0.27 0.015 265);
  --ink-body: oklch(0.30 0.014 265);
  --muted:   oklch(0.56 0.012 265);
  --muted-2: oklch(0.62 0.012 265);

  --code-bg:     oklch(0.975 0.004 265);
  --code-bar:    oklch(0.96 0.005 265);
  --code-line:   oklch(0.90 0.010 265);
  --code-ink:    oklch(0.32 0.015 265);

  --sans: 'IBM Plex Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --mono: 'IBM Plex Mono', ui-monospace, SFMono-Regular, Menlo, monospace;

  --page: 1080px;
  --read: 700px;
  --gutter: 56px;
  --radius: 12px;
}

/* --------------------------------------------------------------- reset --- */

*, *::before, *::after { box-sizing: border-box; }

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

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 17px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

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

a { color: var(--accent-strong); text-decoration: none; }
a:hover { color: var(--accent-dark); }

::selection { background: oklch(0.90 0.06 var(--accent-h)); }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 4px; }

.wrap { max-width: var(--page); margin-inline: auto; padding-inline: var(--gutter); }

.meta {
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}
.meta__dot { width: 4px; height: 4px; border-radius: 50%; background: oklch(0.82 0.01 95); flex: none; }
.meta--row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }

.label {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted-2);
}

/* -------------------------------------------------------------- header --- */

.site-header {
  border-bottom: 1px solid oklch(0.92 0.008 95);
}
.site-header__inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding-block: 24px;
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--ink); }
.brand:hover { color: var(--ink); }
.brand__mark {
  width: 26px; height: 26px;
  border-radius: 7px;
  background: var(--accent);
  display: grid; place-items: center;
  color: #fff;
  font-family: var(--mono); font-size: 13px; font-weight: 600;
}
.brand__name { font-family: var(--mono); font-size: 17px; font-weight: 600; letter-spacing: -0.01em; }

.backlink { font-family: var(--mono); font-size: 13px; color: oklch(0.50 0.014 265); }
.backlink:hover { color: var(--accent-strong); }

/* -------------------------------------------------------------- footer --- */

.site-footer {
  border-top: 1px solid oklch(0.92 0.008 95);
  margin-top: 96px;
}
.site-footer__inner {
  display: flex; align-items: center; justify-content: space-between; gap: 24px;
  padding-block: 26px;
  font-family: var(--mono); font-size: 12px; color: var(--muted);
}

/* ---------------------------------------------------------------- tags --- */

.tags { display: flex; flex-wrap: wrap; gap: 8px; }
.tag {
  font-family: var(--mono); font-size: 12px;
  color: oklch(0.45 0.03 265);
  background: var(--wash);
  border: 1px solid var(--line);
  padding: 5px 10px;
  border-radius: 999px;
}
.tag:hover { background: var(--accent-wash); border-color: var(--accent-line); color: var(--accent-strong); }

/* --------------------------------------------------------- index: hero --- */

.hero {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 380px;
  gap: 56px;
  align-items: center;
  padding-block: 72px;
}
.hero__body { display: flex; flex-direction: column; gap: 20px; }
.hero__flag { color: oklch(0.52 0.15 150); font-weight: 600; }
.hero__title {
  margin: 0;
  font-size: clamp(30px, 4vw, 42px);
  line-height: 1.1;
  font-weight: 600;
  letter-spacing: -0.03em;
  text-wrap: balance;
}
.hero__title a { color: inherit; }
.hero__title a:hover { color: var(--accent-strong); }
.hero__teaser {
  margin: 0;
  font-size: 18px; line-height: 1.6;
  color: oklch(0.45 0.014 265);
  max-width: 52ch;
  text-wrap: pretty;
}
.hero__cta {
  align-self: flex-start;
  margin-top: 8px;
  display: inline-flex; align-items: center; gap: 8px;
  font-family: var(--mono); font-size: 13px; font-weight: 500;
  color: #fff; background: var(--ink);
  padding: 11px 18px; border-radius: 9px;
  transition: background 0.16s ease;
}
.hero__cta:hover { background: var(--accent); color: #fff; }
.hero__figure {
  display: block;
  aspect-ratio: 4 / 3;
  border-radius: 14px;
  overflow: hidden;
  border: 1px solid oklch(0.90 0.008 95);
  background: var(--accent-tint-a);
}
.hero__figure img { width: 100%; height: 100%; object-fit: cover; }

/* ------------------------------------------------------- index: ledger --- */

.ledger { padding-bottom: 8px; }
.ledger__head,
.ledger__row {
  display: grid;
  grid-template-columns: 120px minmax(0, 1fr) 90px;
  gap: 24px;
}
.ledger__head {
  padding-bottom: 12px;
  border-bottom: 1px solid oklch(0.90 0.008 95);
  font-family: var(--mono); font-size: 11px;
  letter-spacing: 0.12em; text-transform: uppercase;
  color: var(--muted-2);
}
.ledger__head span:last-child { text-align: right; }
.ledger__row {
  align-items: baseline;
  padding: 18px 12px;
  margin-inline: -12px;
  border-bottom: 1px solid var(--line-soft);
  color: inherit;
  border-radius: 8px;
}
.ledger__row:hover { background: oklch(0.97 0.006 95); color: inherit; }
.ledger__row:hover .ledger__title { color: var(--accent-strong); }
.ledger__date { font-family: var(--mono); font-size: 13px; color: oklch(0.58 0.012 265); }
.ledger__main { display: flex; flex-wrap: wrap; align-items: baseline; gap: 10px; }
.ledger__title { font-size: 17px; font-weight: 500; letter-spacing: -0.01em; }
.ledger__tags { font-family: var(--mono); font-size: 12px; color: oklch(0.62 0.03 265); }
.ledger__read { font-family: var(--mono); font-size: 12px; color: var(--muted-2); text-align: right; }

.pager { display: flex; justify-content: center; padding-top: 32px; }
.pager__link {
  font-family: var(--mono); font-size: 13px;
  color: oklch(0.40 0.02 265);
  border: 1px solid oklch(0.88 0.008 95);
  background: var(--surface);
  padding: 10px 20px; border-radius: 9px;
}
.pager__link:hover { border-color: var(--accent); color: var(--accent-strong); }

/* ------------------------------------------------------- post: chrome --- */

.post-hero {
  width: 100%;
  aspect-ratio: 1080 / 380;
  overflow: hidden;
  background: var(--accent-tint-a);
  box-shadow: 0 8px 24px -12px oklch(0 0 0 / 0.25);
}
.post-hero img { width: 100%; height: 100%; object-fit: cover; object-position: top; }
.post-hero:empty { display: none; }

.post-layout {
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr);
  gap: 56px;
  padding-block: 72px 24px;
  align-items: start;
}
/* no h2 → toc stays empty (see post.js) → drop the sidebar column instead of reserving dead space */
.post-layout:has(#toc:empty) { grid-template-columns: minmax(0, 1fr); }
.post-layout:has(#toc:empty) .rail { display: none; }
.post-layout:has(#toc:empty) .post { margin-inline: auto; }

.rail {
  position: sticky;
  top: 24px;
  display: flex; flex-direction: column; gap: 14px;
}
.rail__group { display: flex; flex-direction: column; gap: 8px; margin-top: 20px; }
.toc { display: flex; flex-direction: column; gap: 2px; border-left: 2px solid var(--line); }
.toc a {
  padding: 7px 0 7px 16px;
  font-size: 14px;
  color: oklch(0.50 0.014 265);
  border-left: 2px solid transparent;
  margin-left: -2px;
}
.toc a:hover { color: var(--accent-strong); }
.toc a.is-active {
  color: var(--accent-strong);
  font-weight: 500;
  border-left-color: var(--accent);
}
.toc:empty, .rail__toc-empty { display: none; }

.share { display: flex; gap: 8px; flex-wrap: wrap; }
.share button, .share a {
  font-family: var(--mono); font-size: 12px;
  color: oklch(0.42 0.02 265);
  border: 1px solid oklch(0.90 0.008 95);
  background: var(--surface);
  padding: 6px 11px; border-radius: 7px;
  cursor: pointer;
  line-height: 1.4;
}
.share button:hover, .share a:hover { border-color: var(--accent); color: var(--accent-strong); }

.post { max-width: var(--read); }
.post__header { display: flex; flex-direction: column; gap: 22px; }
.post__title {
  margin: 0;
  font-size: clamp(32px, 4.2vw, 44px);
  line-height: 1.08;
  font-weight: 600;
  letter-spacing: -0.035em;
  text-wrap: balance;
}
.post__rule { height: 1px; background: var(--line); margin: 28px 0 0; border: 0; }

/* ------------------------------------------ post: CMS-rendered content --- */
/* Everything below styles raw HTML coming out of {{ content }}. */

.post-body { font-size: 19px; line-height: 1.72; color: var(--ink-body); overflow-wrap: break-word; word-break: break-word; }
.post-body > * { margin-block: 26px; }
.post-body > *:first-child { margin-top: 26px; }
.post-body > *:last-child { margin-bottom: 0; }

.post-body h2 {
  margin-top: 52px; margin-bottom: 0;
  font-size: 27px; line-height: 1.2;
  font-weight: 600; letter-spacing: -0.02em;
  color: var(--ink);
  scroll-margin-top: 24px;
}
.post-body h3 {
  margin-top: 40px; margin-bottom: 0;
  font-size: 21px; font-weight: 600; letter-spacing: -0.015em;
  color: var(--ink);
  scroll-margin-top: 24px;
}
.post-body p { text-wrap: pretty; }
.post-body strong { font-weight: 600; color: var(--ink); }
.post-body a { border-bottom: 1px solid var(--accent-line); }
.post-body a:hover { border-bottom-color: var(--accent-dark); }

.post-body ul, .post-body ol { padding-left: 24px; }
.post-body li { margin-block: 8px; }
.post-body li::marker { color: var(--accent); }

.post-body blockquote {
  padding: 4px 0 4px 22px;
  border-left: 3px solid var(--accent);
  color: oklch(0.42 0.03 265);
  font-style: italic;
  line-height: 1.65;
}
.post-body blockquote p { margin: 0; }

.post-body img {
  border-radius: var(--radius);
  border: 1px solid var(--line);
}
.post-body figure { margin-inline: 0; }
.post-body figcaption {
  margin-top: 10px;
  font-family: var(--mono); font-size: 12px; color: var(--muted);
}

.post-body hr { border: 0; height: 1px; background: var(--line); margin-block: 44px; }

.post-body table {
  width: 100%;
  border-collapse: collapse;
  font-size: 16px;
}
.post-body th, .post-body td {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line-soft);
}
.post-body th {
  font-family: var(--mono); font-size: 11px;
  letter-spacing: 0.1em; text-transform: uppercase;
  color: var(--muted-2);
}

/* inline code */
.post-body :not(pre) > code:not(.code__content) {
  font-family: var(--mono);
  font-size: 0.88em;
  background: oklch(0.95 0.008 95);
  border: 1px solid var(--line);
  padding: 1px 6px;
  border-radius: 5px;
  color: oklch(0.35 0.03 265);
}

/* ---------------------------------------------------------- code block --- */
/* .code-block is created at runtime by the script in post.js, wrapping
   every .editor-code (the CMS's code-block markup) that comes out of
   {{ content }}. */

.code-block {
  border: 1px solid var(--code-line);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--code-bg);
}
.code-block__bar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 9px 14px;
  border-bottom: 1px solid oklch(0.93 0.008 265);
  background: var(--code-bar);
}
.code-block__lang {
  font-family: var(--mono); font-size: 11px;
  letter-spacing: 0.1em; text-transform: uppercase;
  color: var(--muted);
}
.code-block__copy {
  font-family: var(--mono); font-size: 11px;
  letter-spacing: 0.04em; text-transform: uppercase;
  color: oklch(0.45 0.02 265);
  background: var(--surface);
  border: 1px solid oklch(0.90 0.008 265);
  padding: 4px 10px; border-radius: 6px;
  cursor: pointer;
}
.code-block__copy:hover { border-color: var(--accent); color: var(--accent-strong); }
.code-block__copy[data-copied] { border-color: oklch(0.75 0.10 150); color: oklch(0.50 0.13 150); }

.post-body .editor-code {
  margin: 0;
  padding: 18px 20px;
  overflow-x: auto;
  background: none;
}
.post-body .code__content {
  display: block;
  white-space: pre;
  font-family: var(--mono);
  font-size: 14.5px;
  line-height: 1.7;
  color: var(--code-ink);
  background: none;
  border: 0;
  padding: 0;
}

/* highlight.js tokens — light, low-saturation */
.hljs-comment, .hljs-quote { color: oklch(0.62 0.02 265); font-style: italic; }
.hljs-string, .hljs-meta .hljs-string, .hljs-regexp { color: oklch(0.52 0.13 150); }
.hljs-keyword, .hljs-built_in, .hljs-literal, .hljs-selector-tag { color: oklch(0.52 0.16 300); }
.hljs-number, .hljs-symbol { color: oklch(0.55 0.14 60); }
.hljs-title, .hljs-title.function_, .hljs-section, .hljs-name { color: var(--accent-strong); }
.hljs-attr, .hljs-attribute, .hljs-params, .hljs-variable { color: oklch(0.45 0.05 265); }
.hljs-meta, .hljs-type { color: oklch(0.50 0.08 265); }
.hljs-deletion { color: oklch(0.52 0.15 25); }
.hljs-addition { color: oklch(0.50 0.13 150); }

/* ------------------------------------------------------- post: footer  --- */

.post-share {
  display: flex; align-items: center; justify-content: space-between; gap: 20px;
  flex-wrap: wrap;
  margin-top: 56px;
  padding-block: 18px;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.postnav {
  margin-top: 24px;
  display: grid; grid-template-columns: 1fr 1fr; gap: 16px;
}
.postnav__item {
  display: flex; flex-direction: column; gap: 8px;
  padding: 20px 22px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: inherit;
}
.postnav__item:hover { border-color: var(--accent-line); color: inherit; }
.postnav__item:hover .postnav__title { color: var(--accent-strong); }
.postnav__item--next { text-align: right; }
.postnav__item--empty { visibility: hidden; }
.postnav__title { font-size: 16px; font-weight: 500; line-height: 1.35; }

.site-search { position: relative; }
.site-search__input {
  font: inherit;
  font-size: 14px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  width: 200px;
  max-width: 40vw;
}
.site-search__input::placeholder { color: var(--muted-2); }
.site-search__input:focus { outline: 2px solid var(--accent); outline-offset: 2px; }
.site-search__results {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  width: 340px;
  max-width: 85vw;
  max-height: 60vh;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 12px 28px oklch(0.2 0.02 265 / 0.14);
  z-index: 60;
}
.search-result-list { list-style: none; margin: 0; padding: 6px; }
.search-result-list li + li { border-top: 1px solid var(--line-soft); }
.search-result-list a { display: block; padding: 10px 12px; text-decoration: none; color: inherit; border-radius: 8px; }
.search-result-list a:hover { background: var(--accent-wash); }
.search-result-list > li > p { margin: 0; padding: 10px 12px; font-size: 13px; line-height: 1.5; color: var(--muted); }
.search-result-desc { margin: 0; font-size: 13px; line-height: 1.45; color: var(--muted); }
.search-result-desc b { color: var(--ink); font-weight: 600; }

/* --------------------------------------------------------- responsive --- */

@media (max-width: 980px) {
  :root { --gutter: 32px; }
  .hero { grid-template-columns: 1fr; gap: 32px; padding-block: 48px; }
  .hero__figure { order: -1; aspect-ratio: 16 / 9; }
  .post-layout { grid-template-columns: 1fr; gap: 32px; padding-block: 48px 16px; }
  .rail { position: static; flex-direction: row; flex-wrap: wrap; gap: 24px 40px; }
  .rail__group { margin-top: 0; }
  .post { max-width: none; }
  .post-hero { aspect-ratio: 16 / 7; }
}

@media (max-width: 640px) {
  :root { --gutter: 20px; }
  body { font-size: 16px; }
  .post-body { font-size: 17px; }
  .ledger__head { display: none; }
  .ledger__row { grid-template-columns: 1fr; gap: 6px; padding-block: 16px; }
  .ledger__read { text-align: left; }
  .postnav { grid-template-columns: 1fr; }
  .postnav__item--next { text-align: left; }
  .postnav__item--empty { display: none; }
  .site-footer__inner { flex-direction: column; align-items: flex-start; gap: 8px; }
  .site-header__inner { flex-wrap: wrap; row-gap: 12px; }
  .site-search { width: 100%; }
  .site-search__input { width: 100%; max-width: none; }
  .site-search__results { left: 0; right: 0; width: auto; max-width: none; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; scroll-behavior: auto !important; }
}