/* Phonoscope: "phonetics textbook". Ruled tables instead of cards, glyphs as specimens,
   language identity carried by a two-part mark under each glyph (left = A, right = B).
   Tokens first; see DESIGN.md. */
/* Charis 7.000 by SIL Global, unmodified web fonts (OFL 1.1, Reserved Font Names "Charis" and "SIL":
   subsetting would make it a Modified Version, so the full fonts are served). Google Fonts' subsets
   lack combining marks such as U+032A, which rendered as boxes in t̪. */
@font-face { font-family: "Charis"; src: url("fonts/Charis-Regular.woff2") format("woff2"); font-weight: 400; font-display: swap; }
@font-face { font-family: "Charis"; src: url("fonts/Charis-Bold.woff2") format("woff2"); font-weight: 700; font-display: swap; }
:root {
  color-scheme: light;
  --bg: oklch(0.985 0.003 230);
  --surface: oklch(0.965 0.004 230);
  --fg: oklch(0.23 0.012 250);
  --fg-2: oklch(0.42 0.012 250);
  --muted: oklch(0.56 0.01 250);
  --rule: oklch(0.88 0.006 240);
  --rule-strong: oklch(0.74 0.008 240);
  --a: #1baf7a;       /* identity A: validated pair (dataviz validator, all-pairs, both modes) */
  --b: #eb6834;       /* identity B */
  --dot: oklch(0.80 0.006 240);
  --focus: oklch(0.55 0.15 40);

  --f-glyph: "Charis", "Doulos SIL", "Gentium Plus", serif;
  --f-ui: "IBM Plex Sans", "Helvetica Neue", sans-serif;
  --f-num: "IBM Plex Mono", ui-monospace, monospace;
  /* scale 1.25 on 15px */
  --t-xs: 12px; --t-s: 13.5px; --t-m: 15px; --t-l: 18.75px; --t-xl: 23.4px; --t-2xl: 29.3px; --t-3xl: 36.6px;
  --u: 4px;
  --r: 2px;
  --ease: cubic-bezier(.2, .7, .2, 1);
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: oklch(0.18 0.006 250);
    --surface: oklch(0.22 0.007 250);
    --fg: oklch(0.93 0.006 240);
    --fg-2: oklch(0.80 0.008 240);
    --muted: oklch(0.64 0.01 240);
    --rule: oklch(0.31 0.008 250);
    --rule-strong: oklch(0.45 0.01 250);
    --a: #199e70;
    --b: #d95926;
    --dot: oklch(0.38 0.008 250);
    --focus: oklch(0.72 0.14 50);
  }
}
* { box-sizing: border-box; }
html { background: var(--bg); color: var(--fg); }
body { margin: 0; font: 400 var(--t-m)/1.55 var(--f-ui); -webkit-font-smoothing: antialiased; }
a { color: inherit; text-decoration-color: var(--rule-strong); text-underline-offset: 3px; }
a:hover { text-decoration-color: currentColor; }
:focus-visible { outline: none; box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--focus); border-radius: var(--r); }
.vh { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.note { color: var(--muted); font-size: var(--t-s); font-weight: 400; }
.num { font-family: var(--f-num); font-variant-numeric: tabular-nums; font-size: 0.93em; }

/* page grid: a narrow left margin column for section titles, like a textbook */
.masthead, .compare, .sheet, footer { padding-inline: clamp(16px, 4vw, 56px); }
.masthead { padding-top: calc(var(--u) * 10); }
h1 { font: 700 var(--t-3xl)/1.1 var(--f-glyph); margin: 0; letter-spacing: -0.01em; }
.lede { margin: calc(var(--u) * 2) 0 0; color: var(--fg-2); font-size: var(--t-l); max-width: 60ch; }

.compare { padding-top: calc(var(--u) * 8); padding-bottom: calc(var(--u) * 6); border-bottom: 1px solid var(--rule); }
.sentence { margin: 0; display: flex; flex-wrap: wrap; align-items: baseline; gap: calc(var(--u) * 2) calc(var(--u) * 3);
  font: 400 var(--t-2xl)/1.25 var(--f-glyph); }
.and { color: var(--muted); }
.pick { font: inherit; color: var(--fg); background: transparent; border: 0; border-bottom: 2px solid var(--rule-strong);
  border-radius: 0; padding: 0 2px 2px; width: min(15em, 80vw); }
.pick:hover { border-bottom-color: var(--fg-2); }
.pick:focus { outline: none; border-bottom-color: var(--focus); box-shadow: none; }
.mark-a, .mark-b { display: inline-block; width: 14px; height: 6px; align-self: center; }
.mark-a { background: var(--a); }
.mark-b { background: var(--b); }
button.quiet, .tries button, .sources button { font: 500 var(--t-s) var(--f-ui); color: var(--fg-2); background: none; border: 0;
  padding: 4px 2px; min-height: 24px; cursor: pointer; text-decoration: underline; text-decoration-color: var(--rule-strong); text-underline-offset: 3px; }
button.quiet:hover, .tries button:hover, .sources button:hover { color: var(--fg); text-decoration-color: currentColor; }
button.quiet:active, .tries button:active { color: var(--focus); }
.sources { margin: calc(var(--u) * 3) 0 0; font-size: var(--t-s); color: var(--fg-2); display: grid; gap: 2px; }
.sources b { font-weight: 600; color: var(--fg); }
.sources button.cur { color: var(--fg); text-decoration: none; font-weight: 600; cursor: default; }
.tries { margin: calc(var(--u) * 3) 0 0; font-size: var(--t-s); color: var(--muted); }
.tries button { margin-right: calc(var(--u) * 3); }

.sheet { padding-top: calc(var(--u) * 10); padding-bottom: calc(var(--u) * 4); }
.sheet + .sheet { border-top: 1px solid var(--rule); }
.sheet-head { display: grid; grid-template-columns: minmax(180px, 1fr) 3fr; gap: calc(var(--u) * 6); align-items: baseline; margin-bottom: calc(var(--u) * 6); }
h2 { font: 700 var(--t-xl)/1.2 var(--f-glyph); margin: 0; }
.sheet-head .note { margin: 0; max-width: 72ch; font-size: var(--t-m); color: var(--fg-2); }
.key { margin: 0; display: flex; flex-wrap: wrap; gap: calc(var(--u) * 2) calc(var(--u) * 5); font-size: var(--t-s); color: var(--fg-2); align-items: center; }
.key span { display: inline-flex; align-items: center; gap: 8px; }
figure { margin: 0; min-width: 0; }
figcaption { font: 600 var(--t-m) var(--f-ui); margin-bottom: calc(var(--u) * 3); }
figcaption .note { margin-left: 6px; }
.charts { display: grid; grid-template-columns: minmax(0, 1.7fr) minmax(320px, 1fr); gap: calc(var(--u) * 10); align-items: start; }
.scroll { overflow-x: auto; }

/* glyph specimen: ink glyph over a split mark [A|B]; hatched half = the other language has something close */
.g { --ma: var(--rule); --mb: var(--rule); position: relative; display: inline-flex; flex-direction: column; align-items: center;
  min-width: 26px; min-height: 30px; padding: 1px 3px 6px; margin: 1px; font: 400 19px/1.15 var(--f-glyph); color: var(--fg);
  background: none; border: 0; cursor: pointer; border-radius: var(--r); }
.g::after { content: ""; position: absolute; left: 3px; right: 3px; bottom: 2px; height: 4px;
  background: linear-gradient(to right, var(--ma) 0 50%, var(--mb) 50% 100%); }
.g.ha { --ma: var(--a); } .g.hb { --mb: var(--b); }
.g.ca::after { background: linear-gradient(to right, transparent 0 50%, var(--mb) 50% 100%),
  repeating-linear-gradient(135deg, var(--a) 0 1.5px, transparent 1.5px 3.5px); }
.g.cb::after { background: linear-gradient(to right, var(--ma) 0 50%, transparent 50% 100%),
  repeating-linear-gradient(135deg, var(--b) 0 1.5px, transparent 1.5px 3.5px); }
.g:hover { background: var(--surface); }
.g.hl { background: var(--surface); box-shadow: inset 0 0 0 1px var(--fg-2); }
.g.focused { box-shadow: inset 0 0 0 2px var(--focus); }
.g.static { cursor: default; }
.g.static:hover { background: none; }

table.cons { border-collapse: collapse; }
.cons th { font: 500 var(--t-xs)/1.2 var(--f-ui); color: var(--muted); padding: 0 4px 6px; text-align: left; vertical-align: bottom; }
.cons thead th { max-width: 72px; }
.cons th.row { text-align: right; padding: 0 10px 0 0; vertical-align: middle; white-space: nowrap; }
.cons td { border-top: 1px solid var(--rule); border-left: 1px solid var(--rule); padding: 3px 4px; min-width: 60px; vertical-align: middle; }
.cons tr td:last-child { border-right: 1px solid var(--rule); }
.cons tr:last-child td { border-bottom: 1px solid var(--rule); }
.extra { font-size: var(--t-s); color: var(--fg-2); margin: calc(var(--u) * 3) 0 0; }

#vowels { width: 100%; height: auto; overflow: visible; }
#vowels .frame { fill: none; stroke: var(--rule-strong); stroke-width: 1.25; }
#vowels .gl { stroke: var(--rule); stroke-width: 1; }
#vowels .lab { fill: var(--muted); font: 500 12px var(--f-ui); }
#vowels .diph { fill: none; stroke-width: 1.5; opacity: .75; }
.toggle { font-size: var(--t-s); color: var(--fg-2); display: inline-flex; gap: 6px; align-items: center; min-height: 24px; }

.learn { display: grid; grid-template-columns: 1fr 1fr; gap: calc(var(--u) * 12); }
.learn h3 { font: 700 var(--t-l)/1.3 var(--f-glyph); margin: 0 0 calc(var(--u) * 2); }
.learn .sum { margin: 0 0 calc(var(--u) * 3); color: var(--fg-2); max-width: 60ch; }
.bar { display: flex; gap: 2px; height: 10px; margin: 0 0 6px; }
.bar > div { height: 100%; }
.bar .have { background: var(--rule-strong); border-radius: var(--r) 0 0 var(--r); }
.bar .close { background: repeating-linear-gradient(135deg, var(--c) 0 2px, transparent 2px 5px); }
.bar .new { background: var(--c); border-radius: 0 var(--r) var(--r) 0; }
.barlab { display: flex; font: 500 var(--t-xs) var(--f-ui); color: var(--muted); margin-bottom: calc(var(--u) * 4); }
.barlab > div { min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
dl.lists { margin: 0; display: grid; grid-template-columns: max-content 1fr; gap: calc(var(--u) * 2) calc(var(--u) * 4); }
dl.lists dt { font: 600 var(--t-s) var(--f-ui); color: var(--fg-2); padding-top: 6px; }
dl.lists dd { margin: 0; }
.pairs { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 0 calc(var(--u) * 4); }
.pair { display: flex; align-items: center; gap: 6px; font-size: var(--t-s); color: var(--fg-2); min-height: 34px; }
.pair .ipa { font: 400 17px var(--f-glyph); color: var(--fg); }
.rank { margin-top: calc(var(--u) * 6); font-size: var(--t-s); color: var(--fg-2); }
.rank table { border-collapse: collapse; margin-top: calc(var(--u) * 2); }
.rank td { padding: 3px 14px 3px 0; border-bottom: 1px solid var(--rule); }
.rank td.r { text-align: right; font-family: var(--f-num); font-variant-numeric: tabular-nums; color: var(--muted); }
.rank tr.me td { color: var(--fg); font-weight: 600; }

.focus { min-height: 28px; margin: 0 0 calc(var(--u) * 3); font-size: var(--t-m); }
.focus .ipa { font: 400 var(--t-xl) var(--f-glyph); margin-right: 6px; }
.maps { display: grid; grid-template-columns: 1fr 1fr; gap: calc(var(--u) * 8); }
#galaxy, #world { width: 100%; height: 480px; display: block; background: var(--surface); border-radius: var(--r); touch-action: none; }
#galaxy circle, #world circle { fill: var(--dot); }
#galaxy circle.has, #world circle.has { fill: var(--fg-2); }
#galaxy circle.a, #world circle.a { fill: var(--a); stroke: var(--bg); }
#galaxy circle.b, #world circle.b { fill: var(--b); stroke: var(--bg); }
#galaxy circle.hov, #world circle.hov { stroke: var(--fg); stroke-width: 1.5; }
#galaxy line { stroke: var(--a); opacity: .6; }
.lbl { font: 600 12px var(--f-ui); fill: var(--fg); paint-order: stroke; stroke: var(--surface); stroke-width: 3px; stroke-linejoin: round; pointer-events: none; }
.lbl.small { font-weight: 500; fill: var(--fg-2); }
.lbl.island { fill: var(--muted); font-weight: 500; }
.maptools { display: flex; flex-wrap: wrap; gap: calc(var(--u) * 2) calc(var(--u) * 6); margin-top: calc(var(--u) * 3); font-size: var(--t-s); color: var(--fg-2); align-items: center; }
.maptools label { margin-left: 8px; min-height: 24px; display: inline-flex; gap: 4px; align-items: center; }

#tip { position: fixed; z-index: 20; pointer-events: none; display: none; max-width: 320px; padding: 10px 12px;
  background: var(--bg); color: var(--fg); border-radius: var(--r); font-size: var(--t-s); line-height: 1.45;
  box-shadow: 0 1px 2px oklch(0 0 0 / .12), 0 8px 24px oklch(0 0 0 / .14); }
#tip .big { font: 400 30px/1.1 var(--f-glyph); }
#tip .who { display: flex; gap: 10px; margin-top: 4px; }

footer { padding-top: calc(var(--u) * 8); padding-bottom: calc(var(--u) * 16); border-top: 1px solid var(--rule); font-size: var(--t-s); color: var(--fg-2); }
footer summary { cursor: pointer; font-weight: 600; color: var(--fg); min-height: 24px; }
footer p { max-width: 72ch; }

@media (max-width: 1080px) {
  .charts, .learn, .maps { grid-template-columns: 1fr; }
  .sheet-head { grid-template-columns: 1fr; gap: calc(var(--u) * 2); }
  .sentence { font-size: var(--t-xl); }
}
@media (prefers-reduced-motion: no-preference) {
  .g, .pick { transition: background-color 120ms var(--ease), border-color 120ms var(--ease); }
}

/* ---------- wide gamut: same lightness and hue, more chroma where the screen can show it ---------- */
@media (color-gamut: p3) {
  :root { --a: oklch(0.669 0.19 162); --b: oklch(0.671 0.22 40.6); }
}
@media (color-gamut: p3) and (prefers-color-scheme: dark) {
  :root { --a: oklch(0.621 0.17 163); --b: oklch(0.622 0.21 40.1); }
}

/* ---------- terms (definitions quoted from Wikipedia) ---------- */
button.term { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: help;
  text-decoration: underline dotted var(--rule-strong); text-underline-offset: 3px; min-height: 24px; }
button.term:hover { text-decoration-color: currentColor; color: var(--fg); }
#vowels .lab.term { cursor: help; }
#vowels .lab.term:hover, #vowels .lab.term:focus-visible { fill: var(--fg); outline: none; }
.cite-btn { font: 500 var(--t-xs) var(--f-ui); color: var(--fg-2); background: none; border: 1px solid var(--rule-strong);
  border-radius: var(--r); padding: 0 5px; min-height: 22px; cursor: pointer; margin-left: 4px; }
.cite-btn:hover { border-color: var(--fg-2); color: var(--fg); }

/* ---------- sound card: side panel on wide screens, bottom sheet on phones ---------- */
#scrim { position: fixed; inset: 0; z-index: 29; background: oklch(0.2 0.01 250 / 0.28); opacity: 0; }
#scrim.open { opacity: 1; }
.card { position: fixed; z-index: 30; top: 0; right: 0; bottom: 0; width: min(440px, 100vw); overflow-y: auto;
  background: var(--bg); color: var(--fg); padding: 20px 24px 40px; border-left: 1px solid var(--rule);
  box-shadow: 0 1px 2px oklch(0 0 0 / .10), 0 12px 40px oklch(0 0 0 / .18); transform: translateX(16px); opacity: 0; overscroll-behavior: contain; }
.card.open { transform: none; opacity: 1; }
@media (prefers-reduced-motion: no-preference) {
  .card { transition: transform 220ms var(--ease), opacity 160ms var(--ease); }
  #scrim { transition: opacity 200ms var(--ease); }
}
.card-h { display: grid; grid-template-columns: auto 1fr auto; gap: 16px; align-items: start; padding-bottom: 14px; border-bottom: 1px solid var(--rule); }
.card-h .big { font: 400 64px/1 var(--f-glyph); min-width: 56px; text-align: center; }
.card-h h2 { font: 700 var(--t-l)/1.25 var(--f-glyph); margin: 4px 0 8px; }
.card-h h2 a { text-decoration-color: var(--rule-strong); }
.card .x { font: 400 24px/1 var(--f-ui); background: none; border: 0; color: var(--fg-2); cursor: pointer; width: 36px; height: 36px; border-radius: var(--r); }
.card .x:hover { background: var(--surface); color: var(--fg); }
.card .play { font: 600 var(--t-s) var(--f-ui); color: var(--bg); background: var(--fg); border: 0; border-radius: var(--r);
  padding: 6px 12px; min-height: 32px; cursor: pointer; }
.card .play:hover { background: var(--fg-2); }
.card .play:active { transform: translateY(1px); }
.card section { padding: 14px 0; border-bottom: 1px solid var(--rule); }
.card h3 { font: 600 var(--t-s) var(--f-ui); color: var(--fg-2); margin: 0 0 8px; }
.card .cite, .card .srcs { font-size: var(--t-xs); color: var(--muted); line-height: 1.5; }
.card .cite a, .card .srcs a { color: var(--fg-2); }
.card .srcs ol { padding-left: 18px; margin: 0; display: grid; gap: 8px; }
.card .srcs h3 { color: var(--fg-2); }
dl.defs { margin: 0; display: grid; gap: 10px; }
.def dt { font: 600 var(--t-s) var(--f-ui); }
.def dd { margin: 2px 0 0; font-size: var(--t-s); color: var(--fg-2); }
.card blockquote { margin: 0 0 8px; font: 400 var(--t-m)/1.55 var(--f-glyph); }
ul.sides { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; font-size: var(--t-s); }
.ipa { font-family: var(--f-glyph); }
details.feats { margin-top: 12px; font-size: var(--t-s); }
details.feats summary { cursor: pointer; font-weight: 600; min-height: 24px; }
details.feats .f { display: inline-block; font: 500 var(--t-xs) var(--f-num); background: var(--surface); padding: 1px 5px; border-radius: var(--r); margin: 2px 0; }

@media (max-width: 720px) {
  .card { top: auto; left: 0; width: 100%; max-height: 82vh; border-left: 0; border-top: 1px solid var(--rule);
    border-radius: 8px 8px 0 0; transform: translateY(24px); padding: 12px 18px calc(32px + env(safe-area-inset-bottom)); }
  .card::before { content: ""; display: block; width: 40px; height: 4px; border-radius: 2px; background: var(--rule-strong); margin: 0 auto 10px; }
  .card-h .big { font-size: 48px; min-width: 40px; }
}
@media (min-width: 721px) { #scrim { background: transparent; } }

/* ---------- footer: method and references ---------- */
footer section + section { margin-top: calc(var(--u) * 10); }
footer h2 { margin-bottom: calc(var(--u) * 4); }
footer .cols { columns: 2 34ch; column-gap: calc(var(--u) * 10); }
footer .cols p { margin-top: 0; break-inside: avoid; }
ol.refs { padding-left: 22px; max-width: 90ch; display: grid; gap: 8px; }
ol.refs a { color: var(--fg-2); }
.lede-2 { margin: calc(var(--u) * 2) 0 0; color: var(--muted); max-width: 64ch; }
