:root {
  --bg: #fafaf7;
  --ink: #111111;
  --muted: #6b6b6b;
  --rule: #111111;
  --sel: #111111;
  --sel-ink: #fafaf7;

  --font: "Berkeley Mono", "IBM Plex Mono", ui-monospace, "SF Mono",
          Menlo, Consolas, "DejaVu Sans Mono", monospace;

  --fs: 15px;
  --lh: 1.55;
  --pad-y: 48px;
  --pad-x: 56px;
  --content-ch: 90ch;

  --divider: "===";
  --show-ascii: 1;
  --show-linenums: 1;
  --link-underline: underline;
}

[data-density="cozy"]  { --fs: 15px; --lh: 1.65; --pad-y: 56px; }
[data-density="normal"]{ --fs: 15px; --lh: 1.55; --pad-y: 48px; }
[data-density="compact"]{--fs: 13.5px; --lh: 1.45; --pad-y: 36px; }

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0a0a0a;
    --ink: #d4d4c8;
    --muted: #7a7a6e;
    --rule: #d4d4c8;
    --sel: #d4d4c8;
    --sel-ink: #0a0a0a;
  }
}

[data-theme="dark"] {
  --bg: #0a0a0a;
  --ink: #d4d4c8;
  --muted: #7a7a6e;
  --rule: #d4d4c8;
  --sel: #d4d4c8;
  --sel-ink: #0a0a0a;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--ink); }
body {
  font-family: var(--font);
  font-size: var(--fs);
  line-height: var(--lh);
  font-variant-ligatures: none;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  min-height: 100vh;
}
::selection { background: var(--sel); color: var(--sel-ink); }

a {
  color: inherit;
  text-decoration: var(--link-underline);
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
  cursor: pointer;
}
a:hover { text-decoration: underline; }
a.nolink { text-decoration: none; }
a:focus-visible { outline: 1px dashed var(--ink); outline-offset: 2px; }

.wrap {
  max-width: var(--content-ch);
  margin: 0 auto;
  padding: var(--pad-y) var(--pad-x);
}

.pre, pre, code, kbd {
  font-family: var(--font);
  font-size: inherit;
}
pre {
  margin: 0;
  white-space: pre;
  overflow-x: auto;
}
.block { white-space: pre; }
.muted { color: var(--muted); }

.sep {
  white-space: pre;
  margin: 18px 0;
  user-select: none;
  color: var(--ink);
}
.sep::before { content: var(--divider); letter-spacing: 0; }

.topbar {
  position: sticky; top: 0; z-index: 20;
  background: var(--bg);
  border-bottom: 1px solid var(--ink);
}
.topbar-inner {
  max-width: var(--content-ch);
  margin: 0 auto;
  padding: 10px var(--pad-x);
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px;
}
.topbar .brand { white-space: nowrap; }
.topbar nav { display: flex; gap: 18px; flex-wrap: wrap; }
.topbar .cmd { color: var(--muted); font-size: 0.92em; white-space: nowrap; }
@media (max-width: 720px) {
  .topbar-inner { padding: 10px 20px; }
  .topbar .cmd { display: none; }
}

.hdr-ascii {
  white-space: pre;
  line-height: 1.1;
  margin: 8px 0 18px;
  overflow-x: auto;
}
[data-ascii="off"] .hdr-ascii { display: none; }

.meta-table {
  white-space: pre;
  margin: 0 0 8px;
}

.post-row {
  display: grid;
  grid-template-columns: 12ch 1fr 8ch;
  gap: 12px;
  padding: 4px 0;
  align-items: baseline;
}
.post-row .date { color: var(--muted); white-space: nowrap; }
.post-row .tag  { color: var(--muted); text-align: right; white-space: nowrap; }
.post-row .title a { text-decoration: var(--link-underline); }
.post-row.is-active {
  background: var(--ink); color: var(--bg);
}
.post-row.is-active .date,
.post-row.is-active .tag { color: var(--bg); }
@media (max-width: 640px) {
  .post-row { grid-template-columns: 10ch 1fr; }
  .post-row .tag { grid-column: 2; text-align: left; color: var(--muted); }
}

article h1, article h2, article h3 {
  font-weight: 700;
  font-size: 1em;
  margin: 28px 0 10px;
  letter-spacing: 0;
}
article h1 { font-size: 1em; }
article h2::before { content: "# "; }
article h3::before { content: "## "; }
article p  { margin: 0 0 14px; max-width: 78ch; }
article ul, article ol { padding-left: 2.5ch; margin: 0 0 14px; max-width: 78ch; }
article li { margin: 2px 0; }
article blockquote {
  margin: 14px 0; padding: 0 0 0 2ch;
  border-left: 1px solid var(--ink);
  color: var(--muted);
  max-width: 78ch;
}
article figure { margin: 18px 0; }
article figcaption { color: var(--muted); margin-top: 6px; }

/* fallback for bare pre/code inside post content (indented code blocks) */
.post-content > pre {
  margin: 18px 0;
  overflow-x: auto;
  border: 1px solid var(--ink);
  padding: 10px 12px;
}
.post-content > pre code { border: none; padding: 0; }

.code-frame {
  margin: 18px 0;
  overflow-x: auto;
}
.code-frame .code-top,
.code-frame .code-bot,
.code-frame .code-row {
  white-space: pre;
  font-family: var(--font);
}
.code-frame .code-body { padding: 0; }
.code-frame .ln { color: var(--muted); user-select: none; }
[data-linenums="off"] .code-frame .ln { display: none; }
[data-linenums="off"] .code-frame .ln-sp { display: none; }

.tagrow { color: var(--muted); }
.tagrow a { text-decoration: underline; }

.fn-marker { vertical-align: super; font-size: 0.8em; text-decoration: underline; }
.footnotes { margin-top: 24px; color: var(--muted); }
.footnotes ol { padding-left: 3ch; }

.tree { white-space: pre; }
.tree a { text-decoration: underline; }

.cmdbar {
  position: fixed; left: 0; right: 0; bottom: 0;
  background: var(--bg);
  border-top: 1px solid var(--ink);
  padding: 10px var(--pad-x);
  display: none;
  z-index: 30;
}
.cmdbar.open { display: block; }
.cmdbar .inner {
  max-width: var(--content-ch);
  margin: 0 auto;
  display: flex; gap: 10px; align-items: center;
}
.cmdbar input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--ink);
  font: inherit;
  caret-color: var(--ink);
}
.cmdbar .prompt { color: var(--muted); }
.cmdbar .hint { color: var(--muted); font-size: 0.9em; }
@media (max-width: 720px) {
  .cmdbar { padding: 10px 20px; }
  .cmdbar .hint { display: none; }
}

.help {
  position: fixed; inset: 0;
  background: color-mix(in srgb, var(--bg) 96%, transparent);
  display: none;
  z-index: 40;
  padding: 32px;
  overflow: auto;
}
.help.open { display: block; }
.help .inner {
  max-width: 70ch;
  margin: 0 auto;
  white-space: pre;
}

.tweaks {
  position: fixed; right: 16px; bottom: 16px;
  width: 300px;
  background: var(--bg);
  border: 1px solid var(--ink);
  padding: 14px 16px 16px;
  z-index: 50;
  display: none;
  font-size: 13px;
  line-height: 1.4;
}
.tweaks.open { display: block; }
.tweaks h4 { margin: 0 0 8px; font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px; }
.tweaks .row { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 8px 0; }
.tweaks .row label { color: var(--muted); }
.tweaks select, .tweaks input[type="text"] {
  background: transparent; border: 1px solid var(--ink);
  font: inherit; color: var(--ink); padding: 2px 6px; max-width: 140px;
}
.tweaks .close {
  position: absolute; top: 6px; right: 10px; cursor: pointer; color: var(--muted);
  text-decoration: none;
}
@media (max-width: 520px) {
  .tweaks { left: 12px; right: 12px; width: auto; bottom: 60px; }
}

.caret { display: inline-block; width: 1ch; margin-left: 1px; animation: blink 1.06s steps(1) infinite; }
@keyframes blink { 50% { opacity: 0; } }

::-webkit-scrollbar { height: 8px; width: 8px; }
::-webkit-scrollbar-thumb { background: var(--muted); }
::-webkit-scrollbar-track { background: transparent; }

.theme-toggle {
  background: none;
  border: 1px solid var(--ink);
  color: var(--ink);
  font: inherit;
  font-size: 0.92em;
  padding: 2px 6px;
  cursor: pointer;
  white-space: nowrap;
  line-height: 1;
}
.theme-toggle:hover {
  background: var(--ink);
  color: var(--bg);
}
.theme-toggle:focus-visible {
  outline: 1px dashed var(--ink);
  outline-offset: 2px;
}

@media (max-width: 720px) {
  :root { --pad-x: 20px; --pad-y: 28px; --fs: 14px; }
  .hdr-ascii { font-size: 10.5px; }
  .topbar nav a { font-size: 14px; }
}
@media (max-width: 400px) {
  .hdr-ascii { font-size: 9px; }
}

@media print {
  .topbar, .cmdbar, .tweaks, .help { display: none !important; }
  body { background: #fff; color: #000; }
}