/* ==========================================================================
   Rummikub Royal: 2D Magnetic Grid Edition - Luxury UI Stylesheet
   ========================================================================== */

:root,
body[data-theme="emerald"] {
  --bg-table-center: #0f3d2e;
  --bg-table-edge: #061c14;
  --bg-hud: rgba(6, 24, 18, 0.92);
  --bg-players: rgba(9, 32, 24, 0.88);
  --grid-cell-bg: rgba(255, 255, 255, 0.028);
  --grid-cell-border: rgba(255, 255, 255, 0.09);
  --grid-cell-hover: rgba(52, 211, 153, 0.22);
  --rack-bg: linear-gradient(180deg, #2d1e14 0%, #1b110b 100%);
  --rack-border: #5c3d28;
  --rack-slot-bg: rgba(0, 0, 0, 0.28);
  --rack-slot-border: rgba(255, 215, 170, 0.12);
  --accent-primary: #10b981;
  --accent-gold: #f59e0b;
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
}

body[data-theme="obsidian"] {
  --bg-table-center: #161b26;
  --bg-table-edge: #090c12;
  --bg-hud: rgba(10, 14, 22, 0.94);
  --bg-players: rgba(15, 20, 32, 0.90);
  --grid-cell-bg: rgba(255, 255, 255, 0.03);
  --grid-cell-border: rgba(148, 163, 184, 0.11);
  --grid-cell-hover: rgba(56, 189, 248, 0.22);
  --rack-bg: linear-gradient(180deg, #1e2536 0%, #0f141f 100%);
  --rack-border: #334155;
  --rack-slot-bg: rgba(0, 0, 0, 0.35);
  --rack-slot-border: rgba(148, 163, 184, 0.14);
  --accent-primary: #38bdf8;
  --accent-gold: #fbbf24;
}

body[data-theme="wood"] {
  --bg-table-center: #3b2416;
  --bg-table-edge: #1c1008;
  --bg-hud: rgba(24, 14, 8, 0.94);
  --bg-players: rgba(34, 20, 12, 0.90);
  --grid-cell-bg: rgba(255, 243, 224, 0.035);
  --grid-cell-border: rgba(255, 224, 178, 0.12);
  --grid-cell-hover: rgba(245, 158, 11, 0.25);
  --rack-bg: linear-gradient(180deg, #4a2c18 0%, #2a170b 100%);
  --rack-border: #7c4d2b;
  --rack-slot-bg: rgba(0, 0, 0, 0.30);
  --rack-slot-border: rgba(255, 224, 178, 0.15);
  --accent-primary: #f59e0b;
  --accent-gold: #fcd34d;
}

body[data-theme="midnight"] {
  --bg-table-center: #17153b;
  --bg-table-edge: #09081a;
  --bg-hud: rgba(10, 9, 26, 0.94);
  --bg-players: rgba(18, 16, 44, 0.90);
  --grid-cell-bg: rgba(255, 255, 255, 0.03);
  --grid-cell-border: rgba(167, 139, 250, 0.12);
  --grid-cell-hover: rgba(167, 139, 250, 0.25);
  --rack-bg: linear-gradient(180deg, #221f4d 0%, #110f29 100%);
  --rack-border: #4c1d95;
  --rack-slot-bg: rgba(0, 0, 0, 0.34);
  --rack-slot-border: rgba(196, 181, 253, 0.14);
  --accent-primary: #a78bfa;
  --accent-gold: #fbbf24;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: 'Pretendard', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  color: var(--text-main);
  background: radial-gradient(circle at 50% 42%, var(--bg-table-center) 0%, var(--bg-table-edge) 100%);
  user-select: none;
  -webkit-user-select: none;
}

#confetti-canvas {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 9999;
}

.app-shell {
  display: flex;
  flex-direction: column;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
}

/* ==========================================================================
   1. Top Slim HUD Bar (50px)
   ========================================================================== */
.top-hud {
  height: 50px;
  min-height: 50px;
  background: var(--bg-hud);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 18px;
  backdrop-filter: blur(12px);
  z-index: 100;
}

.brand-area {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-logo {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 900;
  font-size: 17px;
  color: #fff;
  box-shadow: 0 2px 10px rgba(245, 158, 11, 0.35);
}

.brand-title {
  font-size: 16px;
  font-weight: 800;
  letter-spacing: -0.3px;
  display: flex;
  align-items: center;
  gap: 7px;
}

.brand-sub {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 999px;
  background: rgba(16, 185, 129, 0.18);
  color: #34d399;
  border: 1px solid rgba(16, 185, 129, 0.35);
}

.hud-center-stats {
  display: flex;
  align-items: center;
  gap: 14px;
}

.pool-badge {
  display: flex;
  align-items: center;
  gap: 7px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.12);
  padding: 5px 12px;
  border-radius: 999px;
  font-size: 13px;
}

.pool-badge b {
  color: var(--accent-gold);
  font-size: 14px;
}

.timer-widget {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(15, 23, 42, 0.65);
  border: 1px solid rgba(255, 255, 255, 0.12);
  padding: 3px 12px 3px 6px;
  border-radius: 999px;
  transition: all 0.25s ease;
}

.timer-widget.timer-urgent {
  background: rgba(127, 29, 29, 0.78);
  border-color: #ef4444;
  box-shadow: 0 0 15px rgba(239, 68, 68, 0.45);
  animation: pulseUrgent 0.8s infinite alternate;
}

@keyframes pulseUrgent {
  from { transform: scale(1); }
  to { transform: scale(1.04); }
}

.timer-ring-wrap {
  position: relative;
  width: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.timer-svg {
  width: 34px;
  height: 34px;
  transform: rotate(-90deg);
}

.timer-bg-circle {
  fill: none;
  stroke: rgba(255, 255, 255, 0.12);
  stroke-width: 3.5;
}

.timer-fg-circle {
  fill: none;
  stroke: var(--accent-primary);
  stroke-width: 3.5;
  stroke-linecap: round;
  stroke-dasharray: 125.6;
  stroke-dashoffset: 0;
  transition: stroke-dashoffset 0.35s linear, stroke 0.25s ease;
}

.timer-widget.timer-urgent .timer-fg-circle {
  stroke: #f87171;
}

#timer-seconds {
  position: absolute;
  font-size: 11.5px;
  font-weight: 800;
  color: #fff;
}

.timer-label {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 600;
}

.meld-badge {
  font-size: 12.5px;
  font-weight: 700;
  padding: 5px 13px;
  border-radius: 999px;
  transition: all 0.25s ease;
}

.meld-badge.meld-pending {
  background: rgba(245, 158, 11, 0.14);
  color: #fcd34d;
  border: 1px solid rgba(245, 158, 11, 0.38);
}

.meld-badge.meld-ready {
  background: rgba(16, 185, 129, 0.22);
  color: #6ee7b7;
  border: 1px solid rgba(16, 185, 129, 0.6);
  box-shadow: 0 0 12px rgba(16, 185, 129, 0.28);
}

.meld-badge.meld-complete {
  background: rgba(59, 130, 246, 0.18);
  color: #93c5fd;
  border: 1px solid rgba(59, 130, 246, 0.4);
}

.hud-right-tools {
  display: flex;
  align-items: center;
  gap: 6px;
  position: relative;
}

.hud-btn {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: var(--text-main);
  height: 34px;
  padding: 0 11px;
  border-radius: 8px;
  font-size: 12.5px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.hud-btn:hover {
  background: rgba(255, 255, 255, 0.14);
  border-color: rgba(255, 255, 255, 0.25);
}

.hud-btn.active-toggle {
  background: rgba(16, 185, 129, 0.22);
  border-color: rgba(16, 185, 129, 0.55);
  color: #6ee7b7;
}

.hud-btn.btn-primary-sm {
  background: linear-gradient(135deg, #10b981 0%, #059669 100%);
  border-color: #34d399;
  color: #fff;
}

.theme-dropdown {
  display: none;
  position: absolute;
  top: 42px;
  left: 0;
  background: #0f172a;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 10px;
  padding: 6px;
  width: 190px;
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.6);
  z-index: 300;
}

.theme-opt {
  padding: 8px 10px;
  border-radius: 7px;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  color: #e2e8f0;
}

.theme-opt:hover,
.theme-opt.active {
  background: rgba(255, 255, 255, 0.1);
  color: var(--accent-gold);
}

/* ==========================================================================
   2. Players Summary Strip (44px)
   ========================================================================== */
.players-bar {
  height: 44px;
  min-height: 44px;
  background: var(--bg-players);
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 0 16px;
  z-index: 90;
}

.player-chip {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 4px 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
  min-width: 185px;
  transition: all 0.25s ease;
}

.player-chip.active-turn {
  background: rgba(16, 185, 129, 0.18);
  border-color: #34d399;
  box-shadow: 0 0 14px rgba(16, 185, 129, 0.25);
}

.p-avatar {
  font-size: 18px;
  line-height: 1;
}

.p-info {
  display: flex;
  flex-direction: column;
  gap: 1px;
  flex: 1;
}

.p-name-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

.p-name {
  font-size: 12px;
  font-weight: 700;
  color: #f1f5f9;
}

.p-meld-tag {
  font-size: 10px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 999px;
}

.p-meld-tag.done {
  background: rgba(52, 211, 153, 0.2);
  color: #6ee7b7;
}

.p-meld-tag.wait {
  background: rgba(148, 163, 184, 0.16);
  color: #cbd5e1;
}

.p-meta-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  color: var(--text-muted);
}

.p-tiles-count b {
  color: var(--accent-gold);
}

.p-thought {
  color: #6ee7b7;
  font-size: 10.5px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 190px;
}

/* ==========================================================================
   3. Center 2D Magnetic Tile Grid Arena (74%+ Viewport Height)
   ========================================================================== */
.table-viewport {
  flex: 1;
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  overflow: auto;
  padding: 14px 20px 22px;
}

.table-floating-tools {
  position: absolute;
  top: 10px;
  right: 18px;
  display: flex;
  align-items: center;
  gap: 6px;
  z-index: 40;
}

.grid-tool-btn {
  background: rgba(15, 23, 42, 0.72);
  border: 1px solid rgba(255, 255, 255, 0.15);
  color: #e2e8f0;
  height: 30px;
  padding: 0 10px;
  border-radius: 7px;
  font-size: 11.5px;
  font-weight: 600;
  cursor: pointer;
  backdrop-filter: blur(8px);
  transition: all 0.15s ease;
}

.grid-tool-btn:hover {
  background: rgba(30, 41, 59, 0.92);
  border-color: var(--accent-primary);
  color: #fff;
}

.grid-board {
  --grid-cols: 10;
  --grid-scale: 1;
  --cell-w: 48px;
  --cell-h: 64px;
  --cell-gap: 4px;
  --row-gap: 10px;
  --tile-num-size: 23px;
  position: relative;
  display: flex;
  flex-direction: column;
  gap: var(--row-gap);
  padding: 16px 18px;
  border-radius: 18px;
  background: rgba(0, 0, 0, 0.20);
  border: 1px solid rgba(255, 255, 255, 0.10);
  box-shadow: inset 0 4px 24px rgba(0, 0, 0, 0.38), 0 8px 28px rgba(0, 0, 0, 0.25);
  margin: auto;
  transition: width 0.22s ease, height 0.22s ease;
}

.grid-empty-watermark {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  z-index: 0;
  text-align: center;
  padding: 16px;
}

.wm-sub {
  font-size: 13px;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.24);
  background: rgba(0, 0, 0, 0.22);
  padding: 6px 14px;
  border-radius: 999px;
  border: 1px dashed rgba(255, 255, 255, 0.12);
}

.grid-row {
  position: relative;
  display: grid;
  grid-template-columns: repeat(var(--grid-cols, 10), var(--cell-w));
  gap: var(--cell-gap);
  height: var(--cell-h);
  align-items: center;
  justify-content: center;
}

/* Boxless Contiguous Set Aura */
.grid-set-aura {
  position: absolute;
  top: -3px;
  bottom: -3px;
  left: calc(var(--start-col) * (var(--cell-w) + var(--cell-gap)) - 3px);
  width: calc(var(--span-cols) * var(--cell-w) + (var(--span-cols) - 1) * var(--cell-gap) + 6px);
  border-radius: 9px;
  pointer-events: none;
  transition: all 0.18s ease;
}

.grid-set-aura.aura-valid {
  background: rgba(16, 185, 129, 0.14);
  border: 1.5px solid rgba(52, 211, 153, 0.72);
  box-shadow: 0 2px 10px rgba(16, 185, 129, 0.18);
}

.grid-set-aura.aura-invalid {
  background: rgba(245, 158, 11, 0.16);
  border: 1.5px dashed rgba(251, 191, 36, 0.9);
  box-shadow: 0 2px 10px rgba(245, 158, 11, 0.2);
}

.aura-score-pill {
  position: absolute;
  top: -8px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 8.5px;
  font-weight: 800;
  line-height: 1;
  padding: 1.5px 6px;
  border-radius: 999px;
  letter-spacing: -0.2px;
  white-space: nowrap;
  pointer-events: auto;
  cursor: grab;
  -webkit-user-drag: element;
  z-index: 35;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.45);
  transition: transform 0.12s ease, filter 0.12s ease;
}

.aura-score-pill:hover {
  transform: translateX(-50%) scale(1.08);
  filter: brightness(1.18);
}

.aura-edge-cap {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 16px;
  height: 24px;
  border-radius: 6px;
  background: rgba(15, 23, 42, 0.88);
  border: 1px solid rgba(52, 211, 153, 0.7);
  color: #6ee7b7;
  font-size: 13px;
  font-weight: 900;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: auto;
  cursor: pointer;
  z-index: 35;
  opacity: 0.72;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.4);
  transition: all 0.14s ease;
}

.aura-edge-cap.cap-left {
  left: -6px;
}

.aura-edge-cap.cap-right {
  right: -6px;
}

.aura-edge-cap:hover,
.aura-edge-cap.cap-hover {
  opacity: 1;
  background: #10b981;
  color: #ffffff;
  border-color: #a7f3d0;
  transform: translateY(-50%) scale(1.15);
}

.aura-valid .aura-score-pill {
  background: #065f46;
  color: #a7f3d0;
  border: 1px solid #34d399;
}

.aura-invalid .aura-score-pill {
  background: #78350f;
  color: #fde68a;
  border: 1px solid #fbbf24;
}

@keyframes auraShake {
  0%, 100% { transform: translateX(0); }
  20%, 60% { transform: translateX(-6px); }
  40%, 80% { transform: translateX(6px); }
}

.aura-shake {
  animation: auraShake 0.36s ease-in-out;
  border-color: #ef4444 !important;
  background: rgba(239, 68, 68, 0.24) !important;
}

.grid-cell {
  width: var(--cell-w);
  height: var(--cell-h);
  border-radius: 7px;
  background: var(--grid-cell-bg);
  border: 1px dashed var(--grid-cell-border);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  z-index: 2;
  transition: background 0.12s ease, border-color 0.12s ease;
}

.grid-cell:hover {
  border-color: rgba(255, 255, 255, 0.26);
  background: rgba(255, 255, 255, 0.06);
}

.grid-cell.cell-drop-hover {
  background: var(--grid-cell-hover);
  border: 1.5px solid var(--accent-primary);
  transform: scale(1.04);
}

.grid-cell.has-tile {
  border-color: transparent;
  background: transparent;
}

/* Floating Selection Helper Bar */
.selection-helper-bar {
  position: absolute;
  bottom: 10px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  opacity: 0;
  pointer-events: none;
  background: rgba(15, 23, 42, 0.94);
  border: 1px solid rgba(52, 211, 153, 0.55);
  border-radius: 999px;
  padding: 6px 14px;
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 12.5px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.55);
  transition: all 0.2s ease;
  z-index: 60;
}

.selection-helper-bar.visible {
  opacity: 1;
  pointer-events: auto;
  transform: translateX(-50%) translateY(0);
}

.helper-btn {
  background: linear-gradient(135deg, #10b981 0%, #059669 100%);
  color: #fff;
  border: none;
  border-radius: 999px;
  padding: 4px 12px;
  font-size: 11.5px;
  font-weight: 700;
  cursor: pointer;
}

.helper-btn.secondary {
  background: rgba(255, 255, 255, 0.12);
  color: #cbd5e1;
}

/* ==========================================================================
   4. Realistic 3D Melamine/Ivory Rummikub Tile
   ========================================================================== */
.rummi-tile {
  width: calc(var(--cell-w, 43px) - 2px);
  height: calc(var(--cell-h, 59px) - 2px);
  background: linear-gradient(180deg, #fffdf9 0%, #f3efe6 88%, #e2dacb 100%);
  border-radius: 7px;
  border: 1px solid #d6cbb9;
  box-shadow:
    0 3px 0 #b8ad99,
    0 4px 8px rgba(0, 0, 0, 0.38),
    inset 0 1px 0 #ffffff;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  position: relative;
  cursor: grab;
  -webkit-user-drag: element;
  transition: transform 0.14s cubic-bezier(0.2, 0.8, 0.2, 1), box-shadow 0.14s ease;
}

.rummi-tile:hover {
  transform: translateY(-3px);
  box-shadow:
    0 5px 0 #b8ad99,
    0 7px 14px rgba(0, 0, 0, 0.45),
    inset 0 1px 0 #ffffff;
}

.rummi-tile.dragging {
  opacity: 0.45;
  cursor: grabbing;
}

.rummi-tile.tile-selected {
  transform: translateY(-9px) scale(1.04);
  border: 2px solid #f59e0b;
  box-shadow:
    0 6px 0 #d97706,
    0 0 16px rgba(245, 158, 11, 0.75);
  z-index: 15;
}

.rummi-tile.tile-played-this-turn {
  box-shadow:
    0 3px 0 #10b981,
    0 0 10px rgba(16, 185, 129, 0.45);
}

.turn-dot {
  position: absolute;
  top: 3px;
  right: 3px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #10b981;
  box-shadow: 0 0 4px #10b981;
}

.rummi-tile.tile-ai-recent {
  animation: aiTilePulse 1.6s ease-in-out 2;
  border-color: #a855f7;
}

@keyframes aiTilePulse {
  0%, 100% { box-shadow: 0 3px 0 #b8ad99, 0 0 0 rgba(168, 85, 247, 0); }
  50% { box-shadow: 0 3px 0 #9333ea, 0 0 16px rgba(168, 85, 247, 0.85); }
}

.rummi-tile.tile-hint-glow {
  border: 2px solid #38bdf8;
  box-shadow: 0 4px 0 #0284c7, 0 0 18px rgba(56, 189, 248, 0.9);
  animation: hintBounce 0.9s infinite alternate;
}

@keyframes hintBounce {
  from { transform: translateY(-2px); }
  to { transform: translateY(-8px); }
}

.tile-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  padding: 0;
}

.tile-number {
  font-size: var(--tile-num-size, 21px);
  font-weight: 900;
  line-height: 1;
  letter-spacing: -0.04em;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.85);
}

/* Official 4 Tile Colors */
.tile-red { color: #dc2626; }
.tile-blue { color: #2563eb; }
.tile-yellow { color: #d97706; }
.tile-black { color: #1e293b; }

.tile-joker .joker-face {
  font-size: var(--tile-num-size, 20px);
  line-height: 1;
}

.joker-swap-badge {
  position: absolute;
  top: -5px;
  right: -5px;
  width: 18px;
  height: 18px;
  background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
  color: #fff;
  border: 1.5px solid #fef3c7;
  border-radius: 50%;
  font-size: 9.5px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.45);
  z-index: 25;
}

.joker-swap-badge:hover {
  transform: scale(1.15);
}

/* ==========================================================================
   5. Bottom Ergonomic Control Dock (Left Pod | 2x24 Rack | Right Pod)
   ========================================================================== */
.control-dock {
  background: rgba(7, 16, 13, 0.95);
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  padding: 10px 16px 12px;
  display: flex;
  align-items: stretch;
  justify-content: center;
  gap: 12px;
  z-index: 100;
}

.dock-pod {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 6px;
  min-width: 148px;
}

.pod-btn {
  flex: 1;
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid rgba(255, 255, 255, 0.14);
  color: #f1f5f9;
  border-radius: 9px;
  padding: 0 12px;
  font-size: 12.5px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.pod-btn:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.15);
  border-color: rgba(255, 255, 255, 0.3);
  transform: translateY(-1px);
}

.pod-btn:disabled {
  opacity: 0.38;
  cursor: not-allowed;
}

.pod-btn-row {
  display: flex;
  gap: 6px;
  flex: 1;
}

.pod-btn.btn-smart-meld {
  background: linear-gradient(135deg, rgba(245, 158, 11, 0.24) 0%, rgba(217, 119, 6, 0.24) 100%);
  border-color: rgba(245, 158, 11, 0.55);
  color: #fde68a;
}

.pod-btn.btn-draw {
  background: linear-gradient(135deg, #2563eb 0%, #1d4ed8 100%);
  border-color: #60a5fa;
  color: #fff;
}

.pod-btn.btn-finish {
  background: linear-gradient(135deg, #10b981 0%, #059669 100%);
  border-color: #34d399;
  color: #fff;
  font-size: 13.5px;
}

.pod-btn.btn-finish.ready-pulse {
  box-shadow: 0 0 18px rgba(16, 185, 129, 0.65);
  animation: finishPulse 1.1s infinite alternate;
}

@keyframes finishPulse {
  from { filter: brightness(1); }
  to { filter: brightness(1.18); }
}

/* Center 2-Tier 48-Slot Wooden/Obsidian Rack */
.rack-wrapper {
  background: var(--rack-bg);
  border: 2px solid var(--rack-border);
  border-radius: 14px;
  padding: 8px 12px;
  box-shadow:
    inset 0 3px 10px rgba(0, 0, 0, 0.55),
    0 6px 18px rgba(0, 0, 0, 0.45);
  display: flex;
  flex-direction: column;
  gap: 6px;
  position: relative;
}

.rack-header-mini {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 11px;
  color: rgba(255, 255, 255, 0.65);
  padding: 0 2px;
}

.rack-header-mini b {
  color: var(--accent-gold);
}

.rack-tier {
  display: grid;
  grid-template-columns: repeat(var(--rack-cols, 13), var(--cell-w, 41px));
  gap: var(--cell-gap, 3px);
  height: var(--cell-h, 56px);
  align-items: center;
  justify-content: center;
}

.rack-slot {
  width: var(--cell-w);
  height: var(--cell-h);
  border-radius: 6px;
  background: var(--rack-slot-bg);
  border: 1px solid var(--rack-slot-border);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.12s ease, border-color 0.12s ease;
}

.rack-slot.slot-drop-hover {
  background: rgba(245, 158, 11, 0.25);
  border-color: var(--accent-gold);
}

.rack-slot.occupied {
  background: transparent;
  border-color: transparent;
}

/* ==========================================================================
   6. Modals & Toasts
   ========================================================================== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.72);
  backdrop-filter: blur(6px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 2000;
  padding: 20px;
}

.modal-overlay.open {
  display: flex;
}

.modal-card {
  background: #0f172a;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 16px;
  width: 100%;
  max-width: 640px;
  max-height: 86vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.65);
}

.modal-header {
  padding: 16px 20px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-header h3 {
  font-size: 16px;
  font-weight: 800;
}

.modal-close-btn {
  background: transparent;
  border: none;
  color: #94a3b8;
  font-size: 20px;
  cursor: pointer;
}

.modal-body {
  padding: 18px 20px;
  overflow-y: auto;
  font-size: 13.5px;
  line-height: 1.65;
  color: #cbd5e1;
}

.modal-footer {
  padding: 12px 20px;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

/* Deck Counter Analyzer */
.analyzer-legend {
  display: flex;
  gap: 16px;
  margin-bottom: 14px;
  font-size: 12px;
}

.leg-dot, .ac-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.leg-dot.board, .ac-dot.board { background: #10b981; }
.leg-dot.hand, .ac-dot.hand { background: #f59e0b; }
.leg-dot.hidden, .ac-dot.hidden { background: #475569; }

.analyzer-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}

.analyzer-color-label {
  width: 48px;
  font-weight: 800;
  font-size: 12.5px;
}

.analyzer-cells {
  display: grid;
  grid-template-columns: repeat(13, 1fr);
  gap: 5px;
  flex: 1;
}

.analyzer-cell {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 6px;
  padding: 4px 2px;
  text-align: center;
}

.analyzer-cell.all-seen {
  opacity: 0.42;
}

.ac-num {
  font-weight: 800;
  font-size: 12px;
  margin-bottom: 3px;
}

.ac-dots {
  display: flex;
  justify-content: center;
  gap: 3px;
}

/* Settings Form */
.setting-group {
  margin-bottom: 14px;
}

.setting-group label {
  display: block;
  font-weight: 700;
  margin-bottom: 6px;
  color: #f1f5f9;
}

.setting-select {
  width: 100%;
  height: 38px;
  background: #1e293b;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 8px;
  color: #fff;
  padding: 0 12px;
  font-size: 13.5px;
}

/* Victory Modal */
.victory-winner-banner {
  text-align: center;
  padding: 16px;
  background: rgba(16, 185, 129, 0.14);
  border: 1px solid rgba(52, 211, 153, 0.4);
  border-radius: 12px;
  margin-bottom: 14px;
}

.vw-avatar { font-size: 40px; }
.vw-title { font-size: 19px; font-weight: 900; color: #fff; margin-top: 4px; }
.vw-points { font-size: 15px; font-weight: 800; color: #34d399; margin-top: 2px; }

.victory-score-row {
  display: flex;
  justify-content: space-between;
  padding: 8px 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.score-neg { color: #f87171; }

/* Toast Notifications */
.toast-container {
  position: fixed;
  top: 60px;
  right: 18px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 3000;
  pointer-events: none;
}

.rummi-toast {
  background: rgba(15, 23, 42, 0.94);
  border-left: 4px solid #38bdf8;
  color: #f8fafc;
  padding: 10px 15px;
  border-radius: 8px;
  font-size: 12.5px;
  font-weight: 600;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.45);
  transition: all 0.28s ease;
  max-width: 420px;
}

.rummi-toast.toast-success { border-left-color: #10b981; }
.rummi-toast.toast-warning { border-left-color: #f59e0b; }
.rummi-toast.toast-out {
  opacity: 0;
  transform: translateX(30px);
}


/* ==========================================================================
   7. Real-Time Multiplayer, Invite Banner, Mobile Touch & Responsive Layout
   ========================================================================== */
.hud-btn.btn-mp-highlight {
  background: linear-gradient(135deg, rgba(16, 185, 129, 0.25) 0%, rgba(59, 130, 246, 0.28) 100%);
  border-color: rgba(52, 211, 153, 0.65);
  color: #fff;
  font-weight: 800;
  gap: 6px;
}

.hud-btn.btn-mp-highlight:hover {
  background: linear-gradient(135deg, rgba(16, 185, 129, 0.4) 0%, rgba(59, 130, 246, 0.42) 100%);
  border-color: #34d399;
}

.mp-online-badge {
  font-style: normal;
  font-size: 10.5px;
  font-weight: 800;
  background: rgba(16, 185, 129, 0.3);
  border: 1px solid rgba(52, 211, 153, 0.6);
  color: #6ee7b7;
  padding: 1px 7px;
  border-radius: 999px;
}

/* Floating Real-Time Invite Notification Banner */
.mp-invite-banner {
  position: fixed;
  top: 12px;
  left: 50%;
  transform: translate(-50%, -140%);
  background: linear-gradient(135deg, #065f46 0%, #1e3a8a 100%);
  border: 1.5px solid #34d399;
  border-radius: 999px;
  padding: 8px 18px;
  display: flex;
  align-items: center;
  gap: 14px;
  z-index: 4000;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.65);
  transition: transform 0.35s cubic-bezier(0.22, 1, 0.36, 1);
}

.mp-invite-banner.visible {
  transform: translate(-50%, 0);
}

.mp-invite-banner-text {
  font-size: 13px;
  color: #f8fafc;
}

.mp-invite-banner-actions {
  display: flex;
  gap: 6px;
}

/* Floating Quick Emoji / Chat Bar */
.mp-chat-floating {
  position: absolute;
  bottom: 12px;
  right: 16px;
  background: rgba(15, 23, 42, 0.88);
  backdrop-filter: blur(8px);
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 999px;
  padding: 5px 12px;
  display: flex;
  align-items: center;
  gap: 6px;
  z-index: 95;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.45);
}

.mp-chat-label {
  font-size: 11px;
  font-weight: 700;
  color: #94a3b8;
  margin-right: 2px;
}

.mp-quick-emoji {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.15);
  color: #f1f5f9;
  border-radius: 999px;
  padding: 4px 9px;
  font-size: 11.5px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.15s ease;
}

.mp-quick-emoji:hover {
  background: rgba(52, 211, 153, 0.22);
  border-color: #34d399;
  transform: translateY(-1px);
}

/* Multiplayer Modal UI */
.mp-profile-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 10px;
  padding: 10px 14px;
  margin-bottom: 14px;
}

.mp-profile-bar label {
  font-weight: 800;
  font-size: 13px;
  color: #e2e8f0;
  white-space: nowrap;
}

.mp-input {
  flex: 1;
  height: 36px;
  background: #1e293b;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 8px;
  color: #fff;
  padding: 0 12px;
  font-size: 13.5px;
  font-weight: 700;
}

.mp-hero-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 14px;
}

.mp-action-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  border-radius: 12px;
  border: 1.5px solid rgba(255, 255, 255, 0.16);
  background: rgba(255, 255, 255, 0.05);
  color: #f8fafc;
  text-align: left;
  cursor: pointer;
  transition: all 0.18s ease;
}

.mp-action-card.primary {
  background: linear-gradient(135deg, rgba(16, 185, 129, 0.22) 0%, rgba(5, 150, 105, 0.28) 100%);
  border-color: rgba(52, 211, 153, 0.55);
}

.mp-action-card.accent {
  background: linear-gradient(135deg, rgba(37, 99, 235, 0.22) 0%, rgba(124, 58, 237, 0.28) 100%);
  border-color: rgba(96, 165, 250, 0.55);
}

.mp-action-card:hover {
  transform: translateY(-2px);
  filter: brightness(1.12);
}

.mac-icon {
  font-size: 28px;
}

.mac-text {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.mac-text strong {
  font-size: 14.5px;
  font-weight: 800;
}

.mac-text span {
  font-size: 11.5px;
  color: #cbd5e1;
}

.mp-code-join-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 10px;
  padding: 10px 14px;
  margin-bottom: 16px;
}

.mp-code-label {
  font-weight: 800;
  font-size: 13px;
  color: #fbbf24;
  white-space: nowrap;
}

.mp-input.code-input {
  letter-spacing: 2px;
  text-align: center;
  font-size: 15px;
}

.mp-section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 13px;
  font-weight: 800;
  color: #f1f5f9;
  margin-bottom: 8px;
}

.mp-section-title small {
  font-weight: 500;
  font-size: 11.5px;
  color: #94a3b8;
}

.mp-public-rooms-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 180px;
  overflow-y: auto;
}

.mp-empty-rooms {
  background: rgba(255, 255, 255, 0.03);
  border: 1px dashed rgba(255, 255, 255, 0.16);
  border-radius: 10px;
  padding: 16px;
  text-align: center;
  font-size: 12.5px;
  color: #94a3b8;
}

.mp-room-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 10px;
  padding: 10px 14px;
}

.mri-info {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.mri-code {
  background: rgba(245, 158, 11, 0.2);
  border: 1px solid rgba(245, 158, 11, 0.5);
  color: #fbbf24;
  font-weight: 900;
  font-size: 12.5px;
  padding: 2px 8px;
  border-radius: 6px;
}

.mri-counts {
  font-size: 12px;
  color: #cbd5e1;
}

.mri-state {
  font-size: 11px;
  font-weight: 800;
  padding: 2px 7px;
  border-radius: 999px;
}

.mri-state.waiting {
  background: rgba(16, 185, 129, 0.2);
  color: #34d399;
}

.mri-state.playing {
  background: rgba(59, 130, 246, 0.22);
  color: #60a5fa;
}

/* Active Room View */
.mp-room-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  background: linear-gradient(135deg, rgba(16, 185, 129, 0.16) 0%, rgba(30, 58, 138, 0.28) 100%);
  border: 1px solid rgba(52, 211, 153, 0.45);
  border-radius: 12px;
  padding: 12px 16px;
  margin-bottom: 10px;
}

.mrb-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.mrb-label {
  font-size: 12px;
  color: #cbd5e1;
  font-weight: 700;
}

.mrb-code {
  font-size: 24px;
  font-weight: 900;
  color: #fbbf24;
  letter-spacing: 2px;
}

.mrb-right {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.mp-invite-link-row {
  margin-bottom: 10px;
}

.mp-qr-container {
  display: flex;
  align-items: center;
  gap: 16px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 12px;
  padding: 12px 16px;
  margin-bottom: 12px;
}

.mp-qr-container img {
  background: #fff;
  padding: 6px;
  border-radius: 8px;
}

.mp-qr-desc strong {
  display: block;
  color: #34d399;
  font-size: 13.5px;
  margin-bottom: 4px;
}

.mp-qr-desc p {
  font-size: 12px;
  color: #cbd5e1;
  line-height: 1.5;
}

.mp-bot-controls {
  display: flex;
  gap: 6px;
}

.mp-seats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.mp-seat-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.12);
}

.mp-seat-card.seat-human {
  background: rgba(16, 185, 129, 0.14);
  border-color: rgba(52, 211, 153, 0.45);
}

.mp-seat-card.seat-bot {
  background: rgba(59, 130, 246, 0.12);
  border-color: rgba(96, 165, 250, 0.35);
}

.mp-seat-card.empty {
  border-style: dashed;
  opacity: 0.7;
}

.seat-avatar {
  font-size: 26px;
}

.seat-name {
  font-weight: 800;
  font-size: 13.5px;
  color: #fff;
}

.seat-tag {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  margin-top: 2px;
}

.seat-tag.human { color: #34d399; }
.seat-tag.bot { color: #60a5fa; }
.seat-tag.wait { color: #94a3b8; }

/* Mobile Touch Floating Drag Ghost */
.touch-drag-ghost {
  position: fixed;
  z-index: 9999;
  pointer-events: none;
  transform: translate(-50%, -85%);
  display: flex;
  align-items: center;
  filter: drop-shadow(0 12px 20px rgba(0, 0, 0, 0.65));
}

.touch-drag-count {
  position: absolute;
  top: -10px;
  right: -10px;
  background: #f59e0b;
  color: #fff;
  font-weight: 900;
  font-size: 11px;
  padding: 2px 6px;
  border-radius: 999px;
}

/* Mobile & Tablet Responsive Optimizations */
@media (max-width: 1100px) {
  .app-shell {
    height: 100dvh;
    max-height: 100dvh;
  }
  .top-hud {
    height: auto;
    min-height: 44px;
    flex-wrap: nowrap;
    overflow-x: auto;
    padding: 4px 10px;
    gap: 8px;
    -webkit-overflow-scrolling: touch;
  }
  .brand-sub {
    display: none;
  }
  .hud-btn span {
    display: none;
  }
  .hud-btn.btn-mp-highlight span,
  .hud-btn.btn-primary-sm span {
    display: inline;
  }
  .players-bar {
    height: auto;
    min-height: 38px;
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    padding: 4px 10px;
    gap: 6px;
  }
  .player-chip {
    min-width: 0;
    padding: 4px 8px;
    border-radius: 10px;
    gap: 6px;
  }
  .control-dock {
    flex-wrap: wrap;
    padding: 6px 8px;
    gap: 6px;
  }
  .rack-wrapper {
    order: -1;
    width: 100%;
    align-items: center;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  .dock-pod {
    flex: 1;
    flex-direction: row;
    min-width: unset;
  }
  .mp-hero-actions,
  .mp-seats-grid {
    grid-template-columns: 1fr;
  }
}

/* Smartphone Portrait & Landscape Deep Ergonomics */
@media (max-width: 768px) {
  .top-hud {
    padding: 3px 6px;
    min-height: 40px;
    gap: 4px;
  }
  .brand-area {
    gap: 5px;
    flex-shrink: 0;
  }
  .brand-logo {
    display: none;
  }
  .brand-title {
    font-size: 13px;
    white-space: nowrap;
  }
  .hud-center-stats {
    gap: 4px;
    flex-shrink: 0;
  }
  .pool-badge {
    padding: 2px 6px;
    font-size: 11px;
    gap: 3px;
    white-space: nowrap;
  }
  .pool-badge span {
    display: none;
  }
  .pool-badge::before {
    content: '🀄';
    font-size: 11px;
  }
  .meld-badge {
    padding: 2px 7px;
    font-size: 10.5px;
    white-space: nowrap;
  }
  .timer-widget {
    padding: 2px 4px;
    gap: 0;
  }
  .timer-ring-wrap,
  .timer-svg {
    width: 26px;
    height: 26px;
  }
  #timer-seconds {
    font-size: 10px;
  }
  .timer-label {
    display: none;
  }
  .hud-right-tools {
    gap: 3px;
    flex-shrink: 0;
  }
  .hud-btn {
    height: 27px;
    padding: 0 6px;
    font-size: 11px;
    border-radius: 6px;
    white-space: nowrap;
  }
  .hud-btn.btn-mp-highlight span {
    display: none;
  }
  .mp-online-badge {
    font-size: 9.5px;
    padding: 1px 4px;
  }
  .players-bar {
    padding: 3px 6px;
    min-height: 34px;
    gap: 4px;
  }
  .player-chip {
    padding: 3px 6px;
    gap: 4px;
    border-radius: 8px;
  }
  .p-avatar {
    font-size: 14px;
  }
  .p-info {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    gap: 3px;
    min-width: 0;
  }
  .p-name-row {
    min-width: 0;
  }
  .p-name {
    font-size: 11px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .p-meld-tag,
  .p-thought {
    display: none !important;
  }
  .p-meta-row {
    font-size: 10.5px;
    flex-shrink: 0;
  }
  .table-viewport {
    padding: 36px 6px 8px;
  }
  .table-floating-tools {
    top: 4px;
    right: 6px;
    gap: 4px;
  }
  .grid-tool-btn {
    height: 25px;
    padding: 0 7px;
    font-size: 10.5px;
  }
  .grid-board {
    padding: 10px 10px;
    border-radius: 14px;
  }
  .wm-sub {
    font-size: 11px;
    padding: 5px 10px;
  }
  .control-dock {
    padding: 4px 6px 6px;
    gap: 4px;
    flex-direction: column;
  }
  .rack-wrapper {
    padding: 4px 6px 6px;
    gap: 3px;
    border-radius: 10px;
  }
  .rack-header-mini {
    width: 100%;
    font-size: 10px;
  }
  .rack-header-mini span:first-child {
    max-width: 72%;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .dock-pod {
    width: 100%;
    display: flex;
    flex-direction: row;
    gap: 4px;
  }
  .pod-btn-row {
    display: contents;
  }
  .pod-btn {
    height: 32px;
    padding: 0 5px;
    font-size: 11px;
    border-radius: 7px;
    white-space: nowrap;
    gap: 3px;
  }
  .pod-btn.btn-finish {
    font-size: 11.5px;
  }
  .selection-helper-bar {
    bottom: 6px;
    padding: 5px 10px;
    font-size: 11px;
    max-width: 95vw;
    white-space: nowrap;
  }
}
