:root {
  --bg: #0e0e10;
  --panel: #151518;
  --panel-2: #1b1b1f;
  --line: #27272d;
  --line-2: #34343b;
  --text: #ececef;
  --muted: #9a9aa4;
  --accent: #f2b705;
  --accent-ink: #191300;
  --radius: 10px;
  --ease: cubic-bezier(.2, .7, .2, 1);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 "Be Vietnam Pro", system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
h1, h2 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }
h1 { font-size: 24px; }
h2 { font-size: 15px; }
.muted { color: var(--muted); margin: 0; }
.small { font-size: 13px; }

/* ---------- Hiện / ẩn có hoạt ảnh ---------- */
.anim-in { animation: fadeIn .24s var(--ease) both; }
.anim-out { animation: fadeOut .2s ease both; pointer-events: none; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@keyframes fadeOut { from { opacity: 1; transform: none; } to { opacity: 0; transform: translateY(6px); } }
@media (prefers-reduced-motion: reduce) {
  .anim-in, .anim-out { animation-duration: .01s; }
}

/* ---------- Nút ---------- */
.btn {
  appearance: none;
  font: inherit;
  font-weight: 500;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--line-2);
  border-radius: 8px;
  padding: 9px 16px;
  cursor: pointer;
  transition: background .15s, border-color .15s, opacity .15s, color .15s;
}
.btn:hover:not(:disabled) { border-color: #4a4a53; background: #222227; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.primary:hover:not(:disabled) { background: #ffc61a; border-color: #ffc61a; }
.btn.ghost { background: transparent; border-color: var(--line); }
.btn.small { padding: 6px 12px; font-size: 13px; }
.btn.block { width: 100%; }
.btn.armed { border-color: var(--accent); color: var(--accent); }
.btn:focus-visible, input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.chip {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; font-weight: 500;
  padding: 3px 10px; border-radius: 999px;
  background: var(--panel-2); border: 1px solid var(--line-2); color: var(--muted);
  white-space: nowrap;
  transition: color .2s, border-color .2s, background .2s;
}
.chip.line { background: transparent; }
.chip.live { color: var(--accent); border-color: var(--accent); }

/* ---------- Đăng nhập ---------- */
.login { min-height: 100%; display: grid; place-items: center; padding: 24px; }
.login-card {
  width: 100%; max-width: 380px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
  padding: 28px; display: grid; gap: 14px;
}
.field { display: grid; gap: 6px; font-size: 13px; color: var(--muted); }
.field input {
  font: inherit; font-size: 16px; color: var(--text);
  background: var(--bg); border: 1px solid var(--line-2); border-radius: 8px;
  padding: 11px 12px; width: 100%;
  transition: border-color .15s;
}
.field input:focus { border-color: var(--accent); outline: none; }
.form-error { margin: 0; font-size: 13px; color: var(--accent); }

/* ---------- Phòng ---------- */
.room { min-height: 100%; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 20px; border-bottom: 1px solid var(--line);
  position: sticky; top: 0; background: var(--bg); z-index: 5;
}
.brand { font-weight: 600; }
.spacer { flex: 1; }
.me { display: flex; align-items: center; gap: 8px; min-width: 0; }
.me-name { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 200px; }

.layout {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 20px;
  padding: 20px;
  max-width: 1280px; width: 100%; margin: 0 auto;
}
.stage { display: flex; flex-direction: column; align-items: center; gap: 18px; min-width: 0; }
.wheel-wrap { position: relative; width: min(100%, 600px, calc(100vh - 230px)); min-width: 260px; aspect-ratio: 1; }
#wheel { width: 100%; height: 100%; display: block; transition: opacity .18s ease; }
#wheel.swap { opacity: 0; }
.pointer {
  position: absolute; left: 50%; top: -6px; transform: translateX(-50%);
  width: 0; height: 0;
  border-left: 14px solid transparent; border-right: 14px solid transparent;
  border-top: 26px solid var(--accent);
}

.banner {
  position: absolute; left: 50%; top: 50%;
  transform: translate(-50%, -50%);
  min-width: 62%; max-width: 92%;
  background: var(--panel); border: 1px solid var(--accent); border-radius: 12px;
  padding: 18px 22px; text-align: center;
}
.banner.anim-in { animation: popIn .32s var(--ease) both; }
.banner.anim-out { animation: popOut .22s ease both; }
@keyframes popIn { from { opacity: 0; transform: translate(-50%, -50%) scale(.92); } to { opacity: 1; transform: translate(-50%, -50%) scale(1); } }
@keyframes popOut { from { opacity: 1; transform: translate(-50%, -50%) scale(1); } to { opacity: 0; transform: translate(-50%, -50%) scale(.96); } }
.banner-prize { color: var(--accent); font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: .08em; }
.banner-name { font-size: clamp(22px, 4vw, 34px); font-weight: 700; word-break: break-word; margin-top: 4px; }

.readout { text-align: center; min-height: 64px; }
.readout-label { color: var(--muted); font-size: 13px; }
.readout-name { font-size: clamp(20px, 3vw, 28px); font-weight: 600; word-break: break-word; }

.side { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; display: flex; flex-direction: column; gap: 10px;
}
.card.grow { flex: 1; min-height: 220px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.count { color: var(--muted); font-size: 13px; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }

.prizes { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.prize {
  display: grid; grid-template-columns: 84px 1fr; gap: 10px; align-items: center;
  padding: 9px 12px; border: 1px solid var(--line); border-radius: 8px;
  transition: border-color .25s;
}
.prize.won { border-color: var(--accent); }
.prize-label { color: var(--muted); font-size: 13px; }
.prize.won .prize-label { color: var(--accent); }
.prize-value { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.prize-value.pending { color: var(--muted); font-weight: 400; }

.players { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; overflow: auto; max-height: calc(100vh - 420px); min-height: 80px; }
.player {
  display: flex; align-items: center; gap: 10px;
  padding: 7px 10px; border: 1px solid var(--line); border-radius: 8px;
  min-height: 40px;
}
.player.enter { animation: rowIn .26s var(--ease) both; }
.player.leave { animation: rowOut .22s ease both; pointer-events: none; }
@keyframes rowIn { from { opacity: 0; transform: translateX(-8px); } to { opacity: 1; transform: none; } }
@keyframes rowOut { from { opacity: 1; transform: none; } to { opacity: 0; transform: translateX(8px); } }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--line-2); flex: none; transition: background .25s; }
.dot.on { background: var(--accent); }
.pname { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.player.me .pname { font-weight: 600; }
.tag { font-size: 12px; color: var(--muted); border: 1px solid var(--line-2); border-radius: 999px; padding: 1px 8px; white-space: nowrap; }
.player.excluded .pname { color: var(--muted); }
.player.winner { border-color: var(--accent); }

.switch { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); cursor: pointer; user-select: none; white-space: nowrap; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch .track { width: 30px; height: 18px; border-radius: 999px; border: 1px solid var(--line-2); background: var(--bg); position: relative; transition: background .18s, border-color .18s; }
.switch .track::after { content: ""; position: absolute; top: 2px; left: 2px; width: 12px; height: 12px; border-radius: 50%; background: var(--muted); transition: transform .18s var(--ease), background .18s; }
.switch input:checked + .track { background: var(--accent); border-color: var(--accent); }
.switch input:checked + .track::after { transform: translateX(12px); background: var(--accent-ink); }
.switch input:focus-visible + .track { outline: 2px solid var(--accent); outline-offset: 2px; }
.switch input:disabled + .track { opacity: .45; }
.icon-btn { appearance: none; background: none; border: 1px solid transparent; color: var(--muted); border-radius: 6px; width: 26px; height: 26px; cursor: pointer; font-size: 16px; line-height: 1; transition: color .15s, border-color .15s; }
.icon-btn:hover:not(:disabled) { color: var(--text); border-color: var(--line-2); }
.icon-btn:disabled { opacity: .35; cursor: not-allowed; }
.empty { text-align: center; padding: 12px 0; }

/* ---------- Thông báo ---------- */
#toasts { position: fixed; top: 64px; left: 50%; transform: translateX(-50%); display: grid; gap: 8px; z-index: 20; pointer-events: none; width: max-content; max-width: calc(100vw - 32px); }
.toast { background: var(--panel-2); border: 1px solid var(--line-2); border-radius: 8px; padding: 8px 14px; font-size: 14px; text-align: center; }
.toast b { font-weight: 600; }
.toast.anim-in { animation: toastIn .26s var(--ease) both; }
.toast.anim-out { animation: toastOut .22s ease both; }
@keyframes toastIn { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: none; } }
@keyframes toastOut { from { opacity: 1; transform: none; } to { opacity: 0; transform: translateY(-8px); } }
.conn { position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); z-index: 30; background: var(--panel-2); border: 1px solid var(--accent); color: var(--text); border-radius: 8px; padding: 8px 14px; font-size: 14px; }
.conn.anim-in { animation: toastIn .24s var(--ease) both; }
.conn.anim-out { animation: toastOut .2s ease both; }

/* ---------- Màn hình nhỏ ---------- */
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; padding: 14px; gap: 14px; }
  .wheel-wrap { width: min(100%, 520px); }
  .players { max-height: none; }
  .topbar { flex-wrap: wrap; padding: 10px 14px; gap: 8px; }
  .brand { width: 100%; }
  .spacer { display: none; }
  .me-name { max-width: 140px; }
}
