/* Bote — tema oscuro, pensado para un móvil en la mano a las 3 de la mañana:
 * tipografía grande, contraste alto y nada que se pueda tocar por error. */

:root {
  --fondo: #0b0f0d;
  --superficie: #151b18;
  --superficie-2: #1e2622;
  --borde: #2a332e;
  --texto: #f1f5f3;
  --apagado: #8b9791;
  --verde: #22c55e;
  --verde-oscuro: #14532d;
  --rojo: #f05252;
  --ambar: #f59e0b;
  --radio: 14px;
  --alto-toque: 48px;

  /* Márgenes de seguridad del iPhone (muesca e indicador de inicio). */
  --arriba: env(safe-area-inset-top, 0px);
  --abajo: env(safe-area-inset-bottom, 0px);
  --izq: env(safe-area-inset-left, 0px);
  --der: env(safe-area-inset-right, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--fondo);
  color: var(--texto);
  font: 17px/1.45 -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Segoe UI', Roboto, sans-serif;
  /* Detalles que separan una app de una web: sin flash azul al tocar, sin
     rebote de scroll y sin seleccionar texto sin querer. */
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
  user-select: none;
  -webkit-user-select: none;
}

body { overflow: hidden; }

input, textarea { user-select: text; -webkit-user-select: text; }

h1, h2, h3, p, ul, ol { margin: 0; }
ul { list-style: none; padding: 0; }

/* ── armazón ─────────────────────────────────────────────────────────────── */

.app {
  display: grid;
  grid-template-rows: auto 1fr auto;
  height: 100dvh;
}

.barra {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 8px;
  padding: calc(var(--arriba) + 10px) calc(var(--der) + 12px) 10px calc(var(--izq) + 12px);
  background: color-mix(in srgb, var(--fondo) 82%, transparent);
  backdrop-filter: saturate(160%) blur(18px);
  -webkit-backdrop-filter: saturate(160%) blur(18px);
  border-bottom: 1px solid var(--borde);
}

.barra__titulo {
  grid-column: 2;
  font-size: 17px;
  font-weight: 600;
  text-align: center;
  white-space: nowrap;
}

.barra__atras, .barra__accion {
  appearance: none;
  border: 0;
  background: none;
  color: var(--verde);
  font: inherit;
  font-size: 16px;
  padding: 6px 2px;
  min-height: 36px;
  cursor: pointer;
}
.barra__atras { grid-column: 1; justify-self: start; display: flex; align-items: center; gap: 2px; }
.barra__atras[hidden], .barra__accion[hidden] { display: none; }
.barra__accion { grid-column: 3; justify-self: end; }
.barra__atras svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }

#principal {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 16px calc(var(--der) + 16px) 24px calc(var(--izq) + 16px);
}

.vista { display: none; }
body[data-vista='inicio']  .vista[data-para='inicio'],
body[data-vista='ajustes'] .vista[data-para='ajustes'],
body[data-vista='partida'] .vista[data-para='partida'],
body[data-vista='contar']  .vista[data-para='contar'],
body[data-vista='reparto'] .vista[data-para='reparto'] {
  display: block;
  animation: entrar .22s ease both;
}
@keyframes entrar { from { opacity: 0; transform: translateY(6px); } }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

.pie {
  padding: 12px calc(var(--der) + 16px) calc(var(--abajo) + 12px) calc(var(--izq) + 16px);
  border-top: 1px solid var(--borde);
  background: var(--fondo);
  display: grid;
  gap: 8px;
}
.pie[hidden] { display: none; }

/* ── piezas ──────────────────────────────────────────────────────────────── */

.tarjeta {
  background: var(--superficie);
  border: 1px solid var(--borde);
  border-radius: var(--radio);
  overflow: hidden;
}
.tarjeta + .tarjeta, .bloque + .bloque { margin-top: 16px; }

.rotulo {
  font-size: 13px;
  font-weight: 600;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--apagado);
  margin: 0 0 8px 4px;
}

.fila {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: var(--alto-toque);
  padding: 12px 14px;
  background: none;
  border: 0;
  border-bottom: 1px solid var(--borde);
  color: inherit;
  font: inherit;
  text-align: left;
}
.fila:last-child { border-bottom: 0; }
button.fila { cursor: pointer; }
button.fila:active { background: var(--superficie-2); }
.fila__princ { flex: 1; min-width: 0; }
.fila__nombre { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fila__sub { font-size: 13px; color: var(--apagado); }
/* Los movimientos son frases enteras: mejor que doblen a que se corten. */
.fila__nombre--largo { white-space: normal; overflow: visible; }
.fila__cifra { font-variant-numeric: tabular-nums; font-weight: 600; }
.fila__chevron { color: var(--apagado); font-size: 20px; line-height: 1; }

.vacio {
  text-align: center;
  color: var(--apagado);
  padding: 32px 16px;
  font-size: 15px;
}

/* ── botones ─────────────────────────────────────────────────────────────── */

.btn {
  appearance: none;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  min-height: var(--alto-toque);
  padding: 12px 18px;
  border: 1px solid transparent;
  border-radius: 12px;
  background: var(--superficie-2);
  color: var(--texto);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: transform .08s ease, opacity .12s ease;
}
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .4; cursor: default; }
.btn--principal { background: var(--verde); color: #04210f; }
.btn--fantasma { background: none; border-color: var(--borde); }
.btn--peligro { background: none; border-color: var(--borde); color: var(--rojo); }
.btn--pequeño { width: auto; min-height: 38px; padding: 8px 14px; font-size: 15px; border-radius: 10px; }
.botonera { display: flex; gap: 8px; }
.botonera .btn { flex: 1; }

/* ── resumen de cabecera ─────────────────────────────────────────────────── */

.marcador {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1px;
  background: var(--borde);
  border: 1px solid var(--borde);
  border-radius: var(--radio);
  overflow: hidden;
  margin-bottom: 16px;
}
.marcador__dato { background: var(--superficie); padding: 14px 8px; text-align: center; }
.marcador__cifra { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }
.marcador__pie { font-size: 12px; color: var(--apagado); text-transform: uppercase; letter-spacing: .04em; }

/* ── formularios ─────────────────────────────────────────────────────────── */

.campo { display: grid; gap: 6px; }
.campo__etiqueta { font-size: 13px; color: var(--apagado); }
input[type='text'], input[type='number'], select {
  appearance: none;
  width: 100%;
  min-height: var(--alto-toque);
  padding: 10px 14px;
  background: var(--superficie-2);
  border: 1px solid var(--borde);
  border-radius: 12px;
  color: var(--texto);
  font: inherit;
  font-size: 17px;             /* menos de 16px hace que iOS haga zoom al enfocar */
}
input:focus, select:focus { outline: 2px solid var(--verde); outline-offset: 1px; }
input[type='number'] { font-variant-numeric: tabular-nums; }
select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238b9791' stroke-width='2.4' stroke-linecap='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 18px;
  padding-right: 40px;
}

/* ── fichas ──────────────────────────────────────────────────────────────── */

/* Editor de un color: nombre arriba, valor y unidades debajo. */
.ficha {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 14px;
  border-bottom: 1px solid var(--borde);
}
.ficha:last-child { border-bottom: 0; }
.ficha__abajo { grid-column: 1 / -1; display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }


.punto {
  flex: none;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 2px dashed rgba(255, 255, 255, .55);
  box-shadow: inset 0 0 0 3px rgba(0, 0, 0, .18);
}

.contador { display: flex; align-items: center; gap: 6px; }
.contador__btn {
  appearance: none;
  width: 40px; height: 40px;
  flex: none;
  border-radius: 50%;
  border: 1px solid var(--borde);
  background: var(--superficie-2);
  color: var(--texto);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
}
.contador__btn:active { background: var(--verde); color: #04210f; }
.contador__btn:disabled { opacity: .35; }
.contador input {
  width: 68px;
  min-height: 40px;
  text-align: center;
  padding: 6px;
  font-weight: 700;
}

/* ── cuadre ──────────────────────────────────────────────────────────────── */

.cuadre {
  border-radius: var(--radio);
  padding: 14px 16px;
  margin-bottom: 16px;
  border: 1px solid var(--borde);
  background: var(--superficie);
}
.cuadre--ok { border-color: var(--verde); background: color-mix(in srgb, var(--verde) 14%, var(--superficie)); }
.cuadre--mal { border-color: var(--ambar); background: color-mix(in srgb, var(--ambar) 14%, var(--superficie)); }
.cuadre__titulo { font-weight: 700; }
.cuadre__detalle { font-size: 14px; color: var(--apagado); margin-top: 2px; }
.cuadre--ok .cuadre__detalle, .cuadre--mal .cuadre__detalle { color: color-mix(in srgb, var(--texto) 78%, transparent); }

.aviso {
  border: 1px solid var(--ambar);
  background: color-mix(in srgb, var(--ambar) 12%, var(--superficie));
  border-radius: var(--radio);
  padding: 12px 14px;
  font-size: 14px;
  margin-bottom: 12px;
}

/* ── resultados ──────────────────────────────────────────────────────────── */

.gana { color: var(--verde); }
.pierde { color: var(--rojo); }

.pago { display: flex; align-items: center; gap: 10px; }
.pago__flecha { color: var(--apagado); flex: none; }

/* ── panel inferior ──────────────────────────────────────────────────────── */

.panel { position: fixed; inset: 0; z-index: 40; }
.panel[hidden] { display: none; }
.panel__fondo { position: absolute; inset: 0; background: rgba(0, 0, 0, .55); animation: fundir .2s ease both; }
@keyframes fundir { from { opacity: 0; } }

.panel__caja {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  max-height: 88dvh;
  overflow-y: auto;
  background: var(--superficie);
  border-top: 1px solid var(--borde);
  border-radius: 20px 20px 0 0;
  padding: 8px calc(var(--der) + 16px) calc(var(--abajo) + 16px) calc(var(--izq) + 16px);
  animation: subir .26s cubic-bezier(.32, .72, 0, 1) both;
}
@keyframes subir { from { transform: translateY(100%); } }

.panel__asa { width: 38px; height: 5px; border-radius: 3px; background: var(--borde); margin: 6px auto 10px; }
.panel__titulo { font-size: 18px; font-weight: 700; text-align: center; margin-bottom: 14px; }
.panel__cuerpo { display: grid; gap: 12px; }

/* ── aviso de instalación ────────────────────────────────────────────────── */

/* Va dentro del inicio, no flotando: flotando tapaba el botón del pie. */
.instalar {
  position: relative;
  margin-top: 20px;
  background: var(--superficie-2);
  border: 1px solid var(--borde);
  border-radius: var(--radio);
  padding: 14px 40px 14px 16px;
  font-size: 14px;
}
.instalar[hidden] { display: none; }
.instalar__gesto { color: var(--apagado); margin-top: 4px; display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.instalar__cerrar {
  position: absolute; top: 8px; right: 8px;
  width: 32px; height: 32px;
  border: 0; border-radius: 50%;
  background: none; color: var(--apagado);
  font-size: 15px; cursor: pointer;
}

/* Ya instalada en la pantalla de inicio: el aviso no tiene nada que decir. */
@media (display-mode: standalone) { .instalar { display: none !important; } }

/* Pantallas grandes: la app se queda centrada y con ancho de móvil. */
@media (min-width: 620px) {
  .app { max-width: 560px; margin: 0 auto; border-inline: 1px solid var(--borde); }
  .panel__caja { max-width: 560px; margin: 0 auto; border-radius: 20px 20px 0 0; }
}
