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

:root {
  --bg: #0f0f1a;
  --bg-surface: #1a1a2e;
  --bg-elevated: #232340;
  --board-bg: #12121f;
  --board-border: #2a2a45;
  --cell-bg: #1e1e35;
  --cell-border: #2a2a48;
  --tw: #8b2230;
  --tw-light: rgba(230,57,70,0.15);
  --dw: #7a2d5a;
  --dw-light: rgba(180,50,120,0.15);
  --tl: #2a3a7a;
  --tl-light: rgba(67,97,238,0.15);
  --dl: #1a6a7a;
  --dl-light: rgba(0,140,170,0.15);
  --tile-bg: #f0ead6;
  --tile-bg-end: #e4dcc8;
  --tile-border: #c8b888;
  --tile-shadow: #a89868;
  --accent: #00d2d3;
  --accent-glow: rgba(0,210,211,0.35);
  --accent-secondary: #0abde3;
  --text: #e8e8f0;
  --text-light: #8888a8;
  --text-dark: #3a2e1e;
  --glass-bg: rgba(26,26,46,0.75);
  --glass-border: rgba(255,255,255,0.08);
  --success: #00cec9;
  --danger: #e63946;
  --warning: #fdcb6e;
}

html, body {
  height: 100%;
  font-family: 'Outfit', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
  touch-action: pan-y;
  -webkit-user-select: none;
  user-select: none;
  -webkit-text-size-adjust: 100%;
}

.landscape-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: var(--bg);
  color: var(--text);
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  font-size: 1.2rem;
  text-align: center;
  padding: 2rem;
}
.landscape-overlay .rotate-icon { font-size: 3rem; }
@media (orientation: landscape) and (max-height: 500px) {
  .landscape-overlay { display: flex; }
  #app { display: none; }
}

#app {
  display: flex;
  flex-direction: column;
  align-items: center;
  height: var(--real-vh, 100dvh);
  max-width: 500px;
  margin: 0 auto;
  padding: calc(4px + env(safe-area-inset-top, 0px)) 4px calc(4px + env(safe-area-inset-bottom, 0px));
  gap: 2px;
}

/* Scoreboard */
#scoreboard {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 6px 12px;
  background: var(--bg-surface);
  border: 1px solid var(--glass-border);
  border-radius: 12px;
  color: var(--text);
  gap: 4px;
  flex-wrap: nowrap;
  min-height: 48px;
}

.game-title { font-weight: 700; font-size: 1rem; letter-spacing: 3px; opacity: 0.7; flex-shrink: 0; color: var(--accent); }
.game-title-sm { font-weight: 700; font-size: 0.7rem; letter-spacing: 2px; opacity: 0.5; flex-shrink: 0; color: var(--accent); }
.player { display: flex; flex-direction: column; align-items: center; gap: 1px; min-width: 0; flex: 1; }
.player-name { font-size: 0.65rem; opacity: 0.6; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.player-score { font-size: 1.2rem; font-weight: 700; }
.player.active {
  background: rgba(0,210,211,0.12);
  border-radius: 8px;
  padding: 4px 8px;
  box-shadow: 0 0 0 1.5px var(--accent), inset 0 0 12px rgba(0,210,211,0.08);
}
.player.active .player-score { color: var(--accent); }
.player.active .player-name { opacity: 1; font-weight: 600; }
.player.disconnected { opacity: 0.4; }

/* Turn indicator */
.turn-indicator { display: none !important; }

/* Message toast */
.message {
  position: fixed;
  top: 32px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.8rem;
  font-weight: 600;
  padding: 6px 14px;
  border-radius: 8px;
  text-align: center;
  z-index: 200;
  pointer-events: none;
  animation: toastIn 0.3s ease;
  white-space: nowrap;
  backdrop-filter: blur(12px);
}
.message.error { background: rgba(230,57,70,0.9); color: #fff; }
.message.info { background: rgba(0,210,211,0.9); color: #0f0f1a; }

@keyframes toastIn {
  from { transform: translate(-50%, -12px); opacity: 0; }
  to { transform: translate(-50%, 0); opacity: 1; }
}

/* Board */
#board-container {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 0;
  position: relative;
  overflow: hidden;
  touch-action: none;
}

#board-wrapper {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  transform-origin: center center;
  will-change: transform;
}

#board {
  display: grid;
  grid-template-columns: repeat(15, 1fr);
  grid-template-rows: repeat(15, 1fr);
  gap: 1.5px;
  aspect-ratio: 1;
  width: min(100%, calc(100dvh - 220px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px)));
  max-height: 100%;
  background: var(--board-border);
  border: 2px solid var(--board-border);
  border-radius: 8px;
  padding: 2px;
}

.cell {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--cell-bg);
  border-radius: 2px;
  font-size: clamp(5px, 1.4vw, 8px);
  font-weight: 600;
  color: rgba(255,255,255,0.18);
  line-height: 1;
  text-align: center;
  overflow: hidden;
}

.cell.tw { background: var(--tw); color: rgba(255,255,255,0.9); }
.cell.dw { background: var(--dw); color: rgba(255,255,255,0.9); }
.cell.tl { background: var(--tl); color: rgba(255,255,255,0.9); }
.cell.dl { background: var(--dl); color: rgba(255,255,255,0.9); }
.cell.center { background: var(--dw); color: rgba(255,255,255,0.9); }

.cell.center-hint-pulse { animation: centerPulse 2s ease-in-out infinite; }
@keyframes centerPulse {
  0%, 100% { box-shadow: inset 0 0 0 0 rgba(0,210,211,0); }
  50% { box-shadow: inset 0 0 10px 3px rgba(0,210,211,0.5); }
}

.cell-label {
  font-size: clamp(6px, 1.6vw, 9px);
  font-weight: 700;
  line-height: 1.1;
  pointer-events: none;
  text-shadow: 0 1px 2px rgba(0,0,0,0.5);
}
.cell.center .cell-label { font-size: clamp(8px, 2.5vw, 16px); }
.cell.drag-over { outline: 2px solid var(--accent); outline-offset: -2px; }
.cell.word-highlight { outline: 2px solid var(--warning); outline-offset: -1px; z-index: 5; }

/* Tiles */
.tile {
  position: absolute;
  inset: 1px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(145deg, var(--tile-bg), var(--tile-bg-end));
  border: 1px solid var(--tile-border);
  border-radius: 3px;
  box-shadow: 0 2px 4px rgba(0,0,0,0.4), inset 0 1px 0 rgba(255,255,255,0.5);
  cursor: grab;
  z-index: 10;
  touch-action: none;
}
.tile:active { cursor: grabbing; }
.tile.committed { cursor: default; }
.tile.pending {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent), 0 0 8px var(--accent-glow), 0 2px 4px rgba(0,0,0,0.4);
  animation: tileBounce 0.25s ease;
}
@keyframes tileBounce {
  0% { transform: scale(1.15); }
  50% { transform: scale(0.95); }
  100% { transform: scale(1); }
}
.tile.last-played { border-color: var(--success); box-shadow: 0 0 0 1px var(--success), 0 2px 4px rgba(0,0,0,0.4); }
.tile.ai-played { border-color: #4361ee; box-shadow: 0 0 0 1px #4361ee, 0 2px 4px rgba(0,0,0,0.4); background: linear-gradient(145deg, #e8f0fa, #d4e4f4); }
.tile.blank-tile { background: linear-gradient(145deg, #e0d8c8, #d0c8b8); }
.tile.blank-tile .tile-letter { color: #8b6914; font-style: italic; }
.tile.exchange-selected { border-color: var(--danger); box-shadow: 0 0 0 2px var(--danger); transform: translateY(-3px); }
.tile.score-glow { animation: scoreGlow 1.5s ease-out; }
@keyframes scoreGlow {
  0% { box-shadow: 0 0 16px 6px rgba(0,210,211,0.7); border-color: var(--accent); }
  100% { box-shadow: 0 2px 4px rgba(0,0,0,0.4); }
}

.tile-letter { font-size: clamp(8px, 2.5vw, 16px); font-weight: 700; color: var(--text-dark); line-height: 1; }
.tile-points { position: absolute; bottom: 1px; right: 2px; font-size: clamp(4px, 1vw, 7px); font-weight: 600; color: #7a6e5e; }

.tile-ghost {
  position: fixed;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 56px;
  height: 56px;
  background: linear-gradient(145deg, var(--tile-bg), var(--tile-bg-end));
  border: 2px solid var(--accent);
  border-radius: 10px;
  box-shadow: 0 8px 28px rgba(0,0,0,0.5), 0 0 20px var(--accent-glow);
  z-index: 1000;
  pointer-events: none;
  transform: translate(-50%, -110%) scale(1.5);
  transform-origin: center center;
}
.tile-ghost .tile-letter { font-size: 22px; font-weight: 700; color: var(--text-dark); }
.tile-ghost .tile-points { position: absolute; bottom: 2px; right: 4px; font-size: 9px; }

/* Rack */
#rack-container { width: 100%; display: flex; justify-content: center; padding: 0; }
#rack {
  display: flex;
  gap: 4px;
  padding: 8px 6px;
  background: var(--glass-bg);
  backdrop-filter: blur(16px);
  border: 1px solid var(--glass-border);
  border-radius: 12px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.3);
  width: 100%;
  justify-content: center;
}
.rack-slot {
  position: relative;
  width: 0;
  flex: 1;
  max-width: 52px;
  aspect-ratio: 1;
  background: rgba(255,255,255,0.04);
  border: 1px dashed rgba(255,255,255,0.1);
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.rack-slot .tile {
  inset: 2px;
  border-radius: 6px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.35), inset 0 1px 0 rgba(255,255,255,0.5);
}
.rack-slot .tile-letter { font-size: clamp(14px, 4vw, 22px); }
.rack-slot .tile-points { font-size: clamp(7px, 1.8vw, 10px); bottom: 3px; right: 4px; }
.rack-slot.drag-over { background: rgba(0,210,211,0.15); border-color: var(--accent); }

#exchange-hint { font-size: 0.75rem; color: var(--accent); font-weight: 600; text-align: center; }

/* Score preview */
#actions { position: relative; }
.score-preview {
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  margin-bottom: 4px;
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--bg);
  background: linear-gradient(135deg, var(--accent), var(--accent-secondary));
  padding: 4px 16px;
  border-radius: 14px;
  text-align: center;
  z-index: 100;
  pointer-events: none;
  white-space: nowrap;
  box-shadow: 0 2px 10px var(--accent-glow);
}

/* Actions */
#actions { display: flex; gap: 4px; width: 100%; justify-content: center; }
#actions-row2 { display: flex; gap: 6px; width: 100%; align-items: center; justify-content: center; padding-bottom: max(8px, env(safe-area-inset-bottom, 8px)); }
#tiles-remaining { font-size: 0.75rem; color: var(--text-light); }

.action-btn {
  padding: 8px 10px;
  border: none;
  border-radius: 10px;
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.1s, box-shadow 0.1s;
  flex: 1;
}
.action-btn:active { transform: scale(0.96); }
.action-btn.primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-secondary));
  color: var(--bg);
  box-shadow: 0 3px 12px var(--accent-glow);
}
.action-btn.secondary {
  background: var(--bg-elevated);
  color: var(--text);
  border: 1px solid var(--glass-border);
  box-shadow: 0 2px 6px rgba(0,0,0,0.2);
}

.words-toggle-btn { flex: none !important; padding: 6px 14px !important; font-size: 0.75rem !important; }
.mute-btn { flex: none !important; padding: 6px 10px !important; font-size: 0.9rem !important; min-width: 36px; }

.has-unread { position: relative; }
.has-unread::after {
  content: '';
  position: absolute;
  top: 4px;
  right: 4px;
  width: 8px;
  height: 8px;
  background: var(--danger);
  border-radius: 50%;
}

/* Zoom */
.zoom-indicator {
  position: absolute;
  top: 8px;
  right: 8px;
  background: rgba(0,0,0,0.8);
  color: var(--text);
  font-size: 0.75rem;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 6px;
  pointer-events: none;
  z-index: 50;
}
.reset-zoom-btn {
  position: absolute;
  bottom: 8px;
  right: 8px;
  background: rgba(0,0,0,0.7);
  color: var(--text);
  border: 1px solid var(--glass-border);
  font-family: inherit;
  font-size: 0.7rem;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 6px;
  cursor: pointer;
  z-index: 50;
}

/* Words Panel */
.words-panel {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  max-height: 50vh;
  background: var(--bg-surface);
  border-radius: 16px 16px 0 0;
  box-shadow: 0 -4px 24px rgba(0,0,0,0.5);
  z-index: 400;
  flex-direction: column;
  overflow: hidden;
  border-top: 1px solid var(--glass-border);
}
.words-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  font-weight: 700;
  font-size: 0.95rem;
  border-bottom: 1px solid var(--glass-border);
  flex-shrink: 0;
}
.words-close-btn { background: none; border: none; font-size: 1.2rem; cursor: pointer; color: var(--text-light); padding: 4px 8px; }
.words-list { overflow-y: auto; padding: 8px 16px 16px; flex: 1; }
.word-entry { padding: 8px 0; border-bottom: 1px solid rgba(255,255,255,0.05); }
.word-entry:last-child { border-bottom: none; }
.word-header { display: flex; align-items: center; gap: 8px; }
.word-text { font-weight: 700; font-size: 0.95rem; letter-spacing: 1px; }
.word-score { font-weight: 700; font-size: 0.8rem; color: var(--accent); }
.word-player { font-size: 0.7rem; font-weight: 600; padding: 1px 6px; border-radius: 4px; margin-left: auto; }
.word-player-you { background: rgba(0,206,201,0.15); color: var(--success); }
.word-player-cpu { background: rgba(67,97,238,0.15); color: #7c93f4; }
.word-sub-entry { display: flex; align-items: baseline; gap: 6px; margin-top: 4px; padding-left: 4px; flex-wrap: wrap; }
.word-sub-score { font-size: 0.75rem; font-weight: 600; color: var(--accent); flex-shrink: 0; }
.word-sub-entry .word-text { font-size: 0.88rem; }
.word-sub-entry .word-def { font-size: 0.73rem; color: var(--text-light); line-height: 1.3; width: 100%; }
.word-def { font-size: 0.78rem; color: var(--text-light); margin-top: 2px; line-height: 1.3; }

/* Chat Panel */
.chat-panel {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  max-height: 50vh;
  background: var(--bg-surface);
  border-radius: 16px 16px 0 0;
  box-shadow: 0 -4px 24px rgba(0,0,0,0.5);
  z-index: 400;
  flex-direction: column;
  overflow: hidden;
  border-top: 1px solid var(--glass-border);
}
.chat-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  font-weight: 700;
  font-size: 0.95rem;
  border-bottom: 1px solid var(--glass-border);
  flex-shrink: 0;
}
.chat-messages {
  overflow-y: auto;
  padding: 8px 16px;
  flex: 1;
  min-height: 100px;
  max-height: 30vh;
}
.chat-msg { font-size: 0.85rem; margin-bottom: 4px; line-height: 1.4; }
.chat-msg strong { color: var(--text); }
.chat-system { font-style: italic; color: var(--text-light); font-size: 0.78rem; }
.chat-input-row {
  display: flex;
  gap: 8px;
  padding: 8px 16px 12px;
  border-top: 1px solid var(--glass-border);
}
.chat-input {
  flex: 1;
  padding: 8px 12px;
  border: 1px solid var(--glass-border);
  border-radius: 8px;
  font-family: inherit;
  font-size: 0.85rem;
  outline: none;
  background: var(--bg-elevated);
  color: var(--text);
}
.chat-input:focus { border-color: var(--accent); }
.chat-send-btn {
  padding: 8px 16px;
  background: linear-gradient(135deg, var(--accent), var(--accent-secondary));
  color: var(--bg);
  border: none;
  border-radius: 8px;
  font-family: inherit;
  font-weight: 600;
  font-size: 0.85rem;
  cursor: pointer;
}

/* Score popup */
.score-popup {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.8);
  background: var(--bg-surface);
  border: 1px solid var(--glass-border);
  color: var(--text);
  padding: 16px 24px;
  border-radius: 14px;
  text-align: center;
  z-index: 500;
  opacity: 0;
  transition: opacity 0.3s, transform 0.3s;
  pointer-events: none;
  backdrop-filter: blur(12px);
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
}
.score-popup.show { opacity: 1; transform: translate(-50%, -50%) scale(1); }
.score-popup.fade { opacity: 0; transform: translate(-50%, -60%) scale(0.9); }
.score-points { font-size: 2rem; font-weight: 700; color: var(--accent); display: block; }
.score-words { font-size: 0.85rem; margin-top: 4px; opacity: 0.8; display: block; }
.score-bingo { font-size: 0.9rem; margin-top: 6px; color: #ff6b6b; font-weight: 700; display: block; }

/* Blank picker */
.blank-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.7); display: flex; align-items: center; justify-content: center; z-index: 600; backdrop-filter: blur(4px); }
.blank-dialog { background: var(--bg-surface); border: 1px solid var(--glass-border); border-radius: 14px; padding: 20px; max-width: 320px; width: 90%; text-align: center; color: var(--text); }
.blank-dialog h3 { margin-bottom: 12px; font-size: 1.1rem; }
.blank-letters { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; }
.blank-letter-btn {
  width: 38px; height: 38px; border: 1px solid var(--glass-border); border-radius: 8px;
  background: var(--bg-elevated); font-family: inherit; font-size: 1rem; font-weight: 700; cursor: pointer; color: var(--text);
}
.blank-letter-btn:hover { background: var(--accent); color: var(--bg); border-color: var(--accent); }

/* Game over */
.game-over-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.7); display: flex; align-items: center; justify-content: center; z-index: 700; backdrop-filter: blur(4px); }
.game-over-box { background: var(--bg-surface); border: 1px solid var(--glass-border); border-radius: 18px; padding: 28px; text-align: center; max-width: 340px; width: 90%; color: var(--text); }
.game-over-box h2 { font-size: 1.5rem; margin-bottom: 8px; }
.go-reason { font-size: 0.85rem; color: var(--text-light); margin-bottom: 12px; }
.go-scores { margin-bottom: 16px; }
.go-scores div { font-size: 1rem; margin: 4px 0; }
.penalty { color: var(--danger); font-size: 0.85rem; }
.game-over-box .action-btn { width: 100%; margin-top: 8px; }

/* Start Menu */
.start-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.8); display: flex; align-items: center; justify-content: center; z-index: 800; backdrop-filter: blur(8px); }
.start-box {
  background: var(--bg-surface); border: 1px solid var(--glass-border); border-radius: 22px; padding: 36px 32px; text-align: center;
  max-width: 360px; width: 90%; box-shadow: 0 20px 60px rgba(0,0,0,0.5); color: var(--text);
}
.start-title { font-size: 2.2rem; font-weight: 700; letter-spacing: 6px; color: var(--accent); margin-bottom: 4px; }
.start-sub { font-size: 0.85rem; color: var(--text-light); margin-bottom: 20px; }

.stats-mini { display: flex; justify-content: center; gap: 16px; margin-bottom: 20px; font-size: 0.85rem; font-weight: 600; color: var(--text-light); }

.start-buttons { display: flex; flex-direction: column; gap: 12px; }
.start-btn {
  width: 100%; padding: 14px; border: 1px solid var(--glass-border); border-radius: 12px;
  background: var(--bg-elevated); font-family: inherit; font-size: 1.05rem; font-weight: 700;
  cursor: pointer; transition: all 0.15s; color: var(--text);
}
.start-btn:hover { border-color: var(--accent); background: rgba(0,210,211,0.08); }

.ai-options, .mp-options { margin-top: 16px; }

.difficulty-select { margin-bottom: 20px; }
.difficulty-select label {
  display: block; font-size: 0.8rem; font-weight: 600; color: var(--text-light);
  margin-bottom: 10px; text-transform: uppercase; letter-spacing: 1px;
}
.diff-buttons { display: flex; gap: 8px; justify-content: center; }
.diff-btn {
  padding: 10px 20px; border: 1px solid var(--glass-border); border-radius: 10px;
  background: var(--bg-elevated); font-family: inherit; font-size: 0.9rem; font-weight: 600; cursor: pointer; flex: 1; color: var(--text);
}
.diff-btn:hover { border-color: var(--accent); }
.diff-btn.selected { background: linear-gradient(135deg, var(--accent), var(--accent-secondary)); color: var(--bg); border-color: transparent; }

.start-play-btn {
  width: 100%; padding: 14px; border: none; border-radius: 12px;
  background: linear-gradient(135deg, var(--accent), var(--accent-secondary)); color: var(--bg);
  font-family: inherit; font-size: 1.1rem; font-weight: 700; cursor: pointer;
  box-shadow: 0 4px 16px var(--accent-glow); margin-top: 12px;
}
.start-play-btn:active { transform: scale(0.97); }

.start-back-btn {
  width: 100%; padding: 10px; border: none; border-radius: 8px;
  background: transparent; color: var(--text-light); font-family: inherit;
  font-size: 0.85rem; font-weight: 600; cursor: pointer; margin-top: 8px;
}
.start-back-btn:hover { color: var(--text); }

.name-input, .room-input {
  width: 100%; padding: 12px; border: 1px solid var(--glass-border); border-radius: 10px;
  font-family: inherit; font-size: 1rem; text-align: center; margin-bottom: 12px; outline: none;
  background: var(--bg-elevated); color: var(--text);
}
.name-input:focus, .room-input:focus { border-color: var(--accent); }
.name-input::placeholder, .room-input::placeholder { color: var(--text-light); }

.mp-join-section { margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--glass-border); }

.ai-stats { margin-bottom: 16px; }
.ai-stat-row { display: flex; justify-content: space-between; font-size: 0.8rem; color: var(--text-light); padding: 2px 0; }
.ai-stat-diff { text-transform: capitalize; font-weight: 600; }

.mp-create-options { margin-top: 12px; }
.mp-create-options label { display: block; font-size: 0.8rem; font-weight: 600; color: var(--text-light); margin-bottom: 8px; }

/* Lobby */
.lobby-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.8); display: flex; align-items: center; justify-content: center; z-index: 800; backdrop-filter: blur(8px); }
.lobby-box {
  background: var(--bg-surface); border: 1px solid var(--glass-border); border-radius: 22px; padding: 32px; text-align: center;
  max-width: 360px; width: 90%; box-shadow: 0 20px 60px rgba(0,0,0,0.5); color: var(--text);
}
.lobby-box h2 { font-size: 1.3rem; margin-bottom: 12px; }
.lobby-code { color: var(--accent); letter-spacing: 3px; font-size: 1.5rem; }
.lobby-link-row { display: flex; gap: 8px; margin-bottom: 16px; }
.lobby-link {
  flex: 1; padding: 8px; border: 1px solid var(--glass-border); border-radius: 8px;
  font-family: inherit; font-size: 0.75rem; color: var(--text-light); text-align: center;
  background: var(--bg-elevated);
}
.lobby-copy-btn {
  padding: 8px 12px; border: 1px solid var(--glass-border); border-radius: 8px;
  background: var(--bg-elevated); cursor: pointer; font-size: 1rem;
}
.lobby-copy-btn:hover { background: var(--bg-surface); }
.lobby-players { margin-bottom: 16px; text-align: left; }
.lobby-player {
  display: flex; align-items: center; gap: 8px; padding: 8px 12px;
  background: var(--bg-elevated); border-radius: 8px; margin-bottom: 6px; font-weight: 600;
}
.lobby-player.disconnected { opacity: 0.4; }
.lobby-player-num { color: var(--text-light); font-size: 0.85rem; }
.lobby-host { font-size: 0.85rem; }
.lobby-dc { font-size: 0.7rem; color: var(--danger); margin-left: auto; }
.lobby-waiting { font-size: 0.85rem; color: var(--text-light); margin-bottom: 16px; }
.lobby-start-btn { margin-bottom: 8px; }
.lobby-leave-btn { width: 100%; }

/* Confetti canvas */
.confetti-canvas {
  position: fixed;
  inset: 0;
  z-index: 650;
  pointer-events: none;
}

/* Responsive tweaks */
@media (max-height: 700px) {
  #app { padding: 2px 4px 4px; gap: 1px; }
  #scoreboard { padding: 3px 8px; min-height: 40px; }
  .player-score { font-size: 1rem; }
  #rack { gap: 3px; padding: 5px 4px; }
  .action-btn { padding: 7px 6px; font-size: 0.75rem; }
  #actions-row2 { gap: 4px; }
}

@media (max-width: 360px) {
  .start-box { padding: 24px 20px; }
  .start-title { font-size: 1.8rem; letter-spacing: 4px; }
  .diff-btn { padding: 8px 12px; font-size: 0.8rem; }
}

/* Word validity highlighting */
.cell.word-valid { outline: 2px solid var(--success); outline-offset: -1px; z-index: 5; }
.cell.word-invalid { outline: 2px solid var(--danger); outline-offset: -1px; z-index: 5; }

/* Board score tag */
.board-score-tag {
  position: absolute;
  font-size: 0.75rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 8px;
  z-index: 60;
  pointer-events: none;
  white-space: nowrap;
  box-shadow: 0 2px 8px rgba(0,0,0,0.4);
  animation: tagFadeIn 0.2s ease;
}
.board-score-tag.tag-valid { background: var(--success); color: var(--bg); }
.board-score-tag.tag-invalid { background: var(--danger); color: #fff; }
@keyframes tagFadeIn {
  from { opacity: 0; transform: translateY(-50%) scale(0.8); }
  to { opacity: 1; transform: translateY(-50%) scale(1); }
}

/* My Games Section */
.my-games-section { margin-bottom: 16px; width: 100%; }
.my-games-header {
  font-size: 0.9rem; font-weight: 700; color: var(--text);
  margin-bottom: 8px; text-align: left;
}
.my-games-list { display: flex; flex-direction: column; gap: 8px; max-height: 200px; overflow-y: auto; }
.my-game-card {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--bg-elevated); border: 1px solid var(--glass-border); border-radius: 10px;
  padding: 10px 12px; cursor: pointer; transition: all 0.15s;
}
.my-game-card:hover { border-color: var(--accent); }
.my-game-card.my-turn { border-color: var(--success); background: rgba(0,206,201,0.06); }
.my-game-info { display: flex; flex-direction: column; gap: 2px; min-width: 0; flex: 1; }
.my-game-opponent { font-size: 0.85rem; font-weight: 700; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.my-game-score { font-size: 0.75rem; color: var(--text-light); font-weight: 600; }
.my-game-turn { font-size: 0.7rem; font-weight: 600; }
.my-game-actions { display: flex; gap: 6px; align-items: center; flex-shrink: 0; margin-left: 8px; }
.my-game-resume {
  padding: 6px 14px; border: none; border-radius: 8px;
  background: linear-gradient(135deg, var(--accent), var(--accent-secondary)); color: var(--bg);
  font-family: inherit; font-size: 0.8rem; font-weight: 700; cursor: pointer;
}
.my-game-resume:active { transform: scale(0.96); }
.my-game-abandon {
  padding: 6px 8px; border: 1px solid var(--glass-border); border-radius: 8px;
  background: var(--bg-elevated); color: var(--danger); font-size: 0.85rem; cursor: pointer;
  font-family: inherit; font-weight: 600;
}
.my-game-abandon:hover { background: rgba(230,57,70,0.1); border-color: var(--danger); }
