* { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  /* Tông CAM chủ đạo + xanh giữ lại cho chữ nhấn (tên, nhãn) */
  --leaf: #2e9b3e;          /* xanh — chữ nhấn (tên, slider label) */
  --leaf-dark: #167539;     /* xanh đậm — chữ */
  --lemon: #ffd23f;
  --lemon-dark: #f4b400;
  --orange: #f3791b;        /* cam chủ đạo (theo design mới) */
  --orange-dark: #c2520a;
  --orange-border: #ef7d12;
  --sky-top: #ffe3b0;       /* nền gradient ấm (thay xanh cũ) */
  --sky-bot: #ffc56b;
  --card: #ffffff;
  --text: #225530;          /* chữ chính — giữ xanh đậm */
  --muted: #6b9a73;
  --gold: #ffc107;
}
html, body {
  height: 100%;
  font-family: -apple-system, "Segoe UI", Roboto, system-ui, sans-serif;
  color: var(--text);
  background: linear-gradient(180deg, var(--sky-top) 0%, var(--sky-bot) 100%);
  overflow: hidden;
  -webkit-user-select: none; user-select: none;
  touch-action: none;
  overscroll-behavior: none;   /* chặn quẹt ngang -> back/forward & pull-to-refresh trên mobile */
}
#gameWrap, #game { touch-action: none; overscroll-behavior: none; }
/* Garden background (design) behind all screens; gradient above is the fallback */
body::before {
  content: ""; position: fixed; inset: 0; z-index: -1;
  background: url("/images/backgrounds/bg-san-choi.webp") center / 100% 100% no-repeat;
}
.screen { position: fixed; inset: 0; display: none; flex-direction: column;
  align-items: center; justify-content: flex-start; padding: 22px; text-align: center;
  overflow-y: auto; -webkit-overflow-scrolling: touch;
  background: url("/images/backgrounds/bg-san-choi.webp") center / 100% 100% no-repeat; }
.screen.active { display: flex; }
/* center when it fits, scroll (no clipping) when content is taller than the screen */
.screen > * { margin-top: auto; margin-bottom: auto; flex-shrink: 0; }
/* logo TEA+ luôn cố định ở góc trái-trên mọi màn */
.brand-logo { position: fixed; top: 12px; left: 14px; z-index: 60; width: 42px; height: auto;
  pointer-events: none; filter: drop-shadow(0 2px 4px rgba(0,0,0,.18)); }

h1 { font-size: 1.6rem; margin-bottom: 6px; color: var(--leaf-dark); }
p.sub { color: var(--muted); margin-bottom: 18px; font-weight: 600; }

input[type=text], input[type=number], input[type=password] {
  width: 100%; padding: 15px; font-size: 1rem; border-radius: 8px;
  border: 1px solid #cfe8d2; color: var(--text); text-align: left; font-weight: 500;
}
/* password field + show/hide toggle */
.pw-wrap { position: relative; width: 100%; max-width: 360px; margin: 0 auto; }
.pw-wrap input { padding-right: 50px; }
.pw-toggle { position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
  background: none; border: 0; font-size: 1.3rem; line-height: 1; padding: 8px; cursor: pointer; }
.pw-toggle:active { transform: translateY(-50%) scale(.9); }
input:focus { outline: none; border-color: var(--lemon-dark); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 15px 30px; font-size: 1.15rem; font-weight: 800; border: none; border-radius: 999px;
  background: linear-gradient(180deg, #ffd23f, #f59008); color: #1c7a2e; cursor: pointer;
  margin-top: 16px; border: 3px solid #ec7a10; box-shadow: 0 6px 0 #bf5e08, 0 10px 18px rgba(0,0,0,.18);
  transition: transform .06s; -webkit-text-stroke: .4px #145e24; }
.btn:active { transform: translateY(3px); box-shadow: 0 3px 0 #bf5e08; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.lemon { background: linear-gradient(180deg, var(--lemon), var(--lemon-dark)); color: var(--leaf-dark);
  box-shadow: 0 6px 0 #c98f00, 0 10px 18px rgba(0,0,0,.18); }
.btn.lemon:active { box-shadow: 0 3px 0 #c98f00; }
.error { color: #d64545; margin-top: 12px; min-height: 22px; font-weight: 700; }

/* Shared form/card style for ALL screens: thick green border, rounded corners, shadow */
.card { background: var(--card); border-radius: 22px; padding: 22px; width: 100%; max-width: 440px;
  box-shadow: 0 12px 30px rgba(31,94,42,.18); border: 5px solid #ef7d12; }

/* Create Room screen: logo + button OUTSIDE the form (matches design) */
.config-stack { display: flex; flex-direction: column; align-items: center; gap: 12px; width: 100%; max-width: 440px; }
.config-stack .card { width: 100%; margin: 0; }
.config-stack .btn { margin-top: 4px; }
.config-stack .logo-img { max-width: 280px; }
/* tiêu đề ảnh pill ĐÈ lên mép trên card (giống design) */
.titled { position: relative; width: 100%; padding-top: 24px; display: flex; flex-direction: column; align-items: center; }
.pill-header-img { position: absolute; top: 0; left: 50%; transform: translateX(-50%); z-index: 3;
  display: block; height: auto; width: auto; max-width: 78%; max-height: 50px; margin: 0;
  filter: drop-shadow(0 4px 5px rgba(120,60,0,.22)); }
/* card THỂ LỆ CHƠI: gọn lại (ảnh khung panel-cream 9-slice) */
.section-title { font-weight: 900; color: var(--leaf-dark); font-size: 1.35rem; margin-bottom: 12px; letter-spacing: .5px; }
/* panel CƠ HỘI TRÚNG QUÀ: to hơn — ảnh quà lớn, tên 2 dòng, nhiều padding */
.gift-row { display: flex; gap: 6px; width: 100%; justify-content: center; align-items: flex-start;
  border: 30px solid transparent; border-image: url("/images/ui/panel-cream.webp") 60 fill stretch; padding: 8px 2px; }
.gift { flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: center; gap: 8px;
  background: transparent; }
.gift-name { font-size: .9rem; font-weight: 900; color: var(--text); text-align: center; line-height: 1.1;
  text-transform: uppercase; letter-spacing: .3px; }
.gift img { height: 112px; max-width: 100%; object-fit: contain; display: block;
  filter: drop-shadow(0 4px 5px rgba(120,60,0,.2)); }

/* HOME: thể lệ 2 cột */
.rules-2col { display: flex; align-items: stretch; gap: 6px; width: 100%; max-width: 440px;
  border: 30px solid transparent; border-image: url("/images/ui/panel-cream.webp") 60 fill stretch;
  background: transparent; padding: 4px 2px; }
.rcol { flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 6px 4px; }
.rcol-title { font-weight: 900; color: var(--leaf-dark); font-size: 1.1rem; letter-spacing: .3px; }
.rcol-desc { font-weight: 800; color: #000000; font-size: .85rem; text-align: center; line-height: 1.25; }
.rcol-desc b { color: var(--text); font-weight: 900; }
.rcol-img { width: 84%; max-width: 120px; height: auto; display: block; margin-top: 2px; }
.rcol-divider { width: 2px; align-self: stretch; background: #FEEC24; margin: 6px 0; border-radius: 2px; }
.timer-box { position: relative; width: 84%; max-width: 120px; margin-top: 2px; }
.timer-box img { width: 100%; display: block; }
.timer-num { position: absolute; left: 60%; top: 56%; transform: translate(-50%, -50%);
  font-weight: 900; color: var(--orange); font-size: 1.2rem; }

/* HOME: thanh nút dưới (gear / TẠO PHÒNG / fullscreen) */
.home-bar { display: flex; align-items: center; justify-content: center; gap: 12px; width: 100%; margin-top: 4px; }
.home-bar .createbtn-img { flex: 1; max-width: 300px; margin: 0; }
.home-bar .createbtn-img img { width: 100%; height: auto; display: block; }
.icon-btn { flex: 0 0 auto; width: 58px; height: 58px; padding: 0; border: 0; background: none;
  box-shadow: none; cursor: pointer; line-height: 0; transition: transform .06s; }
.icon-btn:active { transform: translateY(2px); }
.icon-btn img { width: 100%; height: 100%; display: block; }

/* SETTINGS: ô nhập dùng khung ảnh input-field */
#settingsScreen .sp-section input[type=number] { width: 100%; background: transparent; border-radius: 0;
  text-align: center; font-weight: 800; height: 52px; padding: 0 12px; border: 15px solid transparent;
  border-image: url("/images/ui/input-field.webp") 42 fill stretch; }
#settingsScreen .sp-section input[type=number]:focus { outline: none; }
/* nút tăng/giảm 2 bên ô nhập */
.stepper { display: flex; align-items: center; gap: 8px; width: 100%; }
.stepper input[type=number] { flex: 1; min-width: 0; }
.step-btn { flex: 0 0 auto; width: 48px; height: 48px; border: 0; border-radius: 12px; cursor: pointer;
  background: linear-gradient(180deg, #ffd23f, #f5901f); color: #1c7a2e; font-size: 1.9rem; font-weight: 900;
  line-height: 1; display: flex; align-items: center; justify-content: center;
  box-shadow: 0 3px 0 #c2520a; -webkit-text-stroke: .4px #145e24; transition: transform .06s; }
.step-btn:active { transform: translateY(2px); box-shadow: 0 1px 0 #c2520a; }

/* card cài đặt (Settings) — DÙNG 1 ẢNH panel 3-card (settings-panel.webp) + overlay nội dung */
.settings-panel { position: relative; width: 100%; max-width: 440px; margin: 0 auto; }
.sp-bg { width: 100%; height: auto; display: block; }
.sp-section { position: absolute; left: 11%; right: 11%; display: flex; flex-direction: column;
  justify-content: center; gap: 12px; text-align: left; }
.sp-section .section-title { margin-bottom: 0; }
.sp-1 { top: 1.5%; height: 30%; }
.sp-2 { top: 34.5%; height: 30%; }
.sp-3 { top: 66.9%; height: 30%; }

/* Name entry screen: logo + button outside the card, green-bordered card, cream sub-boxes (matches design) */
.join-stack, .result-stack { display: flex; flex-direction: column; align-items: center; gap: 16px; width: 100%; max-width: 460px; }
.result-stack .card { width: 100%; margin: 0; }
.join-stack .card { width: 100%; margin: 0; }
.join-stack .btn { margin-top: 0; }
/* logo nhỏ lại + khoảng cách gọn để màn nhập tên vừa điện thoại, không phải scroll */
.join-stack { gap: 12px; max-width: 500px; }
/* màn nhập tên: bớt padding 2 bên để ảnh card to hơn */
#joinScreen { padding-left: 12px; padding-right: 12px; }
/* logo căn giữa tuyệt đối (chống lệch trái) */
.join-stack .logo-img { width: 78%; max-width: 280px; margin-left: auto; margin-right: auto; align-self: center; }
/* thông báo lỗi nằm NGOÀI card, đọc rõ trên nền */
.join-stack > .error { margin: 0; min-height: 0; text-shadow: 0 1px 3px rgba(255,255,255,.95), 0 0 2px rgba(255,255,255,.9); }
/* card nhập tên = ảnh baked join-card.webp + overlay giờ / nhiệt độ / ô nhập (tỉ lệ cố định -> overlay % ổn định) */
.join-card { position: relative; width: 100%; max-width: 480px; aspect-ratio: 544 / 591; margin: 0 auto;
  background: url("/images/ui/join-card.webp") center / 100% 100% no-repeat;
  border: 0; padding: 0; box-shadow: none; }
/* nhãn trắng overlay (chữ không baked trong ảnh) */
.jc-lbl { position: absolute; color: #fff; font-weight: 800; line-height: 1.15; letter-spacing: .3px;
  font-size: clamp(.7rem, 3.4vw, .95rem); text-shadow: 0 1px 3px rgba(150,55,0,.45); text-align: left; }
.jc-l1 { left: 9%; top: 15%; }
.jc-l2 { left: 48%; top: 46%; width: 46%; }
.jc-l3 { left: 9%; top: 78%; }
.jc-clock, .jc-temp { position: absolute; color: #fff; font-weight: 900; line-height: 1;
  font-size: clamp(3rem, 8vw, 2.5rem); text-shadow: 0 2px 5px rgba(150,55,0,.4); }
.jc-clock { left: 9%; top: 20%; }
.jc-temp { left: 48%; top: 55%; }
.jc-input { position: absolute; left: 8%; top: 84%; max-width: 84%; height: 10%;
  padding: 12px; border: 2px solid #cfe8d2; border-radius: 12px; background: #fff;
  text-align: center; font-weight: 700; color: var(--text); font-size: 1.05rem; box-sizing: border-box; }
.jc-input:focus { outline: none; }


/* official design assets: image logos / buttons / labels */
.logo-img { width: 82%; max-width: 360px; height: auto; display: block; margin: 0 auto;
  filter: drop-shadow(0 6px 8px rgba(31,94,42,.22)); }
.logo-img.sm { max-width: 230px; }
.img-btn { background: none; border: 0; padding: 0; box-shadow: none; cursor: pointer; line-height: 0; }
.img-btn img { width: 300px; max-width: 82vw; height: auto; display: block; }
.img-btn:active { transform: translateY(2px); }
.img-btn:disabled { opacity: .55; }
/* rules screen: baked-in image panel + waiting pill */
.rules-stack { gap: 14px; }
.rules-stack .logo-img { max-width: 300px; }
.rules-panel-box { position: relative; width: 100%; max-width: 400px; margin: 0 auto; }
.rules-panel-img { width: 100%; height: auto; display: block;
  filter: drop-shadow(0 8px 14px rgba(120,50,0,.18)); }
/* thời gian (theo setting) overlay ngay sau chữ "trong" trong mục MỤC TIÊU */
.rules-dur { position: absolute; left: 17.5%; top: 17%; transform: translateY(-50%);
  color: #f3791b; font-weight: 800; font-size: clamp(.72rem, 3.4vw, 1rem); white-space: nowrap; }
.waiting-img { width: 78%; max-width: 320px; height: auto; display: block; margin: 0 auto;
  animation: waitPulse 1.4s ease-in-out infinite; }
@keyframes waitPulse { 0%,100% { transform: scale(1); opacity: 1; } 50% { transform: scale(.97); opacity: .85; } }
.victory-mascot { width: 70%; max-width: 280px; height: auto; display: block; margin: 4px auto;
  filter: drop-shadow(0 8px 10px rgba(31,94,42,.28)); }
/* popup nhãn xếp dọc: ĐIỂM -> TÊN ITEM -> (COMBO x2) */
.pop-label { display: flex; flex-direction: column; align-items: center; gap: 2px; }
.pop-label img { display: block; height: auto; filter: drop-shadow(0 3px 4px rgba(120,55,0,.35)); }
.pop-label .pl-pts { width: 110px; max-width: 32vw; }
.pop-label .pl-name { width: 150px; max-width: 44vw; margin-top: -2px; }
.pop-label .pl-combo { width: 140px; max-width: 42vw; margin-top: 1px; }
/* combo: điểm to hơn cho nổi bật */
.pop-label.combo .pl-pts { width: 150px; max-width: 42vw; }

.seg { display: flex; gap: 10px; }
.seg button { flex: 1; padding: 14px 4px; border-radius: 10px; border: 2px solid #bfe3c4; background: #fff;
  font-weight: 800; color: var(--leaf-dark); cursor: pointer; font-size: .95rem; white-space: nowrap; }
/* nút chọn = XANH (giống design) */
.seg button.on { background: linear-gradient(180deg, #3ba94c, #2e9b3e); color: #fff; border-color: #1f7a2e; }

/* QR screen — không card, logo ngoài, QR trong hộp trắng (giống design) */
.qr-stack { display: flex; flex-direction: column; align-items: center; gap: 12px; width: 100%; max-width: 420px; }
.qr-stack .logo-img { max-width: 280px; }
/* hộp QR: viền gradient cam-vàng bọc ngoài, ô trắng bên trong (giống design) */
.qr-box { background: linear-gradient(160deg, #ffd23f 0%, #f3791b 100%); padding: 9px; border-radius: 28px;
  display: inline-block; box-shadow: 0 10px 26px rgba(150,55,0,.22); }
#qrcode { display: block; line-height: 0; background: #fff; padding: 14px; border-radius: 20px; }
#qrcode img, #qrcode canvas { display: block; border-radius: 6px; }
.joinurl { display: none; font-family: monospace; color: var(--leaf-dark); word-break: break-all; font-weight: 700;
  font-size: .8rem; -webkit-user-select: text; user-select: text; max-width: 90%; }
.joined { font-size: 1.2rem; font-weight: 800; color: var(--leaf-dark); margin: 0;
  -webkit-text-stroke: 2px #fff; paint-order: stroke fill; text-shadow: 0 2px 2px rgba(120,55,0,.2); }
.joined b { color: var(--orange); font-size: 1.45rem; }
/* hàng avatar người chơi (flow cuối) */
.player-list { display: flex; flex-wrap: wrap; gap: 10px 8px; justify-content: center; max-width: 340px; min-height: 60px; }
.pavatar { display: flex; flex-direction: column; align-items: center; gap: 4px; width: 60px; }
.pav-circle { width: 44px; height: 44px; border-radius: 50%; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(180deg, #fbaf3a, #f3791b); color: #fff; font-weight: 900; font-size: 1.2rem;
  border: 2px solid #fff; box-shadow: 0 3px 6px rgba(150,55,0,.25); }
/* ô cuối (+N) dùng chung màu cam như các ô khác */
.pavatar.more .pav-circle { font-size: 1.05rem; }
.pav-name { font-size: .95rem; font-weight: 800; color: var(--leaf-dark); max-width: 64px;
  white-space: normal; overflow-wrap: break-word; word-break: break-word; line-height: 1.15; text-align: center;
  -webkit-text-stroke: 1.5px #fff; paint-order: stroke fill; }
.start-img img { width: 240px; max-width: 80vw; }
.reset-img img { width: 280px; max-width: 82vw; }
.home-img { margin-top: 6px; }
.home-img img { width: 260px; max-width: 80vw; }
.endbtn-img img { width: 230px; max-width: 70vw; }
.ready-img img { width: 280px; max-width: 82vw; }

/* Game */
#gameWrap { display: none; position: fixed; inset: 0;
  background: url("/images/backgrounds/bg-scene-pool-2.webp") center / 100% 100% no-repeat; }
#gameWrap.active { display: block; }
#game { width: 100%; height: 100%; display: block; background: transparent; }
.hud { position: fixed; top: 0; left: 0; right: 0; padding: 12px 16px;
  display: flex; justify-content: end; gap: 8px; pointer-events: none; }
.hud .pill { background: rgba(255,255,255,.92); border-radius: 14px; padding: 8px 14px; text-align: center;
  box-shadow: 0 4px 10px rgba(0,0,0,.12); }
.hud .pill .lbl { font-size: .62rem; color: var(--muted); font-weight: 800; display: block; }
.hud .pill .v { font-size: 1.3rem; font-weight: 900; color: var(--leaf-dark); }
.hud .pill.rank .v { color: var(--orange); }
.hud .pill.time .v { color: #d64545; }

/* floating popups */
.popups { position: fixed; inset: 0; pointer-events: none; overflow: hidden; }
.pop { position: absolute; white-space: nowrap; animation: floatUp 1s ease-out forwards; }
@keyframes floatUp { 0% { transform: translateY(0) scale(.6); opacity: 0; }
  20% { opacity: 1; transform: translateY(-6px) scale(1.1); } 100% { transform: translateY(-70px) scale(1); opacity: 0; } }

#countdown { position: fixed; inset: 0; display: none; align-items: center; justify-content: center;
  font-size: 8rem; font-weight: 900; color: var(--lemon); -webkit-text-stroke: 3px var(--leaf-dark);
  background: rgba(31,94,42,.35); z-index: 50; }
#countdown.active { display: flex; }
/* player result: 1 card cream (logo trong card, header cam, cúp trái + điểm phải) */
.result-card { border: 25px solid transparent;
  border-image: url("/images/ui/panel-cream.webp") 60 fill stretch;
  background: transparent; padding: 10px; }
.result-logo { width: 100%; max-width: 320px; min-width: 280px; margin: 0px auto; position: relative; z-index: 2;
  filter: drop-shadow(0 6px 8px rgba(120,60,0,.22)); }
.result-table { width: 100%; border-collapse: collapse; margin: 6px 0 0; border-radius: 12px; overflow: hidden; }
.result-table th, .result-table td { padding: 11px 8px; font-weight: 800; text-align: center; }
.result-table thead { background: linear-gradient(180deg, #f9a825, #f1731b); color: #fff; }
.result-table thead th { font-size: .85rem; letter-spacing: .3px; }
.result-table tbody td { background: #fff6df; font-size: 1.3rem; color: var(--leaf-dark); }
.result-table tbody td#rRank { color: var(--orange); }
.congrats-img { display: block; width: 70%; max-width: 280px; height: auto; margin: 16px auto 10px; }
.congrats-body { display: flex; align-items: center; justify-content: center; gap: 4px; padding: 4px 0 8px; }
.congrats-body .victory-mascot { width: 46%; max-width: 180px; margin: 0; }
.congrats-score { text-align: left; }
.congrats-score p { color: var(--leaf-dark); font-weight: 800; font-size: .8rem; margin: 0 0 2px; max-width: 140px; }
.congrats-score .hi { font-size: 3.2rem; text-align: center; font-weight: 900; color: var(--orange); line-height: 1;
  text-shadow: 0 2px 4px rgba(191,94,8,.2); }
/* closed screen: dùng nguyên 1 ảnh card đã bake (logo + chai + mascot + chữ QR) */
/* pháo hoa màn kết quả: canvas phủ màn, nằm SAU thẻ kết quả */
#fireworks { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 0; }
#resultScreen .result-stack { position: relative; z-index: 1; }
.closed-card-img { display: block; width: 100%; max-width: 420px; height: auto; margin: 0 auto;
  filter: drop-shadow(0 10px 14px rgba(120,60,0,.22)); }
.card { position: relative; }

/* ---- HOST big screen ---- */
.host-body { overflow-y: auto; touch-action: auto; }
/* ---- Host live screen (Đường đua + bảng xếp hạng) — match design ---- */
.live-stack { display: flex; flex-direction: column; align-items: center; gap: 12px; width: 100%; max-width: 520px; }
.live-stack .logo-img { max-width: 300px; }
.cream-card { background: #fff6df; }
.titled .cream-card { padding-top: 32px; }
/* --- End screen: panel ảnh baked TOP 10 + overlay 10 hàng tên/điểm --- */
.end-panel { position: relative; width: 100%; max-width: 440px; margin: 0 auto; }
.ep-bg { width: 100%; height: auto; display: block; }
.ep-rows { position: absolute; inset: 0; }
.ep-row { position: absolute; left: 0; right: 0; transform: translateY(-50%); }
.ep-row:nth-child(1)  { top: 22%; }
.ep-row:nth-child(2)  { top: 30.4%; }
.ep-row:nth-child(3)  { top: 37.9%; }
.ep-row:nth-child(4)  { top: 45.8%; }
.ep-row:nth-child(5)  { top: 54.2%; }
.ep-row:nth-child(6)  { top: 61.9%; }
.ep-row:nth-child(7)  { top: 70.1%; }
.ep-row:nth-child(8)  { top: 78.3%; }
.ep-row:nth-child(9)  { top: 86.4%; }
.ep-row:nth-child(10) { top: 94.3%; }
.ep-row .ep-nm { position: absolute; left: 30%; right: 28%; color: #1f7a34; font-weight: 800;
  font-size: clamp(12px, 3.7vw, 18px); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; text-align: left; }
.ep-row .ep-sc { position: absolute; right: 15%; color: #1f7a34; font-weight: 900;
  font-size: clamp(13px, 3.9vw, 19px); text-align: right; }

/* --- Battle: thời gian còn lại ở dưới --- */
.time-left { font-weight: 900; color: #1f7a34; font-size: 1.45rem; margin-top: 2px;
  -webkit-text-stroke: 2px #fff; paint-order: stroke fill; text-shadow: 0 2px 2px rgba(120,55,0,.2); }
.time-left b { color: #f5901f; font-size: 1.7rem; }
/* --- Battle: panel ảnh baked + overlay số đếm & bảng đua --- */
.battle-panel { position: relative; width: 100%; max-width: 440px; margin: 0 auto; }
.bp-bg { width: 100%; height: auto; display: block; }
/* số đếm xN trên 4 chip (vị trí theo icon baked: TL chanh, TR mong, BL tra, BR matroi) */
.bp-count { position: absolute; transform: translate(-50%, -50%); color: #1f7a34; font-weight: 900;
  font-size: clamp(16px, 5.6vw, 26px); -webkit-text-stroke: 2px #fff; paint-order: stroke fill;
  text-shadow: 0 2px 2px rgba(120,55,0,.25); letter-spacing: .5px; }
.bp-count[data-k="chanh"]  { left: 38%; top: 13%; }
.bp-count[data-k="mong"]   { left: 80%; top: 13%; }
.bp-count[data-k="tra"]    { left: 38%; top: 27%; }
.bp-count[data-k="matroi"] { left: 80%; top: 27%; }
.bp-count.bump { animation: numPop .4s ease; }
@keyframes numPop { 0% { transform: translate(-50%,-50%) scale(1); }
  35% { transform: translate(-50%,-50%) scale(1.4); color: #fff59d; }
  100% { transform: translate(-50%,-50%) scale(1); } }
/* bảng đua: 5 hàng overlay (medal/số thứ tự đã baked sẵn) */
.bp-rows { position: absolute; inset: 0; }
.bp-row { position: absolute; left: 10px; right: 10px; transform: translateY(-50%); display: flex; align-items: center; }
.bp-row:nth-child(1) { top: 60%; }
.bp-row:nth-child(2) { top: 67.65%; }
.bp-row:nth-child(3) { top: 75.3%; }
.bp-row:nth-child(4) { top: 82.95%; }
.bp-row:nth-child(5) { top: 90.6%; }
.bp-row .bp-nm { position: absolute; left: 25%; right: 28%; color: #1f7a34; font-weight: 800;
  font-size: clamp(13px, 4.1vw, 20px); white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  text-align: left; }
.bp-row .bp-sc { position: absolute; right: 16%; color: #1f7a34; font-weight: 900;
  font-size: clamp(14px, 4.4vw, 22px); text-align: right; }
.controls { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; margin-top: 18px; }

/* ===== Màn thấp/nhỏ: thu gọn logo + khoảng cách + padding để thấy nút, hạn chế cuộn ===== */
@media (max-height: 820px) {
  .screen { padding: 12px; }
  .logo-img,
  .join-stack .logo-img, .config-stack .logo-img, .live-stack .logo-img,
  .qr-stack .logo-img, .rules-stack .logo-img { max-width: 200px; }
  .join-stack, .config-stack, .live-stack, .qr-stack { gap: 8px; }
  .result-stack { gap: 10px; }
  .titled { padding-top: 18px; }
  .gift img { height: 86px; }
  .rcol-img, .timer-box { max-width: 100px; }
  .time-left { font-size: 1.25rem; margin-top: 0; }
  /* giới hạn panel cao theo chiều cao màn -> không phải cuộn mới thấy nút */
  .battle-panel { max-width: min(440px, 46vh); }
  .end-panel { max-width: min(440px, 40vh); }
  .settings-panel { max-width: min(440px, 54vh); }
}
/* Màn rất thấp (Android nhỏ, landscape...): gọn thêm nữa */
@media (max-height: 690px) {
  .screen { padding: 8px; }
  .logo-img,
  .join-stack .logo-img, .config-stack .logo-img, .live-stack .logo-img,
  .qr-stack .logo-img, .rules-stack .logo-img { max-width: 150px; }
  .join-stack, .config-stack, .live-stack, .qr-stack, .result-stack { gap: 6px; }
  .gift img { height: 70px; }
  .gift-name { font-size: .8rem; }
  .battle-panel { max-width: min(440px, 44vh); }
  .end-panel { max-width: min(440px, 38vh); }
  .settings-panel { max-width: min(440px, 50vh); }
}
