/* balthazar.sh — classic LaTeX academic paper style
 * Computer Modern, paper-white, narrow column, numbered theorems.
 */

/* Computer Modern fonts via CDN */
@import url('/fonts/cmu.css');   /* self-hosted Sep 25 — was fonts.cdnfonts.com (a third party saw every reader) */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  color-scheme: only light;          /* opt out of browser auto-dark-mode */
  --paper:       #fdfdfc;
  --ink:         #0b0b0b;
  --ink-2:       #3a3a3a;
  --ink-3:       #6a6a6a;
  --rule:        #d0d0cf;
  --rule-2:      #e8e7e3;
  --link:        #8b0000;           /* LaTeX default link color */
  --link-visited:#5b0000;
  --highlight:   #fff9e6;            /* theorem callout background */
  --mono-bg:     #f5f4ef;
  --serif:       'CMU Serif', 'Latin Modern Roman', 'Computer Modern Serif',
                 Georgia, 'Times New Roman', Times, serif;
  --sans:        'CMU Sans Serif', 'Latin Modern Sans', 'Computer Modern Sans',
                 Helvetica, Arial, sans-serif;
  --mono:        'CMU Typewriter Text', 'Latin Modern Mono', 'Computer Modern Typewriter',
                 'SF Mono', Menlo, Consolas, monospace;
}

html {
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
  font-size: 17px;
}

body {
  background: var(--paper);
  color: var(--ink);
  font-family: var(--serif);
  font-feature-settings: "liga" 1, "kern" 1, "onum" 1;
  line-height: 1.58;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ─── Links ───────────────────────────────────────────────────── */
a {
  color: var(--link);
  text-decoration: none;
  border-bottom: 1px solid transparent;
  transition: border-color 0.5s ease;
}
a:hover { border-bottom-color: var(--link); }
a:visited { color: var(--link-visited); }

/* ─── Header (masthead) ───────────────────────────────────────── */
.masthead {
  border-bottom: 1px solid var(--rule);
  padding: 22px 0 18px;
  text-align: center;
  margin-bottom: 48px;
  position: relative;
}
.kids-toggle {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 100;
  background: none;
  border: none;
  font-size: 26px;
  line-height: 1;
  cursor: pointer;
  opacity: 0.15;
  padding: 4px;
  transition: opacity 0.8s ease;
}
.kids-toggle:hover { opacity: 0.5; }
html.kids-mode .kids-toggle { opacity: 0.6; }
.masthead-title {
  font-family: var(--serif);
  font-size: 15px;
  letter-spacing: 1.5px;
  font-variant: small-caps;
  color: var(--ink-2);
  text-decoration: none;
  border: none;
}
.masthead-title:hover { border: none; color: var(--ink); }
.masthead-sub {
  font-family: var(--serif);
  font-style: italic;
  font-size: 13px;
  color: var(--ink-3);
  margin-top: 4px;
}

/* ─── Layout ──────────────────────────────────────────────────── */
main {
  max-width: 38rem;      /* ~64 characters at 17px serif, classic paper column */
  margin: 0 auto;
  padding: 0 28px 96px;
}

/* ─── Title block ─────────────────────────────────────────────── */
.title-block {
  text-align: center;
  margin: 36px 0 52px;
}
.title-block h1 {
  font-family: var(--serif);
  font-size: 34px;
  font-weight: 400;
  line-height: 1.2;
  letter-spacing: -0.2px;
  margin-bottom: 18px;
  color: var(--ink);
}
.title-block .authors {
  font-family: var(--serif);
  font-size: 15px;
  color: var(--ink-2);
  margin-bottom: 6px;
}
.title-block .affiliation {
  font-family: var(--serif);
  font-style: italic;
  font-size: 13px;
  color: var(--ink-3);
  margin-bottom: 14px;
}
.title-block .date {
  font-family: var(--serif);
  font-size: 13px;
  color: var(--ink-3);
}

/* ─── Abstract ────────────────────────────────────────────────── */
.abstract {
  margin: 28px auto 44px;
  padding: 0 2.2rem;
  max-width: 34rem;
}
.abstract-heading {
  text-align: center;
  font-family: var(--serif);
  font-size: 14px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 10px;
  color: var(--ink);
}
.abstract p {
  font-size: 15px;
  line-height: 1.55;
  color: var(--ink-2);
  text-align: justify;
  hyphens: auto;
}

/* ─── Table of contents (LaTeX-style) ────────────────────────── */
.toc {
  margin: 8px auto 44px;
  padding: 18px 26px 20px;
  max-width: 34rem;
  border-top: 1px solid var(--rule);
  border-bottom: 1px solid var(--rule);
}
.toc-heading {
  text-align: center;
  font-family: var(--serif);
  font-size: 14px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 14px;
  color: var(--ink);
}
.toc-list {
  list-style: none;
  margin: 0;
  padding: 0;
  font-family: var(--serif);
  font-size: 15px;
  counter-reset: toc;
}
.toc-list > li {
  counter-increment: toc;
  margin: 3px 0;
}
.toc-list > li > a {
  display: flex;
  align-items: baseline;
  gap: 8px;
  color: var(--ink);
  border: none;
  text-decoration: none;
  padding: 2px 0;
}
.toc-list > li > a::before {
  content: counter(toc) ".";
  font-variant-numeric: tabular-nums;
  color: var(--ink-2);
  min-width: 1.5em;
  flex-shrink: 0;
}
.toc-title {
  color: var(--ink);
  flex-shrink: 0;
}
.toc-list > li > a:hover .toc-title { color: var(--link); }
.toc-dots {
  flex: 1;
  border-bottom: 1px dotted var(--ink-3);
  margin: 0 2px 5px;
  min-width: 18px;
}
.toc-sublist {
  list-style: none;
  margin: 2px 0 6px 2.4em;
  padding: 0;
  font-size: 13px;
}
.toc-sublist li { margin: 2px 0; }
.toc-sublist a {
  color: var(--ink-3);
  font-style: italic;
  border: none;
  text-decoration: none;
  border-bottom: 1px solid transparent;
  transition: border-color 0.5s ease, color 0.5s ease;
}
.toc-sublist a:hover {
  color: var(--link);
  border-bottom-color: var(--link);
}

/* ─── Body text ───────────────────────────────────────────────── */
main p {
  margin: 0 0 14px;
  text-align: justify;
  hyphens: auto;
  orphans: 3;
  widows: 3;
}
main p + p { text-indent: 1.4em; }
main h2 + p, main h3 + p, main .formula + p, main blockquote + p,
main ul + p, main ol + p, main pre + p { text-indent: 0; }

strong { font-weight: 700; }
em { font-style: italic; }

/* ─── Section headings ────────────────────────────────────────── */
h2 {
  font-family: var(--serif);
  font-size: 19px;
  font-weight: 700;
  margin: 40px 0 14px;
  color: var(--ink);
  counter-increment: section;
}
h2.numbered::before {
  content: counter(section) ". ";
}
h3 {
  font-family: var(--serif);
  font-size: 16px;
  font-weight: 700;
  font-style: italic;
  margin: 28px 0 10px;
  color: var(--ink);
}

/* ─── Theorems / Definitions / Axioms (LaTeX-style boxes) ────── */
.formula, .theorem, .definition, .axiom, .proof-block {
  font-family: var(--mono);
  font-size: 13.5px;
  line-height: 1.75;
  background: var(--mono-bg);
  border-left: 3px solid var(--ink);
  padding: 14px 18px;
  margin: 20px 0;
  overflow-x: auto;
}

/* Zap link — clickable Lightning address that opens wallet on tap */
a.formula.zap-link,
a.formula.repo-link {
  display: block;
  text-align: left;
  color: var(--ink);
  text-decoration: none;
  border-bottom: none;
  cursor: pointer;
}
a.formula.zap-link:visited,
a.formula.repo-link:visited { color: var(--ink); }

/* zap link bolt — pulses gently on hover */
.zap-link .bolt {
  display: inline-block;
}
.zap-link:hover .bolt {
  animation: zap-pulse 0.7s ease-in-out infinite;
}
@keyframes zap-pulse {
  0%, 100% { transform: scale(1) rotate(0deg); }
  25%      { transform: scale(1.2) rotate(-6deg); }
  75%      { transform: scale(1.2) rotate(6deg); }
}

/* repo link arrow — slides in from the left on hover */
.repo-link .arrow {
  display: inline-block;
  margin-left: 0;
  opacity: 0;
  transform: translateX(-8px);
  transition: opacity 0.8s ease, transform 0.8s ease, margin-left 0.8s ease;
}
.repo-link:hover .arrow {
  opacity: 1;
  margin-left: 10px;
  transform: translateX(0);
}
.repo-link.copied .arrow { opacity: 0; margin-left: 0; }

/* "copied" indicator — slides in after click, fades out after 1.5s */
.copied-msg {
  display: inline-block;
  margin-left: 12px;
  font-style: italic;
  font-family: var(--serif);
  font-size: 12.5px;
  color: var(--ink-3);
  opacity: 0;
  transform: translateX(-4px);
  transition: opacity 0.8s ease, transform 0.8s ease;
  pointer-events: none;
}
.copyable.copied .copied-msg {
  opacity: 1;
  transform: translateX(0);
}

/* Display math — centered, no background, italic serif */
.display-math {
  font-family: var(--serif);
  font-style: italic;
  font-size: 18px;
  text-align: center;
  margin: 24px 0;
  letter-spacing: 0.2px;
}

/* Named environments (Theorem 1., Definition, Axiom, Proof) */
.env {
  margin: 22px 0;
  padding: 14px 20px 12px;
  border-left: 3px solid var(--ink);
  background: var(--highlight);
}
.env-label {
  font-family: var(--serif);
  font-weight: 700;
  font-style: normal;
  color: var(--ink);
  margin-right: 8px;
}
.env-name {
  font-family: var(--serif);
  font-style: italic;
  font-weight: 400;
  color: var(--ink-2);
  margin-right: 8px;
}
.env p { margin-bottom: 6px; }
.env p:last-child { margin-bottom: 0; }
.proof-env {
  margin: 18px 0;
  padding: 4px 0 4px 0;
  font-size: 15px;
}
.proof-env::before {
  content: "Proof.";
  font-family: var(--serif);
  font-style: italic;
  font-weight: 700;
  margin-right: 8px;
}
.proof-env::after {
  content: "□";
  display: inline-block;
  margin-left: 6px;
  color: var(--ink);
}

/* ─── Grid of cards (theorem, body, constraint listings) ─────── */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(14rem, 1fr));
  gap: 12px;
  margin: 22px 0;
}
.card {
  display: block;
  padding: 12px 14px 14px;
  background: var(--paper);
  border: 1px solid var(--rule);
  text-decoration: none;
  color: var(--ink);
  font-family: var(--serif);
  transition: border-color 0.6s ease, background 0.6s ease;
}
.card:hover {
  border-color: var(--ink);
  background: var(--mono-bg);
  text-decoration: none;
}
.card-num {
  font-family: var(--serif);
  font-size: 12px;
  font-variant: small-caps;
  letter-spacing: 1px;
  color: var(--ink-3);
  margin-bottom: 4px;
}
.card-title {
  font-family: var(--serif);
  font-size: 15px;
  font-weight: 400;
  color: var(--ink);
  margin-bottom: 3px;
  line-height: 1.35;
}
.card-ref {
  font-family: var(--serif);
  font-style: italic;
  font-size: 12.5px;
  color: var(--ink-3);
}

/* ─── Inline code ─────────────────────────────────────────────── */
code {
  font-family: var(--mono);
  font-size: 0.9em;
  background: var(--mono-bg);
  padding: 1px 5px;
  border-radius: 2px;
  color: var(--ink);
}
.formula code, pre code, .env code { background: none; padding: 0; }

/* ─── Lists ───────────────────────────────────────────────────── */
main ul, main ol {
  margin: 14px 0 16px 28px;
  color: var(--ink);
}
main li { margin-bottom: 6px; line-height: 1.55; }

/* ─── Blockquotes (scripture) ─────────────────────────────────── */
blockquote {
  margin: 20px 2.2rem;
  padding: 10px 0;
  font-family: var(--serif);
  font-style: italic;
  font-size: 15px;
  color: var(--ink-2);
  text-align: justify;
  border-left: 2px solid var(--ink-3);
  padding-left: 16px;
}
blockquote .ref {
  display: block;
  margin-top: 6px;
  font-style: normal;
  font-size: 12.5px;
  color: var(--ink-3);
  font-variant: small-caps;
  letter-spacing: 0.8px;
}

/* ─── Tables / reference lists ────────────────────────────────── */
table {
  width: 100%;
  border-collapse: collapse;
  margin: 22px 0;
  font-size: 14px;
}
table thead th {
  text-align: left;
  font-weight: 700;
  font-family: var(--serif);
  padding: 6px 8px;
  border-bottom: 1.5px solid var(--ink);
  color: var(--ink);
}
table td {
  padding: 6px 8px;
  border-bottom: 1px solid var(--rule);
  vertical-align: top;
  color: var(--ink-2);
}
table tbody tr:last-child td { border-bottom: none; }

/* ─── Index-card list (for /theorems/, /body/) ───────────────── */
.index-list {
  list-style: none;
  margin: 20px 0;
  padding: 0;
  font-size: 15px;
}
.index-list li {
  display: flex;
  align-items: baseline;
  padding: 7px 0;
  border-bottom: 1px dotted var(--rule);
}
.index-list li:last-child { border-bottom: none; }
.index-list .num {
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0.02em;
  color: var(--ink-3);
  min-width: 11em;
  flex-shrink: 0;
}
.index-list .name {
  flex: 1;
  margin-right: 10px;
}
.index-list .name a {
  color: var(--ink);
  border: none;
}
.index-list .name a:hover { color: var(--link); }
.index-list .ref {
  font-family: var(--serif);
  font-style: italic;
  font-size: 13px;
  color: var(--ink-3);
  text-align: right;
}

/* ─── Figures and captions ────────────────────────────────────── */
figure {
  margin: 26px 0;
  text-align: center;
}
figcaption {
  font-family: var(--serif);
  font-size: 13px;
  font-style: italic;
  color: var(--ink-3);
  margin-top: 8px;
}

/* ─── Page navigation (prev/next) ─────────────────────────────── */
.prev-next {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  margin: 56px 0 0;
  padding-top: 20px;
  border-top: 1px solid var(--rule);
  font-size: 14px;
}
.prev-next a {
  flex: 1;
  padding: 10px 14px;
  border: 1px solid var(--rule);
  border-radius: 2px;
  background: var(--paper);
  display: block;
  text-decoration: none;
  border-bottom: 1px solid var(--rule);
}
.prev-next a:hover { border-color: var(--ink); }
.prev-next .label {
  display: block;
  font-size: 11px;
  font-variant: small-caps;
  letter-spacing: 0.5px;
  color: var(--ink-3);
  margin-bottom: 2px;
}
.prev-next .title {
  display: block;
  color: var(--ink);
  font-style: italic;
}
.prev-next .next { text-align: right; }

/* ─── Crumbs (breadcrumb trail) ──────────────────────────────── */
.crumb {
  font-family: var(--serif);
  font-size: 13px;
  color: var(--ink-3);
  font-style: italic;
  margin-bottom: 20px;
  text-align: center;
}
.crumb a { color: var(--ink-3); border: none; }
.crumb a:hover { color: var(--link); }

/* ─── Footer ──────────────────────────────────────────────────── */
footer {
  max-width: 38rem;
  margin: 0 auto;
  padding: 48px 28px 48px;
  border-top: 1px solid var(--rule);
  text-align: center;
  font-family: var(--serif);
  font-size: 12.5px;
  color: var(--ink-3);
  font-style: italic;
}
footer a { color: var(--ink-3); border: none; }
footer a:hover { color: var(--link); }
footer .brand {
  font-variant: small-caps;
  letter-spacing: 0.8px;
  font-style: normal;
}

/* ─── Small print ─────────────────────────────────────────────── */
.small {
  font-size: 13px;
  color: var(--ink-3);
}

/* ─── Responsive ──────────────────────────────────────────────── */
@media (max-width: 600px) {
  html { font-size: 16px; }
  main { padding: 0 20px 60px; }
  .abstract { padding: 0 0.5rem; }
  .title-block h1 { font-size: 26px; }
  .formula, .theorem, .definition, .axiom, .proof-block { font-size: 12.5px; padding: 12px 14px; }
  blockquote { margin: 18px 0.6rem; }
}

/* ─── Theorem tooltips ────────────────────────────────────────── */
.has-tooltip {
  position: relative;
  cursor: help;
}
.has-tooltip::after {
  content: attr(data-tooltip);
  position: absolute;
  left: 0;
  top: calc(100% + 6px);
  background: var(--ink);
  color: var(--paper);
  font-family: var(--serif);
  font-size: 12px;
  font-style: italic;
  line-height: 1.5;
  padding: 7px 11px;
  width: 230px;
  border-radius: 2px;
  opacity: 0;
  pointer-events: none;
  transform: translateY(-4px);
  transition: opacity 0.7s ease, transform 0.7s ease;
  z-index: 20;
  white-space: normal;
}
.has-tooltip:hover::after {
  opacity: 1;
  transform: translateY(0);
}


/* ─── Magic C ─────────────────────────────────────────────────── */
#magic-c { cursor: default; user-select: none; }

/* ─── Kids mode theme ─────────────────────────────────────────── */
html.kids-mode {
  --paper:         #fffef5;
  --ink:           #2c1a0e;
  --ink-2:         #4a2c1a;
  --ink-3:         #8b6a4e;
  --rule:          #e8d5b8;
  --rule-2:        #f0e6d3;
  --link:          #c0440a;
  --link-visited:  #8b3008;
  --highlight:     #fff9db;
  --mono-bg:       #fdf6e8;
}
html.kids-mode h2 {
  color: #c0440a;
}
html.kids-mode .title-block .authors {
  display: none;
}
html.kids-mode .env {
  border-left-color: #f4a261;
  border-radius: 0 6px 6px 0;
}
html.kids-mode .display-math {
  font-size: 17px;
  font-style: normal;
  background: var(--highlight);
  padding: 18px 22px;
  border-radius: 6px;
  line-height: 1.7;
}
html.kids-mode .formula {
  border-left-color: #f4a261;
  border-radius: 0 6px 6px 0;
}
html.kids-mode blockquote {
  border-left-color: #f4a261;
}
/* ─── Kids card (sub-page summary) ───────────────────────────── */
.kids-card {
  background: #fff9db;
  border-left: 3px solid #f9a825;
  border-radius: 0 6px 6px 0;
  padding: 16px 20px;
  margin: 20px 0 32px;
  font-family: var(--serif);
  font-size: 15px;
  line-height: 1.68;
  color: var(--ink-2);
}
.kids-card-label {
  display: block;
  font-size: 11px;
  font-variant: small-caps;
  letter-spacing: 0.8px;
  color: #b8860b;
  margin-bottom: 8px;
}

.kids-subtext {
  display: block;
  font-family: var(--serif);
  font-style: italic;
  font-size: 14px;
  color: var(--ink-3);
  margin-top: 8px;
}

/* ─── Sidebar Navigation ──────────────────────────────────────── */
.nav-toggle {
  position: fixed;
  top: 18px;
  left: 18px;
  z-index: 200;
  background: none;
  border: none;
  font-size: 18px;
  cursor: pointer;
  opacity: 0.25;
  padding: 6px;
  transition: opacity 0.8s ease;
  line-height: 1;
  color: var(--ink-2);
}
.nav-toggle:hover { opacity: 0.6; }
.nav-sidebar {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: 260px;
  max-width: 75vw;
  background: var(--paper);
  border-right: 1px solid var(--rule);
  z-index: 199;
  transform: translateX(-100%);
  transition: transform 0.6s cubic-bezier(0.25, 0.1, 0.25, 1);
  overflow-y: auto;
  padding: 60px 20px 30px;
  font-family: var(--serif);
  font-size: 13px;
}
.nav-sidebar.open { transform: translateX(0); }
.nav-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.15);
  z-index: 198;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.8s ease;
}
.nav-overlay.open { opacity: 1; pointer-events: auto; }
.nav-sidebar h3 {
  font-size: 10px;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--ink-3);
  margin: 18px 0 6px;
  font-weight: normal;
  font-family: var(--sans);
}
.nav-sidebar h3:first-child { margin-top: 0; }
.nav-sidebar a {
  display: block;
  padding: 5px 0;
  color: var(--ink-2);
  text-decoration: none;
  border: none;
  line-height: 1.4;
  transition: color 0.5s ease;
}
.nav-sidebar a:hover { color: var(--link); }
.nav-sidebar a.active {
  color: var(--link);
  font-weight: bold;
}

@media print { .nav-toggle, .nav-sidebar, .nav-overlay { display: none; } }

/* ─── Print ───────────────────────────────────────────────────── */
@media print {
  body { font-size: 11pt; color: #000; background: #fff; }
  .masthead, .prev-next, .crumb, footer { display: none; }
  main { max-width: none; padding: 0; }
  a { color: #000; border: none; }
  .env, .formula, .theorem, .definition, .axiom, .proof-block { page-break-inside: avoid; }
}
