:root {
  --bg-deep: #0c0517;
  --bg-felt: #220e3d;
  --bg-felt-light: #361661;
  --purple: #a855f7;
  --purple-light: #c084fc;
  --purple-dark: #7e22ce;
  --purple-deep: #581c87;
  --purple-glow: rgba(168, 85, 247, 0.45);
  --wood-dark: #1b0a2c;
  --wood-mid: #331454;
  --wood-edge: #57228e;
  --tile-bg: #fdf8ee;
  --tile-bg-bottom: #ecdbbf;
  --tile-ink: #1b0e2b;
  --gold: #f5b942;
  --gold-dark: #d28e18;
  --danger: #ef5350;
  --amber: #ffb74d;
  --text-main: #f5f0fc;
  --text-muted: #baa4d6;
  --card-bg: rgba(26, 12, 46, 0.92);
  --card-border: rgba(192, 132, 252, 0.16);
  --cell-size: 48px;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: radial-gradient(circle at 50% 20%, #2b124c 0%, #0c0517 100%);
  color: var(--text-main);
  overflow-x: hidden;
}

.hidden {
  display: none !important;
}

.screen {
  display: none;
  min-height: 100vh;
}

.screen.active {
  display: flex;
  flex-direction: column;
}

/* TYPOGRAPHY & BUTTONS */
h1, h2, h3, h4 {
  font-family: 'Fredoka', 'Inter', sans-serif;
  margin: 0;
  letter-spacing: 0.01em;
}

.muted {
  color: var(--text-muted);
  font-size: 0.9rem;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: none;
  border-radius: 10px;
  padding: 10px 16px;
  font-family: inherit;
  font-weight: 700;
  font-size: 0.95rem;
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.15s ease, filter 0.15s ease, opacity 0.15s ease;
  color: var(--text-main);
  background: rgba(255, 255, 255, 0.1);
}

.btn:hover:not(:disabled) {
  transform: translateY(-1px);
  filter: brightness(1.07);
}

.btn:active:not(:disabled) {
  transform: translateY(1px);
}

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

.btn-sm {
  padding: 6px 12px;
  font-size: 0.82rem;
  border-radius: 8px;
}

.btn-lg {
  padding: 13px 22px;
  font-size: 1.05rem;
  width: 100%;
}

.btn-xl {
  padding: 16px 32px;
  font-size: 1.2rem;
  border-radius: 14px;
}

.btn-gold {
  background: linear-gradient(180deg, #ffd064 0%, #e49b21 100%);
  color: #231503;
  box-shadow: 0 4px 0 #9f670a, 0 8px 20px rgba(0, 0, 0, 0.35);
}

.btn-emerald {
  background: linear-gradient(180deg, #b86bfc 0%, #7c22ce 100%);
  color: #ffffff;
  box-shadow: 0 4px 0 #581c87, 0 8px 20px rgba(124, 34, 206, 0.4);
}

.btn-ghost {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(192, 132, 252, 0.2);
}

.btn-danger-ghost {
  background: rgba(239, 83, 80, 0.15);
  border: 1px solid rgba(239, 83, 80, 0.4);
  color: #ffb3b1;
}

.btn-icon {
  width: 38px;
  height: 38px;
  padding: 0;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(192, 132, 252, 0.2);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
}

.btn-icon svg {
  display: block;
  pointer-events: none;
  flex-shrink: 0;
}

.btn-leave-game {
  background: rgba(239, 68, 68, 0.14);
  border-color: rgba(248, 113, 113, 0.35);
  color: #fca5a5;
}

.btn-leave-game:hover {
  background: rgba(239, 68, 68, 0.28);
  border-color: rgba(248, 113, 113, 0.65);
  color: #fff;
}

/* HOME SCREEN */
.home-shell {
  max-width: 980px;
  margin: 0 auto;
  padding: 36px 20px 28px;
  width: 100%;
}

.brand-header {
  text-align: center;
  margin-bottom: 30px;
}

.logo-tiles {
  display: inline-flex;
  gap: 8px;
  margin-bottom: 12px;
}

.mini-tile {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  position: relative;
  width: 42px;
  height: 44px;
  background: linear-gradient(180deg, var(--tile-bg) 0%, var(--tile-bg-bottom) 100%);
  color: var(--tile-ink);
  font-family: 'Fredoka', sans-serif;
  font-weight: 700;
  font-size: 1.35rem;
  border-radius: 8px;
  box-shadow: 0 4px 0 #baa17e, 0 8px 16px rgba(0, 0, 0, 0.35);
}

.mini-tile sub {
  position: absolute;
  bottom: 3px;
  right: 5px;
  font-size: 0.62rem;
  font-weight: 800;
}

.brand-header h1 {
  font-size: 2.75rem;
  color: #fff;
  text-shadow: 0 3px 18px rgba(168, 85, 247, 0.5);
}

.subtitle {
  margin: 8px auto 0;
  max-width: 600px;
  color: #d1bfe8;
  font-size: 1.05rem;
}

.home-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 22px;
}

.card {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 18px;
  padding: 24px;
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(12px);
}

.card-primary {
  border-color: rgba(168, 85, 247, 0.45);
  box-shadow: 0 18px 40px rgba(12, 5, 23, 0.6), 0 0 25px rgba(168, 85, 247, 0.12);
}

.card h2 {
  font-size: 1.45rem;
  margin-bottom: 6px;
}

.card-desc {
  color: var(--text-muted);
  font-size: 0.92rem;
  margin: 0 0 18px;
}

form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.85rem;
  font-weight: 600;
  color: #e0d2f0;
}

input[type="text"],
input[type="number"],
select {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  box-sizing: border-box;
  background: rgba(14, 6, 26, 0.85);
  border: 1px solid rgba(192, 132, 252, 0.22);
  border-radius: 10px;
  padding: 10px 12px;
  color: #fff;
  font-size: 0.98rem;
  font-family: inherit;
  outline: none;
  text-overflow: ellipsis;
}

input:focus, select:focus {
  border-color: var(--purple-light);
  box-shadow: 0 0 0 2px rgba(168, 85, 247, 0.25);
}

.row-2 {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 12px;
}

.row-2 > label {
  min-width: 0;
}

@media (max-width: 480px) {
  .row-2 {
    grid-template-columns: 1fr;
  }
}

.checkbox-row {
  flex-direction: row;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  font-weight: 500;
}

.checkbox-row input {
  width: 17px;
  height: 17px;
  accent-color: var(--purple);
}

.code-input {
  text-transform: uppercase;
  letter-spacing: 0.18em;
  font-weight: 800;
  text-align: center;
  font-size: 1.15rem !important;
}

.rules-mini {
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid rgba(192, 132, 252, 0.12);
}

.rules-mini h3 {
  font-size: 1rem;
  margin-bottom: 8px;
  color: var(--gold);
}

.rules-mini ol {
  margin: 0;
  padding-left: 18px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.85rem;
  color: #ded3ee;
}

.dict-status {
  text-align: center;
  margin-top: 16px;
  font-size: 0.82rem;
  color: var(--text-muted);
}

/* LOBBY SCREEN */
.lobby-shell {
  max-width: 960px;
  margin: 0 auto;
  padding: 28px 20px;
  width: 100%;
}

.lobby-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  flex-wrap: wrap;
  gap: 16px;
  margin-bottom: 22px;
}

.pill-tag {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.1em;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(168, 85, 247, 0.2);
  color: #d8b4fe;
  border: 1px solid rgba(168, 85, 247, 0.35);
  margin-bottom: 6px;
}

.code-badge {
  color: var(--gold);
  letter-spacing: 0.14em;
  background: rgba(245, 185, 66, 0.14);
  padding: 2px 10px;
  border-radius: 8px;
}

.share-url {
  margin: 6px 0 0;
  color: var(--text-muted);
  font-size: 0.88rem;
}

.lobby-top-actions {
  display: flex;
  gap: 10px;
}

.lobby-grid {
  display: grid;
  grid-template-columns: 1.2fr 1fr;
  gap: 20px;
}

@media (max-width: 780px) {
  .lobby-grid {
    grid-template-columns: 1fr;
  }
}

.card-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
}

.player-roster {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.roster-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(192, 132, 252, 0.12);
}

.roster-name {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
}

.tag {
  font-size: 0.7rem;
  font-weight: 800;
  padding: 2px 7px;
  border-radius: 6px;
  text-transform: uppercase;
}

.tag-you { background: rgba(245, 185, 66, 0.22); color: var(--gold); }
.tag-host { background: rgba(168, 85, 247, 0.24); color: #d8b4fe; }
.tag-bot { background: rgba(120, 170, 255, 0.2); color: #8ec0ff; }

.settings-stack {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-top: 12px;
}

.lobby-start-wrap {
  margin-top: 22px;
}

/* GAMEPLAY LAYOUT */
#screen-game {
  height: 100vh;
  overflow: hidden;
}

.game-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  background: linear-gradient(180deg, rgba(30, 13, 52, 0.98), rgba(16, 7, 30, 0.98));
  border-bottom: 2px solid rgba(168, 85, 247, 0.22);
  z-index: 20;
}

.topbar-left, .topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.pill-round {
  background: rgba(255, 255, 255, 0.12);
  padding: 5px 12px;
  border-radius: 999px;
  font-weight: 800;
  font-size: 0.82rem;
  letter-spacing: 0.06em;
}

.pill-final {
  background: linear-gradient(90deg, #ff9800, #ffd54f);
  color: #261400;
  padding: 5px 12px;
  border-radius: 999px;
  font-weight: 900;
  font-size: 0.78rem;
  letter-spacing: 0.06em;
  animation: pulseGlow 1.6s infinite;
}

@keyframes pulseGlow {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255, 193, 7, 0.45); }
  50% { box-shadow: 0 0 18px 4px rgba(255, 193, 7, 0.55); }
}

.room-mini {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.topbar-center {
  flex: 1;
  display: flex;
  justify-content: center;
  min-width: 0;
}

.event-ticker {
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid rgba(192, 132, 252, 0.18);
  border-radius: 999px;
  padding: 6px 16px;
  font-size: 0.88rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

.event-ticker.flash {
  border-color: var(--gold);
  color: #ffe39b;
}

.pile-widget {
  display: flex;
  align-items: center;
  gap: 9px;
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid rgba(192, 132, 252, 0.2);
  padding: 5px 12px;
  border-radius: 10px;
}

.pile-widget.empty {
  border-color: var(--danger);
  background: rgba(239, 83, 80, 0.2);
}

.pile-icon {
  width: 22px;
  height: 26px;
  border-radius: 4px;
  background: linear-gradient(135deg, #59258c, #311152);
  border: 1px solid #8e47db;
  box-shadow: 2px 2px 0 #1c0830;
}

.pile-count {
  font-weight: 800;
  font-size: 0.92rem;
  line-height: 1.1;
}

.pile-label {
  font-size: 0.68rem;
  color: var(--text-muted);
  text-transform: uppercase;
}

.game-layout {
  flex: 1;
  display: flex;
  min-height: 0;
}

/* STANDINGS SIDEBAR */
.standings-panel {
  width: 270px;
  flex-shrink: 0;
  background: rgba(16, 7, 30, 0.92);
  border-right: 1px solid rgba(168, 85, 247, 0.15);
  display: flex;
  flex-direction: column;
  padding: 14px 12px;
  overflow-y: auto;
}

@media (max-width: 860px) {
  .game-layout {
    flex-direction: column;
  }
  .standings-panel {
    width: 100%;
    max-height: 145px;
    border-right: none;
    border-bottom: 1px solid rgba(168, 85, 247, 0.15);
  }
  .standings-list {
    flex-direction: row !important;
    overflow-x: auto;
  }
  .standing-card {
    min-width: 195px;
  }
}

.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.panel-head h3 {
  font-size: 1rem;
}

.limit-chip {
  font-size: 0.76rem;
  background: rgba(239, 83, 80, 0.16);
  border: 1px solid rgba(239, 83, 80, 0.35);
  color: #ffb8b6;
  padding: 2px 8px;
  border-radius: 999px;
}

.standings-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.standing-card {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(192, 132, 252, 0.12);
  border-radius: 12px;
  padding: 10px;
  transition: opacity 0.2s ease, border-color 0.2s ease;
}

.standing-card.is-self {
  border-color: rgba(168, 85, 247, 0.55);
  background: rgba(168, 85, 247, 0.12);
}

.standing-card.is-eliminated {
  opacity: 0.48;
  background: rgba(0, 0, 0, 0.25);
}

.standing-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 6px;
  margin-bottom: 5px;
}

.standing-name {
  font-weight: 700;
  font-size: 0.92rem;
  display: flex;
  align-items: center;
  gap: 6px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.standing-score {
  font-weight: 800;
  font-size: 0.85rem;
  white-space: nowrap;
}

.danger-bar {
  height: 7px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.1);
  overflow: hidden;
  margin-bottom: 6px;
}

.danger-fill {
  height: 100%;
  border-radius: 999px;
  transition: width 0.35s ease;
}

.danger-safe { background: linear-gradient(90deg, #c084fc, #a855f7); }
.danger-warn { background: var(--amber); }
.danger-crit { background: var(--danger); }

.standing-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.76rem;
  color: var(--text-muted);
}

.ko-badge {
  font-size: 0.68rem;
  font-weight: 800;
  color: #ff9c9a;
  background: rgba(239, 83, 80, 0.22);
  padding: 2px 6px;
  border-radius: 5px;
}

.finalist-badge {
  font-size: 0.68rem;
  font-weight: 800;
  color: #ffe08a;
  background: rgba(245, 185, 66, 0.2);
  padding: 2px 6px;
  border-radius: 5px;
}

/* MAIN TABLE STAGE */
.table-stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  position: relative;
  min-width: 0;
  min-height: 0;
  background:
    radial-gradient(circle at 50% 45%, rgba(68, 26, 114, 0.65) 0%, rgba(18, 7, 34, 0.95) 100%);
}

.ready-overlay {
  position: absolute;
  inset: 0;
  z-index: 30;
  background: rgba(12, 5, 23, 0.88);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.ready-card {
  background: var(--card-bg);
  border: 2px solid rgba(168, 85, 247, 0.5);
  border-radius: 22px;
  padding: 32px;
  max-width: 560px;
  width: 100%;
  text-align: center;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.7), 0 0 35px rgba(168, 85, 247, 0.2);
}

.ready-card h2 {
  font-size: 1.9rem;
  margin-bottom: 8px;
}

.facedown-row {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin: 24px 0 28px;
  flex-wrap: wrap;
}

.eliminated-banner {
  background: rgba(239, 83, 80, 0.22);
  border-bottom: 1px solid rgba(239, 83, 80, 0.45);
  color: #ffd3d2;
  padding: 8px 16px;
  text-align: center;
  font-size: 0.9rem;
}

.board-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 14px;
  gap: 10px;
  flex-wrap: wrap;
  background: rgba(0, 0, 0, 0.22);
  border-bottom: 1px solid rgba(192, 132, 252, 0.12);
}

.toolbar-group {
  display: flex;
  align-items: center;
  gap: 6px;
}

.validation-pill {
  padding: 5px 12px;
  border-radius: 999px;
  font-size: 0.82rem;
  font-weight: 700;
}

.validation-pill.neutral { background: rgba(255, 255, 255, 0.1); color: #ded3ee; }
.validation-pill.valid { background: rgba(168, 85, 247, 0.24); color: #e9d5ff; border: 1px solid rgba(168, 85, 247, 0.5); }
.validation-pill.invalid { background: rgba(239, 83, 80, 0.22); color: #ffb3b1; border: 1px solid rgba(239, 83, 80, 0.45); }
.validation-pill.warn { background: rgba(255, 183, 77, 0.22); color: #ffe0a3; border: 1px solid rgba(255, 183, 77, 0.45); }

.table-viewport {
  flex: 1;
  overflow: auto;
  position: relative;
  padding: 20px;
  display: flex;
  align-items: flex-start;
  justify-content: flex-start;
  cursor: grab;
}

.table-viewport:active {
  cursor: grabbing;
}

.freeform-grid {
  display: grid;
  gap: 3px;
  margin: auto;
  padding: 18px;
  border-radius: 16px;
  background: rgba(16, 7, 32, 0.5);
  border: 1px dashed rgba(192, 132, 252, 0.25);
}

.grid-cell {
  width: var(--cell-size);
  height: var(--cell-size);
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(192, 132, 252, 0.08);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  transition: background 0.1s ease, border-color 0.1s ease;
}

.grid-cell:hover {
  background: rgba(168, 85, 247, 0.12);
}

.grid-cell.drag-over {
  background: rgba(168, 85, 247, 0.25);
  border-color: var(--purple-light);
}

.grid-cell.cursor-active {
  border: 2px solid var(--purple-light);
  background: rgba(168, 85, 247, 0.18);
}

.cursor-arrow {
  position: absolute;
  font-size: 0.85rem;
  font-weight: 900;
  color: var(--purple-light);
  pointer-events: none;
  opacity: 0.85;
}

/* SCRABBLE TILES */
.tile {
  width: calc(var(--cell-size) - 2px);
  height: calc(var(--cell-size) - 2px);
  border-radius: 8px;
  background: linear-gradient(180deg, var(--tile-bg) 0%, var(--tile-bg-bottom) 100%);
  color: var(--tile-ink);
  font-family: 'Fredoka', sans-serif;
  font-weight: 700;
  font-size: calc(var(--cell-size) * 0.48);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  user-select: none;
  cursor: pointer;
  touch-action: none;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.85),
    0 3px 0 #bda582,
    0 5px 10px rgba(0, 0, 0, 0.35);
  transition: transform 0.1s ease, box-shadow 0.1s ease;
}

.tile.is-dragging {
  opacity: 0.35 !important;
}

.tile-drag-ghost, .tile-drag-ghost * {
  pointer-events: none !important;
}

.tile-drag-ghost {
  position: fixed !important;
  z-index: 99999 !important;
  transform: translate(-50%, -50%) scale(1.15) !important;
  box-shadow: 0 14px 35px rgba(0, 0, 0, 0.75), 0 0 25px rgba(168, 85, 247, 0.7) !important;
  transition: none !important;
  will-change: left, top;
}

.tile:hover {
  transform: translateY(-2px);
}

.tile.selected {
  outline: 3px solid var(--purple-light);
  transform: translateY(-4px);
  box-shadow: 0 6px 0 #bda582, 0 10px 20px rgba(168, 85, 247, 0.55);
}

.tile.tile-wild {
  color: #7c22ce;
}

.tile.tile-valid {
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.9),
    0 3px 0 #9333ea,
    0 0 0 2px var(--purple);
}

.tile.tile-invalid {
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.7),
    0 3px 0 #b55757,
    0 0 0 2px var(--danger);
}

.tile.tile-disconnected {
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.7),
    0 3px 0 #b78d4a,
    0 0 0 2px var(--amber);
}

.tile-pts {
  position: absolute;
  bottom: 3px;
  right: 5px;
  font-family: 'Inter', sans-serif;
  font-size: calc(var(--cell-size) * 0.21);
  font-weight: 800;
  line-height: 1;
  opacity: 0.85;
}

.tile-back {
  width: 52px;
  height: 54px;
  cursor: default;
  background: linear-gradient(135deg, #59258c 0%, #2f104f 100%);
  border: 2px solid #8e47db;
  box-shadow: 0 4px 0 #1c0830, 0 8px 14px rgba(0, 0, 0, 0.45);
}

.tile-back::after {
  content: "";
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 2px solid rgba(192, 132, 252, 0.45);
}

/* RACK & ACTION DOCK */
.rack-dock {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 12px 16px;
  background: linear-gradient(180deg, #30134f 0%, #1a0a2c 100%);
  border-top: 3px solid #552089;
  box-shadow: 0 -8px 24px rgba(0, 0, 0, 0.5);
  z-index: 15;
  flex-wrap: wrap;
}

.rack-controls-left, .rack-controls-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.player-rack {
  flex: 1;
  min-height: 60px;
  min-width: 240px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 7px;
  padding: 8px 14px;
  background: rgba(0, 0, 0, 0.32);
  border-radius: 12px;
  border: 1px solid rgba(192, 132, 252, 0.16);
}

.player-rack.drag-over {
  outline: 2px dashed var(--purple-light);
}

.rack-empty-hint {
  color: rgba(255, 255, 255, 0.5);
  font-size: 0.85rem;
  font-weight: 600;
}

.btn-callout {
  min-width: 190px;
  flex-direction: column;
  gap: 2px;
  padding: 10px 20px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.12);
}

.btn-callout span {
  font-family: 'Fredoka', sans-serif;
  font-size: 1.18rem;
  letter-spacing: 0.03em;
}

.btn-callout small {
  font-size: 0.72rem;
  font-weight: 600;
  opacity: 0.88;
}

.btn-callout.ready-take-two:not(:disabled) {
  background: linear-gradient(180deg, #c084fc 0%, #7e22ce 100%);
  color: #ffffff;
  box-shadow: 0 4px 0 #581c87, 0 0 26px rgba(168, 85, 247, 0.65);
  animation: bounceCallout 1.1s infinite;
}

.btn-callout.ready-stop:not(:disabled) {
  background: linear-gradient(180deg, #ffd466 0%, #e59312 100%);
  color: #241300;
  box-shadow: 0 4px 0 #9b6006, 0 0 28px rgba(245, 185, 66, 0.75);
  animation: bounceCallout 0.9s infinite;
}

@keyframes bounceCallout {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.03); }
}

/* MODALS */
.modal {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(10, 4, 18, 0.85);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
}

.modal-card {
  background: #1c0c33;
  border: 1px solid rgba(192, 132, 252, 0.22);
  border-radius: 20px;
  padding: 26px;
  max-width: 560px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 28px 65px rgba(0, 0, 0, 0.75);
}

.modal-wide {
  max-width: 880px;
}

.modal-head {
  text-align: center;
  margin-bottom: 16px;
}

.modal-head h2 {
  font-size: 2rem;
}

.final-alert-banner {
  background: linear-gradient(90deg, rgba(255, 152, 0, 0.24), rgba(255, 213, 79, 0.24));
  border: 1px solid var(--gold);
  color: #ffe29a;
  text-align: center;
  padding: 10px 14px;
  border-radius: 12px;
  margin-bottom: 16px;
  font-size: 0.95rem;
}

.round-modal-body {
  display: grid;
  grid-template-columns: 1.35fr 1fr;
  gap: 18px;
  align-items: start;
}

@media (max-width: 760px) {
  .round-modal-body {
    grid-template-columns: 1fr;
  }
}

.results-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.results-table th, .results-table td {
  padding: 10px 8px;
  text-align: left;
  border-bottom: 1px solid rgba(192, 132, 252, 0.12);
}

.results-table th {
  color: var(--text-muted);
  font-size: 0.76rem;
  text-transform: uppercase;
}

.tiny-tiles {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.tiny-tile {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 2px 6px;
  border-radius: 5px;
  background: var(--tile-bg);
  color: var(--tile-ink);
  font-weight: 800;
  font-size: 0.76rem;
}

.tiny-tile sub {
  font-size: 0.6rem;
  margin-left: 1px;
}

.winner-grid-preview-wrap {
  background: rgba(0, 0, 0, 0.3);
  border-radius: 14px;
  padding: 12px;
  border: 1px solid rgba(192, 132, 252, 0.14);
}

.winner-grid-preview-wrap h4 {
  font-size: 0.95rem;
  margin-bottom: 8px;
  color: var(--gold);
}

.winner-grid-preview {
  display: grid;
  gap: 2px;
  overflow: auto;
  max-height: 260px;
}

.preview-cell {
  width: 28px;
  height: 28px;
}

.preview-tile {
  width: 28px;
  height: 28px;
  border-radius: 5px;
  background: var(--tile-bg);
  color: var(--tile-ink);
  font-family: 'Fredoka', sans-serif;
  font-weight: 700;
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 0 #bda582;
}

.modal-footer {
  margin-top: 20px;
  display: flex;
  justify-content: center;
  gap: 12px;
}

.modal-wild-card {
  text-align: center;
  max-width: 440px;
}

.wild-letters {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 8px;
  margin: 16px 0;
}

.wild-btn {
  padding: 10px 0;
  border-radius: 8px;
  border: none;
  background: var(--tile-bg);
  color: var(--tile-ink);
  font-family: 'Fredoka', sans-serif;
  font-weight: 700;
  font-size: 1.05rem;
  cursor: pointer;
  box-shadow: 0 3px 0 #bda582;
}

.wild-btn:hover {
  background: #ecd9ff;
}

.modal-champ {
  text-align: center;
}

.trophy-icon {
  font-size: 3.8rem;
  margin-bottom: 8px;
}

.champ-standings {
  margin-top: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  text-align: left;
}

.rules-list {
  padding-left: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 0.92rem;
  line-height: 1.45;
}

.toast-container {
  position: fixed;
  bottom: 92px;
  right: 20px;
  z-index: 80;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast {
  background: rgba(30, 13, 54, 0.96);
  border: 1px solid var(--purple-light);
  color: #fff;
  padding: 10px 16px;
  border-radius: 12px;
  font-weight: 600;
  font-size: 0.9rem;
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.55);
}

/* STOPWATCH & LEADERBOARD */
.pill-timer {
  font-variant-numeric: tabular-nums;
  font-family: 'Inter', monospace;
  font-weight: 800;
  font-size: 0.9rem;
  padding: 5px 11px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid rgba(192, 132, 252, 0.2);
  color: #ded3ee;
}

.pill-timer.running {
  border-color: rgba(192, 132, 252, 0.6);
  color: #e9d5ff;
}

.round-time-line {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin: 6px 0 4px;
  padding: 4px 12px;
  border-radius: 999px;
  background: rgba(168, 85, 247, 0.18);
  border: 1px solid rgba(168, 85, 247, 0.4);
  color: #e9d5ff;
  font-size: 0.88rem;
  font-weight: 700;
}

.record-pill {
  background: linear-gradient(90deg, #ff9800, #ffd54f);
  color: #261400;
  font-size: 0.72rem;
  font-weight: 900;
  padding: 2px 8px;
  border-radius: 999px;
}

.leaderboard-card {
  margin-top: 22px;
}

.leaderboard-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 14px;
}

.leaderboard-head h3 {
  font-size: 1.25rem;
}

.leaderboard-head p {
  margin: 4px 0 0;
}

.leaderboard-controls {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
}

.lb-filter {
  font-size: 0.84rem;
  color: var(--text-muted);
}

.lb-tabs {
  display: inline-flex;
  background: rgba(0, 0, 0, 0.3);
  border-radius: 10px;
  padding: 3px;
  gap: 4px;
}

.lb-tab {
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-family: inherit;
  font-weight: 700;
  font-size: 0.8rem;
  padding: 6px 12px;
  border-radius: 8px;
  cursor: pointer;
}

.lb-tab.active {
  background: rgba(168, 85, 247, 0.25);
  color: #e9d5ff;
}

.lb-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.lb-table th, .lb-table td {
  padding: 9px 10px;
  border-bottom: 1px solid rgba(192, 132, 252, 0.12);
  text-align: left;
}

.lb-table th {
  font-size: 0.74rem;
  text-transform: uppercase;
  color: var(--text-muted);
}

.lb-rank {
  font-weight: 800;
  color: var(--gold);
  width: 44px;
}

.lb-time {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  color: #d8b4fe;
}

/* MOBILE RESPONSIVE ENHANCEMENTS */
@media (max-width: 768px) {
  :root {
    --cell-size: clamp(34px, 8.5vw, 44px);
  }

  .game-topbar {
    padding: 6px 8px;
    gap: 4px 6px;
    min-height: 44px;
    flex-wrap: wrap;
    justify-content: space-between;
    overflow: visible;
  }

  .topbar-left {
    gap: 5px;
    flex-wrap: wrap;
    flex-shrink: 1;
    min-width: 0;
    align-items: center;
  }

  .topbar-center {
    display: none !important;
  }

  .room-mini {
    display: none !important;
  }

  .topbar-right {
    gap: 5px;
    flex-wrap: nowrap;
    flex-shrink: 0;
    align-items: center;
    margin-left: auto;
  }

  .pill-round {
    padding: 3px 7px;
    font-size: 0.7rem;
    font-weight: 800;
    letter-spacing: 0.03em;
  }

  .pill-final {
    padding: 3px 7px;
    font-size: 0.68rem;
    max-width: 115px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .pill-timer {
    padding: 3px 7px;
    font-size: 0.72rem;
    font-weight: 800;
  }

  .pile-widget {
    padding: 3px 8px;
    gap: 5px;
  }

  .pile-label {
    display: none !important;
  }

  .pile-count {
    font-size: 0.76rem;
    font-weight: 700;
    white-space: nowrap;
  }

  .pile-icon {
    width: 13px;
    height: 14px;
  }

  .btn-icon {
    width: 32px;
    height: 32px;
    min-width: 32px;
    border-radius: 8px;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    padding: 0 !important;
  }

  .btn-icon svg {
    width: 16px;
    height: 16px;
    display: block;
    margin: auto;
  }

  .standings-panel {
    max-height: 52px;
    padding: 4px 8px;
  }

  .panel-head {
    display: none;
  }

  .standings-list {
    flex-direction: row !important;
    overflow-x: auto;
    gap: 6px;
    padding-bottom: 2px;
  }

  .standing-card {
    min-width: 125px;
    padding: 4px 8px;
    border-radius: 8px;
  }

  .standing-header {
    margin-bottom: 0;
  }

  .standing-name {
    font-size: 0.76rem;
  }

  .standing-score {
    font-size: 0.74rem;
  }

  .standing-body {
    display: none;
  }

  .board-toolbar {
    padding: 4px 8px;
    gap: 6px;
    flex-wrap: wrap;
  }

  .board-toolbar .btn {
    padding: 4px 8px;
    font-size: 0.74rem;
  }

  .validation-pill {
    font-size: 0.72rem;
    padding: 3px 8px;
    flex: 1 1 120px;
    min-width: 0;
    max-width: none;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .word-meanings-bar {
    flex-direction: column;
    align-items: stretch;
    gap: 5px;
    padding: 6px 10px;
    max-height: 92px;
    overflow-y: auto;
  }

  .word-meanings-chips {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 2px;
  }

  .word-chip {
    flex-shrink: 0;
  }

  .word-meanings-def {
    min-width: 0;
    width: 100%;
    font-size: 0.76rem;
    line-height: 1.3;
    word-break: break-word;
  }

  .rack-dock {
    padding: 6px 8px 10px;
    gap: 6px;
    flex-direction: column;
  }

  .rack-controls-left, .rack-controls-right {
    width: 100%;
    justify-content: space-between;
    gap: 6px;
  }

  .rack-controls-left .btn, .rack-controls-right .btn {
    padding: 5px 9px;
    font-size: 0.76rem;
  }

  .player-rack {
    width: 100%;
    min-height: 54px;
    padding: 4px 8px;
    overflow-x: auto;
    flex-wrap: nowrap;
    justify-content: flex-start;
    -webkit-overflow-scrolling: touch;
  }

  .btn-callout {
    width: 100%;
    min-width: auto;
    padding: 8px 12px;
  }

  .btn-callout span {
    font-size: 1.05rem;
  }

  .btn-callout small {
    font-size: 0.68rem;
  }

  .modal-card {
    padding: 14px;
    max-width: 95vw;
    max-height: 92dvh;
  }

  .modal-card h2 {
    font-size: 1.25rem;
    word-break: break-word;
  }

  .modal-champ .winner-grid-preview-wrap,
  .winner-grid-preview-wrap {
    padding: 8px;
    margin-top: 8px;
  }

  .winner-grid-preview {
    max-height: 180px;
  }

  .preview-cell,
  .preview-tile {
    width: 22px;
    height: 22px;
    font-size: 0.74rem;
  }

  .modal-footer {
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px;
  }

  .modal-footer .btn {
    flex: 1 1 auto;
    min-width: 110px;
  }
}

@media (max-width: 400px) {
  .btn-icon {
    width: 28px;
    height: 28px;
    min-width: 28px;
  }

  .btn-icon svg {
    width: 14px;
    height: 14px;
  }

  .pile-widget {
    padding: 2px 6px;
    gap: 4px;
  }

  .pile-count {
    font-size: 0.7rem;
  }
}

/* OPEN ROOMS SECTION */
.open-rooms-section {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid rgba(255, 255, 255, 0.12);
}

.open-rooms-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.open-rooms-header h3 {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--amber);
  margin: 0;
  letter-spacing: 0.3px;
}

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

.open-room-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  padding: 8px 12px;
  gap: 10px;
  transition: all 0.15s ease;
}

.open-room-item:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: var(--amber);
}

.open-room-meta {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.open-room-code {
  font-family: 'Fredoka', cursive, sans-serif;
  font-weight: 700;
  color: #fff;
  letter-spacing: 1.5px;
  font-size: 1.05rem;
}

.open-room-host {
  font-size: 0.75rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* WORD MEANINGS BAR */
.word-meanings-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 14px;
  background: rgba(20, 6, 38, 0.88);
  border-bottom: 1px solid rgba(192, 132, 252, 0.18);
  font-size: 0.82rem;
  flex-wrap: wrap;
}

.word-meanings-chips {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.word-chip {
  padding: 2px 8px;
  border-radius: 6px;
  background: rgba(16, 185, 129, 0.16);
  border: 1px solid rgba(16, 185, 129, 0.4);
  color: #6ee7b7;
  font-weight: 700;
  font-size: 0.74rem;
  letter-spacing: 0.5px;
  cursor: pointer;
  transition: all 0.12s ease;
}

.word-chip:hover,
.word-chip.active {
  background: rgba(16, 185, 129, 0.35);
  border-color: #34d399;
  color: #fff;
}

.word-meanings-def {
  color: #e9d5ff;
  font-size: 0.8rem;
  line-height: 1.35;
  flex: 1;
  min-width: 180px;
}

.word-meanings-def strong {
  color: var(--amber);
}

/* Scale tile text smoothly when zoomed out to fit whole grid on mobile */
.grid-cell .tile {
  font-size: clamp(0.68rem, calc(var(--cell-size) * 0.45), 1.35rem);
}
.grid-cell .tile .tile-pts {
  font-size: clamp(0.45rem, calc(var(--cell-size) * 0.2), 0.68rem);
}
