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

:root {
  --bg-color: #ddd6cb;
  --card-bg: #ece6dc;
  --accent: #7a6245;
  --accent-hover: #937a5c;
  --text: #3a3530;
  --text-muted: #8a8078;
  --tile-bg: #1a1a1a;
  --cell-bg: rgba(0, 0, 0, 0.04);
  --cell-border: rgba(139, 119, 101, 0.25);
  --btn-secondary-bg: #c9bfb2;
  --btn-secondary-hover: #b8ad9e;
  --btn-small-bg: #c9bfb2;
  --btn-small-hover: #b8ad9e;
  --input-border: #b8ad9e;
  --tile-size: 50px;
  --cell-size: 54px;

  /* Gradients */
  --gradient-primary: linear-gradient(135deg, var(--accent), var(--accent-hover));
  --gradient-bg: radial-gradient(ellipse at 50% 0%, rgba(122,98,69,0.08) 0%, transparent 70%);

  /* Shadows */
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.08), 0 2px 4px rgba(0,0,0,0.04);
  --shadow-lg: 0 12px 40px rgba(0,0,0,0.12), 0 4px 12px rgba(0,0,0,0.06);
  --shadow-glow: 0 0 20px rgba(122,98,69,0.25);

  /* Glass */
  --glass-bg: rgba(236,230,220,0.7);
  --glass-border: rgba(255,255,255,0.3);
  --glass-blur: 12px;

  /* Transitions */
  --transition-fast: 0.15s ease;
  --transition-normal: 0.25s ease;
  --transition-slow: 0.4s cubic-bezier(0.16, 1, 0.3, 1);

  /* Border Radius */
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 24px;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg-color);
  background-image: var(--gradient-bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

.screen {
  width: 100%;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 20px 0;
  position: relative;
}

#lobby {
  justify-content: flex-start;
  padding-top: 0;
}

/* ======================== */
/* Navbar                   */
/* ======================== */
.navbar {
  position: sticky;
  top: 0;
  width: 100%;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 20px;
  background: var(--glass-bg);
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
  border-bottom: 1px solid var(--glass-border);
  box-shadow: var(--shadow-sm);
  z-index: 100;
  flex-shrink: 0;
}

.nav-logo {
  font-size: 22px;
  font-weight: 800;
  text-decoration: none;
  color: var(--accent);
  letter-spacing: -0.5px;
  flex-shrink: 0;
}

.nav-links {
  display: flex;
  gap: 4px;
  margin-left: 12px;
}

.nav-link {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-muted);
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  transition: color var(--transition-fast), background var(--transition-fast);
}

.nav-link:hover {
  color: var(--text);
  background: rgba(0,0,0,0.05);
}

.nav-right {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
}

.nav-lang {
  display: flex;
  gap: 4px;
}

/* User menu in navbar */
.nav-user-menu {
  position: relative;
}

.nav-avatar-btn {
  background: none;
  border: 2px solid transparent;
  border-radius: 50%;
  cursor: pointer;
  padding: 2px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color var(--transition-fast);
}

.nav-avatar-btn:hover {
  border-color: var(--accent);
}

.nav-avatar-placeholder {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
}

.nav-avatar-btn .avatar-tiny {
  width: 28px;
  height: 28px;
}

.nav-dropdown {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  background: var(--card-bg);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  min-width: 140px;
  overflow: hidden;
  z-index: 200;
}

.nav-dropdown-item {
  display: block;
  width: 100%;
  padding: 10px 16px;
  background: none;
  border: none;
  text-align: left;
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
  cursor: pointer;
  transition: background var(--transition-fast);
}

.nav-dropdown-item:hover {
  background: rgba(0,0,0,0.06);
}

.nav-login-link {
  font-weight: 600;
  color: var(--accent);
}

.nav-login-link:hover {
  color: var(--accent-hover);
}

/* Language switcher — now inline in navbar */
.language-switcher {
  display: flex;
  gap: 4px;
}

.lang-flag {
  background: none;
  border: 2px solid transparent;
  border-radius: 4px;
  cursor: pointer;
  padding: 2px;
  line-height: 0;
  opacity: 0.5;
  transition: opacity var(--transition-fast), border-color var(--transition-fast);
}

.lang-flag svg {
  display: block;
  border-radius: 2px;
}

.lang-flag:hover {
  opacity: 0.8;
}

.lang-flag.active {
  opacity: 1;
  border-color: var(--accent);
}

.screen-enter {
  animation: screenFadeIn 0.3s ease;
}

@keyframes screenFadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* Game screen stays fixed — has its own internal scrolling */
#gameScreen {
  height: 100vh;
  min-height: 0;
  overflow: hidden;
  padding: 10px;
}

.hidden {
  display: none !important;
}

/* Buttons */
.btn {
  padding: 12px 24px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 16px;
  cursor: pointer;
  transition: transform var(--transition-fast), box-shadow var(--transition-fast), background var(--transition-fast);
  font-weight: 600;
}

.btn-primary {
  background: var(--gradient-primary);
  color: #faf5ef;
  box-shadow: var(--shadow-sm);
}

.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-glow);
}

.btn-secondary {
  background: rgba(255,255,255,0.4);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid var(--glass-border);
  color: var(--text);
}

.btn-secondary:hover {
  background: rgba(255,255,255,0.6);
  transform: translateY(-1px);
}

.btn-small {
  padding: 8px 16px;
  font-size: 14px;
  font-weight: 500;
  background: var(--btn-small-bg);
  color: var(--text);
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background var(--transition-fast), transform var(--transition-fast);
}

.btn-small:hover {
  background: var(--btn-small-hover);
  transform: translateY(-1px);
}

.btn-icon {
  background: none;
  border: none;
  font-size: 20px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
  transition: background 0.2s;
}

.btn-icon:hover {
  background: rgba(0, 0, 0, 0.08);
}

.btn-danger {
  padding: 12px 24px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 16px;
  cursor: pointer;
  font-weight: 600;
  background: linear-gradient(135deg, #c0392b, #e74c3c);
  color: white;
  transition: transform var(--transition-fast), box-shadow var(--transition-fast);
  box-shadow: var(--shadow-sm);
}

.btn-danger:hover {
  transform: translateY(-2px);
  box-shadow: 0 0 20px rgba(192,57,43,0.3);
}

.abort-btn {
  color: var(--text-muted);
  font-size: 16px;
}

.abort-btn:hover {
  color: #e74c3c;
  background: rgba(231, 76, 60, 0.15);
}

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

/* Input type password */
input[type="password"] {
  width: 100%;
  padding: 12px;
  border: 1.5px solid rgba(0,0,0,0.1);
  border-radius: var(--radius-md);
  background: rgba(255,255,255,0.5);
  color: var(--text);
  font-size: 16px;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

input[type="password"]:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(122,98,69,0.15);
}

/* Auth Section */
.auth-section {
  background: var(--glass-bg);
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
  border: 1px solid var(--glass-border);
  box-shadow: var(--shadow-lg);
  padding: 24px;
  border-radius: var(--radius-xl);
  width: 400px;
  max-width: 90vw;
  margin-top: 32px;
  margin-bottom: 16px;
}

.auth-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 20px;
  border-radius: 50px;
  background: rgba(0,0,0,0.05);
  padding: 4px;
}

.auth-tab {
  flex: 1;
  padding: 10px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 15px;
  font-weight: 600;
  transition: all var(--transition-normal);
  border-radius: 50px;
}

.auth-tab.active {
  background: var(--gradient-primary);
  color: white;
  box-shadow: var(--shadow-sm);
}

.auth-form .input-group {
  margin-bottom: 12px;
}

.auth-divider {
  text-align: center;
  color: var(--text-muted);
  margin-top: 16px;
  font-size: 14px;
  position: relative;
}

.auth-divider::before,
.auth-divider::after {
  content: '';
  position: absolute;
  top: 50%;
  width: 30%;
  height: 1px;
  background: var(--input-border);
}

.auth-divider::before { left: 0; }
.auth-divider::after { right: 0; }

/* User Info Bar */
.user-info-bar {
  display: none;
}

.user-display-name {
  font-weight: 600;
  flex: 1;
}

/* Avatar Sizes */
.avatar-tiny {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}

.avatar-small {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}

.avatar-large {
  width: 96px;
  height: 96px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}

.avatar-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--btn-small-bg);
  color: var(--text-muted);
  font-size: 32px;
  font-weight: bold;
}

/* Profile Modal */
.profile-modal-content {
  text-align: left;
  max-width: 500px;
  width: 90vw;
  max-height: 80vh;
  overflow-y: auto;
}

/* Rules modal */
.rules-modal-content {
  text-align: left;
  max-width: 500px;
  width: 90vw;
  max-height: 80vh;
  overflow-y: auto;
}

.rules-section {
  margin-bottom: 16px;
}

.rules-section h4 {
  font-size: 15px;
  font-weight: 700;
  margin-bottom: 4px;
  color: var(--accent);
}

.rules-section p {
  font-size: 14px;
  line-height: 1.5;
  color: var(--text-muted);
}

.profile-header {
  display: flex;
  gap: 20px;
  align-items: flex-start;
  margin-bottom: 20px;
}

.profile-avatar-wrapper {
  position: relative;
}

.avatar-edit-btn {
  position: absolute;
  bottom: 0;
  right: 0;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid var(--card-bg);
  background: var(--accent);
  color: white;
  font-size: 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

.profile-info {
  flex: 1;
}

.profile-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 20px;
}

.stat-card {
  background: rgba(0, 0, 0, 0.06);
  padding: 12px;
  border-radius: 8px;
  text-align: center;
}

.stat-value {
  font-size: 24px;
  font-weight: bold;
  color: var(--accent);
}

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

/* Match History */
.match-history-list {
  max-height: 250px;
  overflow-y: auto;
}

.match-history-entry {
  background: rgba(0, 0, 0, 0.06);
  padding: 10px 12px;
  border-radius: 8px;
  margin-bottom: 6px;
  font-size: 13px;
}

.match-history-entry .match-date {
  color: var(--text-muted);
  font-size: 11px;
}

.match-history-entry .match-players {
  margin-top: 4px;
}

.match-history-entry .match-player {
  display: flex;
  justify-content: space-between;
  padding: 2px 0;
}

.match-history-entry .match-player.self {
  font-weight: bold;
  color: var(--accent);
}

.match-history-entry .match-player.winner {
  color: #a08030;
}

/* Avatar Upload Modal */
.avatar-upload-area {
  margin: 16px 0;
  text-align: center;
}

.cropper-container {
  width: 100%;
  max-height: 300px;
  margin-top: 12px;
  overflow: hidden;
}

.cropper-container img {
  display: block;
  max-width: 100%;
}

/* Player bar avatar */
.player-info .avatar-tiny {
  margin-bottom: 2px;
}

/* Lobby */
/* Lobby greeting */
.lobby-greeting {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-top: 32px;
  margin-bottom: 28px;
}

.avatar-greeting {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
  border: 2px solid var(--glass-border);
  box-shadow: var(--shadow-sm);
}

.avatar-greeting.avatar-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--accent);
  color: #fff;
  font-size: 20px;
  font-weight: 700;
}

.greeting-text {
  font-size: 18px;
  color: var(--text-muted);
}

.greeting-text strong {
  color: var(--text);
}

.lobby-container {
  background: var(--glass-bg);
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
  border: 1px solid var(--glass-border);
  box-shadow: var(--shadow-lg);
  padding: 40px;
  border-radius: var(--radius-xl);
  width: 400px;
  max-width: 90vw;
}

.input-group {
  margin-bottom: 24px;
}

.input-group label {
  display: block;
  margin-bottom: 8px;
  color: var(--text-muted);
  font-weight: 500;
}

input[type="text"],
select {
  width: 100%;
  padding: 12px;
  border: 1.5px solid rgba(0,0,0,0.1);
  border-radius: var(--radius-md);
  background: rgba(255,255,255,0.5);
  color: var(--text);
  font-size: 16px;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

input[type="text"]:focus,
select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(122,98,69,0.15);
}

.lobby-actions {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.divider {
  text-align: center;
  color: var(--text-muted);
}

.join-section {
  display: flex;
  gap: 8px;
}

.join-section input {
  flex: 1;
  text-transform: uppercase;
}

/* Lobby Game List */
.lobby-list-section {
  width: 400px;
  max-width: 90vw;
  margin-top: 24px;
}

.lobby-list-section h3 {
  color: var(--text-muted);
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 12px;
}

.lobby-game-list {
  max-height: 300px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.lobby-game-card {
  background: var(--glass-bg);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid var(--glass-border);
  border-left: 3px solid var(--accent);
  box-shadow: var(--shadow-sm);
  padding: 14px 18px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  transition: transform var(--transition-fast), box-shadow var(--transition-fast);
  cursor: pointer;
  animation: fadeInUp 0.3s ease backwards;
}

.lobby-game-card:nth-child(1) { animation-delay: 0s; }
.lobby-game-card:nth-child(2) { animation-delay: 0.05s; }
.lobby-game-card:nth-child(3) { animation-delay: 0.05s; }
.lobby-game-card:nth-child(4) { animation-delay: 0.1s; }
.lobby-game-card:nth-child(5) { animation-delay: 0.15s; }
.lobby-game-card:nth-child(6) { animation-delay: 0.2s; }

.lobby-game-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

.lobby-game-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
  min-width: 0;
}

.lobby-game-code {
  font-weight: bold;
  font-size: 14px;
  color: var(--accent);
  letter-spacing: 2px;
}

.lobby-game-details {
  font-size: 13px;
  color: var(--text-muted);
}

.lobby-empty {
  text-align: center;
  color: var(--text-muted);
  padding: 20px;
  font-size: 14px;
}

.lobby-join-btn {
  padding: 8px 18px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  background: var(--gradient-primary);
  color: #faf5ef;
  transition: transform var(--transition-fast), box-shadow var(--transition-fast);
  white-space: nowrap;
  flex-shrink: 0;
  box-shadow: var(--shadow-sm);
}

.lobby-join-btn:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-glow);
}

/* Waiting Room */
/* ======================== */
/* Waiting Room             */
/* ======================== */
#waitingRoom {
  gap: 0;
  justify-content: flex-start;
  padding-top: 0;
}

.navbar-waitingroom {
  margin-bottom: 0;
}

.btn-nav-action {
  padding: 8px 18px;
  font-size: 14px;
}

.wr-content {
  width: 100%;
  max-width: 800px;
  padding: 24px 20px 40px;
  display: flex;
  flex-direction: column;
  gap: 24px;
  margin: 0 auto;
}

/* Code section */
.wr-code-section {
  text-align: center;
}

.game-code-display {
  font-size: 28px;
  background: var(--glass-bg);
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
  border: 1px solid var(--glass-border);
  box-shadow: var(--shadow-md);
  padding: 16px 28px;
  border-radius: var(--radius-lg);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  flex-wrap: wrap;
}

.game-code-display span {
  color: var(--accent);
  font-weight: bold;
  letter-spacing: 4px;
  font-family: 'Inter', monospace;
}

.code-actions {
  display: flex;
  gap: 6px;
}

.wr-share-hint {
  color: var(--text-muted);
  font-size: 13px;
  margin-top: 8px;
}

/* Two-column grid */
.wr-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  align-items: start;
}

.wr-panel-title {
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-muted);
  margin-bottom: 14px;
}

/* Players panel */
.wr-players-panel {
  background: var(--glass-bg);
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
  border: 1px solid var(--glass-border);
  box-shadow: var(--shadow-sm);
  border-radius: var(--radius-lg);
  padding: 20px;
}

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

.player-card {
  background: rgba(255,255,255,0.35);
  border: 1px solid var(--glass-border);
  box-shadow: var(--shadow-sm);
  padding: 12px 16px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  gap: 12px;
  transition: transform var(--transition-fast), box-shadow var(--transition-fast);
}

.player-card:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

.player-card.current {
  border: 2px solid var(--accent);
  background: rgba(122,98,69,0.08);
}

.player-card .avatar-small {
  flex-shrink: 0;
}

.player-card-name {
  font-weight: 600;
  font-size: 15px;
  flex: 1;
}

.player-card-badge {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 99px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.player-card-badge.badge-creator {
  background: rgba(122,98,69,0.15);
  color: var(--accent);
}

.player-card-badge.badge-bot {
  background: rgba(52,152,219,0.12);
  color: #2980b9;
}

.player-card-badge.badge-you {
  background: rgba(46,204,113,0.12);
  color: #27ae60;
}

/* Empty slot */
.player-card.empty-slot {
  border: 2px dashed rgba(0,0,0,0.12);
  background: transparent;
  box-shadow: none;
  justify-content: center;
  color: var(--text-muted);
  font-size: 13px;
  padding: 12px 16px;
  opacity: 0.6;
}

.player-card.empty-slot:hover {
  transform: none;
  box-shadow: none;
}

.empty-slot-icon {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 2px dashed rgba(0,0,0,0.15);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 18px;
  flex-shrink: 0;
}

/* Add Bot section */
.wr-add-bot {
  margin-top: 12px;
  display: flex;
  gap: 8px;
  align-items: center;
}

.wr-add-bot select {
  width: auto;
  min-width: 100px;
  padding: 8px 12px;
  font-size: 13px;
  flex-shrink: 0;
}

.wr-add-bot-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  font-size: 13px;
  flex: 1;
  justify-content: center;
}

.wr-bot-icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

.waiting-info {
  color: var(--text-muted);
  font-size: 13px;
  margin-top: 12px;
  animation: waitingPulse 2s ease-in-out infinite;
}

@keyframes waitingPulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

/* Settings panel */
.wr-settings-panel .match-settings {
  background: var(--glass-bg);
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
  border: 1px solid var(--glass-border);
  box-shadow: var(--shadow-sm);
  border-radius: var(--radius-lg);
  padding: 20px;
  min-width: 0;
}

.match-settings {
  background: var(--glass-bg);
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
  border: 1px solid var(--glass-border);
  box-shadow: var(--shadow-md);
  padding: 20px 30px;
  border-radius: var(--radius-lg);
  min-width: 0;
}

.match-settings h3 {
  margin-bottom: 16px;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
  gap: 12px;
}

.settings-row:last-child {
  margin-bottom: 0;
}

.settings-row label {
  color: var(--text);
  white-space: nowrap;
  font-size: 14px;
}

.settings-row select {
  width: auto;
  min-width: 130px;
}

/* Start button */
.wr-start-btn {
  width: 100%;
  padding: 16px;
  font-size: 18px;
  letter-spacing: 0.5px;
}

.settings-row input[type="checkbox"] {
  width: 20px;
  height: 20px;
  accent-color: var(--accent);
}

/* Game Screen overrides */
#gameScreen {
  justify-content: flex-start;
  gap: 0;
  position: relative;
}

/* ========================
   Game Header
   ======================== */
.game-header {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 16px;
  background: var(--glass-bg);
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-md);
  position: relative;
}

.players-bar {
  display: flex;
  gap: 12px;
  overflow-x: auto;
  flex: 1;
}

.player-info {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 6px 14px;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.05);
  flex-shrink: 0;
}

.player-info.active {
  background: var(--accent);
  color: #faf5ef;
  box-shadow: 0 0 0 2px var(--accent), var(--shadow-glow);
}

.player-info.disconnected {
  opacity: 0.5;
}

.player-name {
  font-weight: bold;
  font-size: 13px;
}

.player-score {
  font-size: 20px;
  color: var(--accent);
}

.player-info.active .player-score {
  color: #faf5ef;
}

.player-tiles {
  font-size: 11px;
  color: var(--text-muted);
}

.player-info.active .player-tiles {
  color: rgba(250, 245, 239, 0.7);
}

/* ========================
   3-Dot Menu Dropdown
   ======================== */
.header-menu {
  position: relative;
  flex-shrink: 0;
}

.menu-trigger {
  background: none;
  border: none;
  font-size: 24px;
  cursor: pointer;
  padding: 6px 10px;
  border-radius: 8px;
  color: var(--text-muted);
  transition: background 0.15s;
  line-height: 1;
}

.menu-trigger:hover {
  background: rgba(0, 0, 0, 0.08);
  color: var(--text);
}

.header-dropdown {
  display: none;
  position: absolute;
  top: 100%;
  right: 0;
  margin-top: 6px;
  background: var(--glass-bg);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  z-index: 200;
  min-width: 200px;
  padding: 6px;
  animation: dropdownFade 0.15s ease;
}

.header-dropdown.open {
  display: block;
}

@keyframes dropdownFade {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: translateY(0); }
}

.dropdown-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 14px;
  border: none;
  background: none;
  border-radius: 6px;
  font-size: 14px;
  color: var(--text);
  cursor: pointer;
  transition: background 0.12s;
  text-align: left;
}

.dropdown-item:hover {
  background: rgba(0, 0, 0, 0.06);
}

.dropdown-item.danger {
  color: #c0392b;
}

.dropdown-item.danger:hover {
  background: rgba(192, 57, 43, 0.08);
}

.dropdown-icon {
  font-size: 16px;
  width: 20px;
  text-align: center;
  flex-shrink: 0;
}

.dropdown-divider {
  height: 1px;
  background: rgba(139, 119, 101, 0.15);
  margin: 4px 8px;
}

/* ========================
   Turn Banner
   ======================== */
.turn-banner {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 8px 16px;
  border-radius: 8px;
  margin: 6px 0;
  font-size: 15px;
  font-weight: 600;
  transition: background 0.2s;
}

.turn-banner.my-turn {
  background: rgba(122, 98, 69, 0.12);
  color: var(--accent);
}

.turn-banner.other-turn {
  background: rgba(0, 0, 0, 0.04);
  color: var(--text-muted);
}

.turn-banner .bag-count {
  font-weight: 400;
  font-size: 13px;
  color: var(--text-muted);
}

/* Turn Timer */
.turn-timer {
  font-weight: bold;
  font-size: 16px;
  color: var(--text);
}

.turn-timer.timer-warning {
  color: #c0392b;
  animation: timerBlink 0.5s infinite alternate;
}

@keyframes timerBlink {
  from { opacity: 1; }
  to { opacity: 0.4; }
}

/* Board */
.game-container {
  flex: 1;
  width: 100%;
  overflow: hidden;
  position: relative;
  padding-bottom: 90px;
}

.board-wrapper {
  width: 100%;
  height: 100%;
  overflow: auto;
  position: relative;
  touch-action: pan-x pan-y;
  -webkit-overflow-scrolling: touch;
}

.board {
  display: grid;
  gap: 2px;
  padding: 20px;
  min-width: max-content;
  min-height: max-content;
  position: relative;
  transform-origin: 0 0;
}

.cell {
  width: var(--cell-size);
  height: var(--cell-size);
  background: var(--cell-bg);
  border: 1px solid var(--cell-border);
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: manipulation;
  contain: layout style;
  box-shadow: inset 0 1px 3px rgba(0,0,0,0.06);
}

.cell.valid-drop {
  background: rgba(122, 98, 69, 0.15);
  border-color: var(--accent);
}

.cell.drag-over {
  background: rgba(122, 98, 69, 0.3);
  transform: scale(1.05);
  transition: transform 0.15s, background 0.15s;
}

.cell.placed-this-turn {
  box-shadow: 0 0 10px var(--accent);
}

.cell.opponent-placed {
  box-shadow: 0 0 8px 2px rgba(0, 0, 0, 0.1);
  border-color: rgba(139, 119, 101, 0.5);
  z-index: 5;
  position: relative;
}

/* Opponent color borders — only on current turn opponent placements */
.cell.opponent-color-0 { border-left: 3px solid #e94560; }
.cell.opponent-color-1 { border-left: 3px solid #3498db; }
.cell.opponent-color-2 { border-left: 3px solid #2ecc71; }
.cell.opponent-color-3 { border-left: 3px solid #f39c12; }

/* Turn Notification */
.turn-pulse {
  animation: turnPulse 1.5s ease-out;
}

@keyframes turnPulse {
  0% { transform: scale(1); }
  15% { transform: scale(1.15); text-shadow: 0 0 12px var(--accent); }
  30% { transform: scale(1); }
  45% { transform: scale(1.1); text-shadow: 0 0 8px var(--accent); }
  60% { transform: scale(1); text-shadow: none; }
  100% { transform: scale(1); text-shadow: none; }
}

.turn-flash {
  position: absolute;
  inset: 0;
  background: var(--accent);
  opacity: 0;
  pointer-events: none;
  z-index: 10;
  animation: turnFlash 0.6s ease-out forwards;
  border-radius: 8px;
}

@keyframes turnFlash {
  0% { opacity: 0.15; }
  100% { opacity: 0; }
}

/* Turn Replay */
.replay-overlay {
  position: absolute;
  top: 60px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 50;
  pointer-events: none;
  transition: opacity 0.3s;
}

.replay-overlay.replay-fade-out {
  opacity: 0;
}

.replay-header {
  display: flex;
  align-items: center;
  gap: 12px;
  background: rgba(236, 230, 220, 0.9);
  backdrop-filter: blur(8px);
  padding: 10px 20px;
  border-radius: 12px;
  white-space: nowrap;
}

.replay-player {
  font-weight: 600;
  font-size: 15px;
  color: var(--text);
}

.replay-score-counter {
  font-size: 22px;
  font-weight: bold;
  color: var(--accent);
}

.replay-score-bump {
  animation: replayBump 0.25s ease-out;
}

@keyframes replayBump {
  0% { transform: scale(1); }
  50% { transform: scale(1.3); }
  100% { transform: scale(1); }
}

.cell.replay-highlight {
  box-shadow: 0 0 12px 3px var(--accent), inset 0 0 8px rgba(255, 255, 255, 0.15);
  border-color: var(--accent);
  z-index: 5;
  position: relative;
  animation: replayPulse 0.4s ease-out;
}

@keyframes replayPulse {
  0% { transform: scale(0.9); opacity: 0.5; }
  50% { transform: scale(1.08); }
  100% { transform: scale(1); opacity: 1; }
}

/* Qwirkle Animation */
.cell.qwirkle {
  animation: qwirkleGlow 0.5s ease-in-out 6 alternate;
}

@keyframes qwirkleGlow {
  from {
    box-shadow: 0 0 10px rgba(255, 215, 0, 0.4);
  }
  to {
    box-shadow: 0 0 25px rgba(255, 215, 0, 0.9), 0 0 50px rgba(255, 215, 0, 0.4);
    border-color: gold;
  }
}

/* Tiles */
.tile {
  width: var(--tile-size);
  height: var(--tile-size);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: grab;
  transition: transform 0.15s, box-shadow 0.15s;
  user-select: none;
  touch-action: manipulation;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.1);
}

.tile:hover {
  transform: scale(1.05);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.tile.dragging {
  opacity: 0.5;
  cursor: grabbing;
}

.tile.selected {
  outline: 3px solid #00ff88;
  transform: scale(1.1);
  box-shadow: 0 0 12px rgba(0, 255, 136, 0.5);
}

.tile svg {
  width: 35px;
  height: 35px;
}

/* Tile Colors — vivid on dark background */
.tile.red { background: var(--tile-bg); color: #e8312a; }
.tile.orange { background: var(--tile-bg); color: #f5921b; }
.tile.yellow { background: var(--tile-bg); color: #f5d623; }
.tile.green { background: var(--tile-bg); color: #59b336; }
.tile.blue { background: var(--tile-bg); color: #2a8fd5; }
.tile.purple { background: var(--tile-bg); color: #9b4fbf; }

/* ========================
   Floating Hand Section
   ======================== */
.hand-section {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 100;
  background: var(--glass-bg);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid var(--glass-border);
  box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.1);
  padding: 10px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.hand-label {
  display: none;
}

.player-hand {
  display: flex;
  gap: 8px;
  flex: 1;
  min-height: 54px;
  align-items: center;
}

/* ========================
   Icon-Only Action Buttons
   ======================== */
.action-buttons {
  display: flex;
  gap: 6px;
  align-items: center;
}

.action-btn {
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 12px;
  font-size: 0;
  cursor: pointer;
  transition: all 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  position: relative;
}

.action-btn svg {
  width: 20px;
  height: 20px;
}

.action-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
  transform: none !important;
}

/* Tooltip on hover */
.action-btn[title]:hover::after {
  content: attr(title);
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  background: rgba(58, 53, 48, 0.9);
  color: #faf5ef;
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 12px;
  white-space: nowrap;
  pointer-events: none;
  z-index: 300;
}

.action-btn-undo {
  background: #c9bfb2;
  color: #5a5048;
}

.action-btn-undo:hover:not(:disabled) {
  background: #b8ad9e;
  transform: translateY(-2px);
}

.action-btn-undo-all {
  background: #c9bfb2;
  color: #5a5048;
}

.action-btn-undo-all:hover:not(:disabled) {
  background: #b8ad9e;
  transform: translateY(-2px);
}

.action-btn-exchange {
  background: #a8c4d4;
  color: #2a5a7a;
}

.action-btn-exchange:hover:not(:disabled) {
  background: #92b4c8;
  transform: translateY(-2px);
}

.action-btn-pass {
  background: #d4c8b8;
  color: #6a5a48;
}

.action-btn-pass:hover:not(:disabled) {
  background: #c4b8a8;
  transform: translateY(-2px);
}

.action-btn-end {
  background: var(--accent);
  color: #faf5ef;
  width: 52px;
  height: 44px;
}

.action-btn-end:hover:not(:disabled) {
  background: var(--accent-hover);
  transform: translateY(-2px);
  box-shadow: var(--shadow-glow);
}

/* Exchange Mode */
.tile.exchange-selected {
  outline: 3px solid var(--accent);
  transform: scale(0.95);
}

/* Modal */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal-content {
  background: var(--glass-bg);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--glass-border);
  padding: 32px;
  border-radius: var(--radius-xl);
  min-width: 400px;
  max-width: 90vw;
  text-align: center;
  box-shadow: var(--shadow-lg);
  animation: modalSlideUp 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes modalSlideUp {
  from { opacity: 0; transform: translateY(20px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.modal-content h2,
.modal-content h3 {
  margin-bottom: 24px;
}

.exchange-tiles {
  display: flex;
  gap: 10px;
  justify-content: center;
  margin-bottom: 24px;
  flex-wrap: wrap;
}

.modal-actions {
  display: flex;
  gap: 12px;
  justify-content: center;
}

#finalScores {
  margin-bottom: 24px;
}

.final-score-entry {
  display: flex;
  justify-content: space-between;
  padding: 12px;
  margin: 8px 0;
  background: rgba(0, 0, 0, 0.06);
  border-radius: 8px;
}

.final-score-entry.winner {
  background: var(--gradient-primary);
  color: #faf5ef;
  box-shadow: 0 0 20px rgba(255,215,0,0.3);
  animation: winnerGlow 0.5s ease-out;
  transform: scale(1.02);
}

@keyframes winnerGlow {
  0% { transform: scale(0.95); opacity: 0.7; }
  50% { transform: scale(1.04); }
  100% { transform: scale(1.02); opacity: 1; }
}

/* Gold confetti particles for game over */
#gameOverModal .modal-content {
  position: relative;
  overflow: hidden;
}

#gameOverModal .modal-content::before,
#gameOverModal .modal-content::after {
  content: '';
  position: absolute;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  pointer-events: none;
}

#gameOverModal .modal-content::before {
  top: -10px;
  left: 20%;
  background: gold;
  box-shadow:
    40px 8px 0 rgba(255,215,0,0.7),
    80px 4px 0 rgba(255,215,0,0.5),
    120px 12px 0 rgba(255,215,0,0.6),
    160px 6px 0 rgba(255,215,0,0.4),
    200px 10px 0 rgba(255,215,0,0.7);
  animation: confettiFall 2s ease-in forwards;
}

#gameOverModal .modal-content::after {
  top: -10px;
  left: 30%;
  background: rgba(122,98,69,0.6);
  box-shadow:
    30px 6px 0 rgba(122,98,69,0.5),
    70px 10px 0 rgba(122,98,69,0.4),
    110px 4px 0 rgba(122,98,69,0.6),
    150px 14px 0 rgba(122,98,69,0.3),
    190px 8px 0 rgba(122,98,69,0.5);
  animation: confettiFall 2.5s ease-in 0.3s forwards;
}

@keyframes confettiFall {
  0% { transform: translateY(0) rotate(0); opacity: 1; }
  100% { transform: translateY(300px) rotate(720deg); opacity: 0; }
}

/* Chat Panel */
.chat-panel,
.history-panel {
  position: fixed;
  right: 0;
  top: 0;
  width: 320px;
  height: 100vh;
  background: var(--glass-bg);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-left: 1px solid var(--glass-border);
  z-index: 500;
  display: flex;
  flex-direction: column;
  box-shadow: -4px 0 20px rgba(0, 0, 0, 0.12);
  animation: panelSlideIn 0.25s ease;
}

@keyframes panelSlideIn {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

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

.panel-header h3 {
  margin: 0;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
}

.chat-message {
  margin-bottom: 8px;
  font-size: 14px;
  line-height: 1.4;
  word-break: break-word;
}

.chat-time {
  color: var(--text-muted);
  font-size: 12px;
}

.chat-input-row {
  display: flex;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid rgba(0, 0, 0, 0.1);
}

.chat-input-row input {
  flex: 1;
  padding: 8px 12px;
  font-size: 14px;
}

/* History Panel */
.history-list {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
}

.history-entry {
  padding: 8px 12px;
  margin-bottom: 4px;
  background: rgba(0, 0, 0, 0.06);
  border-radius: 6px;
  font-size: 14px;
}

/* Qwirkle Toast */
.qwirkle-toast {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 48px;
  font-weight: 900;
  color: gold;
  text-shadow: 0 0 20px rgba(255, 215, 0, 0.8), 0 0 40px rgba(255, 215, 0, 0.4);
  z-index: 2000;
  animation: qwirklePop 0.5s ease-out;
  pointer-events: none;
}

@keyframes qwirklePop {
  0% { transform: translate(-50%, -50%) scale(0); opacity: 0; }
  50% { transform: translate(-50%, -50%) scale(1.2); opacity: 1; }
  100% { transform: translate(-50%, -50%) scale(1); opacity: 1; }
}

/* Score Popup */
#scorePopupContainer {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  pointer-events: none;
  z-index: 1500;
}

.score-popup {
  font-size: 36px;
  font-weight: bold;
  color: var(--accent);
  text-shadow: 0 0 10px rgba(122, 98, 69, 0.4);
  animation: scoreFloat 1s ease-out forwards;
}

@keyframes scoreFloat {
  0% { opacity: 1; transform: translateY(0) scale(1); }
  100% { opacity: 0; transform: translateY(-30px) scale(1.2); }
}

/* Tile bounce after placement */
@keyframes tileBounce {
  0% { transform: scale(0.8); opacity: 0.5; }
  60% { transform: scale(1.05); }
  100% { transform: scale(1); opacity: 1; }
}

.tile-just-placed {
  animation: tileBounce 0.3s ease;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 100px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--glass-bg);
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
  padding: 16px 32px;
  border-radius: var(--radius-md);
  border: 1px solid var(--accent);
  box-shadow: var(--shadow-md);
  z-index: 1001;
  animation: slideUp 0.3s ease;
}

.toast.error {
  border-color: #b04040;
  background: rgba(176, 64, 64, 0.15);
}

@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateX(-50%) translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
  }
}

/* Scrollbar */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: #dbd6ce;
}

::-webkit-scrollbar-thumb {
  background: #b8ad9e;
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: #a09588;
}

/* Settings Modal */
#settingsModal .modal-content {
  min-width: 340px;
  text-align: left;
}

.settings-section {
  margin-bottom: 20px;
}

.settings-section h4 {
  margin-bottom: 10px;
  color: var(--text-muted);
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.settings-section label {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 0;
  cursor: pointer;
  color: var(--text);
  font-size: 15px;
}

.settings-section input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

#settingsModal .btn-primary {
  display: block;
  width: 100%;
  margin-top: 8px;
}

/* Spectator Banner */
.spectator-banner {
  width: 100%;
  background: rgba(255, 200, 0, 0.15);
  border: 1px solid rgba(255, 200, 0, 0.4);
  padding: 10px 20px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-weight: 600;
  color: #a08030;
}

/* Emoji Picker */
.emoji-picker {
  position: fixed;
  bottom: 120px;
  right: 20px;
  background: var(--glass-bg);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-lg);
  padding: 8px;
  display: flex;
  gap: 4px;
  box-shadow: var(--shadow-lg);
  z-index: 600;
}

.emoji-btn {
  background: none;
  border: none;
  font-size: 24px;
  cursor: pointer;
  padding: 6px 8px;
  border-radius: 8px;
  transition: background 0.15s, transform 0.15s;
}

.emoji-btn:hover {
  background: rgba(0, 0, 0, 0.06);
  transform: scale(1.2);
}

/* Floating Emoji */
.emoji-float-container {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 1500;
  overflow: hidden;
}

.emoji-float {
  position: absolute;
  font-size: 36px;
  animation: emojiFloat 2s ease-out forwards;
  pointer-events: none;
}

.emoji-float-label {
  position: absolute;
  font-size: 11px;
  font-weight: 600;
  color: var(--text);
  background: rgba(236, 230, 220, 0.85);
  padding: 2px 6px;
  border-radius: 4px;
  white-space: nowrap;
  top: -16px;
  left: 50%;
  transform: translateX(-50%);
}

@keyframes emojiFloat {
  0% {
    opacity: 1;
    transform: translateY(0) scale(0.5);
  }
  20% {
    transform: translateY(-30px) scale(1.2);
  }
  100% {
    opacity: 0;
    transform: translateY(-150px) scale(0.8);
  }
}

/* Player Colors */
.player-color-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
  margin-right: 4px;
  flex-shrink: 0;
}

/* Rematch Vote Info */
.rematch-vote-info {
  margin-bottom: 16px;
  font-size: 14px;
  color: var(--text-muted);
}

.rematch-vote-info .vote-count {
  font-weight: bold;
  color: var(--accent);
}

/* Rejoin Banner */
.rejoin-banner {
  width: 400px;
  max-width: 90vw;
  background: var(--glass-bg);
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
  border: 2px solid var(--accent);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  padding: 16px 20px;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.rejoin-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.rejoin-code {
  font-size: 13px;
  color: var(--accent);
  letter-spacing: 2px;
  font-weight: 600;
}

.rejoin-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

/* Watchable game card */
.lobby-game-card.watchable {
  border-left: 3px solid rgba(160, 128, 48, 0.5);
}

.lobby-spectate-btn {
  padding: 8px 18px;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  background: rgba(160, 128, 48, 0.15);
  color: #a08030;
  transition: all 0.2s;
  white-space: nowrap;
  flex-shrink: 0;
}

.lobby-spectate-btn:hover {
  background: rgba(160, 128, 48, 0.25);
  transform: translateY(-1px);
}

/* ========================
   Leaderboard
   ======================== */
.leaderboard-list {
  max-height: 400px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.leaderboard-row {
  display: flex;
  align-items: center;
  padding: 10px 12px;
  background: var(--glass-bg);
  border-radius: 12px;
  gap: 12px;
  cursor: pointer;
  transition: transform var(--transition-fast), box-shadow var(--transition-fast);
  animation: fadeInUp 0.3s ease backwards;
}

.leaderboard-row:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
}

.leaderboard-rank {
  width: 24px;
  font-weight: 700;
  text-align: center;
  flex-shrink: 0;
}

.leaderboard-rank.top-3 {
  color: var(--accent);
}

.leaderboard-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}

.leaderboard-avatar-placeholder {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--glass-border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 13px;
  color: var(--text-muted);
  flex-shrink: 0;
}

.leaderboard-name {
  flex: 1;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.leaderboard-stats {
  display: flex;
  gap: 16px;
  font-size: 12px;
  color: var(--text-muted);
  flex-shrink: 0;
}

.leaderboard-stat-value {
  font-weight: 600;
  color: var(--text);
}

/* ========================
   Responsive
   ======================== */
@media (max-width: 768px) {
  :root {
    --tile-size: 40px;
    --cell-size: 44px;
    --glass-blur: 8px;
  }

  .navbar {
    padding: 8px 12px;
    gap: 8px;
  }

  .nav-links {
    margin-left: 4px;
  }

  .nav-link {
    font-size: 13px;
    padding: 5px 8px;
  }

  .lobby-container {
    width: 90vw;
    padding: 24px;
  }

  .auth-section {
    width: 90vw;
    padding: 16px;
  }

  .profile-header {
    flex-direction: column;
    align-items: center;
  }

  .profile-stats {
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
  }

  .game-code-display {
    font-size: 20px;
    padding: 12px 20px;
    flex-wrap: wrap;
    justify-content: center;
  }

  .game-header {
    padding: 6px 10px;
  }

  .players-bar {
    gap: 8px;
    overflow-x: auto;
    width: 100%;
    justify-content: flex-start;
  }

  .player-info {
    padding: 4px 8px;
  }

  .player-name {
    font-size: 11px;
  }

  .player-score {
    font-size: 16px;
  }

  .turn-banner {
    font-size: 13px;
    padding: 6px 12px;
    gap: 10px;
  }

  .hand-section {
    padding: 8px 10px;
    gap: 8px;
  }

  .player-hand {
    gap: 6px;
  }

  .action-btn {
    width: 38px;
    height: 38px;
    border-radius: 10px;
  }

  .action-btn-end {
    width: 46px;
    height: 38px;
  }

  .game-container {
    padding-bottom: 80px;
  }

  .modal-content {
    min-width: auto;
    width: 90vw;
    padding: 20px;
  }

  .chat-panel,
  .history-panel {
    width: 100vw;
  }

  .tile svg {
    width: 28px;
    height: 28px;
  }

  .match-settings {
    min-width: auto;
  }

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

  .wr-content {
    padding: 16px 16px 32px;
  }
}

@media (max-width: 480px) {
  :root {
    --tile-size: 34px;
    --cell-size: 38px;
    --glass-blur: 6px;
  }

  .navbar {
    padding: 6px 10px;
    gap: 6px;
  }

  .nav-logo {
    font-size: 18px;
  }

  .nav-links {
    margin-left: 2px;
    gap: 2px;
  }

  .nav-link {
    font-size: 12px;
    padding: 4px 6px;
  }

  .game-code-display {
    font-size: 16px;
  }

  .player-info {
    padding: 4px 6px;
  }

  .player-name {
    font-size: 10px;
  }

  .player-score {
    font-size: 14px;
  }

  .player-tiles {
    font-size: 9px;
  }

  .action-btn {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    min-height: 44px;
    min-width: 36px;
  }

  .action-btn-end {
    width: 42px;
    height: 36px;
    min-height: 44px;
  }

  .game-container {
    padding-bottom: 70px;
  }

  .tile svg {
    width: 22px;
    height: 22px;
  }

  .qwirkle-toast {
    font-size: 32px;
  }

  .score-popup {
    font-size: 28px;
  }
}

/* ========================
   Desktop: Sidebar Layout
   ======================== */
@media (min-width: 1025px) {
  #gameScreen {
    display: grid;
    grid-template-columns: 200px 1fr;
    grid-template-rows: auto 1fr;
    gap: 0;
    padding: 0;
    height: 100vh;
    min-height: 0;
  }

  .game-header {
    grid-column: 1;
    grid-row: 1 / 3;
    flex-direction: column;
    align-items: stretch;
    width: 100%;
    height: 100%;
    border-radius: 0;
    padding: 12px;
    gap: 12px;
    justify-content: flex-start;
    overflow-y: auto;
  }

  .players-bar {
    flex-direction: column;
    gap: 8px;
    overflow-x: visible;
    width: 100%;
  }

  .player-info {
    width: 100%;
    flex-direction: row;
    gap: 8px;
    padding: 8px 10px;
    justify-content: flex-start;
  }

  .player-info .player-name {
    flex: 1;
    text-align: left;
  }

  .header-menu {
    width: 100%;
    display: flex;
    justify-content: center;
    margin-top: auto;
  }

  .turn-banner {
    grid-column: 2;
    grid-row: 1;
    margin: 0;
    border-radius: 0;
    padding: 8px 20px;
  }

  .game-container {
    grid-column: 2;
    grid-row: 2;
  }

  .hand-section {
    left: 200px;
  }
}

/* ========================
   Feature 2: Score Preview on valid cells
   ======================== */
.cell.valid-drop {
  position: relative;
}

.cell.valid-drop[data-score]::after {
  content: attr(data-score);
  position: absolute;
  top: 2px;
  right: 3px;
  font-size: 10px;
  font-weight: 700;
  color: var(--accent);
  opacity: 0.8;
  pointer-events: none;
}

/* ========================
   Feature 3: Center Board Button
   ======================== */
.center-board-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 20;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: var(--card-bg);
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 8px rgba(0,0,0,0.12);
  transition: background 0.15s, color 0.15s;
}

.center-board-btn:hover {
  background: var(--accent);
  color: #faf5ef;
}

.center-board-btn svg {
  width: 18px;
  height: 18px;
}

/* ========================
   Feature 4: Colorblind Mode
   ======================== */
[data-colorblind="true"] .tile::after {
  content: attr(data-color-letter);
  position: absolute;
  bottom: 1px;
  right: 3px;
  font-size: 9px;
  font-weight: 700;
  color: rgba(255,255,255,0.8);
  pointer-events: none;
  line-height: 1;
}

[data-colorblind="true"] .tile {
  position: relative;
}

/* ========================
   Feature 5: Settings Badges in Lobby Cards
   ======================== */
.lobby-setting-badges {
  display: flex;
  gap: 4px;
  margin-top: 2px;
  flex-wrap: wrap;
}

.lobby-setting-badge {
  font-size: 11px;
  padding: 2px 6px;
  background: rgba(0,0,0,0.06);
  border-radius: 4px;
  color: var(--text-muted);
  white-space: nowrap;
}

/* ========================
   Feature 10: Reconnect Overlay
   ======================== */
.reconnect-overlay {
  position: fixed;
  inset: 0;
  z-index: 2000;
  background: rgba(0,0,0,0.5);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  color: #faf5ef;
  font-size: 18px;
  font-weight: 600;
}

.reconnect-spinner {
  width: 40px;
  height: 40px;
  border: 4px solid rgba(255,255,255,0.2);
  border-top-color: #faf5ef;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* ========================
   Feature 14: Mini Tiles in History
   ======================== */
.history-tiles {
  display: inline-flex;
  gap: 2px;
  margin-left: 4px;
  vertical-align: middle;
}

.mini-tile {
  width: 16px;
  height: 16px;
  border-radius: 2px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0;
  flex-shrink: 0;
  vertical-align: middle;
}

.mini-tile svg {
  width: 11px;
  height: 11px;
}

.mini-tile.red { background: var(--tile-bg); color: #e8312a; }
.mini-tile.orange { background: var(--tile-bg); color: #f5921b; }
.mini-tile.yellow { background: var(--tile-bg); color: #f5d623; }
.mini-tile.green { background: var(--tile-bg); color: #59b336; }
.mini-tile.blue { background: var(--tile-bg); color: #2a8fd5; }
.mini-tile.purple { background: var(--tile-bg); color: #9b4fbf; }

/* ========================
   Feature 15: Bot Thinking Indicator
   ======================== */
.thinking-dots span {
  animation: thinkingDot 1.4s infinite;
  opacity: 0.2;
}

.thinking-dots span:nth-child(2) {
  animation-delay: 0.2s;
}

.thinking-dots span:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes thinkingDot {
  0%, 60%, 100% { opacity: 0.2; }
  30% { opacity: 1; }
}

/* ========================
   Feature 16: Closable Game-Over Modal
   ======================== */
.modal-close-btn {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 32px;
  height: 32px;
  border: none;
  background: none;
  font-size: 24px;
  color: var(--text-muted);
  cursor: pointer;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, color 0.15s;
}

.modal-close-btn:hover {
  background: rgba(0,0,0,0.08);
  color: var(--text);
}

.btn-show-results {
  position: fixed;
  bottom: 100px;
  right: 16px;
  z-index: 90;
  padding: 8px 16px;
  font-size: 13px;
  background: var(--card-bg);
  color: var(--text);
  border: 1px solid var(--input-border);
  border-radius: 8px;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.btn-show-results:hover {
  background: var(--btn-small-hover);
}

/* ========================
   Feature 9: Game-Over Stats
   ======================== */
.final-score-stats {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

.final-score-entry.winner .final-score-stats {
  color: rgba(250,245,239,0.7);
}

/* ========================
   Feature 13: Keyboard Controls
   ======================== */
.cell.keyboard-focus {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
  z-index: 10;
  position: relative;
}

/* ========================
   Feature 8: Bot Difficulty Select
   ======================== */
/* Remove bot button */
.wr-remove-bot-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 16px;
  padding: 4px 8px;
  border-radius: 6px;
  transition: color var(--transition-fast), background var(--transition-fast);
  flex-shrink: 0;
  line-height: 1;
}

.wr-remove-bot-btn:hover {
  color: #e74c3c;
  background: rgba(231,76,60,0.1);
}

/* ========================
   Feature 7: Max Players Select in settings
   ======================== */
.settings-row .max-players-select {
  width: auto;
  min-width: 80px;
}

/* ========================
   QoL Feature 1: Chat Badge
   ======================== */
.chat-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 9px;
  background: #e74c3c;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  margin-left: auto;
  line-height: 1;
}

/* ========================
   QoL Feature 2: Zoom Controls
   ======================== */
.board-zoom-controls {
  position: absolute;
  top: 50px;
  right: 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  z-index: 20;
}

.board-control-btn {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  border: none;
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 4px rgba(0,0,0,0.12);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}

.board-control-btn svg {
  width: 18px;
  height: 18px;
}

.board-control-btn:hover {
  background: var(--hover);
}

/* ========================
   QoL Feature 4: Timer Progress Bar
   ======================== */
.timer-bar {
  width: 80px;
  height: 4px;
  background: rgba(0,0,0,0.1);
  border-radius: 2px;
  overflow: hidden;
  flex-shrink: 0;
}

.timer-bar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
  transition: width 1s linear;
}

.timer-bar-fill.timer-bar-warning {
  background: #c0392b;
}

/* ========================
   QoL Feature 5: Animated Tile Draw
   ======================== */
@keyframes tileSlideIn {
  from {
    transform: translateY(20px) scale(0.8);
    opacity: 0;
  }
  to {
    transform: translateY(0) scale(1);
    opacity: 1;
  }
}

.tile-new {
  animation: tileSlideIn 0.3s ease-out;
}

/* ========================
   QoL Feature 6: Board Minimap
   ======================== */
.board-minimap {
  position: absolute;
  bottom: 8px;
  left: 8px;
  width: 120px;
  height: 120px;
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 1px 4px rgba(0,0,0,0.15);
  opacity: 0.85;
  z-index: 20;
  cursor: pointer;
  transition: opacity 0.15s;
}

.board-minimap:hover {
  opacity: 1;
}

/* ========================
   QoL Feature 7: Shortcut Table
   ======================== */
.shortcut-table {
  width: 100%;
  border-collapse: collapse;
}

.shortcut-table td {
  padding: 6px 8px;
  border-bottom: 1px solid rgba(0,0,0,0.06);
  font-size: 14px;
}

.shortcut-table td:first-child {
  white-space: nowrap;
  text-align: right;
  padding-right: 16px;
  width: 1%;
}

kbd {
  display: inline-block;
  padding: 2px 6px;
  border-radius: 4px;
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 12px;
  background: rgba(0,0,0,0.06);
  border: 1px solid rgba(0,0,0,0.1);
  line-height: 1.4;
  margin: 0 2px;
}

/* ========================
   QoL Feature 9: Score Diff
   ======================== */
.player-diff {
  font-size: 10px;
  font-weight: 600;
  margin-left: 2px;
}

.diff-positive {
  color: #27ae60;
}

.diff-negative {
  color: #c0392b;
}

.diff-leader {
  color: var(--accent);
}

/* ========================
   QoL Feature 11: Game Duration
   ======================== */
.game-duration {
  font-size: 13px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  margin-left: auto;
}

/* ========================
   QoL Feature 12: Hand Pips
   ======================== */
.player-hand-bar {
  display: flex;
  gap: 1px;
  margin-top: 2px;
}

.player-hand-pip {
  width: 6px;
  height: 3px;
  border-radius: 1px;
  background: rgba(0,0,0,0.15);
}

.player-hand-pip.filled {
  background: var(--accent);
}

.player-info.active .player-hand-pip {
  background: rgba(255,255,255,0.3);
}

.player-info.active .player-hand-pip.filled {
  background: #fff;
}

/* ========================
   QoL Feature 13: Volume Slider
   ======================== */
.volume-control {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
  font-size: 14px;
}

.volume-slider {
  flex: 1;
  -webkit-appearance: none;
  appearance: none;
  height: 4px;
  border-radius: 2px;
  background: rgba(0,0,0,0.12);
  outline: none;
}

.volume-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  border: none;
}

.volume-slider::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  border: none;
}

#volumeValue {
  min-width: 32px;
  text-align: right;
  font-size: 13px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}
