/* ================= CHIA ĐỘI 2/9 — nghi thức bốc thăm ================= */
/* Dùng chung token màu ở style.css (--red, --gold, --ink…). File này lo phần
   riêng của trang chia đội: màn chọn vai, màn chiếu (projector), màn điện thoại. */

.cd { min-height: 100vh; }
.hidden { display: none !important; }

/* ---------- Màn chọn vai trò ---------- */
.cd-choose {
  min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; gap: 18px; padding: 30px;
}
.cd-star { font-size: 76px; filter: drop-shadow(0 6px 12px rgba(201, 138, 0, .35)); animation: pop .6s ease; }
.cd-h1 { font-size: clamp(30px, 6vw, 56px); color: var(--red-dark); line-height: 1.05; }
.cd-sub { max-width: 560px; font-size: clamp(13px, 2vw, 16px); }
.cd-roles { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 18px; width: min(720px, 100%); }
.cd-roles .role { cursor: pointer; font: inherit; }
.cd-back { text-decoration: none; font-size: 14px; margin-top: 6px; }

/* ================= MÀN CHIẾU (BOARD) ================= */
#boardView {
  min-height: 100vh; display: flex; flex-direction: column; gap: 14px; padding: 18px clamp(14px, 2.5vw, 34px) 14px;
  color: #fff;
  background:
    radial-gradient(1100px 520px at 50% -10%, rgba(255, 205, 0, .22), transparent 60%),
    radial-gradient(900px 600px at 110% 120%, rgba(0, 0, 0, .28), transparent 60%),
    linear-gradient(160deg, #7a0f09 0%, #b3140d 46%, #da251d 100%);
}
#boardView::before { /* sao chìm trang trí */
  content: ""; position: fixed; inset: 0; z-index: 0; pointer-events: none;
  background-image: radial-gradient(circle, rgba(255, 255, 255, .06) 1.4px, transparent 1.6px);
  background-size: 46px 46px;
}
#boardView > * { position: relative; z-index: 1; }

/* Thanh trên: tiêu đề + tiến độ + điều khiển */
.cd-board-top { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.cd-titlewrap { display: flex; align-items: center; gap: 14px; min-width: 0; }
.cd-titlewrap .brand-logo { width: 48px; height: 48px; filter: drop-shadow(0 2px 6px rgba(0, 0, 0, .4)); }
.cd-board-title { font-size: clamp(16px, 2.2vw, 26px); font-weight: 900; letter-spacing: .3px; text-shadow: 0 2px 8px rgba(0, 0, 0, .35); }
.cd-progress { display: flex; align-items: center; gap: 12px; margin-top: 6px; font-weight: 700; font-size: clamp(13px, 1.5vw, 16px); }
.cd-progress #progText { color: #ffe27a; white-space: nowrap; }
.cd-bar { width: clamp(120px, 20vw, 260px); height: 10px; border-radius: 999px; background: rgba(255, 255, 255, .22); overflow: hidden; }
.cd-bar i { display: block; height: 100%; width: 0; border-radius: 999px; background: linear-gradient(90deg, #ffd23f, #fff); transition: width .5s cubic-bezier(.2, .8, .2, 1); }

.cd-controls { display: flex; align-items: center; gap: 8px; }
.cd-tools { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- Sân khấu quay số ---------- */
.cd-stage {
  flex: 0 0 auto; min-height: clamp(200px, 34vh, 340px);
  display: grid; place-items: center; text-align: center;
  border-radius: 26px; padding: 18px 24px;
  background: rgba(255, 255, 255, .10); border: 1px solid rgba(255, 255, 255, .22);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .25), 0 20px 50px rgba(0, 0, 0, .25);
  backdrop-filter: blur(2px);
  transition: background .5s ease, box-shadow .5s ease;
  overflow: hidden;
}
.cd-stage.landed { box-shadow: inset 0 0 0 3px var(--tc, #fff), 0 26px 60px rgba(0, 0, 0, .35); }
.stage-idle { display: grid; gap: 12px; }
.stage-idle .big { font-size: clamp(26px, 4vw, 48px); font-weight: 900; text-shadow: 0 2px 10px rgba(0, 0, 0, .3); }
.stage-idle .small { color: #ffe9b8; font-weight: 600; font-size: clamp(14px, 1.8vw, 19px); }
.stage-idle .em { font-size: clamp(40px, 7vw, 80px); }

/* Reel: tên chạy nhanh khi quay, dừng lại ở người được bốc */
.reel { display: grid; gap: 10px; width: 100%; }
.reel .label { font-size: clamp(13px, 1.6vw, 18px); letter-spacing: 3px; text-transform: uppercase; color: #ffe27a; font-weight: 800; }
.reel .who {
  font-size: clamp(34px, 6.2vw, 92px); font-weight: 900; line-height: 1.05;
  text-shadow: 0 4px 16px rgba(0, 0, 0, .4); overflow-wrap: anywhere;
}
.reel.spin .who { animation: reel-jit .1s linear infinite; }
.reel .verdict { display: none; }
.reel.landed .who { animation: land-pop .5s cubic-bezier(.2, 1.4, .4, 1); }
.reel.landed .verdict {
  display: flex; align-items: center; justify-content: center; gap: 14px; flex-wrap: wrap;
  margin-top: 4px; animation: fade-up .5s .12s both;
}
.reel .verdict .arrow { font-size: clamp(18px, 2.4vw, 30px); opacity: .85; }
.reel .verdict .team-pill {
  font-size: clamp(24px, 4.2vw, 58px); font-weight: 900; padding: 6px 26px; border-radius: 999px;
  color: #fff; background: var(--tc, var(--red)); box-shadow: 0 10px 26px rgba(0, 0, 0, .35);
  text-shadow: 0 2px 6px rgba(0, 0, 0, .35);
}
@keyframes reel-jit { 0% { transform: translateY(-2px); } 50% { transform: translateY(2px); } 100% { transform: translateY(-2px); } }
@keyframes land-pop { 0% { transform: scale(.7); opacity: .3; } 100% { transform: scale(1); opacity: 1; } }
@keyframes fade-up { from { transform: translateY(12px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

/* ---------- 5 cột đội ---------- */
.cd-teams { flex: 1 1 auto; display: grid; grid-template-columns: repeat(var(--cols, 5), 1fr); gap: clamp(8px, 1.2vw, 16px); align-content: stretch; }
.team-col {
  display: flex; flex-direction: column; min-height: 0;
  background: rgba(255, 255, 255, .96); border-radius: 18px; overflow: hidden;
  box-shadow: 0 14px 34px rgba(0, 0, 0, .28); border: 1px solid rgba(255, 255, 255, .5);
  transition: transform .25s ease, box-shadow .25s ease;
}
.team-col.hit { transform: translateY(-6px) scale(1.015); box-shadow: 0 20px 46px rgba(0, 0, 0, .4), 0 0 0 3px var(--tc); }
.tc-head {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 12px 14px; color: #fff; background: var(--tc, var(--red));
  text-shadow: 0 1px 3px rgba(0, 0, 0, .35);
}
.tc-name { font-weight: 900; font-size: clamp(15px, 1.9vw, 24px); letter-spacing: .3px; }
.tc-count { font-weight: 800; font-size: clamp(12px, 1.4vw, 16px); background: rgba(0, 0, 0, .18); padding: 3px 11px; border-radius: 999px; white-space: nowrap; }
.tc-chips { flex: 1; display: flex; flex-direction: column; gap: 7px; padding: 12px; overflow: auto; }
.chip {
  display: flex; align-items: center; gap: 9px; padding: 9px 12px; border-radius: 12px;
  background: #faf6f4; border: 1px solid var(--line); color: var(--ink);
  font-weight: 700; font-size: clamp(13px, 1.5vw, 18px); overflow-wrap: anywhere;
}
.chip .n { flex: 0 0 auto; width: 26px; height: 26px; border-radius: 8px; display: grid; place-items: center;
  font-size: 12px; font-weight: 900; color: #fff; background: var(--tc, var(--red)); }
.chip.pop { animation: chip-in .45s cubic-bezier(.2, 1.3, .4, 1); }
@keyframes chip-in { 0% { transform: translateX(20px) scale(.85); opacity: 0; } 100% { transform: translateX(0) scale(1); opacity: 1; } }
.tc-empty { color: var(--muted); font-size: 13px; text-align: center; padding: 10px 0; }

/* ---------- Hàng "chưa chia" ---------- */
.cd-pool { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; min-height: 34px; }
.cd-pool-label { font-weight: 800; color: #ffe27a; font-size: 14px; white-space: nowrap; }
.cd-pool-list { display: flex; flex-wrap: wrap; gap: 7px; }
.pool-chip { padding: 5px 12px; border-radius: 999px; background: rgba(255, 255, 255, .16); color: #fff; font-weight: 600; font-size: clamp(12px, 1.3vw, 15px); }
.pool-chip.claimed { background: rgba(255, 226, 122, .9); color: #5a3d00; }
.cd-pool.done .cd-pool-label { color: #b6f2c6; }

/* ================= ĐIỆN THOẠI ================= */
#phoneView { min-height: 100vh; }
.cd-picklist { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; max-height: 52vh; overflow: auto; }
.pick {
  display: flex; align-items: center; gap: 8px; text-align: left;
  padding: 12px 12px; border-radius: 12px; border: 2px solid var(--line); background: #fff;
  font: inherit; font-weight: 700; color: var(--ink); cursor: pointer; overflow-wrap: anywhere;
}
.pick:hover:not(:disabled) { border-color: var(--red); background: #fff7f5; }
.pick:disabled { cursor: not-allowed; opacity: .8; background: #f4efec; }
.pick .tag-dot { flex: 0 0 auto; width: 12px; height: 12px; border-radius: 50%; background: var(--dc, #cbb); }
.pick .assigned { margin-left: auto; font-size: 11px; font-weight: 800; color: #fff; background: var(--dc, #999); padding: 2px 8px; border-radius: 999px; white-space: nowrap; }

.cd-me { text-align: center; }
.cd-me-hi { color: var(--muted); font-weight: 600; }
.cd-me-name { font-size: clamp(24px, 7vw, 34px); font-weight: 900; color: var(--red-dark); margin: 2px 0 16px; overflow-wrap: anywhere; }
.cd-reveal-btn { font-size: clamp(18px, 5vw, 24px); padding: 20px; }
.cd-reveal-btn.spinning { pointer-events: none; opacity: .7; }
.cd-reveal-btn.armed-pulse { animation: pulse 1.1s ease-in-out infinite; }
.btn.unlocked { background: linear-gradient(180deg, #7ee2a0, #34c26e); color: #063d20; box-shadow: 0 3px 0 #1f8f4d; }
#changeName { display: inline-block; }

/* Bảng đội mini trên điện thoại */
.cd-mini { display: flex; flex-direction: column; gap: 8px; }
.mini-team { border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.mini-head { display: flex; align-items: center; justify-content: space-between; padding: 7px 12px; color: #fff; background: var(--tc); font-weight: 800; }
.mini-head .c { font-size: 12px; background: rgba(0, 0, 0, .18); padding: 2px 9px; border-radius: 999px; }
.mini-body { padding: 8px 12px; display: flex; flex-wrap: wrap; gap: 6px; }
.mini-body .m { font-size: 13px; font-weight: 600; background: #faf6f4; border: 1px solid var(--line); padding: 4px 9px; border-radius: 999px; }
.mini-body .m.me { background: var(--gold-soft); border-color: var(--gold); }
.mini-body .none { color: var(--muted); font-size: 13px; }

/* ---------- Takeover: reveal toàn màn của chính mình ---------- */
.cd-takeover {
  position: fixed; inset: 0; z-index: 60; display: grid; place-items: center; text-align: center;
  padding: 24px; color: #fff; background: var(--tc, var(--red));
  animation: to-in .35s ease;
}
.cd-takeover::before { content: ""; position: absolute; inset: 0; background: radial-gradient(circle at 50% 30%, rgba(255, 255, 255, .25), transparent 60%); }
.cd-takeover .inner { position: relative; display: grid; gap: 10px; }
.cd-takeover .hi { font-size: clamp(16px, 4vw, 22px); letter-spacing: 2px; text-transform: uppercase; opacity: .95; font-weight: 700; }
.cd-takeover .team { font-size: clamp(46px, 16vw, 96px); font-weight: 900; text-shadow: 0 6px 20px rgba(0, 0, 0, .35); line-height: 1; animation: land-pop .5s cubic-bezier(.2, 1.4, .4, 1); }
.cd-takeover .mates-label { margin-top: 14px; font-size: 13px; text-transform: uppercase; letter-spacing: 1px; opacity: .9; font-weight: 700; }
.cd-takeover .mates { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; max-width: 560px; }
.cd-takeover .mates span { background: rgba(255, 255, 255, .2); padding: 6px 13px; border-radius: 999px; font-weight: 700; }
.cd-takeover .mates span.me { background: #fff; color: var(--tc); }
.cd-takeover .close { margin-top: 22px; }
.cd-takeover .close .btn { background: #fff; color: var(--ink); box-shadow: 0 4px 0 rgba(0, 0, 0, .2); }
@keyframes to-in { from { opacity: 0; transform: scale(1.05); } to { opacity: 1; transform: scale(1); } }

/* Reel quay trên điện thoại (trước takeover) */
.cd-spin-phone { position: fixed; inset: 0; z-index: 59; display: grid; place-items: center; background: rgba(20, 6, 4, .92); color: #fff; text-align: center; }
.cd-spin-phone .label { color: #ffe27a; font-weight: 800; letter-spacing: 2px; text-transform: uppercase; margin-bottom: 10px; }
.cd-spin-phone .who { font-size: clamp(30px, 9vw, 52px); font-weight: 900; animation: reel-jit .1s linear infinite; overflow-wrap: anywhere; padding: 0 16px; }

/* ---------- Modal ---------- */
.cd-modal { position: fixed; inset: 0; z-index: 70; display: grid; place-items: center; padding: 20px; background: rgba(20, 6, 4, .55); }
.cd-modal-card { background: #fff; color: var(--ink); border-radius: 18px; padding: 20px; width: min(420px, 100%); box-shadow: var(--shadow-lg); }
.cd-modal-lg { width: min(560px, 100%); }
.cd-modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }
.cd-err { color: var(--red-dark); font-weight: 600; min-height: 20px; font-size: 14px; margin-top: 4px; }
.cd-textarea { resize: vertical; font-family: inherit; line-height: 1.6; }
.cd-editteams { display: grid; gap: 8px; margin-top: 6px; }
.cd-editteams .et-row { display: flex; align-items: center; gap: 8px; }
.cd-editteams input[type=color] { width: 42px; height: 42px; border: none; border-radius: 10px; background: none; cursor: pointer; flex: 0 0 auto; padding: 0; }
.cd-editteams input.field { flex: 1; }

/* ================= Responsive ================= */
@media (max-width: 900px) {
  /* Màn chiếu thu nhỏ (nếu ai lỡ mở trên tablet) */
  .cd-teams { grid-template-columns: repeat(var(--cols, 5), 1fr); }
}
@media (max-width: 640px) {
  .cd-picklist { grid-template-columns: 1fr; max-height: 56vh; }
  /* Trên điện thoại, nếu mở "màn chiếu" thì cho cuộn dọc gọn */
  #boardView { padding: 12px; }
  .cd-teams { grid-template-columns: 1fr 1fr; }
  .cd-stage { min-height: 200px; }
}
