*, *::before, *::after { box-sizing: border-box; }
html { scroll-behavior: smooth; -webkit-text-size-adjust: 100%; }
html.modal-open { overflow: hidden; }
body {
  margin: 0; min-height: 100vh; padding-right: var(--rail);
  background-color: var(--paper);
  color: var(--ink); font: 500 16px/1.6 var(--font-body);
  -webkit-font-smoothing: antialiased;
}
/* Layered backdrop: three light pools + faded fold-crease pattern masked to two corners. */
body::before, body::after { content: ''; position: fixed; inset: 0; z-index: -1; pointer-events: none; }
body::before {
  background:
    radial-gradient(44rem 30rem at 6% -4%, var(--pool-1), transparent 70%),
    radial-gradient(38rem 30rem at 102% 38%, var(--pool-2), transparent 70%),
    radial-gradient(44rem 30rem at 38% 108%, var(--pool-3), transparent 70%);
}
body::after {
  background-image: var(--crease); background-size: 260px 260px; opacity: .17;
  -webkit-mask-image: radial-gradient(ellipse 60% 55% at 92% 8%, #000 10%, transparent 70%), radial-gradient(ellipse 45% 45% at 4% 96%, #000 5%, transparent 70%);
  mask-image: radial-gradient(ellipse 60% 55% at 92% 8%, #000 10%, transparent 70%), radial-gradient(ellipse 45% 45% at 4% 96%, #000 5%, transparent 70%);
}
img, svg { display: block; max-width: 100%; }
a { color: inherit; text-decoration-color: var(--umber); text-underline-offset: 3px; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: progress; opacity: .7; }
h1, h2, h3, h4 { font-family: var(--font-display); line-height: 1.05; margin: 0; letter-spacing: -0.02em; font-weight: 800; }
p { margin: 0 0 1em; }
::selection { background: var(--hl); color: var(--on-hl); }
:focus-visible { outline: 3px solid var(--ink); outline-offset: 2px; box-shadow: 0 0 0 6px var(--hl); border-radius: 4px; }
[hidden] { display: none !important; }
.wrap { width: min(var(--wrap), 100% - 40px); margin-inline: auto; }
.mono { font-family: var(--font-mono); font-size: .74rem; letter-spacing: .08em; text-transform: uppercase; font-weight: 600; }
.muted { color: var(--muted); }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip { position: absolute; left: 12px; top: -60px; z-index: 200; background: var(--ink); color: var(--paper); padding: 10px 18px; border-radius: var(--pill); font-weight: 800; text-decoration: none; }
.skip:focus { top: 12px; }
main:focus { outline: none; }
h1[tabindex='-1']:focus { outline: none; box-shadow: none; }
h1[tabindex='-1']:focus-visible { outline: 3px dashed var(--umber); outline-offset: 6px; box-shadow: none; }

/* progress */
#progress { position: fixed; inset: 0 auto auto 0; height: 4px; width: 0; background: var(--umber); z-index: 90; transition: width .1s linear; }

/* top bar */
#top { position: relative; z-index: 20; }
.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 0; }
.logo { display: inline-flex; align-items: center; gap: 10px; text-decoration: none; font: 800 1.4rem/1 var(--font-display); letter-spacing: -0.04em; }
.logo svg { width: 32px; height: 32px; }
.top-actions { display: flex; align-items: center; gap: 8px; }
#open-menu { display: none; }

/* buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 2px solid var(--ink);
  background: transparent; padding: 10px 20px; border-radius: var(--pill); font-weight: 800; text-decoration: none; white-space: nowrap;
  transition: transform .2s var(--ease), background .2s, color .2s;
}
.btn:hover { transform: translateY(-2px); }
.btn-hl { background: var(--hl); color: var(--on-hl); border-color: var(--ink); }
.btn-ink { background: var(--ink); color: var(--paper); }
.btn-sm { padding: 7px 14px; font-size: .88rem; }
.btn-xs { padding: 5px 11px; font-size: .78rem; border-width: 1.5px; }
.btn-danger { color: var(--danger); border-color: var(--danger); }
.icon-btn { width: 40px; height: 40px; padding: 0; }
.icon-btn svg, .btn svg { width: 19px; height: 19px; flex: none; }
.kbd { font: 600 .7rem var(--font-mono); border: 1.5px solid currentColor; border-radius: 6px; padding: 1px 6px; opacity: .7; }
.btn.busy::after { content: ''; width: 14px; height: 14px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* right-edge notebook index tabs (primary nav, desktop) */
#rail { position: fixed; right: 0; top: 50%; transform: translateY(-50%); z-index: 50; display: none; flex-direction: column; align-items: flex-end; gap: 6px; }
.rail-head { padding-right: 16px; color: var(--muted); font-size: .64rem; }
.tab {
  display: grid; grid-template-columns: auto 1fr; column-gap: 7px; align-items: baseline; width: 114px; padding: 9px 10px 9px 12px;
  border: 1.5px solid var(--ink); border-right: 0; border-radius: 12px 0 0 12px; text-decoration: none; color: var(--ink);
  background: var(--sheet); box-shadow: -8px 8px 18px -14px rgba(42, 29, 22, .55);
  transform: translateX(8px); transition: transform .25s var(--ease), background .2s, color .2s;
}
.tab.t0 { background: var(--clay); } .tab.t1 { background: var(--hl); color: var(--on-hl); } .tab.t2 { background: var(--sheet); } .tab.t3 { background: var(--lilac); }
.tab-n { font-size: .62rem; opacity: .75; }
.tab-l { font: 800 .95rem/1.1 var(--font-display); letter-spacing: -.01em; }
.tab-s { grid-column: 1 / -1; font-size: .66rem; opacity: .72; font-weight: 600; margin-top: 1px; }
.tab:hover { transform: translateX(0); }
.tab.active { background: var(--umber); color: var(--on-umber); transform: translateX(-10px); }
@media (min-width: 1000px) { #rail { display: flex; } }

/* mobile index dialog */
#menu { position: fixed; inset: 0; z-index: 110; background: color-mix(in srgb, var(--ink) 38%, transparent); display: flex; justify-content: flex-end; animation: fade .2s; }
.menu-sheet { width: min(340px, 88vw); height: 100%; overflow-y: auto; background: var(--paper); border-left: 2px solid var(--ink); padding: 18px 0 18px 18px; display: flex; flex-direction: column; gap: 16px; animation: slide .25s var(--ease); }
.menu-top { display: flex; align-items: center; justify-content: space-between; padding-right: 18px; }
.menu-tabs { display: flex; flex-direction: column; gap: 8px; align-items: stretch; }
.menu-tabs .tab { width: auto; transform: none; padding: 14px 16px; }
.menu-tabs .tab.active { transform: translateX(-8px); }
.menu-tabs .tab-l { font-size: 1.15rem; }
@keyframes slide { from { transform: translateX(40px); opacity: 0; } }
@media (max-width: 999px) { #open-menu { display: inline-flex; } }

main { padding-bottom: 72px; min-height: 60vh; }

/* tags, chips */
.tag { display: inline-flex; align-items: center; gap: 6px; padding: 2px 10px; border-radius: var(--pill); border: 1.5px solid var(--ink); font: 600 .66rem var(--font-mono); letter-spacing: .08em; text-transform: uppercase; background: transparent; white-space: nowrap; }
/* topic colour keys stored in the DB (mint, lime, green, ink) map onto the umber palette */
.tag.mint { background: var(--clay); } .tag.lime { background: var(--hl); color: var(--on-hl); }
.tag.green { background: var(--umber); color: var(--on-umber); border-color: var(--umber); } .tag.ink { background: var(--ink); color: var(--paper); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { display: inline-flex; align-items: center; gap: 6px; border: 1.5px solid var(--ink); background: var(--sheet); padding: 6px 14px; border-radius: var(--pill); font-weight: 700; font-size: .88rem; text-decoration: none; }
.chip small { opacity: .65; font-family: var(--font-mono); }
.chip:hover { background: var(--clay); }
.chip[aria-pressed='true'], .chip.on { background: var(--ink); color: var(--paper); }

/* ledger rows (article list): row inverts to ink on hover, thumb tilts */
.ledger { border-top: 2px solid var(--ink); }
.row {
  position: relative; display: grid; grid-template-columns: 56px 1fr 124px; gap: 18px; align-items: center;
  padding: 14px 16px 14px 8px; border-bottom: 1px solid var(--line); text-decoration: none;
  transition: background .25s var(--ease), color .25s, padding .25s var(--ease);
}
.row-n { font: 600 1rem var(--font-mono); color: var(--umber); }
.row-title { display: block; font: 800 clamp(1.1rem, 1.8vw, 1.45rem)/1.15 var(--font-display); letter-spacing: -0.02em; margin: 6px 0 4px; }
.row-ex { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; color: var(--muted); max-width: 70ch; font-size: .92rem; }
.row-meta { display: flex; flex-direction: column; align-items: flex-end; gap: 8px; }
.row-img { width: 124px; height: 78px; object-fit: cover; border: 1.5px solid var(--ink); transition: transform .35s var(--ease); }
.row-time { font: 600 .7rem var(--font-mono); letter-spacing: .08em; text-transform: uppercase; color: var(--muted); white-space: nowrap; }
.row:hover, .row.sel { background: var(--ink); color: var(--paper); padding-left: 18px; }
.row:hover .row-n { color: var(--hl); }
.row:hover .row-ex, .row:hover .row-time, .row.sel .row-time { color: color-mix(in srgb, var(--paper) 72%, transparent); }
.row:hover .row-img { transform: rotate(-3deg) scale(1.05); border-color: var(--hl); }
.row:hover .tag, .row.sel .tag { border-color: currentColor; }
.row.compact { grid-template-columns: 1fr auto; padding: 12px 14px; }
.row.compact .row-title { font-size: 1.08rem; margin: 6px 0 0; }
@media (max-width: 760px) {
  .row { grid-template-columns: 1fr 88px; padding-inline: 4px; gap: 12px; }
  .row-n, .row-ex, .row-time { display: none; } .row-img { width: 88px; height: 58px; }
  .row.compact .row-time { display: block; }
}

/* forms */
.field { width: 100%; background: var(--panel); border: 2px solid var(--ink); border-radius: 12px; padding: 12px 14px; }
.field:focus { outline: none; border-color: var(--umber); box-shadow: 0 0 0 4px var(--hl); }
.field[aria-invalid='true'] { border-color: var(--danger); }
label.lbl { display: block; font: 600 .72rem var(--font-mono); letter-spacing: .08em; text-transform: uppercase; margin: 14px 0 6px; }
textarea.field { resize: vertical; min-height: 120px; }
.alert { padding: 10px 14px; border: 2px solid var(--danger); border-radius: 10px; color: var(--danger); font-weight: 700; background: var(--panel); }
.inline-form { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-top: 10px; }

/* footer */
#foot { position: relative; overflow: hidden; container-type: inline-size; background: var(--ink); color: var(--paper); padding: 44px var(--rail) 0 0; margin-right: calc(-1 * var(--rail)); }
:root[data-theme='dark'] #foot { background: #0f0b09; color: var(--ink); }
.foot-kicker { color: var(--hl); margin: 0 0 8px; }
.news { display: grid; grid-template-columns: 1fr minmax(0, 1fr); gap: 36px; align-items: end; padding-bottom: 28px; }
.news h2 { font-size: clamp(1.7rem, 3.2vw, 2.6rem); }
.news h2 mark { background: var(--hl); color: var(--on-hl); padding: 0 .14em; }
.news-note { margin: 10px 0 0; opacity: .78; max-width: 52ch; font-size: .95rem; }
.news-form { display: flex; gap: 8px; }
.news-form .field { flex: 1; min-width: 0; background: transparent; color: inherit; border-color: color-mix(in srgb, currentColor 50%, transparent); border-radius: var(--pill); padding-inline: 20px; }
.news-form .field::placeholder { color: color-mix(in srgb, currentColor 55%, transparent); }
.news-form .field:focus { border-color: var(--hl); box-shadow: 0 0 0 4px color-mix(in srgb, var(--hl) 40%, transparent); }
.news-form .btn { flex: none; }
.news-msg { min-height: 1.6em; margin: 8px 0 0; font-size: .92rem; color: var(--hl); font-weight: 700; }
.news-msg.bad { color: #f4a394; }
.page-head .news-msg { color: var(--umber); }
.news-msg a { color: inherit; }
.foot-row { display: grid; grid-template-columns: auto 1fr; gap: 10px 40px; align-items: center; padding: 18px 0; border-top: 1px solid color-mix(in srgb, currentColor 22%, transparent); }
.foot-links { display: flex; flex-wrap: wrap; gap: 6px 22px; font-weight: 700; }
.foot-links a { text-decoration: none; opacity: .85; } .foot-links a:hover { opacity: 1; color: var(--hl); }
.foot-legal { font-size: .8rem; opacity: .62; margin: 0; max-width: 78ch; justify-self: end; text-align: right; }
.foot-word { font: 800 11.5cqi/.74 var(--font-display); letter-spacing: -0.06em; color: transparent; -webkit-text-stroke: 1.5px color-mix(in srgb, var(--hl) 70%, transparent); text-align: center; margin: 6px 0 -.16em; user-select: none; white-space: nowrap; }
@media (max-width: 860px) {
  .news, .foot-row { grid-template-columns: 1fr; } .foot-legal { justify-self: start; text-align: left; }
}
@media (max-width: 480px) { .news-form { flex-direction: column; } }

/* search dialog */
#overlay { position: fixed; inset: 0; z-index: 100; background: color-mix(in srgb, var(--paper) 97%, transparent); overflow-y: auto; padding: 5vh 0 60px; animation: fade .2s; }
#overlay::before { content: ''; position: fixed; inset: 0; z-index: -1; background-image: var(--crease); background-size: 260px; opacity: .08; }
.ov-inner { max-width: 880px; }
.ov-top { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.ov-input { width: 100%; background: transparent; border: 0; border-bottom: 4px solid var(--ink); padding: 8px 0; font: 800 clamp(1.8rem, 5.4vw, 4rem)/1.1 var(--font-display); letter-spacing: -0.03em; }
.ov-input:focus { outline: none; border-bottom-color: var(--umber); box-shadow: 0 8px 0 -4px var(--hl); }
.ov-input::placeholder { color: color-mix(in srgb, var(--ink) 28%, transparent); }
.ov-hint { margin: 12px 0 22px; }
.ov-sub { margin: 4px 0 10px; }
@keyframes fade { from { opacity: 0; } }

/* toast */
#toasts { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 120; display: grid; gap: 8px; }
.toast { background: var(--hl); color: var(--on-hl); font-weight: 800; padding: 10px 22px; border-radius: var(--pill); border: 2px solid var(--ink); animation: pop .3s var(--ease); }
@keyframes pop { from { transform: translateY(14px); opacity: 0; } }

/* skeleton + reveal */
.skel { background: linear-gradient(90deg, var(--line), transparent, var(--line)); background-size: 200% 100%; animation: sk 1.2s linear infinite; min-height: 78px; margin: 10px 0; border-radius: 8px; }
@keyframes sk { to { background-position: -200% 0; } }
.rv { opacity: 0; transform: translateY(14px); transition: opacity .5s var(--ease), transform .5s var(--ease); }
.rv.in { opacity: 1; transform: none; }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; } .rv { opacity: 1; transform: none; } }

/* prose */
.prose { font-size: 1.08rem; line-height: 1.8; }
.prose h2 { font-size: clamp(1.6rem, 2.8vw, 2.2rem); margin: 2em 0 .6em; scroll-margin-top: 24px; }
.prose h2::before { content: ''; display: block; width: 46px; height: 8px; background: var(--hl); border: 1.5px solid var(--ink); margin-bottom: 14px; }
.prose h3 { font-size: 1.3rem; margin: 1.7em 0 .5em; scroll-margin-top: 24px; }
.prose p, .prose ul, .prose ol { margin: 0 0 1.2em; }
.prose li { margin: .35em 0; } .prose li::marker { color: var(--umber); font-weight: 800; }
.prose blockquote { margin: 1.8em 0; padding: 18px 24px; background: var(--clay); border-left: 8px solid var(--umber); font: 700 1.2rem/1.45 var(--font-display); }
.prose table { width: 100%; border-collapse: collapse; margin: 1.6em 0; font-size: .96rem; border: 2px solid var(--ink); background: var(--panel); }
.prose th { background: var(--ink); color: var(--paper); text-align: left; font: 600 .74rem var(--font-mono); text-transform: uppercase; letter-spacing: .08em; }
.prose th, .prose td { padding: 10px 14px; border-bottom: 1px solid var(--line); }
.prose code { font-family: var(--font-mono); background: var(--lilac); padding: 1px 6px; font-size: .9em; }
.prose pre { background: var(--ink); color: var(--paper); padding: 16px; overflow-x: auto; }
.prose pre code { background: none; }
.prose hr { border: 0; border-top: 2px dotted var(--ink); margin: 2.4em 0; }
.prose a { font-weight: 700; text-decoration-thickness: 2px; }
.prose .table-wrap { overflow-x: auto; }
main.enter { animation: enter .4s var(--ease); }
@keyframes enter { from { opacity: 0; transform: translateY(8px); } }

/* back to top (every page, after about one screen of scroll) */
.to-top { position: fixed; right: 22px; bottom: 22px; z-index: 60; display: inline-flex; align-items: center; gap: 6px; height: 42px; padding: 0 16px 0 12px; border: 1.5px solid var(--ink); border-radius: 999px; background: var(--umber); color: var(--on-umber); box-shadow: var(--shadow); font-size: .8rem; transition: transform .2s; }
.to-top:hover { transform: translateY(-2px); }
.to-top svg { width: 18px; height: 18px; }
.to-top[hidden] { display: none; }
@media (max-width: 640px) { .to-top { right: 14px; bottom: 14px; height: 40px; } }
