:root {
  --primary: #EE6600;
  --secondary: #0A1F44;
  --bg: #f5f6fa;
  --card: #ffffff;
  --text: #1a1a1a;
  --muted: #666;
  --pitch: #2e8b57;
  --pitch-line: rgba(255,255,255,0.85);
  --border: #e2e4ea;
}

body[data-land="BE"] {
  --primary: #CC0000;
  --secondary: #111111;
}

* { box-sizing: border-box; }

html, body {
  /* Vangnet tegen horizontale scroll bij smalle schermen */
  overflow-x: hidden;
  max-width: 100%;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  background: var(--secondary);
  color: white;
  position: sticky;
  top: 0;
  z-index: 50;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.brand { display: flex; align-items: center; gap: 10px; }
.brand h1 { font-size: 1.3rem; margin: 0; letter-spacing: 0.5px; }
.logo { font-size: 1.6rem; }

.topbar nav { display: flex; gap: 16px; }
.topbar nav a {
  color: rgba(255,255,255,0.8);
  text-decoration: none;
  font-weight: 500;
  padding: 6px 12px;
  border-radius: 6px;
  transition: background 0.15s;
}
.topbar nav a:hover { background: rgba(255,255,255,0.1); color: white; }
.topbar nav a.active {
  background: var(--primary);
  color: white;
}

.builder {
  display: grid;
  grid-template-columns: 1fr 320px;
  gap: 20px;
  padding: 20px;
  max-width: 1400px;
  margin: 0 auto;
}

.controls {
  grid-column: 1 / -1;
  display: flex;
  gap: 24px;
  flex-wrap: wrap;
  align-items: flex-end;
  background: var(--card);
  padding: 16px 20px;
  border-radius: 12px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.04);
}

.control-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.control-group label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--muted);
  font-weight: 600;
}

.control-group select {
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 1rem;
  background: white;
  min-width: 140px;
}

.control-group.buttons { flex-direction: row; gap: 10px; margin-left: auto; align-items: stretch; }

.land-switch { display: flex; gap: 8px; }
.land-btn {
  padding: 8px 14px;
  border: 2px solid var(--border);
  background: white;
  border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
  font-size: 0.95rem;
  transition: all 0.15s;
}
.land-btn.active {
  border-color: var(--primary);
  background: var(--primary);
  color: white;
}

.btn-primary, .btn-secondary {
  padding: 10px 18px;
  border: none;
  border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
  font-size: 0.95rem;
  transition: all 0.15s;
}
.btn-primary {
  background: var(--primary);
  color: white;
}
.btn-primary:hover { filter: brightness(1.08); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-secondary {
  background: white;
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-secondary:hover { background: #f0f0f0; }

.pitch-wrap {
  background: var(--card);
  border-radius: 12px;
  padding: 16px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.04);
}

.pitch-meta {
  text-align: center;
  font-size: 0.9rem;
  color: var(--muted);
  margin-bottom: 8px;
}
.pitch-meta #filled-count { font-weight: 700; color: var(--primary); }

.pitch {
  position: relative;
  width: 100%;
  aspect-ratio: 2 / 3;
  /* Donkere basis + maaipatroon als horizontale banden */
  background:
    repeating-linear-gradient(
      to bottom,
      #2f8b54 0,
      #2f8b54 calc(100% / 14),
      #3aa46a calc(100% / 14),
      #3aa46a calc(200% / 14)
    );
  border-radius: 8px;
  overflow: hidden;
  box-shadow: inset 0 0 60px rgba(0,0,0,0.25);
}

.pitch::before,
.pitch::after {
  content: "";
  position: absolute;
  border: 3px solid #ffffff;
}
/* Outer field outline */
.pitch::before {
  inset: 8px;
  border-radius: 4px;
}
/* Center line */
.pitch::after {
  left: 8px;
  right: 8px;
  top: 50%;
  height: 0;
  border-top: 3px solid #ffffff;
  border-left: none;
  border-right: none;
  border-bottom: none;
}

.pitch-decor {
  position: absolute;
  inset: 0;
  pointer-events: none;
}
.pitch-decor svg { width: 100%; height: 100%; display: block; }

.slot {
  position: absolute;
  transform: translate(-50%, -50%);
  width: 14%;
  min-width: 60px;
  text-align: center;
  cursor: pointer;
  z-index: 2;
}
.slot .badge {
  width: 60px;
  height: 60px;
  margin: 0 auto;
  border-radius: 50%;
  background: var(--primary);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.9rem;
  border: 3px solid white;
  box-shadow: 0 3px 10px rgba(0,0,0,0.4);
  transition: transform 0.15s;
}
.slot:hover .badge { transform: scale(1.08); }
.slot.empty .badge {
  background: rgba(0, 30, 15, 0.55);
  border-style: dashed;
  border-color: #ffffff;
  color: #ffffff;
  box-shadow: 0 2px 6px rgba(0,0,0,0.4);
}
.slot .name {
  margin-top: 6px;
  font-size: 0.75rem;
  font-weight: 600;
  color: white;
  text-shadow: 0 1px 3px rgba(0,0,0,0.6);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.slot .role {
  display: block;
  font-size: 0.65rem;
  color: rgba(255,255,255,0.7);
  text-shadow: 0 1px 2px rgba(0,0,0,0.6);
}

.squad {
  background: var(--card);
  border-radius: 12px;
  padding: 16px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.04);
  max-height: 80vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.squad-header { margin-bottom: 12px; }
.squad-header h2 { margin: 0 0 8px; font-size: 1.1rem; }
.squad-header input {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.95rem;
}

.squad-list { overflow-y: auto; flex: 1; }

.squad-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px;
  border-radius: 6px;
  margin-bottom: 4px;
  cursor: pointer;
  transition: background 0.1s;
  user-select: none;
}
.squad-item:hover { background: #f0f3f8; }
.squad-item.used {
  background: #e6f4ea;
  color: var(--muted);
}
.squad-item.used .check { color: #2e7d32; }

.squad-item .info { display: flex; flex-direction: column; }
.squad-item .name { font-weight: 600; font-size: 0.92rem; }
.squad-item .club { font-size: 0.78rem; color: var(--muted); }
.squad-item .pos-tag {
  font-size: 0.7rem;
  padding: 2px 6px;
  border-radius: 4px;
  background: var(--primary);
  color: white;
  font-weight: 700;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal-overlay[hidden] { display: none; }
.modal {
  background: var(--card);
  border-radius: 12px;
  padding: 20px;
  width: 100%;
  max-width: 420px;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.modal h3 { margin: 0; font-size: 1.05rem; }
.modal input {
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
}
.modal-list { overflow-y: auto; flex: 1; }

/* Results modal */
.results-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.65);
  z-index: 150;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  animation: fadeIn 0.2s ease-out;
}
.results-overlay[hidden] { display: none; }

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { transform: translateY(20px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

.results-modal {
  background: var(--card);
  border-radius: 16px;
  padding: 24px;
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
  position: relative;
  animation: slideUp 0.25s ease-out;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}

.results-modal h2 {
  margin: 0 0 4px;
  font-size: 1.4rem;
}
.results-modal h3 {
  margin: 18px 0 10px;
  font-size: 0.95rem;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--muted);
}

.results-subtitle {
  margin: 0 0 16px;
  color: var(--muted);
  font-size: 0.95rem;
}

.results-close {
  position: absolute;
  top: 12px;
  right: 16px;
  background: transparent;
  border: none;
  font-size: 1.8rem;
  line-height: 1;
  color: var(--muted);
  cursor: pointer;
  padding: 4px 10px;
  border-radius: 6px;
}
.results-close:hover { background: #f0f0f0; color: var(--text); }

.results-lowdata {
  text-align: center;
  padding: 20px 10px;
}
.results-emoji { font-size: 3rem; margin-bottom: 8px; }
.results-lowdata p { color: var(--muted); }
.results-hint { font-size: 0.85rem; margin-top: 8px; }

.results-formation {
  display: flex;
  align-items: center;
  gap: 12px;
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  color: white;
  padding: 14px 18px;
  border-radius: 10px;
  margin-bottom: 4px;
}
.results-formation-label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  opacity: 0.85;
}
.results-formation strong {
  font-size: 1.3rem;
  letter-spacing: 1px;
}
.results-formation-meta {
  margin-left: auto;
  font-size: 0.85rem;
  opacity: 0.9;
  text-align: right;
}

.results-slots {
  list-style: none;
  padding: 0;
  margin: 0;
}
.results-slots li {
  display: grid;
  grid-template-columns: 40px 1fr auto auto;
  align-items: center;
  gap: 10px;
  padding: 8px 4px;
  border-bottom: 1px solid var(--border);
}
.results-slots li:last-child { border-bottom: none; }
.results-slots .slot-id {
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--muted);
  letter-spacing: 0.5px;
}
.results-slots .slot-name {
  font-weight: 600;
  font-size: 0.92rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.results-slots .slot-bar {
  width: 80px;
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
  position: relative;
}
.results-slots .slot-bar > span {
  display: block;
  height: 100%;
  background: var(--primary);
  border-radius: 3px;
  transition: width 0.4s ease-out;
}
.results-slots .slot-pct {
  font-weight: 700;
  font-size: 0.9rem;
  min-width: 48px;
  text-align: right;
}
.results-slots .slot-tag {
  grid-column: 2 / -1;
  margin-top: -2px;
  font-size: 0.72rem;
  color: var(--muted);
  font-style: italic;
}
.results-slots .slot-tag.consensus { color: #2e7d32; }
.results-slots .slot-tag.contrarian { color: #c62828; font-weight: 600; }

.results-summary {
  margin-top: 14px;
  padding: 12px 14px;
  background: #f7f8fb;
  border-left: 4px solid var(--primary);
  border-radius: 6px;
  font-size: 0.9rem;
  line-height: 1.5;
}

.results-actions {
  display: flex;
  gap: 10px;
  margin-top: 18px;
  justify-content: flex-end;
  flex-wrap: wrap;
}
.results-actions a { text-decoration: none; }

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--secondary);
  color: white;
  padding: 12px 20px;
  border-radius: 8px;
  font-weight: 500;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
  z-index: 200;
  max-width: 90vw;
  text-align: center;
}
.toast.show { opacity: 1; }
.toast.error { background: #c62828; }

footer {
  text-align: center;
  padding: 20px;
  color: var(--muted);
  font-size: 0.85rem;
}
footer a { color: var(--primary); }

/* Stats page */
.stats-page {
  max-width: 1100px;
  margin: 0 auto;
  padding: 20px;
  display: grid;
  gap: 20px;
}
.stats-controls {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--card);
  padding: 14px 18px;
  border-radius: 12px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.04);
  flex-wrap: wrap;
  gap: 12px;
}
.stat-summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
}
.stat-card {
  background: var(--card);
  padding: 16px;
  border-radius: 12px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.04);
  text-align: center;
}
.stat-card .label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--muted);
  font-weight: 600;
}
.stat-card .value {
  font-size: 2rem;
  font-weight: 700;
  color: var(--primary);
  margin-top: 4px;
}

.charts-grid {
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  gap: 20px;
}
.chart-card {
  background: var(--card);
  border-radius: 12px;
  padding: 16px 20px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.04);
}
.chart-card h3 { margin: 0 0 12px; font-size: 1rem; }
.chart-card canvas { max-height: 320px; }

.consensus-card {
  grid-column: 1 / -1;
}
.consensus-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 10px;
}
.consensus-item {
  background: #f7f8fb;
  padding: 10px 12px;
  border-radius: 8px;
  border-left: 4px solid var(--primary);
}
.consensus-item .pos { font-size: 0.7rem; color: var(--muted); font-weight: 700; letter-spacing: 0.5px; }
.consensus-item .name { font-weight: 600; }
.consensus-item .votes { font-size: 0.75rem; color: var(--muted); }

.controversial-list { list-style: none; padding: 0; margin: 0; }
.controversial-list li {
  display: flex;
  justify-content: space-between;
  padding: 8px 10px;
  border-radius: 6px;
}
.controversial-list li:nth-child(odd) { background: #f7f8fb; }
.controversial-list .pct { color: var(--muted); font-size: 0.85rem; }

@media (max-width: 900px) {
  .builder { grid-template-columns: 1fr; }
  .squad { max-height: 360px; }
  .charts-grid { grid-template-columns: 1fr; }
  .control-group.buttons { margin-left: 0; width: 100%; }
  .control-group.buttons button { flex: 1; }
}

@media (max-width: 600px) {
  /* Topbar compacter zodat brand + nav op één regel passen */
  .topbar { padding: 10px 12px; }
  .brand h1 { font-size: 1.05rem; letter-spacing: 0.3px; }
  .logo { font-size: 1.3rem; }
  .topbar nav { gap: 4px; }
  .topbar nav a { padding: 6px 10px; font-size: 0.88rem; }

  /* Controls: elke groep eigen rij, knoppen 50/50 */
  .builder { padding: 12px; gap: 12px; }
  .controls { padding: 12px 14px; gap: 12px; }
  .control-group { width: 100%; }
  .control-group select { width: 100%; min-width: 0; }
  .land-switch { width: 100%; }
  .land-btn { flex: 1; min-width: 0; padding: 8px 10px; }

  /* Squad-sidebar volle breedte, kleiner padding */
  .squad { padding: 12px; }

  /* Stats: kleinere paddings */
  .stats-page { padding: 12px; gap: 12px; }
  .stats-controls { padding: 12px; }
  .chart-card { padding: 12px; }
  .chart-card h3 { font-size: 0.95rem; }
}
