:root {
  --bg: #f6f5f1; --card: #ffffff; --ink: #1d2327; --muted: #667079; --line: #dedbd3;
  --accent: #1f5f8b; --accent-ink: #ffffff; --soft: #e9f1f6;
  --good: #23764a; --good-bg: #e3f3ea; --mid: #96690a; --mid-bg: #fbf0d3; --bad: #a8322d; --bad-bg: #fae5e3;
  --tag: #d3e5f2; --pend: #fbf0d3; --pend-line: #96690a; --none-bg: #ebebea; --paper: #ffffff;
  color-scheme: light;
}
/* Dark colours apply when the device is in dark mode (unless the reader chose Light with the header
   button), or when the reader chose Dark. The two blocks must stay identical. Same palette as the
   Methods and Specialist sites. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #15181b; --card: #1e2327; --ink: #e8eaec; --muted: #98a2ab; --line: #343b42;
    --accent: #6db3e2; --accent-ink: #10202b; --soft: #233441;
    --good: #6fd09a; --good-bg: #1c3528; --mid: #e6bd5c; --mid-bg: #3a3017; --bad: #f08a84; --bad-bg: #40211f;
    --tag: #284660; --pend: #3a3017; --pend-line: #e6bd5c; --none-bg: #2b3137; --paper: #1e2327;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #15181b; --card: #1e2327; --ink: #e8eaec; --muted: #98a2ab; --line: #343b42;
  --accent: #6db3e2; --accent-ink: #10202b; --soft: #233441;
  --good: #6fd09a; --good-bg: #1c3528; --mid: #e6bd5c; --mid-bg: #3a3017; --bad: #f08a84; --bad-bg: #40211f;
  --tag: #284660; --pend: #3a3017; --pend-line: #e6bd5c; --none-bg: #2b3137; --paper: #1e2327;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.6 system-ui, -apple-system, "Segoe UI", sans-serif; }
body.bar-open { padding-bottom: 150px; }
a { color: var(--accent); }
main { max-width: 1120px; margin: 0 auto; padding: 24px 16px 80px; }
.wrap { max-width: 1120px; margin: 0 auto; padding: 0 16px; }
h1 { font-size: 1.5rem; line-height: 1.25; margin: 0 0 4px; letter-spacing: -0.01em; }
h2 { font-size: 1.05rem; margin: 28px 0 10px; }
h3 { font-size: 1rem; margin: 18px 0 2px; }
.muted { color: var(--muted); }
.small { font-size: 0.875rem; }
.center { text-align: center; }

.top { display: flex; align-items: center; gap: 24px; padding: 12px 20px; border-bottom: 1px solid var(--line); background: var(--card); position: sticky; top: 0; z-index: 5; }
.brand { font-weight: 700; text-decoration: none; color: var(--ink); letter-spacing: -0.01em; }
.demo { font-size: 0.7rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; background: var(--soft); color: var(--accent); border-radius: 999px; padding: 2px 8px; margin-left: 4px; vertical-align: 2px; }
.top nav { display: flex; gap: 16px; }
.top nav a { text-decoration: none; color: var(--muted); font-weight: 500; }
.top nav a:hover, .top nav a.on { color: var(--ink); }
.theme-btn { margin-left: auto; display: inline-flex; align-items: center; gap: 7px; font: inherit; font-size: 0.875rem; font-weight: 500; color: var(--muted); background: transparent; border: 1px solid var(--line); border-radius: 999px; padding: 5px 12px 5px 10px; cursor: pointer; white-space: nowrap; }
.theme-btn:hover { color: var(--ink); border-color: var(--accent); }
.theme-btn svg { width: 16px; height: 16px; flex: none; }
@media (max-width: 560px) {
  .top { gap: 10px 14px; padding: 10px 14px; flex-wrap: wrap; position: static; }
  .top nav { order: 3; width: 100%; }
  .theme-btn { padding: 6px; }
  .theme-btn span { display: none; }
}

.card { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 16px 18px; margin: 14px 0; }
.how { background: var(--soft); border-color: transparent; }
.btn { font: inherit; font-weight: 600; border: 1px solid var(--line); background: var(--card); color: var(--ink); border-radius: 8px; padding: 7px 14px; cursor: pointer; }
.btn:hover:not(:disabled) { border-color: var(--accent); }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.good { background: var(--good-bg); border-color: var(--good); color: var(--good); }
.btn.bad { background: var(--bad-bg); border-color: var(--bad); color: var(--bad); }
.link-btn { font: inherit; font-size: 0.85rem; color: var(--accent); background: none; border: 0; padding: 0; text-decoration: underline; cursor: pointer; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; align-items: center; }
.actions.center { justify-content: center; }
.toggle { display: inline-flex; gap: 6px; align-items: center; margin-top: 10px; cursor: pointer; }
label.toggle.center { display: flex; justify-content: center; }

/* feature finding */
.layout { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 0 18px; align-items: start; }
.side { position: sticky; top: 72px; }
@media (max-width: 860px) { .layout { grid-template-columns: minmax(0, 1fr); } .side { position: static; } }
.textcard { background: var(--paper); }
.intro { font-style: italic; color: var(--muted); font-size: 0.92rem; margin-top: 0; }
.text { font-family: Georgia, "Times New Roman", serif; font-size: 1.06rem; line-height: 1.95; }
.ln { display: grid; grid-template-columns: 2.4em minmax(0, 1fr); }
.no { color: var(--muted); font: 0.75rem/2.6 system-ui, sans-serif; font-variant-numeric: tabular-nums; text-align: right; padding-right: 0.9em; user-select: none; -webkit-user-select: none; }
.tx { overflow-wrap: anywhere; }
.w { border-radius: 3px; cursor: text; padding: 1px 0; }
.w:hover { box-shadow: inset 0 -2px 0 var(--line); }
.sp { padding: 1px 0; }
.t-tagged { background: var(--tag); }
.t-good { background: var(--good-bg); box-shadow: inset 0 -2px 0 var(--good); }
.t-mid { background: var(--mid-bg); box-shadow: inset 0 -2px 0 var(--mid); }
.t-long { background: var(--mid-bg); box-shadow: inset 0 -2px 0 var(--mid); }
.t-none { background: var(--none-bg); }
.k { text-decoration: underline dashed var(--accent) 2px; text-underline-offset: 5px; }
.fl { animation: flash 0.65s ease-in-out 4; }
@keyframes flash { 50% { background: var(--pend); box-shadow: 0 0 0 3px var(--pend); } }
.pe { background: var(--soft); box-shadow: inset 0 -2px 0 var(--accent); }
@media (prefers-reduced-motion: reduce) { .fl { animation: none; background: var(--pend); } }

.tags { list-style: none; margin: 0; padding: 0; }
.tags li { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 8px; align-items: start; padding: 8px 0; border-bottom: 1px solid var(--line); }
.tags li:last-child { border-bottom: 0; }
.tags li:not([class]) { grid-template-columns: minmax(0, 1fr) auto; }
.tags .lab { display: inline-block; font-size: 0.78rem; font-weight: 600; background: var(--soft); color: var(--accent); border-radius: 999px; padding: 1px 8px; }
.tags .q { font-family: Georgia, serif; }
.ri { width: 22px; height: 22px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; font-size: 0.8rem; font-weight: 700; margin-top: 1px; }
.r-good .ri { background: var(--good-bg); color: var(--good); }
.r-mid .ri, .r-long .ri { background: var(--mid-bg); color: var(--mid); }
.r-none .ri { background: var(--none-bg); color: var(--muted); }
.x { font: inherit; font-size: 1.1rem; line-height: 1; background: none; border: 0; color: var(--muted); cursor: pointer; padding: 2px 6px; border-radius: 6px; }
.x:hover { color: var(--bad); background: var(--bad-bg); }

.legend { display: flex; flex-wrap: wrap; gap: 6px 18px; font-size: 0.875rem; color: var(--muted); }
.sw { display: inline-block; width: 14px; height: 14px; border-radius: 3px; margin-right: 6px; vertical-align: -2px; }
.kgroup + .kgroup { margin-top: 10px; }
.kgroup h3 { display: flex; justify-content: space-between; gap: 10px; align-items: baseline; border-top: 1px solid var(--line); padding-top: 14px; }
.kgroup > p { margin: 2px 0 8px; }
.kitem { border: 1px solid var(--line); border-left: 4px solid var(--line); border-radius: 8px; padding: 10px 14px; margin: 10px 0; }
.kitem p { margin: 6px 0; }
.kitem.got { border-left-color: var(--good); }
.kitem.miss { border-left-color: var(--mid); }
.khead { display: flex; flex-wrap: wrap; gap: 4px 10px; align-items: baseline; }
.khead .link-btn { margin-left: auto; }
.badge { font-size: 0.75rem; font-weight: 600; border-radius: 999px; padding: 1px 8px; }
.got .badge { background: var(--good-bg); color: var(--good); }
.miss .badge { background: var(--mid-bg); color: var(--mid); }
.kq { font-family: Georgia, serif; margin-top: 4px; }
.link { color: var(--accent); font-weight: 600; }

.tagbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; background: var(--card); border-top: 2px solid var(--accent); box-shadow: 0 -6px 18px rgba(0, 0, 0, 0.12); padding: 10px 0 calc(10px + env(safe-area-inset-bottom)); }
.bar-in { display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: center; justify-content: space-between; }
.bar-in .sel { min-width: 0; flex: 1 1 260px; }
.bar-in .q { font-family: Georgia, serif; }
.ctl { display: flex; gap: 8px; flex-wrap: wrap; }
.ctl select { font: inherit; font-size: 0.95rem; padding: 7px 10px; border-radius: 8px; border: 1px solid var(--line); background: var(--card); color: var(--ink); max-width: 100%; }

/* metalanguage */
.segs { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; padding: 3px; background: var(--card); margin: 10px 0 4px; }
.seg { font: inherit; font-size: 0.92rem; border: 0; background: none; color: var(--muted); padding: 6px 14px; border-radius: 7px; cursor: pointer; }
.seg.on { background: var(--accent); color: var(--accent-ink); }
.progress { display: flex; align-items: center; gap: 12px; margin: 14px 0 6px; }
.progress .bar { flex: 1; height: 6px; background: var(--line); border-radius: 3px; overflow: hidden; }
.progress .bar i { display: block; height: 100%; background: var(--accent); }
.flash { display: block; width: 100%; max-width: 640px; min-height: 260px; margin: 10px auto 0; text-align: left; font: inherit; color: inherit; background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 22px 24px; cursor: pointer; box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05); }
.flash:hover { border-color: var(--accent); }
.flash:not(.back) { display: flex; flex-direction: column; justify-content: center; align-items: center; text-align: center; }
.topic { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); }
.term { font-size: 1.35rem; font-weight: 700; margin: 4px 0 8px; }
.term.big { font-size: 2rem; }
.def.big { font-size: 1.15rem; max-width: 34em; margin: 8px auto; }
.ex b { color: var(--accent); }
.tip { background: var(--soft); border-radius: 8px; padding: 8px 12px; }
.intext { border-left: 3px solid var(--accent); padding: 4px 12px; margin-top: 12px; }
.intext .q, .def .q { font-family: Georgia, serif; }
.options { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 8px; margin-top: 12px; }
.opt { font: inherit; text-align: left; border: 1px solid var(--line); background: var(--card); color: var(--ink); border-radius: 10px; padding: 12px 14px; cursor: pointer; }
.opt:hover:not(:disabled) { border-color: var(--accent); }
.opt:disabled { cursor: default; }
.opt.right { background: var(--good-bg); border-color: var(--good); color: var(--good); font-weight: 600; }
.opt.wrong { background: var(--bad-bg); border-color: var(--bad); color: var(--bad); }
.feedback { margin-top: 12px; padding: 10px 14px; border-radius: 8px; }
.feedback.ok { background: var(--good-bg); }
.feedback.no { background: var(--bad-bg); }
.review { text-align: left; max-width: 640px; margin: 0 auto 14px; }
.termcard .term { margin-top: 2px; }
