:root {
  --pitch-900: #0d2b1d;
  --pitch-800: #14392a;
  --pitch-700: #1b4d36;
  --pitch-line: #2f6a4a;
  --chalk: #f5f7f2;
  --chalk-dim: #cfe0d3;
  --amber: #f2b134;
  --amber-dark: #b9800f;
  --taken: #7d8a80;
  --danger: #e2574c;
  --radius: 14px;
  --font-display: 'Barlow Condensed', sans-serif;
  --font-body: 'Inter', sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--pitch-900);
  color: var(--chalk);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
}

body {
  background-image:
    repeating-linear-gradient(0deg, rgba(255,255,255,0.02) 0 40px, transparent 40px 80px);
}

.hidden { display: none !important; }

/* ---------- Loading ---------- */
.loading {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}
.spinner {
  width: 34px; height: 34px;
  border-radius: 50%;
  border: 3px solid rgba(245,247,242,0.15);
  border-top-color: var(--amber);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Gate / Namensauswahl ---------- */
.gate {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.gate-card {
  width: 100%;
  max-width: 400px;
  background: var(--pitch-800);
  border: 1px solid var(--pitch-line);
  border-radius: var(--radius);
  padding: 32px 24px;
  text-align: center;
}
.gate-crest {
  font-size: 40px;
  line-height: 1;
  margin-bottom: 8px;
  filter: drop-shadow(0 0 12px rgba(242,177,52,0.25));
}
.gate-logo-img { height: 128px; width: auto; max-width: 280px; object-fit: contain; }
.gate-title {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 34px;
  letter-spacing: 0.02em;
  margin: 0;
  text-transform: uppercase;
}
.gate-club {
  color: var(--amber);
  font-weight: 600;
  margin: 4px 0 16px;
  font-size: 14px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.gate-text {
  color: var(--chalk-dim);
  font-size: 14px;
  line-height: 1.5;
  margin-bottom: 24px;
}
.gate-label {
  display: block;
  text-align: left;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--chalk-dim);
  margin-bottom: 6px;
}
#nameSelect {
  width: 100%;
  padding: 13px 14px;
  font-size: 16px;
  font-family: var(--font-body);
  border-radius: 10px;
  border: 1px solid var(--pitch-line);
  background: var(--pitch-900);
  color: var(--chalk);
  margin-bottom: 16px;
  appearance: none;
}
.btn-primary {
  width: 100%;
  padding: 14px;
  font-size: 15px;
  font-weight: 700;
  font-family: var(--font-body);
  border: none;
  border-radius: 10px;
  background: var(--amber);
  color: #241a03;
  cursor: pointer;
  transition: transform 0.1s ease, opacity 0.15s ease;
}
.btn-primary:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}
.btn-primary:not(:disabled):active {
  transform: scale(0.98);
}
.gate-error {
  color: var(--danger);
  font-size: 13px;
  margin-top: 14px;
  line-height: 1.4;
}

/* ---------- Topbar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--pitch-800);
  border-bottom: 1px solid var(--pitch-line);
}
.topbar-inner {
  max-width: 640px;
  margin: 0 auto;
  padding: 8px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.topbar-crest { font-size: 22px; display: flex; align-items: center; }
.topbar-logo-img { height: 60px; width: auto; max-width: 76px; object-fit: contain; }
.topbar-titles { display: flex; flex-direction: column; line-height: 1.2; flex: 1; }
.topbar-club { font-family: var(--font-display); font-weight: 700; font-size: 17px; text-transform: uppercase; letter-spacing: 0.02em; }
.topbar-sub { font-size: 11px; color: var(--chalk-dim); }

.profile-wrap { position: relative; }
.topbar-me {
  font-size: 12px;
  font-weight: 600;
  background: rgba(242,177,52,0.12);
  color: var(--amber);
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid rgba(242,177,52,0.3);
  white-space: nowrap;
  cursor: pointer;
  font-family: var(--font-body);
}
.profile-menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  background: var(--pitch-800);
  border: 1px solid var(--pitch-line);
  border-radius: 12px;
  padding: 8px;
  min-width: 200px;
  z-index: 30;
  box-shadow: 0 12px 32px rgba(0,0,0,0.45);
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.profile-menu-name {
  font-size: 12px;
  color: var(--chalk-dim);
  padding: 8px 10px 6px;
  border-bottom: 1px solid var(--pitch-line);
  margin-bottom: 4px;
  font-weight: 600;
}
.profile-menu-item {
  display: block;
  text-align: left;
  padding: 9px 10px;
  border-radius: 8px;
  border: none;
  background: transparent;
  color: var(--chalk);
  font-size: 13.5px;
  font-family: var(--font-body);
  cursor: pointer;
  text-decoration: none;
}
.profile-menu-item:hover { background: rgba(255,255,255,0.06); }

/* ---------- Scoreboard ---------- */
.scoreboard {
  max-width: 640px;
  margin: 16px auto 0;
  padding: 0 16px;
}
.scoreboard-row {
  display: flex;
  align-items: center;
  background: var(--pitch-800);
  border: 1px solid var(--pitch-line);
  border-radius: var(--radius);
  padding: 16px 8px;
}
.scoreboard-cell {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}
.scoreboard-num {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 30px;
  color: var(--amber);
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
.scoreboard-label {
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--chalk-dim);
}
.scoreboard-divider {
  width: 1px;
  align-self: stretch;
  background: var(--pitch-line);
}

/* ---------- View-Tabs (Hauptnavigation) ---------- */
.view-tabs {
  max-width: 640px;
  margin: 16px auto 0;
  padding: 0 16px;
  display: flex;
  gap: 6px;
  overflow-x: auto;
  scrollbar-width: none;
}
.view-tabs::-webkit-scrollbar { display: none; }
.view-tab {
  flex: none;
  padding: 8px 14px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 600;
  background: transparent;
  border: 1px solid transparent;
  color: var(--chalk-dim);
  cursor: pointer;
  font-family: var(--font-body);
  white-space: nowrap;
}
.view-tab.active {
  background: var(--pitch-800);
  border-color: var(--pitch-line);
  color: var(--amber);
}

/* ---------- Tabs ---------- */
.tabs {
  max-width: 640px;
  margin: 16px auto 0;
  padding: 0 16px;
  display: flex;
  gap: 8px;
  overflow-x: auto;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  flex: none;
  padding: 9px 16px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 600;
  background: var(--pitch-800);
  border: 1px solid var(--pitch-line);
  color: var(--chalk-dim);
  cursor: pointer;
  white-space: nowrap;
}
.tab.active {
  background: var(--amber);
  color: #241a03;
  border-color: var(--amber);
}

.cat-info {
  max-width: 640px;
  margin: 12px auto 0;
  padding: 10px 16px;
  font-size: 12.5px;
  line-height: 1.5;
  color: var(--chalk-dim);
}

/* ---------- Liste ---------- */
.list {
  max-width: 640px;
  margin: 4px auto 48px;
  padding: 8px 16px 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.event-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.event-head {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 10px 4px 2px;
}
.event-date {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 15px;
  color: var(--amber);
  text-transform: uppercase;
}
.event-time {
  font-size: 12.5px;
  color: var(--chalk-dim);
}

.slot-card {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--pitch-800);
  border: 1px solid var(--pitch-line);
  border-radius: 12px;
  padding: 13px 14px;
  cursor: pointer;
  user-select: none;
  transition: border-color 0.15s ease, background 0.15s ease;
}
.slot-card:active { transform: scale(0.995); }

.slot-check {
  flex: none;
  width: 24px; height: 24px;
  border-radius: 7px;
  border: 2px solid var(--pitch-line);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  color: transparent;
  background: var(--pitch-900);
}

.slot-body { flex: 1; min-width: 0; }
.slot-title {
  font-size: 14px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.slot-meta {
  font-size: 12px;
  color: var(--chalk-dim);
  margin-top: 2px;
}

.slot-hours {
  flex: none;
  font-size: 11.5px;
  font-weight: 700;
  color: var(--chalk-dim);
  background: rgba(255,255,255,0.05);
  padding: 3px 8px;
  border-radius: 999px;
}

/* Zustände */
.slot-card.state-free .slot-check { border-color: var(--pitch-line); }

.slot-card.state-mine {
  border-color: var(--amber);
  background: rgba(242,177,52,0.08);
}
.slot-card.state-mine .slot-check {
  background: var(--amber);
  border-color: var(--amber);
  color: #241a03;
}

.slot-card.state-taken {
  opacity: 0.6;
  cursor: default;
}
.slot-card.state-taken .slot-check {
  background: var(--taken);
  border-color: var(--taken);
  color: var(--pitch-900);
}
.slot-card.state-taken .slot-meta { color: var(--taken); }

/* Gesperrt: eigener Termin, aber < 2 Wochen entfernt -> keine Selbstabmeldung mehr */
.slot-card.state-locked {
  border-color: var(--amber);
  background: rgba(242,177,52,0.08);
  cursor: default;
}
.slot-card.state-locked .slot-check {
  background: var(--amber);
  border-color: var(--amber);
  color: #241a03;
}
.slot-card.locked-hint .slot-meta { color: var(--amber); }

/* Kategorie-Farbmarkierung in der Gesamtübersicht */
.slot-card.cat-tagged { border-left-width: 4px; }
.cat-badge {
  display: inline-block;
  width: 8px; height: 8px;
  border-radius: 50%;
  margin-right: 6px;
  flex: none;
}

/* ---------- Kalenderansicht ---------- */
.calendar {
  max-width: 640px;
  margin: 4px auto 48px;
  padding: 8px 16px 0;
}
.cal-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}
.cal-nav-btn {
  width: 36px; height: 36px;
  border-radius: 10px;
  border: 1px solid var(--pitch-line);
  background: var(--pitch-800);
  color: var(--chalk);
  font-size: 18px;
  cursor: pointer;
}
.cal-month {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 18px;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}
.cal-weekdays {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  text-align: center;
  font-size: 11px;
  color: var(--chalk-dim);
  margin-bottom: 4px;
}
.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
}
.cal-day {
  aspect-ratio: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  font-size: 13px;
  background: var(--pitch-800);
  border: 1px solid transparent;
  cursor: default;
  color: var(--chalk-dim);
  position: relative;
}
.cal-day.in-month { color: var(--chalk); }
.cal-day.has-events { cursor: pointer; border-color: var(--pitch-line); }
.cal-day.has-events:active { transform: scale(0.95); }
.cal-day.selected { border-color: var(--amber); background: rgba(242,177,52,0.1); }
.cal-day-dot {
  width: 5px; height: 5px;
  border-radius: 50%;
  background: var(--taken);
  margin-top: 2px;
}
.cal-day.has-open .cal-day-dot { background: var(--amber); }
.cal-day.has-mine { border-color: var(--amber); }
.cal-day-list {
  margin-top: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.cal-day-list-empty {
  text-align: center;
  color: var(--chalk-dim);
  font-size: 13px;
  padding: 24px 0;
}

/* ---------- Mein Bereich ---------- */
.mine-view, .rank-view, .history-view {
  max-width: 640px;
  margin: 4px auto 48px;
  padding: 8px 16px 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.section-title {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 16px;
  text-transform: uppercase;
  color: var(--amber);
  margin: 14px 0 2px;
}
.mine-empty {
  text-align: center;
  color: var(--chalk-dim);
  font-size: 13.5px;
  padding: 32px 12px;
  background: var(--pitch-800);
  border: 1px solid var(--pitch-line);
  border-radius: var(--radius);
}

/* Ausklappbarer "Belegte Dienste"-Bereich in der Listenansicht */
.section-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  background: transparent;
  border: none;
  border-top: 1px solid var(--pitch-line);
  padding: 14px 4px 10px;
  margin-top: 8px;
  cursor: pointer;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 16px;
  text-transform: uppercase;
  color: var(--chalk-dim);
}
.section-toggle:hover { color: var(--chalk); }
.section-toggle-arrow { font-size: 13px; transition: transform 0.15s ease; }
.section-toggle-content.hidden { display: none; }

/* "+ Termin hinzufügen" Button in der Sonstiges-Kategorie */
.add-event-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 100%;
  padding: 13px;
  margin-bottom: 12px;
  border-radius: 12px;
  border: 1px dashed var(--pitch-line);
  background: transparent;
  color: var(--amber);
  font-size: 14px;
  font-weight: 600;
  font-family: var(--font-body);
  cursor: pointer;
}
.add-event-btn:hover { border-color: var(--amber); background: rgba(242,177,52,0.06); }
.mine-card {
  background: var(--pitch-800);
  border: 1px solid var(--pitch-line);
  border-radius: 12px;
  padding: 13px 14px;
}
.mine-card-title { font-size: 14px; font-weight: 600; }
.mine-card-meta { font-size: 12px; color: var(--chalk-dim); margin-top: 3px; }
.mine-card-with { font-size: 12px; color: var(--chalk-dim); margin-top: 6px; }
.mine-card-actions { display: flex; gap: 8px; margin-top: 10px; }
.chip-btn {
  font-size: 11.5px;
  font-weight: 600;
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid var(--pitch-line);
  background: var(--pitch-900);
  color: var(--chalk);
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.chip-btn:hover { border-color: var(--amber); color: var(--amber); }
.export-all-btn {
  align-self: flex-start;
  margin-top: 2px;
}

/* ---------- Rangliste ---------- */
.rank-row {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--pitch-800);
  border: 1px solid var(--pitch-line);
  border-radius: 12px;
  padding: 11px 14px;
}
.rank-row.rank-me { border-color: var(--amber); background: rgba(242,177,52,0.08); }
.rank-pos {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 18px;
  color: var(--chalk-dim);
  width: 24px;
  text-align: center;
  flex: none;
}
.rank-row:nth-child(1) .rank-pos { color: #f2c94c; }
.rank-row:nth-child(2) .rank-pos { color: #cfd8d3; }
.rank-row:nth-child(3) .rank-pos { color: #c98a4b; }
.rank-name { flex: 1; font-size: 14px; font-weight: 600; }
.rank-stats { text-align: right; font-size: 12px; color: var(--chalk-dim); }
.rank-stats b { color: var(--amber); font-size: 14px; }

/* ---------- Verlauf ---------- */
.hist-row {
  display: flex;
  gap: 10px;
  padding: 10px 4px;
  border-bottom: 1px solid var(--pitch-line);
  font-size: 13px;
}
.hist-icon { flex: none; font-size: 15px; }
.hist-text { flex: 1; line-height: 1.4; }
.hist-text b { color: var(--amber); }
.hist-time { flex: none; font-size: 11px; color: var(--chalk-dim); white-space: nowrap; }

/* ---------- Slot-Card Share-Button ---------- */
.event-head { justify-content: space-between; }
.event-head-left { display: flex; align-items: center; gap: 8px; }
.share-btn {
  flex: none;
  background: transparent;
  border: none;
  color: var(--chalk-dim);
  cursor: pointer;
  padding: 4px 6px;
  display: flex;
  align-items: center;
}
.share-btn svg { display: block; }
.wa-icon { width: 18px; height: 18px; display: block; border-radius: 50%; }
.chip-btn .wa-icon { width: 15px; height: 15px; }
.share-btn:hover { opacity: 0.8; }

/* Kalender: mehrere Kategorie-Punkte in der Gesamtübersicht */
.cal-day-dots { display: flex; gap: 2px; margin-top: 2px; }
.cal-day-dots .cal-day-dot { margin-top: 0; }

/* ---------- Bestätigungs-Modal ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(4, 12, 8, 0.72);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 100;
  backdrop-filter: blur(2px);
}
@media (min-width: 480px) {
  .modal-overlay { align-items: center; }
}
.modal-card {
  width: 100%;
  max-width: 420px;
  background: var(--pitch-800);
  border: 1px solid var(--pitch-line);
  border-radius: 18px 18px 0 0;
  padding: 22px 20px 24px;
}
@media (min-width: 480px) {
  .modal-card { border-radius: 18px; }
}
.modal-title {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 19px;
  text-transform: uppercase;
  margin-bottom: 10px;
}
.modal-body {
  font-size: 14px;
  line-height: 1.6;
  color: var(--chalk-dim);
  margin-bottom: 20px;
}
.modal-body b { color: var(--chalk); }
.modal-actions {
  display: flex;
  gap: 10px;
}
.modal-actions .chip-btn {
  flex: 1;
  justify-content: center;
  padding: 12px;
  font-size: 13.5px;
}
.modal-confirm-btn {
  flex: 1.4;
  width: auto;
  padding: 12px;
}

/* Formularfelder (z.B. "Sonstiges"-Termin anlegen) */
.form-field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; text-align: left; }
.form-field label { font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--chalk-dim); }
.form-field input, .form-field select {
  padding: 10px 11px; border-radius: 8px; border: 1px solid var(--pitch-line);
  background: var(--pitch-900); color: var(--chalk); font-size: 15px; font-family: var(--font-body);
}

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  background: var(--pitch-800);
  border: 1px solid var(--pitch-line);
  color: var(--chalk);
  padding: 12px 18px;
  border-radius: 10px;
  font-size: 13.5px;
  max-width: 90%;
  text-align: center;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
  z-index: 50;
}
.toast.error { border-color: var(--danger); color: #ffd8d5; }

@media (prefers-reduced-motion: reduce) {
  .spinner { animation: none; }
}
