/* ============================================================================
   moonorm · site styles — "Mirror Seam · Light/Dark Twin"
   The seam is the signature; the two worlds are its halves.
   Radius is 0. Structure is line, not fill.
   ========================================================================== */

/* ---- top bar (identical on every page) ---- */
.topbar {
  position: sticky; top: 0; z-index: 50;
  display: flex; align-items: center; gap: var(--s3);
  padding: var(--s2) var(--s3);
  background: color-mix(in srgb, var(--paper) 88%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--hair);
}
.brand { display: flex; align-items: center; gap: var(--s1); font-family: var(--font-serif); font-weight: 600; font-size: 19px; color: var(--ink); border: 0; }
.brand .glyph { width: 22px; height: 22px; }
.nav { display: flex; gap: var(--s3); margin-left: auto; font-family: var(--font-mono); font-size: 13px; }
.nav a { color: var(--ink-soft); border: 0; padding: var(--s1) 0; }
.nav a:hover, .nav a[aria-current="page"] { color: var(--ink); box-shadow: inset 0 -2px 0 var(--pointer); }
.nav a[aria-current="page"] { color: var(--ink); }
/* the theme twin, as a two-position switch — no icon, just the two lights */
.theme-toggle { display: flex; border: 1px solid var(--hair-strong); }
.theme-toggle button {
  border: 0; border-left: 1px solid var(--hair-strong); background: transparent;
  color: var(--ink-faint); font-family: var(--font-mono); font-size: 11px;
  letter-spacing: 0.06em; padding: 5px 9px; cursor: pointer;
  transition: color var(--t1) var(--ease), background-color var(--t1) var(--ease);
}
.theme-toggle button:first-child { border-left: 0; }
.theme-toggle button:hover { color: var(--ink); }
.theme-toggle button.on { background: var(--ink); color: var(--paper); }

/* ---- hero / the seam ----
   THE SEAM is a bound ledger: two worlds in two columns, one gutter between
   them. A field is one row, so its two halves are aligned by the grid — never
   by measurement. The gutter is the seam; each row is stitched across it. */
.hero { padding: var(--s6) 0 var(--s5); }
.hero .eyebrow { margin-bottom: var(--s2); }
.hero .lede { font-family: var(--font-serif); font-size: clamp(18px, 2.2vw, 26px); line-height: 1.4; max-width: 70ch; color: var(--ink); margin: var(--s3) 0 var(--s5); }
.hero .lede b { color: var(--moonbit); font-weight: 600; }
.hero .lede i {
  font-style: italic; font-weight: 500; color: var(--ink);
  text-decoration: underline; text-decoration-color: var(--hair-strong);
  text-decoration-thickness: 1px; text-underline-offset: 4px;
}
.hero-note { margin: var(--s3) 0 0; font-size: 13px; max-width: 78ch; }

/* a documentation page opens tighter than the front page */
.hero.compact { padding-bottom: var(--s2); }
.hero.compact .lede { margin-bottom: var(--s1); }

/* the plate: a narrower measure than the prose, so the cells stay dense and
   the gutter reads as a binding rather than a void */
.seam-stage { --gutter: 96px; max-width: 760px; border: 1px solid var(--hair-strong); background: var(--paper); }

/* toolbar strip: which dialect the right column is speaking */
.seam-bar {
  display: flex; align-items: center; gap: var(--s2);
  padding: 6px var(--s2); background: var(--paper-2);
  border-bottom: 1px solid var(--hair-strong);
}
.seam-file { font-family: var(--font-mono); font-size: 11px; letter-spacing: 0.06em; color: var(--ink-faint); }
.seg { display: flex; margin-left: auto; border: 1px solid var(--hair-strong); }
.seg button {
  border: 0; border-left: 1px solid var(--hair-strong); background: transparent;
  color: var(--ink-soft); font-family: var(--font-mono); font-size: 11px;
  letter-spacing: 0.04em; padding: 4px 10px; cursor: pointer;
  transition: color var(--t1) var(--ease), background-color var(--t1) var(--ease);
}
.seg button:first-child { border-left: 0; }
.seg button:hover { color: var(--ink); }
.seg button.on { background: var(--ink); color: var(--paper); }

/* column headings */
.ledger-head {
  display: grid; grid-template-columns: minmax(0, 1fr) var(--gutter) minmax(0, 1fr);
  border-bottom: 1px solid var(--hair);
}
.ledger-head .hd { font-family: var(--font-mono); font-size: 10.5px; letter-spacing: 0.18em; text-transform: uppercase; padding: 10px var(--s2); }
.ledger-head .hd.left { color: var(--moonbit); text-align: right; }
.ledger-head .hd.right { color: var(--relation); }

/* rows */
.ledger-box { position: relative; }
.ledger { display: grid; grid-template-columns: minmax(0, 1fr) var(--gutter) minmax(0, 1fr); }
.lrow { display: contents; }
.cell {
  display: flex; flex-wrap: wrap; align-items: baseline; gap: 0 8px;
  padding: 12px var(--s2); margin: 0;
  font-family: var(--font-mono); font-size: 13px; line-height: 1.5;
  border-bottom: 1px solid var(--hair);
  overflow-wrap: anywhere; cursor: default;
  transition: background-color var(--t1) var(--ease);
}
.lrow:last-child .cell { border-bottom: 0; }
.cell .col { font-weight: 500; }
.cell .typ { color: var(--ink); }
.cell .flag { color: var(--ink-faint); font-size: 11px; letter-spacing: 0.03em; }
/* both halves point at the seam: left column right-aligned, right column
   left-aligned, so the two worlds meet in the gutter instead of drifting apart */
.cell.left { justify-content: flex-end; }
.cell.left .col { color: var(--moonbit); }
.cell.left .typ { color: var(--ink-soft); }
.cell.right .col { color: var(--relation); }
.cell.sel { background: color-mix(in srgb, var(--mapped) 10%, transparent); }
.cell.sel.bad { background: color-mix(in srgb, var(--broken) 12%, transparent); }
.cell.bad .typ { color: var(--broken); }

/* the seam: a channel with one thread crossing it per row */
.spine {
  position: absolute; top: 0; bottom: 0;
  left: calc(50% - var(--gutter) / 2); width: var(--gutter);
  border-left: 1px solid var(--hair-strong); border-right: 1px solid var(--hair-strong);
  background: var(--paper-2); overflow: hidden; pointer-events: none; z-index: 0;
}
.spine-glow {
  position: absolute; left: 50%; width: 2px; height: 34px; margin-left: -1px;
  background: linear-gradient(to bottom, transparent, var(--mapped) 60%, transparent);
  box-shadow: 0 0 12px color-mix(in srgb, var(--mapped) 45%, transparent);
  animation: seam-travel 3.2s linear infinite;
}
@keyframes seam-travel {
  0%   { top: -28px; opacity: 0; }
  12%  { opacity: 0.9; }
  88%  { opacity: 0.9; }
  100% { top: 100%; opacity: 0; }
}

/* one stitch per field: two end ticks and a thread across the channel */
.suture {
  position: relative; z-index: 1;
  display: flex; align-items: center;
}
.suture::before, .suture::after {
  content: ""; position: absolute; top: 50%; width: 1px; height: 11px;
  margin-top: -6px; background: var(--hair-strong);
}
.suture::before { left: 9px; }
.suture::after { right: 9px; }
/* at rest the thread is a row of stitches; it goes solid the moment a
   mapping is locked, and tears when the types disagree */
.suture i {
  display: block; width: 100%; height: 2px;
  background: repeating-linear-gradient(
    to right,
    color-mix(in srgb, var(--ink) 42%, transparent) 0 6px,
    transparent 6px 11px);
  transition: background-color var(--t2) var(--ease);
}
.suture.lit i { background: var(--mapped); box-shadow: 0 0 10px color-mix(in srgb, var(--mapped) 60%, transparent); }
.suture.bad i {
  background: repeating-linear-gradient(to right, var(--broken) 0 4px, transparent 4px 14px);
  box-shadow: none;
}

/* compile diagnostic strip */
.diagnostic {
  max-width: 760px;
  margin-top: var(--s3); font-family: var(--font-mono); font-size: 13px;
  border: 1px solid var(--hair); background: var(--paper-2); padding: var(--s2) var(--s3);
  display: flex; align-items: center; gap: var(--s2);
}
.diagnostic .badge { font-weight: 700; letter-spacing: 0.04em; }
.diagnostic.ok .badge { color: var(--mapped); }
.diagnostic.err { border-color: color-mix(in srgb, var(--broken) 50%, var(--hair)); }
.diagnostic.err .badge { color: var(--broken); }
.diagnostic .msg { color: var(--ink-soft); overflow-wrap: anywhere; }

/* generated statement */
.gen { max-width: 760px; margin: var(--s2) 0 0; }
.gen-cap {
  display: flex; justify-content: space-between; gap: var(--s2);
  font-family: var(--font-mono); font-size: 10.5px; letter-spacing: 0.16em;
  text-transform: uppercase; color: var(--ink-faint);
  padding: 0 0 6px;
}
.gen-sql {
  margin: 0; font-family: var(--font-mono); font-size: 13px; line-height: 1.7;
  border: 1px solid var(--hair); border-left: 3px solid var(--mapped); background: var(--paper-2);
  padding: var(--s2) var(--s3); color: var(--ink); white-space: pre; overflow: auto;
}
.gen-sql.err { border-left-color: var(--broken); color: var(--broken); }
/* the SQL side keeps its ochre: keywords in it, bound values in the pointer's
   orange, literals in the colour of a mapping that holds */
.gen-sql .sql-kw { color: var(--relation); font-weight: 600; }
.gen-sql .sql-arg { color: var(--pointer); }
.gen-sql .sql-str { color: var(--mapped); }

/* ---- feature cards (the four acts) ---- */
.acts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1px; background: var(--hair); border: 1px solid var(--hair); }
.act { background: var(--paper); padding: var(--s4); }
.act .no { font-family: var(--font-mono); font-size: 13px; color: var(--pointer); letter-spacing: 0.1em; }
.act .act-body { color: var(--ink-soft); font-size: 15px; }
.act .act-body code.inline { color: var(--ink); }

/* ---- type-mapping table: the MoonBit column is the type side (indigo);
        every dialect column is the relation side (ochre). ---- */
.map-table td, .map-table th { font-family: var(--font-mono); font-size: 13px; }
.map-table th { font-size: 11px; letter-spacing: 0.14em; }
.map-table th:first-child, .map-table td:first-child { color: var(--moonbit); }
.map-table th:nth-child(2), .map-table td:nth-child(2),
.map-table th:nth-child(3), .map-table td:nth-child(3),
.map-table th:nth-child(4), .map-table td:nth-child(4) { color: var(--relation); }
.map-table th:last-child, .map-table td:last-child { color: var(--ink-faint); text-align: right; }
.map-table tr.broken td { color: var(--broken); }
.map-table tr.broken td:last-child { text-align: right; }
.map-table tr.broken td:first-child::after { content: " \2717"; color: var(--broken); }

/* ---- code ⟷ SQL side-by-side ---- */
.duo { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1px; background: var(--hair); border: 1px solid var(--hair); }
.duo > div { background: var(--paper-2); padding: var(--s1); }
.duo .cap { font-family: var(--font-mono); font-size: 11px; letter-spacing: 0.12em; text-transform: uppercase; padding: var(--s1) var(--s2); color: var(--ink-faint); }

/* ---- spec status bar ---- */
.statusbar { display: flex; flex-wrap: wrap; gap: var(--s3); font-family: var(--font-mono); font-size: 12px; color: var(--ink-soft); border: 1px solid var(--hair); background: var(--paper-2); padding: var(--s2) var(--s3); }
.statusbar b { color: var(--ink); font-weight: 600; }

/* ---- CTA ---- */
.cta { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s3); padding: var(--s5) 0; }
.btn { font-family: var(--font-mono); font-size: 14px; padding: var(--s2) var(--s3); border: 1px solid var(--ink); color: var(--ink); background: transparent; cursor: pointer; }
.btn:hover { background: var(--ink); color: var(--paper); }
.btn.primary { border-color: var(--pointer); color: var(--pointer); }
.btn.primary:hover { background: var(--pointer); color: var(--paper); }

/* ---- API reference: one entry per declaration, signature then prose ---- */
.section.first { border-top: 0; padding-top: 0; }
.section.first h2 { margin-top: var(--s2); }
.section h2 + h3 { margin-top: var(--s4); }
.section h3 .count {
  font-family: var(--font-mono); font-size: 12px; font-weight: 400;
  color: var(--ink-faint); letter-spacing: 0.04em; margin-left: 6px;
}
/* a signature is a line of code: it gets the full measure, and the prose that
   explains it sits underneath rather than squeezing it into a column */
.entry {
  padding: 14px 0 18px; border-top: 1px solid var(--hair);
}
.entry:last-child { border-bottom: 1px solid var(--hair); }
.entry .signature {
  margin: 0; border: 0; background: transparent; padding: 0;
  font-family: var(--font-mono); font-size: 12.5px; line-height: 1.6;
  color: var(--ink); overflow-x: auto; white-space: pre;
}
.entry .doc { color: var(--ink-soft); font-size: 14px; line-height: 1.65; max-width: 82ch; margin-top: 6px; }
.entry .doc p { margin: 0 0 8px; }
.entry .doc p:last-child { margin-bottom: 0; }
.entry .doc code.inline { font-size: 12.5px; color: var(--ink); }
.side a .n { color: var(--ink-faint); font-size: 11px; }


/* ---- side index (docs pages) ---- */
.doc-grid { display: grid; grid-template-columns: 240px minmax(0, 1fr); gap: var(--s5); align-items: start; }
.side { position: sticky; top: 72px; font-family: var(--font-mono); font-size: 13px; }
.side a { display: flex; justify-content: space-between; gap: var(--s1); color: var(--ink-soft); border: 0; padding: 6px 0 6px var(--s2); border-left: 2px solid var(--hair); }
.side a:hover, .side a[aria-current="page"] { color: var(--ink); border-left-color: var(--pointer); }
.side .grp { color: var(--ink-faint); text-transform: uppercase; letter-spacing: 0.12em; font-size: 11px; margin-top: var(--s3); }

/* ---- footer ---- */
.foot { border-top: 1px solid var(--hair); padding-block: var(--s5); color: var(--ink-faint); font-family: var(--font-mono); font-size: 12px; display: flex; flex-wrap: wrap; gap: var(--s3); justify-content: space-between; }
.foot a { color: var(--ink-soft); border: 0; }
.foot .cross { color: var(--ink-faint); }
.foot .cross a { color: var(--ink-soft); }

/* ---- showcase / live engine playground ---- */
.pg-section { padding: var(--s5) 0; border-top: 1px solid var(--hair); }
.pg-section h2 { font-family: var(--font-serif); font-size: clamp(22px, 3vw, 30px); color: var(--ink); margin: 0 0 var(--s2); }
.pg-section .pg-intro { color: var(--ink-soft); font-size: 16px; max-width: 72ch; margin: 0 0 var(--s4); }
.pg-block { display: grid; grid-template-columns: 220px minmax(0, 1fr); gap: var(--s4); align-items: start; margin-bottom: var(--s5); }
.pg-block .pg-label { font-family: var(--font-mono); font-size: 12px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--ink-faint); }
.pg-block .pg-label b { display: block; color: var(--ink); font-size: 15px; letter-spacing: 0; text-transform: none; margin-top: 4px; font-weight: 600; }
.pg-tabs { display: flex; gap: 1px; background: var(--hair); border: 1px solid var(--hair); margin-bottom: var(--s3); }
.pg-tab { flex: 1; font-family: var(--font-mono); font-size: 13px; padding: var(--s2); border: 0; background: var(--paper-2); color: var(--ink-soft); cursor: pointer; }
.pg-tab:hover { color: var(--ink); }
.pg-tab.active { background: var(--paper); color: var(--moonbit); box-shadow: inset 0 -3px 0 var(--moonbit); font-weight: 600; }
.pg-controls { display: flex; flex-wrap: wrap; gap: var(--s3); margin-bottom: var(--s3); }
.pg-toggle { display: flex; align-items: center; gap: var(--s1); font-family: var(--font-mono); font-size: 13px; color: var(--ink); cursor: pointer; border: 1px solid var(--hair); background: var(--paper-2); padding: var(--s1) var(--s2); }
.pg-toggle input { accent-color: var(--pointer); width: 16px; height: 16px; }
.pg-note { font-family: var(--font-mono); font-size: 12.5px; line-height: 1.7; color: var(--ink-soft); border: 1px dashed var(--hair-strong); padding: var(--s2) var(--s3); background: var(--paper-2); }
.pg-note b { color: var(--mapped); }
@media (width <= 860px) {
  .pg-block { grid-template-columns: minmax(0, 1fr); gap: var(--s2); }
}

/* ---- mobile: the ledger keeps its seam, narrowed ---- */
@media (width <= 860px) {
  .seam-stage { --gutter: 30px; }
  .ledger-head .hd { font-size: 9px; letter-spacing: 0.1em; padding: 8px 10px; }
  .cell { padding: 10px; font-size: 11.5px; gap: 0 6px; }
  .cell .flag { font-size: 10px; }
  .suture::before, .suture::after { display: none; }
  .seam-bar { flex-wrap: wrap; gap: var(--s1); }
  .seg { margin-left: 0; }
  .acts, .duo { grid-template-columns: minmax(0, 1fr); }
  .doc-grid { grid-template-columns: minmax(0, 1fr); }
  .side { position: static; }

  /* the bar takes a second row instead of squeezing the links into each other */
  .topbar { flex-wrap: wrap; gap: var(--s2); }
  .nav { order: 3; width: 100%; margin-left: 0; justify-content: space-between; gap: var(--s2); }
  .nav a { flex: none; padding: 4px 0; }
  .theme-toggle { margin-left: auto; }
}

/* ---- scroll bars: the page's shows while it moves or under the pointer and
   hides a moment after, keeping its place; a box's is thin, faint at rest and
   darker under the pointer ---- */
@supports selector(::-webkit-scrollbar) {
  ::-webkit-scrollbar { width: 8px; height: 8px; }
  ::-webkit-scrollbar-track, ::-webkit-scrollbar-corner { background: transparent; }
  ::-webkit-scrollbar-thumb { border: 2px solid transparent; border-radius: 99px; background: color-mix(in srgb, var(--ink) 16%, transparent) padding-box; }
  *:hover::-webkit-scrollbar-thumb { background: color-mix(in srgb, var(--ink) 32%, transparent) padding-box; }
  html::-webkit-scrollbar { width: 10px; }
  html::-webkit-scrollbar-thumb { border-width: 3px; background: color-mix(in srgb, var(--ink) 26%, transparent) padding-box; }
  html::-webkit-scrollbar-thumb:hover { background: color-mix(in srgb, var(--ink) 40%, transparent) padding-box; }
  html:not(.scrolling)::-webkit-scrollbar-thumb { background: transparent; border-color: transparent; }
}
@supports not selector(::-webkit-scrollbar) {
  * { scrollbar-width: thin; scrollbar-color: color-mix(in srgb, var(--ink) 22%, transparent) transparent; }
  html:not(.scrolling) { scrollbar-color: transparent transparent; }
}
