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

:root {
  --primary: #6366f1;
  --primary-hover: #4f46e5;
  --primary-light: #e0e7ff;
  --primary-ghost: rgba(99,102,241,0.08);
  --bg: #f8fafc;
  --surface: #ffffff;
  --border: #e2e8f0;
  --text: #1e293b;
  --text-secondary: #64748b;
  --text-muted: #94a3b8;
  --success: #10b981;
  --danger: #ef4444;
  --warning: #f59e0b;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-lg: 0 10px 25px rgba(0,0,0,0.08);
  --transition: 150ms ease;

  /* Team colors */
  --team-1: #6366f1; --team-1-bg: #eef2ff;
  --team-2: #ec4899; --team-2-bg: #fdf2f8;
  --team-3: #10b981; --team-3-bg: #ecfdf5;
  --team-4: #f59e0b; --team-4-bg: #fffbeb;
  --team-5: #06b6d4; --team-5-bg: #ecfeff;
  --team-6: #8b5cf6; --team-6-bg: #f5f3ff;
  --team-7: #ef4444; --team-7-bg: #fef2f2;
  --team-8: #14b8a6; --team-8-bg: #f0fdfa;
  --team-9: #f97316; --team-9-bg: #fff7ed;
  --team-10: #3b82f6; --team-10-bg: #eff6ff;
}

html { scroll-behavior: smooth; }

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}

/* ===== Header ===== */
header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 16px 24px;
  position: sticky;
  top: 0;
  z-index: 100;
}

.logo {
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: 900px;
  margin: 0 auto;
}

.logo-icon { width: 40px; height: 40px; flex-shrink: 0; }

.logo h1 {
  font-size: 1.25rem;
  font-weight: 800;
  background: linear-gradient(135deg, var(--primary), #8b5cf6);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  line-height: 1.2;
}

.tagline {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: 500;
}

/* ===== Main Layout ===== */
main {
  max-width: 900px;
  margin: 0 auto;
  padding: 24px 16px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* ===== Cards ===== */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow);
}

.card-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.card-header h2 {
  font-size: 1.125rem;
  font-weight: 700;
  flex: 1;
}

.card-actions {
  display: flex;
  gap: 8px;
}

.step-badge {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--primary);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.8rem;
  flex-shrink: 0;
}

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--primary);
  color: white;
}
.btn-primary:hover:not(:disabled) {
  background: var(--primary-hover);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(99,102,241,0.3);
}

.btn-outline {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border);
}
.btn-outline:hover {
  border-color: var(--primary);
  color: var(--primary);
  background: var(--primary-ghost);
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
}
.btn-ghost:hover { background: var(--primary-ghost); color: var(--primary); }

.btn-danger {
  background: transparent;
  color: var(--danger);
}
.btn-danger:hover { background: rgba(239,68,68,0.08); }

.btn-sm { padding: 4px 10px; font-size: 0.8rem; }
.btn-lg { padding: 12px 28px; font-size: 1rem; width: 100%; justify-content: center; }
.btn-icon {
  width: 36px;
  height: 36px;
  padding: 0;
  justify-content: center;
  background: var(--surface);
  border-color: var(--border);
  border-radius: var(--radius-sm);
  font-size: 1.1rem;
  color: var(--text);
}
.btn-icon:hover { border-color: var(--primary); color: var(--primary); }

/* ===== Tabs ===== */
.tab-bar {
  display: flex;
  gap: 4px;
  background: var(--bg);
  padding: 4px;
  border-radius: var(--radius-sm);
  margin-bottom: 16px;
}

.tab {
  flex: 1;
  padding: 8px 12px;
  border: none;
  background: none;
  border-radius: 6px;
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition);
}
.tab:hover { color: var(--text); }
.tab.active {
  background: var(--surface);
  color: var(--primary);
  box-shadow: var(--shadow);
}

.tab-content { display: none; }
.tab-content.active { display: block; }

/* ===== Inputs ===== */
input[type="text"],
input[type="number"],
textarea,
select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 0.9rem;
  color: var(--text);
  background: var(--surface);
  transition: border-color var(--transition);
}
input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(99,102,241,0.1);
}

textarea { resize: vertical; min-height: 120px; }

.add-player-row {
  display: flex;
  gap: 8px;
}
.add-player-row input { flex: 1; }

/* ===== Drop Zone ===== */
.drop-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 32px;
  text-align: center;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition);
}
.drop-zone:hover, .drop-zone.drag-over {
  border-color: var(--primary);
  background: var(--primary-ghost);
  color: var(--primary);
}
.drop-zone svg { margin: 0 auto 8px; display: block; }
.drop-zone p { font-size: 0.9rem; font-weight: 500; }
.drop-hint { font-size: 0.8rem; color: var(--text-muted); margin-top: 4px; }

/* ===== Player List ===== */
.player-list-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
  flex-wrap: wrap;
  gap: 8px;
}
.player-list-header h3 { font-size: 0.9rem; color: var(--text-secondary); }

.player-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 400px;
  overflow-y: auto;
}

.player-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: var(--bg);
  border-radius: var(--radius-sm);
  transition: background var(--transition);
  animation: slideIn 200ms ease;
}
.player-row:hover { background: var(--primary-ghost); }

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

.player-name {
  flex: 1;
  font-weight: 500;
  font-size: 0.9rem;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.player-attrs {
  display: none;
  align-items: center;
  gap: 6px;
}
.player-attrs.visible { display: flex; }

.player-attrs select,
.player-attrs input {
  width: auto;
  padding: 4px 6px;
  font-size: 0.75rem;
  min-width: 0;
}
.player-attrs input[type="number"] { width: 56px; }
.player-attrs select { width: 80px; }

.player-remove {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  display: flex;
  transition: all var(--transition);
}
.player-remove:hover { color: var(--danger); background: rgba(239,68,68,0.08); }

/* ===== Toggle ===== */
.toggle-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.8rem;
  color: var(--text-secondary);
  cursor: pointer;
  user-select: none;
}
.toggle-label input { display: none; }
.toggle-slider {
  width: 36px;
  height: 20px;
  background: var(--border);
  border-radius: 10px;
  position: relative;
  transition: background var(--transition);
  flex-shrink: 0;
}
.toggle-slider::after {
  content: '';
  width: 16px;
  height: 16px;
  background: white;
  border-radius: 50%;
  position: absolute;
  top: 2px;
  left: 2px;
  transition: transform var(--transition);
  box-shadow: 0 1px 2px rgba(0,0,0,0.1);
}
.toggle-label input:checked + .toggle-slider { background: var(--primary); }
.toggle-label input:checked + .toggle-slider::after { transform: translateX(16px); }

/* ===== Settings ===== */
.settings-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin-bottom: 20px;
}

.setting-item label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 8px;
}

.stepper {
  display: flex;
  align-items: center;
  gap: 8px;
}
.stepper input {
  width: 60px;
  text-align: center;
  font-weight: 700;
  font-size: 1.1rem;
  -moz-appearance: textfield;
}
.stepper input::-webkit-inner-spin-button,
.stepper input::-webkit-outer-spin-button { -webkit-appearance: none; }

.checkbox-group { display: flex; flex-direction: column; gap: 6px; }
.checkbox-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.875rem;
  cursor: pointer;
  color: var(--text-secondary);
}
.checkbox-label input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--primary);
}

.balance-hint {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 6px;
  font-style: italic;
}

/* ===== Teams Grid ===== */
.teams-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
  margin-bottom: 20px;
}

.team-card {
  border-radius: var(--radius);
  padding: 16px;
  border: 2px solid;
  animation: fadeUp 300ms ease both;
}

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

.team-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid rgba(0,0,0,0.06);
}

.team-card-header h3 {
  font-size: 0.95rem;
  font-weight: 700;
}

.team-stats {
  font-size: 0.7rem;
  color: var(--text-muted);
  font-weight: 500;
}

.team-member {
  padding: 6px 0;
  font-size: 0.875rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.team-member + .team-member { border-top: 1px solid rgba(0,0,0,0.04); }

.member-name { font-weight: 500; }
.member-attrs {
  font-size: 0.7rem;
  color: var(--text-muted);
  display: flex;
  gap: 6px;
}
.member-attr {
  background: rgba(0,0,0,0.04);
  padding: 1px 6px;
  border-radius: 4px;
}

/* ===== Export Bar ===== */
.export-bar {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.share-link-display {
  display: flex;
  gap: 8px;
  margin-top: 12px;
  padding: 12px;
  background: var(--bg);
  border-radius: var(--radius-sm);
}
.share-link-display input {
  flex: 1;
  background: var(--surface);
  font-size: 0.8rem;
}

/* ===== Instructions ===== */
.instructions-card h2 {
  font-size: 1.125rem;
  font-weight: 700;
  margin-bottom: 20px;
  text-align: center;
}

.instructions-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 20px;
}

.instruction {
  text-align: center;
  padding: 16px;
}

.instruction-num {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--primary-light);
  color: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.9rem;
  margin: 0 auto 12px;
}

.instruction h3 {
  font-size: 0.9rem;
  font-weight: 700;
  margin-bottom: 6px;
}

.instruction p {
  font-size: 0.8rem;
  color: var(--text-secondary);
  line-height: 1.5;
}

.optional-tag {
  font-size: 0.65rem;
  background: var(--warning);
  color: white;
  padding: 1px 6px;
  border-radius: 4px;
  font-weight: 600;
  vertical-align: middle;
}

/* ===== Ad Slots ===== */
.ad-slot {
  max-width: 900px;
  margin: 0 auto;
  padding: 0 16px;
}
.ad-slot-top { margin-top: 8px; }
.ad-slot-mid { margin: 0 auto; max-width: 900px; padding: 0 16px; }
.ad-slot-bottom { margin-bottom: 16px; max-width: 900px; padding: 0 16px; }

.ad-placeholder {
  background: var(--bg);
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
  padding: 20px;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.75rem;
  font-weight: 500;
}

.ad-slot-side {
  display: none; /* shown on wide screens via media query */
}

/* ===== Toast ===== */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: var(--text);
  color: white;
  padding: 10px 20px;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  transition: transform 300ms ease;
  z-index: 1000;
  white-space: nowrap;
}
.toast.visible { transform: translateX(-50%) translateY(0); }

/* ===== Footer ===== */
footer {
  max-width: 900px;
  margin: 0 auto;
  padding: 24px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.8rem;
  color: var(--text-muted);
  flex-wrap: wrap;
  gap: 8px;
}

.footer-links { display: flex; gap: 16px; }
.footer-links a {
  color: var(--text-secondary);
  text-decoration: none;
}
.footer-links a:hover { color: var(--primary); }

/* ===== Responsive ===== */
@media (max-width: 640px) {
  .settings-grid { grid-template-columns: 1fr; }
  .card { padding: 16px; }
  .teams-grid { grid-template-columns: 1fr; }
  .export-bar { flex-direction: column; }
  .export-bar .btn { width: 100%; justify-content: center; }
  .player-attrs input[type="number"] { width: 48px; }
  .player-attrs select { width: 70px; }
}

@media (min-width: 1200px) {
  main { max-width: 1100px; }

  .ad-slot-side {
    display: block;
    position: fixed;
    right: calc((100vw - 1100px) / 2 - 180px);
    top: 80px;
    width: 160px;
    padding: 0;
  }

  .ad-slot-top, .ad-slot-mid, .ad-slot-bottom {
    max-width: 1100px;
  }

  footer { max-width: 1100px; }
  header .logo { max-width: 1100px; }
}
