/* baroque-ear — a 17th-century treatise, printed alive.
   Type: IM Fell English (display, a digitization of 1670s Fell types),
   EB Garamond (body). Palette: aged paper, iron-gall ink, rubricated
   vermilion, ochre, slate. */

:root {
  --paper: #f3ead6;
  --paper-deep: #ecdfc2;
  --paper-plate: #f7f0df;
  --ink: #2b2118;
  --ink-faint: #5c5040;
  --verm: #9e2a15;
  --ochre: #8a6d1f;
  --slate: #3d5468;
  --rule: #b9a884;
  --rule-dark: #8a7a5c;
  --serif: "EB Garamond", "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --fell: "IM Fell English", "EB Garamond", Georgia, serif;
  --fell-sc: "IM Fell English SC", "IM Fell English", Georgia, serif;
}

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

html { scroll-behavior: smooth; }

body {
  background: var(--paper);
  color: var(--ink);
  font-family: var(--serif);
  font-size: 1.19rem;
  line-height: 1.62;
  /* Laid-paper grain */
  background-image:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='240' height='240'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.8' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='240' height='240' filter='url(%23n)' opacity='0.05'/%3E%3C/svg%3E");
}

::selection { background: rgba(158, 42, 21, 0.22); }

a { color: var(--verm); text-decoration-thickness: 1px; text-underline-offset: 2px; }
a:hover { color: #c0361b; }

em { font-style: italic; }

/* ---------- layout ---------- */

.page {
  max-width: 100rem;
  margin: 0 auto;
  padding: 0 1.2rem 6rem;
}

.chapter {
  display: grid;
  grid-template-columns: minmax(0, 44rem) 15rem;
  justify-content: center;
  column-gap: 3.2rem;
  row-gap: 0;
  margin-top: 5.5rem;
}

.chapter > * { grid-column: 1; }
.chapter > .note { grid-column: 2; }
.chapter > .plate, .chapter > .full { grid-column: 1 / -1; max-width: 62rem; justify-self: center; width: 100%; }

@media (max-width: 900px) {
  .chapter { display: block; }
  .chapter > .note {
    margin: 1.2rem 0;
    border-left: 2px solid var(--rule);
    padding-left: 1rem;
  }
}

/* ---------- title page ---------- */

header.frontis {
  text-align: center;
  padding: 5.5rem 1rem 3.5rem;
  max-width: 46rem;
  margin: 0 auto;
}

.frontis .rule-orn {
  color: var(--rule-dark);
  letter-spacing: 0.8em;
  font-size: 1rem;
  margin: 1.4rem 0;
}

.frontis h1 {
  font-family: var(--fell);
  font-weight: 400;
  font-size: clamp(2.6rem, 7vw, 4.6rem);
  line-height: 1.06;
  letter-spacing: 0.01em;
  margin: 0.6rem 0;
}

.frontis h1 .red { color: var(--verm); }

.frontis .subtitle {
  font-family: var(--fell);
  font-style: italic;
  font-size: 1.35rem;
  color: var(--ink-faint);
  max-width: 34rem;
  margin: 1rem auto 0;
  line-height: 1.5;
}

.frontis .imprint {
  margin-top: 2.6rem;
  font-family: var(--fell-sc);
  font-size: 0.95rem;
  letter-spacing: 0.18em;
  color: var(--ink-faint);
}

.frontis .imprint .anno { color: var(--verm); }

.headphones {
  margin: 2.2rem auto 0;
  max-width: 30rem;
  font-size: 1.02rem;
  font-style: italic;
  color: var(--ink-faint);
  border: 1px solid var(--rule);
  border-radius: 2px;
  padding: 0.7rem 1.1rem;
  background: var(--paper-plate);
}

/* ---------- table of contents ---------- */

nav.toc {
  max-width: 44rem;
  margin: 2rem auto 0;
  border-top: 3px double var(--rule-dark);
  border-bottom: 3px double var(--rule-dark);
  padding: 1.4rem 1.6rem;
  column-count: 2;
  column-gap: 3rem;
}

@media (max-width: 700px) { nav.toc { column-count: 1; } }

nav.toc a {
  display: block;
  text-decoration: none;
  color: var(--ink);
  padding: 0.18rem 0;
  font-size: 1.05rem;
  break-inside: avoid;
}

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

nav.toc .n {
  font-family: var(--fell-sc);
  color: var(--verm);
  display: inline-block;
  min-width: 2.6rem;
  letter-spacing: 0.08em;
}

/* ---------- chapters ---------- */

.chapnum {
  font-family: var(--fell-sc);
  color: var(--verm);
  letter-spacing: 0.35em;
  font-size: 1.05rem;
  text-align: center;
}

h2 {
  font-family: var(--fell);
  font-weight: 400;
  font-size: clamp(1.9rem, 4.5vw, 2.7rem);
  text-align: center;
  line-height: 1.15;
  margin: 0.3rem 0 0.6rem;
}

h2 + .epigraph {
  text-align: center;
  font-style: italic;
  color: var(--ink-faint);
  font-size: 1.05rem;
  max-width: 34rem;
  margin: 0 auto 1.8rem;
}

.epigraph .attr { font-style: normal; font-size: 0.9rem; letter-spacing: 0.06em; }

h3 {
  font-family: var(--fell);
  font-weight: 400;
  font-size: 1.45rem;
  margin: 2.2rem 0 0.6rem;
}

p { margin: 0 0 1.1rem; }

/* Rubricated drop cap for each chapter's opening paragraph */
p.opener::first-letter {
  font-family: var(--fell);
  float: left;
  font-size: 4.3rem;
  line-height: 0.82;
  padding: 0.08em 0.12em 0 0;
  color: var(--verm);
}

.term { font-weight: 600; letter-spacing: 0.01em; }
.term-it { font-style: italic; font-weight: 600; }

/* margin notes */
.note {
  font-size: 0.98rem;
  line-height: 1.5;
  color: var(--ink-faint);
  align-self: start;
}

.note .note-head {
  font-family: var(--fell-sc);
  font-size: 0.85rem;
  letter-spacing: 0.14em;
  color: var(--verm);
  display: block;
  margin-bottom: 0.2rem;
}

.note + .note { margin-top: 1.2rem; }

/* ---------- plates (the interactive engravings) ---------- */

.plate {
  background: var(--paper-plate);
  border: 1px solid var(--rule-dark);
  outline: 3px double var(--rule-dark);
  outline-offset: 4px;
  padding: 1.5rem 1.6rem 1.3rem;
  margin: 2.4rem 0 2.6rem;
}

.plate-head {
  display: flex;
  align-items: baseline;
  gap: 0.9rem;
  flex-wrap: wrap;
  border-bottom: 1px solid var(--rule);
  padding-bottom: 0.7rem;
  margin-bottom: 1rem;
}

.plate-num {
  font-family: var(--fell-sc);
  letter-spacing: 0.22em;
  font-size: 0.92rem;
  color: var(--verm);
  white-space: nowrap;
}

.plate-title {
  font-family: var(--fell);
  font-style: italic;
  font-size: 1.18rem;
  color: var(--ink);
}

.plate-caption {
  font-size: 0.98rem;
  font-style: italic;
  color: var(--ink-faint);
  margin-top: 0.8rem;
}

/* A/B pairs */
.ab { display: grid; grid-template-columns: 1fr 1fr; gap: 1.4rem; }
@media (max-width: 860px) { .ab { grid-template-columns: 1fr; } }

.ab .half { min-width: 0; }

.ab .half-label {
  font-family: var(--fell-sc);
  letter-spacing: 0.12em;
  font-size: 0.95rem;
  margin-bottom: 0.4rem;
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.ab .half-label .ab-letter {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.5rem; height: 1.5rem;
  border: 1.5px solid var(--ink);
  border-radius: 50%;
  font-size: 0.85rem;
}

/* ---------- controls ---------- */

button { font-family: inherit; cursor: pointer; }

.play {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  background: var(--ink);
  color: var(--paper);
  border: none;
  border-radius: 2px;
  font-family: var(--fell-sc);
  letter-spacing: 0.14em;
  font-size: 0.95rem;
  padding: 0.5rem 1.1rem 0.42rem;
  box-shadow: 2px 2px 0 rgba(43, 33, 24, 0.25);
  transition: transform 0.06s ease, box-shadow 0.06s ease, background 0.12s;
}

.play::before { content: '▶'; font-size: 0.75rem; transform: translateY(-1px); }
.play.playing { background: var(--verm); }
.play.playing::before { content: '■'; }
.play:hover { background: #463628; }
.play.playing:hover { background: #b23520; }
.play:active { transform: translate(1px, 1px); box-shadow: 1px 1px 0 rgba(43, 33, 24, 0.25); }

.controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.8rem 1.2rem;
  margin-bottom: 0.9rem;
}

.layers { display: flex; flex-wrap: wrap; gap: 0.4rem 1.1rem; font-size: 1rem; }

.layers label {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  cursor: pointer;
  color: var(--ink-faint);
}

.layers input { accent-color: var(--verm); width: 1rem; height: 1rem; }

.layers .swatch {
  width: 0.85rem; height: 0.55rem;
  border-radius: 1px;
  display: inline-block;
}

.stepper { display: flex; flex-wrap: wrap; gap: 0.5rem; }

.stepper button {
  background: none;
  border: 1px solid var(--rule-dark);
  border-radius: 2px;
  font-family: var(--serif);
  font-size: 0.98rem;
  padding: 0.35rem 0.8rem;
  color: var(--ink);
}

.stepper button:hover { border-color: var(--verm); color: var(--verm); }

.word-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(15rem, 1fr));
  gap: 1.2rem;
}

.word-card {
  border: 1px solid var(--rule);
  background: var(--paper-plate);
  padding: 0.9rem 1rem 0.7rem;
}

.word-card .word {
  font-family: var(--fell);
  font-style: italic;
  font-size: 1.5rem;
  margin-bottom: 0.1rem;
}

.word-card .gloss {
  font-size: 0.92rem;
  color: var(--ink-faint);
  font-style: italic;
  margin-bottom: 0.5rem;
}

.word-card .roll { margin-top: 0.5rem; }

/* ---------- the rolls ---------- */

.rollbox { overflow-x: auto; }

.roll { display: block; }
.roll-beat { stroke: rgba(138, 122, 92, 0.18); stroke-width: 0.6; }
.roll-bar { stroke: rgba(138, 122, 92, 0.45); stroke-width: 0.9; }
.roll-c { stroke: rgba(138, 122, 92, 0.25); stroke-width: 0.5; stroke-dasharray: 2 3; }
.roll-note { opacity: 0.88; transition: opacity 0.1s; }
.roll-note.on { opacity: 1; stroke: var(--verm); stroke-width: 1.4; }
.roll-note.muted { opacity: 0.13; }
.roll-head { stroke: var(--verm); stroke-width: 1.2; opacity: 0.85; }
.roll-ann-line { stroke: rgba(158, 42, 21, 0.3); stroke-width: 0.7; stroke-dasharray: 3 3; }
.roll-ann { font-family: var(--serif); font-style: italic; font-size: 8.5px; fill: var(--verm); }
.roll-lyric { font-family: var(--serif); font-style: italic; font-size: 9px; fill: var(--ink-faint); }

/* ---------- comparison table (ch. X) ---------- */

table.versus {
  width: 100%;
  border-collapse: collapse;
  margin: 1.6rem 0;
  font-size: 1.04rem;
}

table.versus th {
  font-family: var(--fell-sc);
  letter-spacing: 0.12em;
  font-weight: 400;
  font-size: 1rem;
  text-align: left;
  border-bottom: 2px solid var(--rule-dark);
  padding: 0.5rem 0.8rem;
}

table.versus th:first-child { width: 9rem; }
table.versus td {
  border-bottom: 1px solid var(--rule);
  padding: 0.55rem 0.8rem;
  vertical-align: top;
}

table.versus td:first-child {
  font-family: var(--fell-sc);
  font-size: 0.9rem;
  letter-spacing: 0.08em;
  color: var(--ink-faint);
}

table.versus .ren { color: var(--slate); }
table.versus .bar { color: var(--verm); }

/* ---------- listening links ---------- */

.listen {
  border-left: 3px solid var(--ochre);
  background: rgba(138, 109, 31, 0.06);
  padding: 0.8rem 1.1rem;
  margin: 1.4rem 0;
  font-size: 1.02rem;
}

.listen .listen-head {
  font-family: var(--fell-sc);
  font-size: 0.88rem;
  letter-spacing: 0.16em;
  color: var(--ochre);
  display: block;
  margin-bottom: 0.3rem;
}

.listen ul { list-style: none; }
.listen li { padding: 0.12rem 0; }
.listen li::before { content: '♪ '; color: var(--ochre); }

/* ---------- glossary ---------- */

.glossary dl {
  border-top: 1px solid var(--rule);
  margin-top: 1rem;
}

.glossary dt {
  font-family: var(--fell);
  font-size: 1.2rem;
  padding-top: 0.9rem;
}

.glossary dt .ch-ref {
  font-family: var(--fell-sc);
  font-size: 0.8rem;
  letter-spacing: 0.14em;
  color: var(--verm);
  margin-left: 0.6rem;
  text-decoration: none;
}

.glossary dd {
  padding: 0.15rem 0 0.9rem;
  border-bottom: 1px solid var(--rule);
  color: var(--ink-faint);
  font-size: 1.05rem;
}

/* ---------- section dividers & footer ---------- */

.divider {
  text-align: center;
  color: var(--rule-dark);
  font-size: 1.3rem;
  letter-spacing: 1.2em;
  margin: 3.5rem 0 0;
  user-select: none;
}

footer.colophon {
  text-align: center;
  margin-top: 5rem;
  font-family: var(--fell-sc);
  font-size: 0.9rem;
  letter-spacing: 0.16em;
  color: var(--ink-faint);
}

footer.colophon .rule-orn { letter-spacing: 0.8em; margin-bottom: 1rem; color: var(--rule-dark); }
