/*
  Docs site styling. The fixed frosted nav is lifted VERBATIM from
  apps/website/public/index.html so the docs read as one continuous site; the
  rest is a clean, readable docs layout. Dark, to match the marketing chrome.
  Code blocks are highlighted at build time by Shiki (inline styles) — this
  file only frames them. Copied to /docs/docs.css by scripts/docs.ts.
*/
:root {
  --font-display: "Space Grotesk", "Segoe UI", system-ui, sans-serif;
  --font-copy: "IBM Plex Mono", ui-monospace, "SFMono-Regular", monospace;
  /* Palette shared with the landing page (apps/website/public/index.html):
     same ink/dim/line values and the same #ffdd00 accent. */
  --doc-bg: #0b0f14;
  --doc-fg: rgba(255, 255, 255, 0.84);
  --doc-fg-strong: #eef2f6;
  --doc-fg-muted: #9aa7b4;
  --doc-accent: #ffdd00;
  --doc-border: rgba(255, 255, 255, 0.12);
  --doc-surface: rgba(255, 255, 255, 0.04);
  --nav-h: 52px;
  --footer-h: 0px; /* footer removed; kept for padding math */
}

* {
  box-sizing: border-box;
}
html {
  scroll-behavior: smooth;
  scroll-padding-top: calc(var(--nav-h) + 16px);
  /* Solid canvas color: without it the body background propagates to the
     canvas and TILES on pages shorter than the viewport, reading as
     repeating horizontal bands. */
  background: var(--doc-bg);
}
body {
  margin: 0;
  min-height: 100vh;
  /* The landing page's soft blue wash at the top, for one continuous site. */
  background:
    radial-gradient(90% 60% at 50% -10%, rgba(47, 111, 222, 0.14) 0%, rgba(47, 111, 222, 0) 60%)
      no-repeat,
    var(--doc-bg);
  color: var(--doc-fg);
  font-family: var(--font-copy);
  font-size: 15px;
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
}

/* ── Top nav — lifted from index.html ── */
.nav {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--nav-h);
  padding: 0 clamp(1rem, 4vw, 2.5rem);
  background: rgba(8, 12, 16, 0.42);
  backdrop-filter: blur(10px) saturate(1.2);
  -webkit-backdrop-filter: blur(10px) saturate(1.2);
  border-bottom: 1px solid var(--doc-border);
  font-family: var(--font-display);
  color: #fff;
}
.nav-brand {
  display: inline-flex;
  flex-direction: column;
  line-height: 1.04;
  color: #fff;
  text-decoration: none;
}
.nav-brand-name {
  font-weight: 700;
  letter-spacing: 0.03em;
  font-size: 1.1rem;
}
.nav-brand-kana {
  margin-top: 2px;
  font-size: 0.52rem;
  letter-spacing: 0.28em;
  font-weight: 500;
  color: rgba(255, 255, 255, 0.55);
}
.nav-links {
  display: flex;
  gap: clamp(0.9rem, 2.6vw, 1.9rem);
}
.nav-links a {
  color: rgba(255, 255, 255, 0.82);
  text-decoration: none;
  font-size: 0.92rem;
  font-weight: 500;
  letter-spacing: 0.01em;
  font-family: var(--font-display);
}
.nav-links a:hover,
.nav-links a[aria-current="page"] {
  color: #fff;
}

/* The X link sits with the text links but renders as an icon; align it
   optically with the labels around it. */
.nav-x {
  display: inline-flex;
  align-items: center;
  color: rgba(255, 255, 255, 0.82);
  transition: color 120ms ease;
}
.nav-x:hover {
  color: #fff;
}

/* ── Layout: sidebar | article | on-this-page ── */
.docs-shell {
  max-width: 1240px;
  margin: 0 auto;
  padding: calc(var(--nav-h) + 24px) clamp(1rem, 4vw, 2.5rem) calc(var(--footer-h) + 64px);
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr) 200px;
  gap: clamp(1.5rem, 4vw, 3.5rem);
  align-items: start;
}
.changelog-shell {
  grid-template-columns: 220px minmax(0, 1fr);
}
/* Legal pages (/terms, /refund): single readable prose column, no sidebar. */
.legal-shell {
  max-width: 820px;
  grid-template-columns: minmax(0, 1fr);
}
.legal-shell .docs-sidebar {
  display: none;
}

/* Sidebar */
.docs-sidebar,
.docs-toc {
  position: sticky;
  top: calc(var(--nav-h) + 24px);
  align-self: start;
  font-size: 0.86rem;
  /* A sticky column taller than the viewport is otherwise unreachable past
     the fold — cap it to the viewport and let it scroll on its own. */
  max-height: calc(100vh - var(--nav-h) - 40px);
  overflow-y: auto;
  overscroll-behavior: contain;
  padding-bottom: 1rem;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.22) transparent;
}
.docs-sidebar nav {
  display: flex;
  flex-direction: column;
  gap: 1.4rem;
}
.docs-sidebar .sb-section-title {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 0.7rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--doc-fg-muted);
  margin: 0 0 0.5rem;
}
.docs-sidebar ul {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}
.docs-sidebar a {
  display: block;
  padding: 0.28rem 0.6rem;
  border-radius: 6px;
  color: var(--doc-fg-muted);
  text-decoration: none;
  border-left: 2px solid transparent;
}
.docs-sidebar a:hover {
  color: var(--doc-fg-strong);
  background: var(--doc-surface);
}
.docs-sidebar a[aria-current="page"] {
  color: var(--doc-accent);
  border-left-color: var(--doc-accent);
  background: var(--doc-surface);
}

/* On this page */
.docs-toc .toc-title {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 0.7rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--doc-fg-muted);
  margin: 0 0 0.6rem;
}
.docs-toc ul {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  border-left: 1px solid var(--doc-border);
}
.docs-toc a {
  display: block;
  padding-left: 0.8rem;
  color: var(--doc-fg-muted);
  text-decoration: none;
  font-size: 0.82rem;
  line-height: 1.4;
}
.docs-toc a:hover {
  color: var(--doc-fg-strong);
}
.docs-toc a.toc-h3 {
  padding-left: 1.6rem;
  font-size: 0.78rem;
}

/* ── Article prose ── */
.docs-article {
  min-width: 0;
  max-width: 76ch;
}
.docs-article > :first-child {
  margin-top: 0;
}
.docs-article img {
  display: block;
  max-width: 100%;
  height: auto;
  margin: 1.8rem 0;
  border: 1px solid var(--doc-border);
  border-radius: 10px;
}
.docs-article h1 {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: clamp(1.9rem, 4vw, 2.5rem);
  line-height: 1.12;
  letter-spacing: -0.02em;
  color: var(--doc-fg-strong);
  margin: 0 0 1.4rem;
}
.docs-article h2 {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.45rem;
  letter-spacing: -0.01em;
  color: var(--doc-fg-strong);
  margin: 2.6rem 0 1rem;
  padding-top: 0.4rem;
  border-top: 1px solid var(--doc-border);
}
.docs-article h3 {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.12rem;
  color: var(--doc-fg-strong);
  margin: 1.9rem 0 0.7rem;
}
.docs-article h2 a.anchor,
.docs-article h3 a.anchor {
  color: var(--doc-fg-muted);
  text-decoration: none;
  margin-left: 0.4rem;
  opacity: 0;
  font-weight: 400;
}
.docs-article h2:hover a.anchor,
.docs-article h3:hover a.anchor {
  opacity: 1;
}
.docs-article p,
.docs-article li {
  color: var(--doc-fg);
}
.docs-article a {
  color: var(--doc-accent);
  text-decoration: none;
}
.docs-article a:hover {
  text-decoration: underline;
}
.docs-article strong {
  color: var(--doc-fg-strong);
  font-weight: 600;
}
.docs-article ul,
.docs-article ol {
  padding-left: 1.3rem;
}
.docs-article li {
  margin: 0.3rem 0;
}
.docs-article kbd {
  font-family: var(--font-copy);
  font-size: 0.82em;
  background: var(--doc-surface);
  border: 1px solid var(--doc-border);
  border-bottom-width: 2px;
  border-radius: 5px;
  padding: 0.1em 0.45em;
  color: var(--doc-fg-strong);
  white-space: nowrap;
}
.docs-article :not(pre) > code {
  font-family: var(--font-copy);
  font-size: 0.85em;
  background: var(--doc-surface);
  border: 1px solid var(--doc-border);
  border-radius: 5px;
  padding: 0.1em 0.4em;
  /* Terminal green, matching the landing page's path chips. */
  color: #d7f7d0;
}
.docs-article pre {
  margin: 1.2rem 0;
  padding: 1rem 1.1rem;
  border: 1px solid var(--doc-border);
  border-radius: 10px;
  overflow-x: auto;
  font-size: 0.84rem;
  line-height: 1.6;
  /* Shiki sets its own background via the theme. */
}
.docs-article pre code {
  font-family: var(--font-copy);
}
.docs-article blockquote {
  margin: 1.2rem 0;
  padding: 0.6rem 1.1rem;
  border-left: 3px solid var(--doc-accent);
  background: var(--doc-surface);
  border-radius: 0 8px 8px 0;
  color: var(--doc-fg);
}
.docs-article blockquote p {
  margin: 0.3rem 0;
}
.docs-article table {
  width: 100%;
  border-collapse: collapse;
  margin: 1.3rem 0;
  font-size: 0.86rem;
}
.docs-article th,
.docs-article td {
  text-align: left;
  padding: 0.5rem 0.8rem;
  border: 1px solid var(--doc-border);
  vertical-align: top;
}
.docs-article th {
  font-family: var(--font-display);
  color: var(--doc-fg-strong);
  background: var(--doc-surface);
}
.docs-article hr {
  border: none;
  border-top: 1px solid var(--doc-border);
  margin: 2.4rem 0;
}

/* Section-card grid on the docs landing (authored as raw HTML in index.md). */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 1rem;
  margin: 1.6rem 0;
}
.card-grid a {
  display: block;
  padding: 1.1rem 1.2rem;
  border: 1px solid var(--doc-border);
  border-radius: 12px;
  background: var(--doc-surface);
  text-decoration: none;
}
.card-grid a:hover {
  border-color: var(--doc-accent);
}
.card-grid .card-title {
  font-family: var(--font-display);
  font-weight: 700;
  color: var(--doc-fg-strong);
  display: block;
  margin-bottom: 0.3rem;
}
.card-grid .card-desc {
  color: var(--doc-fg-muted);
  font-size: 0.85rem;
}

/* ── Blog (single prose column via .legal-shell; these are the extras) ── */
.post-meta {
  margin: -0.9rem 0 1.6rem;
  font-size: 0.8rem;
  letter-spacing: 0.06em;
  color: var(--doc-fg-muted);
}
.post-list {
  list-style: none;
  margin: 1.6rem 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}
.post-list a {
  display: block;
  padding: 1.1rem 1.2rem;
  border: 1px solid var(--doc-border);
  border-radius: 12px;
  background: var(--doc-surface);
  text-decoration: none;
}
.post-list a:hover {
  border-color: var(--doc-accent);
  text-decoration: none;
}
.post-list .post-title {
  display: block;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.15rem;
  color: var(--doc-fg-strong);
}
.post-list .post-meta {
  display: block;
  margin: 0.25rem 0 0.45rem;
}
.post-list .post-desc {
  display: block;
  color: var(--doc-fg);
  font-size: 0.88rem;
  line-height: 1.6;
}
/* Two screenshots side by side inside a post. */
.shot-pair {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin: 1.8rem 0;
}
.shot-pair img {
  margin: 0;
  max-width: 100%;
  height: auto;
  border: 1px solid var(--doc-border);
  border-radius: 10px;
}
.engine-pair figure {
  min-width: 0;
  margin: 0;
}
.engine-pair figcaption {
  margin-top: 0.55rem;
  color: var(--doc-fg-muted);
  font-size: 0.78rem;
  text-align: center;
}
.architecture-map {
  margin: 1.8rem 0;
  overflow-x: auto;
  border-radius: 10px;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.22) transparent;
}
.architecture-map img {
  width: 100%;
  margin: 0;
}
@media (max-width: 640px) {
  .shot-pair {
    grid-template-columns: 1fr;
  }
  .architecture-map img {
    width: 700px;
    max-width: none;
  }
}

/* ── Responsive ── */
@media (max-width: 1080px) {
  .docs-shell {
    grid-template-columns: 200px minmax(0, 1fr);
  }
  .docs-toc {
    display: none;
  }
}
@media (max-width: 760px) {
  .docs-shell {
    grid-template-columns: minmax(0, 1fr);
  }
  .docs-sidebar {
    position: static;
    max-height: none;
    overflow-y: visible;
    border-bottom: 1px solid var(--doc-border);
    padding-bottom: 1rem;
    margin-bottom: 0.5rem;
  }
  .nav-links {
    gap: 0.9rem;
  }
}
