/* ===== Đấu Trường Triết Học — giao diện ===== */
:root {
  --ink: #1b1d3a;
  --ink-2: #4a4f7d;
  --blue: #3156f5;
  --blue-deep: #2340c9;
  --blue-soft: #e8edff;
  --sun: #ffc93c;
  --sun-deep: #e0a100;
  --sun-soft: #fff4d1;
  --coral: #ff5a5f;
  --coral-deep: #d93c42;
  --mint: #2ed3a0;
  --mint-deep: #17a077;
  --text-ok: #0f7a59;
  --text-bad: #c4252c;
  --on-blue: #e6ebff;
  --line: #dde3fb;
  --r: 22px;
  --shadow: 0 12px 28px -10px rgba(14, 22, 92, 0.5), 0 2px 6px rgba(14, 22, 92, 0.12);
  --shadow-sm: 0 6px 16px -6px rgba(14, 22, 92, 0.35);
  --display: "Dela Gothic One", "Be Vietnam Pro", system-ui, sans-serif;
  --ease: cubic-bezier(0.16, 1, 0.3, 1);
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  font-family: "Be Vietnam Pro", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background-color: var(--blue);
  background-image: conic-gradient(rgba(255, 255, 255, 0.055) 25%, transparent 0 50%, rgba(255, 255, 255, 0.055) 0 75%, transparent 0);
  background-size: 96px 96px;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  caret-color: var(--blue);
  scrollbar-color: rgba(255, 255, 255, 0.45) transparent;
}
::selection { background: var(--sun); color: var(--ink); }
:focus-visible { outline: 3px solid var(--sun); outline-offset: 3px; }
.card :focus-visible, .sidebar :focus-visible, .modal :focus-visible { outline-color: var(--blue); }
button { font: inherit; color: inherit; cursor: pointer; }
input, select { font: inherit; }
a { color: inherit; text-underline-offset: 3px; }
.hidden { display: none !important; }
.ic { width: 1.15em; height: 1.15em; flex: none; vertical-align: -0.2em; }
.mascot { display: block; user-select: none; -webkit-user-drag: none; }
b, .num, .tnum { font-variant-numeric: tabular-nums; }

/* ===== Khối dùng chung ===== */
.card {
  background: #fff;
  border-radius: var(--r);
  box-shadow: var(--shadow);
  color: var(--ink);
}
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 54px;
  padding: 0 22px;
  border: 0;
  border-radius: 16px;
  font-weight: 800;
  font-size: 17px;
  letter-spacing: 0.01em;
  transition: transform 0.08s ease, box-shadow 0.08s ease, filter 0.15s;
  user-select: none;
}
.btn .ic { width: 22px; height: 22px; }
.btn:active:not(:disabled) { transform: translateY(3px); }
.btn:disabled { filter: grayscale(0.8); opacity: 0.55; cursor: not-allowed; }
.btn.primary { background: var(--sun); color: var(--ink); box-shadow: 0 5px 0 var(--sun-deep), 0 12px 22px -10px rgba(14, 22, 92, 0.6); }
.btn.primary:hover:not(:disabled) { filter: brightness(1.04); }
.btn.primary:active:not(:disabled) { box-shadow: 0 2px 0 var(--sun-deep); }
.btn.danger { background: var(--coral); color: var(--ink); box-shadow: 0 4px 0 var(--coral-deep); }
.btn.danger:active { box-shadow: 0 1px 0 var(--coral-deep); }
.btn.ghost { background: rgba(255, 255, 255, 0.14); color: #fff; box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.55); }
.btn.ghost:hover { background: rgba(255, 255, 255, 0.22); }
.card .btn.ghost, .sidebar .btn.ghost, .controls .btn.ghost { background: var(--blue-soft); color: var(--ink); box-shadow: 0 4px 0 var(--line); }
.btn.block { width: 100%; }
.btn.big { min-height: 64px; font-size: 21px; padding: 0 30px; border-radius: 18px; }
.btn.small { min-height: 44px; font-size: 15px; padding: 0 16px; border-radius: 14px; }

.icon-btn {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: #fff;
  color: var(--blue);
  box-shadow: var(--shadow-sm);
}
.icon-btn .ic { width: 22px; height: 22px; }
.icon-btn.off { color: #9aa1c4; background: #f1f3fb; }

.lbl { display: block; font-size: 13px; font-weight: 800; color: var(--ink-2); letter-spacing: 0.02em; margin: 0 0 8px; }
input[type="text"], input:not([type]), input[type="password"] {
  width: 100%;
  height: 54px;
  padding: 0 16px;
  border: 2px solid var(--line);
  border-radius: 14px;
  background: #f7f8ff;
  color: var(--ink);
  font-size: 17px;
  font-weight: 700;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
input::placeholder { color: #7a80a8; font-weight: 500; }
input:focus { border-color: var(--blue); box-shadow: 0 0 0 4px rgba(49, 86, 245, 0.18); background: #fff; }
.err { min-height: 1.2em; margin-top: 10px; color: var(--text-bad); font-weight: 700; font-size: 14px; text-align: center; }

/* ===== Màn hình (người chơi) ===== */
.screen {
  position: fixed;
  inset: 0;
  z-index: 30;
  background: inherit; /* nền đặc, không để khung hình trận lộ ra phía sau */
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}
.wrap {
  max-width: 460px;
  margin: 0 auto;
  padding: calc(18px + var(--safe-t)) 16px calc(28px + var(--safe-b));
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.wrap.narrow { max-width: 400px; min-height: 100%; justify-content: center; }

.brand { text-align: center; color: #fff; padding-top: 4px; }
.brand-row { display: flex; justify-content: center; margin-bottom: 4px; }
.brand-row .mascot {
  width: 74px;
  height: 74px;
  margin: 0 -7px;
  animation: bob 2.6s ease-in-out infinite;
  animation-delay: calc(var(--i) * -0.55s);
  filter: drop-shadow(0 6px 6px rgba(14, 22, 92, 0.35));
}
@keyframes bob { 50% { transform: translateY(-6px); } }
.title {
  margin: 0;
  font-family: var(--display);
  font-weight: 400;
  font-size: clamp(36px, 11vw, 50px);
  line-height: 1.04;
  letter-spacing: -0.01em;
  color: #fff;
  text-shadow: 0 6px 18px rgba(14, 22, 92, 0.45);
}
.title span { display: block; }
.title .hl { color: var(--sun); }
.lead { margin: 10px auto 0; max-width: 32ch; color: var(--on-blue); font-size: 15px; line-height: 1.5; font-weight: 500; text-wrap: balance; }

.join-card { padding: 20px 18px 16px; }
.join-card h2 { font-family: var(--display); font-weight: 400; font-size: 24px; margin: 4px 0 16px; text-align: center; }
.skin-lbl { margin-top: 18px; display: flex; justify-content: space-between; align-items: baseline; }
#skinName { color: var(--blue); font-weight: 800; font-size: 14px; letter-spacing: 0; }
.skins { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 18px; }
.skin {
  position: relative;
  aspect-ratio: 1;
  padding: 4px;
  border: 2px solid transparent;
  border-radius: 16px;
  background: #f1f4ff;
  transition: transform 0.15s var(--ease), background 0.15s, border-color 0.15s;
}
.skin .mascot { width: 100%; height: 100%; }
.skin:active { transform: scale(0.94); }
.skin.on { border-color: var(--blue); background: #e2e8ff; transform: translateY(-2px); }
.skin.on::after {
  content: "";
  position: absolute;
  top: -7px;
  right: -7px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 3px solid #fff;
  background: var(--blue) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='3.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M5 12.5l4.5 4.5L19 7.5'/%3E%3C/svg%3E") center / 13px no-repeat;
}

.howto {
  list-style: none;
  margin: 0;
  padding: 14px;
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.1);
  display: grid;
  gap: 10px;
}
.howto li { display: flex; align-items: center; gap: 12px; color: #fff; font-size: 14.5px; line-height: 1.4; font-weight: 500; }
.howto .ic { width: 36px; height: 36px; padding: 8px; border-radius: 12px; background: #fff; color: var(--blue); }
.host-link { display: inline-flex; align-self: center; align-items: center; gap: 8px; color: var(--on-blue); font-weight: 700; font-size: 14px; padding: 8px 12px; }

/* Phòng chờ */
.lobby-hero { text-align: center; color: #fff; padding-top: 10px; }
.lobby-ring {
  width: 188px;
  height: 188px;
  margin: 0 auto 10px;
  border-radius: 50%;
  background: #fff;
  border: 8px solid var(--me, var(--sun));
  box-shadow: var(--shadow);
  display: grid;
  place-items: center;
}
.lobby-ring .mascot { width: 150px; height: 150px; animation: bob 2.4s ease-in-out infinite; }
.me-name { font-family: var(--display); font-size: 28px; line-height: 1.15; word-break: break-word; }
.me-skin { display: inline-block; margin-top: 8px; padding: 5px 12px; border-radius: 999px; background: var(--sun); color: var(--ink); font-weight: 800; font-size: 13px; }
.lobby-card { padding: 18px; text-align: center; }
.big-count { display: flex; align-items: baseline; justify-content: center; gap: 10px; }
.big-count b { font-family: var(--display); font-weight: 400; font-size: 46px; color: var(--blue); line-height: 1; }
.big-count span { color: var(--ink-2); font-weight: 700; }
.wait { display: flex; align-items: center; justify-content: center; gap: 10px; margin: 12px 0 0; color: var(--ink-2); font-weight: 700; font-size: 15px; }
.wait.light { color: var(--on-blue); }
.wait .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--mint); animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 50% { transform: scale(1.6); opacity: 0.45; } }

/* ===== Trong trận (người chơi) ===== */
#game { position: fixed; inset: 0; width: 100%; height: 100%; touch-action: none; display: block; }
#hud { position: fixed; inset: 0; z-index: 10; pointer-events: none; }
#hud button { pointer-events: auto; }
.hud-left { position: absolute; top: calc(10px + var(--safe-t)); left: 10px; display: flex; flex-direction: column; gap: 8px; align-items: flex-start; }
.hud-right { position: absolute; top: calc(10px + var(--safe-t)); right: 10px; display: flex; flex-direction: column; gap: 8px; align-items: flex-end; }
.lvcard { display: flex; align-items: center; gap: 10px; padding: 8px 12px 8px 8px; border-radius: 18px; box-shadow: var(--shadow-sm); }
.lvbadge { width: 48px; height: 48px; border-radius: 14px; background: var(--blue); color: #fff; display: grid; place-items: center; align-content: center; line-height: 1; }
.lvbadge small { font-size: 9.5px; font-weight: 800; letter-spacing: 0.06em; text-transform: uppercase; opacity: 0.9; }
.lvbadge b { font-family: var(--display); font-weight: 400; font-size: 22px; margin-top: 2px; }
.lvinfo { width: 118px; }
.xpbar { height: 10px; border-radius: 6px; background: var(--blue-soft); overflow: hidden; box-shadow: inset 0 0 0 1.5px var(--line); }
.xpbar div { height: 100%; width: 0; border-radius: 6px; background: var(--sun); box-shadow: inset 0 -3px 0 var(--sun-deep); transition: width 0.4s var(--ease); }
.statrow { display: flex; justify-content: space-between; margin-top: 6px; font-size: 13px; }
.statrow span { display: inline-flex; align-items: center; gap: 3px; color: var(--ink-2); }
.statrow .ic { width: 14px; height: 14px; color: var(--blue); }
.statrow b { color: var(--ink); font-weight: 800; }
.hpcard { padding: 6px; border-radius: 12px; box-shadow: var(--shadow-sm); }
.hpbar { width: 168px; height: 10px; border-radius: 6px; background: #ffe0e1; overflow: hidden; }
.hpbar div { height: 100%; background: var(--coral); border-radius: 6px; transition: width 0.2s; }
.zone-msg { padding: 6px 12px; border-radius: 999px; background: var(--ink); color: #fff; font-size: 12.5px; font-weight: 700; box-shadow: var(--shadow-sm); }
.zone-msg.warn { background: var(--coral); color: var(--ink); animation: pulse-soft 1s ease-in-out infinite; }
@keyframes pulse-soft { 50% { transform: scale(1.05); } }
.toprow { display: flex; gap: 12px; align-items: center; padding: 8px 12px; border-radius: 16px; box-shadow: var(--shadow-sm); font-size: 15px; }
.toprow span { display: inline-flex; align-items: center; gap: 5px; }
.toprow .ic { color: var(--blue); width: 16px; height: 16px; }
.toprow b { font-weight: 800; }
#minimap { border-radius: 14px; border: 3px solid #fff; box-shadow: var(--shadow-sm); display: block; }
.mini-lb { list-style: none; margin: 0; padding: 6px 8px; border-radius: 14px; box-shadow: var(--shadow-sm); font-size: 12px; min-width: 130px; max-width: 150px; }
.mini-lb:empty { display: none; }
.mini-lb li { display: flex; align-items: center; gap: 5px; padding: 2px 0; }
.mini-lb li.me { color: var(--blue); font-weight: 800; }
.mini-lb li.dead { opacity: 0.45; }
.mini-lb .rk { width: 14px; font-weight: 800; color: var(--ink-2); }
.mini-lb i { width: 8px; height: 8px; border-radius: 50%; flex: none; box-shadow: 0 0 0 1.5px var(--ink); }
.mini-lb .nm { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.mini-lb .xp { font-weight: 800; font-variant-numeric: tabular-nums; }
#soundBtn { width: 40px; height: 40px; }
.finale #hud { display: none; }
#feed { position: absolute; left: 10px; bottom: calc(118px + var(--safe-b)); display: flex; flex-direction: column; gap: 5px; max-width: 64vw; }
.feed-line {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px;
  padding: 5px 10px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: var(--shadow-sm);
  font-size: 12.5px;
  color: var(--ink-2);
  transition: opacity 0.6s;
}
.feed-line.fade { opacity: 0; }
.feed-line .ic { width: 14px; height: 14px; color: var(--coral-deep); }
.feed-line b, .h-feed b { display: inline-flex; align-items: center; gap: 5px; color: var(--ink); font-weight: 800; }
.feed-line b::before, .h-feed b::before { content: ""; width: 9px; height: 9px; border-radius: 50%; background: var(--c, var(--blue)); box-shadow: 0 0 0 1.5px var(--ink); }
#centerMsg { position: absolute; left: 0; right: 0; top: 30%; text-align: center; opacity: 0; pointer-events: none; }
#centerMsg .big { display: inline-block; padding: 10px 22px; border-radius: 18px; background: var(--ink); color: var(--sun); font-family: var(--display); font-size: 28px; box-shadow: var(--shadow); }
#centerMsg .small { display: block; width: fit-content; margin: 8px auto 0; padding: 4px 12px; border-radius: 999px; background: #fff; color: var(--ink); font-weight: 700; font-size: 14px; }
#centerMsg.show { animation: center-pop 1.8s var(--ease) both; }
@keyframes center-pop {
  0% { opacity: 0; transform: scale(0.6); }
  12% { opacity: 1; transform: scale(1); }
  80% { opacity: 1; transform: scale(1); }
  100% { opacity: 0; transform: translateY(-16px); }
}
#specMsg { position: absolute; left: 50%; bottom: calc(24px + var(--safe-b)); transform: translateX(-50%); width: max-content; max-width: 90vw; padding: 9px 16px; border-radius: 999px; background: var(--ink); color: #fff; font-size: 13.5px; font-weight: 700; text-align: center; }
#attackBtn {
  position: absolute;
  right: calc(18px + env(safe-area-inset-right, 0px));
  bottom: calc(26px + var(--safe-b));
  width: 92px;
  height: 92px;
  border-radius: 50%;
  border: 5px solid #fff;
  background: var(--coral);
  color: #fff;
  display: grid;
  place-items: center;
  box-shadow: 0 6px 0 var(--coral-deep), 0 14px 24px -8px rgba(14, 22, 92, 0.6);
  touch-action: none;
  overflow: hidden;
  isolation: isolate;
}
#attackBtn .ic { width: 44px; height: 44px; filter: drop-shadow(0 2px 0 rgba(27, 29, 58, 0.35)); }
#attackBtn::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: conic-gradient(rgba(27, 29, 58, 0.5) calc(var(--cd, 0) * 360deg), transparent 0);
  z-index: 1;
}
#attackBtn.press { transform: translateY(4px); box-shadow: 0 2px 0 var(--coral-deep); }
#ping { position: absolute; left: 8px; bottom: calc(4px + var(--safe-b)); font-size: 10px; color: rgba(27, 29, 58, 0.45); font-weight: 600; }
#vignette { position: fixed; inset: 0; z-index: 5; pointer-events: none; background: radial-gradient(ellipse at center, transparent 45%, rgba(255, 90, 95, 0.5) 100%); animation: pulse-vig 0.9s ease-in-out infinite alternate; }
@keyframes pulse-vig { from { opacity: 0.6; } to { opacity: 1; } }
#toast {
  position: fixed;
  left: 50%;
  top: calc(64px + var(--safe-t));
  z-index: 70;
  transform: translate(-50%, -12px);
  max-width: 88vw;
  width: max-content;
  padding: 10px 18px;
  border-radius: 999px;
  background: var(--ink);
  color: #fff;
  font-weight: 700;
  font-size: 14px;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.3s var(--ease);
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#conn { position: fixed; top: 0; left: 0; right: 0; z-index: 90; padding: calc(8px + var(--safe-t)) 12px 8px; background: var(--sun); color: var(--ink); text-align: center; font-weight: 800; font-size: 14px; }

/* ===== Câu hỏi ===== */
.modal, .overlay {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(12px + var(--safe-t)) 12px calc(12px + var(--safe-b));
  background: rgba(18, 24, 72, 0.55);
  overflow-y: auto;
}
.qbox {
  width: 100%;
  max-width: 520px;
  margin: auto;
  padding: 16px;
  border-radius: 26px;
  background: #fff;
  box-shadow: var(--shadow);
  animation: sheet 0.35s var(--ease) both;
}
@keyframes sheet { from { transform: translateY(24px); opacity: 0.4; } }
.qhead { display: flex; align-items: center; gap: 8px; }
.qtag { display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: 999px; background: var(--blue); color: #fff; font-weight: 800; font-size: 13px; }
.qtag .ic { width: 16px; height: 16px; }
.qstreak:empty { display: none; }
.qstreak { display: inline-flex; align-items: center; gap: 4px; padding: 6px 10px; border-radius: 999px; background: var(--sun-soft); color: var(--ink); font-weight: 800; font-size: 13px; }
.qstreak .ic { width: 15px; height: 15px; color: var(--coral-deep); }
.qsec { margin-left: auto; font-family: var(--display); font-size: 20px; color: var(--ink); font-variant-numeric: tabular-nums; }
.qsec.hurry { color: var(--text-bad); animation: pulse-soft 0.5s ease-in-out infinite; }
.qtimer { height: 8px; margin: 12px 0 14px; border-radius: 4px; background: var(--blue-soft); overflow: hidden; }
#qTimerBar { height: 100%; width: 100%; background: var(--blue); border-radius: 4px; }
.qtext { font-size: 18px; font-weight: 700; line-height: 1.45; margin-bottom: 14px; text-wrap: pretty; }
.qopts { display: grid; gap: 9px; }
.qopt {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 56px;
  padding: 10px 12px;
  border: 2px solid var(--line);
  border-radius: 16px;
  background: #f5f7ff;
  box-shadow: 0 3px 0 var(--line);
  text-align: left;
  font-size: 15.5px;
  font-weight: 600;
  line-height: 1.35;
  color: var(--ink);
  transition: transform 0.08s, background 0.15s, border-color 0.15s;
}
.qopt:active:not(:disabled) { transform: translateY(2px); box-shadow: 0 1px 0 var(--line); }
.ql { flex: none; width: 34px; height: 34px; border-radius: 11px; display: grid; place-items: center; font-family: var(--display); font-size: 15px; color: var(--ink); background: var(--sun); }
.qopt:nth-child(1) .ql { background: var(--blue); color: #fff; }
.qopt:nth-child(2) .ql { background: var(--coral); }
.qopt:nth-child(3) .ql { background: var(--sun); }
.qopt:nth-child(4) .ql { background: var(--mint); }
.qopt.chosen { border-color: var(--blue); background: var(--blue-soft); }
.qopt:disabled { opacity: 0.5; cursor: default; }
.qopt.correct { opacity: 1; background: var(--mint); border-color: var(--mint-deep); box-shadow: 0 3px 0 var(--mint-deep); }
.qopt.correct .ql { background: #fff; color: var(--ink); }
.qopt.wrong { opacity: 1; background: var(--coral); border-color: var(--coral-deep); box-shadow: 0 3px 0 var(--coral-deep); }
.qopt.wrong .ql { background: #fff; color: var(--ink); }
.qfeedback:empty { display: none; }
.qfeedback { display: flex; align-items: center; justify-content: center; gap: 8px; margin-top: 14px; font-family: var(--display); font-size: 19px; }
.qfeedback .ic { width: 24px; height: 24px; }
.qfeedback.ok { color: var(--text-ok); }
.qfeedback.bad { color: var(--text-bad); }
.qexplain { margin-top: 10px; padding: 12px 14px; border-radius: 14px; background: var(--sun-soft); font-size: 14.5px; line-height: 1.5; }
.qshield { display: flex; align-items: center; justify-content: center; gap: 6px; margin-top: 12px; color: var(--ink-2); font-size: 12.5px; font-weight: 600; }
.qshield .ic { color: var(--blue); width: 16px; height: 16px; }

/* ===== Bị hạ gục ===== */
.dead-card { max-width: 360px; width: 100%; padding: 22px 20px; text-align: center; animation: sheet 0.35s var(--ease) both; }
.dead-ic { width: 72px; height: 72px; margin: 0 auto 10px; border-radius: 22px; background: var(--blue-soft); display: grid; place-items: center; color: var(--ink); }
.dead-ic .ic { width: 40px; height: 40px; }
.dead-card h2 { margin: 0 0 6px; font-family: var(--display); font-weight: 400; font-size: 22px; line-height: 1.25; }
.sub { margin: 0 0 14px; color: var(--ink-2); font-weight: 600; font-size: 15px; line-height: 1.45; }

/* ===== Màn chiến thắng ===== */
.victory {
  position: fixed;
  inset: 0;
  z-index: 50;
  pointer-events: none;
  overflow: hidden;
  background: radial-gradient(ellipse at 50% 55%, transparent 28%, rgba(18, 24, 72, 0.55) 100%);
}
.v-rays {
  position: absolute;
  left: 50%;
  top: 52%;
  width: 170vmax;
  height: 170vmax;
  margin: -85vmax 0 0 -85vmax;
  background: repeating-conic-gradient(rgba(255, 201, 60, 0.32) 0 9deg, transparent 9deg 18deg);
  -webkit-mask: radial-gradient(circle, #000 6%, transparent 38%);
  mask: radial-gradient(circle, #000 6%, transparent 38%);
  opacity: 0;
}
.v-title {
  position: absolute;
  left: 12px;
  right: 12px;
  top: calc(11% + var(--safe-t));
  text-align: center;
  font-family: var(--display);
  font-size: clamp(46px, 13vw, 124px);
  line-height: 1;
  color: var(--sun);
  -webkit-text-stroke: 0.06em var(--ink);
  paint-order: stroke fill;
  text-shadow: 0 10px 30px rgba(14, 22, 92, 0.55);
  opacity: 0;
}
.v-card {
  position: absolute;
  left: 50%;
  bottom: calc(9% + var(--safe-b));
  display: flex;
  align-items: center;
  gap: 14px;
  width: max-content;
  max-width: calc(100vw - 32px);
  padding: 12px 22px 12px 12px;
  border-radius: 26px;
  background: #fff;
  box-shadow: var(--shadow);
  transform: translateX(-50%);
  opacity: 0;
}
.victory.mine .v-card { box-shadow: 0 0 0 5px var(--sun), var(--shadow); }
.v-mascot { width: 86px; height: 86px; flex: none; }
.v-name { font-family: var(--display); font-size: 26px; line-height: 1.15; word-break: break-word; }
.v-sub { margin-top: 3px; color: var(--ink-2); font-weight: 700; font-size: 14px; }
.victory.go .v-card { animation: v-card 0.7s var(--ease) 0.1s both; }
.victory.go .v-title { animation: v-slam 0.75s var(--ease) 0.9s both; }
.victory.go .v-rays { animation: v-rays-in 0.6s ease-out 0.9s both, spin 16s linear 0.9s infinite; }
@keyframes v-card { from { opacity: 0; transform: translate(-50%, 50px) scale(0.92); } to { opacity: 1; transform: translate(-50%, 0); } }
@keyframes v-slam {
  0% { opacity: 0; transform: scale(3.2) rotate(-12deg); filter: blur(6px); }
  35% { opacity: 1; filter: blur(0); }
  100% { opacity: 1; transform: scale(1) rotate(-4deg); }
}
@keyframes v-rays-in { to { opacity: 1; } }
@keyframes spin { to { transform: rotate(360deg); } }
#confetti { position: fixed; inset: 0; width: 100%; height: 100%; z-index: 60; pointer-events: none; }

/* ===== Kết thúc (người chơi) ===== */
.end-title { margin: 6px 0 0; text-align: center; color: #fff; font-family: var(--display); font-weight: 400; font-size: 28px; }
.my-place { display: flex; align-items: center; gap: 14px; padding: 14px 18px 14px 12px; }
.my-place .mascot { width: 84px; height: 84px; flex: none; }
.my-place .lbl { margin: 0; text-transform: uppercase; letter-spacing: 0.06em; font-size: 12px; }
.my-place .num { font-family: var(--display); font-size: 44px; line-height: 1.05; color: var(--blue); }
.my-place .of { color: var(--ink-2); font-weight: 600; font-size: 14px; }
.my-place.champ { background: var(--sun); }
.my-place.champ .num, .my-place.champ .lbl, .my-place.champ .of { color: var(--ink); }
.end-stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.end-stats:empty { display: none; }
.st { display: grid; justify-items: center; gap: 2px; padding: 10px 4px; border-radius: 16px; background: #fff; box-shadow: var(--shadow-sm); }
.st .ic { width: 18px; height: 18px; color: var(--blue); }
.st b { font-family: var(--display); font-weight: 400; font-size: 20px; }
.st span { font-size: 11.5px; color: var(--ink-2); font-weight: 700; }

.podium { display: flex; align-items: flex-end; justify-content: center; gap: 8px; margin-top: 8px; }
.pod { flex: 1; max-width: 140px; min-width: 0; text-align: center; color: #fff; }
.pod-av { width: 72px; height: 72px; margin: 0 auto -6px; position: relative; z-index: 1; filter: drop-shadow(0 6px 6px rgba(14, 22, 92, 0.35)); }
.pod1 .pod-av { width: 92px; height: 92px; }
.pod-name { margin-top: 8px; font-weight: 800; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pod-xp { display: flex; align-items: center; justify-content: center; gap: 3px; margin: 2px 0 6px; font-size: 12px; color: var(--on-blue); font-weight: 600; }
.pod-xp .ic { width: 13px; height: 13px; }
.pod-xp b { color: #fff; }
.pod-bar { display: grid; place-items: start center; padding-top: 8px; border-radius: 16px 16px 6px 6px; color: var(--ink); font-family: var(--display); font-size: 32px; box-shadow: var(--shadow-sm); }
.pod1 .pod-bar { height: 118px; background: var(--sun); box-shadow: inset 0 -8px 0 var(--sun-deep), var(--shadow-sm); }
.pod2 .pod-bar { height: 88px; background: #fff; box-shadow: inset 0 -8px 0 var(--line), var(--shadow-sm); }
.pod3 .pod-bar { height: 66px; background: var(--coral); box-shadow: inset 0 -8px 0 var(--coral-deep), var(--shadow-sm); }
.podium.reveal .pod { animation: rise 0.8s var(--ease) both; }
.podium.reveal .pod3 { animation-delay: 0.25s; }
.podium.reveal .pod2 { animation-delay: 0.95s; }
.podium.reveal .pod1 { animation-delay: 1.75s; }
.podium.instant .pod { animation: none; }
@keyframes rise { from { opacity: 0; transform: translateY(70px) scale(0.9); } }

.awards { display: grid; gap: 8px; }
.award { padding: 12px 14px; border-radius: 18px; background: #fff; box-shadow: var(--shadow-sm); }
.aw-t { display: flex; align-items: center; gap: 6px; color: var(--blue); font-weight: 800; font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; }
.aw-t .ic { width: 16px; height: 16px; }
.aw-who { display: flex; align-items: center; gap: 8px; margin-top: 4px; }
.aw-av { width: 40px; height: 40px; flex: none; }
.aw-n { font-weight: 800; font-size: 17px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.aw-d { color: var(--ink-2); font-size: 13px; font-weight: 600; margin-top: 2px; }

/* ===== Máy chiếu ===== */
body.host { overflow: hidden; }
#hLobby {
  height: 100vh;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.05fr);
  gap: 48px;
  padding: 44px 56px;
}
.hl-left { display: flex; flex-direction: column; align-items: flex-start; min-height: 0; }
.host .brand-row { justify-content: flex-start; margin: 0 0 6px 8px; }
.host .brand-row .mascot { width: 92px; height: 92px; margin: 0 -8px; }
.host #hLobby .title { font-size: clamp(54px, 5.6vw, 96px); }
.qr-card { margin-top: auto; display: grid; justify-items: center; gap: 12px; padding: 22px 26px; border-radius: 30px; background: #fff; box-shadow: var(--shadow); }
.qr { width: min(36vh, 380px); height: min(36vh, 380px); display: block; }
.qr-cap { display: flex; align-items: center; gap: 8px; font-weight: 800; font-size: 20px; }
.qr-cap .ic { color: var(--blue); }
.join-url { font-weight: 800; font-size: 26px; color: var(--blue); letter-spacing: 0.01em; }
.hl-right { display: flex; flex-direction: column; gap: 20px; min-height: 0; }
.h-count { display: flex; align-items: baseline; gap: 16px; color: #fff; }
.h-count b { font-family: var(--display); font-weight: 400; font-size: 120px; line-height: 0.9; }
.h-count span { font-size: 26px; font-weight: 700; color: var(--on-blue); }
.chips { flex: 1; min-height: 0; overflow-y: auto; display: flex; flex-wrap: wrap; align-content: flex-start; gap: 10px; padding: 4px; }
.chips-empty { color: var(--on-blue); font-size: 20px; font-weight: 600; padding: 12px 4px; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 4px 16px 4px 4px;
  border-radius: 999px;
  background: #fff;
  box-shadow: var(--shadow-sm);
  font-weight: 800;
  font-size: 18px;
  max-width: 100%;
}
.chip .mascot { width: 40px; height: 40px; border-radius: 50%; background: #eef1ff; background: color-mix(in srgb, var(--c) 22%, white); }
.chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip.off { opacity: 0.5; }
.chip.new { animation: chip-in 0.5s var(--ease) both; }
@keyframes chip-in { from { transform: scale(0.4); opacity: 0; } }
.controls { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 14px; padding: 18px; }
.dur { display: grid; gap: 6px; font-size: 13px; font-weight: 800; color: var(--ink-2); }
.dur select { height: 50px; padding: 0 12px; border: 2px solid var(--line); border-radius: 14px; background: #f7f8ff; color: var(--ink); font-weight: 700; font-size: 16px; accent-color: var(--blue); }
.controls #startBtn { grid-column: 2; }
.controls .ctrl-row { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 10px; }
.set-summary {
  grid-column: 1 / -1;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 0;
  border: 0;
  background: none;
  text-align: left;
  cursor: pointer;
}
.set-summary:empty { display: none; }
.set-chip { display: inline-flex; align-items: center; gap: 5px; padding: 5px 10px; border-radius: 999px; background: #f1f3fb; color: var(--ink-2); font-size: 13px; font-weight: 700; font-variant-numeric: tabular-nums; }
.set-chip .ic { width: 14px; height: 14px; color: var(--blue); }
.set-summary:hover .set-chip { background: var(--blue-soft); }

/* ===== Cài đặt trận (quản trò) ===== */
.set-box {
  width: min(1120px, 100%);
  max-height: calc(100vh - 32px);
  margin: auto;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  border-radius: 26px;
  background: #fff;
  box-shadow: var(--shadow);
  animation: sheet 0.35s var(--ease) both;
}
.set-head { display: flex; align-items: center; gap: 14px; padding: 18px 20px 14px 24px; border-bottom: 2px solid var(--line); }
.set-head h2 { display: flex; align-items: center; gap: 10px; margin: 0; font-family: var(--display); font-weight: 400; font-size: 24px; }
.set-head h2 .ic { width: 26px; height: 26px; color: var(--blue); }
.set-note { flex: 1; color: var(--ink-2); font-size: 14px; font-weight: 600; }
.set-head .icon-btn { background: #f1f3fb; box-shadow: none; color: var(--ink); }
.set-body { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 280px; gap: 18px 26px; padding: 18px 24px; overflow-y: auto; }
.set-col { display: grid; align-content: start; gap: 16px; }
.set-group { margin: 0; padding: 0; border: 0; display: grid; gap: 12px; }
.set-group legend { display: flex; align-items: center; gap: 8px; padding: 0; margin-bottom: 4px; color: var(--blue); font-size: 13px; font-weight: 800; letter-spacing: 0.06em; text-transform: uppercase; }
.set-group legend .ic { width: 17px; height: 17px; }
.set-field { display: grid; gap: 4px; }
.set-top { display: flex; align-items: baseline; gap: 8px; }
.set-top label { flex: 1; font-weight: 700; font-size: 15px; }
.set-val { font-weight: 800; font-size: 15px; color: var(--ink); font-variant-numeric: tabular-nums; white-space: nowrap; }
.set-def { padding: 2px 8px; border: 0; border-radius: 999px; background: var(--sun-soft); color: var(--ink-2); font-size: 12px; font-weight: 700; cursor: pointer; white-space: nowrap; }
.set-def:hover { background: var(--sun); color: var(--ink); }
.set-def[hidden] { display: none; }
.set-hint { min-height: 1em; color: var(--ink-2); font-size: 12.5px; font-weight: 500; line-height: 1.35; }
.set-hint:empty { display: none; }
.set-field input[type=range] {
  --p: 50%;
  width: 100%;
  height: 26px;
  margin: 0;
  background: transparent;
  -webkit-appearance: none;
  appearance: none;
  cursor: pointer;
}
.set-field input[type=range]::-webkit-slider-runnable-track { height: 10px; border-radius: 999px; background: linear-gradient(90deg, var(--blue) var(--p), var(--blue-soft) var(--p)); }
.set-field input[type=range]::-moz-range-track { height: 10px; border-radius: 999px; background: linear-gradient(90deg, var(--blue) var(--p), var(--blue-soft) var(--p)); }
.set-field input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 24px; height: 24px; margin-top: -7px; border: 4px solid #fff; border-radius: 50%; background: var(--blue); box-shadow: 0 2px 6px rgba(14, 22, 92, 0.35); }
.set-field input[type=range]::-moz-range-thumb { width: 16px; height: 16px; border: 4px solid #fff; border-radius: 50%; background: var(--blue); box-shadow: 0 2px 6px rgba(14, 22, 92, 0.35); }
.set-field input[type=range]:focus-visible { outline: 3px solid var(--blue); outline-offset: 2px; border-radius: 999px; }
.set-preview { margin: 0; display: grid; grid-template-rows: minmax(0, 1fr) auto; gap: 8px; min-height: 420px; padding: 10px; border-radius: 18px; background: var(--blue-soft); }
.set-preview canvas { width: 100%; height: 100%; min-height: 0; border-radius: 12px; background: #f6f8ff; }
.set-preview figcaption { text-align: center; color: var(--ink-2); font-size: 12.5px; font-weight: 700; }
.set-foot { display: flex; align-items: center; gap: 12px; padding: 14px 24px 18px; border-top: 2px solid var(--line); }
.set-foot .btn.ghost { background: var(--blue-soft); color: var(--ink); box-shadow: 0 4px 0 var(--line); }
.set-msg { flex: 1; color: var(--ink-2); font-weight: 700; font-size: 14px; }
@media (max-width: 1100px) {
  .set-body { grid-template-columns: minmax(0, 1fr); }
  .set-preview { min-height: 360px; }
  .set-note { display: none; }
}
.toggles { display: flex; gap: 8px; }
.controls .toggles { grid-column: 3; grid-row: 1; }
.controls .icon-btn, .sidebar .icon-btn { background: var(--blue-soft); box-shadow: none; }
.controls .icon-btn.off, .sidebar .icon-btn.off { background: #f1f3fb; }
.qstatus { grid-column: 1 / -1; font-size: 15px; font-weight: 700; }
.qstatus .ok { display: flex; align-items: center; gap: 8px; color: var(--text-ok); }
.qstatus .bad { display: flex; align-items: center; gap: 8px; color: var(--text-bad); }
.qstatus .small { font-size: 13px; font-weight: 600; }

#hGame { height: 100vh; display: grid; grid-template-columns: minmax(0, 1fr) 390px; }
.h-canvas-wrap { position: relative; min-width: 0; min-height: 0; }
#hCanvas { display: block; }
.sidebar {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 0;
  padding: 20px 20px 14px;
  background: #fff;
  color: var(--ink);
  box-shadow: -10px 0 30px -12px rgba(14, 22, 92, 0.5);
  scrollbar-color: rgba(27, 29, 58, 0.25) transparent;
}
.side-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.host-actions { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.host-actions .btn { flex: none; white-space: nowrap; }
.h-timer { font-family: var(--display); font-size: 64px; line-height: 1; font-variant-numeric: tabular-nums; }
.pill { padding: 9px 14px; border-radius: 14px; background: var(--blue-soft); font-weight: 800; font-size: 16px; }
.pill:empty { display: none; }
.pill.warn { background: var(--coral); animation: pulse-soft 1s ease-in-out infinite; }
.h-phase.warn { animation: none; background: var(--ink); color: #fff; }
.h-alive { display: flex; align-items: baseline; gap: 8px; font-size: 17px; color: var(--ink-2); font-weight: 700; }
.h-alive .ic { align-self: center; color: var(--blue); width: 24px; height: 24px; }
.h-alive b { font-family: var(--display); font-weight: 400; font-size: 34px; color: var(--ink); }
.late-qr { display: flex; align-items: center; gap: 14px; padding: 10px; border-radius: 18px; background: var(--sun-soft); font-size: 16px; font-weight: 700; line-height: 1.4; }
.late-qr img { width: 112px; height: 112px; border-radius: 10px; background: #fff; }
.sidebar h3 { display: flex; align-items: center; gap: 7px; margin: 4px 0 0; font-size: 13px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-2); }
.sidebar h3 .ic { width: 17px; height: 17px; color: var(--blue); }
.h-lb { list-style: none; margin: 0; padding: 0; display: grid; gap: 3px; }
.h-lb li { display: grid; grid-template-columns: 24px 32px minmax(0, 1fr) auto auto 52px; align-items: center; gap: 8px; padding: 3px 8px 3px 6px; border-radius: 12px; font-size: 15.5px; }
.h-lb li:first-child { background: var(--sun-soft); }
.h-lb li:nth-child(n + 9) { display: none; }
@media (min-height: 1000px) { .h-lb li:nth-child(n + 9) { display: grid; } }
.h-lb li.dead { opacity: 0.4; }
.h-lb .rk { font-family: var(--display); color: var(--ink-2); font-size: 14px; text-align: center; }
.h-lb .mascot { width: 32px; height: 32px; }
.h-lb .nm { font-weight: 800; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.h-lb .lv { font-size: 12px; font-weight: 800; padding: 2px 6px; border-radius: 6px; background: var(--ink); color: #fff; }
.h-lb .k { display: inline-flex; align-items: center; gap: 2px; color: var(--ink-2); font-weight: 700; font-size: 14px; }
.h-lb .k .ic { width: 14px; height: 14px; }
.h-lb .xp { text-align: right; font-weight: 800; font-variant-numeric: tabular-nums; }
.h-feed { flex: 1; min-height: 40px; overflow: hidden; display: flex; flex-direction: column; gap: 4px; font-size: 15px; color: var(--ink-2); }
.h-feed .feed-line { box-shadow: none; background: #f5f7ff; font-size: 15px; }
.h-stats { font-size: 11px; color: var(--ink-2); line-height: 1.4; }

#hEnd { height: 100vh; overflow-y: auto; padding: 36px 40px 48px; display: flex; flex-direction: column; align-items: center; gap: 22px; }
.host .end-title { font-size: 52px; margin: 0; }
.podium.big { gap: 18px; width: 100%; max-width: 860px; }
.podium.big .pod { max-width: 260px; }
.podium.big .pod-av { width: 130px; height: 130px; }
.podium.big .pod1 .pod-av { width: 170px; height: 170px; }
.podium.big .pod-name { font-size: 26px; }
.podium.big .pod-xp { font-size: 17px; }
.podium.big .pod-xp .ic { width: 17px; height: 17px; }
.podium.big .pod-bar { font-size: 56px; padding-top: 14px; }
.podium.big .pod1 .pod-bar { height: 200px; }
.podium.big .pod2 .pod-bar { height: 150px; }
.podium.big .pod3 .pod-bar { height: 112px; }
.awards.big { display: flex; justify-content: center; width: 100%; max-width: 1000px; gap: 14px; }
.awards.big .award { flex: 1 1 0; max-width: 330px; padding: 16px 18px; }
#resetBtn { position: fixed; right: 32px; bottom: 28px; z-index: 5; }
.awards.big .aw-av { width: 52px; height: 52px; }
.awards.big .aw-n { font-size: 21px; }
.h-rest { list-style: none; margin: 0; padding: 0; width: 100%; max-width: 1000px; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px 14px; }
.h-rest:empty { display: none; }
.h-rest li { display: grid; grid-template-columns: 44px 36px minmax(0, 1fr) auto; align-items: center; gap: 10px; padding: 6px 14px 6px 10px; border-radius: 14px; background: rgba(255, 255, 255, 0.95); font-size: 17px; }
.h-rest .rk { font-family: var(--display); color: var(--ink-2); }
.h-rest .mascot { width: 36px; height: 36px; }
.h-rest .nm { font-weight: 800; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.h-rest .xp { display: inline-flex; align-items: center; gap: 3px; color: var(--ink-2); font-weight: 700; font-size: 14px; }
.h-rest .xp .ic { width: 14px; height: 14px; }
.host .victory { right: 390px; }
.host .v-card { padding: 18px 34px 18px 18px; }
.host .v-mascot { width: 130px; height: 130px; }
.host .v-name { font-size: 44px; }
.host .v-sub { font-size: 20px; }
.key-ic { width: 64px; height: 64px; margin: 0 auto; border-radius: 20px; background: var(--blue-soft); color: var(--blue); display: grid; place-items: center; }
.key-ic .ic { width: 32px; height: 32px; }
.host #keyForm .btn { margin-top: 16px; }

@media (max-width: 1100px) {
  #hLobby { grid-template-columns: 1fr; height: auto; min-height: 100vh; overflow-y: auto; }
  body.host { overflow: auto; }
  #hGame { grid-template-columns: 1fr; grid-template-rows: 60vh auto; height: auto; }
}

@media (min-width: 700px) {
  .player .wrap { padding-top: calc(36px + var(--safe-t)); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
  .victory.go .v-title, .victory.go .v-card, .victory.go .v-rays { animation-delay: 0s !important; }
}
