/* ============================================================
   VỆ BINH CỬU CHƯƠNG – style.css
   Giao diện vũ trụ thân thiện với trẻ nhỏ, tối ưu cho iPad (cảm ứng)
   ============================================================ */

:root {
  --font: "Baloo 2", "Arial Rounded MT Bold", "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  --orange: #ff6b35;
  --orange-dark: #d84f1d;
  --teal: #2ec4b6;
  --teal-dark: #1e9a8e;
  --yellow: #ffd166;
  --yellow-dark: #e0a800;
  --purple: #7b5ea7;
  --purple-dark: #5a3f85;
  --green: #06d6a0;
  --green-dark: #04a67c;
  --red: #ef476f;
  --red-dark: #c42b52;
  --blue: #118ab2;
  --blue-dark: #0c6a8a;
  --space: #0b1a3a;
  --ink: #2b2d42;
  --ink-soft: #5b5f7a;
  --paper: #ffffff;
  --paper-soft: #f4f6fc;
  --shadow: 0 12px 40px rgba(0, 10, 40, 0.45);
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
  --sar: env(safe-area-inset-right, 0px);
  --pad-w: 250px;
  --pad-key: 62px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--space);
  font-family: var(--font);
  color: var(--ink);
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  overscroll-behavior: none;
  touch-action: none;
}

#app {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  touch-action: none;
}

#game {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

/* ---------- Màn hình (overlay) ---------- */
.screen {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(var(--sat) + 12px) calc(var(--sar) + 12px) calc(var(--sab) + 12px) calc(var(--sal) + 12px);
  pointer-events: none;
  opacity: 1;
  transition: opacity 0.25s ease;
  z-index: 5;
}
.screen.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}
.screen > * { pointer-events: auto; }
.screen.dim { background: rgba(5, 12, 35, 0.55); }

.panel {
  background: var(--paper);
  border-radius: 32px;
  padding: 28px 30px;
  max-width: 760px;
  width: min(100%, 760px);
  max-height: 100%;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
  box-shadow: var(--shadow);
  text-align: center;
  position: relative;
}
.panel.wide { max-width: 900px; width: min(100%, 900px); }
.panel h1, .panel h2 {
  margin: 0 0 8px;
  font-weight: 800;
  line-height: 1.1;
}
.panel h2 { font-size: 34px; color: var(--ink); }
.panel p { margin: 6px 0; font-size: 19px; color: var(--ink-soft); font-weight: 600; }

/* ---------- Nút bấm ---------- */
.btn {
  font-family: var(--font);
  font-weight: 800;
  font-size: 24px;
  line-height: 1;
  border: none;
  border-radius: 999px;
  padding: 18px 34px;
  min-height: 62px;
  color: #fff;
  background: linear-gradient(180deg, var(--orange) 0%, #ff8b5a 100%);
  box-shadow: 0 7px 0 var(--orange-dark), 0 12px 24px rgba(0, 0, 0, 0.18);
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 0.08s ease, box-shadow 0.08s ease, filter 0.15s;
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.15);
  letter-spacing: 0.3px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}
.btn:active, .btn.pressed {
  transform: translateY(5px);
  box-shadow: 0 2px 0 var(--orange-dark), 0 4px 10px rgba(0, 0, 0, 0.18);
}
.btn.big { font-size: 32px; padding: 22px 46px; min-height: 78px; }
.btn.teal { background: linear-gradient(180deg, var(--teal), #4fd8cb); box-shadow: 0 7px 0 var(--teal-dark), 0 12px 24px rgba(0,0,0,0.18); }
.btn.teal:active { box-shadow: 0 2px 0 var(--teal-dark), 0 4px 10px rgba(0,0,0,0.18); }
.btn.purple { background: linear-gradient(180deg, var(--purple), #9b7fc7); box-shadow: 0 7px 0 var(--purple-dark), 0 12px 24px rgba(0,0,0,0.18); }
.btn.purple:active { box-shadow: 0 2px 0 var(--purple-dark), 0 4px 10px rgba(0,0,0,0.18); }
.btn.green { background: linear-gradient(180deg, var(--green), #3ee8b8); box-shadow: 0 7px 0 var(--green-dark), 0 12px 24px rgba(0,0,0,0.18); }
.btn.green:active { box-shadow: 0 2px 0 var(--green-dark), 0 4px 10px rgba(0,0,0,0.18); }
.btn.blue { background: linear-gradient(180deg, var(--blue), #2aa8d4); box-shadow: 0 7px 0 var(--blue-dark), 0 12px 24px rgba(0,0,0,0.18); }
.btn.blue:active { box-shadow: 0 2px 0 var(--blue-dark), 0 4px 10px rgba(0,0,0,0.18); }
.btn.ghost {
  background: #f1f3fa;
  color: var(--ink);
  text-shadow: none;
  box-shadow: 0 6px 0 #cfd4e6, 0 8px 16px rgba(0,0,0,0.08);
}
.btn.ghost:active { box-shadow: 0 2px 0 #cfd4e6; }
.btn.small { font-size: 19px; padding: 12px 22px; min-height: 50px; }
.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  justify-content: center;
  margin-top: 18px;
}

/* ---------- Menu chính ---------- */
#menu .panel {
  background: rgba(255, 255, 255, 0.95);
  padding: 22px 30px 26px;
}
.logo-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 18px;
  flex-wrap: wrap;
}
.logo-row svg {
  width: 150px;
  height: 150px;
  filter: drop-shadow(0 10px 14px rgba(0,0,0,0.25));
  animation: logo-bob 3s ease-in-out infinite;
}
@keyframes logo-bob {
  0%, 100% { transform: translateY(0) rotate(-3deg); }
  50% { transform: translateY(-10px) rotate(3deg); }
}
.title {
  font-size: clamp(42px, 8vw, 72px);
  font-weight: 800;
  line-height: 0.95;
  margin: 0;
  background: linear-gradient(180deg, #2ec4b6 0%, #118ab2 50%, #7b5ea7 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  -webkit-text-stroke: 0;
  filter: drop-shadow(0 3px 0 rgba(0,0,0,0.12));
  letter-spacing: -1px;
}
.title small {
  display: block;
  font-size: 0.36em;
  letter-spacing: 3px;
  color: var(--orange-dark);
  background: none;
  -webkit-text-fill-color: var(--orange-dark);
}
.subtitle { font-size: 21px; color: var(--ink-soft); margin: 10px 0 18px; font-weight: 700; }
.menu-options {
  display: flex;
  gap: 12px;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
  margin-top: 14px;
}
.chip-group {
  display: inline-flex;
  background: #eef1f8;
  border-radius: 999px;
  padding: 5px;
  gap: 4px;
}
.chip-group button {
  font-family: var(--font);
  font-weight: 800;
  font-size: 17px;
  border: none;
  background: transparent;
  color: var(--ink-soft);
  padding: 9px 16px;
  min-height: 42px;
  border-radius: 999px;
  cursor: pointer;
  touch-action: manipulation;
}
.chip-group button.on {
  background: #fff;
  color: var(--orange-dark);
  box-shadow: 0 3px 8px rgba(0,0,0,0.12);
}
.chip-label { font-size: 17px; font-weight: 800; color: var(--ink-soft); margin-right: 4px; }
.toggle-row { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin-top: 12px; }
.toggle {
  font-family: var(--font);
  font-weight: 800;
  font-size: 16px;
  border: 3px solid #dfe3ef;
  background: #f1f3fa;
  color: var(--ink-soft);
  padding: 8px 14px;
  min-height: 42px;
  border-radius: 999px;
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 0.08s;
}
.toggle:active { transform: scale(0.96); }
.toggle.on { background: #e3fff4; border-color: var(--green); color: #05603f; }
.toggle.off { text-decoration: line-through; opacity: 0.8; }
.toggle[disabled] { opacity: 0.5; cursor: default; text-decoration: none; }
.footer-note { margin-top: 14px; font-size: 15px; color: #98a0bd; font-weight: 700; }
.footer-note a { color: var(--blue); text-decoration: none; }

/* ---------- Chọn màn ---------- */
.screen-head {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 12px;
}
.screen-head h2 { flex: 1; text-align: center; margin: 0; }
.tabs {
  display: flex;
  gap: 10px;
  justify-content: center;
  margin: 8px 0 12px;
}
.tab {
  font-family: var(--font);
  font-weight: 800;
  font-size: 20px;
  border: 3px solid #e4e8f3;
  background: #f6f7fb;
  color: var(--ink-soft);
  padding: 12px 24px;
  border-radius: 999px;
  cursor: pointer;
  touch-action: manipulation;
  min-height: 54px;
}
.tab.on { background: var(--yellow); border-color: var(--yellow-dark); color: #6a4a00; }
#op-row { margin: 0 0 8px; }
.mode-desc { font-size: 18px; margin: 0 0 14px; }
.level-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 14px;
  text-align: left;
}
.level-card {
  position: relative;
  background: linear-gradient(180deg, #ffffff, #f4f6fc);
  border: 3px solid #e3e7f2;
  border-radius: 24px;
  padding: 16px 16px 14px;
  cursor: pointer;
  touch-action: manipulation;
  box-shadow: 0 6px 0 #dfe3ef;
  transition: transform 0.08s;
  min-height: 150px;
  display: flex;
  flex-direction: column;
}
.level-card:active { transform: translateY(4px); box-shadow: 0 2px 0 #dfe3ef; }
.level-card .icon { font-size: 40px; line-height: 1; }
.level-card .name { font-size: 22px; font-weight: 800; margin-top: 6px; line-height: 1.15; }
.level-card .desc { font-size: 15px; color: var(--ink-soft); font-weight: 600; margin-top: 2px; }
.level-card .grade {
  position: absolute; top: 12px; right: 12px;
  font-size: 13px; font-weight: 800; color: #fff;
  background: var(--purple); border-radius: 999px; padding: 4px 10px;
}
.level-card .grade.g2 { background: var(--blue); }
.level-card .grade.g3 { background: var(--purple); }
.level-card .grade.gx { background: var(--red); }
.level-card .meta {
  display: flex; align-items: center; justify-content: space-between;
  margin-top: auto; padding-top: 10px; font-size: 16px; font-weight: 800;
}
.level-card .best { color: var(--orange-dark); }
.level-card .stars { color: #ffbf1f; letter-spacing: 2px; font-size: 20px; }
.level-card .stars .off { color: #d5d9e6; }

/* ---------- Bảng cửu chương ---------- */
.table-tabs { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin: 6px 0 14px; }
.table-tabs button {
  font-family: var(--font); font-weight: 800; font-size: 22px;
  width: 54px; height: 54px; border-radius: 50%;
  border: 3px solid #e4e8f3; background: #f6f7fb; color: var(--ink-soft);
  cursor: pointer; touch-action: manipulation;
}
.table-tabs button.on { background: var(--teal); border-color: var(--teal-dark); color: #fff; transform: scale(1.08); }
.table-body {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  text-align: left;
}
.table-col { background: var(--paper-soft); border-radius: 20px; padding: 10px 12px; }
.table-col h3 { margin: 2px 0 6px; font-size: 18px; text-align: center; color: var(--blue-dark); }
.table-col.div h3 { color: var(--purple-dark); }
.table-row {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  font-size: 24px; font-weight: 800; color: var(--ink);
  background: #fff; border-radius: 14px; padding: 6px 12px; margin: 5px 0;
  cursor: pointer; touch-action: manipulation; box-shadow: 0 3px 0 #e3e7f2;
  font-variant-numeric: tabular-nums;
}
.table-row:active, .table-row.speaking { background: #fff4d6; transform: translateY(2px); box-shadow: 0 1px 0 #e3e7f2; }
.table-row .ans { color: var(--orange-dark); }

/* ---------- HUD ---------- */
#hud {
  align-items: flex-start;
  justify-content: stretch;
  padding: calc(var(--sat) + 8px) calc(var(--sar) + 10px) 0 calc(var(--sal) + 10px);
  z-index: 3;
}
#hud > * { pointer-events: none; }
.hud-top {
  width: 100%;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  grid-template-areas: "left center right";
  align-items: start;
  gap: 10px;
}
.hud-left { grid-area: left; display: flex; flex-direction: column; gap: 6px; align-items: flex-start; }
.hud-center { grid-area: center; }
.hud-right { grid-area: right; display: flex; gap: 10px; align-items: center; justify-content: flex-end; }
.score-box {
  background: rgba(255,255,255,0.94);
  border-radius: 18px;
  padding: 6px 16px 4px;
  min-width: 120px;
  box-shadow: 0 4px 14px rgba(0,0,0,0.25);
  line-height: 1;
}
.score-box .label { display: block; font-size: 13px; letter-spacing: 2px; font-weight: 800; color: var(--ink-soft); }
.score-box .value { display: block; font-size: 34px; font-weight: 800; color: var(--orange-dark); transition: transform 0.1s; }
.score-box .value.bump { transform: scale(1.18); }
.stage-chip {
  background: var(--purple); color: #fff; font-weight: 800; font-size: 15px;
  padding: 5px 12px; border-radius: 999px; box-shadow: 0 3px 10px rgba(0,0,0,0.25);
}
.combo-chip {
  background: linear-gradient(90deg, #ff7a00, #ffb800); color: #fff; font-weight: 800; font-size: 16px;
  padding: 5px 12px; border-radius: 999px; box-shadow: 0 3px 10px rgba(0,0,0,0.25);
  transform-origin: left center;
  animation: chip-pop 0.3s ease;
}
@keyframes chip-pop { 0% { transform: scale(0.5); } 60% { transform: scale(1.15); } 100% { transform: scale(1); } }

.hud-center { display: flex; flex-direction: column; align-items: center; gap: 8px; }
.answer-card {
  background: #fff;
  border-radius: 24px;
  padding: 8px 30px 6px;
  font-size: clamp(34px, 5.6vw, 58px);
  font-weight: 800;
  color: var(--ink);
  box-shadow: 0 8px 0 #dfe3ef, 0 14px 30px rgba(0,0,0,0.3);
  line-height: 1.1;
  min-width: 260px;
  text-align: center;
  white-space: nowrap;
  transition: transform 0.15s ease, background 0.2s;
  font-variant-numeric: tabular-nums;
}
.answer-card .typed {
  display: inline-block;
  min-width: 1.1em;
  color: var(--orange);
  border-bottom: 5px solid var(--orange);
  line-height: 1;
  padding: 0 2px;
  text-align: center;
}
.answer-card .typed.empty { color: #c5cbe0; border-bottom-color: #c5cbe0; }
.answer-card .caret {
  display: inline-block; width: 4px; height: 0.9em; background: var(--orange); vertical-align: -0.12em;
  margin-left: 2px; animation: caret-blink 0.9s steps(2) infinite; border-radius: 2px;
}
@keyframes caret-blink { 50% { opacity: 0; } }
.answer-card .op { color: var(--blue); }
.answer-card.pop { animation: card-pop 0.35s ease; }
@keyframes card-pop { 0% { transform: scale(0.7); } 60% { transform: scale(1.08); } 100% { transform: scale(1); } }
.answer-card.shake { animation: card-shake 0.4s ease; background: #ffe3e8; }
@keyframes card-shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-8px); } 40% { transform: translateX(8px); }
  60% { transform: translateX(-5px); } 80% { transform: translateX(5px); }
}
.answer-card.ok { background: #e3fff4; }
.timer {
  display: flex; align-items: center; gap: 8px;
  background: rgba(255,255,255,0.92);
  border-radius: 999px;
  padding: 4px 12px 4px 8px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.25);
}
.timer .bar { width: 150px; height: 12px; background: #e6e9f3; border-radius: 999px; overflow: hidden; }
.timer .fill { height: 100%; width: 100%; background: linear-gradient(90deg, var(--teal), var(--green)); border-radius: 999px; transition: width 0.25s linear; }
.timer .fill.warn { background: linear-gradient(90deg, #ff8a00, #ffcf00); }
.timer .fill.danger { background: linear-gradient(90deg, #ff2d55, #ff7a90); }
.timer .time { font-weight: 800; font-size: 19px; color: var(--ink); min-width: 46px; text-align: right; font-variant-numeric: tabular-nums; }
.timer.danger .time { color: var(--red); animation: blink 0.5s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0.35; } }

.hint {
  background: rgba(43,45,66,0.92); color: #fff; font-weight: 800; font-size: 21px;
  padding: 6px 18px; border-radius: 999px; box-shadow: 0 6px 16px rgba(0,0,0,0.3);
  max-width: 92vw; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  animation: chip-pop 0.3s ease;
}
.hint.bad { background: var(--red); }
.hint.ok { background: var(--green); color: #063b2c; }
.hint.info { background: var(--blue); }
.shields { display: flex; gap: 4px; background: rgba(255,255,255,0.92); border-radius: 999px; padding: 6px 12px; box-shadow: 0 4px 12px rgba(0,0,0,0.25); }
.shields span { font-size: 28px; line-height: 1; transition: transform 0.2s, filter 0.2s; display: inline-block; }
.shields span.lost { filter: grayscale(1) opacity(0.35); transform: scale(0.8); }
.shields span.gain { animation: shield-gain 0.5s ease; }
.shields.hit { animation: shields-hit 0.45s ease; }
@keyframes shield-gain { 0% { transform: scale(0.3); } 60% { transform: scale(1.4); } 100% { transform: scale(1); } }
@keyframes shields-hit { 0%, 100% { transform: translateX(0); } 25% { transform: translateX(-6px); } 50% { transform: translateX(6px); } 75% { transform: translateX(-4px); } }

#btn-pause {
  pointer-events: auto;
  width: 56px; height: 56px; min-height: 56px; padding: 0;
  font-size: 24px; border-radius: 50%;
  background: rgba(255,255,255,0.94); color: var(--ink);
  box-shadow: 0 5px 0 #cfd4e6, 0 8px 16px rgba(0,0,0,0.2);
  text-shadow: none;
}
#btn-pause:active { box-shadow: 0 1px 0 #cfd4e6; }

/* ---------- Bàn phím số ---------- */
#numpad {
  position: absolute;
  right: calc(var(--sar) + 10px);
  bottom: calc(var(--sab) + 10px);
  width: var(--pad-w);
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(4, var(--pad-key));
  grid-template-areas:
    "k7 k8 k9"
    "k4 k5 k6"
    "k1 k2 k3"
    "del k0 fire";
  gap: 8px;
  padding: 10px;
  background: rgba(10, 22, 55, 0.55);
  border: 2px solid rgba(154, 240, 255, 0.35);
  border-radius: 26px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.35);
  z-index: 4;
  touch-action: manipulation;
  transition: opacity 0.25s;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}
#numpad.off { visibility: hidden; opacity: 0; pointer-events: none; }
#numpad .k {
  font-family: var(--font);
  font-weight: 800;
  font-size: 30px;
  line-height: 1;
  border: none;
  border-radius: 18px;
  background: linear-gradient(180deg, #ffffff, #e9edf8);
  color: var(--ink);
  box-shadow: 0 5px 0 #b9c1d8, 0 6px 12px rgba(0,0,0,0.25);
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 0.06s ease, box-shadow 0.06s ease;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 0;
}
#numpad .k:active, #numpad .k.pressed { transform: translateY(4px); box-shadow: 0 1px 0 #b9c1d8, 0 2px 6px rgba(0,0,0,0.25); }
#numpad .k7 { grid-area: k7; } #numpad .k8 { grid-area: k8; } #numpad .k9 { grid-area: k9; }
#numpad .k4 { grid-area: k4; } #numpad .k5 { grid-area: k5; } #numpad .k6 { grid-area: k6; }
#numpad .k1 { grid-area: k1; } #numpad .k2 { grid-area: k2; } #numpad .k3 { grid-area: k3; }
#numpad .k0 { grid-area: k0; } #numpad .del { grid-area: del; } #numpad .fire { grid-area: fire; }
#numpad .del { background: linear-gradient(180deg, #ffe3e8, #ffc7d2); color: var(--red-dark); box-shadow: 0 5px 0 #e39aab, 0 6px 12px rgba(0,0,0,0.25); font-size: 26px; }
#numpad .del:active { box-shadow: 0 1px 0 #e39aab; }
#numpad .fire {
  background: linear-gradient(180deg, var(--orange), #ff8b5a); color: #fff;
  box-shadow: 0 5px 0 var(--orange-dark), 0 6px 12px rgba(0,0,0,0.25);
  font-size: 24px; text-shadow: 0 2px 0 rgba(0,0,0,0.15);
}
#numpad .fire small { font-size: 13px; letter-spacing: 1px; margin-top: 2px; }
#numpad .fire:active, #numpad .fire.pressed { box-shadow: 0 1px 0 var(--orange-dark); }
#numpad .fire.ready { animation: fire-pulse 0.9s ease-in-out infinite; }
@keyframes fire-pulse { 50% { filter: brightness(1.2); } }

/* Màn hình dọc (điện thoại, iPad dọc): bàn phím nằm ngang phía dưới, 2 hàng */
@media (max-aspect-ratio: 1/1) {
  #numpad {
    left: calc(var(--sal) + 10px);
    right: calc(var(--sar) + 10px);
    width: auto;
    grid-template-columns: repeat(6, 1fr);
    grid-template-rows: repeat(2, var(--pad-key));
    grid-template-areas:
      "k1 k2 k3 k4 k5 del"
      "k6 k7 k8 k9 k0 fire";
  }
}

/* ---------- Đếm ngược ---------- */
#countdown { pointer-events: none; }
#countdown .count {
  font-size: clamp(120px, 28vw, 260px);
  font-weight: 800;
  color: #fff;
  text-shadow: 0 8px 0 rgba(0,0,0,0.25), 0 0 40px rgba(154,240,255,0.7);
  -webkit-text-stroke: 4px var(--blue-dark);
  line-height: 1;
  animation: count-pop 1s ease both;
}
#countdown .count.go { color: var(--yellow); -webkit-text-stroke: 4px var(--red-dark); font-size: clamp(90px, 20vw, 190px); }
@keyframes count-pop {
  0% { transform: scale(0.2); opacity: 0; }
  25% { transform: scale(1.2); opacity: 1; }
  70% { transform: scale(1); opacity: 1; }
  100% { transform: scale(1.4); opacity: 0; }
}

/* ---------- Kết quả ---------- */
.result-title { font-size: 40px; margin-bottom: 2px; }
.result-title.timeup { color: var(--blue); }
.result-title.nolife { color: var(--red); }
.result-score {
  font-size: clamp(56px, 12vw, 92px);
  font-weight: 800;
  line-height: 1;
  color: var(--orange-dark);
  margin: 4px 0 0;
}
.result-score-label { font-size: 16px; letter-spacing: 3px; color: var(--ink-soft); font-weight: 800; }
.result-stars { font-size: 52px; line-height: 1; margin: 6px 0; letter-spacing: 4px; color: #ffbf1f; }
.result-stars .off { color: #dfe3ef; }
.result-stars .on { display: inline-block; animation: star-in 0.5s ease both; }
.result-stars .on:nth-child(2) { animation-delay: 0.2s; }
.result-stars .on:nth-child(3) { animation-delay: 0.4s; }
@keyframes star-in { 0% { transform: scale(0) rotate(-90deg); } 70% { transform: scale(1.3) rotate(10deg); } 100% { transform: scale(1) rotate(0); } }
.record-badge {
  display: inline-block;
  background: linear-gradient(90deg, #ffb300, #ff6b35);
  color: #fff; font-weight: 800; font-size: 20px;
  padding: 6px 18px; border-radius: 999px; margin: 6px 0 4px;
  animation: badge-pulse 1s ease-in-out infinite;
  box-shadow: 0 6px 16px rgba(255, 120, 0, 0.35);
}
@keyframes badge-pulse { 50% { transform: scale(1.06); } }
.stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin: 12px 0 8px;
}
.stat {
  background: #f4f6fc; border-radius: 18px; padding: 10px 6px 8px;
}
.stat .v { font-size: 30px; font-weight: 800; line-height: 1; }
.stat .k { font-size: 14px; font-weight: 800; color: var(--ink-soft); margin-top: 4px; }
.stat.ok .v { color: var(--green-dark); }
.stat.bad .v { color: var(--red); }
.stat.combo .v { color: var(--orange-dark); }
.stat.acc .v { color: var(--blue); }
.review { background: #fff4d6; border-radius: 18px; padding: 8px 14px 10px; margin: 8px auto 4px; max-width: 560px; }
.review h3 { margin: 0 0 6px; font-size: 17px; color: #8a5a00; }
.review-chips { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; }
.review-chips span {
  background: #fff; border-radius: 999px; padding: 5px 12px; font-size: 17px; font-weight: 800; color: var(--ink);
  box-shadow: 0 2px 0 #e8d5a8; cursor: pointer; touch-action: manipulation; font-variant-numeric: tabular-nums;
}
.review-chips span b { color: var(--orange-dark); }
.name-entry {
  display: flex; gap: 10px; align-items: center; justify-content: center; flex-wrap: wrap;
  margin: 10px 0 6px;
}
.name-entry input {
  font-family: var(--font); font-weight: 800; font-size: 22px;
  border: 3px solid #dfe3ef; border-radius: 999px; padding: 10px 18px; width: 220px;
  outline: none; color: var(--ink); text-align: center;
  -webkit-user-select: text; user-select: text;
}
.name-entry input:focus { border-color: var(--teal); }
.name-chips { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin-top: 6px; }
.name-chips button {
  font-family: var(--font); font-weight: 800; font-size: 16px;
  background: #eef1f8; border: none; border-radius: 999px; padding: 8px 14px; color: var(--ink-soft);
  cursor: pointer; touch-action: manipulation; min-height: 38px;
}
.leader {
  margin: 10px auto 0; max-width: 420px; text-align: left;
  background: #fffaf0; border-radius: 18px; padding: 10px 16px;
}
.leader h3 { margin: 0 0 6px; font-size: 18px; color: var(--orange-dark); text-align: center; }
.leader ol { margin: 0; padding-left: 26px; font-size: 18px; font-weight: 700; }
.leader li { display: flex; justify-content: space-between; padding: 3px 0; }
.leader li.me { color: var(--orange-dark); }
.leader li span:last-child { font-variant-numeric: tabular-nums; }
.leader .empty { text-align: center; font-size: 16px; color: var(--ink-soft); }

/* ---------- Hướng dẫn ---------- */
.howto-list { text-align: left; display: grid; gap: 12px; margin: 10px 0 6px; }
.howto-item {
  display: flex; gap: 14px; align-items: center;
  background: #f6f7fb; border-radius: 20px; padding: 12px 16px;
}
.howto-item .em { font-size: 38px; line-height: 1; width: 52px; text-align: center; flex-shrink: 0; }
.howto-item .tx { font-size: 19px; font-weight: 700; color: var(--ink); line-height: 1.3; }
.howto-item .tx b { color: var(--orange-dark); }
.tip {
  margin-top: 12px; font-size: 16px; color: var(--ink-soft); font-weight: 700;
  background: #fff4d6; border-radius: 16px; padding: 10px 14px;
}

/* ---------- Toast ---------- */
#toast {
  position: absolute; left: 50%; bottom: calc(var(--sab) + 22px);
  transform: translateX(-50%);
  background: rgba(43,45,66,0.92); color: #fff; font-weight: 800; font-size: 18px;
  padding: 12px 22px; border-radius: 999px; pointer-events: none;
  opacity: 0; transition: opacity 0.3s; z-index: 20; max-width: 90%; text-align: center;
}
#toast.show { opacity: 1; }

/* ---------- Responsive ---------- */
@media (max-width: 700px) {
  :root { --pad-key: 54px; }
  .panel { padding: 20px 16px; border-radius: 24px; }
  .btn { font-size: 20px; padding: 14px 24px; }
  .btn.big { font-size: 26px; padding: 18px 34px; min-height: 66px; }
  .logo-row svg { width: 110px; height: 110px; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .score-box { min-width: 90px; padding: 5px 12px 3px; }
  .score-box .value { font-size: 26px; }
  .shields span { font-size: 22px; }
  .timer .bar { width: 90px; }
  .answer-card { padding: 6px 18px 4px; min-width: 180px; font-size: clamp(30px, 9vw, 44px); }
  .hud-top {
    grid-template-columns: 1fr 1fr;
    grid-template-areas: "left right" "center center";
    gap: 6px 10px;
  }
  .hud-left { flex-direction: row; align-items: center; }
  .hud-center { justify-self: center; }
  .hint { font-size: 17px; padding: 5px 14px; }
  .screen-head h2 { font-size: 22px; white-space: nowrap; }
  .screen-head .btn { font-size: 16px; padding: 10px 14px; min-height: 44px; }
  .tab { font-size: 17px; padding: 10px 16px; }
  .mode-desc { font-size: 16px; }
  .level-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
  .level-card { min-height: 130px; padding: 12px; }
  .level-card .name { font-size: 18px; }
  .table-body { grid-template-columns: 1fr; }
  .table-row { font-size: 20px; padding: 5px 10px; margin: 4px 0; }
  .table-tabs button { width: 46px; height: 46px; font-size: 19px; }
  #numpad .k { font-size: 26px; border-radius: 14px; }
  #numpad { gap: 6px; padding: 8px; border-radius: 20px; }
}
@media (max-height: 900px) {
  #gameover .panel { padding: 16px 26px 18px; }
  .result-title { font-size: 32px; }
  .result-score { font-size: clamp(48px, 9vw, 72px); }
  .result-stars { font-size: 40px; margin: 2px 0; }
  .stats { margin: 8px 0 4px; gap: 8px; }
  .stat { padding: 6px 4px 6px; }
  .stat .v { font-size: 24px; }
  .stat .k { font-size: 13px; }
  .name-entry { margin: 6px 0 2px; }
  .leader { padding: 6px 14px; }
  .leader h3 { font-size: 16px; margin-bottom: 2px; }
  .leader ol { font-size: 16px; }
  #gameover .btn-row { margin-top: 10px; }
  #gameover .btn.big { font-size: 26px; padding: 16px 36px; min-height: 64px; }
}
@media (max-height: 520px) {
  :root { --pad-key: 46px; }
  .logo-row svg { width: 90px; height: 90px; }
  .subtitle { margin: 4px 0 10px; }
  .panel { padding: 16px 22px; }
  .howto-item { padding: 8px 12px; }
  #numpad .k { font-size: 22px; }
  #numpad .fire small { display: none; }
}
