/* Aurora-LAB — giao diện theo hệ nhận diện USAC (cùng hệ với Astrosphere)
 * Nền đen gần thuần · điều khiển nhấn cam · màu nhấn (--accent) lấy từ vạch phổ đang xem. */
:root {
  --bg: #040509;
  --bg-2: #080a10;
  --surface: #0c0f16;
  --surface-2: #121621;
  --surface-3: #1a1f2c;
  --line: rgba(255, 255, 255, 0.07);
  --line-2: rgba(255, 255, 255, 0.12);
  --line-3: rgba(255, 255, 255, 0.2);
  --text: #eef1f7;
  --muted: #a3acbb;
  --dim: #6d7686;
  --brand: #ff8a2b;
  --brand-hi: #ffab63;
  --brand-ink: #1c0d00;
  --brand-soft: rgba(255, 138, 43, 0.14);
  --accent-rgb: 125, 255, 114;
  --accent: rgb(var(--accent-rgb));
  --ok: #5ee6a0;
  --bad: #ff6b6b;
  --r-sm: 8px;
  --r: 12px;
  --r-lg: 16px;
  --f-display: "Chakra Petch", system-ui, sans-serif;
  --f-body: "Be Vietnam Pro", system-ui, -apple-system, "Segoe UI", sans-serif;
  --f-mono: "JetBrains Mono", ui-monospace, "Cascadia Mono", Consolas, monospace;
  --gutter: 16px;
  --panel-w: 352px;
  --peek-h: 0px;
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 400 15px/1.5 var(--f-body);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
body::before {
  content: "";
  position: fixed; inset: 0; z-index: -1; pointer-events: none;
  background:
    radial-gradient(1100px 520px at 78% -12%, rgba(var(--accent-rgb), 0.08), transparent 62%),
    radial-gradient(900px 480px at -5% 115%, rgba(255, 138, 43, 0.05), transparent 60%);
  transition: background 0.6s;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--brand-hi); text-underline-offset: 2px; }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; border-radius: 6px; }
kbd {
  font: 600 11px var(--f-mono);
  padding: 1px 6px; border-radius: 5px;
  border: 1px solid var(--line-3); border-bottom-width: 2px;
  background: var(--surface-2); color: var(--text);
}
.muted { color: var(--muted); }

/* ================= Khung ================= */
.app {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto auto;
  height: 100vh; height: 100dvh;
}

/* ---------- Header ---------- */
.hdr {
  display: flex; align-items: center; gap: 16px;
  padding: 10px var(--gutter);
  border-bottom: 1px solid var(--line);
  background: rgba(4, 5, 9, 0.86);
  backdrop-filter: blur(10px);
  position: relative; z-index: 20;
}
.brand { display: flex; align-items: center; gap: 12px; text-decoration: none; color: inherit; min-width: 0; }
.brand-logo { width: 44px; height: 44px; flex: none; object-fit: contain; }
.brand-text { display: flex; flex-direction: column; line-height: 1.15; min-width: 0; }
.brand-club { font-size: 11px; letter-spacing: 0.16em; text-transform: uppercase; color: var(--muted); font-weight: 600; }
.brand-name {
  font: 700 19px/1.2 var(--f-display); letter-spacing: 0.01em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.brand-name em { font-style: normal; color: var(--accent); transition: color 0.5s; }
.brand-sub {
  margin-left: 10px; padding-left: 10px; border-left: 1px solid var(--line-3);
  font: 500 13px var(--f-body); color: var(--muted); letter-spacing: 0;
}
.hdr-actions { margin-left: auto; display: flex; align-items: center; gap: 6px; }
.hdr-menu { display: flex; align-items: center; gap: 2px; }

.seg {
  display: inline-flex; padding: 3px; gap: 2px;
  border: 1px solid var(--line-2); border-radius: 999px; background: var(--surface);
}
.seg button {
  border: 0; background: transparent; padding: 6px 14px; border-radius: 999px;
  font-weight: 600; font-size: 13px; color: var(--muted); transition: background 0.2s, color 0.2s;
}
.seg button:hover { color: var(--text); }
.seg button[aria-checked="true"] { background: var(--brand); color: var(--brand-ink); }
.mode-toggle { margin-right: 6px; }

.hbtn {
  display: inline-flex; align-items: center; gap: 7px;
  height: 36px; padding: 0 11px; border-radius: 10px;
  border: 1px solid transparent; background: transparent;
  color: var(--muted); font-weight: 500; font-size: 14px; white-space: nowrap;
}
.hbtn:hover { color: var(--text); background: var(--surface-2); border-color: var(--line-2); }
.hbtn svg { width: 17px; height: 17px; flex: none; }
.menu-btn { display: none; }

/* ---------- Tab ---------- */
.tabs { display: flex; align-items: center; gap: 4px; padding: 10px var(--gutter); min-width: 0; }
.tab {
  display: flex; align-items: center; gap: 10px;
  padding: 7px 14px 7px 8px; border-radius: 12px;
  border: 1px solid transparent; background: transparent;
  color: var(--muted); text-align: left; transition: background 0.2s, border-color 0.2s, color 0.2s;
}
.tab:hover { color: var(--text); background: var(--surface); }
.tab-num {
  width: 26px; height: 26px; border-radius: 8px; flex: none;
  display: grid; place-items: center;
  font: 700 13px var(--f-display);
  background: var(--surface-2); border: 1px solid var(--line-2);
  transition: background 0.3s, color 0.3s, box-shadow 0.3s;
}
.tab-label { display: flex; flex-direction: column; line-height: 1.15; }
.tab-title { font-weight: 600; font-size: 14px; }
.tab-sub { font-size: 11.5px; color: var(--dim); }
.tab[aria-selected="true"] { background: var(--surface); border-color: var(--line-2); color: var(--text); }
.tab[aria-selected="true"] .tab-num {
  background: var(--accent); color: #04060a; border-color: transparent;
  box-shadow: 0 0 18px rgba(var(--accent-rgb), 0.45);
}
.tabs-aside { margin-left: auto; display: flex; align-items: center; gap: 8px; min-width: 0; }

.challenge {
  display: flex; align-items: center; gap: 10px; min-width: 0; max-width: 460px;
  padding: 6px 12px 6px 8px; border-radius: 12px;
  border: 1px dashed rgba(255, 138, 43, 0.45); background: var(--brand-soft);
  color: var(--text); text-align: left; font-size: 13px;
}
.challenge .ch-ic { font-size: 16px; flex: none; width: 24px; text-align: center; }
.challenge .ch-t { display: flex; flex-direction: column; line-height: 1.25; min-width: 0; }
.challenge .ch-t small { font-size: 10.5px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--brand-hi); font-weight: 700; }
.challenge .ch-p { font: 700 12px var(--f-mono); color: var(--brand-hi); flex: none; }
.challenge .ch-a { font-weight: 600; color: var(--brand-hi); flex: none; font-size: 12.5px; }
.challenge.done { border-style: solid; border-color: rgba(94, 230, 160, 0.45); background: rgba(94, 230, 160, 0.1); }
.challenge.done .ch-t small, .challenge.done .ch-p { color: var(--ok); }
.challenge.pop { animation: pop 0.6s ease; }
@keyframes pop { 30% { transform: scale(1.06); } 60% { transform: scale(0.98); } }
.challenge-m { display: none; }

/* ---------- Phòng lab ---------- */
.lab {
  display: grid; grid-template-columns: minmax(0, 1fr) var(--panel-w); gap: 12px;
  padding: 0 var(--gutter); min-height: 0;
}
.stage {
  display: grid; grid-template-rows: minmax(0, 1fr) auto; min-height: 0;
  border: 1px solid var(--line-2); border-radius: var(--r-lg); overflow: hidden;
  background: #020307;
  box-shadow: 0 24px 70px -36px rgba(var(--accent-rgb), 0.35);
  transition: box-shadow 0.6s;
}
.canvas-wrap { position: relative; min-height: 0; transition: opacity 0.16s ease; }
.canvas-wrap.fading { opacity: 0; }
#sim { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
.stage-q {
  position: absolute; left: 14px; top: 12px; max-width: min(56%, 520px);
  display: flex; flex-direction: column; gap: 1px; pointer-events: none;
  padding: 8px 12px; border-radius: 10px;
  background: rgba(4, 5, 9, 0.62); border: 1px solid var(--line);
  backdrop-filter: blur(6px);
}
.stage-q-k { font: 700 10.5px var(--f-display); letter-spacing: 0.16em; text-transform: uppercase; color: var(--accent); }
#stage-q { font: 600 15px/1.35 var(--f-display); letter-spacing: 0.01em; }

.statusbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 9px 16px; min-height: 50px;
  border-top: 1px solid var(--line-2);
  background: linear-gradient(180deg, var(--surface), var(--bg-2));
}
.readout {
  font: 600 18px/1.3 var(--f-mono); letter-spacing: -0.01em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0;
}
.readout .rk { color: var(--accent); }
.readout .rs { font: 500 13px var(--f-body); color: var(--muted); margin-left: 12px; letter-spacing: 0; }
.hint {
  font-size: 12.5px; color: var(--dim); text-align: right;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex-shrink: 1; min-width: 0;
}
.hint b { color: var(--muted); font-weight: 600; }

/* ---------- Panel điều khiển ---------- */
.panel {
  display: flex; flex-direction: column; min-height: 0;
  border: 1px solid var(--line-2); border-radius: var(--r-lg);
  background: var(--surface); overflow: hidden;
}
.panel-body {
  overflow-y: auto; padding: 10px; display: flex; flex-direction: column; gap: 8px;
  scrollbar-width: thin; scrollbar-color: var(--surface-3) transparent; min-height: 0;
}
.sheet-peek { display: none; }

.step { border: 1px solid var(--line); border-radius: var(--r); background: var(--bg-2); padding: 10px 11px 11px; }
.step-h { display: flex; align-items: center; gap: 9px; margin-bottom: 8px; }
.step-n {
  width: 22px; height: 22px; border-radius: 50%; flex: none;
  display: grid; place-items: center;
  font: 700 12px var(--f-display); background: var(--brand); color: var(--brand-ink);
}
.step-t { margin: 0; font: 600 13px var(--f-display); letter-spacing: 0.08em; text-transform: uppercase; }
.step-aside { margin-left: auto; }
.step > * + * { margin-top: 8px; }
.step > .step-h + * { margin-top: 0; }

.el-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.el-chip {
  display: flex; flex-direction: column; align-items: center; gap: 0;
  padding: 6px 2px 5px; border-radius: 10px;
  border: 1px solid var(--line-2); background: var(--surface-2);
  transition: border-color 0.15s, background 0.15s, box-shadow 0.2s, transform 0.1s;
  min-width: 0;
}
.el-chip:hover { border-color: color-mix(in srgb, var(--c) 60%, transparent); }
.el-chip:active { transform: scale(0.97); }
.el-chip .sym { font: 700 16px/1.2 var(--f-display); color: var(--c); }
.el-chip .nm { font-size: 9.5px; color: var(--dim); max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding: 0 2px; }
.el-chip[aria-pressed="true"] {
  border-color: var(--c);
  background: color-mix(in srgb, var(--c) 15%, var(--surface-2));
  box-shadow: 0 0 18px -6px var(--c);
}
.el-chip[aria-pressed="true"] .nm { color: var(--text); }
.el-chip.wrong { border-color: rgba(255, 107, 107, 0.6); opacity: 0.55; }

.btn-primary {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  width: 100%; height: 42px; border: 0; border-radius: 12px;
  background: var(--brand); color: var(--brand-ink);
  font-weight: 700; font-size: 15px;
  box-shadow: 0 10px 26px -12px rgba(255, 138, 43, 0.85), inset 0 1px 0 rgba(255, 255, 255, 0.35);
  transition: background 0.15s, transform 0.08s;
}
.btn-primary:hover { background: var(--brand-hi); }
.btn-primary:active { transform: translateY(1px); }
.btn-primary .bp-l { display: inline-flex; align-items: center; gap: 8px; }
.btn-primary svg { width: 18px; height: 18px; }
.btn-primary kbd { background: rgba(0, 0, 0, 0.14); border-color: rgba(0, 0, 0, 0.25); color: var(--brand-ink); }
.btn-ghost {
  height: 36px; padding: 0 14px; border-radius: 10px;
  border: 1px solid var(--line-3); background: var(--surface-2);
  font-weight: 600; font-size: 13.5px;
}
.btn-ghost:hover { border-color: var(--brand); color: var(--brand-hi); }
.link-btn { border: 0; background: none; padding: 2px 0; color: var(--brand-hi); font-size: 12.5px; font-weight: 600; }
.link-btn:hover { text-decoration: underline; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }

.check { display: flex; align-items: center; gap: 10px; padding: 1px 0; cursor: pointer; font-size: 13.5px; user-select: none; }
.step > .check + .check { margin-top: 5px; }
.check input {
  appearance: none; -webkit-appearance: none; margin: 0; flex: none;
  width: 18px; height: 18px; border-radius: 5px;
  border: 1.5px solid var(--line-3); background: var(--surface-2);
  display: grid; place-items: center; cursor: pointer; transition: background 0.15s, border-color 0.15s;
}
.check input:checked { background: var(--brand); border-color: var(--brand); }
.check input:checked::after {
  content: ""; width: 9px; height: 5px;
  border: 2.5px solid var(--brand-ink); border-top: 0; border-right: 0;
  transform: rotate(-45deg) translate(1px, -1px);
}

.slider .sl-h { display: flex; justify-content: space-between; align-items: baseline; font-size: 13px; color: var(--muted); }
.slider .sl-v { font: 700 14px var(--f-mono); color: var(--text); }
.slider .sl-ends { display: flex; justify-content: space-between; font-size: 11px; color: var(--dim); margin-top: -2px; }
.range { width: 100%; height: 28px; margin: 2px 0; background: transparent; -webkit-appearance: none; appearance: none; cursor: pointer; }
.range::-webkit-slider-runnable-track {
  height: 6px; border-radius: 6px;
  background: linear-gradient(90deg, var(--brand) 0 var(--p, 50%), var(--surface-3) var(--p, 50%));
}
.range::-webkit-slider-thumb {
  -webkit-appearance: none; width: 20px; height: 20px; margin-top: -7px; border-radius: 50%;
  background: #fff; border: 4px solid var(--brand); box-shadow: 0 0 0 5px rgba(255, 138, 43, 0.18);
}
.range::-moz-range-track { height: 6px; border-radius: 6px; background: var(--surface-3); }
.range::-moz-range-progress { height: 6px; border-radius: 6px; background: var(--brand); }
.range::-moz-range-thumb { width: 13px; height: 13px; border-radius: 50%; background: #fff; border: 4px solid var(--brand); }
.slider.compact { width: 100%; }
.slider.compact .sl-h { font-size: 12px; }

.seg-wide { display: flex; width: 100%; border-radius: 10px; }
.seg-wide button { flex: 1; border-radius: 8px; padding: 6px 8px; font-size: 12.5px; }

.note { margin: 0; font-size: 12.5px; color: var(--dim); line-height: 1.45; }
.note b { color: var(--muted); }
.target {
  display: flex; align-items: center; gap: 8px; padding: 6px 8px 6px 10px; border-radius: 9px;
  background: var(--surface-2); border: 1px solid var(--line-2); font-size: 12.5px; color: var(--muted);
}
.target b { color: var(--text); }
.target .x { margin-left: auto; border: 0; background: none; color: var(--dim); font-size: 12px; padding: 2px 4px; }
.target .x:hover { color: var(--text); }
.sw { display: inline-block; width: 9px; height: 9px; border-radius: 2px; margin-right: 6px; vertical-align: 0; box-shadow: 0 0 8px currentColor; flex: none; }

.explain {
  border-radius: var(--r); padding: 11px 13px 10px;
  background: linear-gradient(180deg, rgba(var(--accent-rgb), 0.09), rgba(var(--accent-rgb), 0.02));
  border: 1px solid rgba(var(--accent-rgb), 0.24);
  transition: background 0.5s, border-color 0.5s;
}
.explain-h { font: 700 11px var(--f-display); letter-spacing: 0.14em; text-transform: uppercase; color: var(--accent); margin-bottom: 5px; }
.explain-b p { margin: 0 0 7px; font-size: 13.5px; line-height: 1.55; color: #d4dae5; }
.explain-b p.muted { color: var(--muted); font-size: 12.5px; }
.formula {
  display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 10px;
  margin: 2px 0 4px; padding: 6px 10px; border-radius: 8px;
  background: rgba(0, 0, 0, 0.35); border: 1px solid var(--line);
  font: 700 14px var(--f-mono); color: var(--text);
}
.formula span { font: 500 12px var(--f-mono); color: var(--muted); }
.more { border: 0; background: none; padding: 2px 0; font-size: 12.5px; font-weight: 600; color: var(--accent); }
.more:hover { text-decoration: underline; }
.term { border-bottom: 1px dotted currentColor; cursor: help; }
.term:focus-visible { outline-offset: 1px; }

.block { border: 1px solid var(--line); border-radius: var(--r); padding: 11px 12px; background: var(--bg-2); }
.block-h { margin: 0 0 8px; font: 600 12px var(--f-display); letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); }
.block > * + * { margin-top: 8px; }
.block > .block-h + * { margin-top: 0; }
.mini-chart { width: 100%; height: 170px; display: block; }
.mystery .mys-h { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 4px; }
.mystery .mys-h b { font: 700 13px var(--f-display); letter-spacing: 0.06em; text-transform: uppercase; color: var(--brand-hi); }
.mystery .mys-h span { font: 600 12px var(--f-mono); color: var(--muted); }

.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 12.5px; }
table.data th { text-align: left; font-weight: 600; color: var(--dim); font-size: 11px; letter-spacing: 0.04em; padding: 4px 6px; border-bottom: 1px solid var(--line-2); white-space: nowrap; }
table.data td { padding: 5px 6px; border-bottom: 1px solid var(--line); white-space: nowrap; font-variant-numeric: tabular-nums; }
table.data tr.clickable { cursor: pointer; }
table.data tr.clickable:hover td { background: rgba(255, 255, 255, 0.03); }
table.data tr.on td { background: rgba(var(--accent-rgb), 0.1); color: var(--text); }
table.data th.sortable { cursor: pointer; user-select: none; }
table.data th.sortable.on { color: var(--brand-hi); }

.explain-f { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 6px; padding-top: 7px; border-top: 1px solid rgba(var(--accent-rgb), 0.16); }
.quiz-link {
  display: inline-flex; align-items: center; gap: 7px; margin-left: auto;
  padding: 4px 10px 4px 5px; border-radius: 999px;
  border: 1px solid rgba(255, 138, 43, 0.4); background: var(--brand-soft);
  font-size: 12.5px; font-weight: 600; color: var(--brand-hi);
}
.quiz-link:hover { border-color: var(--brand); color: #fff; }
.qc-ic { width: 20px; height: 20px; border-radius: 50%; display: grid; place-items: center; background: var(--brand); color: var(--brand-ink); font: 700 12px var(--f-display); flex: none; }

/* ---------- Thanh phổ ---------- */
.specbar { padding: 10px var(--gutter) 0; }
.specbar-head { display: flex; align-items: baseline; gap: 14px; margin-bottom: 6px; font-size: 12px; color: var(--dim); }
.specbar-title { font: 600 12px var(--f-display); letter-spacing: 0.14em; text-transform: uppercase; color: var(--muted); }
.specbar-title b { color: var(--text); font-weight: 700; }
.specbar-legend { display: inline-flex; align-items: center; gap: 6px; }
.specbar-legend i { width: 18px; height: 6px; border-radius: 3px; display: inline-block; }
.lg-uv { background: linear-gradient(90deg, #6a4bd6, #b08cff); }
.lg-ir { background: linear-gradient(90deg, #ff3b2e, #5a1414); }
.specbar-hint { margin-left: auto; }
.spec-wrap { position: relative; height: 80px; border-radius: 12px; border: 1px solid var(--line-2); background: #020306; }
#spec { position: absolute; inset: 0; width: 100%; height: 100%; border-radius: 12px; cursor: crosshair; touch-action: none; }
.spec-tip {
  position: absolute; bottom: calc(100% + 10px); transform: translateX(-50%);
  width: max-content; max-width: 300px; min-width: 210px; padding: 10px 12px; border-radius: 11px;
  background: rgba(13, 16, 24, 0.97); border: 1px solid var(--line-3);
  box-shadow: 0 18px 44px rgba(0, 0, 0, 0.55); font-size: 12.5px; pointer-events: none; z-index: 22;
}
.spec-tip .tip-h { display: flex; align-items: center; gap: 8px; }
.spec-tip .tip-h i { width: 11px; height: 11px; border-radius: 3px; box-shadow: 0 0 10px currentColor; }
.spec-tip .tip-h b { font: 700 16px var(--f-mono); }
.spec-tip .tip-h span { color: var(--muted); }
.spec-tip .tip-sp { margin-top: 3px; color: #d6dce6; }
.spec-tip .tip-kv { margin-top: 2px; font-family: var(--f-mono); font-size: 12px; color: var(--muted); }
.spec-tip .tip-d { margin-top: 6px; color: var(--muted); line-height: 1.45; }
.spec-tip .tip-f { margin-top: 6px; font-size: 11px; color: var(--brand-hi); }

/* ---------- Footer & linh vật ---------- */
.ftr {
  display: flex; align-items: center; justify-content: center; gap: 4px 8px; flex-wrap: wrap;
  padding: 8px 100px 10px; font-size: 12px; color: var(--dim); text-align: center;
}
.ftr .dot { opacity: 0.5; }
.ftr-slogan { font: 600 11.5px var(--f-display); letter-spacing: 0.12em; text-transform: uppercase; color: var(--muted); }
.contact { margin-top: 14px; padding: 12px 14px; border-radius: 12px; background: var(--bg-2); border: 1px solid var(--line-2); font-size: 13.5px; }
.contact p { margin: 0 0 4px; color: var(--muted); }
.contact .contact-h { font: 600 12.5px var(--f-display); letter-spacing: 0.1em; text-transform: uppercase; color: var(--brand-hi); margin-bottom: 6px; }
.ftr a { color: var(--muted); }
.ftr a:hover { color: var(--brand-hi); }

#fx { position: fixed; inset: 0; width: 100vw; height: 100vh; pointer-events: none; z-index: 25; }

.mascot {
  position: fixed; right: 10px; bottom: 2px; z-index: 26;
  width: 76px; height: 76px; padding: 0; border: 0; background: none;
  filter: drop-shadow(0 6px 14px rgba(0, 0, 0, 0.5)) drop-shadow(0 0 14px rgba(154, 134, 255, 0.35));
}
.mascot-img, .mascot-3d { width: 100%; height: 100%; display: block; transition: transform 0.3s; }
.mascot.m3d .mascot-img { display: none; }
.mascot:hover .mascot-img { transform: translateY(-2px) rotate(-6deg); }
.mascot.win .mascot-img { animation: hop 0.5s ease 3; }
@keyframes hop { 50% { transform: translateY(-10px) rotate(8deg); } }
.mascot-bubble {
  position: absolute; right: 74px; bottom: 18px;
  width: max-content; max-width: min(320px, calc(100vw - 90px));
  padding: 9px 12px; border-radius: 12px 12px 2px 12px;
  background: #f5f7fb; color: #10131a; font-size: 13px; line-height: 1.45; text-align: left;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.45);
  opacity: 0; transform: translateY(6px) scale(0.97); transform-origin: bottom right;
  transition: opacity 0.2s, transform 0.2s; pointer-events: none;
}
.mascot.talk .mascot-bubble { opacity: 1; transform: none; }
.mascot.win .mascot-bubble { background: #eafff2; }

.term-tip {
  position: fixed; z-index: 40; max-width: 290px; padding: 9px 11px; border-radius: 10px;
  background: rgba(13, 16, 24, 0.98); border: 1px solid var(--line-3);
  box-shadow: 0 14px 34px rgba(0, 0, 0, 0.55); font-size: 12.5px; line-height: 1.45; color: var(--muted); pointer-events: none;
}
.term-tip b { color: var(--accent); margin-right: 4px; }

/* ---------- Hộp thoại ---------- */
dialog { color: var(--text); }
dialog::backdrop { background: rgba(2, 3, 6, 0.72); backdrop-filter: blur(4px); }
.modal {
  width: min(620px, calc(100vw - 32px)); max-height: min(86dvh, 760px);
  padding: 0; border: 1px solid var(--line-3); border-radius: 18px;
  background: var(--surface); box-shadow: 0 40px 120px rgba(0, 0, 0, 0.7);
}
.modal[open] { display: flex; flex-direction: column; animation: rise 0.22s ease; }
@keyframes rise { from { opacity: 0; transform: translateY(10px); } }
.modal-head, .drawer-head {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 16px;
  padding: 16px 18px 12px; border-bottom: 1px solid var(--line);
}
.modal-head h2, .drawer-head h2 { margin: 0; font: 700 19px/1.3 var(--f-display); }
.modal-body { padding: 14px 18px 18px; overflow-y: auto; font-size: 14px; line-height: 1.6; }
.modal-body h3 { margin: 16px 0 4px; font: 600 14px var(--f-display); letter-spacing: 0.08em; text-transform: uppercase; color: var(--brand-hi); }
.modal-body p { margin: 0 0 8px; }
.icon-btn {
  width: 34px; height: 34px; flex: none; border-radius: 10px;
  border: 1px solid var(--line-2); background: var(--surface-2); color: var(--muted);
}
.icon-btn:hover { color: var(--text); border-color: var(--line-3); }
.howto { margin: 0; padding-left: 20px; }
.howto li { margin-bottom: 6px; }
.keys { list-style: none; padding: 0; margin: 0; }
.keys li { margin: 4px 0; color: var(--muted); }
.facts { margin: 6px 0 10px; padding-left: 18px; }
.facts li { margin-bottom: 7px; color: #cfd6e2; }
.warn {
  margin: 10px 0; padding: 10px 12px; border-radius: 10px; font-size: 13px; line-height: 1.5;
  background: rgba(255, 196, 80, 0.08); border: 1px solid rgba(255, 196, 80, 0.3); color: #f3e3c0;
}

.drawer {
  margin: 0 0 0 auto; height: 100dvh; max-height: 100dvh; width: min(760px, 100vw);
  padding: 0; border: 0; border-left: 1px solid var(--line-3); border-radius: 18px 0 0 18px;
  background: var(--surface); box-shadow: -40px 0 120px rgba(0, 0, 0, 0.6);
}
.drawer[open] { display: flex; flex-direction: column; animation: slide 0.26s ease; }
@keyframes slide { from { transform: translateX(40px); opacity: 0; } }
.eyebrow { font: 700 11px var(--f-display); letter-spacing: 0.16em; text-transform: uppercase; color: var(--brand-hi); margin-bottom: 2px; }
.drawer-head, .modal-head { flex: none; }
.codex-nav { flex: none; display: flex; gap: 6px; padding: 10px 18px; border-bottom: 1px solid var(--line); overflow-x: auto; scrollbar-width: none; }
sup { font-size: 0.68em; line-height: 0; vertical-align: 0.5em; }
.codex-nav a {
  flex: none; padding: 5px 11px; border-radius: 999px; border: 1px solid var(--line-2);
  font-size: 12.5px; font-weight: 600; color: var(--muted); text-decoration: none;
}
.codex-nav a:hover { color: var(--text); border-color: var(--brand); }
.drawer-body { overflow-y: auto; padding: 6px 22px 40px; font-size: 14.5px; line-height: 1.65; scroll-padding-top: 12px; }
.drawer-body section { padding-top: 14px; }
.drawer-body h3 { margin: 6px 0 8px; font: 700 17px var(--f-display); }
.drawer-body p { margin: 0 0 10px; color: #d4dae5; }
.eq-box { margin: 12px 0; padding: 14px; border-radius: 12px; text-align: center; background: var(--bg-2); border: 1px solid var(--line-2); }
.eq { font: 700 20px var(--f-mono); color: var(--accent); }
.eq-sub { margin-top: 6px; font-size: 13px; color: var(--muted); }
.const-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; margin: 12px 0; }
.const-grid div { display: flex; flex-direction: column; padding: 10px 12px; border-radius: 10px; background: var(--bg-2); border: 1px solid var(--line); }
.const-grid b { font: 700 17px var(--f-display); color: #a9c9ff; }
.const-grid span { font-size: 12px; color: var(--muted); }
.const-grid code { font: 600 13px var(--f-mono); margin-top: 3px; }
.calc { margin: 12px 0; padding: 12px; border-radius: 12px; border: 1px solid rgba(255, 138, 43, 0.35); background: var(--brand-soft); }
.calc label { display: block; font: 600 12px var(--f-display); letter-spacing: 0.1em; text-transform: uppercase; color: var(--brand-hi); margin-bottom: 6px; }
.calc-row { display: flex; align-items: center; gap: 8px; }
.calc input {
  width: 120px; padding: 7px 10px; border-radius: 8px; border: 1px solid var(--line-3);
  background: var(--bg); font: 700 15px var(--f-mono);
}
.calc output { display: block; margin-top: 8px; font: 500 14px var(--f-mono); }
.ex { padding-left: 20px; }
.ex li { margin-bottom: 12px; }
.ex details { margin-top: 4px; }
.ex summary { cursor: pointer; color: var(--brand-hi); font-size: 13px; font-weight: 600; }
.ex details p { margin: 6px 0 0; padding: 8px 10px; border-radius: 8px; background: var(--bg-2); border: 1px solid var(--line); }

/* USACodex: thư viện mô phỏng khái niệm */
.drawer.codex { width: min(1180px, 100vw); max-width: 100vw; }
.cx-brand { display: flex; align-items: center; gap: 12px; }
.cx-mascot { width: 48px; height: 48px; flex: none; }
.cx-tabs { flex: none; display: flex; gap: 4px; padding: 8px 18px; border-bottom: 1px solid var(--line); overflow-x: auto; scrollbar-width: none; }
.cx-tabs button { border: 0; background: transparent; padding: 7px 12px; border-radius: 9px; color: var(--muted); font-weight: 600; font-size: 13.5px; white-space: nowrap; }
.cx-tabs button:hover { color: var(--text); }
.cx-tabs button[aria-selected="true"] { background: var(--brand-soft); color: var(--brand-hi); }
.cx-pane[hidden] { display: none !important; }
.cx-sims { flex: 1; min-height: 0; display: grid; grid-template-columns: 270px minmax(0, 1fr); }
.cx-list { overflow-y: auto; padding: 10px 12px 16px; border-right: 1px solid var(--line); display: flex; flex-direction: column; gap: 3px; scrollbar-width: thin; }
.cx-group { font: 700 10.5px var(--f-display); letter-spacing: 0.14em; text-transform: uppercase; color: var(--dim); margin: 12px 8px 4px; }
.cx-item {
  display: flex; gap: 10px; align-items: flex-start; text-align: left;
  border: 1px solid transparent; background: transparent; padding: 8px 10px; border-radius: 10px;
  color: var(--muted); font-size: 13.5px; line-height: 1.35;
}
.cx-item:hover { background: var(--surface-2); color: var(--text); }
.cx-item[aria-current="true"] { background: var(--surface-2); border-color: var(--line-2); color: var(--text); }
.cx-i { width: 22px; height: 22px; border-radius: 7px; flex: none; display: grid; place-items: center; background: var(--surface-3); font: 700 11.5px var(--f-display); }
.cx-item[aria-current="true"] .cx-i { background: var(--brand); color: var(--brand-ink); }
.cx-view { overflow-y: auto; padding: 16px 22px 22px; display: flex; flex-direction: column; gap: 12px; min-height: 0; }
.cx-num { font: 700 11px var(--f-display); letter-spacing: 0.14em; text-transform: uppercase; color: var(--brand-hi); }
.cx-head h3 { margin: 4px 0 2px; font: 700 21px/1.25 var(--f-display); }
.cx-q { margin: 0; color: var(--muted); font-size: 14.5px; }
.cx-stage { position: relative; flex: none; height: clamp(260px, 44vh, 400px); border-radius: 14px; border: 1px solid var(--line-2); overflow: hidden; background: #03050a; }
#cx-canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.cx-controls { display: flex; flex-direction: column; gap: 10px; }
.cx-controls .seg-wide { max-width: 640px; }
.cx-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.cx-chip { padding: 5px 10px; border-radius: 999px; border: 1px solid var(--line-2); background: var(--surface-2); font: 600 12px var(--f-mono); color: var(--muted); }
.cx-chip:hover { border-color: var(--brand); color: var(--text); }
.cx-read { font: 600 14px var(--f-mono); color: var(--text); }
.cx-body { display: grid; grid-template-columns: 1.4fr 1fr; gap: 14px; align-items: start; }
.cx-text { font-size: 14.5px; line-height: 1.65; color: #d4dae5; }
.cx-key { padding: 12px 14px; border-radius: 12px; background: rgba(255, 138, 43, 0.08); border: 1px solid rgba(255, 138, 43, 0.3); font-size: 14px; line-height: 1.55; }
.cx-key b { display: block; font: 700 11px var(--f-display); letter-spacing: 0.14em; text-transform: uppercase; color: var(--brand-hi); margin-bottom: 4px; }
.cx-foot { display: flex; gap: 10px; justify-content: space-between; align-items: center; flex-wrap: wrap; padding-top: 4px; }
.btn-lab { height: 40px; padding: 0 18px; border-radius: 11px; border: 0; background: var(--brand); color: var(--brand-ink); font-weight: 700; font-size: 14px; }
.btn-lab:hover { background: var(--brand-hi); }
.btn-ghost:disabled { opacity: 0.35; cursor: default; }

/* Quiz */
.quiz-q { margin-bottom: 16px; }
.quiz-t { margin: 0 0 8px; }
.quiz-opts { display: grid; gap: 6px; }
.quiz-opt {
  display: flex; align-items: center; gap: 10px; text-align: left;
  padding: 9px 12px; border-radius: 10px; border: 1px solid var(--line-2); background: var(--surface-2); font-size: 14px;
}
.quiz-opt:not(:disabled):hover { border-color: var(--brand); }
.quiz-opt:disabled { cursor: default; opacity: 0.75; }
.quiz-opt .qo-k { width: 22px; height: 22px; border-radius: 6px; display: grid; place-items: center; background: var(--bg-2); font: 700 12px var(--f-display); color: var(--muted); flex: none; }
.quiz-opt.ok { border-color: rgba(94, 230, 160, 0.7); background: rgba(94, 230, 160, 0.1); opacity: 1; }
.quiz-opt.ok .qo-k { background: var(--ok); color: #04150c; }
.quiz-opt.bad { border-color: rgba(255, 107, 107, 0.7); background: rgba(255, 107, 107, 0.08); opacity: 1; }
.quiz-why { margin: 8px 0 0; font-size: 13px; color: var(--muted); }
.quiz-score { font-size: 14px; }
.quiz-foot { display: flex; justify-content: flex-end; }

/* ================= Màn hình vừa ================= */
@media (max-width: 1180px) {
  :root { --panel-w: 320px; }
  .hbtn .lbl { display: none; }
  .hbtn { padding: 0 9px; }
  .challenge { max-width: 320px; }
}
@media (max-width: 1000px) {
  .brand-sub { display: none; }
  .tab-sub { display: none; }
  .specbar-legend { display: none; }
}
@media (max-height: 760px) and (min-width: 861px) {
  .hdr { padding-top: 7px; padding-bottom: 7px; }
  .brand-logo { width: 34px; height: 34px; }
  .tabs { padding-top: 7px; padding-bottom: 7px; }
  .spec-wrap { height: 66px; }
  .ftr { padding-top: 5px; padding-bottom: 6px; }
}

/* ================= Điện thoại: panel thành bottom sheet ================= */
@media (max-width: 860px) {
  :root { --gutter: 10px; --peek-h: 72px; }
  .app { grid-template-rows: auto auto minmax(0, 1fr) auto; padding-bottom: calc(var(--peek-h) + env(safe-area-inset-bottom)); }
  .ftr { display: none; }
  .brand-club { display: none; }
  .brand-name { font-size: 16px; }
  .brand-logo { width: 32px; height: 32px; }
  .hdr { gap: 10px; padding-top: 8px; padding-bottom: 8px; }
  .tabs { padding-top: 8px; padding-bottom: 8px; gap: 4px; }
  .tab { flex: 1; padding: 6px 8px; gap: 7px; justify-content: center; }
  .tab-num { width: 22px; height: 22px; font-size: 12px; }
  .tab-title { font-size: 13px; }
  .tabs-aside { display: none; }
  .challenge-m { display: flex; max-width: none; width: 100%; }
  .lab { grid-template-columns: minmax(0, 1fr); padding: 0 var(--gutter); }
  .stage-q { max-width: calc(100% - 28px); padding: 6px 10px; }
  #stage-q { font-size: 13.5px; }
  .readout { font-size: 15px; }
  .readout .rs { display: none; }
  .hint { display: none; }
  .statusbar { min-height: 42px; padding: 7px 12px; }
  .specbar { padding-top: 8px; }
  .specbar-head { margin-bottom: 4px; }
  .specbar-hint { display: none; }
  .spec-wrap { height: 60px; }
  .panel {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
    height: min(78dvh, 640px);
    border-radius: 20px 20px 0 0; border-bottom: 0;
    transform: translateY(calc(100% - var(--peek-h) - env(safe-area-inset-bottom)));
    transition: transform 0.32s cubic-bezier(0.2, 0.8, 0.2, 1);
    box-shadow: 0 -24px 60px rgba(0, 0, 0, 0.6);
    padding-bottom: env(safe-area-inset-bottom);
  }
  .panel.open { transform: translateY(0); }
  .sheet-peek {
    display: flex; flex-direction: column; flex: none;
    height: var(--peek-h); padding: 0 12px 10px; border-bottom: 1px solid var(--line);
  }
  .sheet-handle { height: 18px; border: 0; background: none; display: grid; place-items: center; padding: 0; flex: none; }
  .sheet-handle span { width: 42px; height: 4px; border-radius: 4px; background: var(--line-3); }
  .peek-body { display: flex; align-items: center; gap: 8px; flex: 1; min-height: 0; }
  .peek-body .btn-primary { height: 42px; }
  .peek-body .btn-primary kbd { display: none; }
  .peek-body .slider.compact .sl-ends { display: none; }
  .mini-el {
    flex: none; height: 42px; min-width: 56px; padding: 0 10px; border-radius: 12px;
    border: 1px solid var(--c); background: color-mix(in srgb, var(--c) 14%, var(--surface-2));
    display: flex; flex-direction: column; align-items: center; justify-content: center; line-height: 1.05;
  }
  .mini-el b { font: 700 16px var(--f-display); color: var(--c); }
  .mini-el span { font-size: 10px; color: var(--muted); }
  .panel-body { padding-bottom: 20px; }
  .mascot { bottom: calc(var(--peek-h) + 70px + env(safe-area-inset-bottom)); right: 6px; width: 56px; height: 56px; }
  .mascot-bubble { right: 56px; bottom: 10px; }
  .btn-primary kbd { display: none; }
}
@media (max-width: 860px) {
  .cx-sims { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr); }
  .cx-list { flex-direction: row; overflow-x: auto; border-right: 0; border-bottom: 1px solid var(--line); padding: 8px 10px; }
  .cx-group { display: none; }
  .cx-item { flex: none; white-space: nowrap; }
  .cx-view { padding: 12px 12px 18px; }
  .cx-head h3 { font-size: 18px; }
  .cx-stage { height: 42vh; }
  .cx-body { grid-template-columns: minmax(0, 1fr); }
  .cx-foot .btn-lab { order: -1; width: 100%; }
  .cx-mascot { width: 36px; height: 36px; }
}
@media (max-width: 560px) {
  .mode-toggle { margin-right: 0; }
  .seg button { padding: 5px 10px; font-size: 12px; }
  .menu-btn { display: inline-flex; }
  .hdr-menu {
    display: none; position: absolute; right: 10px; top: calc(100% + 6px);
    flex-direction: column; align-items: stretch; gap: 2px; padding: 6px; min-width: 190px;
    border-radius: 14px; border: 1px solid var(--line-3); background: var(--surface);
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.6);
  }
  .hdr-menu.open { display: flex; }
  .hdr-menu .hbtn { justify-content: flex-start; }
  .hdr-menu .hbtn .lbl { display: inline; }
  .tab-label { display: contents; }
  .el-grid { grid-template-columns: repeat(5, 1fr); }
}
@media (max-width: 380px) {
  .brand-name { font-size: 14px; }
  .tab-num { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
