:root {
  --gold: #f4b64a;
  --gold2: #ffe09a;
  --green: #09d46a;
  --red: #e74c3c;
  --line: #26384f;
  --text: #f0f4fa;
  --muted: #8899b0;
  --panel: rgba(7, 17, 28, 0.84);
  --cardW: clamp(48px, 4.2vw, 78px);
  --cardH: calc(var(--cardW) * 1.4);
  --felt-main: #148447;
  --felt-mid: #0a6536;
  --felt-dark: #05351d;
  --felt-edge: #02140b;
  --felt-glow: rgba(56, 255, 152, 0.2);
  --felt-line: rgba(244, 182, 74, 0.08);
  --floor-base: #4f89aa;
  --floor-line: rgba(255,255,255,0.14);
  --table-surface: #e6d8d3;
  --table-shadow: rgba(0,0,0,0.28);
}

:root[data-theme="blue"] {
  --floor-base: #4f89aa;
  --table-surface: #e6d8d3;
}

:root[data-theme="red"] {
  --floor-base: #7b2a25;
  --table-surface: #ead5cb;
}

:root[data-theme="green"] {
  --floor-base: #5c6f59;
  --table-surface: #ddd4c8;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
.hidden { display: none !important; }

html, body, #app {
  width: 100%; height: 100%; overflow: hidden;
  font-family: "Segoe UI", Tahoma, "Noto Kufi Arabic", sans-serif;
  background: #050a08;
  color: var(--text);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

/* ===== HOME SCREEN ===== */
.home {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: radial-gradient(ellipse at 50% 50%, #0a2a1a 0%, #050d08 100%);
  z-index: 200;
}
.home-card {
  background: linear-gradient(180deg, #121d2bd8, #0a111bd8);
  border: 1px solid var(--line);
  border-radius: 24px; padding: 32px; width: min(92%, 400px);
  backdrop-filter: blur(12px);
  box-shadow: 0 24px 64px #0008, inset 0 1px 0 #ffffff12;
  text-align: center;
}
.home-card h1 {
  font-size: clamp(48px, 10vw, 72px); color: var(--gold);
  text-shadow: 0 8px 24px #000, 0 0 40px #c97b173d;
  margin-bottom: 4px;
}
.home-card p { color: var(--muted); margin-bottom: 20px; }
.home-card input {
  width: 100%; padding: 14px; margin-bottom: 10px;
  border-radius: 14px; border: 1px solid #2b3a4e;
  background: #09101a; color: white; text-align: center; font-size: 16px;
}
.home-card .btn-row { display: flex; gap: 8px; }
.home-card .btn-row button { flex: 1; }
.character-picker {
  margin-bottom: 14px;
  text-align: start;
}
.mode-picker,
.difficulty-picker {
  margin-bottom: 14px;
  text-align: start;
}
.character-picker-label {
  color: var(--gold2);
  font-size: 13px;
  font-weight: 800;
  margin-bottom: 10px;
}
.mode-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}
.mode-option {
  border: 1px solid #2b3a4e;
  background: linear-gradient(180deg, #101927, #0a111b);
  border-radius: 16px;
  padding: 10px 8px;
  color: var(--text);
  font-weight: 800;
  cursor: pointer;
}
.mode-option.is-active {
  border-color: rgba(244, 182, 74, 0.7);
  box-shadow: 0 0 0 2px rgba(244, 182, 74, 0.2);
}
.character-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}
.character-option {
  border: 1px solid #2b3a4e;
  background: linear-gradient(180deg, #101927, #0a111b);
  border-radius: 18px;
  padding: 8px;
  color: var(--text);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  cursor: pointer;
}
.character-option img {
  width: 56px;
  height: 56px;
  border-radius: 16px;
  background: #172233;
}
.character-option span {
  font-size: 11px;
  font-weight: 800;
}
.character-option.is-active {
  border-color: rgba(244, 182, 74, 0.7);
  box-shadow: 0 0 0 2px rgba(244, 182, 74, 0.2);
}

/* ===== GAME SCREEN ===== */
.game {
  position: fixed; inset: 0;
  display: flex; flex-direction: column;
  background:
    linear-gradient(180deg, rgba(255,255,255,0.06), rgba(255,255,255,0) 15%),
    linear-gradient(0deg, rgba(0,0,0,0.18), rgba(0,0,0,0) 30%),
    var(--floor-base);
}
.game.tv-controller .opponents,
.game.tv-controller .room-table,
.game.tv-controller .status-bar {
  display: none;
}
.game.tv-controller.tv-targeting .opponents {
  display: flex;
}
.game.tv-controller {
  --cardW: clamp(58px, 14vw, 82px);
  --cardH: calc(var(--cardW) * 1.7);
}
.game.tv-controller .table-felt {
  background: radial-gradient(circle at center, rgba(22, 130, 70, 0.24), rgba(6, 16, 12, 0.96));
}
.game.tv-controller .center-zone {
  top: 34%;
  width: min(72vw, 340px);
  justify-content: space-between;
  gap: 0;
}
.game.tv-controller .me-area {
  bottom: 86px;
  width: min(72vw, 340px);
}
.game.tv-controller .table-actions {
  left: 10px;
  bottom: 12px;
  max-width: 88px;
  flex-direction: column;
}
.game.tv-controller .me-panel {
  width: 100%;
  gap: 12px;
  align-items: center;
}
.game.tv-controller .seat-tag-me {
  justify-content: center;
}
.game.tv-controller .pile {
  width: calc(var(--cardW) * 1.35);
  align-items: center;
}
.game.tv-controller .me-hand {
  width: 100%;
  grid-template-columns: repeat(2, var(--cardW));
  grid-auto-rows: var(--cardH);
  justify-content: center;
  gap: 10px 12px;
}
.game.tv-controller .action-panel {
  left: 50%;
  top: calc(34% + var(--cardH) + 22px);
  bottom: auto;
  transform: translateX(-50%);
  max-width: calc(100vw - 24px);
  justify-content: center;
}
.game.tv-controller .action-panel.drawn-mode,
.game.tv-controller .action-panel.center-mode {
  left: 50%;
  top: calc(34% + var(--cardH) + 22px);
  transform: translateX(-50%);
  max-width: calc(100vw - 24px);
}
.game.tv-controller .drawn-action-shell {
  flex-direction: column;
  gap: 8px;
}
.game.tv-controller .drawn-action-btn {
  min-width: 110px;
}
.game.tv-controller .private-peek {
  left: auto;
  right: 10px;
  top: 12px;
}
.game.tv-controller .room-notice {
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  max-width: calc(100vw - 150px);
}
.game.tv-controller.tv-targeting .room-notice {
  top: 82px;
}
.game.tv-spectator .me-area,
.game.tv-spectator .action-panel,
.game.tv-spectator .private-peek,
.game.tv-spectator .table-actions {
  display: none;
}

.room-code-row, .topbar-toggles { display: flex; align-items: center; gap: 8px; justify-content: center; }
.topbar-mini {
  min-width: 52px;
  padding: 6px 10px;
  font-size: 11px;
  border-radius: 12px;
}
.info {
  font-size: 13px; text-align: center; padding: 8px 12px;
  border-radius: 16px; background: rgba(14, 24, 36, 0.7); min-width: 86px;
}
.info b { color: var(--gold); font-size: 22px; display: block; }
.info small { color: var(--muted); }
#copy { font-size: 12px; padding: 4px 10px; border-radius: 8px; }
.round-badge { min-width: 72px; }
.icon-btn {
  width: 44px;
  height: 44px;
  border-radius: 14px;
  border: 1px solid #2a3a4e;
  background: linear-gradient(180deg, #162334, #0b141f);
  color: var(--text);
  font-size: 20px;
  font-weight: 800;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.08);
  transition: transform .12s ease, box-shadow .2s ease, border-color .2s ease;
}
.icon-btn:hover,
.icon-btn.active {
  border-color: rgba(244, 182, 74, 0.5);
  box-shadow: 0 12px 24px rgba(0,0,0,0.24), 0 0 0 1px rgba(244, 182, 74, 0.18);
}
.icon-btn:active { transform: scale(.96); }
.floating-settings,
.floating-round {
  position: absolute;
  top: 14px;
  z-index: 22;
}
.floating-settings { left: 14px; }
.floating-round { right: 14px; }

.settings-panel {
  position: absolute;
  top: 14px;
  inset-inline-end: 14px;
  z-index: 30;
  width: min(320px, calc(100vw - 28px));
  padding: 14px;
  border-radius: 24px;
  background: linear-gradient(180deg, rgba(12, 22, 34, 0.97), rgba(6, 14, 22, 0.96));
  border: 1px solid rgba(244, 182, 74, 0.16);
  box-shadow: 0 24px 60px rgba(0,0,0,0.45);
  backdrop-filter: blur(20px);
}
.settings-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}
.settings-header strong {
  display: block;
  color: var(--gold);
  font-size: 18px;
}
.settings-header small {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}
.settings-close {
  width: 38px;
  height: 38px;
  font-size: 16px;
}
.settings-group {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px 0;
  border-top: 1px solid rgba(255,255,255,0.06);
}
.settings-group:first-of-type {
  border-top: 0;
  padding-top: 0;
}
.settings-label {
  font-size: 12px;
  color: var(--muted);
  font-weight: 700;
}
.theme-options {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}
.theme-chip {
  padding: 10px 12px;
  border-radius: 16px;
  border: 1px solid rgba(255,255,255,0.08);
  background: rgba(255,255,255,0.04);
  color: var(--text);
  font-weight: 800;
  cursor: pointer;
}
.theme-chip.is-active {
  border-color: rgba(244, 182, 74, 0.58);
  box-shadow: inset 0 0 0 1px rgba(244, 182, 74, 0.22), 0 0 24px rgba(244, 182, 74, 0.12);
}

/* ===== TABLE ===== */
.table-wrap {
  flex: 1; min-height: 0; position: relative; overflow: hidden;
}
.table-felt {
  position: absolute; inset: 0;
  background:
    linear-gradient(180deg, rgba(255,255,255,0.04), rgba(255,255,255,0)),
    repeating-linear-gradient(
      -8deg,
      rgba(255,255,255,0.03) 0 42px,
      rgba(0,0,0,0.02) 42px 44px,
      transparent 44px 84px
    ),
    repeating-linear-gradient(
      82deg,
      transparent 0 36px,
      var(--floor-line) 36px 38px,
      transparent 38px 74px
    ),
    var(--floor-base);
}
.table-felt::before {
  content: '';
  position: absolute;
  inset: 0;
  background:
    linear-gradient(0deg, rgba(0,0,0,0.2), transparent 28%),
    linear-gradient(180deg, rgba(255,255,255,0.08), transparent 22%);
  pointer-events: none;
}
.table-felt::after {
  content: '';
  position: absolute;
  inset: 0;
  background:
    repeating-linear-gradient(0deg, transparent 0 54px, rgba(255,255,255,0.05) 54px 56px, transparent 56px 110px);
  pointer-events: none;
}
.table-oval { display: none; }
.room-table {
  position: absolute;
  left: 50%;
  top: 51%;
  width: min(56vw, 760px);
  height: min(34vw, 400px);
  transform: translate(-50%, -50%);
  z-index: 1;
  pointer-events: none;
}
.room-table-surface {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background:
    radial-gradient(circle at 35% 30%, rgba(255,255,255,0.55), rgba(255,255,255,0) 18%),
    radial-gradient(circle at 70% 70%, rgba(0,0,0,0.05), rgba(0,0,0,0) 40%),
    var(--table-surface);
  box-shadow:
    0 24px 36px var(--table-shadow),
    inset 0 -10px 18px rgba(0,0,0,0.08);
}
.room-table::before,
.room-table::after {
  content: '';
  position: absolute;
  width: 28px;
  height: 84px;
  bottom: -56px;
  background: linear-gradient(180deg, #232323, #0d0d0d);
  border-radius: 8px;
  box-shadow: 0 6px 10px rgba(0,0,0,0.28);
}
.room-table::before { left: 18%; transform: rotate(10deg); }
.room-table::after { right: 18%; transform: rotate(-10deg); }

/* ===== STATUS BAR ===== */
.status-bar {
  position: absolute; left: 50%; top: 18px; transform: translateX(-50%);
  z-index: 10; padding: 10px 20px; border-radius: 999px;
  background: rgba(4, 16, 26, 0.92); border: 1px solid rgba(244, 182, 74, 0.2);
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.25);
  font-weight: 800; font-size: clamp(12px, 1.2vw, 15px);
  white-space: nowrap; backdrop-filter: blur(6px);
  text-align: center;
}

/* ===== PEEK TIMER ===== */
.peek-timer {
  position: absolute; left: 50%; top: 62px; transform: translateX(-50%);
  z-index: 11;
  background: var(--gold); color: #000;
  font-weight: 900; font-size: clamp(20px, 2.5vw, 30px);
  padding: 4px 20px; border-radius: 99px;
  box-shadow: 0 0 40px #f4b64a60;
  animation: timerPulse 1s ease-in-out infinite;
}
.peek-timer.urgent { background: var(--red); box-shadow: 0 0 40px #e74c3c60; animation: timerPulse .5s ease-in-out infinite; }
.turn-timer {
  position: absolute; left: 14px; top: 72px;
  z-index: 11;
  min-width: 84px;
  text-align: center;
  background: rgba(4, 16, 26, 0.92);
  color: var(--gold2);
  border: 1px solid rgba(244, 182, 74, 0.22);
  border-radius: 999px;
  padding: 8px 12px;
  font-weight: 900;
  box-shadow: 0 12px 30px rgba(0,0,0,0.22);
}
.turn-timer.urgent {
  color: #fff;
  background: rgba(172, 40, 30, 0.92);
  border-color: rgba(255, 140, 120, 0.4);
}
@keyframes timerPulse {
  0%, 100% { transform: translateX(-50%) scale(1); }
  50% { transform: translateX(-50%) scale(1.06); }
}

/* ===== OPPONENTS ===== */
.opponents { position: absolute; inset: 0; z-index: 3; pointer-events: none; padding-top: 88px; }
.game.tv-controller .opponents {
  inset: 88px 12px auto;
  display: none;
  justify-content: center;
  align-items: flex-start;
  gap: 16px;
  padding: 0;
  pointer-events: auto;
  z-index: 16;
}
.game.tv-controller .tv-target-opponent {
  position: relative !important;
  left: auto !important;
  top: auto !important;
  transform: none !important;
  gap: 6px;
}
.game.tv-controller .tv-target-opponent .opponent-hand {
  gap: 6px;
}
.game.tv-controller .tv-target-opponent .player-card {
  cursor: pointer;
}
.move-fx {
  position: absolute;
  inset: 0;
  z-index: 7;
  pointer-events: none;
}
.opponent {
  position: absolute; pointer-events: auto;
  transform: translate(-50%, -50%);
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  transition: left .4s cubic-bezier(.34,1.56,.64,1), top .4s cubic-bezier(.34,1.56,.64,1);
}
.seat-tag {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 16px;
  background: rgba(10, 18, 28, 0.9);
  border: 1px solid rgba(244, 182, 74, 0.18);
  box-shadow: 0 10px 24px rgba(0,0,0,0.22);
}
.seat-tag-me { gap: 10px; }
.opponent-avatar {
  width: clamp(36px, 3vw, 44px); height: clamp(36px, 3vw, 44px);
  border-radius: 14px; border: 2px solid rgba(255, 255, 255, 0.55);
  background: linear-gradient(180deg, #3ec3ff, #2173a7);
  box-shadow: 0 8px 18px rgba(0,0,0,0.24);
  overflow: hidden;
}
.opponent-avatar img,
.me-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.opponent-name {
  font-size: clamp(10px, 1vw, 13px); font-weight: 800;
  text-align: start; min-width: 72px;
  line-height: 1.2;
}
.opponent-name small { display: block; color: #8fe9ba; font-size: 10px; margin-top: 2px; }
.opponent-hand {
  display: grid;
  grid-template-columns: repeat(var(--hand-cols, 2), var(--cardW));
  grid-auto-rows: var(--cardH);
  gap: 6px;
  justify-content: center;
}
.opponent[data-player] {
  width: max-content;
}
.opponent.knocked { opacity: .35; }
.opponent.knocked .opponent-avatar { filter: grayscale(1); }
.opponent.current .opponent-avatar,
.opponent.current .opponent-name {
  box-shadow: 0 0 0 2px var(--green), 0 0 24px #00ff7770;
}

/* ===== CENTER ZONE ===== */
.center-zone {
  position: absolute; left: 50%; top: 52%; transform: translate(-50%, -50%);
  display: flex; gap: clamp(88px, 11vw, 170px); z-index: 5;
  align-items: center;
}

/* ===== PILES ===== */
.pile {
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  padding: 8px;
  border-radius: 24px;
  background: transparent;
  box-shadow: none;
}
.pile-label,
.pile-count { display: none; }

/* Deck physical stack */
.deck-stack { position: relative; cursor: pointer; transition: transform .15s; }
.deck-stack:hover { transform: translateY(-3px); }
.deck-stack:active { transform: translateY(1px) scale(.97); }
.deck-stack.is-highlighted {
  filter: drop-shadow(0 0 18px rgba(244, 182, 74, 0.45));
}
.deck-card {
  position: absolute; width: var(--cardW); height: var(--cardH);
  border-radius: 10px; border: 2px solid #c8a040;
  background: linear-gradient(145deg, #1a2a3a, #0a1520);
  box-shadow: 0 4px 10px #0008;
}
.deck-card:nth-child(1) { transform: translate(0, 0); }
.deck-card:nth-child(2) { transform: translate(1px, -1px); }
.deck-card:nth-child(3) { transform: translate(2px, -2px); }
.deck-card:nth-child(4) { transform: translate(3px, -3px); }
.deck-card:nth-child(5) { transform: translate(4px, -4px); }

/* Discard pile */
.discard-pile {
  min-width: calc(var(--cardW) * 1.2);
  min-height: calc(var(--cardH) * 1.25);
  position: relative; cursor: pointer;
  transition: transform .15s;
}
.discard-pile:hover { transform: translateY(-3px); }
.discard-pile.is-highlighted { filter: drop-shadow(0 0 18px rgba(244, 182, 74, 0.45)); }
.discard-pile.drag-over .discard-card { box-shadow: 0 0 0 3px rgba(9, 212, 106, 0.32), 0 18px 36px rgba(0,0,0,0.32); }

/* ===== DISCARD CARDS (messy stack) ===== */
.discard-card {
  position: absolute; inset: 0;
  width: calc(var(--cardW) * 1.15); height: calc(var(--cardH) * 1.15);
  transition: transform .3s cubic-bezier(.34,1.56,.64,1), box-shadow .3s;
  pointer-events: none;
  transform: rotate(-4deg) translateY(-2px);
}
.discard-shadow {
  position: absolute;
  inset: 0;
  width: calc(var(--cardW) * 1.15); height: calc(var(--cardH) * 1.15);
  border-radius: 12px;
  border: 1px solid rgba(244, 182, 74, 0.28);
  background: linear-gradient(145deg, #19283b, #09121c);
  transform: translate(calc(var(--shadow-step) * 5px), calc(var(--shadow-step) * 4px)) rotate(calc(var(--shadow-step) * 2deg));
  box-shadow: 0 10px 22px rgba(0,0,0,0.24);
}

/* ===== ME AREA ===== */
.me-area {
  position: absolute; left: 50%; bottom: clamp(28px, 4vh, 52px);
  transform: translateX(-50%); z-index: 8;
}
.me-panel {
  display: flex; flex-direction: column; align-items: center; gap: 8px;
}
.me-panel.is-highlighted .seat-tag,
.opponent.is-highlighted .seat-tag {
  box-shadow: 0 0 0 2px rgba(244, 182, 74, 0.36), 0 0 28px rgba(244, 182, 74, 0.32);
}
.me-panel.is-highlighted,
.opponent.is-highlighted {
  animation: liveMovePulse .8s ease-in-out 2;
}
.me-avatar {
  width: 44px;
  height: 44px;
  border-radius: 14px;
  overflow: hidden;
  border: 2px solid rgba(255,255,255,0.58);
  background: linear-gradient(180deg, #52d1ff, #2474a7);
  box-shadow: 0 10px 18px rgba(0,0,0,0.22);
}
.me-name {
  font-weight: 800; font-size: clamp(12px, 1.1vw, 15px);
  text-align: start;
}
.me-name small { display: block; color: #8fe9ba; font-size: 10px; margin-top: 2px; }
.player-notice {
  background: rgba(7, 17, 28, 0.9);
  border: 1px solid rgba(244, 182, 74, 0.18);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 11px;
  font-weight: 800;
  color: #f8f2df;
  box-shadow: 0 8px 22px rgba(0,0,0,0.2);
}
.me-hand {
  display: grid;
  grid-template-columns: repeat(var(--hand-cols, 2), var(--cardW));
  grid-auto-rows: var(--cardH);
  gap: 8px;
  justify-content: center;
  padding: 4px 0 0;
}
.me-hand .me-card:hover {
  transform: translateY(-6px) scale(1.02);
}

/* ===== PLAYER CARDS ===== */
.player-card,
.me-card,
.drawn-card,
.discard-card {
  width: var(--cardW); height: var(--cardH);
  border-radius: 9px; border: 2px solid rgba(244, 182, 74, 0.95);
  position: relative;
  display: flex; align-items: center; justify-content: center;
  flex-direction: column;
  font-weight: 800;
  overflow: hidden;
  box-shadow:
    0 18px 28px rgba(0,0,0,0.24),
    inset 0 1px 0 rgba(255,255,255,0.18),
    inset 0 -10px 18px rgba(0,0,0,0.18);
  transition: transform .2s cubic-bezier(.34,1.56,.64,1), box-shadow .2s, filter .2s;
  will-change: transform, box-shadow;
}
.player-card,
.me-card,
.drawn-card {
  cursor: grab;
  touch-action: none;
  transform-origin: center bottom;
}
.player-card:active,
.me-card:active,
.drawn-card:active { cursor: grabbing; }
.player-card::before,
.me-card::before,
.drawn-card::before,
.discard-card::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, rgba(255,255,255,0.18), transparent 38%, transparent 62%, rgba(255,255,255,0.1));
  pointer-events: none;
}
.player-card.back,
.me-card.back,
.drawn-card.back {
  background: radial-gradient(circle at top, rgba(244,182,74,0.16), transparent 28%), linear-gradient(145deg, #1a2a3a, #0a1520);
}

/* Number card colors */
.num-0 { background: linear-gradient(145deg, #5d6770, #2f3b47); color: #fff; }
.num-1 { background: linear-gradient(145deg, #4aa6f0, #1b5278); color: #fff; }
.num-2 { background: linear-gradient(145deg, #3fd080, #14663f); color: #fff; }
.num-3 { background: linear-gradient(145deg, #20c6b0, #0d6358); color: #fff; }
.num-4 { background: linear-gradient(145deg, #a8de5d, #4b8a1b); color: #112616; }
.num-5 { background: linear-gradient(145deg, #f7d24a, #b78612); color: #2a1a00; }
.num-6 { background: linear-gradient(145deg, #f39f44, #9d4f0d); color: #fff; }
.num-7 { background: linear-gradient(145deg, #b07cf1, #5f2b9d); color: #fff; }
.num-8 { background: linear-gradient(145deg, #f88fb9, #a63767); color: #fff; }
.num-9 { background: linear-gradient(145deg, #ffb36a, #b65d0f); color: #fff; }
.num-10 { background: linear-gradient(145deg, #ff6c62, #9f211b); color: #fff; }

/* Action cards */
.action {
  font-size: calc(var(--cardW) * .2);
  line-height: 1.1; padding: 4px;
}
.action::after {
  content: ''; position: absolute; inset: 0;
  background: radial-gradient(circle at 50% 50%, #fff2, transparent 60%);
  pointer-events: none;
}
.action-look { background: linear-gradient(145deg, #7d47a4, #401867); }
.action-swap { background: linear-gradient(145deg, #2c86bf, #154360); }
.action-draw2 { background: linear-gradient(145deg, #2cb56a, #0d5332); }

.card-number {
  font-size: calc(var(--cardW) * .56);
  font-weight: 900;
  text-shadow: 0 2px 6px rgba(0,0,0,0.28);
  line-height: 1;
}
.card-icon { font-size: calc(var(--cardW) * .34); line-height: 1; }
.card-label { font-size: calc(var(--cardW) * .16); font-weight: 800; text-align: center; line-height: 1.1; max-width: 88%; }
.card-accent {
  font-size: calc(var(--cardW) * .13);
  font-weight: 800;
  letter-spacing: .08em;
  opacity: .82;
}
.card-corner {
  position: absolute;
  font-size: calc(var(--cardW) * .14);
  font-weight: 900;
  opacity: .88;
}
.card-corner.top { top: 7px; right: 8px; }
.card-corner.bottom { bottom: 7px; left: 8px; transform: rotate(180deg); }
.card-back-mark {
  font-size: calc(var(--cardW) * .32);
  color: var(--gold);
  text-shadow: 0 0 18px rgba(244, 182, 74, 0.24);
}
.card-back-pattern {
  position: absolute;
  inset: 10%;
  border-radius: 14px;
  border: 1px solid rgba(244, 182, 74, 0.18);
  background:
    radial-gradient(circle at 30% 30%, rgba(244,182,74,0.22), transparent 18%),
    radial-gradient(circle at 70% 70%, rgba(244,182,74,0.12), transparent 16%);
}

/* Card glow for current turn */
.player-card.glow,
.me-card.glow,
.drawn-card.glow {
  box-shadow: 0 0 0 2px var(--green), 0 0 24px #00ff8860;
}
.player-card.selected,
.me-card.selected,
.drawn-card.selected,
.drop-target {
  outline: 3px solid var(--gold);
  box-shadow: 0 0 0 2px #000, 0 0 30px #f4b64a80;
}
.player-card.move-target,
.me-card.move-target {
  outline: 3px solid rgba(88, 255, 178, 0.9);
  box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.65), 0 0 26px rgba(88, 255, 178, 0.5);
  animation: moveTargetPulse 1s ease-in-out 2;
}
.player-card.move-target::after,
.me-card.move-target::after {
  content: '';
  position: absolute;
  inset: -6px;
  border-radius: 14px;
  border: 2px solid rgba(88, 255, 178, 0.65);
  box-shadow: 0 0 18px rgba(88, 255, 178, 0.3);
  animation: targetRingPulse 1s ease-in-out 2;
  pointer-events: none;
}
.move-target-badge {
  position: absolute;
  top: -10px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 3;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 7px;
  border-radius: 999px;
  background: rgba(8, 18, 28, 0.96);
  border: 1px solid rgba(88, 255, 178, 0.5);
  box-shadow: 0 10px 18px rgba(0,0,0,0.28);
  white-space: nowrap;
}
.move-beam {
  position: absolute;
  height: 4px;
  border-radius: 999px;
  transform-origin: 0 50%;
  background: linear-gradient(90deg, rgba(88,255,178,0), rgba(88,255,178,0.95) 22%, rgba(255,244,193,0.96) 55%, rgba(88,255,178,0.2));
  box-shadow: 0 0 18px rgba(88,255,178,0.45), 0 0 26px rgba(255,244,193,0.18);
  animation: beamFlash 1s ease-out forwards;
}
.move-beam::after {
  content: '';
  position: absolute;
  right: -6px;
  top: 50%;
  width: 10px;
  height: 10px;
  transform: translateY(-50%);
  border-radius: 50%;
  background: radial-gradient(circle, #fff6c2 0%, #8cffce 60%, rgba(88,255,178,0) 100%);
  box-shadow: 0 0 14px rgba(255,244,193,0.7);
}
.move-target-icon {
  width: 12px;
  height: 12px;
  position: relative;
  display: inline-block;
}
.move-target-text {
  font-size: 9px;
  font-weight: 900;
  line-height: 1;
  color: #dffef2;
}
.move-eye .move-target-icon::before {
  content: '';
  position: absolute;
  inset: 2px 0;
  border: 2px solid #8cffce;
  border-radius: 100% / 70%;
}
.move-eye .move-target-icon::after {
  content: '';
  position: absolute;
  width: 4px;
  height: 4px;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: #8cffce;
}
.move-swap .move-target-icon::before {
  content: '⇄';
  position: absolute;
  inset: -1px 0 0;
  color: #8cffce;
  font-size: 12px;
  font-weight: 900;
  text-align: center;
}
.move-match .move-target-icon::before {
  content: '✓';
  position: absolute;
  inset: -1px 0 0;
  color: #8cffce;
  font-size: 12px;
  font-weight: 900;
  text-align: center;
}
.move-miss .move-target-icon::before {
  content: '!';
  position: absolute;
  inset: -1px 0 0;
  color: #ffb092;
  font-size: 12px;
  font-weight: 900;
  text-align: center;
}
.me-card.noticed {
  box-shadow: 0 0 0 2px rgba(255,255,255,0.14), 0 0 32px rgba(255, 172, 64, 0.55);
  animation: noticedPulse 1s ease-in-out infinite;
}
@keyframes noticedPulse {
  0%, 100% { transform: translateY(0) scale(1); }
  50% { transform: translateY(-2px) scale(1.03); }
}
@keyframes moveTargetPulse {
  0%, 100% { transform: translateY(0) scale(1); }
  50% { transform: translateY(-2px) scale(1.04); }
}
@keyframes targetRingPulse {
  0%, 100% { opacity: .55; transform: scale(1); }
  50% { opacity: 1; transform: scale(1.05); }
}
@keyframes beamFlash {
  0% { opacity: 0; filter: saturate(1.2); }
  15% { opacity: 1; }
  70% { opacity: .95; }
  100% { opacity: 0; filter: saturate(.9); }
}

/* Dragging card state (cloned element) */
.drag-ghost {
  position: fixed; pointer-events: none; z-index: 100;
  transition: none !important;
  animation: none !important;
  transform-origin: center center;
}

/* ===== ME MY CARDS ===== */
.me-card { transform: translateY(0); }
#myHand .me-card:hover { transform: translateY(-8px) scale(1.02); z-index: 2; }
.me-card.dragging { opacity: .4; }

/* ===== ACTION PANEL ===== */
.action-panel {
  position: absolute; left: 14px; bottom: 14px;
  z-index: 9;
  display: flex; gap: 8px; align-items: center;
  padding: 8px 12px;
  background: rgba(4, 16, 26, 0.9); border: 1px solid rgba(244, 182, 74, 0.16);
  border-radius: 16px; backdrop-filter: blur(14px);
  max-width: min(38vw, 420px); flex-wrap: wrap; justify-content: flex-start;
  box-shadow: 0 18px 40px rgba(0,0,0,0.26);
}
.action-panel .player-card { cursor: default; }
.action-panel:empty { opacity: 0; pointer-events: none; transform: translateY(10px); }
.action-panel .hint { font-size: 13px; color: #e6eef9; font-weight: 700; text-align: center; }
.action-panel.drag-over {
  box-shadow: 0 0 0 2px rgba(9, 212, 106, 0.24), 0 18px 40px rgba(0,0,0,0.26), inset 0 0 22px rgba(9, 212, 106, 0.16);
  border-color: rgba(9, 212, 106, 0.35);
}
.action-panel.is-highlighted {
  box-shadow: 0 0 0 2px rgba(244, 182, 74, 0.24), 0 18px 40px rgba(0,0,0,0.26), inset 0 0 28px rgba(244, 182, 74, 0.14);
}
.action-panel.drawn-mode {
  left: calc(50% + 28px);
  top: 52%;
  bottom: auto;
  transform: translate(0, -50%);
  padding: 0;
  background: transparent;
  border: 0;
  box-shadow: none;
  backdrop-filter: none;
  width: auto;
  max-width: none;
}
.action-panel.center-mode {
  left: calc(50% + var(--cardW) + 40px);
  top: 52%;
  bottom: auto;
  transform: translateY(-50%);
  max-width: min(30vw, 340px);
}
.drawn-action-shell {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
}
.drawn-action-card {
  display: flex;
  align-items: center;
  justify-content: center;
}
.drawn-action-btn {
  min-width: 78px;
  padding-inline: 16px;
}
.lock-note {
  width: 100%;
  margin-top: 6px;
}

/* ===== DRAW 2 CHOICES ===== */
.draw2-choices { display: flex; gap: 8px; align-items: center; }
.draw2-choice {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
}
.draw2-throw-btns { display: flex; gap: 4px; }
.room-notice {
  position: absolute;
  left: 50%;
  top: 70px;
  transform: translateX(-50%);
  z-index: 15;
  padding: 8px 14px;
  border-radius: 999px;
  background: rgba(7, 17, 28, 0.92);
  border: 1px solid rgba(244, 182, 74, 0.2);
  font-size: 12px;
  font-weight: 800;
  box-shadow: 0 10px 26px rgba(0,0,0,0.2);
}
.room-notice.is-move {
  border-color: rgba(244, 182, 74, 0.34);
  box-shadow: 0 14px 34px rgba(0,0,0,0.24), 0 0 0 1px rgba(244, 182, 74, 0.16);
}
.private-peek {
  position: absolute;
  left: calc(50% + var(--cardW) + 44px);
  top: calc(52% + 116px);
  z-index: 12;
  min-width: 120px;
  padding: 10px;
  border-radius: 18px;
  background: rgba(7, 17, 28, 0.92);
  border: 1px solid rgba(244, 182, 74, 0.2);
  box-shadow: 0 16px 34px rgba(0,0,0,0.24);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}
.private-peek-label {
  color: var(--gold2);
  font-size: 11px;
  font-weight: 900;
}
.private-peek-meta {
  font-size: 11px;
  text-align: center;
  color: var(--text);
}
.private-peek-card {
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ===== FLOATING ACTIONS ===== */
.table-actions {
  position: absolute;
  left: 14px;
  bottom: 14px;
  z-index: 12;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  max-width: min(42vw, 460px);
}
.table-actions .btn {
  min-width: 92px;
}

.btn {
  border: 1px solid #2a3a4e;
  background: linear-gradient(180deg, #1a2839, #0d1520);
  border-radius: 16px; padding: 10px 12px;
  color: var(--text); font-weight: 800; font-size: 13px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center; gap: 4px;
  transition: transform .1s, filter .1s, box-shadow .2s;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.08);
}
.btn:active { transform: scale(.95); }
.btn:disabled { opacity: .35; filter: saturate(.5); }
.btn-gold { background: linear-gradient(135deg, #7d4b10, #c98a25) !important; border-color: #c98a25 !important; }
.btn-stop { background: linear-gradient(135deg, #671d1d, #b2322b) !important; border-color: #b2322b !important; }
.btn-stop.active { animation: stopPulse 1s ease-in-out infinite; }
@keyframes stopPulse {
  0%, 100% { box-shadow: 0 0 10px #ff4444; }
  50% { box-shadow: 0 0 28px #ff4444, 0 0 50px #ff444444; }
}

/* ===== MODALS ===== */
.modal-overlay {
  position: fixed; inset: 0; z-index: 200;
  background: #000000cc; backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center;
  animation: fadeIn .2s ease;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.modal-box {
  background: linear-gradient(180deg, #1a2a3d, #0d1622);
  border: 1px solid var(--line);
  border-radius: 20px; width: min(92%, 440px);
  max-height: 80vh; overflow-y: auto;
  box-shadow: 0 30px 60px #000;
  animation: slideUp .3s cubic-bezier(.34,1.56,.64,1);
}
@keyframes slideUp { from { transform: translateY(40px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

.modal-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 16px 18px 8px; border-bottom: 1px solid var(--line);
}
.modal-header h2 { color: var(--gold); font-size: 18px; margin: 0; }
.modal-close { background: none; border: none; color: var(--muted); font-size: 22px; cursor: pointer; padding: 4px; }

.modal-body { padding: 12px 18px 16px; }
.player-row {
  display: flex; justify-content: space-between; padding: 8px 0;
  border-bottom: 1px solid #1a2a3e; font-size: 14px;
}
.player-row:last-child { border-bottom: none; }

.result-row {
  display: grid; grid-template-columns: 30px 1fr auto auto; gap: 8px;
  padding: 10px 6px; border-bottom: 1px solid #1a2a3e;
  font-weight: 700; font-size: 14px; align-items: center;
}
.result-row:last-child { border-bottom: none; }
.result-row.winner { background: linear-gradient(90deg, #f4b64a22, transparent); color: var(--gold); }
.result-row.doubled { color: #ff6b6b; }
.result-row.knocked { color: var(--muted); opacity: .7; }
.badge-gold { color: var(--gold); }
.knock-section { margin-top: 12px; padding-top: 10px; border-top: 2px dashed #3a2a2a; }
.knock-section h3 { color: var(--red); font-size: 14px; margin-bottom: 6px; }
.gameover { text-align: center; padding: 14px; font-size: 20px; font-weight: 900; color: var(--gold); text-shadow: 0 0 30px #f4b64a88; }

/* ===== ANIMATIONS ===== */
@keyframes cardFlyIn {
  from { opacity: 0; transform: translateY(30px) scale(.8) rotateY(90deg); }
  to { opacity: 1; transform: translateY(0) scale(1) rotateY(0); }
}
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20%, 60% { transform: translateX(-6px); }
  40%, 80% { transform: translateX(6px); }
}
@keyframes burst {
  0% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.3); opacity: .7; }
  100% { transform: scale(1); opacity: 0; }
}
.card-fly { animation: none; }
.shake { animation: shake .4s ease; }
@keyframes liveMovePulse {
  0%, 100% { filter: brightness(1); }
  50% { filter: brightness(1.1); }
}

/* ===== RESPONSIVE ===== */
@media (max-width: 1100px) {
  :root { --cardW: clamp(40px, 4.2vw, 58px); }
}
@media (max-width: 820px) {
  .game { overflow: hidden; }
  .game.tv-controller { --cardW: clamp(56px, 14vw, 76px); }
  .game.tv-controller { --cardH: calc(var(--cardW) * 1.7); }
  .table-wrap {
    flex: 1; min-height: 0; height: auto;
    position: relative;
    display: block;
    padding: 8px;
    overflow: hidden;
  }
  .table-felt {
    position: absolute; inset: 8px;
    min-height: 0; border-radius: 18px; margin: 0;
  }
  .settings-panel {
    top: 8px;
    inset-inline-end: 8px;
    width: min(300px, calc(100vw - 16px));
    border-radius: 20px;
  }
  .floating-settings,
  .floating-round { top: 10px; }
  .floating-settings { left: 10px; }
  .floating-round { right: 10px; }
  .table-oval { display: none; }
  .opponents {
    position: absolute; inset: 78px 14px auto;
    display: flex; justify-content: space-between; gap: 12px; padding: 0;
    pointer-events: auto;
  }
  .opponent {
    position: relative !important; left: auto !important; top: auto !important; transform: none !important;
    gap: 5px;
  }
  .room-table {
    width: min(80vw, 520px);
    height: min(52vw, 300px);
    top: 51%;
  }
  .opponent-avatar { width: 34px; height: 34px; border-radius: 12px; }
  .opponent-hand { gap: 4px; }
  .status-bar { position: absolute; left: 50%; top: 12px; transform: translateX(-50%); margin: 0; max-width: calc(100% - 180px); }
  .peek-timer { position: absolute; left: 50%; top: 50px; transform: translateX(-50%); margin: 0; }
  .turn-timer { position: absolute; left: 12px; top: 62px; margin: 0; min-width: 74px; }
  .peek-timer.urgent { animation: none; }
  .center-zone { position: absolute; left: 50%; top: 54%; transform: translate(-50%, -50%); padding: 0; gap: 52px; }
  .pile { padding: 10px 12px; gap: 6px; }
  .me-area {
    position: absolute; left: 50%; bottom: 24px; transform: translateX(-50%);
    width: calc(100% - 20px);
  }
  .me-panel { gap: 5px; }
  .me-avatar { width: 36px; height: 36px; border-radius: 12px; }
  .me-name { font-size: 11px; }
  .me-hand { gap: 6px; padding: 4px 0 0; }
  .table-actions {
    left: 10px;
    bottom: 104px;
    max-width: 140px;
    flex-direction: column;
  }
  .table-actions .btn { min-width: 0; width: 100%; }
  .action-panel {
    position: absolute; left: 10px; bottom: 12px;
    margin: 0; width: min(42vw, 220px); padding: 8px 10px;
  }
  .action-panel:empty { display: none; }
  .action-panel .hint { font-size: 11px; }
  .action-panel.drawn-mode {
    left: calc(50% + 18px);
    top: 54%;
    bottom: auto;
    width: auto;
    max-width: none;
  }
  .action-panel.center-mode {
    left: calc(50% + var(--cardW) + 20px);
    top: 54%;
    max-width: min(40vw, 220px);
  }
  .private-peek {
    left: calc(50% + var(--cardW) + 18px);
    top: calc(54% + 94px);
  }
  .drawn-action-shell { gap: 10px; }
  .draw2-choices { gap: 4px; }
  .draw2-throw-btns { gap: 4px; flex-wrap: wrap; justify-content: center; }
  .game.tv-controller .center-zone {
    top: 33%;
    width: min(72vw, 320px);
  }
  .game.tv-controller .opponents {
    inset: 86px 8px auto;
    gap: 10px;
  }
  .game.tv-controller .action-panel {
    left: 50%;
    top: calc(33% + var(--cardH) + 18px);
    transform: translateX(-50%);
    max-width: calc(100vw - 24px);
  }
  .game.tv-controller .action-panel.drawn-mode,
  .game.tv-controller .action-panel.center-mode {
    left: 50%;
    top: calc(33% + var(--cardH) + 18px);
    transform: translateX(-50%);
  }
  .game.tv-controller .private-peek {
    right: 8px;
    top: 58px;
    min-width: 92px;
  }
  .game.tv-controller .room-notice {
    top: 10px;
    max-width: calc(100vw - 92px);
    font-size: 11px;
  }
  .game.tv-controller .me-area {
    width: min(72vw, 320px);
    bottom: 82px;
  }
}
@media (max-width: 600px) {
  :root { --cardW: clamp(31px, 6vw, 39px); }
  .game.tv-controller { --cardW: clamp(52px, 15vw, 68px); }
  .game.tv-controller { --cardH: calc(var(--cardW) * 1.7); }
  .icon-btn { width: 40px; height: 40px; border-radius: 12px; }
  .round-badge { min-width: 62px; padding: 6px 8px; }
  .settings-panel {
    top: 8px;
    inset-inline: 8px;
    width: auto;
    padding: 12px;
  }
  .settings-header strong { font-size: 16px; }
  .settings-header small { font-size: 11px; }
  .theme-options { grid-template-columns: repeat(3, 1fr); }
  .character-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
  .character-option img { width: 46px; height: 46px; }
  .room-table {
    width: min(88vw, 420px);
    height: min(62vw, 250px);
    top: 50%;
  }
  .opponents { inset: 88px 8px auto; gap: 8px; }
  .opponent-name { min-width: 62px; padding: 4px 6px; font-size: 9px; }
  .opponent-name small { font-size: 8px; }
  .status-bar { top: 12px; padding: 8px 16px; max-width: calc(100% - 150px); }
  .turn-timer { top: 58px; left: 10px; min-width: 66px; padding: 7px 10px; }
  .center-zone { top: 54%; gap: 36px; }
  .pile { padding: 8px; }
  .table-actions {
    left: 8px;
    bottom: 96px;
    max-width: 124px;
    gap: 6px;
  }
  .action-panel { left: 8px; bottom: 8px; width: min(40vw, 170px); }
  .action-panel.drawn-mode {
    left: calc(50% + 12px);
    top: 54%;
    bottom: auto;
  }
  .action-panel.center-mode {
    left: calc(50% + var(--cardW) + 12px);
    top: 54%;
    max-width: min(42vw, 170px);
  }
  .private-peek {
    left: calc(50% + var(--cardW) + 12px);
    top: calc(54% + 84px);
    min-width: 98px;
    padding: 8px;
  }
  .me-area { bottom: 18px; width: calc(100% - 120px); }
  .drawn-action-shell { gap: 8px; }
  .drawn-action-btn { min-width: 64px; padding-inline: 10px; }
  .btn { font-size: 10px; padding: 6px 8px; }
  .game.tv-controller .center-zone {
    top: 31%;
    width: min(72vw, 290px);
  }
  .game.tv-controller .opponents {
    inset: 82px 6px auto;
    gap: 8px;
  }
  .game.tv-controller .tv-target-opponent .opponent-name {
    min-width: 54px;
    font-size: 8px;
  }
  .game.tv-controller .tv-target-opponent .opponent-name small {
    font-size: 7px;
  }
  .game.tv-controller .action-panel {
    left: 50%;
    top: calc(31% + var(--cardH) + 16px);
    transform: translateX(-50%);
    max-width: calc(100vw - 20px);
    padding: 6px 8px;
  }
  .game.tv-controller .action-panel.drawn-mode,
  .game.tv-controller .action-panel.center-mode {
    left: 50%;
    top: calc(31% + var(--cardH) + 16px);
    transform: translateX(-50%);
  }
  .game.tv-controller .drawn-action-shell {
    gap: 6px;
  }
  .game.tv-controller .drawn-action-btn {
    min-width: 86px;
    padding-inline: 8px;
  }
  .game.tv-controller .me-area {
    width: min(72vw, 290px);
    bottom: 78px;
  }
  .game.tv-controller .room-notice {
    top: 8px;
    max-width: calc(100vw - 82px);
  }
  .game.tv-controller .table-actions {
    max-width: 76px;
  }
}
@media (orientation: landscape) and (max-height: 620px) {
  .table-wrap { min-height: 200px; }
}
