:root {
  --bg: #f7f7f5;
  --panel: #ffffff;
  --fg: #1d1d1f;
  --muted: #6b6b70;
  --border: #e2e2de;
  --accent: #3b5bdb;
  --button-bg: #3b5bdb;
  --button-fg: #ffffff;
  --error: #c92a2a;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  --j-key: #7a5da8;
  --j-string: #237536;
  --j-punct: #68686f;
  --num-base: #59595f;
  --pos: #a33a05;
  --neg: #1663ab;

  --e0: #f08c00;
  --e1: #1c7ed6;
  --e2: #2f9e44;
  --e3: #d6336c;
  --e4: #7048e8;
  --e5: #0c8599;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #141416;
    --panel: #1d1d20;
    --fg: #ececee;
    --muted: #9a9aa2;
    --border: #2e2e33;
    --accent: #748ffc;
    --button-bg: #4263eb;
    --error: #ff8787;
    --j-key: #b197fc;
    --j-string: #8ce99a;
    --j-punct: #9e9ea6;
    --num-base: #aaaab2;
    --pos: #ff922b;
    --neg: #4dabf7;
    --e0: #ffa94d;
    --e1: #4dabf7;
    --e2: #69db7c;
    --e3: #f783ac;
    --e4: #9775fa;
    --e5: #3bc9db;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  padding: 16px 12px 24px;
  background: var(--bg);
  color: var(--fg);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
}

header, nav, form, main { max-width: 1000px; margin: 0 auto; }
[hidden] { display: none !important; }

h1 { font-size: 1.5rem; margin: 0 0 4px; }
h2 { font-size: 1.1rem; margin: 0 0 4px; }
h3 { font-size: 0.95rem; font-weight: 600; margin: 0 0 10px; display: flex; gap: 8px; align-items: baseline; overflow-wrap: anywhere; }
.lede, .hint, .muted, .method { color: var(--muted); }
.lede { margin: 0 0 12px; }
.hint { font-size: 0.85rem; margin: 0 0 12px; }
.method { font-size: 0.8rem; margin: 0 0 12px; }
.error { color: var(--error); white-space: pre-wrap; }
.loading { animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.4; } }
@media (prefers-reduced-motion: reduce) {
  .loading { animation: none; }
}

/* ---- form ---- */

form {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 12px;
  align-items: end;
  margin-bottom: 12px;
}
.try-examples { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.try-examples .label { margin-right: 4px; }
button.example { background: var(--panel); color: var(--fg); border: 1px solid var(--border); padding: 4px 12px; font-size: 0.85rem; }
button.example:hover { border-color: var(--accent); color: var(--accent); }
button:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.input-hint, .status { grid-column: 1 / -1; margin: 0; font-size: 0.8rem; color: var(--muted); }
.status:empty { display: none; }
label { display: flex; flex-direction: column; gap: 4px; }
.label { font-size: 0.8rem; font-weight: 600; color: var(--muted); }
textarea {
  min-width: 0;
  width: 100%;
  font: inherit;
  color: inherit;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  resize: vertical;
}
textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
button {
  font: inherit;
  font-weight: 600;
  color: var(--button-fg);
  background: var(--button-bg);
  border: 0;
  border-radius: 8px;
  padding: 10px 22px;
  cursor: pointer;
  height: fit-content;
}
button:disabled { opacity: 0.55; cursor: progress; }

/* ---- results ---- */

main { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 20px; }
.column { min-width: 0; }
.result {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  margin-bottom: 10px;
}
.badge {
  flex: none;
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--accent);
  border: 1px solid currentColor;
  border-radius: 4px;
  padding: 0 6px;
}

@media (max-width: 680px) {
  form, main { grid-template-columns: 1fr; }
}

/* ---- JSON ---- */

.swatch { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-left: 6px; }
.swatch.pos { background: var(--pos); }
.swatch.neg { background: var(--neg); }

.json {
  margin: 0;
  font: 12px/1.6 var(--mono);
  white-space: pre-wrap;
  word-break: break-word;
}
.j-line { padding-left: 2ch; }
.j-key { color: var(--j-key); }
.j-string { color: var(--j-string); }
.j-punct { color: var(--j-punct); }
.j-number { color: var(--pos); font-weight: 700; }
.j-note { color: var(--muted); font-style: italic; }
.j-vector {
  padding-left: 2ch;
  max-height: 150px;
  overflow-y: auto;
  border-left: 2px solid var(--border);
  margin: 2px 0 2px 2ch;
}
.vector-details { margin-top: 6px; }
.vector-details summary { cursor: pointer; color: var(--muted); font-size: 0.8rem; }
.j-num {
  display: inline-block;
  margin-right: 1ch;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.j-num.pos { color: color-mix(in oklab, var(--pos) calc(var(--m) * 100%), var(--num-base)); }
.j-num.neg { color: color-mix(in oklab, var(--neg) calc(var(--m) * 100%), var(--num-base)); }

/* ---- entity linking ---- */

.interlinear { display: flex; flex-wrap: wrap; gap: 14px 10px; align-items: flex-start; }
.token { display: flex; flex-direction: column; gap: 6px; min-width: 0; max-width: min(17rem, 100%); }
.word { font-size: 1rem; line-height: 1.4; padding: 0 4px; width: fit-content; max-width: 100%; overflow-wrap: anywhere; }
.token.plain .word { color: var(--muted); }
mark.word { color: var(--fg); border-radius: 4px; border-bottom: 2px solid var(--c); background: color-mix(in oklab, var(--c) 22%, transparent); }

.e0 { --c: var(--e0); }
.e1 { --c: var(--e1); }
.e2 { --c: var(--e2); }
.e3 { --c: var(--e3); }
.e4 { --c: var(--e4); }
.e5 { --c: var(--e5); }

.annotation {
  font-size: 0.8rem;
  line-height: 1.4;
  border-left: 3px solid var(--c);
  padding: 2px 0 2px 8px;
}
code { font-family: var(--mono); }
.synset {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--fg);
  margin-bottom: 2px;
}
.examples { color: var(--muted); font-style: italic; margin-top: 2px; }
.senses { margin-top: 4px; font-size: 0.75rem; }
.senses summary { color: var(--muted); cursor: pointer; }
.senses ul { list-style: none; margin: 4px 0 0; padding: 0; }
.senses li { color: var(--muted); }
.senses li.chosen { color: var(--fg); font-weight: 600; }
.senses code { font-size: 0.7rem; }
.tick { display: inline-block; width: 1.4ch; color: var(--c); }
