/* nib-site-next: the front page as one program that grows.

   The page's one bold move is the file on the right: box.nib, sticky beside
   the story, showing the program as it stands after the step being read.
   Each line carries a stripe for its side of the seam, so the language's
   one idea is visible in the file itself:

     cobalt     a module: it changes nothing
     vermilion  an effector: the only code that holds state
     mustard    the seam itself, interfaces and the wire

   Lines the current step added carry the marker-pen wash the rest of the
   site uses. Everything else stays quiet: system type, no cards, no shadows
   but the panel's own. The palette is the existing site's, so the guide and
   the standard library still look like the same place. */

:root {
  --paper: #fbf8f1;
  --panel: #f2ecdd;
  --line: #e3dac5;
  --ink: #17150f;
  --ink-2: #4c4739;
  --ink-3: #6d6757;
  --card: #fffdf7;

  --cobalt: #1c39c4;
  --vermilion: #b8340c;
  --mustard: #ffd44a;

  --c-keyword: #1c39c4;
  --c-type: #6b2a86;
  --c-function: #0d635c;
  --c-string: #36601c;
  --c-literal: #8a5300;

  --band: #16134a;
  --band-ink: #fbf8f1;
  --band-ink-2: #c9c6e6;
  --run-bg: #1a1838;
  --run-ink: #ece9f7;
  --run-cmd: #ffd44a;

  --side-core: #1c39c4;
  --side-shell: #b8340c;
  --side-seam: #d9a600;
  --pen-wash: rgb(255 212 74 / 0.34);
  --focus-wash: rgb(28 57 196 / 0.12);
  --link-line: rgb(184 52 12 / 0.45);

  --mono: ui-monospace, SFMono-Regular, "SF Mono", "Cascadia Mono",
    "Roboto Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    "Helvetica Neue", "Noto Sans", Arial, sans-serif;

  --gutter: clamp(1.25rem, 4vw, 3rem);
  --wide: 1320px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #13121a;
    --panel: #1c1b26;
    --line: #2f2d3d;
    --ink: #eeeae0;
    --ink-2: #c6c0b1;
    --ink-3: #9d978a;
    --card: #1a1924;

    --cobalt: #8ea2ff;
    --vermilion: #ff8f63;

    --c-keyword: #9fb0ff;
    --c-type: #d8a6f2;
    --c-function: #63d2c6;
    --c-string: #a9d987;
    --c-literal: #f2b663;

    --band: #1b1852;
    --run-bg: #0d0c17;

    --side-core: #8ea2ff;
    --side-shell: #ff8f63;
    --side-seam: #ffd44a;
    --pen-wash: rgb(255 212 74 / 0.15);
    --focus-wash: rgb(142 162 255 / 0.2);
    --link-line: rgb(255 143 99 / 0.5);
  }
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
}

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 17px/1.62 var(--sans);
  -webkit-text-size-adjust: 100%;
}

a {
  color: inherit;
  text-decoration-color: var(--link-line);
  text-decoration-thickness: 1.5px;
  text-underline-offset: 3px;
}
a:hover { text-decoration-color: currentColor; }
a:focus-visible, summary:focus-visible {
  outline: 2px solid var(--cobalt);
  outline-offset: 3px;
  border-radius: 3px;
}

code {
  font-family: var(--mono);
  font-size: 0.86em;
}
p code, li code, dd code, td code, summary code {
  white-space: nowrap;
  background: var(--panel);
  border-radius: 4px;
  padding: 0.08em 0.3em;
}

.preview-note {
  margin: 0;
  padding: 0.45rem var(--gutter);
  background: var(--mustard);
  color: #17150f;
  font-size: 0.85rem;
}

/* ---- hero ---------------------------------------------------------- */

.hero {
  background: var(--band);
  color: var(--band-ink);
  padding: 1.25rem var(--gutter) 3.25rem;
}
.hero > * { max-width: var(--wide); margin-left: auto; margin-right: auto; }
.hero a:focus-visible { outline-color: var(--mustard); }

.top {
  display: flex;
  align-items: baseline;
  gap: 1.5rem;
  font-size: 0.95rem;
}
.top a { color: var(--band-ink-2); text-decoration: none; }
.top a:hover { color: var(--band-ink); }
.top .mark {
  margin-right: auto;
  font: 700 1.5rem/1 var(--mono);
  color: var(--band-ink);
  letter-spacing: -0.02em;
}

.hero h1 {
  margin-top: clamp(2.5rem, 7vw, 4.75rem);
  margin-bottom: 1.4rem;
  max-width: 21ch;
  font-size: clamp(2rem, 1.2rem + 2.9vw, 3.55rem);
  line-height: 1.08;
  letter-spacing: -0.02em;
  font-weight: 700;
  text-wrap: balance;
}
.hero h1, .hero .lede, .hero .steps, .hero .release {
  margin-left: max(0px, calc((100% - var(--wide)) / 2));
}

.hero .lede {
  max-width: 58ch;
  margin-top: 0;
  font-size: 1.14rem;
  color: var(--band-ink-2);
}

/* The eight steps really are a sequence, so they are numbered. */
.steps {
  list-style: none;
  counter-reset: step;
  margin-top: 2.25rem;
  margin-bottom: 2rem;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0;
  border-top: 1px solid rgb(255 255 255 / 0.16);
  max-width: 64rem;
}
.steps li {
  counter-increment: step;
  border-bottom: 1px solid rgb(255 255 255 / 0.16);
}
.steps a {
  display: flex;
  gap: 0.7rem;
  align-items: baseline;
  padding: 0.7rem 1rem 0.7rem 0;
  text-decoration: none;
  color: var(--band-ink);
  font-size: 0.95rem;
  line-height: 1.35;
}
.steps a::before {
  content: counter(step);
  font: 700 0.95rem/1 var(--mono);
  color: var(--mustard);
  min-width: 1ch;
}
.steps a:hover { color: var(--mustard); }

.release { margin-bottom: 0; color: var(--band-ink-2); font-size: 0.95rem; }

/* ---- the story: prose on the left, the file on the right ------------ */

.story {
  max-width: var(--wide);
  margin: 0 auto;
  padding: 0 var(--gutter);
  display: grid;
  grid-template-columns: minmax(0, 35rem) minmax(0, 1fr);
  gap: clamp(2rem, 4.5vw, 4.5rem);
  align-items: start;
}

.ch {
  padding: 4rem 0 2.5rem;
  min-height: 70vh;
}
.ch + .ch { border-top: 1px solid var(--line); }
.ch:last-child { min-height: 0; padding-bottom: 5rem; }

.ch h2 {
  margin: 0 0 1.1rem;
  font-size: 1.6rem;
  line-height: 1.2;
  letter-spacing: -0.01em;
  text-wrap: balance;
}
.ch h2 .n {
  display: block;
  margin-bottom: 0.5rem;
  font: 700 0.95rem/1 var(--mono);
  color: var(--cobalt);
}
.ch p { margin: 0 0 1.1rem; }

.scope {
  font-size: 0.9rem;
  color: var(--ink-2);
  border-left: 2px solid var(--line);
  padding-left: 0.9rem;
}
.scope .today { font-weight: 700; color: var(--ink); }
.scope .later { font-weight: 700; color: var(--ink-3); margin-left: 0.35rem; }

/* ---- code ----------------------------------------------------------- */

pre {
  margin: 0;
  font-family: var(--mono);
  font-size: 12.8px;
  line-height: 1.62;
}

pre.file code { display: block; }
.l {
  display: block;
  position: relative;
  white-space: pre;
  padding: 0 1.1rem 0 3.3rem;
  border-left: 3px solid transparent;
}
.l::before {
  content: attr(data-n);
  position: absolute;
  left: 0.3rem;
  width: 2.1rem;
  text-align: right;
  color: var(--ink-3);
  opacity: 0.65;
}
.l.s-core { border-left-color: var(--side-core); }
.l.s-shell { border-left-color: var(--side-shell); }
.l.s-seam { border-left-color: var(--side-seam); }
.l.new { background: var(--pen-wash); }
.l.focus { background: var(--focus-wash); }

.fold {
  display: block;
  padding-left: 3.3rem;
  color: var(--ink-3);
  line-height: 1.2;
}

/* What a step added, inline: only where the sticky file is not shown. */
.added {
  display: none;
  margin: 0 0 1.25rem;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.55rem 0;
  overflow-x: auto;
}

pre.run {
  margin: 0 0 1.25rem;
  padding: 0.9rem 1.1rem;
  background: var(--run-bg);
  color: var(--run-ink);
  border-radius: 10px;
  font-size: 12.5px;
  line-height: 1.58;
  white-space: pre;
  overflow-x: auto;
}
pre.run .cmd { color: var(--run-cmd); }

pre.spec {
  margin: 0 0 1.25rem;
  padding: 0.8rem 1rem;
  background: var(--card);
  border: 1px solid var(--line);
  border-left: 3px solid var(--side-seam);
  border-radius: 10px;
  color: var(--ink-2);
  overflow-x: auto;
}

/* tree-sitter-nib's classes, as the rest of the site inks them */
.keyword { color: var(--c-keyword); font-weight: 600; }
.type { color: var(--c-type); font-weight: 600; }
.type.builtin { font-style: italic; font-weight: 500; }
.constructor { color: var(--c-literal); font-weight: 600; }
.string, .string.special { color: var(--c-string); }
.number, .constant, .constant.builtin { color: var(--c-literal); }
.comment { color: var(--ink-3); font-style: italic; }
.function, .function.builtin { color: var(--c-function); }
.property, .property.builtin, .attribute { color: var(--ink-2); }
.variable, .variable.builtin { color: var(--ink); }
.variable.parameter { color: var(--ink-2); font-style: italic; }
.operator { color: var(--ink-2); }
.punctuation, .punctuation.bracket, .punctuation.delimiter, .punctuation.special { color: var(--ink-3); }

/* ---- the journal, as a tape ----------------------------------------- */

.tape {
  list-style: none;
  margin: 0 0 0.6rem;
  padding: 0.35rem 0;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  font: 12.5px/1.5 var(--mono);
}
.tape li {
  display: grid;
  grid-template-columns: 1.6rem minmax(0, 1fr) auto;
  gap: 0.6rem;
  padding: 0.22rem 0.9rem 0.22rem 0.7rem;
  border-left: 4px solid transparent;
}
.tape .seq { color: var(--ink-3); text-align: right; }
.tape .op { overflow-wrap: anywhere; color: var(--ink-2); }
.tape .op b { color: var(--ink); font-weight: 700; }
.tape .ans { color: var(--ink); }
.tape .k-effect { border-left-color: var(--side-core); }
.tape .k-operation { border-left-color: var(--side-shell); }
.tape .k-publication { border-left-color: var(--side-seam); }
.tape .k-end { color: var(--ink-3); }

.key {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem 1.1rem;
  font-size: 0.82rem;
  color: var(--ink-2);
}
.key span::before, .sides span::before {
  content: "";
  display: inline-block;
  width: 0.7rem;
  height: 0.7rem;
  margin-right: 0.4rem;
  border-radius: 2px;
  vertical-align: -0.05rem;
}
.key .k-effect::before, .sides .s-core::before { background: var(--side-core); }
.key .k-operation::before, .sides .s-shell::before { background: var(--side-shell); }
.key .k-publication::before, .sides .s-seam::before { background: var(--side-seam); }

/* ---- the panel ------------------------------------------------------ */

.panel {
  position: sticky;
  top: 1rem;
  margin: 1rem 0;
  height: calc(100vh - 2rem);
  display: flex;
  flex-direction: column;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: 0 1px 2px rgb(72 54 20 / 0.05), 0 10px 30px rgb(72 54 20 / 0.07);
  overflow: hidden;
}
.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 0.75rem 1.1rem 0.4rem;
}
.fname { font: 700 0.95rem/1 var(--mono); }
.at { font-size: 0.82rem; color: var(--ink-3); }
.at b { color: var(--ink); font-family: var(--mono); }
.sides {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem 1rem;
  margin: 0;
  padding: 0 1.1rem 0.7rem;
  border-bottom: 1px solid var(--line);
  font-size: 0.78rem;
  color: var(--ink-2);
}
.files {
  position: relative;
  flex: 1;
  overflow: auto;
  padding: 0.6rem 0 2rem;
  overscroll-behavior: contain;
}
.files pre.file { display: none; }
.files pre.file[data-ch="8"] { display: block; }
html.js .files pre.file[data-ch="8"] { display: none; }
html.js .files pre.file.on { display: block; }
.panel-foot {
  display: flex;
  gap: 1.2rem;
  margin: 0;
  padding: 0.6rem 1.1rem;
  border-top: 1px solid var(--line);
  font-size: 0.85rem;
}

details.wholefile { margin-top: 1.5rem; }
details.wholefile summary { cursor: pointer; color: var(--ink-2); }
details.wholefile pre.file {
  margin-top: 0.8rem;
  padding: 0.55rem 0;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow-x: auto;
}
@media (min-width: 961px) {
  details.wholefile { display: none; }
}

/* ---- after the story ------------------------------------------------ */

.more, .road, .start {
  max-width: var(--wide);
  margin: 0 auto;
  padding: 4rem var(--gutter) 0;
}
.more h2, .road h2, .start h2 {
  margin: 0 0 1.5rem;
  font-size: 1.6rem;
  letter-spacing: -0.01em;
  padding-top: 2.5rem;
  border-top: 1px solid var(--line);
}

/* Two columns of term-and-description pairs; a pair never splits. */
.more dl {
  margin: 0;
  max-width: 62rem;
  columns: 2 20rem;
  column-gap: 3rem;
}
.more dt { font-weight: 700; margin: 0 0 0.2rem; break-after: avoid; }
.more dd {
  margin: 0 0 1.4rem;
  color: var(--ink-2);
  font-size: 0.95rem;
  break-inside: avoid;
}

.road table {
  width: 100%;
  max-width: 62rem;
  border-collapse: collapse;
  font-size: 0.95rem;
}
.road th, .road td {
  text-align: left;
  vertical-align: top;
  padding: 0.75rem 1.25rem 0.75rem 0;
  border-bottom: 1px solid var(--line);
}
.road thead th { color: var(--ink-3); font-weight: 600; font-size: 0.85rem; }
.road tbody th { width: 9rem; }
.road td + td { color: var(--ink-2); }

.start > p, .start details { max-width: 62ch; }
.downloads {
  list-style: none;
  margin: 1.5rem 0;
  padding: 0;
  max-width: 34rem;
  border-top: 1px solid var(--line);
}
.downloads li {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.7rem 0;
  border-bottom: 1px solid var(--line);
}
.downloads a { font-weight: 700; }
.downloads span { color: var(--ink-3); font-size: 0.9rem; }
.start pre.run { max-width: 40rem; }
.start details { margin: 0 0 1.5rem; }
.start summary { cursor: pointer; color: var(--ink-2); }
.sums { font-size: 0.8rem; }
.sums dt { font-weight: 700; margin-top: 0.4rem; }
.sums dd { margin: 0; overflow-wrap: anywhere; }

footer {
  max-width: var(--wide);
  margin: 4rem auto 0;
  padding: 1.5rem var(--gutter) 3rem;
  color: var(--ink-3);
  font-size: 0.85rem;
}
footer p { max-width: 62ch; border-top: 1px solid var(--line); padding-top: 1.5rem; margin: 0; }

/* ---- narrow: one column, each step shows what it added ---------------- */

@media (max-width: 960px) {
  .story { grid-template-columns: minmax(0, 1fr); }
  .panel { display: none; }
  .added { display: block; }
  .ch { min-height: 0; padding-top: 3rem; }
  .steps { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 520px) {
  body { font-size: 16px; }
  .steps { grid-template-columns: minmax(0, 1fr); }
  .top { gap: 1rem; font-size: 0.88rem; }
  .top a[href="#start"] { display: none; }
  pre, pre.run { font-size: 12px; }
}
