/* ============================================================
   Self-hosted fonts (SIL OFL 1.1) — thay cho Google Fonts để chạy offline
   Fredoka & Nunito dạng variable, chia subset theo unicode-range
   ============================================================ */
@font-face {
  font-family: 'Fredoka';
  font-style: normal;
  font-display: swap;
  font-weight: 300 700;
  src: url(../fonts/fredoka-latin-wght-normal.woff2) format('woff2-variations'),
       url(../fonts/fredoka-latin-wght-normal.woff2) format('woff2');
  unicode-range: U+0000-00FF,U+0131,U+0152-0153,U+02BB-02BC,U+02C6,U+02DA,U+02DC,U+0304,U+0308,U+0329,U+2000-206F,U+20AC,U+2122,U+2191,U+2193,U+2212,U+2215,U+FEFF,U+FFFD;
}
@font-face {
  font-family: 'Fredoka';
  font-style: normal;
  font-display: swap;
  font-weight: 300 700;
  src: url(../fonts/fredoka-latin-ext-wght-normal.woff2) format('woff2-variations'),
       url(../fonts/fredoka-latin-ext-wght-normal.woff2) format('woff2');
  unicode-range: U+0100-02BA,U+02BD-02C5,U+02C7-02CC,U+02CE-02D7,U+02DD-02FF,U+0304,U+0308,U+0329,U+1D00-1DBF,U+1E00-1E9F,U+1EF2-1EFF,U+2020,U+20A0-20AB,U+20AD-20C0,U+2113,U+2C60-2C7F,U+A720-A7FF;
}
@font-face {
  font-family: 'Nunito';
  font-style: normal;
  font-display: swap;
  font-weight: 200 1000;
  src: url(../fonts/nunito-vietnamese-wght-normal.woff2) format('woff2-variations'),
       url(../fonts/nunito-vietnamese-wght-normal.woff2) format('woff2');
  unicode-range: U+0102-0103,U+0110-0111,U+0128-0129,U+0168-0169,U+01A0-01A1,U+01AF-01B0,U+0300-0301,U+0303-0304,U+0308-0309,U+0323,U+0329,U+1EA0-1EF9,U+20AB;
}
@font-face {
  font-family: 'Nunito';
  font-style: normal;
  font-display: swap;
  font-weight: 200 1000;
  src: url(../fonts/nunito-latin-ext-wght-normal.woff2) format('woff2-variations'),
       url(../fonts/nunito-latin-ext-wght-normal.woff2) format('woff2');
  unicode-range: U+0100-02BA,U+02BD-02C5,U+02C7-02CC,U+02CE-02D7,U+02DD-02FF,U+0304,U+0308,U+0329,U+1D00-1DBF,U+1E00-1E9F,U+1EF2-1EFF,U+2020,U+20A0-20AB,U+20AD-20C0,U+2113,U+2C60-2C7F,U+A720-A7FF;
}
@font-face {
  font-family: 'Nunito';
  font-style: normal;
  font-display: swap;
  font-weight: 200 1000;
  src: url(../fonts/nunito-latin-wght-normal.woff2) format('woff2-variations'),
       url(../fonts/nunito-latin-wght-normal.woff2) format('woff2');
  unicode-range: U+0000-00FF,U+0131,U+0152-0153,U+02BB-02BC,U+02C6,U+02DA,U+02DC,U+0304,U+0308,U+0329,U+2000-206F,U+20AC,U+2122,U+2191,U+2193,U+2212,U+2215,U+FEFF,U+FFFD;
}

/* ============================================================
   THIẾT KẾ GỐC (giữ nguyên từ bản Gemini)
   ============================================================ */
:root {
  --primary: #FF6B6B;
  --primary-dark: #EE5253;
  --secondary: #4ECDC4;
  --secondary-dark: #1DD1A1;
  --accent: #FFE66D;
  --accent-dark: #FECA57;
  --purple: #A29BFE;
  --blue: #54A0FF;
  --bg-sky: #E8F8F5;
  --bg-card: #FFFFFF;
  --text-main: #2D3436;
  --text-muted: #636E72;
  --shadow-soft: 0 10px 25px rgba(0, 0, 0, 0.08);
  --shadow-btn: 0 6px 0 rgba(0, 0, 0, 0.15);
  --radius-lg: 24px;
  --radius-md: 16px;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

body {
  margin: 0;
  padding: 0;
  font-family: 'Fredoka', 'Nunito', sans-serif;
  background: linear-gradient(180deg, #D6EAF8 0%, #E8F8F5 50%, #FEF9E7 100%);
  color: var(--text-main);
  min-height: 100vh;
  overflow-x: hidden;
}

/* Header & Mascot */
header {
  background: #FFFFFF;
  padding: 12px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: 0 4px 15px rgba(0,0,0,0.06);
  position: sticky;
  top: 0;
  z-index: 100;
  border-bottom: 4px solid #FFE66D;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
}

.mascot-avatar {
  width: 54px;
  height: 54px;
  background: linear-gradient(135deg, #FFE66D, #FF9F43);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 32px;
  box-shadow: 0 4px 10px rgba(255, 159, 67, 0.4);
  border: 3px solid #FFF;
  animation: float 3s ease-in-out infinite;
}

@keyframes float {
  0%, 100% { transform: translateY(0px); }
  50% { transform: translateY(-5px); }
}

.brand-title h1 {
  margin: 0;
  font-size: 1.3rem;
  color: #6C5CE7;
  line-height: 1.1;
}

.brand-title span {
  font-size: 0.85rem;
  color: #00B894;
  font-weight: 600;
}

.stats-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.stat-pill {
  background: #F8F9FA;
  border: 2px solid #E9ECEF;
  padding: 6px 14px;
  border-radius: 50px;
  font-weight: 700;
  font-size: 0.95rem;
  display: flex;
  align-items: center;
  gap: 6px;
}

.stat-pill.stars { background: #FFF9DB; border-color: #FFE066; color: #E67700; }
.stat-pill.level { background: #E7F5FF; border-color: #74C0FC; color: #1971C2; }

.nav-btn {
  background: #6C5CE7;
  color: white;
  border: none;
  padding: 8px 16px;
  border-radius: 50px;
  font-family: inherit;
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  box-shadow: 0 4px 0 #4834D4;
  transition: transform 0.1s;
}

.nav-btn:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 #4834D4;
}

.nav-btn.parent-btn {
  background: #2D3436;
  box-shadow: 0 4px 0 #000000;
}

/* Main Container */
main {
  max-width: 1150px;
  margin: 0 auto;
  padding: 20px;
}

/* Mascot Speech Banner */
.mascot-banner {
  background: #FFFFFF;
  border-radius: var(--radius-lg);
  padding: 16px 24px;
  margin-bottom: 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  box-shadow: var(--shadow-soft);
  border: 3px solid #A29BFE;
}

.mascot-speech {
  display: flex;
  align-items: center;
  gap: 15px;
}

.mascot-big {
  font-size: 48px;
  cursor: pointer;
  transition: transform 0.2s;
}
.mascot-big:hover { transform: scale(1.15) rotate(8deg); }

.speech-bubble {
  background: #F3F0FF;
  padding: 12px 18px;
  border-radius: 18px;
  position: relative;
  font-size: 1.05rem;
  color: #3B3B98;
  font-weight: 600;
}

/* Quick Action Bar */
.quick-actions {
  display: flex;
  gap: 12px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}

.action-card {
  flex: 1;
  min-width: 220px;
  background: linear-gradient(135deg, #FF9FF3, #F368E0);
  color: white;
  padding: 16px 20px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  box-shadow: 0 6px 0 #B33771;
  transition: transform 0.15s;
}

.action-card.map-card {
  background: linear-gradient(135deg, #48DBFB, #0ABDE3);
  box-shadow: 0 6px 0 #006266;
}

.action-card.review-card {
  background: linear-gradient(135deg, #FF6B6B, #EE5253);
  box-shadow: 0 6px 0 #B33939;
}

.action-card:active {
  transform: translateY(4px);
}

/* 10 Learning Zones Grid */
.zones-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 18px;
}

.zone-card {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  padding: 20px 16px;
  text-align: center;
  box-shadow: var(--shadow-soft);
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  border-bottom: 6px solid #DFE6E9;
  position: relative;
  overflow: hidden;
}

.zone-card:hover {
  transform: translateY(-6px);
}

.zone-icon {
  font-size: 52px;
  margin-bottom: 10px;
  display: block;
}

.zone-title {
  font-size: 1.2rem;
  font-weight: 700;
  margin: 0 0 4px;
  color: var(--text-main);
}

.zone-sub {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 12px;
}

.progress-mini {
  height: 10px;
  background: #EDF2F7;
  border-radius: 10px;
  overflow: hidden;
  margin-top: 8px;
}

.progress-mini-fill {
  height: 100%;
  background: #00B894;
  border-radius: 10px;
  transition: width 0.4s ease;
}

.weak-badge {
  position: absolute;
  top: 10px;
  right: 10px;
  background: #FF7675;
  color: white;
  font-size: 0.72rem;
  padding: 3px 8px;
  border-radius: 20px;
  font-weight: 700;
}

/* Game Arena View */
.view-section {
  display: none;
}
.view-section.active {
  display: block;
  animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.game-container {
  background: #FFFFFF;
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow-soft);
  border: 4px solid #74B9FF;
  min-height: 480px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.game-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 2px dashed #DFE6E9;
  padding-bottom: 14px;
  margin-bottom: 20px;
  flex-wrap: wrap;
  gap: 10px;
}

.game-mode-tabs {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.mode-pill {
  padding: 6px 14px;
  border-radius: 20px;
  border: 2px solid #DFE6E9;
  background: #F8F9FA;
  font-family: inherit;
  font-weight: 600;
  cursor: pointer;
  font-size: 0.85rem;
}

.mode-pill.active {
  background: #0984E3;
  color: white;
  border-color: #0984E3;
}

.audio-btn-big {
  background: linear-gradient(135deg, #FF9F43, #EE5253);
  color: white;
  border: none;
  width: 72px;
  height: 72px;
  border-radius: 50%;
  font-size: 32px;
  cursor: pointer;
  box-shadow: 0 6px 0 #B33939;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.1s;
}

.audio-btn-big:active {
  transform: translateY(4px);
  box-shadow: 0 2px 0 #B33939;
}

.prompt-box {
  text-align: center;
  margin: 15px 0 25px;
}

.prompt-text {
  font-size: 1.65rem;
  font-weight: 700;
  color: #2D3436;
  margin: 12px 0 6px;
}

.prompt-hint {
  font-size: 1rem;
  color: #636E72;
}

/* Options Grid */
.options-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  margin: 15px 0;
}

.option-card {
  background: #F8F9FA;
  border: 3px solid #DFE6E9;
  border-radius: 20px;
  padding: 18px;
  text-align: center;
  cursor: pointer;
  transition: all 0.15s;
  box-shadow: 0 5px 0 #DFE6E9;
}

.option-card:hover {
  border-color: #74B9FF;
  background: #EBF5FB;
}

.option-card.correct {
  background: #D4EDDA !important;
  border-color: #28A745 !important;
  box-shadow: 0 5px 0 #28A745 !important;
  animation: bounce 0.4s;
}

.option-card.wrong {
  background: #F8D7DA !important;
  border-color: #DC3545 !important;
  box-shadow: 0 5px 0 #DC3545 !important;
  animation: shake 0.4s;
}

@keyframes bounce {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.06); }
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-8px); }
  75% { transform: translateX(8px); }
}

.option-emoji {
  font-size: 48px;
  display: block;
  margin-bottom: 8px;
}

.option-label {
  font-size: 1.25rem;
  font-weight: 700;
}

/* Letter / Word Builder (Drag & Tap) */
.builder-slots {
  display: flex;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
  min-height: 64px;
  padding: 14px;
  background: #F1F2F6;
  border-radius: 18px;
  border: 3px dashed #A4B0BE;
  margin-bottom: 20px;
}

.slot-tile, .bank-tile {
  background: #FFFFFF;
  border: 3px solid #0984E3;
  color: #0984E3;
  font-size: 1.4rem;
  font-weight: 700;
  padding: 10px 18px;
  border-radius: 14px;
  cursor: pointer;
  box-shadow: 0 4px 0 #0984E3;
  transition: transform 0.1s;
}

.bank-tile {
  background: #FFEAA7;
  border-color: #FDCB6E;
  color: #2D3436;
  box-shadow: 0 4px 0 #E17055;
}

.bank-tile.used {
  opacity: 0.35;
  pointer-events: none;
}

.word-bank {
  display: flex;
  justify-content: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}

/* Matching Game */
.match-columns {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
  max-width: 700px;
  margin: 0 auto;
}

.match-col {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.match-item {
  background: #FFF;
  border: 3px solid #A29BFE;
  border-radius: 16px;
  padding: 14px;
  text-align: center;
  font-size: 1.2rem;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 4px 0 #A29BFE;
}

.match-item.selected {
  background: #FFEAA7;
  border-color: #FDCB6E;
  transform: scale(1.03);
}

.match-item.matched {
  background: #55EFC4;
  border-color: #00B894;
  color: #006266;
  opacity: 0.7;
  pointer-events: none;
}

/* Feedback Banner */
.feedback-box {
  margin-top: 18px;
  padding: 16px;
  border-radius: 16px;
  text-align: center;
  font-weight: 700;
  font-size: 1.15rem;
  display: none;
}

.feedback-box.success {
  display: block;
  background: #D4EDDA;
  color: #155724;
  border: 2px solid #28A745;
}

.feedback-box.error {
  display: block;
  background: #FFF3CD;
  color: #856404;
  border: 2px solid #FFC107;
}

/* 4-Week Roadmap & Badges */
.roadmap-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 20px;
  margin-top: 16px;
}

.week-card {
  background: #FFF;
  border-radius: 20px;
  padding: 20px;
  border: 3px solid #74B9FF;
  box-shadow: var(--shadow-soft);
}

.week-card h3 {
  margin-top: 0;
  color: #0984E3;
}

.day-node {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  background: #F8F9FA;
  border-radius: 12px;
  margin-bottom: 8px;
  font-weight: 600;
}

.day-node.done {
  background: #D4EDDA;
  color: #155724;
}

.badges-shelf {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  margin-top: 16px;
}

.badge-item {
  background: #FFF;
  border: 3px solid #FFEAA7;
  border-radius: 18px;
  padding: 14px;
  width: 140px;
  text-align: center;
  opacity: 0.4;
  filter: grayscale(100%);
}

.badge-item.unlocked {
  opacity: 1;
  filter: none;
  background: linear-gradient(180deg, #FFFDF5, #FFF3BF);
  box-shadow: 0 6px 15px rgba(253, 203, 110, 0.4);
}

/* Parent Dashboard */
.parent-panel {
  background: #FFF;
  border-radius: 24px;
  padding: 24px;
  box-shadow: var(--shadow-soft);
}

.report-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 16px;
}

.report-table th, .report-table td {
  padding: 12px;
  border-bottom: 1px solid #DFE6E9;
  text-align: left;
}

.report-table th {
  background: #F1F2F6;
}

/* Confetti Canvas */
#confetti-canvas {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 999;
}

@media (max-width: 600px) {
  .prompt-text { font-size: 1.35rem; }
  .option-emoji { font-size: 38px; }
  .match-columns { grid-template-columns: 1fr; }
}

/* ============================================================
   PWA / iOS / CẢM ỨNG — bổ sung, không thay đổi thiết kế gốc
   ============================================================ */
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
* { -webkit-user-select: none; -webkit-touch-callout: none; }

body {
  min-height: 100vh;
  min-height: 100dvh;
  overscroll-behavior-y: none;
  touch-action: manipulation;           /* bỏ độ trễ double-tap zoom */
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
  padding-bottom: env(safe-area-inset-bottom);
}

header { padding-top: calc(12px + env(safe-area-inset-top)); }

button, [onclick], .option-card, .zone-card, .match-item, .bank-tile, .slot-tile, .action-card {
  touch-action: manipulation;
}

/* Vùng chạm tối thiểu 44px theo Apple HIG */
.nav-btn, .mode-pill { min-height: 44px; }
.bank-tile, .slot-tile { min-width: 48px; min-height: 52px; }
.slot-tile { cursor: pointer; }

button:focus-visible, [role="button"]:focus-visible {
  outline: 3px solid #6C5CE7;
  outline-offset: 3px;
}

/* Trạng thái nhấn cho màn hình cảm ứng */
.zone-card:active { transform: scale(0.97); }
.option-card:active { transform: translateY(3px); box-shadow: 0 2px 0 #DFE6E9; }
.match-item:active { transform: scale(0.98); }
.bank-tile:active, .slot-tile:active { transform: translateY(3px); }
.mode-pill:active { transform: scale(0.96); }

/* Trên thiết bị cảm ứng, :hover bị "dính" sau khi chạm → vô hiệu hóa */
@media (hover: none) {
  .zone-card:hover { transform: none; }
  .zone-card:active { transform: scale(0.97); }
  .option-card:hover { border-color: #DFE6E9; background: #F8F9FA; }
  .mascot-big:hover { transform: none; }
}

/* Bảng báo cáo cuộn ngang trên màn hình hẹp */
.report-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.report-table { min-width: 640px; }

.pill-group { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

/* Điện thoại */
@media (max-width: 640px) {
  header {
    flex-wrap: wrap;
    gap: 8px;
    padding: calc(10px + env(safe-area-inset-top)) 12px 10px;
  }
  .mascot-avatar { width: 44px; height: 44px; font-size: 26px; }
  .brand-title h1 { font-size: 1.1rem; }
  .stats-bar { width: 100%; gap: 8px; }
  .pill-group { width: 100%; gap: 8px; }
  .stats-bar .nav-btn { flex: 1 1 0; padding: 8px 10px; font-size: 0.85rem; white-space: nowrap; }
  .stat-pill { padding: 6px 10px; font-size: 0.9rem; }
  main { padding: 14px; }
  .mascot-banner { flex-direction: column; align-items: stretch; padding: 14px; }
  .game-container { padding: 16px; min-height: 0; }
  .game-header { justify-content: center; }
  .game-mode-tabs { justify-content: center; }
  .action-card { min-width: 100%; }
  .zones-grid { grid-template-columns: repeat(2, 1fr); gap: 12px; }
  .zone-card { padding: 16px 10px; }
  .zone-icon { font-size: 42px; }
  .zone-title { font-size: 1.05rem; }
  .options-grid { grid-template-columns: repeat(2, 1fr); gap: 12px; }
  .option-card { padding: 14px 10px; }
  .option-label { font-size: 1.1rem; word-break: break-word; }
  .badge-item { width: calc(50% - 7px); }
  .parent-panel { padding: 16px; }
}
@media (max-width: 360px) {
  .options-grid { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  .mascot-avatar { animation: none; }
  .view-section.active { animation: none; }
}

/* Chỉ báo offline trên thanh trên cùng */
.stat-pill.net { display: none; background: #FFF3CD; border-color: #FFC107; color: #856404; }
body.is-offline .stat-pill.net { display: flex; }

/* Thông báo (cập nhật phiên bản, sao lưu, lỗi lưu dữ liệu) */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(16px + env(safe-area-inset-bottom));
  transform: translate(-50%, 160%);
  background: #2D3436;
  color: #FFF;
  padding: 12px 16px;
  border-radius: 16px;
  display: flex;
  gap: 12px;
  align-items: center;
  z-index: 1000;
  transition: transform 0.3s ease;
  width: max-content;
  max-width: calc(100% - 24px);
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.25);
  font-weight: 600;
}
.toast.show { transform: translate(-50%, 0); }
.toast button {
  background: #00B894; color: #FFF; border: none; border-radius: 50px;
  padding: 8px 14px; font-family: inherit; font-weight: 700; min-height: 40px; cursor: pointer;
}

/* Khu vực Dữ liệu & Ứng dụng trong trang Phụ huynh */
.data-panel {
  margin-top: 24px;
  background: #F8F9FA;
  border-radius: 18px;
  padding: 16px;
  border: 2px dashed #DFE6E9;
}
.data-panel h3 { margin: 0 0 6px; }
.data-actions { display: flex; gap: 10px; flex-wrap: wrap; margin: 12px 0; }
.data-meta { font-size: 0.85rem; color: #636E72; line-height: 1.7; }
.visually-hidden {
  position: absolute !important; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}
