/* conteo: mobile-first, big touch targets (min 48px), big numbers. */
:root {
  --green: #1b5e20;
  --green-dark: #124116;
  --amber: #f9a825;
  --red: #c62828;
  --bg: #f4f6f4;
  --card: #ffffff;
  --text: #1a1a1a;
  --muted: #5f6b5f;
  --line: #d9ded9;
  --tap: 48px;
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 18px;
  line-height: 1.35;
  color: var(--text);
  background: var(--bg);
  -webkit-tap-highlight-color: transparent;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 56px;
  padding: 8px 16px;
  padding-top: calc(8px + env(safe-area-inset-top));
  background: var(--green);
  color: #fff;
}

.brand {
  color: #fff;
  text-decoration: none;
  font-weight: 700;
  font-size: 1.25rem;
  letter-spacing: 0.02em;
}

.badge {
  display: inline-block;
  padding: 8px 12px;
  border-radius: 999px;
  font-size: 0.95rem;
  font-weight: 700;
  white-space: nowrap;
}
.badge.ok { background: #e8f5e9; color: var(--green-dark); }
.badge.pending { background: var(--amber); color: #1a1a1a; }

main {
  max-width: 560px;
  margin: 0 auto;
  padding: 16px 16px calc(32px + env(safe-area-inset-bottom));
}

h1 {
  font-size: 1.5rem;
  margin: 24px 0 12px;
}
h1:first-child { margin-top: 8px; }

.muted { color: var(--muted); margin: 4px 0 12px; }

label {
  display: block;
  font-weight: 600;
  margin: 12px 0;
}

input {
  display: block;
  width: 100%;
  margin-top: 6px;
  min-height: var(--tap);
  padding: 10px 12px;
  font: inherit;
  font-size: 1.1rem;
  border: 2px solid var(--line);
  border-radius: 10px;
  background: #fff;
}
input:focus { outline: 3px solid var(--green); outline-offset: 1px; border-color: var(--green); }
input[readonly] { background: #f4f6f4; color: var(--muted); }

button {
  font: inherit;
  font-weight: 700;
  min-height: var(--tap);
  padding: 10px 14px;
  border: 0;
  border-radius: 12px;
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}
button:active { transform: scale(0.98); }
button:disabled { opacity: 0.6; cursor: default; }

button.primary {
  width: 100%;
  background: var(--green);
  color: #fff;
  font-size: 1.15rem;
  margin-top: 8px;
}
button.secondary {
  width: 100%;
  background: #fff;
  color: var(--green-dark);
  border: 2px solid var(--green);
}

.error {
  color: var(--red);
  font-weight: 600;
  margin: 8px 0;
}
.notice {
  background: #fff8e1;
  border: 1px solid #ffe082;
  border-radius: 10px;
  padding: 10px 12px;
  margin: 8px 0 12px;
  font-size: 0.95rem;
}

.room-head h1 { margin: 4px 0 0; }

.banner {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin: 12px 0 16px;
  padding: 14px 16px;
  border-radius: 14px;
  color: #fff;
  background: var(--muted);
}
.banner.balanced { background: var(--green); }
.banner.unbalanced { background: var(--red); }
.banner.missing { background: #b26a00; }
.banner.empty { background: var(--muted); }
.banner-text { font-size: 1.15rem; font-weight: 800; }
.banner-sub { font-size: 0.95rem; opacity: 0.92; font-variant-numeric: tabular-nums; }

h2 {
  font-size: 1.2rem;
  margin: 28px 0 10px;
}
h3 {
  font-size: 1rem;
  margin: 0 0 6px;
  color: var(--muted);
}

.players {
  list-style: none;
  margin: 0;
  padding: 0;
}

.player {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px 14px;
  margin-bottom: 12px;
}

.player-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}
.player-name {
  font-size: 1.25rem;
  font-weight: 700;
  overflow-wrap: anywhere;
}
.player-total {
  font-size: 1.9rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.player-total.bump { animation: bump 0.35s ease-out; }
@keyframes bump {
  0% { transform: scale(1); }
  40% { transform: scale(1.15); color: var(--green); }
  100% { transform: scale(1); }
}
.player-buys { font-size: 0.9rem; color: var(--muted); margin-top: 2px; }

.buy-buttons {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-top: 12px;
}
.buy-buttons button {
  min-height: 56px;
  font-size: 1.2rem;
  background: #e8f5e9;
  color: var(--green-dark);
  border: 2px solid #c8e6c9;
}
.buy-buttons button.other {
  grid-column: 1 / -1;
  min-height: var(--tap);
  font-size: 1rem;
  background: #fff;
  border-color: var(--line);
}

#add-player-form { margin-top: 20px; }

.share {
  margin-top: 28px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}
.share input { font-size: 0.95rem; }

.player-sub {
  font-size: 0.95rem;
  color: var(--muted);
  margin-top: 4px;
}

.action-buttons {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 8px;
}
.action-buttons button {
  min-height: var(--tap);
  font-size: 1rem;
  background: #fff;
  color: var(--green-dark);
  border: 2px solid var(--green);
}

/* Summary table */
.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
}
.summary {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
  font-variant-numeric: tabular-nums;
}
.summary th,
.summary td {
  padding: 10px 8px;
  text-align: right;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
.summary th:first-child,
.summary td:first-child {
  text-align: left;
  white-space: normal;
  overflow-wrap: anywhere;
  min-width: 72px;
}
.summary th {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--muted);
  white-space: normal;
  vertical-align: bottom;
}
.summary tfoot td {
  font-weight: 800;
  border-bottom: 0;
  background: #f1f5f1;
}
.summary td.pos { color: var(--green-dark); font-weight: 700; }
.summary td.neg { color: var(--red); font-weight: 700; }
.summary td.neutral { color: var(--muted); }

/* Pendiente colors: por recibir (green), a pagar (red), cuadrado / sin entregar (grey) */
.pending.pos { color: var(--green-dark); font-weight: 700; }
.pending.neg { color: var(--red); font-weight: 700; }
.pending.neutral { color: var(--muted); }

/* Cierre */
.cierre {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.cierre-col {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px 14px;
}
.cierre ul {
  list-style: none;
  margin: 0;
  padding: 0;
}
.cierre li {
  padding: 6px 0;
  font-weight: 700;
  border-top: 1px solid var(--line);
  overflow-wrap: anywhere;
}
.cierre li:first-child { border-top: 0; }
.cierre li.muted { font-weight: 400; }
.cierre li.pos { color: var(--green-dark); }
.cierre li.neg { color: var(--red); }

/* Recent entries */
.recent {
  list-style: none;
  margin: 12px 0 0;
  padding: 0;
}
.entry {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  margin-bottom: 8px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
}
.entry.voided .entry-text { text-decoration: line-through; color: var(--muted); }
.entry.pending { border-style: dashed; }
.entry-main { display: flex; flex-direction: column; min-width: 0; }
.entry-text { font-weight: 600; overflow-wrap: anywhere; }
.entry-time { font-size: 0.85rem; color: var(--muted); }
.entry button {
  flex: 0 0 auto;
  min-width: 88px;
  background: #fff;
  color: var(--red);
  border: 2px solid var(--red);
}
.tag {
  flex: 0 0 auto;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--muted);
  padding: 4px 10px;
  border-radius: 999px;
  background: #eceff1;
}

/* Amount dialog */
dialog {
  border: 0;
  border-radius: 16px;
  padding: 20px;
  width: min(92vw, 420px);
  color: var(--text);
  background: var(--card);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.25);
}
dialog::backdrop { background: rgba(0, 0, 0, 0.45); }
dialog h2 { margin: 0 0 8px; }
dialog input { font-size: 1.6rem; text-align: right; }
.dialog-buttons {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 8px;
}
.dialog-buttons button { margin-top: 0; }
