:root {
  --green-1: #0a3d2c;
  --green-2: #0e5a3f;
  --gold: #f4c430;
  --gold-soft: #ffd95e;
  --ink: #0d1b16;
  --card: #ffffff;
  --line: #e3e8e5;
  --muted: #6b7c75;
  --gold-1: #ffd700;
  --silver: #c7ccd1;
  --bronze: #cd7f32;
  --shadow: 0 6px 22px rgba(0, 0, 0, 0.12);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  overflow-x: hidden;
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink);
  background:
    radial-gradient(1200px 600px at 50% -10%, rgba(244, 196, 48, 0.18), transparent 60%),
    linear-gradient(160deg, var(--green-1), var(--green-2));
  min-height: 100vh;
}

/* ── Topbar ── */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px clamp(14px, 4vw, 40px);
  position: sticky;
  top: 0;
  z-index: 5;
  background: rgba(10, 61, 44, 0.85);
  backdrop-filter: blur(8px);
  border-bottom: 2px solid rgba(244, 196, 48, 0.4);
}
.brand { display: flex; align-items: center; gap: 14px; color: #fff; }
.brand .ball { font-size: 38px; filter: drop-shadow(0 2px 4px rgba(0,0,0,.4)); }
.brand h1 {
  margin: 0;
  font-size: clamp(22px, 4vw, 32px);
  letter-spacing: 3px;
  font-weight: 800;
  color: var(--gold-soft);
}
.brand .sub { margin: 0; font-size: 13px; opacity: 0.9; }

.hist-btn {
  background: var(--gold);
  color: #3a2c00;
  border: none;
  padding: 9px 14px;
  border-radius: 999px;
  font-weight: 700;
  cursor: pointer;
  font-size: 14px;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.25);
}
.hist-btn:hover { background: var(--gold-soft); }

main { max-width: 880px; margin: 0 auto; padding: 22px clamp(12px, 4vw, 24px) 80px; }
.hint {
  color: #eafff5;
  text-align: center;
  font-size: 14px;
  margin: 6px 0 22px;
  opacity: 0.9;
}

/* ── Board / tarjetas de equipo ── */
.board { display: flex; flex-direction: column; gap: 14px; }
.loading { color: #fff; text-align: center; padding: 40px; }

.team {
  display: grid;
  grid-template-columns: 56px 1fr auto;
  align-items: center;
  gap: 14px;
  background: var(--card);
  border-radius: 16px;
  padding: 14px 16px;
  box-shadow: var(--shadow);
  border: 2px solid transparent;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.team.moving { transform: scale(1.01); box-shadow: 0 10px 30px rgba(0,0,0,.25); }

.rank {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  font-weight: 800;
  font-size: 20px;
  background: var(--green-2);
  color: #fff;
}
.team:nth-child(1) { border-color: var(--gold-1); }
.team:nth-child(1) .rank { background: linear-gradient(145deg, #ffe17a, #e6b400); color: #3a2c00; }
.team:nth-child(2) { border-color: var(--silver); }
.team:nth-child(2) .rank { background: linear-gradient(145deg, #eef1f4, #b7bdc4); color: #2a2f33; }
.team:nth-child(3) { border-color: var(--bronze); }
.team:nth-child(3) .rank { background: linear-gradient(145deg, #e3a866, #b8702a); color: #3a2200; }

.center { min-width: 0; display: flex; align-items: center; gap: 14px; }
.photos { display: flex; flex-shrink: 0; }
.photos img {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  object-fit: cover;
  border: 3px solid #fff;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.25);
  background: #ddd;
}
.photos img:nth-child(2) { margin-left: -16px; }
.photos img:hover { transform: scale(1.6); transition: transform .12s; z-index: 3; position: relative; }

.name-input {
  border: none;
  background: transparent;
  font-size: clamp(16px, 2.4vw, 20px);
  font-weight: 700;
  color: var(--ink);
  width: 100%;
  min-width: 80px;
  padding: 4px 6px;
  border-radius: 8px;
}
.name-input:hover { background: #f1f5f3; }
.name-input:focus { outline: 2px solid var(--green-2); background: #fff; }

/* ── Controles (puntos + flechas) ── */
.controls { display: flex; align-items: center; gap: 12px; }
.points {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}
.points label { font-size: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: 1px; }
.pts-row { display: flex; align-items: center; gap: 4px; }
.pts-btn {
  width: 26px; height: 26px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #f6f8f7;
  font-size: 16px; font-weight: 700;
  cursor: pointer; color: var(--green-2);
  line-height: 1;
}
.pts-btn:hover { background: #e8efeb; }
.pts-input {
  width: 56px;
  text-align: center;
  font-size: 22px;
  font-weight: 800;
  border: 2px solid var(--line);
  border-radius: 10px;
  padding: 4px;
  color: var(--green-1);
  -moz-appearance: textfield;
}
.pts-input::-webkit-outer-spin-button,
.pts-input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.pts-input:focus { outline: none; border-color: var(--green-2); }

.arrows { display: flex; flex-direction: column; gap: 4px; }
.arrow {
  width: 34px; height: 30px;
  border: none;
  border-radius: 8px;
  background: var(--green-2);
  color: #fff;
  font-size: 15px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.arrow:hover { background: var(--green-1); }
.arrow:disabled { background: #cdd6d2; cursor: not-allowed; }

/* ── Historial ── */
/* El atributo hidden debe ganarle a display:flex/block de abajo */
.hist-panel[hidden], .overlay[hidden] { display: none; }

.overlay {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 20;
}
.hist-panel {
  position: fixed;
  top: 0; right: 0; bottom: 0;
  width: min(420px, 92vw);
  background: #fff;
  z-index: 21;
  box-shadow: -8px 0 30px rgba(0, 0, 0, 0.3);
  display: flex;
  flex-direction: column;
  animation: slide 0.22s ease;
}
@keyframes slide { from { transform: translateX(100%); } to { transform: translateX(0); } }
.hist-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 20px;
  border-bottom: 1px solid var(--line);
}
.hist-head h2 { margin: 0; font-size: 18px; }
.icon-btn { border: none; background: #f0f3f1; width: 34px; height: 34px; border-radius: 8px; cursor: pointer; font-size: 16px; }
.hist-list { list-style: none; margin: 0; padding: 8px 0; overflow-y: auto; }
.hist-list li {
  padding: 10px 20px;
  border-bottom: 1px solid #f1f4f2;
  font-size: 14px;
}
.hist-list .when { color: var(--muted); font-size: 12px; }
.hist-list .what b { color: var(--green-1); }
.hist-empty { padding: 30px 20px; color: var(--muted); text-align: center; }

/* ── Footer ── */
.foot {
  position: fixed; bottom: 0; left: 0; right: 0;
  display: flex; align-items: center; justify-content: center; gap: 10px;
  padding: 8px;
  font-size: 12px;
  color: #d6efe4;
  background: rgba(10, 61, 44, 0.9);
}
.status { color: #59e08f; font-size: 10px; }
.status.off { color: #ff6b6b; }

/* ── Responsive ── */
@media (max-width: 560px) {
  .topbar { padding: 11px 12px; }
  .brand { gap: 9px; }
  .brand .ball { font-size: 28px; }
  .brand h1 { letter-spacing: 1px; }
  .hist-btn { padding: 8px 11px; font-size: 13px; }
  main { padding-left: 10px; padding-right: 10px; }
  .team { grid-template-columns: 42px 1fr; grid-auto-rows: auto; row-gap: 12px; padding: 12px; }
  .center { gap: 10px; min-width: 0; }
  .name-input { font-size: 16px; min-width: 0; }
  .controls { grid-column: 1 / -1; justify-content: flex-start; gap: 22px; }
  .photos img { width: 46px; height: 46px; }
  .photos img:nth-child(2) { margin-left: -14px; }
  .rank { width: 38px; height: 38px; font-size: 17px; }
  .arrows { flex-direction: row; }
  .arrow { width: 40px; height: 34px; }
}
