/* ============================================================
   Silica documentation site

   Plain .css, not .scss, on purpose. GitHub Pages pins an old
   Ruby Sass that evaluates arithmetic inside clamp() and min(),
   and fails the build on "Incompatible units: 'vw' and 'rem'".
   A .css file is copied verbatim, so modern CSS is safe here.
   Do not rename this to .scss.

   Layout: a fixed ~70ch measure for prose with a sticky table of
   contents in the left margin, and code/tables allowed to break
   out wider than the measure.
   ============================================================ */

/* ---- tokens: light ----
   The palette follows the browser's prefers-color-scheme setting and nothing else;
   there is no in-page theme switch. color-scheme lets form controls and scrollbars match. */
:root {
  color-scheme: light dark;
  --bg:        #f7f8f9;
  --surface:   #eef1f3;
  --ink:       #171d23;
  --muted:     #59656f;
  --rule:      #dde2e6;
  --accent:    #1a6e7a;
  --accent-2:  #135861;
  --danger:    #a6552b;
  --code-bg:   #eef1f3;
  --code-ink:  #1f272e;
  --selection: #cfe6e8;

  --measure:   42rem;
  --rail:      13.5rem;
  --gutter:    3.5rem;
  --shell:     72rem;

  --font-body:    "Source Serif 4", Georgia, "Times New Roman", serif;
  --font-ui:      "IBM Plex Sans", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-mono:    "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

/* ---- tokens: dark, when the browser asks for it ---- */
@media (prefers-color-scheme: dark) {
  :root {
    --bg:        #101519;
    --surface:   #182027;
    --ink:       #e2e7ea;
    --muted:     #93a2ad;
    --rule:      #29333a;
    --accent:    #58b8c1;
    --accent-2:  #7fcdd4;
    --danger:    #d9926a;
    --code-bg:   #0a0e11;
    --code-ink:  #d7dee3;
    --selection: #1d4b52;
  }
}

* { box-sizing: border-box; }

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

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  /* Fluid: 16.5px on a phone up to 17.5px on a desktop. */
  font-size: clamp(1.03rem, 0.99rem + 0.18vw, 1.095rem);
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

::selection { background: var(--selection); }

.skip-link {
  position: absolute; left: -9999px; top: 0; z-index: 100;
  background: var(--accent); color: #fff;
  padding: .6rem 1rem; border-radius: 0 0 6px 0;
  font-family: var(--font-ui); font-size: .85rem;
}
.skip-link:focus { left: 0; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 2px;
}

/* ============================================================
   Site header
   ============================================================ */
.site-header {
  border-bottom: 1px solid var(--rule);
  background: var(--bg);
  position: sticky; top: 0; z-index: 30;
}
.site-header-in {
  max-width: var(--shell); margin: 0 auto;
  padding: .8rem clamp(1rem, 4vw, 2.5rem);
  display: flex; align-items: center; gap: 1.25rem; flex-wrap: wrap;
}
.site-logo {
  font-family: var(--font-ui); font-weight: 600;
  font-size: 1.05rem; letter-spacing: -.015em;
  color: var(--ink); text-decoration: none;
}
.site-nav {
  display: flex; gap: 1.2rem; flex-wrap: wrap; margin-left: auto;
  font-family: var(--font-ui); font-size: .85rem;
}
.site-nav a {
  color: var(--muted); text-decoration: none;
  padding-bottom: 1px; border-bottom: 1px solid transparent;
}
.site-nav a:hover { color: var(--accent); }
.site-nav a[aria-current="page"] {
  color: var(--ink); border-bottom-color: var(--accent);
}


/* ============================================================
   Shell: sticky rail + bleed-capable content column
   ============================================================ */
.site-main {
  max-width: var(--shell); margin: 0 auto;
  padding: 0 clamp(1rem, 4vw, 2.5rem);
}
.site-layout {
  display: grid;
  grid-template-columns: var(--rail) minmax(0, 1fr);
  gap: 0 var(--gutter);
  align-items: start;
  padding: 2.5rem 0 4rem;
}
/* The content always takes the main column. Without this, a page whose rail stays hidden
   (fewer than three H2 sections, see site.js) puts its content in the narrow rail column
   and leaves the main column empty. */
.site-layout > .content { grid-column: 2; }

/* The content column is a grid whose middle track is the measure.
   Anything given `grid-column: full` escapes it. */
.content {
  display: grid;
  grid-template-columns:
    [full-start] 0
    [content-start] min(var(--measure), 100%) [content-end]
    minmax(0, 1fr) [full-end];
  min-width: 0;
}
.content > * { grid-column: content; min-width: 0; }

/* Wide things break the measure. */
.content > table,
.content > .code-block,
.content > div.highlighter-rouge,
.content > pre,
.content > .cards,
.content > .masthead { grid-column: full; }

/* ---- table of contents rail ---- */
.toc {
  position: sticky; top: 4.5rem;
  font-family: var(--font-ui);
  font-size: .84rem; line-height: 1.45;
  border-left: 2px solid var(--rule);
  padding-left: 1rem;
  max-height: calc(100vh - 6.5rem);
  overflow-y: auto;
}
.toc[hidden] { display: none; }
.toc-title {
  font-size: .66rem; text-transform: uppercase; letter-spacing: .1em;
  color: var(--muted); font-weight: 600; margin: 0 0 .75rem;
}
.toc-nav { display: grid; gap: .5rem; }
.toc-nav a {
  color: var(--muted); text-decoration: none; display: block;
  transition: color .13s ease;
}
.toc-nav a:hover { color: var(--accent); }
.toc-nav a.is-current {
  color: var(--accent); font-weight: 500;
  box-shadow: -1rem 0 0 -.94rem var(--accent);
}
.toc-nav a.lvl-3 { padding-left: .8rem; font-size: .8rem; }

/* ============================================================
   Prose
   ============================================================ */
.content h1, .content h2, .content h3,
.content h4, .content h5, .content h6 {
  font-family: var(--font-ui);
  color: var(--ink);
  text-wrap: balance;
  line-height: 1.25;
  scroll-margin-top: 4.5rem;
}
.content h1 {
  font-size: clamp(1.85rem, 1.55rem + 1.3vw, 2.2rem);
  font-weight: 600; letter-spacing: -.022em;
  margin: 0 0 1rem;
}
.content h2 {
  font-size: clamp(1.3rem, 1.18rem + 0.5vw, 1.45rem);
  font-weight: 600; letter-spacing: -.014em;
  margin: 2.75rem 0 .9rem;
  padding-top: 1.4rem;
  border-top: 1px solid var(--rule);
}
.content h3 { font-size: 1.12rem; font-weight: 600; margin: 2rem 0 .6rem; }
.content h4 { font-size: .96rem; font-weight: 600; margin: 1.7rem 0 .5rem; color: var(--muted); }
.content h5, .content h6 { font-size: .88rem; font-weight: 600; margin: 1.4rem 0 .45rem; color: var(--muted); }

.content p { margin: 0 0 1.05em; }
.content ul, .content ol { margin: 0 0 1.2em; padding-left: 1.3rem; }
.content li { margin-bottom: .5em; }
.content li > ul, .content li > ol { margin: .5em 0 0; }

.content a { color: var(--accent); text-underline-offset: .16em; }
.content a:hover { color: var(--accent-2); }

.content blockquote {
  margin: 1.6rem 0; padding: .2rem 0 .2rem 1.1rem;
  border-left: 3px solid var(--rule); color: var(--muted);
}
.content hr {
  border: 0; border-top: 1px solid var(--rule);
  margin: 2.5rem 0;
}
.content img { max-width: 100%; height: auto; }
.content strong { font-weight: 600; }

/* Anchor links added to headings by site.js */
.heading-anchor {
  color: var(--muted); text-decoration: none;
  margin-left: .4rem; opacity: 0;
  font-weight: 400; font-size: .8em;
  transition: opacity .13s ease;
}
h2:hover > .heading-anchor,
h3:hover > .heading-anchor,
.heading-anchor:focus { opacity: 1; }

/* ============================================================
   Masthead (index)
   ============================================================ */
.content .masthead {
  display: flex; align-items: center; gap: 1.5rem;
  margin: 0 0 1.75rem;
}
.content .masthead img {
  flex: 0 0 auto;
  width: 96px; height: 96px; max-width: 96px;
  margin: 0; border-radius: 16px;
}
.content .masthead-tagline {
  font-family: var(--font-ui);
  font-size: clamp(1.05rem, .95rem + .5vw, 1.22rem);
  font-weight: 500; line-height: 1.4; letter-spacing: -.01em;
  min-width: 0; overflow-wrap: break-word;
}

/* ============================================================
   Landing cards
   ============================================================ */
.cards {
  display: grid; gap: .8rem;
  grid-template-columns: repeat(auto-fit, minmax(15.5rem, 1fr));
  margin: 0 0 2.5rem;
  font-family: var(--font-ui);
}
.card {
  display: grid; gap: .25rem; align-content: start;
  border: 1px solid var(--rule); border-radius: 9px;
  padding: 1rem 1.1rem;
  text-decoration: none; color: inherit;
  transition: border-color .14s ease, transform .14s ease;
}
.card:hover { border-color: var(--accent); transform: translateY(-1px); }
.card b {
  font-size: .94rem; font-weight: 600; letter-spacing: -.008em;
  color: var(--ink);
}
.card span { font-size: .82rem; color: var(--muted); line-height: 1.45; }

/* ============================================================
   Code
   ============================================================ */
.content pre,
.content code { font-family: var(--font-mono); }

/* Kramdown tags INLINE code spans as `language-plaintext highlighter-rouge`
   too, so code styling must be anchored on the direct child of .content,
   never on a bare .highlighter-rouge descendant. */
.content :not(pre) > code {
  background: var(--surface);
  border: 0;
  padding: .1em .35em;
  border-radius: 3px;
  font-size: .86em;
}

/* Silica has no Rouge lexer, so kramdown emits a bare
   <pre><code class="language-silica">, with no wrapper div. site.js wraps
   that in .code-block to add the language label; both shapes look alike.
   (div.highlighter-rouge is here for the day a lexer exists.) */
.content > pre,
.content > .code-block,
.content > div.highlighter-rouge {
  background: var(--code-bg);
  border: 1px solid var(--rule);
  border-radius: 9px;
  margin: 0 0 1.6rem;
  overflow: hidden;
}
.content > .code-block > pre,
.content > div.highlighter-rouge pre,
.content > div.highlighter-rouge .highlight {
  border: 0;
  border-radius: 0;
  margin: 0;
  background: none;
}
.content pre {
  padding: 1.1rem 1.25rem;
  overflow-x: auto;
  color: var(--code-ink);
  font-size: .845rem;
  line-height: 1.65;
}
.content pre code {
  background: none; border: 0; padding: 0; border-radius: 0;
  font-size: inherit; color: inherit;
}

/* Language chip added by site.js */
.code-label {
  font-family: var(--font-mono);
  font-size: .64rem; text-transform: uppercase; letter-spacing: .09em;
  color: var(--muted);
  padding: .5rem .95rem;
  border-bottom: 1px solid var(--rule);
  background: var(--surface);
}

/* ============================================================
   Tables
   ============================================================ */
.content table {
  border-collapse: collapse;
  width: 100%;
  display: block;
  overflow-x: auto;
  font-family: var(--font-ui);
  font-size: .86rem;
  line-height: 1.5;
  margin: 0 0 1.6rem;
}
.content th, .content td {
  text-align: left;
  padding: .58rem .85rem;
  border-bottom: 1px solid var(--rule);
  vertical-align: top;
}
.content th {
  font-size: .67rem; text-transform: uppercase; letter-spacing: .08em;
  color: var(--muted); font-weight: 600;
  border-bottom: 1px solid var(--rule);
}
.content tbody tr:last-child td { border-bottom: 0; }

/* ============================================================
   Callouts
   ============================================================ */
.motto {
  display: flex; align-items: center; gap: .8rem;
  margin: 2rem 0; padding: 1rem 1.2rem;
  background: var(--surface);
  border-left: 3px solid var(--accent);
  border-radius: 0 6px 6px 0;
  font-family: var(--font-ui); font-size: .96rem; font-weight: 500;
}
.motto img { height: 1.6em; width: auto; flex-shrink: 0; margin: 0; }
.motto p { margin: 0; }

.see { font-family: var(--font-ui); font-size: .86rem; color: var(--muted); }
.see a { color: var(--accent); }

/* ============================================================
   Footer
   ============================================================ */
.site-footer {
  border-top: 1px solid var(--rule);
  background: var(--surface);
  margin-top: 2rem;
}
.site-footer-in {
  max-width: var(--shell); margin: 0 auto;
  padding: 2rem clamp(1rem, 4vw, 2.5rem);
  display: flex; flex-wrap: wrap; gap: .6rem 2rem;
  align-items: baseline; justify-content: space-between;
  font-family: var(--font-ui);
}
.footer-motto { margin: 0; font-size: .88rem; font-weight: 500; color: var(--ink); }
.footer-meta  { margin: 0; font-size: .82rem; color: var(--muted); }
.footer-meta a { color: var(--muted); }
.footer-meta a:hover { color: var(--accent); }

/* ============================================================
   Narrow screens: the rail folds to the top of the page
   ============================================================ */
@media (max-width: 62rem) {
  .site-layout {
    display: block;
    padding-top: 2rem;
  }
  .toc {
    position: static;
    max-height: none;
    overflow: visible;
    border-left: 0;
    padding: 1rem 1.15rem;
    background: var(--surface);
    border-radius: 8px;
    margin: 0 0 2.25rem;
  }
  .toc-nav { gap: .35rem; }
  .toc-nav a.is-current { box-shadow: none; }
  .content .masthead { gap: 1.1rem; }
  .content .masthead img { width: 72px; height: 72px; max-width: 72px; }
}

@media (max-width: 34rem) {
  .site-nav { gap: .85rem; font-size: .8rem; }
  .content .masthead { flex-direction: column; align-items: flex-start; }
}
