:root {
  --bg: #0b1b2b;
  --panel: #13283d;
  --line: #23405c;
  --text: #e8f1fa;
  --muted: #8aa4bd;
  --accent: #ffd23f;
  --good: #3ddc84;
  --bad: #ff5d5d;
  --peer: #5cc8ff;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: radial-gradient(circle at 50% 0%, #17385a, var(--bg) 70%) fixed;
  color: var(--text);
  font: 15px/1.4 "Be Vietnam Pro", "Plus Jakarta Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}
[hidden] { display: none !important; }
.ic { width: 1.15em; height: 1.15em; vertical-align: -0.2em; flex: none; }
header button { display: inline-flex; align-items: center; gap: 4px; }
button, input { font: inherit; color: inherit; }
button {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 12px;
  cursor: pointer;
  white-space: nowrap;
}
button:hover { border-color: var(--muted); }
button:disabled { opacity: .4; cursor: default; }
button.primary { background: var(--accent); color: #1b1300; border-color: var(--accent); font-weight: 600; }
input {
  background: #0a1724;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  width: 100%;
}
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 24px;
  width: min(360px, calc(100vw - 32px));
  display: grid;
  gap: 12px;
  text-align: center;
  box-shadow: 0 12px 40px #0008;
}
.card h1, .card h2 { margin: 0; }
.card label { display: grid; gap: 4px; text-align: left; color: var(--muted); }
.sub, .muted { margin: 0; color: var(--muted); }
.muted { font-size: 13px; }
.join { display: flex; gap: 8px; }
h1 .back { color: var(--muted); display: inline-flex; vertical-align: middle; }
h1 .back:hover { color: var(--text); }
.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.seg button { display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
.seg4 { grid-template-columns: repeat(4, 1fr); }
.seg4 button { padding-inline: 4px; font-variant-numeric: tabular-nums; }
.seg button.on { border-color: var(--accent); color: var(--accent); }
.seg button:disabled { opacity: 1; }
#ovTitle { display: flex; align-items: center; justify-content: center; gap: 8px; }
#code { text-transform: uppercase; letter-spacing: 3px; text-align: center; }

#home { height: 100%; display: grid; place-items: center; padding: 16px; }

#room { height: 100%; display: flex; flex-direction: column; }
header {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  padding-top: max(8px, env(safe-area-inset-top));
  overflow-x: auto;
}
header #clock { margin-left: auto; font-variant-numeric: tabular-nums; font-weight: 600; min-width: 48px; text-align: right; }
@media (max-width: 480px) {
  header { gap: 4px; padding-inline: 8px; }
  header button { padding: 6px 5px; }
  header .lbl { display: none; }
  /* Chừa chỗ cho nút Cách chơi: đồng hồ bỏ bề rộng tối thiểu; khi có thêm nút ẩn/hiện người chơi khác
     (panel.js bỏ class panel-empty) thì nút mời chỉ còn icon QR — mã phòng vẫn hiện trong hộp mời. */
  body:not(.panel-empty) header #roomCode { display: none; }
  header #clock { min-width: 0; flex: none; }
  header #modeTag { display: none; }
}
/* 360–380px (Galaxy S8/S9, iPhone SE zoom): thanh trên gọn thêm để nút âm thanh không bị đẩy khuất. */
@media (max-width: 380px) {
  header { gap: 3px; padding-inline: 6px; }
  header button { padding: 6px 4px; }
}
#modeTag { display: inline-flex; align-items: center; gap: 4px; font-size: 13px; color: var(--muted); white-space: nowrap; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--bad); flex: none; }
.dot.on { background: var(--good); }
#timeTrack { height: 6px; margin: 0 12px; background: #0a1724; border-radius: 3px; overflow: hidden; }
#timebar { height: 100%; width: 0; background: var(--good); transition: width .25s linear; }
#players { list-style: none; margin: 8px 12px 0; padding: 0; display: flex; gap: 6px; overflow-x: auto; }
#players li {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 4px 10px;
  font-size: 13px;
  white-space: nowrap;
}
#players li.me { border-color: var(--accent); }
#players li.off { opacity: .45; }
#players b { color: var(--accent); }
#players li { display: inline-flex; align-items: center; gap: 4px; }
#players .ic { color: var(--accent); }
#players li.mate { box-shadow: inset 4px 0 var(--peer); }
#players li.peer-on { border-color: var(--peer); }

#boardWrap { position: relative; flex: 1; min-height: 0; margin: 8px; }
.arena #boardWrap { margin: 8px; }
#board { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); }
.cell {
  position: absolute;
  background-image: url("images/tiles.webp");
  background-repeat: no-repeat;
  border-radius: 4px;
  outline: 1px solid #0003;
  cursor: pointer;
  transition: transform .08s;
}
.cell.sel { outline: 3px solid var(--accent); transform: scale(.92); z-index: 1; }
.cell.peer { outline: 3px dashed var(--peer); z-index: 1; }
.cell.hint { animation: hint .5s ease-in-out 3; }
@keyframes hint { 50% { outline: 3px solid var(--good); transform: scale(1.1); } }
#cells, #fx { position: absolute; inset: 0; }
#fx { pointer-events: none; z-index: 3; }
#fx > svg.path { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
#fx polyline { fill: none; stroke: var(--bad); stroke-width: 4; stroke-linecap: round; stroke-linejoin: round; }
#board.shake { animation: shake .25s; }
@keyframes shake { 25% { margin-left: -6px; } 75% { margin-left: 6px; } }

/* Hiệu ứng: ô vỡ, điểm bay, ping, banner qua màn, cảm xúc */
.cell.popping { animation: popping .35s ease-out forwards; pointer-events: none; }
@keyframes popping { to { transform: scale(1.35) rotate(8deg); opacity: 0; filter: brightness(1.8); } }
.float {
  position: absolute; transform: translate(-50%, 0); color: var(--c, var(--accent));
  font-weight: 800; font-size: 16px; text-shadow: 0 2px 4px #000a; white-space: nowrap;
  animation: floatUp .9s ease-out forwards;
}
.float.combo { font-size: 20px; }
.float b { color: var(--accent); font-size: 1.3em; }
@keyframes floatUp { to { transform: translate(-50%, -48px); opacity: 0; } }
.ping { position: absolute; border: 3px solid var(--c); border-radius: 8px; animation: ping .5s ease-out 3; }
.ping span {
  position: absolute; left: 50%; bottom: 100%; transform: translate(-50%, -2px);
  background: var(--c); color: #0b1b2b; font-size: 11px; font-weight: 700; padding: 1px 6px; border-radius: 6px; white-space: nowrap;
}
@keyframes ping { 0% { box-shadow: 0 0 0 0 var(--c); } 100% { box-shadow: 0 0 0 14px transparent; } }
.banner {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  display: grid; justify-items: center; gap: 4px; padding: 16px 28px; border-radius: 16px;
  background: #0b1b2be0; border: 2px solid var(--accent); animation: banner 1.8s ease forwards;
}
.banner b { font-size: 28px; color: var(--accent); }
@keyframes banner { 0% { opacity: 0; transform: translate(-50%, -50%) scale(.7); } 15%, 80% { opacity: 1; transform: translate(-50%, -50%) scale(1); } 100% { opacity: 0; } }
.emo-fly .ic { filter: drop-shadow(0 2px 3px #0008); }
.emo-fly { position: fixed; transform: translate(-50%, -100%); font-size: 30px; pointer-events: none; z-index: 20; animation: emo 1.6s ease-out forwards; }
@keyframes emo { to { transform: translate(-50%, -180%) scale(1.4); opacity: 0; } }
.cursor { position: absolute; transition: left 80ms linear, top 80ms linear; color: var(--c); }
.cursor .ic { width: 22px; height: 22px; fill: var(--c); stroke: #0b1b2b; stroke-width: 1.5; filter: drop-shadow(0 1px 2px #0008); }
.cursor span {
  position: absolute; left: 16px; top: 18px;
  background: var(--c); color: #0b1b2b;
  font-size: 11px; font-weight: 600; padding: 1px 6px; border-radius: 6px; white-space: nowrap;
}
#emoBar { display: flex; justify-content: center; gap: 6px; padding: 6px 12px max(8px, env(safe-area-inset-bottom)); }
#emoBar button { font-size: 20px; padding: 4px 12px; line-height: 1.2; }
#specBar { display: flex; gap: 6px; align-items: center; margin: 8px 12px 0; overflow-x: auto; font-size: 13px; color: var(--muted); }
#specBar span { display: inline-flex; align-items: center; gap: 4px; }
#specBar button.on { border-color: var(--accent); color: var(--accent); }
#levelTag { font-size: 13px; font-weight: 600; color: var(--accent); white-space: nowrap; }
#players i.team { font-style: normal; font-weight: 800; color: var(--peer); }
.teams { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.team-col { display: grid; gap: 4px; align-content: start; padding: 8px; border: 1px solid var(--c); border-radius: 10px; font-size: 13px; }
.team-col b { color: var(--c); }
.team-col button { padding: 4px 8px; font-size: 12px; }
#ovScore { margin: 0; color: var(--accent); font-weight: 600; font-size: 14px; }
.seg3 { grid-template-columns: repeat(3, 1fr); }
.seg3 button { padding-inline: 4px; }
#home { align-content: safe center; gap: 16px; overflow-y: auto; }
#top h2 { display: flex; align-items: center; justify-content: center; gap: 8px; font-size: 18px; }
#topList { margin: 0; padding-left: 24px; text-align: left; display: grid; gap: 4px; }
#topList li span { display: inline-block; max-width: 60%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; vertical-align: bottom; }
#topList li b { color: var(--accent); margin-left: 6px; }
#topList small { color: var(--muted); }
.credit { margin: 0; text-align: center; font-size: 11px; color: var(--muted); }
.credit a { color: inherit; }
#overlay { position: absolute; inset: 0; display: grid; place-items: center; background: #0b1b2bb0; z-index: 5; }

