/* DualFace - giao diện. Sân chơi logic 400x600 được scale bằng transform để overlay luôn khớp canvas. */
:root {
  --bg: #0e1222;
  --panel: #171c33;
  --panel-2: #1f2545;
  --text: #f3f4ff;
  --muted: #9aa3c7;
  --accent: #ffb703;
  --accent-2: #fb8500;
  --ok: #2ec4b6;
  --danger: #ef476f;
  --p1: #3b82f6;
  --p2: #ef4444;
  --p3: #22c55e;
  --p4: #a855f7;
  --radius: 16px;
  --shadow: 0 10px 30px rgba(0, 0, 0, .35);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: radial-gradient(1200px 800px at 50% -10%, #223059 0%, var(--bg) 60%);
  color: var(--text);
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  overflow: hidden;
  touch-action: manipulation;
  -webkit-user-select: none; user-select: none;
}
button { font: inherit; cursor: pointer; }
input { font: inherit; }
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

#app {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 24px;
  padding: 8px;
}

/* ---- Sân chơi ---- */
#stage-wrap { position: relative; flex: none; }
#stage {
  position: relative;
  width: 400px; height: 600px;
  transform-origin: top left;
  border-radius: 18px;
  overflow: hidden;
  box-shadow: var(--shadow);
  background: #70c5ce;
}
#game { display: block; width: 400px; height: 600px; image-rendering: auto; }

/* HUD */
#hud {
  position: absolute; inset: 0 0 auto 0;
  display: flex; gap: 5px; justify-content: center; padding: 10px 92px 10px 8px; /* chừa chỗ nút góc phải */
  pointer-events: none;
}
.chip {
  display: flex; align-items: center; gap: 6px;
  background: rgba(10, 12, 30, .72); border: 2px solid var(--c, #fff);
  border-radius: 999px; padding: 3px 9px 3px 3px;
  font-weight: 700; font-size: 15px; color: #fff; min-width: 62px;
  backdrop-filter: blur(4px);
  transition: transform .15s;
}
.chip.dead { opacity: .45; filter: grayscale(1); }
.chip.pop { transform: scale(1.12); }
.chip .ava { width: 24px; height: 24px; border-radius: 50%; object-fit: cover; background: #ffe9c7; display: grid; place-items: center; font-size: 15px; overflow: hidden; }
.chip .ava img { width: 100%; height: 100%; object-fit: cover; }
#hud-level {
  position: absolute; top: 48px; left: 0; right: 0; text-align: center; font-size: 12px; font-weight: 700;
  color: rgba(255, 255, 255, .85); text-shadow: 0 1px 2px rgba(0,0,0,.6); pointer-events: none;
}

/* Vùng chạm (chỉ hiện trên thiết bị cảm ứng khi đang chơi) */
#touch-zones { position: absolute; inset: 0; display: none; pointer-events: none; }
#touch-zones.show { display: flex; }
#touch-zones .zone { flex: 1; border-left: 2px dashed rgba(255,255,255,.25); display: flex; align-items: flex-end; justify-content: center; padding-bottom: 70px; font-weight: 800; color: rgba(255,255,255,.55); font-size: 14px; }
#touch-zones .zone:first-child { border-left: 0; }

/* Đếm ngược */
#countdown {
  position: absolute; inset: 0; display: grid; place-items: center; pointer-events: none;
  font-size: 120px; font-weight: 900; color: #fff; text-shadow: 0 6px 0 #1b1b2f, 0 0 30px rgba(0,0,0,.5);
}
#countdown span { animation: pop .9s ease-out; display: block; }
@keyframes pop { 0% { transform: scale(1.6); opacity: 0; } 30% { transform: scale(1); opacity: 1; } 100% { transform: scale(.9); opacity: 0; } }

/* ---- Overlay chung ---- */
.overlay {
  position: absolute; inset: 0;
  display: flex;
  overflow: auto;                 /* nội dung cao hơn khung thì cuộn, không bị cắt đỉnh */
  background: rgba(8, 10, 26, .55);
  backdrop-filter: blur(3px);
  padding: 14px;
  scrollbar-width: thin;
}
.overlay-card {
  width: 100%; margin: auto;       /* tự căn giữa khi vừa khung */
  background: var(--panel);
  border: 1px solid rgba(255,255,255,.08);
  border-radius: var(--radius);
  padding: 18px 16px;
  box-shadow: var(--shadow);
  scrollbar-width: thin;
}
.overlay-card h1, .overlay-card h2 { margin: 0 0 6px; }
.title { font-size: 34px; font-weight: 900; letter-spacing: 1px; text-align: center; line-height: 1; }
.title .a { color: var(--p1); } .title .b { color: var(--p2); }
.subtitle { text-align: center; color: var(--muted); font-size: 13px; margin: 4px 0 14px; }
.section-label { font-size: 12px; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); margin: 12px 0 6px; font-weight: 700; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 0; border-radius: 12px; padding: 12px 16px;
  font-weight: 800; font-size: 16px; color: #1b1b2f; background: var(--accent);
  box-shadow: 0 4px 0 #b57d00; transition: transform .06s, box-shadow .06s, filter .15s;
  min-height: 44px;
}
.btn:hover { filter: brightness(1.05); }
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 #b57d00; }
.btn:focus-visible, button:focus-visible, input:focus-visible { outline: 3px solid #fff; outline-offset: 2px; }
.btn.block { width: 100%; }
.btn.secondary { background: var(--panel-2); color: #fff; box-shadow: 0 4px 0 #0c0f22; }
.btn.secondary:active { box-shadow: 0 1px 0 #0c0f22; }
.btn.ghost { background: transparent; color: var(--muted); box-shadow: none; padding: 8px 10px; min-height: 36px; font-size: 14px; }
.btn.ghost:hover { color: #fff; }
.btn.ok { background: var(--ok); box-shadow: 0 4px 0 #1b8a80; }
.btn.danger { background: var(--danger); color: #fff; box-shadow: 0 4px 0 #9b1f41; }
.btn.small { padding: 8px 12px; font-size: 14px; min-height: 36px; border-radius: 10px; }
.btn[disabled] { opacity: .5; cursor: not-allowed; filter: grayscale(.5); }
.row { display: flex; gap: 8px; flex-wrap: wrap; }
.row > .btn { flex: 1; }
.stack { display: flex; flex-direction: column; gap: 8px; }

/* Chọn số người */
.seg { display: flex; background: var(--panel-2); border-radius: 12px; padding: 4px; gap: 4px; }
.seg button { flex: 1; border: 0; border-radius: 9px; padding: 10px 0; background: transparent; color: var(--muted); font-weight: 800; font-size: 16px; min-height: 42px; }
.seg button[aria-pressed="true"] { background: var(--accent); color: #1b1b2f; }

/* Thẻ người chơi */
.players { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.pcard {
  background: var(--panel-2); border-radius: 14px; padding: 10px; border-top: 4px solid var(--c);
  display: flex; flex-direction: column; gap: 6px; align-items: center;
}
.pcard .ava-big {
  width: 64px; height: 64px; border-radius: 50%; border: 3px solid var(--c); background: #ffe9c7;
  display: grid; place-items: center; font-size: 36px; overflow: hidden; cursor: pointer; position: relative;
}
.pcard .ava-big img { width: 100%; height: 100%; object-fit: cover; }
.pcard .ava-big .cam { position: absolute; right: -2px; bottom: -2px; background: var(--c); color: #fff; width: 22px; height: 22px; border-radius: 50%; font-size: 12px; display: grid; place-items: center; border: 2px solid var(--panel-2); }
.pcard input {
  width: 100%; background: rgba(0,0,0,.25); border: 1px solid rgba(255,255,255,.1); color: #fff;
  border-radius: 8px; padding: 6px 8px; text-align: center; font-weight: 700; font-size: 14px;
}
.pcard .key { font-size: 11px; color: var(--muted); font-weight: 700; }
.pcard .key kbd { background: #0c0f22; border: 1px solid rgba(255,255,255,.15); border-bottom-width: 3px; border-radius: 5px; padding: 1px 6px; color: #fff; font-family: inherit; }
.pcard .mini { display: flex; gap: 4px; }
.pcard .mini button { border: 0; background: rgba(255,255,255,.08); color: #fff; border-radius: 8px; padding: 4px 8px; font-size: 12px; font-weight: 700; min-height: 30px; }
.pcard .mini button:hover { background: rgba(255,255,255,.16); }

/* Lưới màn chơi */
.levels { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.lcard {
  position: relative; border: 0; border-radius: 14px; padding: 10px; text-align: left; color: #fff;
  background: linear-gradient(160deg, var(--sky0), var(--sky1)); min-height: 108px;
  display: flex; flex-direction: column; gap: 3px; box-shadow: inset 0 0 0 1px rgba(255,255,255,.12);
  transition: transform .08s;
}
.lcard:hover { transform: translateY(-2px); }
.lcard .ic { font-size: 28px; line-height: 1; }
.lcard .nm { font-weight: 900; font-size: 15px; text-shadow: 0 1px 2px rgba(0,0,0,.5); }
.lcard .tg { font-size: 11px; opacity: .9; text-shadow: 0 1px 2px rgba(0,0,0,.6); line-height: 1.25; }
.lcard .stars { font-size: 11px; color: var(--accent); letter-spacing: 1px; }
.lcard .best { position: absolute; top: 8px; right: 8px; font-size: 11px; background: rgba(0,0,0,.45); padding: 2px 6px; border-radius: 999px; }
.lcard.locked { filter: grayscale(.9) brightness(.55); }
.lcard.locked::after { content: "🔒"; position: absolute; inset: 0; display: grid; place-items: center; font-size: 32px; }
.lcard.done .nm::after { content: " ✔"; color: var(--ok); }
.lcard.selected { outline: 3px solid var(--accent); }

/* Màn sẵn sàng */
.ready-level { display: flex; align-items: center; gap: 12px; background: var(--panel-2); border-radius: 12px; padding: 10px; }
.ready-level .ic { font-size: 40px; }
.ready-level .nm { font-weight: 900; font-size: 20px; }
.ready-level .tg { color: var(--muted); font-size: 13px; }
.tip { background: rgba(255,183,3,.12); border-left: 4px solid var(--accent); padding: 8px 10px; border-radius: 8px; font-size: 13px; margin: 10px 0; }
.controls { display: grid; grid-template-columns: 1fr; gap: 6px; }
.ctl { display: flex; align-items: center; gap: 8px; background: var(--panel-2); border-radius: 10px; padding: 6px 8px; font-size: 13px; border-left: 4px solid var(--c); }
.ctl .ava { width: 28px; height: 28px; border-radius: 50%; overflow: hidden; background: #ffe9c7; display: grid; place-items: center; font-size: 18px; flex: none; }
.ctl .ava img { width: 100%; height: 100%; object-fit: cover; }
.ctl kbd { background: #0c0f22; border: 1px solid rgba(255,255,255,.15); border-bottom-width: 3px; border-radius: 5px; padding: 1px 6px; font-family: inherit; font-weight: 700; }
.ctl .nm { font-weight: 800; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Kết quả */
.rank { display: flex; flex-direction: column; gap: 6px; margin: 8px 0; }
.rk { display: flex; align-items: center; gap: 10px; background: var(--panel-2); border-radius: 12px; padding: 8px 10px; border-left: 5px solid var(--c); }
.rk.first { background: linear-gradient(90deg, rgba(255,183,3,.25), var(--panel-2)); }
.rk .pl { font-size: 22px; width: 32px; text-align: center; }
.rk .ava { width: 36px; height: 36px; border-radius: 50%; overflow: hidden; background: #ffe9c7; display: grid; place-items: center; font-size: 22px; border: 2px solid var(--c); }
.rk .ava img { width: 100%; height: 100%; object-fit: cover; }
.rk .nm { font-weight: 800; flex: 1; }
.rk .sc { font-weight: 900; font-size: 18px; }
.rk .wins { font-size: 11px; color: var(--muted); }
.badge { display: inline-block; background: var(--ok); color: #062a27; font-weight: 900; padding: 4px 10px; border-radius: 999px; font-size: 13px; }
.badge.warn { background: var(--accent); color: #1b1b2f; }
.center { text-align: center; }
.winner-title { font-size: 26px; font-weight: 900; text-align: center; margin: 4px 0 10px; }

/* Camera modal */
#cam-box { position: relative; width: 100%; aspect-ratio: 4 / 3; background: #000; border-radius: 12px; overflow: hidden; }
#cam-video { width: 100%; height: 100%; object-fit: cover; transform: scaleX(-1); }
#cam-guide { position: absolute; top: 50%; left: 50%; width: 60%; aspect-ratio: 1; transform: translate(-50%, -50%); border: 3px dashed #fff; border-radius: 50%; box-shadow: 0 0 0 999px rgba(0,0,0,.45); pointer-events: none; }
#cam-flash { position: absolute; inset: 0; background: #fff; opacity: 0; pointer-events: none; transition: opacity .25s; }
#cam-error { color: var(--danger); font-size: 13px; margin: 6px 0; }
.emoji-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; }
.emoji-grid button { border: 0; background: var(--panel-2); border-radius: 10px; font-size: 26px; padding: 6px 0; min-height: 44px; }
.emoji-grid button:hover { background: #2b325c; }

/* Bảng bên (desktop) */
#side {
  width: 260px; display: none; flex-direction: column; gap: 12px; color: var(--text);
}
#side .panel { background: var(--panel); border-radius: var(--radius); padding: 14px; border: 1px solid rgba(255,255,255,.06); }
#side h3 { margin: 0 0 8px; font-size: 13px; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); }
#side .series { display: flex; flex-direction: column; gap: 6px; }
#side .srow { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 14px; }
#side .srow .dot { width: 12px; height: 12px; border-radius: 50%; background: var(--c); }
#side .srow .w { margin-left: auto; font-weight: 900; }
#side .help { font-size: 13px; color: var(--muted); line-height: 1.5; }
#side kbd { background: #0c0f22; border: 1px solid rgba(255,255,255,.15); border-bottom-width: 3px; border-radius: 5px; padding: 0 6px; font-family: inherit; color: #fff; }
@media (min-width: 900px) { #side { display: flex; } }

/* Nút nổi góc */
#topbar { position: absolute; top: 8px; right: 8px; display: flex; gap: 6px; z-index: 5; }
#topbar button { border: 0; background: rgba(10,12,30,.7); color: #fff; width: 38px; height: 38px; border-radius: 50%; font-size: 17px; display: grid; place-items: center; }
#topbar button:hover { background: rgba(10,12,30,.95); }

.toast {
  position: absolute; left: 50%; bottom: 70px; transform: translateX(-50%);
  background: rgba(10,12,30,.9); color: #fff; padding: 8px 14px; border-radius: 999px; font-weight: 700; font-size: 13px;
  pointer-events: none; opacity: 0; transition: opacity .2s; white-space: nowrap;
}
.toast.show { opacity: 1; }

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

/* Giải đấu & kết quả mở rộng */
#results-tour { background: var(--panel-2); border-radius: 12px; padding: 8px 10px; }
#results-tour .section-label { margin: 0 0 6px; }
#results-tour .srow { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 14px; }
#results-tour .srow .dot { width: 12px; height: 12px; border-radius: 50%; background: var(--c); }
#results-tour .srow .w { margin-left: auto; font-weight: 900; color: var(--accent); }

/* Bảng xếp hạng online */
.online { background: var(--panel-2); border-radius: 12px; padding: 8px 10px; margin-bottom: 10px; }
.online .section-label { margin: 0 0 6px; }
.online .srow { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 14px; padding: 2px 4px; border-radius: 6px; }
.online .srow.me { background: rgba(255,183,3,.18); }
.online .srow .pos { width: 18px; text-align: right; color: var(--muted); font-size: 12px; }
.online .srow .em { font-size: 16px; }
.online .srow .w { margin-left: auto; font-weight: 900; color: var(--accent); }
.lcard .best.world { top: 30px; background: rgba(46,196,182,.55); }
.online .srow .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.online .hint { margin-top: 6px; font-size: 12px; color: var(--accent); line-height: 1.4; }
.online .hint.muted { color: var(--muted); }

/* Bảng xếp hạng tuần / mọi lúc */
.seg.small { padding: 3px; }
.seg.small button { padding: 6px 0; min-height: 36px; font-size: 13px; }
.online-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 6px; }
.online-head .section-label { margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.online-head .seg { flex: none; width: 160px; }
.online .btn.block { margin-top: 6px; }
.pick {
  width: 100%; min-height: 44px; border-radius: 12px; border: 1px solid rgba(255,255,255,.12);
  background: var(--panel-2); color: var(--text); font-weight: 700; font-size: 15px; padding: 0 12px;
}
.pick option { background: var(--panel); color: var(--text); }
.board-list { margin: 10px 0; min-height: 120px; }
.board-list .srow { padding: 6px 6px; font-size: 15px; }
.board-list .srow .pos { width: 26px; font-size: 14px; }
