:root {
  --ink: #1c2430;
  --muted: #5b6573;
  --paper: #f4efe6;
  --card: #fffcf7;
  --line: #d9d0c2;
  --teal: #1b6b5a;
  --teal-soft: #d7efe7;
  --clay: #c45c26;
  --clay-soft: #f8e4d4;
  --navy: #2c4a7c;
  --navy-soft: #d9e4f5;
  --gold: #c9a227;
  --shadow: 0 10px 30px rgba(28, 36, 48, 0.08);
  --serif: "Source Serif 4", "Times New Roman", serif;
  --sans: "Source Sans 3", "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at top right, #efe6d4 0, transparent 36%),
    var(--paper);
  font-family: var(--sans);
  line-height: 1.65;
}

img,
svg {
  max-width: 100%;
}

a {
  color: var(--teal);
}

code {
  font-family: "Cambria Math", "Times New Roman", serif;
  background: #efe8db;
  padding: 0.08em 0.38em;
  border-radius: 6px;
  font-size: 0.98em;
}

.skip-link {
  position: absolute;
  left: 12px;
  top: -40px;
  background: var(--ink);
  color: white;
  padding: 8px 12px;
  z-index: 20;
}

.skip-link:focus {
  top: 12px;
}

.wrap {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: rgba(244, 239, 230, 0.92);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}

.topbar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 16px;
  min-height: 64px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: inherit;
  text-decoration: none;
  font-weight: 700;
}

.brand-mark {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border-radius: 10px;
  background: var(--ink);
  color: #f4efe6;
  font-family: var(--serif);
}

.nav {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
}

.nav a {
  color: var(--muted);
  text-decoration: none;
  font-size: 0.95rem;
}

.nav a:hover,
.nav a.active {
  color: var(--teal);
}

.nav-toggle {
  display: none;
}

.hero {
  padding: 42px 0 18px;
}

.hero-grid {
  display: grid;
  grid-template-columns: 1.15fr 0.85fr;
  gap: 28px;
  align-items: center;
}

.eyebrow {
  margin: 0 0 8px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-size: 0.78rem;
  color: var(--clay);
  font-weight: 700;
}

article,
h1,
h2,
h3 {
  scroll-margin-top: 84px;
}

h1,
h2,
h3 {
  font-family: var(--serif);
  line-height: 1.25;
  margin: 0 0 12px;
}

h1 {
  font-size: clamp(2rem, 4vw, 3.2rem);
}

h2 {
  font-size: 1.7rem;
}

h3 {
  font-size: 1.28rem;
}

.lead {
  font-size: 1.12rem;
  color: var(--muted);
}

.hero-terms {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.hero-card,
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
}

.hero-card {
  padding: 16px 16px 8px;
}

.hero-card figcaption,
figure figcaption {
  text-align: center;
  color: var(--muted);
  font-size: 0.95rem;
  padding: 6px 4px 10px;
}

.layout {
  display: grid;
  grid-template-columns: 220px 1fr;
  gap: 28px;
  padding: 10px 0 64px;
}

.toc {
  position: sticky;
  top: 84px;
  align-self: start;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 16px;
  border-left: 3px solid var(--gold);
}

.toc p {
  margin: 0 0 4px;
  font-weight: 700;
}

.toc a {
  color: var(--muted);
  text-decoration: none;
  font-size: 0.92rem;
}

.toc a:hover {
  color: var(--ink);
}

.content {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.card {
  padding: 28px;
}

.callout {
  background: var(--teal-soft);
  border-radius: 14px;
  padding: 14px 16px;
  margin: 16px 0;
}

.note {
  color: var(--muted);
  font-style: italic;
}

.formula {
  font-family: var(--serif);
  font-size: 1.15rem;
  background: #f7f1e5;
  border-left: 4px solid var(--gold);
  padding: 10px 14px;
  border-radius: 0 10px 10px 0;
}

.trio {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin: 16px 0;
}

.mini {
  background: #f7f2e8;
  border-radius: 14px;
  padding: 14px;
}

.mini h3 {
  font-size: 1.05rem;
}

.diagram-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
  align-items: start;
  margin: 16px 0;
}

.diagram-row figure,
.play-venn {
  margin: 0;
  background: #f8f4eb;
  border-radius: 14px;
  padding: 8px;
}

.facts {
  margin: 12px 0 0;
  padding-left: 18px;
}

.sheet {
  width: 100%;
  border-collapse: collapse;
  margin: 16px 0;
  font-size: 0.96rem;
}

.sheet caption {
  caption-side: top;
  text-align: left;
  font-weight: 700;
  margin-bottom: 8px;
  font-family: var(--serif);
}

.sheet th,
.sheet td {
  border: 1px solid var(--line);
  padding: 8px 10px;
  vertical-align: top;
}

.sheet thead th {
  background: #ece4d5;
  text-align: left;
}

.sheet tbody tr:nth-child(even) {
  background: #faf6ee;
}

.sheet.tight td,
.sheet.tight th {
  text-align: center;
}

.sheet .yes {
  background: var(--teal-soft);
  font-weight: 700;
}

.grid-table th,
.grid-table td {
  text-align: center;
}

.table-scroll {
  overflow-x: auto;
}

.lex {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 6px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px 6px 3px 10px;
  margin: 2px 0;
  vertical-align: middle;
}

.lex.compact {
  padding: 2px 5px 2px 8px;
  font-size: 0.92em;
}

.lex strong {
  font-family: var(--serif);
}

.ipa,
.respell {
  color: var(--navy);
  font-family: var(--serif);
}

.respell {
  color: var(--clay);
  font-size: 0.92em;
}

.bg {
  color: var(--muted);
}

.lex::after,
.speak-btn {
  content: "";
}

.speak-btn {
  border: 0;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--teal);
  color: white;
  cursor: pointer;
  display: inline-grid;
  place-items: center;
  padding: 0;
}

.speak-btn:hover,
.speak-btn.playing {
  background: var(--clay);
}

.speak-btn svg {
  width: 14px;
  height: 14px;
  fill: currentColor;
}

.venn .universe {
  fill: #fffdf8;
  stroke: #b7ad9d;
  stroke-width: 1.5;
}

.venn .u-label,
.venn .set-label,
.venn .tiny,
.venn .chip-label {
  font-family: var(--serif);
  fill: var(--ink);
}

.venn .tiny {
  font-size: 12px;
  fill: var(--muted);
}

.venn .fill-a {
  fill: rgba(27, 107, 90, 0.28);
}

.venn .fill-b {
  fill: rgba(44, 74, 124, 0.28);
}

.venn .fill-a.nested {
  fill: rgba(196, 92, 38, 0.35);
}

.venn .fill-union,
.venn .fill-inter,
.venn .fill-diff,
.venn .fill-sym,
.venn .fill-comp {
  fill: rgba(196, 92, 38, 0.42);
}

.venn .ghost {
  fill: transparent;
}

.venn .stroke-a {
  fill: none;
  stroke: var(--teal);
  stroke-width: 2.4;
}

.venn .stroke-b {
  fill: none;
  stroke: var(--navy);
  stroke-width: 2.4;
}

.play-toolbar,
.modes {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.mode,
.ghost-btn,
.op-label + select {
  font: inherit;
}

.mode,
.ghost-btn {
  border: 1px solid var(--line);
  background: white;
  border-radius: 999px;
  padding: 8px 14px;
  cursor: pointer;
}

.mode.active {
  background: var(--teal);
  color: white;
  border-color: var(--teal);
}

.universe-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 16px 0;
}

.chip {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: 2px solid var(--line);
  background: white;
  font: 700 1.05rem var(--serif);
  cursor: pointer;
}

.chip.in-a {
  background: var(--teal-soft);
  border-color: var(--teal);
}

.chip.in-b {
  background: var(--navy-soft);
  border-color: var(--navy);
}

.chip.in-a.in-b {
  background: linear-gradient(135deg, var(--teal-soft), var(--navy-soft));
  border-color: var(--clay);
}

.play-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
  align-items: start;
}

#op-select {
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: white;
  margin: 6px 0 14px;
}

.results {
  display: grid;
  gap: 8px;
  margin: 0;
}

.results div {
  background: #f7f2e8;
  border-radius: 10px;
  padding: 8px 10px;
}

.results dt {
  font-weight: 700;
  font-family: var(--serif);
}

.results dd {
  margin: 2px 0 0;
}

.glossary {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 10px;
}

.glossary .lex {
  border-radius: 14px;
  padding: 10px;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
}

.page-switch {
  display: flex;
  gap: 8px;
  margin-left: 8px;
}

.page-switch a {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 10px;
  text-decoration: none;
  color: var(--muted);
  font-size: 0.85rem;
}

.page-switch a.now {
  background: var(--ink);
  color: #f4efe6;
  border-color: var(--ink);
}

.field-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 10px;
  margin: 12px 0;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.92rem;
}

.field input,
.field textarea,
.num-box {
  font: inherit;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: white;
}

.field textarea {
  min-height: 90px;
  resize: vertical;
}

.plane,
.chart-card {
  background: #f8f4eb;
  border-radius: 14px;
  padding: 8px;
  margin: 0;
}

.plane-axis {
  stroke: #8a8172;
  stroke-width: 1.2;
}

.plane-grid {
  stroke: #e4dccb;
  stroke-width: 1;
}

.plane-label {
  font-family: var(--serif);
  font-size: 12px;
  fill: var(--muted);
}

.z-dot {
  stroke: #fff;
  stroke-width: 1.5;
}

.z-line {
  stroke-width: 1.6;
  stroke-dasharray: 4 3;
  opacity: 0.85;
}

.hist {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  height: 180px;
  padding: 8px 4px 0;
}

.hist-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: center;
  min-width: 0;
}

.hist-bar {
  width: 100%;
  background: linear-gradient(180deg, var(--teal), #2a8f78);
  border-radius: 8px 8px 0 0;
  min-height: 4px;
}

.hist-lab {
  font-size: 0.75rem;
  color: var(--muted);
  margin-top: 4px;
  text-align: center;
}

.tree-node {
  fill: #fffdf8;
  stroke: var(--teal);
  stroke-width: 1.6;
}

.bell {
  fill: rgba(27, 107, 90, 0.22);
  stroke: var(--teal);
  stroke-width: 2;
}

.footer {
  border-top: 1px solid var(--line);
  padding: 24px 0 40px;
  color: var(--muted);
}

@media (max-width: 980px) {
  .hero-grid,
  .layout,
  .trio,
  .diagram-row,
  .play-grid {
    grid-template-columns: 1fr;
  }

  .toc {
    position: static;
    flex-direction: row;
    flex-wrap: wrap;
    border-left: 0;
    padding: 0 0 8px;
  }

  .nav-toggle {
    display: inline-flex;
    border: 1px solid var(--line);
    background: white;
    border-radius: 999px;
    padding: 8px 14px;
  }

  .nav {
    display: none;
    position: absolute;
    right: 16px;
    top: 64px;
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 12px;
    flex-direction: column;
    box-shadow: var(--shadow);
  }

  .nav.open {
    display: flex;
  }
}

@media (max-width: 640px) {
  .card {
    padding: 18px;
  }

  .lex {
    border-radius: 14px;
  }
}
