:root {
  --grass-a: #1d7a37;
  --grass-b: #208540;
  --grass-dark: #145c2c;
  --chalk: #ffffff;
  --chalk-soft: rgba(255, 255, 255, 0.72);
  --chalk-line: rgba(255, 255, 255, 0.28);
  --ink: #0f2a18;
  --ink-soft: #4b6354;
  --card: #ffffff;
  --accent: #f2601d;
  --accent-dark: #b8430f;
  --accent-glow: rgba(242, 96, 29, 0.3);
  --team-a: var(--accent);
  --team-b: #ffffff;
  --wa: #25d366;
  --danger: #ff6b6b;
  --radius: 16px;
  --display: 'Bebas Neue', 'Impact', sans-serif;
  --body: 'Inter', system-ui, -apple-system, sans-serif;
  --ad-h: 0px; /* alto de la barra de anuncio (0 si no hay) */
}
body.has-ad { --ad-h: calc(58px + env(safe-area-inset-bottom)); }
body.has-ad #app { padding-bottom: var(--ad-h); }

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body { margin: 0; height: 100%; }

body {
  font-family: var(--body);
  color: var(--chalk);
  background-color: var(--grass-a);
  /* franjas de césped */
  background-image: repeating-linear-gradient(
    180deg,
    var(--grass-a) 0 64px,
    var(--grass-b) 64px 128px
  );
  background-attachment: fixed;
  overscroll-behavior: none;
}

button, textarea, input { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; }

#app { max-width: 480px; margin: 0 auto; }

/* ---------- Layout ---------- */
.screen {
  min-height: calc(100vh - var(--ad-h));
  min-height: calc(100dvh - var(--ad-h));
  display: flex;
  flex-direction: column;
  padding: max(14px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom));
  gap: 14px;
}
.screen.fit { height: calc(100vh - var(--ad-h)); height: calc(100dvh - var(--ad-h)); overflow: hidden; }
body.has-ad .screen { padding-bottom: 12px; }

.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
}
.topbar .grow { flex: 1; min-width: 0; }
.topbar h2 { margin: 0; font-family: var(--display); font-size: 30px; letter-spacing: 1px; line-height: 1; font-weight: 400; }
.topbar p { margin: 2px 0 0; color: var(--chalk-soft); font-size: 13px; }

.icon-btn {
  width: 44px; height: 44px;
  border-radius: 50%;
  display: grid; place-items: center;
  background: rgba(0, 0, 0, 0.18);
  font-size: 20px;
  flex: none;
}
.icon-btn:active { transform: scale(0.94); }

.logo-mini { font-family: var(--display); font-size: 24px; letter-spacing: 1px; }

/* ---------- Botones ---------- */
.btn {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%;
  min-height: 56px;
  padding: 0 20px;
  border-radius: var(--radius);
  font-weight: 800;
  font-size: 17px;
  letter-spacing: 0.2px;
  transition: transform 0.1s, opacity 0.2s;
}
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.45; pointer-events: none; }
.btn.primary { background: var(--accent); color: #fff; box-shadow: 0 4px 0 var(--accent-dark); }
.btn.primary:active { box-shadow: 0 1px 0 var(--accent-dark); transform: translateY(3px); }
.btn.wa { background: var(--wa); color: #06361b; box-shadow: 0 4px 0 #189a48; }
.btn.ghost { background: rgba(0, 0, 0, 0.2); color: var(--chalk); border: 2px solid var(--chalk-line); }
.btn-row { display: flex; gap: 10px; }
.btn-row .btn { flex: 1; }

/* ---------- Home ---------- */
.hero {
  text-align: center;
  padding: 18px 0 4px;
  position: relative;
}
.hero .ball { font-size: 52px; display: inline-block; animation: bounce 1.6s ease-in-out infinite; }
.hero h1 {
  font-family: var(--display);
  font-weight: 400;
  font-size: 64px;
  line-height: 0.9;
  margin: 6px 0 0;
  letter-spacing: 2px;
  text-shadow: 0 3px 0 rgba(0, 0, 0, 0.18);
}
.hero p { margin: 8px 0 0; color: var(--chalk-soft); font-size: 15px; }

@keyframes bounce {
  0%, 100% { transform: translateY(0) rotate(0); }
  50% { transform: translateY(-10px) rotate(180deg); }
}

.steps {
  display: flex; justify-content: center; gap: 6px;
  font-size: 12px; font-weight: 700; color: var(--chalk-soft);
  flex-wrap: wrap;
}
.steps span { background: rgba(0, 0, 0, 0.18); padding: 5px 10px; border-radius: 99px; }

.panel {
  background: rgba(8, 40, 18, 0.35);
  border: 2px solid var(--chalk-line);
  border-radius: 20px;
  padding: 14px;
  display: flex; flex-direction: column; gap: 10px;
}
.panel label { font-weight: 800; font-size: 15px; }
.panel .hint { font-size: 13px; color: var(--chalk-soft); margin-top: -6px; }

textarea {
  width: 100%;
  min-height: 150px;
  resize: vertical;
  border-radius: 12px;
  border: 0;
  padding: 12px 14px;
  background: var(--card);
  color: var(--ink);
  font-size: 16px;
  line-height: 1.45;
  outline: none;
}
textarea:focus { box-shadow: 0 0 0 3px var(--accent); }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--card); color: var(--ink);
  border-radius: 99px;
  padding: 6px 6px 6px 12px;
  font-weight: 700; font-size: 14px;
  animation: pop 0.2s ease-out;
}
.chip button {
  width: 22px; height: 22px; border-radius: 50%;
  background: #e7efe9; color: var(--ink-soft);
  font-size: 13px; line-height: 1;
}
@keyframes pop { from { transform: scale(0.7); opacity: 0; } }

.count { font-weight: 800; font-size: 14px; display: flex; align-items: center; gap: 8px; }
.count .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--chalk-soft); }
.count.ok .dot { background: #fff; box-shadow: 0 0 0 4px var(--accent-glow); }
.count.warn { color: #ffd0b8; }

.recent h3 { margin: 6px 0 8px; font-size: 13px; text-transform: uppercase; letter-spacing: 1px; color: var(--chalk-soft); }
.recent a {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 14px; margin-bottom: 6px;
  background: rgba(0, 0, 0, 0.18); border-radius: 12px;
  color: var(--chalk); text-decoration: none; font-weight: 600; font-size: 14px;
}
.recent a small { color: var(--chalk-soft); font-weight: 400; }

/* ---------- Share ---------- */
.share-card {
  background: var(--card); color: var(--ink);
  border-radius: 20px; padding: 16px;
  display: flex; flex-direction: column; gap: 10px;
  animation: pop 0.25s ease-out;
}
.share-card h3 { margin: 0; font-family: var(--display); font-weight: 400; font-size: 28px; letter-spacing: 1px; }
.share-card p { margin: 0; color: var(--ink-soft); font-size: 14px; }
.link-box {
  display: flex; align-items: center; gap: 8px;
  background: #eef4f0; border-radius: 12px; padding: 4px 4px 4px 12px;
  font-size: 13px; font-weight: 600; color: var(--ink-soft);
}
.link-box span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.link-box button { background: var(--ink); color: #fff; border-radius: 9px; padding: 9px 12px; font-weight: 700; font-size: 13px; }

/* ---------- ¿Quién sos? ---------- */
.who-grid {
  flex: 1; min-height: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-auto-rows: minmax(0, 1fr);
  gap: 10px;
  max-height: 460px;
}
.who-btn {
  background: var(--card); color: var(--ink);
  border-radius: 14px;
  font-weight: 800; font-size: 17px;
  padding: 6px 10px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.18);
  overflow: hidden;
  min-height: 0;
}
.who-btn span.name { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.who-btn:active { transform: translateY(3px); box-shadow: 0 1px 0 rgba(0, 0, 0, 0.18); }
.who-btn small { font-size: 11px; font-weight: 700; color: #1d7a37; }

/* ---------- Votación (drag) ---------- */
.board {
  flex: 1; min-height: 0;
  display: grid;
  grid-template-columns: 44px 1fr;
  gap: 10px;
}
.ranks, .rank-list {
  display: flex; flex-direction: column;
  gap: 7px;
  min-height: 0;
}
.rank-badge, .player-card { flex: 1 1 0; min-height: 0; max-height: 64px; }
.rank-badge {
  display: grid; place-items: center;
  font-family: var(--display);
  font-size: clamp(20px, 4.2vh, 30px);
  color: var(--chalk-soft);
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.16);
}
.rank-badge.r1 { background: var(--accent); color: #fff; }
.rank-badge.r2 { background: rgba(255, 255, 255, 0.85); color: var(--ink); }
.rank-badge.r3 { background: rgba(255, 255, 255, 0.55); color: var(--ink); }

.rank-list { touch-action: none; user-select: none; -webkit-user-select: none; }
.player-card {
  position: relative;
  display: flex; align-items: center; gap: 10px;
  padding: 0 14px;
  background: var(--card); color: var(--ink);
  border-radius: 12px;
  font-weight: 800;
  font-size: clamp(15px, 2.6vh, 19px);
  box-shadow: 0 3px 0 rgba(0, 0, 0, 0.16);
  transition: transform 0.22s cubic-bezier(0.2, 0.8, 0.2, 1), box-shadow 0.2s;
  touch-action: none;
  cursor: grab;
  will-change: transform;
}
.player-card .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.player-card .grip {
  display: grid; grid-template-columns: repeat(2, 4px); gap: 3px;
  opacity: 0.35;
}
.player-card .grip i { width: 4px; height: 4px; border-radius: 50%; background: var(--ink); }
.player-card.dragging {
  transition: box-shadow 0.2s;
  z-index: 5;
  cursor: grabbing;
  box-shadow: 0 14px 28px rgba(0, 0, 0, 0.35), 0 0 0 3px var(--accent);
}
.player-card.dropping {
  z-index: 5;
  transition: transform 0.18s cubic-bezier(0.2, 0.8, 0.2, 1), box-shadow 0.18s;
}

/* ---------- Resultados ---------- */
.pitch {
  position: relative;
  border: 3px solid var(--chalk);
  border-radius: 10px;
  padding: 14px 12px;
  display: flex; flex-direction: column; gap: 30px;
  background:
    repeating-linear-gradient(180deg, rgba(255,255,255,0.05) 0 36px, transparent 36px 72px),
    rgba(0, 0, 0, 0.08);
  overflow: hidden;
}
/* línea central y círculo */
.pitch::before {
  content: ''; position: absolute; left: 0; right: 0; top: 50%;
  border-top: 3px solid var(--chalk-line);
}
.pitch::after {
  content: ''; position: absolute; left: 50%; top: 50%;
  width: 84px; height: 84px; margin: -42px 0 0 -42px;
  border: 3px solid var(--chalk-line); border-radius: 50%;
}
.team { position: relative; z-index: 1; }
.team-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 8px; }
.team-head h3 { margin: 0; font-family: var(--display); font-weight: 400; font-size: 30px; letter-spacing: 1px; }
.team-head .total { font-family: var(--display); font-size: 26px; }
.team-head .total small { font-family: var(--body); font-size: 11px; color: var(--chalk-soft); margin-right: 4px; }
.team-players { display: flex; flex-direction: column; gap: 6px; }
.tp {
  display: flex; align-items: center; gap: 10px;
  border-radius: 12px; padding: 8px 12px;
  font-weight: 800; font-size: 16px;
  color: var(--ink);
  animation: slidein 0.35s ease-out both;
}
.team.a .tp { background: var(--team-a); color: #fff; }
.team.b .tp { background: var(--team-b); }
.tp .shirt { font-size: 18px; }
.tp .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tp .rt { font-family: var(--display); font-size: 22px; font-weight: 400; opacity: 0.8; }
@keyframes slidein { from { opacity: 0; transform: translateX(-12px); } }

.diff {
  text-align: center; font-weight: 700; font-size: 14px;
  background: rgba(0, 0, 0, 0.2); border-radius: 99px; padding: 8px 14px;
  align-self: center;
}

.section-title {
  margin: 8px 0 0; font-size: 13px; text-transform: uppercase; letter-spacing: 1px;
  color: var(--chalk-soft); font-weight: 800;
}
.table { display: flex; flex-direction: column; gap: 4px; }
.row {
  display: grid; grid-template-columns: 26px 1fr 90px 36px; align-items: center; gap: 8px;
  background: rgba(0, 0, 0, 0.16); border-radius: 10px; padding: 8px 10px;
  font-size: 14px; font-weight: 700;
}
.row .pos { color: var(--chalk-soft); font-family: var(--display); font-size: 18px; font-weight: 400; }
.row .n { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar { height: 8px; border-radius: 99px; background: rgba(255, 255, 255, 0.18); overflow: hidden; }
.bar i { display: block; height: 100%; border-radius: 99px; background: var(--accent); }
.row .v { text-align: right; font-family: var(--display); font-size: 20px; font-weight: 400; }

.voters { display: flex; flex-wrap: wrap; gap: 6px; }
.voter {
  font-size: 13px; font-weight: 700; padding: 5px 10px; border-radius: 99px;
  background: rgba(0, 0, 0, 0.18); color: var(--chalk-soft);
}
.voter.yes { background: var(--chalk); color: var(--ink); }

.empty {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; gap: 8px; padding: 30px 10px;
}
.empty .big { font-size: 56px; }
.empty h3 { margin: 0; font-family: var(--display); font-weight: 400; font-size: 32px; letter-spacing: 1px; }
.empty p { margin: 0; color: var(--chalk-soft); }

.how { font-size: 13px; color: var(--chalk-soft); line-height: 1.5; }
.how summary { font-weight: 700; cursor: pointer; }

.center { flex: 1; display: grid; place-items: center; }
.spinner { font-size: 48px; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.error-msg { color: var(--ink); background: var(--danger); padding: 10px 12px; border-radius: 12px; font-weight: 700; font-size: 14px; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(24px + max(var(--ad-h), env(safe-area-inset-bottom)));
  transform: translate(-50%, 30px);
  background: var(--ink); color: var(--chalk);
  padding: 12px 18px; border-radius: 99px;
  font-weight: 700; font-size: 15px;
  opacity: 0; pointer-events: none;
  transition: opacity 0.2s, transform 0.25s;
  z-index: 100;
  white-space: nowrap;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Anuncio ---------- */
.ad-bar {
  position: fixed; left: 0; right: 0; bottom: 0;
  height: var(--ad-h);
  padding: 4px 0 env(safe-area-inset-bottom);
  display: flex; justify-content: center; align-items: flex-start;
  background: var(--grass-dark);
  border-top: 1px solid var(--chalk-line);
  z-index: 50;
  overflow: hidden;
}
.ad-bar[hidden] { display: none; }
