/* Charis 7 (SIL, Open Font License: fonts/OFL.txt), self-hosted and subset to Latin + IPA.
   Google Fonts' copy lacks several IPA diacritics (◌̚ ◌̥ ◌̊ ◌̬), which then render as empty boxes. */
@font-face { font-family: "Charis Web"; src: url("fonts/Charis-Regular.woff2") format("woff2"); font-weight: 400; font-style: normal; font-display: swap; }
@font-face { font-family: "Charis Web"; src: url("fonts/Charis-Bold.woff2") format("woff2"); font-weight: 700; font-style: normal; font-display: swap; }
@font-face { font-family: "Charis Web"; src: url("fonts/Charis-Italic.woff2") format("woff2"); font-weight: 400; font-style: italic; font-display: swap; }

:root {
  --paper: #f5efe3;
  --paper-2: #ece3d2;
  --card: #fbf8f1;
  --ink: #1c1915;
  --ink-2: #5d564b;
  --ink-3: #8a8173;
  --rule: #d6cab4;
  --accent: #b3261e;
  --accent-ink: #fbf8f1;
  --accent-soft: rgba(179, 38, 30, 0.1);
  --phonemic: #1f4f7a;
  --shadow: 0 1px 0 rgba(0, 0, 0, 0.04), 0 10px 30px -12px rgba(60, 40, 10, 0.25);
  --ipa: "Charis Web", "Charis SIL", "Doulos SIL", "Gentium Plus", "Noto Serif", serif;
  --display: "Fraunces", "Charis Web", Georgia, serif;
  --mono: "IBM Plex Mono", ui-monospace, Menlo, monospace;
  --grain: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 0.35 0 0 0 0 0.27 0 0 0 0 0.15 0 0 0 .07 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #16130f; --paper-2: #1f1b15; --card: #1c1813;
    --ink: #ede5d5; --ink-2: #b3a894; --ink-3: #7f7666; --rule: #3a3229;
    --accent: #ef6a5a; --accent-ink: #16130f; --accent-soft: rgba(239, 106, 90, 0.14);
    --phonemic: #8ab8e0;
    --shadow: 0 1px 0 rgba(0, 0, 0, 0.3), 0 12px 30px -12px rgba(0, 0, 0, 0.6);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper: #16130f; --paper-2: #1f1b15; --card: #1c1813;
  --ink: #ede5d5; --ink-2: #b3a894; --ink-3: #7f7666; --rule: #3a3229;
  --accent: #ef6a5a; --accent-ink: #16130f; --accent-soft: rgba(239, 106, 90, 0.14);
  --phonemic: #8ab8e0;
  --shadow: 0 1px 0 rgba(0, 0, 0, 0.3), 0 12px 30px -12px rgba(0, 0, 0, 0.6);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--paper) var(--grain);
  color: var(--ink);
  font: 400 17px/1.55 var(--ipa);
  overflow-x: hidden;
}
a { color: inherit; text-decoration-color: var(--rule); text-underline-offset: 3px; }
a:hover { text-decoration-color: var(--accent); }
button { font: inherit; color: inherit; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

/* ---------- masthead ---------- */
.masthead {
  position: sticky; top: 0; z-index: 20;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 24px;
  padding: 14px clamp(16px, 4vw, 48px);
  background: color-mix(in srgb, var(--paper) 88%, transparent);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--rule);
}
.brand { display: grid; grid-template-columns: auto auto; column-gap: 10px; align-items: baseline; text-decoration: none; }
.brand-mark { grid-row: span 2; font: 500 1.9rem/1 var(--ipa); color: var(--accent); align-self: center; }
.brand-name { font: 800 1.35rem/1 var(--display); letter-spacing: -0.01em; font-variation-settings: "opsz" 72; }
.brand-sub { font: 400 0.68rem/1.4 var(--mono); color: var(--ink-3); text-transform: uppercase; letter-spacing: 0.08em; }

.search { position: relative; max-width: 560px; width: 100%; justify-self: center; }
.search input {
  width: 100%;
  padding: 11px 16px 11px 42px;
  font: 400 1.05rem/1.2 var(--ipa);
  color: var(--ink);
  background: var(--card) no-repeat 14px 50% / 18px
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238a8173' stroke-width='2' stroke-linecap='round'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cpath d='m20 20-3.5-3.5'/%3E%3C/svg%3E");
  border: 1px solid var(--rule);
  border-radius: 999px;
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.05);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.search input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }
#suggest {
  position: absolute; left: 0; right: 0; top: calc(100% + 6px);
  margin: 0; padding: 6px; list-style: none;
  background: var(--card);
  border: 1px solid var(--rule);
  border-radius: 14px;
  box-shadow: var(--shadow);
  max-height: 60vh; overflow-y: auto;
}
#suggest li {
  display: flex; justify-content: space-between; gap: 12px; align-items: baseline;
  padding: 7px 12px; border-radius: 8px; cursor: pointer;
}
#suggest li b { font-weight: 700; }
#suggest li .s-ipa { color: var(--ink-3); font-size: 0.92rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#suggest li[aria-selected="true"], #suggest li:hover { background: var(--accent-soft); }

.tools { display: flex; gap: 6px; align-items: center; }
.tools a, .tools button {
  font: 500 0.78rem/1 var(--mono); text-transform: uppercase; letter-spacing: 0.06em;
  padding: 8px 10px; border: 1px solid transparent; border-radius: 8px;
  background: none; cursor: pointer; text-decoration: none; color: var(--ink-2);
}
.tools a:hover, .tools button:hover { border-color: var(--rule); color: var(--ink); }
.tools button[aria-pressed="true"] { background: var(--ink); color: var(--paper); }

/* ---------- thumb index ---------- */
.thumbs {
  position: fixed; right: 0; top: 50%; transform: translateY(-50%); z-index: 10;
  display: flex; flex-direction: column;
}
.thumbs a {
  display: block; width: 30px; padding: 2px 0 2px 9px;
  font: 700 0.72rem/1.25 var(--display); text-transform: uppercase; text-decoration: none;
  color: var(--ink-3);
  border-left: 3px solid transparent;
  transition: color 0.12s, background 0.12s;
}
.thumbs a:hover { color: var(--ink); background: var(--paper-2); }
.thumbs a.on { color: var(--accent); border-left-color: var(--accent); background: var(--paper-2); }

/* ---------- main ---------- */
main { flex: 1; width: 100%; max-width: 980px; margin: 0 auto; padding: clamp(24px, 5vw, 56px) clamp(16px, 5vw, 64px) 64px; }
main:focus { outline: none; }
.loading { color: var(--ink-3); font-style: italic; }

.eyebrow { font: 500 0.72rem/1 var(--mono); text-transform: uppercase; letter-spacing: 0.12em; color: var(--ink-3); }

/* entry */
.entry { display: grid; grid-template-columns: minmax(0, 1fr) 200px; gap: 48px; animation: rise 0.35s ease-out both; }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } }
.headword {
  /* Tight line-height for the big type, plus bottom padding so descenders (g p y j q) clear the rule below. */
  margin: 10px 0 0;
  padding-bottom: 0.32em;
  font: 850 clamp(2.8rem, 10vw, 6rem)/1 var(--display);
  font-variation-settings: "opsz" 144;
  letter-spacing: -0.035em;
  overflow-wrap: anywhere;
}
.headword .hw-dot { color: var(--accent); }
.syllabified { font: italic 400 1rem/1.4 var(--ipa); color: var(--ink-3); margin: 0 0 28px; }

.pron {
  position: relative;
  display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 6px 20px; align-items: center;
  padding: 22px 0; border-top: 1px solid var(--rule);
}
.pron:last-of-type { border-bottom: 1px solid var(--rule); }
.pron-num {
  position: absolute; left: -34px; top: 26px;
  font: 700 0.8rem/1 var(--mono); color: var(--ink-3);
}
.play {
  grid-row: span 2;
  width: 58px; height: 58px; border-radius: 50%;
  display: grid; place-items: center;
  border: 1.5px solid var(--ink); background: var(--card);
  cursor: pointer; transition: transform 0.12s, background 0.12s, color 0.12s;
}
.play svg { width: 22px; height: 22px; margin-left: 3px; }
.play:hover { background: var(--ink); color: var(--paper); transform: scale(1.04); }
.play.playing { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.play.playing svg { margin-left: 0; }
.play[disabled] { opacity: 0.35; cursor: not-allowed; transform: none; background: var(--card); color: var(--ink); }

.narrow { font: 400 clamp(1.9rem, 6vw, 2.9rem)/1.3 var(--ipa); overflow-wrap: anywhere; }
.narrow .br { color: var(--accent); font-weight: 400; }
.sym { position: relative; border-radius: 4px; transition: background 0.12s; }
.sym.changed { color: var(--accent); cursor: help; }
.sym.stress, .sym.dot { color: var(--ink-3); }
.sym.lit, .sym.changed:hover, .sym.changed:focus-visible { background: var(--accent-soft); outline: none; }
.dots-off .sym.dot { display: none; }

.broad { font: 400 1.15rem/1.4 var(--ipa); color: var(--phonemic); }
.broad .lbl { font: 500 0.66rem/1 var(--mono); text-transform: uppercase; letter-spacing: 0.1em; color: var(--ink-3); margin-right: 10px; vertical-align: 0.2em; }
.note { grid-column: 2; font-style: italic; color: var(--ink-2); font-size: 0.95rem; }

.source {
  grid-column: 1 / -1; margin-top: 10px;
  display: flex; flex-wrap: wrap; gap: 6px 10px; align-items: center;
  font: 400 0.78rem/1.4 var(--mono); color: var(--ink-3);
}
.badge {
  font: 500 0.66rem/1 var(--mono); text-transform: uppercase; letter-spacing: 0.08em;
  padding: 4px 7px; border-radius: 4px; border: 1px solid currentColor;
}
.badge.own { color: var(--accent); }
.badge.wikimedia { color: var(--phonemic); }
.badge.synthetic, .badge.browser { color: var(--ink-3); }

/* apparatus: the list of rules applied */
.apparatus { margin: 34px 0 0; padding: 0; list-style: none; counter-reset: app; }
.apparatus h2 { margin: 0 0 10px; }
.apparatus li {
  display: grid; grid-template-columns: 3.2rem minmax(0, 1fr); gap: 14px;
  padding: 12px 10px; border-radius: 10px; transition: background 0.12s;
}
.apparatus li.lit { background: var(--accent-soft); }
.apparatus .a-sym { font: 400 1.7rem/1 var(--ipa); color: var(--accent); text-align: center; padding-top: 2px; }
.apparatus .a-name { font: 700 1rem/1.3 var(--display); font-variation-settings: "opsz" 24; }
.apparatus .a-desc { color: var(--ink-2); font-size: 0.95rem; }
.auto-was { color: var(--ink-3); font-size: 0.9rem; }

/* side column: nearby words, like a dictionary's running column */
.nearby { font-size: 0.95rem; padding-top: 12px; }
.nearby ol { list-style: none; margin: 10px 0 0; padding: 0; border-left: 1px solid var(--rule); }
.nearby li a { display: block; padding: 3px 0 3px 14px; text-decoration: none; color: var(--ink-2); }
.nearby li a:hover { color: var(--ink); }
.nearby li.here a { color: var(--ink); font-weight: 700; border-left: 3px solid var(--accent); margin-left: -2px; padding-left: 13px; }

/* tooltip */
.tip {
  position: fixed; z-index: 50; max-width: min(320px, calc(100vw - 32px));
  padding: 10px 12px; border-radius: 10px;
  background: var(--ink); color: var(--paper);
  font: 400 0.88rem/1.45 var(--ipa);
  box-shadow: var(--shadow); pointer-events: none;
  opacity: 0; transform: translateY(4px); transition: opacity 0.12s, transform 0.12s;
}
.tip.on { opacity: 1; transform: none; }
.tip b { font-family: var(--display); }

/* home */
.home { animation: rise 0.4s ease-out both; }
.home h1 {
  font: 800 clamp(2.4rem, 8vw, 5.2rem)/0.98 var(--display);
  font-variation-settings: "opsz" 144; letter-spacing: -0.035em;
  margin: 12px 0 20px; max-width: 14ch; word-spacing: 0.08em;
}
.home h1 em { font-weight: 400; font-style: italic; color: var(--accent); }
.home .lede { font-size: 1.12rem; color: var(--ink-2); max-width: 60ch; }
.samples { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; margin: 34px 0 0; padding: 0; list-style: none; }
.samples a {
  display: block; padding: 16px 18px; height: 100%;
  background: var(--card); border: 1px solid var(--rule); border-radius: 14px;
  text-decoration: none; transition: transform 0.15s, border-color 0.15s, box-shadow 0.15s;
  animation: rise 0.4s ease-out both;
}
.samples a:hover { transform: translateY(-2px); border-color: var(--accent); box-shadow: var(--shadow); }
.samples .w { font: 750 1.35rem/1.1 var(--display); display: block; }
.samples .n { font: 400 1.3rem/1.4 var(--ipa); color: var(--accent); display: block; margin-top: 6px; }
.samples .r { font: 400 0.7rem/1.3 var(--mono); color: var(--ink-3); text-transform: uppercase; letter-spacing: 0.08em; display: block; margin-top: 6px; }

/* key */
.key h1 { font: 800 clamp(2.2rem, 7vw, 4rem)/1 var(--display); letter-spacing: -0.03em; margin: 12px 0 8px; }
.key table { width: 100%; border-collapse: collapse; margin-top: 24px; }
.key td, .key th { text-align: left; vertical-align: top; padding: 14px 12px 14px 0; border-top: 1px solid var(--rule); }
.key th { font: 700 1rem/1.3 var(--display); width: 30%; }
.key .off { font: 500 0.66rem/1 var(--mono); text-transform: uppercase; letter-spacing: 0.08em; color: var(--ink-3); border: 1px solid var(--rule); padding: 3px 6px; border-radius: 4px; margin-left: 6px; vertical-align: 0.15em; }
.key td { color: var(--ink-2); }

.notfound h1 { font: 800 2.4rem/1.1 var(--display); }

.colophon {
  padding: 22px clamp(16px, 5vw, 64px) 30px; border-top: 1px solid var(--rule);
  font: 400 0.75rem/1.6 var(--mono); color: var(--ink-3); text-align: center;
}
.colophon #meta { display: block; margin-top: 4px; }

/* ---------- small screens ---------- */
@media (max-width: 900px) {
  .entry { grid-template-columns: minmax(0, 1fr); gap: 28px; }
  .nearby ol { columns: 2; border-left: 0; }
  .nearby li a { padding-left: 0; }
  .nearby li.here a { border-left: 0; margin-left: 0; padding-left: 0; color: var(--accent); }
  .pron-num { position: static; grid-column: 1 / -1; }
}
@media (max-width: 700px) {
  .masthead { grid-template-columns: auto auto; gap: 10px 12px; padding: 10px 16px; }
  .search { grid-column: 1 / -1; grid-row: 2; max-width: none; }
  .brand-sub { display: none; }
  .brand-mark { font-size: 1.5rem; }
  .tools { justify-self: end; }
  .thumbs {
    position: static; transform: none; flex-direction: row; overflow-x: auto;
    padding: 0 16px; border-bottom: 1px solid var(--rule); scrollbar-width: none;
  }
  .thumbs::-webkit-scrollbar { display: none; }
  .thumbs a { width: auto; padding: 8px 9px; border-left: 0; border-bottom: 3px solid transparent; font-size: 0.8rem; }
  .thumbs a.on { border-bottom-color: var(--accent); }
  main { padding: 22px 16px 48px; }
  .play { width: 50px; height: 50px; }
  .pron { gap: 6px 14px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ---------- local edit mode ---------- */
.edit-row { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 8px; }
.btn {
  font: 500 0.72rem/1 var(--mono); text-transform: uppercase; letter-spacing: 0.06em;
  padding: 8px 11px; border-radius: 8px; border: 1px solid var(--rule); background: var(--card); color: var(--ink-2); cursor: pointer;
}
.btn:hover { border-color: var(--ink-3); color: var(--ink); }
.btn.primary { background: var(--ink); border-color: var(--ink); color: var(--paper); }
.btn.rec-on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.7; } }
.edit-status { font: 400 0.78rem/1.3 var(--mono); color: var(--ink-3); }
.edit-form {
  grid-column: 1 / -1; display: grid; gap: 10px; margin-top: 10px; padding: 16px;
  background: var(--card); border: 1px dashed var(--ink-3); border-radius: 12px;
}
.edit-form[hidden] { display: none; }
.edit-form label { display: grid; grid-template-columns: 6.5rem minmax(0, 1fr); align-items: center; gap: 10px; font: 500 0.7rem/1 var(--mono); text-transform: uppercase; letter-spacing: 0.08em; color: var(--ink-3); }
.edit-form input { font: 400 1.25rem/1.3 var(--ipa); padding: 7px 10px; border: 1px solid var(--rule); border-radius: 8px; background: var(--paper); color: var(--ink); min-width: 0; }
.edit-form input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.edit-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
body.editing .brand-sub::after { content: " · edit mode"; color: var(--accent); }
@media (max-width: 700px) { .edit-form label { grid-template-columns: minmax(0, 1fr); } }

/* ---------- display option switches (Key page) ---------- */
.key tr.group td { padding-top: 34px; color: var(--ink-2); }
.key tr.group p { margin: 0 0 6px; }
.switch-row { display: inline-flex; align-items: center; gap: 12px; cursor: pointer; }
.switch {
  flex: none; position: relative; width: 42px; height: 24px; padding: 0;
  border-radius: 999px; border: 1.5px solid var(--ink-3); background: var(--paper-2); cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.switch .knob {
  position: absolute; top: 2px; left: 2px; width: 17px; height: 17px; border-radius: 50%;
  background: var(--ink-3); transition: transform 0.15s, background 0.15s;
}
.switch[aria-checked="true"] { background: var(--accent); border-color: var(--accent); }
.switch[aria-checked="true"] .knob { transform: translateX(18px); background: var(--accent-ink); }
