/* pscat site — one stylesheet, no framework.
   Dark by default, light when the reader's system asks for it.
   Prose is set in the system sans-serif; code, the brand and the
   navigation keep the monospace of the terminal the LaserWriter was
   plugged into. Every colour comes from a token below, so the two themes
   cannot drift apart. */

:root {
  color-scheme: dark light;
  --bg: #14161c;
  --panel: #1c1f27;
  --edge: #2c3040;
  --ink: #e1e4ea;
  --dim: #9aa1b2;
  --accent: #7fd4c1;
  --accent2: #e8a1bb;
  --accent-ink: #0d1f1b;     /* text on an accent-coloured button */
  --button: #3b4a7a;
  --button-hover: #48598f;
  --button-ink: #f1f3ff;
  --err: #ee8b8b;
  --stage: #0e1013;          /* the dark wall behind a rendered page */
  --shadow: rgba(0, 0, 0, .55);
  --header-bg: rgba(20, 22, 28, .92);
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #fbfaf7;
    --panel: #f1eee7;
    --edge: #d9d4c7;
    --ink: #21242c;
    --dim: #5d6372;
    --accent: #0b6b5b;
    --accent2: #a23a69;
    --accent-ink: #ffffff;
    --button: #35467a;
    --button-hover: #2a3866;
    --button-ink: #ffffff;
    --err: #b3261e;
    --stage: #e6e2d8;
    --shadow: rgba(40, 30, 10, .25);
    --header-bg: rgba(251, 250, 247, .92);
  }
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.65 var(--sans);
}

/* ------- header and navigation ------- */
.site-header {
  display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 22px;
  padding: 12px 24px;
  border-bottom: 1px solid var(--edge);
  position: sticky; top: 0; z-index: 10;
  background: var(--header-bg);
  backdrop-filter: blur(6px);
  font-family: var(--mono); font-size: 14px;
}
.site-header .brand { font-weight: 700; font-size: 18px; color: var(--accent); text-decoration: none; }
.site-header nav { display: flex; flex-wrap: wrap; gap: 2px 16px; margin-left: auto; }
.site-header nav a {
  color: var(--dim); text-decoration: none;
  padding: 4px 0; border-bottom: 2px solid transparent;
}
.site-header nav a:hover { color: var(--ink); }
.site-header nav a.here { color: var(--ink); border-bottom-color: var(--accent); }

/* ------- page body ------- */
main { max-width: 920px; margin: 0 auto; padding: 36px 24px 80px; }
main.wide { max-width: 1200px; }

h1 { font-size: 30px; line-height: 1.2; margin: 0 0 8px; letter-spacing: -.01em; }
h1 + .sub { color: var(--dim); margin: 0 0 28px; font-size: 17px; }
h2 { font-size: 21px; line-height: 1.3; margin: 44px 0 10px; color: var(--accent); }
h3 { font-size: 16px; margin: 26px 0 6px; color: var(--accent2); }
a { color: var(--accent); text-underline-offset: 2px; }
a:hover { text-decoration-thickness: 2px; }
p, li { max-width: 72ch; }
li { margin: 4px 0; }
hr { border: 0; border-top: 1px solid var(--edge); margin: 36px 0; }
img { max-width: 100%; height: auto; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

code, pre {
  background: var(--panel);
  border: 1px solid var(--edge);
  border-radius: 5px;
  font-family: var(--mono);
  font-size: .9em;
}
code { padding: 1px 5px; overflow-wrap: anywhere; }
pre { padding: 14px 16px; overflow-x: auto; line-height: 1.5; max-width: 100%; }
pre code { background: none; border: 0; padding: 0; font-size: 1em; overflow-wrap: normal; }

table { border-collapse: collapse; margin: 12px 0; }
th, td { border: 1px solid var(--edge); padding: 7px 12px; text-align: left; vertical-align: top; }
th { color: var(--dim); font-weight: 600; }
/* wide tables scroll inside their own box instead of the whole page */
@media (max-width: 720px) {
  table { display: block; overflow-x: auto; }
}

/* ------- cards (gallery, fonts, guides, landing page) ------- */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 18px; margin: 20px 0; }
.card {
  background: var(--panel); border: 1px solid var(--edge); border-radius: 8px;
  padding: 0 0 12px; overflow: hidden;
}
.card img { width: 100%; height: auto; display: block; background: #fff; }
.card .body { padding: 10px 14px 0; }
.card .body b { display: block; margin-bottom: 3px; }
.card .body span { color: var(--dim); font-size: 14px; }

/* a card that is one big link: the guides index, the landing page paths */
a.card { display: block; padding: 14px 16px 16px; color: inherit; text-decoration: none; }
a.card:hover { border-color: var(--accent); }
a.card b { display: block; color: var(--accent); margin-bottom: 4px; }
a.card span { color: var(--dim); font-size: 14px; }
a.card .tag {
  display: inline-block; margin-top: 8px; font: 12px var(--mono); color: var(--dim);
  border: 1px solid var(--edge); border-radius: 999px; padding: 0 8px;
}

.reference-comparison {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(280px, 100%), 1fr));
  gap: 18px;
  margin: 20px 0 34px;
}
.reference-comparison figure {
  margin: 0;
  padding: 12px;
  border: 1px solid var(--edge);
  border-radius: 6px;
  background: var(--panel);
}
.reference-comparison img {
  width: 100%;
  height: auto;
  max-height: min(68vw, 620px);
  display: block;
  object-fit: contain;
  background: var(--stage);
}
.reference-comparison figcaption { padding: 10px 2px 0; }
.reference-comparison figcaption b { display: block; margin-bottom: 3px; }
.reference-comparison figcaption span { color: var(--dim); font-size: 14px; }

/* ------- gallery (generated by scripts/gallery.py) ------- */
.card .body b a { color: inherit; text-decoration: none; }
.card .body b a:hover { color: var(--accent); }
.card .meta { padding: 6px 14px 0; font-size: 13px; color: var(--dim); }
.card[hidden], #art section[hidden] { display: none; }
#art section, #specimens, [id^="group-"] { scroll-margin-top: 72px; }
#art .cards, [id^="group-"] .cards { align-items: start; }

.jump-label { margin: 18px 0 4px; font: 600 13px var(--mono); color: var(--dim); text-transform: uppercase; letter-spacing: .04em; }
.jump { display: flex; flex-wrap: wrap; gap: 8px; }
.jump a, .filter button {
  display: inline-block; padding: 4px 12px; border-radius: 999px; font-size: 14px;
  background: var(--panel); border: 1px solid var(--edge); color: var(--ink); text-decoration: none;
}
.jump a:hover, .filter button:hover { border-color: var(--accent); background: var(--panel); }
.jump a span, .filter button span { color: var(--dim); margin-left: 4px; }
.filter { display: block; margin-top: 18px; }
.filter[hidden] { display: none; }
.filter .chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.filter button[aria-pressed="true"] { border-color: var(--accent); color: var(--accent); }

.crumbs { margin: 0 0 14px; color: var(--dim); font-size: 14px; }
figure.piece { margin: 6px 0 8px; text-align: center; }
figure.piece img {
  width: auto; max-width: 100%; max-height: 86vh; background: var(--stage);
  border: 1px solid var(--edge); border-radius: 6px; box-shadow: 0 6px 30px var(--shadow);
}
figure.piece figcaption { color: var(--dim); font-size: 13px; margin-top: 8px; }
dl.facts { display: grid; grid-template-columns: max-content 1fr; gap: 6px 22px; margin: 12px 0; }
dl.facts dt { color: var(--dim); }
dl.facts dd { margin: 0; }
details { margin: 14px 0; }
summary { cursor: pointer; color: var(--accent); }
.open-pg { font-weight: 600; }
.pager { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 10px 20px; margin: 44px 0 0; padding-top: 18px; border-top: 1px solid var(--edge); }

.pill {
  display: inline-block; background: var(--panel); border: 1px solid var(--edge);
  border-radius: 999px; padding: 2px 12px; margin: 2px 4px 2px 0; color: var(--dim); font-size: 13px;
}
.small { color: var(--dim); font-size: 14px; }

/* ------- "View source" window (#461; scripts/gallery.py, site/source-viewer.js) ------- */
a.view-source { font-weight: 600; }
.source-dialog {
  padding: 0; border: 1px solid var(--edge); border-radius: 10px;
  background: var(--bg); color: var(--ink);
  width: min(1040px, calc(100vw - 32px)); max-width: none;
  height: min(88vh, 940px); max-height: none;
  box-shadow: 0 10px 50px var(--shadow); overscroll-behavior: contain;
}
.source-dialog[open] { display: flex; flex-direction: column; }
.source-dialog::backdrop { background: rgba(8, 10, 14, .72); }
html.dialog-open { overflow: hidden; }
.source-head {
  display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 18px;
  padding: 12px 16px; border-bottom: 1px solid var(--edge); background: var(--panel);
}
.source-title { flex: 1 1 260px; min-width: 0; }
.source-name { margin: 0; font: 700 16px var(--mono); color: var(--accent); overflow-wrap: anywhere; }
.source-meta { margin: 0; color: var(--dim); font-size: 14px; }
.source-actions { display: flex; align-items: center; gap: 14px; }
.source-actions a { font-size: 14px; }
.source-libs { flex: 1 0 100%; margin: 0; max-width: none; font-size: 14px; color: var(--dim); overflow-wrap: anywhere; }
.source-libs[hidden] { display: none; }
.source-body {
  flex: 1; min-height: 0; overflow: auto; display: flex; align-items: flex-start;
  background: var(--bg); font: 13px/1.5 var(--mono); tab-size: 4; overscroll-behavior: contain;
}
.source-body pre {
  margin: 0; border: 0; border-radius: 0; background: transparent; max-width: none;
  overflow: visible; font: inherit; line-height: inherit; padding: 12px 0; flex: none;
}
.source-body pre code { font: inherit; }
.source-body pre.source-gutter {
  position: sticky; left: 0; z-index: 1; text-align: right; padding: 12px 10px 12px 14px;
  color: var(--dim); background: var(--panel); border-right: 1px solid var(--edge);
  user-select: none; -webkit-user-select: none;
}
.source-body pre.source-code { padding: 12px 18px 12px 14px; white-space: pre; }
.source-note { margin: 0; padding: 16px; font: 15px/1.6 var(--sans); color: var(--dim); }

/* ------- landing page ------- */
.landing-hero { margin: 0 0 8px; display: grid; gap: 8px 40px; align-items: center; }
.landing-hero .copy { max-width: 62ch; }
.landing-hero .cta { max-width: none; }
@media (min-width: 1000px) {
  .landing-hero { grid-template-columns: 6fr 7fr; }
}
.landing-hero h1 { font-size: clamp(28px, 5.2vw, 44px); margin-bottom: 12px; }
.landing-hero .lede { font-size: 18px; color: var(--ink); margin: 0 0 22px; }
.landing-hero figure { margin: 18px 0 0; }
@media (min-width: 1000px) { .landing-hero figure { margin: 0; } }
.landing-hero figure img {
  width: 100%; display: block; border-radius: 8px; border: 1px solid var(--edge);
  background: var(--stage);
}
.landing-hero figcaption { color: var(--dim); font-size: 14px; padding-top: 8px; }

.cta { display: flex; flex-wrap: wrap; gap: 10px; margin: 0; }
.cta a {
  display: inline-block; padding: 10px 14px; border-radius: 8px; font-weight: 600; font-size: 15px;
  text-decoration: none; border: 1px solid var(--edge); color: var(--ink); background: var(--panel);
}
.cta a:hover { border-color: var(--accent); }
.cta a.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.cta a.primary:hover { filter: brightness(1.08); }

/* ------- Learn page (#252) ------- */
/* in-page links land below the sticky header, not under it */
main.learn [id] { scroll-margin-top: 72px; }
.toc {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(min(280px, 100%), 1fr));
  gap: 6px 28px; margin: 24px 0 8px; padding: 14px 18px;
  background: var(--panel); border: 1px solid var(--edge); border-radius: 8px;
}
.toc ol { margin: 6px 0 4px; padding-left: 22px; }
.toc li { margin: 2px 0; }
.toc b a { color: var(--ink); text-decoration: none; }
a.cite { font-size: .8em; vertical-align: super; line-height: 0; text-decoration: none; margin-left: 1px; }
ol.sources li { font-size: 15px; overflow-wrap: anywhere; }

/* an example: its source, the "Try it" link, then what it prints or draws */
figure.example {
  margin: 14px 0 24px; border: 1px solid var(--edge); border-radius: 8px;
  overflow: hidden; background: var(--panel);
}
figure.example > pre { margin: 0; border: 0; border-radius: 0; background: transparent; }
figure.example figcaption {
  display: flex; justify-content: flex-end; padding: 6px 12px;
  border-top: 1px solid var(--edge); font-size: 14px;
}
a.try {
  font-family: var(--mono); font-weight: 600; text-decoration: none;
  padding: 3px 10px; border-radius: 6px; border: 1px solid var(--accent);
}
a.try:hover { background: var(--accent); color: var(--accent-ink); }
a.try::after { content: " ▸"; }
.result { border-top: 1px solid var(--edge); padding: 10px 14px 14px; background: var(--bg); }
.result .label {
  display: block; margin-bottom: 6px; font: 12px var(--mono);
  color: var(--dim); text-transform: uppercase; letter-spacing: .06em;
}
.result pre.output { margin: 0; }
.result img { display: block; background: #fff; border: 1px solid var(--edge); border-radius: 3px; }

/* ------- footer ------- */
.site-footer {
  border-top: 1px solid var(--edge); color: var(--dim);
  text-align: center; padding: 20px 24px; font-size: 14px;
}
.site-footer p { margin: 4px auto; max-width: none; }
.site-footer a { color: var(--dim); }
.site-footer a:hover { color: var(--ink); }

/* ------- controls shared by the playground and the charts page ------- */
button, select {
  background: var(--button); color: var(--button-ink); border: 0; border-radius: 6px;
  padding: 8px 16px; font: inherit; cursor: pointer;
}
select { background: var(--panel); border: 1px solid var(--edge); color: var(--ink); }
button:hover { background: var(--button-hover); }

/* ------- playground ------- */
/* The page below the header is a flex column, so the editor fills whatever
   height the header leaves, however many rows the nav wraps to. */
body.app { min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; }
#play { display: flex; flex: 1; min-height: 0; }
#play-left { flex: 1; display: flex; flex-direction: column; padding: 16px; min-width: 0; }
#src {
  flex: 1; resize: none; background: var(--panel); color: var(--ink);
  border: 1px solid var(--edge); border-radius: 6px; padding: 12px;
  font: 14px/1.5 var(--mono); tab-size: 4; white-space: pre; overflow: auto;
}
#controls { display: flex; gap: 10px; align-items: center; margin-top: 12px; flex-wrap: wrap; }
#status { color: var(--dim); margin-left: auto; white-space: nowrap; }
#err { color: var(--err); white-space: pre-wrap; margin-top: 8px; max-height: 6em; overflow: auto; }
#out { margin: 8px 0 0; max-height: 14em; overflow: auto; white-space: pre-wrap; }
#play-right { display: flex; align-items: center; justify-content: center; padding: 16px; background: var(--stage); }
#page {
  max-height: calc(100vh - 100px); max-width: 44vw;
  background: #fff; border-radius: 3px; box-shadow: 0 8px 40px var(--shadow);
}

/* ------- phones and narrow windows ------- */
@media (max-width: 760px) {
  body { font-size: 16px; }
  .site-header { position: static; padding: 10px 16px; gap: 6px 14px; }
  .site-header nav { margin-left: 0; width: 100%; gap: 2px 14px; }
  main { padding: 24px 16px 56px; }
  h1 { font-size: 25px; }
  h2 { margin-top: 34px; }
  .cards { grid-template-columns: repeat(auto-fill, minmax(min(240px, 100%), 1fr)); gap: 14px; }
  .cta a { flex: 1 1 100%; text-align: center; }
  .source-dialog { width: 100vw; height: 100vh; height: 100dvh; border-radius: 0; border: 0; }
  .source-head { padding: 10px 12px; }
  #play { flex-direction: column; }
  #play-left { padding: 12px; }
  #src { flex: none; height: 46vh; min-height: 220px; }
  #play-right { padding: 12px; }
  #page { max-width: 100%; max-height: none; height: auto; }
  #status { margin-left: 0; white-space: normal; }
}
