/* Times Table Dragon — giao diện cho trẻ em: trời sáng, card trắng viền màu, nút "kẹo" nổi khối.
   Luôn dùng tông sáng (game có art direction riêng, không đổi theo dark mode của máy). */
:root {
  color-scheme: light;
  --sky-1: #7fd0ff;
  --sky-2: #c9eeff;
  --sky-3: #fff6d8;
  --panel: #ffffff;
  --panel-2: #f2f7ff;
  --ink: #2b2257;
  --ink-soft: #5b5785;
  --line: #e1e7f6;
  --primary: #e8590c;
  --primary-dark: #b4440a;
  --secondary: #6a45f5;
  --secondary-dark: #4f2fd0;
  --secondary-soft: #ece7ff;
  --secondary-ink: #5236d6;
  --green-dark: #17804a;
  --green-soft: #dcf7e8;
  --yellow: #ffd23f;
  --yellow-dark: #e0a800;
  --danger: #e5384f;
  --good: #22c55e;
  --gold: #ffc23d;
  --ring: #6a45f5;
  --shadow: 0 8px 0 rgba(43, 34, 87, .08), 0 14px 30px rgba(43, 34, 87, .12);
  --radius: 26px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overscroll-behavior: none; }
body {
  font-family: 'Baloo 2', ui-rounded, system-ui, sans-serif;
  line-height: 1.35;
  color: var(--ink);
  background: linear-gradient(180deg, var(--sky-1) 0%, var(--sky-2) 55%, var(--sky-3) 100%) fixed;
  overflow-x: hidden;
  touch-action: manipulation;
  -webkit-text-size-adjust: 100%;
}
/* Mây trôi trang trí */
body::before, body::after {
  content: ''; position: fixed; z-index: 0; pointer-events: none; border-radius: 999px; background: #fff; opacity: .75;
  box-shadow: 60px 10px 0 10px #fff, 130px -6px 0 0 #fff, 190px 12px 0 -4px #fff;
  width: 120px; height: 46px; animation: cloud 60s linear infinite;
}
body::before { top: 9vh; left: -260px; }
body::after { top: 30vh; left: -260px; animation-duration: 85s; animation-delay: -30s; opacity: .6; }
#app { position: relative; z-index: 1; }
button { font: inherit; color: inherit; cursor: pointer; }
button, .keypad, .chips, .seg { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
input { font: inherit; }
h1, h2, b, strong { line-height: 1.15; }
.ic { width: 1.2em; height: 1.2em; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.muted { color: var(--ink-soft); }
.center { text-align: center; }
[hidden] { display: none !important; }

.screen { display: none; min-height: 100dvh; }
.screen.active { display: block; }

/* ---------- Nút "kẹo" nổi khối ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .5em;
  border: 0; border-radius: 18px; padding: .6em 1.2em; min-height: 54px; font-weight: 800; font-size: 1.1rem; line-height: 1.1;
  transition: transform .08s ease, box-shadow .08s ease, filter .15s ease;
}
.btn:active { transform: translateY(4px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; box-shadow: 0 6px 0 var(--primary-dark); font-size: 1.2rem; }
.btn-primary:active { box-shadow: 0 2px 0 var(--primary-dark); }
.btn-secondary { background: var(--secondary-soft); color: var(--secondary-ink); box-shadow: 0 5px 0 #d3c9ff; }
.btn-secondary:active { box-shadow: 0 1px 0 #d3c9ff; }
.btn-lg { width: 100%; min-height: 64px; font-size: 1.3rem; border-radius: 22px; }
.btn-sm { min-height: 46px; padding: .4em .9em; font-size: 1rem; }
.btn-icon {
  width: 50px; height: 50px; border-radius: 16px; border: 0; display: grid; place-items: center;
  background: var(--panel); color: var(--ink); box-shadow: 0 5px 0 var(--line);
}
.btn-icon:active { transform: translateY(3px); box-shadow: 0 2px 0 var(--line); }
.link-btn { border: 0; background: none; color: var(--secondary-ink); font-weight: 800; font-size: 1rem; padding: 8px 12px; margin-left: 8px; border-radius: 12px; min-height: 40px; }
@media (hover: hover) { .btn:hover, .btn-icon:hover { filter: brightness(1.05); } .link-btn:hover { background: var(--secondary-soft); } }
.btn:focus-visible, .btn-icon:focus-visible, .link-btn:focus-visible, input:focus-visible, .keypad button:focus-visible, .chips button:focus-visible, .seg button:focus-visible, .hud-exit:focus-visible, .lang-toggle button:focus-visible {
  outline: 4px solid var(--ring); outline-offset: 3px;
}

/* ---------- Card ---------- */
.panel { background: var(--panel); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); border: 3px solid #fff; }
.panel h2 { margin: 0 0 12px; font-size: 1.25rem; display: flex; align-items: center; gap: 8px; }
.panel h2 .ic { color: var(--primary); width: 1.4em; height: 1.4em; }
.pill { background: var(--secondary-soft); color: var(--secondary-ink); border-radius: 99px; padding: 0 10px; font-size: .95rem; font-weight: 800; }
.avatar { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; color: #fff; font-weight: 800; flex: none; font-size: 1rem; box-shadow: inset 0 -3px 0 rgba(0,0,0,.15); }

.lang-toggle { display: inline-flex; background: var(--panel-2); border-radius: 14px; padding: 4px; flex: none; border: 2px solid var(--line); }
.lang-toggle button { border: 0; background: transparent; border-radius: 10px; min-width: 44px; min-height: 36px; padding: 2px 10px; font-weight: 800; font-size: .95rem; color: var(--ink-soft); }
.lang-toggle button.on { background: var(--secondary); color: #fff; }

/* ---------- Màn hình chính ---------- */
#screen-home.active { display: grid; place-items: start center; padding: 20px 16px 32px; }
.home-wrap { width: 100%; max-width: 440px; display: grid; gap: 18px; }
.home-card {
  background: var(--panel); border-radius: 32px; padding: 18px 20px 22px; box-shadow: var(--shadow); border: 4px solid #fff;
  display: flex; flex-direction: column; gap: 14px; position: relative;
}
.hero-dragons { display: flex; justify-content: center; gap: 2%; margin: -6px -6px 0; }
.hero-dragons img { width: 23%; max-width: 104px; aspect-ratio: 1; object-fit: contain; filter: drop-shadow(0 6px 6px rgba(43,34,87,.18)); animation: bounce 2.4s ease-in-out infinite; }
.hero-dragons img:nth-child(2) { animation-delay: .3s; } .hero-dragons img:nth-child(3) { animation-delay: .6s; } .hero-dragons img:nth-child(4) { animation-delay: .9s; }
.logo { display: flex; align-items: center; gap: 12px; }
.logo-ic { width: 54px; height: 54px; padding: 11px; border-radius: 50%; background: var(--yellow); color: var(--ink); box-shadow: 0 4px 0 var(--yellow-dark); stroke-width: 2.4; }
.logo h1 { margin: 0; flex: 1; line-height: .95; font-size: 1.7rem; font-weight: 800; color: var(--ink); }
.logo h1 span { display: inline-block; color: var(--primary); font-size: 2.15rem; -webkit-text-stroke: 2px #fff; paint-order: stroke fill; text-shadow: 0 3px 0 rgba(180,68,10,.25); }
.tagline { margin: 0; color: var(--ink-soft); font-size: 1.05rem; line-height: 1.4; }
.field { display: flex; flex-direction: column; gap: 4px; font-weight: 800; }
.field input, .join-row input {
  border: 3px solid var(--line); background: var(--panel-2); color: var(--ink); border-radius: 16px; padding: .55em .9em; font-size: 1.15rem; width: 100%; min-height: 54px;
}
.field input:focus, .join-row input:focus { border-color: var(--secondary); outline: none; background: #fff; }
.join-row { display: flex; gap: 10px; }
.join-row input { letter-spacing: .3em; text-align: center; font-weight: 800; }
.join-row .btn { flex: none; }
.divider { display: flex; align-items: center; gap: 10px; color: var(--ink-soft); font-size: .95rem; font-weight: 700; }
.divider::before, .divider::after { content: ''; flex: 1; height: 3px; background: var(--line); border-radius: 3px; }
.error { color: var(--danger); margin: 0; min-height: 1.2em; font-weight: 800; }
.howto { background: var(--green-soft); border-radius: 18px; padding: 10px 16px; }
.howto summary { font-weight: 800; cursor: pointer; color: var(--green-dark); min-height: 32px; display: flex; align-items: center; }
.howto ul { margin: 6px 0 4px; padding-left: 20px; color: var(--ink); line-height: 1.45; }

.rooms-panel h2 { margin-bottom: 12px; }
.btn-refresh { margin-left: auto; width: 46px; height: 46px; background: var(--panel-2); }
.btn-refresh.spin .ic { animation: spin .8s linear infinite; }
.rooms-list { display: flex; flex-direction: column; gap: 10px; max-height: 62vh; overflow: auto; padding: 2px; }
.room-row { display: grid; grid-template-columns: auto 1fr auto; gap: 10px; align-items: center; background: var(--panel-2); border-radius: 18px; padding: 8px 12px; border: 2px solid var(--line); }
.room-row img { width: 52px; height: 52px; object-fit: contain; }
.room-row .rinfo { min-width: 0; }
.room-row .rtop { display: flex; flex-wrap: wrap; column-gap: 8px; align-items: baseline; font-weight: 800; line-height: 1.2; }
.room-row .rcode { color: var(--secondary-ink); letter-spacing: .08em; font-size: 1.1rem; }
.room-row .rhost { overflow-wrap: anywhere; }
.room-row .rmeta { color: var(--ink-soft); font-size: .9rem; font-weight: 700; display: flex; gap: 0 10px; flex-wrap: wrap; line-height: 1.3; }
.room-row .rmeta .live { color: var(--danger); }
.room-row .btn { min-height: 48px; padding: .3em .9em; font-size: 1.05rem; }
.rooms-empty { text-align: center; color: var(--ink-soft); padding: 18px 8px; display: flex; flex-direction: column; align-items: center; gap: 4px; }
.rooms-empty .ic { width: 40px; height: 40px; color: var(--secondary); }
.rooms-empty b { color: var(--ink); font-size: 1.1rem; }

/* ---------- Phòng chờ ---------- */
.lobby, .end { max-width: 560px; margin: 0 auto; padding: 18px 16px 32px; display: flex; flex-direction: column; gap: 16px; }
.lobby-main, .lobby-side { display: flex; flex-direction: column; gap: 16px; }
.lobby-head { display: flex; align-items: center; gap: 10px; background: var(--panel); border-radius: 24px; padding: 10px 12px; box-shadow: var(--shadow); }
.lobby-head > div:not(.lang-toggle) { flex: 1; min-width: 0; }
.room-code { font-size: 2.5rem; font-weight: 800; letter-spacing: .14em; line-height: 1; color: var(--secondary-ink); }
.share { margin: -6px 4px 0; font-size: .92rem; word-break: break-all; color: var(--ink); background: rgba(255,255,255,.75); border-radius: 12px; padding: 4px 10px; }
.lobby-players { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 8px; }
.lobby-players li { display: flex; align-items: center; gap: 8px; background: var(--panel-2); border-radius: 16px; padding: 8px 10px; font-weight: 800; min-width: 0; }
.lobby-players li span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.host-ic { color: var(--yellow-dark); margin-left: auto; }
.lineup { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
@media (max-width: 480px) { .lineup { grid-template-columns: repeat(2, 1fr); row-gap: 16px; } }
.lineup-card { position: relative; border-radius: 20px; padding: 10px 8px 12px; text-align: center; background: var(--panel-2); border: 3px solid transparent; }
.lineup-card img { width: 100%; max-width: 116px; aspect-ratio: 1; object-fit: contain; display: block; margin: 0 auto; filter: drop-shadow(0 6px 6px rgba(43,34,87,.18)); }
.lineup-card b { display: block; font-size: 1.05rem; margin: 2px 0 3px; text-wrap: balance; }
.lineup-card small { display: block; color: var(--ink-soft); font-size: .82rem; line-height: 1.25; text-wrap: pretty; }
.lineup-card .num { position: absolute; top: 6px; left: 8px; width: 26px; height: 26px; border-radius: 50%; background: #fff; display: grid; place-items: center; font-weight: 800; font-size: .9rem; }
.lineup-card .boss { position: absolute; top: -12px; left: 50%; transform: translateX(-50%); background: var(--danger); color: #fff; border-radius: 99px; font-size: .78rem; font-weight: 800; padding: 1px 10px; box-shadow: 0 3px 0 #a3202f; }
.lineup-card[data-kind="leaf"] { background: #e6fbef; border-color: #6ee7a8; } .lineup-card[data-kind="fire"] { background: #fff0e4; border-color: #fdba74; }
.lineup-card[data-kind="ice"] { background: #e9f7ff; border-color: #7dd3fc; } .lineup-card[data-kind="thunder"] { background: #f2ecff; border-color: #c4b5fd; }
.setting { margin-top: 12px; }
.setting-label { font-weight: 800; margin-bottom: 6px; display: flex; align-items: center; }
.setting-hint { margin: -2px 0 8px; font-size: .9rem; line-height: 1.35; }
.chips { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
.chips button, .seg button {
  border: 0; background: var(--panel-2); color: var(--ink); border-radius: 14px; min-height: 52px; font-weight: 800; font-size: 1.15rem; box-shadow: 0 4px 0 var(--line);
}
.chips button:active, .seg button:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--line); }
.chips button.on, .seg button.on { background: var(--secondary); color: #fff; box-shadow: 0 4px 0 var(--secondary-dark); }
.seg { display: flex; gap: 8px; }
.seg button { flex: 1; font-size: 1rem; padding: 0 6px; }
.readonly .chips button, .readonly .seg button { pointer-events: none; }

/* ---------- Trận đấu ---------- */
#screen-game.active { height: 100dvh; overflow: hidden; }
.game { max-width: 600px; margin: 0 auto; height: 100dvh; display: flex; flex-direction: column; position: relative; padding-bottom: env(safe-area-inset-bottom); }
.arena { position: relative; flex: 0 0 auto; height: clamp(190px, 36dvh, 440px); overflow: hidden; border-radius: 0 0 34px 34px; transition: background .8s;
  background: radial-gradient(120% 90% at 50% 100%, #c8f7d4 0%, #8fdcff 55%, #5fb7ff 100%); box-shadow: 0 6px 0 rgba(43,34,87,.08); }
.arena[data-dragon="fire"] { background: radial-gradient(120% 90% at 50% 100%, #ffe0a3 0%, #ffab7a 50%, #f0703f 100%); }
.arena[data-dragon="ice"] { background: radial-gradient(120% 90% at 50% 100%, #ffffff 0%, #d2f0ff 50%, #95cdf5 100%); }
.arena[data-dragon="thunder"] { background: radial-gradient(120% 90% at 50% 100%, #ddd2ff 0%, #9b82f0 50%, #5b3fc4 100%); }
#dragon-canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

.hud-top { position: absolute; top: max(8px, env(safe-area-inset-top)); left: 10px; right: 10px; display: flex; gap: 6px; align-items: stretch; z-index: 3; }
.hud-exit { flex: none; display: inline-flex; flex-direction: column; align-items: center; justify-content: center; min-width: 50px; min-height: 52px; border: 0; border-radius: 16px;
  background: #fff; color: var(--danger); font-weight: 800; font-size: .78rem; line-height: 1; padding: 4px 6px; box-shadow: 0 4px 0 rgba(43,34,87,.15); }
.hud-exit .ic { width: 1.4em; height: 1.4em; font-size: 1rem; margin-bottom: 2px; }
.hud-exit:active { transform: translateY(3px); box-shadow: 0 1px 0 rgba(43,34,87,.15); }
.dragon-bar { position: relative; flex: 1; min-width: 0; background: #fff; border-radius: 16px; padding: 5px 9px; color: var(--ink); display: flex; flex-direction: column; justify-content: center; box-shadow: 0 4px 0 rgba(43,34,87,.15); }
.dragon-bar-label { display: flex; align-items: center; gap: 4px; font-weight: 800; font-size: .9rem; white-space: nowrap; min-width: 0; }
.dragon-bar-label .ic { color: var(--primary); }
.dragon-bar-label #dragon-name { overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.dragon-bar .bar { height: 16px; margin-top: 3px; }
#dragon-hp-text { position: absolute; left: 9px; right: 9px; bottom: 5px; height: 16px; line-height: 16px; text-align: center; font-size: .74rem; color: #fff; text-shadow: 0 1px 2px rgba(0,0,0,.55); z-index: 1; pointer-events: none; font-variant-numeric: tabular-nums; }
.stage-dots { display: inline-flex; flex: none; gap: 3px; margin-left: 2px; }
.stage-dots i { width: 8px; height: 8px; border-radius: 50%; background: #d9dcef; }
.stage-dots i.done { background: var(--good); } .stage-dots i.now { background: var(--primary); box-shadow: 0 0 0 2px #ffd5bd; }
.game-timer { display: flex; align-items: center; gap: 3px; background: #fff; color: var(--ink); border-radius: 16px; padding: 0 9px; font-weight: 800; font-size: 1rem; font-variant-numeric: tabular-nums; box-shadow: 0 4px 0 rgba(43,34,87,.15); }
.game-timer.hurry { color: #fff; background: var(--danger); animation: pulse 1s infinite; }
.sound-btn { width: 44px; height: auto; min-height: 50px; border-radius: 14px; background: #fff; box-shadow: 0 4px 0 rgba(43,34,87,.15); flex: none; }

.bar { position: relative; height: 14px; background: #e6e8f4; border-radius: 99px; overflow: hidden; }
.bar.small { height: 14px; flex: 1; }
.bar-fill, .bar-ghost { position: absolute; inset: 0 auto 0 0; border-radius: 99px; transition: width .25s ease; }
.bar-ghost { background: #ffd8a8; transition: width .9s ease .2s; }
.bar-fill.dragon { background: linear-gradient(90deg, #ff4d6d, #ffb347); }
.bar-fill.me { background: linear-gradient(90deg, #22c55e, #7ee2a0); }
.bar-fill.me.low { background: linear-gradient(90deg, #e5384f, #ff9a76); }

.fx-layer { position: absolute; inset: 0; pointer-events: none; z-index: 2; }
.dmg { position: absolute; font-weight: 800; font-size: 2.1rem; color: #fff; -webkit-text-stroke: 3px var(--ink); paint-order: stroke fill; animation: float-up 1.1s ease-out forwards; white-space: nowrap; transform: translate(-50%, 0); }
.dmg small { display: block; font-size: .8rem; -webkit-text-stroke: 0; color: var(--ink); text-align: center; background: #fff; border-radius: 8px; padding: 0 6px; }
.dmg.big { font-size: 2.7rem; color: var(--yellow); }
.slash-mark { position: absolute; inset: 0; }
.slash-mark i { position: absolute; left: 10%; width: 90%; height: 10px; border-radius: 10px; background: linear-gradient(90deg, transparent, #fff 30%, #ff4d6d 70%, transparent);
  transform: rotate(-28deg) scaleX(0); transform-origin: left; animation: slash .45s ease-out forwards; box-shadow: 0 0 18px #ff4d6d; }
.slash-mark i:nth-child(1) { top: 30%; } .slash-mark i:nth-child(2) { top: 45%; animation-delay: .06s; } .slash-mark i:nth-child(3) { top: 60%; animation-delay: .12s; }
.feed { position: absolute; left: 10px; bottom: 10px; z-index: 3; display: flex; flex-direction: column; gap: 4px; pointer-events: none; max-width: 64%; }
.feed div { background: #fff; color: var(--ink); border-radius: 12px; padding: 2px 10px; font-size: .85rem; font-weight: 800; box-shadow: 0 3px 0 rgba(43,34,87,.12); animation: feed-in .25s ease-out, fade-out .5s ease 3.5s forwards; }
.feed .bad { color: #c41d3d; } .feed .good { color: var(--green-dark); }

.charge { position: absolute; left: 12px; right: 12px; top: 70px; z-index: 4; background: #fff; color: var(--ink); border-radius: 18px; padding: 7px 12px; border: 4px solid var(--danger);
  box-shadow: 0 6px 0 rgba(43,34,87,.15); animation: charge-in .25s ease-out, wiggle .5s ease-in-out infinite; }
.charge-title { font-weight: 800; font-size: 1rem; line-height: 1.15; }
.charge-sub { font-weight: 700; font-size: .88rem; color: var(--ink-soft); margin-top: 2px; line-height: 1.2; }
.charge .bar { height: 10px; margin-top: 4px; }
.charge-fill { background: linear-gradient(90deg, #ff4d6d, #ffc23d); transition: width .2s linear; }
.charge[data-dragon="ice"] { border-color: #38bdf8; } .charge[data-dragon="ice"] .charge-fill { background: linear-gradient(90deg, #38bdf8, #bae6fd); }
.charge[data-dragon="thunder"] { border-color: #8b5cf6; } .charge[data-dragon="thunder"] .charge-fill { background: linear-gradient(90deg, #8b5cf6, #facc15); }

.banner { position: absolute; left: 50%; top: 48%; transform: translate(-50%, -50%); z-index: 5; text-align: center; pointer-events: none; width: 92%; animation: banner-in .5s cubic-bezier(.2,1.6,.4,1); }
.banner-title { font-size: clamp(1.7rem, 7vw, 2.6rem); font-weight: 800; color: var(--yellow); -webkit-text-stroke: 4px var(--ink); paint-order: stroke fill; line-height: 1.05; }
.banner-sub { display: inline-block; margin-top: 6px; background: #fff; color: var(--ink); font-weight: 800; border-radius: 99px; padding: 2px 14px; box-shadow: 0 3px 0 rgba(43,34,87,.15); }

/* Bảng làm bài */
.console { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; gap: clamp(6px, 1.2dvh, 12px); padding: clamp(8px, 1.4dvh, 14px) 12px clamp(8px, 1.5dvh, 16px); }
.me-bar { flex: 0 0 auto; display: flex; align-items: center; gap: 8px; font-weight: 800; background: #fff; border-radius: 16px; padding: 6px 12px; box-shadow: 0 4px 0 rgba(43,34,87,.1); }
.me-bar .heart { color: var(--danger); width: 1.5em; height: 1.5em; fill: #ffc2cc; }
.combo { min-width: 70px; text-align: right; color: var(--primary); }
.question-wrap { position: relative; display: grid; place-items: center; min-height: clamp(104px, 15dvh, 150px); }
.q-ring { position: absolute; left: 6px; top: 50%; height: clamp(92px, 13dvh, 128px); width: clamp(92px, 13dvh, 128px); transform: translateY(-50%) rotate(-90deg); z-index: 1; }
.q-ring-bg { fill: #fff; stroke: var(--line); stroke-width: 10; }
.q-ring-fg { fill: none; stroke: var(--good); stroke-width: 10; stroke-linecap: round; stroke-dasharray: 339.3; transition: stroke .2s; }
.q-ring-fg.warn { stroke: var(--gold); } .q-ring-fg.hurry { stroke: var(--danger); }
.question { width: 100%; min-height: clamp(104px, 15dvh, 150px); background: #fff; border-radius: var(--radius); box-shadow: 0 6px 0 rgba(43,34,87,.1); border: 3px solid #fff;
  display: flex; flex-direction: column; justify-content: center; padding: 8px 14px 8px clamp(112px, 15.5dvh, 150px); }
.q-text { font-size: clamp(2.1rem, 5.4dvh, 2.9rem); font-weight: 800; line-height: 1; letter-spacing: .02em; }
.q-words { display: flex; flex-direction: column; font-size: .95rem; line-height: 1.2; color: var(--secondary-ink); font-weight: 800; margin-top: 3px; }
.q-words span[lang="vi"] { color: var(--primary); }
.q-answer { font-size: clamp(1.8rem, 4.6dvh, 2.4rem); font-weight: 800; color: var(--secondary); min-height: 1.25em; display: flex; align-items: center; line-height: 1.1; }
.q-answer::before { content: '= '; color: var(--ink-soft); margin-right: .2em; }
.caret { display: inline-block; width: 3px; height: 1em; background: var(--secondary); margin-left: 2px; animation: blink 1s steps(1) infinite; }
.question.shake { animation: shake .4s; }
.question.good { animation: pop .3s; }

/* Bàn phím: phím kẹo nhiều màu */
.keypad { flex: 1 1 auto; min-height: 0; display: grid; grid-template-columns: repeat(3, 1fr); grid-auto-rows: 1fr; gap: clamp(7px, 1.1dvh, 12px); }
.keypad button { min-height: 48px; max-height: 76px; height: auto; border: 0; border-radius: 18px; font-size: clamp(1.6rem, 3.8dvh, 2.1rem); font-weight: 800; color: var(--ink);
  display: flex; align-items: center; justify-content: center; gap: 6px; touch-action: manipulation; transition: transform .06s; }
.keypad button:nth-child(-n+3) { background: #ffe3ea; box-shadow: 0 5px 0 #f6b3c4; }
.keypad button:nth-child(n+4):nth-child(-n+6) { background: #fff1c2; box-shadow: 0 5px 0 #f0d06a; }
.keypad button:nth-child(n+7):nth-child(-n+9) { background: #d9f7e6; box-shadow: 0 5px 0 #8fdcb2; }
.keypad button[data-k="0"], .keypad .k-del { background: #e2ebff; box-shadow: 0 5px 0 #a9c0f5; }
.keypad .k-del { color: var(--ink-soft); }
.keypad .k-ok { background: var(--primary); color: #fff; box-shadow: 0 5px 0 var(--primary-dark); font-size: clamp(1.15rem, 2.8dvh, 1.45rem); }
.keypad button:active, .keypad button.pressed { transform: translateY(4px); box-shadow: 0 1px 0 rgba(43,34,87,.2); }
.keypad.locked { opacity: .45; pointer-events: none; }

/* Đồng đội: 1 hàng cuộn ngang trên mobile */
.team { list-style: none; margin: 0; padding: 0 0 2px; display: flex; flex: 0 0 auto; overflow-x: auto; gap: 6px; scrollbar-width: none; }
.team::-webkit-scrollbar { display: none; }
.team li { flex: 0 0 136px; background: #fff; border-radius: 14px; padding: 5px 8px; display: grid; grid-template-columns: auto 1fr; gap: 0 8px; align-items: center; font-size: .9rem; box-shadow: 0 3px 0 rgba(43,34,87,.1); }
.team li.me { outline: 3px solid var(--secondary); outline-offset: -3px; }
.team li.down { opacity: .55; }
.team li.off { opacity: .35; }
.team li.hurt { animation: shake .4s; }
.team li.frozen { background: linear-gradient(160deg, #e0f2fe, #bae6fd); }
.team li.burn { animation: burn-card .7s; }
.team li.zap { animation: zap-card .6s; }
.team .avatar { grid-row: span 2; width: 30px; height: 30px; font-size: .85rem; }
.team .nm { font-weight: 800; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: flex; gap: 4px; }
.team .nm em { font-style: normal; color: var(--ink-soft); margin-left: auto; }
.team .bar { height: 8px; }

/* Đóng băng bàn phím */
.console.frozen .keypad button { background: linear-gradient(160deg, #eff9ff, #bae6fd) !important; color: #0c4a6e; box-shadow: 0 5px 0 #7dd3fc !important; }
.console.frozen .question { box-shadow: 0 0 0 4px #7dd3fc, 0 6px 0 rgba(43,34,87,.1); }
.frozen-label { position: absolute; z-index: 3; top: -12px; left: 50%; transform: translateX(-50%); background: #0369a1; color: #fff; font-weight: 800; border-radius: 99px; padding: 2px 14px; display: flex; gap: 6px; align-items: center; animation: pop .3s; white-space: nowrap; }

/* ---------- Lớp phủ / hộp thoại ---------- */
.overlay { position: fixed; inset: 0; background: rgba(43, 34, 87, .45); display: grid; place-items: center; z-index: 20; padding: 16px; backdrop-filter: blur(3px); }
.overlay-card { background: #fff; border-radius: 30px; padding: 26px 22px; max-width: 380px; width: 100%; text-align: center; box-shadow: var(--shadow); animation: pop .35s; border: 4px solid #fff; }
.overlay-card p { line-height: 1.4; }
.ko { font-size: 1.8rem; font-weight: 800; color: var(--danger); line-height: 1.1; }
.confirm-title { font-size: 1.6rem; font-weight: 800; line-height: 1.15; }
.confirm-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 8px; }
#confirm { z-index: 40; }

/* ---------- Hiệu ứng toàn màn hình ---------- */
.screen-flash { position: fixed; inset: 0; pointer-events: none; z-index: 15; animation: flash .5s ease-out forwards; }
.screen-flash.red { background: radial-gradient(circle, transparent 45%, rgba(229, 56, 79, .45)); }
.game.shake { animation: shake .4s; }
.fx-overlay { position: fixed; inset: 0; pointer-events: none; z-index: 16; }
.fx-chomp::before { content: ''; position: absolute; inset: 0; background: radial-gradient(circle, transparent 55%, rgba(255, 77, 109, .4)); animation: burn .8s ease-out forwards; }
.chomp-burst { position: absolute; left: 50%; top: 30%; width: min(58vw, 240px); aspect-ratio: 1; transform: translate(-50%, -50%) rotate(-8deg) scale(0); animation: chomp-pop .8s cubic-bezier(.2, 1.7, .4, 1) forwards; display: grid; place-items: center; }
.chomp-burst svg { position: absolute; inset: 0; width: 100%; height: 100%; filter: drop-shadow(0 6px 0 rgba(43, 34, 87, .3)); }
.chomp-burst polygon { fill: #ffd84d; stroke: var(--ink); stroke-width: 6; stroke-linejoin: round; }
.chomp-burst span { position: relative; font-size: clamp(1.8rem, 9vw, 2.6rem); font-weight: 800; color: #ff4d6d; -webkit-text-stroke: 3px var(--ink); paint-order: stroke fill; }
.fx-burn { background: radial-gradient(ellipse at 50% 120%, rgba(255,120,0,.8), rgba(255,60,0,.3) 45%, transparent 70%); animation: burn 1.1s ease-out forwards; }
.fx-burn::after { content: ''; position: absolute; inset: auto 0 0 0; height: 40%; background: repeating-radial-gradient(circle at 50% 120%, rgba(255,210,80,.6) 0 18px, rgba(255,90,0,.3) 18px 36px); filter: blur(6px); animation: flame-rise 1.1s ease-out forwards; }
.fx-frost { box-shadow: inset 0 0 80px 30px rgba(190,235,255,.95), inset 0 0 0 6px rgba(255,255,255,.8); background: radial-gradient(circle, transparent 55%, rgba(186,230,253,.45)); animation: frost 3s ease-out forwards; }
.fx-zap { background: radial-gradient(circle at 50% 20%, rgba(255,250,200,.7), rgba(255,255,255,.25) 60%, transparent); animation: zap .7s steps(1) forwards; }
.fx-zap::after { content: ''; position: absolute; left: 50%; top: 0; width: 120px; height: 75%; transform: translateX(-50%); background: #fde047; clip-path: polygon(55% 0, 20% 48%, 48% 48%, 30% 100%, 82% 38%, 54% 38%, 75% 0); filter: drop-shadow(0 0 18px #facc15); }
.fx-heal { background: radial-gradient(circle, rgba(134,239,172,.5), transparent 70%); animation: flash 1s ease-out forwards; }

/* ---------- Kết thúc ---------- */
.end-banner { text-align: center; font-size: clamp(2rem, 8vw, 3rem); font-weight: 800; line-height: 1.05; margin-top: 16px; animation: pop .5s; -webkit-text-stroke: 4px #fff; paint-order: stroke fill; }
.end-banner.win { color: var(--primary); } .end-banner.lose { color: var(--secondary); }
#end-sub { font-weight: 700; color: var(--ink); background: rgba(255,255,255,.8); border-radius: 14px; padding: 6px 12px; margin: 0; }
.stats { width: 100%; border-collapse: collapse; font-size: 1rem; }
.stats th { text-align: right; color: var(--ink-soft); font-weight: 800; font-size: .82rem; padding: 4px; }
.stats th:first-child, .stats td:first-child { text-align: left; }
.stats td { text-align: right; padding: 8px 4px; border-top: 2px solid var(--line); font-weight: 800; font-variant-numeric: tabular-nums; }
.stats td:first-child { display: flex; align-items: center; gap: 6px; }
.stats .mvp { color: var(--yellow-dark); }
.confetti { position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: 10; }
.confetti i { position: absolute; top: -20px; width: 10px; height: 16px; border-radius: 3px; animation: fall linear forwards; }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 40px); opacity: 0; background: var(--ink); color: #fff;
  padding: 10px 18px; border-radius: 16px; font-weight: 800; transition: .25s; z-index: 30; max-width: calc(100% - 32px); text-align: center; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* Chặn xoay ngang trên điện thoại */
.rotate-lock { display: none; position: fixed; inset: 0; z-index: 100; background: linear-gradient(180deg, var(--sky-1), var(--sky-3)); color: var(--ink);
  flex-direction: column; align-items: center; justify-content: center; gap: 10px; text-align: center; padding: 16px; }
.rotate-lock .ic { width: 64px; height: 64px; color: var(--secondary); animation: rotate-hint 1.8s ease-in-out infinite; }
.rotate-lock b { font-size: 1.4rem; }
@media (orientation: landscape) and (max-height: 560px) and (hover: none) {
  .rotate-lock { display: flex; }
  #app { visibility: hidden; }
}

/* ---------- Màn thấp / hẹp ---------- */
@media (max-height: 640px) and (orientation: portrait) {
  .arena { height: 30dvh; }
  .q-words { font-size: .8rem; }
  .me-bar { padding: 3px 10px; }
}
@media (max-width: 360px) {
  .chips { gap: 6px; }
  .chips button { font-size: 1rem; }
  .logo h1 { font-size: 1.45rem; } .logo h1 span { font-size: 1.8rem; }
}

/* ======================================================================
   DESKTOP — dùng toàn màn hình
   ====================================================================== */
@media (min-width: 900px) {
  #screen-home.active { padding: 36px 32px; }
  .home-wrap { max-width: 1180px; grid-template-columns: minmax(0, 480px) minmax(0, 1fr); gap: 28px; align-items: start; }
  .hero-dragons img { max-width: 120px; }
  .logo h1 { font-size: 2rem; } .logo h1 span { font-size: 2.6rem; }
  .rooms-list { max-height: calc(100vh - 180px); }

  .lobby { max-width: 1180px; display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); grid-template-areas: "head head" "share share" "main side"; gap: 20px 24px; padding: 28px 32px 40px; }
  .lobby-head { grid-area: head; }
  .share { grid-area: share; margin: -8px 4px 0; justify-self: start; }
  .lobby-main { grid-area: main; } .lobby-side { grid-area: side; position: sticky; top: 20px; align-self: start; }
  .lineup-card b { font-size: 1.15rem; } .lineup-card small { font-size: .9rem; }

  .end { max-width: 900px; padding: 32px; }
}

@media (min-width: 1024px) and (min-height: 600px) {
  /* Trận đấu: rồng to bên trái, bảng làm bài bên phải, phủ kín màn hình */
  .game { max-width: none; height: 100dvh; display: grid; grid-template-columns: minmax(0, 1fr) clamp(440px, 36vw, 600px); }
  .arena { height: 100dvh; border-radius: 0 40px 40px 0; }
  .hud-top { top: 18px; left: 18px; right: 18px; gap: 10px; }
  .hud-exit { min-width: 64px; min-height: 64px; font-size: .9rem; }
  .dragon-bar { max-width: 560px; padding: 8px 14px; }
  .dragon-bar-label { font-size: 1.15rem; }
  .dragon-bar .bar { height: 22px; }
  #dragon-hp-text { height: 22px; line-height: 22px; bottom: 8px; font-size: .9rem; left: 14px; right: 14px; }
  .game-timer { font-size: 1.35rem; padding: 0 16px; margin-left: auto; }
  .sound-btn { width: 60px; min-height: 64px; }
  .charge { top: 100px; left: 50%; right: auto; width: min(560px, 80%); transform: translateX(-50%); padding: 10px 16px; animation: charge-in .25s ease-out; }
  .charge-title { font-size: 1.3rem; } .charge-sub { font-size: 1rem; }
  .banner-title { font-size: 3.4rem; }
  .feed { left: 18px; bottom: 18px; max-width: 46%; }
  .feed div { font-size: 1rem; padding: 4px 14px; }
  .dmg { font-size: 2.8rem; } .dmg.big { font-size: 3.6rem; }

  .console { padding: 22px 24px; gap: 14px; overflow: hidden; }
  .me-bar { padding: 10px 16px; font-size: 1.15rem; }
  .bar.small { height: 18px; }
  .question-wrap, .question { min-height: 170px; }
  .q-ring { height: 140px; width: 140px; left: 10px; }
  .question { padding-left: 168px; }
  .q-text { font-size: 3.4rem; }
  .q-words { font-size: 1.1rem; }
  .q-answer { font-size: 2.8rem; }
  .keypad { gap: 12px; }
  .keypad button { max-height: 92px; font-size: 2.3rem; border-radius: 22px; }
  .keypad .k-ok { font-size: 1.6rem; }
  .team { flex-wrap: wrap; overflow-x: visible; max-height: 22vh; overflow-y: auto; }
  .team li { flex: 1 1 160px; padding: 7px 10px; font-size: 1rem; }
}

@keyframes cloud { from { transform: translateX(0); } to { transform: translateX(calc(100vw + 520px)); } }
@keyframes bounce { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-8px); } }
@keyframes wiggle { 0%, 100% { transform: rotate(0); } 25% { transform: rotate(-.6deg); } 75% { transform: rotate(.6deg); } }
@keyframes float-up { 0% { opacity: 0; transform: translate(-50%, 10px) scale(.6); } 15% { opacity: 1; transform: translate(-50%, 0) scale(1.15); } 100% { opacity: 0; transform: translate(-50%, -70px) scale(1); } }
@keyframes slash { 0% { transform: rotate(-28deg) scaleX(0); opacity: 1; } 60% { transform: rotate(-28deg) scaleX(1); opacity: 1; } 100% { transform: rotate(-28deg) scaleX(1); opacity: 0; } }
@keyframes shake { 0%, 100% { transform: translateX(0); } 20% { transform: translateX(-8px); } 40% { transform: translateX(8px); } 60% { transform: translateX(-5px); } 80% { transform: translateX(5px); } }
@keyframes pop { 0% { transform: scale(.85); } 60% { transform: scale(1.05); } 100% { transform: scale(1); } }
@keyframes pulse { 50% { transform: scale(1.06); } }
@keyframes blink { 50% { opacity: 0; } }
@keyframes flash { from { opacity: 1; } to { opacity: 0; } }
@keyframes feed-in { from { opacity: 0; transform: translateX(-10px); } }
@keyframes fade-out { to { opacity: 0; } }
@keyframes fall { to { transform: translateY(110vh) rotate(720deg); } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes charge-in { from { opacity: 0; } }
@keyframes banner-in { from { opacity: 0; transform: translate(-50%, -50%) scale(.4); } }
@keyframes chomp-pop { 0% { transform: translate(-50%, -50%) rotate(-20deg) scale(0); opacity: 1; } 35% { transform: translate(-50%, -50%) rotate(-6deg) scale(1.12); } 55% { transform: translate(-50%, -50%) rotate(-8deg) scale(1); opacity: 1; } 100% { transform: translate(-50%, -60%) rotate(-8deg) scale(.95); opacity: 0; } }
@keyframes burn { 0% { opacity: 0; } 15% { opacity: 1; } 100% { opacity: 0; } }
@keyframes flame-rise { from { transform: translateY(40%); } to { transform: translateY(-30%); opacity: 0; } }
@keyframes frost { 0% { opacity: 0; } 10%, 80% { opacity: 1; } 100% { opacity: 0; } }
@keyframes zap { 0% { opacity: 1; } 15% { opacity: 0; } 25% { opacity: .9; } 40%, 100% { opacity: 0; } }
@keyframes burn-card { 0%, 100% { box-shadow: none; } 30% { box-shadow: 0 0 0 4px #fb923c, 0 0 18px #f97316; } }
@keyframes zap-card { 0%, 100% { filter: none; } 20%, 60% { filter: brightness(1.6) saturate(2); } 40% { filter: none; } }
@keyframes rotate-hint { 0%, 30% { transform: rotate(-90deg); } 60%, 100% { transform: rotate(0deg); } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; } }

/* Nút EN/VI nổi ở góc thẻ chính để tiêu đề có đủ chỗ */
.home-card > .logo > .lang-toggle { position: absolute; top: -16px; right: 16px; background: #fff; box-shadow: 0 4px 0 rgba(43,34,87,.12); }
.join-row input::placeholder { letter-spacing: normal; font-weight: 700; }
