/* Màn chơi + bảng xếp hạng (trang người chơi và host) */
/* ---------- Màn chơi ---------- */
#game { height: 100dvh; display: flex; flex-direction: column; }
.qbar {
  padding: 8px 16px 10px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  display: grid;
  gap: 6px;
}
.qmeta { display: flex; justify-content: space-between; gap: 12px; color: var(--muted); font-weight: 700; }
#qtimer { color: var(--text); min-width: 3ch; text-align: right; }
#qtext { font-size: clamp(18px, 3.2vw, 34px); font-weight: 700; line-height: 1.25; text-align: center; }
.timebar { height: 8px; background: var(--bg); border-radius: 4px; overflow: hidden; }
#timefill { height: 100%; width: 0; background: var(--ok); }
#timefill.urgent { background: var(--danger); }

.stage { flex: 1; min-height: 0; position: relative; display: grid; place-items: center; padding: 8px; }
.stage canvas { display: block; border-radius: 12px; }
.banner {
  position: absolute;
  left: 50%;
  top: 45%;
  transform: translate(-50%, -50%);
  background: rgba(15, 18, 40, .93);
  border: 2px solid var(--line);
  border-radius: 16px;
  padding: 14px 24px;
  text-align: center;
  font-size: clamp(18px, 3vw, 30px);
  font-weight: 800;
  width: max-content;
  max-width: min(92%, 640px);
  pointer-events: none;
}
.banner.good { border-color: var(--ok); color: var(--ok); }
.banner.bad { border-color: var(--danger); color: #ffb3ba; }
.banner small { display: block; font-size: .6em; font-weight: 600; color: var(--muted); }
.banner ol { text-align: left; font-size: .6em; margin: 8px 0 0; padding-left: 1.4em; color: var(--text); }
.banner ol span { float: right; margin-left: 24px; color: var(--muted); }

.controls {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 16px calc(8px + env(safe-area-inset-bottom));
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}
.controls .pad { display: flex; gap: 12px; }
.controls button {
  width: 80px;
  height: 64px;
  border: 0;
  border-radius: 16px;
  background: var(--panel-2);
  color: var(--text);
  font: inherit;
  font-size: 26px;
  font-weight: 800;
  touch-action: none;
}
.controls button.active { background: var(--primary); }
.controls .jump { width: 130px; font-size: 20px; }
.key-hint { display: none; }
.rotate-hint { display: none; }
@media (orientation: portrait) and (pointer: coarse) {
  .rotate-hint { display: block; position: absolute; bottom: 12px; margin: 0; color: var(--muted); font-weight: 600; }
}
/* Điện thoại xoay ngang: đặt nút vào hai khoảng trống bên cạnh sân để sân được to nhất */
@media (orientation: landscape) and (max-height: 560px) {
  .qbar { padding: 4px 12px 6px; gap: 2px; }
  #qtext { font-size: clamp(15px, 4.2vh, 22px); }
  .controls {
    position: fixed;
    inset: auto 0 0 0;
    padding: 0 max(12px, env(safe-area-inset-left)) max(12px, env(safe-area-inset-bottom));
    pointer-events: none;
  }
  .controls .pad, .controls .jump { pointer-events: auto; }
  .controls button { width: 72px; height: 64px; background: rgba(40, 48, 98, .85); }
  .controls .jump { width: 96px; height: 96px; border-radius: 50%; font-size: 17px; }
  .controls .pad { gap: 8px; }
  .controls .pad button { width: 64px; height: 80px; }
}
@media (hover: hover) and (pointer: fine) {
  .controls { display: none; }
  .key-hint { display: inline; }
}

/* ---------- Bảng xếp hạng ---------- */
.podium { display: flex; justify-content: center; align-items: flex-end; gap: 12px; margin: 8px 0 16px; }
.step { display: grid; justify-items: center; gap: 4px; width: min(32%, 180px); }
.step .character { display: block; margin-bottom: 2px; }
.step .pname { font-weight: 800; text-align: center; word-break: break-word; }
.step .pscore { font-weight: 800; }
.step .pcorrect { color: var(--muted); font-size: 13px; margin-top: -4px; }
.step .block {
  width: 100%;
  display: grid;
  place-items: center;
  font-size: 36px;
  font-weight: 800;
  border-radius: 12px 12px 0 0;
}
.step-1 .block { height: 140px; background: linear-gradient(#ffd43b, #f08c00); color: #3b2a00; }
.step-2 .block { height: 100px; background: linear-gradient(#e9ecef, #868e96); color: #222; }
.step-3 .block { height: 72px; background: linear-gradient(#ffa94d, #a0522d); color: #2b1300; }
.step.me .pname { color: var(--primary-2); }
.rest { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; counter-reset: rank 3; }
.rest li {
  counter-increment: rank;
  display: grid;
  grid-template-columns: 44px 26px 1fr auto auto;
  gap: 12px;
  align-items: center;
  background: var(--panel-2);
  border-radius: 10px;
  padding: 8px 12px;
}
.rest li::before { content: "#" counter(rank); color: var(--muted); font-weight: 700; }
.rest li.me { outline: 2px solid var(--primary); }
.rest .pname { font-weight: 700; overflow-wrap: anywhere; }
.rest .pcorrect { color: var(--muted); font-size: 14px; }
.rest .pscore { font-weight: 800; }
#my-rank { font-size: 20px; font-weight: 700; margin: 0; text-align: center; }

/* ---------- Tạm dừng ---------- */
.pause-overlay {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  background: rgba(10, 12, 28, .6);
  backdrop-filter: blur(3px);
}
.pause-box {
  display: grid;
  justify-items: center;
  gap: 4px;
  padding: 24px 40px;
  border-radius: 18px;
  background: var(--panel);
  border: 2px solid var(--line);
  text-align: center;
}
.pause-box strong { font-size: clamp(22px, 4vw, 36px); }
.pause-icon { font-size: clamp(40px, 8vw, 72px); line-height: 1; }

/* ---------- Bảng xếp hạng giữa các câu ---------- */
.standings-card { width: min(820px, 100%); }
.st-head { justify-content: space-between; }
.standings-list { position: relative; }
.st-row {
  position: absolute;
  left: 0;
  right: 0;
  height: 48px;
  display: grid;
  grid-template-columns: 52px 32px 1fr auto auto 80px;
  align-items: center;
  gap: 12px;
  padding: 0 14px;
  border-radius: 12px;
  background: var(--panel-2);
  font-weight: 700;
}
.settled .st-row { transition: transform .8s cubic-bezier(.3, 1.3, .5, 1); }
.st-row.me { outline: 2px solid var(--primary); background: #33307a; }
.st-row.outside::before {
  content: "⋯";
  position: absolute;
  top: -20px;
  left: 50%;
  color: var(--muted);
}
.st-rank { color: var(--muted); }
.st-row .character { display: block; }
.st-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.st-change { min-width: 36px; text-align: center; font-size: 15px; opacity: 0; transition: opacity .4s .6s; }
.settled .st-change { opacity: 1; }
.st-change.up { color: var(--ok); }
.st-change.down { color: var(--danger); }
.st-gain { color: var(--ok); font-size: 15px; min-width: 52px; text-align: right; }
.st-score { text-align: right; font-size: 20px; font-variant-numeric: tabular-nums; }
@media (max-width: 560px) {
  .st-row { grid-template-columns: 40px 24px 1fr auto 60px; gap: 8px; padding: 0 10px; }
  .st-gain { display: none; }
  .st-row .character { width: 22px; height: auto; }
}

/* ---------- Công bố kết quả cuối ---------- */
.lb-anim .rest li,
.lb-anim .step { opacity: 0; animation: lb-in .55s ease-out forwards; animation-delay: var(--d); }
.lb-anim .step .block { transform-origin: bottom; animation: lb-rise .8s cubic-bezier(.2, .9, .3, 1.15) both; animation-delay: var(--d); }
/* Nhân vật trên bục nhún nhảy sau khi được công bố; hạng 1 nhảy cao hơn và toả sáng */
.lb-anim .step .character { animation: lb-bob 1.1s ease-in-out infinite; animation-delay: calc(var(--d) + .8s); }
.lb-anim .step-1 .character { animation: lb-hop .9s ease-in-out infinite, lb-glow 1.8s ease-in-out infinite; animation-delay: calc(var(--d) + .8s); }
@keyframes lb-in { from { opacity: 0; transform: translateY(18px); } to { opacity: 1; transform: none; } }
@keyframes lb-rise { from { transform: scaleY(0); } }
@keyframes lb-glow { 50% { filter: drop-shadow(0 0 14px rgba(255, 212, 59, .8)); } }
@keyframes lb-bob { 50% { transform: translateY(-5px); } }
@keyframes lb-hop { 0%, 100% { transform: translateY(0); } 40% { transform: translateY(-16px); } 60% { transform: translateY(-16px); } }
.reveal-later { opacity: 0; transition: opacity .5s; pointer-events: none; }
.reveal-later.shown { opacity: 1; pointer-events: auto; }
.confetti { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 50; }
@media (prefers-reduced-motion: reduce) {
  .settled .st-row, .st-change { transition: none; }
}

/* Thứ hạng + điểm của người chơi trên thanh câu hỏi */
.me-stat b { color: var(--text); }
#live-rank b { color: var(--primary-2); }
