:root {
  --bg: #FDFBF7;
  --surface: #FFFFFF;
  --surface-2: #F4EFE6;
  --border: #E5DEC9;
  --text: #1E293B;
  --muted: #64748B;
  --primary: #D9383A;
  --primary-dark: #B91C1C;
  --primary-soft: #FEE2E2;
  --cobalt: #1D4ED8;
  --cobalt-soft: #DBEAFE;
  --teal: #0D9488;
  --teal-soft: #CCFBF1;
  --amber: #F59E0B;
  --amber-soft: #FEF3C7;
  --ok: #16A34A;
  --ok-soft: #DCFCE7;
  --err: #DC2626;
  --err-soft: #FEE2E2;
  --shadow: 0 8px 24px rgba(15, 23, 42, 0.06);
  --radius: 18px;
}

body.dark {
  --bg: #0F172A;
  --surface: #1E293B;
  --surface-2: #283548;
  --border: #334155;
  --text: #F1F5F9;
  --muted: #94A3B8;
  --primary: #F87171;
  --primary-dark: #EF4444;
  --primary-soft: rgba(239, 68, 68, 0.16);
  --cobalt: #60A5FA;
  --cobalt-soft: rgba(59, 130, 246, 0.16);
  --teal: #2DD4BF;
  --teal-soft: rgba(20, 184, 166, 0.16);
  --amber: #FBBF24;
  --amber-soft: rgba(245, 158, 11, 0.16);
  --ok: #4ADE80;
  --ok-soft: rgba(34, 197, 94, 0.16);
  --err: #FB7185;
  --err-soft: rgba(244, 63, 94, 0.16);
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'Be Vietnam Pro', 'Nunito', system-ui, -apple-system, sans-serif;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea { font-family: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.text-primary { color: var(--primary); }
.small-note { font-size: 0.86rem; }

/* Kids mode larger friendly typography */
body.kids-mode .main-stage { font-size: 1.05rem; }
body.kids-mode .lesson-node { border-radius: 24px; }

/* Shell Layout */
.app-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 10px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.topbar-left, .topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.brand-link {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
  color: var(--text);
  font-weight: 800;
  font-size: 1.12rem;
}

.brand-bear { font-size: 1.45rem; }

.profile-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 5px 12px;
  color: var(--text);
  font-weight: 700;
  font-size: 0.9rem;
}

.stat-chip {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 11px;
  font-size: 0.88rem;
  font-weight: 700;
}

.tool-btn {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 10px;
  padding: 6px 10px;
  font-size: 0.84rem;
  font-weight: 700;
}
.tool-btn.active {
  background: var(--cobalt-soft);
  border-color: var(--cobalt);
  color: var(--cobalt);
}

/* Body 3-column grid */
.app-body {
  display: grid;
  grid-template-columns: 230px minmax(0, 1fr) 295px;
  gap: 20px;
  max-width: 1460px;
  width: 100%;
  margin: 0 auto;
  padding: 18px;
  flex: 1;
}

.sidebar {
  position: sticky;
  top: 76px;
  align-self: start;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.nav-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px;
  box-shadow: var(--shadow);
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 14px;
  border-radius: 12px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text);
  font-weight: 700;
  font-size: 0.94rem;
  text-align: left;
  transition: all 0.15s ease;
}
.nav-item:hover { background: var(--surface-2); }
.nav-item.active {
  background: var(--primary-soft);
  color: var(--primary);
  border-color: rgba(217, 56, 58, 0.25);
}

.sidebar-quick-box {
  background: var(--amber-soft);
  border: 1px solid rgba(245, 158, 11, 0.3);
  border-radius: var(--radius);
  padding: 14px;
  font-size: 0.86rem;
}
.sq-title { font-weight: 800; margin-bottom: 4px; }
.sq-text { margin: 0; }

.main-stage { min-width: 0; }

.companion-panel {
  position: sticky;
  top: 76px;
  align-self: start;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* Common Cards & Buttons */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 18px;
  border-radius: 12px;
  border: 1px solid transparent;
  font-weight: 700;
  font-size: 0.94rem;
  transition: transform 0.1s ease, filter 0.15s ease;
}
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-sm { padding: 6px 12px; font-size: 0.84rem; border-radius: 10px; }
.btn-lg { padding: 14px 24px; font-size: 1.05rem; border-radius: 14px; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-cobalt { background: var(--cobalt); color: #fff; }
.btn-teal { background: var(--teal); color: #fff; }
.btn-danger { background: #E11D48; color: #fff; }
.btn-outline { background: transparent; border-color: var(--border); color: var(--text); }
.btn-outline:hover { background: var(--surface-2); }
.btn-soft { background: var(--surface-2); color: var(--text); border-color: var(--border); }
.btn-soft:hover { filter: brightness(0.96); }
.btn-icon {
  width: 38px; height: 38px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  display: inline-flex; align-items: center; justify-content: center; font-size: 1rem;
}

.input, .select {
  width: 100%;
  padding: 10px 14px;
  border-radius: 12px;
  border: 1.5px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 0.95rem;
}
.input:focus, .select:focus { outline: none; border-color: var(--cobalt); }

.pill-row, .games-nav-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
}
.pill-btn {
  padding: 8px 15px;
  border-radius: 999px;
  border: 1.5px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-weight: 700;
  font-size: 0.88rem;
}
.pill-btn.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

/* Hero / Track Switcher */
.track-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(175px, 1fr));
  gap: 10px;
  margin-bottom: 18px;
}
.track-card {
  text-align: left;
  padding: 12px 14px;
  border-radius: 14px;
  border: 2px solid var(--border);
  background: var(--surface);
  color: var(--text);
  transition: all 0.15s ease;
}
.track-card.active {
  border-color: var(--primary);
  background: var(--primary-soft);
}
.track-card-top { display: flex; justify-content: space-between; align-items: center; font-size: 1.25rem; }
.track-badge {
  font-size: 0.72rem;
  font-weight: 800;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text);
}
.track-name { font-weight: 800; margin-top: 6px; font-size: 0.94rem; }
.track-desc { font-size: 0.78rem; color: var(--muted); margin-top: 2px; }

/* Unit & Lesson Path */
.unit-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 18px;
  margin-bottom: 18px;
  box-shadow: var(--shadow);
}
.unit-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding-bottom: 12px;
  border-bottom: 1px dashed var(--border);
  margin-bottom: 14px;
}
.unit-title-wrap { display: flex; align-items: center; gap: 12px; }
.unit-icon {
  width: 48px; height: 48px; border-radius: 14px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.65rem; color: #fff; flex-shrink: 0;
}
.lesson-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 12px;
}
.lesson-node {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  text-align: left;
  padding: 14px;
  border-radius: 16px;
  border: 2px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  transition: transform 0.12s ease, border-color 0.15s ease;
}
.lesson-node:hover { transform: translateY(-2px); border-color: var(--cobalt); }
.lesson-node.completed {
  background: var(--ok-soft);
  border-color: var(--ok);
}
.lesson-node-top { display: flex; justify-content: space-between; align-items: center; font-weight: 800; font-size: 0.95rem; margin-bottom: 4px; }
.lesson-node-sub { font-size: 0.82rem; color: var(--muted); }

/* Lesson Interactive View */
.lesson-word-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(235px, 1fr));
  gap: 12px;
}
.word-card {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.word-card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.word-ru-lg { font-size: 1.25rem; font-weight: 800; color: var(--cobalt); }
.word-phon { font-size: 0.82rem; color: var(--muted); font-family: monospace; }
.word-vi-lg { font-weight: 700; font-size: 0.96rem; }
.word-ex { font-size: 0.84rem; padding-top: 6px; border-top: 1px dashed var(--border); }
.word-btns { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 4px; }

.dialogue-box { display: flex; flex-direction: column; gap: 10px; }
.dlg-line {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-radius: 14px;
  background: var(--surface-2);
  border: 1px solid var(--border);
}
.dlg-speaker { font-weight: 800; font-size: 0.82rem; color: var(--primary); }
.dlg-ru { font-weight: 700; font-size: 1.04rem; }
.dlg-vi { font-size: 0.88rem; color: var(--muted); }

/* Alphabet 33 Letters Grid */
.alpha-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
  gap: 10px;
  margin-bottom: 18px;
}
.alpha-tile {
  padding: 12px 8px;
  border-radius: 14px;
  border: 2px solid var(--border);
  background: var(--surface);
  color: var(--text);
  text-align: center;
  transition: all 0.15s ease;
}
.alpha-tile:hover { transform: translateY(-2px); border-color: var(--primary); }
.alpha-tile.active { border-color: var(--primary); background: var(--primary-soft); }
.alpha-tile.vowel { border-bottom: 4px solid #EF4444; }
.alpha-tile.consonant { border-bottom: 4px solid #2563EB; }
.alpha-tile.sign { border-bottom: 4px solid #94A3B8; }
.alpha-chars { font-size: 1.45rem; font-weight: 900; }
.alpha-cursive { font-family: 'Lora', Georgia, serif; font-style: italic; font-size: 1rem; color: var(--muted); }
.alpha-name { font-size: 0.78rem; font-weight: 700; margin-top: 2px; }

.alpha-detail-card {
  display: grid;
  grid-template-columns: 220px 1fr;
  gap: 18px;
  align-items: start;
}
.alpha-hero-box {
  background: var(--surface-2);
  border-radius: 16px;
  padding: 18px;
  text-align: center;
}
.alpha-hero-print { font-size: 3.2rem; font-weight: 900; color: var(--primary); line-height: 1.1; }
.alpha-hero-italic { font-family: 'Lora', Georgia, serif; font-style: italic; font-size: 2.4rem; color: var(--cobalt); margin-top: 4px; }

/* Canvas Video Player & YouTube Theater */
.cv-player-shell { display: flex; flex-direction: column; gap: 12px; }
.cv-canvas-wrap {
  position: relative;
  border-radius: 18px;
  overflow: hidden;
  border: 2px solid var(--border);
  background: #FCF7EC;
  aspect-ratio: 16 / 9;
}
.cv-canvas { width: 100%; height: 100%; display: block; }
.cv-center-play {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  padding: 14px 26px;
  border-radius: 999px;
  border: none;
  background: rgba(217, 56, 58, 0.94);
  color: #fff;
  font-size: 1.05rem;
  font-weight: 800;
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.3);
}
.cv-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.cv-progress-dots { display: flex; gap: 6px; flex-wrap: wrap; flex: 1; }
.cv-dot {
  padding: 5px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 0.78rem;
  font-weight: 700;
}
.cv-dot.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.cv-speed-group { display: flex; gap: 4px; }
.cv-speed {
  padding: 5px 8px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface-2); color: var(--text); font-size: 0.78rem; font-weight: 700;
}
.cv-speed.active { background: var(--cobalt); color: #fff; border-color: var(--cobalt); }
.cv-subtitle-box {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 12px 16px;
}
.cv-sub-hint { font-size: 0.8rem; color: var(--muted); margin-bottom: 6px; }
.cv-sub-ru { font-size: 1.15rem; font-weight: 800; line-height: 1.8; }
.cv-sub-vi { font-size: 0.94rem; color: var(--muted); margin-top: 4px; }

.ru-word-chip {
  display: inline-block;
  padding: 1px 6px;
  margin: 1px;
  border-radius: 8px;
  border: 1px solid transparent;
  background: rgba(29, 78, 216, 0.08);
  color: var(--text);
  font-weight: 800;
  font-size: inherit;
}
.ru-word-chip:hover {
  background: var(--cobalt);
  color: #fff;
}

.yt-theater-grid {
  display: grid;
  grid-template-columns: 1.35fr 1fr;
  gap: 16px;
}
.yt-frame-wrap {
  aspect-ratio: 16 / 9;
  border-radius: 16px;
  overflow: hidden;
  border: 1px solid var(--border);
  background: #0F172A;
}
.yt-frame-wrap iframe { width: 100%; height: 100%; border: 0; }
.yt-sub-list {
  max-height: 390px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.yt-sub-row {
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface-2);
}
.yt-sub-row.active-line { border-color: var(--primary); background: var(--primary-soft); }

.yt-playlist-section {
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1.5px solid var(--border);
}
.yt-playlist-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}
.yt-search-inp {
  flex: 1 1 240px;
  max-width: 340px;
}
.yt-playlist-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(215px, 1fr));
  gap: 10px;
  max-height: 460px;
  overflow-y: auto;
  padding: 2px 4px 4px 2px;
}
.yt-card {
  display: flex;
  flex-direction: column;
  text-align: left;
  padding: 0;
  border: 1.5px solid var(--border);
  border-radius: 14px;
  overflow: hidden;
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
  transition: transform 0.14s ease, border-color 0.14s ease, background 0.14s ease;
}
.yt-card:hover {
  transform: translateY(-2px);
  border-color: var(--primary);
}
.yt-card.active {
  border: 2px solid var(--primary);
  background: var(--primary-soft);
}
.yt-thumb-box {
  position: relative;
  aspect-ratio: 16 / 9;
  width: 100%;
  background: #0F172A;
  overflow: hidden;
}
.yt-thumb-box img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.yt-thumb-dur {
  position: absolute;
  right: 6px;
  bottom: 6px;
  background: rgba(15, 23, 42, 0.85);
  color: #fff;
  font-size: 0.72rem;
  font-weight: 800;
  padding: 2px 6px;
  border-radius: 6px;
}
.yt-thumb-playing {
  position: absolute;
  left: 6px;
  top: 6px;
  background: var(--primary);
  color: #fff;
  font-size: 0.72rem;
  font-weight: 800;
  padding: 2px 8px;
  border-radius: 999px;
}
.yt-card-body {
  padding: 9px 10px 11px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.yt-card-meta {
  font-size: 0.74rem;
  font-weight: 700;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.yt-card-title {
  font-size: 0.84rem;
  font-weight: 800;
  line-height: 1.32;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.mp4-video-wrap {
  aspect-ratio: 16 / 9;
  border-radius: 16px;
  overflow: hidden;
  border: 2px solid var(--border);
  background: #0F172A;
}
.mp4-player {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
  background: #0F172A;
}
.mp4-controls-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 10px;
}
.mp4-speed-group { display: flex; gap: 5px; align-items: center; }

/* Dictionary */
.dict-search-bar {
  display: grid;
  grid-template-columns: 1fr 165px 125px auto;
  gap: 10px;
  margin-bottom: 12px;
}
.dict-results {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(290px, 1fr));
  gap: 12px;
}
.dict-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 15px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  box-shadow: var(--shadow);
}
.dict-badge {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 800;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--cobalt-soft);
  color: var(--cobalt);
}
.dict-match-note {
  font-size: 0.78rem;
  background: var(--amber-soft);
  padding: 4px 8px;
  border-radius: 8px;
  font-weight: 700;
}

/* Virtual Keyboard */
.vk-keyboard {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 10px;
  margin-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.vk-row { display: flex; justify-content: center; gap: 5px; flex-wrap: wrap; }
.vk-key {
  min-width: 34px; height: 38px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-weight: 800;
  font-size: 0.96rem;
}
.vk-key:hover { background: var(--cobalt-soft); }
.vk-key.vk-glow {
  background: var(--amber);
  color: #1E293B;
  border-color: #D97706;
  transform: scale(1.08);
  box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.35);
}

/* Grammar Tables */
.grammar-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
}
.grammar-table th, .grammar-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  text-align: left;
}
.grammar-table th { background: var(--surface-2); font-weight: 800; }
.end-hl { color: var(--primary); font-weight: 900; text-decoration: underline; }

/* Flashcards 3D & Games */
.flashcard-stage { max-width: 560px; margin: 0 auto; }
.flashcard-meta { display: flex; justify-content: space-between; font-size: 0.85rem; color: var(--muted); margin-bottom: 10px; flex-wrap: wrap; gap: 6px; }
.flashcard-3d {
  position: relative;
  min-height: 290px;
  cursor: pointer;
  perspective: 1000px;
  margin-bottom: 14px;
}
.fc-face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: 22px;
  padding: 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 8px;
  box-shadow: var(--shadow);
  transition: transform 0.5s ease;
}
.fc-back { transform: rotateY(180deg); background: var(--surface-2); }
.flashcard-3d.flipped .fc-front { transform: rotateY(180deg); }
.flashcard-3d.flipped .fc-back { transform: rotateY(0deg); }
.fc-emoji { font-size: 2.6rem; }
.fc-ru { font-size: 2rem; font-weight: 900; color: var(--cobalt); }
.fc-vi { font-size: 1.45rem; font-weight: 800; color: var(--primary); }
.fc-ex-ru { font-weight: 700; font-size: 1rem; margin-top: 6px; }
.fc-tap-hint { font-size: 0.78rem; color: var(--muted); margin-top: 8px; }

.srs-grade-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.srs-grade {
  padding: 10px 6px; border-radius: 12px; border: 1.5px solid var(--border);
  background: var(--surface); color: var(--text); font-weight: 800;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
}
.srs-grade small { font-weight: 500; color: var(--muted); font-size: 0.75rem; }
.srs-grade.g1:hover { border-color: var(--err); background: var(--err-soft); }
.srs-grade.g2:hover { border-color: var(--amber); background: var(--amber-soft); }
.srs-grade.g3:hover { border-color: var(--cobalt); background: var(--cobalt-soft); }
.srs-grade.g4:hover { border-color: var(--ok); background: var(--ok-soft); }
.srs-custom-add { display: grid; grid-template-columns: 1fr 1fr auto; gap: 10px; }

.match-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.match-col { display: flex; flex-direction: column; gap: 10px; }
.match-tile {
  padding: 14px; border-radius: 14px; border: 2px solid var(--border);
  background: var(--surface-2); color: var(--text); font-weight: 800;
  display: flex; justify-content: space-between; align-items: center;
}
.match-tile.selected { border-color: var(--cobalt); background: var(--cobalt-soft); }
.match-tile.done { border-color: var(--ok); background: var(--ok-soft); opacity: 0.6; }

.ac-audio-panel { display: flex; justify-content: center; gap: 12px; margin: 16px 0; }
.ac-options { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.ac-opt-card {
  padding: 16px; border-radius: 16px; border: 2px solid var(--border);
  background: var(--surface-2); color: var(--text); text-align: center;
}
.ac-opt-card.correct { border-color: var(--ok); background: var(--ok-soft); }
.ac-opt-card.wrong { border-color: var(--err); background: var(--err-soft); }
.ac-emoji { font-size: 2rem; }
.ac-vi { font-weight: 800; margin-top: 4px; }
.ac-ru { font-size: 0.9rem; color: var(--cobalt); font-weight: 700; }

.sb-answer-zone {
  min-height: 64px; padding: 12px; border-radius: 14px;
  border: 2px dashed var(--border); background: var(--surface-2);
  display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 14px 0;
}
.sb-bank { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.word-tile {
  padding: 8px 14px; border-radius: 12px; border: 1.5px solid var(--border);
  background: var(--surface); color: var(--text); font-weight: 800; font-size: 1rem;
}
.word-tile.chosen { background: var(--cobalt-soft); border-color: var(--cobalt); }
.sb-actions { display: flex; gap: 10px; }

/* Handwriting Canvas */
.hw-layout { display: grid; grid-template-columns: 280px 1fr; gap: 18px; }
.hw-letter-big { font-size: 3rem; font-weight: 900; color: var(--primary); }
.hw-letter-cursive { font-family: 'Lora', serif; font-style: italic; font-size: 2rem; color: var(--cobalt); }
.hw-picker { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 10px; }
.hw-chip {
  width: 30px; height: 30px; border-radius: 7px; border: 1px solid var(--border);
  background: var(--surface-2); color: var(--text); font-weight: 800; font-size: 0.82rem;
}
.hw-chip.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.hw-canvas {
  width: 100%; max-width: 440px; height: auto;
  background: #FFFDF8; border: 2px solid var(--border); border-radius: 16px;
  touch-action: none; display: block;
}
.hw-canvas-btns { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }

/* Speaking Lab */
.speak-prompt-card {
  background: var(--surface-2); border-radius: 16px; padding: 18px;
  text-align: center; margin: 12px 0;
}
.speak-ru { font-size: 1.5rem; font-weight: 900; color: var(--cobalt); }
.speak-vi { font-size: 0.96rem; color: var(--muted); margin: 6px 0 12px; }
.speak-listen-btns, .speak-mic-box { display: flex; justify-content: center; gap: 10px; flex-wrap: wrap; margin: 12px 0; }
.speak-result-box { background: var(--surface-2); border-radius: 14px; padding: 14px; text-align: center; margin-top: 10px; }
.speak-word-breakdown { display: flex; justify-content: center; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.sw-chip { padding: 4px 10px; border-radius: 999px; font-weight: 700; font-size: 0.85rem; }
.sw-chip.hit { background: var(--ok-soft); color: var(--ok); }
.sw-chip.miss { background: var(--amber-soft); color: #B45309; }

.type-target-box { text-align: center; padding: 14px; background: var(--surface-2); border-radius: 14px; }
.type-letters { font-size: 2.1rem; font-weight: 900; letter-spacing: 6px; margin: 8px 0; }
.type-letters .typed-ok { color: var(--ok); }
.type-letters .typed-cur { color: var(--primary); text-decoration: underline; }

/* 5 New Games & 4 New Exercise Styles */
.balloon-prompt-bar {
  display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 12px 16px; border-radius: 14px; background: var(--surface-2); margin-bottom: 12px;
}
.bl-canvas {
  width: 100%; max-width: 760px; height: auto; display: block; margin: 0 auto;
  border-radius: 16px; border: 2px solid var(--border); cursor: crosshair; touch-action: none;
}

.mem-grid {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-top: 12px;
}
.mem-card {
  min-height: 92px; padding: 10px; border-radius: 14px;
  border: 2px solid var(--border); background: var(--surface-2); color: var(--text);
  display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center;
  transition: transform 0.14s ease, border-color 0.15s ease;
}
.mem-card:hover:not(:disabled) { transform: translateY(-2px); border-color: var(--primary); }
.mem-card.open { background: var(--surface); border-color: var(--cobalt); }
.mem-card.matched { background: var(--ok-soft); border-color: var(--ok); }
.mem-card-back { font-size: 2rem; }
.mem-card-val { font-weight: 800; font-size: 0.96rem; }
.mem-card-sub { font-size: 0.74rem; color: var(--muted); }

.blitz-card {
  text-align: center; padding: 24px 16px; margin: 14px 0;
  border-radius: 18px; background: var(--surface-2); border: 1.5px solid var(--border);
}
.blitz-emoji { font-size: 2.4rem; }
.blitz-ru { font-size: 1.9rem; font-weight: 900; color: var(--cobalt); }
.blitz-eq { font-size: 1.2rem; font-weight: 900; margin: 4px 0; color: var(--muted); }
.blitz-vi { font-size: 1.3rem; font-weight: 800; color: var(--primary); }
.blitz-btns { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.hm-stage-bar {
  text-align: center; padding: 14px; border-radius: 14px; background: var(--surface-2); margin: 12px 0;
}
.hm-slots {
  display: flex; justify-content: center; flex-wrap: wrap; gap: 8px; margin: 16px 0;
}
.hm-slot {
  width: 42px; height: 48px; border-radius: 10px; border: 2px solid var(--border);
  background: var(--surface); display: inline-flex; align-items: center; justify-content: center;
  font-size: 1.45rem; font-weight: 900; color: var(--muted);
}
.hm-slot.revealed { border-color: var(--cobalt); color: var(--cobalt); background: var(--cobalt-soft); }
.hm-letters { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; }
.hm-btn.hm-hit { background: var(--ok-soft); border-color: var(--ok); color: var(--ok); }
.hm-btn.hm-miss { background: var(--err-soft); border-color: var(--err); color: var(--err); opacity: 0.55; }

.boss-arena {
  display: grid; grid-template-columns: 1fr auto 1fr; gap: 14px; align-items: center;
  padding: 16px; border-radius: 16px; background: var(--surface-2); margin-bottom: 12px;
}
.fighter-box { text-align: center; }
.fighter-icon { font-size: 2.5rem; }
.vs-badge { font-weight: 900; font-size: 1.25rem; color: var(--primary); }
.hp-bar {
  height: 12px; border-radius: 999px; background: var(--surface); border: 1px solid var(--border);
  overflow: hidden; margin: 6px 0 3px;
}
.hp-fill { height: 100%; transition: width 0.25s ease; }
.hp-fill.misha { background: var(--ok); }
.hp-fill.boss { background: var(--primary); }
.boss-log {
  padding: 10px 14px; border-radius: 12px; background: var(--amber-soft); font-weight: 700; font-size: 0.9rem;
}

.masked-word-box {
  text-align: center; padding: 18px; border-radius: 16px; background: var(--surface-2); margin: 10px 0;
}
.chat-bubble.incoming {
  padding: 14px 16px; border-radius: 18px 18px 18px 4px;
  background: var(--cobalt-soft); border: 1px solid rgba(29, 78, 216, 0.2);
}

/* Feedback & Companion */
.feedback-banner {
  margin-top: 12px; padding: 10px 14px; border-radius: 12px; font-weight: 700; display: none;
}
.feedback-banner.ok { display: block; background: var(--ok-soft); color: var(--ok); }
.feedback-banner.err { display: block; background: var(--err-soft); color: var(--err); }

.misha-card {
  text-align: center;
  background: linear-gradient(145deg, var(--surface) 0%, var(--amber-soft) 100%);
}
.misha-avatar { font-size: 4rem; line-height: 1.1; }
.goal-bar { height: 10px; border-radius: 999px; background: var(--surface-2); overflow: hidden; margin: 8px 0; border: 1px solid var(--border); }
.goal-bar-fill { height: 100%; background: var(--ok); transition: width 0.3s ease; }

/* Certificate */
.cert-box {
  background: linear-gradient(135deg, #FFFBEB 0%, #FEF3C7 100%);
  color: #1E293B;
  border: 6px double #D97706;
  border-radius: 20px;
  padding: 28px;
  text-align: center;
}

/* Modal & Toast */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(15, 23, 42, 0.55);
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
}
.modal-card {
  width: 100%; max-width: 520px; max-height: 90vh; overflow-y: auto;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: 20px;
  padding: 22px; box-shadow: 0 24px 60px rgba(0, 0, 0, 0.35);
}
.toast-box {
  position: fixed; bottom: 78px; left: 50%; transform: translateX(-50%);
  z-index: 120; pointer-events: none;
  display: flex; flex-direction: column; gap: 6px;
}
.toast-item {
  background: #0F172A; color: #fff; padding: 10px 18px;
  border-radius: 999px; font-weight: 700; font-size: 0.9rem;
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.25);
}
.opt-badge {
  display: inline-flex; align-items: center; justify-content: center;
  width: 26px; height: 26px; flex-shrink: 0; border-radius: 8px;
  background: var(--cobalt-soft); color: var(--cobalt);
  font-weight: 900; font-size: 0.82rem; margin-right: 8px;
}
.match-tile.done .opt-badge, .match-tile.selected .opt-badge {
  background: rgba(255, 255, 255, 0.22); color: inherit;
}

/* Bottom Mobile Nav */
.bottom-nav {
  display: none;
  position: sticky;
  bottom: 0;
  z-index: 50;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 6px 4px;
  justify-content: space-around;
}
.bnav-item {
  border: none; background: transparent; color: var(--muted);
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  font-size: 0.72rem; font-weight: 700; padding: 4px 8px;
}
.bnav-item.active { color: var(--primary); }

@keyframes shakeErr {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-5px); }
  75% { transform: translateX(5px); }
}
.shake-err { animation: shakeErr 0.28s ease; }

@keyframes pulseMic {
  0%, 100% { box-shadow: 0 0 0 0 rgba(225, 29, 72, 0.45); }
  50% { box-shadow: 0 0 0 12px rgba(225, 29, 72, 0); }
}
.pulse-mic { animation: pulseMic 1.2s infinite; }

/* Responsive Breakpoints */
.exam-sticky-bar {
  position: sticky;
  top: calc(var(--topbar-h, 62px) + 8px);
  z-index: 25;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
@media (max-width: 1180px) {
  .app-body { grid-template-columns: 205px minmax(0, 1fr); }
  .companion-panel {
    grid-column: 2;
    position: static;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 14px;
  }
}
@media (max-width: 860px) {
  .app-body { grid-template-columns: 1fr; padding: 12px 12px 24px; }
  .sidebar { display: none; }
  .companion-panel {
    grid-column: 1;
    grid-template-columns: 1fr;
  }
  .bottom-nav { display: flex; }
  .yt-theater-grid, .alpha-detail-card, .hw-layout, .dict-search-bar, .srs-custom-add {
    grid-template-columns: 1fr;
  }
  .srs-grade-row { grid-template-columns: repeat(2, 1fr); }
  .mem-grid { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 640px) {
  .yt-playlist-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    max-height: 420px;
  }
  .yt-search-inp { max-width: none; }
}

/* ==================== STORY LESSONS (9YO READING, INFERENCE & RETELLING) ==================== */
.story-showcase-card {
  border: 2px solid rgba(15, 118, 110, 0.25);
  background: linear-gradient(135deg, rgba(15, 118, 110, 0.06), rgba(37, 99, 235, 0.04));
}
.story-showcase-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 12px;
}
.story-feature-tile {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
  padding: 16px;
  border-radius: 16px;
  border: 2px solid var(--border);
  background: var(--surface);
  color: var(--ink);
  text-align: left;
  cursor: pointer;
  transition: transform 0.14s ease, border-color 0.14s ease, box-shadow 0.14s ease;
}
.story-feature-tile:hover {
  transform: translateY(-2px);
  border-color: var(--teal);
  box-shadow: var(--shadow-sm);
}
.story-feature-tile.completed {
  border-color: rgba(16, 185, 129, 0.55);
}
.story-feature-tile.in-progress {
  border-color: rgba(245, 158, 11, 0.65);
}
.story-feature-title {
  font-size: 1.08rem;
  font-weight: 900;
  color: var(--cobalt);
  line-height: 1.35;
}
.story-feature-goal {
  font-size: 0.86rem;
  color: var(--muted);
  line-height: 1.45;
}
.story-feature-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--ink);
  margin-top: auto;
  padding-top: 4px;
}
.story-step-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}
.story-audio-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}
.story-lines-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.story-line-card {
  padding: 12px 14px;
  border-radius: 14px;
  background: var(--surface-2);
  border: 2px solid transparent;
  transition: border-color 0.18s ease, background 0.18s ease;
}
.story-line-card.active-line {
  border-color: var(--primary);
  background: var(--amber-soft);
}
.story-line-card.clue-focus {
  border-color: var(--cobalt);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.14);
}
.story-line-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 6px;
}
.story-line-ru {
  font-size: 1.06rem;
  font-weight: 700;
  line-height: 1.65;
}
.story-line-vi {
  font-size: 0.88rem;
  color: var(--muted);
  margin-top: 6px;
  padding-top: 6px;
  border-top: 1px dashed var(--border);
}
.story-ru-def {
  font-size: 0.88rem;
  line-height: 1.5;
  padding: 8px 10px;
  border-radius: 10px;
  background: var(--surface-2);
  margin-top: 6px;
}
.story-clue-box {
  margin: 10px 0;
  padding: 12px 14px;
  border-radius: 12px;
  background: var(--amber-soft);
  border: 1px solid rgba(245, 158, 11, 0.45);
}
.match-tile.wrong-pick {
  border-color: var(--err);
  background: var(--err-soft);
}
.story-order-chosen {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 54px;
  padding: 12px;
  border-radius: 12px;
  background: var(--surface-2);
  border: 2px dashed var(--border);
  margin-bottom: 12px;
}
.story-order-slot {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--cobalt);
  background: var(--surface);
  color: var(--ink);
  font-weight: 700;
  cursor: pointer;
}
.story-order-pool {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.parent-rubric-box {
  margin-top: 12px;
  padding: 12px;
  border-radius: 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.parent-rubric-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  font-size: 0.86rem;
  font-weight: 700;
}
/* Seamless inline prose for clickable Russian words inside stories, clues & dialogues */
.story-line-ru .ru-word-chip,
.story-clue-box .ru-word-chip,
.story-ru-def .ru-word-chip,
.story-sample-details .ru-word-chip,
.dlg-ru .ru-word-chip,
.word-ex .ru-word-chip {
  display: inline;
  padding: 0 1px;
  margin: 0;
  border: 0;
  border-radius: 4px;
  background: transparent;
  font-weight: inherit;
  line-height: inherit;
  color: inherit;
  text-decoration: underline dotted rgba(37, 99, 235, 0.34);
  text-underline-offset: 3px;
  cursor: pointer;
}
.story-line-ru .ru-word-chip:hover,
.story-line-ru .ru-word-chip:focus-visible,
.story-clue-box .ru-word-chip:hover,
.story-clue-box .ru-word-chip:focus-visible,
.story-ru-def .ru-word-chip:hover,
.story-ru-def .ru-word-chip:focus-visible,
.story-sample-details .ru-word-chip:hover,
.story-sample-details .ru-word-chip:focus-visible,
.dlg-ru .ru-word-chip:hover,
.dlg-ru .ru-word-chip:focus-visible,
.word-ex .ru-word-chip:hover,
.word-ex .ru-word-chip:focus-visible {
  background: rgba(37, 99, 235, 0.14);
  color: var(--cobalt);
  text-decoration: none;
  outline: none;
}
.story-line-ru {
  font-size: 1.07rem;
  font-weight: 700;
  line-height: 1.72;
  word-spacing: 0.04em;
}
@media (max-width: 640px) {
  .story-showcase-grid { grid-template-columns: 1fr; }
  .story-line-ru { font-size: 1.02rem; line-height: 1.72; }
}
