:root {
  --blue-deep: #06152d;
  --blue-mid: #0e3068;
  --blue-glow: #1d57a8;
  --blue-panel: rgba(10, 32, 70, 0.85);
  --blue-border: rgba(120, 175, 255, 0.25);

  --wood-top: #e2b578;
  --wood-mid: #c99352;
  --wood-dark: #9c6b31;
  --wood-ledge: #ecd6b0;

  --tile-cream: #fcf9f2;
  --tile-bottom: #e5dec9;
  --tile-red: #d92323;
  --tile-blue: #1462d4;
  --tile-orange: #e67e00;
  --tile-black: #1b2028;

  --accent-green: #38b000;
  --accent-green-bright: #70e000;
  --accent-gold: #f59e0b;
  --accent-danger: #ef4444;

  --text-main: #f8fafc;
  --text-muted: #93b4e0;

  /* Proportional PC sizing (24" monitor: tiles ~10.6% of viewport height, matching rummikub-apps.com) */
  --tile-h: clamp(74px, min(5.3vw, 10.6dvh), 112px);
  --tile-w: calc(var(--tile-h) * 0.725);
  --tile-font: calc(var(--tile-h) * 0.38);
}

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

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: radial-gradient(circle at 50% 42%, var(--blue-glow) 0%, var(--blue-mid) 55%, var(--blue-deep) 100%);
  color: var(--text-main);
  font-family: 'Segoe UI', system-ui, -apple-system, Roboto, sans-serif;
  overscroll-behavior: none;
  user-select: none;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
}

.hidden {
  display: none !important;
}

/* ==================== TOP BAR ==================== */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 14px;
  background: linear-gradient(180deg, rgba(5, 18, 42, 0.92), rgba(8, 28, 62, 0.75));
  border-bottom: 1px solid var(--blue-border);
  flex-shrink: 0;
  z-index: 25;
}

.profile-chip {
  display: flex;
  align-items: center;
  gap: 7px;
  background: rgba(0, 0, 0, 0.42);
  border: 1.5px solid rgba(251, 191, 36, 0.55);
  border-radius: 999px;
  padding: 3px 12px 3px 4px;
}

.profile-role-tag {
  font-size: 12px;
  font-weight: 800;
  color: #fde68a;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

.profile-edit-Hint {
  font-size: 13px;
  color: #93c5fd;
  pointer-events: none;
}

.host-menu-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 22px;
  width: 100%;
  max-width: 780px;
}

.host-name-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(6, 21, 48, 0.88);
  border: 1.5px solid rgba(251, 191, 36, 0.6);
  border-radius: 999px;
  padding: 7px 18px;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.45);
}

.host-crown {
  font-size: 20px;
}

.host-name-label {
  font-size: 14px;
  font-weight: 800;
  color: #fde68a;
  white-space: nowrap;
}

.host-name-field {
  width: 165px !important;
  background: rgba(255, 255, 255, 0.1) !important;
  border: 1px solid rgba(147, 197, 253, 0.45) !important;
  border-radius: 999px !important;
  padding: 5px 12px !important;
  font-size: 15px !important;
  font-weight: 800 !important;
  color: #fff !important;
  text-align: center;
}

.self-avatar-sm {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: radial-gradient(circle, #3b82f6, #1d4ed8);
  border: 2px solid #93c5fd;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
}

.profile-name-input {
  background: transparent;
  border: none;
  color: #fff;
  font-weight: 700;
  font-size: 13.5px;
  width: 105px;
  outline: none;
}

.profile-name-input:focus {
  border-bottom: 1px solid #60a5fa;
}

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

.brand-title {
  font-weight: 900;
  font-size: 20px;
  letter-spacing: 0.6px;
  color: #ff3b30;
  text-shadow: 0 2px 0 #5c0b07, 0 4px 10px rgba(0, 0, 0, 0.5);
}

.mode-badge {
  font-size: 11px;
  font-weight: 800;
  padding: 2px 8px;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.25);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.hud-icon-btn {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 1px solid var(--blue-border);
  background: linear-gradient(180deg, #1e4b8f, #0f2c5c);
  color: #fff;
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.4);
  transition: transform 0.1s, filter 0.15s;
}

.hud-icon-btn:hover {
  filter: brightness(1.18);
}

.hud-icon-btn:active {
  transform: scale(0.93);
}

.hud-pause-btn {
  border-color: rgba(251, 191, 36, 0.55);
  color: #fde68a;
}

.hud-pause-btn.is-paused {
  background: linear-gradient(180deg, #f59e0b, #d97706);
  border-color: #fef3c7;
  color: #1e1200;
  box-shadow: 0 0 16px rgba(245, 158, 11, 0.65);
}

.pause-overlay {
  position: absolute;
  inset: 0;
  z-index: 40;
  background: rgba(4, 15, 36, 0.95);
  backdrop-filter: blur(18px);
  display: flex;
  align-items: center;
  justify-content: center;
}

.board-arena.is-paused .wooden-rack-frame .tile,
.board-arena.is-paused .table-sets-grid .tile {
  visibility: hidden;
}

.pause-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 28px 42px;
  border-radius: 24px;
  background: linear-gradient(180deg, rgba(16, 48, 102, 0.96), rgba(7, 22, 52, 0.98));
  border: 2px solid rgba(251, 191, 36, 0.65);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.72), 0 0 32px rgba(245, 158, 11, 0.2);
  text-align: center;
}

.pause-glyph {
  font-size: 46px;
  line-height: 1;
  color: #fbbf24;
  text-shadow: 0 4px 14px rgba(245, 158, 11, 0.45);
}

.pause-title {
  font-size: 26px;
  font-weight: 900;
  letter-spacing: 2px;
  color: #fff;
}

.pause-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  font-weight: 700;
  color: #fde68a;
  margin-bottom: 6px;
}

.btn-resume-pill {
  min-width: 190px;
  height: 48px;
  border-radius: 999px;
  border: 2px solid #a3e635;
  background: linear-gradient(180deg, #65a30d, #3f6212);
  color: #fff;
  font-size: 18px;
  font-weight: 900;
  letter-spacing: 1px;
  cursor: pointer;
  box-shadow: 0 8px 22px rgba(101, 163, 13, 0.45);
  transition: filter 0.15s, transform 0.1s;
}

.btn-resume-pill:hover {
  filter: brightness(1.16);
}

.btn-resume-pill:active {
  transform: scale(0.95);
}

/* ==================== MAIN MENU: 2 MODE CARDS ==================== */
.screen-center {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  overflow-y: auto;
}

.mode-cards-stage {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 28px;
  flex-wrap: wrap;
}

.mode-card {
  width: 210px;
  height: 270px;
  border-radius: 22px;
  background: linear-gradient(180deg, rgba(20, 58, 118, 0.92) 0%, rgba(8, 25, 56, 0.96) 100%);
  border: 2.5px solid rgba(110, 231, 183, 0.55);
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.55), inset 0 1px 0 rgba(255, 255, 255, 0.25);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  padding: 26px 18px 22px;
  cursor: pointer;
  transition: transform 0.18s cubic-bezier(0.2, 0.8, 0.2, 1), box-shadow 0.18s;
  color: #fff;
}

.mode-card:hover {
  transform: translateY(-8px) scale(1.03);
}

.mode-card.card-training {
  border-color: #2dd4bf;
  box-shadow: 0 16px 36px rgba(13, 148, 136, 0.35), inset 0 0 24px rgba(45, 212, 191, 0.18);
}

.mode-card.card-private {
  border-color: #f59e0b;
  box-shadow: 0 16px 36px rgba(217, 119, 6, 0.35), inset 0 0 24px rgba(245, 158, 11, 0.18);
}

.mode-card-art {
  position: relative;
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

.cap-badge {
  position: absolute;
  top: -12px;
  left: -14px;
  font-size: 38px;
  transform: rotate(-14deg);
  filter: drop-shadow(0 4px 6px rgba(0, 0, 0, 0.45));
  z-index: 2;
}

.art-tile {
  width: 72px;
  height: 98px;
  border-radius: 12px;
  background: linear-gradient(180deg, #fffdf7, #e7dec8);
  box-shadow: 0 6px 0 #b3a78e, 0 12px 24px rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 44px;
  font-weight: 900;
  color: var(--tile-blue);
}

.art-pair {
  display: flex;
  gap: 8px;
}

.art-pair .art-tile {
  width: 60px;
  height: 84px;
  font-size: 30px;
}

.sil-blue { transform: rotate(-6deg); }
.sil-gold { transform: rotate(6deg); }

.mode-card-title {
  font-size: 20px;
  font-weight: 800;
  letter-spacing: 0.3px;
  text-shadow: 0 2px 6px rgba(0, 0, 0, 0.6);
}

/* ==================== TRAINING & PRIVATE SETUP STAGES ==================== */
.setup-stage {
  width: 100%;
  max-width: 780px;
  background: linear-gradient(180deg, rgba(12, 39, 84, 0.92), rgba(6, 21, 48, 0.96));
  border: 1.5px solid var(--blue-border);
  border-radius: 24px;
  padding: 28px 24px 0;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.6);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  overflow: hidden;
}

.dials-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 18px;
  text-align: center;
  padding: 18px 0 32px;
}

.dial-col {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.dial-value {
  font-size: 56px;
  font-weight: 300;
  letter-spacing: 1px;
  line-height: 1.05;
  color: #fff;
  text-shadow: 0 4px 14px rgba(0, 0, 0, 0.5);
}

.dial-value small {
  font-size: 32px;
  color: #93c5fd;
  margin-left: 2px;
}

.dial-label {
  font-size: 14px;
  font-weight: 600;
  color: #bfdbfe;
  margin: 8px 0 14px;
}

.dial-stepper {
  display: inline-flex;
  border-radius: 12px;
  overflow: hidden;
  border: 1.5px solid rgba(147, 197, 253, 0.45);
  background: rgba(10, 32, 72, 0.9);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}

.step-btn {
  width: 54px;
  height: 42px;
  border: none;
  background: linear-gradient(180deg, #1d4ed8, #1e3a8a);
  color: #fff;
  font-size: 24px;
  font-weight: 700;
  cursor: pointer;
  transition: filter 0.15s;
}

.step-btn:first-child {
  border-right: 1px solid rgba(147, 197, 253, 0.3);
}

.step-btn:hover {
  filter: brightness(1.2);
}

.step-btn:active {
  filter: brightness(0.9);
}

.setup-bottom-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(3, 12, 28, 0.78);
  margin: 0 -24px;
  padding: 12px 24px;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.btn-back-arc {
  width: 54px;
  height: 44px;
  border-radius: 12px;
  border: 1px solid var(--blue-border);
  background: linear-gradient(180deg, #2563eb, #1d4ed8);
  color: #fff;
  font-size: 28px;
  line-height: 1;
  cursor: pointer;
}

.btn-play-arc {
  min-width: 240px;
  height: 50px;
  border-radius: 26px 26px 10px 10px;
  border: 2px solid #a3e635;
  background: linear-gradient(180deg, #65a30d 0%, #3f6212 100%);
  color: #fff;
  font-size: 22px;
  font-weight: 900;
  letter-spacing: 1px;
  cursor: pointer;
  box-shadow: 0 6px 20px rgba(101, 163, 13, 0.5), inset 0 2px 0 rgba(255, 255, 255, 0.35);
  transition: filter 0.15s, transform 0.1s;
}

.btn-play-arc:hover:not(:disabled) {
  filter: brightness(1.15);
}

.btn-play-arc:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.setup-mode-tag {
  font-size: 16px;
  font-weight: 700;
  color: #dbeafe;
}

/* Private Game Compact Stage */
.private-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin-bottom: 18px;
}

.glass-panel {
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid var(--blue-border);
  border-radius: 14px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.mini-dial-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.mini-label {
  font-size: 13px;
  font-weight: 700;
  color: #bfdbfe;
}

.segmented {
  display: flex;
  background: rgba(0, 0, 0, 0.4);
  padding: 3px;
  border-radius: 9px;
  border: 1px solid var(--blue-border);
  gap: 3px;
}

.seg-btn {
  border: none;
  background: transparent;
  color: var(--text-muted);
  padding: 5px 10px;
  font-size: 12px;
  font-weight: 800;
  border-radius: 6px;
  cursor: pointer;
}

.seg-btn.active {
  background: #2563eb;
  color: #fff;
}

.btn-mini-action {
  border: 1px solid rgba(147, 197, 253, 0.4);
  background: linear-gradient(180deg, #2563eb, #1d4ed8);
  color: #fff;
  border-radius: 8px;
  padding: 6px 11px;
  font-size: 12.5px;
  font-weight: 800;
  cursor: pointer;
  white-space: nowrap;
}

.sub-block {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.sub-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12.5px;
  font-weight: 800;
  color: #93c5fd;
  text-transform: uppercase;
}

.badge-dot {
  background: var(--accent-gold);
  color: #1e1200;
  font-size: 11px;
  font-weight: 900;
  padding: 1px 7px;
  border-radius: 999px;
}

.compact-list {
  display: flex;
  flex-direction: column;
  gap: 5px;
  max-height: 115px;
  overflow-y: auto;
}

.compact-list.empty-hint {
  color: var(--text-muted);
  font-size: 12px;
}

.list-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  padding: 5px 8px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.06);
  font-size: 12.5px;
}

.list-row.revoked {
  opacity: 0.45;
}

.row-actions {
  display: flex;
  gap: 4px;
}

.compact-input,
input[type="text"],
input[type="password"],
select {
  width: 100%;
  padding: 7px 10px;
  border-radius: 8px;
  border: 1px solid var(--blue-border);
  background: rgba(0, 0, 0, 0.35);
  color: #fff;
  font-size: 13px;
  outline: none;
}

.inline-row {
  display: flex;
  gap: 6px;
}

.btn-stop-mini {
  border: 1px solid rgba(239, 68, 68, 0.5);
  background: rgba(239, 68, 68, 0.25);
  color: #fecaca;
  border-radius: 8px;
  padding: 6px 10px;
  cursor: pointer;
}

/* Auth & Guest Box */
.glass-card {
  background: var(--blue-panel);
  border: 1.5px solid var(--blue-border);
  border-radius: 20px;
  padding: 24px;
  text-align: center;
  width: 100%;
  max-width: 360px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.55);
}

.card-glyph {
  font-size: 36px;
  margin-bottom: 6px;
}

.glass-card h2 {
  margin: 0 0 14px;
  font-size: 18px;
  letter-spacing: 0.8px;
}

.stack-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.btn-play-green {
  border: 1.5px solid #a3e635;
  background: linear-gradient(180deg, #65a30d, #3f6212);
  color: #fff;
  border-radius: 10px;
  padding: 10px 16px;
  font-weight: 800;
  font-size: 14px;
  cursor: pointer;
}

.btn-glass {
  border: 1px solid var(--blue-border);
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
  border-radius: 10px;
  padding: 8px 14px;
  font-weight: 700;
  cursor: pointer;
}

/* ==================== GAME BOARD ARENA (RUMMIKUB-APPS LAYOUT) ==================== */
.board-arena {
  flex: 1;
  display: grid;
  grid-template-columns: 128px 1fr 116px;
  min-height: 0;
  overflow: hidden;
  position: relative;
}

/* Left Rail: Circular Player Avatars + Tile Counters + Active Timer Ring */
.players-rail {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  padding: 16px 8px 22px;
  z-index: 10;
}

.avatar-node {
  display: flex;
  flex-direction: column;
  align-items: center;
  position: relative;
}

.avatar-ring-wrap {
  position: relative;
  width: 82px;
  height: 82px;
  border-radius: 50%;
  padding: 5px;
  background: rgba(0, 0, 0, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
}

.avatar-ring-wrap.active-turn {
  background: conic-gradient(var(--ring-color, #4ade80) var(--ring-pct, 100%), rgba(255, 255, 255, 0.12) 0);
  box-shadow: 0 0 22px rgba(74, 222, 128, 0.6);
}

.avatar-face {
  position: relative;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #2563eb, #0f172a);
  border: 2.5px solid rgba(255, 255, 255, 0.38);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 34px;
  overflow: hidden;
}

.avatar-timer-overlay {
  position: absolute;
  inset: 0;
  background: rgba(4, 12, 28, 0.62);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  font-weight: 800;
  color: #fff;
  text-shadow: 0 2px 6px rgba(0, 0, 0, 0.8);
}

.avatar-meld-star {
  position: absolute;
  top: -2px;
  right: -4px;
  background: linear-gradient(135deg, #fbbf24, #d97706);
  color: #1e1200;
  font-size: 11px;
  font-weight: 900;
  padding: 2px 6px;
  border-radius: 999px;
  border: 1.5px solid #fff;
  z-index: 3;
}

.avatar-label-pill {
  margin-top: -7px;
  background: rgba(5, 16, 36, 0.94);
  border: 1px solid rgba(147, 197, 253, 0.4);
  border-radius: 9px;
  padding: 3px 9px;
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  max-width: 116px;
  z-index: 2;
}

.avatar-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: #cbd5e1;
  font-weight: 600;
}

.avatar-count {
  font-weight: 900;
  color: #fff;
}

/* Center Stage: Felt Table + 2-Row Wooden Rack */
.center-stage {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  padding: 6px 4px 10px;
}

.table-top-strip {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 24px;
  flex-shrink: 0;
}

.turn-pill {
  font-size: 12px;
  font-weight: 700;
  color: #bfdbfe;
  letter-spacing: 0.3px;
}

.meld-pill {
  font-size: 12px;
  font-weight: 800;
  padding: 2px 9px;
  border-radius: 999px;
  background: rgba(245, 158, 11, 0.25);
  border: 1px solid rgba(245, 158, 11, 0.55);
  color: #fde68a;
}

.meld-pill.ready {
  background: rgba(56, 176, 0, 0.3);
  border-color: #70e000;
  color: #d9f99d;
}

.table-felt {
  flex: 1;
  position: relative;
  overflow: hidden;
  padding: 0;
}

.table-watermark {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 56px;
  font-weight: 900;
  color: rgba(255, 255, 255, 0.04);
  pointer-events: none;
  letter-spacing: 2px;
}

.table-sets-grid {
  position: relative;
  width: 100%;
  height: 100%;
  z-index: 1;
}

.table-set {
  position: absolute;
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 4px 6px;
  border-radius: 11px;
  background: rgba(4, 15, 35, 0.28);
  border: 1.5px solid rgba(147, 197, 253, 0.18);
  white-space: nowrap;
  transition: left 0.14s cubic-bezier(0.22, 1, 0.36, 1), top 0.14s cubic-bezier(0.22, 1, 0.36, 1), box-shadow 0.14s ease, border-color 0.14s ease, transform 0.14s ease;
}

.table-set.valid-set {
  border-color: rgba(74, 222, 128, 0.38);
}

.table-set.invalid-set {
  border-color: rgba(239, 68, 68, 0.85);
  background: rgba(239, 68, 68, 0.14);
}

/* Magnetic Attraction & Repulsion Visual Feedback */
.table-set.magnet-target-attract {
  border-color: #4ade80 !important;
  background: rgba(34, 197, 94, 0.2) !important;
  box-shadow:
    0 0 0 2.5px rgba(74, 222, 128, 0.72),
    0 0 26px rgba(74, 222, 128, 0.62) !important;
  z-index: 6;
}

.table-set.magnet-target-repel {
  border-color: #ef4444 !important;
  background: rgba(239, 68, 68, 0.22) !important;
  box-shadow:
    0 0 0 3px rgba(239, 68, 68, 0.82),
    0 0 28px rgba(239, 68, 68, 0.7) !important;
  animation: repelTargetPulse 0.28s ease-in-out infinite alternate;
  z-index: 6;
}

.table-set.repel-bounce {
  animation: repelBouncePop 0.26s cubic-bezier(0.22, 1.35, 0.36, 1);
}

.table-set.snap-close-pop {
  transform-origin: left center;
  animation: snapCloseGap 0.24s cubic-bezier(0.22, 1.25, 0.36, 1);
}

@keyframes snapCloseGap {
  0% { transform: scaleX(1.14); box-shadow: 0 0 18px rgba(74, 222, 128, 0.65); }
  70% { transform: scaleX(0.98); }
  100% { transform: scaleX(1); }
}

@keyframes repelTargetPulse {
  from { transform: scale(1); }
  to { transform: scale(1.025); }
}

@keyframes repelBouncePop {
  0% { transform: scale(1.06); box-shadow: 0 0 24px rgba(239, 68, 68, 0.75); }
  100% { transform: scale(1); }
}

/* Whole-Series Drag Affordance ONLY on Rack Series First Chip (table chips always unlock individually) */
.rack-cluster.is-draggable-series:has(.tile.series-lead-tile:hover) {
  box-shadow: 0 0 0 2px rgba(251, 191, 36, 0.8), 0 0 18px rgba(251, 191, 36, 0.38);
  border-radius: 11px;
}

.tile.series-lead-tile::before {
  content: '';
  position: absolute;
  top: 5px;
  left: 5px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: linear-gradient(135deg, #fbbf24, #f59e0b);
  box-shadow: 0 0 0 1.5px rgba(255, 255, 255, 0.85), 0 1px 4px rgba(0, 0, 0, 0.35);
  pointer-events: none;
  opacity: 0.9;
}

/* Zero canvas/frame drag highlight: keep felt table & wooden rack clean when dragging chips */
.drop-highlight {
  outline: none !important;
  box-shadow: none !important;
}

/* ==================== 3D DYNAMIC WOODEN RACK ==================== */
.wooden-rack-frame {
  position: relative;
  align-self: center;
  margin: 0 auto;
  width: fit-content;
  min-width: 180px;
  max-width: 98%;
  background: linear-gradient(180deg, var(--wood-top) 0%, var(--wood-mid) 52%, var(--wood-dark) 100%);
  border-radius: 12px 12px 6px 6px;
  border-top: 3px solid var(--wood-ledge);
  box-shadow:
    0 8px 0 #6b441a,
    0 14px 28px rgba(0, 0, 0, 0.65);
  padding: 6px 16px 10px;
  flex-shrink: 0;
  transition: width 0.2s ease, min-width 0.2s ease, padding 0.2s ease;
}

.wooden-rack {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  width: fit-content;
  max-width: 100%;
  gap: 6px;
}

.rack-shelf {
  min-height: calc(var(--tile-h) + 6px);
  width: 100%;
  min-width: 140px;
  display: flex;
  align-items: flex-end;
  flex-wrap: nowrap;
  overflow-x: auto;
  gap: 3px;
  padding: 2px 10px 4px;
  border-bottom: 5px solid #8c5d27;
  box-shadow: inset 0 -3px 6px rgba(0, 0, 0, 0.28);
  border-radius: 4px;
}

.rack-brand-engraving {
  position: absolute;
  right: 14px;
  bottom: 3px;
  font-size: 12px;
  font-weight: 900;
  color: rgba(107, 68, 26, 0.55);
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.25);
  pointer-events: none;
}

/* Visual Separation on the Wooden Rack: Bare Wood Slot Gaps between Series and Other Tiles */
.rack-cluster {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  position: relative;
  padding: 0;
  flex-shrink: 0;
}

.rack-cluster.cluster-run .tile {
  box-shadow:
    0 3px 0 #34d399,
    0 5px 9px rgba(0, 0, 0, 0.42);
}

.rack-cluster.cluster-group .tile {
  box-shadow:
    0 3px 0 #60a5fa,
    0 5px 9px rgba(0, 0, 0, 0.42);
}

.rack-cluster.cluster-pair .tile {
  box-shadow:
    0 3px 0 #fbbf24,
    0 5px 9px rgba(0, 0, 0, 0.42);
}

/* One-tile-wide bare wooden gap separating Series/Groups from Other Tiles */
.rack-slot-gap {
  width: calc(var(--tile-w) * 0.72);
  height: calc(var(--tile-h) - 8px);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.rack-slot-gap.major-gap {
  width: var(--tile-w);
}

/* ==================== RIGHT VERTICAL CONTROLS RAIL ==================== */
.right-controls-rail {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  padding: 12px 14px 20px 4px;
  z-index: 15;
}

/* Vertical Sort Capsule (789 / 777 / ✦) */
.sort-capsule-vertical {
  width: 78px;
  border-radius: 30px;
  background: linear-gradient(180deg, rgba(27, 73, 140, 0.92) 0%, rgba(14, 41, 86, 0.96) 100%);
  border: 2px solid rgba(147, 197, 253, 0.38);
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.55), inset 0 1px 1px rgba(255, 255, 255, 0.25);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.v-sort-btn {
  width: 100%;
  height: 60px;
  border: none;
  border-bottom: 1px solid rgba(147, 197, 253, 0.22);
  background: transparent;
  color: #f8fafc;
  font-size: 22px;
  font-weight: 900;
  letter-spacing: -0.5px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, color 0.15s;
}

.v-sort-btn:last-child {
  border-bottom: none;
}

.v-sort-btn:hover {
  background: rgba(255, 255, 255, 0.14);
}

.v-sort-btn.active {
  background: linear-gradient(180deg, #3b82f6, #1d4ed8);
  color: #fff;
}

.v-sort-smart.active {
  background: linear-gradient(180deg, #10b981, #059669);
}

/* Undo circular dark-blue button with crimson-red border & icon (matches final_step_45.png) */
.v-undo-btn {
  width: 68px;
  height: 68px;
  border-radius: 50%;
  border: 2.5px solid #ef4444;
  background: linear-gradient(180deg, rgba(24, 58, 112, 0.92), rgba(12, 32, 68, 0.96));
  color: #ef4444;
  font-size: 32px;
  font-weight: 900;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.55);
  transition: transform 0.1s, filter 0.15s;
}

.v-undo-btn:hover {
  filter: brightness(1.2);
}

/* Confirm / End Turn green-outlined rounded pill (matches final_step_45.png) */
.v-confirm-pill {
  width: 78px;
  height: 116px;
  border-radius: 32px;
  border: 2.5px solid #4ade80;
  background: linear-gradient(180deg, rgba(24, 68, 112, 0.92), rgba(12, 42, 68, 0.96));
  color: #4ade80;
  font-size: 40px;
  font-weight: 900;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.6), 0 0 16px rgba(74, 222, 128, 0.28);
  transition: transform 0.1s, filter 0.15s;
}

.v-confirm-pill:hover:not(:disabled) {
  filter: brightness(1.2);
}

/* Tall Draw (+) Capsule with orange border and pool count at bottom (matches step_16/22) */
.action-capsule-draw {
  width: 78px;
  height: 174px;
  border-radius: 34px;
  background: linear-gradient(180deg, rgba(30, 74, 138, 0.92) 0%, rgba(14, 38, 78, 0.96) 100%);
  border: 2.5px solid #d97706;
  box-shadow: 0 12px 26px rgba(0, 0, 0, 0.6), inset 0 1px 2px rgba(255, 255, 255, 0.2);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  padding: 36px 6px 16px;
  cursor: pointer;
  color: #f59e0b;
  transition: transform 0.1s, filter 0.15s, opacity 0.15s;
}

.action-capsule-draw:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.action-capsule-draw:active:not(:disabled),
.v-confirm-pill:active:not(:disabled),
.v-undo-btn:active {
  transform: scale(0.94);
}

.draw-plus-glyph {
  font-size: 46px;
  font-weight: 900;
  line-height: 1;
}

.pool-counter-badge {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 16px;
  color: #dbeafe;
}

.pool-icon {
  font-size: 15px;
  opacity: 0.85;
}

/* ==================== RUMMIKUB TILES ==================== */
.tile {
  position: relative;
  width: var(--tile-w);
  height: var(--tile-h);
  border-radius: calc(var(--tile-w) * 0.16);
  background: linear-gradient(180deg, var(--tile-cream) 0%, var(--tile-bottom) 100%);
  box-shadow:
    0 5px 0 #b2a78e,
    0 8px 14px rgba(0, 0, 0, 0.45);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding-top: calc(var(--tile-h) * 0.11);
  touch-action: none;
  cursor: grab;
  flex-shrink: 0;
  transition: transform 0.1s, box-shadow 0.1s;
}

.tile::after {
  content: 'Rummikub';
  font-size: calc(var(--tile-h) * 0.095);
  font-weight: 700;
  color: rgba(0, 0, 0, 0.18);
  margin-top: auto;
  margin-bottom: calc(var(--tile-h) * 0.08);
  letter-spacing: 0.2px;
}

.tile-num {
  font-size: var(--tile-font);
  font-weight: 900;
  line-height: 1.05;
  letter-spacing: -0.6px;
}

.tile.color-red .tile-num { color: var(--tile-red); }
.tile.color-blue .tile-num { color: var(--tile-blue); }
.tile.color-orange .tile-num { color: var(--tile-orange); }
.tile.color-black .tile-num { color: var(--tile-black); }

.tile.joker-red .tile-num { color: var(--tile-red); font-size: calc(var(--tile-font) + 2px); }
.tile.joker-black .tile-num { color: var(--tile-black); font-size: calc(var(--tile-font) + 2px); }

.tile.selected {
  transform: translateY(-9px);
  outline: 2.5px solid #4ade80;
  box-shadow:
    0 6px 0 #16a34a,
    0 12px 20px rgba(74, 222, 128, 0.55);
  z-index: 5;
}

.tile.just-played,
.tile.from-my-rack.just-played {
  outline: 2.5px solid #ff3b3b;
  box-shadow:
    0 0 0 2px rgba(255, 59, 59, 0.88),
    0 0 16px 4px rgba(239, 68, 68, 0.8),
    0 5px 0 #b2a78e,
    0 8px 14px rgba(0, 0, 0, 0.45);
  z-index: 3;
}

.tile.from-my-rack {
  box-shadow:
    0 3px 0 #4ade80,
    0 5px 9px rgba(0, 0, 0, 0.42);
}

/* Face-down state while chip is still flying from deck to player's wooden rack */
.tile.tile-face-down {
  opacity: 0;
  pointer-events: none;
}

.tile.tile-face-down .tile-num {
  visibility: hidden;
}

.tile.tile-flip-reveal {
  animation: tileFlipReveal 0.28s cubic-bezier(0.22, 1.15, 0.36, 1);
}

@keyframes tileFlipReveal {
  0% { transform: scaleX(0.12) translateY(-4px); filter: brightness(1.15); }
  70% { transform: scaleX(1.06) translateY(0); }
  100% { transform: scaleX(1); filter: brightness(1); }
}

/* Face-Down Flying Chip pulled from the Deck (no face/number ever shown) */
.flying-tile-back {
  position: fixed;
  width: var(--tile-w);
  height: var(--tile-h);
  border-radius: calc(var(--tile-w) * 0.16);
  background: linear-gradient(155deg, #fbf6e8 0%, #e7dcc2 58%, #d2c3a2 100%);
  border: 2px solid #fffaf0;
  box-shadow:
    inset 0 0 0 5px rgba(176, 155, 118, 0.28),
    0 6px 0 #a99b7f,
    0 18px 30px rgba(0, 0, 0, 0.62);
  pointer-events: none;
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
  will-change: transform, opacity;
}

.flying-tile-back::after {
  content: '';
  width: 58%;
  height: 68%;
  border-radius: 6px;
  border: 1.5px solid rgba(154, 134, 98, 0.38);
  background: repeating-linear-gradient(
    45deg,
    rgba(168, 146, 108, 0.08),
    rgba(168, 146, 108, 0.08) 4px,
    transparent 4px,
    transparent 8px
  );
}

.avatar-node.avatar-receive-pop {
  animation: avatarReceivePop 0.34s cubic-bezier(0.22, 1.35, 0.36, 1);
}

@keyframes avatarReceivePop {
  0% { transform: scale(1); }
  45% { transform: scale(1.14); }
  100% { transform: scale(1); }
}

.tile.dragging-source {
  opacity: 0.25;
}

.drag-ghost {
  position: fixed;
  pointer-events: none;
  z-index: 9999;
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 4px 6px;
  border-radius: 11px;
  background: rgba(10, 32, 70, 0.38);
  border: 1.5px solid rgba(147, 197, 253, 0.48);
  box-shadow: 0 16px 32px rgba(0, 0, 0, 0.58);
  transform-origin: center center;
  transition: box-shadow 0.1s ease, border-color 0.1s ease, background 0.1s ease;
}

.drag-ghost.magnet-snap {
  border-color: #4ade80;
  background: rgba(34, 197, 94, 0.24);
  box-shadow:
    0 0 0 3px rgba(74, 222, 128, 0.9),
    0 0 26px rgba(74, 222, 128, 0.72),
    0 12px 26px rgba(0, 0, 0, 0.5);
}

.drag-ghost.magnet-repel {
  border-color: #ef4444;
  background: rgba(239, 68, 68, 0.25);
  box-shadow:
    0 0 0 3px rgba(239, 68, 68, 0.92),
    0 0 28px rgba(239, 68, 68, 0.78),
    0 12px 26px rgba(0, 0, 0, 0.5);
  animation: ghostRepelShake 0.16s ease-in-out infinite alternate;
}

@keyframes ghostRepelShake {
  from { transform: translateX(-2px); }
  to { transform: translateX(2px); }
}

/* ==================== MODALS & STATS ==================== */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(3, 10, 24, 0.76);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 14px;
  z-index: 100;
}

.modal-card {
  width: 100%;
  background: linear-gradient(180deg, #0f2c5c, #071733);
  border: 1.5px solid var(--blue-border);
  border-radius: 20px;
  padding: 20px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.7);
}

.round-modal { max-width: 440px; }
.stats-modal {
  max-width: 740px;
  max-height: 88dvh;
  display: flex;
  flex-direction: column;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.modal-header h2 { margin: 0; font-size: 18px; }

.close-x {
  background: rgba(255, 255, 255, 0.12);
  border: none;
  color: #fff;
  width: 30px;
  height: 30px;
  border-radius: 8px;
  cursor: pointer;
}

.stats-mode-tabs { margin-bottom: 12px; }

.stats-scroll-body {
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.h2h-selector-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(0, 0, 0, 0.28);
  padding: 8px 12px;
  border-radius: 10px;
}

.h2h-label { font-size: 13px; font-weight: 800; }
.vs-badge {
  font-size: 11px;
  font-weight: 900;
  padding: 2px 6px;
  border-radius: 5px;
  background: rgba(245, 158, 11, 0.25);
  color: #fde68a;
}

.h2h-summary-box {
  margin: 6px 0 8px;
  padding: 8px 12px;
  border-radius: 9px;
  background: rgba(59, 130, 246, 0.16);
  border: 1px solid var(--blue-border);
  font-size: 13px;
  font-weight: 700;
}

.stats-section h3 {
  margin: 0 0 6px;
  font-size: 13.5px;
  color: #93c5fd;
}

.stats-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.stats-table th,
.stats-table td {
  padding: 7px 9px;
  text-align: left;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.stats-table th { color: var(--text-muted); font-size: 11.5px; }
.score-pos { color: #4ade80; font-weight: 800; }
.score-neg { color: #f87171; font-weight: 800; }

.recent-matches-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.match-history-item {
  padding: 7px 10px;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.22);
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  font-size: 12.5px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 14px;
}

.toast-container {
  position: fixed;
  top: 52px;
  right: 14px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 6px;
  pointer-events: none;
}

.toast {
  background: rgba(6, 21, 45, 0.95);
  border-left: 4px solid #4ade80;
  color: #fff;
  padding: 8px 13px;
  border-radius: 9px;
  font-size: 12.5px;
  font-weight: 700;
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.55);
}

.toast.error { border-left-color: var(--accent-danger); }

.spinner {
  width: 30px;
  height: 30px;
  margin: 0 auto 10px;
  border: 3px solid rgba(255, 255, 255, 0.2);
  border-top-color: #60a5fa;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ==================== MOBILE RESPONSIVE ==================== */
@media (max-width: 680px) {
  :root {
    --tile-w: 34px;
    --tile-h: 48px;
    --tile-font: 16px;
  }

  .board-arena {
    grid-template-columns: 64px 1fr 62px;
  }

  .avatar-ring-wrap {
    width: 46px;
    height: 46px;
  }

  .avatar-face { font-size: 18px; }

  .sort-capsule-vertical,
  .action-capsule-vertical {
    width: 48px;
  }

  .v-sort-btn {
    height: 38px;
    font-size: 13px;
  }

  .dials-row {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .dial-value { font-size: 40px; }

  .private-grid {
    grid-template-columns: 1fr;
  }
}

/* ==================== PASSCODE ACCESS, TAILSCALE & TUTORIAL ==================== */
.hud-tutorial-btn {
  border-color: rgba(45, 212, 191, 0.65);
  color: #99f6e4;
  font-weight: 900;
}

.home-tutorial-row {
  display: flex;
  justify-content: center;
  margin-top: -6px;
}

.btn-tutorial-pill {
  border: 1.5px solid rgba(147, 197, 253, 0.48);
  background: rgba(12, 39, 84, 0.85);
  color: #e0f2fe;
  border-radius: 999px;
  padding: 9px 20px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.38);
  transition: filter 0.15s, transform 0.1s;
}

.btn-tutorial-pill:hover {
  filter: brightness(1.18);
}

.btn-tutorial-link {
  margin-top: 14px;
  width: 100%;
  border: 1px solid rgba(147, 197, 253, 0.38);
  background: rgba(255, 255, 255, 0.08);
  color: #bfdbfe;
  border-radius: 10px;
  padding: 9px 14px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s;
}

.btn-tutorial-link:hover {
  background: rgba(255, 255, 255, 0.16);
}

.guest-subtitle {
  margin: -6px 0 14px;
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.4;
}

.lobby-chips {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin: 10px 0 4px;
}

.lobby-chips .turn-pill {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--blue-border);
  border-radius: 999px;
  padding: 5px 12px;
}

.passcode-box {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 12px;
  border-radius: 12px;
  background: rgba(3, 12, 28, 0.72);
  border: 1.5px solid rgba(251, 191, 36, 0.55);
}

.passcode-digits {
  font-family: 'Cascadia Mono', 'Consolas', monospace;
  font-size: 24px;
  font-weight: 900;
  letter-spacing: 2px;
  color: #fde68a;
  text-shadow: 0 2px 10px rgba(245, 158, 11, 0.35);
}

.btn-rotate {
  background: linear-gradient(180deg, #d97706, #b45309);
  border-color: rgba(253, 230, 138, 0.5);
}

.tunnel-pill {
  font-size: 10.5px;
  font-weight: 900;
  padding: 2px 8px;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

.tunnel-pill.online {
  background: rgba(34, 197, 94, 0.25);
  border: 1px solid #4ade80;
  color: #bbf7d0;
}

.tunnel-pill.setup {
  background: rgba(245, 158, 11, 0.25);
  border: 1px solid #fbbf24;
  color: #fde68a;
}

.tunnel-setup-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 4px;
}

.tunnel-action-link {
  font-size: 12px;
  font-weight: 700;
  color: #93c5fd;
  text-decoration: underline;
}

/* Interactive Tutorial Modal */
.tutorial-modal {
  max-width: 620px;
  max-height: 90dvh;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.tut-dots {
  display: flex;
  justify-content: center;
  gap: 8px;
}

.tut-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.22);
  border: none;
  padding: 0;
  cursor: pointer;
  transition: transform 0.15s, background 0.15s;
}

.tut-dot.active {
  background: #4ade80;
  transform: scale(1.25);
}

.tut-slide-body {
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 4px 2px;
}

.tut-slide-title {
  margin: 0;
  font-size: 18px;
  font-weight: 900;
  color: #fde68a;
}

.tut-rule-list {
  margin: 0;
  padding-left: 20px;
  display: flex;
  flex-direction: column;
  gap: 7px;
  font-size: 13.5px;
  line-height: 1.45;
  color: #e2e8f0;
}

.tut-rule-list strong {
  color: #fff;
}

.tut-visual-box {
  background: rgba(3, 12, 28, 0.55);
  border: 1px solid var(--blue-border);
  border-radius: 14px;
  padding: 12px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 14px;
}

.tut-example-group {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.tut-example-label {
  font-size: 11.5px;
  font-weight: 800;
  color: #93c5fd;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

.tut-tiles-row {
  display: inline-flex;
  gap: 4px;
  --tile-h: 56px;
  --tile-w: 41px;
  --tile-font: 22px;
}

.tut-tiles-row .tile {
  cursor: default;
}

.tut-tip-banner {
  background: rgba(16, 185, 129, 0.16);
  border: 1px solid rgba(52, 211, 153, 0.45);
  border-radius: 10px;
  padding: 9px 12px;
  font-size: 13px;
  color: #d1fae5;
  line-height: 1.4;
}

.tut-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: 6px;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.tut-step-counter {
  font-size: 13px;
  font-weight: 800;
  color: var(--text-muted);
}
