:root {
  --bg: #faf7f2;
  --surface: #ffffff;
  --ink: #1f1b16;
  --muted: #655c52;
  --line: #e4ddd2;
  --accent: #a83f19;
  --accent-soft: #f6e7dd;
  --shadow: 0 12px 32px rgba(31, 27, 22, 0.12);

  /* The faces come from fonts.css (ADR 0015). The names after them are used
     only until a face has loaded; each of them has Vietnamese letters. */
  --serif: "Lora", Georgia, "Times New Roman", serif;
  --sans:
    "Be Vietnam Pro", system-ui, -apple-system, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, sans-serif;
  --mono:
    ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;

  --header-height: 60px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #15130f;
    --surface: #1e1b16;
    --ink: #ece6db;
    --muted: #a59b8d;
    --line: #342f27;
    --accent: #f0915e;
    --accent-soft: #33241a;
    --shadow: 0 12px 32px rgba(0, 0, 0, 0.5);
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #15130f;
  --surface: #1e1b16;
  --ink: #ece6db;
  --muted: #a59b8d;
  --line: #342f27;
  --accent: #f0915e;
  --accent-soft: #33241a;
  --shadow: 0 12px 32px rgba(0, 0, 0, 0.5);
  color-scheme: dark;
}

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

html {
  scroll-padding-top: calc(var(--header-height) + 16px);
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 1rem;
  line-height: 1.65;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

main {
  flex: 1;
  width: 100%;
}

a {
  color: var(--accent);
  text-decoration-thickness: 1px;
  text-underline-offset: 0.18em;
}

a:hover {
  text-decoration-thickness: 2px;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

h1,
h2 {
  font-family: var(--serif);
  line-height: 1.15;
  letter-spacing: -0.01em;
  margin: 0;
  text-wrap: balance;
}

.wrap {
  max-width: 1120px;
  margin: 0 auto;
  padding: 0 24px;
}

.skip {
  position: absolute;
  left: 16px;
  top: -60px;
  z-index: 30;
  background: var(--ink);
  color: var(--bg);
  padding: 8px 14px;
  border-radius: 6px;
  text-decoration: none;
}

.skip:focus {
  top: 10px;
}

.num {
  font-family: var(--mono);
  font-size: 0.75rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.eyebrow {
  margin: 0 0 10px;
  font-size: 0.8125rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.eyebrow a {
  color: inherit;
  text-decoration: none;
}

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

.eyebrow .sep {
  margin: 0 8px;
}

/* ------------------------------------------------------------------ header */

.site-header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}

.header-inner {
  min-height: var(--header-height);
  display: flex;
  align-items: center;
  gap: 20px;
}

.brand {
  font-family: var(--serif);
  font-weight: 700;
  font-size: 1.125rem;
  color: var(--ink);
  text-decoration: none;
  white-space: nowrap;
}

.site-nav {
  display: flex;
  gap: 4px;
}

.site-nav a {
  color: var(--muted);
  text-decoration: none;
  font-size: 0.9375rem;
  padding: 6px 10px;
  border-radius: 6px;
  white-space: nowrap;
}

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

.site-nav a[aria-current="page"] {
  color: var(--ink);
  background: var(--accent-soft);
}

.search {
  position: relative;
  margin-left: auto;
  flex: 0 1 300px;
  min-width: 0;
}

.search input {
  width: 100%;
  height: 38px;
  padding: 0 36px 0 12px;
  font: inherit;
  font-size: 0.9375rem;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  appearance: none;
}

.search input::placeholder {
  color: var(--muted);
  opacity: 1;
}

.search input:focus {
  outline: 2px solid var(--accent);
  outline-offset: 0;
  border-color: transparent;
}

.search input::-webkit-search-cancel-button {
  display: none;
}

.search kbd {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  font-family: var(--mono);
  font-size: 0.75rem;
  line-height: 1;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 3px 6px;
  pointer-events: none;
}

.search input:focus + kbd {
  display: none;
}

#search-results {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  width: min(420px, calc(100vw - 32px));
  max-height: min(70vh, 520px);
  overflow-y: auto;
  margin: 0;
  padding: 6px;
  list-style: none;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: var(--shadow);
}

#search-results a {
  display: block;
  padding: 8px 10px;
  border-radius: 6px;
  color: var(--ink);
  text-decoration: none;
}

#search-results [aria-selected="true"] a,
#search-results a:hover {
  background: var(--accent-soft);
}

#search-results .term {
  font-family: var(--serif);
  font-weight: 700;
}

/* The term's name in the page's language, after its English name. */
#search-results .alt {
  margin-left: 8px;
  font-size: 0.875rem;
  color: var(--muted);
}

#search-results .desc {
  display: block;
  font-size: 0.8125rem;
  line-height: 1.45;
  color: var(--muted);
}

.search-empty {
  padding: 10px;
  font-size: 0.875rem;
  color: var(--muted);
}

.icon-button {
  flex: none;
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  color: var(--muted);
  background: none;
  border: 1px solid var(--line);
  border-radius: 8px;
  cursor: pointer;
}

.icon-button:hover {
  color: var(--ink);
}

/* Two links styled as one switch. The current language is the filled half. */
.lang-toggle {
  flex: none;
  display: flex;
  height: 38px;
  padding: 3px;
  gap: 2px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.lang-toggle a {
  display: grid;
  place-items: center;
  min-width: 36px;
  padding: 0 8px;
  font-size: 0.8125rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--muted);
  text-decoration: none;
  border-radius: 5px;
}

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

.lang-toggle a[aria-current="true"] {
  color: var(--ink);
  background: var(--accent-soft);
}

/* -------------------------------------------------------------------- hero */

.hero {
  padding: 64px 0 40px;
  max-width: 44rem;
}

.hero-compact {
  padding-top: 48px;
}

.hero h1 {
  font-size: clamp(2.25rem, 6vw, 3.5rem);
}

.hero .lede {
  margin: 16px 0 0;
  font-family: var(--serif);
  font-size: clamp(1.2rem, 2.6vw, 1.5rem);
  line-height: 1.4;
}

.hero p {
  margin: 16px 0 0;
}

.hero-meta {
  color: var(--muted);
}

.jump ol {
  margin: 28px 0 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.jump a {
  display: inline-flex;
  align-items: baseline;
  gap: 8px;
  padding: 6px 12px;
  font-size: 0.875rem;
  color: var(--ink);
  text-decoration: none;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
}

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

.letters {
  margin-top: 24px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.letters a {
  min-width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  font-family: var(--serif);
  font-weight: 700;
  color: var(--ink);
  text-decoration: none;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

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

/* --------------------------------------------------------------- term list */

.section {
  padding: 36px 0 12px;
  border-top: 1px solid var(--line);
}

.section-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  column-gap: 16px;
  margin-bottom: 16px;
}

.section-head .eyebrow {
  flex-basis: 100%;
  margin-bottom: 4px;
}

.section-head h2 {
  font-size: clamp(1.5rem, 3.4vw, 2rem);
}

.section-head .count {
  margin: 0;
  font-size: 0.875rem;
  color: var(--muted);
}

.term-list {
  margin: 0 -12px;
  padding: 0;
  list-style: none;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 320px), 1fr));
  column-gap: 16px;
}

.term-list a {
  display: grid;
  grid-template-columns: auto 1fr;
  column-gap: 12px;
  align-items: baseline;
  align-content: start;
  height: 100%;
  padding: 12px;
  border-radius: 8px;
  color: var(--ink);
  text-decoration: none;
}

.term-list a:hover {
  background: var(--accent-soft);
}

.term-list .num {
  grid-row: span 2;
}

.term-list .term {
  font-family: var(--serif);
  font-weight: 700;
  font-size: 1.125rem;
  line-height: 1.3;
}

.term-list a:hover .term {
  color: var(--accent);
}

.term-list .desc {
  grid-column: -2 / -1;
  font-size: 0.875rem;
  line-height: 1.5;
  color: var(--muted);
}

.letter-section .term-list a {
  grid-template-columns: 1fr;
}

/* ------------------------------------------------------------------- entry */

.entry-layout {
  display: grid;
  grid-template-columns: 232px minmax(0, 1fr);
  gap: 56px;
  padding: 40px 0 24px;
}

.sidebar {
  position: sticky;
  top: calc(var(--header-height) + 24px);
  align-self: start;
  max-height: calc(100vh - var(--header-height) - 48px);
  overflow-y: auto;
  padding-right: 8px;
  font-size: 0.875rem;
}

.sidebar details + details {
  margin-top: 2px;
}

.sidebar summary {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 6px 8px;
  border-radius: 6px;
  font-weight: 600;
  line-height: 1.35;
  cursor: pointer;
  list-style: none;
}

.sidebar summary::-webkit-details-marker {
  display: none;
}

.sidebar summary:hover {
  background: var(--accent-soft);
}

.sidebar ol {
  margin: 2px 0 10px 13px;
  padding: 0 0 0 12px;
  list-style: none;
  border-left: 1px solid var(--line);
}

.sidebar li a {
  display: block;
  padding: 4px 8px;
  border-radius: 6px;
  line-height: 1.35;
  color: var(--muted);
  text-decoration: none;
}

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

.sidebar li a[aria-current="page"] {
  color: var(--accent);
  font-weight: 600;
  background: var(--accent-soft);
}

.entry {
  max-width: 44rem;
  min-width: 0;
}

.entry h1 {
  font-size: clamp(2.25rem, 6vw, 3.25rem);
  overflow-wrap: anywhere;
}

/* The term's name in the page's language, under its English name. */
.term-alt {
  margin: 6px 0 0;
  font-size: 1.1875rem;
  line-height: 1.4;
  color: var(--muted);
}

.prose {
  margin-top: 24px;
  font-size: 1.0625rem;
  line-height: 1.7;
}

.prose > p:first-child {
  font-family: var(--serif);
  font-size: 1.25rem;
  line-height: 1.55;
}

.prose p,
.prose ul,
.prose ol {
  margin: 0 0 1.15em;
}

.prose li + li {
  margin-top: 0.35em;
}

.prose code {
  font-family: var(--mono);
  font-size: 0.9em;
  padding: 0.1em 0.35em;
  border-radius: 4px;
  background: var(--accent-soft);
}

.prose pre {
  overflow-x: auto;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.prose pre code {
  padding: 0;
  background: none;
}

.prose blockquote {
  margin: 0 0 1.15em;
  padding-left: 16px;
  border-left: 3px solid var(--line);
  color: var(--muted);
}

.label {
  font-style: normal;
  font-weight: 700;
  font-size: 0.8125rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--accent);
}

.table-wrap {
  margin: 0 0 1.15em;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9375rem;
  line-height: 1.5;
}

th,
td {
  padding: 10px 14px;
  text-align: left;
  vertical-align: top;
  border-bottom: 1px solid var(--line);
}

th {
  font-size: 0.8125rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
  white-space: nowrap;
}

tr:last-child td {
  border-bottom: 0;
}

.usage {
  margin: 32px 0 0;
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
}

.usage h2,
.backlinks h2 {
  margin: 0 0 12px;
  font-family: var(--sans);
  font-size: 0.8125rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.usage .line {
  margin: 0;
  max-width: 88%;
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 1rem;
  line-height: 1.55;
}

.usage .line + .line {
  margin-top: 10px;
}

.usage .line-a {
  background: var(--bg);
  border: 1px solid var(--line);
  border-bottom-left-radius: 2px;
}

.usage .line-b {
  margin-left: auto;
  background: var(--accent-soft);
  border: 1px solid transparent;
  border-bottom-right-radius: 2px;
}

.backlinks {
  margin-top: 32px;
}

.backlinks ul {
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.backlinks a {
  display: block;
  padding: 4px 12px;
  font-size: 0.875rem;
  color: var(--ink);
  text-decoration: none;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
}

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

.pager {
  margin-top: 40px;
  padding-top: 24px;
  border-top: 1px solid var(--line);
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.pager a {
  display: block;
  padding: 14px 16px;
  color: var(--ink);
  text-decoration: none;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
}

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

.pager .next {
  text-align: right;
}

.pager .dir {
  display: block;
  font-size: 0.75rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.pager .term {
  display: block;
  font-family: var(--serif);
  font-weight: 700;
  font-size: 1.125rem;
  line-height: 1.3;
  overflow-wrap: anywhere;
}

/* Shown above an entry that has no translation in the page's language. */
.notice {
  margin: 20px 0 0;
  padding: 10px 14px;
  font-size: 0.9375rem;
  color: var(--muted);
  background: var(--accent-soft);
  border-radius: 8px;
}

/* ------------------------------------------------------------------ footer */

.site-footer {
  margin-top: 56px;
  padding: 24px 0 32px;
  border-top: 1px solid var(--line);
  font-size: 0.875rem;
  color: var(--muted);
}

.site-footer p {
  margin: 0;
  max-width: 44rem;
}

.footer-inner {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 8px 24px;
}

.footer-links {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 20px;
}

/* -------------------------------------------------------------- responsive */

@media (max-width: 900px) {
  .entry-layout {
    grid-template-columns: minmax(0, 1fr);
    padding-top: 28px;
  }

  .sidebar {
    display: none;
  }
}

/* The header takes two rows: name and switches, then views and search. */
@media (max-width: 860px) {
  .site-header .header-inner {
    position: relative;
    flex-wrap: wrap;
    align-content: flex-start;
    min-height: 0;
    gap: 0 12px;
    padding-top: 10px;
    padding-bottom: 10px;
  }

  /* Ends the first row, whatever the width. */
  .header-inner::after {
    content: "";
    order: 2;
    flex-basis: 100%;
    height: 0;
  }

  .site-nav,
  .search {
    margin-top: 8px;
  }

  .brand {
    margin-right: auto;
  }

  .lang-toggle,
  .header-inner .icon-button {
    order: 1;
  }

  .site-nav {
    order: 3;
    gap: 0;
    margin-left: -7px;
  }

  .site-nav a {
    padding: 6px 7px;
  }

  .search {
    order: 4;
    flex: 1 1 0;
    position: static;
    margin-left: 0;
    margin-top: 8px;
  }

  .search kbd {
    display: none;
  }

  .search input {
    padding-right: 12px;
    text-overflow: ellipsis;
  }

  #search-results {
    left: 24px;
    right: 24px;
    top: calc(100% - 2px);
    width: auto;
  }

  html {
    scroll-padding-top: 122px;
  }
}

@media (max-width: 640px) {
  .wrap {
    padding: 0 16px;
  }

  #search-results {
    left: 16px;
    right: 16px;
  }

  .hero {
    padding: 40px 0 28px;
  }

  .term-list {
    margin: 0 -8px;
  }

  .term-list a {
    padding: 10px 8px;
  }

  .usage {
    padding: 14px;
  }

  .usage .line {
    max-width: 94%;
  }

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

  .pager span:empty {
    display: none;
  }

  .pager .next {
    text-align: left;
  }
}

@media print {
  .site-header,
  .sidebar,
  .pager,
  .site-footer {
    display: none;
  }
}

/* --------------------------------------------------------------------- map */

/* The map page is one screen tall: the header, then the map fills the rest. */
.page-map {
  height: 100vh;
  height: 100dvh;
  min-height: 0;
  overflow: hidden;
}

.page-map main {
  position: relative;
  min-height: 0;
}

.graph-stage {
  position: absolute;
  inset: 0;
  overflow: hidden;
}

.graph-canvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: grab;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}

.graph-canvas:focus-visible {
  outline-offset: -4px;
}

/* Text over the map lets the pointer through, except for its links. */
.graph-intro {
  position: absolute;
  top: 28px;
  left: 24px;
  max-width: 21rem;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.graph-intro a {
  pointer-events: auto;
}

/* An open term takes the reader's attention, so the intro steps aside. */
.has-panel .graph-intro {
  opacity: 0;
  visibility: hidden;
}

.graph-intro h1 {
  font-size: 1.75rem;
}

.graph-intro .lede {
  margin: 10px 0 0;
  font-family: var(--serif);
  font-size: 1.0625rem;
  line-height: 1.45;
}

.graph-hint,
.graph-credit {
  margin: 10px 0 0;
  font-size: 0.8125rem;
  line-height: 1.5;
  color: var(--muted);
}

.graph-status {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  margin: 0;
  padding: 8px 14px;
  font-size: 0.9375rem;
  color: var(--muted);
  text-align: center;
}

.graph-status[hidden] {
  display: none;
}

.graph-controls {
  position: absolute;
  left: 24px;
  bottom: 24px;
  display: flex;
  gap: 8px;
}

.graph-controls .icon-button {
  background: var(--surface);
}

.term-panel {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(430px, 44%);
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-left: 1px solid var(--line);
  box-shadow: var(--shadow);
  transform: translateX(100%);
  visibility: hidden;
  transition:
    transform 0.28s ease,
    visibility 0s linear 0.28s;
}

.has-panel .term-panel {
  transform: none;
  visibility: visible;
  transition:
    transform 0.28s ease,
    visibility 0s;
}

.term-panel[hidden],
.term-panel [hidden] {
  display: none;
}

.term-panel-head {
  flex: none;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 16px 0 24px;
}

.term-panel-head .eyebrow {
  margin: 8px 0 0;
}

/* The same term in the Learn view and on its own page. */
.term-panel-head .term-panel-links {
  margin-top: 6px;
}

.term-panel-links a {
  color: var(--accent);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 0.18em;
}

.term-panel-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 8px 24px 28px;
}

.term-panel-body > h2 {
  font-size: 2rem;
  overflow-wrap: anywhere;
}

.term-panel-body > h2:focus {
  outline: none;
}

.term-panel-body .prose {
  margin-top: 16px;
}

.term-panel-body .prose > p:first-child {
  font-size: 1.1875rem;
  line-height: 1.5;
}

.term-panel-pager {
  flex: none;
  margin: 0;
  padding: 12px 16px;
  gap: 12px;
}

.term-panel-pager a {
  padding: 10px 12px;
}

.term-panel-pager .next {
  grid-column: 2;
}

.term-panel-pager .term {
  font-size: 1rem;
}

@media (max-width: 899.98px) {
  .graph-intro {
    top: 16px;
    left: 16px;
    right: 16px;
    max-width: 30rem;
  }

  .graph-intro h1 {
    font-size: 1.375rem;
  }

  .graph-intro .lede {
    margin-top: 6px;
    font-size: 1rem;
  }

  .graph-hint {
    display: none;
  }

  .graph-controls {
    left: 16px;
    bottom: 16px;
  }

  /* On a narrow screen the term opens as a sheet under the map. */
  .term-panel {
    top: auto;
    left: 0;
    width: auto;
    height: 58%;
    border-left: 0;
    border-top: 1px solid var(--line);
    border-radius: 14px 14px 0 0;
    transform: translateY(100%);
  }

  .has-panel .graph-controls {
    display: none;
  }

  .term-panel-head {
    padding: 12px 12px 0 16px;
  }

  .term-panel-body {
    padding: 4px 16px 20px;
  }

  .term-panel-body > h2 {
    font-size: 1.625rem;
  }

  .term-panel-pager {
    grid-template-columns: 1fr 1fr;
    padding: 10px 12px;
  }

  .term-panel-pager .next {
    text-align: right;
  }
}

@media (prefers-reduced-motion: reduce) {
  .term-panel,
  .has-panel .term-panel,
  .graph-intro {
    transition: none;
  }
}

@media print {
  .graph-controls {
    display: none;
  }
}
