* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #0b150d; color: #fff;
  font-family: "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; -webkit-user-select: none; user-select: none; }
body.transparent, body.transparent #stage { background: transparent !important; }
button { font: inherit; }

/* Sân khấu cố định 1080×1920 (dọc) hoặc 1920×1080 (ngang), co giãn bằng transform cho vừa cửa sổ / nguồn OBS */
#stage { position: absolute; left: 0; top: 0; transform-origin: 0 0; overflow: hidden;
  background: radial-gradient(ellipse at 50% 40%, #1f4424 0%, #10241a 55%, #08120c 100%); }
#cv { position: absolute; left: 0; top: 0; }
#stage section { position: absolute; }
#stage .card { background: rgba(8, 22, 12, .74); border: 3px solid rgba(255, 255, 255, .08); border-radius: 28px; }

/* ---------- HUD ---------- */
#hud { background: rgba(8, 22, 12, .78); border: 3px solid rgba(255, 255, 255, .09); border-radius: 30px;
  padding: 16px 26px 14px; text-shadow: 0 2px 4px rgba(0, 0, 0, .45); }
#hud .row1 { display: flex; align-items: center; justify-content: space-between; gap: 16px; height: 54px; }
#hud .brand { display: flex; align-items: center; gap: 12px; white-space: nowrap; }
#hud .logo { font-size: 44px; line-height: 1; font-family: "Segoe UI Emoji", "Apple Color Emoji", "Noto Color Emoji", sans-serif; }
#hud .name { font-size: 40px; font-weight: 900; letter-spacing: 1px; color: #b8f36b; }
#hud .live { font-size: 20px; font-weight: 900; letter-spacing: 2px; padding: 3px 12px; border-radius: 10px;
  background: #ff2d55; color: #fff; box-shadow: 0 0 18px rgba(255, 45, 85, .6); animation: livepulse 1.6s infinite; }
@keyframes livepulse { 50% { box-shadow: 0 0 4px rgba(255, 45, 85, .3); } }
#hud .meta { font-size: 26px; opacity: .9; white-space: nowrap; }
#hud .meta .dot { margin: 0 10px; opacity: .5; }
#hud .lenbar { position: relative; height: 62px; margin-top: 10px; border-radius: 31px; overflow: hidden;
  background: rgba(255, 255, 255, .1); box-shadow: inset 0 3px 8px rgba(0, 0, 0, .45); }
#hud .lenbar .fill { position: absolute; left: 0; top: 0; bottom: 0; width: 0; border-radius: 31px;
  background: linear-gradient(90deg, #2fbf5b, #9be15d 70%, #ffe45c); transition: width .35s ease-out;
  box-shadow: 0 0 22px rgba(155, 225, 93, .55); }
#hud .lenbar .marks i { position: absolute; top: 12px; bottom: 12px; width: 3px; background: rgba(255, 255, 255, .22); border-radius: 2px; }
#hud .lenbar .txt { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  gap: 10px; font-size: 30px; font-weight: 700; text-shadow: 0 0 6px rgba(0, 0, 0, .85), 0 2px 3px rgba(0, 0, 0, .8); }
#hud .lenbar .txt b { font-size: 46px; font-weight: 900; }
#hud .lenbar .txt .of { opacity: .85; }
#hud .lenbar.bump .txt b { animation: bump .35s; }
@keyframes bump { 40% { transform: scale(1.3); } }
#hud .tug { display: grid; grid-template-columns: 150px 1fr 150px; align-items: center; gap: 14px; margin-top: 14px; }
#hud .tug .side { display: flex; align-items: center; gap: 8px; font-size: 36px; font-weight: 900; }
#hud .tug .side.b { justify-content: flex-end; }
#hud .tug .side.a b { color: #6ef08a; }
#hud .tug .side.b b { color: #ff9a3c; }
#hud .tug .ic { width: 46px; height: 46px; }
#hud .tugbar { position: relative; display: flex; height: 26px; border-radius: 13px; overflow: hidden;
  background: rgba(255, 255, 255, .1); box-shadow: inset 0 2px 6px rgba(0, 0, 0, .5); }
#hud .tugbar .fa { background: linear-gradient(90deg, #1fae4a, #6ef08a); width: 50%; transition: width .4s; }
#hud .tugbar .fb { background: linear-gradient(90deg, #ff9a3c, #e8461c); flex: 1; }
#hud .tugbar .mid { position: absolute; left: 50%; top: -4px; bottom: -4px; width: 4px; margin-left: -2px; background: #fff; opacity: .55; }
#hud .tops { display: grid; grid-template-columns: 1fr 1fr; align-items: center; gap: 16px; margin-top: 10px; height: 52px; }
#hud .tops .list { display: flex; gap: 10px; min-width: 0; overflow: hidden; }
#hud .tops .list.b { justify-content: flex-end; }
#hud .tops .vs { display: none; }
.tp { position: relative; display: flex; align-items: center; gap: 6px; padding: 3px 12px 3px 3px; border-radius: 26px;
  background: rgba(255, 255, 255, .08); font-size: 22px; font-weight: 700; white-space: nowrap; max-width: 210px; }
.tp .av { width: 44px; height: 44px; flex: 0 0 44px; }
.tp .nm { overflow: hidden; text-overflow: ellipsis; max-width: 110px; }
.tp .v { opacity: .9; }
.list.a .tp .v { color: #6ef08a; } .list.b .tp .v { color: #ff9a3c; }
.tp .rk { position: absolute; left: -4px; top: -6px; font-size: 18px; }

/* Avatar tròn (ảnh TikTok hoặc chữ cái đầu) */
.av { display: inline-flex; align-items: center; justify-content: center; border-radius: 50%; object-fit: cover;
  background: #345; color: #fff; font-weight: 900; border: 3px solid rgba(255, 255, 255, .85); overflow: hidden; }

/* ---------- Cách chơi ---------- */
#legend { overflow: hidden; background: rgba(8, 22, 12, .74); border: 3px solid rgba(255, 255, 255, .08); border-radius: 28px; padding: 12px 22px 14px; }
#legend .h { font-size: 26px; font-weight: 900; letter-spacing: 2px; color: #ffe45c; margin-bottom: 6px; }
#legend .rules { display: grid; grid-template-columns: 1fr 1fr; column-gap: 26px; row-gap: 4px; }
.rl { display: flex; align-items: center; gap: 12px; height: 44px; font-size: 26px; font-weight: 700; white-space: nowrap; min-width: 0; }
.rl .gi { width: 42px; height: 42px; flex: 0 0 42px; display: flex; align-items: center; justify-content: center;
  font-size: 34px; font-family: "Segoe UI Emoji", "Apple Color Emoji", "Noto Color Emoji", sans-serif; }
.rl .gi img { width: 42px; height: 42px; object-fit: contain; }
.rl .cond { overflow: hidden; text-overflow: ellipsis; min-width: 0; flex: 0 1 auto; }
.rl .ar { opacity: .55; flex: 0 0 auto; }
.rl .fx { display: flex; align-items: center; gap: 4px; flex: 0 0 auto; font-weight: 900; }
.rl .fx img { width: 38px; height: 38px; }
.fx.a { color: #6ef08a; } .fx.g { color: #ffd23a; } .fx.b { color: #ff9a3c; }

/* ---------- Bảng tin ---------- */
#feed { display: flex; flex-direction: column; gap: 8px; overflow: hidden; }
.fi { display: flex; align-items: center; gap: 12px; height: 56px; padding: 0 18px 0 6px; border-radius: 28px;
  background: rgba(8, 22, 12, .72); border: 2px solid rgba(255, 255, 255, .07); font-size: 25px;
  animation: fin .35s ease-out; transition: opacity .6s; white-space: nowrap; }
.fi.old { opacity: .55; }
.fi.big { border-color: rgba(255, 210, 58, .6); background: rgba(60, 44, 0, .7); }
@keyframes fin { from { transform: translateX(-40px); opacity: 0; } }
.fi .av { width: 46px; height: 46px; flex: 0 0 46px; font-size: 22px; }
.fi .tx { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.fi .tx b { color: #b8f36b; }
.fi .tx .gimg { width: 30px; height: 30px; vertical-align: -6px; }
.fi .fx { display: flex; align-items: center; gap: 4px; font-weight: 900; font-size: 28px; }
.fi .fx img { width: 34px; height: 34px; }

/* ---------- Thông báo lớn ---------- */
#banner { position: absolute; display: flex; align-items: center; justify-content: center; pointer-events: none; }
#banner .bn { display: flex; flex-direction: column; align-items: center; gap: 10px; max-width: 92%; padding: 22px 40px;
  border-radius: 32px; background: rgba(0, 0, 0, .66); border: 4px solid rgba(255, 255, 255, .25); text-align: center;
  font-size: 52px; font-weight: 900; line-height: 1.15; text-shadow: 0 3px 8px rgba(0, 0, 0, .6);
  animation: bnin .45s cubic-bezier(.2, 1.6, .4, 1); }
#banner .bn.out { animation: bnout .4s forwards; }
#banner .bn small { display: block; font-size: 32px; font-weight: 700; opacity: .92; margin-top: 6px; }
#banner.top { align-items: flex-start; padding-top: 18px; }
#banner .bn.small { flex-direction: row; gap: 18px; padding: 12px 28px 12px 14px; font-size: 38px; text-align: left; border-width: 3px; border-radius: 26px; }
#banner .bn.small small { font-size: 28px; margin-top: 2px; }
#banner .bn.small .av { width: 84px; height: 84px; font-size: 40px; flex: 0 0 84px; border-width: 4px; }
#banner .bn .av { width: 110px; height: 110px; font-size: 52px; border-width: 5px; }
#banner .bn.win { background: rgba(10, 70, 25, .82); border-color: #6ef08a; }
#banner .bn.lose { background: rgba(90, 20, 5, .84); border-color: #ff9a3c; }
#banner .bn.gold { border-color: #ffd23a; }
#banner .bn.bomb { border-color: #ff7a1a; }
@keyframes bnin { from { transform: scale(.3); opacity: 0; } }
@keyframes bnout { to { transform: scale(.85); opacity: 0; } }

/* ---------- Bố cục dọc 1080×1920 (TikTok LIVE điện thoại) ---------- */
#stage.port #hud { left: 40px; top: 96px; width: 1000px; height: 286px; }
#stage.port #legend { left: 40px; top: 1400px; width: 1000px; height: 318px; }
#stage.port #feed { left: 40px; top: 1730px; width: 1000px; height: 184px; }
/* ---------- Bố cục ngang 1920×1080 (TikTok LIVE Studio ngang / máy tính) ---------- */
#stage.land #hud { left: 1020px; top: 30px; width: 870px; height: 286px; }
#stage.land #legend { left: 1020px; top: 330px; width: 870px; height: 360px; }
#stage.land #feed { left: 1020px; top: 704px; width: 870px; height: 366px; }
#stage.land .fi { height: 52px; }
#stage.land .rl { font-size: 25px; }
#stage.land .tp .nm { max-width: 76px; }

/* ---------- Trạng thái kết nối, nút điều khiển, cài đặt (ngoài sân khấu, không co giãn) ---------- */
#status { position: fixed; left: 10px; top: 10px; z-index: 20; max-width: min(560px, calc(100vw - 20px)); padding: 6px 12px;
  border-radius: 10px; font-size: 13px; line-height: 1.35; background: rgba(0, 0, 0, .72); border: 1px solid rgba(255, 255, 255, .15);
  transition: opacity .5s; pointer-events: none; }
#status.hide { opacity: 0; }
#status .d { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 6px; background: #888; }
#status.ok .d { background: #3ddc6a; box-shadow: 0 0 8px #3ddc6a; }
#status.wait .d { background: #ffc83d; }
#status.err .d { background: #ff5a3c; }

#controls { position: fixed; left: 50%; bottom: max(10px, env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 20;
  display: flex; gap: 6px; padding: 6px; border-radius: 16px; background: rgba(0, 0, 0, .55); border: 1px solid rgba(255, 255, 255, .12);
  backdrop-filter: blur(6px); transition: opacity .4s; }
#controls.idle { opacity: .15; }
#controls[hidden] { display: none; }
#controls button { display: flex; align-items: center; gap: 6px; padding: 8px 12px; border: 0; border-radius: 11px; cursor: pointer;
  background: rgba(255, 255, 255, .1); color: #fff; font-size: 14px; font-weight: 700; white-space: nowrap;
  font-family: "Segoe UI", Roboto, Arial, "Segoe UI Emoji", "Noto Color Emoji", sans-serif; }
#controls button:hover { background: rgba(255, 255, 255, .2); }
#controls button.on { background: #2f8f4a; }
#controls img { width: 22px; height: 22px; }
@media (max-width: 520px) { #controls button span { display: none; } #controls button { padding: 9px 11px; font-size: 18px; } }

#settings { position: fixed; inset: 0; z-index: 30; display: flex; align-items: flex-start; justify-content: center;
  padding: 3vh 10px; background: rgba(0, 0, 0, .55); overflow: auto; -webkit-user-select: text; user-select: text; }
#settings[hidden] { display: none; }
#settings .panel { width: min(760px, 100%); background: #122019; color: #e6f3e8; border: 1px solid #2c4a37; border-radius: 14px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .6); font-size: 14px; }
#settings .ph { position: sticky; top: 0; z-index: 2; display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; background: #183025; border-radius: 14px 14px 0 0; font-size: 17px; }
#settings .x { border: 0; background: none; color: #fff; font-size: 20px; cursor: pointer; }
#set-body { padding: 4px 16px 16px; }
#settings h3 { margin: 18px 0 8px; font-size: 15px; color: #b8f36b; text-transform: uppercase; letter-spacing: .5px; }
#settings .hint { margin: 4px 0 8px; color: #9fb8a6; font-size: 13px; line-height: 1.45; }
#settings .hint code, #settings code { background: #0b1611; padding: 1px 5px; border-radius: 4px; color: #ffe08a; word-break: break-all; }
#settings .grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 8px 14px; }
#settings .f { display: flex; flex-direction: column; gap: 3px; color: #b9cfbf; font-size: 13px; }
#settings input, #settings select { font: inherit; color: #fff; background: #0b1611; border: 1px solid #2f4c3a; border-radius: 7px; padding: 6px 8px; min-width: 0; }
#settings input[type=checkbox] { width: auto; }
#settings input[type=range] { padding: 0; }
#settings .row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
#settings .btn { border: 1px solid #3c6a4c; background: #1f3a2b; color: #fff; border-radius: 8px; padding: 7px 12px; cursor: pointer; font-weight: 600; }
#settings .btn:hover { background: #2a4d39; }
#settings .btn.pri { background: #2f8f4a; border-color: #46b765; }
#settings .btn.warn { background: #5a2a1a; border-color: #8c4429; }
#settings .seg { display: flex; flex-wrap: wrap; gap: 6px; }
#settings .seg button { border: 1px solid #2f4c3a; background: #0b1611; color: #cfe3d4; border-radius: 8px; padding: 7px 12px; cursor: pointer; }
#settings .seg button.on { background: #2f8f4a; border-color: #46b765; color: #fff; }
#settings .cst { margin-top: 8px; padding: 8px 10px; border-radius: 8px; background: #0b1611; font-size: 13px; }
.rtable { display: flex; flex-direction: column; gap: 6px; }
.rrow { display: grid; grid-template-columns: 54px 118px 1fr 112px 70px 30px; gap: 6px; align-items: center; }
.rrow.head { color: #8fa996; font-size: 12px; }
.rrow .cnd { display: flex; gap: 6px; align-items: center; min-width: 0; }
.rrow .cnd input[type=text] { flex: 1; }
.rrow .cnd .pc { display: flex; align-items: center; gap: 3px; white-space: nowrap; font-size: 12px; color: #b9cfbf; }
.rrow .del { border: 0; background: none; color: #ff8a73; font-size: 18px; cursor: pointer; }
.rrow input.ic { text-align: center; font-size: 18px; padding: 3px; }
@media (max-width: 640px) {
  .rrow { grid-template-columns: 44px 1fr 1fr 30px; }
  .rrow .cnd { grid-column: 1 / -1; order: 5; }
  .rrow.head { display: none; }
}
.gseen { display: flex; flex-wrap: wrap; gap: 6px; }
.gseen span { display: inline-flex; align-items: center; gap: 4px; padding: 3px 8px; border-radius: 12px; background: #0b1611; font-size: 12px; cursor: pointer; }
.gseen img { width: 20px; height: 20px; }
