/* Based And Pasted theme. Values mirror design_handoff_blog_theme (README + prototype). */

/* ---------- fonts (self-hosted, no third-party requests) ---------- */
@font-face {
  font-family: 'Space Mono';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('/fonts/space-mono400-normal.woff2') format('woff2');
}
@font-face {
  font-family: 'Space Mono';
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url('/fonts/space-mono700-normal.woff2') format('woff2');
}
@font-face {
  font-family: 'Figtree';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('/fonts/figtree400-normal.woff2') format('woff2');
}
@font-face {
  font-family: 'Figtree';
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url('/fonts/figtree500-normal.woff2') format('woff2');
}
@font-face {
  font-family: 'Figtree';
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url('/fonts/figtree600-normal.woff2') format('woff2');
}

/* ---------- base ---------- */
* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-sans);
  font-size: var(--text-md);
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent-bright); text-decoration: none; }
a:hover { color: var(--accent-hover); }
::selection { background: var(--accent); color: #fff; }

img { max-width: 100%; }
button { font-family: inherit; }

.container { max-width: var(--container); width: 100%; margin: 0 auto; padding: 0 var(--pad-x); }
.container-prose { max-width: var(--container-prose); width: 100%; margin: 0 auto; padding: 0 var(--pad-x); }
.container-narrow { max-width: var(--container-narrow); width: 100%; margin: 0 auto; padding: 0 var(--pad-x); }
.mono { font-family: var(--font-mono); }
.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap;
}

/* ---------- keyframes ---------- */
@keyframes blink { 0%, 49% { opacity: 1; } 50%, 100% { opacity: 0; } }
@keyframes drift { from { background-position: 0 0; } to { background-position: 40px 40px; } }
@keyframes breathe {
  0%, 100% { opacity: .55; transform: scale(1); }
  50% { opacity: 1; transform: scale(1.08); }
}
@keyframes rise { from { opacity: 0; transform: translateY(18px); } to { opacity: 1; transform: none; } }
@keyframes pageIn {
  from { opacity: 0; transform: translateY(14px); filter: blur(4px); }
  to { opacity: 1; transform: none; filter: none; }
}
@keyframes pageOut {
  from { opacity: 1; transform: none; }
  to { opacity: 0; transform: translateY(-10px); filter: blur(4px); }
}
@keyframes wipe {
  0% { transform: scaleX(0); transform-origin: left; }
  45% { transform: scaleX(1); transform-origin: left; }
  55% { transform: scaleX(1); transform-origin: right; }
  100% { transform: scaleX(0); transform-origin: right; }
}

/* ---------- page transitions (JS-driven, see theme.js) ---------- */
.is-leaving .page-root { animation: pageOut var(--dur-page) var(--ease-out) both; }
.is-leaving .page-wipe { animation: wipe var(--dur-rise) var(--ease-wipe) both; }

/* ---------- header ---------- */
.site-header {
  position: sticky;
  top: 0;
  z-index: 40;
  background: rgba(16, 17, 19, .88);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

.header-row {
  height: var(--header-h);
  display: flex;
  align-items: center;
  gap: 28px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--fg);
  font: 700 15px var(--font-mono);
  letter-spacing: -.02em;
  white-space: nowrap;
}
.brand:hover { color: var(--fg); }
.brand-mark {
  display: inline-block;
  width: 10px;
  height: 18px;
  background: var(--accent-grad);
  border-radius: 2px;
  box-shadow: var(--accent-glow);
}
.brand-short { display: none; }

.nav { display: flex; gap: 4px; font-size: 14px; font-weight: 500; }
.nav a {
  padding: 6px 10px;
  border-radius: var(--r-sm);
  color: var(--fg-muted);
  transition: background var(--dur-fast), color var(--dur-fast);
}
.nav a:hover { background: var(--surface-raised); color: var(--fg); }
.nav a.is-active { color: var(--fg-heading); }
.nav .caret { font-size: 9px; opacity: .6; }
.nav a.has-caret { display: flex; align-items: center; gap: 6px; }

.header-right { margin-left: auto; display: flex; align-items: center; gap: 10px; }

.icon-btn {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border: 1px solid var(--border-input);
  border-radius: var(--r-md);
  background: var(--surface-grad);
  color: var(--fg-meta);
  cursor: pointer;
  transition: color var(--dur-fast), border-color var(--dur-fast);
}
.icon-btn:hover { color: var(--accent-bright); border-color: #3a2a22; }

/* search field */
.search-wrap { position: relative; }
.search-field {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 34px;
  padding: 0 12px;
  width: 220px;
  background: linear-gradient(180deg, #17191c, #14161a);
  border: 1px solid var(--border-input);
  border-radius: var(--r-md);
  color: #6b717b;
  font: var(--text-sm) var(--font-mono);
  box-shadow: var(--inset-hairline);
  transition: border-color var(--dur-fast);
}
.search-field:focus-within { border-color: var(--accent); }
.search-slash { color: var(--fg-meta); }
.search-field input {
  flex: 1;
  min-width: 0;
  background: none;
  border: 0;
  outline: 0;
  color: var(--fg);
  font: 13px var(--font-sans);
}
.search-field input::placeholder { color: #6b717b; }
.search-field input::-webkit-search-cancel-button { display: none; }
.kbd {
  padding: 1px 5px;
  border: 1px solid var(--border-input);
  border-radius: var(--r-xs);
  font-size: 10px;
}

.search-panel {
  position: absolute;
  top: 42px;
  right: 0;
  width: 360px;
  max-width: calc(100vw - 32px);
  border: 1px solid var(--border-chip);
  border-radius: var(--r-lg);
  background: linear-gradient(180deg, rgba(26, 28, 32, .98), rgba(20, 22, 25, .98));
  backdrop-filter: blur(12px);
  box-shadow: var(--shadow-float);
  overflow: hidden;
  animation: rise var(--dur-fast) ease both;
  z-index: 45;
}
.search-panel[hidden] { display: none; }
.search-panel-head {
  display: flex;
  justify-content: space-between;
  padding: 8px 14px;
  border-bottom: 1px solid var(--border);
  font: var(--text-xs) var(--font-mono);
  color: var(--fg-faint);
}
.search-result {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--surface-chip);
  color: var(--fg);
}
.search-result:hover { background: rgba(240, 115, 58, .08); color: var(--fg); }
.search-result .t { font: 700 13px var(--font-mono); color: var(--fg-heading); }
.search-result .m { display: flex; gap: 10px; font: var(--text-xs) var(--font-mono); color: var(--fg-meta); }
.search-result .m .tags { color: var(--accent-bright); }
.search-empty { padding: 20px 14px; font: var(--text-sm) var(--font-mono); color: var(--fg-meta); }
.search-empty span { color: var(--accent-bright); }

/* reading progress + page wipe */
.progress-bar {
  position: absolute;
  left: 0;
  bottom: -1px;
  height: 2px;
  width: 100%;
  transform-origin: left;
  transform: scaleX(0);
  background: linear-gradient(90deg, var(--accent), var(--accent-bright));
  box-shadow: 0 0 10px rgba(240, 115, 58, .6);
  opacity: 0;
  transition: transform .1s linear, opacity var(--dur-fast);
}
.is-post .progress-bar { opacity: 1; }
.page-wipe {
  position: absolute;
  left: 0;
  right: 0;
  bottom: -1px;
  height: 2px;
  z-index: 70;
  background: linear-gradient(90deg, var(--accent), var(--accent-bright));
  box-shadow: 0 0 12px rgba(240, 115, 58, .7);
  pointer-events: none;
  transform: scaleX(0);
}

/* ---------- bottom sheets (mobile nav/search, post TOC) ---------- */
.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 56;
  background: rgba(10, 11, 12, .6);
  backdrop-filter: blur(4px);
}
.sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 57;
  display: flex;
  flex-direction: column;
  max-height: 80vh;
  padding: 12px var(--pad-x-mobile) 24px;
  border-top: 1px solid var(--border-chip);
  border-radius: 16px 16px 0 0;
  background: linear-gradient(180deg, #1a1c20, #131518);
  box-shadow: 0 -20px 48px -16px rgba(0, 0, 0, .9);
  animation: rise var(--dur-base) var(--ease-out) both;
}
.sheet-backdrop[hidden], .sheet[hidden] { display: none; }
.sheet-grab { flex: none; padding: 6px 0 10px; margin: -6px 0 4px; cursor: grab; }
.sheet-grab span {
  display: block;
  width: 40px;
  height: 4px;
  margin: 0 auto;
  border-radius: 2px;
  background: var(--fg-divider);
}
.sheet-body { overflow: auto; min-height: 0; }

/* segmented control */
.sheet-tabs {
  flex: none;
  display: flex;
  gap: 4px;
  margin-bottom: 14px;
  padding: 3px;
  border: 1px solid var(--border-chip);
  border-radius: 9px;
  background: #0d0e10;
}
.sheet-tab {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 34px;
  border: 0;
  border-radius: 6px;
  background: none;
  color: var(--fg-meta);
  font: 700 var(--text-sm) var(--font-mono);
  cursor: pointer;
}
.sheet-tab.is-active { background: var(--accent-grad); color: #fff; }
.sheet-pane[hidden] { display: none; }

/* nav sheet: menu pane */
.sheet-nav { display: flex; flex-direction: column; gap: 2px; }
.sheet-nav a {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 13px 10px;
  border-radius: 8px;
  color: var(--fg-muted);
  font: 700 15px var(--font-mono);
}
.sheet-nav a .d { width: 6px; height: 6px; border-radius: 50%; background: var(--fg-divider); flex: none; }
.sheet-nav a.is-active { background: rgba(240, 115, 58, .08); color: var(--fg-heading); }
.sheet-nav a.is-active .d { background: var(--accent-bright); }
.sheet-links {
  display: flex;
  gap: 8px;
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}
.sheet-links a {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 44px;
  border: 1px solid var(--border-input);
  border-radius: 8px;
  background: var(--surface);
  color: var(--fg-secondary);
  font: var(--text-sm) var(--font-mono);
}

/* nav sheet: search pane */
.sheet-search .search-field {
  width: auto;
  height: 46px;
  border-radius: 8px;
  background: #0d0e10;
  border-color: var(--accent);
  box-shadow: none;
}
.sheet-search .search-slash { color: var(--accent-bright); }
.sheet-search .search-field input { font-size: 15px; }
.sheet-search-head {
  display: flex;
  justify-content: space-between;
  padding: 12px 4px 4px;
  font: var(--text-xs) var(--font-mono);
  color: var(--fg-faint);
}
.sheet-search .search-result { padding: 12px 4px; }
.sheet-search .search-result:hover { background: none; color: var(--fg); }
.sheet-search .search-empty { padding: 16px 4px; }

/* ---------- page shell ---------- */
/* No fill-mode: once pageIn ends, <main> drops the animated `filter` entirely. */
.page-root { flex: 1; animation: pageIn var(--dur-page) var(--ease-out); }

/* ---------- home hero ---------- */
.hero {
  position: relative;
  height: 72vh;
  min-height: 340px;
  display: flex;
  align-items: flex-end;
  overflow: hidden;
  border-bottom: 1px solid var(--border);
}
.hero-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  filter: saturate(.6) contrast(1.05);
}
.hero-fade {
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(16, 17, 19, .35) 0%, rgba(16, 17, 19, .75) 55%, var(--bg) 100%);
}
.hero-dots {
  position: absolute;
  inset: 0;
  background-image: radial-gradient(rgba(255, 255, 255, .09) 1px, transparent 1px);
  background-size: 40px 40px;
  animation: drift 14s linear infinite;
  mask-image: linear-gradient(180deg, transparent, #000 40%, transparent);
  -webkit-mask-image: linear-gradient(180deg, transparent, #000 40%, transparent);
}
.hero-glow {
  position: absolute;
  left: -10%;
  bottom: -30%;
  width: 60%;
  height: 110%;
  background: radial-gradient(closest-side, rgba(217, 72, 15, .28), transparent);
  animation: breathe 7s ease-in-out infinite;
  transform-origin: center;
}
.hero-inner {
  position: relative;
  max-width: var(--container);
  width: 100%;
  margin: 0 auto;
  padding: 0 var(--pad-x) var(--space-10);
}
.hero-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 4px 10px;
  border: 1px solid var(--border-accent-soft);
  border-radius: var(--r-pill);
  background: var(--accent-bg-soft);
  color: var(--accent-bright);
  font: var(--text-sm) var(--font-mono);
  margin-bottom: 18px;
  min-width: 80px;
}
.hero-badge .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent-bright);
  box-shadow: 0 0 8px var(--accent-bright);
}
.hero h1 {
  margin: 0;
  max-width: 760px;
  font: 700 var(--text-hero) / 1.15 var(--font-mono);
  letter-spacing: var(--tracking-heading);
  color: var(--fg-heading);
  text-wrap: pretty;
}
.hero-cursor {
  display: inline-block;
  width: .5em;
  height: .9em;
  margin-left: .15em;
  vertical-align: -.1em;
  background: var(--accent-bright);
  animation: blink 1.1s steps(1) infinite;
}
.hero p {
  margin: 16px 0 0;
  max-width: 560px;
  color: var(--fg-muted);
  font-size: 16px;
  line-height: 1.55;
}

/* ---------- section heading row ---------- */
.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: var(--space-6);
  padding-bottom: var(--space-3);
  border-bottom: 1px solid var(--border);
}
.section-head h2, .section-head .h {
  margin: 0;
  font: 700 var(--text-base) var(--font-mono);
  color: var(--fg-meta);
  letter-spacing: var(--tracking-label);
  text-transform: uppercase;
}
.section-head .slashes { color: var(--accent-bright); }
.section-head .count { font: var(--text-sm) var(--font-mono); color: var(--fg-faint); }

.home-posts { padding: var(--space-12) var(--pad-x) var(--space-18); }

/* ---------- post grid ---------- */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: var(--space-5);
}
.card {
  position: relative;
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border-strong);
  border-radius: var(--r-lg);
  background: var(--surface-grad);
  box-shadow: var(--shadow-card);
  overflow: hidden;
  transition: border-color var(--dur-fast), transform var(--dur-fast);
  animation: rise var(--dur-rise) var(--ease-out) both;
}
.card:hover { border-color: var(--border-hover); transform: translateY(-2px); }
.card-spot {
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0;
  transition: opacity .3s;
  background: radial-gradient(220px circle at var(--mx, 50%) var(--my, 50%), rgba(240, 115, 58, .14), transparent 70%);
}
.card-cover {
  display: block;
  aspect-ratio: 16 / 8;
  background: #0d0e10;
  border-bottom: 1px solid var(--border);
  overflow: hidden;
}
.card-cover img { width: 100%; height: 100%; object-fit: cover; filter: saturate(.8); }
.cover-placeholder {
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
  background: repeating-linear-gradient(135deg, #151719 0 8px, #191b1f 8px 16px);
  color: var(--fg-faint);
  font: var(--text-xs) var(--font-mono);
}
.card-body {
  padding: 18px 20px 20px;
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  flex: 1;
}
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  padding: 2px 8px;
  border-radius: var(--r-xs);
  border: 1px solid var(--border-chip);
  background: var(--surface-chip);
  color: var(--fg-muted);
  font: var(--text-xs) var(--font-mono);
}
a.chip:hover { color: var(--accent-bright); border-color: var(--accent); }
.card h3 { margin: 0; font: 700 var(--text-h3) / 1.3 var(--font-mono); letter-spacing: -.02em; }
.card h3 a { color: var(--fg-heading); }
.card h3 a:hover { color: var(--accent-bright); }
.card-excerpt {
  margin: 0;
  color: var(--fg-muted);
  font-size: 14px;
  line-height: 1.6;
  flex: 1;
  text-wrap: pretty;
}
.card-foot {
  display: flex;
  align-items: center;
  gap: 10px;
  padding-top: var(--space-3);
  border-top: 1px solid var(--border);
  font-size: var(--text-sm);
  color: var(--fg-meta);
}
.card-foot img { width: 22px; height: 22px; border-radius: 50%; object-fit: cover; border: 1px solid var(--border-chip); }
.card-foot .author { color: var(--fg-secondary); font-weight: 500; }
.card-foot .sep { color: var(--fg-divider); }
.card-foot .date { font-family: var(--font-mono); }
.card-foot .read { margin-left: auto; font: var(--text-sm) var(--font-mono); }

/* ---------- single post ---------- */
.post-wrap { padding: var(--space-10) var(--pad-x) var(--space-18); }
.back-link { font: var(--text-sm) var(--font-mono); color: var(--fg-meta); }
.back-link:hover { color: var(--accent-bright); }
.post-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) var(--toc-w);
  gap: var(--toc-gap);
  margin-top: var(--space-5);
  align-items: start;
}
.post-article { min-width: 0; }
.post-article > .chips { margin-bottom: 16px; }
.post-article h1 {
  margin: 0;
  font: 700 var(--text-h1) / 1.15 var(--font-mono);
  letter-spacing: var(--tracking-heading);
  color: var(--fg-heading);
  text-wrap: pretty;
}
.post-meta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  margin: var(--space-5) 0 var(--space-7);
  padding-bottom: var(--space-5);
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  color: var(--fg-meta);
}
.post-meta img { width: 28px; height: 28px; border-radius: 50%; object-fit: cover; border: 1px solid var(--border-chip); }
.post-meta .author { color: var(--fg-secondary); font-weight: 500; }
.post-meta .sep { color: var(--fg-divider); }
.post-meta .num { font-family: var(--font-mono); }
.post-cover {
  border: 1px solid var(--border-strong);
  border-radius: var(--r-lg);
  overflow: hidden;
  margin-bottom: var(--space-8);
  box-shadow: 0 8px 24px -12px rgba(0, 0, 0, .6);
}
.post-cover img { display: block; width: 100%; height: auto; }

/* ---------- prose ---------- */
.prose { font-size: var(--text-body); line-height: var(--leading-body); color: var(--fg-body); }
.prose p { margin: 0 0 var(--space-5); }
.prose > :first-child { margin-top: 0; }
.prose h2 {
  margin: var(--space-10) 0 14px;
  font: 700 var(--text-h2) var(--font-mono);
  letter-spacing: -.02em;
  color: var(--fg-heading);
  scroll-margin-top: 110px;
}
.prose h2::before { content: '#'; color: var(--accent-bright); margin-right: 8px; }
.prose h3 {
  margin: var(--space-8) 0 var(--space-3);
  font: 700 var(--text-h3) var(--font-mono);
  letter-spacing: -.02em;
  color: var(--fg-heading);
  scroll-margin-top: 110px;
}
.prose h4 {
  margin: var(--space-6) 0 var(--space-2);
  font: 700 15px var(--font-mono);
  color: var(--fg-heading);
}
.prose a { text-decoration: none; border-bottom: 1px solid rgba(240, 115, 58, .35); }
.prose a:hover { border-bottom-color: var(--accent-hover); }
.prose ul, .prose ol { margin: 0 0 var(--space-5); padding-left: 22px; }
.prose li { margin: 6px 0; }
.prose li::marker { color: var(--fg-meta); }
.prose hr { border: 0; border-top: 1px solid var(--border); margin: var(--space-8) 0; }
.prose img {
  display: block;
  max-width: 100%;
  height: auto;
  margin: var(--space-6) 0;
  border: 1px solid var(--border-strong);
  border-radius: var(--r-lg);
  background: #0d0e10;
}
.prose figure { margin: var(--space-6) 0; }
.prose figcaption { font: var(--text-sm) var(--font-mono); color: var(--fg-meta); margin-top: 8px; }
.prose code {
  padding: 1px 6px;
  border-radius: var(--r-xs);
  background: var(--surface-chip);
  border: 1px solid var(--border-chip);
  color: var(--accent-tint);
  font: 14px var(--font-mono);
}
.prose pre code {
  padding: 0;
  border: 0;
  border-radius: 0;
  background: none;
  color: inherit;
  font: inherit;
}
.prose blockquote {
  margin: 0 0 var(--space-5);
  padding: 2px 0 2px 16px;
  border-left: 2px solid var(--accent);
  color: var(--fg-secondary);
  font-style: italic;
}
.prose blockquote p:last-child { margin-bottom: 0; }
.table-scroll { overflow-x: auto; margin: 0 0 var(--space-6); }
.table-scroll table { margin-bottom: 0; }
.prose table {
  width: 100%;
  margin: 0 0 var(--space-6);
  border-collapse: collapse;
  font-size: 14px;
  border: 1px solid var(--border-strong);
  border-radius: var(--r-lg);
  overflow: hidden;
}
.prose thead { background: var(--surface-raised); }
.prose th {
  text-align: left;
  padding: 10px 14px;
  font: 700 var(--text-xs) var(--font-mono);
  letter-spacing: var(--tracking-label);
  text-transform: uppercase;
  color: var(--fg-meta);
  border-bottom: 1px solid var(--border-strong);
}
.prose td { padding: 10px 14px; border-bottom: 1px solid var(--border); color: var(--fg-body); }
.prose tbody tr:last-child td { border-bottom: 0; }
.prose sup { font-size: 11px; }
.prose .footnote-definition { font-size: 14px; color: var(--fg-muted); }
.prose .footnote-definition p { display: inline; }

/* ---------- callout / github alerts ---------- */
.prose blockquote.markdown-alert-warning,
.prose blockquote.markdown-alert-caution,
.prose blockquote.markdown-alert-note,
.prose blockquote.markdown-alert-tip,
.prose blockquote.markdown-alert-important,
.callout {
  padding: 14px 18px;
  margin: 0 0 var(--space-7);
  border: 1px solid rgba(240, 115, 58, .3);
  border-radius: var(--r-sm);
  border-radius: 8px;
  background: linear-gradient(180deg, rgba(217, 72, 15, .12), rgba(217, 72, 15, .05));
  color: #e6c9b8;
  font-size: 14px;
  line-height: 1.55;
  font-style: normal;
}
.prose blockquote.markdown-alert-warning p,
.callout p { margin: 0 0 8px; }
.prose blockquote.markdown-alert-warning p:last-child,
.callout p:last-child { margin-bottom: 0; }
.prose blockquote.markdown-alert-warning::before,
.prose blockquote.markdown-alert-caution::before,
.prose blockquote.markdown-alert-note::before,
.prose blockquote.markdown-alert-tip::before,
.prose blockquote.markdown-alert-important::before,
.callout::before {
  content: 'WARNING';
  display: block;
  margin-bottom: 4px;
  font: 700 var(--text-xs) var(--font-mono);
  color: var(--accent-bright);
  letter-spacing: .06em;
}
.prose blockquote.markdown-alert-note::before { content: 'NOTE'; }
.prose blockquote.markdown-alert-tip::before { content: 'TIP'; }
.prose blockquote.markdown-alert-important::before { content: 'IMPORTANT'; }
.prose blockquote.markdown-alert-caution::before { content: 'CAUTION'; }
.prose blockquote.markdown-alert-note,
.prose blockquote.markdown-alert-tip { border-color: var(--border-chip); background: var(--surface-grad); color: var(--fg-body); }
.prose blockquote.markdown-alert-note::before,
.prose blockquote.markdown-alert-tip::before { color: var(--fg-meta); }

/* ---------- code blocks ---------- */
.prose pre, .code-block pre {
  margin: 0;
  padding: 16px 18px;
  overflow: auto;
  font: var(--text-base) / var(--leading-code) var(--font-mono);
  color: #d6d9de;
  tab-size: 4;
  background: var(--bg-code);
  counter-reset: codeline;
}
/* standalone pre (before JS chrome wraps it) */
.prose > pre {
  border: 1px solid var(--border-input);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-code);
  margin: 0 0 var(--space-6);
}
.code-block {
  margin: 0 0 var(--space-6);
  border: 1px solid var(--border-input);
  border-radius: var(--r-lg);
  background: var(--bg-code);
  box-shadow: var(--shadow-code);
  overflow: hidden;
}
.code-block pre { border: 0; border-radius: 0; box-shadow: none; }
.code-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px 8px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--header-grad);
  font: var(--text-sm) var(--font-mono);
  color: var(--fg-meta);
}
.code-head .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); flex: none; }
.code-head .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.code-head .lang {
  margin-left: auto;
  padding: 2px 6px;
  border-radius: var(--r-xs);
  border: 1px solid var(--border-chip);
  color: var(--fg-faint);
  font-size: 10px;
  flex: none;
}
.code-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  height: 26px;
  padding: 0 9px;
  border-radius: var(--r-sm);
  border: 1px solid var(--border-chip);
  background: var(--surface-raised);
  color: var(--fg-meta);
  font: var(--text-xs) var(--font-mono);
  cursor: pointer;
  flex: none;
  transition: color var(--dur-fast), border-color var(--dur-fast);
}
.code-btn:hover { border-color: var(--accent); color: var(--accent-bright); }
.code-btn.is-on { border-color: #5a3324; color: var(--accent-bright); }
.code-btn.is-copied { color: var(--accent-bright); border-color: #5a3324; }
.code-block.is-terminal pre { color: var(--fg-muted); padding: 14px 18px; }
.code-block.is-terminal .code-head .term-icon { color: var(--fg-meta); display: flex; }

/* line numbers: rendered with counters so the toggle works for every block */
.giallo-ln { display: none; }
pre.giallo .giallo-l { counter-increment: codeline; }
.linenos-on pre.giallo {
  background-image: linear-gradient(90deg, var(--border) 0 1px, transparent 1px);
  background-repeat: no-repeat;
  background-size: 1px 100%;
  background-position: calc(18px + 3ch + 14px) 0;
  background-attachment: local;
}
.linenos-on pre.giallo .giallo-l::before {
  content: counter(codeline);
  display: inline-block;
  width: 3ch;
  margin-right: 14px;
  padding-right: 14px;
  text-align: right;
  color: var(--fg-ghost);
  user-select: none;
  -webkit-user-select: none;
}
.code-block.is-terminal pre.giallo .giallo-l::before { content: none; }

pre.giallo, .z-code { background: var(--bg-code); color: #d6d9de; }

/* ---------- prev / next ---------- */
.post-nav {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-4);
  margin-top: var(--space-14);
  padding-top: var(--space-7);
  border-top: 1px solid var(--border);
}
.post-nav a {
  display: block;
  padding: 16px 18px;
  border: 1px solid var(--border-strong);
  border-radius: var(--r-lg);
  background: var(--surface-grad);
  color: var(--fg);
  transition: border-color var(--dur-fast);
}
.post-nav a:hover { border-color: var(--border-hover); color: var(--fg); }
.post-nav a.next { text-align: right; }
.post-nav .label { display: block; font: var(--text-xs) var(--font-mono); color: var(--fg-meta); margin-bottom: 6px; }
.post-nav .title { font: 700 14px var(--font-mono); }
.post-nav .spacer { display: block; }

/* ---------- TOC desktop ---------- */
.toc-aside { position: sticky; top: 110px; }
.toc-label {
  font: 700 var(--text-xs) var(--font-mono);
  color: var(--fg-meta);
  letter-spacing: var(--tracking-label);
  text-transform: uppercase;
  margin-bottom: var(--space-3);
}
.toc-list {
  list-style: none;
  margin: 0;
  padding: 0;
  border-left: 1px solid var(--border-strong);
  display: flex;
  flex-direction: column;
  position: relative;
}
.toc-list a {
  display: block;
  padding: 6px 14px;
  font-size: var(--text-base);
  line-height: 16px;
  color: var(--fg-meta);
  transition: color var(--dur-fast);
}
.toc-list a:hover { color: var(--fg); }
.toc-list a.is-active { color: var(--fg-heading); }
.toc-indicator {
  position: absolute;
  left: -1px;
  top: 0;
  height: 28px;
  width: 2px;
  background: var(--accent-bright);
  box-shadow: 0 0 8px rgba(240, 115, 58, .6);
  transform: translateY(0);
  transition: transform .25s ease;
}
.author-card {
  margin-top: var(--space-7);
  padding: 14px;
  border: 1px solid var(--border-strong);
  border-radius: var(--r-lg);
  background: var(--surface-grad);
}
.author-card .row { display: flex; align-items: center; gap: 10px; }
.author-card img { width: 36px; height: 36px; border-radius: 50%; object-fit: cover; border: 1px solid var(--border-chip); }
.author-card .name { display: block; color: var(--fg-heading); font-weight: 600; font-size: 14px; }
.author-card .sub { font: var(--text-xs) var(--font-mono); color: var(--fg-meta); }

/* ---------- sheet trigger (mobile FAB) ---------- */
.sheet-fab {
  position: fixed;
  right: 16px;
  bottom: 20px;
  z-index: 55;
  display: none;
  place-items: center;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: 1px solid #5a3324;
  background: var(--accent-grad);
  color: #fff;
  box-shadow: 0 12px 28px -8px rgba(217, 72, 15, .75);
  cursor: pointer;
}

/* ---------- chapters pane (mobile TOC) ---------- */
.toc-pane .head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}
.toc-pane .head .t {
  font: 700 var(--text-xs) var(--font-mono);
  color: var(--fg-meta);
  letter-spacing: var(--tracking-label);
  text-transform: uppercase;
}
.toc-pane .head .pct { font: var(--text-xs) var(--font-mono); color: var(--accent-bright); }
.toc-pane ul { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.toc-pane a {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 10px;
  border-radius: 8px;
  color: var(--fg-meta);
  font-size: 15px;
}
.toc-pane a .d { width: 6px; height: 6px; border-radius: 50%; background: var(--fg-divider); flex: none; }
.toc-pane a.is-active { background: rgba(240, 115, 58, .08); color: var(--fg-heading); }
.toc-pane a.is-active .d { background: var(--accent-bright); }

/* ---------- about ---------- */
.about { padding: 64px var(--pad-x) 80px; }
.prompt { font: var(--text-sm) var(--font-mono); color: var(--accent-bright); margin-bottom: 14px; }
.page-title {
  margin: 0 0 var(--space-6);
  font: 700 clamp(30px, 4vw, 44px) / 1.1 var(--font-mono);
  letter-spacing: var(--tracking-heading);
  color: var(--fg-heading);
}
.about-row { display: flex; gap: var(--space-7); align-items: flex-start; flex-wrap: wrap; }
.about-avatar {
  width: 120px;
  height: 120px;
  border-radius: var(--r-xl);
  border-radius: 12px;
  object-fit: cover;
  border: 1px solid var(--border-chip);
  box-shadow: 0 8px 24px -12px rgba(0, 0, 0, .8);
}
.about-bio { flex: 1; min-width: 260px; font-size: var(--text-body); line-height: var(--leading-body); color: var(--fg-body); }
.about-bio p { margin: 0 0 16px; }
.facts { display: flex; flex-wrap: wrap; gap: 16px; font: 13px var(--font-mono); color: var(--fg-meta); }
.facts span { display: flex; align-items: center; gap: 6px; }
.pull-quote {
  margin: 14px 0 0;
  font: italic 13px / 1.6 var(--font-mono);
  color: var(--fg-secondary);
  border-left: 2px solid var(--accent);
  padding-left: 12px;
}
.link-chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: var(--space-7); }
.link-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 12px;
  border: 1px solid var(--border-input);
  border-radius: var(--r-md);
  background: var(--surface-grad);
  color: var(--fg-secondary);
  font: var(--text-sm) var(--font-mono);
  transition: border-color var(--dur-fast), color var(--dur-fast);
}
.link-chip:hover { border-color: var(--accent); color: var(--accent-bright); }
.link-chip .i { display: flex; color: var(--accent-bright); }
.about h2.sub-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: var(--space-12) 0 14px;
  font: 700 var(--text-base) var(--font-mono);
  color: var(--fg-meta);
  letter-spacing: var(--tracking-label);
  text-transform: uppercase;
}
.stack-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: var(--space-3); }
.stack-card {
  padding: 14px 16px;
  border: 1px solid var(--border-strong);
  border-radius: var(--r-lg);
  background: var(--surface-grad);
  transition: border-color var(--dur-fast);
}
.stack-card:hover { border-color: var(--border-hover); }
.stack-card .row { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.stack-card .tile {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: var(--r-md);
  border: 1px solid var(--border-chip);
  background: var(--surface-chip);
  color: var(--accent-bright);
  flex: none;
}
.stack-card .k { font: 700 13px var(--font-mono); color: var(--fg-heading); }
.stack-card .v { font-size: var(--text-base); line-height: 1.5; color: var(--fg-muted); text-wrap: pretty; }
.repo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: var(--space-3); }
.repo-card {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 16px 18px;
  border: 1px solid var(--border-strong);
  border-radius: var(--r-lg);
  background: var(--surface-grad);
  color: var(--fg);
  box-shadow: 0 8px 24px -14px rgba(0, 0, 0, .6);
  transition: border-color var(--dur-fast);
}
.repo-card:hover { border-color: var(--border-hover); color: var(--fg); }
.repo-card .n { display: flex; align-items: center; gap: 8px; font: 700 14px var(--font-mono); color: var(--fg-heading); }
.repo-card .n .ext { margin-left: auto; }
.repo-card p { margin: 0; flex: 1; font-size: var(--text-base); line-height: 1.5; color: var(--fg-muted); text-wrap: pretty; }
.repo-card .foot { display: flex; gap: 14px; font: var(--text-xs) var(--font-mono); color: var(--fg-meta); }
.repo-card .foot span { display: flex; align-items: center; gap: 6px; }
.repo-card .foot .langdot { width: 8px; height: 8px; border-radius: 50%; }
.repo-card .foot .stars { gap: 5px; }

.stat-row { display: flex; gap: var(--space-6); font: var(--text-sm) var(--font-mono); color: var(--fg-meta); margin-top: var(--space-7); }
.stat-row .n { font-size: 24px; color: var(--fg-heading); font-weight: 700; font-family: var(--font-mono); }

/* ---------- post rows (tags, about) ---------- */
.post-rows { display: flex; flex-direction: column; }
.post-row {
  display: grid;
  grid-template-columns: 110px minmax(0, 1fr) auto;
  gap: var(--space-5);
  align-items: center;
  padding: 18px 4px;
  border-bottom: 1px solid var(--border);
  color: var(--fg);
}
.post-row:hover { background: rgba(255, 255, 255, .015); color: var(--fg); }
.post-row .d { font: var(--text-sm) var(--font-mono); color: var(--fg-meta); }
.post-row .t { font: 700 16px var(--font-mono); letter-spacing: -.02em; color: var(--fg-heading); }
.post-row .a { font: var(--text-sm) var(--font-mono); color: var(--accent-bright); }

/* ---------- tags ---------- */
.tags-page { padding: var(--space-14) var(--pad-x) 80px; }
.tag-cloud { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: var(--space-12); }
.tag-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  border: 1px solid var(--border-input);
  border-radius: 8px;
  background: var(--surface-grad);
  color: var(--fg-secondary);
  font: 13px var(--font-mono);
  transition: border-color var(--dur-fast), color var(--dur-fast);
}
.tag-pill:hover { border-color: var(--accent); color: var(--accent-bright); }
.tag-pill.is-selected { border-color: var(--accent); color: var(--accent-bright); }
.tag-pill .n { padding: 0 6px; border-radius: var(--r-xs); background: var(--border); color: var(--fg-meta); font-size: var(--text-xs); }
.tag-group-head {
  display: flex;
  align-items: baseline;
  gap: var(--space-3);
  margin-bottom: 8px;
  padding-bottom: var(--space-3);
  border-bottom: 1px solid var(--border);
}
.tag-group-head h2 {
  margin: 0;
  font: 700 var(--text-base) var(--font-mono);
  color: var(--fg-meta);
  letter-spacing: var(--tracking-label);
  text-transform: uppercase;
}
.tag-group-head .slashes { color: var(--accent-bright); }
.tag-group-head .count { font: var(--text-sm) var(--font-mono); color: var(--fg-faint); }
.tag-group + .tag-group { margin-top: var(--space-12); }

/* ---------- 404 ---------- */
.notfound {
  max-width: var(--container-narrow);
  margin: 0 auto;
  padding: 80px var(--pad-x) 100px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: var(--space-5);
}
.notfound .cmd { font: var(--text-sm) var(--font-mono); color: var(--fg-meta); }
.notfound .big {
  font: 700 clamp(72px, 14vw, 140px) / 1 var(--font-mono);
  letter-spacing: -.06em;
  background: linear-gradient(180deg, #f3f1ec 30%, #5c626b);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.stderr-block {
  width: 100%;
  border: 1px solid var(--border-input);
  border-radius: var(--r-lg);
  background: var(--bg-code);
  overflow: hidden;
}
.stderr-block .head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--header-grad);
  font: var(--text-sm) var(--font-mono);
  color: var(--fg-meta);
}
.stderr-block .head .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); }
.stderr-block pre {
  margin: 0;
  padding: 16px 18px;
  font: var(--text-base) / var(--leading-code) var(--font-mono);
  color: #d6d9de;
  white-space: pre-wrap;
}
.stderr-block .e { color: var(--accent-bright); }
.stderr-block .ty { color: var(--code-type); }
.stderr-block .st { color: var(--code-string); }
.stderr-block .cm { color: var(--code-comment); }
.btn-row { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 4px; }
.btn {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 40px;
  padding: 0 16px;
  border-radius: var(--r-md);
  font: 600 13px var(--font-sans);
}
.btn-primary {
  border: 1px solid var(--accent);
  background: var(--accent-grad);
  color: #fff;
  box-shadow: var(--shadow-cta);
}
.btn-primary:hover { color: #fff; }
.btn-secondary {
  border: 1px solid var(--border-input);
  background: var(--surface-grad);
  color: var(--fg-secondary);
  transition: border-color var(--dur-fast), color var(--dur-fast);
}
.btn-secondary:hover { border-color: var(--accent); color: var(--accent-bright); }

/* ---------- footer ---------- */
.site-footer {
  border-top: 1px solid var(--border);
  background: linear-gradient(180deg, var(--bg), #0b0c0d);
}
.site-footer .inner { padding: var(--space-12) var(--pad-x) var(--space-10); }
.footer-quote {
  margin: 0;
  padding: 22px 26px;
  border: 1px solid var(--border-strong);
  border-radius: 12px;
  background: linear-gradient(135deg, #17191c, #121416);
  box-shadow: var(--inset-hairline);
  position: relative;
  overflow: hidden;
}
.footer-quote .bar { position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--accent-grad); }
.footer-quote p { margin: 0; font: 400 15px / 1.7 var(--font-mono); color: var(--fg-secondary); text-wrap: pretty; }
.footer-quote cite { display: block; margin-top: var(--space-3); font: var(--text-sm) var(--font-mono); color: var(--accent-bright); font-style: normal; }
.footer-bottom {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  align-items: center;
  justify-content: space-between;
  margin-top: var(--space-8);
  font: var(--text-sm) var(--font-mono);
  color: var(--fg-faint);
}
.footer-bottom a { color: var(--fg-meta); }
.footer-bottom a:hover { color: var(--accent-bright); }
.footer-bottom .left a { color: var(--fg-faint); }
.footer-bottom .links { display: flex; gap: 18px; }

/* ---------- responsive ---------- */
@media (max-width: 1023px) {
  .post-layout { grid-template-columns: minmax(0, 1fr); gap: 0; }
  .toc-aside { display: none; }
  /* The chapters tab is the only TOC below 1024px, so the trigger must show. */
  .sheet-fab.has-chapters { display: grid; }
}

@media (max-width: 639px) {
  :root { --pad-x: 16px; }
  .brand-full { display: none; }
  .brand-short { display: inline; }
  .nav, .header-right { display: none; }
  .sheet-fab { display: grid; }
  .hero h1 { font-size: 36px; }
  .card-grid { grid-template-columns: minmax(0, 1fr); }
  .post-wrap { padding-top: var(--space-7); }
  .about { padding-top: var(--space-10); }
  .facts { gap: 10px 16px; }
}

@media (min-width: 1024px) {
  #sheet-fab, #nav-backdrop, #nav-sheet { display: none; }
}

@media (max-width: 400px) {
  .post-nav { grid-template-columns: minmax(0, 1fr); }
  .post-row { grid-template-columns: minmax(0, 1fr) auto; }
  .post-row .d { grid-column: 1 / -1; }
}

/* ---------- reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .hero-dots, .hero-glow, .card, .search-panel, .sheet { animation: none; }
  .hero-cursor { animation: none; }
  .card:hover { transform: none; }
  .toc-indicator, .progress-bar { transition: none; }
  .page-root, .is-leaving .page-root, .is-leaving .page-wipe { animation: none; }
}
