/* ============================================================================
   Positronia — technical-journal theme.
   Asymmetric layout, active margin, numbered sections. Self-hosted type.
   ========================================================================== */

/* --- fonts ---------------------------------------------------------------- */
@font-face {
  font-family: 'Newsreader';
  src: url('/fonts/newsreader.woff2') format('woff2');
  font-weight: 400 700; font-style: normal; font-display: swap;
}
@font-face {
  font-family: 'Newsreader';
  src: url('/fonts/newsreader-italic.woff2') format('woff2');
  font-weight: 400 700; font-style: italic; font-display: swap;
}
@font-face {
  font-family: 'IBM Plex Mono';
  src: url('/fonts/plexmono-400.woff2') format('woff2');
  font-weight: 400; font-style: normal; font-display: swap;
}
@font-face {
  font-family: 'IBM Plex Mono';
  src: url('/fonts/plexmono-500.woff2') format('woff2');
  font-weight: 500; font-style: normal; font-display: swap;
}

/* --- design tokens -------------------------------------------------------- */
:root {
  --paper:     #faf8f1;
  --paper-2:   #f0ebdd;
  --ink:       #211c17;
  --ink-soft:  #5c554b;
  --ink-faint: #918a7d;
  --rule:      #ddd5c3;
  --accent:    #8c2e22;
  --selection: #e8dcbf;

  --serif: 'Newsreader', Charter, 'Iowan Old Style', Georgia, serif;
  --mono: 'IBM Plex Mono', ui-monospace, 'SF Mono', Menlo, Consolas, monospace;

  --page-max: 54rem;
  --margin-col: 12rem;
  --col-gap: 2.6rem;
  --text-w: calc(100% - var(--margin-col) - var(--col-gap));
}

html.dark {
  --paper:     #191712;
  --paper-2:   #221f18;
  --ink:       #e7e1d4;
  --ink-soft:  #a7a093;
  --ink-faint: #7c7568;
  --rule:      #363028;
  --accent:    #df9d88;
  --selection: #3b3324;
}

/* --- reset ---------------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body, h1, h2, h3, h4, p, ul, ol, figure, blockquote { margin: 0; }
img { max-width: 100%; height: auto; }
::selection { background: var(--selection); }

/* --- base ----------------------------------------------------------------- */
body {
  background: var(--paper);
  color: var(--ink);
  font-family: var(--serif);
  font-size: 1.2rem;
  line-height: 1.62;
  font-optical-sizing: auto;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}
main { flex: 1 0 auto; }

a {
  color: var(--ink);
  text-decoration: underline;
  text-decoration-color: var(--accent);
  text-decoration-thickness: 1px;
  text-underline-offset: 0.14em;
}
a:hover { color: var(--accent); }

h1, h2, h3, h4 {
  font-family: var(--serif);
  font-weight: 600;
  line-height: 1.2;
  letter-spacing: -0.012em;
  scroll-margin-top: 1.5rem;
}

.skip-link {
  position: absolute; left: -999px; top: 0; z-index: 10;
  background: var(--accent); color: #fff; padding: 0.6rem 1rem;
}
.skip-link:focus { left: 0; }

/* --- masthead ------------------------------------------------------------- */
.masthead { padding-top: 1.9rem; }
.masthead-in {
  max-width: var(--page-max); margin: 0 auto; padding: 0 1.5rem 0.65rem;
  display: flex; align-items: flex-end; justify-content: space-between; gap: 1.5rem;
  border-bottom: 2px solid var(--ink);
}
.wordmark {
  display: inline-flex; align-items: center; gap: 0.5rem;
  text-decoration: none; color: var(--ink); line-height: 1;
}
.mark { width: 1.6rem; height: 1.6rem; display: block; }
.wordmark-name {
  font-family: var(--serif); font-size: 1.5rem; font-weight: 600;
  letter-spacing: -0.01em;
}
h1.wordmark { font-size: inherit; }

.masthead-nav { display: flex; align-items: center; gap: 1.15rem; }
.masthead-nav a {
  font-family: var(--mono); font-size: 0.69rem; text-transform: uppercase;
  letter-spacing: 0.14em; color: var(--ink-soft); text-decoration: none;
}
.masthead-nav a:hover { color: var(--accent); }
#theme-toggle {
  display: inline-flex; align-items: center; justify-content: center;
  width: 30px; height: 30px; padding: 0; cursor: pointer;
  background: none; border: 1px solid var(--rule); border-radius: 50%;
  color: var(--ink-soft);
}
#theme-toggle:hover { color: var(--accent); border-color: var(--accent); }

/* --- page wrapper --------------------------------------------------------- */
.page { max-width: var(--page-max); margin: 0 auto; padding: 0 1.5rem; }

/* --- homepage front matter ------------------------------------------------ */
.frontmatter { max-width: var(--text-w); margin-top: 2.6rem; }
.standfirst {
  font-family: var(--mono); font-size: 0.72rem; text-transform: uppercase;
  letter-spacing: 0.15em; color: var(--accent);
}
.lead { font-size: 1.4rem; line-height: 1.44; margin-top: 0.85rem; }
.lead-sub { font-size: 1.13rem; color: var(--ink-soft); margin-top: 0.7rem; }

/* --- the index ------------------------------------------------------------ */
.index { counter-reset: entry; }
.index-label {
  display: flex; justify-content: space-between; align-items: baseline;
  font-family: var(--mono); font-size: 0.73rem; font-weight: 500;
  text-transform: uppercase; letter-spacing: 0.15em; color: var(--ink-soft);
  margin-top: 3.4rem; padding-bottom: 0.6rem; border-bottom: 2px solid var(--ink);
}
.index-label span { color: var(--ink-faint); letter-spacing: 0.08em; }

.entry {
  counter-increment: entry;
  display: grid;
  grid-template-columns: minmax(0, 1fr) var(--margin-col);
  column-gap: var(--col-gap);
  margin-top: 2.5rem;
}
.entry-rule {
  grid-column: 1 / -1;
  display: flex; align-items: center; gap: 0.85rem; margin-bottom: 0.85rem;
}
.entry-rule::after {
  content: ""; flex: 1; height: 1px; background: var(--rule);
}
.sec {
  font-family: var(--mono); font-size: 0.71rem; letter-spacing: 0.05em;
  color: var(--accent); white-space: nowrap;
}
.sec::before { content: "§ " counter(entry, decimal-leading-zero); }

.entry-body { grid-column: 1; }
.entry-title { font-size: 1.5rem; line-height: 1.24; }
.entry-title a { color: var(--ink); text-decoration: none; }
.entry-title a:hover { color: var(--accent); }
.entry-dek { margin-top: 0.4rem; color: var(--ink-soft); font-size: 1.04rem; line-height: 1.5; }

.entry-side {
  grid-column: 2; align-self: start;
  font-family: var(--mono); font-size: 0.73rem; line-height: 1.5;
  color: var(--ink-faint);
}
.entry-side p { margin-bottom: 0.15rem; }
.entry-side a { color: var(--ink-faint); text-decoration: none; }
.entry-side a:hover { color: var(--accent); }
.side-tags { display: flex; flex-wrap: wrap; gap: 0 0.5rem; }

/* series part list on the index */
.parts { list-style: none; margin-top: 1.1rem; padding: 0; }
.parts li {
  display: flex; align-items: baseline; gap: 0.7rem;
  padding: 0.36rem 0; border-top: 1px solid var(--rule);
}
.parts li:first-child { border-top: none; }
.parts .pno { font-family: var(--mono); font-size: 0.7rem; color: var(--accent); }
.parts a { text-decoration: none; color: var(--ink); }
.parts a:hover { color: var(--accent); }
.parts time {
  margin-left: auto; font-family: var(--mono); font-size: 0.69rem;
  color: var(--ink-faint); white-space: nowrap;
}

/* --- single-article homepage feature ------------------------------------- */
.feature { max-width: var(--text-w); margin-top: 2.2rem; }
.feature-cover { display: block; text-align: center; margin-bottom: 1.5rem; }
.feature-cover img {
  max-width: 100%; max-height: 21rem; width: auto; height: auto;
  display: inline-block; border: 1px solid var(--rule);
}
.feature-meta { font-family: var(--mono); font-size: 0.73rem; color: var(--ink-faint); }
.feature-meta time { color: var(--ink-soft); }
.feature-meta a { color: var(--ink-faint); text-decoration: none; }
.feature-meta a:hover { color: var(--accent); }
.feature-title { font-size: 2.1rem; line-height: 1.16; margin-top: 0.65rem; }
.feature-title a { color: var(--ink); text-decoration: none; }
.feature-title a:hover { color: var(--accent); }
.feature-dek { margin-top: 0.7rem; font-size: 1.18rem; line-height: 1.5; color: var(--ink-soft); }
.feature-link { margin-top: 1.1rem; font-family: var(--mono); font-size: 0.78rem; }
.feature-link a { color: var(--accent); text-decoration: none; }
.feature-link a:hover { text-decoration: underline; }

/* --- post header ---------------------------------------------------------- */
.post-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) var(--margin-col);
  column-gap: var(--col-gap);
  margin-top: 2.6rem; padding-bottom: 1.5rem; border-bottom: 1px solid var(--rule);
}
.post-head-body { grid-column: 1; }
.kicker {
  font-family: var(--mono); font-size: 0.71rem; text-transform: uppercase;
  letter-spacing: 0.12em; margin-bottom: 0.7rem;
}
.kicker a { color: var(--accent); text-decoration: none; }
.kicker a:hover { text-decoration: underline; }
.post-head h1 { font-size: 2.3rem; line-height: 1.14; }

.post-head-side {
  grid-column: 2; align-self: start;
  font-family: var(--mono); font-size: 0.73rem; line-height: 1.5;
  color: var(--ink-soft);
}
.phs-row { margin-bottom: 0.55rem; }
.phs-k {
  display: block; font-size: 0.62rem; text-transform: uppercase;
  letter-spacing: 0.1em; color: var(--ink-faint); margin-bottom: 0.05rem;
}
.phs-row a { color: var(--ink-soft); }
.phs-row time { color: var(--ink); }
.phs-tags { display: inline-flex; flex-wrap: wrap; gap: 0 0.45rem; }

.about-portrait {
  width: 100%; max-width: 150px; display: block;
  filter: grayscale(1); border: 1px solid var(--rule);
}

/* Draft markers — only render in `npm run build:drafts` preview builds. */
.draft-flag {
  display: inline-block; margin-bottom: 0.85rem;
  font-family: var(--mono); font-size: 0.66rem; font-weight: 500;
  text-transform: uppercase; letter-spacing: 0.12em; color: var(--accent);
  border: 1px solid var(--accent); padding: 0.22rem 0.55rem;
}
.draft-flag-sm {
  font-family: var(--mono); font-size: 0.6rem; font-weight: 500;
  text-transform: uppercase; letter-spacing: 0.08em; color: var(--accent);
  border: 1px solid var(--accent); padding: 0.04rem 0.32rem;
  white-space: nowrap;
}

/* --- prose ---------------------------------------------------------------- */
.prose {
  max-width: var(--text-w); margin-top: 2.2rem;
  font-variant-numeric: oldstyle-nums;
}
.post .prose { counter-reset: sec; }
.prose > * + * { margin-top: 1.42rem; }
.prose > *:first-child { margin-top: 0; }

.prose h2 { font-size: 1.4rem; margin-top: 2.9rem; line-height: 1.3; }
.post .prose h2 { counter-increment: sec; }
.post .prose h2::before {
  content: "§" counter(sec); font-family: var(--mono); font-size: 0.78rem;
  font-weight: 500; color: var(--accent); margin-right: 0.6rem;
}
.prose h3 { font-size: 1.16rem; margin-top: 2rem; }
.prose h4 { font-size: 1.03rem; margin-top: 1.6rem; }
.prose h2 + *, .prose h3 + *, .prose h4 + * { margin-top: 0.75rem; }

.hanchor {
  margin-left: 0.35rem; color: var(--ink-faint); text-decoration: none;
  font-family: var(--mono); font-size: 0.62em; opacity: 0;
}
.prose h2:hover .hanchor, .prose h3:hover .hanchor,
.prose h4:hover .hanchor, .hanchor:focus { opacity: 1; }

.prose ul, .prose ol { padding-left: 1.4rem; }
.prose li + li { margin-top: 0.32rem; }
.prose li > ul, .prose li > ol { margin-top: 0.32rem; }

.prose blockquote {
  border-left: 2px solid var(--accent); padding-left: 1.25rem;
  color: var(--ink-soft); font-style: italic;
}

.prose hr {
  border: none; height: 1px; background: var(--rule);
  width: 28%; margin: 2.4rem 0;
}

.prose figure { margin: 2.7rem 0; text-align: center; }
.prose figure img {
  max-width: 100%; max-height: 24rem; width: auto; height: auto;
  display: inline-block; border: 1px solid var(--rule);
}
.prose figcaption {
  margin-top: 0.6rem; text-align: left;
  font-family: var(--mono); font-size: 0.72rem;
  line-height: 1.55; color: var(--ink-faint); max-width: 32rem;
}

.prose table {
  width: 100%; border-collapse: collapse; font-size: 0.96rem;
  display: block; overflow-x: auto;
}
.prose th, .prose td { border: 1px solid var(--rule); padding: 0.45rem 0.75rem; text-align: left; }
.prose th { background: var(--paper-2); font-weight: 600; }

/* --- code ----------------------------------------------------------------- */
.prose :not(pre) > code {
  font-family: var(--mono); font-size: 0.83em;
  background: var(--paper-2); padding: 0.1em 0.34em; border: 1px solid var(--rule);
}
.codeblock { position: relative; margin: 1.7rem 0; border: 1px solid var(--rule); }
.codeblock-title {
  font-family: var(--mono); font-size: 0.71rem; color: var(--ink-soft);
  padding: 0.45rem 0.85rem; background: var(--paper-2);
  border-bottom: 1px solid var(--rule);
}
.codeblock pre { margin: 0; padding: 0.95rem 1rem; overflow-x: auto; font-size: 0.83rem; line-height: 1.6; }
.codeblock pre code { background: none; padding: 0; font-size: inherit; border: 0; }
/* Shiki ships light colors inline; swap to its dark palette in dark mode. */
html.dark .shiki, html.dark .shiki span {
  color: var(--shiki-dark) !important;
  background-color: var(--shiki-dark-bg) !important;
}
.copy-btn {
  position: absolute; top: 0; right: 0;
  font-family: var(--mono); font-size: 0.64rem; text-transform: uppercase;
  letter-spacing: 0.08em; padding: 0.32rem 0.55rem; cursor: pointer;
  color: var(--ink-faint); background: var(--paper-2);
  border: 0; border-left: 1px solid var(--rule); border-bottom: 1px solid var(--rule);
  opacity: 0;
}
.codeblock:hover .copy-btn, .copy-btn:focus { opacity: 1; }

/* --- series box ----------------------------------------------------------- */
.series-box {
  max-width: var(--text-w); margin-top: 3rem;
  border: 1px solid var(--rule); background: var(--paper-2); padding: 1.1rem 1.3rem;
}
.sb-label {
  font-family: var(--mono); font-size: 0.64rem; text-transform: uppercase;
  letter-spacing: 0.14em; color: var(--ink-faint);
}
.sb-name { font-weight: 600; font-size: 1.1rem; margin-top: 0.1rem; }
.sb-list { list-style: none; margin-top: 0.7rem; padding: 0; }
.sb-list li { display: flex; gap: 0.6rem; padding: 0.27rem 0; font-size: 1.02rem; }
.sb-list .pno { font-family: var(--mono); font-size: 0.71rem; color: var(--accent); }
.sb-list a { text-decoration: none; color: var(--ink); }
.sb-list a:hover { color: var(--accent); }
.sb-list li[aria-current] .here { font-weight: 600; }

/* --- prev / next ---------------------------------------------------------- */
.prevnext {
  display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem;
  margin-top: 3rem; padding-top: 1.4rem; border-top: 2px solid var(--ink);
}
.pn { text-decoration: none; }
.pn-next { text-align: right; }
.pn-dir {
  display: block; font-family: var(--mono); font-size: 0.65rem;
  text-transform: uppercase; letter-spacing: 0.1em; color: var(--ink-faint);
}
.pn-title { display: block; margin-top: 0.25rem; color: var(--ink); font-size: 1.05rem; }
.pn:hover .pn-title { color: var(--accent); }

.post-footer {
  max-width: var(--text-w); margin-top: 2rem;
  font-family: var(--mono); font-size: 0.74rem; line-height: 1.65; color: var(--ink-faint);
}
.post-footer a { color: var(--ink-soft); }

/* --- leaf pages (tags, about, 404) --------------------------------------- */
.leaf-head {
  margin-top: 2.6rem; padding-bottom: 1.4rem; border-bottom: 1px solid var(--rule);
}
.leaf-eyebrow {
  font-family: var(--mono); font-size: 0.71rem; text-transform: uppercase;
  letter-spacing: 0.12em; margin-bottom: 0.5rem;
}
.leaf-eyebrow a { color: var(--accent); text-decoration: none; }
.leaf-head h1 { font-size: 2.3rem; }
.leaf-intro { margin-top: 0.6rem; color: var(--ink-soft); }
.leaf-404 { text-align: center; padding: 2.5rem 0; }

.tag-index { list-style: none; padding: 0; margin-top: 2rem; max-width: var(--text-w); }
.tag-index li { display: flex; align-items: baseline; gap: 0.7rem; padding: 0.62rem 0; }
.tag-index a { font-size: 1.22rem; text-decoration: none; color: var(--ink); }
.tag-index a:hover { color: var(--accent); }
.tag-rule { flex: 1; border-bottom: 1px dotted var(--ink-faint); transform: translateY(-0.2em); }
.tag-count { font-family: var(--mono); font-size: 0.78rem; color: var(--ink-faint); }

/* --- colophon ------------------------------------------------------------- */
.colophon { margin-top: 4rem; border-top: 1px solid var(--rule); }
.colophon-in {
  max-width: var(--page-max); margin: 0 auto; padding: 2.1rem 1.5rem 3rem;
  display: flex; gap: 1.4rem; align-items: flex-start;
}
.colophon-portrait {
  width: 60px; height: 60px; flex-shrink: 0;
  filter: grayscale(1); border: 1px solid var(--rule);
}
.colophon-text {
  font-family: var(--mono); font-size: 0.75rem; line-height: 1.6; color: var(--ink-faint);
}
.colophon-by { color: var(--ink-soft); }
.colophon-links { margin-top: 0.45rem; display: flex; flex-wrap: wrap; gap: 1rem; }
.colophon-links a { color: var(--ink-soft); }
.colophon-fine { margin-top: 0.45rem; }

/* --- responsive ----------------------------------------------------------- */
@media (max-width: 58rem) {
  .entry, .post-head { display: block; }
  .prose, .frontmatter, .feature, .series-box, .post-footer, .tag-index { max-width: none; }

  .entry-side {
    display: flex; flex-wrap: wrap; gap: 0 1.1rem;
    margin-top: 0.7rem; color: var(--ink-faint);
  }
  .entry-side p { margin: 0; }
  .post-head-side {
    margin-top: 1.3rem; padding-top: 1rem; border-top: 1px solid var(--rule);
    display: grid; grid-template-columns: 1fr 1fr; gap: 0.5rem 1.5rem;
  }
  .about-portrait { max-width: 110px; }
}

@media (max-width: 34rem) {
  body { font-size: 1.13rem; }
  .post-head h1, .leaf-head h1 { font-size: 1.85rem; }
  .lead { font-size: 1.24rem; }
  .prose h2 { font-size: 1.28rem; }
  .copy-btn { opacity: 1; }
  .prevnext { grid-template-columns: 1fr; gap: 1rem; }
  .pn-next { text-align: left; }
}

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