/* Layout: một màn hình — HUD trên cùng, sân khấu thiên thạch rơi ở giữa, bảng nghĩa và bàn phím ảo ở dưới.
   Giao diện tối duy nhất (không gian), nên chỉ có một bộ màu. */
:root {
  --void: #03050c;
  --deep: #0a1130;
  --panel: rgba(12, 19, 46, 0.82);
  --line: rgba(128, 156, 255, 0.24);
  --ink: #eaf0ff;
  --muted: #95a3cf;
  --laser: #5ff2ff;
  --thrust: #ffb547;
  --danger: #ff4f62;
  --ok: #72ffb6;
  --f-display: "Chakra Petch", "Segoe UI", system-ui, sans-serif;
  --f-body: "Be Vietnam Pro", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { height: 100%; background: var(--void); }
body {
  height: 100%;
  margin: 0;
  background: var(--void);
  color: var(--ink);
  font-family: var(--f-body);
  font-size: 15px;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
}
button { font: inherit; color: inherit; cursor: pointer; }
button:focus-visible { outline: 2px solid var(--laser); outline-offset: 2px; }
[hidden] { display: none !important; }

#sky { position: fixed; inset: 0; width: 100%; height: 100%; z-index: 0; display: block; }

.app {
  position: relative;
  z-index: 1;
  height: 100%;
  max-width: 860px;
  margin: 0 auto;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
}
.app.shake { animation: shake 0.45s; }
@keyframes shake {
  0%, 100% { transform: translate(0, 0); }
  20% { transform: translate(-8px, 4px); }
  40% { transform: translate(7px, -5px); }
  60% { transform: translate(-5px, 3px); }
  80% { transform: translate(4px, -2px); }
}

.screen { height: 100%; display: flex; flex-direction: column; }

/* ---------- Màn hình bắt đầu ---------- */
.start { overflow-y: auto; padding-block: 28px 32px; gap: 26px; }
.eyebrow {
  margin: 0;
  font-family: var(--f-display);
  font-size: 0.78rem;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--laser);
}
.brand h1 {
  margin: 6px 0 10px;
  font-family: var(--f-display);
  font-weight: 700;
  font-size: clamp(2.5rem, 9vw, 4.4rem);
  line-height: 0.95;
  letter-spacing: 0.01em;
  text-transform: uppercase;
  text-wrap: balance;
}
.brand h1 span { color: var(--thrust); display: block; }
.lede { margin: 0; max-width: 54ch; color: var(--muted); line-height: 1.6; }

.picker h2 {
  display: flex; align-items: center; gap: 10px;
  margin: 0 0 12px;
  font-family: var(--f-display); font-weight: 600; font-size: 1.05rem;
  letter-spacing: 0.06em; text-transform: uppercase;
}
.step {
  display: inline-grid; place-items: center;
  width: 24px; height: 24px;
  border: 1px solid var(--laser); color: var(--laser);
  font-size: 0.8rem;
  clip-path: polygon(30% 0, 100% 0, 100% 70%, 70% 100%, 0 100%, 0 30%);
}

.levels { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
.lvl {
  --h: 190;
  position: relative;
  display: grid; grid-template-columns: auto 1fr; grid-template-rows: auto auto;
  column-gap: 10px; align-items: center; text-align: left;
  padding: 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 4px;
  transition: border-color 0.15s, transform 0.15s, box-shadow 0.15s;
}
.lvl:last-child { grid-column: span 2; }
.lvl .planet {
  grid-row: span 2;
  width: 30px; height: 30px; border-radius: 50%;
  background: radial-gradient(circle at 32% 30%, hsl(var(--h) 90% 82%), hsl(var(--h) 70% 48%) 55%, hsl(var(--h) 60% 18%));
  box-shadow: 0 0 14px hsl(var(--h) 90% 60% / 0.35);
}
.lvl b { font-family: var(--f-display); font-size: 1.25rem; line-height: 1; }
.lvl small { color: var(--muted); font-size: 0.78rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lvl:hover { border-color: rgba(95, 242, 255, 0.5); }
.lvl[aria-checked="true"], .diff[aria-checked="true"] {
  border-color: var(--laser);
  box-shadow: 0 0 0 1px var(--laser), 0 0 22px rgba(95, 242, 255, 0.22);
}

.diffs { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
.diff {
  display: flex; flex-direction: column; gap: 4px; text-align: left;
  padding: 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 4px;
}
.diff b { font-family: var(--f-display); font-size: 1.05rem; }
.diff small { color: var(--muted); font-size: 0.8rem; line-height: 1.35; }
.diff em { font-style: normal; font-size: 0.78rem; color: var(--thrust); font-variant-numeric: tabular-nums; }
.diff .sample { font-family: var(--f-display); letter-spacing: 0.18em; color: var(--ink); font-size: 0.9rem; }

.launch-row { display: flex; flex-wrap: wrap; align-items: center; gap: 14px 20px; }
.launch {
  padding: 15px 38px;
  border: 0;
  background: var(--thrust);
  color: #1a0f00;
  font-family: var(--f-display); font-weight: 700; font-size: 1.15rem;
  letter-spacing: 0.14em; text-transform: uppercase;
  clip-path: polygon(14px 0, 100% 0, calc(100% - 14px) 100%, 0 100%);
  box-shadow: 0 0 30px rgba(255, 181, 71, 0.35);
  transition: transform 0.12s, filter 0.12s;
}
.launch:hover { filter: brightness(1.08); }
.launch:active { transform: scale(0.97); }
.launch.small { padding: 12px 28px; font-size: 1rem; }
.best { margin: 0; color: var(--muted); font-size: 0.9rem; font-variant-numeric: tabular-nums; }
.best b { color: var(--ink); }

/* ---------- Màn hình chơi ---------- */
.game { padding-block: 10px 10px; gap: 8px; }
.hud { display: flex; align-items: center; gap: 12px; flex-wrap: nowrap; }
.icon-btn {
  display: grid; place-items: center;
  width: 38px; height: 38px; flex: none;
  background: var(--panel); border: 1px solid var(--line); border-radius: 4px;
}
.icon-btn svg { width: 18px; height: 18px; fill: var(--ink); }
.hud-tag {
  font-family: var(--f-display); font-weight: 600; font-size: 0.85rem;
  letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--laser);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0;
}
.hud-stat { display: flex; flex-direction: column; line-height: 1.1; margin-left: auto; }
.hud-stat + .hud-stat { margin-left: 0; }
.hud-stat .k { font-size: 0.66rem; letter-spacing: 0.14em; text-transform: uppercase; color: var(--muted); }
.hud-stat .v { font-family: var(--f-display); font-weight: 700; font-size: 1.15rem; font-variant-numeric: tabular-nums; }
.lives { display: flex; gap: 5px; flex: none; }
.life {
  width: 16px; height: 18px;
  background: var(--laser);
  clip-path: polygon(50% 0, 100% 18%, 100% 55%, 50% 100%, 0 55%, 0 18%);
  box-shadow: 0 0 10px var(--laser);
  transition: opacity 0.3s, background 0.3s;
}
.life.off { background: rgba(149, 163, 207, 0.25); }

.stage { position: relative; flex: 1 1 auto; min-height: 170px; overflow: hidden; }

.pod {
  position: absolute; left: 50%; top: 0;
  transform: translateX(-50%);
  will-change: transform;
  --c: var(--laser);
  transition: opacity 0.25s;
}
.pod.danger { --c: var(--danger); }
.pod.gone { opacity: 0; }
.pod-trail {
  position: absolute; left: 12%; right: 12%; bottom: 100%;
  height: 90px;
  background: linear-gradient(to top, color-mix(in srgb, var(--c) 35%, transparent), transparent);
  filter: blur(6px);
  pointer-events: none;
}
.pod-body {
  position: relative;
  padding: 14px 18px 12px;
  background: linear-gradient(var(--c), var(--c));
  clip-path: polygon(14px 0, calc(100% - 14px) 0, 100% 14px, 100% calc(100% - 14px), calc(100% - 14px) 100%, 14px 100%, 0 calc(100% - 14px), 0 14px);
}
.pod-body::before {
  content: ""; position: absolute; inset: 1.5px;
  background: radial-gradient(120% 140% at 50% 0%, #142251, #070c22 70%);
  clip-path: inherit;
}
.pod-body > * { position: relative; }
.pod.wrong .pod-body { animation: podshake 0.35s; }
@keyframes podshake {
  0%, 100% { translate: 0; }
  25% { translate: -7px; }
  50% { translate: 6px; }
  75% { translate: -4px; }
}

.slots {
  --n: 5;
  display: flex; justify-content: center; gap: 0.14em;
  font-family: var(--f-display); font-weight: 700;
  font-size: min(2.3rem, calc((100vw - 90px) / (var(--n) * 1.2)), calc(800px / (var(--n) * 1.2)));
  line-height: 1.2;
  text-transform: uppercase;
}
.slot {
  width: 0.92em; text-align: center;
  border-bottom: 0.09em solid rgba(149, 163, 207, 0.55);
  color: var(--ink);
}
.slot.hint { color: var(--thrust); }
.slot.cursor { border-bottom-color: var(--laser); animation: blink 1s steps(2) infinite; }
.slot.bad { color: var(--danger); border-bottom-color: var(--danger); }
.pod.win .slot { color: var(--ok); border-bottom-color: var(--ok); }
.slot.good { color: var(--ok); border-bottom-color: var(--ok); text-shadow: 0 0 12px rgba(114, 255, 182, 0.55); }
.slot.popin { animation: popin 0.28s ease-out; }
@keyframes popin { 0% { transform: scale(1.6); filter: brightness(2); } 100% { transform: scale(1); } }
.slot.hit { animation: hit 0.35s; }
@keyframes hit { 0%, 60% { border-bottom-color: var(--danger); background: rgba(255, 79, 98, 0.18); } }
.slot.ack { animation: ack 0.3s; }
@keyframes ack { 0% { transform: scale(1.3); color: #fff; } }

/* Chữ bay từ phi thuyền tới ô */
.flyer { position: fixed; inset: 0; z-index: 4; pointer-events: none; overflow: hidden; }
.fly {
  position: absolute; left: 0; top: 0;
  font-family: var(--f-display); font-weight: 700; line-height: 1;
  text-transform: uppercase;
  color: #fff;
  text-shadow: 0 0 10px var(--laser), 0 0 22px var(--laser);
  will-change: transform, opacity;
}
.fly.bounced { color: var(--danger); text-shadow: 0 0 10px var(--danger), 0 0 20px var(--danger); }
@keyframes blink { 50% { border-bottom-color: transparent; } }

.fuse { margin-top: 10px; height: 4px; background: rgba(149, 163, 207, 0.18); }
.fuse i { display: block; height: 100%; width: 100%; background: var(--c); transform-origin: left; box-shadow: 0 0 8px var(--c); }

.answer {
  position: absolute; left: 50%; top: 38%; transform: translate(-50%, -50%);
  text-align: center;
  padding: 12px 18px;
  background: rgba(40, 6, 14, 0.85);
  border: 1px solid var(--danger);
  border-radius: 4px;
  max-width: calc(100% - 8px);
  animation: rise 0.3s ease-out;
}
.answer .k { display: block; font-size: 0.72rem; letter-spacing: 0.16em; text-transform: uppercase; color: var(--danger); }
.answer .v { font-family: var(--f-display); font-weight: 700; font-size: 1.7rem; letter-spacing: 0.08em; text-transform: uppercase; overflow-wrap: anywhere; }
@keyframes rise { from { opacity: 0; transform: translate(-50%, -30%); } }

.pop {
  position: absolute; left: 50%; top: 30%;
  font-family: var(--f-display); font-weight: 700; font-size: 1.6rem; color: var(--ok);
  text-shadow: 0 0 14px rgba(114, 255, 182, 0.6);
  pointer-events: none;
  animation: popup 0.9s ease-out forwards;
}
@keyframes popup {
  from { opacity: 1; transform: translate(-50%, 0) scale(0.8); }
  to { opacity: 0; transform: translate(-50%, -50px) scale(1.1); }
}

.ship {
  position: absolute; left: 50%; bottom: 4px;
  width: 54px; height: 61px;
  transform: translateX(-50%);
  filter: drop-shadow(0 0 12px rgba(95, 242, 255, 0.35));
}
.ship .flame { transform-origin: 32px 52px; animation: flicker 0.12s infinite alternate; }
@keyframes flicker { to { transform: scaleY(0.72); } }
.ship.recoil { animation: recoil 0.2s; }
@keyframes recoil { 50% { translate: 0 5px; } }

.console {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 12px 14px 10px;
  display: flex; flex-direction: column; gap: 10px;
}
.def { margin: 0; font-size: 1.04rem; line-height: 1.45; min-height: 2.9em; color: var(--ink); }
.def::before { content: "Nghĩa  ·  "; color: var(--laser); font-family: var(--f-display); font-size: 0.78rem; letter-spacing: 0.14em; text-transform: uppercase; }
.tools { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.timer {
  font-family: var(--f-display); font-weight: 700; font-size: 1.1rem;
  font-variant-numeric: tabular-nums; min-width: 3.6em;
}
.timer.danger { color: var(--danger); }
.streak { font-family: var(--f-display); font-size: 0.85rem; color: var(--thrust); letter-spacing: 0.06em; }
.kb-note { color: var(--muted); font-size: 0.8rem; margin-right: auto; }
.chip-btn {
  padding: 6px 11px;
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 0.8rem; color: var(--muted);
}
.chip-btn:hover { color: var(--ink); border-color: rgba(95, 242, 255, 0.5); }
.chip-btn[aria-pressed="true"] { color: var(--ink); }
.chip-btn:disabled { opacity: 0.4; cursor: default; }
.streak:empty { display: none; }

/* ---------- Bàn phím ảo ---------- */
.kb { display: flex; flex-direction: column; gap: 6px; padding-bottom: 2px; touch-action: manipulation; }
.kb-row { display: flex; gap: 5px; justify-content: center; }
.key {
  flex: 1 1 0; min-width: 0; max-width: 64px;
  height: clamp(42px, 6.4vh, 56px);
  display: grid; place-items: center;
  background: rgba(22, 33, 76, 0.9);
  border: 1px solid var(--line);
  border-bottom-width: 3px;
  border-radius: 5px;
  font-family: var(--f-display); font-weight: 600; font-size: 1.15rem;
  text-transform: uppercase;
  touch-action: manipulation;
}
.key.wide { flex: 1.6 1 0; max-width: 100px; font-size: 0.78rem; white-space: nowrap; color: var(--thrust); }
.key.down { background: var(--laser); color: #021018; border-color: var(--laser); }

/* ---------- Overlay ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 5;
  display: grid; place-items: center;
  padding: 20px max(16px, env(safe-area-inset-right, 0px)) 20px max(16px, env(safe-area-inset-left, 0px));
  background: rgba(2, 4, 12, 0.72);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}
.card {
  width: min(460px, 100%);
  max-height: 100%;
  overflow-y: auto;
  padding: 24px;
  background: linear-gradient(180deg, #0e1840, #070c22);
  border: 1px solid var(--line);
  border-radius: 6px;
  display: flex; flex-direction: column; gap: 14px;
}
.card h3 { margin: 0; font-family: var(--f-display); font-size: 1.7rem; text-transform: uppercase; letter-spacing: 0.04em; text-wrap: balance; }
.muted { margin: 0; color: var(--muted); }
.stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.stats div { display: flex; flex-direction: column; gap: 2px; padding: 10px; border: 1px solid var(--line); border-radius: 4px; }
.stats .k { font-size: 0.68rem; letter-spacing: 0.12em; text-transform: uppercase; color: var(--muted); }
.stats .v { font-family: var(--f-display); font-weight: 700; font-size: 1.5rem; font-variant-numeric: tabular-nums; }
.record { margin: 0; font-family: var(--f-display); color: var(--thrust); letter-spacing: 0.1em; text-transform: uppercase; }
.review h4 { margin: 0 0 8px; font-size: 0.85rem; color: var(--muted); font-weight: 500; letter-spacing: 0.08em; text-transform: uppercase; }
.review ul { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 8px; }
.review li { line-height: 1.4; font-size: 0.92rem; color: var(--muted); }
.review li b { color: var(--ink); font-family: var(--f-display); letter-spacing: 0.04em; margin-right: 6px; }
.card-actions { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; }
.ghost {
  padding: 11px 16px;
  background: transparent; border: 1px solid var(--line); border-radius: 4px;
  color: var(--ink);
}

/* ---------- Màn hình nhỏ ---------- */
@media (max-width: 620px) {
  .diffs { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .levels { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
  .lvl:last-child { grid-column: span 3; }
  .lvl { padding: 10px; column-gap: 8px; }
  .lvl .planet { width: 24px; height: 24px; }
  .hud { gap: 9px; }
  .hud-tag { font-size: 0.75rem; }
  .kb-note { display: none; }
  .def { font-size: 0.98rem; }
}
@media (max-height: 560px) {
  .start { gap: 16px; padding-block: 16px; }
  .brand h1 { font-size: 2.2rem; }
}

@media (prefers-reduced-motion: reduce) {
  .app.shake, .pod.wrong .pod-body, .ship .flame, .slot.cursor { animation: none; }
}
