/* A Book About Turns on a Board — single-page web edition */

:root {
  --sidebar-w: 20rem;
  --measure: 42rem;
  --bg: #fbfaf7;
  --surface: #ffffff;
  --sidebar-bg: #f3f1ea;
  --text: #23201b;
  --muted: #6b6459;
  --rule: #e0ddd2;
  --accent: #0a6cbf;
  --accent-soft: #e6f0fa;
  --mark: #fff2b2;
  --code-bg: #f0eee6;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16150f;
    --surface: #1c1b16;
    --sidebar-bg: #12110c;
    --text: #e7e3d8;
    --muted: #9a9384;
    --rule: #34322a;
    --accent: #6bb7ff;
    --accent-soft: #1e2a38;
    --mark: #5a4b12;
    --code-bg: #26241d;
  }
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; scroll-padding-top: 1.5rem; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Charter, Georgia, "Iowan Old Style", "Palatino Linotype", "Times New Roman", serif;
  font-size: 1.075rem;
  line-height: 1.68;
  -webkit-text-size-adjust: 100%;
}

.skip-link {
  position: absolute;
  left: -999px;
}
.skip-link:focus {
  left: 1rem;
  top: 1rem;
  z-index: 100;
  background: var(--surface);
  padding: 0.5rem 0.9rem;
  border: 1px solid var(--rule);
  border-radius: 0.4rem;
}

/* ---------- layout ---------- */
.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: var(--sidebar-w);
  background: var(--sidebar-bg);
  border-right: 1px solid var(--rule);
  overflow-y: auto;
  overscroll-behavior: contain;
}
.sidebar-inner { padding: 1.4rem 1.1rem 3rem; }

.content {
  margin-left: var(--sidebar-w);
  padding: 3.2rem clamp(1.1rem, 5vw, 4rem) 6rem;
}
.content article,
.content .colophon { max-width: var(--measure); margin-inline: auto; }

/* ---------- sidebar content ---------- */
.brand {
  display: block;
  text-decoration: none;
  color: inherit;
  margin-bottom: 1rem;
  line-height: 1.3;
}
.brand strong { display: block; font-size: 1.02rem; }
.brand span { display: block; font-size: 0.82rem; color: var(--muted); margin-top: 0.15rem; }

.search { margin-bottom: 0.9rem; }
#toc-search {
  width: 100%;
  padding: 0.5rem 0.7rem;
  font: inherit;
  font-size: 0.9rem;
  color: inherit;
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: 0.45rem;
}
#toc-search:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

.toc-wrap { font-family: system-ui, -apple-system, "Segoe UI", sans-serif; }
.toc-wrap ul { list-style: none; margin: 0; padding: 0; }
.toc-wrap > ul > li { margin-top: 0.15rem; }
.toc-wrap li ul { margin-left: 0.75rem; border-left: 1px solid var(--rule); padding-left: 0.4rem; }
.toc-wrap a {
  display: block;
  padding: 0.2rem 0.4rem;
  font-size: 0.83rem;
  line-height: 1.35;
  color: var(--muted);
  text-decoration: none;
  border-radius: 0.35rem;
}
.toc-wrap > ul > li > a { color: var(--text); font-weight: 600; margin-top: 0.35rem; }
.toc-wrap a:hover { background: var(--accent-soft); color: var(--accent); }
.toc-wrap a.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

/* ---------- topbar / drawer (mobile) ---------- */
.topbar { display: none; }
.scrim { display: none; }

@media (max-width: 60rem) {
  .topbar {
    display: flex;
    align-items: center;
    gap: 0.7rem;
    position: sticky;
    top: 0;
    z-index: 30;
    padding: 0.55rem 0.9rem;
    background: var(--surface);
    border-bottom: 1px solid var(--rule);
  }
  .nav-btn { font-size: 1.3rem; cursor: pointer; padding: 0.1rem 0.4rem; }
  .topbar-title { font-size: 0.9rem; color: var(--muted); }
  .sidebar {
    transform: translateX(-100%);
    transition: transform 0.22s ease;
    z-index: 40;
    box-shadow: 0 0 2rem rgba(0,0,0,0.25);
  }
  #nav-toggle:checked ~ .sidebar { transform: translateX(0); }
  #nav-toggle:checked ~ .scrim {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    z-index: 35;
  }
  .content { margin-left: 0; padding-top: 1.6rem; }
}

/* ---------- typography ---------- */
h1, h2, h3, h4 { font-family: system-ui, -apple-system, "Segoe UI", sans-serif; line-height: 1.22; }
h1 {
  font-size: 1.95rem;
  margin: 3.5rem 0 1.4rem;
  padding-top: 2.2rem;
  border-top: 3px solid var(--rule);
}
#top > h1:first-child { border-top: 0; padding-top: 0; margin-top: 0; }
h2 { font-size: 1.4rem; margin: 2.6rem 0 0.9rem; }
h3 { font-size: 1.13rem; margin: 2rem 0 0.6rem; }
h4 { font-size: 1rem; margin: 1.6rem 0 0.5rem; color: var(--muted); }

p { margin: 0 0 1.05rem; }
a { color: var(--accent); text-decoration-thickness: 1px; text-underline-offset: 2px; }

strong { font-weight: 700; }

hr {
  border: 0;
  height: 1px;
  background: var(--rule);
  margin: 2.4rem auto;
  width: 40%;
}

blockquote {
  margin: 1.4rem 0;
  padding: 0.6rem 1.1rem;
  border-left: 3px solid var(--accent);
  background: var(--accent-soft);
  border-radius: 0 0.4rem 0.4rem 0;
}
blockquote p:last-child { margin-bottom: 0; }

ul, ol { padding-left: 1.4rem; margin: 0 0 1.1rem; }
li { margin: 0.3rem 0; }

code {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.9em;
  background: var(--code-bg);
  padding: 0.1rem 0.35rem;
  border-radius: 0.3rem;
}
pre {
  background: var(--code-bg);
  padding: 1rem;
  border-radius: 0.5rem;
  overflow-x: auto;
}
pre code { background: none; padding: 0; }

figure { margin: 1.8rem 0; }
img { max-width: 100%; height: auto; display: block; margin-inline: auto; border-radius: 0.4rem; }
figure.video video { width: 100%; border-radius: 0.5rem; background: #000; }
figcaption, figure > em, .content article em:only-child {
  display: block;
  font-size: 0.88rem;
  color: var(--muted);
  text-align: center;
  margin-top: 0.5rem;
  font-style: italic;
}

mark, .content mark { background: var(--mark); color: inherit; padding: 0 0.15rem; border-radius: 0.2rem; }

.colophon {
  margin-top: 5rem;
  padding-top: 1.4rem;
  border-top: 1px solid var(--rule);
  font-size: 0.85rem;
  color: var(--muted);
  font-family: system-ui, -apple-system, sans-serif;
}

.totop {
  position: fixed;
  right: 1.1rem;
  bottom: 1.1rem;
  z-index: 25;
  width: 2.6rem;
  height: 2.6rem;
  border-radius: 50%;
  border: 1px solid var(--rule);
  background: var(--surface);
  color: var(--text);
  font-size: 1.1rem;
  cursor: pointer;
  box-shadow: 0 2px 10px rgba(0,0,0,0.12);
}

/* ---------- print ---------- */
@media print {
  .sidebar, .topbar, .scrim, .totop, .skip-link { display: none !important; }
  .content { margin: 0; padding: 0; }
  body { background: #fff; color: #000; font-size: 11pt; }
  h1 { break-before: page; border: 0; }
  #top > h1:first-child { break-before: avoid; }
  figure, img, blockquote, pre { break-inside: avoid; }
  a { color: #000; text-decoration: none; }
}
