:root {
  --bg: #262324;
  --chrome: #191617;
  --chrome-2: #221F20;
  --well: #1C191A;
  --well-2: #141112;
  --raised: #302D2E;
  --token-open: rgb(0 0 0 / 27%);
  --token-expanded: rgb(0 0 0 / 49%);
  --token-hover: 15%;
  --control-fill: rgb(0 0 0 / 29%);
  --border: #413E3F;
  --frame-rule: color-mix(in srgb, var(--muted) 45%, transparent);
  --row-rule: color-mix(in srgb, var(--border) 55%, transparent);
  --text: #e7eaf0;
  --muted: #9aa3b2;
  --accent: #4c8dff;
  --accent-press: #3a6fcc;
  --ok: #3ecf8e;
  --err: #ff6b6b;
  --warn: #ffb454;
  --traffic: #e8536f;
  --pinyin-blue: #5EA2FF;
  --gloss-purple: #b98cff;
  --gloss-purple-dim: color-mix(in srgb, var(--gloss-purple) 65%, transparent);
  --no-gloss: color-mix(in srgb, var(--gloss-purple) 45%, transparent);
  --mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  --head-h: 60px;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  padding: env(safe-area-inset-top) 16px calc(env(safe-area-inset-bottom) + 24px);
  margin: 0 auto;
}
h1 { font-size: 1.3rem; margin: 20px 0 4px; }
a { color: var(--accent); }
.boot { position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center; background: var(--bg); visibility: visible; transition: opacity 200ms ease, visibility 0s linear 200ms; }
.boot-inner { display: flex; flex-direction: column; align-items: center; gap: 14px; animation: boot-in 200ms ease 250ms both; }
.boot .logo { height: 56px; width: auto; display: block; }
.boot-note { color: var(--muted); font-size: 0.9rem; margin: 0; }
.boot.boot-done { opacity: 0; visibility: hidden; }
@keyframes boot-in { from { opacity: 0; } to { opacity: 1; } }
.app-head { position: sticky; top: 0; z-index: 30; display: flex; align-items: center; gap: 12px; min-height: 50px; margin: calc(-1 * env(safe-area-inset-top)) -16px 0; padding: calc(env(safe-area-inset-top) + 8px) 16px 8px; background: var(--chrome); }
.app-head .logo { height: 44px; width: auto; display: block; }
.app-head .page-title { margin: 0; font-size: 1.05rem; font-weight: 600; color: var(--text); }
body:not(.authed) .app-head .page-title { display: none; }
body.authed #pages h1 { display: none; }
.app-head #menu-toggle { display: none; background: none; min-width: 0; min-height: 0; padding: 4px; margin-left: -4px; color: var(--muted); font-size: 1.35rem; line-height: 1; }
.app-head #menu-toggle:hover { color: var(--text); }
.app-head #menu-toggle:active { background: none; }
body.authed .app-head #menu-toggle { display: block; }
#app { display: flex; flex-direction: column; min-height: calc(100dvh - env(safe-area-inset-top) - env(safe-area-inset-bottom) - 24px); }
.footer { margin-top: auto; padding: 48px 0 0; color: var(--muted); font-size: 0.85rem; display: flex; justify-content: flex-start; align-items: baseline; gap: 6px; }
h2 { font-size: 1.15rem; color: var(--muted); margin: 40px 0 10px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; }
.chart-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin: 40px 0 10px; flex-wrap: wrap; }
.chart-head h2 { margin: 0; }
.chart-note { font-size: 0.75rem; color: var(--muted); font-weight: 500; }
.nogloss { color: var(--no-gloss); }
.norow, .noanswer { color: var(--muted); }
.page-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.page-head h1 { margin: 0; }
body.authed .page-head {
  position: fixed; z-index: 31;
  top: env(safe-area-inset-top); right: 16px; height: var(--head-h);
  align-items: center;
}
.page-head button.ghost {
  margin-left: auto; align-self: center;
  display: inline-flex; align-items: center; justify-content: center;
  flex: none; width: 34px; height: 34px; min-width: 34px; min-height: 34px; padding: 0;
}
.page-head button.ghost ~ button.ghost { margin-left: 0; }
.page-head button.ghost svg { width: 18px; height: 18px; display: block; }
.page-head button.ghost:hover { color: var(--text); }
.page-head button.ghost:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0; }
button {
  font: inherit;
  font-weight: 600;
  color: #fff;
  background: var(--accent);
  border: 0;
  border-radius: 12px;
  padding: 14px 16px;
  min-height: 52px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
button:active { background: var(--accent-press); }
button:disabled { opacity: 0.55; cursor: default; }
button.ghost { background: var(--well-2); color: var(--muted); min-height: 40px; min-width: 40px; padding: 8px 12px; font-size: 1.15rem; line-height: 1; }
input {
  font: inherit;
  color: var(--text);
  background: var(--well-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 13px 14px;
  width: 100%;
}
input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
select {
  font: inherit;
  color: var(--text);
  background: var(--well-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 13px 14px;
  width: 100%;
}
select:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
#login { display: flex; flex-direction: column; align-items: center; }
.login-form { display: flex; gap: 10px; margin-top: 48px; }
.login-form #token { width: 220px; }
.login-form button { white-space: nowrap; min-width: 122px; }
.field label { display: block; font-size: 0.75rem; color: var(--muted); margin-bottom: 4px; }
.result { margin-top: 12px; font-size: 0.85rem; color: var(--muted); white-space: pre-wrap; word-break: break-word; }
.result.ok { color: var(--ok); }
.result.err { color: var(--err); }
#status-error { text-align: center; margin: 8px 0 16px; }
.placeholder, .loading { color: var(--muted); font-size: 0.9rem; padding: 20px 0; }

.toast {
  position: fixed; z-index: 40;
  left: 50%; bottom: calc(env(safe-area-inset-bottom) + 20px);
  width: max-content; max-width: calc(100vw - 32px);
  padding: 8px 14px; border-radius: 999px;
  background: var(--raised);
  color: var(--text); font-size: 0.8rem; font-weight: 600; line-height: 1.3;
  box-shadow: 0 6px 20px color-mix(in srgb, black 40%, transparent);
  pointer-events: none;
  opacity: 0; transform: translateX(-50%) translateY(6px);
  transition: opacity 160ms ease, transform 160ms ease;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
@media (prefers-reduced-motion: reduce) {
  .toast, .toast.show { transform: translateX(-50%); transition: opacity 160ms ease; }
}

.nav-backdrop { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.5); z-index: 20; }
.nav-drawer { position: fixed; top: calc(env(safe-area-inset-top) + var(--head-h)); left: 0; height: calc(100% - env(safe-area-inset-top) - var(--head-h)); width: 240px; max-width: 82vw; background: var(--chrome); transform: translateX(-100%); transition: transform 0.2s ease; z-index: 21; padding: 16px 12px calc(env(safe-area-inset-bottom) + 16px); display: flex; flex-direction: column; gap: 2px; }
.nav-drawer.open { transform: translateX(0); }
.nav-drawer a { display: block; padding: 12px 14px; border-radius: 10px; color: var(--text); text-decoration: none; font-weight: 600; }
.nav-drawer a:hover { background: var(--chrome-2); }
.nav-drawer a.active { background: var(--accent); color: #fff; }

.gloss-unjustified .gloss {
  --gloss-ink: 22%;
  border-radius: 3px;
  background: color-mix(in srgb, var(--gloss-purple) var(--gloss-ink), transparent);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--gloss-purple) var(--gloss-ink), transparent);
}
.gloss-mark {
  display: inline-block; width: 6px; height: 6px;
  border-radius: 50%; background: var(--pass-dot, var(--muted));
}
.gloss-mark[data-pass="running"], [data-pass="running"] .gloss-mark {
  animation: stub-pulse 1.4s ease-in-out infinite;
}
@keyframes stub-pulse { 50% { opacity: 0.25; } }
@media (prefers-reduced-motion: reduce) {
  .gloss-mark[data-pass="running"], [data-pass="running"] .gloss-mark { animation: none; }
}
[data-pass="running"] { --pass-dot: var(--muted); }
[data-pass="kept"] { --pass-dot: var(--ok); }
[data-pass="changed"] { --pass-dot: var(--warn); }
[data-pass="failed"], [data-pass="lost"] { --pass-dot: var(--err); }
.lexicon-line { display: inline-flex; align-items: center; gap: 6px; }

.lexicon-toggle {
  display: inline-flex; align-items: baseline; gap: 7px;
  min-height: 0; min-width: 0; padding: 0;
  border: 0; border-radius: 0;
  background: none; color: var(--muted); font: inherit; font-size: 0.8rem;
  line-height: 1; cursor: pointer;
}
.lexicon-toggle:active { background: none; }
.lexicon-toggle.static { cursor: default; }
.lexicon-toggle:not(.static):hover .lexicon-toggle-track { filter: brightness(1.2); }
.lexicon-toggle:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.lexicon-toggle-track {
  display: inline-flex; align-items: center; justify-content: flex-start;
  width: 28px; height: 16px; padding: 2px; border-radius: 999px;
  background: color-mix(in srgb, var(--muted) 45%, transparent);
  transition: background 140ms ease;
}
.lexicon-toggle-thumb {
  width: 12px; height: 12px; border-radius: 50%; background: var(--well-2);
  box-shadow: 0 1px 2px color-mix(in srgb, black 25%, transparent);
  transition: transform 140ms ease;
}
.lexicon-toggle.included .lexicon-toggle-track {
  justify-content: flex-end;
  background: color-mix(in srgb, var(--ok) 45%, var(--bg));
}
.lexicon-toggle.excluded .lexicon-toggle-track { background: color-mix(in srgb, var(--err) 62%, transparent); }
.lexicon-toggle.pending .lexicon-toggle-track {
  justify-content: center;
  background: color-mix(in srgb, var(--warn) 55%, transparent);
}

