* { box-sizing: border-box; }
:root {
  font-family: -apple-system, BlinkMacSystemFont, "Helvetica Neue", Inter, "Segoe UI", sans-serif;
  color: #17231f;
  background: #f3f6f3;
  font-synthesis: none;
}
body {
  margin: 0;
  padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom);
}
main {
  max-width: 820px;
  margin: auto;
  padding: 18px 14px 36px;
}
header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 2px 18px;
}
small {
  color: #718078;
  letter-spacing: .08em;
  font-size: .7rem;
  font-weight: 700;
}
h1 { font-size: 1.6rem; margin: 3px 0; }
h2 { font-size: 1.3rem; margin: 4px 0 12px; }
h3 { font-size: 1rem; margin: 0 0 12px; }

.panel {
  background: #fff;
  border: 1px solid #e4ebe5;
  border-radius: 16px;
  padding: 16px;
  margin: 14px 0;
  box-shadow: 0 4px 18px #193b2410;
}
.sheet-card {
  padding: 14px 12px;
}
.welcome, .section-head, .top-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.welcome { padding: 6px 2px; }
.nav-actions { display: flex; gap: 6px; }

.pill {
  background: #eaf4ed;
  color: #24613b;
  border-radius: 99px;
  padding: 6px 11px;
  font-size: .75rem;
  font-weight: 700;
}
.yellow-pill {
  background: #fff475;
  color: #4a4200;
}

.game-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin: 10px 0;
}
.game-card {
  border: 1px solid #dfe8e0;
  background: #fff;
  border-radius: 14px;
  padding: 12px 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  color: #17231f;
}
.game-card.chosen {
  border: 2px solid #28764a;
  background: #f2faf4;
}
.game-card:disabled { opacity: .48; }
.game-icon { font-size: 1.4rem; color: #28764a; }
.game-card small { font-size: .65rem; letter-spacing: 0; }
.muted { color: #78857e; font-size: .8rem; }

.players {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin: 10px 0 14px;
}
.player-choice {
  border: 1px solid #e0e8e1;
  border-radius: 11px;
  padding: 10px;
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
}
.player-choice input, .toggles input {
  accent-color: #28764a;
  width: 18px;
  height: 18px;
  margin: 0;
}

label {
  display: block;
  font-size: .82rem;
  font-weight: 650;
  margin: 10px 0;
}
input, select {
  display: block;
  width: 100%;
  margin-top: 5px;
  padding: 11px;
  border: 1px solid #dce5dd;
  border-radius: 10px;
  background: #fff;
  color: #17231f;
  font: inherit;
  font-size: .95rem;
}
.row-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

button { font: inherit; cursor: pointer; }
button.primary, form button:not(.text-button) {
  width: 100%;
  border: 0;
  border-radius: 11px;
  background: #1d6540;
  color: #fff;
  font-weight: 750;
  padding: 13px;
  margin-top: 12px;
}
.text-button, .quiet, .back {
  border: 0;
  background: transparent;
  color: #1d6540;
  font-weight: 700;
  padding: 6px 8px;
  font-size: .85rem;
}
.danger-text { color: #b42318; }

.history-row {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  text-align: left;
  border: 0;
  border-top: 1px solid #edf1ed;
  background: #fff;
  padding: 12px 0;
  gap: 8px;
}
.history-row span:first-child {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.history-row small { letter-spacing: 0; font-weight: 400; }

/* Entrada rápida de puntos por jugador */
.score-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin: 8px 0 12px;
}
.score-box {
  background: #f5f8f6;
  border: 1px solid #dfe7e1;
  border-radius: 10px;
  padding: 8px;
  text-align: center;
}
.score-box span {
  display: block;
  font-weight: 750;
  font-size: .85rem;
  margin-bottom: 4px;
}
.score-box input {
  text-align: center;
  font-weight: 800;
  font-size: 1.05rem;
  padding: 8px 4px;
  margin: 0;
}

.toggles {
  display: flex;
  gap: 18px;
  flex-wrap: wrap;
  margin: 8px 0;
}
.toggles label {
  display: flex;
  align-items: center;
  gap: 7px;
  margin: 4px 0;
}

/* ESTILO HOJA DE NUMBERS */
.table-wrap {
  width: 100%;
  overflow-x: auto;
  border: 1px solid #999;
  border-radius: 6px;
}
.numbers-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .84rem;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.numbers-table th, .numbers-table td {
  border: 1px solid #b5b5b5;
  padding: 6px 8px;
  text-align: center;
}
.numbers-table th.hdr-gray {
  background: #b8b8b8;
  color: #111;
  font-weight: 700;
}
.numbers-table th.hdr-yellow {
  background: #fff200;
  color: #111;
  font-weight: 700;
}
.numbers-table td.col-date {
  background: #d9d9d9;
  font-weight: 600;
  text-align: right;
  color: #111;
}
.numbers-table td.col-yellow {
  background: #fff533;
  color: #111;
}
.numbers-table td.bold { font-weight: 700; }
.numbers-table .grp-start { border-left: 3px solid #555; }
.numbers-table td.cell-winner {
  background: #fff533;
  font-weight: 800;
}
.numbers-table td.cell-acc {
  background: #fff;
  font-weight: 600;
}
.numbers-table td.cell-over100 {
  background: #f4a4a4;
  color: #9b0000;
  font-weight: 800;
}

/* Tabla de estadísticas superior derecha de Numbers */
.stats-table td.metric-label {
  background: #d9d9d9;
  font-weight: 700;
  text-align: left;
  color: #111;
}
.stats-table td.cell-salmon {
  background: #f4a4a4;
  color: #9b0000;
  font-weight: 700;
}
.left-align { text-align: left !important; }

.error { color: #b42318; font-size: .82rem; }
.hidden { display: none !important; }
footer {
  text-align: center;
  color: #8a968f;
  font-size: .72rem;
  padding: 16px;
}
#login { margin-top: 12vh; }

@media (max-width: 480px) {
  .score-grid { grid-template-columns: repeat(2, 1fr); }
}
/* Orden de jugadores en la mesa */
.order-list { margin: 6px 0 14px; }
.order-row {
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid #e0e8e1;
  border-radius: 11px;
  padding: 4px 6px 4px 12px;
  margin-bottom: 6px;
}
.order-pos { color: #78857e; font-size: .8rem; width: 1.2em; }
.order-name { flex: 1; font-weight: 700; }
.order-row .text-button { font-size: 1rem; padding: 8px 12px; }
.order-row .text-button:disabled { opacity: .3; }

/* Cifra con la que se reengancha */
.numbers-table td.cell-over100 .reeng {
  display: block;
  font-size: .68rem;
  font-weight: 700;
  color: #5a0000;
  line-height: 1.1;
}

/* Partidas guardadas */
.win-pill { background: #fff533; color: #4a4200; white-space: nowrap; }
.win-name { color: #1d6540; }
.history-more { width: 100%; padding: 12px; }

/* Filtro de periodo */
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 4px 0 8px; }
.chip {
  border: 1px solid #cfdad2;
  background: #fff;
  color: #17231f;
  border-radius: 99px;
  padding: 7px 12px;
  font-size: .8rem;
  font-weight: 700;
}
.chip.active { background: #1d6540; border-color: #1d6540; color: #fff; }
.period-summary { margin: 0 0 8px; }
#periodStats { margin-bottom: 4px; }

.stats-table td.cell-lead {
  background: #fff533;
  font-weight: 800;
}

/* Edición de rondas */
.numbers-table tbody tr[data-round] { cursor: pointer; }
.numbers-table tr.row-editing td { outline: 2px solid #1d6540; outline-offset: -2px; }
.edit-actions { display: flex; justify-content: space-between; margin-top: 6px; }

/* Panel plegable de nueva partida */
.fold > summary { list-style: none; cursor: pointer; }
.fold > summary::-webkit-details-marker { display: none; }
.fold > summary h3 { margin: 0; }
.fold[open] > summary { margin-bottom: 12px; }
.fold .chevron { color: #1d6540; font-size: 1.1rem; transition: transform .15s; }
.fold[open] .chevron { transform: rotate(180deg); }

/* Selectores con botones (reparte / win ronda) */
.pick-group { margin: 10px 0; }
.pick-label { display: block; font-size: .82rem; font-weight: 650; margin-bottom: 6px; }
.pick { display: flex; flex-wrap: wrap; gap: 6px; }
#roundForm .pick .pick-btn {
  flex: 1 1 0;
  min-width: 52px;
  width: auto;
  margin: 0;
  padding: 12px 8px;
  border: 1px solid #cfdad2;
  border-radius: 10px;
  background: #fff;
  color: #17231f;
  font-weight: 700;
}
#roundForm #dealerPick .pick-btn.active { background: #1d6540; border-color: #1d6540; color: #fff; }
#roundForm #winnerPick .pick-btn.active { background: #fff533; border-color: #b8a900; color: #17231f; }