/* 羅曼多語言字典 — mobile-first stylesheet (no build step) */

/* ---------- Design tokens ---------- */
:root {
  --bg: #f6f3ec;
  --surface: #ffffff;
  --surface-2: #f0ece3;
  --surface-3: #e7e1d5;
  --text: #1d1b18;
  --muted: #5b564d;
  --border: #dcd5c7;
  --line: #a89f8e;
  --accent: #9a3412;
  --accent-ink: #ffffff;
  --accent-soft: #fbe8dd;
  --focus: #1d4ed8;
  --m: #1d5aa6;  --m-soft: #e4eefb;
  --f: #a3264f;  --f-soft: #fbe5ed;
  --mf: #5b3fa0; --mf-soft: #ece6fa;
  --en: #44403c; --it: #1f7a45; --pt: #8a5300; --fr: #3048b0; --es: #b02a17;
  --ok: #166534; --ok-soft: #dcfce7;
  --shadow: 0 1px 2px rgb(0 0 0 / .05), 0 6px 20px rgb(60 40 10 / .06);
  --radius: 16px;
  --radius-sm: 10px;
  --gutter: 16px;
  --font: system-ui, -apple-system, "Segoe UI", "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", "Heiti TC", sans-serif;
  --font-serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, "Noto Serif TC", "PMingLiU", serif;
  --font-ipa: "Charis SIL", "Doulos SIL", "Gentium Plus", "Segoe UI", "Lucida Sans Unicode", "Noto Sans", "Arial Unicode MS", sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #131210; --surface: #1c1b18; --surface-2: #25231f; --surface-3: #312e28;
    --text: #efebe4; --muted: #b5aea2; --border: #3b3831; --line: #7a7263;
    --accent: #f59e6b; --accent-ink: #1b0d05; --accent-soft: #3a2216; --focus: #8ab4ff;
    --m: #8bb9f6; --m-soft: #1b2a3e; --f: #f59bbd; --f-soft: #3a1b28; --mf: #c3b0f7; --mf-soft: #2a2140;
    --en: #d6d3d1; --it: #7ed3a0; --pt: #e8b35a; --fr: #a3b3f7; --es: #f59d8c;
    --ok: #86efac; --ok-soft: #173222;
    --shadow: 0 1px 2px rgb(0 0 0 / .4), 0 6px 20px rgb(0 0 0 / .25);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #131210; --surface: #1c1b18; --surface-2: #25231f; --surface-3: #312e28;
  --text: #efebe4; --muted: #b5aea2; --border: #3b3831; --line: #7a7263;
  --accent: #f59e6b; --accent-ink: #1b0d05; --accent-soft: #3a2216; --focus: #8ab4ff;
  --m: #8bb9f6; --m-soft: #1b2a3e; --f: #f59bbd; --f-soft: #3a1b28; --mf: #c3b0f7; --mf-soft: #2a2140;
  --en: #d6d3d1; --it: #7ed3a0; --pt: #e8b35a; --fr: #a3b3f7; --es: #f59d8c;
  --ok: #86efac; --ok-soft: #173222;
  --shadow: 0 1px 2px rgb(0 0 0 / .4), 0 6px 20px rgb(0 0 0 / .25);
  color-scheme: dark;
}

[data-lang="en"] { --lc: var(--en); }
[data-lang="it"] { --lc: var(--it); }
[data-lang="pt"] { --lc: var(--pt); }
[data-lang="fr"] { --lc: var(--fr); }
[data-lang="es"] { --lc: var(--es); }

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; scroll-padding-top: 140px; }
body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: clamp(0.95rem, 0.9rem + 0.25vw, 1.0625rem);
  line-height: 1.6;
  overflow-x: clip;
}
main { flex: 1 0 auto; outline: none; }
h1, h2, h3, h4 { line-height: 1.25; margin: 0; }
p { margin: 0; }
a { color: var(--accent); text-underline-offset: 2px; }
button { font: inherit; color: inherit; }
ul, ol { margin: 0; padding: 0; }
svg { flex-shrink: 0; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 6px; }
.sr-only {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.skip-link {
  position: absolute; left: 12px; top: -60px; z-index: 100; padding: 10px 16px;
  background: var(--accent); color: var(--accent-ink); border-radius: 8px; text-decoration: none;
}
.skip-link:focus { top: calc(12px + env(safe-area-inset-top)); }

.container {
  width: 100%;
  max-width: 1320px;
  margin-inline: auto;
  padding-left: max(var(--gutter), env(safe-area-inset-left));
  padding-right: max(var(--gutter), env(safe-area-inset-right));
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; min-width: 44px; padding: 0 14px;
  border-radius: 12px; border: 1px solid transparent; background: transparent;
  cursor: pointer; font-weight: 600; line-height: 1; text-decoration: none;
  transition: background-color .15s, border-color .15s, color .15s;
}
.btn svg { width: 20px; height: 20px; }
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { filter: brightness(1.08); }
.btn-ghost { border-color: var(--border); background: var(--surface); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-icon { padding: 0; width: 44px; }
.btn-small { min-height: 36px; padding: 0 12px; font-size: .875rem; font-weight: 500; }
@media (pointer: coarse) { .btn-small { min-height: 44px; } }

/* theme toggle: show the icon of the mode you will switch to */
.i-sun { display: none; }
:root[data-theme="dark"] .i-sun { display: block; }
:root[data-theme="dark"] .i-moon { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .i-sun { display: block; }
  :root:not([data-theme="light"]) .i-moon { display: none; }
}

/* ---------- Header ---------- */
.topbar {
  position: sticky; top: 0; z-index: 30;
  background: var(--bg);
  background: color-mix(in srgb, var(--bg) 90%, transparent);
  -webkit-backdrop-filter: saturate(1.4) blur(12px);
  backdrop-filter: saturate(1.4) blur(12px);
  border-bottom: 1px solid var(--border);
  padding-top: env(safe-area-inset-top);
}
.topbar-inner {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-areas: "brand tools" "search search";
  gap: 8px 12px;
  align-items: center;
  padding-top: 8px; padding-bottom: 10px;
}
@media (min-width: 768px) {
  .topbar-inner { grid-template-columns: auto minmax(0, 1fr) auto; grid-template-areas: "brand search tools"; padding-block: 12px; gap: 16px; }
}
.brand { grid-area: brand; display: inline-flex; align-items: center; gap: 10px; color: var(--text); text-decoration: none; min-height: 44px; min-width: 0; }
.brand-text { line-height: 1.2; font-weight: 800; font-size: clamp(1.05rem, 1rem + .4vw, 1.3rem); white-space: nowrap; letter-spacing: .02em; }
.toolbar { grid-area: tools; display: flex; gap: 8px; }

.search { grid-area: search; display: flex; gap: 8px; min-width: 0; }
.search-field { position: relative; flex: 1; min-width: 0; }
.search-icon { position: absolute; left: 14px; top: 50%; width: 20px; height: 20px; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.search input {
  width: 100%; min-height: 48px; padding: 0 14px 0 44px;
  border: 1.5px solid var(--border); border-radius: 14px; background: var(--surface); color: var(--text);
  font: inherit; font-size: max(16px, 1rem); /* ≥16px prevents iOS zoom */
}
.search input::placeholder { color: var(--muted); opacity: .85; }
.search input:focus-visible { outline: none; border-color: var(--focus); box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 30%, transparent); }
.search input::-webkit-search-cancel-button { cursor: pointer; }
.search-submit { min-height: 48px; padding-inline: 18px; }

.suggest {
  position: absolute; top: calc(100% + 6px); left: 0; right: 0; z-index: 40;
  list-style: none; padding: 6px; margin: 0;
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow);
  max-height: min(60vh, 420px); overflow-y: auto;
}
.sug {
  display: flex; align-items: center; gap: 8px; min-height: 44px; padding: 6px 10px;
  border-radius: 10px; cursor: pointer; min-width: 0;
}
.sug[aria-selected="true"], .sug:hover { background: var(--surface-2); }
.sug-word { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sug-lang {
  font-size: .7rem; font-weight: 700; letter-spacing: .04em; padding: 2px 6px; border-radius: 6px;
  color: var(--lc, var(--muted)); border: 1px solid currentColor; flex-shrink: 0;
}
.sug-lang[data-lang="zh"] { color: var(--muted); }
.sug-target { margin-left: auto; color: var(--muted); font-size: .875rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sug-target b { color: var(--text); }

/* ---------- Generic cards ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: clamp(16px, 2.5vw, 28px); min-width: 0;
}
.section-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px 16px; margin-bottom: 16px; }
.section-title { font-size: clamp(1.15rem, 1rem + .6vw, 1.45rem); font-weight: 800; }
.section-title small { font-weight: 600; color: var(--muted); font-size: .8em; margin-left: 6px; }
.mini-h { font-size: .8rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.muted { color: var(--muted); }

.chips { list-style: none; display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; min-height: 44px; padding: 6px 14px;
  border: 1px solid var(--border); border-radius: 999px; background: var(--surface-2); color: var(--text);
  cursor: pointer; text-decoration: none; font-size: .95rem; max-width: 100%;
}
.chip:hover { border-color: var(--accent); }
.chip small { color: var(--muted); }
.chip-sm { min-height: 36px; padding: 4px 12px; font-size: .9rem; }
@media (pointer: coarse) { .chip-sm { min-height: 44px; } }

.results { display: grid; gap: clamp(14px, 2vw, 22px); padding-block: clamp(14px, 2.5vw, 28px) 40px; }

/* ---------- Home ---------- */
.hero { padding-block: clamp(24px, 6vw, 64px) clamp(16px, 3vw, 28px); max-width: 60rem; }
.hero-title { font-family: var(--font-serif); font-size: clamp(1.9rem, 1.3rem + 3vw, 3.4rem); font-weight: 700; letter-spacing: -.01em; }
.hero-title span { color: var(--accent); }
.hero-sub { margin-top: 12px; color: var(--muted); font-size: clamp(1rem, .95rem + .3vw, 1.2rem); max-width: 62ch; }
.hero .try { margin-top: 22px; display: grid; gap: 10px; }
.home-grid { display: grid; gap: 16px; padding-bottom: 40px; }
@media (min-width: 768px) { .home-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } .home-grid .how { grid-column: 1 / -1; } }
@media (min-width: 1100px) { .home-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } .home-grid .how { grid-column: auto; } }
.how ul { padding-left: 1.2em; display: grid; gap: 8px; max-width: 70ch; }
.empty { color: var(--muted); }

/* ---------- Notices ---------- */
.notice {
  display: grid; gap: 10px; padding: 14px 18px; border-radius: var(--radius);
  background: var(--accent-soft); border: 1px solid color-mix(in srgb, var(--accent) 35%, transparent);
}
.notice p { max-width: 75ch; }
.notice b { font-weight: 700; }

/* ---------- Collapsible sections ---------- */
.head-tools { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: 8px 12px; margin-left: auto; }
.sec-toggle { gap: 4px; padding: 0 10px 0 8px; font-weight: 600; font-size: .875rem; color: var(--muted); }
.sec-toggle:hover { color: var(--text); }
.sec-toggle .chev { width: 20px; height: 20px; transition: transform .2s; }
.sec-toggle[aria-expanded="false"] .chev { transform: rotate(-90deg); }
.sec-toggle[aria-expanded="false"] { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 45%, var(--border)); }
.card.is-collapsed > .section-head { margin-bottom: 0; }
.sec-body[hidden] { display: none !important; }
@media (max-width: 380px) { .sec-toggle-text { display: none; } .sec-toggle { padding: 0; width: 44px; } }

/* ---------- English entry ---------- */
.entry-head { display: flex; align-items: flex-start; gap: 8px; }
.entry-title { flex: 1; min-width: 0; }
.headword { font-family: var(--font-serif); font-size: clamp(2.1rem, 1.4rem + 3.4vw, 3.6rem); font-weight: 700; letter-spacing: -.015em; overflow-wrap: anywhere; }
.hw-zh { font-size: clamp(1.05rem, 1rem + .5vw, 1.35rem); font-weight: 600; margin-top: 4px; }
.fav { color: var(--muted); }
.fav[aria-pressed="true"] { color: #d97706; border-color: #d97706; }
.fav svg { width: 22px; height: 22px; }

.pron { display: flex; flex-wrap: wrap; gap: 8px 12px; margin-top: 16px; }
.pron-item {
  display: inline-flex; align-items: center; gap: 8px; padding: 2px 4px 2px 12px;
  border: 1px solid var(--border); border-radius: 999px; background: var(--surface-2);
}
.pron-label { font-size: .8rem; font-weight: 700; color: var(--muted); }
.ipa { font-family: var(--font-ipa); font-size: .98em; color: var(--text); }

.say {
  display: inline-grid; place-items: center; width: 44px; height: 44px; border-radius: 50%;
  border: 0; background: transparent; color: var(--accent); cursor: pointer; flex-shrink: 0;
}
.say:hover { background: var(--accent-soft); }
.say svg { width: 22px; height: 22px; }
.say.is-speaking { background: var(--accent); color: var(--accent-ink); }
.say[aria-disabled="true"] { color: var(--muted); cursor: not-allowed; }

.entry-body { display: grid; gap: 24px; margin-top: 24px; }
@media (min-width: 1024px) { .entry-body { grid-template-columns: minmax(0, 1fr) minmax(260px, 340px); gap: 40px; } }
.pos-block + .pos-block { margin-top: 28px; }
.pos-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 8px 12px; padding-bottom: 8px; border-bottom: 1px solid var(--border); }
.pos-name { font-size: 1.15rem; font-weight: 800; color: var(--accent); }
.pos-name span { font-weight: 600; font-style: italic; color: var(--muted); margin-left: 6px; font-size: .9em; }
.ety-num { font-size: .78rem; font-weight: 700; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); color: var(--muted); }
.forms { display: flex; flex-wrap: wrap; gap: 6px 16px; margin-top: 10px; font-size: .95rem; }
.form-label { color: var(--muted); font-size: .85rem; }
.form-val { font-weight: 700; }

.senses { list-style: none; counter-reset: sense; display: grid; gap: 16px; margin-top: 14px; max-width: 70ch; }
.sense { counter-increment: sense; position: relative; padding-left: 2.2em; }
.sense::before {
  content: counter(sense); position: absolute; left: 0; top: .1em; width: 1.6em; height: 1.6em;
  display: grid; place-items: center; border-radius: 50%; background: var(--surface-2); color: var(--muted);
  font-size: .82rem; font-weight: 700;
}
.sense-def { font-size: 1.02em; }
.sense-zh { color: var(--text); font-weight: 600; margin-top: 2px; }
.sense-zh::before { content: "▸ "; color: var(--accent); }
.sense-ex { margin-top: 6px; padding-left: 12px; border-left: 3px solid var(--surface-3); color: var(--muted); font-style: italic; font-family: var(--font-serif); }
.sense-syn { margin-top: 6px; font-size: .9rem; color: var(--muted); }
.labels { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 4px; }
.label {
  font-size: .75rem; font-weight: 700; padding: 1px 8px; border-radius: 6px;
  background: var(--surface-2); border: 1px solid var(--border); color: var(--muted);
}
.label.is-register { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 45%, transparent); }
.label.is-region { color: var(--m); border-color: color-mix(in srgb, var(--m) 45%, transparent); }

.rel-group + .rel-group { margin-top: 18px; }
.rel-group h3 { margin-bottom: 8px; }
.linkish {
  background: none; border: 0; padding: 0; color: var(--accent); cursor: pointer; text-align: left;
  text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 3px; font: inherit;
}
.linkish:hover { text-decoration-thickness: 2px; }
.src-link { display: inline-flex; align-items: center; gap: 4px; font-size: .85rem; min-height: 44px; align-self: flex-start; }
.src-link svg { width: 14px; height: 14px; }

/* ---------- Translations ---------- */
.pt-switch { display: inline-flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 12px; overflow: hidden; background: var(--surface-2); }
.seg button {
  min-height: 40px; min-width: 44px; padding: 0 12px; border: 0; background: transparent; cursor: pointer;
  font-size: .875rem; font-weight: 600; color: var(--muted);
}
@media (pointer: coarse) { .seg button { min-height: 44px; } }
.seg button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); }

.lang-tabs {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; padding: 4px; margin-bottom: 14px;
  background: var(--surface-2); border-radius: 14px; border: 1px solid var(--border);
}
.lang-tabs [role="tab"] {
  min-height: 44px; border: 0; border-radius: 10px; background: transparent; cursor: pointer;
  font-weight: 800; letter-spacing: .04em; color: var(--muted);
}
.lang-tabs [role="tab"][aria-selected="true"] { background: var(--surface); color: var(--lc); box-shadow: inset 0 -3px 0 var(--lc), var(--shadow); }
@media (min-width: 640px) { .lang-tabs { display: none; } }

.tr-rows { display: grid; gap: 16px; }
.tr-row { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); overflow: hidden; }
.tr-row.is-match { border-color: var(--accent); box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 25%, transparent); }
.tr-row-head {
  display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 10px; padding: 12px 16px;
  background: var(--surface-2); border-bottom: 1px solid var(--border); font-size: 1rem;
}
.row-num {
  display: inline-grid; place-items: center; min-width: 1.7em; height: 1.7em; padding: 0 .4em; border-radius: 999px;
  background: var(--accent); color: var(--accent-ink); font-size: .8rem; font-weight: 800; align-self: center;
}
.row-label { font-weight: 700; }
.row-zh { font-weight: 600; color: var(--accent); }
.sense-tag {
  font-size: .8rem; font-weight: 600; padding: 1px 9px; border-radius: 999px;
  background: var(--surface); border: 1px dashed var(--line); color: var(--muted);
}
.ety-rows { font-size: .78rem; font-weight: 600; color: var(--muted); }
.chip-pos { font-size: .75rem; font-weight: 700; padding: 1px 8px; border-radius: 6px; border: 1px solid var(--border); color: var(--muted); }

.tr-grid { display: grid; grid-template-columns: minmax(0, 1fr); }
@media (min-width: 640px) { .tr-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (min-width: 1024px) { .tr-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.tr-cell { padding: 14px 16px 16px; border-top: 4px solid var(--lc); min-width: 0; display: flex; flex-direction: column; gap: 12px; }
@media (min-width: 640px) {
  .tr-cell { border-top: 0; border-left: 1px solid var(--border); box-shadow: inset 0 4px 0 var(--lc); padding-top: 18px; }
  .tr-cell:nth-child(2n+1) { border-left: 0; }
  .tr-cell:nth-child(n+3) { border-top: 1px solid var(--border); }
}
@media (min-width: 1024px) {
  .tr-cell:nth-child(2n+1) { border-left: 1px solid var(--border); }
  .tr-cell:first-child { border-left: 0; }
  .tr-cell:nth-child(n+3) { border-top: 0; }
}
@media (max-width: 639.98px) {
  .tr-rows[data-tab="it"] .tr-cell:not([data-lang="it"]),
  .tr-rows[data-tab="pt"] .tr-cell:not([data-lang="pt"]),
  .tr-rows[data-tab="fr"] .tr-cell:not([data-lang="fr"]),
  .tr-rows[data-tab="es"] .tr-cell:not([data-lang="es"]) { display: none; }
}
.cell-lang { display: flex; align-items: baseline; gap: 8px; font-size: .95rem; }
.cell-lang .native { font-weight: 800; color: var(--lc); }
.cell-lang .local { font-size: .8rem; color: var(--muted); font-weight: 600; }

.tw { display: grid; gap: 4px; min-width: 0; }
.tw + .tw { padding-top: 12px; border-top: 1px dashed var(--border); }
.tw.is-match .tw-word { background: var(--accent-soft); border-radius: 6px; box-shadow: 0 0 0 4px var(--accent-soft); }
.tw-main { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; min-width: 0; }
.tw-art { color: var(--muted); font-size: 1.1rem; font-family: var(--font-serif); }
.tw-word {
  font-family: var(--font-serif); font-size: clamp(1.2rem, 1.1rem + .5vw, 1.45rem); font-weight: 700;
  background: none; border: 0; padding: 0; color: var(--text); cursor: pointer; text-align: left;
  overflow-wrap: anywhere; min-height: 44px;
}
.tw-word:hover { color: var(--accent); text-decoration: underline; text-underline-offset: 4px; }
.tw-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.gender { display: inline-flex; align-items: center; gap: 4px; font-size: .78rem; font-weight: 700; padding: 1px 8px 1px 2px; border-radius: 999px; }
.gender abbr { text-decoration: none; display: inline-grid; place-items: center; min-width: 1.8em; height: 1.5em; padding: 0 4px; border-radius: 999px; color: #fff; font-size: .72rem; }
.g-m { background: var(--m-soft); color: var(--m); } .g-m abbr { background: var(--m); }
.g-f { background: var(--f-soft); color: var(--f); } .g-f abbr { background: var(--f); }
.g-mf { background: var(--mf-soft); color: var(--mf); } .g-mf abbr { background: var(--mf); }
:root[data-theme="dark"] .gender abbr { color: #111; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .gender abbr { color: #111; } }
.variant { font-size: .72rem; font-weight: 700; padding: 1px 7px; border-radius: 6px; background: var(--surface-3); color: var(--muted); }
.tw-detail { display: flex; flex-wrap: wrap; gap: 2px 12px; font-size: .9rem; color: var(--muted); }
.tw-detail .val { color: var(--text); }
.tw-gloss { font-size: .88rem; color: var(--muted); font-style: italic; }
.missing { color: var(--muted); font-size: .92rem; }
.missing .dash { font-weight: 800; margin-right: 4px; }

/* Portuguese variant switch */
:root[data-pt="PT"] .ipa-br, :root[data-pt="BR"] .ipa-pt { display: none; }
:root[data-pt="PT"] .tw[data-v="BR"], :root[data-pt="BR"] .tw[data-v="PT"] { opacity: .62; }

/* ---------- Etymology ---------- */
.ety-group + .ety-group { margin-top: 22px; padding-top: 22px; border-top: 1px solid var(--border); }
.ety-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 12px; }
.ety-head h3 { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 10px; font-size: 1.05rem; }
.badge { display: inline-flex; align-items: center; gap: 6px; padding: 4px 12px; border-radius: 999px; font-size: .82rem; font-weight: 800; }
.badge svg { width: 16px; height: 16px; }
.badge-cog { background: var(--ok-soft); color: var(--ok); border: 1px solid color-mix(in srgb, var(--ok) 40%, transparent); }
.badge-none { background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); }
.ety-summary { margin-top: 12px; padding: 12px 16px; border-radius: 12px; background: var(--surface-2); max-width: 75ch; }
.ety-summary::before { content: attr(data-label); display: block; font-size: .75rem; font-weight: 800; letter-spacing: .06em; color: var(--muted); margin-bottom: 2px; }

.ety-layout { display: grid; gap: 20px; margin-top: 16px; }
@media (min-width: 1024px) { .ety-layout { grid-template-columns: minmax(0, 5fr) minmax(0, 6fr); align-items: start; } }

.chains { list-style: none; display: grid; gap: 10px; margin-top: 8px; }
.chain { padding: 10px 12px 10px 14px; border-left: 4px solid var(--lc); background: var(--surface-2); border-radius: 0 12px 12px 0; min-width: 0; }
.chain-top { display: flex; align-items: center; gap: 8px; margin-bottom: 2px; }
.chain-lang { font-size: .78rem; font-weight: 800; color: var(--lc); letter-spacing: .03em; }
.chain-line { line-height: 1.9; overflow-wrap: anywhere; }
.chain-leaf { font-weight: 800; font-family: var(--font-serif); font-size: 1.08em; }
.arrow { color: var(--line); margin: 0 6px; font-weight: 700; }
.anc { white-space: normal; }
.anc-lang { font-size: .8rem; color: var(--muted); }
.anc-form { font-style: italic; font-family: var(--font-serif); font-weight: 600; }
.anc-gloss, .anc-note { color: var(--muted); font-size: .88rem; }
.cogs { margin-top: 4px; font-size: .85rem; color: var(--muted); }
.grp-tag {
  display: inline-grid; place-items: center; min-width: 1.6em; height: 1.6em; border-radius: 6px; padding: 0 4px;
  background: var(--ok); color: var(--surface); font-size: .75rem; font-weight: 800;
}
.grp-none { background: var(--surface-3); color: var(--muted); }

.tree-fig { margin: 0; min-width: 0; }
.tree-fig figcaption { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 10px; }
.tree-fig .hint { font-size: .8rem; color: var(--muted); }
.forest {
  display: flex; align-items: flex-start; gap: 18px; overflow-x: auto; overscroll-behavior-x: contain;
  margin-top: 8px; padding: 14px 10px 16px; border: 1px solid var(--border); border-radius: 14px;
  background:
    radial-gradient(circle at 1px 1px, color-mix(in srgb, var(--line) 30%, transparent) 1px, transparent 0) 0 0 / 16px 16px,
    var(--surface);
  scrollbar-width: thin;
}
.forest:focus-visible { outline-offset: 3px; }
.tree { flex: 0 0 auto; display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 8px; border-radius: 12px; }
.tree.is-group { background: color-mix(in srgb, var(--ok-soft) 55%, transparent); }
.tree-cap { font-size: .75rem; font-weight: 700; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.tree ul { display: flex; justify-content: center; list-style: none; margin: 0; padding: 18px 0 0; position: relative; }
.tree > ul { padding-top: 0; }
.tree li { position: relative; display: flex; flex-direction: column; align-items: center; padding: 18px 5px 0; }
.tree > ul > li { padding-top: 0; }
.tree li::before, .tree li::after {
  content: ""; position: absolute; top: 0; width: 50%; height: 18px; border-top: 2px solid var(--line);
}
.tree li::before { right: calc(50% - 1px); }
.tree li::after { left: calc(50% - 1px); border-left: 2px solid var(--line); }
.tree li:first-child::before { border: 0; }
.tree li:first-child::after { border-top-left-radius: 8px; }
.tree li:last-child::after { border: 0; }
.tree li:last-child::before { border-right: 2px solid var(--line); border-top-right-radius: 8px; }
.tree li:only-child::before { border: 0; }
.tree li:only-child::after { border-top: 0; border-left: 2px solid var(--line); border-radius: 0; }
.tree > ul > li::before, .tree > ul > li::after { display: none; }
.tree ul ul::before { content: ""; position: absolute; top: 0; left: calc(50% - 1px); height: 18px; border-left: 2px solid var(--line); }

.tn {
  display: inline-flex; flex-direction: column; align-items: center; gap: 0;
  padding: 6px 10px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface);
  white-space: nowrap; font-size: .82rem; line-height: 1.35; text-align: center; max-width: 16rem;
}
.tn-line + .tn-line { margin-top: 4px; padding-top: 4px; border-top: 1px dotted var(--border); }
.tn-lang { display: block; font-size: .7rem; color: var(--muted); font-weight: 600; }
.tn-form {
  background: none; border: 0; padding: 0; cursor: pointer; color: var(--text); font: inherit;
  font-family: var(--font-serif); font-style: italic; font-weight: 700; font-size: .95rem;
}
.tn-form:hover { color: var(--accent); text-decoration: underline; }
.tn-gloss { display: block; font-size: .72rem; color: var(--muted); white-space: normal; max-width: 12rem; }
.tn.is-leaf { border: 2px solid var(--lc); border-top-width: 5px; background: var(--surface); }
.tn.is-leaf .tn-lang { color: var(--lc); font-weight: 800; }
.tn.is-leaf .tn-form { font-style: normal; font-size: 1.02rem; }
.tn.is-leaf.is-unknown { border-style: dashed; }

.ety-full { margin-top: 16px; border: 1px solid var(--border); border-radius: 12px; }
.ety-full summary {
  display: flex; align-items: center; gap: 8px; min-height: 44px; padding: 0 14px; cursor: pointer; font-weight: 700;
  list-style: none;
}
.ety-full summary::-webkit-details-marker { display: none; }
.ety-full summary::before { content: "▸"; transition: transform .15s; color: var(--accent); }
.ety-full[open] summary::before { transform: rotate(90deg); }
.ety-full .when-open { display: none; }
.ety-full[open] .when-open { display: inline; }
.ety-full[open] .when-closed { display: none; }
.ety-full dl { margin: 0; padding: 4px 16px 16px; display: grid; gap: 12px; }
.ety-full dt { font-weight: 800; font-size: .9rem; color: var(--lc, var(--text)); }
.ety-full dd { margin: 2px 0 0; max-width: 75ch; font-family: var(--font-serif); }

/* ---------- Skeleton ---------- */
.skel { display: grid; gap: 12px; }
.skel-line { height: 14px; border-radius: 8px; background: linear-gradient(90deg, var(--surface-2) 25%, var(--surface-3) 50%, var(--surface-2) 75%); background-size: 200% 100%; animation: shimmer 1.2s linear infinite; }
.skel-line.h1 { height: 44px; width: 45%; }
.skel-grid { display: grid; gap: 12px; grid-template-columns: minmax(0, 1fr); }
@media (min-width: 640px) { .skel-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (min-width: 1024px) { .skel-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
@keyframes shimmer { to { background-position: -200% 0; } }

/* ---------- Footer ---------- */
.site-footer { margin-top: 24px; border-top: 1px solid var(--border); background: var(--surface-2); padding-bottom: env(safe-area-inset-bottom); }
.footer-inner { padding-block: 20px 28px; display: grid; gap: 8px; font-size: .875rem; color: var(--muted); }
.footer-inner p { max-width: 90ch; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}
@media print {
  .topbar, .site-footer, .say, .lang-tabs, .pt-switch, .fav { display: none !important; }
  .tr-rows .tr-cell { display: flex !important; }
  .ety-full[open], .ety-full { border: 0; }
}
