/* ─── 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 {
  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;
  gap: 12px;
  flex-wrap: wrap;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 16px;
  box-shadow: var(--shadow);
}
.topbar-group {
  display: flex;
  align-items: center;
  gap: 6px;
}
.game-topbar .btn-ghost {
  margin-left: auto;
}

/* ─── 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;
}

.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-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: 1fr 300px;
  grid-template-rows: auto auto;
  gap: 10px;
  padding: 12px 14px;
  max-width: 1440px;
  margin: 0 auto;
  width: 100%;
  box-sizing: border-box;
  align-items: start;
}
.game-topbar {
  grid-column: 1 / -1;
}

/* ─── SIDE PANEL (right) ────────────────────────────────────────── */
.side-panel-right {
  display: flex;
  flex-direction: column;
  gap: 10px;
  grid-column: 2;
  grid-row: 2 / 4;
}
.score-tools {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* ─── PLAYER BAR ────────────────────────────────────────────────── */
.player-bar {
  display: flex;
  align-items: stretch;
  gap: 0;
  border-radius: var(--radius);
  background: var(--surface);
  border: 2px solid var(--border-light);
  box-shadow: var(--shadow);
  width: 100%;
  overflow: hidden;
}

.player1-bar {
  border-color: var(--p1-border);
}
.player2-bar {
  border-color: var(--p2-border);
}

/* Player meta section (radio + score + generate btn) */
.player-meta {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 6px 10px;
  background: var(--surface2);
  border-right: 1px solid var(--border-light);
  flex-shrink: 0;
  min-width: 64px;
}
.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.3rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: var(--accent);
  line-height: 1;
}
.player1-bar .player-score {
  color: var(--p1);
}
.player2-bar .player-score {
  color: var(--p2);
}

/* Matra block */
.matra-block {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 5px 8px;
  border-right: 1px solid var(--border-light);
  flex-shrink: 0;
}
.matra-block-p1 {
  background: #fdf4e4;
  border: 2px solid var(--p1-border);
  border-radius: 0;
  border-top: none;
  border-bottom: none;
}
.matra-block-p2 {
  background: var(--p2-bg);
  border: 2px solid var(--p2-border);
  border-radius: 0;
  border-top: none;
  border-bottom: none;
}
.matra-label {
  font-size: 0.6rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-dim);
  white-space: nowrap;
}

/* 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: 6px 8px;
  align-items: center;
  flex: 1;
  min-width: 0;
  background: #fffdf5;
}

/* 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: 4px 14px;
  width: 100%;
  box-sizing: border-box;
  border: 2px 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: 1rem;
  line-height: 1;
}

/* ─── GENERATE BUTTON ───────────────────────────────────────────── */
.generate-btn {
  appearance: none !important;
  -webkit-appearance: none !important;
  width: 28px !important;
  min-width: 28px !important;
  max-width: 28px !important;
  height: 28px !important;
  min-height: 28px !important;
  max-height: 28px !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 28px !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: 16px !important;
  height: 16px !important;
  display: block !important;
  fill: none !important;
  flex: 0 0 16px !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: 48px;
  height: 48px;
  border-radius: 50%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-size: 26px;
  font-weight: 700;
  cursor: pointer;
  position: relative;
  user-select: none;
  flex-shrink: 0;
  transition:
    transform 0.12s,
    box-shadow 0.12s;
}
.tile:hover {
  transform: translateY(-3px) scale(1.08);
}

.tile-pts {
  font-size: 7px;
  font-weight: 700;
  position: absolute;
  bottom: 3px;
  right: 5px;
  opacity: 0.75;
  font-variant-numeric: tabular-nums;
  font-family: "Noto Sans", sans-serif;
}

/* P1 tiles: golden amber */
.tile-p1,
.tile-player1 {
  background: linear-gradient(145deg, #fef0c0, #f5c842);
  border: 2px solid #c8853a;
  color: #5c2a06;
  box-shadow: 0 3px 8px rgba(200, 133, 58, 0.4);
}
.tile-p1:hover,
.tile-player1:hover {
  box-shadow:
    0 6px 16px rgba(200, 133, 58, 0.5),
    0 0 0 3px #f5c842;
}

/* P2 tiles: forest green */
.tile-p2,
.tile-player2 {
  background: linear-gradient(145deg, #c8efd8, #5db882);
  border: 2px solid #2e8b57;
  color: #0a3a20;
  box-shadow: 0 3px 8px rgba(46, 139, 87, 0.4);
}
.tile-p2:hover,
.tile-player2:hover {
  box-shadow:
    0 6px 16px rgba(46, 139, 87, 0.5),
    0 0 0 3px #5db882;
}

/* Wildcard tiles */
.tile-wild {
  background: linear-gradient(145deg, #ede9fe, #c4b5fd);
  border: 2px solid #7c3aed;
  color: #3b0764;
  box-shadow: 0 3px 8px rgba(124, 58, 237, 0.35);
}
.tile-wild:hover {
  box-shadow:
    0 6px 16px rgba(124, 58, 237, 0.45),
    0 0 0 3px #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;
  margin-left: 4px;
}
.wildcard-picker {
  display: flex;
  align-items: center;
  gap: 6px;
}

.selected-cell-display {
  width: 42px;
  height: 42px;
  border-radius: var(--radius-sm);
  background: var(--surface2);
  border: 2px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  font-weight: 700;
  color: var(--text);
  flex-shrink: 0;
  box-shadow: 0 0 0 3px var(--accent2);
}

/* ─── 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);
}

/* ─── GRID / BOARD ─────────────────────────────────────────────── */
:root {
  --grid-cols: 11;
  --cell-fs: 32px;
}

.grid {
  display: grid;
  grid-template-columns: repeat(var(--grid-cols), 52px);
  gap: 4px;
  background: #b8892a;
  border-radius: 6px;
}

.grid-cell {
  width: 52px;
  height: 52px;
  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;
  color: var(--text);
}
.grid-cell:hover {
  border-color: #8b6914;
}
.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: 10px;
  flex-wrap: wrap;
  width: 100%;
  justify-content: center;
}

/* ─── BOARD SECTION ─────────────────────────────────────────────── */
.board-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  grid-column: 1;
  grid-row: 2 / 4;
  width: 100%;
}

/* ─── 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);
}

/* ─── LOOKUP CARD ──────────────────────────────────────────────── */
.lookup-card {
  background: var(--surface);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  padding: 12px;
  box-shadow: var(--shadow);
}
.lookup-title {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-dim);
  margin-bottom: 7px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.lookup-hint {
  font-size: 0.71rem;
  color: var(--text-dim);
  line-height: 1.5;
  margin-bottom: 8px;
  padding: 6px 8px;
  background: var(--surface2);
  border-radius: var(--radius-sm);
  border-left: 3px solid var(--p1-border);
}
.lookup-hint strong {
  color: var(--text);
}
.lookup-hint em {
  color: var(--p2);
  font-style: normal;
  font-weight: 600;
}
.lookup-hint code {
  font-family: monospace;
  background: var(--accent2);
  color: var(--accent);
  padding: 0 3px;
  border-radius: 3px;
  font-size: 0.85em;
}
.lookup-row {
  display: flex;
  flex-direction: column;
  gap: 5px;
  margin-bottom: 6px;
}
.lookup-result {
  margin-top: 6px;
  font-size: 0.78rem;
  color: var(--text-dim);
}
.lookup-links {
  margin-top: 4px;
  font-size: 0.73rem;
  max-height: 150px;
  overflow-y: auto;
}
.lookup-link-row {
  display: flex;
  align-items: center;
  gap: 7px;
  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.88rem;
  color: var(--text);
}
.lookup-link-meaning {
  color: var(--p2);
  font-size: 0.73rem;
  white-space: nowrap;
  flex-shrink: 0;
}
.lookup-link-meaning:hover {
  text-decoration: underline;
}

/* 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 {
  background: var(--surface);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  padding: 12px;
  box-shadow: var(--shadow);
}
.kb-section-title {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
  margin: 7px 0 4px;
}
.kb-section-title:first-child {
  margin-top: 0;
}
.kb-keys {
  display: flex;
  flex-wrap: wrap;
  gap: 3px;
}
.kb-key {
  min-width: 26px;
  height: 26px;
  padding: 0 4px;
  background: var(--surface2);
  border: 1px solid var(--border-light);
  border-radius: 4px;
  color: var(--text);
  font-size: 14px;
  font-family: "Noto Serif Devanagari", serif;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition:
    background 0.1s,
    transform 0.08s;
}
.kb-key:hover {
  background: var(--accent2);
  border-color: var(--accent);
}
.kb-key:active {
  transform: scale(0.92);
}

/* ─── SCOREBOARD ───────────────────────────────────────────────── */
.scoreboard-card {
  background: var(--surface);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  padding: 0;
  overflow: hidden;
  box-shadow: var(--shadow);
}
.score-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.78rem;
}
.score-table thead tr {
  background: var(--surface2);
  border-bottom: 1px solid var(--border-light);
}
.score-table th,
.score-table td {
  padding: 6px 9px;
  border-bottom: 1px solid var(--border-light);
  text-align: left;
  vertical-align: top;
}
.score-table td:first-child {
  color: var(--text-dim);
  font-size: 0.72rem;
  white-space: nowrap;
}
.score-table th {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.p1-col {
  color: var(--p1);
}
.p2-col {
  color: var(--p2);
}
.log-cell {
  font-size: 0.68rem;
  max-width: 90px;
  word-break: break-word;
  line-height: 1.4;
}

/* ─── TOAST ────────────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 22px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 9px 18px;
  font-size: 0.83rem;
  box-shadow: var(--shadow);
  z-index: 500;
  animation: fadeIn 0.2s ease;
}
.toast.toast-error {
  background: #fce8d5;
  border-color: #c05030;
  color: #7a1a0a;
}
.toast.toast-ok {
  background: #d4f0de;
  border-color: var(--p2-border);
  color: var(--p2);
}
@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateX(-50%) translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
  }
}

/* ─── RESPONSIVE ───────────────────────────────────────────────── */
@media (max-width: 1050px) {
  .main-layout {
    grid-template-columns: 1fr 250px;
  }
  .grid {
    grid-template-columns: repeat(var(--grid-cols), 44px);
    gap: 3px;
  }
  .grid-cell {
    width: 44px;
    height: 44px;
  }
  .mult-num {
    font-size: 15px;
  }
  .mult-sym {
    font-size: 12px;
  }
}

@media (max-width: 860px) {
  .main-layout {
    grid-template-columns: 1fr;
  }
  .board-section {
    grid-column: 1;
    grid-row: 2;
  }
  .side-panel-right {
    grid-column: 1;
    grid-row: 3;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
  }
  .side-panel-right > .scoreboard-card {
    grid-column: 1 / -1;
  }
  .score-tools {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    align-items: start;
  }
  .grid {
    grid-template-columns: repeat(var(--grid-cols), 40px);
    gap: 3px;
  }
  .grid-cell {
    width: 40px;
    height: 40px;
  }
}

/* Mobile */
@media (max-width: 600px) {
  .main-layout {
    display: flex;
    flex-direction: column;
    padding: 8px;
    gap: 6px;
    min-height: 100svh;
  }
  .game-topbar {
    position: sticky;
    top: 0;
    z-index: 40;
    flex-wrap: wrap;
    gap: 6px;
    padding: 6px 10px;
  }
  .game-topbar .btn-ghost {
    margin-left: 0;
  }

  /* Player bar — horizontal compact row on mobile */
  .player-bar {
    min-height: unset;
  }
  .player-meta {
    flex-direction: row;
    gap: 5px;
    padding: 5px 8px;
    min-width: unset;
  }
  .matra-block {
    flex-direction: row;
    padding: 5px 6px;
    gap: 4px;
  }
  .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;
  }
  .board-section {
    gap: 5px;
  }
  .board-frame {
    width: 100%;
    box-sizing: border-box;
    padding: 4px;
  }
  .grid {
    width: 100%;
    grid-template-columns: repeat(var(--grid-cols), minmax(0, 1fr));
    gap: 2px;
  }
  .grid-cell {
    width: auto;
    height: auto;
    aspect-ratio: 1;
    /* font-size driven by --cell-fs set in JS */
    line-height: 1;
  }
  .cell-mult-label {
    gap: 0;
  }
  .selected-cell-display {
    width: 34px;
    height: 34px;
    font-size: 16px;
  }
  .board-actions {
    gap: 6px;
  }
  .board-actions .btn {
    padding: 6px 11px;
    font-size: 0.78rem;
  }
  .board-legend {
    display: none;
  }
  .side-panel-right {
    display: flex;
    flex-direction: column;
  }
  .scoreboard-card {
    max-height: 130px;
    overflow-y: auto;
  }
  .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) {
  .grid {
    width: 100%;
    grid-template-columns: repeat(var(--grid-cols), minmax(0, 1fr));
  }
  .tile {
    width: 36px;
    height: 36px;
    font-size: 18px;
  }
}