:root {
  --bg: #fbfbfa;
  --panel: #fff;
  --text: #1f2328;
  --muted: #6b7280;
  --line: #e3e3df;
  --accent: #2f5fb3;
  --accent-soft: #e8eefa;
  --bad: #b42318;
  --bad-soft: #fdecea;
  --warn: #8a5a00;
  --warn-soft: #fff6e0;
  --ok: #1d7a46;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17191c; --panel: #1f2226; --text: #e6e6e3; --muted: #9aa0a6; --line: #33373c;
    --accent: #8ab4f8; --accent-soft: #23324a; --bad: #f28b82; --bad-soft: #3b2424;
    --warn: #f2c46d; --warn-soft: #3a3120; --ok: #81c995;
  }
}

* { box-sizing: border-box; }
body { margin: 0; font: 15px/1.45 system-ui, sans-serif; background: var(--bg); color: var(--text); }
code, pre, .mono { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: 13px; }
h1 { font-size: 18px; margin: 0; }
h1 span { font-weight: 400; color: var(--muted); font-size: 15px; margin-left: .4em; }
h2 { font-size: 16px; margin: 0 0 .75em; }
h3 { font-size: 15px; margin: 1.25em 0 .5em; }

header { display: flex; align-items: baseline; gap: 1.25em; padding: 14px 24px 10px; flex-wrap: wrap; }
#summary { color: var(--muted); }
.status { margin-left: auto; color: var(--muted); font-size: 13px; }
.status.error { color: var(--bad); }
.status.ok { color: var(--ok); }

#banner { margin: 0 24px 10px; padding: 10px 14px; border-radius: 6px; background: var(--bad-soft); color: var(--bad); display: flex; gap: 1em; align-items: center; flex-wrap: wrap; }
#banner[hidden] { display: none; }

nav { display: flex; gap: 2px; padding: 0 24px; border-bottom: 1px solid var(--line); overflow-x: auto; }
nav button { border: 0; background: none; padding: 8px 14px; color: var(--muted); border-bottom: 2px solid transparent; border-radius: 0; cursor: pointer; font: inherit; white-space: nowrap; }
nav button:hover { color: var(--text); }
nav button.active { color: var(--accent); border-bottom-color: var(--accent); }

main { padding: 20px 24px 60px; }
.split { display: grid; grid-template-columns: minmax(240px, 340px) 1fr; gap: 28px; align-items: start; }
@media (max-width: 760px) { .split { grid-template-columns: 1fr; } }

input, select, textarea, button { font: inherit; color: inherit; }
input, select, textarea { background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
textarea { resize: vertical; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 13px; }
button { background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 6px 12px; cursor: pointer; }
button:hover { border-color: var(--muted); }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
@media (prefers-color-scheme: dark) { button.primary { color: #10141a; } }
button.danger { color: var(--bad); }
button:disabled { opacity: .5; cursor: default; }

label { display: block; margin-bottom: 12px; font-size: 13px; color: var(--muted); }
label > input, label > select, label > textarea { margin-top: 3px; color: var(--text); font-size: 15px; }
label.inline { display: flex; gap: .5em; align-items: center; color: var(--text); }
label.inline input { width: auto; margin: 0; }
.hint { display: block; font-size: 12px; }
details { margin: 4px 0 12px; }
summary { cursor: pointer; color: var(--muted); margin-bottom: 10px; font-size: 13px; }
.buttons { display: flex; gap: 8px; margin-top: 8px; }
.toolbar { display: flex; gap: 14px; flex-wrap: wrap; align-items: end; margin-bottom: 12px; }
.toolbar label { margin: 0; }
.toolbar label > select, .toolbar label > input { display: block; width: auto; min-width: 7em; }
.toolbar label.inline > input { display: inline; min-width: 0; margin: 0; }
.toolbar > .muted { padding-bottom: 6px; }
.toolbar label.inline { padding-bottom: 6px; }

.list { list-style: none; margin: 10px 0 0; padding: 0; max-height: 70vh; overflow-y: auto; border: 1px solid var(--line); border-radius: 6px; background: var(--panel); }
.list li { padding: 7px 12px; border-bottom: 1px solid var(--line); cursor: pointer; display: flex; justify-content: space-between; gap: 1em; }
.list li:last-child { border-bottom: 0; }
.list li:hover { background: var(--accent-soft); }
.list li.selected { background: var(--accent-soft); box-shadow: inset 3px 0 var(--accent); }
.list .meta { color: var(--muted); font-size: 13px; white-space: nowrap; }
.muted { color: var(--muted); }
.empty { color: var(--muted); padding: 12px; }

table { border-collapse: collapse; width: 100%; background: var(--panel); border: 1px solid var(--line); border-radius: 6px; }
th, td { text-align: left; padding: 5px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; font-weight: 600; color: var(--muted); background: var(--bg); position: sticky; top: 0; }
tr:last-child td { border-bottom: 0; }
td.form { font-weight: 600; }
tr.merged td { color: var(--muted); }
tr.merged td.form { font-weight: 400; }
tr.override td.form { color: var(--warn); }
tr.missing td.form { color: var(--muted); font-weight: 400; font-style: italic; }
tr.collides td.form { background: var(--bad-soft); color: var(--bad); }
.table-wrap { max-height: 65vh; overflow: auto; border-radius: 6px; }
.tag { display: inline-block; font-size: 11px; padding: 0 6px; border-radius: 9px; background: var(--accent-soft); color: var(--accent); margin-left: 4px; }
.tag.warn { background: var(--warn-soft); color: var(--warn); }
.tag.bad { background: var(--bad-soft); color: var(--bad); }

.word-head { display: flex; gap: 1em; align-items: baseline; flex-wrap: wrap; margin-bottom: 6px; }
.word-head h2 { margin: 0; font-size: 20px; }
.word-head .buttons { margin: 0 0 0 auto; }
dl.props { display: grid; grid-template-columns: max-content 1fr; gap: 2px 14px; margin: 6px 0 14px; font-size: 13px; }
dl.props dt { color: var(--muted); }
dl.props dd { margin: 0; }

.msg { padding: 8px 12px; border-radius: 6px; margin: 8px 0; white-space: pre-wrap; font-size: 13px; }
.msg.error { background: var(--bad-soft); color: var(--bad); }
.msg.warn { background: var(--warn-soft); color: var(--warn); }
.msg.ok { background: var(--accent-soft); color: var(--accent); }

.group { border: 1px solid var(--line); border-radius: 6px; background: var(--panel); margin-bottom: 8px; }
.group > summary { padding: 8px 12px; margin: 0; color: var(--text); font-size: 15px; }
.group > div { padding: 0 12px 10px; }
a.word-link { color: var(--accent); cursor: pointer; text-decoration: none; }
a.word-link:hover { text-decoration: underline; }

#lookup-input { max-width: 420px; margin-bottom: 14px; }
pre#stats-output { background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 14px; overflow: auto; }

/* paradigm grid */
.segmented { display: inline-flex; padding-bottom: 1px; }
.segmented button { border-radius: 0; margin-left: -1px; }
.segmented button:first-child { border-radius: 6px 0 0 6px; margin-left: 0; }
.segmented button:last-child { border-radius: 0 6px 6px 0; }
.segmented button.active { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); position: relative; }
table.grid { width: auto; min-width: 50%; }
table.grid th, table.grid td { border: 1px solid var(--line); }
table.grid th.colhead { text-align: center; color: var(--text); }
table.grid th.axis { text-align: right; font-weight: 400; font-style: italic; }
table.grid th.rowhead { background: var(--bg); color: var(--text); font-size: 13px; position: sticky; left: 0; top: auto; }
table.grid td { white-space: nowrap; }
table.grid td.na { background: repeating-linear-gradient(45deg, transparent 0 4px, var(--line) 4px 5px); }
table.grid td.form.merged { color: var(--muted); font-weight: 400; font-style: italic; }
table.grid td.form.override { color: var(--warn); background: var(--warn-soft); }
table.grid td.form.missing { color: var(--muted); font-weight: 400; text-align: center; }
table.grid td.form.collides { background: var(--bad-soft); color: var(--bad); }
.legend { font-size: 12px; display: flex; gap: 14px; flex-wrap: wrap; margin: 8px 0 0; }
.legend .sw::before { content: ""; display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 5px; vertical-align: -1px; border: 1px solid var(--line); }
.legend .sw.override::before { background: var(--warn-soft); border-color: var(--warn); }
.legend .sw.merged::before { background: var(--panel); }
.legend .sw.collides::before { background: var(--bad-soft); border-color: var(--bad); }
table.grid thead th { position: static; }
.split > * { min-width: 0; }
table.grid th.colhead.wide { text-align: left; }
table.grid td.span { text-align: center; vertical-align: middle; }

/* hover tooltip: pronunciation and notes */
#tooltip { position: absolute; z-index: 10; max-width: 420px; padding: 7px 10px; border-radius: 6px; background: var(--text); color: var(--bg); box-shadow: 0 4px 14px rgb(0 0 0 / .2); pointer-events: none; }
#tooltip[hidden] { display: none; }
.tip-ipa { font: 17px/1.35 "Charis SIL", "Doulos SIL", "Gentium Plus", "Noto Serif", "DejaVu Serif", serif; }
.tip-form { font: 12px system-ui, sans-serif; opacity: .7; margin-right: 8px; }
.tip-notes { font: 12px/1.4 ui-monospace, Menlo, Consolas, monospace; white-space: pre-wrap; opacity: .8; margin-top: 3px; }
.tip-ipa + .tip-notes { border-top: 1px solid rgb(127 127 127 / .4); padding-top: 4px; }
.ipa { font-family: "Charis SIL", "Doulos SIL", "Gentium Plus", "Noto Serif", "DejaVu Serif", serif; font-size: 16px; }

/* classes */
#class-new { width: 100%; }
.class-fields { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0 14px; }
.class-fields .wide { grid-column: 1 / -1; }
.class-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.4fr); gap: 28px; align-items: start; }
@media (max-width: 1100px) { .class-grid { grid-template-columns: 1fr; } .class-fields { grid-template-columns: 1fr; } }
.class-users { font-size: 13px; }
table.merges { width: auto; }
table.merges td { display: flex; flex-wrap: wrap; gap: 6px 14px; }
.merge-item { display: inline-flex; align-items: center; gap: 6px; margin: 0; color: var(--text); font-size: 13px; }
.merge-item select { width: auto; margin: 0; padding: 3px 6px; font-size: 13px; }
.merge-item select.merged-select { border-color: var(--accent); color: var(--accent); }
.slots { display: flex; flex-wrap: wrap; gap: 12px; align-items: start; }
table.slot { width: auto; }
table.slot td { padding: 3px 8px; }
input.affix { width: 8em; padding: 3px 6px; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 13px; }
input.affix::placeholder { color: var(--muted); opacity: .7; }
#class-json { margin-top: 4px; }
p.hint { font-size: 12px; color: var(--muted); margin: 0 0 8px; }

/* header search */
#search { width: 260px; margin-left: auto; }
header .status { margin-left: 12px; }

/* menus */
nav .menu { position: relative; display: flex; }
nav .menu-head::after { content: " ▾"; font-size: 11px; }
nav .menu-head.active { color: var(--accent); border-bottom-color: var(--accent); }
nav .menu-items { display: none; position: absolute; top: 100%; left: 0; z-index: 5; min-width: 160px; background: var(--panel); border: 1px solid var(--line); border-radius: 6px; box-shadow: 0 6px 18px rgb(0 0 0 / .12); padding: 4px; flex-direction: column; }
nav .menu:hover .menu-items, nav .menu:focus-within .menu-items { display: flex; }
nav .menu-items button { text-align: left; border-bottom: 0; border-radius: 4px; padding: 7px 12px; }
nav .menu-items button:hover { background: var(--accent-soft); }
nav .menu-items button.active { color: var(--accent); font-weight: 600; }
nav { overflow: visible; }

/* words: shared list, forms or editor */
#word-new, #pos-new { width: 100%; margin-bottom: 8px; }
.split-even { display: grid; grid-template-columns: minmax(260px, 380px) minmax(0, 1fr); gap: 28px; align-items: start; }
@media (max-width: 1100px) { .split-even { grid-template-columns: 1fr; } }
#word-form .word-head { margin-bottom: 12px; }

/* search results */
#tab-search h3:first-child { margin-top: 0; }
.list.search-words { max-height: none; margin-bottom: 8px; }

/* parts of speech */
table.pos-features { width: 100%; }
table.pos-features td { vertical-align: middle; }
table.pos-features td.order { width: 1%; white-space: nowrap; }
table.pos-features td.order button { padding: 2px 7px; }
table.pos-features tr.open > td { background: var(--accent-soft); }
table.pos-features tr.feature-panel > td { background: var(--bg); padding: 12px; }
.feature-name { font-family: ui-monospace, Menlo, Consolas, monospace; font-weight: 600; }
.small { font-size: 12px; }
input.short { width: 9em; }
.values { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0 12px; }
.value-chip { display: inline-flex; align-items: center; border: 1px solid var(--line); border-radius: 6px; background: var(--panel); }
.value-chip input { border: 0; width: 6em; padding: 3px 6px; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 13px; }
.value-chip button { border: 0; border-left: 1px solid var(--line); border-radius: 0 6px 6px 0; padding: 3px 8px; color: var(--bad); }
.add-feature { margin-top: 12px; }
.add-feature .hint { flex-basis: 100%; }
.new-feature { display: inline-flex; gap: 6px; }
.new-feature[hidden] { display: none; }
.new-feature input { width: 12em; }
.pos-stack > div + div { margin-top: 8px; }
table.pos-features td:nth-child(3) { width: 60%; }

/* list tools: filter box + sort */
.list-tools { display: flex; gap: 6px; margin-bottom: 8px; }
.list-tools select { width: auto; flex: none; }
details.advanced { margin: 0 0 4px; padding: 6px 10px; border: 1px solid var(--line); border-radius: 6px; background: var(--panel); }
details.advanced summary { margin: 0; }
details.advanced[open] summary { margin-bottom: 8px; }
details.advanced label { margin-bottom: 8px; }
details.advanced label.inline { font-size: 13px; }
#filter-clear { font-size: 13px; padding: 3px 10px; }

/* spelling */
td.form.misspelled, tr.misspelled td.form { text-decoration: underline wavy var(--bad); text-decoration-thickness: 1px; text-underline-offset: 3px; }
.legend .sw.misspelled { text-decoration: underline wavy var(--bad); text-underline-offset: 3px; }
.legend .sw.misspelled::before { display: none; }
p.hover-hint { margin-top: 4px; }

/* header buttons and history */
header #undo-btn, header #history-btn { padding: 4px 10px; font-size: 13px; }
table.history td { vertical-align: top; }
table.history tr.current td { background: var(--accent-soft); }
ul.changes { margin: 0; padding-left: 18px; }

/* files */
#file-name { cursor: pointer; }
#file-name:hover { text-decoration: underline; }
#tab-files section { margin-bottom: 26px; max-width: 1100px; }
#tab-files tr.current td { background: var(--accent-soft); }
#tab-files .toolbar { align-items: end; }
#tab-files .toolbar label.grow { flex: 1; }
#tab-files .toolbar label.grow > input { width: 100%; }
input.path { min-width: 22em; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 13px; }
input[type=file] { border: 0; padding: 4px 0; background: none; }

/* spelling rules */
#spelling-rules { margin-bottom: 28px; }
h2.spelling-list-head { font-size: 16px; }
table.spelling-classes, table.spelling-rules { margin-bottom: 8px; }
table.spelling-classes td, table.spelling-rules td { vertical-align: middle; }
table.spelling-classes td.members { font-size: 13px; max-width: 320px; }
table.spelling-rules input.message { min-width: 16em; font-size: 13px; }
table.spelling-rules select, table.spelling-classes select { width: auto; }
.ref { display: inline-flex; flex-wrap: wrap; gap: 4px; align-items: center; }
.ref .chip { display: inline-flex; align-items: center; border: 1px solid var(--line); border-radius: 6px; background: var(--panel); }
.ref .chip select { border: 0; padding: 3px 4px; width: auto; }
.ref .chip button { border: 0; border-left: 1px solid var(--line); border-radius: 0 6px 6px 0; padding: 2px 7px; }
.ref select.add-ref { width: auto; font-size: 12px; padding: 2px 4px; color: var(--muted); }
table.spelling-classes td:first-child input { width: 12em; }

/* save to computer */
header #save-btn { padding: 4px 12px; font-size: 13px; font-weight: 600; }
header #save-btn.pending::after { content: ""; display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--warn); margin-left: 6px; vertical-align: 1px; }
#tab-files td.actions { white-space: nowrap; }
#tab-files td.actions button { margin-left: 4px; }
input.grow-input { width: 100%; }

/* File menu and its pages */
nav .menu-items hr { border: 0; border-top: 1px solid var(--line); margin: 4px 2px; }
nav .menu-items button:disabled { opacity: .45; }
#tab-open, #tab-new, #tab-import, #tab-alphabet { max-width: 1100px; }
#tab-open tr.current td { background: var(--accent-soft); }
#tab-open td.actions { white-space: nowrap; }
#tab-open td.actions button { margin-left: 4px; }
.toolbar.narrow { max-width: 560px; }
.toolbar label.grow { flex: 1; }
.toolbar label.wide { flex: 2; }
label.file-drop { display: inline-flex; align-items: center; gap: 10px; padding: 14px 18px; border: 1px dashed var(--muted); border-radius: 8px; background: var(--panel); color: var(--text); cursor: pointer; margin: 0; }
label.file-drop:hover { border-color: var(--accent); background: var(--accent-soft); }
label.file-drop input[type=file] { width: auto; }
#info-output .details { max-width: 1100px; margin-bottom: 8px; }
.letters { display: flex; flex-wrap: wrap; gap: 6px; }
.letter { display: inline-flex; flex-direction: column; align-items: center; min-width: 3.2em; padding: 4px 8px; border: 1px solid var(--line); border-radius: 6px; background: var(--panel); }
.letter strong { font-size: 17px; }
.letter .ipa { font-size: 13px; color: var(--muted); }
.letter strong { font-family: "Charis SIL", "Doulos SIL", "Gentium Plus", "Noto Serif", "DejaVu Serif", serif; font-weight: 600; }
#tab-alphabet .toolbar select { width: auto; max-width: 100%; }
button.letter { cursor: pointer; font: inherit; color: inherit; }
button.letter:hover { border-color: var(--accent); }
button.letter.selected { border-color: var(--accent); background: var(--accent-soft); box-shadow: 0 0 0 1px var(--accent); }
.letter-form { margin-bottom: 4px; }
.letter-form input.letter-input, .letter-form input.ipa-input { font-family: "Charis SIL", "Doulos SIL", "Gentium Plus", "Noto Serif", "DejaVu Serif", serif; font-size: 17px; width: 7em; }
.letter-form select { width: auto; }
label.inline-select select { width: auto; }
details.md-import { margin-top: 18px; }

/* merge editor */
.merge-editor { margin-bottom: 8px; }
.merge-row { border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; margin-bottom: 6px; background: var(--panel); }
.merge-main, .merge-when { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.merge-when { margin: 6px 0 0 18px; }
.merge-row select { width: auto; padding: 3px 6px; font-size: 13px; }
.merge-row button { padding: 2px 8px; font-size: 13px; }
.value-checks { display: inline-flex; flex-wrap: wrap; gap: 2px 10px; }
label.check { margin: 0; font-size: 13px; gap: 4px; }
button.link-button { border: 0; background: none; color: var(--accent); padding: 2px 4px; font-size: 13px; }
button.link-button:hover { text-decoration: underline; }
.merge-inherited ul { margin: 2px 0 8px; padding-left: 18px; color: var(--muted); }
.class-features .checks { display: flex; flex-wrap: wrap; gap: 4px 14px; margin: 4px 0 10px; }
.class-features select, .intrinsic-fields select { width: auto; }
.label-like { font-size: 13px; color: var(--muted); margin-bottom: 4px; }
table.pos-features td.actions { white-space: nowrap; width: 1%; }
table.pos-features td.actions button { margin-left: 4px; }

/* list tools: Sort labels and the part-of-speech checklist */
.list-tools { align-items: center; }
label.sort-label { display: inline-flex; align-items: center; gap: 6px; margin: 0; font-size: 13px; color: var(--muted); white-space: nowrap; }
label.sort-label select { margin: 0; width: auto; color: var(--text); font-size: 14px; }
.list-tools input[type=search] { flex: 1; }
details.checklist { position: relative; flex: 1; min-width: 0; }
details.checklist summary { margin: 0; padding: 6px 8px; border: 1px solid var(--line); border-radius: 6px; background: var(--panel); color: var(--text); font-size: 13px; list-style: none; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
details.checklist summary::after { content: " ▾"; font-size: 11px; color: var(--muted); }
details.checklist[open] .checklist-items { position: absolute; z-index: 4; top: calc(100% + 2px); left: 0; right: 0; display: flex; flex-direction: column; gap: 6px; padding: 8px 10px; background: var(--panel); border: 1px solid var(--line); border-radius: 6px; box-shadow: 0 6px 18px rgb(0 0 0 / .12); }
label.sort-label { flex: 1; }
label.sort-label select { flex: 1; }
details.checklist { display: block; margin-bottom: 8px; }
details.checklist[open] .checklist-items { min-width: 100%; width: max-content; }
#class-new + .list-tools { margin-top: 0; }
#class-new { width: 100%; margin-bottom: 8px; }

/* editing forms by clicking them */
td.form.editable { cursor: pointer; }
td.form.editable:hover, td.form.editable:focus { outline: 2px solid var(--accent); outline-offset: -2px; background: var(--accent-soft); }
#cell-panel { position: absolute; z-index: 20; width: 300px; padding: 10px 12px; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 8px 24px rgb(0 0 0 / .18); }
#cell-panel[hidden] { display: none; }
#cell-panel .cell-panel-title { font-size: 13px; color: var(--muted); margin-bottom: 8px; }
#cell-panel input { font-size: 16px; }
#cell-panel .buttons { flex-wrap: wrap; }
ul.override-list { list-style: none; margin: 0 0 10px; padding: 0; font-size: 14px; }
ul.override-list li { padding: 2px 0; }
#lexeme-stems .toolbar { margin-bottom: 10px; }
