/* ============================================================
   HỌC TIẾNG TRUNG CÙNG GẤU TRÚC PANPAN
   Giao diện cho bé 5 tuổi: chữ to, nút to, màu tươi
   ============================================================ */

:root {
  --pink:   #FF6B9D;
  --red:    #FF5A5F;
  --orange: #FFA630;
  --yellow: #FFD93D;
  --green:  #4ECB71;
  --teal:   #2EC4B6;
  --blue:   #4D96FF;
  --purple: #9B72FF;
  --brown:  #8D6E63;

  --ink:    #2D2A32;
  --ink-2:  #6B6673;
  --paper:  #FFFDF7;
  --card:   #FFFFFF;

  --shadow: 0 6px 0 rgba(0,0,0,.10), 0 12px 24px rgba(0,0,0,.08);
  --shadow-sm: 0 4px 0 rgba(0,0,0,.08), 0 6px 14px rgba(0,0,0,.06);
  --radius: 28px;

  --font: "Baloo 2", "Nunito", "Chalkboard SE", "Comic Sans MS",
          -apple-system, "Segoe UI", system-ui, sans-serif;
  --font-zh: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei",
             "Noto Sans SC", sans-serif;
}

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

html, body {
  margin: 0; padding: 0;
  font-family: var(--font);
  color: var(--ink);
  background: var(--paper);
  overscroll-behavior-y: contain;
}

body {
  background-image:
    radial-gradient(circle at 12% 8%,  rgba(255,217,61,.20) 0 90px, transparent 91px),
    radial-gradient(circle at 88% 18%, rgba(77,150,255,.16) 0 120px, transparent 121px),
    radial-gradient(circle at 78% 82%, rgba(78,203,113,.16) 0 140px, transparent 141px),
    radial-gradient(circle at 18% 92%, rgba(255,107,157,.16) 0 110px, transparent 111px);
  background-attachment: fixed;
}

.wrap { max-width: 1080px; margin: 0 auto; padding: 20px 18px 80px; }

/* ---------- Header ---------- */
.topbar {
  display: flex; align-items: center; gap: 14px;
  padding: 14px 18px; position: sticky; top: 0; z-index: 50;
  background: rgba(255,253,247,.88);
  backdrop-filter: blur(10px);
  border-bottom: 3px solid rgba(0,0,0,.06);
}
.topbar .brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 20px; }
.topbar .spacer { flex: 1; }

.btn {
  border: none; cursor: pointer; font-family: var(--font); font-weight: 800;
  font-size: 18px; color: #fff; background: var(--blue);
  padding: 12px 22px; border-radius: 999px;
  box-shadow: 0 5px 0 rgba(0,0,0,.15);
  transition: transform .08s ease, box-shadow .08s ease, filter .15s ease;
}
.btn:hover { filter: brightness(1.05); }
.btn:active { transform: translateY(4px); box-shadow: 0 1px 0 rgba(0,0,0,.15); }
.btn.ghost { background: #fff; color: var(--ink); box-shadow: 0 5px 0 rgba(0,0,0,.08); }
.btn.pink { background: var(--pink); }
.btn.green { background: var(--green); }
.btn.orange { background: var(--orange); }
.btn.purple { background: var(--purple); }
.btn.big { font-size: 24px; padding: 16px 34px; }
.btn:disabled { opacity: .45; cursor: not-allowed; }

/* ---------- Trang chủ ---------- */
.hero-home {
  text-align: center; padding: 26px 16px 10px;
}
.hero-home h1 {
  font-size: clamp(30px, 6vw, 52px); margin: 8px 0 6px; line-height: 1.1;
  background: linear-gradient(90deg, var(--pink), var(--orange), var(--green), var(--blue));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.hero-home p { font-size: 19px; color: var(--ink-2); margin: 0 0 6px; }

.panda-wave { width: 150px; height: 150px; animation: bob 2.6s ease-in-out infinite; }
@keyframes bob { 0%,100%{transform:translateY(0) rotate(-2deg)} 50%{transform:translateY(-12px) rotate(2deg)} }

.progress-bar-home {
  max-width: 520px; margin: 14px auto 0; background: #fff; border-radius: 999px;
  height: 26px; box-shadow: var(--shadow-sm); overflow: hidden; position: relative;
}
.progress-bar-home > i {
  display: block; height: 100%; width: 0;
  background: linear-gradient(90deg, var(--green), var(--teal));
  border-radius: 999px; transition: width .6s cubic-bezier(.2,.9,.3,1.2);
}
.progress-bar-home > span {
  position: absolute; inset: 0; display: grid; place-items: center;
  font-size: 14px; font-weight: 800; color: var(--ink);
}

.grid {
  display: grid; gap: 18px; margin-top: 26px;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
}

.lesson-card {
  background: var(--card); border-radius: var(--radius); padding: 18px 16px 16px;
  box-shadow: var(--shadow); cursor: pointer; text-align: center;
  position: relative; overflow: hidden; border: 4px solid transparent;
  transition: transform .14s ease, box-shadow .14s ease;
  text-decoration: none; color: inherit; display: block;
}
.lesson-card:hover { transform: translateY(-6px) rotate(-1deg); }
.lesson-card .num {
  position: absolute; top: 10px; left: 12px; font-weight: 900; font-size: 15px;
  background: rgba(0,0,0,.06); border-radius: 999px; padding: 3px 11px; color: var(--ink-2);
}
.lesson-card .emo { font-size: 64px; line-height: 1.1; display: block; margin: 12px 0 6px; }
.lesson-card .zh  { font-family: var(--font-zh); font-size: 26px; font-weight: 800; }
.lesson-card .py  { font-size: 14px; color: var(--ink-2); }
.lesson-card .vi  { font-size: 17px; font-weight: 800; margin-top: 6px; }
.lesson-card .stars { margin-top: 8px; font-size: 18px; letter-spacing: 2px; }
.lesson-card .band { position: absolute; inset: 0 0 auto 0; height: 10px; }

/* ---------- Trang bài học ---------- */
.lesson-hero { border-radius: 34px; overflow: hidden; box-shadow: var(--shadow); margin-bottom: 8px; }
.lesson-hero svg { display: block; width: 100%; height: auto; }

.steps {
  display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; margin: 18px 0 6px;
}
.step-pill {
  background: #fff; border-radius: 999px; padding: 9px 16px; font-weight: 800; font-size: 15px;
  box-shadow: var(--shadow-sm); cursor: pointer; border: 3px solid transparent; color: var(--ink-2);
}
.step-pill.active { border-color: var(--blue); color: var(--ink); transform: translateY(-2px); }
.step-pill.done { background: #EAFBEF; color: var(--green); }

section.panel {
  background: var(--card); border-radius: var(--radius); padding: 22px;
  box-shadow: var(--shadow); margin-top: 18px;
}
section.panel > h2 {
  margin: 0 0 4px; font-size: 27px; display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
}
section.panel > h2 .mins {
  font-size: 14px; font-weight: 800; background: var(--yellow);
  padding: 4px 12px; border-radius: 999px; color: #6b4f00;
}
section.panel > .sub { margin: 0 0 16px; color: var(--ink-2); font-size: 17px; }

/* Thẻ từ vựng */
.word-grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
.word-card {
  border-radius: 24px; padding: 14px 10px 12px; text-align: center; cursor: pointer;
  box-shadow: var(--shadow-sm); position: relative; user-select: none;
  transition: transform .12s ease;
  background: #fff; border: 4px solid #F0EFF4;
}
.word-card:hover { transform: translateY(-4px) scale(1.02); }
.word-card.speaking { animation: pop .5s ease; border-color: var(--green); }
@keyframes pop { 0%{transform:scale(1)} 40%{transform:scale(1.10) rotate(-3deg)} 100%{transform:scale(1)} }
.word-card .emo { font-size: 62px; display: block; line-height: 1.15; }
.word-card .zh { font-family: var(--font-zh); font-size: 30px; font-weight: 800; margin-top: 2px; }
.word-card .py { font-size: 15px; color: var(--ink-2); }
.word-card .vn { font-size: 14px; color: var(--purple); font-weight: 800; }
.word-card .vi { font-size: 16px; font-weight: 800; margin-top: 4px; }
.word-card .spk { position: absolute; top: 8px; right: 10px; font-size: 20px; opacity: .5; }

/* Mẫu câu */
.sent {
  display: flex; gap: 14px; align-items: center; padding: 14px 16px; border-radius: 22px;
  background: #F7F9FF; margin-bottom: 12px; cursor: pointer; border: 3px solid transparent;
}
.sent:hover { border-color: var(--blue); }
.sent .emo { font-size: 46px; }
.sent .zh { font-family: var(--font-zh); font-size: 27px; font-weight: 800; }
.sent .py { font-size: 15px; color: var(--ink-2); }
.sent .vn { font-size: 14px; color: var(--purple); font-weight: 800; }
.sent .vi { font-size: 17px; margin-top: 3px; }
.sent.b { background: #FFF6F9; }

/* Chant / bài hát */
.chant { background: linear-gradient(135deg,#FFF3D6,#FFE6F0); border-radius: 24px; padding: 18px 20px; }
.chant .line { font-size: 24px; font-family: var(--font-zh); font-weight: 800; margin: 6px 0; }
.chant .line small { font-family: var(--font); font-size: 14px; color: var(--ink-2); font-weight: 700; }

/* Trò chơi */
.game-box { background: #FBFAFF; border-radius: 24px; padding: 18px; border: 4px dashed #E3E0F0; }
.game-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.game-head h3 { margin: 0; font-size: 22px; }
.game-head .score { margin-left: auto; font-weight: 900; font-size: 18px; }

.opt-grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); }
.opt {
  background: #fff; border: 5px solid #EDEBF3; border-radius: 24px; padding: 16px 8px;
  font-size: 60px; cursor: pointer; text-align: center; box-shadow: var(--shadow-sm);
  transition: transform .1s ease;
}
.opt:hover { transform: scale(1.05); }
.opt.right { border-color: var(--green); background: #EAFBEF; animation: pop .45s ease; }
.opt.wrong { border-color: var(--red); background: #FFEFEF; animation: shake .4s ease; }
.opt .zh { font-family: var(--font-zh); font-size: 34px; font-weight: 800; display: block; }
@keyframes shake { 0%,100%{transform:translateX(0)} 25%{transform:translateX(-9px)} 75%{transform:translateX(9px)} }

.match-grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(110px,1fr)); }
.tile {
  aspect-ratio: 1/1; border-radius: 22px; display: grid; place-items: center; cursor: pointer;
  font-size: 46px; background: linear-gradient(135deg,var(--blue),var(--purple)); color: #fff;
  box-shadow: var(--shadow-sm); transition: transform .18s ease;
}
.tile .face { display: none; }
.tile.open, .tile.matched { background: #fff; color: var(--ink); }
.tile.open .face, .tile.matched .face { display: block; }
.tile.open .back, .tile.matched .back { display: none; }
.tile.matched { opacity: .45; cursor: default; }
.tile .zh { font-family: var(--font-zh); font-size: 30px; font-weight: 800; }

.drag-zone { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(150px,1fr)); }
.slot {
  min-height: 108px; border-radius: 22px; border: 5px dashed #D9D5E8; background: #fff;
  display: grid; place-items: center; padding: 8px; text-align: center;
}
.slot.over { border-color: var(--blue); background: #EEF4FF; }
.slot.filled { border-style: solid; border-color: var(--green); background: #EAFBEF; }
.slot .zh { font-family: var(--font-zh); font-size: 26px; font-weight: 800; }
.chip {
  font-size: 50px; background: #fff; border-radius: 20px; padding: 8px 14px; cursor: grab;
  box-shadow: var(--shadow-sm); display: inline-block; border: 4px solid #EDEBF3;
}
.chip.dragging { opacity: .4; }
.chip-tray { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; margin-top: 16px; }

.mic-box { text-align: center; }
.mic-word { font-family: var(--font-zh); font-size: 62px; font-weight: 800; }
.mic-btn {
  width: 110px; height: 110px; border-radius: 50%; border: none; cursor: pointer; font-size: 46px;
  background: var(--red); color: #fff; box-shadow: 0 6px 0 rgba(0,0,0,.18); margin: 12px;
}
.mic-btn.rec { animation: pulse 1s infinite; }
@keyframes pulse { 0%,100%{transform:scale(1)} 50%{transform:scale(1.10)} }

.feedback { font-size: 22px; font-weight: 900; text-align: center; min-height: 34px; margin-top: 10px; }
.feedback.ok { color: var(--green); }
.feedback.no { color: var(--red); }

/* Phần thưởng */
.reward { text-align: center; padding: 10px; }
.reward .big-stars { font-size: 58px; letter-spacing: 6px; }
.sticker {
  width: 130px; height: 130px; border-radius: 50%; display: inline-grid; place-items: center;
  font-size: 66px; background: radial-gradient(circle at 35% 30%, #fff, #FFE9A8);
  box-shadow: var(--shadow); animation: bob 3s ease-in-out infinite; margin: 10px;
}

/* Ghi chú bố mẹ */
.parent-tip {
  background: #F1F7FF; border-left: 8px solid var(--blue); border-radius: 16px;
  padding: 14px 18px; font-size: 16px; color: var(--ink-2); margin-top: 14px;
}
.parent-tip b { color: var(--ink); }

.nav-bottom { display: flex; gap: 12px; justify-content: space-between; margin-top: 26px; flex-wrap: wrap; }

/* Confetti */
#confetti { position: fixed; inset: 0; pointer-events: none; z-index: 999; }

@media (max-width: 560px) {
  .word-card .emo { font-size: 52px; }
  .opt { font-size: 48px; }
  section.panel { padding: 16px; }
}

@media print {
  .btn, .steps, .nav-bottom, .game-box { display: none !important; }
  body { background: #fff; }
}

/* ============================================================
   TỐI ƯU CHO iPAD
   ============================================================ */

/* không zoom khi bé chạm hai lần, không hiện menu khi giữ lâu */
* { touch-action: manipulation; }
html { -webkit-text-size-adjust: 100%; }
body {
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

/* chừa chỗ cho tai thỏ / thanh home của iPad */
.topbar { padding-top: calc(14px + env(safe-area-inset-top)); }
.wrap {
  padding-left: calc(18px + env(safe-area-inset-left));
  padding-right: calc(18px + env(safe-area-inset-right));
  padding-bottom: calc(90px + env(safe-area-inset-bottom));
}

/* máy cảm ứng: bỏ hiệu ứng hover (kẹt trạng thái sau khi chạm), thêm phản hồi khi nhấn */
@media (hover: none) {
  .lesson-card:hover, .word-card:hover, .opt:hover, .sent:hover { transform: none; }
  .lesson-card:active { transform: scale(.97); }
  .word-card:active { transform: scale(.94); border-color: var(--green); }
  .opt:active      { transform: scale(.94); }
  .tile:active     { transform: scale(.94); }
  .chip:active     { transform: scale(.90); }
  .sent:active     { border-color: var(--blue); }
  .btn:active      { transform: translateY(4px); }
}

/* vùng chạm tối thiểu 60px cho ngón tay bé */
.btn { min-height: 56px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; }
.step-pill { min-height: 48px; display: inline-flex; align-items: center; }
.word-card, .opt, .tile, .slot { min-height: 130px; }
.chip { min-width: 82px; min-height: 82px; display: inline-flex; align-items: center; justify-content: center; }

/* iPad dựng đứng (768–834pt) */
@media (min-width: 700px) and (max-width: 900px) {
  .wrap { max-width: 100%; }
  .grid { grid-template-columns: repeat(3, 1fr); }
  .word-grid { grid-template-columns: repeat(3, 1fr); }
  .opt-grid { grid-template-columns: repeat(2, 1fr); }
  .match-grid { grid-template-columns: repeat(5, 1fr); }
  .drag-zone { grid-template-columns: repeat(2, 1fr); }
  .word-card .emo { font-size: 66px; }
  .opt { font-size: 70px; }
}

/* iPad nằm ngang (1024–1194pt) */
@media (min-width: 901px) and (pointer: coarse) {
  .grid { grid-template-columns: repeat(4, 1fr); }
  .word-grid { grid-template-columns: repeat(4, 1fr); }
  .opt-grid { grid-template-columns: repeat(4, 1fr); }
}

/* khi thêm vào Màn hình chính (chạy toàn màn hình, không có thanh Safari) */
@media (display-mode: standalone) {
  .topbar { padding-top: calc(20px + env(safe-area-inset-top)); }
}

/* ---------- Màn "Chạm để bắt đầu" ---------- */
.tapgate {
  position: fixed; inset: 0; z-index: 900; display: grid; place-items: center;
  background: linear-gradient(160deg, #FFF3D6, #FFE6F0 45%, #E7F1FF);
  text-align: center; padding: 24px; cursor: pointer;
  transition: opacity .3s ease;
}
.tapgate.gone { opacity: 0; }
.tapgate .tg-h { font-size: clamp(26px, 5vw, 42px); font-weight: 900; margin: 10px 0 4px; }
.tapgate .tg-s { font-size: 19px; color: var(--ink-2); margin-bottom: 22px; max-width: 460px; }
.tapgate .btn { animation: bob 2.2s ease-in-out infinite; }

/* ---------- Chấm điểm phát âm ---------- */
.score-zone { margin-top: 14px; min-height: 10px; }
.score-zone.show { animation: pop .5s ease; }

.score-ring {
  width: 128px; height: 128px; border-radius: 50%; margin: 0 auto;
  display: grid; place-items: center; background: #fff;
  border: 10px solid var(--green); box-shadow: var(--shadow-sm);
}
.score-ring.big { width: 152px; height: 152px; }
.score-ring span { font-size: 46px; font-weight: 900; line-height: 1; }
.score-ring.big span { font-size: 56px; }
.score-ring.great { border-color: var(--green); }
.score-ring.good  { border-color: var(--green); }
.score-ring.bad   { border-color: var(--red); }
.score-ring.great span { color: var(--green); }
.score-ring.good span  { color: var(--green); }
.score-ring.bad span   { color: var(--red); }

.score-label { font-size: 23px; font-weight: 900; margin-top: 10px; }
.score-label.great, .score-label.good { color: var(--green); }
.score-label.bad { color: var(--red); }
.score-heard { font-size: 16px; color: var(--ink-2); margin-top: 4px; }

.score-table { max-width: 420px; margin: 18px auto 0; text-align: left; }
.score-table .row {
  display: flex; align-items: center; gap: 10px; padding: 9px 14px;
  background: #fff; border-radius: 16px; margin-bottom: 8px; box-shadow: var(--shadow-sm);
}
.score-table .row .zh { font-family: var(--font-zh); font-size: 24px; min-width: 84px; }
.score-table .row span { color: var(--ink-2); font-size: 15px; flex: 1; }
.score-table .pill {
  font-style: normal; font-weight: 900; font-size: 17px; color: #fff;
  border-radius: 999px; padding: 5px 15px; background: var(--green);
}
.score-table .pill.bad { background: var(--red); }
