:root {
  --bg: #0d1117;
  --bg-card: #161b22;
  --bg-hover: #1c2128;
  --border: #30363d;
  --text: #e6edf3;
  --text-muted: #8b949e;
  --team-a: #388bfd;
  --team-a-bg: rgba(56,139,253,0.08);
  --team-b: #f85149;
  --team-b-bg: rgba(248,81,73,0.08);
  --green: #238636;
  --green-hover: #2ea043;
  --radius: 12px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  min-height: 100vh;
  padding: 2.5rem 1rem 0;
  line-height: 1.6;
  display: flex;
  flex-direction: column;
}

.container { max-width: 860px; margin: 0 auto; flex: 1; width: 100%; }

/* ── Header ── */
header { text-align: center; margin-bottom: 2.5rem; }

.logo {
  display: inline-flex;
  align-items: center;
  gap: 0.625rem;
  margin-bottom: 0.4rem;
}

.logo-icon { font-size: 2rem; }

header h1 {
  font-size: 2.25rem;
  font-weight: 800;
  background: linear-gradient(135deg, var(--team-a) 30%, var(--team-b));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  letter-spacing: -0.5px;
}

.subtitle {
  color: var(--text-muted);
  font-size: 0.95rem;
  margin-bottom: 1.5rem;
}

nav {
  display: inline-flex;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 50px;
  padding: 0.3rem;
  gap: 0.25rem;
}

.nav-link {
  text-decoration: none;
  color: var(--text-muted);
  padding: 0.45rem 1.35rem;
  border-radius: 50px;
  font-size: 0.875rem;
  font-weight: 500;
  transition: all 0.2s;
}

.nav-link:hover { color: var(--text); background: var(--bg-hover); }

.nav-link.active {
  background: var(--border);
  color: var(--text);
}

/* ── Cards ── */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.75rem;
  margin-bottom: 1.25rem;
}

.card-title {
  font-size: 1.05rem;
  font-weight: 600;
  margin-bottom: 0.3rem;
}

.hint {
  color: var(--text-muted);
  font-size: 0.85rem;
  margin-bottom: 1rem;
}

/* ── Textarea ── */
textarea {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-family: inherit;
  font-size: 0.9375rem;
  padding: 0.875rem;
  resize: vertical;
  min-height: 220px;
  transition: border-color 0.2s;
  line-height: 1.7;
}

textarea:focus { outline: none; border-color: var(--team-a); }
textarea::placeholder { color: var(--text-muted); opacity: 0.6; }

/* ── Buttons ── */
.actions { display: flex; gap: 0.75rem; margin-top: 1rem; flex-wrap: wrap; }

.btn {
  padding: 0.6rem 1.4rem;
  border-radius: 8px;
  border: none;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  transition: all 0.2s;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  white-space: nowrap;
}

.btn:active { transform: scale(0.97); }

.btn-primary {
  background: var(--green);
  color: #fff;
}
.btn-primary:hover { background: var(--green-hover); transform: translateY(-1px); }

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
}
.btn-ghost:hover { color: var(--text); border-color: var(--text-muted); }

.btn-reshuffle {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
  margin: 0 auto;
  display: flex;
}
.btn-reshuffle:hover { color: var(--text); border-color: var(--text-muted); }

/* ── Results ── */
.results { animation: fadeUp 0.35s ease; }
.hidden { display: none !important; }

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(14px); }
  to   { opacity: 1; transform: translateY(0); }
}

.results-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}

.results-header h2 { font-size: 1rem; color: var(--text-muted); font-weight: 500; }

.team-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin-bottom: 1rem;
}

@media (max-width: 580px) { .team-grid { grid-template-columns: 1fr; } }

.team-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.4rem;
  position: relative;
  overflow: hidden;
}

.team-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
}

.team-a::before { background: var(--team-a); }
.team-b::before { background: var(--team-b); }

.team-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}

.team-name {
  font-size: 1rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.team-a .team-name { color: var(--team-a); }
.team-b .team-name { color: var(--team-b); }

.team-count-badge {
  font-size: 0.75rem;
  color: var(--text-muted);
  background: var(--bg);
  border: 1px solid var(--border);
  padding: 0.15rem 0.55rem;
  border-radius: 50px;
}

.player-list-result {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
}

.player-list-result li {
  padding: 0.5rem 0.75rem;
  background: var(--bg);
  border-radius: 6px;
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  animation: slideIn 0.25s ease both;
}

@keyframes slideIn {
  from { opacity: 0; transform: translateX(-6px); }
  to   { opacity: 1; transform: translateX(0); }
}

.player-num {
  color: var(--text-muted);
  font-size: 0.75rem;
  min-width: 1.25rem;
  font-variant-numeric: tabular-nums;
}

.score-pill {
  font-size: 0.75rem;
  font-weight: 700;
  padding: 0.15rem 0.5rem;
  border-radius: 4px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-muted);
  flex-shrink: 0;
}

.team-footer {
  margin-top: 0.875rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
  font-size: 0.8rem;
  color: var(--text-muted);
  display: flex;
  justify-content: space-between;
}

.team-footer strong { color: var(--text); }

/* ── Variance info ── */
.variance-bar-wrap {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.5rem;
  margin-bottom: 1rem;
  display: flex;
  align-items: center;
  gap: 1.5rem;
  font-size: 0.85rem;
  flex-wrap: wrap;
}

.variance-label { color: var(--text-muted); }

.variance-track {
  flex: 1;
  min-width: 120px;
  height: 6px;
  background: var(--bg);
  border-radius: 3px;
  overflow: hidden;
}

.variance-fill {
  height: 100%;
  border-radius: 3px;
  background: linear-gradient(90deg, var(--green), #f0a500, var(--team-b));
  transition: width 0.5s ease;
}

.variance-pct {
  font-weight: 700;
  font-size: 0.875rem;
  color: var(--text);
  min-width: 3rem;
  text-align: right;
}

/* ── Balanced page: player rows ── */
.player-rows { display: flex; flex-direction: column; gap: 0.5rem; margin-bottom: 1rem; }

.col-labels {
  display: grid;
  grid-template-columns: 1fr 90px 38px;
  gap: 0.5rem;
  margin-bottom: 0.25rem;
  padding: 0 0.125rem;
}

.col-label {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.col-label.center { text-align: center; }

.player-row {
  display: grid;
  grid-template-columns: 1fr 90px 38px;
  gap: 0.5rem;
  align-items: center;
}

.player-row input[type="text"],
.player-row input[type="number"] {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-family: inherit;
  font-size: 0.9rem;
  padding: 0.55rem 0.75rem;
  transition: border-color 0.2s;
  width: 100%;
}

.player-row input[type="number"] { text-align: center; }

.player-row input:focus { outline: none; border-color: var(--team-a); }
.player-row input::placeholder { color: var(--text-muted); opacity: 0.55; }

.btn-del {
  width: 38px;
  height: 38px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  transition: all 0.2s;
  flex-shrink: 0;
}

.btn-del:hover {
  color: var(--team-b);
  border-color: var(--team-b);
  background: var(--team-b-bg);
}

/* ── Bulk paste ── */
details.bulk {
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

details.bulk summary {
  cursor: pointer;
  color: var(--text-muted);
  font-size: 0.85rem;
  user-select: none;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

details.bulk summary::-webkit-details-marker { display: none; }
details.bulk summary:hover { color: var(--text); }
details.bulk textarea { margin-top: 0.75rem; min-height: 110px; }

.bulk-actions { display: flex; gap: 0.5rem; margin-top: 0.5rem; }

/* ── Error ── */
.field-error {
  color: var(--team-b);
  font-size: 0.8rem;
  margin-top: 0.4rem;
  display: none;
}
.field-error.visible { display: block; }

/* ── Toast ── */
.toast {
  position: fixed;
  bottom: 2rem;
  left: 50%;
  transform: translateX(-50%) translateY(3rem);
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.65rem 1.4rem;
  border-radius: 50px;
  font-size: 0.85rem;
  opacity: 0;
  transition: all 0.3s cubic-bezier(.4,0,.2,1);
  z-index: 999;
  pointer-events: none;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ── Copy button ── */
.copy-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.75rem;
  padding: 0.2rem 0.55rem;
  border-radius: 4px;
  transition: all 0.2s;
  font-family: inherit;
}
.copy-btn:hover { color: var(--text); border-color: var(--text-muted); }

/* ── Page badge ── */
.page-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  background: rgba(56,139,253,0.12);
  border: 1px solid rgba(56,139,253,0.3);
  color: var(--team-a);
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.25rem 0.75rem;
  border-radius: 50px;
  margin-bottom: 1.5rem;
}

/* ── Empty state ── */
.empty-state {
  text-align: center;
  padding: 2rem;
  color: var(--text-muted);
  font-size: 0.875rem;
}

/* ── Footer ── */
.site-footer {
  margin-top: auto;
  padding: 1.5rem 1rem 2rem;
  border-top: 1px solid var(--border);
  text-align: center;
}

.footer-links {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 0.25rem 1.5rem;
  margin-bottom: 0.75rem;
}

.footer-links a {
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.85rem;
  transition: color 0.2s;
}

.footer-links a:hover { color: var(--text); }

.footer-copy {
  color: var(--text-muted);
  font-size: 0.78rem;
  opacity: 0.6;
}

/* ════════════════════════════════════════
   RESPONSIVE
════════════════════════════════════════ */

/* ── Tablet (≤768px) ── */
@media (max-width: 768px) {
  body { padding: 1.75rem 1rem 3rem; }

  header h1 { font-size: 1.875rem; }

  .card { padding: 1.375rem; }

  .variance-bar-wrap { gap: 0.75rem; padding: 0.875rem 1.25rem; }
}

/* ── Mobile (≤580px) — team-grid single column ── */
@media (max-width: 580px) {
  .team-grid { grid-template-columns: 1fr; }

  .results-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.5rem;
  }
}

/* ── Mobile (≤480px) ── */
@media (max-width: 480px) {
  body { padding: 1.125rem 0.75rem 2.5rem; }

  /* Header */
  header { margin-bottom: 1.5rem; }
  .logo-icon { font-size: 1.5rem; }
  header h1 { font-size: 1.375rem; letter-spacing: -0.25px; }
  .subtitle { font-size: 0.8rem; margin-bottom: 1.1rem; }

  /* Nav — stretch full width on very small screens */
  nav { width: 100%; justify-content: stretch; }
  .nav-link {
    flex: 1;
    text-align: center;
    padding: 0.45rem 0.5rem;
    font-size: 0.775rem;
  }

  /* Cards */
  .card { padding: 1rem; border-radius: 10px; margin-bottom: 1rem; }
  .card-title { font-size: 0.95rem; }
  .hint { font-size: 0.8rem; }

  /* Textarea */
  textarea { min-height: 160px; font-size: 1rem; /* prevent iOS zoom */ }

  /* Buttons — stack full-width on mobile */
  .actions { flex-direction: column; gap: 0.5rem; }
  .btn {
    width: 100%;
    justify-content: center;
    min-height: 46px; /* touch target */
    font-size: 0.9rem;
  }

  /* Reshuffle button */
  .btn-reshuffle { width: 100%; }

  /* Balance button (balanced.html inline style override) */
  #balanceBtn {
    width: 100% !important;
    padding: 0.875rem 1rem !important;
    font-size: 0.95rem !important;
  }

  /* Results header */
  .results-header { flex-direction: column; align-items: flex-start; gap: 0.5rem; }
  .results-header h2 { font-size: 0.85rem; }
  .copy-btn { align-self: flex-start; }

  /* Team cards */
  .team-card { padding: 1rem; }
  .team-name { font-size: 0.9rem; }
  .player-list-result li { font-size: 0.85rem; padding: 0.45rem 0.625rem; }

  /* Variance bar — stack vertically */
  .variance-bar-wrap {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.5rem;
    padding: 0.875rem 1rem;
  }
  .variance-track { width: 100%; min-width: unset; }
  .variance-pct { text-align: left; }

  /* Player rows on balanced page */
  .player-row { grid-template-columns: 1fr 68px 36px; gap: 0.375rem; }
  .col-labels  { grid-template-columns: 1fr 68px 36px; gap: 0.375rem; }
  .player-row input[type="text"],
  .player-row input[type="number"] {
    font-size: 1rem; /* prevent iOS zoom */
    padding: 0.5rem 0.5rem;
  }
  .btn-del { width: 36px; height: 36px; font-size: 1rem; }

  /* Bulk actions */
  .bulk-actions { flex-direction: column; }
  .bulk-actions .btn { width: 100%; justify-content: center; }

  /* Page badge */
  .page-badge { font-size: 0.7rem; padding: 0.2rem 0.6rem; }
}
