/* ===================== Toán Vui – Trắc nghiệm Nhân Chia ===================== */
/* Reset & biến màu */
:root {
  --bg1: #6a11cb;
  --bg2: #2575fc;
  --card: #ffffff;
  --ink: #24314d;
  --ink-soft: #5b6b8c;
  --primary: #ff7a18;
  --primary-2: #ffb347;
  --good: #2ecc71;
  --good-d: #22a35b;
  --bad: #ff5169;
  --bad-d: #d63a51;
  --sel: #2575fc;
  --shadow: 0 12px 30px rgba(20, 20, 60, .18);
  --radius: 20px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

/* Bảo đảm thuộc tính [hidden] luôn có hiệu lực, kể cả khi phần tử có display khác */
[hidden] { display: none !important; }

body {
  font-family: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  color: var(--ink);
  background: linear-gradient(135deg, var(--bg1), var(--bg2));
  background-attachment: fixed;
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  -webkit-tap-highlight-color: transparent;
}

/* Màn hình thấp: canh trên để không che HUD, cho phép cuộn */
@media (max-height: 640px) {
  body { align-items: flex-start; }
}

.app {
  width: 100%;
  max-width: 520px;
}

/* ===================== Màn hình (screen) ===================== */
.screen { display: none; animation: pop .35s ease; }
.screen.is-active { display: block; }

@keyframes pop {
  from { opacity: 0; transform: translateY(14px) scale(.98); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* ===================== Thẻ ===================== */
.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 26px 22px;
  text-align: center;
}

/* ===================== Màn bắt đầu ===================== */
.logo { font-size: 64px; line-height: 1; animation: bob 2.4s ease-in-out infinite; }
@keyframes bob { 0%,100%{ transform: translateY(0);} 50%{ transform: translateY(-8px);} }

.title {
  font-size: 40px;
  margin-top: 6px;
  background: linear-gradient(90deg, var(--primary), var(--sel));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  letter-spacing: .5px;
}
.subtitle { color: var(--ink-soft); margin-top: 2px; font-size: 16px; }

.best-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin: 16px auto 4px;
  padding: 8px 16px;
  background: #fff6e6;
  border: 2px solid #ffe1a8;
  border-radius: 999px;
  font-size: 15px;
  color: #a56412;
}
.best-star { animation: spin 4s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.field { margin-top: 18px; text-align: left; }
.field-label {
  display: block;
  font-weight: 700;
  font-size: 14px;
  color: var(--ink-soft);
  margin-bottom: 8px;
  padding-left: 4px;
}

.option-group { display: flex; gap: 8px; }
.option-btn {
  flex: 1;
  padding: 12px 6px;
  border: 2px solid #e6ebf5;
  background: #f7f9ff;
  border-radius: 14px;
  font-size: 15px;
  font-weight: 700;
  color: var(--ink);
  cursor: pointer;
  transition: transform .1s, border-color .15s, background .15s, box-shadow .15s;
}
.option-btn:hover { border-color: #c9d6f0; }
.option-btn:active { transform: scale(.96); }
.option-btn.is-selected {
  border-color: var(--sel);
  background: #eaf2ff;
  color: var(--sel);
  box-shadow: 0 4px 12px rgba(37, 117, 252, .22);
}

/* ===================== Nút chung ===================== */
.btn {
  display: block;
  width: 100%;
  border: none;
  border-radius: 16px;
  padding: 15px 18px;
  font-size: 18px;
  font-weight: 800;
  cursor: pointer;
  transition: transform .1s, box-shadow .15s, filter .15s;
}
.btn:active { transform: translateY(2px) scale(.99); }

.btn-primary {
  color: #fff;
  background: linear-gradient(90deg, var(--primary), var(--primary-2));
  box-shadow: 0 8px 18px rgba(255, 122, 24, .38);
}
.btn-primary:hover { filter: brightness(1.05); }

.btn-play { margin-top: 22px; }

.btn-ghost {
  background: transparent;
  color: var(--ink-soft);
  box-shadow: none;
  font-size: 16px;
}
.btn-ghost:hover { color: var(--ink); }

.hint { margin-top: 14px; font-size: 13px; color: var(--ink-soft); }
.hint b { color: var(--ink); }

/* ===================== HUD (màn chơi) ===================== */
.hud {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(255, 255, 255, .16);
  border: 1px solid rgba(255, 255, 255, .28);
  border-radius: 16px;
  padding: 10px 16px;
  color: #fff;
  backdrop-filter: blur(4px);
}
.hud-item { display: flex; flex-direction: column; align-items: center; gap: 2px; }
.hud-label { font-size: 12px; opacity: .85; }
.hud-value { font-size: 22px; font-weight: 800; }
.hud-lives { flex-direction: row; gap: 4px; font-size: 20px; }
.heart { transition: transform .2s; }
.heart.lost { filter: grayscale(1) opacity(.35); transform: scale(.8); }
.hud-combo .hud-value { color: #ffe08a; }

/* Thanh thời gian */
.timer-wrap {
  height: 12px;
  background: rgba(255, 255, 255, .22);
  border-radius: 999px;
  overflow: hidden;
  margin: 14px 0;
}
.timer-bar {
  height: 100%;
  width: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, #7dffb0, #37d67a);
  transform-origin: left center;
}
.timer-bar.warn { background: linear-gradient(90deg, #ffd76a, #ff9f43); }
.timer-bar.danger { background: linear-gradient(90deg, #ff8a8a, #ff5169); }

/* Thân màn chơi */
.play-body {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px 18px 18px;
  text-align: center;
  margin-bottom: 12px;
}
.progress-line { font-size: 13px; color: var(--ink-soft); }
.progress-line b { color: var(--ink); }

.question {
  font-size: 52px;
  font-weight: 800;
  margin: 18px 0 22px;
  color: var(--ink);
  letter-spacing: 1px;
}
.question.flash { animation: qflash .3s ease; }
@keyframes qflash { 0%{ transform: scale(.9); opacity:.4;} 100%{ transform: scale(1); opacity:1;} }

.answers {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.answer-btn {
  padding: 20px 8px;
  border: 3px solid #e6ebf5;
  background: #f7f9ff;
  border-radius: 16px;
  font-size: 26px;
  font-weight: 800;
  color: var(--ink);
  cursor: pointer;
  transition: transform .08s, border-color .15s, background .15s;
}
.answer-btn:hover:not(:disabled) { border-color: #c9d6f0; transform: translateY(-2px); }
.answer-btn:active:not(:disabled) { transform: scale(.96); }
.answer-btn:disabled { cursor: default; }
.answer-btn.correct {
  background: var(--good); border-color: var(--good-d); color: #fff;
  animation: bounce .45s ease;
}
.answer-btn.wrong {
  background: var(--bad); border-color: var(--bad-d); color: #fff;
  animation: shake .4s ease;
}
@keyframes bounce {
  0%{ transform: scale(1);} 30%{ transform: scale(1.14);} 60%{ transform: scale(.94);} 100%{ transform: scale(1);}
}
@keyframes shake {
  0%,100%{ transform: translateX(0);} 20%{ transform: translateX(-8px);}
  40%{ transform: translateX(8px);} 60%{ transform: translateX(-6px);} 80%{ transform: translateX(6px);}
}

.feedback { min-height: 26px; margin-top: 16px; font-size: 18px; font-weight: 800; }
.feedback.good { color: var(--good-d); }
.feedback.bad { color: var(--bad-d); }

.btn-quit { color: rgba(255, 255, 255, .9); }
.btn-quit:hover { color: #fff; }

/* ===================== Màn kết thúc ===================== */
.end-emoji { font-size: 64px; animation: bob 2s ease-in-out infinite; }
.end-title { font-size: 30px; margin-top: 6px; color: var(--ink); }

.new-record {
  display: inline-block;
  margin: 12px 0 4px;
  padding: 8px 18px;
  background: linear-gradient(90deg, #ffd76a, #ffb347);
  color: #7a4a00;
  border-radius: 999px;
  font-weight: 800;
  animation: pulse 1.2s ease-in-out infinite;
}
@keyframes pulse { 0%,100%{ transform: scale(1);} 50%{ transform: scale(1.06);} }

.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin: 22px 0;
}
.stat { background: #f4f7ff; border-radius: 14px; padding: 14px 6px; }
.stat-value { font-size: 30px; font-weight: 800; color: var(--sel); }
.stat-label { font-size: 12px; color: var(--ink-soft); margin-top: 2px; }

.end-card .btn + .btn { margin-top: 10px; }

/* ===================== Responsive ===================== */
@media (max-width: 380px) {
  .title { font-size: 34px; }
  .question { font-size: 42px; }
  .answer-btn { font-size: 22px; padding: 16px 6px; }
  .option-btn { font-size: 13px; padding: 10px 4px; }
  .card { padding: 22px 16px; }
}
