:root {
  --bg: #f7f5f0;
  --panel: #ffffff;
  --side: #efece5;
  --ink: #1f2328;
  --muted: #646a73;
  --line: #dcd7cc;
  --accent: #8a2d1f;          /* oxblood */
  --accent-soft: #f3e3dd;
  --on-accent: #ffffff;
  --hl: #fff1b8;
  --noun: #23527c;
  --adj: #6a3d8a;
  --warn: #9a5b00;
  --latin: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --ui: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #17191c; --panel: #1f2226; --side: #1b1e21; --ink: #e7e4dd; --muted: #9aa0a8;
    --line: #33373d; --accent: #e08a74; --accent-soft: #3a2621; --on-accent: #1b1e21; --hl: #4a4020;
    --noun: #8cb8e0; --adj: #c9a2e6; --warn: #e0a24a;
  }
}
:root[data-theme="dark"] {
  --bg: #17191c; --panel: #1f2226; --side: #1b1e21; --ink: #e7e4dd; --muted: #9aa0a8;
  --line: #33373d; --accent: #e08a74; --accent-soft: #3a2621; --on-accent: #1b1e21; --hl: #4a4020;
  --noun: #8cb8e0; --adj: #c9a2e6; --warn: #e0a24a;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--ink); font-family: var(--ui); font-size: 15px; line-height: 1.45; }
a { color: var(--accent); }

.topbar { height: 48px; display: flex; align-items: center; gap: 12px; padding: 0 16px;
  border-bottom: 1px solid var(--line); background: var(--panel); }
.brand { font-family: var(--latin); font-size: 20px; font-weight: 700; text-decoration: none; color: var(--ink); }
.brand span { font-weight: 400; color: var(--muted); }
.menu-btn { display: none; font-size: 20px; background: none; border: 1px solid var(--line); border-radius: 6px;
  color: var(--ink); width: 36px; height: 32px; cursor: pointer; }

.layout { display: grid; grid-template-columns: minmax(280px, 380px) 1fr; height: calc(100% - 48px); }

/* ---------- sidebar / accordion ---------- */
.sidebar { background: var(--side); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.search { padding: 12px; border-bottom: 1px solid var(--line); }
.search input { width: 100%; padding: 8px 10px; font: inherit; border: 1px solid var(--line); border-radius: 6px;
  background: var(--panel); color: var(--ink); }
.search input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.search-info { font-size: 12px; color: var(--muted); margin-top: 6px; min-height: 1em; }
.tree { overflow: auto; flex: 1; padding: 6px 4px 40px; font-family: var(--latin); font-size: 15px; }
.tree ul { list-style: none; margin: 0; padding: 0 0 0 14px; }
.tree > ul { padding-left: 0; }
.tree li > ul { display: none; }
.tree li.open > ul { display: block; }
.row { display: flex; align-items: flex-start; border-radius: 4px; }
.row:hover { background: var(--accent-soft); }
.tw, .tw-space { flex: none; width: 20px; height: 24px; border: 0; background: none; color: var(--muted);
  cursor: pointer; font-size: 11px; padding: 0; }
.tw::before { content: "▸"; display: inline-block; transition: transform .12s; }
li.open > .row > .tw::before { transform: rotate(90deg); }
.lbl { flex: 1; color: var(--ink); text-decoration: none; padding: 2px 4px; }
.tree > ul > li > .row .lbl { font-weight: 700; }
li.current > .row { background: var(--accent); }
li.current > .row .lbl, li.current > .row .tw { color: var(--on-accent); }
.count { font-family: var(--ui); font-size: 11px; color: var(--muted); padding: 4px 6px 0 0; }
li.current > .row .count { color: var(--on-accent); }

.tree.filtering li { display: none; }
.tree.filtering li.match, .tree.filtering li.path { display: block; }
.tree.filtering li.path > ul { display: block; }
.tree.filtering li.match > .row .lbl mark { background: var(--hl); color: inherit; }

/* ---------- main ---------- */
.main { overflow: auto; padding: 28px 40px 80px; min-width: 0; }
.main:focus { outline: none; }
.wrap { max-width: 1000px; }
.crumbs { font-size: 13px; color: var(--muted); margin-bottom: 18px; }
.crumbs a { color: var(--muted); text-decoration: none; }
.crumbs a:hover { color: var(--accent); text-decoration: underline; }
.crumbs .sep { margin: 0 6px; opacity: .6; }
.kicker { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 0 0 6px; }

/* interlinear term display */
.term { display: flex; flex-wrap: wrap; gap: 6px 26px; margin: 0 0 30px; }
.tok { display: flex; flex-direction: column; text-decoration: none; color: inherit; border-radius: 8px; padding: 4px 6px; margin: -4px -6px; }
a.tok:hover { background: var(--accent-soft); }
.tok .la { font-family: var(--latin); font-size: clamp(32px, 5vw, 54px); line-height: 1.1; color: var(--ink);
  border-bottom: 2px solid transparent; }
a.tok:hover .la { border-bottom-color: var(--accent); }
.tok .en { font-size: 16px; color: var(--accent); margin-top: 4px; }
.tok .no { font-size: 13px; color: var(--muted); }
.tok.unknown .la { color: var(--muted); border-bottom: 2px dashed var(--line); }

h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 34px 0 10px; font-weight: 600; }

table { border-collapse: collapse; width: 100%; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
th, td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; background: var(--side); }
tr:last-child td { border-bottom: 0; }
td.la { font-family: var(--latin); font-size: 18px; }
td.la a { text-decoration: none; }
td.la a:hover { text-decoration: underline; }
.table-scroll { overflow-x: auto; }

.pos { display: inline-block; font-size: 12px; font-weight: 600; padding: 1px 8px; border-radius: 99px; border: 1px solid currentColor; }
.pos.noun { color: var(--noun); }
.pos.adjective { color: var(--adj); }
.pos.other { color: var(--muted); }
.reading { display: block; }
.reading + .reading { margin-top: 3px; }
.reading + .reading::before { content: "or "; color: var(--muted); font-style: italic; }
.reading .agr { color: var(--muted); font-size: 13px; }
.reading .agr i { font-family: var(--latin); font-size: 15px; }
.muted { color: var(--muted); }
.warn { color: var(--warn); }
.note { background: var(--accent-soft); border-left: 3px solid var(--accent); padding: 10px 14px; border-radius: 4px; margin: 18px 0; }

/* word page */
.headword { font-family: var(--latin); font-size: clamp(36px, 6vw, 60px); line-height: 1.05; margin: 0; }
.headword small { font-size: .45em; color: var(--muted); font-style: italic; }
.meaning { font-size: 22px; margin: 10px 0 0; color: var(--accent); }
.meaning-no { font-size: 16px; color: var(--muted); margin: 2px 0 0; }
.facts { display: flex; flex-wrap: wrap; gap: 8px; margin: 18px 0 0; padding: 0; list-style: none; }
.facts li { background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 4px 10px; font-size: 13px; }
.facts b { color: var(--muted); font-weight: 600; margin-right: 4px; }
.decl td, .decl th { text-align: center; }
.decl td:first-child, .decl th:first-child { text-align: left; }
.decl td.f { font-family: var(--latin); font-size: 19px; }
.decl td.f.hit { background: var(--hl); font-weight: 700; box-shadow: inset 0 0 0 2px var(--accent); }
.decl td.f.same { background: var(--accent-soft); }
.legend { font-size: 13px; color: var(--muted); margin: -4px 0 10px; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.legend .sw { width: 14px; height: 14px; border-radius: 3px; display: inline-block; margin-left: 10px; }
.legend .sw:first-child { margin-left: 0; }
.legend .sw.hit { background: var(--hl); box-shadow: inset 0 0 0 2px var(--accent); }
.legend .sw.same { background: var(--accent-soft); }
.small { font-size: 12px; margin-top: 3px; }
.decl td.empty { color: var(--line); }
.decl tr.group th { background: var(--panel); color: var(--ink); text-align: left; }
.back { display: inline-block; margin-bottom: 16px; font-size: 14px; text-decoration: none; }
.back:hover { text-decoration: underline; }

.links { columns: 2 260px; column-gap: 28px; padding: 0; margin: 0; list-style: none; font-family: var(--latin); font-size: 16px; }
.links li { break-inside: avoid; padding: 2px 0; }
.links a { text-decoration: none; }
.links a:hover { text-decoration: underline; }

.welcome h1 { font-family: var(--latin); font-size: 44px; margin: 0 0 8px; }
.welcome p { max-width: 640px; color: var(--muted); font-size: 16px; }
.btn { display: inline-block; margin-top: 10px; padding: 8px 16px; border-radius: 6px; background: var(--accent); color: var(--on-accent);
  border: 0; font: inherit; cursor: pointer; text-decoration: none; }
.stats { display: flex; gap: 28px; margin: 24px 0; }
.stats div { font-size: 13px; color: var(--muted); }
.stats b { display: block; font-family: var(--latin); font-size: 30px; color: var(--ink); }

/* ---------- narrow screens ---------- */
@media (max-width: 800px) {
  .menu-btn { display: block; }
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: fixed; top: 48px; bottom: 0; left: 0; width: min(88vw, 380px); z-index: 10;
    transform: translateX(-100%); transition: transform .2s; visibility: hidden; }
  body.drawer .sidebar { transform: none; visibility: visible; box-shadow: 0 0 30px rgba(0,0,0,.25); }
  .main { padding: 20px 16px 60px; }
  .tok .la { font-size: 34px; }
  th, td { padding: 7px 8px; }
}

.loading { color: var(--muted); padding: 20px 0; }
.error { color: var(--warn); }

/* corrections of TA2 */
.star { color: var(--accent); font-weight: 700; }
sup.star { margin-left: 1px; font-family: var(--ui); font-size: 12px; }
.tok .la.star { margin-left: -20px; }
.correction { margin: -14px 0 24px; font-size: 14px; max-width: 760px; }
.correction:not(.muted) { background: var(--accent-soft); border-left: 3px solid var(--accent); padding: 8px 12px; border-radius: 4px; }
li.current > .row .star { color: var(--on-accent); }

/* ---------- top menu ---------- */
.topnav { display: flex; gap: 4px; margin-left: 24px; height: 100%; }
.topnav a { display: flex; align-items: center; padding: 0 12px; color: var(--muted); text-decoration: none;
  font-size: 14px; font-weight: 500; border-bottom: 2px solid transparent; }
.topnav a:hover { color: var(--ink); }
.topnav a[aria-current="page"] { color: var(--ink); border-bottom-color: var(--accent); }
.topbar { gap: 0; }
.menu-btn { margin-right: 12px; }

/* pronunciation page: no term list */
body[data-page="pronunciation"] .layout, body[data-page="quiz"] .layout { grid-template-columns: 1fr; }
body[data-page="pronunciation"] .sidebar, body[data-page="quiz"] .sidebar, body[data-page="quiz"] .menu-btn,
body[data-page="pronunciation"] .menu-btn { display: none; }
body[data-page="pronunciation"] .main, body[data-page="quiz"] .main { padding-left: max(40px, calc((100% - 1000px) / 2)); }

/* ---------- pronunciation ---------- */
.pron-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; }
.page-title { font-family: var(--latin); font-size: 44px; margin: 0; line-height: 1.1; }
.lang-switch { display: flex; align-items: center; gap: 6px; font-size: 13px; }
.lang-switch button { font: inherit; padding: 5px 12px; border: 1px solid var(--line); background: var(--panel);
  color: var(--ink); border-radius: 6px; cursor: pointer; }
.lang-switch button[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.pron[data-lang="en"] [data-lang-no], .pron[data-lang="no"] [data-lang-en] { display: none; }
.pron .lead { color: var(--muted); margin: -4px 0 12px; max-width: 700px; }
.pron-table td { vertical-align: middle; }
.pron-table td:first-child { width: 170px; }
.pron-table td:nth-child(2) { width: 40%; }
.pron-table tr.vfirst td { border-top: 1px solid var(--line); }
.letter { font-family: var(--latin); font-size: 22px; font-weight: 700; margin-right: 8px; }
.ctx { display: block; font-size: 12px; color: var(--muted); }
.qty { display: inline-block; min-width: 42px; font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.pron .la { font-family: var(--latin); font-size: 17px; }
.pron .gloss { color: var(--muted); font-size: 13px; }
.small-inline { font-size: 11px; text-transform: none; letter-spacing: 0; font-weight: 400; }
.stress-rules { padding-left: 22px; max-width: 760px; }
.stress-rules li { margin-bottom: 16px; }
.stress-rules p { margin: 0 0 4px; }
.syll { font-family: var(--latin); font-size: 19px; }
.syll b { color: var(--accent); }
.syll .hy { color: var(--muted); margin: 0 1px; }

@media (max-width: 800px) {
  .topnav { margin-left: 8px; }
  .topnav a { padding: 0 8px; font-size: 13px; }
  .brand { font-size: 16px; }
  body[data-page="pronunciation"] .main, body[data-page="quiz"] .main { padding-left: 16px; }
  .pron-table td:first-child { width: auto; }
}
@media (max-width: 520px) {
  .brand { display: none; }
}
.ybreve { position: relative; display: inline-block; }
.ybreve::after { content: "˘"; position: absolute; left: 0; right: 0; top: -0.45em; text-align: center; font-size: .9em; }

@media (max-width: 600px) {
  .pron-table thead { display: none; }
  .pron-table, .pron-table tbody, .pron-table tr, .pron-table td { display: block; width: auto !important; }
  .pron-table tr { padding: 10px 12px; border-bottom: 1px solid var(--line); }
  .pron-table td { border: 0; padding: 2px 0; }
  .pron-table tr.vfirst td { border-top: 0; }
  .pron-table td[rowspan] { padding-bottom: 4px; }
}

/* ---------- quiz ---------- */
.quiz-tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin: 18px 0 16px; }
.quiz-tabs a { padding: 8px 14px; text-decoration: none; color: var(--muted); font-weight: 500; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.quiz-tabs a[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--accent); }
.quiz-bar { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; }
.quiz-intro { margin: 0; max-width: 620px; }
.quiz-score { display: flex; gap: 10px; align-items: center; font-size: 14px; white-space: nowrap; }
.quiz-score .streak { background: var(--accent-soft); color: var(--accent); padding: 2px 8px; border-radius: 99px; font-size: 12px; font-weight: 600; }
.quiz-filters { display: flex; gap: 16px; flex-wrap: wrap; margin: 14px 0 0; font-size: 14px; color: var(--muted); }
.quiz-filters select { margin-left: 6px; font: inherit; color: var(--ink); background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 4px 8px; }
.quiz-card { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 24px 28px; margin-top: 18px; }
.q-term { font-family: var(--latin); font-size: clamp(26px, 4vw, 40px); line-height: 1.3; color: var(--muted); }
.q-term .target { color: var(--ink); background: var(--hl); border-bottom: 3px solid var(--accent); padding: 0 4px; border-radius: 3px; }
.q-ask { font-size: 16px; margin: 14px 0 18px; }
.q-ask .la, .quiz .la { font-family: var(--latin); font-size: 1.1em; }
.q-groups { display: grid; gap: 12px; }
.q-group { display: grid; grid-template-columns: 110px 1fr; align-items: center; gap: 10px; }
.q-label { font-size: 13px; color: var(--muted); font-weight: 600; }
.q-opts { display: flex; flex-wrap: wrap; gap: 6px; }
.q-opts button { font: inherit; font-size: 14px; padding: 6px 14px; border-radius: 99px; border: 1px solid var(--line); background: var(--bg); color: var(--ink); cursor: pointer; }
.q-opts button:hover:not(:disabled) { border-color: var(--accent); }
.q-opts button[aria-pressed="true"] { background: var(--ink); color: var(--panel); border-color: var(--ink); }
.q-opts button.is-right { background: #2f7d4a; border-color: #2f7d4a; color: #fff; }
.q-opts button.is-wrong { background: #b3402e; border-color: #b3402e; color: #fff; text-decoration: line-through; }
.q-opts button:disabled { cursor: default; }
.q-actions { margin-top: 20px; }
.q-actions .btn:disabled { opacity: .45; cursor: default; }
.q-feedback:not(:empty) { margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--line); }
.verdict { font-weight: 700; font-size: 18px; margin: 0 0 6px; }
.verdict.ok { color: #2f7d4a; }
.verdict.bad { color: #b3402e; }
.q-readings { margin: 4px 0 8px; }
.linkish { font: inherit; background: none; border: 0; padding: 0; color: var(--accent); cursor: pointer; text-decoration: underline; }
.q-word { display: flex; align-items: baseline; gap: 16px; flex-wrap: wrap; }
.q-word .headword { font-family: var(--latin); font-size: clamp(36px, 6vw, 56px); }
.q-meta { font-size: 14px; color: var(--muted); }
.q-decl { max-width: 560px; margin-top: 8px; }
.q-decl td { padding: 8px; }
.q-decl td.given { font-family: var(--latin); font-size: 19px; text-align: center; }
.q-decl input { width: 100%; font-family: var(--latin); font-size: 18px; padding: 6px 8px; border: 1px solid var(--line); border-radius: 6px; background: var(--bg); color: var(--ink); text-align: center; }
.q-decl input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.q-decl input.is-right { border-color: #2f7d4a; background: #e3f2e7; color: #1d5532; }
.q-decl input.is-wrong { border-color: #b3402e; background: #f8e1dc; color: #7c2a1d; text-decoration: line-through; }
.q-correct { display: block; font-family: var(--latin); font-size: 17px; color: #2f7d4a; font-weight: 700; margin-top: 4px; text-align: center; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .q-decl input.is-right { background: #1d3a26; color: #a8dcb6; }
  :root:not([data-theme="light"]) .q-decl input.is-wrong { background: #432019; color: #f0b3a6; }
  :root:not([data-theme="light"]) .q-correct, :root:not([data-theme="light"]) .verdict.ok { color: #7fcf97; }
  :root:not([data-theme="light"]) .verdict.bad { color: #f09482; }
}
@media (max-width: 600px) {
  .quiz-card { padding: 16px; }
  .q-group { grid-template-columns: 1fr; gap: 4px; }
  .topnav a { padding: 0 6px; }
}
