/* ─── RESET & BASE ─────────────────────────────────────────────── */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

/* ─── DESIGN TOKENS — Traditional Indian / Parchment Theme ──── */
:root {
  /* Page & surface */
  --bg: #f5ead0;
  --bg-pattern: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%23c9a85c' fill-opacity='0.08'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
  --surface: #fdf6e3;
  --surface2: #f7edcf;
  --border: #d4a84b;
  --border-light: #e8d09a;

  /* Maroon/gold — Player 1 */
  --p1: #7b1c2e;
  --p1-light: #faebd0;
  --p1-bg: #fdf4e4;
  --p1-border: #c8853a;

  /* Forest green — Player 2 */
  --p2: #1a5c3a;
  --p2-light: #d4f0de;
  --p2-bg: #edf8f1;
  --p2-border: #2e8b57;

  /* Accent = maroon */
  --accent: #7b1c2e;
  --accent-hover: #5c1220;
  --accent2: #fae8d5;

  /* Text */
  --text: #2c1810;
  --text-dim: #7a5c3a;

  /* Radii & shadow */
  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 2px 10px rgba(100, 50, 10, 0.12);
  --shadow-md: 0 4px 20px rgba(100, 50, 10, 0.18);

  /* Board cell colors */
  --cell: #ede0c4;
  --cell-border: #c9a96e;
}

html {
  font-size: 15px;
}

body {
  background: var(--bg);
  background-image: var(--bg-pattern);
  color: var(--text);
  font-family: "Noto Sans", "Segoe UI", system-ui, sans-serif;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Devanagari characters use serif font */
.tile,
.grid-cell,
.selected-cell-display,
.matra-wheel {
  font-family: "Noto Serif Devanagari", "Noto Sans", serif;
}

/* ─── SCROLLBAR ────────────────────────────────────────────────── */
::-webkit-scrollbar {
  width: 6px;
}
::-webkit-scrollbar-track {
  background: var(--surface2);
}
::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

/* ─── GAME TOPBAR ──────────────────────────────────────────────── */
.game-topbar {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: nowrap;
  background: linear-gradient(180deg, #fffef8 0%, #f7edd4 100%);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 12px;
  box-shadow: 0 3px 12px rgba(100, 50, 10, 0.1), 0 1px 3px rgba(0, 0, 0, 0.04);
  position: relative;
}
.game-topbar::before {
  content: "";
  position: absolute;
  inset: 2px;
  border-radius: calc(var(--radius) - 2px);
  border: 1px solid rgba(212, 168, 75, 0.28);
  pointer-events: none;
}
.topbar-controls {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px 10px;
  flex: 1;
  min-width: 0;
}
.topbar-pill-card {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: #fffcf4;
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  padding: 3px 8px;
  box-shadow: 0 1px 3px rgba(100, 50, 10, 0.05);
}
.topbar-icon {
  font-size: 0.85rem;
  color: #b07a28;
  line-height: 1;
  display: inline-flex;
  align-items: center;
}
.topbar-divider {
  width: 1px;
  height: 16px;
  background: var(--border-light);
  margin: 0 1px;
}
.topbar-group {
  display: flex;
  align-items: center;
  gap: 5px;
}
.topbar-actions-group {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}
.topbar-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  font-size: 0.78rem;
  font-weight: 600;
  border-radius: var(--radius-sm);
  background: #fffcf4;
  border: 1px solid var(--border-light);
  color: var(--text);
  box-shadow: 0 1px 3px rgba(100, 50, 10, 0.05);
  transition: all 0.15s ease;
  height: 28px;
}
.topbar-btn .btn-svg {
  width: 13px;
  height: 13px;
  flex-shrink: 0;
}
.topbar-btn:hover {
  background: #faf0d8;
  border-color: var(--accent);
  color: var(--accent);
  transform: translateY(-1px);
  box-shadow: 0 2px 6px rgba(123, 28, 46, 0.15);
}
.topbar-status-card {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.74rem;
  font-weight: 700;
  background: #fffcf4;
  border: 1px solid var(--border-light);
  box-shadow: 0 1px 3px rgba(100, 50, 10, 0.05);
  margin-left: auto;
  letter-spacing: 0.01em;
  transition: all 0.2s ease;
}
.topbar-status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #c8853a;
  display: inline-block;
  animation: statusPulse 2s infinite ease-in-out;
}
@keyframes statusPulse {
  0%, 100% {
    opacity: 1;
    transform: scale(1);
  }
  50% {
    opacity: 0.4;
    transform: scale(0.8);
  }
}
.topbar-status-card.turn-p1 {
  background: #fdf5ea;
  border-color: var(--p1-border);
  color: var(--p1);
}
.topbar-status-card.turn-p1 .topbar-status-dot {
  background: var(--p1);
  box-shadow: 0 0 5px rgba(123, 28, 46, 0.4);
}
.topbar-status-card.turn-p2 {
  background: var(--p2-bg);
  border-color: var(--p2-border);
  color: var(--p2);
}
.topbar-status-card.turn-p2 .topbar-status-dot {
  background: var(--p2);
  box-shadow: 0 0 5px rgba(26, 92, 58, 0.4);
}

.topbar-lang {
  display: flex;
  align-items: center;
  gap: 0;
  flex-shrink: 0;
  position: static;
  z-index: 2;
}
.topbar-lang-globe {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  background: var(--accent);
  color: #fff;
  border-radius: var(--radius-sm) 0 0 var(--radius-sm);
  flex-shrink: 0;
}
.topbar-lang-globe svg {
  width: 15px;
  height: 15px;
}
.lang-select {
  appearance: none;
  -webkit-appearance: none;
  background: var(--surface2);
  border: 1px solid var(--border-light);
  border-left: none;
  color: var(--accent);
  font-weight: 700;
  font-size: 0.8rem !important;
  padding: 4px 26px 4px 9px !important;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  cursor: pointer;
  outline: none;
  height: 26px;
  background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%237b1c2e' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 6px center;
  background-size: 11px;
  transition:
    border-color 0.15s,
    box-shadow 0.15s;
}
.lang-select:hover {
  border-color: var(--accent);
}
.lang-select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent2);
}
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ─── FORM ELEMENTS ────────────────────────────────────────────── */
.select-input {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 4px 8px !important;
  font-size: 0.82rem !important;
  width: auto;
  cursor: pointer;
  outline: none;
  box-shadow: 0 1px 3px rgba(100, 50, 10, 0.08);
}
.select-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent2);
}
.select-sm {
  padding: 3px 7px;
  font-size: 0.78rem;
}

.text-input {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  font-size: 0.82rem;
  outline: none;
  width: 100%;
  box-shadow: 0 1px 3px rgba(100, 50, 10, 0.06);
}
.text-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent2);
}
.text-input::placeholder {
  color: var(--text-dim);
}

/* ─── CONTROL LABEL ────────────────────────────────────────────── */
.control-label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-dim);
  white-space: nowrap;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* ─── BUTTONS ──────────────────────────────────────────────────── */
.btn {
  border: none;
  border-radius: var(--radius-sm);
  padding: 7px 16px;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
  letter-spacing: 0.01em;
  font-family: "Noto Sans", system-ui, sans-serif;
}
.btn-sm {
  padding: 5px 9px;
  font-size: 0.74rem;
}
.btn:active {
  transform: scale(0.97);
}
.btn-block {
  width: 100%;
  margin-top: 8px;
}

/* Primary = maroon */
.btn-primary {
  background: var(--p1);
  color: #fff;
  box-shadow: 0 2px 8px rgba(123, 28, 46, 0.35);
}
.btn-primary:hover {
  background: var(--accent-hover);
  box-shadow: 0 4px 12px rgba(123, 28, 46, 0.4);
}

/* Secondary = tan */
.btn-secondary {
  background: #f5e4c0;
  color: var(--p1);
  border: 1px solid var(--p1-border);
}
.btn-secondary:hover {
  background: #ead8a8;
}

/* Legacy btn-danger → same as secondary */
.btn-danger {
  background: #f5e4c0;
  color: var(--p1);
  border: 1px solid var(--p1-border);
}
.btn-danger:hover {
  background: #ead8a8;
}

.btn-ghost {
  background: var(--surface);
  color: var(--text-dim);
  border: 1px solid var(--border-light);
}
.btn-ghost:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent2);
}
.btn-icon {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-dim);
  font-size: 1rem;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
}
.btn-icon:hover {
  background: var(--surface2);
  color: var(--text);
}

/* ─── TOGGLE SWITCH ────────────────────────────────────────────── */
.toggle-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.8rem;
  color: var(--text-dim);
  cursor: pointer;
  user-select: none;
}
.toggle-label input {
  display: none;
}
.toggle-track {
  width: 32px;
  height: 18px;
  background: #c9b999;
  border-radius: 18px;
  position: relative;
  transition: background 0.2s;
  flex-shrink: 0;
}
.toggle-thumb {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.2s;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}
.toggle-label input:checked + .toggle-track {
  background: var(--p2);
}
.toggle-label input:checked + .toggle-track .toggle-thumb {
  transform: translateX(14px);
}

/* ─── MODAL ────────────────────────────────────────────────────── */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 2000;
  background: rgba(44, 24, 16, 0.55);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  animation: backdropIn 0.18s ease;
}
@keyframes backdropIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

.modal-box {
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: 14px;
  box-shadow:
    0 20px 60px rgba(100, 50, 10, 0.25),
    0 4px 16px rgba(0, 0, 0, 0.1);
  max-width: 560px;
  width: 100%;
  max-height: 88vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  animation: modalIn 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
}
@keyframes modalIn {
  from {
    opacity: 0;
    transform: scale(0.93) translateY(12px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 22px 14px;
  border-bottom: 1px solid var(--border-light);
  background: var(--surface2);
}
.modal-title {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--accent);
}
.modal-close {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  color: var(--text-dim);
  background: none;
  border: 1px solid var(--border-light);
  cursor: pointer;
  transition: all 0.15s;
}
.modal-close:hover {
  background: #f9e8e8;
  border-color: var(--p1);
  color: var(--p1);
}
.modal-body {
  padding: 18px 22px;
  overflow-y: auto;
}
.modal-confirm-box {
  max-width: 420px;
}
.modal-confirm-text {
  color: var(--text);
  line-height: 1.55;
}
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 20px;
}

.help-list {
  padding-left: 18px;
  margin-bottom: 20px;
}
.help-list li {
  margin-bottom: 8px;
  font-size: 0.87rem;
  color: var(--text);
  line-height: 1.65;
}
.help-list li strong {
  color: var(--accent);
}
.help-list li em {
  color: var(--p2);
  font-style: normal;
  font-weight: 600;
}

.help-scoring {
  background: var(--surface2);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  padding: 12px;
}
.help-video {
  margin-top: 12px;
}
.help-video video {
  width: 100%;
  max-height: 50vh;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-light);
  background: #000;
  display: block;
}
.help-scoring-title {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
  margin-bottom: 8px;
}
.help-scoring-grid {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 5px 10px;
  align-items: center;
  margin-bottom: 8px;
}
.pts-badge {
  font-size: 0.7rem;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 20px;
  white-space: nowrap;
  text-align: center;
}
.pts-1 {
  background: #edf8f1;
  color: #1a5c3a;
  border: 1px solid #2e8b57;
}
.pts-2 {
  background: #eff6ff;
  color: #1d4ed8;
  border: 1px solid #93c5fd;
}
.pts-3 {
  background: #fef9e7;
  color: #7a4f10;
  border: 1px solid #d4a84b;
}
.pts-4 {
  background: #fdf4e4;
  color: var(--p1);
  border: 1px solid var(--p1-border);
}
.pts-5 {
  background: #fdf2fb;
  color: #7e22ce;
  border: 1px solid #d8b4fe;
}
.pts-6 {
  background: #fae8d5;
  color: var(--p1);
  border: 1px solid var(--p1-border);
}
.help-scoring-grid span:not(.pts-badge) {
  font-size: 0.85rem;
  color: var(--text);
  letter-spacing: 0.04em;
}
.help-note {
  font-size: 0.73rem;
  color: var(--text-dim);
  line-height: 1.5;
}

.hidden {
  display: none !important;
}

/* ─── MAIN LAYOUT ───────────────────────────────────────────────── */
.main-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 310px;
  grid-template-rows: auto auto 1fr;
  gap: 16px;
  padding: 12px 16px;
  max-width: 1440px;
  margin: 0 auto;
  width: 100%;
  box-sizing: border-box;
  align-items: start;
  position: relative;
}
.page-intro {
  grid-row: 1;
}
.game-topbar {
  grid-column: 1 / -1;
  grid-row: 2;
}
.main-layout:has(#scrabbleReadOnlyBanner:not(.hidden)) .scrabble-readonly-banner {
  grid-row: 1;
}
.main-layout:has(#scrabbleReadOnlyBanner:not(.hidden)) .page-intro {
  grid-row: 2;
}
.main-layout:has(#scrabbleReadOnlyBanner:not(.hidden)) .game-topbar {
  grid-row: 3;
}
.main-layout:has(#scrabbleReadOnlyBanner:not(.hidden)) .board-section,
.main-layout:has(#scrabbleReadOnlyBanner:not(.hidden)) .side-panel-right {
  grid-row: 4 / 6;
}

/* ─── PAGE INTRO ───────────────────────────────────────────────── */
.page-intro {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 14px;
  background: linear-gradient(180deg, #fffcf6 0%, #f7edd4 100%);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  position: relative;
}
.page-intro::before {
  content: "";
  position: absolute;
  inset: 2px;
  border-radius: calc(var(--radius) - 2px);
  border: 1px solid rgba(212, 168, 75, 0.3);
  pointer-events: none;
}
.page-intro-left {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  flex: 1;
}
.page-intro-scripts {
  display: flex;
  gap: 5px;
  flex-shrink: 0;
}
.intro-tile {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: "Noto Serif Devanagari", "Noto Sans", serif;
  font-size: 1.1rem;
  font-weight: 700;
  box-shadow: 0 2px 4px rgba(80, 40, 10, 0.16);
  border: 1.5px solid rgba(255, 255, 255, 0.6);
}
.intro-tile-hi {
  background: #f3d08a;
  color: var(--p1);
}
.intro-tile-kn {
  background: #d4f0de;
  color: var(--p2);
}
.intro-tile-gu {
  background: #f5c9b0;
  color: #8a3a18;
}

.page-intro-copy {
  min-width: 0;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.page-intro-title-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.page-intro-title {
  margin: 0;
  font-family: "Noto Serif Devanagari", "Noto Sans", serif;
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--p1);
  letter-spacing: 0.01em;
  line-height: 1.1;
}
.page-intro-badge {
  font-size: 0.62rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  background: #fce8d5;
  color: var(--p1);
  border: 1px solid var(--p1-border);
  border-radius: 4px;
  padding: 1px 6px;
  line-height: 1.2;
}
.page-intro-tagline {
  margin: 0;
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #b07a28;
  line-height: 1.2;
}
.page-intro-text {
  margin: 0;
  font-size: 0.72rem;
  line-height: 1.3;
  color: var(--text-dim);
  max-width: 780px;
}

@media (max-width: 600px) {
  .page-intro {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
    padding: 8px 10px;
  }
  .page-intro-left {
    width: 100%;
  }
  .page-intro-title {
    font-size: 1.15rem;
  }
  .intro-tile {
    width: 28px;
    height: 28px;
    font-size: 0.95rem;
  }
  .page-intro-text {
    font-size: 0.68rem;
  }
}

/* ─── SIDE PANEL (right) ────────────────────────────────────────── */
.side-panel-right {
  display: flex;
  flex-direction: column;
  gap: 14px;
  grid-column: 2;
  grid-row: 3 / 5;
  min-width: 0;
  width: 100%;
  box-sizing: border-box;
}
.score-tools {
  display: flex;
  flex-direction: column;
  gap: 14px;
  width: 100%;
  box-sizing: border-box;
}

/* ─── PLAYER BAR ────────────────────────────────────────────────── */
.player-bar {
  display: flex;
  align-items: stretch;
  gap: 0;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1.5px solid var(--border-light);
  box-shadow: var(--shadow);
  width: 100%;
  overflow: hidden;
  transition: all 0.2s ease;
}

.player1-bar {
  border-color: var(--p1-border);
}
.player2-bar {
  border-color: var(--p2-border);
}

.player1-bar.is-active-turn,
.player1-bar:has(input[name="player"]:checked) {
  border-color: var(--p1-border);
  box-shadow: 0 0 0 2px var(--p1-border), 0 3px 12px rgba(123, 28, 46, 0.18);
  opacity: 1 !important;
}
.player2-bar.is-active-turn,
.player2-bar:has(input[name="player"]:checked) {
  border-color: var(--p2-border);
  box-shadow: 0 0 0 2px var(--p2-border), 0 3px 12px rgba(26, 92, 58, 0.18);
  opacity: 1 !important;
}

/* Player meta section (radio + score + generate btn) — single row */
.player-meta {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 4px 8px;
  background: var(--surface2);
  border-right: 1px solid var(--border-light);
  flex-shrink: 0;
  min-width: 0;
}
.player1-bar .player-meta {
  background: var(--p1-bg);
  border-right-color: var(--p1-border);
}
.player2-bar .player-meta {
  background: var(--p2-bg);
  border-right-color: var(--p2-border);
}

.player-radio-label {
  display: flex;
  align-items: center;
  gap: 5px;
  cursor: pointer;
}
.player-radio-label input[type="radio"] {
  accent-color: var(--accent);
}
.player-name {
  font-weight: 700;
  font-size: 0.82rem;
  color: var(--text);
}
.player-score {
  font-size: 1.15rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: var(--accent);
  line-height: 1;
  min-width: 1.1rem;
  text-align: center;
}
.player1-bar .player-score {
  color: var(--p1);
}
.player2-bar .player-score {
  color: var(--p2);
}

/* Matra block (right of keys) */
.matra-block {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  padding: 3px 5px;
  border-left: 1px solid var(--border-light);
  flex-shrink: 0;
  min-width: 0;
}
.matra-block-p1 {
  background: #fdf4e4;
  border: none;
  border-left: 1px solid var(--p1-border);
}
.matra-block-p2 {
  background: var(--p2-bg);
  border: none;
  border-left: 1px solid var(--p2-border);
}
.matra-label {
  font-size: 0.5rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-dim);
  white-space: nowrap;
  line-height: 1;
}
.matra-block .select-input {
  font-size: 0.72rem !important;
  padding: 2px 4px !important;
  min-width: 0;
  max-width: 52px;
}

/* Empty rack hint */
.rack-empty-hint {
  font-size: 0.75rem;
  color: var(--text-dim);
  font-style: italic;
  opacity: 0.7;
  white-space: nowrap;
  padding: 0 4px;
}

/* Tile rack — wraps to show all tiles */
.tile-rack {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 5px 8px;
  align-items: center;
  flex: 1;
  min-width: 0;
  background: linear-gradient(180deg, #eedcb4 0%, #faecd2 30%, #f4e3c0 100%);
  box-shadow: inset 0 2px 4px rgba(90, 50, 10, 0.1);
}

/* Drop zone — slim full-width strip between P1 rack and board */
.rack-drop-zone {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 3px 14px;
  width: 100%;
  box-sizing: border-box;
  border: 1.5px dashed #c9a86e;
  border-radius: var(--radius-sm);
  color: #9a7040;
  font-size: 0.72rem;
  font-weight: 500;
  background: #faf3e0;
  cursor: default;
  transition:
    background 0.15s,
    border-color 0.15s;
  user-select: none;
  white-space: nowrap;
}
.rack-drop-zone.drag-over {
  background: #f0e0c0;
  border-color: var(--p1);
  box-shadow: inset 0 0 0 2px rgba(123, 28, 46, 0.15);
}
.rack-drop-icon {
  font-size: 0.95rem;
  line-height: 1;
}

/* ─── GENERATE BUTTON ───────────────────────────────────────────── */
.generate-btn {
  appearance: none !important;
  -webkit-appearance: none !important;
  width: 26px !important;
  min-width: 26px !important;
  max-width: 26px !important;
  height: 26px !important;
  min-height: 26px !important;
  max-height: 26px !important;
  border-radius: var(--radius-sm) !important;
  border: 1.5px solid var(--border) !important;
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  padding: 0 !important;
  margin: 0 !important;
  cursor: pointer !important;
  flex: 0 0 26px !important;
  line-height: 0 !important;
  transition:
    background 0.15s,
    border-color 0.15s,
    transform 0.12s,
    box-shadow 0.12s !important;
}
.generate-btn svg {
  width: 15px !important;
  height: 15px !important;
  display: block !important;
  fill: none !important;
  flex: 0 0 15px !important;
}
.generate-btn svg path {
  stroke: currentColor !important;
  stroke-width: 2.2 !important;
  stroke-linecap: round !important;
  stroke-linejoin: round !important;
}
.generate-btn:hover {
  transform: translateY(-1px) !important;
}
.generate-btn:active {
  transform: scale(0.96) !important;
}
.generate-btn:disabled {
  opacity: 0.45 !important;
  cursor: not-allowed !important;
  transform: none !important;
}

.generate-btn-p1 {
  background: var(--p1-light) !important;
  border-color: var(--p1-border) !important;
  color: var(--p1) !important;
}
.generate-btn-p1:hover:not(:disabled) {
  background: #f3d08a !important;
  box-shadow: 0 3px 8px rgba(123, 28, 46, 0.2) !important;
}
.generate-btn-p2 {
  background: var(--p2-light) !important;
  border-color: var(--p2-border) !important;
  color: var(--p2) !important;
}
.generate-btn-p2:hover:not(:disabled) {
  background: #a7e8c0 !important;
  box-shadow: 0 3px 8px rgba(26, 92, 58, 0.2) !important;
}

/* ─── TILES ─────────────────────────────────────────────────────── */
.tile {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  font-weight: 700;
  cursor: grab;
  position: relative;
  user-select: none;
  -webkit-user-select: none;
  -webkit-user-drag: element;
  flex-shrink: 0;
  background: radial-gradient(circle at 35% 35%, #fffdf6 0%, #fbe8c3 60%, #eed29b 100%);
  border: 1.5px solid #c89c44;
  box-shadow: 0 2px 5px rgba(80, 40, 10, 0.2), inset 0 1px 1px rgba(255, 255, 255, 0.75);
  transition:
    transform 0.12s,
    box-shadow 0.12s;
}
.tile:active {
  cursor: grabbing;
}
.tile.dragging {
  opacity: 0.45;
}
.tile:hover {
  transform: translateY(-2px) scale(1.06);
  box-shadow: 0 4px 10px rgba(80, 40, 10, 0.28);
}

.tile-pts {
  font-size: 8px;
  font-weight: 800;
  position: absolute;
  bottom: 4px;
  right: 6px;
  line-height: 1;
  opacity: 0.85;
  font-variant-numeric: tabular-nums;
  font-family: "Noto Sans", sans-serif;
  pointer-events: none; /* keep drag start on parent .tile */
}

/* P1 tiles: golden amber */
.tile-p1,
.tile-player1 {
  background: radial-gradient(circle at 35% 35%, #fffbf0 0%, #fae29c 60%, #eec25e 100%);
  border: 1.5px solid #c8853a;
  color: #5c2a06;
  box-shadow: 0 2px 6px rgba(200, 133, 58, 0.35);
}
.tile-p1:hover,
.tile-player1:hover {
  box-shadow:
    0 5px 14px rgba(200, 133, 58, 0.45),
    0 0 0 2.5px #f5c842;
}

/* P2 tiles: forest green */
.tile-p2,
.tile-player2 {
  background: radial-gradient(circle at 35% 35%, #f2fbf6 0%, #b8eacf 60%, #76caa0 100%);
  border: 1.5px solid #2e8b57;
  color: #0a3a20;
  box-shadow: 0 2px 6px rgba(46, 139, 87, 0.35);
}
.tile-p2:hover,
.tile-player2:hover {
  box-shadow:
    0 5px 14px rgba(46, 139, 87, 0.45),
    0 0 0 2.5px #5db882;
}

/* Wildcard tiles */
.tile-wild {
  background: radial-gradient(circle at 35% 35%, #faf7ff 0%, #ddd6fe 60%, #b59efa 100%);
  border: 1.5px solid #7c3aed;
  color: #3b0764;
  box-shadow: 0 2px 6px rgba(124, 58, 237, 0.3);
}
.tile-wild:hover {
  box-shadow:
    0 5px 14px rgba(124, 58, 237, 0.4),
    0 0 0 2.5px #7c3aed;
}

.tile-used {
  opacity: 0.3;
  cursor: default;
  pointer-events: none;
}

/* ─── TOPBAR CELL DISPLAY (selected cell + wildcard, lives in topbar) ── */
.topbar-cell-display {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}
.topbar-matra-studio {
  display: flex;
  align-items: center;
  gap: 8px;
  background: #fffcf4;
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  padding: 3px 6px;
  box-shadow: 0 1px 3px rgba(100, 50, 10, 0.05);
  flex-shrink: 0;
}
.matra-studio-header {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 1px;
}
.matra-studio-tag {
  font-size: 0.62rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #b07a28;
  line-height: 1.1;
  white-space: nowrap;
}
.matra-wheel-wrapper {
  display: flex;
  align-items: center;
  gap: 8px;
}

.wildcard-popup {
  position: fixed;
  inset: 0;
  z-index: 520;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 16px;
  background: rgba(44, 24, 16, 0.35);
  animation: toastSlideIn 0.22s ease;
}
.wildcard-popup.hidden {
  display: none;
}
.wildcard-popup-box {
  width: min(94vw, 420px);
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow-md);
  padding: 16px 16px 14px;
  text-align: center;
  margin-bottom: 12px;
}
.wildcard-popup-text {
  margin: 0 0 12px;
  font-size: 0.92rem;
  font-weight: 500;
  line-height: 1.4;
  color: var(--text);
}
.wildcard-grid {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
  margin: 0 0 14px;
}
.wildcard-btn {
  min-width: 36px;
  height: 38px;
  padding: 2px 6px;
  border-radius: 8px;
  border: 1.5px solid #c89c44;
  background: radial-gradient(circle at 35% 35%, #fffdf6 0%, #fbe8c3 60%, #eed29b 100%);
  color: var(--text);
  font-family: 'Noto Sans Devanagari', 'Noto Sans', sans-serif;
  font-size: 18px;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  position: relative;
}
.wildcard-btn:hover {
  border-color: var(--p1);
  transform: scale(1.06);
}
.wildcard-btn-pts {
  position: absolute;
  bottom: 1px;
  right: 3px;
  font-size: 9px;
  font-weight: 500;
  opacity: .55;
}
@media (min-width: 700px) {
  .wildcard-popup {
    align-items: center;
  }
  .wildcard-popup-box {
    margin-bottom: 0;
  }
}

.game-mode-name-row {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin: 12px 0;
}
.game-mode-name-row .control-label {
  font-size: 13px;
  color: var(--text-muted);
}
.game-mode-name-row .text-input {
  width: 100%;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 14px;
}
.game-mode-name-row .text-input:focus {
  outline: none;
  border-color: var(--p1);
}
.game-mode-setup-row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin: 12px 0 0;
}
.game-mode-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1 1 120px;
  min-width: 0;
}
.game-mode-field .control-label {
  font-size: 13px;
  color: var(--text-muted);
}
.game-mode-field .select-input {
  width: 100%;
  padding: 7px 10px;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 14px;
}

.selected-cell-display {
  width: 38px;
  height: 38px;
  border-radius: var(--radius-sm);
  background: var(--surface2);
  border: 1.5px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
  flex-shrink: 0;
  box-shadow: 0 0 0 2px var(--accent2);
}

/* ─── MATRA WHEEL (selected tile + visual matras) ── */
.matra-wheel {
  --mw-size: 92px;
  position: relative;
  width: var(--mw-size);
  height: var(--mw-size);
  border-radius: 50%;
  flex-shrink: 0;
  background: conic-gradient(
    from -90deg,
    #f3e4c0 0deg,
    #faf0d8 12deg,
    #f3e4c0 24deg,
    #faf0d8 36deg,
    #f3e4c0 48deg,
    #faf0d8 60deg,
    #f3e4c0 72deg,
    #faf0d8 84deg,
    #f3e4c0 96deg,
    #faf0d8 108deg,
    #f3e4c0 120deg,
    #faf0d8 132deg,
    #f3e4c0 144deg,
    #faf0d8 156deg,
    #f3e4c0 168deg,
    #faf0d8 180deg,
    #f3e4c0 192deg,
    #faf0d8 204deg,
    #f3e4c0 216deg,
    #faf0d8 228deg,
    #f3e4c0 240deg,
    #faf0d8 252deg,
    #f3e4c0 264deg,
    #faf0d8 276deg,
    #f3e4c0 288deg,
    #faf0d8 300deg,
    #f3e4c0 312deg,
    #faf0d8 324deg,
    #f3e4c0 336deg,
    #faf0d8 348deg,
    #f3e4c0 360deg
  );
  border: 2px solid #5c3a1a;
  box-shadow:
    0 0 0 1px #d4a84b,
    0 2px 6px rgba(80, 40, 10, 0.15);
}
.matra-wheel-ring {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  pointer-events: none;
  overflow: hidden;
}
.matra-wheel-spoke {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 1px;
  height: 50%;
  margin-left: -0.5px;
  background: rgba(92, 58, 26, 0.22);
  transform-origin: top center;
  pointer-events: none;
}
.matra-wheel-item {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 22px;
  height: 22px;
  margin: -11px 0 0 -11px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 600;
  color: #1a5c3a;
  background: transparent;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  pointer-events: auto;
  font-family: "Noto Serif Devanagari", "Noto Sans", serif;
  line-height: 1;
  padding: 0;
  z-index: 1;
  transition:
    background 0.12s,
    transform 0.12s,
    color 0.12s;
}
.matra-wheel-item:hover {
  background: rgba(26, 92, 58, 0.15);
  color: #0f3d26;
  transform: scale(1.2);
}
.matra-wheel-item:active {
  background: rgba(26, 92, 58, 0.25);
  transform: scale(0.95);
}
.matra-wheel-center {
  position: absolute;
  inset: 28%;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #fffdf8 0%, #fdf5e2 70%, #f5e4c0 100%);
  border: 2px solid #c9a050;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2;
  box-shadow: 0 1px 4px rgba(100, 60, 10, 0.14), inset 0 1px 1px rgba(255, 255, 255, 0.8);
}
#selectedCellContent {
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
  line-height: 1;
}
.matra-wheel-pts {
  position: absolute;
  right: 4px;
  bottom: 3px;
  font-size: 7.5px;
  font-weight: 700;
  color: var(--text-dim);
  font-family: "Noto Sans", sans-serif;
  line-height: 1;
}
.matra-wheel-pts:empty {
  display: none;
}

/* ─── BOARD FRAME ───────────────────────────────────────────────── */
.board-frame {
  border: 4px solid #8b6914;
  border-radius: 10px;
  padding: 6px;
  background: #c9a050;
  box-shadow:
    0 0 0 2px #d4a84b,
    0 6px 24px rgba(100, 60, 10, 0.35),
    inset 0 0 8px rgba(0, 0, 0, 0.15);
}

/* Coordinate board: [corner][cols…] / [row][cells…] — one CSS grid so labels always align */
.board-with-coords {
  --coord-gutter: 22px;
  --cell-size: 52px;
  --board-gap: 4px;
  display: grid;
  grid-template-columns: var(--coord-gutter) repeat(
      var(--grid-cols),
      var(--cell-size)
    );
  grid-template-rows: var(--coord-gutter) repeat(
      var(--grid-cols),
      var(--cell-size)
    );
  gap: var(--board-gap);
  width: max-content;
  max-width: 100%;
  margin: 0 auto;
  background: #b8892a;
  border-radius: 6px;
  padding: 4px;
  box-sizing: border-box;
}
.coord-corner {
  /* empty top-left */
}
.coord-label {
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: "Noto Sans", system-ui, sans-serif;
  font-size: 0.72rem;
  font-weight: 700;
  color: #f5ead0;
  line-height: 1;
  user-select: none;
  opacity: 0.95;
  text-shadow: 0 1px 0 rgba(60, 30, 0, 0.35);
  min-width: 0;
  min-height: 0;
}
.coord-col {
  align-self: center;
}
.coord-row {
  justify-self: center;
}

/* ─── GRID / BOARD ─────────────────────────────────────────────── */
:root {
  --grid-cols: 11;
  --cell-fs: 32px;
}

.grid-cell {
  width: var(--cell-size);
  height: var(--cell-size);
  border-radius: 50%;
  border: 1px solid var(--cell-border);
  background: #ede0c4;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--cell-fs);
  font-weight: 600;
  cursor: pointer;
  position: relative;
  transition:
    background 0.12s,
    transform 0.08s;
  user-select: none;
  -webkit-user-select: none;
  color: var(--text);
  box-sizing: border-box;
  min-width: 0;
  min-height: 0;
}
.grid-cell.dragging {
  opacity: 0.45;
}
.grid-cell:hover {
  border-color: #8b6914;
}
@keyframes dragOverPulse {
  0% {
    box-shadow:
      0 0 0 3px rgba(200, 133, 58, 0.9),
      0 0 0 6px rgba(200, 133, 58, 0.4);
  }
  50% {
    box-shadow:
      0 0 0 5px rgba(200, 133, 58, 1),
      0 0 0 10px rgba(200, 133, 58, 0.15);
  }
  100% {
    box-shadow:
      0 0 0 3px rgba(200, 133, 58, 0.9),
      0 0 0 6px rgba(200, 133, 58, 0.4);
  }
}
.grid-cell.drag-over {
  background: #ffe066 !important;
  border-color: #c8853a !important;
  border-width: 3px !important;
  animation: dragOverPulse 0.7s ease-in-out infinite;
  transform: scale(1.15);
  z-index: 2;
}
.grid-cell.selected {
  border-color: var(--accent) !important;
  box-shadow: 0 0 0 2px var(--accent);
  background: var(--accent2) !important;
}

/* Multiplier label — horizontal pair: number + symbol */
.cell-mult-label {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  display: inline-flex;
  align-items: center;
  gap: 1px;
  opacity: 0.82;
  color: inherit;
  pointer-events: none;
  font-family: "Noto Serif Devanagari", serif;
  line-height: 1;
  white-space: nowrap;
}
.mult-num {
  font-size: 24px;
  font-weight: 700;
  line-height: 1;
}
.mult-sym {
  font-size: 20px;
  font-weight: 400;
  line-height: 1;
  opacity: 0.9;
}

.cell-p1 .cell-mult-label,
.cell-p2 .cell-mult-label,
.cell-wild .cell-mult-label {
  display: none !important;
}

/* Cell multiplier themes */
.cell-dw {
  background: #fce8d5;
  border-color: #e07050;
  color: #8b2010;
}
.cell-tw {
  background: #f5d8f5;
  border-color: #c060c0;
  color: #7a0a7a;
}
.cell-dl {
  background: #d5e8fc;
  border-color: #5080d0;
  color: #1030a0;
}
.cell-tl {
  background: #e8d5fc;
  border-color: #8050c0;
  color: #400080;
}

/* Player-colored placed cells */
.cell-p1 {
  background: #fef3c0 !important;
  border-color: #c8853a !important;
  color: #5c2a06 !important;
}
.cell-p2 {
  background: #d4f0de !important;
  border-color: #2e8b57 !important;
  color: #0a3a20 !important;
}
.cell-wild::after {
  content: "*";
  position: absolute;
  right: 3px;
  bottom: 1px;
  font-size: 9px;
  font-weight: 800;
  color: #6d28d9;
}

/* ─── BOARD LEGEND ──────────────────────────────────────────────── */
.board-legend {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  font-size: 0.72rem;
  color: var(--text-dim);
}
.legend-chip {
  padding: 2px 7px;
  border-radius: 4px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  gap: 1px;
  font-family: "Noto Serif Devanagari", serif;
}
.legend-chip .mult-num {
  font-size: 13px;
}
.legend-chip .mult-sym {
  font-size: 9px;
  opacity: 0.9;
}
.legend-chip.dw {
  background: #fce8d5;
  border: 1px solid #e07050;
  color: #8b2010;
}
.legend-chip.tw {
  background: #f5d8f5;
  border: 1px solid #c060c0;
  color: #7a0a7a;
}
.legend-chip.dl {
  background: #d5e8fc;
  border: 1px solid #5080d0;
  color: #1030a0;
}
.legend-chip.tl {
  background: #e8d5fc;
  border: 1px solid #8050c0;
  color: #400080;
}
.legend-text {
  margin-right: 5px;
}

/* ─── ACTION BUTTONS ROW ────────────────────────────────────────── */
.board-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: nowrap;
  width: 100%;
  justify-content: center;
}
.board-actions .btn {
  padding: 6px 11px;
  font-size: 0.78rem;
}
.board-actions .toggle-label {
  font-size: 0.74rem;
  gap: 6px;
  white-space: nowrap;
}
.board-actions .toggle-track {
  width: 28px;
  height: 16px;
}
.board-actions .toggle-thumb {
  width: 12px;
  height: 12px;
}
.board-actions .toggle-label input:checked + .toggle-track .toggle-thumb {
  transform: translateX(12px);
}

/* ─── BOARD SECTION ─────────────────────────────────────────────── */
.board-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  grid-column: 1;
  grid-row: 3 / 5;
  width: 100%;
  min-width: 0;
  max-width: 100%;
  box-sizing: border-box;
}

/* ─── HIGHLIGHT FLASH ───────────────────────────────────────────── */
@keyframes highlightPulse {
  0% {
    box-shadow: 0 0 0 0 rgba(123, 28, 46, 0.55);
    background-color: var(--accent2);
  }
  60% {
    box-shadow: 0 0 0 6px rgba(123, 28, 46, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(123, 28, 46, 0);
    background-color: inherit;
  }
}
.highlight-flash {
  animation: highlightPulse 1.2s ease forwards;
  border-radius: var(--radius-sm);
}

/* Shared card surface style for right panel */
.scoreboard-card,
.tile-bag-card,
.lookup-card,
.keyboard-card {
  background: #fffdf8;
  border: 1.5px solid var(--border-light);
  border-radius: var(--radius);
  box-shadow: 0 2px 8px rgba(100, 50, 10, 0.07);
  width: 100%;
  box-sizing: border-box;
  position: relative;
  overflow: hidden;
  transition: box-shadow 0.15s ease;
}
.scoreboard-card:hover,
.tile-bag-card:hover,
.lookup-card:hover,
.keyboard-card:hover {
  box-shadow: 0 3px 12px rgba(100, 50, 10, 0.11);
}

/* ─── LOOKUP CARD ──────────────────────────────────────────────── */
.lookup-card {
  padding: 12px 14px;
}
.lookup-title {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 7px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  display: flex;
  align-items: center;
  gap: 5px;
}
.lookup-hint {
  font-size: 0.7rem;
  color: var(--text-dim);
  line-height: 1.45;
  margin-bottom: 8px;
  padding: 6px 9px;
  background: #fdf6e7;
  border: 1px solid #ebd9b0;
  border-left: 3px solid #c8853a;
  border-radius: var(--radius-sm);
}
.lookup-hint strong {
  color: var(--text);
  font-weight: 700;
}
.lookup-hint em {
  color: var(--p2);
  font-style: normal;
  font-weight: 700;
}
.lookup-hint code {
  font-family: monospace;
  background: #faebd0;
  color: var(--accent);
  padding: 1px 4px;
  border-radius: 3px;
  font-size: 0.88em;
  font-weight: 600;
}
.lookup-row {
  display: flex;
  gap: 6px;
  margin-bottom: 6px;
}
.lookup-row .text-input {
  background: #fffcf8;
  border: 1px solid var(--border-light);
  padding: 5px 9px;
  font-size: 0.8rem;
}
.lookup-actions {
  display: flex;
  gap: 6px;
  margin-bottom: 4px;
}
.lookup-actions .btn {
  flex: 1;
  padding: 5px 10px;
  font-size: 0.76rem;
  background: #fdf7e8;
  border: 1px solid #dfc38a;
  color: var(--text);
  border-radius: var(--radius-sm);
  transition: all 0.15s ease;
}
.lookup-actions .btn:hover {
  background: #faeed0;
  border-color: var(--accent);
  color: var(--accent);
}
.lookup-result {
  margin-top: 5px;
  font-size: 0.76rem;
  color: var(--text-dim);
}
.lookup-links {
  margin-top: 4px;
  font-size: 0.72rem;
  max-height: 150px;
  overflow-y: auto;
}
.lookup-link-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  padding: 3px 0;
  border-bottom: 1px solid var(--border-light);
}
.lookup-link-row:last-child {
  border-bottom: none;
}
.lookup-link-word {
  flex: 1;
  font-size: 0.85rem;
  color: var(--text);
}
.lookup-link-meaning {
  color: var(--p2);
  font-size: 0.72rem;
  white-space: nowrap;
  flex-shrink: 0;
}
.lookup-link-meaning:hover {
  text-decoration: underline;
}
.lookup-link-defs {
  flex-basis: 100%;
  font-size: 0.7rem;
  line-height: 1.35;
  color: var(--text-dim);
  padding-left: 29px; /* align under the word, past the place buttons */
}

/* Place word buttons */
.btn-place {
  border: none;
  border-radius: 4px;
  width: 22px;
  height: 22px;
  font-size: 13px;
  line-height: 1;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition:
    background 0.12s,
    transform 0.08s;
  padding: 0;
}
.btn-place:active {
  transform: scale(0.9);
}
.btn-place-h {
  background: #d5e8fc;
  color: #1030a0;
  border: 1px solid #5080d0;
}
.btn-place-h:hover {
  background: #b5d4f8;
}
.btn-place-v {
  background: var(--p2-light);
  color: var(--p2);
  border: 1px solid var(--p2-border);
}
.btn-place-v:hover {
  background: #a0d8b8;
}

/* ─── KEYBOARD CARD ────────────────────────────────────────────── */
.keyboard-card {
  padding: 10px 12px;
}
.kb-section-title {
  font-size: 0.66rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #b07a28;
  margin: 8px 0 4px;
}
.kb-section-title:first-child {
  margin-top: 0;
}
.kb-keys {
  display: flex;
  flex-wrap: wrap;
  gap: 3px;
}
.kb-key {
  min-width: 26px;
  min-height: 26px;
  padding: 1px 3px;
  background: #fffdf8;
  border: 1px solid var(--border-light);
  border-radius: 4px;
  color: var(--text);
  font-size: 13.5px;
  font-family: "Noto Serif Devanagari", serif;
  cursor: pointer;
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0;
  line-height: 1;
  transition:
    background 0.1s,
    transform 0.08s,
    border-color 0.1s;
  position: relative;
  box-shadow: 0 1px 2px rgba(100, 50, 10, 0.04);
}
.kb-key-label {
  font-size: 13.5px;
  line-height: 1;
}
.kb-bag-count {
  font-size: 7.5px;
  font-weight: 700;
  font-family: "Noto Sans", sans-serif;
  color: var(--text-dim);
  line-height: 1;
  margin-top: 1px;
}
.kb-key-empty {
  opacity: 0.35;
}
.kb-key-empty .kb-bag-count {
  color: #b91c1c;
}
.kb-key:hover {
  background: #faeed0;
  border-color: var(--accent);
  transform: translateY(-1px);
}
.kb-key:active {
  transform: scale(0.92);
}

/* ─── TILE BAG CARD ─────────────────────────────────────────────── */
.tile-bag-card {
  padding: 10px 12px;
}
.tile-bag-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 8px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border-light);
}
.tile-bag-title {
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 5px;
}
.tile-bag-title strong {
  font-variant-numeric: tabular-nums;
}
.tile-bag-icon {
  font-size: 0.95rem;
  opacity: 0.85;
}
.tile-bag-meta {
  display: flex;
  gap: 8px;
  font-size: 0.74rem;
  color: var(--text-dim);
}
.tile-bag-meta strong {
  color: var(--text);
  font-variant-numeric: tabular-nums;
}
.tile-bag-list {
  display: flex;
  flex-wrap: wrap;
  gap: 5px 8px;
  max-height: 150px;
  overflow-y: auto;
}
.tile-points-title {
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #b07a28;
  margin: 2px 0 4px;
}
.tile-points-grid {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 3px 6px;
  align-items: center;
}
.tile-points-letters {
  font-family: "Noto Serif Devanagari", "Noto Sans", serif;
  font-size: 0.78rem;
  color: var(--text);
  letter-spacing: 0.03em;
  line-height: 1.2;
}
.tile-points-note {
  margin: 5px 0 0;
  font-size: 0.65rem;
  color: var(--text-dim);
}
.tile-bag-item {
  display: inline-flex;
  align-items: baseline;
  gap: 2px;
  font-family: "Noto Serif Devanagari", "Noto Sans", serif;
  font-size: 0.88rem;
  color: var(--text);
  line-height: 1.2;
}
.tile-bag-letter {
  font-weight: 600;
}
.tile-bag-count {
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--text-dim);
  font-family: "Noto Sans", sans-serif;
}
.tile-bag-item-special .tile-bag-letter {
  color: #6d28d9;
}
.tile-bag-item-special .tile-bag-count {
  color: #7c3aed;
}

/* ─── SCOREBOARD ───────────────────────────────────────────────── */
.scoreboard-card {
  padding: 0;
}

/* Lifetime / session metrics */
.stats-bar {
  padding: 8px 10px;
  background: #f8f1de;
  border-bottom: 1px solid var(--border-light);
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 4px;
}
.stat-chip {
  background: #fffdf8;
  border: 1px solid var(--border-light);
  border-radius: 6px;
  padding: 4px 3px;
  text-align: center;
  box-shadow: 0 1px 2px rgba(100, 50, 10, 0.04);
  min-width: 0;
}
.stat-chip-accent {
  background: #fdf5e2;
  border-color: #c9a050;
  box-shadow: 0 1px 3px rgba(160, 100, 20, 0.08);
}
.stat-chip-label {
  display: block;
  font-size: 0.56rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text-dim);
  line-height: 1.1;
  margin-bottom: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.stat-chip-value {
  display: block;
  font-size: 1.05rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: var(--text);
  line-height: 1.1;
}

.stats-players {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 5px;
}
.stats-player {
  display: grid;
  grid-template-columns: auto 1fr auto;
  grid-template-rows: auto auto;
  column-gap: 6px;
  row-gap: 1px;
  align-items: center;
  padding: 4px 7px;
  border-radius: 6px;
  border: 1px solid var(--border-light);
  background: #fffdf8;
}
.stats-player-p1 {
  border-color: var(--p1-border);
  background: #fdf6ec;
}
.stats-player-p2 {
  border-color: var(--p2-border);
  background: #f2fbf6;
}
.stats-player-tag {
  grid-column: 1;
  grid-row: 1 / span 2;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.65rem;
  font-weight: 800;
  letter-spacing: 0.02em;
}
.stats-player-p1 .stats-player-tag {
  background: var(--p1);
  color: #fff8ee;
}
.stats-player-p2 .stats-player-tag {
  background: var(--p2);
  color: #f0fff6;
}
.stats-player-main {
  grid-column: 2;
  grid-row: 1;
  font-size: 0.98rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}
.stats-player-p1 .stats-player-main {
  color: var(--p1);
}
.stats-player-p2 .stats-player-main {
  color: var(--p2);
}
.stats-player-sub {
  grid-column: 2;
  grid-row: 2;
  font-size: 0.58rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-dim);
  line-height: 1;
}
.stats-player-life {
  grid-column: 3;
  grid-row: 1 / span 2;
  justify-self: end;
  align-self: center;
  font-size: 0.65rem;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.stats-player-life strong {
  color: var(--text);
  font-size: 0.74rem;
}

.score-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.74rem;
  background: #fffdf8;
}
.score-table thead tr {
  background: #f5ecd6;
  border-bottom: 1px solid var(--border-light);
}
.score-table th,
.score-table td {
  padding: 4px 8px;
  border-bottom: 1px solid var(--border-light);
  text-align: left;
  vertical-align: middle;
  word-break: break-word;
}
.score-table td:first-child,
.score-th-stat {
  color: var(--text-dim);
  font-size: 0.65rem;
  font-weight: 700;
  white-space: nowrap;
  width: 4.8rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.score-table th {
  font-size: 0.68rem;
  font-weight: 700;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 5px 8px;
}
.score-th-p {
  text-align: center;
  min-width: 2.8rem;
}
.score-table td.p1-col,
.score-table td.p2-col {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}
#score-p1-cell,
#score-p2-cell {
  text-align: center;
  font-size: 1rem;
  font-weight: 800;
}
.score-table .log-cell {
  font-size: 0.68rem;
  font-weight: 500;
  white-space: pre-line;
  text-align: left;
  max-height: 80px;
}
.score-table tbody tr:last-child td {
  border-bottom: none;
}
.score-table tbody tr:nth-child(even) {
  background: #fcf6e8;
}
.score-table tbody tr:hover {
  background: #faeed0;
}
.p1-col {
  color: var(--p1);
}
.p2-col {
  color: var(--p2);
}
.word-chip {
  display: inline-flex;
  align-items: baseline;
  gap: 3px;
  padding: 1px 5px 1px 6px;
  margin: 1px 0;
  border-radius: 999px;
  background: var(--surface2);
  border: 1px solid var(--border-light);
  font-size: 0.72rem;
  font-weight: 600;
  line-height: 1.4;
  white-space: nowrap;
}
.word-chip-label {
  font-weight: 600;
}
.word-chip-score {
  font-size: 0.62rem;
  font-weight: 700;
  padding: 0 4px;
  border-radius: 999px;
  min-width: 14px;
  text-align: center;
}
.p1-col .word-chip {
  border-color: var(--p1-border, var(--border));
  background: var(--p1-light, var(--surface2));
}
.p1-col .word-chip-score {
  background: var(--p1);
  color: #fff;
}
.p2-col .word-chip {
  border-color: var(--p2-border, var(--border));
  background: var(--p2-light, var(--surface2));
}
.p2-col .word-chip-score {
  background: var(--p2);
  color: #fff;
}
.log-cell {
  font-size: 0.65rem;
  max-width: 90px;
  word-break: break-word;
  line-height: 1.35;
}

/* ─── TOAST ────────────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 22px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 220px;
  max-width: min(92vw, 460px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--border);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 10px 14px 10px 12px;
  font-size: 0.85rem;
  font-weight: 500;
  line-height: 1.35;
  box-shadow: var(--shadow-md);
  z-index: 500;
  animation: toastSlideIn 0.28s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.toast::before {
  content: '';
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
  opacity: .9;
}

/* Default / neutral */
.toast::before {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23d4a84b' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='12' r='9'/%3E%3Cpath d='M12 16v-4M12 8h.01'/%3E%3C/svg%3E");
}

/* Success */
.toast.toast-ok {
  background: var(--p2-bg);
  border-color: var(--p2-border);
  border-left-color: var(--p2);
  color: #0e3b22;
}
.toast.toast-ok::before {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%231a5c3a' stroke-width='2.6' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M20 6L9 17l-5-5'/%3E%3C/svg%3E");
}

/* Error */
.toast.toast-error {
  background: #fdeee6;
  border-color: #c05030;
  border-left-color: #a52815;
  color: #6a160a;
}
.toast.toast-error::before {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23a52815' stroke-width='2.6' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='12' r='9'/%3E%3Cpath d='M12 8v4M12 16h.01'/%3E%3C/svg%3E");
}

@keyframes toastSlideIn {
  from {
    opacity: 0;
    transform: translateX(-50%) translateY(14px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateX(-50%) translateY(0) scale(1);
  }
}
.toast.hidden {
  display: none;
}

/* ─── RESPONSIVE ───────────────────────────────────────────────── */
@media (max-width: 1200px) {
  .main-layout {
    grid-template-columns: minmax(0, 1fr) 280px;
    gap: 12px;
  }
  .board-with-coords {
    --cell-size: 46px;
    --board-gap: 3px;
    --coord-gutter: 18px;
  }
  .coord-label {
    font-size: 0.62rem;
  }
  .mult-num {
    font-size: 15px;
  }
  .mult-sym {
    font-size: 12px;
  }
}

@media (max-width: 980px) {
  .main-layout {
    grid-template-columns: 1fr;
    gap: 14px;
  }
  .board-section {
    grid-column: 1;
    grid-row: 3;
  }
  .side-panel-right {
    grid-column: 1;
    grid-row: 4;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
  }
  .main-layout:has(#scrabbleReadOnlyBanner:not(.hidden)) .board-section {
    grid-row: 4;
  }
  .main-layout:has(#scrabbleReadOnlyBanner:not(.hidden)) .side-panel-right {
    grid-row: 5;
  }
  .side-panel-right > .scoreboard-card {
    grid-column: 1 / -1;
  }
  .score-tools {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    align-items: start;
  }
  .board-with-coords {
    --cell-size: 40px;
    --board-gap: 3px;
    --coord-gutter: 16px;
  }
  .coord-label {
    font-size: 0.58rem;
  }
}

/* Mobile */
@media (max-width: 600px) {
  .main-layout {
    display: flex;
    flex-direction: column;
    padding: 8px;
    gap: 10px;
    min-height: 100svh;
  }
  .side-panel-right {
    display: flex;
    flex-direction: column;
    gap: 10px;
  }
  .score-tools {
    display: flex;
    flex-direction: column;
    gap: 10px;
  }
  .game-topbar {

    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 6px;
    padding: 6px 8px;
    flex-wrap: nowrap;
  }
  .topbar-controls {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 5px 6px;
    flex: unset;
    min-width: 0;
  }
  .topbar-pill-card {
    padding: 2px 6px;
    gap: 5px;
  }
  .topbar-actions-group {
    gap: 4px;
  }
  .topbar-btn {
    padding: 3px 7px;
    font-size: 0.72rem;
    height: 25px;
  }
  .topbar-btn .btn-svg {
    width: 11px;
    height: 11px;
  }
  .topbar-status-card {
    padding: 2px 8px;
    font-size: 0.68rem;
    margin-left: 0;
  }
  .topbar-group {
    gap: 4px;
  }
  .topbar-lang {
    align-self: center;
    margin-left: 0;
  }
  .lang-select {
    font-size: 0.72rem !important;
    padding: 3px 22px 3px 7px !important;
    height: 24px;
  }
  .topbar-lang-globe {
    width: 24px;
    height: 24px;
  }
  .topbar-lang-globe svg {
    width: 13px;
    height: 13px;
  }
  .topbar-group .control-label {
    font-size: 0.62rem;
    letter-spacing: 0.04em;
  }
  .topbar-group .select-input {
    font-size: 0.75rem !important;
    padding: 2px 5px !important;
  }
  .topbar-cell-display {
    margin-left: 0;
    align-self: flex-start;
    width: 100%;
    justify-content: flex-end;
  }
  .topbar-matra-studio {
    padding: 2px 6px;
    gap: 6px;
    width: 100%;
    justify-content: space-between;
  }
  .matra-studio-tag {
    font-size: 0.58rem;
  }
  .wildcard-picker {
    flex-wrap: wrap;
    max-width: 110px;
  }

  /* Player bar — horizontal compact row on mobile */
  .player-bar {
    min-height: unset;
  }
  .player-meta {
    gap: 4px;
    padding: 4px 6px;
    min-width: unset;
  }
  .matra-block {
    padding: 2px 4px;
    gap: 1px;
  }
  .matra-block .select-input {
    max-width: 44px;
    font-size: 0.68rem !important;
  }
  .matra-label {
    font-size: 0.45rem;
  }
  .tile-rack {
    gap: 5px;
    padding: 5px 6px;
  }
  .rack-drop-zone {
    padding: 5px 8px;
    font-size: 0.68rem;
  }

  .player-name {
    font-size: 0.75rem;
  }
  .player-score {
    font-size: 1.1rem;
  }
  .tile {
    width: 40px;
    height: 40px;
    font-size: 22px;
  }
  .tile-pts {
    font-size: 7px;
    bottom: 3.5px;
    right: 5.5px;
  }
  .board-section {
    gap: 5px;
  }
  .board-frame {
    width: 100%;
    box-sizing: border-box;
    padding: 3px;
  }
  .board-with-coords {
    width: 100%;
    max-width: 100%;
    --coord-gutter: 13px;
    --board-gap: 2px;
    --cell-size: auto;
    grid-template-columns: var(--coord-gutter) repeat(
        var(--grid-cols),
        minmax(0, 1fr)
      );
    grid-template-rows: 13px repeat(var(--grid-cols), auto);
    padding: 2px;
  }
  .grid-cell {
    width: 100%;
    height: auto;
    aspect-ratio: 1;
    font-size: var(--cell-fs);
    line-height: 1;
  }
  .coord-label {
    font-size: 0.58rem;
    font-weight: 800;
    color: #fff6e0;
  }
  .coord-row {
    align-self: stretch;
  }
  .cell-mult-label {
    gap: 0;
  }
  .mult-num {
    font-size: 11px;
  }
  .mult-sym {
    font-size: 9px;
  }
  .selected-cell-display {
    width: 34px;
    height: 34px;
    font-size: 16px;
  }
  .matra-wheel {
    --mw-size: 76px;
  }
  .matra-wheel-item {
    width: 18px;
    height: 18px;
    margin: -9px 0 0 -9px;
    font-size: 11px;
  }
  #selectedCellContent {
    font-size: 15px;
  }
  .matra-wheel-pts {
    right: 3px;
    bottom: 3px;
    font-size: 7px;
  }
  .board-actions {
    gap: 4px;
    flex-wrap: wrap;
  }
  .board-actions .btn {
    padding: 5px 9px;
    font-size: 0.72rem;
  }
  .board-legend {
    display: none;
  }
  .side-panel-right {
    display: flex;
    flex-direction: column;
  }
  .scoreboard-card {
    max-height: none;
    overflow: visible;
  }
  .stats-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .stat-chip-value {
    font-size: 1.05rem;
  }
  .stats-players {
    grid-template-columns: 1fr 1fr;
  }
  .score-table {
    font-size: 0.73rem;
  }
  .score-table th,
  .score-table td {
    padding: 4px 6px;
  }
  .score-tools {
    display: flex;
    flex-direction: column;
    gap: 8px;
  }
  .keyboard-card,
  .lookup-card {
    padding: 9px;
  }
  .kb-key {
    min-width: 25px;
    height: 25px;
    font-size: 13px;
  }
  .toast {
    bottom: 10px;
    width: max-content;
    max-width: calc(100vw - 20px);
  }
}

/* ─── MOBILE LOG PANEL ──────────────────────────────────────────── */
.mobile-log-panel {
  display: none;
}

@media (max-width: 600px) {
  .mobile-log-panel {
    display: flex;
    flex-direction: column;
    gap: 5px;
    background: var(--surface2);
    border: 1px solid var(--border-light);
    border-radius: var(--radius);
    padding: 7px 9px;
  }
  .mobile-log-entry {
    display: flex;
    align-items: baseline;
    gap: 6px;
    font-size: 0.76rem;
  }
  .mobile-log-label {
    font-weight: 700;
    font-size: 0.68rem;
    min-width: 16px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    opacity: 0.7;
  }
  .mobile-log-score {
    font-weight: 700;
    font-size: 0.92rem;
    min-width: 24px;
  }
  .mobile-log-p1 .mobile-log-score {
    color: var(--p1);
  }
  .mobile-log-p2 .mobile-log-score {
    color: var(--p2);
  }
  .mobile-log-text {
    flex: 1;
    color: var(--text-dim);
    font-size: 0.73rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
}

/* Very small phones */
@media (max-width: 380px) {
  .board-with-coords {
    --coord-gutter: 11px;
    --board-gap: 1.5px;
    grid-template-rows: 11px repeat(var(--grid-cols), auto);
    padding: 1px;
  }
  .coord-label {
    font-size: 0.5rem;
  }
  .tile {
    width: 36px;
    height: 36px;
    font-size: 18px;
  }
  .tile-pts {
    font-size: 6.5px;
    bottom: 3px;
    right: 5px;
  }
  .matra-wheel {
    --mw-size: 64px;
  }
  .matra-wheel-item {
    width: 16px;
    height: 16px;
    margin: -8px 0 0 -8px;
    font-size: 9px;
  }
  #selectedCellContent {
    font-size: 13px;
  }
  .topbar-group .control-label {
    display: none;
  }
}

/* Host-site floating menu (FABs) overlaid on the board */
.floating-menu,
.floating-menu ul.fm-bar,
ul.fm-bar {
  display: none !important;
  visibility: hidden !important;
  pointer-events: none !important;
}

/* ─── SAVE / SHARE / LOGIN / READ-ONLY (new) ─────────────────────── */

/* Login benefits list inside the login-prompt modal */
.login-benefits {
  list-style: none;
  margin: 12px 0 4px;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.login-benefits li {
  position: relative;
  padding-left: 22px;
  font-size: 0.9rem;
  line-height: 1.5;
  color: var(--text);
}
.login-benefits li::before {
  content: "✓";
  position: absolute;
  left: 0;
  top: 0;
  color: var(--p2);
  font-weight: 700;
}

/* Share modal input row */
.share-input-row {
  display: flex;
  gap: 8px;
  margin: 12px 0 4px;
  align-items: stretch;
}
.share-input-row .text-input {
  flex: 1 1 auto;
  min-width: 0;
}
#shareGameUrl {
  font-size: 0.8rem;
  background: var(--surface2);
}

.share-lock-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 14px 0 4px;
  padding: 10px 12px;
  background: var(--surface2);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
}
.share-lock-copy {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.share-lock-label {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--accent);
}
.share-lock-hint {
  font-size: 0.72rem;
  color: var(--text-dim);
  line-height: 1.35;
}
.share-lock-toggle {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--p1-border);
  background: #fce8d5;
  color: #7a1a0a;
  border-radius: 999px;
  padding: 5px 12px 5px 6px;
  font-size: 0.75rem;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
  white-space: nowrap;
}
.share-lock-toggle.is-unlocked {
  background: #d4f0de;
  border-color: var(--p2-border);
  color: var(--p2);
}
.share-lock-knob {
  width: 28px;
  height: 16px;
  border-radius: 999px;
  background: #c05030;
  position: relative;
  flex-shrink: 0;
}
.share-lock-toggle.is-unlocked .share-lock-knob {
  background: var(--p2);
}
.share-lock-knob::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #fff;
  transition: left 0.15s ease;
}
.share-lock-toggle.is-unlocked .share-lock-knob::after {
  left: 14px;
}

/* Owner-only share group in the topbar */
.scrabble-share-group {
  display: flex;
  align-items: center;
  gap: 8px;
}
.scrabble-share-group.hidden {
  display: none;
}

/* Read-only banner — rich banner inside .main-layout */
.scrabble-readonly-banner {
  grid-column: 1 / -1;
  position: relative;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 18px;
  background: linear-gradient(135deg, #7b1c2e 0%, #a33246 100%);
  color: #fff;
  border-radius: var(--radius);
  border: 1px solid rgba(255, 255, 255, 0.2);
  box-shadow: 0 4px 14px rgba(123, 28, 46, 0.25), 0 2px 6px rgba(0, 0, 0, 0.08);
  box-sizing: border-box;
  animation: fadeIn 0.2s ease;
}
.scrabble-readonly-banner.hidden {
  display: none !important;
}
.readonly-banner-icon {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.18);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.readonly-banner-icon svg {
  width: 18px;
  height: 18px;
  stroke: #fff;
}
.readonly-banner-content {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.readonly-banner-tag {
  font-size: 0.86rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: #fff;
}
.readonly-banner-text {
  font-size: 0.76rem;
  color: rgba(255, 255, 255, 0.9);
  line-height: 1.35;
}
@media (max-width: 600px) {
  .scrabble-readonly-banner {
    padding: 9px 12px;
    gap: 10px;
  }
  .readonly-banner-icon {
    width: 28px;
    height: 28px;
  }
  .readonly-banner-icon svg {
    width: 15px;
    height: 15px;
  }
  .readonly-banner-tag {
    font-size: 0.8rem;
  }
  .readonly-banner-text {
    font-size: 0.7rem;
  }
}

/* Read-only mode: disable every interactive surface */
body.scrabble-readonly .board-section,
body.scrabble-readonly .player-bar,
body.scrabble-readonly .tile-rack,
body.scrabble-readonly .board-actions,
body.scrabble-readonly .score-tools,
body.scrabble-readonly .matra-block,
body.scrabble-readonly .wildcard-picker {
  pointer-events: none;
  opacity: 0.9;
  filter: grayscale(0.15);
}
body.scrabble-readonly .game-topbar .topbar-controls,
body.scrabble-readonly .topbar-lang,
body.scrabble-readonly .topbar-cell-display {
  pointer-events: none;
}
body.scrabble-readonly .grid-cell {
  cursor: default !important;
}
body.scrabble-readonly .tile {
  cursor: default !important;
}

/* ─── MY GAMES DASHBOARD (new) ───────────────────────────────────── */
.scrabble-mygames-wrap {
  max-width: 960px;
  margin: 24px auto;
  padding: 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow, 0 4px 16px rgba(0, 0, 0, 0.08));
}
.scrabble-mygames-header h2 {
  margin: 0 0 4px;
  color: var(--accent);
  font-size: 1.4rem;
}
.scrabble-mygames-count {
  margin: 0 0 8px;
  color: var(--text);
}
.scrabble-mygames-new {
  margin: 0 0 16px;
}
.scrabble-mygames-new .btn {
  text-decoration: none;
  display: inline-block;
}
.scrabble-mygames-empty {
  padding: 24px;
  text-align: center;
  color: var(--text-dim);
  background: var(--surface2);
  border-radius: 10px;
  border: 1px dashed var(--border);
}
.scrabble-mygames-empty a {
  color: var(--accent);
  font-weight: 600;
}
.scrabble-mygames-note {
  margin-top: 12px;
  font-size: 0.8rem;
  color: var(--text-dim);
  line-height: 1.5;
}
.scrabble-mygames-alert {
  max-width: 640px;
  margin: 40px auto;
  padding: 20px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 10px;
  text-align: center;
  color: var(--text);
}
.scrabble-mygames-alert a {
  color: var(--accent);
  font-weight: 600;
}
.scrabble-mygames-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}
.scrabble-mygames-table th,
.scrabble-mygames-table td {
  padding: 10px 8px;
  text-align: left;
  border-bottom: 1px solid var(--border-light);
  vertical-align: middle;
}
.scrabble-mygames-table th {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-dim);
  background: var(--surface2);
}
.scrabble-mygames-table th.mg-col-toggle {
  width: 36px;
  padding: 10px 4px;
}
.scrabble-mygames-table th.mg-col-actions {
  text-align: right;
  width: 1%;
  white-space: nowrap;
}
.scrabble-mygames-table tbody tr.mg-row {
  cursor: pointer;
}
.scrabble-mygames-table tbody tr.mg-row:hover {
  background: var(--surface2);
}
.scrabble-mygames-table tbody tr.mg-row.is-open {
  background: var(--surface2);
}
.mg-sno {
  width: 36px;
  text-align: center;
  white-space: nowrap;
}
.mg-sno-num {
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
}
.mg-toggle {
  background: transparent;
  border: 0;
  padding: 0 4px 0 0;
  margin: 0;
  cursor: pointer;
  color: var(--text-dim);
  font: inherit;
  line-height: 1;
}
.mg-toggle:hover,
.mg-toggle:focus-visible {
  color: var(--accent);
}
.mg-chevron {
  display: inline-block;
  transition: transform 0.15s ease;
}
.mg-row.is-open .mg-chevron {
  transform: rotate(90deg);
}
.mg-name-text {
  cursor: pointer;
  font-weight: 600;
}
.mg-name-text:hover {
  color: var(--accent);
}
.mg-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  white-space: nowrap;
  justify-content: flex-end;
}
.mg-details[hidden] {
  display: none;
}
.mg-details > td {
  padding: 0 8px 12px 56px;
  background: var(--surface2);
  border-bottom: 1px solid var(--border-light);
}
.mg-details-grid {
  margin: 0;
  padding: 10px 0 4px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 8px 24px;
}
.mg-details-row {
  margin: 0;
  display: flex;
  align-items: baseline;
  gap: 8px;
  font-size: 0.78rem;
}
.mg-details-row dt {
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  font-size: 0.68rem;
  font-weight: 600;
  margin: 0;
  min-width: 90px;
}
.mg-details-row dd {
  margin: 0;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}
.mg-lock-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
  margin-left: 6px;
}
.mg-lock-badge.is-locked {
  background: #fce8d5;
  color: #7a1a0a;
  border: 1px solid #d8a070;
}
.mg-lock-badge.is-unlocked {
  background: #d4f0de;
  color: var(--p2);
  border: 1px solid var(--p2-border);
}
.mg-lock-badge.is-autosave {
  background: var(--p1-light);
  color: var(--p1);
  border: 1px solid var(--p1-border);
}
@media (max-width: 640px) {
  .scrabble-mygames-table {
    font-size: 0.78rem;
  }
  .mg-actions .btn {
    padding: 4px 8px;
    font-size: 0.7rem;
  }
  .mg-details > td {
    padding-left: 24px;
  }
}


/* ───────────────────── SHARED / MULTIPLAYER INDICATORS ───────────────────── */

.topbar-multiplayer {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.scrabble-live-status {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .02em;
  color: var(--text-dim);
  padding: 3px 9px 3px 20px;
  border: 1px solid var(--border-light);
  border-radius: 999px;
  background: var(--surface);
  position: relative;
  white-space: nowrap;
}

.scrabble-live-status:empty {
  display: none;
}

.scrabble-live-status::before {
  content: "";
  position: absolute;
  left: 8px;
  top: 50%;
  transform: translateY(-50%);
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-dim);
}

.scrabble-live-status.is-live::before   { background: var(--p2-border); }
.scrabble-live-status.is-polling::before { background: var(--border); }
.scrabble-live-status.is-offline::before { background: var(--p1); }

.scrabble-turn-banner {
  font-size: 12px;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  background: var(--p2-light);
  color: var(--p2);
  border: 1px solid var(--p2-border);
  white-space: nowrap;
}

.scrabble-turn-banner.is-waiting {
  background: var(--p1-light);
  color: var(--p1);
  border-color: var(--p1-border);
}

/* A seat locked to the opponent (shared/multiplayer game): dim it so the
   viewer can see they may not touch that rack. Functional locking is done
   via pointer-events:none + disabled controls in game-persistence.js. */
.player-bar.is-seat-locked {
  opacity: .45;
  filter: grayscale(.4);
}
.player-bar.is-seat-locked .tile-rack {
  cursor: not-allowed;
}
