:root {
  --bg: #0f1722;
  --card: #18222f;
  --card2: #1f2c3c;
  --text: #e8eef5;
  --muted: #8aa0b6;
  --accent: #2e9e6b;
  --accent2: #2563eb;
  --danger: #e05555;
  --border: #2a3a4d;
}

* { box-sizing: border-box; }

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

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  padding: 14px 20px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
}
.topbar h1 { font-size: 1.2rem; margin: 0; }
.user-box { display: flex; align-items: center; gap: 12px; }

#app {
  max-width: 720px;
  margin: 0 auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 20px;
}
.card h2 { margin-top: 0; font-size: 1.1rem; }

.form { display: flex; flex-direction: column; gap: 12px; }
.form.row { flex-direction: row; }
.form.row input { flex: 1; }

input, select {
  background: var(--card2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 12px 14px;
  border-radius: 10px;
  font-size: 1rem;
  width: 100%;
}
.field { display: flex; flex-direction: column; gap: 6px; }
.field > span { font-size: .85rem; color: var(--muted); }

.btn {
  background: var(--accent);
  color: white;
  border: none;
  padding: 12px 18px;
  border-radius: 10px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
}
.btn:hover { filter: brightness(1.1); }
.btn-ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
  padding: 8px 12px;
  border-radius: 10px;
  cursor: pointer;
}
.btn-ghost:hover { color: var(--text); }

.tabs { display: flex; gap: 8px; margin-bottom: 16px; }
.tab {
  flex: 1;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  padding: 10px;
  border-radius: 10px;
  cursor: pointer;
}
.tab.active { background: var(--accent2); color: white; border-color: var(--accent2); }

.hidden { display: none !important; }
.muted { color: var(--muted); }
.error { color: var(--danger); min-height: 1.2em; margin: 4px 0 0; }

.room-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 8px; }
.room-list li {
  display: flex; justify-content: space-between; align-items: center;
  background: var(--card2); padding: 12px 14px; border-radius: 10px;
}
.room-list button { font-size: .9rem; }

.room-header { display: flex; flex-direction: column; gap: 10px; }
.room-meta { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.code {
  font-family: monospace; font-size: 1.1rem; letter-spacing: 2px;
  background: var(--card2); padding: 4px 10px; border-radius: 8px;
}
.badge {
  font-size: .8rem; padding: 3px 10px; border-radius: 20px;
  background: var(--accent2); color: white;
}

.scoreboard {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 16px;
  align-items: start;
}
.side {
  background: var(--card);
  border: 2px solid var(--border);
  border-radius: 14px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.side.leading { transform: translateY(-3px); box-shadow: 0 8px 24px rgba(0,0,0,.45); }

.side-head { padding: 14px; text-align: center; color: #fff; }
.side-name { font-size: 1.05rem; font-weight: 700; }
.side-total { font-size: 2.8rem; font-weight: 800; line-height: 1.1; }

.side-history {
  list-style: none; margin: 0; padding: 8px;
  display: flex; flex-direction: column; gap: 5px; min-height: 44px;
}
.hist-line {
  display: flex; align-items: center; gap: 8px;
  background: var(--card2); border-radius: 8px; padding: 8px 10px;
  font-variant-numeric: tabular-nums;
}
.hist-num { color: var(--muted); font-size: .8rem; min-width: 22px; }
.hist-pts { font-size: 1.25rem; font-weight: 700; }
.hist-line.editable { cursor: pointer; }
.hist-line.editable:hover { outline: 2px solid var(--accent); }
.hist-empty { color: var(--muted); font-size: .85rem; text-align: center; padding: 6px; }
.edit-input { width: 64px; padding: 6px; }
.edit-save, .edit-del { border: none; border-radius: 6px; padding: 6px 9px; cursor: pointer; font-size: 1rem; }
.edit-save { background: var(--accent); color: #fff; }
.edit-del { background: var(--danger); color: #fff; }

.add-row { padding: 10px; border-top: 1px solid var(--border); display: flex; flex-direction: column; gap: 8px; }
.add-row .quick { display: flex; gap: 8px; }
.add-row .quick button {
  flex: 1; background: var(--card2); border: 1px solid var(--border); color: var(--text);
  border-radius: 8px; padding: 12px; font-size: 1.2rem; font-weight: 800; cursor: pointer;
}
.add-row .quick button:hover { background: var(--accent); border-color: var(--accent); }
.add-row .custom { display: flex; gap: 6px; }
.add-row .custom .amount-input { flex: 1; padding: 9px; }
.add-row .add-go {
  background: var(--accent2); color: #fff; border: none; border-radius: 8px;
  padding: 9px 14px; font-weight: 700; cursor: pointer; white-space: nowrap;
}

/* Colores fuertes para diferenciar las columnas rivales */
.side-color-0 { border-color: #2563eb; } .side-color-0 .side-head { background: #2563eb; }
.side-color-1 { border-color: #dc2626; } .side-color-1 .side-head { background: #dc2626; }
.side-color-2 { border-color: #16a34a; } .side-color-2 .side-head { background: #16a34a; }
.side-color-3 { border-color: #d97706; } .side-color-3 .side-head { background: #d97706; }
.side-color-4 { border-color: #7c3aed; } .side-color-4 .side-head { background: #7c3aed; }
.side-color-5 { border-color: #0d9488; } .side-color-5 .side-head { background: #0d9488; }
.side-color-6 { border-color: #db2777; } .side-color-6 .side-head { background: #db2777; }
.side-color-7 { border-color: #0891b2; } .side-color-7 .side-head { background: #0891b2; }

.winner {
  text-align: center; font-size: 1.4rem; font-weight: 800;
  background: var(--accent); color: white; padding: 16px; border-radius: 14px;
}

/* Cabecera de "Salas" con boton + */
.home-header {
  display: flex; align-items: center; justify-content: space-between;
}
.home-header h2 { margin: 0; font-size: 1.4rem; }
.fab {
  width: 48px; height: 48px; border-radius: 50%;
  background: var(--accent); color: #fff; border: none;
  font-size: 1.8rem; line-height: 1; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 4px 14px rgba(0,0,0,.4);
}
.fab:hover { filter: brightness(1.1); }

/* Modal (ventana flotante) */
.modal-overlay {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(0,0,0,.6);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 20px; overflow-y: auto;
}
.modal { width: 100%; max-width: 460px; margin-top: 30px; display: flex; flex-direction: column; gap: 14px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; }
.modal-head h2 { margin: 0; }
.modal-sep { text-align: center; color: var(--muted); font-size: .85rem; position: relative; }

/* Aviso de instalacion en el movil */
.install-banner {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 60;
  background: var(--card2); border-top: 1px solid var(--border);
  padding: 14px 18px; display: flex; align-items: center; justify-content: space-between;
  gap: 12px; flex-wrap: wrap;
}
.install-banner #installText { flex: 1; min-width: 180px; }
.install-actions { display: flex; gap: 8px; }
.install-actions .btn { padding: 10px 16px; }

/* Navegacion (Salas / Amigos / Perfil) */
.nav { display: flex; gap: 6px; }
.nav-btn {
  background: transparent; border: 1px solid var(--border); color: var(--muted);
  padding: 8px 12px; border-radius: 10px; cursor: pointer; font-size: .9rem;
}
.nav-btn:hover { color: var(--text); }
.nav-btn.active { background: var(--accent2); color: #fff; border-color: var(--accent2); }

/* Mensaje de exito */
.ok { color: var(--accent); min-height: 1.2em; margin: 4px 0 0; }

/* Pantalla de conexión */
.auth-title { text-align: center; margin: 0 0 16px; font-size: 1.4rem; }
.auth-lang { display: flex; justify-content: flex-end; margin-bottom: 12px; }
.lang-mini { width: auto; padding: 6px 10px; font-size: .9rem; }

/* Botón de instalar en la pantalla de login */
.auth-install { text-align: center; margin-top: 16px; }
.auth-install .muted { font-size: .85rem; margin-top: 6px; }

/* Codigo QR */
.qr-box { text-align: center; margin-top: 12px; display: flex; flex-direction: column; align-items: center; gap: 6px; }
.qr-box img { width: 200px; height: 200px; background: #fff; border-radius: 12px; padding: 8px; }

/* ===== Juego de dominó ===== */
.waiting-card { text-align: center; display: flex; flex-direction: column; align-items: center; gap: 12px; }
.code.big { font-size: 2rem; letter-spacing: 4px; padding: 10px 18px; }

.game-opponent { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 8px; }
.opp-tiles { display: flex; gap: 3px; }
.domino-back { width: 14px; height: 28px; background: linear-gradient(160deg, #3a4a5e, #243343); border: 1px solid var(--border); border-radius: 4px; }
.game-turn { text-align: center; font-weight: 700; margin: 8px 0; min-height: 1.2em; }

/* Mesa cuadrada de fieltro verde con borde de madera */
#gameBoardWrap {
  width: 100%; max-width: 460px; aspect-ratio: 1 / 1; margin: 0 auto;
  position: relative; overflow: hidden;
  background: radial-gradient(circle at 50% 45%, #1e7a46, #134e2c);
  border: 7px solid #6b4423;
  border-radius: 18px;
  box-shadow: inset 0 0 45px rgba(0,0,0,.4), 0 6px 16px rgba(0,0,0,.4);
}
.game-board { position: relative; width: 100%; height: 100%; }
.game-board .domino { position: absolute; }
/* Fichas en la mesa: tamaño parejo (horizontales y dobles verticales) */
.domino.board { padding: 3px; }
.domino.board .domino-half { width: 24px; height: 24px; }
.game-controls { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; align-items: center; margin: 12px 0; }
.game-hand { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; margin-top: 10px; }

/* Una ficha de dominó */
.domino { display: flex; background: #f8fafc; border: 2px solid #0f1722; border-radius: 8px; padding: 4px; box-shadow: 0 2px 5px rgba(0,0,0,.35); }
.domino-h { flex-direction: row; }
.domino-v { flex-direction: column; }
.domino-divider { background: #0f1722; }
.domino-h > .domino-divider { width: 2px; align-self: stretch; margin: 0 3px; }
.domino-v > .domino-divider { height: 2px; align-self: stretch; margin: 3px 0; }
.domino-half { display: grid; grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(3, 1fr); gap: 2px; }
.domino-h .domino-half { width: 34px; height: 34px; }
.domino-v .domino-half { width: 42px; height: 42px; }
.pip-cell { width: 100%; height: 100%; }
.pip-cell.on { background: #0f1722; border-radius: 50%; }
.domino.playable { cursor: pointer; border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent), 0 2px 6px rgba(0,0,0,.4); }
.domino.playable:hover { transform: translateY(-3px); }
.domino.disabled { opacity: .55; }

/* --- Config de la partida (lobby) --- */
.game-config { margin: 10px 0; background: var(--card2); border-radius: 10px; padding: 10px 14px; }
.game-config summary { cursor: pointer; font-weight: 600; }
.game-config .field { margin-top: 10px; }
.game-config input { width: 100%; }

/* --- Marcador del match (mesa de juego) --- */
.game-scores { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: center; margin-bottom: 8px; }
.gs-row {
  display: flex; align-items: center; gap: 8px;
  background: var(--card2); padding: 6px 12px; border-radius: 10px; min-width: 110px; justify-content: space-between;
}
.gs-row.leading { outline: 2px solid var(--accent); }
.gs-name { font-weight: 600; }
.gs-score { font-size: 1.2rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.gs-target { font-size: .8rem; color: var(--muted); width: 100%; text-align: center; }

/* --- Petición de barajar --- */
.shuffle-ask {
  display: flex; gap: 8px; align-items: center; justify-content: center; flex-wrap: wrap;
  background: #3a3015; border: 1px solid #b08900; color: #ffe9a8;
  padding: 10px 14px; border-radius: 12px; margin: 8px 0;
}

/* --- Resultado de la mano / capicúa --- */
.hand-result {
  text-align: center; font-size: 1.1rem; font-weight: 700;
  background: var(--card2); padding: 12px; border-radius: 12px; margin: 8px 0;
}
.hand-result.capicua {
  background: linear-gradient(120deg, #16a34a, #f59e0b); color: #fff;
  font-size: 1.3rem; animation: capicuaPulse 1s ease-in-out infinite alternate;
}
@keyframes capicuaPulse { from { transform: scale(1); } to { transform: scale(1.04); } }

/* --- Barra de botones de la mesa --- */
.game-toolbar { display: flex; gap: 10px; justify-content: center; margin-top: 10px; }
.btn-ghost.danger { color: #fca5a5; border-color: #7f1d1d; }
.btn-ghost.danger:hover { background: #7f1d1d; color: #fff; }
