/* Giao dien rieng cua tung game. */

/* ================= Khung ve dung chung ================= */

.canvas-area {
  flex: 1;
  min-height: 0;
  display: flex;
  padding: 10px;
}

.canvas-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  min-height: 0;
}

.draw-canvas {
  background: #fff;
  border-radius: 10px;
  box-shadow: var(--shadow);
  touch-action: none; /* khong cho trinh duyet cuon khi dang ve bang ngon tay */
  display: block;
}
/* Khi khong den luot minh ve, tra lai cu chi cuon/phong to cho nguoi dung. */
.canvas-wrap.is-locked .draw-canvas { opacity: .96; touch-action: auto; }

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  background: var(--bg-deep);
  border-top: 1px solid var(--line);
  flex-shrink: 0;
}

.swatches { display: flex; flex-wrap: wrap; gap: 5px; }
.swatch {
  width: 25px;
  height: 25px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  padding: 0;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .16);
}
.swatch.is-on { border-color: var(--accent); transform: scale(1.14); }

.widths { display: flex; gap: 5px; }
.width-btn {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: var(--surface-2);
  display: grid;
  place-items: center;
  cursor: pointer;
  padding: 0;
}
.width-btn span { background: var(--text); border-radius: 50%; display: block; }
.width-btn.is-on { border-color: var(--accent); background: var(--surface-3); }

.tool-actions { display: flex; gap: 7px; margin-left: auto; }
.btn.is-on, .tool-erase.is-on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }

/* ================= Vẽ & Đoán ================= */

.draw-layout { flex: 1; display: flex; min-height: 0; position: relative; }
.draw-main { flex: 1; display: flex; flex-direction: column; min-width: 0; }

.draw-head {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 16px;
  background: var(--bg-deep);
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}
.draw-round { font-size: 13px; color: var(--muted); white-space: nowrap; }
.draw-word {
  flex: 1;
  text-align: center;
  font-size: clamp(17px, 3.4vw, 26px);
  font-weight: 700;
  letter-spacing: .18em;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}
.draw-word.is-revealed { color: var(--accent); letter-spacing: .02em; }

.draw-timer {
  font-size: 25px;
  font-weight: 800;
  min-width: 52px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.draw-timer.is-urgent { color: var(--red); animation: pulse .9s infinite; }
@keyframes pulse { 50% { opacity: .45; } }

.draw-side {
  width: 290px;
  flex-shrink: 0;
  border-left: 1px solid var(--line);
  background: var(--bg-deep);
  display: flex;
  flex-direction: column;
}

.chat-log {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 14px;
  min-height: 0;
}
.chat-line { word-break: break-word; }
.chat-name { color: var(--muted); font-weight: 600; }
.chat-system { color: var(--muted); font-style: italic; font-size: 13px; }
.chat-correct { color: var(--green); font-weight: 600; }
.chat-hint { color: var(--accent); font-size: 13px; }
.chat-secret { color: var(--violet); }
.chat-lock { opacity: .7; }

.chat-form { padding: 10px; border-top: 1px solid var(--line); flex-shrink: 0; }
.chat-input { width: 100%; }

/* Lop phu: chon tu, lo dap an, ket qua */

.draw-overlay, .blocks-overlay {
  position: absolute;
  inset: 0;
  background: rgba(9, 9, 14, .82);
  backdrop-filter: blur(3px);
  display: grid;
  place-items: center;
  z-index: 30;
  padding: 20px;
  overflow-y: auto;
}
.draw-overlay[hidden], .blocks-overlay[hidden] { display: none; }

.overlay-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 26px;
  text-align: center;
  max-width: 440px;
  width: 100%;
  box-shadow: var(--shadow);
}
.overlay-card.is-inline { margin: auto; }
.overlay-card h3 { margin: 0 0 16px; font-size: 21px; }

.choice-row { display: flex; flex-direction: column; gap: 9px; }
.choice {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 15px 18px;
  cursor: pointer;
  transition: border-color .15s ease, transform .1s ease;
}
.choice:hover { border-color: var(--accent); transform: translateX(3px); }
.choice-word { font-size: 18px; font-weight: 700; }
.choice-level { font-size: 12px; padding: 3px 10px; border-radius: 20px; }
.choice-easy .choice-level { background: rgba(74, 222, 128, .18); color: var(--green); }
.choice-medium .choice-level { background: rgba(255, 181, 69, .18); color: var(--accent); }
.choice-hard .choice-level { background: rgba(248, 113, 113, .18); color: var(--red); }

.reveal-label { color: var(--muted); font-size: 13px; margin: 0; }
.reveal-word { font-size: 30px; margin: 4px 0 18px; color: var(--accent); }
.reveal-scores { display: flex; flex-direction: column; gap: 7px; }
.reveal-row {
  display: flex;
  justify-content: space-between;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  padding: 9px 14px;
}
.reveal-row strong { color: var(--green); }
.reveal-none { color: var(--muted); padding: 12px; }

.final-scores { display: flex; flex-direction: column; gap: 7px; margin-bottom: 20px; }
.final-row {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  padding: 11px 15px;
}
.final-row.is-first {
  background: linear-gradient(96deg, rgba(255, 181, 69, .22), transparent);
  border: 1px solid var(--accent);
}
.final-rank { color: var(--muted); font-weight: 700; min-width: 20px; }
.final-name { flex: 1; text-align: left; }
.final-score { color: var(--accent); font-variant-numeric: tabular-nums; }

/* ================= Đấu Trí (quiz) ================= */

.quiz-layout {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 18px;
  gap: 14px;
  overflow-y: auto;
  min-height: 0;
}

.quiz-head { display: flex; justify-content: space-between; align-items: center; }
.quiz-progress { color: var(--muted); font-size: 14px; }
.quiz-timer { font-size: 28px; font-weight: 800; font-variant-numeric: tabular-nums; }
.quiz-timer.is-urgent { color: var(--red); animation: pulse .9s infinite; }

.quiz-question {
  font-size: clamp(19px, 3.6vw, 28px);
  text-align: center;
  margin: 6px 0 4px;
  line-height: 1.35;
}

.answer-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  flex: 1;
  min-height: 200px;
}

.answer {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 18px 20px;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 17px;
  font-weight: 600;
  text-align: left;
  color: #fff;
  overflow: hidden;
  transition: transform .1s ease, opacity .2s ease;
}
.answer:hover:not(:disabled) { transform: scale(1.02); }
.answer-a { background: #d64545; }
.answer-b { background: #2b6cb0; }
.answer-c { background: #b7791f; }
.answer-d { background: #2f855a; }
.answer.is-dim { opacity: .35; }
.answer.is-picked { outline: 3px solid #fff; }
.answer.is-correct { outline: 3px solid var(--green); opacity: 1; }
.answer-shape { font-size: 22px; }
.answer-text { flex: 1; position: relative; z-index: 2; }
.answer-count {
  position: relative;
  z-index: 2;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}
.answer-bar {
  position: absolute;
  left: 0;
  bottom: 0;
  height: 5px;
  background: rgba(255, 255, 255, .85);
  transition: width .5s ease;
}
.answer-grid.is-result .answer { cursor: default; }

.quiz-foot {
  display: flex;
  align-items: center;
  gap: 14px;
  color: var(--muted);
  font-size: 14px;
}
.quiz-waiting { color: var(--accent); }

.result-banner {
  text-align: center;
  padding: 14px;
  border-radius: var(--radius);
  font-size: 19px;
  font-weight: 700;
}
.result-banner.is-right { background: rgba(74, 222, 128, .16); color: var(--green); }
.result-banner.is-wrong { background: rgba(248, 113, 113, .16); color: var(--red); }
.result-banner.is-none { background: var(--surface-2); color: var(--muted); }
.streak-note { text-align: center; color: var(--accent); font-size: 14px; }

.mini-board { display: flex; flex-direction: column; gap: 5px; }
.mini-row {
  display: flex;
  justify-content: space-between;
  background: var(--surface);
  border-radius: var(--radius-sm);
  padding: 8px 14px;
  font-size: 14px;
}

.deck-current { color: var(--muted); font-size: 13px; margin: 0 0 12px; }
.custom-deck { margin-top: 14px; }
.custom-deck summary { cursor: pointer; color: var(--accent); font-size: 14px; }
.deck-help {
  background: var(--bg-deep);
  border-radius: var(--radius-sm);
  padding: 11px;
  font-size: 12px;
  color: var(--muted);
  white-space: pre-wrap;
  margin: 10px 0;
}
.deck-input { width: 100%; margin-bottom: 9px; font-family: ui-monospace, Menlo, monospace; font-size: 13px; }

/* ================= Xếp Khối ================= */

.blocks-layout { flex: 1; display: flex; min-height: 0; position: relative; }

.blocks-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 14px;
  overflow-y: auto;
  position: relative;
}

.blocks-hud {
  display: flex;
  gap: 9px;
  flex-wrap: wrap;
  justify-content: center;
  width: 100%;
}
.hud-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 7px 16px;
  min-width: 78px;
}
.hud-item span { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.hud-item strong { font-size: 20px; font-variant-numeric: tabular-nums; }
.hud-item strong.is-urgent { color: var(--red); animation: pulse .9s infinite; }
.hud-best strong { color: var(--accent); }
.hud-level strong { color: var(--violet); }
.hud-level strong.is-up { animation: level-up .7s ease; }
@keyframes level-up {
  0% { transform: scale(1); }
  35% { transform: scale(1.5); color: var(--accent); }
  100% { transform: scale(1); }
}

/* Ban co: o vuong tuyet doi, canh bang min() de khong bao gio tran ra ngoai
   man hinh du man ngang hay man doc. */
.blocks-board {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  width: min(92vw, 58vh, 440px);
  aspect-ratio: 1;
  background: var(--bg-deep);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 4px;
  flex-shrink: 0;
  touch-action: none; /* keo khoi chu khong keo cuon trang */
}

.bb-cell { padding: 2px; }
.bb-cell i {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 5px;
  background: rgba(255, 255, 255, .055);
  transition: background .12s ease, transform .12s ease;
}
.bb-cell.is-preview i { background: rgba(255, 255, 255, .3); }
.bb-cell.is-preview-bad i { background: rgba(248, 113, 113, .38); }
.bb-cell.is-cleared i { animation: cell-pop .3s ease; }
@keyframes cell-pop {
  0% { transform: scale(1); background: #fff; }
  100% { transform: scale(.2); background: rgba(255, 255, 255, .05); }
}

/* Bang mau dung chung cho ban co, khoi trong khay va khoi dang keo. */
[data-c="1"] i { background: #f97316; }
[data-c="2"] i { background: #38bdf8; }
[data-c="3"] i { background: #a78bfa; }
[data-c="4"] i { background: #facc15; }
[data-c="5"] i { background: #34d399; }
[data-c="6"] i { background: #f472b6; }
[data-c="7"] i { background: #60a5fa; }
[data-c="8"] i { background: #fb7185; }

.blocks-tray {
  display: flex;
  gap: 10px;
  justify-content: center;
  align-items: center;
  width: min(92vw, 440px);
  min-height: 86px;
}
.tray-slot {
  flex: 1;
  display: grid;
  place-items: center;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 9px;
  min-height: 82px;
  cursor: grab;
  touch-action: none;
  transition: border-color .15s ease, transform .1s ease;
}
.tray-slot:active { cursor: grabbing; transform: scale(.97); }
.tray-slot.is-empty { opacity: .3; cursor: default; }
.tray-slot.is-locked { cursor: default; opacity: .55; }

.tray-piece { display: grid; gap: 2px; }
.tray-piece .pv-cell { width: 15px; height: 15px; }
.pv-cell i { display: block; width: 100%; height: 100%; border-radius: 3px; }
.pv-cell.is-blank i { background: transparent; }

/* Khoi dang duoc keo: bam theo con tro, khong nhan su kien chuot de
   con tro van "nhin xuyen" xuong ban co ben duoi. */
.drag-ghost {
  position: fixed;
  left: 0;
  top: 0;
  z-index: 80;
  pointer-events: none;
  display: grid;
  gap: 2px;
  filter: drop-shadow(0 8px 16px rgba(0, 0, 0, .5));
  opacity: .92;
  /* Di chuyen bang transform chu khong phai left/top: trinh duyet chi phai
     ve lai lop nay thay vi tinh lai bo cuc ca trang o moi khung hinh. */
  will-change: transform;
}
.drag-ghost .pv-cell { width: var(--cell, 40px); height: var(--cell, 40px); padding: 2px; }
.drag-ghost .pv-cell i { border-radius: 5px; }

.combo-flash {
  position: absolute;
  top: 34%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 30px;
  font-weight: 800;
  color: var(--accent);
  text-shadow: 0 3px 14px rgba(0, 0, 0, .8);
  pointer-events: none;
  opacity: 0;
}
.combo-flash.is-on { animation: combo-rise .85s ease-out; }
@keyframes combo-rise {
  0% { opacity: 0; transform: translate(-50%, -30%) scale(.7); }
  25% { opacity: 1; transform: translate(-50%, -50%) scale(1.12); }
  100% { opacity: 0; transform: translate(-50%, -95%) scale(1); }
}

/* Ban co doi thu */
.blocks-rivals {
  width: 176px;
  flex-shrink: 0;
  border-left: 1px solid var(--line);
  background: var(--bg-deep);
  padding: 12px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.blocks-rivals[hidden] { display: none; }
.rivals-title {
  margin: 0;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--muted);
}
.rival-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 9px;
}
.rival-card.is-over { opacity: .5; }
.rival-head { display: flex; justify-content: space-between; gap: 6px; margin-bottom: 6px; font-size: 12.5px; }
.rival-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rival-score { color: var(--accent); font-variant-numeric: tabular-nums; }
.rival-board {
  width: 100%;
  aspect-ratio: 1;
  display: block;
  border-radius: 5px;
  background: var(--bg-deep);
  /* Canvas chi 8x8 diem anh roi phong to - giu canh sac net thay vi lam nhoe. */
  image-rendering: pixelated;
}
.rival-flag { display: block; margin-top: 5px; font-size: 11px; color: var(--red); text-align: center; }

.rival-card.is-leader { border-color: var(--accent); background: rgba(255, 181, 69, .09); }
.rival-score.is-bump { animation: score-bump .5s ease; }
@keyframes score-bump {
  0% { transform: scale(1); }
  30% { transform: scale(1.35); color: var(--green); }
  100% { transform: scale(1); }
}
.rival-diff {
  display: block;
  margin-top: 5px;
  font-size: 11px;
  text-align: center;
  color: var(--muted);
}
.rival-diff.is-ahead { color: var(--green); }
.rival-diff.is-behind { color: var(--red); }

.hud-rank strong { color: var(--blue); }
.hud-rank strong.is-leading { color: var(--accent); }

.combo-flash.is-perfect { color: var(--green); font-size: 34px; }

/* O nhap so phut tuy y o sanh cho */
.custom-time { display: flex; align-items: center; gap: 8px; margin-top: 10px; }
.time-label { font-size: 13px; color: var(--muted); }
.time-input {
  width: 76px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  outline: none;
}
.time-input:focus { border-color: var(--accent); }

/* Ket qua choi mot minh */
.solo-score { display: flex; align-items: baseline; justify-content: center; gap: 8px; margin-bottom: 16px; }
.solo-score strong { font-size: 46px; color: var(--accent); font-variant-numeric: tabular-nums; }
.solo-score span { color: var(--muted); }

.solo-stats { display: flex; gap: 9px; margin-bottom: 18px; }
.stat-box {
  flex: 1;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  padding: 10px 6px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.stat-box strong { font-size: 18px; font-variant-numeric: tabular-nums; }
.stat-box span { font-size: 11px; color: var(--muted); }

.history-title { margin: 0 0 9px; font-size: 13px; color: var(--muted); text-align: left; }
.history-list { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; max-height: 190px; overflow-y: auto; }
.history-row {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  padding: 7px 12px;
  font-size: 13px;
}
.history-date { color: var(--muted); }
.history-lines { flex: 1; text-align: left; color: var(--muted); font-size: 12px; }
.history-score { color: var(--accent); font-variant-numeric: tabular-nums; }
.history-note { font-size: 11.5px; color: var(--muted); margin: 0 0 16px; }

.best-badge {
  display: flex;
  align-items: baseline;
  gap: 9px;
  background: rgba(255, 181, 69, .1);
  border: 1px solid rgba(255, 181, 69, .3);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  margin-bottom: 14px;
  font-size: 13px;
}
.best-badge strong { font-size: 21px; color: var(--accent); }
.best-count { margin-left: auto; color: var(--muted); font-size: 12px; }

/* ================= Bảng Vẽ Chung ================= */

.board-layout { flex: 1; display: flex; flex-direction: column; min-height: 0; }

.cursor-layer { position: absolute; inset: 0; pointer-events: none; }
.remote-cursor {
  position: absolute;
  transform: translate(-3px, -3px);
  transition: left .07s linear, top .07s linear, opacity .3s ease;
  display: flex;
  align-items: flex-start;
  gap: 4px;
}
.remote-cursor.is-idle { opacity: .25; }
.cursor-dot {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: var(--violet);
  border: 2px solid #fff;
  flex-shrink: 0;
}
.cursor-name {
  background: var(--violet);
  color: #fff;
  font-size: 11px;
  padding: 1px 7px;
  border-radius: 10px;
  white-space: nowrap;
}

/* ================= Chốt Đi ================= */

.decide-layout {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 20px;
  overflow-y: auto;
  min-height: 0;
  max-width: 680px;
  width: 100%;
  margin: 0 auto;
}

.decide-tabs { display: flex; gap: 8px; flex-wrap: wrap; }
.decide-head { display: flex; flex-direction: column; gap: 4px; }
.decide-title { margin: 0; font-size: 24px; }
.decide-title.is-editable {
  border-bottom: 1px dashed var(--line);
  outline: none;
  cursor: text;
}
.decide-title.is-editable:focus { border-color: var(--accent); }
.decide-sub { color: var(--muted); font-size: 13px; }

.poll-list { display: flex; flex-direction: column; gap: 9px; }
.poll-row {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  cursor: pointer;
  overflow: hidden;
  text-align: left;
  width: 100%;
}
.poll-row:hover { border-color: var(--accent); }
.poll-row.is-mine { border-color: var(--accent); }
.poll-fill {
  position: absolute;
  inset: 0 auto 0 0;
  background: rgba(255, 181, 69, .16);
  transition: width .45s ease;
}
.poll-text { flex: 1; position: relative; z-index: 2; }
.poll-count { position: relative; z-index: 2; font-weight: 800; color: var(--accent); }
.poll-remove { position: relative; z-index: 2; color: var(--muted); padding: 0 4px; }
.poll-remove:hover { color: var(--red); }

.add-option { display: flex; gap: 9px; }
.add-input { flex: 1; }
.decide-controls { display: flex; gap: 9px; flex-wrap: wrap; }

.wheel-display {
  background: var(--surface);
  border: 2px solid var(--line);
  border-radius: var(--radius);
  padding: 46px 20px;
  text-align: center;
  font-size: clamp(24px, 6vw, 44px);
  font-weight: 800;
  word-break: break-word;
}
.wheel-display.is-final {
  border-color: var(--accent);
  color: var(--accent);
  animation: pop .45s ease;
}
@keyframes pop {
  0% { transform: scale(.88); }
  60% { transform: scale(1.05); }
  100% { transform: scale(1); }
}

.team-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
}
.team-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 15px;
  border-top: 3px solid var(--accent);
}
.team-1 { border-top-color: var(--blue); }
.team-2 { border-top-color: var(--green); }
.team-3 { border-top-color: var(--violet); }
.team-card h3 { margin: 0 0 9px; font-size: 16px; }
.team-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 5px; }
.team-list li {
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  padding: 6px 11px;
  font-size: 14px;
}

/* =====================================================================
   RESPONSIVE
   ===================================================================== */

/* --- Cua so hep nhung van la man hinh ngang: thu cot chat lai --- */
@media (max-width: 1080px) and (min-width: 781px) {
  .draw-side { width: 240px; }
  .draw-word { font-size: 17px; letter-spacing: .12em; }
  .decide-layout { padding: 16px; }
}

/* --- Dien thoai dung --- */
@media (max-width: 780px) {
  /* iOS tu phong to trang khi con tro vao o nhap co chu nho hon 16px.
     Giu dung 16px la cach duy nhat chan viec do ma khong tat zoom toan trang. */
  input[type="text"], textarea, .chat-input { font-size: 16px; }

  .draw-layout { flex-direction: column; }

  /* Khung ve giu ti le 4:3 theo be ngang, phan con lai danh cho chat.
     Dat chieu cao co dinh theo vh se sai moi khi ban phim ao bat len. */
  .draw-main { flex: 0 0 auto; min-height: 0; }
  .canvas-area { padding: 6px; }
  .canvas-wrap { width: 100%; aspect-ratio: 4 / 3; }

  .draw-side {
    width: 100%;
    flex: 1;
    min-height: 120px;
    height: auto;
    border-left: none;
    border-top: 1px solid var(--line);
  }
  .chat-log { padding: 9px 11px; gap: 4px; }
  .chat-form { padding: 8px; padding-bottom: max(8px, env(safe-area-inset-bottom)); }

  .draw-head { padding: 7px 12px; gap: 9px; }
  .draw-round { font-size: 11.5px; }
  .draw-word { font-size: 16px; letter-spacing: .12em; }
  .draw-timer { font-size: 21px; min-width: 40px; }

  .toolbar {
    gap: 7px;
    padding: 7px 9px;
    padding-bottom: max(7px, env(safe-area-inset-bottom));
  }
  .swatches { gap: 4px; }
  .swatch { width: 24px; height: 24px; }
  .width-btn { width: 30px; height: 30px; }
  .tool-actions { margin-left: 0; width: 100%; justify-content: flex-end; }

  .overlay-card { padding: 20px 17px; }
  .choice { padding: 13px 15px; }
  .choice-word { font-size: 16.5px; }
  .reveal-word { font-size: 25px; }

  .quiz-layout { padding: 13px; gap: 11px; }
  .answer-grid { grid-template-columns: 1fr; min-height: 0; }
  .answer { padding: 14px 16px; font-size: 15.5px; }
  .quiz-question { font-size: 19px; }
  .quiz-timer { font-size: 23px; }
  .quiz-foot { flex-wrap: wrap; gap: 9px; font-size: 13px; }

  /* Xep Khoi: ban co doi thu chuyen xuong duoi thanh dai cuon ngang,
     nhuong toan bo be ngang cho ban co cua chinh minh. */
  .blocks-layout { flex-direction: column; }
  .blocks-main { padding: 10px; gap: 9px; }
  .blocks-board { width: min(94vw, 52vh, 420px); }
  .blocks-tray { width: min(94vw, 420px); gap: 8px; min-height: 74px; }
  .tray-slot { min-height: 70px; padding: 7px; }
  .tray-piece .pv-cell { width: 14px; height: 14px; }
  .hud-item { padding: 5px 12px; min-width: 68px; }
  .hud-item strong { font-size: 17px; }
  .combo-flash { font-size: 25px; }

  /* Diem doi thu phai nam TREN ban co. De o duoi thi no bi day khoi man hinh
     va nguoi choi khong bao gio thay minh dang hon hay thua. */
  .blocks-rivals {
    order: -1;
    width: 100%;
    flex-direction: row;
    border-left: none;
    border-bottom: 1px solid var(--line);
    padding: 7px 9px;
    gap: 7px;
    overflow-x: auto;
    overflow-y: hidden;
    flex-shrink: 0;
  }
  .rivals-title { display: none; }
  /* Doi thu thu gon thanh the ngang: ban co ti hon ben trai, ten va diem ben phai. */
  .rival-card {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 5px 10px 5px 6px;
  }
  .rival-head {
    flex-direction: column;
    align-items: flex-start;
    margin: 0;
    gap: 0;
    order: 2;
  }
  .rival-name { max-width: 88px; font-size: 12px; }
  .rival-score { font-size: 15px; }
  .rival-board { width: 32px; height: 32px; flex-shrink: 0; }
  .rival-flag { margin: 0; order: 4; font-size: 10px; }
  .rival-diff { order: 3; margin: 0; font-size: 10.5px; white-space: nowrap; }
  .solo-stats { gap: 6px; }
  .solo-score strong { font-size: 38px; }

  .decide-layout { padding: 14px; gap: 13px; }
  .decide-title { font-size: 20px; }
  .poll-row { padding: 13px 14px; }
  .wheel-display { padding: 34px 16px; }
  .team-grid { grid-template-columns: repeat(2, 1fr); gap: 9px; }
  .add-option { flex-wrap: wrap; }
  .add-input { min-width: 60%; }
}

/* --- May rat nho --- */
@media (max-width: 380px) {
  .swatch { width: 21px; height: 21px; }
  .swatches { max-width: 100%; }
  .width-btn { width: 27px; height: 27px; }
  .draw-word { font-size: 14px; letter-spacing: .08em; }
  .draw-timer { font-size: 19px; min-width: 34px; }
  .answer { padding: 12px 13px; font-size: 14.5px; }
  .answer-shape { font-size: 18px; }
  .quiz-question { font-size: 17.5px; }
  .team-grid { grid-template-columns: 1fr; }
  .decide-controls { gap: 6px; }
}

/* --- Dien thoai xoay ngang: doi lai bo cuc hai cot vi chieu cao rat hiem --- */
@media (orientation: landscape) and (max-height: 520px) {
  .draw-layout { flex-direction: row; }
  .draw-main { flex: 1; min-width: 0; }
  .canvas-wrap { aspect-ratio: auto; }
  .canvas-area { padding: 4px; }

  .draw-side {
    flex: 0 0 210px;
    width: 210px;
    min-height: 0;
    border-top: none;
    border-left: 1px solid var(--line);
    padding-right: env(safe-area-inset-right);
  }

  .draw-head { padding: 4px 10px; }
  .draw-round { font-size: 11px; }
  .draw-word { font-size: 15px; }
  .draw-timer { font-size: 18px; min-width: 34px; }

  .toolbar { padding: 4px 8px; gap: 6px; }
  .swatch { width: 18px; height: 18px; }
  .width-btn { width: 24px; height: 24px; }
  .tool-actions { width: auto; margin-left: auto; }

  /* Lop phu phai cuon duoc, neu khong nut bam se nam ngoai man hinh. */
  .draw-overlay { padding: 10px; align-items: start; }
  .overlay-card { padding: 15px 18px; max-height: 92vh; overflow-y: auto; }
  .overlay-card h3 { margin-bottom: 10px; font-size: 17px; }
  .choice { padding: 9px 14px; }
  .choice-word { font-size: 15px; }
  .reveal-word { font-size: 21px; margin: 2px 0 10px; }
  .final-row { padding: 7px 12px; }

  /* Xep Khoi khi xoay ngang: quay lai hai cot, ban co bam theo chieu cao. */
  .blocks-layout { flex-direction: row; }
  .blocks-main { padding: 8px; gap: 7px; flex-direction: row; flex-wrap: wrap; justify-content: center; align-content: center; }
  .blocks-hud { width: auto; flex-direction: column; gap: 5px; }
  .hud-item { padding: 4px 10px; min-width: 64px; }
  .hud-item strong { font-size: 15px; }
  .blocks-board { width: min(46vw, 82vh); }
  .blocks-tray { width: auto; flex-direction: column; min-height: 0; gap: 6px; }
  .tray-slot { min-height: 56px; min-width: 62px; padding: 6px; }
  .tray-piece .pv-cell { width: 11px; height: 11px; }
  /* Xoay ngang thi co lai chieu ngang: doi thu quay ve cot ben phai,
     go lai moi thu ma khoi man hinh doc da doi. */
  .blocks-rivals {
    order: 0;
    width: 128px;
    flex-direction: column;
    border-top: none;
    border-bottom: none;
    border-left: 1px solid var(--line);
    padding: 8px;
    overflow-x: hidden;
    overflow-y: auto;
  }
  .rival-card { flex: 0 0 auto; display: block; padding: 7px; }
  .rival-head { flex-direction: row; align-items: baseline; margin-bottom: 5px; gap: 6px; }
  .rival-name { max-width: none; }
  .rival-board { width: 100%; height: auto; }
  .combo-flash { font-size: 22px; }
  .solo-score strong { font-size: 32px; }
  .history-list { max-height: 110px; }

  .quiz-layout { padding: 10px 14px; gap: 8px; }
  .answer-grid { grid-template-columns: repeat(2, 1fr); min-height: 0; }
  .answer { padding: 10px 13px; font-size: 14.5px; }
  .quiz-question { font-size: 17px; margin: 0; }
  .quiz-timer { font-size: 20px; }
  .mini-board { display: none; } /* bang xep hang phu, nhuong cho cho cau hoi */

  .decide-layout { padding: 10px 14px; gap: 10px; }
  .wheel-display { padding: 20px 16px; font-size: 26px; }
  .decide-title { font-size: 18px; }
}

/* --- Man hinh rong --- */
@media (min-width: 1500px) {
  .draw-side { width: 340px; }
  .decide-layout { max-width: 760px; }
}

/* --- Man hinh cam ung: bo hieu ung di chuot --- */
@media (hover: none) {
  .answer:hover:not(:disabled) { transform: none; }
  .choice:hover { transform: none; }
  .poll-row:hover { border-color: var(--line); }
  .poll-row.is-mine { border-color: var(--accent); }
}
