:root {
  --bg: #0f172a;
  --bg-gradient: linear-gradient(135deg, #09090b 0%, #1e1b4b 100%);
  --glass-bg: rgba(255, 255, 255, 0.05);
  --glass-border: rgba(255, 255, 255, 0.1);
  --glass-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
  --text: #f8fafc;
  --muted: #94a3b8;
  --ok: #28a745;
  --bad: #dc2626;
  --primary: #007bff;
  --x: #2563eb;
  --o: #dc2626;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

/* ── Screens ──────────────────────────────────────── */
.screen {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  position: relative;
  overflow-x: hidden;
}

/* ── Mode Selection Screen ────────────────────────── */
.mode-screen {
  justify-content: center;
  min-height: 100dvh;
  padding: 40px 20px;
  max-width: 500px;
  margin: 0 auto;
}

.mode-header {
  margin-bottom: 32px;
}

.mode-logo {
  font-size: 48px;
  margin-bottom: 12px;
  filter: drop-shadow(0 4px 12px rgba(0, 0, 0, 0.3));
}

.mode-screen h1 {
  font-size: clamp(24px, 7vw, 32px);
  font-weight: 800;
  letter-spacing: -0.5px;
}

.mode-subtitle {
  color: var(--muted);
  font-size: 15px;
  margin-top: 8px;
}

/* Difficulty Selector */
.difficulty-row {
  width: 100%;
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  border-radius: 20px;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
  backdrop-filter: blur(10px);
}

.diff-label {
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
}

.diff-toggle {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  background: rgba(0, 0, 0, 0.2);
  border-radius: 12px;
  padding: 4px;
}

.diff-btn {
  border: none;
  background: transparent;
  color: var(--muted);
  padding: 8px 4px;
  border-radius: 8px;
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  white-space: nowrap;
}

.diff-btn.active {
  background: #ffffff;
  color: #0f172a;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

#btnUltra.active {
  background: linear-gradient(135deg, #ef4444 0%, #f97316 100%);
  color: #fff;
  animation: ultraPulse 2s infinite;
  box-shadow: 0 4px 15px rgba(239, 68, 68, 0.4);
}

@keyframes ultraPulse {
  0% {
    transform: scale(1);
  }

  50% {
    transform: scale(1.05);
  }

  100% {
    transform: scale(1);
  }
}

/* Mode Buttons List */
.mode-buttons {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
}

.mode-btn {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 16px 20px;
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  border-radius: 20px;
  color: var(--text);
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  text-align: left;
  backdrop-filter: blur(10px);
}

.mode-btn-content {
  display: flex;
  align-items: center;
  gap: 16px;
}

.mode-icon {
  font-size: 28px;
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.05);
  border-radius: 14px;
}

.mode-text {
  display: flex;
  flex-direction: column;
}

.mode-label {
  font-size: 17px;
  font-weight: 700;
  margin-bottom: 2px;
}

.mode-desc {
  font-size: 13px;
  color: var(--muted);
}

.mode-arrow {
  font-size: 24px;
  color: var(--muted);
  opacity: 0.5;
  transition: transform 0.3s;
}

.mode-btn:active {
  transform: scale(0.98);
  background: rgba(255, 255, 255, 0.08);
}

.mode-btn.bot-highlight {
  border-color: rgba(245, 158, 11, 0.3);
}

@media (hover: hover) {
  .mode-btn:hover {
    background: rgba(255, 255, 255, 0.08);
    border-color: var(--glass-border);
    transform: translateX(4px);
  }

  .mode-btn:hover .mode-arrow {
    transform: translateX(4px);
    opacity: 1;
    color: var(--text);
  }
}

/* ── Theme Selection Screen ───────────────────────── */
.theme-screen {
  justify-content: center;
  min-height: 100dvh;
  padding: 40px 20px;
  max-width: 500px;
  margin: 0 auto;
}

.theme-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
  margin-bottom: 24px;
}

.theme-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  border-radius: 20px;
  padding: 16px 20px;
  cursor: pointer;
  transition: all 0.3s ease;
  backdrop-filter: blur(10px);
}

.theme-card-body {
  display: flex;
  align-items: center;
  gap: 16px;
}

.theme-preview {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  width: 60px;
  height: 60px;
  background: rgba(0, 0, 0, 0.2);
  border-radius: 14px;
  font-size: 20px;
  font-weight: 900;
}

.theme-info {
  display: flex;
  flex-direction: column;
}

.theme-name {
  font-size: 16px;
  font-weight: 700;
  margin-bottom: 2px;
}

.theme-desc {
  font-size: 13px;
  color: var(--muted);
}

.theme-status {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  color: #facc15;
}

.theme-card.locked {
  opacity: 0.7;
  filter: grayscale(0.8);
  cursor: not-allowed;
  border-color: rgba(255, 255, 255, 0.05);
  background: rgba(0, 0, 0, 0.1);
}

.theme-card.locked .theme-preview {
  position: relative;
  background: rgba(0, 0, 0, 0.4);
}

.lock-icon {
  position: absolute;
  font-size: 24px;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.5));
}

.theme-card.locked .theme-status {
  color: var(--muted);
  font-size: 11px;
}

.theme-card.selected {
  border-color: #facc15;
  background: rgba(250, 204, 21, 0.05);
  box-shadow: 0 8px 24px rgba(250, 204, 21, 0.1);
}

.theme-actions {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  width: 100%;
}

.confirm-btn {
  width: 100%;
  background: linear-gradient(135deg, #10b981, #059669);
  color: #fff;
  padding: 16px;
  border-radius: 20px;
  font-size: 16px;
  font-weight: 800;
  border: none;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(16, 185, 129, 0.3);
  transition: all 0.2s;
}

.confirm-btn:active {
  transform: scale(0.98);
}

/* .back-link is now handled by .nav-btn */

/* ── Lobby Screen ─────────────────────────────────── */
.lobby-screen {
  padding: 36px 20px 40px;
  gap: 0;
}

.lobby-screen h1 {
  font-size: 22px;
  margin-bottom: 20px;
}

.lobby-card {
  background: var(--glass-bg);
  backdrop-filter: blur(12px);
  border: 1px solid var(--glass-border);
  box-shadow: var(--glass-shadow);
  border-radius: 16px;
  padding: 24px;
  width: 100%;
  max-width: 360px;
  box-shadow: 0 3px 12px rgba(0, 0, 0, .07);
  text-align: center;
}

.lobby-card h3 {
  margin: 0 0 6px;
  font-size: 16px;
}

.lobby-card p {
  margin: 0 0 12px;
  font-size: 13px;
  color: var(--muted);
}

.lobby-btn {
  padding: 11px 24px;
  border: none;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  transition: background .2s;
  min-height: 44px;
}

.create-btn {
  background: #6366f1;
  color: #fff;
  width: 100%;
}

.join-btn {
  background: #10b981;
  color: #fff;
  padding: 11px 18px;
}

@media (hover: hover) {
  .create-btn:hover {
    background: #4f46e5;
  }

  .join-btn:hover {
    background: #059669;
  }
}

.room-code-display {
  margin-top: 14px;
}

.room-code {
  font-size: 22px;
  font-weight: 800;
  letter-spacing: 4px;
  color: #fff;
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid rgba(255, 255, 255, 0.1);
  text-shadow: 0 0 10px rgba(255, 255, 255, 0.4);
  border-radius: 10px;
  padding: 10px 16px;
  margin: 8px 0;
  word-break: break-all;
  font-family: monospace;
}

.copy-btn {
  padding: 8px 16px;
  border: 1.5px solid #6366f1;
  background: transparent;
  color: #6366f1;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all .2s;
}

@media (hover: hover) {
  .copy-btn:hover {
    background: #6366f1;
    color: #fff;
  }
}

.waiting-msg {
  margin-top: 12px;
  font-size: 13px;
  color: var(--muted);
}

.lobby-or {
  margin: 18px 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
}

.join-row {
  display: flex;
  gap: 8px;
}

.join-input {
  flex: 1;
  padding: 10px 12px;
  border: 1.5px solid #d1d5db;
  border-radius: 10px;
  font-size: 16px;
  outline: none;
  min-height: 44px;
}

.join-input:focus {
  border-color: #10b981;
}

.join-status {
  margin-top: 10px;
  font-size: 13px;
  min-height: 20px;
}

.join-status.ok {
  color: #16a34a;
}

.join-status.err {
  color: #dc2626;
}

/* .back-btn is now handled by .nav-btn */

/* ── Online Badge ─────────────────────────────────── */
.online-badge {
  display: flex;
  align-items: center;
  gap: 12px;
  background: #f0fdf4;
  border: 1px solid #bbf7d0;
  border-radius: 20px;
  padding: 6px 16px;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 6px;
  flex-wrap: wrap;
  justify-content: center;
}

.conn-ok {
  color: #16a34a;
  display: none;
  /* Hide the dot connection status as it's confusing */
}

.conn-lost {
  color: #dc2626;
  font-weight: bold;
}

body {
  font-family: "Segoe UI", system-ui, sans-serif;
  text-align: center;
  background: var(--bg-gradient);
  background-attachment: fixed;
  color: var(--text);
  margin: 0;
  padding: max(16px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) max(24px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  min-height: 100dvh;
  overscroll-behavior: none;
  overflow: hidden;
  /* Global stability: prevent casual scrolling */
  -webkit-user-select: none;
  -ms-user-select: none;
  user-select: none;
}

/* Scroll is only allowed if content actually overflows and it's not a touch-drag area */
.screen {
  overflow-y: auto;
  max-height: 100dvh;
  width: 100%;
  scrollbar-width: none;
}

.screen::-webkit-scrollbar {
  display: none;
}

/* Desktop/Landscape Layout for Game Screen */
@media screen and (min-width: 1024px) or (orientation: landscape) and (min-height: 500px) {
  #gameScreen {
    flex-direction: row !important;
    align-items: center;
    justify-content: center;
    gap: 40px;
    padding: 20px;
    max-width: 1200px;
    margin: 0 auto;
  }

  #gameScreen .board {
    order: 1;
    width: 80vh !important;
    height: 80vh !important;
    max-width: none;
    margin: 0;
  }

  #gameScreen .game-controls-wrap {
    order: 2;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    text-align: left;
    gap: 12px;
    max-width: 400px;
  }
}

/* Heading */
h1 {
  margin: 0 0 10px;
  font-size: clamp(18px, 5vw, 24px);
  color: var(--text);
}

/* Toolbar & Inventory */
.toolbar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 8px;
  width: 100%;
}

.inventory {
  font-size: 14px;
  padding: 6px 10px;
  background: var(--glass-bg);
  backdrop-filter: blur(12px);
  border: 1px solid var(--glass-border);
  border-radius: 16px;
  box-shadow: var(--glass-shadow);
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: center;
}

.inv-slot {
  display: inline-flex;
  flex-direction: column;
  gap: 4px;
  align-items: center;
  width: 52px;
  background: transparent;
}

.inv-piece {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: #fff;
  font-weight: 800;
  cursor: grab;
  user-select: none;
  box-shadow: 0 4px 10px rgba(0, 0, 0, .12);
}

.inv-piece:active {
  cursor: grabbing;
  transform: translateY(-2px);
}

.inv-piece[data-player="X"] {
  background: radial-gradient(circle at 30% 30%, #60a5fa, #2563eb, #1e3a8a);
  box-shadow: inset 0 -4px 10px rgba(0, 0, 0, 0.6), inset 0 4px 10px rgba(255, 255, 255, 0.4), 0 6px 16px rgba(37, 99, 235, 0.4);
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.8);
}

.inv-piece[data-player="O"] {
  background: radial-gradient(circle at 30% 30%, #f87171, #dc2626, #7f1d1d);
  box-shadow: inset 0 -4px 10px rgba(0, 0, 0, 0.6), inset 0 4px 10px rgba(255, 255, 255, 0.4), 0 6px 16px rgba(220, 38, 38, 0.4);
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.8);
}

.inv-piece.lv1 {
  font-size: 14px;
}

.inv-piece.lv2 {
  font-size: 16px;
}

.inv-piece.lv3 {
  font-size: 18px;
}

.inv-count {
  font-size: 11px;
  color: var(--muted);
}

/* Level Select */
.level-select-wrap {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--muted);
}

.level-select-wrap label {
  white-space: nowrap;
}

.level-select-wrap select {
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid #d1d5db;
  font-size: 16px;
  cursor: pointer;
  background: #fff;
  min-height: 40px;
}

/* Board layout responsive */
.board {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  width: 85vmin;
  height: 85vmin;
  max-width: 380px;
  max-height: 380px;
  gap: 4px;
  margin: 0 auto 10px;
  touch-action: none;
  background: var(--glass-bg);
  padding: 8px;
  border-radius: 20px;
  backdrop-filter: blur(12px);
  border: 1px solid var(--glass-border);
  box-shadow: var(--glass-shadow);
}

.game-controls-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  gap: 6px;
  margin-bottom: 4px;
  /* Tránh đè lên nút Home ở góc trái trên cùng (Mobile) */
  padding-top: 60px;
}

@media screen and (min-width: 1024px) {
  .game-controls-wrap {
    padding-top: 0;
  }
}

.game-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
  width: 100%;
  margin-top: 10px;
}

.game-actions .reset-btn {
  margin: 0;
  flex: 1;
  max-width: 150px;
}


.cell {
  background: rgba(0, 0, 0, 0.2);
  border: 1px solid rgba(255, 255, 255, 0.05);
  box-shadow: inset 0 4px 8px rgba(0, 0, 0, 0.3);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: calc(90vw / 10);
  cursor: pointer;
  border-radius: 10px;
  transition: 0.2s ease;
  position: relative;
  touch-action: none;
}

.cell.dimmed {
  opacity: 0.3;
}

.cell.highlight {
  background: rgba(255, 255, 255, 0.1);
  box-shadow: inset 0 0 20px rgba(255, 215, 0, 0.3), 0 0 15px rgba(255, 215, 0, 0.4);
  border-color: rgba(255, 215, 0, 0.6);
  animation: winPulse 1.5s infinite;
}

@keyframes winPulse {

  0%,
  100% {
    box-shadow: inset 0 0 20px rgba(255, 215, 0, 0.3), 0 0 15px rgba(255, 215, 0, 0.4);
  }

  50% {
    box-shadow: inset 0 0 30px rgba(255, 215, 0, 0.6), 0 0 25px rgba(255, 215, 0, 0.8);
  }
}

/* Piece inside cell */
.cell .piece {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  border-radius: 50%;
  margin: auto;
  color: #fff;
  font-weight: 800;
  letter-spacing: 0.5px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, .12);
  transition: transform .2s ease;
}

.cell .piece.lv1 {
  width: 58%;
  height: 58%;
  font-size: 18px;
}

.cell .piece.lv2 {
  width: 74%;
  height: 74%;
  font-size: 22px;
}

.cell .piece.lv3 {
  width: 90%;
  height: 90%;
  font-size: 26px;
}

.cell .piece.X {
  background: radial-gradient(circle at 30% 30%, #60a5fa, #2563eb, #1e3a8a);
  box-shadow: inset 0 -4px 10px rgba(0, 0, 0, 0.6), inset 0 4px 10px rgba(255, 255, 255, 0.4), 0 6px 16px rgba(37, 99, 235, 0.4);
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.8);
}

.cell .piece.O {
  background: radial-gradient(circle at 30% 30%, #f87171, #dc2626, #7f1d1d);
  box-shadow: inset 0 -4px 10px rgba(0, 0, 0, 0.6), inset 0 4px 10px rgba(255, 255, 255, 0.4), 0 6px 16px rgba(220, 38, 38, 0.4);
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.8);
}

.cell .piece .tag {
  position: absolute;
  top: -6px;
  right: -6px;
  background: #111827;
  color: #fff;
  font-size: 11px;
  padding: 2px 6px;
  border-radius: 999px;
  border: 2px solid #fff;
}

/* Buried mini pieces */
.cell .buried {
  position: absolute;
  bottom: 4px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 2px;
}

.cell .buried .mini {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 10px;
  font-weight: 700;
  color: #fff;
  box-shadow: 0 2px 4px rgba(0, 0, 0, .15);
  border: 1px solid #fff;
}

.cell .buried .mini.X {
  background: radial-gradient(circle at 30% 30%, #60a5fa, #2563eb, #1e3a8a);
  box-shadow: inset 0 -4px 10px rgba(0, 0, 0, 0.6), inset 0 4px 10px rgba(255, 255, 255, 0.4), 0 6px 16px rgba(37, 99, 235, 0.4);
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.8);
}

.cell .buried .mini.O {
  background: radial-gradient(circle at 30% 30%, #f87171, #dc2626, #7f1d1d);
  box-shadow: inset 0 -4px 10px rgba(0, 0, 0, 0.6), inset 0 4px 10px rgba(255, 255, 255, 0.4), 0 6px 16px rgba(220, 38, 38, 0.4);
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.8);
}

.cell .buried .more {
  font-size: 12px;
  color: var(--muted);
  margin-left: 2px;
}

/* Cell hover & selection */
.cell.selected {
  outline: 3px solid var(--primary);
  outline-offset: 0;
  z-index: 2;
  animation: pulse 1s infinite;
}

@keyframes pulse {
  0% {
    box-shadow: 0 0 0 0 rgba(0, 123, 255, .35);
  }

  70% {
    box-shadow: 0 0 0 10px rgba(0, 123, 255, 0);
  }

  100% {
    box-shadow: 0 0 0 0 rgba(0, 123, 255, 0);
  }
}

.cell.target-ok {
  outline: 3px dashed var(--ok);
  outline-offset: 2px;
  z-index: 3;
}

.cell.target-bad {
  outline: 3px dashed var(--bad);
  outline-offset: 2px;
  z-index: 3;
}

.cell.pop {
  animation: pop-in .22s ease;
}

@keyframes pop-in {
  0% {
    transform: scale(.86);
  }

  100% {
    transform: scale(1);
  }
}

.piece.dragging {
  opacity: 0.85;
  transform: scale(1.02);
  box-shadow: 0 14px 34px rgba(0, 0, 0, .22);
  z-index: 9999;
}

/* ===== New Game Header (Merged Score/Status) ===== */
.game-header {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  width: 100%;
  margin-top: 10px;
}

.player-card {
  flex: 1;
  max-width: 160px;
  /* Tăng từ 140px để đủ chỗ cho tên dài */
  background: var(--glass-bg);
  backdrop-filter: blur(12px);
  border: 1px solid var(--glass-border);
  border-radius: 16px;
  padding: 8px 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  position: relative;
  box-shadow: var(--glass-shadow);
  opacity: 0.8;
  /* Tăng từ 0.6 để tên người chơi rõ hơn khi không phải lượt */
}

.player-card.active {
  opacity: 1;
  transform: translateY(-4px);
  border-color: rgba(99, 102, 241, 0.8);
  box-shadow: 0 0 20px rgba(99, 102, 241, 0.2), var(--glass-shadow);
}

.player-card.active::after {
  content: "";
  position: absolute;
  inset: -1px;
  border-radius: 16px;
  border: 2px solid #6366f1;
  animation: cardPulse 2s infinite;
}

@keyframes cardPulse {
  0% {
    transform: scale(1);
    opacity: 1;
  }

  100% {
    transform: scale(1.05);
    opacity: 0;
  }
}

.player-card.x.active {
  border-color: #3b82f6;
  box-shadow: 0 0 20px rgba(59, 130, 246, 0.3);
}

.player-card.o.active {
  border-color: #ef4444;
  box-shadow: 0 0 20px rgba(239, 68, 68, 0.3);
}

.p-avatar {
  width: 32px;
  height: 32px;
  background: #f3f4f6;
  border-radius: 10px;
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 14px;
}

.x .p-avatar {
  color: #2563eb;
  background: #dbeafe;
}

.o .p-avatar {
  color: #dc2626;
  background: #fee2e2;
}

.p-info {
  flex: 1;
  text-align: left;
}

.p-name {
  font-size: 11px;
  /* Tăng nhẹ */
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text);
  /* Chuyển sang --text để đậm hơn --muted */
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.p-score {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  margin-top: 2px;
}

.p-score span {
  font-size: 18px;
  font-weight: 800;
  color: var(--text);
  margin-left: 2px;
}

.vs-divider {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  font-size: 10px;
  font-weight: 800;
  color: var(--muted);
  background: rgba(0, 0, 0, 0.05);
  padding: 6px 8px;
  border-radius: 12px;
}

.reset-score-btn {
  background: none;
  border: none;
  font-size: 14px;
  cursor: pointer;
  opacity: 0.4;
  transition: all 0.2s;
  padding: 2px;
  line-height: 1;
}

.reset-score-btn:hover {
  opacity: 1;
  transform: rotate(-180deg);
}

.status-sub {
  font-size: 12px;
  color: var(--muted);
  min-height: 18px;
  margin-top: 4px;
}

.winner-msg {
  font-size: 16px;
  font-weight: 700;
  color: #16a34a;
  margin-top: 4px;
}

.bottom-controls {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  margin-top: 15px;
  width: 100%;
}

.action-row {
  display: flex;
  gap: 12px;
  justify-content: center;
}

.reset-btn {
  margin-top: 12px;
  font-size: 16px;
  padding: 8px 14px;
  border-radius: 10px;
  border: none;
  background: var(--primary);
  color: #fff;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(0, 0, 0, .2);
  transition: background .2s ease;
}

@media (hover: hover) {
  .reset-btn:hover {
    background: #0056b3;
  }
}

/* Responsive - tự điều chỉnh theo chiều rộng */
@media screen and (max-width: 768px) {
  .board {
    width: 92vw;
    max-width: 400px;
  }

  .cell {
    font-size: calc(92vw / 10);
  }

  .inv-slot {
    width: 52px;
  }

  .inv-piece {
    width: 46px;
    height: 46px;
  }
}

/* iPhone 14 Pro Max & các màn hình ≤ 430px */
@media screen and (max-width: 430px) {
  h1 {
    font-size: 18px;
    margin-bottom: 6px;
  }

  .board {
    width: 88vw;
    max-width: 388px;
    gap: 5px;
  }

  .cell {
    font-size: calc(88vw / 9);
    border-radius: 12px;
    min-height: 0;
  }

  .inventory {
    padding: 8px;
    gap: 6px;
  }

  .inv-slot {
    width: 52px;
  }

  .inv-piece {
    width: 48px;
    height: 48px;
  }

  .status,
  .scoreboard {
    font-size: 14px;
    margin: 3px 0;
  }

  .winner {
    font-size: 15px;
  }

  .reset-btn {
    margin-top: 8px;
    padding: 10px 20px;
    min-height: 44px;
  }

  .help-btn {
    padding: 8px 16px;
    min-height: 44px;
  }

  .level-select-wrap {
    font-size: 12px;
  }
}

/* ===== Top Navigation Buttons ===== */
/* New Premium Navigation System (Icon Only) */
.nav-btn {
  height: 44px;
  width: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text);
  cursor: pointer;
  transition: all 0.2s ease;
  user-select: none;
  z-index: 1000;
  background: transparent;
  border: none;
  box-shadow: none;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
}

.nav-btn .icon {
  font-size: 28px;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.3));
}

.nav-btn:hover {
  transform: scale(1.15);
  color: #6366f1;
}

.nav-btn:active {
  transform: scale(0.9);
}

.nav-top-left {
  position: absolute;
  top: env(safe-area-inset-top, 20px);
  left: 15px;
  z-index: 1000;
}

.nav-top-right {
  position: absolute;
  top: env(safe-area-inset-top, 20px);
  right: 15px;
  z-index: 1000;
}

.nav-btn.home-btn,
.nav-btn.help-btn {
  background: transparent;
  border: none;
}

@media screen and (min-width: 1024px) {

  .nav-top-left,
  .nav-top-right {
    top: 30px;
    left: 40px;
  }

  .nav-top-right {
    left: auto;
    right: 40px;
  }

  .nav-btn {
    height: 48px;
    width: 48px;
  }
}

@media screen and (max-width: 360px) {

  .nav-top-left,
  .nav-top-right {
    top: 10px;
  }

  .nav-btn {
    height: 38px;
    width: 38px;
  }
}

/* ===== Modal ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .55);
  z-index: 9000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  animation: fadeIn .18s ease;
}

@keyframes fadeIn {
  from {
    opacity: 0
  }

  to {
    opacity: 1
  }
}

.modal-box {
  background: #ffffff;
  border: 1px solid rgba(0, 0, 0, 0.1);
  border-radius: 20px;
  padding: 28px;
  max-width: 560px;
  width: 100%;
  max-height: 85vh;
  overflow-y: auto;
  position: relative;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.3);
  animation: slideUp .2s ease;
  text-align: left;
}

@keyframes slideUp {
  from {
    transform: translateY(20px);
    opacity: 0
  }

  to {
    transform: translateY(0);
    opacity: 1
  }
}

.modal-box h2 {
  margin: 0 0 16px;
  font-size: 20px;
  color: #1e293b;
  padding-right: 32px;
  font-weight: 800;
}

.modal-box h3 {
  font-size: 15px;
  color: #4f46e5;
  margin: 16px 0 6px;
  font-weight: 700;
}

.modal-box section {
  border-bottom: 1px solid rgba(0, 0, 0, 0.05);
  padding-bottom: 10px;
}

.modal-box section:last-of-type {
  border-bottom: none;
}

.modal-box p,
.modal-box li {
  font-size: 15px;
  color: #475569;
  line-height: 1.6;
}

.modal-box ul,
.modal-box ol {
  padding-left: 20px;
  margin: 4px 0;
}

.modal-box li {
  margin-bottom: 4px;
}

.modal-close {
  position: absolute;
  top: 14px;
  right: 16px;
  background: #f1f5f9;
  border: none;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  font-size: 18px;
  cursor: pointer;
  color: #64748b;
  display: grid;
  place-items: center;
  line-height: 1;
  transition: all 0.2s;
}

.modal-close:hover {
  background: #e2e8f0;
  color: #0f172a;
}

.modal-close-btn {
  margin-top: 18px;
  width: 100%;
  padding: 11px;
  border-radius: 10px;
  border: none;
  background: #4f46e5;
  color: #fff;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  transition: background .2s;
}

@media (hover: hover) {
  .modal-close-btn:hover {
    background: #4338ca;
  }
}

@media screen and (max-width: 480px) {
  .modal-box {
    padding: 20px 16px 18px;
  }

  .modal-box h2 {
    font-size: 17px;
  }
}

/* ===== Timer & Emoji ===== */
.timer-container {
  width: 85vmin;
  max-width: 380px;
  height: 12px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 6px;
  overflow: hidden;
  position: relative;
  margin: 20px auto;
  border: 1px solid rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(4px);
}

.timer-bar {
  height: 100%;
  background: #10b981;
  width: 100%;
  transition: width 1s linear, background-color 0.3s;
  border-radius: 999px;
}

.timer-text {
  position: absolute;
  top: -24px;
  right: 0;
  font-size: 14px;
  font-weight: bold;
  color: #ef4444;
}

.emoji-bar {
  position: fixed;
  right: 15px;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: rgba(255, 255, 255, 0.9);
  padding: 12px 8px;
  border-radius: 20px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
  backdrop-filter: blur(8px);
  z-index: 100;
}

.emoji-btn {
  background: transparent;
  border: none;
  font-size: 28px;
  cursor: pointer;
  transition: transform 0.2s cubic-bezier(0.18, 0.89, 0.32, 1.28);
  padding: 4px;
}

.emoji-btn:active {
  transform: scale(0.85);
}

@media (hover: hover) {
  .emoji-btn:hover {
    transform: scale(1.2);
  }
}

.floating-emojis {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 9999;
  overflow: hidden;
}

.emoji-fly {
  position: absolute;
  font-size: 48px;
  animation: floatUp 2s cubic-bezier(0.25, 1, 0.5, 1) forwards;
  will-change: transform, opacity;
}

@keyframes floatUp {
  0% {
    transform: translate(var(--startX), 100vh) scale(0.5);
    opacity: 0;
  }

  15% {
    opacity: 1;
    transform: translate(var(--midX), 80vh) scale(1.2);
  }

  85% {
    opacity: 1;
  }

  100% {
    transform: translate(var(--endX), -10vh) scale(1);
    opacity: 0;
  }
}

/* Image Preview & Pieces */
.img-preview {
  display: inline-block;
  width: 40px;
  height: 40px;
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
  background-color: rgba(0, 0, 0, 0.15);
  /* Cải thiện độ tương phản cho ảnh trắng */
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.1);
}

.piece.is-image,
.inv-piece.is-image {
  background: var(--bg-image) center/contain no-repeat !important;
  background-color: rgba(255, 255, 255, 0.95) !important;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.15), inset 0 0 0 1px rgba(0, 0, 0, 0.05) !important;
  border-radius: 50% !important;
  /* Back to circle for pieces */
  border: 2px solid #fff !important;
}

.cell .buried .mini.is-image {
  background: var(--bg-image) center/contain no-repeat !important;
  background-color: rgba(255, 255, 255, 0.9) !important;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1) !important;
  border-radius: 50% !important;
  border: 1px solid rgba(255, 255, 255, 0.8) !important;
}

/* --- Theme overrides for light mode --- */
body.theme-forest {
  --bg-gradient: linear-gradient(135deg, #f0fdf4 0%, #dcfce7 100%);
  --text: #064e3b;
  /* Darker for better contrast */
  --muted: #065f46;
  --primary: #10b981;
  --glass-bg: rgba(255, 255, 255, 0.7);
  --glass-border: rgba(6, 78, 59, 0.1);
  --glass-shadow: 0 8px 32px rgba(6, 78, 59, 0.08);
}

body.theme-couple {
  --bg-gradient: linear-gradient(135deg, #fffafb 0%, #fce7f3 100%);
  --text: #831843;
  --muted: #9d174d;
  --primary: #db2777;
  --glass-bg: rgba(255, 255, 255, 0.75);
  --glass-border: rgba(131, 24, 67, 0.1);
  --glass-shadow: 0 8px 32px rgba(131, 24, 67, 0.08);
}

body.theme-forest .cell,
body.theme-couple .cell {
  background: rgba(255, 255, 255, 0.6);
  box-shadow: inset 0 4px 8px rgba(0, 0, 0, 0.05);
  border-color: rgba(255, 255, 255, 0.8);
}

body.theme-forest .status,
body.theme-forest .scoreboard,
body.theme-forest h1,
body.theme-forest .mode-label,
body.theme-couple .status,
body.theme-couple .scoreboard,
body.theme-couple h1,
body.theme-couple .mode-label {
  color: var(--text);
}

body.theme-forest .mode-desc,
body.theme-couple .mode-desc {
  color: var(--muted);
}

/* --- Footer SEO --- */
.game-footer {
  margin-top: 50px;
  padding: 40px 20px;
  background: rgba(0, 0, 0, 0.03);
  color: var(--muted);
  font-size: 13px;
  text-align: center;
  border-top: 1px solid rgba(0, 0, 0, 0.05);
}

.footer-content p {
  margin: 5px 0;
  max-width: 600px;
  margin-left: auto;
  margin-right: auto;
}

/* ── Compact Footer ──────────────────────────────── */
.game-footer {
  padding: 24px 20px;
  background: rgba(0, 0, 0, 0.2);
  border-top: 1px solid var(--glass-border);
  width: 100%;
}

.footer-bottom p {
  margin: 5px 0;
  font-size: 13px;
  color: var(--muted);
}

.footer-bottom strong {
  color: var(--text);
}

.footer-legal-links {
  margin: 10px 0;
  font-size: 12px;
}

.footer-legal-links a {
  color: #6366f1;
  text-decoration: none;
  font-weight: 600;
}

.seo-keywords-compact {
  display: flex;
  justify-content: center;
  gap: 12px;
  margin-top: 12px;
  opacity: 0.5;
  font-size: 11px;
}

/* ── Info Screen ─────────────────────────────────── */
.info-screen {
  background: var(--bg-gradient);
  padding: 0;
  height: 100dvh;
  z-index: 2000;
}

.info-header {
  position: sticky;
  top: 0;
  width: 100%;
  padding: env(safe-area-inset-top, 20px) 20px 15px;
  background: rgba(15, 23, 42, 0.8);
  backdrop-filter: blur(15px);
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: center;
  border-bottom: 1px solid var(--glass-border);
}

.nav-btn-back {
  position: absolute;
  left: 20px;
  top: 50%;
  transform: translateY(-50%);
  background: transparent;
  border: none;
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 4px;
}

.nav-btn-back .icon {
  font-size: 24px;
}

.info-content {
  padding: 24px 20px 60px;
  max-width: 650px;
  width: 100%;
  margin: 0 auto;
  text-align: left;
}

.info-section {
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  border-radius: 20px;
  padding: 24px;
  margin-bottom: 24px;
  backdrop-filter: blur(10px);
}

.section-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  padding-bottom: 12px;
}

.section-icon {
  font-size: 24px;
}

.section-header h2 {
  font-size: 20px;
  margin: 0;
  font-weight: 800;
  color: #fff;
}

.section-body {
  color: var(--muted);
  line-height: 1.6;
}

.info-sub-section {
  margin-top: 16px;
  background: rgba(0, 0, 0, 0.2);
  border-radius: 12px;
  padding: 16px;
}

.info-sub-section h4 {
  margin: 0 0 10px;
  color: var(--text);
}

.rules-list,
.strategy-list {
  padding-left: 20px;
  margin: 0;
}

.rules-list li,
.strategy-list li {
  margin-bottom: 8px;
}

.warning-text {
  color: #fbbf24;
  font-size: 13px;
  margin-top: 12px;
}

.faq-body {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.faq-q {
  font-weight: 700;
  color: var(--text);
  margin: 0 0 4px;
}

.faq-a {
  margin: 0;
  font-size: 14px;
}

.legal-section {
  margin-top: 40px;
  text-align: center;
}

.legal-links-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 20px;
}

.legal-btn {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--glass-border);
  color: var(--text);
  padding: 12px;
  border-radius: 12px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.copyright-info {
  font-size: 11px;
  opacity: 0.6;
}

/* ── Menu Animation Override ── */
.mode-btn.info-highlight {
  border-color: rgba(99, 102, 241, 0.3);
}

@media (hover: hover) {
  .mode-btn.info-highlight:hover {
    border-color: #6366f1;
    background: rgba(99, 102, 241, 0.1);
  }
}

.seo-keywords {
  margin: 15px 0;
  display: flex;
  justify-content: center;
  gap: 15px;
  flex-wrap: wrap;
  font-weight: 600;
  opacity: 0.6;
}

.copyright {
  font-size: 11px;
  margin-top: 20px !important;
  opacity: 0.5;
}

/* Theme overrides for footer */
body.theme-forest .game-footer {
  background: rgba(20, 83, 45, 0.03);
}

body.theme-couple .game-footer {
  background: rgba(157, 23, 77, 0.03);
}

/* ── AD MODAL UI ── */
.ad-box {
  background: #0f172a !important;
  border: 2px solid #334155 !important;
  padding: 0 !important;
  overflow: hidden;
  max-width: 400px !important;
  border-radius: 12px !important;
}

.ad-header {
  background: #1e293b;
  padding: 15px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid #334155;
}

.ad-header h3 {
  margin: 0;
  font-size: 16px;
  color: #fff;
}

.ad-countdown {
  background: #ef4444;
  color: #fff;
  padding: 2px 8px;
  border-radius: 4px;
  font-weight: 800;
  font-family: monospace;
}

.ad-content {
  padding: 40px 20px;
  background: #000;
  min-height: 200px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.ad-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 15px;
  color: #94a3b8;
}

.ad-icon {
  font-size: 50px;
  animation: adPulse 2s infinite;
}

@keyframes adPulse {
  0% { transform: scale(1); opacity: 0.5; }
  50% { transform: scale(1.1); opacity: 1; }
  100% { transform: scale(1); opacity: 0.5; }
}

.ad-footer {
  padding: 15px;
  background: #1e293b;
  text-align: center;
}