﻿/* ─────────────── Base ─────────────── */
:root {
  /* Palette theo mockup quiz tím */
  --bg: #f5f4fd;
  --surface: #ffffff;
  --surface-alt: #f0eefb;
  --ink: #2d2a4a;
  --muted: #8e8aad;
  --line: #e9e7f6;
  --primary: #6c5ce7;
  --primary-soft: #efecfd;
  --primary-ink: #ffffff;
  --success: #27ae60;
  --success-soft: #e6f8ef;
  --danger: #eb5757;
  --danger-soft: #fdeaea;
  --warn: #e8903a;
  --warn-soft: #fdeedd;
  --dark: #6c5ce7; /* header dùng màu tím như mockup */
  --radius: 20px;
  --radius-sm: 14px;
  --radius-lg: 28px;
  --shadow: 0 10px 30px rgba(108, 92, 231, 0.12);
  --shadow-sm: 0 4px 14px rgba(45, 42, 74, 0.07);
  --topbar-h: 60px;
  --branch: var(--primary);
  font-family: "Segoe UI", system-ui, -apple-system, "SF Pro Rounded", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
  line-height: 1.5;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
}

a {
  color: var(--primary);
}

button,
input,
select {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
}

:focus-visible {
  outline: 3px solid var(--primary);
  outline-offset: 2px;
}

h1:focus,
h2:focus {
  outline: none;
}

.skip-link {
  position: absolute;
  left: -999px;
  top: 8px;
  z-index: 100;
  background: var(--dark);
  color: #fff;
  padding: 8px 14px;
  border-radius: 8px;
}

.skip-link:focus {
  left: 8px;
}

.muted {
  color: var(--muted);
}

.small {
  font-size: 0.875rem;
}

.noscript {
  padding: 2rem;
  text-align: center;
}

/* ─────────────── Top bar ─────────────── */
.topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 50;
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 16px;
  background: var(--dark);
  color: #fff;
  box-shadow: 0 2px 12px rgba(45, 42, 74, 0.18);
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  color: #fff;
  text-decoration: none;
  font-size: 1.1rem;
  white-space: nowrap;
}

.nav {
  display: flex;
  gap: 4px;
  margin-left: 8px;
}

.nav a {
  color: #cbd5e1;
  text-decoration: none;
  padding: 8px 12px;
  border-radius: 10px;
  white-space: nowrap;
}

.nav a:hover {
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
}

.nav a[aria-current="page"] {
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
  font-weight: 600;
}

.stats {
  margin-left: auto;
  display: flex;
  gap: 14px;
  font-size: 0.95rem;
  color: #e2e8f0;
}

.stat {
  white-space: nowrap;
}

@media (max-width: 720px) {
  .brand-text,
  .nav a span,
  .stat-label {
    display: none;
  }
  .topbar {
    gap: 8px;
    padding: 0 10px;
  }
  .nav a {
    padding: 8px 10px;
    font-size: 1.15rem;
  }
  .stats {
    gap: 8px;
    font-size: 0.85rem;
  }
}

/* ─────────────── Buttons & pills ─────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 12px 20px;
  border-radius: var(--radius-sm);
  border: 2px solid transparent;
  font-weight: 700;
  text-decoration: none;
  background: var(--surface);
  color: var(--ink);
  transition: transform 0.08s ease, background 0.15s ease, box-shadow 0.15s ease;
}

.btn:active {
  transform: scale(0.97);
}

.btn.block {
  display: flex;
  width: 100%;
  margin-top: 12px;
}

.btn.small {
  padding: 8px 14px;
  font-size: 0.9rem;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
  box-shadow: 0 6px 16px rgba(108, 92, 231, 0.3);
}

.btn-primary:hover {
  filter: brightness(1.06);
}

.btn-outline {
  border-color: var(--primary);
  color: var(--primary);
  background: var(--surface);
}

.btn-outline:hover {
  background: var(--primary-soft);
}

.btn-success {
  background: var(--success-soft);
  border-color: var(--success);
  color: var(--success);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.icon-btn {
  border: none;
  background: transparent;
  font-size: 1.1rem;
  width: 36px;
  height: 36px;
  border-radius: 50%;
}

.icon-btn:hover {
  background: var(--bg);
}

.pill {
  display: inline-block;
  padding: 5px 12px;
  border-radius: 999px;
  background: var(--primary-soft);
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--primary);
  white-space: nowrap;
}

.pill.best {
  background: var(--warn-soft);
  color: var(--warn);
}

.speak-btn {
  flex: none;
  border: none;
  background: var(--primary-soft);
  color: var(--primary);
  border-radius: 50%;
  width: 34px;
  height: 34px;
  font-size: 0.95rem;
}

.speak-btn:hover:not(:disabled) {
  background: #e3dffb;
}

.speak-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* ─────────────── Toast ─────────────── */
.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translate(-50%, 140%);
  background: var(--dark);
  color: #fff;
  padding: 12px 20px;
  border-radius: 12px;
  box-shadow: var(--shadow);
  transition: transform 0.25s ease, opacity 0.25s ease, visibility 0.25s;
  z-index: 50;
  pointer-events: none;
  max-width: calc(100vw - 32px);
  opacity: 0;
  visibility: hidden;
}

.toast.show {
  transform: translate(-50%, 0);
  opacity: 1;
  visibility: visible;
}

/* ─────────────── Mindmap view ─────────────── */
.map-view {
  display: grid;
  grid-template-columns: 1fr;
  margin-top: var(--topbar-h);
  height: calc(100vh - var(--topbar-h));
  height: calc(100dvh - var(--topbar-h));
  overflow: hidden;
}

@media (min-width: 960px) {
  .map-view.panel-open {
    grid-template-columns: 1fr minmax(380px, 34%);
  }
}

.map-host {
  position: relative;
  min-width: 0;
  min-height: 0;
  background-color: #f8fafc;
  background-image: radial-gradient(#d7deea 1px, transparent 1px);
  background-size: 22px 22px;
}

.mindmap-svg {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  user-select: none;
  cursor: grab;
}

.mindmap-svg.dragging {
  cursor: grabbing;
}

.node {
  cursor: pointer;
}

.node .node-box {
  transition: filter 0.15s ease;
  filter: drop-shadow(0 2px 3px rgba(15, 23, 42, 0.12));
}

.node:hover .node-box {
  filter: drop-shadow(0 4px 10px rgba(15, 23, 42, 0.25));
}

.node.selected .node-box {
  stroke: #f59e0b;
  stroke-width: 4px;
}

.node:focus {
  outline: none;
}

.node:focus-visible .node-box {
  stroke: #f59e0b;
  stroke-width: 4px;
  stroke-dasharray: 6 3;
}

.node text {
  pointer-events: none;
}

.toggle {
  cursor: pointer;
}

.toggle:hover circle {
  fill: #f1f5f9;
}

.link {
  opacity: 0.85;
}

.map-toolbar {
  position: absolute;
  top: 12px;
  left: 12px;
  right: 12px;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: flex-start;
  pointer-events: none;
  z-index: 2;
}

.map-toolbar > * {
  pointer-events: auto;
}

.map-search {
  position: relative;
  flex: 1 1 220px;
  max-width: 360px;
}

.map-search-input {
  width: 100%;
  padding: 10px 14px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.map-search-results {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  margin: 0;
  padding: 6px;
  list-style: none;
  background: var(--surface);
  border-radius: 12px;
  box-shadow: var(--shadow);
  border: 1px solid var(--line);
  max-height: 320px;
  overflow: auto;
}

.map-search-results li {
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
}

.map-search-results li.active,
.map-search-results li:hover {
  background: var(--primary-soft);
}

.res-path {
  font-size: 0.78rem;
  color: var(--muted);
}

.tool-group {
  display: flex;
  background: var(--surface);
  border-radius: 12px;
  box-shadow: var(--shadow);
  border: 1px solid var(--line);
  overflow: hidden;
}

.tool-btn {
  border: none;
  background: transparent;
  width: 40px;
  height: 40px;
  font-size: 1.05rem;
}

.tool-btn + .tool-btn {
  border-left: 1px solid var(--line);
}

.tool-btn:hover {
  background: var(--bg);
}

.map-hint {
  position: absolute;
  bottom: 10px;
  left: 50%;
  transform: translateX(-50%);
  margin: 0;
  padding: 6px 12px;
  border-radius: 999px;
  background: rgba(31, 35, 51, 0.75);
  color: #fff;
  font-size: 0.8rem;
  white-space: nowrap;
  pointer-events: none;
}

@media (max-width: 600px) {
  .map-hint {
    display: none;
  }
}

/* ─────────────── Panel ─────────────── */
.panel {
  background: var(--surface);
  overflow-y: auto;
  border-left: 1px solid var(--line);
  display: none;
  overscroll-behavior: contain;
}

.panel-open .panel {
  display: block;
}

@media (max-width: 959px) {
  .panel-open .panel {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    height: 72vh;
    height: 72dvh;
    border-radius: 20px 20px 0 0;
    border-left: none;
    box-shadow: 0 -10px 40px rgba(15, 23, 42, 0.25);
    z-index: 30;
    animation: sheet-up 0.22s ease-out;
  }
}

@keyframes sheet-up {
  from {
    transform: translateY(40px);
    opacity: 0;
  }
}

.panel-head {
  position: sticky;
  top: 0;
  background: var(--surface);
  padding: 14px 20px 14px;
  border-bottom: 1px solid var(--line);
  border-top: 5px solid var(--branch);
  z-index: 1;
}

.panel-head-row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
}

.crumbs {
  flex: 1;
  font-size: 0.82rem;
  color: var(--muted);
}

.crumb {
  border: none;
  background: none;
  padding: 0;
  color: var(--primary);
  text-decoration: underline;
  font-size: inherit;
}

.crumb.current {
  color: var(--muted);
  text-decoration: none;
}

.panel-title {
  margin: 6px 0 0;
  font-size: 1.4rem;
  display: flex;
  align-items: center;
  gap: 10px;
}

.panel-en {
  margin: 2px 0 8px;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 8px;
  font-style: italic;
}

.panel-meta {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}

.panel-body {
  padding: 8px 20px 32px;
}

.panel-desc {
  font-size: 1.02rem;
}

.panel-section {
  margin-top: 22px;
}

.panel-section h3 {
  font-size: 1rem;
  margin: 0 0 10px;
  padding-left: 10px;
  border-left: 4px solid var(--branch);
}

.tips,
.formula {
  margin: 0;
  padding-left: 20px;
}

.tips li,
.formula li {
  margin: 6px 0;
}

.formula code {
  font-family: "Cascadia Code", Consolas, monospace;
  background: #f1f5f9;
  padding: 3px 8px;
  border-radius: 6px;
  font-size: 0.9rem;
  display: inline-block;
}

.letters {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(62px, 1fr));
  gap: 6px;
}

.letter {
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 10px;
  padding: 6px 4px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.letter strong {
  font-size: 1.25rem;
}

.letter small {
  color: var(--muted);
  font-size: 0.75rem;
}

.letter:hover,
.sound:hover {
  border-color: var(--branch);
  background: #f8fafc;
}

.sounds {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  gap: 6px;
}

.sound {
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 10px;
  padding: 8px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  text-align: left;
}

.sound .ipa {
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--branch);
}

.sound .hint {
  font-size: 0.75rem;
  color: var(--muted);
}

.vocab-list,
.sentence-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.vocab-list li {
  display: grid;
  grid-template-columns: 34px minmax(80px, auto) 1fr;
  grid-template-areas:
    "spk en ipa"
    "spk vi vi";
  column-gap: 10px;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px dashed var(--line);
}

.vocab-list .speak-btn {
  grid-area: spk;
}

.v-en {
  grid-area: en;
  font-weight: 700;
}

.v-ipa {
  grid-area: ipa;
  color: var(--muted);
  font-size: 0.88rem;
}

.v-vi {
  grid-area: vi;
  font-size: 0.92rem;
}

.sentence-list li {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 8px 0;
  border-bottom: 1px dashed var(--line);
}

.sentence-list p {
  margin: 0;
}

.s-en {
  font-weight: 600;
}

.s-vi {
  color: var(--muted);
  font-size: 0.92rem;
}

.child-links {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.child-link {
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 999px;
  padding: 6px 12px;
}

.child-link:hover {
  border-color: var(--branch);
}

.child-link.done {
  background: var(--success-soft);
  border-color: #86efac;
}

.mini-games {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 8px;
}

.mini-game {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px;
  border-radius: 12px;
  border: 1px solid var(--line);
  text-decoration: none;
  color: var(--ink);
  font-size: 0.9rem;
  font-weight: 600;
}

a.mini-game:hover {
  border-color: var(--branch);
  background: #f8fafc;
}

.mini-game.disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.mg-icon {
  font-size: 1.3rem;
}

/* ─────────────── Pages ─────────────── */
.page {
  max-width: 980px;
  margin: 0 auto;
  padding: calc(24px + var(--topbar-h)) 16px 64px;
}

.page h1 {
  margin: 0 0 6px;
  font-size: 1.7rem;
}

.lead {
  color: var(--muted);
  margin-top: 0;
}

.empty {
  text-align: center;
  padding: 40px 16px;
  background: var(--surface);
  border-radius: var(--radius);
}

/* Outline */
.progress-card {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--surface);
  padding: 14px 18px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin: 18px 0;
}

.progress-bar {
  flex: 1;
  height: 12px;
  background: #e2e8f0;
  border-radius: 999px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--success), var(--success));
  border-radius: 999px;
  transition: width 0.3s ease;
}

.outline-branch {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 12px;
  overflow: hidden;
}

.outline-branch summary {
  list-style: none;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 18px;
  cursor: pointer;
  border-left: 6px solid var(--branch);
}

.outline-branch summary::-webkit-details-marker {
  display: none;
}

.ob-icon {
  font-size: 1.6rem;
}

.ob-title {
  flex: 1;
  font-weight: 700;
  font-size: 1.1rem;
  display: flex;
  flex-direction: column;
}

.ob-title small {
  font-weight: 400;
  color: var(--muted);
  font-size: 0.85rem;
}

.ob-count {
  font-weight: 700;
  color: var(--muted);
}

.ob-desc {
  margin: 0;
  padding: 0 18px 8px 24px;
}

.outline-list {
  list-style: none;
  margin: 0;
  padding: 0 0 8px;
}

.outline-list li {
  display: flex;
  align-items: center;
  border-top: 1px solid var(--line);
}

.outline-list li a:first-child {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 18px 10px 24px;
  color: var(--ink);
  text-decoration: none;
}

.outline-list li a:first-child:hover {
  background: #f8fafc;
}

.outline-list li.overview .ol-title {
  font-style: italic;
}

.ol-title {
  flex: 1;
}

.ol-meta {
  font-size: 0.8rem;
  color: var(--muted);
}

.ol-play {
  padding: 10px 18px;
  text-decoration: none;
  font-size: 1.15rem;
}

/* Hub */
.scope-row {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  margin: 16px 0 20px;
}

.scope-row label {
  font-weight: 600;
}

.scope-select {
  flex: 1 1 260px;
  max-width: 480px;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--surface);
}

.game-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 14px;
}

.game-card {
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
  text-decoration: none;
  color: var(--ink);
  border: 2px solid transparent;
  transition: transform 0.12s ease, border-color 0.12s ease;
}

a.game-card:hover {
  transform: translateY(-3px);
  border-color: var(--primary);
}

.game-card.disabled {
  opacity: 0.55;
}

.gc-icon {
  font-size: 2.2rem;
}

.gc-name {
  margin: 6px 0 4px;
  font-size: 1.15rem;
}

.gc-desc {
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 0.92rem;
  flex: 1;
}

.gc-foot {
  display: flex;
  gap: 6px;
  align-items: center;
  flex-wrap: wrap;
}

.gc-play {
  margin-left: auto;
  font-weight: 700;
  color: var(--primary);
}

.gc-reason {
  margin-left: auto;
  font-size: 0.8rem;
  color: var(--danger);
}

/* ─────────────── Game shell ─────────────── */
.game-page {
  max-width: 760px;
}

.game-head {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  margin-bottom: 18px;
  padding-bottom: 12px;
  border-bottom: 4px solid var(--branch);
}

.back-link {
  text-decoration: none;
  font-weight: 600;
}

.g-title {
  flex: 1;
  min-width: 180px;
}

.g-title h1 {
  font-size: 1.4rem;
  margin: 0;
}

.g-title p {
  margin: 0;
}

.g-stats {
  display: flex;
  gap: 12px;
  align-items: center;
  font-weight: 700;
}

.g-progress {
  color: var(--muted);
  font-weight: 600;
}

.g-score-wrap {
  background: #fef3c7;
  color: var(--warn);
  padding: 4px 12px;
  border-radius: 999px;
}

.game-body {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px;
  min-height: 320px;
}

.game-prompt {
  text-align: center;
  margin: 8px 0 20px;
}

.game-prompt .label {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin: 0;
}

.game-prompt .big {
  font-size: clamp(1.6rem, 6vw, 2.4rem);
  font-weight: 800;
  margin: 6px 0;
  word-break: break-word;
}

.game-prompt .ipa {
  color: var(--muted);
}

.options {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 10px;
}

.option {
  padding: 15px 18px;
  border-radius: var(--radius-sm);
  border: 2px solid var(--line);
  background: var(--surface);
  font-size: 1.05rem;
  font-weight: 600;
  text-align: left;
  display: flex;
  gap: 10px;
  align-items: center;
}

.option:hover:not(:disabled) {
  border-color: var(--primary);
  background: var(--primary-soft);
}

.option kbd {
  flex: none;
  display: inline-grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border-radius: 8px;
  background: var(--primary-soft);
  font-size: 0.8rem;
  font-family: inherit;
  color: var(--primary);
}

.option.correct {
  border-color: var(--success);
  background: var(--success-soft);
}

.option.wrong {
  border-color: var(--danger);
  background: var(--danger-soft);
}

.option:disabled {
  cursor: default;
}

.feedback {
  min-height: 28px;
  margin: 14px 0 0;
  text-align: center;
  font-weight: 600;
}

.feedback.good {
  color: var(--success);
}

.feedback.bad {
  color: var(--danger);
}

.game-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
  margin-top: 18px;
}

.big-speak {
  width: 88px;
  height: 88px;
  border-radius: 50%;
  border: none;
  background: var(--branch);
  color: #fff;
  font-size: 2.2rem;
  box-shadow: var(--shadow);
}

.big-speak:active {
  transform: scale(0.95);
}

/* Flashcard */
.flashcard {
  perspective: 1000px;
  max-width: 440px;
  margin: 0 auto;
}

.flashcard-inner {
  position: relative;
  width: 100%;
  height: 240px;
  transition: transform 0.45s ease;
  transform-style: preserve-3d;
  border: none;
  background: none;
  padding: 0;
}

.flashcard.flipped .flashcard-inner {
  transform: rotateY(180deg);
}

.fc-face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  border-radius: 18px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 18px;
  box-shadow: var(--shadow);
  border: 2px solid var(--line);
  background: var(--surface);
}

.fc-front .fc-word {
  font-size: 2.2rem;
  font-weight: 800;
}

.fc-back {
  transform: rotateY(180deg);
  background: var(--branch);
  color: #fff;
  border-color: transparent;
}

.fc-back .fc-word {
  font-size: 1.8rem;
  font-weight: 700;
}

.fc-hint {
  font-size: 0.8rem;
  opacity: 0.75;
}

@media (prefers-reduced-motion: reduce) {
  .flashcard-inner {
    transition: none;
  }
}

/* Memory */
.memory-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
}

@media (max-width: 520px) {
  .memory-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

.mem-card {
  aspect-ratio: 4 / 3;
  border-radius: 12px;
  border: 2px solid var(--line);
  background: linear-gradient(135deg, var(--branch), #1f2333);
  color: transparent;
  font-weight: 700;
  font-size: 0.95rem;
  padding: 6px;
  word-break: break-word;
  transition: transform 0.15s ease, background 0.2s ease;
}

.mem-card .q {
  color: rgba(255, 255, 255, 0.6);
  font-size: 1.6rem;
}

.mem-card.open,
.mem-card.matched {
  background: var(--surface);
  color: var(--ink);
}

.mem-card.open {
  border-color: var(--branch);
}

.mem-card.matched {
  border-color: var(--success);
  background: var(--success-soft);
  cursor: default;
}

.mem-card.miss {
  border-color: var(--danger);
  animation: shake 0.35s;
}

.mem-card .lang {
  display: block;
  font-size: 0.7rem;
  color: var(--muted);
  font-weight: 500;
}

@keyframes shake {
  25% {
    transform: translateX(-4px);
  }
  75% {
    transform: translateX(4px);
  }
}

/* Spelling */
.spell-form {
  display: flex;
  gap: 8px;
  max-width: 460px;
  margin: 0 auto;
}

.spell-input {
  flex: 1;
  padding: 12px 14px;
  font-size: 1.2rem;
  border-radius: 12px;
  border: 2px solid var(--line);
  min-width: 0;
}

.spell-input:focus {
  border-color: var(--branch);
  outline: none;
}

.mask {
  font-family: "Cascadia Code", Consolas, monospace;
  letter-spacing: 0.08em;
  font-size: 1.3rem;
  text-align: center;
  color: var(--branch);
  margin: 6px 0 14px;
}

/* Scramble */
.scramble-answer,
.scramble-bank {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  min-height: 60px;
  padding: 10px;
  border-radius: 12px;
  justify-content: center;
  align-items: center;
}

.scramble-answer {
  border: 2px dashed var(--line);
  background: #f8fafc;
  margin-bottom: 14px;
}

.scramble-answer.correct {
  border-color: var(--success);
  background: var(--success-soft);
}

.scramble-answer.wrong {
  border-color: var(--danger);
  background: var(--danger-soft);
}

.chip {
  border: 2px solid var(--line);
  background: var(--surface);
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 1.05rem;
  font-weight: 600;
}

.chip:hover:not(:disabled) {
  border-color: var(--branch);
}

.chip.used {
  visibility: hidden;
}

.placeholder {
  color: var(--muted);
  font-size: 0.9rem;
}

/* Speed */
.timer {
  height: 10px;
  background: #e2e8f0;
  border-radius: 999px;
  overflow: hidden;
  margin-bottom: 18px;
}

.timer-fill {
  height: 100%;
  background: var(--branch);
  width: 100%;
  transition: width 0.25s linear;
}

.timer-fill.low {
  background: var(--danger);
}

.tf-card {
  text-align: center;
  padding: 24px 12px;
  border-radius: 16px;
  border: 2px solid var(--line);
  margin-bottom: 18px;
}

.tf-card.flash-good {
  border-color: var(--success);
  background: var(--success-soft);
}

.tf-card.flash-bad {
  border-color: var(--danger);
  background: var(--danger-soft);
}

.tf-card .tf-en {
  font-size: 2rem;
  font-weight: 800;
}

.tf-card .tf-eq {
  color: var(--muted);
  margin: 4px 0;
}

.tf-card .tf-vi {
  font-size: 1.4rem;
  font-weight: 600;
}

.tf-buttons {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.tf-btn {
  padding: 18px;
  border-radius: var(--radius-sm);
  border: none;
  font-size: 1.2rem;
  font-weight: 800;
  color: #fff;
  box-shadow: var(--shadow-sm);
}

.tf-btn.yes {
  background: var(--success);
}

.tf-btn.no {
  background: var(--danger);
}

.tf-btn:active {
  transform: scale(0.97);
}

/* Result */
.result {
  text-align: center;
}

.stars {
  font-size: 3rem;
  letter-spacing: 6px;
}

.stars .on {
  color: #f59e0b;
}

.stars .off {
  color: #e2e8f0;
}

.result h2 {
  margin: 4px 0 14px;
}

.result-stats {
  display: flex;
  justify-content: center;
  gap: 12px;
  flex-wrap: wrap;
}

.result-stats div {
  background: var(--bg);
  border-radius: 12px;
  padding: 10px 18px;
  min-width: 96px;
  display: flex;
  flex-direction: column;
}

.result-stats strong {
  font-size: 1.5rem;
}

.result-stats span {
  color: var(--muted);
  font-size: 0.85rem;
}

.record {
  font-weight: 700;
  color: var(--warn);
}

.review {
  text-align: left;
  margin: 20px auto 0;
  max-width: 520px;
}

.result-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
  margin-top: 22px;
}

.start-screen {
  text-align: center;
  padding: 20px 0;
}

.start-screen p {
  max-width: 460px;
  margin: 0 auto 16px;
}

.toggle-row {
  display: flex;
  gap: 8px;
  justify-content: center;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.toggle-row button[aria-pressed="true"] {
  border-color: var(--branch);
  background: var(--primary-soft);
}


/* ═════════════════ Tab Toán 12 ═════════════════ */

/* Danh sách thẻ công thức ở panel */
.math-card-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.math-card-list li {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-left: 4px solid var(--branch);
  border-radius: 10px;
  background: var(--surface);
}

.math-card-list .mc-q {
  font-weight: 600;
  font-size: 0.95rem;
}

.math-card-list .mc-a code {
  font-family: "Cascadia Code", Consolas, monospace;
  background: #f1f5f9;
  padding: 3px 8px;
  border-radius: 6px;
  font-size: 0.9rem;
  display: inline-block;
  word-break: break-word;
}

/* Trắc nghiệm Toán: đáp án dài → cho phép xuống dòng, 1 cột trên mobile */
.math-options {
  grid-template-columns: 1fr;
}

@media (min-width: 620px) {
  .math-options {
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  }
}

.math-option {
  align-items: flex-start;
  font-size: 1rem;
  line-height: 1.4;
}

.math-option span {
  word-break: break-word;
}

.game-prompt .math-q {
  font-size: clamp(1.1rem, 3.8vw, 1.5rem);
  font-weight: 700;
  line-height: 1.4;
}

.feedback .explain {
  display: block;
  margin-top: 6px;
  font-weight: 400;
  font-size: 0.9rem;
  color: var(--muted);
}

/* Phần ôn lại (câu/thẻ sai) ở màn hình kết quả */
.math-review-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  text-align: left;
}

.math-review-list li {
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
}

.math-review-list .mr-front {
  margin: 0 0 6px;
  font-weight: 600;
  font-size: 0.95rem;
}

.math-review-list .mr-back {
  margin: 0;
}

.math-review-list .mr-back code {
  font-family: "Cascadia Code", Consolas, monospace;
  background: #f1f5f9;
  padding: 3px 8px;
  border-radius: 6px;
  font-size: 0.9rem;
  display: inline-block;
  word-break: break-word;
}

/* ─────── Game lật thẻ công thức ─────── */
.flashcard-game {
  display: flex;
  flex-direction: column;
  gap: 18px;
  max-width: 480px;
  margin: 0 auto;
}

.flip-card {
  perspective: 1200px;
  position: relative;
  width: 100%;
  min-height: 220px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.flip-card .flip-face {
  position: relative;
  width: 100%;
  min-height: 220px;
  backface-visibility: hidden;
  border-radius: 18px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 22px;
  box-shadow: var(--shadow);
  border: 2px solid var(--line);
  background: var(--surface);
  transition: transform 0.45s ease;
  transform-style: preserve-3d;
}

.flip-card .flip-back {
  position: absolute;
  inset: 0;
  transform: rotateY(180deg);
  background: var(--branch, var(--primary));
  color: #fff;
  border-color: transparent;
}

.flip-card.is-flipped .flip-front {
  transform: rotateY(180deg);
}

.flip-card.is-flipped .flip-back {
  transform: rotateY(360deg);
}

.flip-tag {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  opacity: 0.7;
}

.flip-text {
  margin: 0;
  text-align: center;
  font-size: clamp(1.1rem, 4.5vw, 1.5rem);
  font-weight: 700;
  line-height: 1.4;
  word-break: break-word;
}

.flip-back .flip-text code {
  font-family: "Cascadia Code", Consolas, monospace;
  color: #fff;
  background: rgba(255, 255, 255, 0.18);
  padding: 4px 10px;
  border-radius: 8px;
  display: inline-block;
}

.flip-hint {
  font-size: 0.8rem;
  opacity: 0.7;
}

.flip-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.flip-card:focus-visible {
  outline: 3px solid var(--branch, var(--primary));
  outline-offset: 3px;
  border-radius: 18px;
}

@media (prefers-reduced-motion: reduce) {
  .flip-card .flip-face {
    transition: none;
  }
}


/* ═════════════════ Tab Bài tập Tiếng Anh ═════════════════ */
.exam-list-page,
.exam-unit-page {
  max-width: 900px;
  margin: 0 auto;
}

/* Danh sách unit */
.exam-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 14px;
  margin-top: 16px;
}

.exam-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.exam-card-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.exam-no {
  font-weight: 800;
  color: var(--brand, var(--primary));
  font-size: 0.85rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.exam-title {
  font-size: 1.1rem;
  margin: 2px 0;
}

.exam-meta {
  display: flex;
  gap: 6px;
  margin: 4px 0 10px;
}

.exam-modes {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: auto;
}

.exam-modes .btn {
  flex: 1 1 auto;
  text-align: center;
}

/* Header unit + chuyển chế độ */
.exam-head {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 16px;
}

.exam-mode-switch {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

/* Grammar note */
.exam-grammar {
  margin-bottom: 20px;
}

.grammar-note {
  margin: 12px 0;
}

.grammar-note h3 {
  margin: 0 0 6px;
  font-size: 1rem;
}

.grammar-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.grammar-table th,
.grammar-table td {
  border: 1px solid var(--line);
  padding: 7px 9px;
  text-align: left;
  vertical-align: top;
}

.grammar-table th {
  width: 32%;
  background: #f1f5f9;
  font-weight: 600;
}

/* Exercise chung */
.exam-ex {
  border-top: 2px solid var(--line);
  padding-top: 16px;
  margin-top: 20px;
}

.exam-ex h2 {
  font-size: 1.15rem;
  margin: 0 0 4px;
}

.ex-instruction {
  color: var(--muted);
  font-style: italic;
  margin: 0 0 12px;
  font-size: 0.9rem;
}

.ex-badge {
  display: inline-block;
  background: var(--primary-soft);
  color: #3730a3;
  font-weight: 700;
  font-size: 0.85rem;
  padding: 3px 10px;
  border-radius: 999px;
  margin-bottom: 10px;
}

/* MCQ (chế độ đọc) */
.mcq-list {
  margin: 0;
  padding-left: 22px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.mcq-q {
  margin: 0 0 6px;
  font-weight: 600;
}

.mcq-opts {
  display: grid;
  grid-template-columns: 1fr;
  gap: 4px;
}

@media (min-width: 620px) {
  .mcq-opts {
    grid-template-columns: 1fr 1fr;
  }
}

.mcq-opt {
  padding: 4px 8px;
  border-radius: 6px;
  font-size: 0.95rem;
}

.mcq-opt.is-answer {
  background: var(--success-soft);
  border: 1px solid var(--success);
  font-weight: 600;
}

.mcq-explain {
  margin: 6px 0 0;
  font-size: 0.85rem;
  color: var(--muted);
}

/* Reorder (đọc) */
.reorder-item {
  margin: 0 0 16px;
}

.reorder-prompt {
  font-weight: 700;
  margin: 0 0 6px;
}

.reorder-src {
  margin: 0 0 6px;
  padding-left: 20px;
}

.reorder-src li {
  margin: 3px 0;
}

.reorder-answer {
  margin: 0;
  color: #15803d;
}

/* Cloze */
.cloze-intro {
  font-weight: 700;
  text-align: center;
  margin: 0 0 10px;
}

.cloze-passage {
  line-height: 1.9;
  background: #f8fafc;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 14px;
  margin: 0 0 14px;
}

.cloze-mark {
  color: var(--primary);
}

/* ─────── Chế độ làm bài ─────── */
.exam-result-bar {
  position: sticky;
  top: calc(var(--topbar-h) + 6px);
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  justify-content: center;
  background: var(--surface);
  border: 2px solid var(--success);
  border-radius: var(--radius);
  padding: 12px 16px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}

.exam-score strong {
  font-size: 1.8rem;
  color: var(--success);
}

.exam-count {
  color: var(--muted);
}

.do-list {
  margin: 0;
  padding-left: 22px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.do-opts {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  margin-top: 8px;
}

@media (min-width: 620px) {
  .do-opts {
    grid-template-columns: 1fr 1fr;
  }
}

.do-opt {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  text-align: left;
  padding: 11px 13px;
  border: 2px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  font-size: 1rem;
  line-height: 1.4;
}

.do-opt kbd {
  flex: none;
  display: inline-grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border-radius: 6px;
  background: var(--bg);
  font-family: inherit;
  color: var(--muted);
  font-size: 0.8rem;
}

.do-opt.picked {
  border-color: var(--brand, var(--primary));
  background: var(--primary-soft);
}

.do-opt.correct {
  border-color: var(--success);
  background: var(--success-soft);
}

.do-opt.wrong {
  border-color: var(--danger);
  background: var(--danger-soft);
}

.do-opt:disabled {
  cursor: default;
}

/* Reorder (làm bài) */
.reorder-chips {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 8px 0;
}

.chip {
  text-align: left;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  font-size: 0.92rem;
  line-height: 1.4;
}

.chip.used {
  opacity: 0.45;
}

.reorder-chosen {
  margin: 8px 0;
  min-height: 24px;
}

.exam-actions {
  margin: 24px 0 40px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* Mini game exam dùng lại .game-* có sẵn */
.exam-game-q {
  font-size: clamp(1rem, 3.6vw, 1.35rem) !important;
  line-height: 1.45;
}


/* ═════════════════ Bộ đề Toán 12 ═════════════════ */
.mexam-list-page,
.mexam-do-page {
  max-width: 820px;
  margin: 0 auto;
}

.mexam-grid {
  display: grid;
  gap: 14px;
  margin-top: 16px;
}

.mexam-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
  padding: 16px;
}

.mexam-title {
  margin: 0 0 2px;
  font-size: 1.2rem;
}

.mexam-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 10px 0 14px;
}

/* Header + đồng hồ */
.mexam-head {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.mexam-head h1 {
  font-size: 1.3rem;
  margin: 0;
}

.mexam-clock-wrap {
  margin-left: auto;
  font-weight: 700;
  font-size: 1.1rem;
}

.mexam-clock {
  font-variant-numeric: tabular-nums;
  background: var(--primary-soft);
  color: #3730a3;
  padding: 4px 10px;
  border-radius: 8px;
}

.mexam-clock.warn {
  background: var(--danger-soft);
  color: #b91c1c;
  animation: pulse 1s infinite;
}

@keyframes pulse {
  50% { opacity: 0.55; }
}

/* Thanh kết quả dính trên */
.mexam-result-bar {
  position: sticky;
  top: calc(var(--topbar-h) + 6px);
  z-index: 5;
  background: var(--surface);
  border: 2px solid var(--success);
  border-radius: var(--radius);
  padding: 12px 16px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
  text-align: center;
}

.mexam-score strong {
  font-size: 2rem;
  color: var(--success);
}

.mexam-breakdown {
  color: var(--muted);
  margin-top: 2px;
}

/* Phần & câu hỏi */
.mexam-part {
  margin: 22px 0;
}

.mexam-part > h2 {
  font-size: 1.05rem;
  border-left: 4px solid var(--branch, var(--primary));
  padding-left: 10px;
  margin: 0 0 14px;
}

.mexam-q {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
  margin-bottom: 14px;
  background: var(--surface);
}

.mexam-qno {
  font-weight: 700;
  color: var(--branch, var(--primary));
  margin-bottom: 6px;
}

.mexam-imgs {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.mexam-img {
  width: 100%;
  height: auto;
  max-width: 760px;
  border-radius: 6px;
}

/* Lựa chọn A/B/C/D */
.mexam-opts.abcd {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-top: 10px;
}

.mexam-opt {
  padding: 10px 0;
  border: 2px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  font-weight: 700;
  font-size: 1.05rem;
}

.mexam-opt.picked {
  border-color: var(--branch, var(--primary));
  background: var(--primary-soft);
}

.mexam-opt.correct {
  border-color: var(--success);
  background: var(--success-soft);
}

.mexam-opt.wrong {
  border-color: var(--danger);
  background: var(--danger-soft);
}

/* Đúng/Sai */
.mexam-ds {
  margin-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.mexam-ds-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.ds-lab {
  font-weight: 700;
  min-width: 24px;
}

.ds-choices {
  display: flex;
  gap: 6px;
}

.ds-btn {
  padding: 7px 16px;
  border: 2px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  font-weight: 600;
  font-size: 0.9rem;
}

.ds-btn.d-true {
  color: var(--success);
}

.ds-btn.d-false {
  color: var(--danger);
}

.ds-btn.picked {
  border-color: var(--branch, var(--primary));
  background: var(--primary-soft);
}

.ds-btn.d-true.picked {
  border-color: var(--success);
  background: var(--success-soft);
}

.ds-btn.d-false.picked {
  border-color: var(--danger);
  background: var(--danger-soft);
}

.ds-btn.correct {
  border-color: var(--success);
  background: var(--success-soft);
}

.ds-btn.wrong {
  border-color: var(--danger);
  background: var(--danger-soft);
}

/* Trả lời ngắn */
.mexam-short {
  margin-top: 10px;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.mexam-input {
  padding: 9px 12px;
  border: 2px solid var(--line);
  border-radius: 8px;
  font-size: 1rem;
  min-width: 160px;
}

.mexam-input:focus {
  outline: none;
  border-color: var(--branch, var(--primary));
}

/* Phản hồi đúng/sai */
.mexam-fb {
  margin: 10px 0 0;
  font-weight: 600;
}

.mexam-fb.good {
  color: var(--success, var(--success));
}

.mexam-fb.bad {
  color: var(--danger, var(--danger));
}

.mexam-actions {
  margin: 20px 0 12px;
}

@media (max-width: 520px) {
  .mexam-opts.abcd {
    grid-template-columns: repeat(2, 1fr);
  }
}
