:root {
  --bg: #f6f3ea;
  --card: #ffffff;
  --ink: #2b2320;
  --muted: #6b6255;
  --accent: #b8860b;
  --accent-dark: #8a6508;
  --border: #e3dcc9;
  --danger: #b3403a;
  --ok: #2f7d4a;
  --warn: #b26a00;
  --board: #1f6b52;
  --cell: #e9e1c9;
  --tile: #f3dfae;
  --tile-edge: #c9a660;
  --tw: #2e9e57;
  --dw: #f4d03f;
  --dl: #3d7fd6;
  --tl: #d9382f;
}

* { box-sizing: border-box; }

.hidden { display: none !important; }

body {
  margin: 0;
  font-family: 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--ink);
  min-height: 100vh;
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  background: var(--accent);
  color: #fff;
  flex-wrap: wrap;
  gap: 0.5rem;
}

header h1 { margin: 0; font-size: 1.3rem; }

button { font: inherit; }

.primary-btn,
.secondary-btn,
.ghost-btn,
.ghost-dark-btn {
  padding: 0.6rem 1rem;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
  border: 1px solid transparent;
}

.primary-btn { background: var(--accent); color: #fff; }
.primary-btn:hover:not(:disabled) { background: var(--accent-dark); }
.secondary-btn { background: var(--card); color: var(--ink); border-color: var(--border); }
.secondary-btn:hover:not(:disabled) { border-color: var(--accent); }
.ghost-btn { background: transparent; color: #fff; border-color: rgba(255, 255, 255, 0.7); }
.ghost-btn:hover { background: rgba(255, 255, 255, 0.15); }
.ghost-dark-btn { background: transparent; color: var(--danger); border-color: var(--border); }
button:disabled { opacity: 0.45; cursor: default; }

.link-btn {
  background: none;
  border: none;
  padding: 0;
  color: var(--accent-dark);
  text-decoration: underline;
  cursor: pointer;
  font-size: 0.85rem;
}

.panel {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1rem;
}

.section-title { margin: 0 0 0.6rem; font-size: 1.1rem; }
.sub-title { margin: 1rem 0 0.4rem; font-size: 0.95rem; }
.hint { margin: 0.5rem 0 0; font-size: 0.85rem; color: var(--muted); }

/* ---------- Inicio ---------- */

.setup {
  max-width: 1000px;
  margin: 0 auto;
  padding: 1rem;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 1.25rem;
  align-items: start;
}

.field { display: flex; flex-direction: column; gap: 0.3rem; margin-bottom: 1rem; font-weight: 600; }

.field input,
.verify-form input {
  padding: 0.65rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 1.05rem;
  font: inherit;
}

fieldset { border: none; padding: 0; margin: 0 0 1rem; }
legend { font-weight: 600; margin-bottom: 0.4rem; padding: 0; }

.modes { display: grid; grid-template-columns: repeat(auto-fit, minmax(9rem, 1fr)); gap: 0.6rem; }
.modes legend { grid-column: 1 / -1; }

.mode input,
.difficulty input { position: absolute; opacity: 0; pointer-events: none; }

.mode-card {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  height: 100%;
  padding: 0.8rem;
  border: 2px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
}

.mode-card small { color: var(--muted); }
.mode input:checked + .mode-card { border-color: var(--accent); background: #fbf5e4; }
.mode input:focus-visible + .mode-card,
.difficulty input:focus-visible + span { outline: 2px solid var(--accent-dark); outline-offset: 2px; }

.difficulty { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.difficulty legend { width: 100%; }

.difficulty span {
  display: inline-block;
  padding: 0.45rem 0.9rem;
  border: 2px solid var(--border);
  border-radius: 999px;
  cursor: pointer;
  font-weight: 600;
}

.difficulty input:checked + span { border-color: var(--accent); background: #fbf5e4; }

.setup-actions { display: flex; gap: 0.6rem; flex-wrap: wrap; }

.rules { margin: 0 0 1rem; padding-left: 1.2rem; font-size: 0.92rem; }
.rules li { margin-bottom: 0.35rem; }

.premium-table { border-collapse: collapse; font-size: 0.9rem; }
.premium-table td { padding: 0.2rem 0.5rem 0.2rem 0; }

.swatch { display: inline-block; width: 1.1rem; height: 1.1rem; border-radius: 3px; vertical-align: middle; }
.swatch.tw { background: var(--tw); }
.swatch.dw { background: var(--dw); }
.swatch.dl { background: var(--dl); }
.swatch.tl { background: var(--tl); }

.records { margin: 0; padding-left: 1.5rem; font-size: 0.92rem; }
.records li { padding: 0.15rem 0; }
.records li span { display: inline-block; min-width: 8rem; }
.records li.current { color: var(--accent-dark); font-weight: 700; }

.muted { color: var(--muted); font-weight: normal; }

/* ---------- Sala de espera ---------- */

.lobby-code {
  margin: 0.2rem 0 0.6rem;
  font-size: 2.6rem;
  font-weight: 800;
  letter-spacing: 0.35em;
  color: var(--accent-dark);
  font-variant-numeric: tabular-nums;
}
.lobby-links { margin: 0.4rem 0 0; padding-left: 1.2rem; font-size: 0.95rem; overflow-wrap: anywhere; }
.lobby-actions { margin-top: 1rem; }
#join-code { text-transform: uppercase; letter-spacing: 0.15em; }

/* ---------- Partida ---------- */

.game {
  margin: 0 auto;
  padding: 1rem;
  display: grid;
  /* --board-col crece con el zoom (ver app.js). */
  max-width: calc(var(--board-col, 640px) + 560px);
  grid-template-columns: minmax(0, var(--board-col, 640px)) minmax(260px, 1fr);
  gap: 1.25rem;
  align-items: start;
  justify-content: center;
}

.side-col { display: flex; flex-direction: column; gap: 1rem; }

.board {
  container-type: inline-size;
  display: grid;
  grid-template-columns: repeat(15, 1fr);
  gap: 2px;
  padding: 4px;
  background: var(--board);
  border-radius: 8px;
  width: var(--board-size, 100%);
  user-select: none;
}

/* Con zoom el tablero puede pasar del ancho disponible: se desplaza dentro de su marco. */
.board-wrap { overflow: auto; max-width: 100%; border-radius: 8px; }

.zoom-bar { display: flex; align-items: center; justify-content: flex-end; gap: 0.35rem; margin-bottom: 0.5rem; }

.zoom-btn {
  min-width: 2.2rem;
  height: 2.2rem;
  padding: 0 0.6rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card);
  color: var(--ink);
  font-weight: 700;
  font-size: 1.05rem;
  cursor: pointer;
}

.zoom-btn:hover:not(:disabled) { border-color: var(--accent); }
.zoom-fit { font-size: 0.85rem; font-weight: 600; }
.zoom-label { min-width: 4.5rem; text-align: center; font-size: 0.85rem; color: var(--muted); font-variant-numeric: tabular-nums; }

.cell {
  position: relative;
  aspect-ratio: 1;
  background: var(--cell);
  border-radius: 2px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  min-width: 0;
}

.cell.sq-tw { background: var(--tw); color: #fff; }
.cell.sq-dw { background: var(--dw); color: #5a4a00; }
.cell.sq-dl { background: var(--dl); color: #fff; }
.cell.sq-tl { background: var(--tl); color: #fff; }

.cell-label { font-size: 2.4cqi; font-weight: 700; opacity: 0.9; }
.cell-label.star { font-size: 4cqi; }

.cell.cursor { box-shadow: inset 0 0 0 2px var(--accent-dark); }
.cell.cursor::after {
  content: '→';
  position: absolute;
  font-size: 3.4cqi;
  font-weight: 700;
  color: var(--accent-dark);
}
.cell.cursor-down::after { content: '↓'; }
.cell.cursor .cell-label { opacity: 0.25; }

.tile {
  position: relative;
  width: 100%;
  height: 100%;
  background: var(--tile);
  border: 1px solid var(--tile-edge);
  border-radius: 3px;
  box-shadow: 0 1px 0 var(--tile-edge);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--ink);
  cursor: default;
}

.board .tile-letter { font-size: 3.6cqi; font-weight: 700; line-height: 1; }
.board .tile-value { position: absolute; right: 8%; bottom: 4%; font-size: 1.7cqi; font-weight: 600; }

.tile.blank .tile-letter { color: #a4532b; }
.tile.last { background: #f7e7a4; box-shadow: 0 0 0 2px var(--accent) inset; }
.tile.pending { background: #fff3cf; box-shadow: 0 0 0 2px var(--accent-dark) inset; cursor: pointer; }
.tile.pending.invalid { background: #fbd9d5; box-shadow: 0 0 0 2px var(--danger) inset; }
.tile.ghost { opacity: 0.55; border-style: dashed; }

.status {
  margin: 0.7rem 0;
  min-height: 2.6rem;
  padding: 0.55rem 0.8rem;
  border-radius: 8px;
  background: var(--card);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
  font-size: 0.95rem;
}

.status.error { background: #fbe7e5; color: var(--danger); border-color: #f0c4bf; }
.status.warn { background: #fff2dc; color: var(--warn); border-color: #f2d9a8; }
.status.preview { background: #e5f4ea; color: var(--ok); border-color: #bfe0c9; }
.status.thinking { color: var(--muted); font-style: italic; }
.status.hint-status { background: #eef3fb; color: #1f4e8c; border-color: #cddcf1; }
.preview-total { margin-left: auto; font-size: 1.05rem; }

.rack-row { display: flex; justify-content: center; }

.rack {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 3.3rem));
  gap: 0.35rem;
  padding: 0.5rem;
  background: #8a6a3a;
  border-radius: 8px;
}

.rack-slot { aspect-ratio: 1; border-radius: 4px; background: rgba(0, 0, 0, 0.15); }
.rack .tile { cursor: pointer; transition: transform 0.1s; }
.rack .tile-letter { font-size: 1.5rem; font-weight: 700; }
.rack .tile-value { position: absolute; right: 7%; bottom: 3%; font-size: 0.7rem; font-weight: 600; }
.rack .tile.selected { transform: translateY(-6px); box-shadow: 0 0 0 3px var(--accent-dark); }
.rack .tile.marked { transform: translateY(-6px); background: #fbd9d5; box-shadow: 0 0 0 3px var(--danger); }

.actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 0.45rem;
  margin-top: 0.8rem;
}

.actions .hint { width: 100%; text-align: center; margin: 0; }

.players { display: flex; flex-direction: column; gap: 0.45rem; }

.player {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  padding: 0.55rem 0.8rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  border-left: 6px solid #2e86ab;
}

.player.rival-0 { border-left-color: #2f7d4a; }
.player.rival-1 { border-left-color: #d1495b; }
.player.rival-2 { border-left-color: #7b4bb8; }
.player.rival-3 { border-left-color: #c26a14; }
.player.resigned { opacity: 0.55; }
.player.active { background: #fbf5e4; }
.player-name { font-weight: 600; display: flex; align-items: center; gap: 0.4rem; min-width: 0; }
.player-score { font-size: 1.6rem; font-weight: 700; }
.player-meta { font-size: 0.8rem; color: var(--muted); }

.turn-dot { width: 0.55rem; height: 0.55rem; border-radius: 50%; background: var(--ok); flex: none; }

.bag-line {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 0.4rem;
  margin-top: 0.6rem;
  font-size: 0.88rem;
  color: var(--muted);
}

.unseen { display: flex; flex-wrap: wrap; gap: 0.3rem; margin-top: 0.6rem; }

.unseen-item {
  display: inline-flex;
  gap: 0.25rem;
  padding: 0.15rem 0.4rem;
  border-radius: 4px;
  background: #f3ecd9;
  font-size: 0.82rem;
}

.unseen-item.gone { opacity: 0.35; }

.log {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 320px;
  overflow-y: auto;
  font-size: 0.92rem;
}

.log-entry {
  display: grid;
  grid-template-columns: 4.5rem 1fr auto;
  gap: 0.4rem;
  padding: 0.35rem 0;
  border-bottom: 1px solid var(--border);
  align-items: baseline;
}

.log-empty { color: var(--muted); }
.log-who { font-weight: 600; color: #2e86ab; }
.log-who.rival-0 { color: #2f7d4a; }
.log-who.rival-1 { color: #d1495b; }
.log-who.rival-2 { color: #7b4bb8; }
.log-who.rival-3 { color: #c26a14; }
.log-body { min-width: 0; overflow-wrap: anywhere; }
.log-body small { color: var(--muted); }
.log-score { font-weight: 700; }

.word-link {
  background: none;
  border: none;
  padding: 0;
  font-weight: 600;
  color: var(--ink);
  text-decoration: underline dotted;
  cursor: pointer;
}

.bingo { margin-left: 0.35rem; font-size: 0.75rem; font-weight: 700; color: var(--ok); }

/* ---------- Verificación y significados (como en el marcador) ---------- */

.verify-form { display: flex; gap: 0.5rem; }
.verify-form input { flex: 1; min-width: 0; }

.verify-form button {
  padding: 0.65rem 1rem;
  border: none;
  background: var(--accent);
  color: #fff;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
}

.verify-result { margin: 0.8rem 0 0.2rem; }
.verify-result:empty { display: none; }

.verify-status {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  padding: 0.6rem 0.8rem;
  border-radius: 8px;
  font-weight: 600;
}

.verify-status.valid { background: #e5f4ea; color: var(--ok); }
.verify-status.probable { background: #fff2dc; color: var(--warn); }
.verify-status.invalid { background: #fbe7e5; color: var(--danger); }

.lang-badge {
  font-size: 0.75rem;
  font-weight: 700;
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
}

.lang-badge.lang-es { background: #dbe8f7; color: #1f4e8c; }
.lang-badge.lang-arn { background: #d3ecef; color: #1d6b7a; }

.source-list { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-top: 0.4rem; }

.source-badge {
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.15rem 0.5rem;
  border-radius: 6px;
  border: 1px solid var(--border);
}

.source-valid { color: var(--ok); }
.source-invalid { color: var(--danger); }
.source-unknown { color: var(--muted); }

.meanings { display: flex; flex-direction: column; gap: 0.7rem; margin-top: 0.7rem; }
.meaning-entry { border-left: 4px solid var(--border); padding: 0.1rem 0 0.1rem 0.8rem; }
.meaning-entry.lang-es { border-left-color: #7ea6d8; }
.meaning-entry.lang-arn { border-left-color: #58a9b6; }
.meaning-head { font-weight: 700; }
.meaning-source { font-weight: 400; font-size: 0.8rem; color: var(--muted); }
.meaning-pos { margin-top: 0.35rem; font-size: 0.85rem; font-style: italic; color: var(--muted); }
.meaning-text { font-size: 0.93rem; margin-top: 0.1rem; }
.meaning-defs { margin: 0.15rem 0 0; padding-left: 1.3rem; font-size: 0.93rem; }
.meaning-defs li { margin-bottom: 0.15rem; }
.meaning-note { margin-top: 0.6rem; font-size: 0.88rem; color: var(--muted); }

.meaning-example {
  padding: 0.5rem 0.75rem;
  border-radius: 8px;
  background: #fbf5e4;
  font-size: 0.95rem;
  font-style: italic;
}

.meaning-example q { quotes: '«' '»'; }
.meaning-example-label { font-style: normal; font-weight: 700; color: var(--accent-dark); }
.meaning-example .meaning-source { font-style: normal; }

/* ---------- Diálogos ---------- */

.modal {
  position: fixed;
  inset: 0;
  background: rgba(30, 24, 18, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  z-index: 10;
}

.modal-card {
  position: relative;
  background: var(--card);
  border-radius: 12px;
  padding: 1.25rem;
  width: min(460px, 100%);
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.25);
}

.modal-close {
  position: absolute;
  top: 0.6rem;
  right: 0.6rem;
  background: none;
  border: none;
  font-size: 1.1rem;
  cursor: pointer;
  color: var(--muted);
}

.modal-actions { display: flex; justify-content: flex-end; gap: 0.5rem; margin-top: 1rem; }

.blank-letters { display: grid; grid-template-columns: repeat(auto-fill, minmax(2.6rem, 1fr)); gap: 0.35rem; }

.blank-letter {
  aspect-ratio: 1;
  background: var(--tile);
  border: 1px solid var(--tile-edge);
  border-radius: 4px;
  font-weight: 700;
  font-size: 1.1rem;
  cursor: pointer;
}

.blank-letter:hover { background: #f7e7a4; }

.final-table { width: 100%; border-collapse: collapse; margin-top: 0.6rem; }
.final-table td { padding: 0.4rem 0.3rem; border-bottom: 1px solid var(--border); }
.final-table .muted { color: var(--muted); font-size: 0.85rem; }
.final-score { text-align: right; font-weight: 700; font-size: 1.2rem; }

/* ---------- Pantallas chicas ---------- */

@media (max-width: 900px) {
  .game { grid-template-columns: minmax(0, 1fr); }
  .setup { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 520px) {
  .game, .setup { padding: 0.75rem 0.5rem; }
  .board { gap: 1px; padding: 2px; }
  .modes { grid-template-columns: 1fr; }
  .rack { gap: 0.25rem; padding: 0.35rem; grid-template-columns: repeat(7, minmax(0, 2.8rem)); }
  .actions button { padding: 0.5rem 0.7rem; }
}
