/* ============================================================
   Lexicon — unified dictionary UI. Design system.
   Warm "manuscript" palette (gold accent, cream text, serif
   headings). Dark by default; follows OS or the theme toggle.
   ============================================================ */
:root {
  --bg: #131009;
  --bg-glow: #1c160c;
  --surface: #1c170f;
  --surface-2: #241d12;
  --input: #17130c;
  --border: #3a3021;
  --border-strong: #4d4029;
  --text: #f3ead9;
  --text-dim: #a8967a;
  --text-faint: #7c6d57;
  --accent: #dba847;
  --accent-ink: #241a05;
  --good: #6fb8ac;
  --warn: #ffd166;
  --danger: #ff8b7c;
  --info: #6fb8ac;
  --radius: 14px;
  --radius-sm: 9px;
  --mono: ui-monospace, "SFMono-Regular", "SF Mono", Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, system-ui, sans-serif;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, "Times New Roman", serif;
  /* soft tints derive from the accents, so they follow the theme automatically */
  --accent-soft: color-mix(in srgb, var(--accent) 15%, transparent);
  --good-soft: color-mix(in srgb, var(--good) 17%, transparent);
  --warn-soft: color-mix(in srgb, var(--warn) 16%, transparent);
  --shadow: 0 1px 2px rgba(0,0,0,.28), 0 10px 34px rgba(0,0,0,.32);
  color-scheme: dark;
}
/* ---- light "parchment" ---- */
:root[data-theme="light"] {
  --bg: #f6f0e2; --bg-glow: #ece2c9; --surface: #fffcf4; --surface-2: #f3ead4;
  --input: #fffef9; --border: #ddceac; --border-strong: #cbb888; --text: #2a2115;
  --text-dim: #7c6b4c; --text-faint: #96876a; --accent: #a3701c; --accent-ink: #fff8ea;
  --good: #2d6e63; --warn: #8a6412; --danger: #b4392c; --info: #2d6e63;
  --shadow: 0 1px 2px rgba(120,90,30,.08), 0 10px 30px rgba(120,90,30,.10);
  color-scheme: light;
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme]) {
    --bg: #f6f0e2; --bg-glow: #ece2c9; --surface: #fffcf4; --surface-2: #f3ead4;
    --input: #fffef9; --border: #ddceac; --border-strong: #cbb888; --text: #2a2115;
    --text-dim: #7c6b4c; --text-faint: #96876a; --accent: #a3701c; --accent-ink: #fff8ea;
    --good: #2d6e63; --warn: #8a6412; --danger: #b4392c; --info: #2d6e63;
    --shadow: 0 1px 2px rgba(120,90,30,.08), 0 10px 30px rgba(120,90,30,.10);
    color-scheme: light;
  }
}
:root[data-theme="dark"] { color-scheme: dark; }

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--sans);
  background:
    radial-gradient(circle at 12% 0%, color-mix(in srgb, var(--accent) 9%, transparent), transparent 34rem),
    var(--bg);
  background-attachment: fixed;
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  transition: background .2s, color .2s;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button { font-family: inherit; }
/* serif headings give the scholarly, dictionary feel */
.brand, h1, h2, h3, .entry-lemma, .tile .tval, .empty .big + div { font-family: var(--serif); }

/* ---------- Layout ---------- */
.app { max-width: 1120px; margin: 0 auto; padding: 0 20px 80px; }
header.top {
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  margin: 0 -20px 24px;
  padding: 0 20px;
}
.top-row { max-width: 1120px; margin: 0 auto; display: flex; align-items: center; gap: 14px; height: 58px; }
.brand { font-weight: 700; font-size: 17px; letter-spacing: -.02em; display: flex; align-items: center; gap: 8px; }
.brand .logo { color: var(--accent); font-size: 20px; }
.top-spacer { flex: 1; }
.status-pill { display: inline-flex; align-items: center; gap: 7px; font-size: 12.5px; color: var(--text-dim);
  background: var(--surface); border: 1px solid var(--border); padding: 5px 11px; border-radius: 999px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--text-faint); }
.dot.ok { background: var(--good); box-shadow: 0 0 0 3px var(--good-soft); }
.dot.bad { background: var(--warn); box-shadow: 0 0 0 3px var(--warn-soft); }
.icon-btn { background: var(--surface); border: 1px solid var(--border); color: var(--text-dim);
  width: 34px; height: 34px; border-radius: 9px; cursor: pointer; font-size: 15px; display: grid; place-items: center; }
.icon-btn:hover { color: var(--text); border-color: var(--border-strong); }

/* ---------- Tabs ---------- */
nav.tabs { display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; }
nav.tabs::-webkit-scrollbar { display: none; }
.tab {
  background: transparent; border: none; color: var(--text-dim);
  padding: 9px 15px; border-radius: 9px; cursor: pointer; font-size: 14px; font-weight: 550;
  white-space: nowrap; display: inline-flex; align-items: center; gap: 7px;
}
.tab:hover { background: var(--surface-2); color: var(--text); }
.tab.active { background: var(--accent); color: var(--accent-ink); }
.tab .ico { font-size: 15px; }

/* ---------- Cards / surfaces ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.section-title { font-size: 13px; font-weight: 650; text-transform: uppercase; letter-spacing: .05em; color: var(--text-faint); margin: 0 0 12px; }
.muted { color: var(--text-dim); }
.faint { color: var(--text-faint); }

/* ---------- Stat tiles (Overview) ---------- */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; }
.tile {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px 17px; text-align: left; cursor: default; position: relative; transition: transform .08s, border-color .12s, box-shadow .12s;
}
.tile.clickable { cursor: pointer; }
.tile.clickable:hover { border-color: var(--accent); box-shadow: var(--shadow); transform: translateY(-1px); }
.tile .tval { font-size: 26px; font-weight: 720; letter-spacing: -.02em; line-height: 1.1; }
.tile .tlabel { font-size: 13px; color: var(--text-dim); margin-top: 3px; font-weight: 560; }
.tile .tsub { font-size: 11.5px; color: var(--text-faint); margin-top: 2px; }
.tile .go { position: absolute; top: 14px; right: 14px; color: var(--text-faint); font-size: 13px; opacity: 0; transition: opacity .12s; }
.tile.clickable:hover .go { opacity: 1; }

/* ---------- Badges ---------- */
.badge { display: inline-flex; align-items: center; gap: 4px; font-size: 11.5px; font-weight: 600;
  padding: 2px 8px; border-radius: 999px; background: var(--surface-2); color: var(--text-dim); border: 1px solid var(--border); }
.badge.accent { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.badge.good { background: var(--good-soft); color: var(--good); border-color: transparent; }
.badge.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.badge.pos { font-family: var(--mono); text-transform: lowercase; }

/* ---------- Inputs ---------- */
.input, select.input, textarea.input {
  width: 100%; background: var(--input); border: 1px solid var(--border-strong); color: var(--text);
  padding: 11px 13px; border-radius: var(--radius-sm); font-size: 15px; font-family: inherit; outline: none;
}
.input:focus, select.input:focus, textarea.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
textarea.input { resize: vertical; min-height: 110px; line-height: 1.6; }
.btn { background: var(--accent); color: var(--accent-ink); border: none; padding: 11px 18px; border-radius: var(--radius-sm);
  font-size: 14.5px; font-weight: 600; cursor: pointer; }
.btn:hover { filter: brightness(1.06); }
.btn.ghost { background: var(--surface); color: var(--text); border: 1px solid var(--border-strong); }
.btn.ghost:hover { border-color: var(--accent); color: var(--accent); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; min-width: 160px; }

/* ---------- Entry card (renderEntry) ---------- */
.entry { padding: 18px 20px; }
.entry + .entry { margin-top: 12px; }
.entry-head { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.entry-lemma { font-size: 23px; font-weight: 700; letter-spacing: -.01em; }
.entry-lemma.rtl { direction: rtl; }
.entry-trad { font-size: 18px; color: var(--text-dim); }
.entry-pinyin { font-family: var(--mono); font-size: 13.5px; color: var(--info); }
.entry-meta { display: flex; gap: 7px; align-items: center; flex-wrap: wrap; margin-top: 2px; }
.entry-block { margin-top: 15px; }
.entry-block h4 { font-size: 12px; font-weight: 650; text-transform: uppercase; letter-spacing: .05em;
  color: var(--text-faint); margin: 0 0 8px; }
.sense { padding: 8px 0; border-top: 1px solid var(--border); }
.sense:first-of-type { border-top: none; }
.sense-def { font-size: 15px; }
.sense-gloss { color: var(--text-dim); font-size: 14px; }
.sense .dom { font-size: 11.5px; color: var(--info); font-style: italic; margin-left: 6px; }
.pron { display: inline-flex; align-items: center; gap: 6px; margin-right: 14px; font-family: var(--mono); font-size: 14px; }
.pron .play { cursor: pointer; color: var(--accent); border: none; background: none; font-size: 15px; padding: 0; }
.tr-lang { margin-bottom: 8px; }
.tr-lang .lname { font-size: 12px; font-weight: 600; color: var(--text-faint); }
.tr-chips { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 3px; }
.tr-chip { background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 3px 9px; font-size: 14px;
  display: inline-flex; align-items: center; gap: 5px; }
.ex { padding: 7px 0; border-top: 1px solid var(--border); font-size: 14px; }
.ex:first-of-type { border-top: none; }
.ex .ex-tr { color: var(--text-dim); font-size: 13px; }
.rel-group { margin-bottom: 6px; }
.rel-group .rname { font-size: 12px; color: var(--text-faint); font-weight: 600; text-transform: capitalize; }
.rel-words { display: inline; }
.rel-word { color: var(--accent); cursor: pointer; }
.rel-word:not(:last-child)::after { content: ", "; color: var(--text-faint); }
.src-list { display: flex; flex-direction: column; gap: 5px; }
.src-item { display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--text-dim); }
.src-item .sname { font-weight: 600; color: var(--text); }

/* ---------- Tables ---------- */
table.grid { width: 100%; border-collapse: collapse; font-size: 14px; }
table.grid th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--text-faint);
  font-weight: 600; padding: 9px 12px; border-bottom: 1px solid var(--border); position: sticky; top: 58px; background: var(--surface); }
table.grid td { padding: 9px 12px; border-bottom: 1px solid var(--border); }
table.grid tr:hover td { background: var(--surface-2); }

/* ---------- Language pills ---------- */
.lang-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.lang-pill { display: flex; justify-content: space-between; align-items: center; gap: 8px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 9px; padding: 9px 12px; cursor: pointer; }
.lang-pill:hover { border-color: var(--accent); }
.lang-pill .lp-name { font-weight: 560; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lang-pill .lp-code { font-family: var(--mono); font-size: 11px; color: var(--text-faint); }
.lang-pill .lp-count { font-size: 12.5px; color: var(--text-dim); font-variant-numeric: tabular-nums; }

/* ---------- Misc ---------- */
.empty { text-align: center; padding: 48px 20px; color: var(--text-dim); }
.empty .big { font-size: 34px; margin-bottom: 10px; }
.spinner { width: 22px; height: 22px; border: 2.5px solid var(--border); border-top-color: var(--accent);
  border-radius: 50%; animation: spin .7s linear infinite; margin: 40px auto; }
@keyframes spin { to { transform: rotate(360deg); } }
.pager { display: flex; gap: 10px; align-items: center; justify-content: center; margin-top: 18px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip-btn { background: var(--surface); border: 1px solid var(--border); color: var(--text-dim); border-radius: 999px;
  padding: 5px 12px; font-size: 13px; cursor: pointer; }
.chip-btn:hover, .chip-btn.on { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.hint { font-size: 13px; color: var(--text-faint); }
.divider { height: 1px; background: var(--border); margin: 18px 0; }
[hidden] { display: none !important; }
