/* Majordomo — Shared Stylesheet (ePub + Web) */

/* ---- Theme Variables ---- */

:root {
  --bg: #fff;
  --text: #1a1a1a;
  --text-muted: #555;
  --text-faint: #666;
  --border: #ccc;
  --code-bg: #f4f4f4;
  --callout-bg: #fafafa;
  --table-header-bg: #f0f0f0;
  --link: #2563eb;
  --blockquote-text: #333;
  --callout-label: #666;
  --callout-science: #2563eb;
  --callout-tip: #15803d;
  --callout-fairness: #dc2626;
  --callout-meme: #9333ea;
  --callout-spec: #c2410c;
  --callout-also: #0e7490;
  --placeholder-border: #ff0000;
  --placeholder-bg: #f8f8f6;
  --placeholder-text: #666;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141414;
    --text: #d4d4d4;
    --text-muted: #aaa;
    --text-faint: #888;
    --border: #333;
    --code-bg: #1e1e1e;
    --callout-bg: #1c1c1c;
    --table-header-bg: #252525;
    --link: #60a5fa;
    --blockquote-text: #bbb;
    --callout-label: #999;
    --callout-science: #60a5fa;
    --callout-tip: #4ade80;
    --callout-fairness: #f87171;
    --callout-meme: #c084fc;
    --callout-spec: #fb923c;
    --callout-also: #22d3ee;
    --placeholder-border: #cc4444;
    --placeholder-bg: #1a1a1a;
    --placeholder-text: #666;
  }
}

/* ---- Base Typography ---- */

body {
  font-family: Georgia, 'Times New Roman', serif;
  font-size: 1em;
  line-height: 1.6;
  margin: 1em;
  color: var(--text);
  background-color: var(--bg);
}

h1 {
  font-family: Helvetica, Arial, sans-serif;
  font-size: 1.8em;
  font-weight: 900;
  margin-top: 2em;
  margin-bottom: 0.5em;
  line-height: 1.2;
}

h2 {
  font-family: Helvetica, Arial, sans-serif;
  font-size: 1.4em;
  font-weight: 700;
  margin-top: 1.5em;
  margin-bottom: 0.4em;
}

h3 {
  font-family: Helvetica, Arial, sans-serif;
  font-size: 1.15em;
  font-weight: 700;
  margin-top: 1.2em;
  margin-bottom: 0.3em;
}

h4 {
  font-family: Helvetica, Arial, sans-serif;
  font-size: 1em;
  font-weight: 700;
  margin-top: 1em;
  margin-bottom: 0.3em;
}

p {
  margin: 0.6em 0;
  text-indent: 0;
}

blockquote {
  margin: 1em 1.5em;
  padding-left: 0.8em;
  border-left: 3px solid var(--border);
  color: var(--blockquote-text);
}

/* ---- Code / Prompt Examples ---- */

code {
  font-family: 'Courier New', Courier, monospace;
  font-size: 0.9em;
  background: var(--code-bg);
  padding: 0.1em 0.3em;
  border-radius: 2px;
}

pre {
  font-family: 'Courier New', Courier, monospace;
  font-size: 0.85em;
  background: var(--code-bg);
  padding: 1em;
  margin: 1em 0;
  line-height: 1.4;
  border-radius: 3px;
  overflow-x: auto;
}

/* ---- Conversation Blocks ---- */

pre.conversation {
  white-space: normal;
  -webkit-hyphens: none;
  hyphens: none;
  padding: 1em;
  page-break-inside: avoid;
  break-inside: avoid;
}

pre.conversation kbd,
pre.conversation samp {
  font: inherit;
  display: block;
  padding-left: 1.8em;
  position: relative;
}

pre.conversation kbd::before {
  content: '\1F464';
  position: absolute;
  top: 0;
  left: 0;
  font-size: 1.2em;
  line-height: 1;
}

pre.conversation samp::before {
  content: '\2728';
  position: absolute;
  top: 0;
  left: 0;
  font-size: 1.2em;
  line-height: 1;
}

pre code {
  background: none;
  padding: 0;
}

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

table {
  border-collapse: collapse;
  width: 100%;
  margin: 1em 0;
  font-size: 0.9em;
}

th, td {
  border: 1px solid var(--border);
  padding: 0.4em 0.6em;
  text-align: left;
}

th {
  background: var(--table-header-bg);
  font-weight: 700;
}

/* ---- Tap-to-Define Glossary ---- */

/* Noteref link in the text: reads as prose, signals with a dotted rule.
   Apple Books pops the target aside over the page; elsewhere it jumps to
   the Definitions block below. */
a.gloss-ref {
  color: inherit;
  text-decoration: none;
  border-bottom: 1px dotted var(--link);
}

.glossary {
  margin-top: 2em;
  padding-top: 1em;
  border-top: 1px solid var(--border);
}

.gloss-note {
  font-size: 0.85em;
  margin: 0.5em 0;
  line-height: 1.5;
}

.gloss-note p {
  margin: 0;
}

.gloss-term {
  font-style: normal;
  font-weight: bold;
}

.gloss-backlink {
  margin-left: 0.4em;
  text-decoration: none;
  color: var(--link);
}

/* ---- Callout Blocks ---- */

.callout {
  margin: 1.2em 0;
  padding: 0.8em 1em;
  border-left: 4px solid var(--border);
  background: var(--callout-bg);
  font-size: 0.92em;
  page-break-inside: avoid;
  break-inside: avoid;
}

.callout-label {
  font-family: Helvetica, Arial, sans-serif;
  font-size: 0.75em;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-bottom: 0.3em;
  color: var(--callout-label);
  padding-left: 3.5em;
  position: relative;
}

.callout-label::before {
  content: '';
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 2.8em;
  height: 2.8em;
  background-repeat: no-repeat;
  background-position: center;
  background-size: contain;
}

.callout-science {
  border-left-color: var(--callout-science);
}

.callout-science .callout-label {
  color: var(--callout-science);
}

.callout-science .callout-label::before {
  background-image: url(../images/callout-icon-science-bohr-atom.png);
}

.callout-tip {
  border-left-color: var(--callout-tip);
}

.callout-tip .callout-label {
  color: var(--callout-tip);
}

.callout-tip .callout-label::before {
  background-image: url(../images/callout-icon-tip-star.png);
}

.callout-fairness {
  border-left-color: var(--callout-fairness);
}

.callout-fairness .callout-label {
  color: var(--callout-fairness);
}

.callout-fairness .callout-label::before {
  background-image: url(../images/callout-icon-fairness-yin-yang.png);
}

.callout-meme {
  border-left-color: var(--callout-meme);
}

.callout-meme .callout-label {
  color: var(--callout-meme);
}

.callout-meme .callout-label::before {
  background-image: url(../images/callout-icon-meme-cool-s.png);
}

.callout-spec {
  border-left-color: var(--callout-spec);
}

.callout-spec .callout-label {
  color: var(--callout-spec);
}

.callout-spec .callout-label::before {
  background-image: url(../images/callout-icon-spec-3d-cube.png);
}

.callout-also {
  border-left-color: var(--callout-also);
}

.callout-also .callout-label {
  color: var(--callout-also);
}

.callout-also .callout-label::before {
  background-image: url(../images/callout-icon-also-block-arrow.png);
}

@media (prefers-color-scheme: dark) {
  .callout-label::before {
    filter: invert(1) hue-rotate(180deg);
  }
}

/* ---- Endnotes ---- */

.endnotes {
  margin-top: 2em;
  padding-top: 1em;
  border-top: 1px solid var(--border);
}

/* Notes carry their own visible [n] labels, so the list must not number them. */
.endnote-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.endnote {
  font-size: 0.85em;
  margin: 0.5em 0;
  line-height: 1.5;
}

.endnote-ref {
  font-size: 0.8em;
  vertical-align: super;
  text-decoration: none;
  color: var(--link);
}

.endnote-num {
  font-weight: bold;
  margin-right: 0.3em;
}

.endnote-backlink {
  margin-left: 0.4em;
  text-decoration: none;
  color: var(--link);
}

/* ---- Chapter Opener Illustrations (Trinitron) ---- */

.illustration {
  margin: 2em 0;
  text-align: center;
}

.illustration img {
  max-width: 100%;
}

.illustration figcaption {
  font-style: italic;
  font-size: 0.9em;
  margin-top: 0.5em;
  color: var(--text-muted);
}

/* ---- Inline Graphics (transparent background) ---- */

.inline-graphic {
  margin: 1.2em 0;
}

.inline-graphic img {
  max-width: 100%;
}

.inline-graphic figcaption {
  font-style: italic;
  font-size: 0.88em;
  margin-top: 0.4em;
  color: var(--text-muted);
}

.inline-graphic-full {
  text-align: center;
}

.inline-graphic-full img {
  max-width: 100%;
}

.inline-graphic-half {
  max-width: 45%;
}

.inline-graphic-half-left {
  float: left;
  margin-right: 1em;
  margin-bottom: 0.5em;
}

.inline-graphic-half-right {
  float: right;
  margin-left: 1em;
  margin-bottom: 0.5em;
}

.inline-graphic-margin {
  max-width: 25%;
}

/* ---- Art Placeholders (no image yet) ---- */

.art-placeholder {
  margin: 1.2em 0;
}

.art-placeholder-box {
  border: 2px dashed var(--placeholder-border);
  background: var(--placeholder-bg);
  padding: 0.6em;
  text-align: center;
  overflow: hidden;
}

.art-placeholder-file {
  font-family: 'Courier New', Courier, monospace;
  font-size: 0.7em;
  color: var(--placeholder-text);
  margin: 0;
}

.art-placeholder-box details {
  margin: 0;
}

.art-placeholder-box summary {
  font-style: italic;
  font-size: 0.75em;
  color: var(--text-faint);
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  list-style: none;
}

.art-placeholder-box summary::-webkit-details-marker {
  display: none;
}

.art-placeholder-box details[open] summary {
  white-space: normal;
  overflow: visible;
}

.art-placeholder-alt {
  font-style: italic;
  font-size: 0.75em;
  color: var(--text-faint);
  margin: 0.3em 0 0;
  text-align: left;
}

.art-placeholder-full .art-placeholder-box {
  height: 12em;
}

.art-placeholder-half-left {
  max-width: 45%;
  float: left;
  margin-right: 1em;
  margin-bottom: 0.5em;
}

.art-placeholder-half-left .art-placeholder-box {
  height: 9em;
}

.art-placeholder-half-right {
  max-width: 45%;
  float: right;
  margin-left: 1em;
  margin-bottom: 0.5em;
}

.art-placeholder-half-right .art-placeholder-box {
  height: 9em;
}

.art-placeholder-margin {
  max-width: 25%;
}

.art-placeholder-margin .art-placeholder-box {
  height: 5em;
}

/* Dark mode: transparent inline graphics need a light "paper" behind them.
   Inverting the pixels would distort skin tones in drawings of people. */
@media (prefers-color-scheme: dark) {
  .inline-graphic img {
    background: #f5f3f0;
    padding: 0.6em;
    border-radius: 2px;
  }
}

/* ---- Lists ---- */

ul, ol {
  margin: 0.8em 0;
  padding-left: 1.5em;
}

li {
  margin: 0.3em 0;
}

/* ---- Horizontal Rules ---- */

hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 2em 0;
}

/* ---- Links ---- */

a {
  color: var(--link);
  text-decoration: underline;
}

/* ---- Emphasis ---- */

em {
  font-style: italic;
}

strong {
  font-weight: 700;
}

/* ---- Read-along narration-only text ---- */

/*
 * Announces images to the audiobook edition's narration (see
 * build/audio/narrate-images.ts). Visually hidden and aria-hidden since
 * sighted readers already see the image and screen-reader users already
 * get its description via the img's own alt text — this exists only for
 * the Media Overlay audio track, which reads real text content regardless
 * of visibility or ARIA state.
 */
.narration-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Majordomo — Website Layout */

/* ---- Site Variables ---- */

:root {
  --sidebar-bg: #f8f8f8;
  --sidebar-width: 280px;
  --content-max: 45em;
  --nav-bg: #f0f0f0;
  --hero-bg: #f5f3f0;
}

@media (prefers-color-scheme: dark) {
  :root {
    --sidebar-bg: #1a1a1a;
    --nav-bg: #1e1e1e;
    --hero-bg: #1a1a1a;
  }
}

/* ---- Reset for web ---- */

body {
  margin: 0;
}

/* ---- Toggle (checkbox hack) ---- */

#toc-toggle {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.toc-btn {
  position: fixed;
  top: 0.75em;
  left: 0.75em;
  z-index: 200;
  cursor: pointer;
  width: 2.5em;
  height: 2.5em;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
}

.toc-btn span {
  display: block;
  width: 18px;
  height: 2px;
  background: var(--text);
  position: relative;
  transition: background 0.2s;
}

.toc-btn span::before,
.toc-btn span::after {
  content: '';
  display: block;
  width: 18px;
  height: 2px;
  background: var(--text);
  position: absolute;
  transition: transform 0.2s;
}

.toc-btn span::before { top: -6px; }
.toc-btn span::after { top: 6px; }

/* ---- Sidebar ---- */

.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: var(--sidebar-width);
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  padding: 1em;
  padding-top: 3.5em;
  z-index: 100;
  transform: translateX(-100%);
  transition: transform 0.2s ease;
}

#toc-toggle:checked ~ .sidebar {
  transform: translateX(0);
}

.sidebar-title {
  display: block;
  font-family: Helvetica, Arial, sans-serif;
  font-size: 0.85em;
  font-weight: 700;
  color: var(--text);
  text-decoration: none;
  margin-bottom: 1em;
  padding-bottom: 0.5em;
  border-bottom: 1px solid var(--border);
}

.sidebar-title:hover {
  color: var(--link);
}

/* ---- TOC in sidebar ---- */

.toc {
  list-style: none;
  padding: 0;
  margin: 0;
}

.toc details {
  margin-bottom: 0.3em;
}

.toc summary {
  font-family: Helvetica, Arial, sans-serif;
  font-size: 0.75em;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0.3em 0;
  list-style: none;
}

.toc summary::-webkit-details-marker {
  display: none;
}

.toc summary::before {
  content: '\25B8';
  display: inline-block;
  width: 1em;
  transition: transform 0.15s;
}

.toc details[open] > summary::before {
  transform: rotate(90deg);
}

.toc ol {
  list-style: none;
  padding: 0 0 0 1em;
  margin: 0.2em 0 0.5em;
}

.toc li {
  margin: 0;
}

.toc a {
  display: block;
  font-size: 0.85em;
  color: var(--text);
  text-decoration: none;
  padding: 0.2em 0.4em;
  border-radius: 3px;
  line-height: 1.3;
}

.toc a:hover {
  background: var(--code-bg);
  color: var(--link);
}

.toc .toc-current > a {
  background: var(--link);
  color: #fff;
  font-weight: 600;
}

/* ---- Overlay (mobile sidebar backdrop) ---- */

.overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 50;
  cursor: pointer;
}

#toc-toggle:checked ~ .overlay {
  display: block;
}

/* ---- Main Content ---- */

main {
  min-height: 100vh;
  padding: 3.5em 1.5em 2em;
  transition: margin-left 0.2s ease;
}

main > article {
  max-width: var(--content-max);
  margin: 0 auto;
}

main > article h1:first-child {
  margin-top: 0.5em;
}

/* ---- Chapter Navigation ---- */

.chapter-nav {
  max-width: var(--content-max);
  margin: 3em auto 0;
  padding-top: 1.5em;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  gap: 1em;
}

.chapter-nav a {
  text-decoration: none;
  max-width: 45%;
}

.chapter-nav-dir {
  display: block;
  font-family: Helvetica, Arial, sans-serif;
  font-size: 0.75em;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

.chapter-nav-title {
  display: block;
  font-size: 0.95em;
  color: var(--link);
  margin-top: 0.15em;
}

.chapter-nav a:hover .chapter-nav-title {
  text-decoration: underline;
}

.chapter-nav-next {
  text-align: right;
  margin-left: auto;
}

/* ---- Footer ---- */

.site-footer {
  max-width: var(--content-max);
  margin: 3em auto 0;
  padding: 1.5em 0;
  border-top: 1px solid var(--border);
  font-size: 0.8em;
  color: var(--text-muted);
}

.site-footer a {
  color: var(--text-muted);
}

.site-footer p {
  margin: 0.2em 0;
}

/* ---- Landing Page ---- */

.landing {
  display: block;
}

.hero {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 4em 1.5em;
  background: var(--hero-bg);
  text-align: center;
}

.hero-cover {
  max-width: 280px;
  width: 100%;
  border-radius: 4px;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.15);
}

.hero-text {
  max-width: 36em;
  margin-top: 2em;
}

.hero h1 {
  font-size: 2.2em;
  margin: 0 0 0.2em;
}

.hero-subtitle {
  font-family: Helvetica, Arial, sans-serif;
  font-size: 1.1em;
  color: var(--text-muted);
  margin: 0 0 1.5em;
}

.hero-pitch {
  font-size: 1.05em;
  line-height: 1.5;
  color: var(--text);
  margin: 0 0 2em;
  font-style: italic;
}

.hero-ctas {
  display: flex;
  gap: 1em;
  flex-wrap: wrap;
  justify-content: center;
}

.hero-cta {
  display: inline-block;
  font-family: Helvetica, Arial, sans-serif;
  font-size: 1.1em;
  font-weight: 700;
  color: #fff;
  background: var(--link);
  padding: 0.7em 2em;
  border-radius: 4px;
  text-decoration: none;
}

.hero-cta:hover {
  opacity: 0.9;
  color: #fff;
}

.hero-cta-secondary {
  background: transparent;
  color: var(--link);
  border: 2px solid var(--link);
}

.hero-cta-secondary:hover {
  background: var(--link);
  color: #fff;
}

/* Landing page sections */

.landing-content {
  max-width: 42em;
  margin: 0 auto;
  padding: 3em 1.5em;
}

.landing-content h2 {
  font-size: 1.3em;
  margin-top: 2em;
}

.landing-content p {
  font-size: 0.95em;
  line-height: 1.6;
}

/* ---- Share Buttons ---- */

.share-section {
  max-width: 42em;
  margin: 0 auto;
  padding: 2em 1.5em;
  text-align: center;
}

.share-label {
  font-family: Helvetica, Arial, sans-serif;
  font-size: 0.85em;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin: 0 0 0.8em;
}

.share-links {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5em;
  justify-content: center;
}

.share-btn {
  display: inline-block;
  font-family: Helvetica, Arial, sans-serif;
  font-size: 0.85em;
  font-weight: 600;
  padding: 0.4em 1em;
  border-radius: 2em;
  text-decoration: none;
  color: #fff;
}

.share-btn:hover {
  opacity: 0.85;
  color: #fff;
}

.share-bluesky { background: #0085ff; }
.share-mastodon { background: #6364ff; }
.share-twitter { background: #1d9bf0; }
.share-facebook { background: #1877f2; }
.share-linkedin { background: #0a66c2; }

.landing-footer {
  max-width: 42em;
  margin: 0 auto;
  padding: 2em 1.5em;
  border-top: 1px solid var(--border);
  font-size: 0.8em;
  color: var(--text-muted);
  text-align: center;
}

.landing-footer a {
  color: var(--text-muted);
}

/* ---- TOC Page ---- */

.toc-page {
  max-width: var(--content-max);
  margin: 0 auto;
}

.toc-page h1 {
  margin-top: 0.5em;
}

.toc-page h2 {
  font-size: 1.1em;
  margin-top: 2em;
  margin-bottom: 0.3em;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.toc-page ol {
  list-style: none;
  padding: 0;
  margin: 0 0 1em;
}

.toc-page li {
  margin: 0;
}

.toc-page a {
  display: block;
  padding: 0.4em 0.5em;
  text-decoration: none;
  color: var(--text);
  border-radius: 3px;
}

.toc-page a:hover {
  background: var(--code-bg);
  color: var(--link);
}

/* ---- 404 Page ---- */

.not-found {
  text-align: center;
  padding: 6em 1.5em;
}

.not-found h1 {
  font-size: 4em;
  margin: 0;
  color: var(--text-muted);
}

.not-found p {
  font-size: 1.1em;
  color: var(--text-muted);
}

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

@media (min-width: 60em) {
  .toc-btn {
    top: 1em;
    left: 1em;
  }

  #toc-toggle:checked ~ main {
    margin-left: var(--sidebar-width);
  }

  .overlay {
    display: none !important;
  }

  .hero {
    flex-direction: row;
    text-align: left;
    padding: 5em 3em;
    gap: 3em;
    justify-content: center;
  }

  .hero-cover {
    max-width: 320px;
    flex-shrink: 0;
  }

  .hero-text {
    margin-top: 0;
  }

  .hero-ctas {
    justify-content: flex-start;
  }
}

/* ---- Print ---- */

@media print {
  .sidebar,
  .toc-btn,
  .overlay,
  #toc-toggle,
  .chapter-nav {
    display: none !important;
  }

  main {
    margin-left: 0 !important;
    padding: 0;
  }
}
