
/* ===========================================================
   RWA Velocity Textbook — global styles
   Academic-paper aesthetic with interactive component support
   =========================================================== */

:root {
  --bg:           #faf9f5;
  --bg-card:     #ffffff;
  --bg-sidebar:  #f3f1ea;
  --ink:         #1a1a1a;
  --ink-soft:    #3a3a3a;
  --ink-muted:   #6b6b6b;
  --rule:        #d8d4c4;
  --rule-soft:   #ebe7d8;
  --accent:      #185FA5;
  --accent-soft: #4d8ac8;
  --highlight:   #E24B4A;
  --good:        #3a7c47;
  --warn:        #b6822a;
  --code-bg:     #f5f2e8;
  --pull-bg:     #f8f4e6;

  --font-serif:  "Iowan Old Style", "Charter", "Palatino", "Georgia", serif;
  --font-sans:   "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  --font-mono:   "JetBrains Mono", "SF Mono", "Menlo", "Consolas", monospace;

  --sidebar-w:   280px;
  --read-w:      720px;
  --gap:         48px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-serif);
  font-size: 17px;
  line-height: 1.62;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}

/* ----- Layout ----- */

.layout {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100vh;
}

.sidebar {
  background: var(--bg-sidebar);
  border-right: 1px solid var(--rule);
  padding: 24px 20px 80px 24px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  font-family: var(--font-sans);
  font-size: 13.5px;
}

.sidebar h1 {
  font-family: var(--font-serif);
  font-size: 18px;
  line-height: 1.3;
  margin: 0 0 4px 0;
  color: var(--ink);
}
.sidebar .subtitle {
  font-size: 11.5px;
  color: var(--ink-muted);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  margin-bottom: 24px;
}

.sidebar nav ol {
  list-style: none;
  padding: 0;
  margin: 0;
  counter-reset: chap;
}
.sidebar nav li {
  counter-increment: chap;
  margin: 2px 0;
}
.sidebar nav a {
  display: block;
  padding: 6px 10px 6px 32px;
  border-radius: 4px;
  color: var(--ink-soft);
  text-decoration: none;
  position: relative;
  transition: background 0.12s ease;
}
.sidebar nav a::before {
  content: counter(chap, decimal-leading-zero);
  position: absolute;
  left: 4px;
  top: 6px;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink-muted);
  font-weight: 500;
}
.sidebar nav a:hover { background: rgba(24, 95, 165, 0.07); color: var(--accent); }
.sidebar nav a.active {
  background: rgba(24, 95, 165, 0.12);
  color: var(--accent);
  font-weight: 600;
}
.sidebar nav .section-label {
  font-size: 10.5px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-muted);
  margin: 22px 0 6px 4px;
  font-weight: 600;
}

.sidebar .footer-note {
  margin-top: 32px;
  padding-top: 16px;
  border-top: 1px solid var(--rule);
  font-size: 11.5px;
  color: var(--ink-muted);
  line-height: 1.5;
}

/* ----- Main column ----- */

main.content {
  padding: 56px var(--gap) 120px var(--gap);
  max-width: calc(var(--read-w) + 240px);
}

.chapter-meta {
  font-family: var(--font-sans);
  font-size: 12px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-muted);
  margin-bottom: 14px;
}

h1.chapter-title {
  font-family: var(--font-serif);
  font-size: 42px;
  line-height: 1.1;
  font-weight: 600;
  margin: 0 0 8px 0;
  max-width: var(--read-w);
  letter-spacing: -0.01em;
}
.chapter-subtitle {
  font-family: var(--font-serif);
  font-size: 20px;
  font-style: italic;
  color: var(--ink-muted);
  max-width: var(--read-w);
  margin: 0 0 36px 0;
  line-height: 1.4;
}

main h2 {
  font-family: var(--font-sans);
  font-size: 24px;
  font-weight: 600;
  letter-spacing: -0.005em;
  margin: 56px 0 16px 0;
  color: var(--ink);
  max-width: var(--read-w);
  border-bottom: 1px solid var(--rule);
  padding-bottom: 6px;
}
main h3 {
  font-family: var(--font-sans);
  font-size: 18px;
  font-weight: 600;
  margin: 32px 0 10px 0;
  color: var(--ink);
  max-width: var(--read-w);
}
main h4 {
  font-family: var(--font-sans);
  font-size: 15px;
  font-weight: 600;
  margin: 24px 0 6px 0;
  color: var(--ink-soft);
  max-width: var(--read-w);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

main p, main ul, main ol {
  max-width: var(--read-w);
  margin: 0 0 18px 0;
}
main ul, main ol { padding-left: 24px; }
main li { margin: 6px 0; }

main strong { color: var(--ink); font-weight: 600; }
main em { color: var(--ink-soft); }

main a {
  color: var(--accent);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
}
main a:hover { color: var(--highlight); }

/* ----- Code ----- */

code {
  font-family: var(--font-mono);
  font-size: 0.88em;
  background: var(--code-bg);
  padding: 1px 5px;
  border-radius: 3px;
  color: #6c3a1f;
}

pre {
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.55;
  background: var(--code-bg);
  border: 1px solid var(--rule);
  border-left: 3px solid var(--accent);
  padding: 14px 16px;
  border-radius: 4px;
  overflow-x: auto;
  max-width: var(--read-w);
  margin: 18px 0;
}
pre code { background: transparent; padding: 0; color: var(--ink); }

.code-r       { border-left-color: #276DC3; }
.code-py      { border-left-color: #FFD43B; }
.code-sql     { border-left-color: #336791; }
.code-bash    { border-left-color: #4EAA25; }
.code-solidity{ border-left-color: #6c4dad; }

.code-label {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 10.5px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-muted);
  background: var(--rule-soft);
  padding: 1px 6px;
  border-radius: 2px;
  margin-bottom: -8px;
  position: relative;
  top: 8px;
  left: 8px;
}

/* ----- Callouts ----- */

.callout {
  border-left: 3px solid var(--accent);
  background: var(--pull-bg);
  padding: 14px 18px 14px 18px;
  border-radius: 0 4px 4px 0;
  max-width: var(--read-w);
  margin: 20px 0;
  font-size: 15.5px;
}
.callout .label {
  font-family: var(--font-sans);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 4px;
}
.callout p:last-child { margin-bottom: 0; }
.callout.warn  { border-color: var(--warn);      background: #fbf4dd; }
.callout.warn  .label { color: var(--warn); }
.callout.error { border-color: var(--highlight); background: #fbe9e7; }
.callout.error .label { color: var(--highlight); }
.callout.good  { border-color: var(--good);      background: #e7f1e7; }
.callout.good  .label { color: var(--good); }

/* ----- Interactive components ----- */

.interactive {
  background: var(--bg-card);
  border: 1px solid var(--rule);
  border-radius: 6px;
  padding: 20px 22px;
  margin: 28px 0;
  max-width: 920px;
}
.interactive .interactive-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 12px;
  border-bottom: 1px solid var(--rule-soft);
  padding-bottom: 8px;
}
.interactive .interactive-header h3 {
  margin: 0;
  font-family: var(--font-sans);
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.02em;
}
.interactive .interactive-header .tag {
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--ink-muted);
  background: var(--rule-soft);
  padding: 2px 8px;
  border-radius: 3px;
  letter-spacing: 0.04em;
}
.interactive .interactive-caption {
  font-family: var(--font-sans);
  font-size: 13px;
  color: var(--ink-muted);
  margin-top: 8px;
  line-height: 1.5;
}
.interactive .controls {
  display: flex;
  flex-wrap: wrap;
  gap: 18px 24px;
  align-items: center;
  margin: 8px 0 14px 0;
  font-family: var(--font-sans);
  font-size: 13px;
}
.interactive .controls label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  color: var(--ink-soft);
}
.interactive .controls input[type="range"] {
  width: 180px;
  accent-color: var(--accent);
}
.interactive .controls .value {
  font-family: var(--font-mono);
  color: var(--accent);
  font-weight: 600;
  font-size: 12.5px;
}
.interactive .controls button {
  background: var(--accent);
  color: white;
  border: none;
  padding: 7px 14px;
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 500;
  border-radius: 4px;
  cursor: pointer;
}
.interactive .controls button:hover { background: var(--accent-soft); }
.interactive .controls button.secondary {
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--accent);
}
.interactive .readout {
  font-family: var(--font-mono);
  font-size: 12.5px;
  color: var(--ink-soft);
  background: var(--code-bg);
  padding: 8px 12px;
  border-radius: 3px;
  margin-top: 10px;
  line-height: 1.6;
}
.interactive .readout strong { color: var(--accent); }

/* ----- Tables ----- */

table.data {
  border-collapse: collapse;
  margin: 18px 0;
  max-width: var(--read-w);
  font-family: var(--font-sans);
  font-size: 13.5px;
  width: 100%;
}
table.data th, table.data td {
  padding: 8px 12px;
  text-align: left;
  border-bottom: 1px solid var(--rule);
}
table.data th {
  font-weight: 600;
  color: var(--ink);
  border-bottom: 2px solid var(--ink);
  background: var(--bg-sidebar);
}
table.data tr:hover td { background: var(--pull-bg); }
table.data td.num, table.data th.num { text-align: right; font-family: var(--font-mono); }

/* ----- Math (KaTeX overrides) ----- */

.katex-display { margin: 18px 0 !important; max-width: var(--read-w); }
.katex { font-size: 1.05em; }

/* ----- Figure caption ----- */

figure {
  margin: 24px 0;
  max-width: var(--read-w);
}
figcaption {
  font-family: var(--font-sans);
  font-size: 12.5px;
  color: var(--ink-muted);
  margin-top: 8px;
  line-height: 1.5;
  font-style: italic;
}

/* ----- Footnotes / references ----- */

.fn-ref {
  font-family: var(--font-sans);
  font-size: 0.7em;
  vertical-align: super;
  color: var(--accent);
  text-decoration: none;
  margin-left: 1px;
}
.fn-list {
  margin-top: 64px;
  padding-top: 24px;
  border-top: 1px solid var(--rule);
  font-size: 14px;
  color: var(--ink-soft);
  max-width: var(--read-w);
}
.fn-list ol { padding-left: 18px; }
.fn-list li { margin: 6px 0; }

/* ----- Nav bottom (next/prev) ----- */

.chapter-nav {
  display: flex;
  justify-content: space-between;
  margin-top: 80px;
  padding-top: 24px;
  border-top: 1px solid var(--rule);
  max-width: var(--read-w);
  font-family: var(--font-sans);
  font-size: 14px;
  gap: 16px;
}
.chapter-nav a {
  flex: 1;
  text-decoration: none;
  color: var(--ink-soft);
  padding: 12px 16px;
  border: 1px solid var(--rule);
  border-radius: 4px;
  background: var(--bg-card);
  transition: all 0.15s ease;
}
.chapter-nav a:hover {
  border-color: var(--accent);
  color: var(--accent);
}
.chapter-nav a .dir {
  display: block;
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-muted);
  margin-bottom: 2px;
}
.chapter-nav a.next { text-align: right; }

/* ----- Landing page ----- */

.landing {
  padding: 80px var(--gap) 120px var(--gap);
  max-width: 980px;
}
.landing .hero {
  margin-bottom: 56px;
}
.landing .hero h1 {
  font-family: var(--font-serif);
  font-size: 54px;
  line-height: 1.05;
  font-weight: 600;
  letter-spacing: -0.02em;
  margin: 0 0 14px 0;
  max-width: 860px;
}
.landing .hero .tagline {
  font-family: var(--font-serif);
  font-size: 22px;
  font-style: italic;
  color: var(--ink-soft);
  max-width: 740px;
  line-height: 1.4;
}
.landing .hero .meta {
  font-family: var(--font-sans);
  font-size: 12.5px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--ink-muted);
  margin-bottom: 12px;
}

.part-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 18px;
  margin: 32px 0;
}
.part-card {
  background: var(--bg-card);
  border: 1px solid var(--rule);
  border-radius: 6px;
  padding: 20px 22px;
  transition: all 0.15s ease;
}
.part-card:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
}
.part-card .part-num {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.08em;
  color: var(--ink-muted);
  margin-bottom: 6px;
}
.part-card h3 {
  font-family: var(--font-sans);
  font-size: 17px;
  margin: 0 0 8px 0;
  font-weight: 600;
}
.part-card p {
  font-family: var(--font-serif);
  font-size: 14.5px;
  color: var(--ink-soft);
  margin: 0 0 12px 0;
  line-height: 1.5;
}
.part-card .chapter-list {
  font-family: var(--font-sans);
  font-size: 12.5px;
  color: var(--ink-muted);
  border-top: 1px solid var(--rule-soft);
  padding-top: 10px;
  line-height: 1.6;
}
.part-card .chapter-list a {
  color: var(--accent);
  text-decoration: none;
  display: block;
  padding: 2px 0;
}
.part-card .chapter-list a:hover { text-decoration: underline; }

/* ----- Token chip ----- */

.token-chip {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.04em;
  padding: 2px 7px;
  border-radius: 3px;
  background: var(--accent);
  color: white;
  font-weight: 600;
  margin: 0 2px;
}
.token-chip.untreated { background: var(--ink-muted); }

/* ----- SVG defaults ----- */

svg .axis line, svg .axis path {
  stroke: var(--ink-muted);
  stroke-width: 1;
}
svg .axis text {
  font-family: var(--font-sans);
  font-size: 11px;
  fill: var(--ink-soft);
}
svg .grid line {
  stroke: var(--rule-soft);
  stroke-width: 1;
  shape-rendering: crispEdges;
}
svg text.label {
  font-family: var(--font-sans);
  font-size: 11.5px;
  fill: var(--ink-soft);
}

/* ----- Responsive (basic) ----- */

@media (max-width: 920px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar {
    position: relative;
    height: auto;
    border-right: none;
    border-bottom: 1px solid var(--rule);
  }
  main.content { padding: 32px 24px 80px 24px; }
  .landing { padding: 40px 24px; }
  .landing .hero h1 { font-size: 38px; }
  h1.chapter-title { font-size: 32px; }
}

