/* ============================================================
   AMERICANA PADEL — Mobile-first
   Paleta: verde cancha (#0b3d2e) + lima (#cbdb29) + dark
   ============================================================ */

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

:root {
  --green-900: #0b3d2e;
  --green-700: #16604a;
  --green-500: #2e9c70;
  --lime: #cbdb29;
  --lime-dark: #a8b81f;
  --bg: #0a1f17;
  --surface: #112d22;
  --surface-2: #1a3d2f;
  --border: #1f4a39;
  --text: #e8f5ee;
  --text-dim: #8aa399;
  --danger: #ef4444;
  --gold: #fbbf24;
  --silver: #cbd5e1;
  --bronze: #d97706;
  --shadow: 0 8px 32px rgba(0,0,0,0.4);
  --radius: 14px;
}

html, body {
  background: radial-gradient(ellipse at top, #133d2e 0%, var(--bg) 60%);
  color: var(--text);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

body {
  max-width: 720px;
  margin: 0 auto;
  padding: 16px 16px 80px;
}

.view { display: none; animation: fadeIn 0.3s ease; }
.view.active { display: block; }
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ============= SETUP ============= */
.setup-header {
  text-align: center;
  padding: 24px 0 28px;
}
.logo-mark {
  font-size: 56px;
  margin-bottom: 4px;
  filter: drop-shadow(0 4px 12px rgba(203, 219, 41, 0.3));
}
.setup-header h1 {
  font-size: 42px;
  font-weight: 900;
  letter-spacing: -1.5px;
  line-height: 1;
}
.setup-header h1 .accent { color: var(--lime); }
.setup-header .tagline {
  color: var(--text-dim);
  font-size: 14px;
  margin-top: 8px;
  font-weight: 500;
}

.setup-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}

.field { margin-bottom: 18px; }
.field label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-dim);
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.field label .hint {
  text-transform: none;
  letter-spacing: 0;
  color: var(--text-dim);
  font-weight: 400;
  font-size: 11px;
}

.type-toggle {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.type-btn {
  background: var(--surface-2);
  border: 1.5px solid var(--border);
  border-radius: 10px;
  padding: 12px 10px;
  cursor: pointer;
  text-align: left;
  font-family: inherit;
  transition: all 0.15s;
  display: flex;
  flex-direction: column;
  gap: 4px;
  color: var(--text-dim);
}
.type-btn:hover { background: rgba(203, 219, 41, 0.06); }
.type-btn.active {
  border-color: var(--lime);
  background: rgba(203, 219, 41, 0.1);
  color: var(--text);
}
.type-btn .type-title {
  font-size: 14px;
  font-weight: 700;
  letter-spacing: -0.2px;
}
.type-btn.active .type-title { color: var(--lime); }
.type-btn .type-desc {
  font-size: 11px;
  line-height: 1.35;
  font-weight: 500;
  color: var(--text-dim);
}

.pair-input {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
}
.pair-input .pair-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}
.pair-input .pair-header .badge {
  background: var(--green-700);
  color: var(--lime);
  width: 26px;
  height: 26px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  flex-shrink: 0;
}
.pair-input .pair-header strong {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.pair-input .pair-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  background: transparent;
  border: none;
  padding: 0;
}
.pair-input .pair-row input {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 14px;
  font-weight: 500;
  height: 38px;
  outline: none;
  font-family: inherit;
  padding: 0 10px;
}
.pair-input .pair-row input:focus { border-color: var(--lime); }
.pair-input .pair-row input::placeholder { color: var(--text-dim); }

.counter {
  display: flex;
  align-items: center;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
}
.counter button {
  width: 44px;
  height: 44px;
  background: transparent;
  color: var(--lime);
  border: none;
  font-size: 22px;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s;
}
.counter button:hover { background: rgba(203, 219, 41, 0.1); }
.counter button:active { background: rgba(203, 219, 41, 0.2); }
.counter input {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text);
  text-align: center;
  font-size: 20px;
  font-weight: 700;
  height: 44px;
  width: 100%;
  outline: none;
  font-family: inherit;
}
.counter input::-webkit-outer-spin-button,
.counter input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

.player-names {
  display: grid;
  gap: 8px;
}
.player-input {
  display: flex;
  align-items: center;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0 12px;
  gap: 10px;
}
.player-input .badge {
  background: var(--green-700);
  color: var(--lime);
  width: 26px;
  height: 26px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  flex-shrink: 0;
}
.player-input input {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text);
  font-size: 15px;
  font-weight: 500;
  height: 40px;
  outline: none;
  font-family: inherit;
}
.player-input input::placeholder { color: var(--text-dim); }

.summary {
  background: rgba(203, 219, 41, 0.08);
  border: 1px solid rgba(203, 219, 41, 0.25);
  border-radius: 10px;
  padding: 12px 14px;
  margin: 8px 0 16px;
  font-size: 13px;
  color: var(--text);
}
.summary strong { color: var(--lime); }
.summary .warn { color: #fbbf24; font-weight: 600; display: block; margin-top: 6px; }

/* ============= BUTTONS ============= */
.btn-primary {
  width: 100%;
  background: linear-gradient(180deg, var(--lime) 0%, var(--lime-dark) 100%);
  color: #0a1f17;
  border: none;
  border-radius: 12px;
  padding: 16px;
  font-size: 16px;
  font-weight: 800;
  cursor: pointer;
  letter-spacing: -0.2px;
  box-shadow: 0 4px 16px rgba(203, 219, 41, 0.25);
  transition: transform 0.1s, box-shadow 0.15s;
  font-family: inherit;
}
.btn-primary:hover { box-shadow: 0 6px 20px rgba(203, 219, 41, 0.35); }
.btn-primary:active { transform: scale(0.98); }
.btn-primary:disabled { opacity: 0.4; cursor: not-allowed; }

.btn-ghost {
  width: 100%;
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  margin-top: 10px;
  font-family: inherit;
  transition: background 0.15s;
}
.btn-ghost:hover { background: var(--surface-2); }

.btn-link {
  display: block;
  margin: 24px auto 0;
  background: none;
  color: var(--text-dim);
  border: none;
  font-size: 13px;
  cursor: pointer;
  font-family: inherit;
  padding: 8px;
}
.btn-link:hover { color: var(--text); }

/* ============= RULES ============= */
.rules {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-top: 16px;
  overflow: hidden;
}
.rules summary {
  padding: 14px 18px;
  cursor: pointer;
  font-weight: 600;
  font-size: 14px;
  color: var(--text);
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.rules summary::after {
  content: '+';
  font-size: 20px;
  color: var(--lime);
  font-weight: 700;
}
.rules[open] summary::after { content: '−'; }
.rules summary::-webkit-details-marker { display: none; }
.rules ul {
  padding: 0 18px 18px 36px;
  font-size: 13px;
  color: var(--text-dim);
  line-height: 1.7;
}
.rules ul ul { padding-bottom: 0; padding-top: 4px; }
.rules strong { color: var(--lime); font-weight: 700; }

/* ============= ROUND VIEW ============= */
.round-header {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  margin-bottom: 14px;
  box-shadow: var(--shadow);
}
.round-meta {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 14px;
}
.round-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1.2px;
  color: var(--lime);
  text-transform: uppercase;
}
.round-counter {
  font-size: 22px;
  font-weight: 800;
  letter-spacing: -0.5px;
}

.timer {
  text-align: center;
}
.timer-display {
  font-size: 56px;
  font-weight: 900;
  letter-spacing: -2px;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  line-height: 1;
  margin-bottom: 12px;
  font-family: 'Inter', monospace;
}
.timer.running .timer-display { color: var(--lime); }
.timer.warning .timer-display { color: #fbbf24; animation: pulse 1s ease-in-out infinite; }
.timer.danger .timer-display { color: var(--danger); animation: pulse 0.5s ease-in-out infinite; }
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}
.timer-controls {
  display: flex;
  gap: 8px;
  justify-content: center;
}
.timer-btn {
  background: var(--lime);
  color: #0a1f17;
  border: none;
  border-radius: 10px;
  padding: 10px 24px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
  transition: transform 0.1s;
}
.timer-btn:active { transform: scale(0.95); }
.timer-btn-ghost {
  background: transparent;
  color: var(--text-dim);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 16px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
}

/* ============= MATCHES ============= */
.matches { display: grid; gap: 12px; }
.match-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}
.match-court {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1.2px;
  color: var(--lime);
  text-transform: uppercase;
  margin-bottom: 10px;
}
.match-pairs {
  display: grid;
  gap: 8px;
}
.pair-row {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
}
.pair-row.winning { border-color: var(--lime); background: rgba(203, 219, 41, 0.08); }
.pair-names {
  font-size: 14px;
  font-weight: 600;
  line-height: 1.3;
}
.pair-names .partner-sep {
  color: var(--text-dim);
  margin: 0 6px;
  font-weight: 400;
}
.pair-score {
  display: flex;
  align-items: center;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}
.pair-score button {
  width: 32px;
  height: 32px;
  background: transparent;
  color: var(--lime);
  border: none;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
}
.pair-score input {
  width: 36px;
  text-align: center;
  background: transparent;
  border: none;
  color: var(--text);
  font-size: 18px;
  font-weight: 800;
  font-family: inherit;
  outline: none;
  font-variant-numeric: tabular-nums;
}
.pair-score input::-webkit-outer-spin-button,
.pair-score input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.match-vs {
  text-align: center;
  font-size: 11px;
  font-weight: 700;
  color: var(--text-dim);
  letter-spacing: 1px;
  padding: 2px 0;
}

.resting-box {
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-top: 12px;
  font-size: 13px;
  color: var(--text-dim);
}
.resting-label {
  font-weight: 700;
  color: var(--lime);
  margin-right: 8px;
}

.buzzer-tip {
  background: rgba(251, 191, 36, 0.08);
  border: 1px solid rgba(251, 191, 36, 0.25);
  border-radius: 10px;
  padding: 10px 14px;
  margin-top: 12px;
  font-size: 12px;
  color: var(--text-dim);
  line-height: 1.5;
}
.buzzer-tip strong { color: var(--gold); display: block; margin-bottom: 2px; font-size: 13px; }

.round-actions {
  display: grid;
  grid-template-columns: 1fr 1.6fr;
  gap: 10px;
  margin-top: 16px;
}
.round-actions .btn-ghost,
.round-actions .btn-primary { margin-top: 0; }

/* ============= LEADERBOARD ============= */
.lb-header { text-align: center; padding: 16px 0 20px; }
.lb-header h2 {
  font-size: 28px;
  font-weight: 800;
  letter-spacing: -1px;
}
.lb-subtitle {
  color: var(--text-dim);
  font-size: 14px;
  margin-top: 4px;
}

.lb-table-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}
.lb-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
.lb-table thead {
  background: var(--surface-2);
}
.lb-table th {
  padding: 12px 8px;
  text-align: center;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.8px;
  text-transform: uppercase;
  color: var(--text-dim);
}
.lb-table th:nth-child(2) { text-align: left; padding-left: 12px; }
.lb-table td {
  padding: 14px 8px;
  text-align: center;
  border-top: 1px solid var(--border);
  font-variant-numeric: tabular-nums;
}
.lb-table td.player-name {
  text-align: left;
  padding-left: 12px;
  font-weight: 600;
}
.lb-table td.rank {
  font-weight: 800;
  font-size: 16px;
}
.lb-table td.diff {
  font-weight: 800;
  font-size: 15px;
}
.lb-table td.diff.positive { color: var(--lime); }
.lb-table td.diff.negative { color: var(--danger); }
.lb-table tr.rank-1 td.rank { color: var(--gold); }
.lb-table tr.rank-1 td.player-name::before { content: '🥇 '; }
.lb-table tr.rank-2 td.rank { color: var(--silver); }
.lb-table tr.rank-2 td.player-name::before { content: '🥈 '; }
.lb-table tr.rank-3 td.rank { color: var(--bronze); }
.lb-table tr.rank-3 td.player-name::before { content: '🥉 '; }
.lb-table tr.rank-1 { background: rgba(251, 191, 36, 0.06); }

.lb-actions {
  display: grid;
  gap: 10px;
  margin-top: 16px;
}
.lb-actions .btn-ghost,
.lb-actions .btn-primary { margin-top: 0; }

/* ============= RESPONSIVE ============= */
@media (min-width: 600px) {
  body { padding: 24px 24px 80px; }
  .setup-header h1 { font-size: 52px; }
  .timer-display { font-size: 72px; }
  .matches { grid-template-columns: 1fr; }
  .pair-row { grid-template-columns: 1fr 140px; }
}

@media (max-width: 380px) {
  .setup-header h1 { font-size: 36px; }
  .timer-display { font-size: 48px; }
  .pair-names { font-size: 13px; }
  body { padding: 12px 12px 60px; }
}
