/* Đố Vui — tươi sáng, thẻ bo tròn */
:root {
  --bg1: #fff4e2;
  --bg2: #e6f2ff;
  --ink: #1f2440;
  --muted: #6b7290;
  --card: #ffffff;
  --line: #e7e2f0;
  --accent: #6c5ce7;
  --ok: #20c065;
  --bad: #ff4d5e;
  --gold: #ffb400;
  --shadow: 0 10px 30px rgba(60, 50, 120, 0.12);
}
* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}
[hidden] {
  display: none !important;
}
html,
body {
  height: 100%;
  margin: 0;
  color: var(--ink);
  font-family: "Be Vietnam Pro", system-ui, sans-serif;
  background: linear-gradient(160deg, var(--bg1), var(--bg2));
  overscroll-behavior: none;
}
button {
  font: inherit;
  color: inherit;
  cursor: pointer;
}
.app {
  position: fixed;
  inset: 0;
  overflow: hidden;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
.screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  overflow: auto;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  animation: fadeIn 0.25s ease-out;
}
@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
}
.grow {
  flex: 1;
}

/* ---------- nút chung ---------- */
.bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 14px;
  flex: none;
}
.bar h2 {
  margin: 0;
  font: 800 22px "Baloo 2", sans-serif;
}
.back {
  color: var(--muted);
  text-decoration: none;
  font-weight: 700;
  font-size: 14px;
  padding: 8px 12px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.7);
}
.icon-btn {
  width: 40px;
  height: 40px;
  flex: none;
  border: 0;
  border-radius: 13px;
  background: rgba(255, 255, 255, 0.85);
  box-shadow: 0 3px 10px rgba(60, 50, 120, 0.1);
  font-size: 17px;
  font-weight: 800;
}
.btn {
  border: 0;
  border-radius: 16px;
  padding: 12px 20px;
  font-weight: 800;
  font-size: 15px;
  background: #fff;
  box-shadow: 0 4px 14px rgba(60, 50, 120, 0.12);
  transition: transform 0.1s;
}
.btn:active {
  transform: scale(0.96);
}
.btn.primary {
  background: linear-gradient(135deg, #7b6cff, #5b4bd6);
  color: #fff;
  box-shadow: 0 8px 22px rgba(91, 75, 214, 0.35);
}
.btn.danger {
  background: transparent;
  color: var(--bad);
  box-shadow: none;
  border: 1px solid rgba(255, 77, 94, 0.4);
  font-size: 13px;
}
.btns {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
}
.pill {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 6px 12px;
  border-radius: 999px;
  background: #fff;
  box-shadow: 0 3px 10px rgba(60, 50, 120, 0.1);
  font-weight: 800;
  font-size: 15px;
  font-variant-numeric: tabular-nums;
}
.pill.streak {
  background: #fff1e0;
  color: #e8590c;
}
.pill.streak.hot {
  animation: pulse 0.5s;
}
@keyframes pulse {
  50% {
    transform: scale(1.18);
  }
}

/* ---------- sảnh ---------- */
.home-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 22px;
  padding: 0 16px 28px;
  text-align: center;
}
.hero {
  position: relative;
}
.bubbles span {
  position: absolute;
  font-size: 30px;
  animation: float 3.5s ease-in-out infinite;
}
.bubbles span:nth-child(1) {
  left: -50px;
  top: -10px;
}
.bubbles span:nth-child(2) {
  right: -46px;
  top: -18px;
  animation-delay: 0.8s;
}
.bubbles span:nth-child(3) {
  left: -20px;
  bottom: 10px;
  animation-delay: 1.4s;
  font-size: 22px;
}
.bubbles span:nth-child(4) {
  right: -30px;
  bottom: 16px;
  animation-delay: 2s;
  font-size: 24px;
}
@keyframes float {
  50% {
    transform: translateY(-10px) rotate(8deg);
  }
}
.logo {
  margin: 0;
  font: 800 clamp(54px, 12vw, 92px) / 1 "Baloo 2", sans-serif;
  color: var(--accent);
  text-shadow: 0 6px 0 rgba(108, 92, 231, 0.15);
}
.logo span {
  color: #ff7a59;
}
.tag {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 15px;
  max-width: 420px;
}
.modes {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  width: min(620px, 100%);
}
.mode {
  border: 0;
  border-radius: 22px;
  padding: 20px 14px 18px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  color: #fff;
  box-shadow: var(--shadow);
  transition: transform 0.15s;
}
.mode:hover {
  transform: translateY(-3px) rotate(-0.5deg);
}
.mode:active {
  transform: scale(0.97);
}
.mode .mi {
  font-size: 34px;
  line-height: 1.1;
}
.mode b {
  font: 800 21px "Baloo 2", sans-serif;
}
.mode small {
  font-size: 13px;
  opacity: 0.92;
  font-weight: 600;
}
.m-quick {
  background: linear-gradient(135deg, #7b6cff, #5b4bd6);
}
.m-surv {
  background: linear-gradient(135deg, #ff7a8a, #e8425a);
}
.m-duel {
  background: linear-gradient(135deg, #2ec5ff, #1c8ee0);
}
.m-daily {
  background: linear-gradient(135deg, #ffc533, #ff9500);
}
.mode.done {
  filter: saturate(0.75);
}
.stats {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

/* ---------- chủ đề ---------- */
.topic-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  width: min(820px, 100%);
  margin: 0 auto;
  padding: 4px 16px 24px;
}
.topic {
  position: relative;
  border: 0;
  border-radius: 20px;
  background: #fff;
  box-shadow: var(--shadow);
  padding: 16px 12px 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  text-align: center;
  transition: transform 0.15s;
  border-top: 6px solid var(--c);
}
.topic:hover {
  transform: translateY(-3px);
}
.topic .ti {
  font-size: 34px;
}
.topic b {
  font-size: 15px;
}
.topic small {
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}
.topic .ts {
  font-size: 14px;
  letter-spacing: 1px;
  color: var(--gold);
}
.topic .ts .off {
  color: #d9d6e6;
}
.topic.mix {
  grid-column: 1 / -1;
  flex-direction: row;
  justify-content: center;
  gap: 12px;
}

/* ---------- câu hỏi ---------- */
.quiz-body {
  flex: 1;
  width: min(760px, 100%);
  margin: 0 auto;
  padding: 0 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.prog {
  display: flex;
  gap: 4px;
}
.prog i {
  width: 18px;
  height: 8px;
  border-radius: 4px;
  background: rgba(31, 36, 64, 0.12);
}
.prog i.ok {
  background: var(--ok);
}
.prog i.bad {
  background: var(--bad);
}
.prog i.cur {
  background: var(--accent);
}
.prog .num {
  font-weight: 800;
  font-size: 14px;
  color: var(--muted);
}
.lives {
  font-size: 18px;
  letter-spacing: 1px;
}
.lives .lost {
  filter: grayscale(1);
  opacity: 0.3;
}
.qcard {
  background: #fff;
  border-radius: 24px;
  box-shadow: var(--shadow);
  padding: 18px 20px 16px;
  animation: pop 0.3s cubic-bezier(0.3, 1.4, 0.5, 1);
}
@keyframes pop {
  from {
    transform: scale(0.94);
    opacity: 0;
  }
}
.qmeta {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.chip {
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
  background: #f1eefc;
  color: var(--accent);
}
.chip.lv {
  background: #f4f4f8;
  color: var(--muted);
}
.chip.lv.l3 {
  background: #ffe9ec;
  color: #d6336c;
}
.qtext {
  margin: 12px 0 14px;
  font-size: clamp(19px, 3.2vw, 25px);
  font-weight: 800;
  line-height: 1.35;
  min-height: 2.7em;
}
.timer {
  position: relative;
  height: 10px;
  border-radius: 5px;
  background: #eeecf6;
  overflow: hidden;
}
.timer i {
  position: absolute;
  inset: 0 auto 0 0;
  width: 100%;
  border-radius: 5px;
  background: linear-gradient(90deg, #20c065, #7be495);
}
.timer i.mid {
  background: linear-gradient(90deg, #ffb400, #ffd666);
}
.timer i.low {
  background: linear-gradient(90deg, #ff4d5e, #ff8a95);
}
.timer b {
  position: absolute;
  right: 6px;
  top: -20px;
  font-size: 12px;
  color: var(--muted);
}
.answers {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}
.ans {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 64px;
  padding: 12px 14px;
  border: 3px solid transparent;
  border-radius: 18px;
  background: #fff;
  box-shadow: 0 5px 0 rgba(60, 50, 120, 0.1), 0 8px 18px rgba(60, 50, 120, 0.08);
  text-align: left;
  font-size: 16px;
  font-weight: 700;
  line-height: 1.3;
  transition:
    transform 0.1s,
    background 0.2s,
    border-color 0.2s,
    opacity 0.2s;
  animation: ansIn 0.35s cubic-bezier(0.3, 1.3, 0.5, 1) backwards;
}
.ans:nth-child(2) {
  animation-delay: 0.05s;
}
.ans:nth-child(3) {
  animation-delay: 0.1s;
}
.ans:nth-child(4) {
  animation-delay: 0.15s;
}
@keyframes ansIn {
  from {
    transform: translateY(14px);
    opacity: 0;
  }
}
.ans:hover:not(:disabled) {
  transform: translateY(-2px);
  border-color: #d8d2fb;
}
.ans:active:not(:disabled) {
  transform: translateY(2px);
}
.ans .key {
  flex: none;
  width: 34px;
  height: 34px;
  border-radius: 11px;
  display: grid;
  place-items: center;
  font-weight: 800;
  color: #fff;
}
.ans:nth-child(1) .key {
  background: #7b6cff;
}
.ans:nth-child(2) .key {
  background: #2ec5ff;
}
.ans:nth-child(3) .key {
  background: #ff9500;
}
.ans:nth-child(4) .key {
  background: #ff5d8f;
}
.ans.ok {
  background: #e5f9ed;
  border-color: var(--ok);
  animation: bounce 0.45s;
}
.ans.ok .key {
  background: var(--ok);
}
.ans.bad {
  background: #ffecee;
  border-color: var(--bad);
  animation: shake 0.4s;
}
.ans.bad .key {
  background: var(--bad);
}
.ans.dim {
  opacity: 0.45;
}
.ans.gone {
  opacity: 0.15;
  pointer-events: none;
}
.ans:disabled {
  cursor: default;
}
@keyframes bounce {
  40% {
    transform: scale(1.05);
  }
}
@keyframes shake {
  20%,
  60% {
    transform: translateX(-6px);
  }
  40%,
  80% {
    transform: translateX(6px);
  }
}
.helps {
  display: flex;
  gap: 8px;
  justify-content: center;
}
.help-btn {
  border: 0;
  border-radius: 14px;
  padding: 9px 14px;
  font-weight: 800;
  font-size: 13px;
  background: #fff;
  box-shadow: 0 4px 12px rgba(60, 50, 120, 0.1);
}
.help-btn:disabled {
  opacity: 0.35;
  cursor: default;
}
.feedback {
  background: #fff;
  border-radius: 20px;
  box-shadow: var(--shadow);
  padding: 14px 16px;
  text-align: center;
  animation: pop 0.25s ease-out;
}
.fb-title {
  margin: 0;
  font: 800 20px "Baloo 2", sans-serif;
}
.fb-title.ok {
  color: var(--ok);
}
.fb-title.bad {
  color: var(--bad);
}
.fb-note {
  margin: 6px 0 10px;
  color: var(--muted);
  font-size: 14px;
}
.fb-note:empty {
  display: none;
}
.float {
  position: fixed;
  z-index: 40;
  pointer-events: none;
  font: 800 26px "Baloo 2", sans-serif;
  color: var(--ok);
  text-shadow: 0 2px 0 #fff;
  animation: floatUp 0.9s ease-out forwards;
}
@keyframes floatUp {
  to {
    transform: translateY(-60px);
    opacity: 0;
  }
}

/* ---------- hai người ---------- */
.duel {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 12px;
  padding: 14px;
}
.duel .p1 {
  grid-column: 1;
  grid-row: 1;
}
.duel .p2 {
  grid-column: 3;
  grid-row: 1;
}
.duel-mid {
  grid-column: 2;
  grid-row: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 58px;
}
.duel-mid .timer {
  width: 10px;
  height: 60%;
}
.duel-mid .timer i {
  inset: auto 0 0 0;
  width: 100%;
  height: 100%;
}
.dprog {
  font-size: 13px;
  color: var(--muted);
}
.side {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 14px;
  border-radius: 24px;
  background: rgba(255, 255, 255, 0.55);
  border: 3px solid transparent;
  transition:
    background 0.2s,
    border-color 0.2s;
  min-height: 0;
}
.side.p1 {
  --pc: #7b6cff;
}
.side.p2 {
  --pc: #ff7a59;
}
@media (min-width: 900px) {
  .side {
    justify-content: center;
    padding: 22px;
    gap: 16px;
  }
  .side .dq {
    font-size: 22px;
    padding: 18px 20px;
  }
  .side .ans {
    min-height: 72px;
    font-size: 16px;
  }
}
.side .who {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 800;
  color: var(--pc);
}
.side .who b {
  margin-left: auto;
  font: 800 30px/1 "Baloo 2", sans-serif;
}
.side .dq {
  margin: 0;
  background: #fff;
  border-radius: 18px;
  padding: 12px 14px;
  font-size: 17px;
  font-weight: 800;
  line-height: 1.35;
  box-shadow: var(--shadow);
}
.side .answers {
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.side .ans {
  min-height: 52px;
  font-size: 14px;
  padding: 8px 10px;
  gap: 8px;
}
.side .ans .key {
  width: 28px;
  height: 28px;
  background: var(--pc) !important;
}
.side.locked {
  background: rgba(255, 77, 94, 0.12);
  border-color: rgba(255, 77, 94, 0.5);
}
.side.won {
  background: rgba(32, 192, 101, 0.14);
  border-color: var(--ok);
}
.side .lock-msg {
  text-align: center;
  font-weight: 800;
  color: var(--bad);
  font-size: 13px;
  min-height: 18px;
}

/* ---------- kết quả ---------- */
.result {
  align-items: center;
  justify-content: flex-start;
  padding-top: max(24px, env(safe-area-inset-top));
}
.res-card {
  width: min(560px, calc(100% - 28px));
  margin: auto;
  background: #fff;
  border-radius: 28px;
  box-shadow: var(--shadow);
  padding: 24px 20px 18px;
  text-align: center;
  animation: pop 0.35s cubic-bezier(0.3, 1.4, 0.5, 1);
}
.res-ico {
  font-size: 54px;
  line-height: 1;
}
.res-card h2 {
  margin: 6px 0 4px;
  font: 800 30px "Baloo 2", sans-serif;
  color: var(--accent);
}
.res-stars {
  font-size: 40px;
  letter-spacing: 6px;
}
.res-stars span {
  display: inline-block;
  color: #e6e3ef;
}
.res-stars span.on {
  color: var(--gold);
  animation: starIn 0.5s cubic-bezier(0.3, 1.6, 0.5, 1) backwards;
}
@keyframes starIn {
  from {
    transform: scale(0) rotate(-120deg);
  }
}
.res-nums {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin: 12px 0;
}
.res-nums div {
  background: #f6f4fc;
  border-radius: 14px;
  padding: 8px 4px;
}
.res-nums small {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}
.res-nums b {
  font-size: 20px;
}
.res-nums .rec {
  display: block;
  font-size: 10px;
  font-weight: 800;
  color: #e8590c;
}
.res-msg {
  margin: 0 0 14px;
  color: var(--muted);
}
.review {
  margin-top: 14px;
  text-align: left;
}
.review summary {
  cursor: pointer;
  font-weight: 800;
  color: var(--accent);
  text-align: center;
}
.review ol {
  padding-left: 22px;
  margin: 10px 0 0;
  display: grid;
  gap: 10px;
}
.review li {
  font-size: 14px;
}
.review li b {
  display: block;
}
.review .ra {
  color: var(--ok);
  font-weight: 700;
}
.review .ry {
  color: var(--bad);
  font-weight: 700;
}
.review .rn {
  color: var(--muted);
  font-size: 13px;
}

/* ---------- phủ ---------- */
.overlay {
  position: absolute;
  inset: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(31, 36, 64, 0.35);
  backdrop-filter: blur(3px);
}
.sheet {
  position: relative;
  width: min(480px, 100%);
  max-height: 100%;
  overflow: auto;
  background: #fff;
  border-radius: 24px;
  padding: 22px 20px 18px;
  box-shadow: var(--shadow);
  animation: pop 0.25s ease-out;
}
.sheet h2 {
  margin: 0 0 8px;
  font: 800 26px "Baloo 2", sans-serif;
  text-align: center;
}
.sheet ul {
  padding-left: 18px;
  font-size: 14px;
  line-height: 1.55;
}
.sheet li {
  margin-bottom: 6px;
}
.sheet .btn {
  display: block;
  margin: 8px auto 0;
}
.close {
  position: absolute;
  right: 10px;
  top: 10px;
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 50%;
  background: #f2f0f8;
  font-size: 22px;
  line-height: 1;
}
.confetti {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 35;
}
.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  translate: -50% 0;
  z-index: 50;
  background: var(--ink);
  color: #fff;
  padding: 10px 18px;
  border-radius: 14px;
  font-weight: 700;
  font-size: 14px;
  pointer-events: none;
}

/* ---------- điện thoại ---------- */
@media (max-width: 640px) {
  .modes {
    gap: 10px;
  }
  .mode {
    padding: 16px 10px 14px;
  }
  .mode .mi {
    font-size: 28px;
  }
  .mode b {
    font-size: 18px;
  }
  .topic-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .answers {
    grid-template-columns: 1fr;
    gap: 9px;
  }
  .ans {
    min-height: 54px;
  }
  .prog i {
    width: 12px;
  }
  .qcard {
    padding: 14px 16px 14px;
  }
  .bubbles {
    display: none;
  }
}
/* điện thoại dọc: hai người chia trên/dưới, nửa trên xoay ngược */
@media (orientation: portrait) and (max-width: 820px) {
  .duel {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr auto 1fr;
    gap: 6px;
    padding: 8px;
  }
  .duel .p2 {
    grid-column: 1;
    grid-row: 1;
    transform: rotate(180deg);
  }
  .duel .p1 {
    grid-column: 1;
    grid-row: 3;
  }
  .duel-mid {
    grid-column: 1;
    grid-row: 2;
    flex-direction: row;
    width: auto;
    height: 40px;
  }
  .duel-mid .timer {
    width: 60%;
    height: 10px;
  }
  .duel-mid .timer i {
    inset: 0 auto 0 0;
  }
  .side {
    padding: 10px;
    gap: 8px;
  }
  .side .dq {
    font-size: 15px;
    padding: 10px 12px;
  }
  .side .ans {
    min-height: 44px;
    font-size: 13px;
  }
  .side .who b {
    font-size: 24px;
  }
}
@media (max-height: 500px) and (orientation: landscape) {
  .home-body {
    gap: 10px;
    padding-bottom: 12px;
  }
  .logo {
    font-size: 46px;
  }
  .tag {
    display: none;
  }
  .modes {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    width: min(820px, 100%);
  }
  .mode {
    padding: 12px 8px;
  }
  .mode .mi {
    font-size: 24px;
  }
  .mode b {
    font-size: 16px;
  }
  .bar {
    padding: 6px 12px;
  }
  .quiz-body {
    gap: 8px;
    padding-bottom: 8px;
  }
  .qcard {
    padding: 10px 14px;
  }
  .qtext {
    margin: 6px 0 8px;
    font-size: 18px;
    min-height: 0;
  }
  .answers {
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }
  .ans {
    min-height: 44px;
    padding: 6px 10px;
    font-size: 14px;
  }
  .ans .key {
    width: 28px;
    height: 28px;
  }
  .topic-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
  .topic {
    padding: 10px 8px;
  }
  .topic .ti {
    font-size: 26px;
  }
  .side .dq {
    font-size: 14px;
    padding: 8px 10px;
  }
  .side .ans {
    min-height: 40px;
    font-size: 13px;
  }
  .side {
    padding: 8px;
    gap: 6px;
  }
}
