/* ===== Màu sắc & cỡ chữ chung ===== */
:root {
  --bg: #FFF4D6;
  --bg2: #FFE8B8;
  --ink: #3B2F5C;
  --ink-soft: #6E6390;
  --card-bg: #FFFFFF;
  --line: #EADFC7;
  --good: #2EAD5B;
  --good-bg: #DDF7E5;
  --bad: #E5484D;
  --bad-bg: #FFE3E3;
  --accent: #7C4DFF;
  --sun: #FFC93C;
  --shadow: 0 6px 0 rgba(59, 47, 92, .14);
  --radius: 28px;
  --card: #4FC3F7;
  font-size: 20px;
}
@media (min-width: 768px) { :root { font-size: 22px; } }

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: 'Nunito', 'Segoe UI', 'Helvetica Neue', Arial, sans-serif;
  font-weight: 700;
  color: var(--ink);
  background: var(--bg);
  min-height: 100vh;
  -webkit-tap-highlight-color: transparent;
}
body.student {
  background:
    radial-gradient(circle at 10% 8%, #FFE08A 0 60px, transparent 61px),
    radial-gradient(circle at 92% 18%, #FFFFFF 0 40px, transparent 41px),
    radial-gradient(circle at 85% 20%, #FFFFFF 0 30px, transparent 31px),
    linear-gradient(180deg, #CFEFFF 0, #FFF4D6 280px) #FFF4D6;
  background-repeat: no-repeat;
}
button { font: inherit; color: inherit; cursor: pointer; }
button:disabled { cursor: default; }
:focus-visible { outline: 4px solid var(--accent); outline-offset: 3px; }
.loading, .empty { text-align: center; font-size: 1.4rem; padding: 3rem 1rem; }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

#app { max-width: 1000px; margin: 0 auto; padding: 16px 16px 120px; }

/* ===== Nút to kiểu "kẹo" ===== */
.big-btn {
  border: 0;
  border-radius: 999px;
  padding: .7em 1.4em;
  min-height: 72px;
  font-size: 1.4rem;
  font-weight: 900;
  color: #fff;
  background: var(--accent);
  box-shadow: 0 6px 0 #5A31D6;
  transition: transform .08s;
}
.big-btn:active { transform: translateY(4px); box-shadow: 0 2px 0 #5A31D6; }
.big-btn.alt { background: #FF8A65; box-shadow: 0 6px 0 #D9623E; }
.big-btn:disabled { opacity: .45; }

/* ===== Trang chủ ===== */
.home-header { text-align: center; padding: 1rem 0 .5rem; }
.logo { font-size: 4.5rem; line-height: 1; animation: bob 3s ease-in-out infinite; }
.home-header h1 { font-size: clamp(2.4rem, 9vw, 3.6rem); font-weight: 900; margin: .2em 0 0; letter-spacing: .02em; color: var(--accent); text-shadow: 3px 3px 0 #fff; }
.grade-badge {
  display: inline-block; margin-top: .4em; padding: .15em .8em; border-radius: 999px;
  background: var(--accent); color: #fff; font-size: 1.15rem; font-weight: 900; box-shadow: 0 4px 0 rgba(0,0,0,.15);
}
.subtitle { font-size: 1.3rem; margin: .3em 0 1em; color: var(--ink-soft); }
.preview-banner { text-align: center; background: #FFF; border: 3px dashed var(--accent); border-radius: 16px; padding: .5em; font-size: 1rem; }

.lesson-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 20px; }
.lesson-card {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .3em;
  min-height: 220px; padding: 1.2em 1em;
  border: 0; border-radius: var(--radius);
  background: var(--card); color: #fff;
  box-shadow: 0 8px 0 rgba(0,0,0,.18);
  transition: transform .12s;
}
.lesson-card:hover { transform: translateY(-4px) rotate(-1deg); }
.lesson-card:active { transform: translateY(4px); box-shadow: 0 3px 0 rgba(0,0,0,.18); }
.lesson-icon { font-size: 4rem; background: rgba(255,255,255,.35); border-radius: 50%; width: 1.6em; height: 1.6em; display: grid; place-items: center; }
.lesson-title { font-size: 1.45rem; font-weight: 900; text-align: center; text-shadow: 0 2px 0 rgba(0,0,0,.15); }
.lesson-count { font-size: 1rem; background: rgba(255,255,255,.3); padding: .15em .8em; border-radius: 999px; }
.home-footer { text-align: center; margin-top: 3rem; }
.home-footer a { color: var(--ink-soft); font-size: .9rem; }

/* ===== Làm bài ===== */
.topbar { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.icon-btn { width: 64px; height: 64px; flex: none; border: 0; border-radius: 50%; background: #fff; font-size: 2rem; box-shadow: var(--shadow); }
.progress { flex: 1; display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; }
.dot { width: 22px; height: 22px; border-radius: 50%; background: #fff; border: 3px solid var(--line); }
.dot.now { border-color: var(--card); background: var(--card); transform: scale(1.25); }
.dot.ok { background: var(--good); border-color: var(--good); }
.dot.retry { background: var(--sun); border-color: var(--sun); }
.counter { flex: none; font-size: 1.2rem; font-weight: 900; background: #fff; padding: .3em .7em; border-radius: 999px; box-shadow: var(--shadow); }

.question-card {
  position: relative;
  background: var(--card-bg);
  border-radius: var(--radius);
  border: 6px solid var(--card);
  box-shadow: var(--shadow);
  padding: 1rem 1rem 1.2rem;
  text-align: center;
  margin-bottom: 18px;
}
.speaker {
  width: 96px; height: 96px; border-radius: 50%; border: 0;
  background: var(--sun); font-size: 3rem; box-shadow: 0 6px 0 #E0A800;
  animation: pulse 2.2s ease-in-out infinite;
}
.speaker:active { transform: translateY(4px); box-shadow: 0 2px 0 #E0A800; }
.q-image { font-size: clamp(4.5rem, 20vw, 7rem); line-height: 1.1; margin-top: .1em; }
.q-text { font-size: clamp(1.8rem, 7vw, 2.6rem); font-weight: 900; margin: .3em 0 0; }

/* Trắc nghiệm */
.options { display: grid; gap: 16px; grid-template-columns: repeat(2, 1fr); }
@media (min-width: 700px) { .options.count-3 { grid-template-columns: repeat(3, 1fr); } .options.count-4 { grid-template-columns: repeat(4, 1fr); } .options.count-5, .options.count-6 { grid-template-columns: repeat(3, 1fr); } }
.option-wrap { position: relative; }
.option {
  width: 100%; min-height: 150px; padding: .2em .3em;
  border: 5px solid var(--line); border-radius: var(--radius);
  background: #fff; box-shadow: var(--shadow);
  transition: transform .1s, background .2s;
}
.option-text { font-size: clamp(3.4rem, 13vw, 5.2rem); font-weight: 900; line-height: 1.1; word-break: break-word; }
.option:active { transform: translateY(4px); }
.option.correct { border-color: var(--good); background: var(--good-bg); animation: pop .4s; }
.option.wrong { border-color: var(--bad); background: var(--bad-bg); animation: shake .4s; opacity: .55; }
.option-speak {
  position: absolute; top: -10px; right: -6px;
  width: 52px; height: 52px; border-radius: 50%;
  border: 3px solid #fff; background: var(--sun); font-size: 1.4rem;
  box-shadow: 0 3px 0 rgba(0,0,0,.15);
}

/* Điền đáp án */
.fill-word {
  text-align: center; font-size: clamp(4rem, 18vw, 6.5rem); font-weight: 900; line-height: 1.2;
  background: #fff; border-radius: var(--radius); box-shadow: var(--shadow); padding: .1em .3em; margin-bottom: 18px;
}
/* Mỗi chữ còn thiếu là một gạch dưới riêng. */
.blank {
  display: inline-block; min-width: .62em; padding: 0; margin: 0 .04em; line-height: 1.05;
  border-bottom: 8px solid var(--accent); border-radius: 3px; color: var(--accent);
}
.fill-word.correct { background: var(--good-bg); }
.fill-word.correct .blank { color: var(--good); border-color: var(--good); }
.fill-word.wrong { animation: shake .4s; }
.fill-word.wrong .blank { color: var(--bad); border-color: var(--bad); }
.tiles { display: flex; flex-wrap: wrap; justify-content: center; gap: 12px; margin-bottom: 16px; }
.tile {
  min-width: 84px; height: 84px; padding: 0 .3em; border-radius: 22px; border: 4px solid var(--line);
  background: #fff; font-size: 2.6rem; font-weight: 900; box-shadow: var(--shadow);
}
.tile:active { transform: translateY(4px); }
.tile:disabled { opacity: .5; }
.tile.erase { background: #FFE3E3; border-color: #FFC9C9; font-size: 2rem; }
.fill-controls { display: flex; gap: 12px; justify-content: center; align-items: center; flex-wrap: wrap; }
.fill-input {
  width: 9rem; height: 84px; border-radius: 22px; border: 4px solid var(--line);
  font: inherit; font-size: 2.2rem; text-align: center; color: var(--ink);
}

/* Toán */
.pic-row { display: flex; align-items: center; justify-content: center; gap: 10px; margin-bottom: 10px; }
.pics { display: flex; flex-wrap: wrap; gap: 4px; max-width: 300px; flex: 0 1 auto; justify-content: center; background: #fff; border-radius: 20px; padding: 10px; box-shadow: var(--shadow); }
.pic { font-size: clamp(1.7rem, 7vw, 2.6rem); line-height: 1; }
.pic.crossed { position: relative; opacity: .4; }
.pic.crossed::after { content: '✕'; position: absolute; inset: 0; display: grid; place-items: center; color: var(--bad); font-size: 2.6rem; opacity: 1; }
.pic-op { font-size: clamp(2.2rem, 9vw, 3rem); font-weight: 900; flex: none; }
.equation {
  text-align: center; font-size: clamp(3.4rem, 15vw, 5.5rem); font-weight: 900; margin: 6px 0 16px;
  background: #fff; border-radius: var(--radius); box-shadow: var(--shadow);
}
.answer-box { display: inline-block; min-width: 1.4em; border-bottom: 8px dashed var(--accent); color: var(--accent); }
.equation.correct { background: var(--good-bg); }
.equation.correct .answer-box { color: var(--good); border-color: var(--good); border-bottom-style: solid; }
.equation.wrong { animation: shake .4s; }
.equation.wrong .answer-box { color: var(--bad); border-color: var(--bad); }
.numpad { display: grid; grid-template-columns: repeat(5, 1fr); gap: 10px; max-width: 560px; margin: 0 auto; }
.numpad .tile { min-width: 0; width: 100%; }
.numpad .check-btn { grid-column: span 4; }

.check-btn { background: var(--good); box-shadow: 0 6px 0 #1E8443; }
.check-btn:active { box-shadow: 0 2px 0 #1E8443; }

/* Thông báo đúng / sai */
.feedback {
  position: fixed; left: 50%; bottom: 16px; transform: translate(-50%, 160%);
  width: min(960px, calc(100% - 24px));
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap; justify-content: center;
  padding: 14px 18px; border-radius: var(--radius);
  font-size: 1.5rem; font-weight: 900; transition: transform .25s;
  z-index: 10;
}
.feedback.show { transform: translate(-50%, 0); }
.feedback.correct { background: var(--good-bg); border: 5px solid var(--good); color: #1B6B39; }
.feedback.wrong { background: var(--bad-bg); border: 5px solid var(--bad); color: #A5262A; }
.fb-emoji { font-size: 2.6rem; }
.next-btn { margin-left: auto; }
@media (max-width: 560px) { .next-btn { margin-left: 0; width: 100%; } }

/* Kết quả */
.result { text-align: center; padding-top: 2rem; }
.result-stars { font-size: 5rem; display: flex; justify-content: center; gap: .1em; }
.star { filter: grayscale(1); opacity: .3; }
.star.on { filter: none; opacity: 1; animation: pop .6s both; }
.result h1 { font-size: clamp(2.6rem, 10vw, 3.8rem); font-weight: 900; color: var(--accent); margin: .2em 0; }
.result-score { font-size: 1.6rem; }
.result-score b { font-size: 2.2rem; color: var(--good); }
.result-actions { display: flex; flex-direction: column; gap: 18px; align-items: center; margin-top: 1.5rem; }
.result-actions .big-btn { width: min(420px, 100%); }

/* Pháo giấy */
.confetti { position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: 20; }
.confetti span { position: absolute; top: -60px; animation: fall 2.2s ease-in forwards; }

@keyframes fall { to { transform: translateY(110vh) rotate(540deg); } }
@keyframes pop { 0% { transform: scale(.6); } 60% { transform: scale(1.15); } 100% { transform: scale(1); } }
@keyframes shake { 0%,100% { transform: translateX(0); } 25% { transform: translateX(-10px); } 75% { transform: translateX(10px); } }
@keyframes pulse { 0%,100% { transform: scale(1); } 50% { transform: scale(1.07); } }
@keyframes bob { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-8px); } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }

/* Nút loa nhỏ: nghe lời chào, tên bài, kết quả */
.lesson-wrap { position: relative; display: grid; }
.say-btn {
  margin-left: .4em; vertical-align: middle;
  width: 44px; height: 44px; border-radius: 50%;
  border: 3px solid #fff; background: var(--sun); font-size: 1.2rem;
  box-shadow: 0 3px 0 rgba(0,0,0,.15);
}

/* Đáp án dài (câu, từ) và hình đếm */
.options.long { grid-template-columns: 1fr; }
@media (min-width: 700px) { .options.long.count-2, .options.long.count-4 { grid-template-columns: repeat(2, 1fr); } .options.long.count-3 { grid-template-columns: repeat(3, 1fr); } }
.options.long .option { min-height: 110px; }
.options.long .option-text { font-size: clamp(1.6rem, 6vw, 2.2rem); word-break: normal; overflow-wrap: anywhere; }
.q-image.many { font-size: clamp(2.4rem, 10vw, 3.6rem); letter-spacing: .05em; overflow-wrap: anywhere; }

/* So sánh số */
.compare-btns { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; max-width: 560px; margin: 0 auto; }
.compare-btn { width: 100%; height: auto; min-height: 120px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; }
.compare-btn .sign { font-size: 3.4rem; line-height: 1; }
.compare-btn .sign-word { font-size: 1rem; color: var(--ink-soft); }

/* Đồng hồ */
.clock-face { display: block; width: min(300px, 70vw); height: auto; margin: 0 auto 16px; filter: drop-shadow(0 6px 0 rgba(59, 47, 92, .14)); }

/* Xếp chữ / xếp từ */
.order-line {
  min-height: 108px; display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: center;
  padding: 12px; margin-bottom: 16px; border: 4px dashed var(--line); border-radius: var(--radius); background: #fff;
}
.order-line.drag-over { border-color: var(--accent); }
.order-line.correct { border-style: solid; border-color: var(--good); background: var(--good-bg); }
.order-line.wrong { border-color: var(--bad); animation: shake .4s; }
.order-tile.word { font-size: 1.8rem; }
.order-tile[draggable="true"] { cursor: grab; }
.options.sentence, .options.sentence.long { grid-template-columns: 1fr !important; }
.options.sentence .option { min-height: 84px; text-align: left; padding-left: 1em; }
