/* From Mass to Form — site styles
   Modern indie-press: serif body, sans-serif headlines, single accent, light/dark.
*/

:root {
  --bg: #fbfaf7;
  --fg: #1a1a1a;
  --muted: #5c5c5c;
  --rule: #e8e4dc;
  --accent: #b54820;
  --accent-soft: #f0d9cf;
  --code-bg: #f3efe8;

  --serif: "Source Serif 4", "Source Serif Pro", Georgia, "Iowan Old Style", "Apple Garamond", "Palatino Linotype", serif;
  --sans:  "Inter", -apple-system, BlinkMacSystemFont, "Helvetica Neue", Arial, sans-serif;
  --mono:  "JetBrains Mono", "SF Mono", Menlo, Consolas, monospace;

  --measure: 36rem;
  --gutter: 1.5rem;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16140f;
    --fg: #ece8df;
    --muted: #9a958a;
    --rule: #2c2820;
    --accent: #e07b50;
    --accent-soft: #3a2218;
    --code-bg: #221e16;
  }
}

* { box-sizing: border-box; }

html { font-size: 18px; -webkit-text-size-adjust: 100%; }
@media (max-width: 640px) { html { font-size: 17px; } }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--serif);
  font-feature-settings: "kern", "liga", "onum";
  line-height: 1.62;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}

/* ── Layout ────────────────────────────────────────────────────────────── */

.site-header {
  border-bottom: 1px solid var(--rule);
  padding: 1.5rem var(--gutter);
}

.site-header-inner {
  max-width: 60rem;
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 2rem;
  flex-wrap: wrap;
}

.brand {
  font-family: var(--sans);
  font-weight: 700;
  font-size: 1rem;
  letter-spacing: -0.01em;
  color: var(--fg);
  text-decoration: none;
  white-space: nowrap;
}
.brand:hover { color: var(--accent); }

.brand .accent { color: var(--accent); }

nav.primary {
  font-family: var(--sans);
  font-size: 0.92rem;
  display: flex;
  gap: 1.5rem;
  flex-wrap: wrap;
}
nav.primary a {
  color: var(--muted);
  text-decoration: none;
  border-bottom: 1px solid transparent;
  padding-bottom: 1px;
}
nav.primary a:hover, nav.primary a.active {
  color: var(--fg);
  border-bottom-color: var(--accent);
}

main {
  max-width: var(--measure);
  margin: 0 auto;
  padding: 3rem var(--gutter) 5rem;
}

main.wide {
  max-width: 60rem;
}

footer.site-footer {
  border-top: 1px solid var(--rule);
  padding: 2rem var(--gutter);
  font-family: var(--sans);
  font-size: 0.85rem;
  color: var(--muted);
}
footer.site-footer-inner {
  max-width: 60rem;
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 1rem;
}
footer.site-footer a { color: var(--muted); }
footer.site-footer a:hover { color: var(--accent); }

/* ── Typography ────────────────────────────────────────────────────────── */

h1, h2, h3, h4 {
  font-family: var(--sans);
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.18;
  color: var(--fg);
  margin-top: 2.5em;
  margin-bottom: 0.5em;
}

h1 {
  font-size: 2.4rem;
  letter-spacing: -0.03em;
  margin-top: 0;
  margin-bottom: 1.5rem;
}

h2 {
  font-size: 1.55rem;
  margin-top: 3rem;
  padding-top: 1rem;
}

h3 {
  font-size: 1.18rem;
  margin-top: 2rem;
}

h4 {
  font-size: 1rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin-top: 1.8rem;
  margin-bottom: 0.4rem;
}

.lede, p.lede {
  font-size: 1.18rem;
  color: var(--muted);
  font-style: italic;
  line-height: 1.55;
  margin: 0 0 2.5rem;
}

p { margin: 0 0 1.1em; }

a {
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px solid var(--accent-soft);
}
a:hover { border-bottom-color: var(--accent); }

strong { font-weight: 600; }

em { font-style: italic; }

blockquote {
  margin: 1.5em 0;
  padding: 0.2em 1.2em;
  border-left: 3px solid var(--accent);
  color: var(--fg);
  font-style: italic;
}
blockquote p:last-child { margin-bottom: 0; }

ul, ol { padding-left: 1.4em; margin: 0 0 1.2em; }
li { margin-bottom: 0.4em; }
li > ul, li > ol { margin: 0.4em 0 0; }

hr {
  border: 0;
  border-top: 1px solid var(--rule);
  margin: 3rem 0;
}

code {
  font-family: var(--mono);
  font-size: 0.9em;
  background: var(--code-bg);
  padding: 0.1em 0.35em;
  border-radius: 3px;
}

pre {
  background: var(--code-bg);
  padding: 1rem 1.2rem;
  border-radius: 4px;
  overflow-x: auto;
  font-size: 0.88rem;
  line-height: 1.5;
  margin: 1.5em 0;
}
pre code { background: none; padding: 0; font-size: inherit; }

/* Math / displayed equations (we use simple inline notation; just style them readably) */
.math, .equation {
  font-family: var(--mono);
  background: var(--code-bg);
  padding: 0.8rem 1rem;
  border-radius: 4px;
  margin: 1.2em 0;
  text-align: center;
  overflow-x: auto;
  font-size: 0.95rem;
}

table {
  border-collapse: collapse;
  width: 100%;
  margin: 1.5em 0;
  font-size: 0.95rem;
  font-family: var(--sans);
}
th, td {
  text-align: left;
  padding: 0.55em 0.8em;
  border-bottom: 1px solid var(--rule);
  vertical-align: top;
}
th {
  font-weight: 600;
  border-bottom-width: 2px;
  background: var(--code-bg);
}

/* ── Home page: hero ──────────────────────────────────────────────────── */

.hero {
  text-align: center;
  padding: 1rem 0 2rem;
}
.hero h1 {
  font-size: 3rem;
  margin-bottom: 0.6rem;
}
.hero .tagline {
  font-family: var(--sans);
  font-size: 1.05rem;
  color: var(--muted);
  letter-spacing: 0.01em;
  margin: 0 auto 2rem;
  max-width: 32rem;
}
.hero .cta {
  display: inline-block;
  font-family: var(--sans);
  font-weight: 600;
  font-size: 0.95rem;
  background: var(--accent);
  color: #fff;
  padding: 0.7em 1.4em;
  border-radius: 4px;
  border-bottom: none;
  margin: 0 0.4rem;
}
.hero .cta.ghost {
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--accent);
}
.hero .cta:hover { opacity: 0.9; }

/* ── Card grid (used on home for chapter list) ────────────────────────── */

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(15rem, 1fr));
  gap: 1.2rem;
  margin: 2rem 0;
}
.card {
  border: 1px solid var(--rule);
  border-radius: 4px;
  padding: 1.2rem 1.3rem;
  background: var(--bg);
  transition: border-color 0.15s;
}
.card:hover { border-color: var(--accent); }
.card h3 {
  font-size: 1.05rem;
  margin: 0 0 0.4rem;
}
.card h3 a {
  color: var(--fg);
  border-bottom: none;
}
.card h3 a:hover { color: var(--accent); }
.card p {
  color: var(--muted);
  font-size: 0.95rem;
  margin: 0;
  line-height: 1.5;
}
.card .meta {
  font-family: var(--sans);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin-bottom: 0.4rem;
}

/* ── Misc ─────────────────────────────────────────────────────────────── */

.muted { color: var(--muted); }
.center { text-align: center; }
.small { font-size: 0.88rem; }

.footnotes {
  margin-top: 3rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--rule);
  font-size: 0.92rem;
  color: var(--muted);
}

.toc {
  background: var(--code-bg);
  padding: 1.2rem 1.5rem;
  border-radius: 4px;
  font-family: var(--sans);
  font-size: 0.92rem;
  margin: 0 0 2.5rem;
}
.toc-title {
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-size: 0.78rem;
  color: var(--muted);
  margin: 0 0 0.6rem;
}
.toc ol { margin: 0; padding-left: 1.2rem; }
.toc li { margin-bottom: 0.3em; }
.toc a { color: var(--fg); border-bottom: none; }
.toc a:hover { color: var(--accent); }

.section-anchor {
  color: var(--muted);
  font-weight: 400;
  margin-left: 0.4em;
  opacity: 0;
  transition: opacity 0.15s;
  border-bottom: none;
}
h2:hover .section-anchor, h3:hover .section-anchor { opacity: 0.6; }

/* ── Figures / diagrams ───────────────────────────────────────────────── */

figure.diagram {
  margin: 2.5rem auto;
  text-align: center;
}
figure.diagram svg {
  display: block;
  width: 100%;
  max-width: 600px;
  height: auto;
  margin: 0 auto;
}
figure.diagram figcaption {
  font-family: var(--sans);
  font-size: 0.9rem;
  color: var(--muted);
  margin-top: 0.8rem;
  max-width: 32rem;
  margin-left: auto;
  margin-right: auto;
  line-height: 1.55;
}

/* SVG colors that respect light/dark mode */
.svg-fg     { stroke: var(--fg);    fill: none; }
.svg-fg-fill{ fill: var(--fg);   stroke: none; }
.svg-accent { stroke: var(--accent); fill: var(--accent); }
.svg-accent-stroke { stroke: var(--accent); fill: none; }
.svg-rule   { stroke: var(--rule);  fill: none; }
.svg-muted-text  { fill: var(--muted); font-family: var(--sans); }
.svg-label  { fill: var(--fg);    font-family: var(--sans); font-weight: 600; }

/* ── Illustration library ─────────────────────────────────────────────── */

.lib-section {
  margin-top: 4rem;
  padding-top: 2rem;
  border-top: 1px solid var(--rule);
}
.lib-section:first-of-type { margin-top: 1rem; border-top: none; padding-top: 0; }
.lib-section > h2 {
  margin-top: 0;
  padding-top: 0;
}
.lib-section > p.lib-desc {
  font-family: var(--sans);
  font-size: 0.95rem;
  color: var(--muted);
  max-width: 38rem;
}

.lib-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2rem;
  margin-top: 2rem;
}
@media (max-width: 760px) {
  .lib-grid { grid-template-columns: 1fr; }
}

.lib-variant {
  border: 1px solid var(--rule);
  border-radius: 4px;
  padding: 1rem 1rem 0.4rem;
  background: var(--bg);
}
.lib-variant .lib-tag {
  font-family: var(--sans);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin: 0 0 0.4rem;
}
.lib-variant .diagram { margin: 0.5rem 0 0; }
.lib-variant .diagram svg { max-width: 100%; }
.lib-variant .diagram figcaption {
  text-align: left;
  margin: 0.6rem 0.2rem 0;
  font-size: 0.85rem;
}

/* ── Diagram 1: the interaction script (animated) ─────────────────────── */

.diagram-script .pole-ring {
  transform-origin: center;
}
.diagram-script .pulse-a {
  animation: pulse-out 6s ease-out infinite;
  transform-origin: 120px 120px;
  transform-box: fill-box;
  opacity: 0;
}
.diagram-script .pulse-b {
  animation: pulse-out-b 6s ease-out infinite;
  transform-origin: 480px 120px;
  transform-box: fill-box;
  opacity: 0;
}

@keyframes pulse-out {
  0%   { transform: scale(1);   opacity: 0.85; }
  18%  { transform: scale(2.2); opacity: 0; }
  100% { transform: scale(2.2); opacity: 0; }
}
@keyframes pulse-out-b {
  0%, 58% { transform: scale(1);   opacity: 0; }
  62%     { transform: scale(1);   opacity: 0.85; }
  82%     { transform: scale(2.4); opacity: 0; }
  100%    { transform: scale(2.4); opacity: 0; }
}

.diagram-script .a-label-tag {
  opacity: 0;
  animation: tag-a 6s ease-in-out infinite;
}
.diagram-script .b-label-tag {
  opacity: 0;
  animation: tag-b 6s ease-in-out infinite;
}
@keyframes tag-a {
  0%, 8%  { opacity: 0; }
  12%, 55% { opacity: 1; }
  60%, 100% { opacity: 0.4; }
}
@keyframes tag-b {
  0%, 60% { opacity: 0; }
  68%, 95% { opacity: 1; }
  100% { opacity: 0; }
}

.diagram-script .ghost {
  opacity: 0.25;
}
.diagram-script .arena-line {
  stroke-dasharray: 5 7;
}

/* ── Pull-quote ───────────────────────────────────────────────────────── */
.pull {
  font-family: var(--sans);
  font-size: 1.4rem;
  line-height: 1.35;
  font-weight: 600;
  color: var(--fg);
  text-align: center;
  margin: 2.5rem 0;
  padding: 1.5rem 0;
  border-top: 1px solid var(--accent);
  border-bottom: 1px solid var(--accent);
  letter-spacing: -0.02em;
}
