/* ── Reset & Base ──────────────────────────────── */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --bg: #1e1e2e;
  --surface: #24243a;
  --surface-2: #2c2c44;
  --border: #3a3a5c;
  --text: #cdd6f4;
  --text-muted: #8e95b3;
  --accent: #8fae8b;
  --accent-hover: #a3c29f;
  --team1: #89b4fa;
  --team2: #f9c74f;
  --error: #f38ba8;
  --success: #a6e3a1;
  --radius: 12px;
  --radius-sm: 8px;
}

body {
  font-family: 'Inter', 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  padding: 16px;
  line-height: 1.5;
}

/* ── Container ────────────────────────────────── */
.container {
  max-width: 900px;
  margin: 0 auto;
}

/* ── Header ───────────────────────────────────── */
.header {
  text-align: center;
  padding: 24px 0 16px;
}
.header h1 {
  font-size: 1.8rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.02em;
}
.subtitle {
  color: var(--text-muted);
  font-size: 0.85rem;
  margin-top: 4px;
}

/* ── Roster Bar ───────────────────────────────── */
.roster-bar {
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 10px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 16px;
}
.roster-bar select {
  flex: 1;
  height: 32px;
  padding: 0 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 0.85rem;
}

/* ── Buttons ──────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px 20px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 120ms ease;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
}
.btn:hover { background: var(--border); }
.btn:active { transform: scale(0.97); }

.btn-primary {
  background: var(--accent);
  color: #1e1e2e;
  border-color: var(--accent);
  font-size: 1rem;
  padding: 12px 28px;
}
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }

.btn-muted {
  color: var(--text-muted);
  background: transparent;
  border-color: var(--border);
}
.btn-muted:hover { color: var(--text); background: var(--surface-2); }

.btn-sm {
  padding: 6px 12px;
  font-size: 0.78rem;
}

/* ── Player Pool ──────────────────────────────── */
.player-pool {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 16px;
}
.pool-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
  font-weight: 600;
  font-size: 0.9rem;
}
.pool-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-height: 36px;
}
.pool-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 5px 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.82rem;
  cursor: grab;
  user-select: none;
  transition: all 100ms ease;
}
.pool-chip:active { cursor: grabbing; opacity: 0.7; }
.pool-chip:hover { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 10%, var(--surface-2)); }
.pool-chip.is-assigned {
  opacity: 0.35;
  text-decoration: line-through;
  pointer-events: none;
}
.pool-chip-remove {
  font-size: 0.7rem;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0 2px;
  line-height: 1;
}
.pool-chip-remove:hover { color: var(--error); }

/* Drop target highlight */
.position-card.drag-over {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 8%, var(--surface));
}
textarea.drag-over {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 8%, var(--surface-2));
}

/* ── Input Grid ───────────────────────────────── */
.input-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.position-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.position-header {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  font-size: 0.9rem;
}

.position-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border-radius: 6px;
  background: var(--accent);
  color: #1e1e2e;
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 0.02em;
  flex-shrink: 0;
}

textarea {
  width: 100%;
  min-height: 80px;
  padding: 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: inherit;
  font-size: 0.85rem;
  resize: vertical;
  transition: border-color 150ms ease;
  line-height: 1.5;
}
textarea::placeholder { color: var(--text-muted); opacity: 0.6; }
textarea:focus { outline: none; border-color: var(--accent); }

.libero-options {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.78rem;
  color: var(--text-muted);
}
.libero-options label {
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
}
.libero-options input[type="checkbox"] {
  accent-color: var(--accent);
}

/* ── Actions ──────────────────────────────────── */
.actions {
  display: flex;
  gap: 10px;
  justify-content: center;
  margin: 20px 0;
  flex-wrap: wrap;
}

/* ── Info Box ─────────────────────────────────── */
.info-box {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  line-height: 1.5;
  margin-bottom: 16px;
}
.info-box.info-error {
  background: color-mix(in srgb, var(--error) 12%, var(--surface));
  border: 1px solid color-mix(in srgb, var(--error) 30%, var(--border));
  color: var(--error);
}
.info-box.info-warn {
  background: color-mix(in srgb, var(--team2) 12%, var(--surface));
  border: 1px solid color-mix(in srgb, var(--team2) 30%, var(--border));
  color: var(--team2);
}
.info-box.info-success {
  background: color-mix(in srgb, var(--success) 12%, var(--surface));
  border: 1px solid color-mix(in srgb, var(--success) 30%, var(--border));
  color: var(--success);
}

/* ── Results ──────────────────────────────────── */
.results { margin-top: 24px; }

.results-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}
.results-header h2 {
  font-size: 1.1rem;
  font-weight: 700;
}

.teams-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.team-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  overflow: hidden;
}

.team-title {
  font-size: 1rem;
  font-weight: 700;
  text-align: center;
  padding-bottom: 10px;
  margin-bottom: 10px;
  border-bottom: 1px solid var(--border);
}
.team-card:first-child .team-title { color: var(--team1); }
.team-card:last-child .team-title { color: var(--team2); }

.team-pos {
  margin-bottom: 8px;
}
.team-pos-label {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 4px;
}
.team-pos-player {
  padding: 4px 8px;
  font-size: 0.85rem;
  border-radius: 4px;
  margin-bottom: 2px;
}
.team-pos-player:hover {
  background: var(--surface-2);
}
.flex-tag {
  font-size: 0.68rem;
  color: var(--text-muted);
  margin-left: 6px;
}

.team-count {
  text-align: center;
  font-size: 0.78rem;
  color: var(--text-muted);
  padding-top: 10px;
  margin-top: 10px;
  border-top: 1px solid var(--border);
}

/* ── Bench ────────────────────────────────────── */
.bench {
  margin-top: 16px;
  padding: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.bench h3 {
  font-size: 0.9rem;
  color: var(--text-muted);
  margin-bottom: 10px;
}
.bench-player {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
  margin: 3px;
}
.bench-player-pos {
  font-size: 0.7rem;
  color: var(--text-muted);
}

/* ── History ──────────────────────────────────── */
.history {
  margin-top: 20px;
  padding: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.history h3 {
  font-size: 0.9rem;
  color: var(--text-muted);
  margin-bottom: 10px;
}
.history-entry {
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  font-size: 0.8rem;
  cursor: pointer;
  transition: background 100ms ease;
}
.history-entry:last-child { border-bottom: none; }
.history-entry:hover { background: var(--surface-2); }
.history-time {
  font-size: 0.7rem;
  color: var(--text-muted);
}

/* ── Toast ────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  padding: 10px 18px;
  background: var(--success);
  color: #1e1e2e;
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
  font-weight: 600;
  opacity: 0;
  transform: translateY(10px);
  transition: all 200ms ease;
  pointer-events: none;
  z-index: 100;
}
.toast.show {
  opacity: 1;
  transform: translateY(0);
}

/* ── Responsive ───────────────────────────────── */
@media (max-width: 640px) {
  body { padding: 10px; }
  .header h1 { font-size: 1.4rem; }
  .input-grid { grid-template-columns: 1fr; }
  .teams-grid { grid-template-columns: 1fr; }
  .roster-bar { flex-wrap: wrap; }
  .actions { flex-direction: column; align-items: stretch; }
  .btn-primary { width: 100%; }
}
