/* ───────────── Tokens ───────────── */
:root,
:root[data-theme="dark"] {
  --bg: #0e1120;
  --bg-grad: radial-gradient(1200px 600px at 85% -10%, #1d2550 0%, transparent 60%),
             radial-gradient(900px 500px at -10% 10%, #1a1633 0%, transparent 55%);
  --surface: #151a2e;
  --surface-2: #1b2139;
  --surface-3: #232a47;
  --border: #2a3152;
  --border-strong: #3a4270;
  --text: #e8eaf6;
  --text-2: #b7bcd9;
  --muted: #8a90b4;
  --accent: #7c9cff;
  --accent-ink: #0e1120;
  --accent-soft: rgba(124, 156, 255, 0.14);
  --ok: #4fd1a1;
  --ok-soft: rgba(79, 209, 161, 0.14);
  --bad: #ff7a90;
  --bad-soft: rgba(255, 122, 144, 0.14);

  --c-stem: #d9dcef;
  --c-stem-bg: rgba(217, 220, 239, 0.08);
  --c-alt: #ff8fa3;
  --c-num: #60b8ff;
  --c-num-bg: rgba(96, 184, 255, 0.13);
  --c-poss: #c99cff;
  --c-poss-bg: rgba(201, 156, 255, 0.13);
  --c-case: #ffb454;
  --c-case-bg: rgba(255, 180, 84, 0.13);
  --c-buf: #6ee7b7;
  --c-trig: #5eead4;
  --c-out: #ffd166;

  --shadow: 0 1px 0 rgba(255, 255, 255, 0.03) inset, 0 10px 30px -12px rgba(0, 0, 0, 0.55);
  --radius: 16px;
  --radius-sm: 10px;
  --font: "Inter", "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: dark;
}

:root[data-theme="light"] {
  --bg: #f5f6fb;
  --bg-grad: radial-gradient(1200px 600px at 85% -10%, #e3e8ff 0%, transparent 60%),
             radial-gradient(900px 500px at -10% 10%, #f1e9ff 0%, transparent 55%);
  --surface: #ffffff;
  --surface-2: #f4f5fb;
  --surface-3: #e9ebf6;
  --border: #dfe2ef;
  --border-strong: #c7cce2;
  --text: #171a2c;
  --text-2: #3d4263;
  --muted: #6b7091;
  --accent: #4561e8;
  --accent-ink: #ffffff;
  --accent-soft: rgba(69, 97, 232, 0.1);
  --ok: #10956b;
  --ok-soft: rgba(16, 149, 107, 0.1);
  --bad: #d23f5a;
  --bad-soft: rgba(210, 63, 90, 0.1);

  --c-stem: #2b3050;
  --c-stem-bg: rgba(43, 48, 80, 0.06);
  --c-alt: #d23f5a;
  --c-num: #1d78c9;
  --c-num-bg: rgba(29, 120, 201, 0.1);
  --c-poss: #8a44d6;
  --c-poss-bg: rgba(138, 68, 214, 0.1);
  --c-case: #b86a00;
  --c-case-bg: rgba(184, 106, 0, 0.1);
  --c-buf: #0f8f63;
  --c-trig: #0e8f86;
  --c-out: #a86b00;

  --shadow: 0 1px 2px rgba(20, 24, 50, 0.05), 0 8px 24px -14px rgba(20, 24, 50, 0.25);
  color-scheme: light;
}

/* ───────────── Base ───────────── */
*,
*::before,
*::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.55;
  color: var(--text);
  background: var(--bg);
  background-image: var(--bg-grad);
  background-attachment: fixed;
  min-height: 100vh;
  overflow-x: hidden;
}

:lang(zh-Hant) body, html[lang="zh-Hant"] body { letter-spacing: 0.01em; }

h1, h2, h3 { margin: 0; line-height: 1.25; }
p { margin: 0; }
a { color: var(--accent); }
button { font: inherit; color: inherit; }
code, pre, .mono { font-family: var(--mono); }
[hidden] { display: none !important; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }

.skip {
  position: absolute; left: -999px; top: 8px; z-index: 100;
  background: var(--accent); color: var(--accent-ink); padding: 8px 12px; border-radius: 8px;
}
.skip:focus { left: 8px; }

.muted { color: var(--muted); }
.hint { color: var(--muted); font-size: 13px; margin-top: 4px; }

/* ───────────── Top bar ───────────── */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px clamp(16px, 3vw, 32px);
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: saturate(140%) blur(14px);
  -webkit-backdrop-filter: saturate(140%) blur(14px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.logo { display: flex; gap: 3px; flex: none; }
.logo span { width: 10px; height: 26px; border-radius: 4px; }
.logo span:nth-child(1) { background: var(--c-stem); width: 14px; }
.logo span:nth-child(2) { background: var(--c-num); }
.logo span:nth-child(3) { background: var(--c-case); }
.brand-text { min-width: 0; }
.brand h1 { font-size: 18px; font-weight: 700; letter-spacing: -0.01em; }
.brand p { font-size: 12.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top-actions { display: flex; gap: 6px; flex: none; }

/* ───────────── Buttons & chips ───────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 36px; padding: 0 14px;
  border-radius: 999px; border: 1px solid var(--border-strong);
  background: var(--surface-2); color: var(--text);
  font-weight: 600; font-size: 13.5px; cursor: pointer; text-decoration: none;
  transition: background 0.15s, border-color 0.15s, transform 0.08s;
}
.btn:hover { background: var(--surface-3); }
.btn:active { transform: translateY(1px); }
.btn.ghost { background: transparent; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.small { height: 30px; padding: 0 11px; font-size: 12.5px; }
.btn.icon { width: 36px; padding: 0; }
.btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; }
.btn svg.fill { fill: currentColor; stroke: none; }
:root[data-theme="dark"] .i-sun, :root[data-theme="light"] .i-moon { display: none; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  min-height: 34px; padding: 5px 12px;
  border-radius: 999px; border: 1px solid var(--border);
  background: var(--surface-2); color: var(--text-2);
  font-size: 13px; font-weight: 500; cursor: pointer; line-height: 1.2;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.chip:hover { border-color: var(--border-strong); color: var(--text); }
.chip small { color: var(--muted); font-weight: 400; font-size: 11.5px; }
.chip[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); color: var(--text); }
.chip[disabled] { opacity: 0.45; cursor: not-allowed; }

.chip.slot-NUMBER[aria-pressed="true"] { background: var(--c-num-bg); border-color: var(--c-num); }
.chip.slot-POSS[aria-pressed="true"] { background: var(--c-poss-bg); border-color: var(--c-poss); }
.chip.slot-CASE[aria-pressed="true"] { background: var(--c-case-bg); border-color: var(--c-case); }

/* ───────────── Tabs ───────────── */
.tabs {
  display: flex; gap: 4px;
  padding: 10px clamp(16px, 3vw, 32px) 0;
  max-width: 1400px; margin: 0 auto;
  overflow-x: auto; scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tabs button {
  flex: none; display: inline-flex; align-items: center; gap: 7px;
  padding: 9px 15px; border-radius: 999px;
  border: 1px solid transparent; background: transparent;
  color: var(--muted); font-weight: 600; font-size: 14px; cursor: pointer;
}
.tabs button:hover { color: var(--text); background: var(--surface-2); }
.tabs button[aria-selected="true"] { color: var(--text); background: var(--surface); border-color: var(--border); box-shadow: var(--shadow); }
.tab-ic { font-size: 13px; opacity: 0.9; font-family: var(--mono); }

/* ───────────── Layout ───────────── */
main { max-width: 1400px; margin: 0 auto; padding: 16px clamp(16px, 3vw, 32px) 24px; }
.panel { display: flex; flex-direction: column; gap: 16px; animation: fade 0.2s ease; }
.panel.narrow { max-width: 820px; margin: 0 auto; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow);
  min-width: 0;
}
.card-head { margin-bottom: 12px; }
.card-head.row { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.card h2 { font-size: 15.5px; font-weight: 700; display: flex; align-items: center; gap: 8px; }
.step-no {
  display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: 50%;
  background: var(--accent-soft); color: var(--accent); font-size: 12px; font-weight: 700;
}
.mini-actions { display: flex; gap: 6px; }
.section-title { font-size: 18px; margin: 8px 2px 0; }
.toolbar { display: flex; flex-wrap: wrap; gap: 10px 18px; align-items: center; margin-bottom: 14px; }
.toolbar .label { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; margin-right: 4px; }
.toolbar .group { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; }

.builder { display: grid; grid-template-columns: minmax(320px, 400px) minmax(0, 1fr); gap: 16px; align-items: start; }
.controls { display: flex; flex-direction: column; gap: 16px; position: sticky; top: 124px; max-height: calc(100vh - 140px); overflow: auto; scrollbar-width: thin; padding-bottom: 2px; }
.results { display: flex; flex-direction: column; gap: 16px; min-width: 0; }

/* ───────────── Concepts ───────────── */
.concept-group + .concept-group { margin-top: 10px; }
.concept-group h3 { font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.07em; color: var(--muted); font-weight: 600; margin-bottom: 6px; }
.chip.concept { padding: 5px 11px; }
.chip.concept .w { font-weight: 600; color: var(--text); }

.stem-inputs { display: grid; gap: 10px; margin-top: 14px; padding-top: 14px; border-top: 1px dashed var(--border); }
.stem-field { display: grid; gap: 5px; }
.stem-field label { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; font-size: 12.5px; font-weight: 600; color: var(--text-2); }
.stem-field label small { font-weight: 400; color: var(--muted); font-family: var(--mono); }
.stem-field input[type="text"] {
  width: 100%; height: 40px; padding: 0 12px;
  border-radius: var(--radius-sm); border: 1px solid var(--border-strong);
  background: var(--surface-2); color: var(--text);
  font: 500 16px var(--font);
}
.stem-field input[type="text"]:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.stem-field.off { opacity: 0.45; }
.kb { display: flex; flex-wrap: wrap; gap: 4px; }
.kb button {
  min-width: 30px; height: 28px; padding: 0 7px; border-radius: 7px;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text-2);
  font-size: 13.5px; cursor: pointer;
}
.kb button:hover { border-color: var(--accent); color: var(--text); }
.flags { display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: 12px; color: var(--muted); }
.flags label { display: inline-flex; align-items: center; gap: 5px; cursor: pointer; }
.flags input { accent-color: var(--accent); }
.note { font-size: 11.5px; color: var(--muted); }

/* ───────────── Slots ───────────── */
.slot-row { display: grid; gap: 6px; }
.slot-row + .slot-row { margin-top: 12px; }
.slot-label { display: flex; align-items: center; gap: 7px; font-size: 12px; font-weight: 700; color: var(--text-2); text-transform: uppercase; letter-spacing: 0.05em; }
.dot { width: 9px; height: 9px; border-radius: 3px; flex: none; }
.dot.NUMBER { background: var(--c-num); }
.dot.POSS { background: var(--c-poss); }
.dot.CASE { background: var(--c-case); }
.dot.STEM { background: var(--c-stem); }
.chip.case small { display: block; }

.lang-toggles { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.lang-toggle {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px;
  border-radius: 12px; border: 1px solid var(--border); background: var(--surface-2);
  cursor: pointer; text-align: left;
}
.lang-toggle .sw { width: 30px; height: 18px; border-radius: 999px; background: var(--surface-3); position: relative; flex: none; transition: background 0.15s; }
.lang-toggle .sw::after { content: ""; position: absolute; top: 2px; left: 2px; width: 14px; height: 14px; border-radius: 50%; background: var(--muted); transition: transform 0.15s, background 0.15s; }
.lang-toggle[aria-pressed="true"] { border-color: var(--accent); }
.lang-toggle[aria-pressed="true"] .sw { background: var(--accent); }
.lang-toggle[aria-pressed="true"] .sw::after { transform: translateX(12px); background: #fff; }
.lang-toggle .nm { font-weight: 600; font-size: 13.5px; line-height: 1.2; }
.lang-toggle .br { font-size: 11.5px; color: var(--muted); }
.lang-toggle[disabled] { opacity: 0.5; cursor: not-allowed; }

/* ───────────── Morpheme rendering ───────────── */
.word { font-weight: 700; letter-spacing: 0.005em; word-break: break-word; }
.seg { border-radius: 4px; padding: 0 1px; }
.seg.stem { color: var(--c-stem); }
.seg.stem.altered { color: var(--c-alt); text-decoration: underline wavy color-mix(in srgb, var(--c-alt) 60%, transparent); text-underline-offset: 5px; text-decoration-thickness: 1.5px; }
.seg.NUMBER { color: var(--c-num); }
.seg.POSS { color: var(--c-poss); }
.seg.CASE { color: var(--c-case); }
.seg.buffer { color: var(--c-buf); font-style: italic; text-decoration: underline dotted; text-underline-offset: 5px; }
.sep { color: var(--muted); opacity: 0.6; font-weight: 400; }

mark.t, mark.o {
  display: inline-block; padding: 0 5px; border-radius: 5px; font-family: var(--mono); font-weight: 600; font-size: 0.95em; line-height: 1.35;
}
mark.t { background: color-mix(in srgb, var(--c-trig) 16%, transparent); color: var(--c-trig); box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--c-trig) 45%, transparent); }
mark.o { background: color-mix(in srgb, var(--c-out) 18%, transparent); color: var(--c-out); }

/* ───────────── Results ───────────── */
.summary { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; }
.summary .meaning { font-size: 20px; font-weight: 700; }
.summary .label { font-size: 11.5px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.07em; font-weight: 600; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 12px; color: var(--muted); margin-top: 12px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }

.lang-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(290px, 1fr)); gap: 16px; }
.lang-card { display: flex; flex-direction: column; gap: 14px; }
.lang-card header { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.lang-card header .nm { font-weight: 700; font-size: 15px; }
.badge { font-size: 11px; font-weight: 600; padding: 3px 8px; border-radius: 999px; background: var(--surface-3); color: var(--text-2); white-space: nowrap; }
.badge.warn { background: var(--bad-soft); color: var(--bad); }
.badge.good { background: var(--ok-soft); color: var(--ok); }
.lang-card .big { font-size: clamp(28px, 4.2vw, 38px); line-height: 1.15; }
.lang-card .roman { font-family: var(--mono); color: var(--muted); font-size: 13.5px; margin-top: 2px; }
.lang-card .gloss { font-family: var(--mono); font-size: 12.5px; color: var(--text-2); background: var(--surface-2); border-radius: 8px; padding: 8px 10px; overflow-x: auto; white-space: nowrap; }
.gloss .tag { font-variant: small-caps; letter-spacing: 0.03em; }

.chain { display: flex; align-items: stretch; flex-wrap: wrap; gap: 6px; }
.block {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  min-width: 56px; padding: 6px 10px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface-2);
  position: relative;
}
.block .bt { font-size: 10.5px; font-weight: 700; letter-spacing: 0.06em; color: var(--muted); }
.block .ba { font-family: var(--mono); font-size: 11.5px; color: var(--muted); }
.block .bs { font-weight: 700; font-size: 17px; }
.block.STEM { background: var(--c-stem-bg); }
.block.STEM .bs { color: var(--c-stem); }
.block.STEM.altered .bs { color: var(--c-alt); }
.block.NUMBER { background: var(--c-num-bg); border-color: color-mix(in srgb, var(--c-num) 40%, transparent); }
.block.NUMBER .bs { color: var(--c-num); }
.block.POSS { background: var(--c-poss-bg); border-color: color-mix(in srgb, var(--c-poss) 40%, transparent); }
.block.POSS .bs { color: var(--c-poss); }
.block.CASE { background: var(--c-case-bg); border-color: color-mix(in srgb, var(--c-case) 40%, transparent); }
.block.CASE .bs { color: var(--c-case); }
.block .buf { color: var(--c-buf); font-style: italic; }
.plus { align-self: center; color: var(--muted); font-weight: 600; }

.traits { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; }
.trait { background: var(--surface-2); border-radius: 9px; padding: 7px 10px; min-width: 0; }
.trait .k { font-size: 11px; color: var(--muted); font-weight: 600; }
.trait .v { font-size: 13.5px; font-weight: 600; overflow-wrap: anywhere; }
.trait .v .mono { font-size: 14px; }
.trait-note { font-size: 12px; color: var(--muted); margin-top: -4px; }

.steps { display: grid; gap: 10px; margin: 0; padding: 0; list-style: none; }
.step { border-left: 3px solid var(--border-strong); padding: 2px 0 2px 12px; }
.step.NUMBER { border-color: var(--c-num); }
.step.POSS { border-color: var(--c-poss); }
.step.CASE { border-color: var(--c-case); }
.step .sh { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px; font-size: 13px; }
.step .sh .tag { font-weight: 700; font-size: 11.5px; letter-spacing: 0.05em; }
.step .sh .arch { font-family: var(--mono); color: var(--muted); }
.step .sh .arrow { color: var(--muted); }
.step .sh .surf { font-family: var(--mono); font-weight: 700; }
.step ul { margin: 5px 0 0; padding-left: 16px; font-size: 13px; color: var(--text-2); }
.step li { margin: 3px 0; }
.step li::marker { color: var(--muted); }

.sub-h { font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.07em; color: var(--muted); font-weight: 700; margin-bottom: 8px; }

/* Tables */
.table-wrap { overflow-x: auto; border-radius: 12px; border: 1px solid var(--border); -webkit-overflow-scrolling: touch; }
table { border-collapse: collapse; width: 100%; font-size: 14px; }
th, td { padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
tr:last-child td { border-bottom: none; }
thead th { background: var(--surface-2); font-size: 12px; color: var(--muted); font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; position: sticky; top: 0; }
tbody th { font-weight: 600; color: var(--text-2); background: var(--surface); position: sticky; left: 0; z-index: 1; }
td.cell { cursor: pointer; font-weight: 600; transition: background 0.12s; }
td.cell:hover { background: var(--accent-soft); }
td.cell.current { background: var(--accent-soft); box-shadow: inset 0 0 0 2px var(--accent); }
td .rom, th .rom { display: block; font-family: var(--mono); font-size: 11.5px; color: var(--muted); font-weight: 400; }
.cmp td .mono { font-weight: 600; }

/* Explorer */
.explorer { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 14px; }
.ex-lang h3 { font-size: 14px; margin-bottom: 8px; display: flex; align-items: center; gap: 8px; }
.ex-group { background: var(--surface-2); border-radius: 12px; padding: 10px 12px; margin-bottom: 8px; }
.ex-group .allo { font-family: var(--mono); font-weight: 700; font-size: 16px; color: var(--c-case); }
.ex-group.NUMBER .allo { color: var(--c-num); }
.ex-group.POSS .allo { color: var(--c-poss); }
.ex-group .words { display: flex; flex-wrap: wrap; gap: 4px 10px; margin-top: 4px; font-size: 13.5px; color: var(--text-2); }

/* Practice */
.scoreboard { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stat { background: var(--surface-2); border-radius: 12px; padding: 10px 12px; text-align: center; }
.stat .n { font-size: 22px; font-weight: 700; }
.stat .k { font-size: 11.5px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; }
.quiz-q { display: flex; flex-direction: column; gap: 14px; }
.quiz-meta { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.quiz-prompt { font-size: 22px; font-weight: 700; display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.options { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.option {
  display: flex; align-items: center; gap: 10px; text-align: left;
  min-height: 56px; padding: 10px 14px; border-radius: 14px;
  border: 1px solid var(--border-strong); background: var(--surface-2);
  font-size: 19px; font-weight: 600; cursor: pointer; transition: border-color 0.15s, background 0.15s;
}
.option .kbd { font-family: var(--mono); font-size: 11px; color: var(--muted); border: 1px solid var(--border-strong); border-radius: 5px; padding: 1px 6px; flex: none; }
.option .rom { font-family: var(--mono); font-size: 12px; color: var(--muted); font-weight: 400; display: block; }
.option:hover:not([disabled]) { border-color: var(--accent); background: var(--accent-soft); }
.option.right { border-color: var(--ok); background: var(--ok-soft); }
.option.wrong { border-color: var(--bad); background: var(--bad-soft); }
.option[disabled] { cursor: default; }
.feedback { border-radius: 12px; padding: 12px 14px; font-weight: 600; }
.feedback.ok { background: var(--ok-soft); color: var(--ok); }
.feedback.no { background: var(--bad-soft); color: var(--bad); }
.quiz-foot { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }

/* Grammar */
.lessons { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 16px; }
.lesson { display: flex; flex-direction: column; gap: 10px; }
.lesson .ic { font-size: 22px; }
.lesson h3 { font-size: 16px; }
.lesson p { color: var(--text-2); font-size: 14px; }
.lesson .ex { display: grid; gap: 6px; }
.lesson .ex div { background: var(--surface-2); border-radius: 9px; padding: 7px 10px; }
.lesson .ex b { font-family: var(--mono); font-size: 13.5px; display: block; }
.lesson .ex span { font-size: 12.5px; color: var(--muted); }

.vowel-chart { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); gap: 18px; align-items: start; }
.vgrid { display: grid; grid-template-columns: 44px repeat(4, minmax(0, 1fr)); gap: 6px; }
.vgrid .hd { font-size: 11px; color: var(--muted); font-weight: 600; text-align: center; align-self: end; line-height: 1.25; }
.vgrid .rh { font-size: 11px; color: var(--muted); font-weight: 600; align-self: center; }
.vbtn {
  aspect-ratio: 1.25; border-radius: 12px; border: 1px solid var(--border-strong); background: var(--surface-2);
  font-size: 26px; font-weight: 700; cursor: pointer; transition: all 0.15s;
}
.vbtn:hover { border-color: var(--accent); }
.vbtn[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.vresult { display: grid; gap: 8px; }
.vresult .row { background: var(--surface-2); border-radius: 10px; padding: 9px 12px; display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; align-items: baseline; }
.vresult .row .k { font-size: 12.5px; color: var(--muted); font-weight: 600; }
.vresult .row .v { font-family: var(--mono); font-size: 15px; font-weight: 600; }

/* Code */
.code {
  margin: 0; padding: 16px; border-radius: 12px; background: #0a0d18; color: #d6dcff;
  border: 1px solid var(--border); overflow: auto; max-height: 560px;
  font-size: 12.8px; line-height: 1.6; tab-size: 2;
}
:root[data-theme="light"] .code { background: #11152a; }
.code .c { color: #7d86b3; font-style: italic; }
.code .s { color: #a8e6a3; }
.code .k { color: #c99cff; }
.code .n { color: #ffb454; }
.trace { display: grid; gap: 12px; }
.trace-lang h3 { font-size: 14px; margin-bottom: 6px; }
.fsm { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.state { border: 1px solid var(--border-strong); border-radius: 12px; padding: 6px 10px; background: var(--surface-2); font-size: 12px; min-width: 0; }
.state .sid { font-family: var(--mono); color: var(--muted); font-size: 11px; }
.state .sf { font-weight: 700; font-size: 15px; }
.state .sv { font-family: var(--mono); color: var(--muted); font-size: 11px; }
.edge { font-family: var(--mono); font-size: 11.5px; color: var(--muted); display: flex; flex-direction: column; align-items: center; line-height: 1.2; }
.edge .arr { font-size: 16px; color: var(--text-2); }

/* Footer, toast */
.footer { max-width: 1400px; margin: 0 auto; padding: 8px clamp(16px, 3vw, 32px) 40px; display: flex; justify-content: space-between; flex-wrap: wrap; gap: 8px; font-size: 12.5px; color: var(--muted); }
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: var(--text); color: var(--bg); padding: 9px 16px; border-radius: 999px; font-weight: 600; font-size: 13.5px;
  transition: opacity 0.2s, transform 0.2s; z-index: 50;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.empty { color: var(--muted); font-size: 14px; padding: 8px 0; }

/* ───────────── Responsive ───────────── */
@media (max-width: 1080px) {
  .builder { grid-template-columns: minmax(0, 1fr); }
  .controls { position: static; max-height: none; overflow: visible; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .controls > .card:first-child { grid-row: span 2; }
}
@media (max-width: 760px) {
  body { font-size: 14.5px; }
  .brand p { display: none; }
  .brand h1 { font-size: 16.5px; }
  .topbar { padding-top: max(10px, env(safe-area-inset-top)); }
  .tabs { position: sticky; top: 57px; z-index: 15; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); padding-bottom: 8px; border-bottom: 1px solid var(--border); }
  .tabs button { padding: 8px 12px; font-size: 13.5px; }
  main { padding-top: 12px; }
  .controls { grid-template-columns: minmax(0, 1fr); }
  .controls > .card:first-child { grid-row: auto; }
  .card { padding: 14px; border-radius: 14px; }
  .lang-cards { grid-template-columns: minmax(0, 1fr); }
  .options { grid-template-columns: minmax(0, 1fr); }
  .vowel-chart { grid-template-columns: minmax(0, 1fr); }
  .quiz-prompt { font-size: 19px; }
  .summary .meaning { font-size: 17px; }
  .lessons { grid-template-columns: minmax(0, 1fr); }
  .scoreboard .stat .n { font-size: 19px; }
  .option .kbd { display: none; }
}
@media (max-width: 480px) {
  .tab-ic { display: none; }
  .tabs button { padding: 7px 11px; }
  .tabs { -webkit-mask-image: linear-gradient(90deg, #000 88%, transparent); mask-image: linear-gradient(90deg, #000 88%, transparent); }
  .lang-toggle { padding: 8px 10px; gap: 8px; }
  .lang-toggle .nm { font-size: 13px; }
}
@media (max-width: 330px) {
  .lang-toggles { grid-template-columns: minmax(0, 1fr); }
  .traits { grid-template-columns: minmax(0, 1fr); }
}
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

/* Select */
.select {
  height: 34px; padding: 0 32px 0 12px; border-radius: 999px;
  border: 1px solid var(--border-strong); background: var(--surface-2); color: var(--text);
  font: 500 13.5px var(--font); max-width: 100%; cursor: pointer;
  appearance: none; -webkit-appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 17px) 15px, calc(100% - 12px) 15px;
  background-size: 5px 5px; background-repeat: no-repeat;
}
.select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

/* Live result bar (narrow screens) */
.live-bar {
  position: fixed; left: 50%; bottom: max(12px, env(safe-area-inset-bottom)); transform: translateX(-50%);
  z-index: 30; width: min(calc(100% - 24px), 640px);
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 9px 10px 9px 14px; border-radius: 16px;
  border: 1px solid var(--border-strong);
  background: color-mix(in srgb, var(--surface) 90%, transparent);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  box-shadow: 0 12px 30px -10px rgba(0, 0, 0, 0.5);
  cursor: pointer; text-align: left;
}
.lb-forms { display: flex; gap: 14px; overflow-x: auto; scrollbar-width: none; min-width: 0; }
.lb-forms::-webkit-scrollbar { display: none; }
.lb-item { display: flex; align-items: baseline; gap: 6px; flex: none; font-size: 16px; }
.lb-item small { font-size: 10px; font-weight: 700; color: var(--muted); letter-spacing: 0.06em; }
.lb-go { flex: none; display: grid; place-items: center; width: 30px; height: 30px; border-radius: 50%; background: var(--accent); color: var(--accent-ink); font-weight: 700; }
@media (max-width: 1080px) { .footer { padding-bottom: 90px; } }

/* Case info (paradigm table) */
.case-h { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.info-btn {
  position: relative; flex: none; display: inline-grid; place-items: center;
  width: 20px; height: 20px; padding: 0; border-radius: 50%;
  border: 1px solid var(--border-strong); background: transparent; color: var(--muted);
  font: italic 700 11.5px/1 Georgia, "Times New Roman", serif; cursor: pointer;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
}
.info-btn::before { content: ""; position: absolute; inset: -9px; } /* 38px touch target */
.info-btn:hover,
.info-btn[aria-expanded="true"] { color: var(--accent); border-color: var(--accent); background: var(--accent-soft); }

.case-pop {
  position: fixed; z-index: 40; width: max-content; max-width: min(280px, calc(100vw - 24px));
  padding: 11px 13px; border-radius: 12px;
  background: var(--surface-3); border: 1px solid var(--border-strong);
  box-shadow: 0 14px 34px -12px rgba(0, 0, 0, 0.55);
  font-size: 13.5px; line-height: 1.5; color: var(--text-2);
  animation: pop-in 0.12s ease;
}
.case-pop::before {
  content: ""; position: absolute; left: calc(var(--arrow-x, 20px) - 5px); width: 10px; height: 10px;
  background: var(--surface-3); border: 1px solid var(--border-strong); transform: rotate(45deg);
}
.case-pop[data-side="below"]::before { top: -6px; border-right: none; border-bottom: none; }
.case-pop[data-side="above"]::before { bottom: -6px; border-left: none; border-top: none; }
.pop-h { display: flex; align-items: center; gap: 8px; margin-bottom: 3px; color: var(--text); font-size: 14px; }
.pop-tag { font: 700 10.5px var(--mono); letter-spacing: 0.05em; color: var(--c-case); background: var(--c-case-bg); padding: 1px 6px; border-radius: 5px; }
.pop-ex { display: flex; align-items: baseline; flex-wrap: wrap; gap: 4px 10px; margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--border); font-size: 13px; }
.pop-ex .word { font-size: 15px; }
@keyframes pop-in { from { opacity: 0; transform: translateY(-3px); } to { opacity: 1; transform: none; } }

/* Analyzer (Builder top bar) */
.analyzer { padding: 14px 18px; }
.an-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px; }
.an-label { display: inline-flex; align-items: center; gap: 8px; font-weight: 700; font-size: 15px; white-space: nowrap; }
.an-label svg { width: 18px; height: 18px; fill: none; stroke: var(--accent); stroke-width: 2.2; stroke-linecap: round; }
.an-field { position: relative; flex: 1 1 260px; min-width: 0; max-width: 460px; }
.an-field input {
  width: 100%; height: 42px; padding: 0 38px 0 14px;
  border-radius: 12px; border: 1px solid var(--border-strong);
  background: var(--surface-2); color: var(--text);
  font: 500 16px var(--font);
}
.an-field input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.an-field input::placeholder { color: var(--muted); font-weight: 400; }
.an-clear {
  position: absolute; right: 7px; top: 50%; transform: translateY(-50%);
  width: 28px; height: 28px; border-radius: 50%; border: none; background: transparent;
  color: var(--muted); font-size: 20px; line-height: 1; cursor: pointer;
}
.an-clear:hover { color: var(--text); background: var(--surface-3); }
.an-examples { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.an-try { flex: none; white-space: nowrap; font-size: 12px; color: var(--muted); font-weight: 600; margin-right: 2px; }
.chip.an-ex { min-height: 30px; padding: 4px 11px; font-size: 13px; }

.an-status { margin: 12px 0 8px; font-size: 13px; color: var(--muted); }
.an-status.diag { color: var(--bad); font-weight: 600; }
.an-status.none { margin-bottom: 0; }
.an-rows { display: grid; gap: 8px; }
.an-rows:first-child { margin-top: 12px; }
.an-row {
  display: grid; grid-template-columns: auto minmax(0, 1fr) auto auto; align-items: center; gap: 12px;
  width: 100%; padding: 10px 12px; text-align: left; cursor: pointer;
  border-radius: 12px; border: 1px solid var(--border); background: var(--surface-2);
  transition: border-color 0.15s, background 0.15s;
}
.an-row:hover { border-color: var(--accent); background: var(--accent-soft); }
.an-lang { font: 700 10.5px var(--mono); letter-spacing: 0.06em; color: var(--muted); background: var(--surface-3); padding: 3px 7px; border-radius: 6px; }
.an-main { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 14px; min-width: 0; }
.an-main .word { font-size: 19px; }
.an-parse { display: inline-flex; flex-wrap: wrap; align-items: center; gap: 5px; font-size: 12.5px; }
.an-lemma { font-weight: 600; color: var(--text-2); margin-right: 2px; }
.an-tag { font: 700 10.5px var(--mono); letter-spacing: 0.04em; padding: 2px 6px; border-radius: 5px; }
.an-tag.NUMBER { color: var(--c-num); background: var(--c-num-bg); }
.an-tag.POSS { color: var(--c-poss); background: var(--c-poss-bg); }
.an-tag.CASE { color: var(--c-case); background: var(--c-case-bg); }
.an-side { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 4px; }
.an-mean { font-size: 13px; color: var(--muted); text-align: right; }
.an-go { color: var(--muted); font-weight: 700; }
.an-row:hover .an-go { color: var(--accent); }
mark.fix { background: color-mix(in srgb, var(--ok) 22%, transparent); color: inherit; border-radius: 3px; box-shadow: inset 0 -2px 0 var(--ok); }

@media (max-width: 760px) {
  .analyzer { padding: 12px 14px; }
  .an-field { flex-basis: 100%; max-width: none; }
  .an-examples { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; margin: 0 -14px; padding: 0 14px; width: calc(100% + 28px); }
  .an-examples::-webkit-scrollbar { display: none; }
  .chip.an-ex { flex: none; }
  .an-row { grid-template-columns: auto minmax(0, 1fr) auto; gap: 10px; }
  .an-side { grid-column: 2 / 4; justify-content: flex-start; grid-row: 2; }
  .an-go { grid-row: 1; grid-column: 3; }
  .an-mean { text-align: left; }
}
