/* Plain minimal site shell */

:root,
[data-theme="dark"] {
  --bg: #111111;
  --fg: #e8e8e8;
  --muted: #9a9a9a;
  --link: #7eb6ff;
  --line: #2a2a2a;
  --surface: #1a1a1a;
  --font-serif: "Newsreader", "Times New Roman", Times, serif;
  --font-mono: "IBM Plex Mono", ui-monospace, "Cascadia Code", "Segoe UI Mono", monospace;
  --font-sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --max: 40rem;
  --pad: 1.25rem;
  --space: 1rem;
}

[data-theme="light"] {
  --bg: #fafafa;
  --fg: #1a1a1a;
  --muted: #5c5c5c;
  --link: #0b57d0;
  --line: #e0e0e0;
  --surface: #f0f0f0;
}

html {
  background: var(--bg);
  color: var(--fg);
}

body {
  font-family: var(--font-serif);
  font-size: 1.125rem;
  background: transparent;
  color: var(--fg);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* Three.js full-viewport background — lvh/lvw resist mobile chrome resize */
#bg-sphere,
canvas#bg-sphere,
.bg-sphere-canvas {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  width: 100lvw;
  height: 100%;
  height: 100lvh;
  z-index: 0;
  pointer-events: none;
}

/* UI above canvas */
.skip-link,
#header,
#main,
#footer {
  position: relative;
  z-index: 1;
}

/* Skip link */
.skip-link {
  position: absolute;
  left: var(--pad);
  top: -100px;
  z-index: 100;
  padding: 0.5rem 0.75rem;
  background: var(--fg);
  color: var(--bg);
  text-decoration: none;
  font-family: var(--font-sans);
  font-size: 0.875rem;
}

.skip-link:focus {
  top: var(--pad);
}

/* Header */
#header {
  border-bottom: 1px solid var(--line);
}

.header-inner {
  max-width: calc(var(--max) + 8rem);
  margin: 0 auto;
  padding: 0.85rem var(--pad);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.site-mark {
  font-family: var(--font-mono);
  font-size: 0.95rem;
  font-weight: 500;
  text-decoration: none;
  letter-spacing: 0.02em;
}

.site-mark:hover,
.site-mark[aria-current="page"] {
  text-decoration: underline;
  text-underline-offset: 0.2em;
}

.header-nav {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem 1rem;
  font-family: var(--font-mono);
  font-size: 0.8rem;
}

.nav-link {
  text-decoration: none;
  color: var(--muted);
  padding: 0.35rem 0;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
}

.nav-link:hover,
.nav-link.active {
  color: var(--fg);
  text-decoration: underline;
  text-underline-offset: 0.2em;
}

.theme-toggle {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 0.25rem;
  padding: 0.35rem 0.55rem;
  min-height: 44px;
}

.theme-toggle:hover {
  color: var(--fg);
  border-color: var(--muted);
}

/* Main */
#main {
  flex: 1;
  width: 100%;
  max-width: calc(var(--max) + 8rem);
  margin: 0 auto;
  padding: 2rem var(--pad) 3rem;
}

/* Same-document View Transitions: content only, live canvas underneath */
main#main {
  view-transition-name: main-content;
}

@media (prefers-reduced-motion: reduce) {
  ::view-transition-group(*),
  ::view-transition-old(*),
  ::view-transition-new(*) {
    animation: none !important;
  }
}

/* Footer */
#footer {
  border-top: 1px solid var(--line);
  max-width: calc(var(--max) + 8rem);
  margin: 0 auto;
  padding: 1rem var(--pad) 1.5rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1.25rem;
  align-items: center;
  justify-content: space-between;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--muted);
}

.footer-legal a {
  color: var(--muted);
  text-decoration: none;
}

.footer-legal a:hover {
  color: var(--fg);
  text-decoration: underline;
  text-underline-offset: 0.15em;
}

.footer-sep {
  margin: 0 0.35rem;
}

/* Links in content */
a {
  color: var(--link);
  text-underline-offset: 0.15em;
}

#header a,
#footer a,
.post-link,
.all-posts-link,
.article-back,
.site-mark {
  color: inherit;
}

/* Home */
.home-hero {
  margin-bottom: 2.5rem;
}

.hero-title {
  font-size: clamp(2rem, 5vw, 2.75rem);
  font-weight: 400;
  line-height: 1.15;
  letter-spacing: -0.02em;
  margin-bottom: 0.75rem;
}

.hero-lede {
  max-width: 36ch;
  color: var(--muted);
  font-size: 1.15rem;
}

.section-label {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin-bottom: 1rem;
  font-weight: 500;
}

/* Post lists */
.post-list {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.post-list > li {
  border-top: 1px solid var(--line);
}

.post-list > li:last-child {
  border-bottom: 1px solid var(--line);
}

.post-link {
  display: grid;
  gap: 0.25rem;
  padding: 1rem 0;
  text-decoration: none;
  color: var(--fg);
}

.post-link:hover .post-title {
  text-decoration: underline;
  text-underline-offset: 0.15em;
}

.post-date,
.post-tag {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--muted);
}

.post-title {
  font-size: 1.2rem;
  line-height: 1.3;
}

.post-blurb {
  color: var(--muted);
  font-size: 1rem;
  max-width: 55ch;
}

.all-posts-link {
  display: inline-block;
  margin-top: 1.5rem;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  text-decoration: none;
}

.all-posts-link:hover {
  text-decoration: underline;
}

/* Page headers */
.page-header {
  margin-bottom: 1.75rem;
}

.page-title {
  font-size: clamp(1.75rem, 4vw, 2.25rem);
  font-weight: 400;
  line-height: 1.2;
  letter-spacing: -0.02em;
}

.page-lede {
  margin-top: 0.5rem;
  color: var(--muted);
  max-width: 40ch;
}

.muted {
  color: var(--muted);
}

/* Prose / legal pages */
.page-content,
.prose,
.article-body {
  max-width: 65ch;
}

.page-content h2,
.article-body h2 {
  font-size: 1.35rem;
  font-weight: 400;
  margin: 2rem 0 0.75rem;
  line-height: 1.3;
}

.page-content p,
.prose p,
.article-body p {
  margin: 0 0 1rem;
}

.page-content a,
.prose a,
.article-body a,
.article-footer a {
  color: var(--link);
}

/* Article */
.article-back {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--muted);
  text-decoration: none;
  margin-bottom: 1.25rem;
}

.article-back:hover {
  color: var(--fg);
  text-decoration: underline;
}

.article-meta {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--muted);
  margin-bottom: 0.5rem;
}

.article-title {
  font-size: clamp(1.75rem, 4vw, 2.35rem);
  font-weight: 400;
  line-height: 1.2;
  letter-spacing: -0.02em;
  margin-bottom: 0.75rem;
}

.article-blurb {
  color: var(--muted);
  font-size: 1.1rem;
  margin-bottom: 1.75rem;
  max-width: 50ch;
}

.article-note {
  border-left: 2px solid var(--line);
  padding: 0.75rem 0 0.75rem 1rem;
  margin: 1.5rem 0;
  color: var(--muted);
}

.article-note-label {
  display: block;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 0.35rem;
  color: var(--fg);
}

.article-footer {
  margin-top: 2.5rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--line);
  font-family: var(--font-mono);
  font-size: 0.85rem;
  color: var(--muted);
}

/* Code / diagrams */
.code-block,
.article-diagram pre,
.qa-diagram {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  line-height: 1.45;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 0.25rem;
  padding: 1rem;
  overflow-x: auto;
  margin: 1.25rem 0;
}

.code-block code {
  font-family: inherit;
  white-space: pre;
}

.article-diagram figcaption,
.qa-diagram figcaption {
  margin-top: 0.5rem;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--muted);
}

.qa-compare-grid {
  display: grid;
  gap: 1rem;
}

@media (min-width: 540px) {
  .qa-compare-grid {
    grid-template-columns: 1fr 1fr;
  }
}

.qa-compare-card {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  padding: 0.75rem;
  border: 1px solid var(--line);
  border-radius: 0.25rem;
}

.qa-compare-tag {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.qa-compare-title {
  font-weight: 500;
}

.qa-compare-q,
.qa-flow-strip {
  color: var(--muted);
}

.qa-flow-strip {
  margin-top: 0.75rem;
}

.qa-phases-cols {
  display: grid;
  gap: 1.25rem;
}

@media (min-width: 540px) {
  .qa-phases-cols {
    grid-template-columns: 1fr 1fr;
  }
}

.qa-phases-cols ol {
  list-style: decimal;
  padding-left: 1.25rem;
  margin-top: 0.5rem;
}

.qa-table-scroll {
  overflow-x: auto;
}

.qa-diagram table {
  width: 100%;
  font-size: 0.8rem;
}

.qa-diagram th,
.qa-diagram td {
  border: 1px solid var(--line);
  padding: 0.4rem 0.6rem;
  text-align: left;
  vertical-align: top;
}

.qa-diagram th {
  background: var(--surface);
  font-weight: 500;
}

/* 404 */
.error-page {
  text-align: left;
}

.error-code {
  font-family: var(--font-mono);
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 0.5rem;
}

/* Responsive tweaks */
@media (max-width: 520px) {
  body {
    font-size: 1.05rem;
  }

  .header-inner {
    align-items: flex-start;
  }

  #footer {
    flex-direction: column;
    align-items: flex-start;
  }
}
