/* Shared styles for every chapter page (chapter01.html, chapter02.html, …). */

:root {
  --bg: #e9e3d8;
  --surface: #f4efe6;
  --surface-2: #fbf8f3;
  --ink: #1c1916;
  --muted: #5e584f;
  --line: #ddd4c6;
  --accent: #0f5c56;
  --accent-soft: #e3f0ee;
  --on-accent: #f7f4ee;
  --warn: #8a3b12;
  --warn-soft: #f8ebe3;
  --bad: #8f2d2d;
  --good: #0f5c56;
  --shadow: 0 1px 0 rgba(28, 25, 22, 0.04), 0 14px 36px rgba(28, 25, 22, 0.06);
  --serif: "Literata", "Iowan Old Style", Palatino, Georgia, serif;
  --sans: "Source Sans 3", "Segoe UI", sans-serif;
  --radius: 16px;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121614;
    --surface: #1a201d;
    --surface-2: #212824;
    --ink: #f3efe6;
    --muted: #c2bbb0;
    --line: #343c38;
    --accent: #7dcec4;
    --accent-soft: #1a3330;
    --on-accent: #10211f;
    --warn: #f0b089;
    --warn-soft: #3a261c;
    --bad: #f0a0a0;
    --good: #7dcec4;
    --shadow: 0 1px 0 rgba(0, 0, 0, 0.2), 0 14px 36px rgba(0, 0, 0, 0.28);
  }
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  background:
    radial-gradient(1200px 420px at 10% -10%, rgba(15, 92, 86, 0.08), transparent 60%),
    var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 1.0625rem;
  line-height: 1.6;
  text-rendering: optimizeLegibility;
}

img {
  max-width: 100%;
  height: auto;
}

a {
  color: var(--accent);
  text-underline-offset: 0.16em;
}

a:focus-visible,
.speak:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

::selection {
  background: var(--accent-soft);
  color: var(--ink);
}

.skip {
  position: absolute;
  left: 1rem;
  top: 0.5rem;
  transform: translateY(-200%);
  z-index: 30;
  background: var(--accent);
  color: var(--on-accent);
  text-decoration: none;
  padding: 0.4rem 0.75rem;
  border-radius: 8px;
}

.skip:focus {
  transform: none;
}

.wrap {
  width: min(1100px, calc(100% - 2rem));
  margin-inline: auto;
}

.site-header {
  position: sticky;
  top: 0;
  z-index: 10;
  border-top: 4px solid var(--accent);
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px);
}

.site-header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  min-height: 3.6rem;
  padding: 0.55rem 0;
}

.brand {
  color: var(--ink);
  text-decoration: none;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.chapter-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.chapter-nav a {
  text-decoration: none;
  color: var(--ink);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.22rem 0.7rem;
  font-size: 0.92rem;
}

.chapter-nav a[aria-current="page"] {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
}

.chapter {
  padding-bottom: 4rem;
}

.hero {
  padding-top: 2.1rem;
}

.kicker,
.toc-label,
.role {
  margin: 0;
  color: var(--accent);
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  font-size: 0.78rem;
}

.hero h1,
.block h2,
.card-title h3,
.choice h3 {
  font-family: var(--serif);
  font-weight: 650;
  letter-spacing: -0.03em;
  line-height: 1.12;
}

.hero h1 {
  margin: 0.25rem 0 0;
  font-size: clamp(2.2rem, 5vw, 3.45rem);
  overflow-wrap: break-word;
}

.en-title {
  margin: 0.35rem 0 0;
  font-family: var(--serif);
  font-style: italic;
  font-size: 1.25rem;
  color: var(--muted);
}

.lede {
  margin: 0.9rem 0 0;
  max-width: 64ch;
  font-size: 1.18rem;
}

.legend {
  max-width: 68ch;
  margin: 1.15rem 0 0;
  padding: 0.85rem 1rem 0.9rem 2rem;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.legend li + li {
  margin-top: 0.2rem;
}

.speech-fallback {
  max-width: 68ch;
  margin: 1rem 0 0;
  padding: 0.8rem 1rem;
  border-radius: 12px;
  background: var(--warn-soft);
  border-left: 3px solid var(--warn);
}

.toc-label {
  margin-top: 1.8rem;
}

.toc {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin-top: 0.55rem;
}

.toc a {
  text-decoration: none;
  color: var(--ink);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.32rem 0.72rem;
  font-size: 0.95rem;
}

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

.block {
  margin-top: 3.15rem;
}

.block h2 {
  margin: 0;
  font-size: clamp(1.6rem, 3vw, 2.15rem);
}

.block > p,
.why,
.card-note,
.note {
  max-width: 68ch;
}

.block > p,
.card-note,
.why {
  margin: 0.7rem 0 0;
}

.note {
  margin: 1rem 0 0;
  padding: 0.85rem 1rem;
  background: var(--accent-soft);
  border-radius: 12px;
  border-left: 3px solid var(--accent);
}

.note--warn {
  background: var(--warn-soft);
  border-left-color: var(--warn);
}

.paradigm,
.examples,
.fix-list,
.recap {
  list-style: none;
  margin: 1rem 0 0;
  padding: 0;
}

.paradigm,
.fix-list {
  display: grid;
  gap: 0.75rem;
}

.paradigm-item,
.choice,
.card,
.fix,
.table-scroll,
.example-panel,
.pair {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.paradigm-item,
.choice,
.card,
.fix {
  padding: 0.95rem 1rem 1rem;
}

.role {
  margin-bottom: 0.45rem;
}

.choice-grid,
.card-grid,
.pair-grid {
  display: grid;
  gap: 0.8rem;
  margin-top: 1.1rem;
}

.choice-grid {
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 200px), 1fr));
}

.card-grid {
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 300px), 1fr));
}

.index-list {
  display: grid;
  gap: 0.8rem;
  margin-top: 1.1rem;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 280px), 1fr));
}

.index-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.35rem;
  padding: 1rem 1.05rem 1.1rem;
  text-decoration: none;
  color: inherit;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.index-card:hover {
  border-color: var(--accent);
}

.index-card h3 {
  margin: 0;
  font-family: var(--serif);
  font-weight: 650;
  font-size: 1.35rem;
  letter-spacing: -0.03em;
  line-height: 1.15;
}

.index-card p {
  margin: 0;
}

.index-card .en-title {
  font-size: 1.05rem;
}

.choice h3 {
  margin: 0;
  font-size: 1.25rem;
}

.choice p,
.choice-forms {
  margin: 0.4rem 0 0;
}

.choice-forms {
  font-family: var(--serif);
  font-weight: 650;
  letter-spacing: -0.02em;
  font-size: 1.05rem;
}

.table-scroll {
  overflow-x: auto;
  margin-top: 1rem;
  box-shadow: none;
}

.ref-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.98rem;
}

.ref-table th,
.ref-table td {
  padding: 0.62rem 0.75rem;
  text-align: left;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}

.ref-table thead th {
  background: var(--surface);
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 700;
  white-space: nowrap;
}

.ref-table tbody th {
  font-weight: 650;
  min-width: 5.5rem;
}

.ref-table td:not(:first-child) {
  white-space: nowrap;
}

.ref-table.loose-table td,
.ref-table.loose-table th {
  white-space: normal;
  vertical-align: top;
}

.ref-table tr:last-child td,
.ref-table tr:last-child th {
  border-bottom: 0;
}

.ref-table tbody tr:hover {
  background: color-mix(in srgb, var(--accent-soft) 70%, transparent);
}

.ref-table caption {
  caption-side: bottom;
  text-align: left;
  padding: 0.75rem 0.85rem 0.9rem;
  color: var(--muted);
  font-size: 0.92rem;
}

.person {
  display: block;
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.symbols {
  display: grid;
  gap: 0.65rem;
  margin: 1rem 0 0;
}

.symbols div {
  display: grid;
  grid-template-columns: 4.2rem minmax(0, 1fr);
  gap: 0.75rem;
  align-items: baseline;
}

.symbols dt {
  margin: 0;
  font-family: var(--serif);
  font-size: 1.45rem;
  color: var(--accent);
}

.symbols dd {
  margin: 0;
}

.card-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.65rem 0.8rem;
}

.card-title h3 {
  margin: 0;
  font-size: 1.9rem;
}

.gloss {
  margin: 0 0 0 auto;
  max-width: 12rem;
  text-align: right;
  color: var(--muted);
  font-weight: 650;
}

.en {
  margin: 0;
  font-family: var(--serif);
  font-size: 1.14rem;
  font-weight: 500;
  letter-spacing: -0.01em;
  overflow-wrap: break-word;
}

.en strong {
  font-weight: 650;
  color: var(--accent);
}

.ipa {
  margin: 0.12rem 0 0;
  color: var(--accent);
  font-family: "Source Sans 3", "Segoe UI", "Noto Sans", sans-serif;
  font-size: 0.98rem;
  letter-spacing: 0.01em;
  overflow-wrap: anywhere;
}

.bg {
  margin: 0.12rem 0 0;
  color: var(--muted);
  font-size: 0.96rem;
}

.example {
  display: grid;
  grid-template-columns: 2.5rem minmax(0, 1fr);
  grid-template-areas:
    "btn en"
    "btn ipa"
    "btn bg";
  column-gap: 0.75rem;
  row-gap: 0.08rem;
  align-items: center;
}

.example .speak {
  grid-area: btn;
}

.example .en {
  grid-area: en;
}

.example .ipa {
  grid-area: ipa;
}

.example .bg {
  grid-area: bg;
}

.examples {
  margin-top: 0.85rem;
}

.example + .example,
.examples .example + .example {
  border-top: 1px solid var(--line);
  margin-top: 0.7rem;
  padding-top: 0.7rem;
}

.example-panel {
  margin-top: 1rem;
  padding: 0.35rem 1rem 0.95rem;
  box-shadow: none;
}

.pair-grid {
  margin-top: 1rem;
}

.pair {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem 1.25rem;
  padding: 0.95rem 1rem 1rem;
  box-shadow: none;
}

.stack {
  display: grid;
  justify-items: start;
  gap: 0.15rem;
}

.stack .ipa {
  margin-bottom: 0.45rem;
}

.stack .speak--inline {
  white-space: normal;
}

.tag {
  display: inline-block;
  margin-right: 0.35rem;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  vertical-align: 0.12em;
}

.tag--bad {
  color: var(--bad);
}

.tag--good {
  color: var(--good);
}

.badline {
  margin: 0;
  color: var(--muted);
}

.badline [lang="en"] {
  font-family: var(--serif);
  text-decoration: line-through;
  text-decoration-color: var(--bad);
  text-decoration-thickness: 1px;
}

.goodlabel {
  margin: 0.55rem 0 0.4rem;
}

.recap {
  max-width: 68ch;
  margin-top: 0.8rem;
  padding-left: 1.2rem;
  list-style: decimal;
}

.recap li {
  margin-top: 0.4rem;
  padding-left: 0.25rem;
}

.recap li::marker {
  color: var(--accent);
  font-weight: 700;
}

.speak {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  color: var(--accent);
  cursor: pointer;
  font: inherit;
}

.speak:not(.speak--inline) {
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface);
}

.speak:not(.speak--inline):not(:has(svg))::before {
  content: "▶";
  font-size: 0.72rem;
  line-height: 1;
}

.speak:not(.speak--inline):hover {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.speak--inline {
  border: 1px solid transparent;
  border-radius: 0.45rem;
  padding: 0.08rem 0.22rem;
  line-height: 1.35;
  text-align: left;
  font-family: var(--serif);
  font-weight: 650;
}

.speak--inline:not(:has(svg))::before {
  content: "▶";
  font-family: var(--sans);
  font-size: 0.62rem;
  font-weight: 700;
}

.speak--inline:hover,
.speak--inline:focus-visible {
  background: var(--accent-soft);
}

.speak svg {
  width: 1.12rem;
  height: 1.12rem;
  flex: none;
}

.speak--inline svg {
  width: 0.88rem;
  height: 0.88rem;
}

.speak.is-speaking,
.speak.is-speaking:hover {
  background: var(--accent);
  color: var(--on-accent);
  border-color: var(--accent);
}

.speak.is-speaking svg {
  animation: speak-pulse 0.9s ease-in-out infinite;
}

.speak:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

@keyframes speak-pulse {
  50% {
    transform: scale(0.86);
    opacity: 0.55;
  }
}

.site-footer {
  border-top: 1px solid var(--line);
  padding: 1.2rem 0 2rem;
  color: var(--muted);
  font-size: 0.95rem;
}

.site-footer p {
  margin: 0;
}

section[id] {
  scroll-margin-top: 5.2rem;
}

@media (max-width: 720px) {
  section[id] {
    scroll-margin-top: 9rem;
  }
}

@media (max-width: 720px) {
  .site-header-inner {
    align-items: flex-start;
    flex-direction: column;
    padding: 0.7rem 0;
  }

  .pair {
    grid-template-columns: 1fr;
  }

  .gloss {
    margin-left: 3.2rem;
    text-align: left;
  }
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  .speak.is-speaking svg {
    animation: none;
  }
}

@media print {
  body {
    background: #fff;
    color: #000;
  }

  .site-header {
    position: static;
  }

  .speak,
  .toc,
  .toc-label,
  .skip {
    display: none !important;
  }

  .example {
    grid-template-columns: 1fr;
    grid-template-areas:
      "en"
      "ipa"
      "bg";
  }

  .card,
  .fix,
  .choice,
  .paradigm-item,
  .pair,
  .table-scroll,
  .example-panel {
    box-shadow: none;
  }
}
