:root {
  --paper: #f4f5f2;
  --paper-alt: #e9eeec;
  --ink: #171a19;
  --muted: #65706c;
  --line: #cbd2ce;
  --accent: #e24b32;
  --accent-2: #096b78;
  --accent-3: #667a35;
  --header: rgba(244, 245, 242, 0.88);
  --max: 1440px;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --sans: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

[data-theme="dark"] {
  --paper: #171a19;
  --paper-alt: #202624;
  --ink: #f1f3ef;
  --muted: #a4afaa;
  --line: #3b4440;
  --accent: #ff735b;
  --accent-2: #75c4cf;
  --accent-3: #b6c97c;
  --header: rgba(23, 26, 25, 0.9);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; scroll-padding-top: 6rem; }
body {
  margin: 0;
  color: var(--ink);
  background: var(--paper);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.5;
  letter-spacing: 0;
  transition: color 180ms ease, background 180ms ease;
}
button, input { font: inherit; }
button { color: inherit; }

.masthead {
  position: sticky;
  z-index: 20;
  top: 0;
  min-height: 68px;
  padding: 0 3vw;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
  background: var(--header);
  backdrop-filter: blur(18px);
}

.wordmark {
  display: inline-flex;
  align-items: center;
  gap: .75rem;
  color: var(--ink);
  text-decoration: none;
  font-weight: 700;
}
.wordmark-mark {
  width: 2rem;
  height: 2rem;
  display: grid;
  place-items: center;
  color: var(--paper);
  background: var(--ink);
  font-family: var(--serif);
  font-size: 1.2rem;
}
.masthead-tools { display: flex; align-items: center; gap: 1rem; }
.total-count { color: var(--muted); font-size: .78rem; text-transform: uppercase; }
.icon-button, .back-to-top {
  width: 2.5rem;
  height: 2.5rem;
  padding: 0;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  background: transparent;
  cursor: pointer;
}
.icon-button svg, .back-to-top svg, .search-shell svg {
  width: 1.15rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.icon-button:hover { border-color: var(--ink); }

main { max-width: var(--max); margin: 0 auto; }
.intro {
  min-height: min(640px, calc(100vh - 68px));
  padding: clamp(4rem, 9vw, 8rem) 5vw 4rem;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(18rem, 34rem);
  column-gap: 6vw;
  align-content: center;
  border-bottom: 1px solid var(--line);
}
.intro-kicker {
  grid-column: 1 / -1;
  margin-bottom: 1.6rem;
  color: var(--accent);
  font-size: .76rem;
  font-weight: 750;
  text-transform: uppercase;
}
h1 {
  margin: 0;
  max-width: 13ch;
  font-family: var(--serif);
  font-size: clamp(3.25rem, 7vw, 7.3rem);
  font-weight: 500;
  line-height: .88;
  letter-spacing: 0;
}
.intro-copy {
  margin: .35rem 0 3rem;
  align-self: end;
  color: var(--muted);
  font-family: var(--serif);
  font-size: clamp(1.25rem, 2vw, 1.65rem);
  line-height: 1.35;
}
.search-shell {
  grid-column: 2;
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: .85rem;
  align-items: center;
  padding: .8rem 0;
  border-bottom: 2px solid var(--ink);
}
.search-shell input {
  min-width: 0;
  padding: 0;
  border: 0;
  outline: 0;
  color: var(--ink);
  background: transparent;
  font-size: 1rem;
}
.search-shell input::placeholder { color: var(--muted); }
kbd { color: var(--muted); font: .72rem var(--sans); }
.view-controls {
  grid-column: 2;
  margin-top: 1.4rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  color: var(--muted);
  font-size: .74rem;
  text-transform: uppercase;
}
.segmented { display: flex; border: 1px solid var(--line); }
.density-button {
  min-width: 5.5rem;
  padding: .55rem .8rem;
  border: 0;
  background: transparent;
  cursor: pointer;
  font-size: .72rem;
}
.density-button + .density-button { border-left: 1px solid var(--line); }
.density-button.active { color: var(--paper); background: var(--ink); }

.reader-layout { display: grid; grid-template-columns: 16rem minmax(0, 1fr); }
.session-nav {
  position: sticky;
  top: 68px;
  height: calc(100vh - 68px);
  padding: 2rem 1.5rem 3rem 3vw;
  overflow: auto;
  border-right: 1px solid var(--line);
}
.session-nav-label {
  margin-bottom: 1.25rem;
  color: var(--muted);
  font-size: .7rem;
  font-weight: 700;
  text-transform: uppercase;
}
.session-link {
  display: grid;
  grid-template-columns: 2rem 1fr auto;
  gap: .4rem;
  padding: .7rem 0;
  color: var(--muted);
  border-bottom: 1px solid var(--line);
  text-decoration: none;
  font-size: .78rem;
  line-height: 1.25;
}
.session-link:hover, .session-link.active { color: var(--ink); }
.session-link.active .session-number { color: var(--accent); }
.session-link-count { font-variant-numeric: tabular-nums; }

.vocabulary { min-width: 0; }
.batch {
  padding: clamp(3rem, 6vw, 6rem) clamp(1.5rem, 5vw, 5rem);
  border-bottom: 1px solid var(--line);
}
.batch:nth-child(3n + 2) { background: var(--paper-alt); }
.batch:nth-child(3n + 3) .batch-number { color: var(--accent-2); }
.batch:nth-child(3n + 1) .batch-number { color: var(--accent-3); }
.batch-header {
  display: grid;
  grid-template-columns: 7rem minmax(0, 1fr) auto;
  gap: 1.25rem;
  align-items: start;
  margin-bottom: 2.5rem;
}
.batch-number { color: var(--accent); font-size: .78rem; font-weight: 750; text-transform: uppercase; }
.batch h2 {
  margin: -.25rem 0 .5rem;
  font-family: var(--serif);
  font-size: clamp(2rem, 4vw, 4rem);
  font-weight: 500;
  line-height: 1;
  letter-spacing: 0;
}
.batch-note { max-width: 46rem; margin: 0; color: var(--muted); font-family: var(--serif); font-size: 1.05rem; }
.batch-count { color: var(--muted); font-size: .72rem; text-transform: uppercase; white-space: nowrap; }
.entries { border-top: 1px solid var(--ink); }
.entry {
  display: grid;
  grid-template-columns: minmax(11rem, .8fr) minmax(16rem, 1.2fr);
  gap: 2rem;
  padding: 1.05rem 0;
  border-bottom: 1px solid var(--line);
}
.entry-word { font-family: var(--serif); font-size: 1.24rem; line-height: 1.25; }
.entry-definition { color: var(--muted); align-self: center; }
.compact .entry { padding: .58rem 0; }
.compact .entry-word { font-size: 1.05rem; }
.empty-state { padding: 8rem 2rem; text-align: center; color: var(--muted); font-family: var(--serif); font-size: 1.5rem; }
.highlight { color: var(--ink); background: color-mix(in srgb, var(--accent) 22%, transparent); }

.back-to-top {
  position: fixed;
  right: 1.25rem;
  bottom: 1.25rem;
  z-index: 10;
  color: var(--paper);
  background: var(--ink);
  opacity: 0;
  pointer-events: none;
  transform: translateY(.6rem);
  transition: 180ms ease;
}
.back-to-top.visible { opacity: 1; pointer-events: auto; transform: none; }

@media (max-width: 850px) {
  .masthead { padding: 0 1rem; }
  .wordmark { font-size: .88rem; }
  .total-count { display: none; }
  .intro {
    min-height: auto;
    padding: 4rem 1.25rem 3rem;
    display: block;
  }
  h1 { font-size: clamp(3.5rem, 16vw, 5.5rem); }
  .intro-copy { margin: 2rem 0 2.5rem; max-width: 30rem; }
  .search-shell { margin-top: 1rem; }
  .view-controls { margin-top: 1.2rem; }
  .reader-layout { display: block; }
  .session-nav {
    position: sticky;
    z-index: 15;
    top: 68px;
    width: 100%;
    height: auto;
    padding: 0 1rem;
    overflow-x: auto;
    border: 0;
    border-bottom: 1px solid var(--line);
    background: var(--header);
    backdrop-filter: blur(18px);
  }
  .session-nav-label { display: none; }
  .session-nav nav { display: flex; width: max-content; }
  .session-link {
    width: auto;
    min-width: 5rem;
    display: flex;
    justify-content: center;
    padding: .85rem 1rem;
    border: 0;
    border-right: 1px solid var(--line);
  }
  .session-link-title { display: none; }
  .batch { padding: 3.5rem 1.25rem; }
  .batch-header { grid-template-columns: 1fr auto; gap: .6rem 1rem; }
  .batch-number { grid-column: 1; }
  .batch-title-wrap { grid-column: 1 / -1; grid-row: 2; }
  .batch-count { grid-column: 2; grid-row: 1; }
  .entry { grid-template-columns: 1fr; gap: .35rem; padding: 1rem 0; }
  .entry-word { font-size: 1.18rem; }
  .entry-definition { font-size: .92rem; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { transition: none !important; }
}
