/* Roads Less Taken — hand-written stylesheet.
   Plain CSS, no framework. The colour scheme is driven by a data-theme
   attribute on <html>, set before first paint by an inline script; the
   prefers-color-scheme query below is only the fallback for when that script
   could not run (no JS), so the site still follows the OS by default.

   Layout notes: type scales fluidly with clamp() between phone and desktop,
   the header is sticky with a scrollable nav row on small screens, and cards
   collapse from a multi-column grid to one column. */

:root {
  --bg: #fdfdfc;
  --bg-soft: #f4f4f1;
  --bg-code: #f6f6f4;
  --fg: #23262b;
  --fg-soft: #5c636e;
  --fg-faint: #686f7a;
  --line: #e2e2dd;
  --line-strong: #cfcfc8;
  --accent: #1f6feb;
  --accent-soft: #e8f0fe;
  --warn: #b45309;
  --radius: 10px;
  --radius-sm: 7px;
  --wrap: 46rem;
  --shadow: 0 1px 2px rgb(20 22 26 / .05), 0 4px 14px rgb(20 22 26 / .06);
  --shadow-hover: 0 2px 4px rgb(20 22 26 / .06), 0 10px 26px rgb(20 22 26 / .1);
  --mono: ui-monospace, "SFMono-Regular", "JetBrains Mono", Menlo, Consolas, monospace;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

[data-theme="dark"] {
  --bg: #16181d;
  --bg-soft: #1d2026;
  --bg-code: #1b1e24;
  --fg: #d8dbe0;
  --fg-soft: #a2a9b4;
  --fg-faint: #858d98;
  --line: #2c313a;
  --line-strong: #3a4150;
  --accent: #6aa4f5;
  --accent-soft: #1e2c42;
  --shadow: 0 1px 2px rgb(0 0 0 / .35), 0 4px 14px rgb(0 0 0 / .3);
  --shadow-hover: 0 2px 4px rgb(0 0 0 / .4), 0 10px 26px rgb(0 0 0 / .45);
}

/* Fallback when the inline script could not run (no JS): follow the OS, unless
   an explicit choice was already applied via data-theme. */
@media (prefers-color-scheme: dark) {
  html:not([data-theme]) {
    --bg: #16181d;
    --bg-soft: #1d2026;
    --bg-code: #1b1e24;
    --fg: #d8dbe0;
    --fg-soft: #a2a9b4;
    --fg-faint: #858d98;
    --line: #2c313a;
    --line-strong: #3a4150;
    --accent: #6aa4f5;
    --accent-soft: #1e2c42;
    --shadow: 0 1px 2px rgb(0 0 0 / .35), 0 4px 14px rgb(0 0 0 / .3);
    --shadow-hover: 0 2px 4px rgb(0 0 0 / .4), 0 10px 26px rgb(0 0 0 / .45);
  }
}

/* Theme toggle button. The icon shows the theme you would switch TO. */
.theme-toggle {
  display: inline-flex; align-items: center; justify-content: center;
  width: 2.4rem; height: 2.4rem; padding: 0;
  background: none; border: 1px solid transparent; border-radius: 50%;
  color: var(--fg-soft); cursor: pointer;
}
.theme-toggle:hover { color: var(--accent); border-color: var(--line); }
.theme-toggle:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.theme-toggle .icon-moon { display: none; }
[data-theme="dark"] .theme-toggle .icon-moon { display: block; }
[data-theme="dark"] .theme-toggle .icon-sun { display: none; }

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
/* The header is sticky, so anchored headings must clear it. The header wraps
   to two rows below roughly 49rem (brand + nav no longer share a row), and on
   true phones it is two rows by design; both need the larger offset. */
html { scroll-padding-top: 5rem; }
@media (max-width: 52rem) {
  html { scroll-padding-top: 8.5rem; }
}
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; }
}

/* Fluid type: ~17px on a phone, 18.5px on desktop. */
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--serif);
  font-size: clamp(1.04rem, 0.98rem + 0.35vw, 1.16rem);
  line-height: 1.65;
  text-rendering: optimizeLegibility;
}

.wrap { width: 100%; max-width: var(--wrap); margin: 0 auto; padding: 0 clamp(1rem, 4vw, 1.5rem); }

/* The header runs a little wider than the text column so brand, nav and the
   theme toggle share one row on desktop; below ~52rem it wraps to two rows
   (nav under brand), which the scroll-padding and nav mask handle. */
.site-header .wrap { max-width: 54rem; }

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

/* Links inside prose must not rely on colour alone (WCAG 1.4.1). */
.post-content a, .page-content a, .post-summary a {
  text-decoration: underline;
  text-underline-offset: 2px;
  text-decoration-thickness: 1px;
}

.skip {
  position: absolute; left: -9999px; top: 0; background: var(--bg);
  padding: .5rem 1rem; z-index: 20;
}
.skip:focus { left: 0; }

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

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

.site-header {
  position: sticky; top: 0; z-index: 15;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.header-inner {
  display: flex; flex-wrap: wrap; align-items: center; gap: .4rem 1rem;
  padding-top: .65rem; padding-bottom: .65rem;
}

.brand { display: flex; align-items: center; gap: .6rem; color: var(--fg); }
.brand:hover { text-decoration: none; }
.brand-mark {
  display: inline-flex; align-items: center; justify-content: center;
  width: 2.2rem; height: 2.2rem; flex: 0 0 auto;
  font-family: var(--mono); font-size: 1.3rem; line-height: 1;
  color: var(--accent);
  background: var(--accent-soft); border-radius: var(--radius-sm);
}
.brand-text { display: flex; flex-direction: column; }
.brand-name { font-weight: 600; letter-spacing: -.01em; font-size: 1rem; }
.brand-tag {
  font-size: .78rem; color: var(--fg-faint); font-family: var(--sans);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  max-width: 52vw;
}

.site-nav {
  margin-left: auto; display: flex; align-items: center; gap: .1rem;
  font-family: var(--sans); font-size: .93rem;
  flex-wrap: nowrap;
  max-width: 100%;
  overflow-x: auto; scrollbar-width: none;
}
.site-nav::-webkit-scrollbar { display: none; }
.site-nav a {
  color: var(--fg-soft); white-space: nowrap;
  padding: .45rem .6rem; border-radius: var(--radius-sm);
}
.site-nav a:hover { color: var(--accent); background: var(--bg-soft); text-decoration: none; }
.site-nav a.active { color: var(--accent); font-weight: 600; }
.site-nav a.active:hover { background: var(--accent-soft); }

/* ---------- hero ---------- */

.hero {
  padding: clamp(2.2rem, 6vw, 3.8rem) 0 clamp(1.4rem, 4vw, 2rem);
}
.hero h1 {
  font-size: clamp(1.9rem, 1.2rem + 3.4vw, 2.7rem);
  line-height: 1.12; margin: 0 0 .75rem;
  letter-spacing: -.025em;
}
.hero-lead {
  font-size: clamp(1.08rem, 1rem + 0.7vw, 1.28rem);
  color: var(--fg-soft); margin: 0 0 .5rem; line-height: 1.45;
}
.hero-body { color: var(--fg-soft); margin: 0 0 1.4rem; max-width: 38rem; }
.hero-links { display: flex; flex-wrap: wrap; gap: .6rem; font-family: var(--sans); font-size: .95rem; }
.hero-links a {
  display: inline-flex; align-items: center; min-height: 2.75rem;
  padding: .35rem .95rem;
  border: 1px solid var(--line); border-radius: 999px;
  color: var(--fg);
}
.hero-links a:hover { border-color: var(--accent); color: var(--accent); text-decoration: none; background: var(--accent-soft); }

/* ---------- sections ---------- */

.section { padding: clamp(1.8rem, 5vw, 2.6rem) 0; border-top: 1px solid var(--line); }
.section-head { margin-bottom: 1.4rem; }
.section-head h1, .section-head h2 {
  font-size: 1.35rem; margin: 0 0 .25rem; letter-spacing: -.01em;
}
.section-sub { margin: 0; color: var(--fg-faint); font-family: var(--sans); font-size: .88rem; }
.section-sub a { color: var(--fg-soft); }

/* ---------- project cards ---------- */

.cards {
  list-style: none; margin: 0; padding: 0;
  display: grid; gap: .9rem;
  grid-template-columns: repeat(auto-fill, minmax(15rem, 1fr));
}
/* Two even columns on small tablets, one on phones. */
@media (max-width: 42rem) {
  .cards { grid-template-columns: repeat(auto-fill, minmax(13.5rem, 1fr)); }
}
@media (max-width: 30rem) {
  .cards { grid-template-columns: 1fr; }
}

.card {
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--bg-soft);
  box-shadow: var(--shadow);
  transition: border-color .15s ease, box-shadow .15s ease, transform .15s ease;
}
.card:hover {
  border-color: var(--line-strong);
  box-shadow: var(--shadow-hover);
  transform: translateY(-2px);
}
.card-link { display: block; padding: 1.05rem 1.1rem; color: inherit; height: 100%; border-radius: inherit; }
.card-link:hover { text-decoration: none; }
.card-link:focus-visible { outline-offset: -2px; }

.card-head { display: flex; align-items: center; gap: .7rem; margin-bottom: .6rem; }
.card-tile {
  display: inline-flex; align-items: center; justify-content: center;
  width: 2.2rem; height: 2.2rem; flex: 0 0 auto;
  border-radius: var(--radius-sm); background: var(--accent-soft); color: var(--accent);
  font-family: var(--mono); font-size: .95rem; font-weight: 600;
}
.card-tile svg { width: 1.2rem; height: 1.2rem; }
.card-tile-lg { width: 2.9rem; height: 2.9rem; }
.card-tile-lg svg { width: 1.6rem; height: 1.6rem; }
.card-title { font-size: 1.05rem; margin: 0; letter-spacing: -.01em; }
.card-tagline { margin: 0 0 .8rem; color: var(--fg-soft); font-size: .92rem; line-height: 1.5; }
.card-meta { display: flex; flex-wrap: wrap; gap: .4rem; margin: 0; }

.chip {
  display: inline-flex; align-items: center; gap: .3rem;
  font-family: var(--sans); font-size: .74rem; line-height: 1.6;
  padding: 0 .55rem; border-radius: 999px;
  background: var(--bg); border: 1px solid var(--line); color: var(--fg-soft);
}
.chip-lang { font-family: var(--mono); }
.chip-link { color: var(--accent); }
.chip-link:hover { border-color: var(--accent); text-decoration: none; }

/* ---------- post lists ---------- */

.post-list { list-style: none; margin: 0; padding: 0; }
.post-item {
  display: grid; grid-template-columns: 7.5rem 1fr; gap: 1rem;
  padding: 1.15rem 0; border-bottom: 1px solid var(--line);
}
.post-item:first-child { border-top: 1px solid var(--line); }
.post-date { color: var(--fg-faint); font-family: var(--sans); font-size: .84rem; padding-top: .3rem; }
.post-title { font-size: 1.12rem; font-weight: 600; letter-spacing: -.01em; }
.post-item .post-title:hover { color: var(--accent); text-decoration: none; }
.post-summary { color: var(--fg-soft); font-size: .95rem; margin-top: .3rem; }
.post-summary p { margin: 0 0 .5rem; }
.post-summary p:last-child { margin-bottom: 0; }
.post-summary img { max-width: 100%; height: auto; }
/* Keep list rows even; the full text is on the post page. */
.post-list .post-summary {
  display: -webkit-box;
  -webkit-line-clamp: 3;
  line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.post-terms { margin: .5rem 0 0; display: flex; flex-wrap: wrap; gap: .35rem; }

@media (max-width: 34rem) {
  .post-item { grid-template-columns: 1fr; gap: .2rem; padding: 1rem 0; }
  .post-date { padding-top: 0; }
}

/* ---------- single post / page ---------- */

.post, .page { padding: clamp(1.8rem, 5vw, 2.6rem) 0 3rem; }
.post-header, .page-header { margin-bottom: 2rem; }
.post-title, .page-header h1 {
  font-size: clamp(1.7rem, 1.3rem + 1.8vw, 2.1rem);
  line-height: 1.2; margin: 0 0 .6rem; letter-spacing: -.02em;
}
.post-byline { margin: 0; color: var(--fg-faint); font-family: var(--sans); font-size: .87rem; }
.post-byline .sep { margin: 0 .35rem; }

.toc {
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--bg-soft); padding: .6rem 1rem; margin-bottom: 2rem;
  font-family: var(--sans); font-size: .88rem;
}
.toc summary { cursor: pointer; color: var(--fg-soft); font-weight: 600; }
.toc ul { margin: .6rem 0 .2rem; padding-left: 1.1rem; }
.toc li { margin: .15rem 0; }
.toc-l3 { margin-left: .9rem; }
.toc-l4 { margin-left: 1.8rem; }

.post-content { font-size: 1rem; }
.post-content h2, .page-content h2 {
  font-size: 1.4rem; margin: 2.2rem 0 .8rem; letter-spacing: -.01em;
  text-wrap: balance;
}
.post-content h3, .page-content h3 { font-size: 1.15rem; margin: 1.8rem 0 .6rem; }
.post-content h4 { font-size: 1rem; margin: 1.5rem 0 .5rem; }
.post-content p, .page-content p { margin: 0 0 1.1rem; }
.post-content ul, .post-content ol, .page-content ul, .page-content ol { margin: 0 0 1.1rem; padding-left: 1.4rem; }
.post-content li { margin: .3rem 0; }
.post-content img, .page-content img { max-width: 100%; height: auto; border-radius: var(--radius-sm); }
.post-content blockquote, .page-content blockquote {
  margin: 1.5rem 0; padding: .2rem 1.2rem; border-left: 3px solid var(--line-strong);
  color: var(--fg-soft); font-style: italic;
}
.post-content blockquote p:last-child { margin-bottom: 0; }
.post-content hr { border: 0; border-top: 1px solid var(--line); margin: 2rem 0; }

.post-content code, .page-content code {
  font-family: var(--mono); font-size: .88em;
  background: var(--bg-code); border: 1px solid var(--line);
  border-radius: 4px; padding: .1em .35em;
  overflow-wrap: anywhere;
}
.post-content pre, .page-content pre {
  font-family: var(--mono); font-size: .85rem; line-height: 1.55;
  background: var(--bg-code); border: 1px solid var(--line);
  border-radius: var(--radius); padding: .9rem 1rem; overflow-x: auto;
  margin: 0 0 1.2rem;
}
.post-content pre code, .page-content pre code {
  background: none; border: 0; padding: 0; font-size: inherit;
}
.highlight { margin: 0 0 1.2rem; }
.highlight pre { margin: 0; }

/* Tables: scroll horizontally on phones instead of breaking the layout. */
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 0 0 1.2rem; }
.table-scroll table { margin: 0; }
table { border-collapse: collapse; width: 100%; margin: 0 0 1.2rem; font-size: .92rem; }
th, td { border: 1px solid var(--line); padding: .4rem .6rem; text-align: left; }
th { background: var(--bg-soft); }

/* Media inside prose (video shortcode, embedded players). */
.post-content video, .page-content video {
  max-width: 100%; height: auto; border-radius: var(--radius-sm);
  background: var(--bg-code);
}

.post-footer { margin-top: 2.5rem; padding-top: 1.2rem; border-top: 1px solid var(--line); }
.post-tags { display: flex; flex-wrap: wrap; gap: .4rem; margin: 0; }

/* ---------- project detail ---------- */

.project-head { display: flex; align-items: center; gap: 1rem; }
.project-tagline { margin: .3rem 0 0; color: var(--fg-soft); font-size: 1rem; }
.project-meta { display: flex; flex-wrap: wrap; gap: .4rem; margin: 1.2rem 0 0; }
.project-nav { margin-top: 2.5rem; padding-top: 1.2rem; border-top: 1px solid var(--line); font-family: var(--sans); font-size: .9rem; }

/* ---------- terms ---------- */

.term-list {
  list-style: none; margin: 0; padding: 0;
  display: grid; gap: .35rem;
  grid-template-columns: repeat(auto-fill, minmax(13rem, 1fr));
  font-family: var(--sans); font-size: .95rem;
}
.term-list li { display: flex; align-items: baseline; gap: .5rem; }
.term-count { color: var(--fg-faint); font-size: .8rem; }

/* ---------- archive ---------- */

.archive-year {
  font-size: 1rem; font-family: var(--sans); color: var(--fg-faint);
  margin: 2rem 0 .5rem; letter-spacing: .04em;
}
.archive-list { list-style: none; margin: 0; padding: 0; }
.archive-list li { display: flex; gap: .8rem; padding: .2rem 0; }
.archive-date {
  flex: 0 0 3.4rem; color: var(--fg-faint);
  font-family: var(--sans); font-size: .82rem; padding-top: .15rem;
}

/* ---------- search ---------- */

.search-input {
  width: 100%; padding: .7rem .9rem; font-size: 1.05rem;
  font-family: var(--sans); color: var(--fg); background: var(--bg);
  border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 1.5rem;
}
.search-input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.search-results { list-style: none; margin: 0; padding: 0; }
.search-results li { padding: .7rem 0; border-bottom: 1px solid var(--line); }
.search-results .result-title { font-size: 1.05rem; font-weight: 600; }
.search-results .result-snippet { color: var(--fg-soft); font-size: .9rem; margin-top: .2rem; }
.search-hint { color: var(--fg-faint); font-family: var(--sans); font-size: .9rem; }

/* ---------- pagination ---------- */

.pagination {
  display: flex; align-items: center; justify-content: space-between;
  gap: 1rem; margin-top: 2rem; font-family: var(--sans); font-size: .9rem;
}
.page-numbers { display: flex; flex-wrap: wrap; gap: .3rem; }
.page-num { padding: .1rem .5rem; border-radius: 4px; color: var(--fg-soft); }
.page-num.current { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.page-prev.disabled, .page-next.disabled { color: var(--fg-faint); }

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

.site-footer {
  border-top: 1px solid var(--line); margin-top: 3rem;
  padding: 1.5rem 0 2.5rem;
}
.footer-inner { display: flex; flex-wrap: wrap; gap: .8rem; align-items: center; }
.footer-note { margin: 0; color: var(--fg-faint); font-family: var(--sans); font-size: .82rem; }
.footer-links {
  margin: 0 0 0 auto; display: flex; flex-wrap: wrap; gap: 1rem;
  font-family: var(--sans); font-size: .82rem;
}
.footer-links a { display: inline-flex; align-items: center; gap: .35rem; color: var(--fg-soft); }
.footer-links a:hover { color: var(--accent); text-decoration: none; }

/* ---------- small screens ---------- */

@media (max-width: 34rem) {
  /* Brand shows the name only; the tagline would fight the nav row. */
  .brand-tag { display: none; }

  .site-nav {
    order: 3; flex-basis: 100%; margin-left: -.6rem; margin-right: -.6rem;
    padding: 0 .6rem; gap: .1rem;
    /* Scroll the nav row sideways rather than wrapping onto more lines. */
    mask-image: linear-gradient(to right, #000 92%, transparent);
    -webkit-mask-image: linear-gradient(to right, #000 92%, transparent);
  }

  /* Comfortable tap targets on touch screens. */
  .site-nav a,
  .footer-links a {
    min-height: 44px;
    align-items: center;
  }
  .pagination a,
  .pagination span {
    min-height: 44px;
    display: inline-flex;
    align-items: center;
  }
  .footer-inner { align-items: flex-start; flex-direction: column; }
  .footer-links { margin-left: 0; }
}
