:root {
  --bg: #f7f5f2;
  --card: #ffffff;
  --ink: #1d1d1f;
  --muted: #6b6b70;
  --line: #e3e0db;
  --accent: #e8590c;
  --accent-ink: #ffffff;
  --accent-soft: #fdebdc;
  --blue: #1c4e9c;
  --ok: #237a3b;
  --warn: #9a5b00;
  --err: #b42318;
  --de: #1c4e9c;
  --het: #a4136a;
  --radius: 14px;
  --tap: 44px;
  --tabbar: 64px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141416; --card: #1f1f22; --ink: #f2f2f4; --muted: #a2a2aa; --line: #34343a;
    --accent: #ff7a33; --accent-soft: #3a2416; --blue: #8fb4ff; --ok: #6fd08a; --warn: #f0b45a; --err: #ff8a80;
    --de: #8fb4ff; --het: #ff8fcf; color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 17px/1.55 -apple-system, BlinkMacSystemFont, "PingFang TC", "Noto Sans TC", "Helvetica Neue", sans-serif;
  overflow-x: hidden;
  padding-bottom: calc(var(--tabbar) + env(safe-area-inset-bottom, 0px) + 12px);
}
main { max-width: 720px; margin: 0 auto; padding: env(safe-area-inset-top, 0px) 16px 0; }
a { color: var(--blue); }
button, input, select, textarea { font: inherit; color: inherit; }
img { max-width: 100%; }
[hidden] { display: none !important; }
.nl, [lang="nl"] { font-feature-settings: "kern"; }

/* search header */
.top { position: sticky; top: env(safe-area-inset-top, 0px); z-index: 5; display: flex; gap: 8px; align-items: center;
  padding: 10px 0; background: var(--bg); }
#search-form { flex: 1; display: flex; align-items: center; background: var(--card); border: 1.5px solid var(--line);
  border-radius: 999px; padding-left: 16px; min-width: 0; }
#search-form:focus-within { border-color: var(--accent); }
#q { flex: 1; min-width: 0; border: 0; background: transparent; height: 48px; font-size: 18px; outline: none; -webkit-appearance: none; }
#q::-webkit-search-cancel-button { display: none; }
.clear { border: 0; background: none; width: 40px; height: 44px; color: var(--muted); }
.go { border: 0; background: var(--accent); color: var(--accent-ink); height: 40px; min-width: 52px; border-radius: 999px; margin: 4px; font-weight: 600; }
.gear { width: var(--tap); height: var(--tap); display: grid; place-items: center; text-decoration: none; font-size: 22px; color: var(--muted); }

/* tab bar */
.tabbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; display: flex; background: var(--card); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom, 0px); }
.tabbar a { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; height: var(--tabbar);
  text-decoration: none; color: var(--muted); font-size: 13px; }
.tabbar a span { font-size: 22px; line-height: 1; }
.tabbar a[aria-current="page"] { color: var(--accent); font-weight: 600; }

.offline { position: sticky; top: 0; z-index: 20; background: #333; color: #fff; text-align: center; font-size: 14px; padding: 6px 12px;
  padding-top: calc(6px + env(safe-area-inset-top, 0px)); }

/* generic */
.page-title { font-size: 24px; margin: 18px 0 10px; }
h2.sub { font-size: 18px; margin: 20px 0 8px; }
h3 { font-size: 16px; margin: 14px 0 6px; }
h4 { font-size: 15px; margin: 12px 0 4px; color: var(--muted); }
.card { background: var(--card); border-radius: var(--radius); padding: 14px 16px; margin: 12px 0; border: 1px solid var(--line); }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.missing { color: var(--warn); }
.ok { color: var(--ok); }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row-between { display: flex; justify-content: space-between; align-items: center; }
.btn { display: inline-flex; align-items: center; justify-content: center; min-height: var(--tap); padding: 8px 18px; border-radius: 12px;
  border: 0; background: var(--accent); color: var(--accent-ink); font-weight: 600; margin: 4px 0; max-width: 100%; text-align: center; }
.btn:disabled { opacity: .5; }
.btn-ghost { background: var(--accent-soft); color: var(--ink); }
.btn-small { min-height: 38px; padding: 6px 14px; font-size: 15px; }
.btn-wide { width: 100%; }
.btn-icon { min-height: 38px; padding: 4px 10px; border-radius: 10px; border: 1px solid var(--line); background: var(--card); font-size: 15px; }
.btn-mini { min-height: 32px; padding: 2px 10px; border-radius: 8px; border: 1px solid var(--line); background: var(--card); font-size: 14px; margin: 2px 4px 2px 0; }
.linkish { border: 0; background: none; color: var(--blue); padding: 8px 0; min-height: var(--tap); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { display: inline-flex; align-items: center; min-height: 38px; padding: 4px 14px; border-radius: 999px; background: var(--card); border: 1px solid var(--line);
  text-decoration: none; color: var(--ink); font-size: 15px; max-width: 100%; overflow-wrap: anywhere; }
.chip-on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.seg { display: flex; flex-wrap: wrap; background: var(--line); border-radius: 12px; padding: 3px; gap: 3px; }
.seg button { flex: 1 1 auto; min-height: 38px; border: 0; border-radius: 9px; background: transparent; font-size: 15px; padding: 4px 8px; }
.seg button[aria-selected="true"] { background: var(--card); font-weight: 600; box-shadow: 0 1px 2px rgba(0,0,0,.12); }
.notice { border-radius: 12px; padding: 10px 14px; margin: 10px 0; font-size: 15px; }
.notice p { margin: 4px 0; }
.notice-info { background: var(--accent-soft); }
.notice-ok { background: color-mix(in srgb, var(--ok) 14%, var(--card)); }
.notice-error { background: color-mix(in srgb, var(--err) 14%, var(--card)); color: var(--ink); }
.loading { display: flex; align-items: center; gap: 10px; padding: 16px 4px; color: var(--muted); }
.spin { width: 18px; height: 18px; border: 2.5px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--tabbar) + env(safe-area-inset-bottom, 0px) + 12px);
  background: #222; color: #fff; padding: 10px 16px; border-radius: 12px; z-index: 50; max-width: calc(100vw - 32px); font-size: 15px; }

/* source badges */
.badge { display: inline-block; font-size: 11.5px; line-height: 1.4; padding: 1px 7px; border-radius: 6px; vertical-align: middle; white-space: nowrap; font-weight: 600; }
.src-wikt { background: #e6eefb; color: #1c4e9c; }
.src-ai { background: #f3e8ff; color: #6b21a8; }
.src-rule { background: #e8f5ec; color: #1f6b35; }
.src-missing { background: #fff4e0; color: #8a5200; }
@media (prefers-color-scheme: dark) {
  .src-wikt { background: #1c2b45; color: #a9c5ff; } .src-ai { background: #34204a; color: #e0c2ff; }
  .src-rule { background: #1d3524; color: #a6e3b6; } .src-missing { background: #3d2c10; color: #f6c879; }
}
.src-line { margin: 10px 0 4px; font-size: 14px; color: var(--muted); }

/* entry */
.entry { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; margin: 12px 0; overflow-wrap: anywhere; }
.via { margin: 0 0 6px; font-size: 15px; color: var(--muted); }
.head { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.head h2 { margin: 0; font-size: 28px; line-height: 1.2; }
.art { font-size: 17px; font-weight: 600; }
.art-de { color: var(--de); } .art-het { color: var(--het); } .art-dehet { color: var(--muted); } .art-missing { color: var(--warn); }
.pos { font-size: 13px; color: var(--muted); border: 1px solid var(--line); border-radius: 6px; padding: 0 6px; }
.star { margin-left: auto; width: var(--tap); height: var(--tap); border: 0; background: none; font-size: 26px; color: var(--accent); }
.pron { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin: 8px 0; }
.ipa { font-family: "Charis SIL", "Doulos SIL", "Lucida Sans Unicode", system-ui, sans-serif; color: var(--muted); }
.zh-short { font-size: 18px; margin: 6px 0; }
.keygram { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 15px; color: var(--muted); }
.tag { display: inline-block; font-size: 12px; background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 0 6px; margin-left: 6px; color: var(--muted); }
.detail { margin-top: 10px; border-top: 1px solid var(--line); }
.detail > summary, .more > summary, .tip > summary { cursor: pointer; min-height: var(--tap); display: flex; align-items: center; color: var(--blue); font-weight: 600; list-style: none; }
.detail > summary::before, .more > summary::before, .tip > summary::before { content: "▸"; margin-right: 6px; transition: transform .15s; }
.detail[open] > summary::before, .more[open] > summary::before, .tip[open] > summary::before { transform: rotate(90deg); }
.detail > summary::-webkit-details-marker { display: none; }
.sec { border-top: 1px dashed var(--line); padding-top: 4px; }
.sec h3 { color: var(--accent); }
.senses { padding-left: 22px; margin: 4px 0; }
.senses li { margin: 4px 0; }
.facts { display: grid; grid-template-columns: max-content 1fr; gap: 6px 14px; margin: 6px 0; }
.facts dt { color: var(--muted); font-size: 15px; }
.facts dd { margin: 0; min-width: 0; }
.rules { padding-left: 20px; font-size: 15px; }
.exs { list-style: none; padding: 0; margin: 4px 0; }
.ex { padding: 8px 0; border-bottom: 1px solid var(--line); }
.ex .zh, .zh { color: var(--muted); font-size: 15px; }
.ex .en { color: var(--muted); font-size: 14px; font-style: italic; }
.lvl { font-size: 11px; border: 1px solid var(--line); border-radius: 5px; padding: 0 5px; color: var(--muted); }
.lvl-up { border-color: var(--warn); color: var(--warn); }
.errors { list-style: none; padding: 0; }
.errors li { padding: 6px 0; border-bottom: 1px solid var(--line); }
.wrong { color: var(--err); font-weight: 700; } .right { color: var(--ok); font-weight: 700; }
.actions { display: flex; flex-direction: column; gap: 4px; margin-top: 12px; }
.footnote { font-size: 13px; color: var(--muted); margin-top: 14px; }
button.w { border: 0; background: none; padding: 0; margin: 0; color: inherit; font: inherit; text-decoration: underline dotted var(--muted); text-underline-offset: 3px; cursor: pointer; }
.strong button.w, .nl.strong { font-weight: 600; }

/* conjugation */
.conj .seg { margin: 8px 0; }
.conj-table { width: 100%; border-collapse: collapse; margin: 6px 0; table-layout: fixed; }
.conj-table caption { text-align: left; font-weight: 600; padding: 4px 0; }
.conj-table th { text-align: left; font-weight: 500; color: var(--muted); width: 38%; padding: 7px 6px 7px 0; vertical-align: top; font-size: 15px; }
.conj-table td { padding: 7px 0; border-bottom: 1px solid var(--line); font-size: 17px; overflow-wrap: anywhere; }
.conj-table .inv { font-size: 14px; color: var(--muted); margin-top: 2px; }
.conj .or { color: var(--muted); font-size: 14px; }
.conj p { font-size: 15px; margin: 6px 0; }
.more ul { padding-left: 20px; font-size: 15px; }

/* chinese results */
.zh-list { list-style: none; padding: 0; }
.zh-item { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 10px 14px; margin: 8px 0; }
.zh-word { font-size: 20px; font-weight: 600; margin-right: 8px; text-decoration: none; }
.usage { margin: 6px 0 0; padding-left: 18px; font-size: 14px; color: var(--muted); }
.mode-label { display: inline-block; background: var(--blue); color: #fff; border-radius: 8px; padding: 2px 10px; font-size: 14px; margin-top: 12px; }
blockquote { margin: 10px 0; padding: 10px 14px; background: var(--card); border-left: 4px solid var(--blue); border-radius: 8px; font-size: 18px; overflow-wrap: anywhere; }
.translation { font-size: 19px; }

/* chat */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.scard { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 10px; display: flex; flex-direction: column; }
.scard-title { font-weight: 600; margin-bottom: 4px; }
.scard .btn { width: 100%; font-size: 15px; min-height: 40px; }
.chat-top { position: sticky; top: env(safe-area-inset-top, 0px); z-index: 5; background: var(--bg); display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 0; }
.log { display: flex; flex-direction: column; gap: 10px; padding: 8px 0; }
.msg { max-width: 92%; padding: 10px 14px; border-radius: 16px; overflow-wrap: anywhere; }
.msg-ai { background: var(--card); border: 1px solid var(--line); align-self: flex-start; border-bottom-left-radius: 4px; }
.msg-user { background: var(--accent-soft); align-self: flex-end; border-bottom-right-radius: 4px; }
.msg-text { font-size: 18px; }
.msg-tools { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.corr { margin-top: 8px; padding-top: 8px; border-top: 1px dashed var(--line); font-size: 15px; }
.used { font-size: 14px; color: var(--ok); margin-top: 4px; }
.samples { background: var(--card); border: 1px dashed var(--line); border-radius: 12px; padding: 8px 12px; font-size: 15px; }
.samples ul { padding-left: 18px; margin: 4px 0; }
.help-row { display: flex; gap: 8px; flex-wrap: wrap; margin: 6px 0; }
.help { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 8px 12px; margin-bottom: 8px; }
.help ul { padding-left: 18px; }
.help input { width: 100%; min-height: var(--tap); border: 1px solid var(--line); border-radius: 10px; padding: 6px 10px; background: var(--bg); margin: 6px 0; }
.help-head { display: flex; justify-content: space-between; align-items: center; }
.composer { position: sticky; bottom: calc(var(--tabbar) + env(safe-area-inset-bottom, 0px)); background: var(--bg); padding: 8px 0; z-index: 4; }
.composer .row { flex-wrap: nowrap; align-items: flex-end; }
.composer textarea { flex: 1; min-width: 0; min-height: 48px; max-height: 140px; border: 1.5px solid var(--line); border-radius: 14px; padding: 10px 12px; background: var(--card); font-size: 17px; resize: none; }
.composer textarea:focus { outline: none; border-color: var(--accent); }
.mic { width: 52px; height: 52px; flex: none; border-radius: 50%; border: 0; background: var(--accent-soft); font-size: 22px; }
.mic.rec { background: var(--err); color: #fff; animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 8px color-mix(in srgb, var(--err) 25%, transparent); } }
.send { flex: none; min-height: 52px; }
.mic-status { font-size: 14px; color: var(--muted); }
.tip { font-size: 15px; margin: 8px 0; }
.tip ol { padding-left: 20px; }
.review ul, .review ol { padding-left: 20px; }
.review textarea, .card textarea { width: 100%; border: 1.5px solid var(--line); border-radius: 12px; padding: 8px 10px; background: var(--bg); }
.corrs li { margin-bottom: 10px; }

/* favorites */
.fav-list { list-style: none; padding: 0; }
.fav { margin: 8px 0; }
.fav-head { width: 100%; text-align: left; display: flex; flex-wrap: wrap; align-items: baseline; gap: 8px; background: var(--card); border: 1px solid var(--line);
  border-radius: 12px; padding: 12px 14px; min-height: var(--tap); }
.fav-w { font-size: 19px; font-weight: 600; }
.fav-zh { color: var(--muted); font-size: 15px; width: 100%; }

/* settings */
.card select, .card input[type="password"] { width: 100%; min-height: var(--tap); border: 1px solid var(--line); border-radius: 10px; padding: 6px 10px; background: var(--bg); }
.card input[type="range"] { width: 60%; vertical-align: middle; }
.card ul.small { padding-left: 18px; }
.card ul.small li { margin: 6px 0; }

/* sheet */
.sheet { position: fixed; inset: 0; z-index: 30; background: rgba(0,0,0,.35); display: flex; align-items: flex-end; }
.sheet-panel { background: var(--bg); width: 100%; max-height: 85vh; overflow-y: auto; border-radius: 18px 18px 0 0; padding: 12px 16px calc(16px + env(safe-area-inset-bottom, 0px)); }
.sheet-close { float: right; border: 0; background: var(--card); border-radius: 10px; min-height: 38px; padding: 4px 14px; }
