/* ============================================================
   Boltzmann Zola theme — layout, chrome, prose, components.
   Depends on tokens.css (design tokens & light/dark aliases).
   ============================================================ */

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  font-family: var(--font-sans);
  font-size: var(--text-md);
  line-height: var(--leading-relaxed);
  color: var(--text-body);
  background: var(--surface-page);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  * { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}

/* --- The mathematical graph-paper backdrop (toggle with x) --- */
body.grid-on {
  background-image:
    linear-gradient(var(--grid-line) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-line) 1px, transparent 1px);
  background-size: var(--rhythm) var(--rhythm);
  background-position: center top;
}

a { color: var(--text-link); text-decoration: none; }
a:hover { color: var(--text-link-hover); text-decoration: underline; text-underline-offset: 2px; }

:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px var(--surface-page), 0 0 0 4px var(--focus-ring);
  border-radius: var(--radius-sm);
}

::selection { background: var(--cyan-200); color: var(--gray-950); }
[data-theme="dark"] ::selection { background: rgba(34, 207, 232, 0.32); color: var(--gray-50); }

/* ============================================================
   Header — the entropy aurora
   ============================================================ */
.site-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background:
    linear-gradient(33deg,
      rgba(107,58,128,0.55) 0%,
      rgba(68,80,137,0.42) 28%,
      rgba(42,143,143,0.36) 50%,
      rgba(168,154,46,0.40) 72%,
      rgba(168,67,47,0.52) 100%),
    rgba(26,24,23,0.86);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-bottom: var(--border-width-accent) solid #fff;
}

.site-header__inner {
  max-width: var(--measure-wide);
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: var(--space-5);
  padding: 14px 24px;
}

.wordmark {
  font-family: var(--font-sans);
  font-weight: var(--weight-semibold);
  font-variant: small-caps;
  letter-spacing: var(--tracking-caps);
  color: #fff;
  line-height: 1;
  font-size: 1.6rem;
  white-space: nowrap;
}
.wordmark:hover { color: #fff; text-decoration: none; }

.site-nav {
  display: flex;
  align-items: center;
  gap: var(--space-5);
  margin-left: auto;
}
.site-nav a {
  color: #fff;
  font-size: var(--text-sm);
  opacity: 0.92;
  white-space: nowrap;
}
.site-nav a:hover { opacity: 1; text-decoration: none; }
.site-nav a.is-active { opacity: 1; box-shadow: inset 0 -2px 0 var(--cyan-400); }

/* Header icon buttons (theme + grid toggles) */
.hbtn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px; height: 32px;
  border: 1px solid rgba(255,255,255,0.25);
  background: transparent;
  border-radius: var(--radius-md);
  color: #fff;
  cursor: pointer;
  transition: background var(--duration-fast) var(--ease-out), border-color var(--duration-fast) var(--ease-out);
  padding: 0;
}
.hbtn:hover { background: rgba(255,255,255,0.12); border-color: rgba(255,255,255,0.5); }
.hbtn.is-on { background: rgba(255,255,255,0.15); border-color: rgba(255,255,255,0.7); }
.hbtn svg { width: 17px; height: 17px; stroke: #fff; }
.hbtn .icon-moon { display: none; }
[data-theme="dark"] .hbtn .icon-sun { display: none; }
[data-theme="dark"] .hbtn .icon-moon { display: inline; }

/* Search box in header */
.site-search { position: relative; flex: 1; max-width: 34rem; }
.site-search input {
  width: 100%;
  height: 38px;
  padding: 0 12px 0 36px;
  background: rgba(255,255,255,0.12);
  border: 1px solid rgba(255,255,255,0.35);
  border-radius: var(--radius-md);
  color: #fff;
  font-family: var(--font-sans);
  font-size: 15px;
  outline: none;
}
.site-search input::placeholder { color: rgba(255,255,255,0.7); }
.site-search input:focus { border-color: var(--cyan-400); box-shadow: 0 0 0 2px rgba(34,207,232,0.4); }
.site-search__icon {
  position: absolute; left: 11px; top: 50%; transform: translateY(-50%);
  color: #fff; opacity: 0.85; display: inline-flex; pointer-events: none;
}
.site-search__icon svg { width: 16px; height: 16px; stroke: #fff; }

.search-results {
  position: absolute;
  top: calc(100% + 8px);
  left: 0; right: 0;
  background: var(--surface-card);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  max-height: 60vh;
  overflow-y: auto;
  display: none;
  z-index: 200;
}
.search-results.is-open { display: block; }
.search-results__item {
  display: block;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border-subtle);
  color: var(--text-body);
}
.search-results__item:last-child { border-bottom: none; }
.search-results__item:hover, .search-results__item.is-active {
  background: var(--surface-hover); text-decoration: none;
}
.search-results__title { font-weight: var(--weight-semibold); color: var(--text-strong); font-size: var(--text-base); }
.search-results__excerpt { font-size: var(--text-sm); color: var(--text-muted); margin-top: 2px; line-height: var(--leading-normal); }
.search-results__empty { padding: 14px; color: var(--text-muted); font-size: var(--text-sm); }

/* ============================================================
   Page shell & layout
   ============================================================ */
.site-main { flex: 1 0 auto; width: 100%; }

.shell {
  max-width: var(--measure-wide);
  margin: 0 auto;
  padding: var(--space-8) var(--space-6) var(--space-10);
}

/* Docs / sectioned layout: sticky sidebar + prose */
.layout-docs {
  max-width: var(--measure-wide);
  margin: 0 auto;
  padding: var(--space-8) var(--space-6) var(--space-10);
  display: grid;
  grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
  gap: var(--space-8);
  align-items: start;
}

.sidebar { position: sticky; top: calc(38px + 28px + var(--space-6)); }
.sidebar__label {
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: var(--tracking-caps);
  color: var(--text-subtle);
  font-weight: var(--weight-semibold);
  margin: 0 0 var(--space-3);
}
.sidebar ul { list-style: none; margin: 0 0 var(--space-6); padding: 0; }
.sidebar li { margin: 0; }
.sidebar a {
  display: block;
  padding: 6px 10px;
  color: var(--text-body);
  border-left: 2px solid var(--border-subtle);
  font-size: var(--text-base);
  line-height: var(--leading-snug);
}
.sidebar a:hover { color: var(--text-link); border-left-color: var(--border-strong); background: var(--surface-hover); text-decoration: none; }
.sidebar a.is-active { color: var(--text-link); border-left-color: var(--accent); font-weight: var(--weight-medium); background: var(--accent-soft); }

/* ============================================================
   Prose (rendered markdown)
   ============================================================ */
.prose { max-width: var(--measure-prose); }
.prose > *:first-child { margin-top: 0; }

.prose h1, .prose h2, .prose h3, .prose h4 {
  font-family: var(--font-sans);
  color: var(--text-strong);
  line-height: var(--leading-tight);
  letter-spacing: var(--tracking-tight);
  margin: calc(var(--rhythm) * 1.4) 0 var(--rhythm);
  scroll-margin-top: 6rem;
}
.prose h1 { font-size: var(--text-3xl); font-weight: var(--weight-bold); margin-top: 0; }
.prose h2 { font-size: var(--text-2xl); font-weight: var(--weight-semibold); padding-bottom: var(--space-2); border-bottom: 1px solid var(--border-subtle); }
.prose h3 { font-size: var(--text-xl); font-weight: var(--weight-semibold); }
.prose h4 { font-size: var(--text-lg); font-weight: var(--weight-semibold); }

.prose p, .prose ul, .prose ol { margin: 0 0 var(--rhythm); }
.prose li { margin: 0.35rem 0; }
.prose li::marker { color: var(--text-subtle); }
.prose ul { padding-left: 1.4rem; }
.prose ol { padding-left: 1.5rem; }

.prose strong { color: var(--text-strong); font-weight: var(--weight-semibold); }

.prose hr {
  border: none;
  height: 6px;
  margin: var(--space-8) 0;
  background: repeating-linear-gradient(-45deg, var(--accent) 0 6px, transparent 6px 12px);
  -webkit-mask: radial-gradient(circle at 6px 0, transparent 6px, #000 6.5px) repeat-x 0 0 / 12px 6px;
          mask: radial-gradient(circle at 6px 0, transparent 6px, #000 6.5px) repeat-x 0 0 / 12px 6px;
  opacity: 0.85;
}

/* Editorial / mathematical pull-quote voice — Plex Serif italic */
.prose blockquote {
  margin: var(--rhythm) 0;
  padding: var(--space-2) 0 var(--space-2) var(--space-5);
  border-left: var(--border-width-accent) solid var(--accent);
  font-family: var(--font-serif);
  font-style: italic;
  font-size: var(--text-lg);
  color: var(--text-muted);
}
.prose blockquote p { margin-bottom: var(--space-3); }
.prose blockquote p:last-child { margin-bottom: 0; }

/* Code — Plex Mono, dark frames in both themes */
.prose :not(pre) > code {
  font-family: var(--font-mono);
  font-size: 0.9em;
  background: var(--surface-sunken);
  color: var(--text-code);
  padding: 0.12em 0.4em;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  word-break: break-word;
}
.prose pre {
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  line-height: var(--leading-code);
  background: var(--surface-code);
  color: var(--gray-100);
  padding: var(--space-5);
  border-radius: var(--radius-md);
  overflow-x: auto;
  margin: var(--rhythm) 0;
  border: 1px solid var(--gray-800);
}
.prose pre code { font-family: inherit; background: none; border: none; padding: 0; color: inherit; }
.prose pre[data-linenos] { padding-left: 0; }

/* Links inside prose stay royalblue, underlined on hover */
.prose a { text-decoration: underline; text-decoration-color: var(--blue-200); text-underline-offset: 2px; }
.prose a:hover { text-decoration-color: currentColor; }
[data-theme="dark"] .prose a { text-decoration-color: rgba(138,164,240,0.4); }

/* Tables — crisp, radius-free */
.prose table {
  width: 100%;
  border-collapse: collapse;
  margin: var(--rhythm) 0;
  font-size: var(--text-base);
}
.prose th, .prose td {
  text-align: left;
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--border-default);
}
.prose th {
  background: var(--surface-sunken);
  font-weight: var(--weight-semibold);
  color: var(--text-strong);
  font-size: var(--text-sm);
  text-transform: uppercase;
  letter-spacing: var(--tracking-wide);
}
.prose tbody tr:nth-child(even) { background: var(--surface-sunken); }

.prose img { max-width: 100%; height: auto; border-radius: var(--radius-md); }

/* Callout — 3px colored left rule */
.prose .callout, .callout {
  margin: var(--rhythm) 0;
  padding: var(--space-4) var(--space-5);
  background: var(--info-bg);
  border-left: var(--border-width-accent) solid var(--info-solid);
  border-radius: 0 var(--radius-md) var(--radius-md) 0;
  font-size: var(--text-base);
}
.callout.warn { background: var(--warning-bg); border-left-color: var(--warning-solid); }
.callout.danger { background: var(--danger-bg); border-left-color: var(--danger-solid); }
.callout.success { background: var(--success-bg); border-left-color: var(--success-solid); }

/* ============================================================
   Page header block (title + meta)
   ============================================================ */
.page-head { margin-bottom: var(--space-7); }
.page-head h1 {
  font-family: var(--font-sans);
  font-size: var(--text-3xl);
  font-weight: var(--weight-bold);
  letter-spacing: var(--tracking-tight);
  line-height: var(--leading-tight);
  color: var(--text-strong);
  margin: 0 0 var(--space-3);
}
.page-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-3);
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  color: var(--text-muted);
}
.page-meta time { color: var(--text-muted); }

.tag-list { display: inline-flex; flex-wrap: wrap; gap: var(--space-2); }
.tag {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  padding: 2px 8px;
  color: var(--text-link);
  background: var(--accent-soft);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
}
.tag:hover { background: var(--surface-selected); text-decoration: none; }

/* ============================================================
   Home hero
   ============================================================ */
.hero {
  position: relative;
  overflow: hidden;
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  background:
    linear-gradient(33deg,
      rgba(107,58,128,0.55) 0%,
      rgba(68,80,137,0.42) 28%,
      rgba(42,143,143,0.36) 50%,
      rgba(168,154,46,0.40) 72%,
      rgba(168,67,47,0.52) 100%),
    var(--gray-900);
  color: #fff;
  padding: var(--space-9) var(--space-8);
  margin-bottom: var(--space-8);
}
.hero__eyebrow {
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  letter-spacing: var(--tracking-wide);
  color: rgba(255,255,255,0.8);
  margin: 0 0 var(--space-3);
}
.hero__title {
  font-family: var(--font-sans);
  font-variant: small-caps;
  letter-spacing: var(--tracking-caps);
  font-weight: var(--weight-bold);
  font-size: var(--text-4xl);
  line-height: 1;
  margin: 0 0 var(--space-3);
}
.hero__tagline {
  font-size: var(--text-lg);
  max-width: 42rem;
  color: rgba(255,255,255,0.9);
  margin: 0;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  height: var(--control-height-md);
  padding: 0 var(--space-5);
  font-family: var(--font-sans);
  font-size: var(--text-base);
  font-weight: var(--weight-medium);
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  white-space: nowrap;
  cursor: pointer;
  transition: background var(--duration-fast) var(--ease-out), transform var(--duration-fast) var(--ease-out);
}
.btn:hover { text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); color: #fff; }
.btn-ghost { background: rgba(255,255,255,0.1); color: #fff; border-color: rgba(255,255,255,0.35); }
.btn-ghost:hover { background: rgba(255,255,255,0.2); color: #fff; }
.hero__actions { display: flex; flex-wrap: wrap; gap: var(--space-3); margin-top: var(--space-6); }

/* ============================================================
   Post / listing cards
   ============================================================ */
.post-list { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--space-4); }
.section-title {
  font-family: var(--font-sans);
  font-size: var(--text-xl);
  font-weight: var(--weight-semibold);
  color: var(--text-strong);
  margin: var(--space-8) 0 var(--space-4);
  padding-bottom: var(--space-2);
  border-bottom: 1px solid var(--border-subtle);
}
.card {
  background: var(--surface-card);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  padding: var(--space-5) var(--space-6);
  transition: border-color var(--duration-normal) var(--ease-out), box-shadow var(--duration-normal) var(--ease-out), transform var(--duration-normal) var(--ease-out);
}
a.card, .card a.card-link { display: block; color: inherit; }
.card:hover { border-color: var(--border-strong); box-shadow: var(--shadow-md); }
.card__title {
  font-family: var(--font-sans);
  font-size: var(--text-lg);
  font-weight: var(--weight-semibold);
  color: var(--text-strong);
  margin: 0 0 var(--space-2);
}
.card__title a { color: inherit; }
.card__title a:hover { color: var(--text-link); text-decoration: none; }
.card__meta {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--text-muted);
  display: flex; flex-wrap: wrap; gap: var(--space-3); align-items: center;
  margin-bottom: var(--space-3);
}
.card__desc { color: var(--text-muted); font-size: var(--text-base); margin: 0; line-height: var(--leading-normal); }
.card__foot { margin-top: var(--space-3); }

/* Pagination */
.pager {
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--space-4);
  margin-top: var(--space-8);
  padding-top: var(--space-5);
  border-top: 1px solid var(--border-subtle);
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  color: var(--text-muted);
}
.pager a {
  display: inline-flex; align-items: center; gap: var(--space-2);
  padding: 6px 12px;
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  color: var(--text-link);
}
.pager a:hover { border-color: var(--border-strong); background: var(--surface-hover); text-decoration: none; }
.pager span { opacity: 0.8; }

/* ============================================================
   Footer
   ============================================================ */
.site-footer {
  flex-shrink: 0;
  background: var(--gray-800);
  color: #e7e5e4;
  margin-top: var(--space-9);
}
.site-footer__inner {
  max-width: var(--measure-wide);
  margin: 0 auto;
  padding: var(--space-6) var(--space-6);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--space-4);
}
.site-footer .wordmark { font-size: 1.1rem; }
.site-footer__tag { font-size: var(--text-sm); color: var(--gray-400); }
.site-footer__brand { display: flex; align-items: center; gap: var(--space-3); flex-wrap: wrap; }
.site-footer__links { display: flex; gap: var(--space-5); font-size: var(--text-sm); }
.site-footer__links a { color: var(--gray-400); }
.site-footer__links a:hover { color: #fff; text-decoration: none; }

/* ============================================================
   Responsive
   ============================================================ */
@media (max-width: 900px) {
  .layout-docs { grid-template-columns: 1fr; gap: var(--space-6); }
  .sidebar {
    position: static;
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
    padding: var(--space-4);
    background: var(--surface-card);
  }
  .site-search { max-width: none; }
}

@media (max-width: 680px) {
  .site-header__inner { flex-wrap: wrap; gap: var(--space-3); padding: 12px 16px; }
  .site-search { order: 3; flex-basis: 100%; max-width: none; }
  .site-nav { margin-left: 0; gap: var(--space-4); }
  .site-nav a.nav-page { display: none; }
  .shell, .layout-docs { padding: var(--space-6) var(--space-4) var(--space-8); }
  .hero { padding: var(--space-7) var(--space-5); }
  .hero__title { font-size: var(--text-3xl); }
  .prose h1, .page-head h1 { font-size: var(--text-2xl); }
  .site-footer__inner { flex-direction: column; align-items: flex-start; }
}

/* Fade-in entrance for content */
@media (prefers-reduced-motion: no-preference) {
  .site-main > * { animation: bz-fade-in var(--duration-slow) var(--ease-out) both; }
}
@keyframes bz-fade-in {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* Skip link (a11y) */
.skip-link {
  position: absolute; left: -9999px; top: 0; z-index: 300;
  background: var(--accent); color: #fff; padding: 10px 16px; border-radius: 0 0 var(--radius-md) 0;
}
.skip-link:focus { left: 0; color: #fff; }
