/* ===================================================================
   TIMO LỚP 2 — Khung làm bài song ngữ Anh–Việt
   Tối ưu hóa cho Lenovo Tab 2025 (xoay ngang, cảm ứng). Màn đề và màn cách giải
   KHÔNG hiển thị song song: mở cách giải thì nó thay chỗ màn đề.
   100dvh, vừa vặn trên 1 trang không cần cuộn dọc.
   =================================================================== */

:root {
  --ink: #0f172a;
  --ink-2: #334155;
  --muted: #64748b;
  --en: #0369a1;
  --line: #e2e8f0;
  --card: #ffffff;
  --bg: #eef6ff;
  --brand: #0ea5e9;
  --brand-dark: #0369a1;
  --good: #16a34a;
  --good-bg: #dcfce7;
  --bad: #dc2626;
  --bad-bg: #fee2e2;
  --warn: #d97706;
  --warn-bg: #fef3c7;
  --hl: #fde68a;
  --violet: #7c3aed;
  --r-lg: 20px;
  --r-md: 14px;
  --shadow: 0 4px 0 rgba(15, 23, 42, 0.06), 0 8px 20px rgba(15, 23, 42, 0.06);
  --font: 'Baloo 2', 'Nunito', system-ui, sans-serif;
  --topbar-h: 60px;
  --gap: 12px;
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html, body { height: 100%; height: 100dvh; }
body {
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(circle at 6% 10%, #fef3c7 0 110px, transparent 111px),
    radial-gradient(circle at 94% 90%, #fce7f3 0 150px, transparent 151px),
    var(--bg);
  overflow: hidden;
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
}
button { font-family: inherit; color: inherit; cursor: pointer; border: none; background: none; }
b { font-weight: 800; }

/* ---------- Song ngữ: hiện/ẩn theo body[data-lang] ---------- */
body[data-lang="vi"] .t-en { display: none !important; }
body[data-lang="en"] .t-vi { display: none !important; }
body[data-lang="both"] .t-en { color: var(--en); font-weight: 700; }

/* ===================== TOP BAR ===================== */
.topbar {
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 16px;
  background: #ffffff;
  border-bottom: 3px solid var(--line);
  box-shadow: 0 2px 8px rgba(15, 23, 42, 0.04);
}
.brand { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.brand-logo { font-size: 28px; }
.brand-text { display: flex; flex-direction: column; line-height: 1; }
.brand-text strong { font-size: 22px; font-weight: 800; color: var(--brand-dark); letter-spacing: 0.5px; }
.brand-text small { font-size: 12px; font-weight: 700; color: var(--muted); }
body[data-lang="both"] .brand-text small .t-en { display: none; }

/* Nút chọn Đề thi nổi bật dạng Card/Pill 3D */
.exam-selector-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 42px;
  padding: 0 14px 0 10px;
  border-radius: 21px;
  background: linear-gradient(135deg, #e0f2fe 0%, #f0fdf4 100%);
  border: 2px solid #38bdf8;
  box-shadow: 0 3px 0 #0284c7, 0 3px 6px rgba(2, 132, 199, 0.15);
  cursor: pointer;
  flex-shrink: 0;
  transition: transform 0.1s ease, box-shadow 0.1s ease, background 0.15s;
}
.exam-selector-btn:hover {
  background: linear-gradient(135deg, #bae6fd 0%, #dcfce7 100%);
  transform: translateY(-1px);
  box-shadow: 0 4px 0 #0284c7, 0 5px 8px rgba(2, 132, 199, 0.2);
}
.exam-selector-btn:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 #0284c7;
}
.exam-ico {
  font-size: 22px;
  line-height: 1;
  filter: drop-shadow(0 2px 2px rgba(0,0,0,0.12));
}
.exam-badge-wrap {
  display: flex;
  flex-direction: column;
  line-height: 1.1;
  text-align: left;
}
.exam-badge-label {
  font-size: 10px;
  font-weight: 800;
  color: #0369a1;
  letter-spacing: 0.5px;
  text-transform: uppercase;
}
.exam-curr-name {
  font-size: 15px;
  font-weight: 800;
  color: #0f172a;
  white-space: nowrap;
}
.exam-dropdown-arrow {
  font-size: 11px;
  color: #0284c7;
  margin-left: 2px;
  transition: transform 0.2s;
}
.exam-selector-btn:hover .exam-dropdown-arrow {
  transform: translateY(2px);
}

.topbar-nav {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-width: 0;
}
.nav-arrow-btn {
  width: 40px; height: 40px; border-radius: 50%;
  background: #f1f5f9; color: var(--brand-dark);
  font-size: 18px; font-weight: 800;
  display: grid; place-items: center;
  box-shadow: 0 2px 0 var(--line);
  transition: transform 0.08s, background 0.15s;
}
.nav-arrow-btn:active { transform: scale(0.92); background: #e0f2fe; }

.journey { display: flex; align-items: center; justify-content: center; gap: 6px; min-width: 0; }
.journey .wave-sep { width: 10px; height: 4px; border-radius: 2px; background: var(--line); }
.journey-dot {
  width: 40px; height: 40px; border-radius: 50%;
  display: grid; place-items: center;
  font-size: 17px; font-weight: 800;
  background: #f1f5f9; color: var(--muted);
  border: 3px solid transparent;
  transition: transform 0.15s;
}
.journey-dot.current {
  background: #ffffff; color: var(--brand-dark);
  border-color: var(--brand); transform: scale(1.1);
  box-shadow: 0 0 0 4px rgba(14, 165, 233, 0.2);
}
.journey-dot.done { background: var(--good); color: #ffffff; }
.journey-dot.tried { background: var(--warn-bg); color: var(--warn); }

.topbar-right { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.stars-pill {
  height: 38px; padding: 0 12px; border-radius: 19px;
  display: flex; align-items: center; gap: 4px;
  background: var(--warn-bg); color: #92400e; font-size: 16px; font-weight: 800;
}
.stars-pill span { font-size: 13px; opacity: 0.7; }
.lang-switch { display: flex; background: #f1f5f9; border-radius: 20px; padding: 3px; }
.lang-switch button {
  height: 32px; padding: 0 10px; border-radius: 16px;
  font-size: 13px; font-weight: 800; color: var(--muted);
}
.lang-switch button.on { background: #ffffff; color: var(--brand-dark); box-shadow: 0 2px 5px rgba(15, 23, 42, 0.12); }
.icon-btn { width: 38px; height: 38px; border-radius: 50%; background: #f1f5f9; font-size: 18px; }

/* ===================== KHUNG CHÍNH (MỘT MÀN TẠI MỘT THỜI ĐIỂM) ===================== */
.exam-frame {
  height: calc(100dvh - var(--topbar-h));
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--gap);
  padding: 10px 14px 12px;
  max-width: 1600px;
  margin: 0 auto;
  overflow: hidden;
}

/* ===================== CỘT 1: LÀM BÀI ===================== */
.exam-card {
  background: var(--card);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow);
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 0;
  overflow-y: auto;
}
.exam-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; flex-shrink: 0; }
.q-number {
  font-size: 20px; font-weight: 800; color: #ffffff;
  background: var(--brand); border-radius: 12px; padding: 2px 14px;
}
.q-number .t-en { color: #e0f2fe !important; font-size: 15px; }
.topic-chip, .wave-chip {
  font-size: 14px; font-weight: 800; border-radius: 10px; padding: 3px 10px;
  background: #f1f5f9; color: var(--ink-2);
}
.wave-chip { margin-left: auto; color: var(--muted); background: transparent; }

/* Dải linh vật dẫn chuyện */
.host-strip {
  display: flex;
  align-items: center;
  gap: 10px;
  background: #f0fdf4;
  border: 2px solid #bbf7d0;
  border-radius: var(--r-md);
  padding: 6px 12px;
  flex-shrink: 0;
}
#host-canvas {
  width: 80px;
  height: 72px;
  flex-shrink: 0;
}
.host-talk {
  flex: 1;
  min-width: 0;
}
.host-name {
  font-size: 13px;
  font-weight: 800;
  color: #15803d;
  margin-bottom: 2px;
}
.host-bubble {
  font-size: 15px;
  font-weight: 700;
  line-height: 1.25;
  color: var(--ink);
}
.host-bubble .t-en { font-size: 13px; color: var(--en); margin-top: 1px; }

.exam-body { display: flex; flex-direction: column; gap: 8px; flex: 1; min-height: 0; overflow-y: auto; }

/* Dữ kiện: gạch đầu dòng rõ ràng */
.facts { list-style: none; display: flex; flex-direction: column; gap: 6px; }
.facts li {
  display: grid; grid-template-columns: 32px 1fr; gap: 8px; align-items: start;
  font-size: 20px; font-weight: 700; line-height: 1.3; color: var(--ink);
}
.facts .f-ico { font-size: 22px; line-height: 1.2; text-align: center; }
.facts .t-en { font-size: 16px; }
body[data-lang="en"] .facts .t-en { font-size: 20px; color: var(--ink); }
.facts b, .ask-text b {
  background: var(--hl);
  border-radius: 6px;
  padding: 0 5px;
  box-decoration-break: clone;
  -webkit-box-decoration-break: clone;
}
body[data-lang="both"] .facts .t-en b, body[data-lang="both"] .ask-text .t-en b { background: #e0f2fe; }

/* Hình minh họa đề */
.figure:empty { display: none; }
.figure {
  position: relative;
  background: #f8fafc;
  border: 2px dashed #cbd5e1;
  border-radius: var(--r-md);
  padding: 10px;
  display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: center; gap: 6px;
  min-height: 70px;
}
.tile {
  min-width: 50px; height: 54px; padding: 0 6px;
  display: grid; place-items: center;
  background: #ffffff; border: 3px solid #93c5fd; border-radius: 12px;
  font-size: 26px; font-weight: 800; color: #1e3a8a;
  position: relative;
}
.tile .idx { position: absolute; bottom: -20px; left: 50%; transform: translateX(-50%); font-size: 12px; color: var(--muted); font-weight: 800; }
.figure.numbered { padding-bottom: 24px; }
.tile.mystery { border-color: var(--violet); background: #f5f3ff; color: var(--violet); }
.tile.mystery.pop { animation: pop 0.45s cubic-bezier(.3, 1.6, .5, 1); }
.tile.op { border: none; background: transparent; min-width: 20px; color: var(--muted); }
.tile.dots { border: none; background: transparent; min-width: 24px; color: var(--muted); }
@keyframes pop { 0% { transform: scale(0.3); } 100% { transform: scale(1); } }
.group { display: flex; flex-direction: column; align-items: center; gap: 2px; margin: 0 10px; }
.group .faces { font-size: 28px; letter-spacing: 2px; }
.group .glabel { font-size: 15px; font-weight: 800; color: var(--ink-2); text-align: center; line-height: 1.15; }
.group .glabel .t-en { display: block; font-size: 13px; }
.cal { display: grid; grid-template-columns: repeat(9, 1fr); gap: 4px; width: 100%; max-width: 580px; }
.cal-cell {
  background: #ffffff; border: 2.5px solid #e2e8f0; border-radius: 10px; padding: 3px 2px;
  text-align: center; font-size: 22px; font-weight: 800; line-height: 1.1;
}
.cal-cell small { display: block; font-size: 11px; font-weight: 800; color: var(--muted); }
.cal-cell.start { border-color: var(--good); }
.cal-cell.start small { color: var(--good); }
.cal-cell.target { border-color: var(--violet); background: #f5f3ff; }
.cal-cell.target small { color: var(--violet); }
.cal-head { width: 100%; text-align: center; font-size: 15px; font-weight: 800; color: var(--muted); }
.tl { display: flex; align-items: flex-start; width: 100%; max-width: 580px; }
.tl-pt { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; position: relative; }
.tl-pt::before { content: ''; position: absolute; top: 24px; left: -50%; width: 100%; height: 4px; background: #cbd5e1; z-index: 0; }
.tl-pt:first-child::before { display: none; }
.tl-bead {
  position: relative; z-index: 1; width: 48px; height: 48px; border-radius: 50%;
  display: grid; place-items: center; background: #ffffff; border: 3.5px solid #93c5fd;
  font-size: 18px; font-weight: 800;
}
.tl-bead.mystery { border-color: var(--violet); color: var(--violet); background: #f5f3ff; font-size: 24px; }
.tl-lbl { font-size: 14px; font-weight: 800; text-align: center; line-height: 1.15; }
.tl-lbl .t-en { display: block; font-size: 12px; }
#nam-runner { position: absolute; left: 0; top: 0; width: 100%; height: 100%; pointer-events: none; }

/* Câu hỏi chính */
.ask-box {
  display: flex; gap: 10px; align-items: center;
  background: #fff7ed; border: 2.5px solid #fdba74; border-radius: var(--r-md);
  padding: 8px 14px; flex-shrink: 0;
}
.ask-ico { font-size: 26px; }
.ask-text { font-size: 21px; font-weight: 800; line-height: 1.25; }
.ask-text .t-en { font-size: 17px; }
body[data-lang="en"] .ask-text .t-en { font-size: 21px; color: var(--ink); }

/* Đáp án 2×2 - Cỡ bự 3D */
.options { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; flex-shrink: 0; }
.opt {
  min-height: 64px;
  display: flex; align-items: center; gap: 12px;
  padding: 6px 14px;
  background: #ffffff;
  border: 3px solid var(--line);
  border-radius: var(--r-md);
  box-shadow: 0 4px 0 #e2e8f0;
  text-align: left;
  transition: transform 0.08s, border-color 0.15s, background 0.15s, box-shadow 0.08s;
}
.opt:active:not(:disabled) { transform: translateY(3px); box-shadow: 0 1px 0 #e2e8f0; }
.opt .letter {
  flex-shrink: 0; width: 40px; height: 40px; border-radius: 50%;
  display: grid; place-items: center;
  background: #f1f5f9; font-size: 19px; font-weight: 800; color: var(--ink-2);
}
.opt .o-big { font-size: 32px; font-weight: 800; color: #1e3a8a; min-width: 32px; text-align: center; }
.opt .o-text { display: flex; flex-direction: column; font-size: 21px; font-weight: 800; line-height: 1.15; }
.opt .o-text .t-en { font-size: 15px; }
body[data-lang="en"] .opt .o-text .t-en { font-size: 21px; color: var(--ink); }
.opt.selected { border-color: var(--brand); background: #f0f9ff; box-shadow: 0 4px 0 #7dd3fc; }
.opt.selected .letter { background: var(--brand); color: #ffffff; }
.opt.wrong { border-color: var(--bad); background: var(--bad-bg); box-shadow: 0 4px 0 #fca5a5; animation: shake 0.4s; }
.opt.wrong .letter { background: var(--bad); color: #ffffff; }
.opt.correct { border-color: var(--good); background: var(--good-bg); box-shadow: 0 4px 0 #86efac; }
.opt.correct .letter { background: var(--good); color: #ffffff; }
.opt:disabled { cursor: default; }
.opt.dim { opacity: 0.45; }
@keyframes shake { 20%, 60% { transform: translateX(-6px); } 40%, 80% { transform: translateX(6px); } }

/* Thanh hành động */
.action-bar { display: flex; gap: 10px; margin-top: auto; flex-shrink: 0; }
.big-btn {
  min-height: 54px;
  border-radius: var(--r-md);
  padding: 6px 14px;
  font-size: 18px; font-weight: 800; line-height: 1.1;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  box-shadow: 0 4px 0 rgba(15, 23, 42, 0.18);
  transition: transform 0.08s, box-shadow 0.08s, opacity 0.2s;
}
.big-btn:active:not(:disabled) { transform: translateY(3px); box-shadow: 0 1px 0 rgba(15, 23, 42, 0.18); }
.big-btn:disabled { opacity: 0.45; cursor: default; }
.big-btn .ico { font-size: 24px; }
.big-btn .lbl { display: flex; flex-direction: column; align-items: flex-start; text-align: left; }
body[data-lang="both"] .big-btn .t-en { display: block; font-size: 13px; color: inherit; opacity: 0.85; }
.btn-hint { background: #ede9fe; color: #5b21b6; justify-content: flex-start; }
.btn-hint .count { margin-left: auto; font-size: 13px; background: #ffffff; border-radius: 8px; padding: 2px 6px; }
.btn-check { flex: 1; background: var(--brand); color: #ffffff; font-size: 22px; }
body[data-lang="both"] .btn-check { flex-direction: column; gap: 0; }
.btn-skip { background: #f1f5f9; color: var(--muted); flex-direction: column; gap: 0; font-size: 16px; }

/* Phản hồi */
.feedback {
  margin-top: auto;
  display: flex; align-items: center; gap: 12px;
  border-radius: var(--r-md);
  padding: 10px 14px;
  border: 3px solid;
  animation: rise 0.25s ease-out;
  flex-shrink: 0;
}
.feedback[hidden] { display: none; }
@keyframes rise { from { transform: translateY(10px); opacity: 0; } }
.feedback.good { background: var(--good-bg); border-color: #86efac; }
.feedback.bad { background: var(--warn-bg); border-color: #fcd34d; }
.fb-icon { font-size: 34px; }
.fb-text { flex: 1; min-width: 0; }
.fb-title { font-size: 20px; font-weight: 800; line-height: 1.2; }
.fb-title .t-en { font-size: 15px; }
.fb-msg { font-size: 16px; font-weight: 700; color: var(--ink-2); line-height: 1.25; }
.fb-msg .t-en { display: block; font-size: 14px; }
.fb-actions { display: flex; gap: 8px; flex-shrink: 0; }
.fb-actions .big-btn { font-size: 16px; flex-direction: column; gap: 0; min-width: 110px; }
.btn-go { background: var(--good); color: #ffffff; }
.btn-retry { background: var(--warn); color: #ffffff; }
.btn-watch { background: var(--brand); color: #ffffff; }

/* ===================== CỘT 2: HƯỚNG DẪN TRỰC QUAN ===================== */
.guide-card {
  background: var(--card);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow);
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 0;
  overflow: hidden;
}
.guide-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-shrink: 0;
}
.guide-title {
  display: flex;
  align-items: baseline;
  gap: 6px;
  font-size: 18px;
  font-weight: 800;
  color: var(--brand-dark);
}
.guide-sub { font-size: 14px; color: var(--muted); font-weight: 700; }
.mode-pills { display: flex; gap: 6px; }
.pill {
  height: 38px; padding: 0 12px; border-radius: 19px;
  background: #f1f5f9; font-size: 14px; font-weight: 800; color: var(--ink-2);
}
.pill.active { background: var(--brand); color: #ffffff; }
body[data-lang="both"] .pill .t-en { color: inherit; font-size: 12px; margin-left: 3px; }
.mobile-only { display: none !important; }

/* Sân khấu Canvas */
.canvas-wrapper {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #f0f9ff;
  border-radius: var(--r-md);
  overflow: hidden;
  box-shadow: inset 0 0 0 3px var(--line);
}
.canvas-wrapper canvas {
  max-width: 100%;
  max-height: 100%;
  aspect-ratio: 16 / 9;
  width: auto;
  height: 100%;
  display: block;
}
#timo-canvas { background: #f0f9ff; }
#webgl-canvas { position: absolute; inset: 0; pointer-events: none; }

.interactive-counter-row {
  display: none; align-items: center; gap: 10px;
  font-size: 16px; font-weight: 800; flex-shrink: 0;
}
.progress-track { flex: 1; height: 12px; background: #f1f5f9; border-radius: 6px; overflow: hidden; }
.progress-fill { width: 0; height: 100%; background: var(--good); transition: width 0.3s; }

/* Bộ điều khiển & Trạm dừng cỡ bự */
.step-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}
.btn-step { min-width: 52px; background: #f1f5f9; color: var(--ink); font-size: 16px; padding: 8px 10px; }
.btn-play { background: var(--warn-bg); color: #92400e; font-size: 14px; padding: 8px 12px; white-space: nowrap; }
.btn-next { background: var(--good); color: #ffffff; font-size: 14px; padding: 8px 12px; white-space: nowrap; }

.map-stations { flex: 1; display: flex; gap: 6px; }
.station-stop {
  flex: 1; min-height: 48px; border-radius: 12px;
  display: flex; align-items: center; justify-content: center; gap: 4px;
  background: #f8fafc; border: 2.5px solid var(--line);
  font-size: 13px; font-weight: 800; color: var(--muted);
  padding: 2px 4px; line-height: 1.1; text-align: center;
  cursor: pointer;
  transition: all 0.15s;
}
.station-stop .station-icon { font-size: 17px; }
.station-stop.active {
  border-color: var(--brand);
  background: #f0f9ff;
  color: var(--brand-dark);
  box-shadow: 0 0 0 3px rgba(14, 165, 233, 0.2);
}
.station-stop.passed { border-color: #86efac; background: var(--good-bg); color: var(--good); }

/* Mẹo vàng & ghi chú */
.room-notes {
  flex-shrink: 0;
  max-height: 84px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.note-card {
  background: #f8fafc;
  border-radius: 10px;
  padding: 8px 12px;
  border: 2px solid var(--line);
  font-size: 14px;
}
.note-card h4 { font-size: 15px; font-weight: 800; color: var(--brand-dark); margin-bottom: 4px; line-height: 1.15; }
.note-card ol { padding-left: 18px; font-size: 14px; font-weight: 700; line-height: 1.3; color: var(--ink-2); }
.note-card.trick {
  background: var(--warn-bg);
  border-color: #fcd34d;
  font-size: 15px;
  font-weight: 800;
  color: #92400e;
  line-height: 1.25;
}

/* ===================== RESPONSIVE / MÀN NHỎ & ĐỨNG ===================== */
@media (orientation: portrait), (max-width: 900px) {
  body { overflow: auto; }
  .topbar { flex-wrap: wrap; height: auto; padding: 8px 12px; row-gap: 6px; }
  .topbar-nav { order: 3; flex-basis: 100%; }
  .exam-frame { height: auto; overflow: visible; }
  .guide-card { min-height: 480px; }
  .exam-body { display: flex; }
}

@media (max-width: 640px) {
  .options { grid-template-columns: 1fr; }
  .lang-switch button { padding: 0 8px; }
  .brand-text small { display: none; }
  .cal { grid-template-columns: repeat(5, 1fr); }
}

/* Nhãn ngắn song ngữ trên cùng một dòng: "Câu 1 · Q1" */
body[data-lang="both"] :is(.q-number, .topic-chip, .wave-chip, .host-name, .cal-head, .fb-title) .t-vi + .t-en::before { content: ' · '; }

/* ===================== HỘP THOẠI CHỌN ĐỀ THI (EXAM MODAL) ===================== */
.exam-modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.68);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  animation: modalFadeIn 0.2s ease-out;
}
.exam-modal-backdrop[hidden] {
  display: none !important;
}

@keyframes modalFadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes modalCardPop {
  0% { transform: scale(0.85) translateY(20px); opacity: 0; }
  70% { transform: scale(1.02) translateY(-4px); opacity: 1; }
  100% { transform: scale(1) translateY(0); opacity: 1; }
}

.exam-modal-card {
  width: 100%;
  max-width: 820px;
  max-height: 92vh;
  display: flex;
  flex-direction: column;
  background: #ffffff;
  border-radius: 28px;
  border: 4px solid #38bdf8;
  box-shadow: 0 24px 60px rgba(15, 23, 42, 0.35), 0 0 0 8px rgba(56, 189, 248, 0.25);
  overflow: hidden;
  animation: modalCardPop 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.exam-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 24px;
  background: linear-gradient(135deg, #e0f2fe 0%, #f0fdf4 100%);
  border-bottom: 3px solid #bae6fd;
}

.exam-modal-title-group {
  display: flex;
  align-items: center;
  gap: 14px;
}

.modal-title-icon {
  font-size: 38px;
  line-height: 1;
  filter: drop-shadow(0 3px 4px rgba(0,0,0,0.15));
}

.exam-modal-title {
  margin: 0;
  font-size: 22px;
  font-weight: 900;
  color: #0369a1;
  letter-spacing: 0.5px;
  line-height: 1.2;
}

.exam-modal-sub {
  margin: 3px 0 0 0;
  font-size: 14px;
  font-weight: 700;
  color: #475569;
}

.modal-close-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: #ffffff;
  border: 3px solid #cbd5e1;
  box-shadow: 0 3px 0 #94a3b8;
  color: #64748b;
  font-size: 20px;
  font-weight: 900;
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: transform 0.1s, background 0.15s, color 0.15s;
}
.modal-close-btn:hover {
  background: #fee2e2;
  border-color: #f87171;
  box-shadow: 0 3px 0 #ef4444;
  color: #b91c1c;
  transform: scale(1.08);
}
.modal-close-btn:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 #ef4444;
}

.exam-list {
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  overflow-y: auto;
  max-height: calc(92vh - 120px);
}

.exam-card-item {
  position: relative;
  background: #f8fafc;
  border-radius: 20px;
  border: 3px solid #e2e8f0;
  box-shadow: 0 4px 0 #cbd5e1;
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}

.exam-card-item:hover {
  transform: translateY(-2px);
  background: #ffffff;
  border-color: #38bdf8;
  box-shadow: 0 6px 0 #0284c7;
}

.exam-card-item.active {
  background: #eff6ff;
  border-color: #2563eb;
  box-shadow: 0 5px 0 #1d4ed8, 0 0 0 3px rgba(37, 99, 235, 0.2);
}

.exam-card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.exam-card-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 12px;
  border-radius: 12px;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.5px;
}

.exam-card-stars {
  font-size: 15px;
  font-weight: 800;
  color: #b45309;
  background: #fef3c7;
  border: 2px solid #fde68a;
  padding: 3px 10px;
  border-radius: 12px;
}
.exam-card-stars strong {
  font-size: 17px;
  color: #92400e;
}

.exam-card-main {
  display: flex;
  align-items: flex-start;
  gap: 14px;
}

.exam-card-icon {
  width: 58px;
  height: 58px;
  border-radius: 18px;
  display: grid;
  place-items: center;
  font-size: 32px;
  flex-shrink: 0;
  box-shadow: inset 0 2px 4px rgba(255,255,255,0.8), 0 3px 6px rgba(0,0,0,0.06);
}

.exam-card-details {
  flex: 1;
  min-width: 0;
}

.exam-card-title {
  margin: 0 0 4px 0;
  font-size: 19px;
  font-weight: 800;
  color: #0f172a;
  line-height: 1.25;
}

.exam-card-desc {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  color: #64748b;
  line-height: 1.4;
}

.exam-card-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: 10px;
  border-top: 2px dashed #e2e8f0;
}

.exam-card-status {
  font-size: 13px;
  font-weight: 800;
  color: #059669;
}

.exam-card-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 40px;
  padding: 0 18px;
  border-radius: 20px;
  background: linear-gradient(135deg, #0ea5e9 0%, #0284c7 100%);
  border: 2px solid #38bdf8;
  box-shadow: 0 3px 0 #0369a1;
  color: #ffffff;
  font-size: 15px;
  font-weight: 800;
  cursor: pointer;
  transition: transform 0.1s, box-shadow 0.1s;
}

.exam-card-item.active .exam-card-btn {
  background: linear-gradient(135deg, #22c55e 0%, #16a34a 100%);
  border-color: #86efac;
  box-shadow: 0 3px 0 #15803d;
}

.exam-card-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 0 #0369a1;
}
.exam-card-btn:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 #0369a1;
}


/* ===================== MÀN ĐỀ ⇄ MÀN CÁCH GIẢI ===================== */
.exam-card, .guide-card { width: 100%; max-width: 1240px; margin: 0 auto; }
.exam-card[hidden], .guide-card[hidden] { display: none !important; }
.journey-dot { cursor: default; }

/* Màn ngang: dữ kiện bên trái, hình minh họa bên phải — đề thoáng, không thành một khối chữ */
@media (orientation: landscape) and (min-width: 901px) {
  .exam-body {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    grid-template-areas: "facts figure" "hint hint" "ask ask";
    grid-auto-rows: min-content;
    align-content: start;
    column-gap: 16px; row-gap: 10px;
  }
  .exam-body .facts { grid-area: facts; align-self: center; }
  .exam-body .figure { grid-area: figure; }
  .exam-body .figure:empty { display: none; }
  .exam-body:has(.figure:empty) .facts { grid-column: 1 / -1; }
  .exam-body .hint-curtain { grid-area: hint; }
  .exam-body .ask-box { grid-area: ask; }
}

/* Nút "Xem cách giải" — luôn bấm được */
.btn-solution { background: #e0f2fe; color: var(--brand-dark); justify-content: flex-start; }
.btn-back { background: #f1f5f9; color: var(--ink); font-size: 16px; }
body[data-lang="both"] .btn-back .t-en::before { content: ' · '; }
.room-penalty { font-size: 13px; font-weight: 800; color: var(--warn); }
.room-penalty[hidden] { display: none; }

/* Cú Mèo soi kính lúp: phóng to từ khóa */
.exam-body b.lens {
  display: inline-block;
  position: relative;
  animation: lensZoom 1.6s ease-in-out;
  animation-delay: var(--d, 0s);
  animation-fill-mode: both;
  z-index: 2;
}
.exam-body b.lens::after {
  content: '🔍';
  position: absolute; right: -16px; top: -22px;
  font-size: 22px;
  opacity: 0;
  animation: lensIcon 1.6s ease-in-out;
  animation-delay: inherit;
  pointer-events: none;
}
@keyframes lensZoom {
  0%, 100% { transform: scale(1); box-shadow: none; }
  30%, 70% { transform: scale(1.35); box-shadow: 0 0 0 4px #fbbf24, 0 6px 14px rgba(146, 64, 14, 0.3); background: #fef08a; }
}
@keyframes lensIcon { 0%, 100% { opacity: 0; } 25%, 75% { opacity: 1; } }

/* Rèm gợi ý: kéo lên hé lộ gợi ý */
.hint-curtain {
  position: relative;
  overflow: hidden;
  border-radius: var(--r-md);
  background: #f5f3ff;
  border: 2.5px solid #c4b5fd;
  padding: 8px 14px 8px 44px;
  flex-shrink: 0;
}
.hint-curtain[hidden] { display: none; }
.hint-curtain::before { content: '🦉'; position: absolute; left: 10px; top: 8px; font-size: 24px; }
.hc-text { font-size: 18px; font-weight: 800; color: #5b21b6; line-height: 1.3; }
.hc-text .t-en { font-size: 15px; color: #6d28d9; }
body[data-lang="en"] .hc-text .t-en { font-size: 18px; }
.hc-cloth {
  position: absolute; inset: 0;
  background: repeating-linear-gradient(90deg, #dc2626 0 22px, #991b1b 22px 34px);
  border-bottom: 6px solid #fbbf24;
  transform-origin: top;
  transform: translateY(0);
  pointer-events: none;
}
.hint-curtain.open .hc-cloth { transform: translateY(-105%); transition: transform 1.1s cubic-bezier(.6, .05, .3, 1); }

/* ===================== CHỌN ĐỀ: VUỐT NGANG ===================== */
.exam-modal-card { max-width: 1040px; }
.exam-carousel { position: relative; display: flex; align-items: center; }
.exam-list {
  flex: 1;
  flex-direction: row;
  overflow-x: auto;
  overflow-y: hidden;
  scroll-snap-type: x mandatory;
  scroll-padding: 0 20px;
  overscroll-behavior-x: contain;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  padding: 20px 20px 24px;
  gap: 18px;
  max-height: none;
}
.exam-list::-webkit-scrollbar { display: none; }
.exam-card-item {
  flex: 0 0 min(80%, 400px);
  scroll-snap-align: center;
  min-height: 300px;
}
.exam-card-item.locked { opacity: 0.85; }
.exam-card-desc { font-size: 15px; }
.exam-card-topics { display: flex; flex-wrap: wrap; gap: 6px; }
.exam-card-topics span {
  font-size: 13px; font-weight: 800; padding: 2px 9px; border-radius: 10px;
  background: #ffffff; border: 2px solid var(--line); color: var(--ink-2);
}
.exam-card-progress { height: 10px; background: #e2e8f0; border-radius: 5px; overflow: hidden; }
.exam-card-progress > div { height: 100%; background: var(--good); }
.exam-card-footer { margin-top: auto; }
.car-arrow {
  flex-shrink: 0; width: 48px; height: 48px; margin: 0 6px; border-radius: 50%;
  background: #ffffff; border: 3px solid #bae6fd; box-shadow: 0 3px 0 #7dd3fc;
  color: var(--brand-dark); font-size: 18px; font-weight: 900;
}
.car-arrow:disabled { opacity: 0.3; }
.car-dots { display: flex; justify-content: center; gap: 8px; padding: 0 0 16px; }
.car-dots button { width: 12px; height: 12px; border-radius: 6px; background: #cbd5e1; transition: width 0.2s, background 0.2s; }
.car-dots button.on { width: 28px; background: var(--brand); }
@media (max-width: 640px) { .car-arrow { display: none; } }

/* Nhãn song ngữ trên thẻ đề & nút chọn đề: tách rõ Việt / Anh */
.exam-card-title .t-en, .exam-curr-name .t-en { display: block; font-size: 0.8em; }
body[data-lang="both"] :is(.exam-card-desc, .exam-card-status, .exam-card-topics span, .exam-card-btn) .t-vi + .t-en::before { content: ' · '; }
.exam-card-btn .t-en { color: inherit !important; opacity: 0.9; }
body[data-lang="both"] .exam-card-topics span .t-en { font-size: 12px; }
.exam-card-btn { white-space: nowrap; }

/* Lớp hiệu ứng WebGL đè khít đúng lên sân khấu canvas (canh giữa, cùng tỉ lệ 16:9) */
#webgl-canvas { inset: auto; top: 0; left: 50%; transform: translateX(-50%); height: 100%; width: auto; }
.guide-head { flex-wrap: wrap; }
.guide-title { flex-wrap: wrap; align-items: baseline; column-gap: 8px; }
body[data-lang="both"] .guide-title > .t-en { font-size: 14px; }
.room-penalty { flex-basis: 100%; }
.room-notes { max-height: 120px; }

/* ===================== LỜI GIẢI TỪNG BƯỚC ===================== */
.steps-view[hidden] { display: none !important; }
.steps-view {
  flex: 1; min-height: 0;
  display: grid; grid-template-columns: minmax(0, 0.9fr) minmax(0, 1.4fr); gap: 14px;
}
.solution-room.steps-mode .canvas-wrapper,
.guide-card.steps-mode .canvas-wrapper,
.guide-card.steps-mode .step-row,
.guide-card.steps-mode .interactive-counter-row { display: none !important; }
.mode-pills[hidden] { display: none !important; }
.sv-side {
  display: flex; flex-direction: column; gap: 10px; min-height: 0; overflow-y: auto;
  background: #f0f9ff; border-radius: var(--r-md); padding: 12px;
}
.sv-host { display: flex; align-items: center; gap: 8px; font-size: 16px; font-weight: 800; color: var(--brand-dark); }
body[data-lang="both"] .sv-host .t-en::before { content: ' · '; }
.sv-emoji { font-size: 40px; animation: svBob 2.4s ease-in-out infinite; }
@keyframes svBob { 50% { transform: translateY(-5px) rotate(-4deg); } }
.sv-ask { font-size: 18px; font-weight: 800; line-height: 1.3; }
.sv-ask .t-en { font-size: 15px; }
.sv-ask b { background: var(--hl); border-radius: 6px; padding: 0 4px; }
.sv-figure { background: #ffffff; border-radius: 12px; padding: 8px; text-align: center; }
.sv-figure[hidden] { display: none; }
.sv-figure img { max-width: 100%; max-height: 260px; object-fit: contain; }
.sv-canvas-box {
  background: #ffffff; border-radius: 14px; padding: 6px; text-align: center;
  border: 2.5px solid var(--line); box-shadow: 0 4px 12px rgba(15,23,42,0.06);
  display: flex; align-items: center; justify-content: center; overflow: hidden;
}
.sv-canvas-box[hidden] { display: none !important; }
.sv-canvas-box canvas {
  width: 100%; max-height: 280px; aspect-ratio: 16 / 9; display: block; border-radius: 10px;
  cursor: pointer; touch-action: manipulation;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.sv-canvas-box canvas:hover {
  box-shadow: 0 4px 16px rgba(14, 165, 233, 0.25);
}
.sv-canvas-box canvas:active {
  transform: scale(0.99);
}
.sv-seq { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; }
.sv-seq .tile { min-width: 42px; height: 46px; font-size: 22px; }
.sv-main { display: flex; flex-direction: column; gap: 10px; min-height: 0; }
.sv-list { list-style: none; flex: 1; min-height: 0; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; padding: 2px; }
.sv-step {
  position: relative; overflow: hidden;
  display: grid; grid-template-columns: 40px 1fr; gap: 10px; align-items: start;
  background: #ffffff; border: 3px solid var(--line); border-radius: var(--r-md);
  padding: 10px 14px; min-height: 58px;
  font-size: 19px; font-weight: 800; line-height: 1.35;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.sv-step .t-en { font-size: 15px; }
body[data-lang="en"] .sv-step .t-en { font-size: 19px; }
.sv-num {
  width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center;
  background: var(--brand); color: #ffffff; font-size: 18px;
}
.sv-step.final { background: var(--good-bg); border-color: #86efac; }
.sv-step.final .sv-num { background: transparent; font-size: 24px; }
.sv-step.current { border-color: var(--brand); box-shadow: 0 0 0 4px rgba(14, 165, 233, 0.18); }
.sv-step.final.current { border-color: var(--good); box-shadow: 0 0 0 4px rgba(22, 163, 74, 0.18); }
/* Rèm đỏ che bước chưa mở; mở bước thì rèm kéo lên */
.sv-cloth {
  position: absolute; inset: 0;
  background: repeating-linear-gradient(90deg, #dc2626 0 20px, #991b1b 20px 30px);
  border-bottom: 5px solid #fbbf24;
  transition: transform 0.9s cubic-bezier(.6, .05, .3, 1);
  display: grid; place-items: center;
}
.sv-cloth::after { content: '🦉 ?'; font-size: 22px; color: #fde68a; }
.sv-step.shown .sv-cloth { transform: translateY(-105%); }
.sv-controls { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.sv-count { flex: 1; text-align: center; font-size: 17px; font-weight: 800; color: var(--muted); }
body[data-lang="both"] .sv-count .t-en::before { content: ' · '; }
body[data-lang="both"] :is(#sv-next, #sv-play) { flex-direction: column; gap: 0; }
body[data-lang="both"] :is(#sv-next, #sv-play) .t-en { font-size: 12px; }
@media (orientation: portrait), (max-width: 900px) {
  .steps-view { grid-template-columns: 1fr; }
  .sv-list { max-height: none; }
}

/* ===================== KHU TRẢ LỜI: CHỌN HÌNH / BÀN PHÍM SỐ / ĐIỀN DẤU ===================== */
.opt .o-img { max-height: 56px; max-width: 120px; object-fit: contain; }
.options.pick { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
.options.keypad-wrap, .options.ops-wrap { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.num-display {
  min-width: 220px; height: 64px; padding: 0 18px;
  display: flex; align-items: center; justify-content: center; gap: 2px;
  background: #ffffff; border: 3px solid var(--brand); border-radius: var(--r-md);
  font-size: 36px; font-weight: 800; color: #1e3a8a; letter-spacing: 2px;
}
.num-display .caret { width: 3px; height: 34px; background: var(--brand); animation: caret 1s steps(2) infinite; }
@keyframes caret { 50% { opacity: 0; } }
.num-display.wrong { border-color: var(--bad); background: var(--bad-bg); animation: shake 0.4s; }
.num-display.correct { border-color: var(--good); background: var(--good-bg); }
.num-display.correct .caret { display: none; }
.keypad { display: grid; grid-template-columns: repeat(6, 64px); gap: 8px; }
.key {
  height: 54px; border-radius: 14px; background: #ffffff; border: 3px solid var(--line);
  box-shadow: 0 4px 0 #e2e8f0; font-size: 26px; font-weight: 800; color: var(--ink);
}
.key.fn { background: #f1f5f9; color: var(--muted); font-size: 22px; }
.key:active:not(:disabled) { transform: translateY(3px); box-shadow: 0 1px 0 #e2e8f0; }
.key:disabled { opacity: 0.4; }
.ops-row { display: flex; align-items: center; flex-wrap: wrap; justify-content: center; gap: 10px; }
.op-num { font-size: 34px; font-weight: 800; color: #1e3a8a; }
.op-slot {
  width: 58px; height: 58px; border-radius: 50%;
  background: #f5f3ff; border: 3px dashed var(--violet); color: var(--violet);
  font-size: 30px; font-weight: 900;
}
.op-slot.wrong { border-style: solid; border-color: var(--bad); background: var(--bad-bg); color: var(--bad); animation: shake 0.4s; }
.op-slot.correct { border-style: solid; border-color: var(--good); background: var(--good-bg); color: var(--good); }
.ops-help { font-size: 14px; font-weight: 800; color: var(--muted); }
body[data-lang="both"] .ops-help .t-en::before { content: ' · '; }
.tile.mystery.caught { border-color: var(--good); background: var(--good-bg); color: var(--good); animation: pop 0.45s cubic-bezier(.3, 1.6, .5, 1); }

/* Thanh tiến độ gọn khi đề có nhiều câu (25 câu) */
.journey.compact { gap: 3px; }
.journey.compact .journey-dot { width: 14px; height: 14px; border-width: 2px; font-size: 0; }
.journey.compact .journey-dot.current { transform: scale(1.35); box-shadow: 0 0 0 3px rgba(14, 165, 233, 0.25); }
.journey.compact .wave-sep { width: 6px; }
.journey-label { margin-left: 8px; font-size: 15px; font-weight: 800; color: var(--brand-dark); white-space: nowrap; }

/* Hình minh hoạ cắt từ đề PDF */
.figure.pic { padding: 8px; background: #ffffff; align-items: center; }
.figure.pic img { max-width: 100%; max-height: 300px; object-fit: contain; display: block; }
@media (orientation: landscape) and (min-width: 901px) { .figure.pic img { max-height: min(240px, 28vh); } }
body[data-lang="both"] .guide-sub .t-vi + .t-en::before { content: ' · '; }
