:root {
  --paper: #faf9f6;
  --paper-raised: #ffffff;
  --paper-soft: #f1f1ee;
  --ink: #1c1b19;
  --ink-soft: #6b685f;
  --rule: #e6e3dc;

  --source-blue: #2f5fd6;
  --source-blue-hover: #24499f;
  --source-blue-tint: #eaf0fd;

  --compiled-amber: #a8672b;
  --compiled-amber-tint: #f7ede0;

  --max-width: 1320px;
  --sidebar-width: 250px;
  --content-width: 760px;

  --font-body: 'IBM Plex Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Consolas, monospace;
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.7;
}

a { color: var(--source-blue); text-decoration: none; }
a:hover { color: var(--source-blue-hover); text-decoration: underline; }
a:focus-visible, button:focus-visible, summary:focus-visible {
  outline: 2px solid var(--source-blue);
  outline-offset: 3px;
}

/* ===================== top bar ===================== */

.topbar {
  height: 60px;
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 28px;
  border-bottom: 1px solid var(--rule);
  background: rgba(250, 249, 246, 0.92);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.wordmark {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 1.2rem;
  letter-spacing: -0.03em;
  color: var(--ink);
}
.wordmark:hover { text-decoration: none; }
.wordmark .dot { color: var(--source-blue); }

.tagline {
  padding-left: 16px;
  border-left: 1px solid var(--rule);
  color: var(--ink-soft);
  font-size: 0.84rem;
  display: none;
}
@media (min-width: 640px) { .tagline { display: inline; } }

.gh-link {
  margin-left: auto;
  color: var(--ink-soft);
  font-family: var(--font-mono);
  font-size: 0.8rem;
  padding: 6px 10px;
  border-radius: 6px;
}
.gh-link:hover { color: var(--ink); background: var(--paper-soft); text-decoration: none; }

/* ===================== mobile nav (hidden on desktop) ===================== */

.mobile-nav { display: none; }

.mobile-nav details { border-bottom: 1px solid var(--rule); background: var(--paper-raised); }

.mobile-nav summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  list-style: none;
  cursor: pointer;
  padding: 12px 20px;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--ink);
}
.mobile-nav summary::-webkit-details-marker { display: none; }

.mobile-nav-chevron {
  color: var(--ink-soft);
  transition: transform 150ms ease;
}
.mobile-nav details[open] .mobile-nav-chevron { transform: rotate(180deg); }

.mobile-nav-content {
  padding: 4px 16px 18px;
  max-height: 60vh;
  overflow-y: auto;
  border-top: 1px solid var(--rule);
}

/* ===================== shell / sidebar ===================== */

.shell {
  max-width: var(--max-width);
  margin: 0 auto;
  display: flex;
  align-items: flex-start;
  gap: 56px;
  padding: 0 28px;
}

.sidebar {
  flex: 0 0 var(--sidebar-width);
  width: var(--sidebar-width);
  position: sticky;
  top: 60px;
  height: calc(100vh - 60px);
  padding: 28px 0 48px;
  overflow-y: auto;
  scrollbar-width: thin;
}
.sidebar::-webkit-scrollbar { width: 4px; }
.sidebar::-webkit-scrollbar-thumb { background: var(--rule); border-radius: 10px; }

.nav-top-link {
  display: block;
  margin-bottom: 20px;
  padding: 6px 10px;
  color: var(--ink);
  font-weight: 600;
  font-size: 0.92rem;
  border-radius: 6px;
}
.nav-top-link:hover { background: var(--paper-soft); text-decoration: none; }

.nav-group { margin-bottom: 22px; }

.nav-heading {
  margin: 0 0 5px;
  padding: 0 10px;
  font-family: var(--font-mono);
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.nav-link {
  display: block;
  padding: 6px 10px;
  color: #4f4d47;
  font-size: 0.9rem;
  border-radius: 6px;
  border-left: 2px solid transparent;
}
.nav-link:hover { background: var(--paper-soft); color: var(--ink); text-decoration: none; }
.nav-link.active,
.nav-top-link.active {
  background: var(--source-blue-tint);
  color: var(--source-blue);
  border-left-color: var(--source-blue);
  font-weight: 500;
}

/* ===================== content typography ===================== */

.content {
  flex: 1 1 var(--content-width);
  min-width: 0;
  max-width: var(--content-width);
  padding: 40px 0 90px;
}

.content h1 {
  font-family: var(--font-mono);
  font-size: 1.9rem;
  letter-spacing: -0.02em;
  margin: 0 0 10px;
}

.content h2 {
  font-family: var(--font-mono);
  font-size: 1.3rem;
  letter-spacing: -0.01em;
  margin: 2.3em 0 0.7em;
  padding-top: 0.6em;
  border-top: 1px solid var(--rule);
}
.content h2:first-child { border-top: none; padding-top: 0; margin-top: 0; }

.content h3 {
  font-family: var(--font-mono);
  font-size: 1.05rem;
  margin: 1.8em 0 0.5em;
}

.content p { margin: 0.95em 0; }
.content ul, .content ol { padding-left: 1.4em; }
.content li { margin: 0.4em 0; }

.content > p:first-of-type {
  font-size: 1.08rem;
  color: var(--ink-soft);
}

.content a { text-underline-offset: 2px; }

.content blockquote {
  margin: 1.2em 0;
  padding: 2px 18px;
  border-left: 3px solid var(--source-blue);
  background: var(--source-blue-tint);
}
.content blockquote p { margin: 0.6em 0; }

.content table {
  border-collapse: collapse;
  width: 100%;
  margin: 1.3em 0;
  font-size: 0.9rem;
}
.content th, .content td {
  border: 1px solid var(--rule);
  padding: 8px 10px;
  text-align: left;
  vertical-align: top;
}
.content th {
  font-family: var(--font-mono);
  font-size: 0.76rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--ink-soft);
  background: var(--paper-soft);
}

.content hr {
  border: none;
  border-top: 1px solid var(--rule);
  margin: 2em 0;
}

/* ===================== code ===================== */

.content pre {
  margin: 1.2em 0;
  padding: 16px 18px;
  overflow-x: auto;
  background: var(--paper-raised);
  border: 1px solid var(--rule);
  border-left: 3px solid var(--rule);
  border-radius: 6px;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  line-height: 1.6;
  color: var(--ink);
}

.content pre code {
  display: block;
  padding: 0;
  background: transparent;
  border: 0;
  color: inherit;
  font-family: inherit;
  font-size: inherit;
  line-height: inherit;
}

.content pre:has(code.language-zing) { border-left-color: var(--source-blue); }
.content pre:has(code.language-php)  { border-left-color: var(--compiled-amber); }

.content :not(pre) > code {
  font-family: var(--font-mono);
  font-size: 0.85em;
  padding: 0.14em 0.4em;
  background: var(--paper-soft);
  border: 1px solid var(--rule);
  border-radius: 4px;
  color: #30312f;
}

/* ===================== signature: source -> compiled panes ===================== */

.compile-pair {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 32px minmax(0, 1fr);
  align-items: center;
  gap: 12px;
  margin: 1.7em 0 2.1em;
}

.compile-pane {
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--rule);
  background: var(--paper-raised);
}
.compile-pane .pane-label {
  padding: 7px 14px;
  font-family: var(--font-mono);
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.compile-pane pre { margin: 0; border: none; border-radius: 0; }

.compile-pane.source .pane-label { background: var(--source-blue-tint); color: var(--source-blue); }
.compile-pane.source pre { border-left: 3px solid var(--source-blue); }
.compile-pane.compiled .pane-label { background: var(--compiled-amber-tint); color: var(--compiled-amber); }
.compile-pane.compiled pre { border-left: 3px solid var(--compiled-amber); }

.compile-arrow {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--ink-soft);
  font-family: var(--font-mono);
  font-size: 1.2rem;
}

/* ===================== callouts (for pages like not-yet-implemented) ===================== */

.content .not-implemented {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--compiled-amber);
  background: var(--compiled-amber-tint);
  border-radius: 4px;
  padding: 2px 8px;
  margin-bottom: 0.6em;
}

/* ===================== footer ===================== */

.footer {
  width: min(100%, var(--max-width));
  margin: 0 auto;
  padding: 28px 28px 44px;
  border-top: 1px solid var(--rule);
  color: var(--ink-soft);
  font-size: 0.8rem;
}

/* ===================== tablet ===================== */

@media (max-width: 1000px) {
  .shell { gap: 36px; padding: 0 22px; }
  .sidebar { flex-basis: 210px; width: 210px; }
}

/* ===================== mobile ===================== */

@media (max-width: 760px) {
  .topbar { height: 56px; padding: 0 18px; }
  .tagline { display: none; }

  .mobile-nav { display: block; }
  .sidebar { display: none; }

  .shell {
    display: block;
    width: 100%;
    padding: 0;
  }

  .content { padding: 32px 20px 70px; }
  .content h1 { font-size: 1.65rem; }
  .content h2 { margin-top: 2em; }

  .content pre {
    margin-left: -4px;
    margin-right: -4px;
    padding: 14px 16px;
    font-size: 0.78rem;
  }

  .compile-pair { grid-template-columns: 1fr; }
  .compile-arrow { transform: rotate(90deg); height: 24px; }

  .content table { display: block; overflow-x: auto; white-space: nowrap; }

  .footer { padding: 24px 20px 40px; }
}

@media (max-width: 420px) {
  body { font-size: 15px; }
  .topbar { padding: 0 14px; }
  .content { padding-left: 16px; padding-right: 16px; }
  .content h1 { font-size: 1.5rem; }
  .content pre { font-size: 0.74rem; }
}

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