:root {
  --bg: #eef1f5;
  --surface: #ffffff;
  --text: #17222e;
  --muted: #64717f;
  --primary: #c8102e; /* SBB-nahes Rot */
  --primary-600: #a50d26;
  --primary-tint: #fdeef0;
  --correct: #1f8a4c;
  --correct-tint: #e8f5ee;
  --wrong: #c8102e;
  --gold: #e7b008;
  --silver: #aab4bf;
  --bronze: #cd8b52;
  --border: #e2e7ec;
  --shadow-sm: 0 1px 3px rgba(20, 40, 60, 0.08);
  --shadow: 0 6px 22px rgba(20, 40, 60, 0.1);
  --radius: 16px;
  --radius-sm: 11px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  -webkit-text-size-adjust: 100%;
}

/* ---- Kopfzeile ---- */
.topbar {
  background: linear-gradient(135deg, #d21633 0%, var(--primary) 45%, var(--primary-600) 100%);
  color: #fff;
  padding: 0.85rem 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem 1rem;
  flex-wrap: wrap;
  box-shadow: 0 2px 10px rgba(120, 10, 25, 0.25);
}

.topbar h1 {
  margin: 0;
  font-size: 1.4rem;
  font-weight: 800;
  letter-spacing: 0.01em;
}

.tagline {
  margin: 0.1rem 0 0;
  font-size: 0.88rem;
  opacity: 0.92;
}

/* Konto-Bereich */
.account {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-wrap: wrap;
  font-size: 0.9rem;
}

.account .btn-link {
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.45);
  border-radius: 999px;
  padding: 0.32rem 0.7rem;
  font: inherit;
  font-size: 0.8rem;
  cursor: pointer;
  transition: background 0.15s;
}

@media (hover: hover) {
  .account .btn-link:hover {
    background: rgba(255, 255, 255, 0.28);
  }
}

.account-name {
  font-weight: 700;
  padding: 0.15rem 0.5rem 0.15rem 0;
}

.account-menu {
  display: flex;
  gap: 0.35rem;
  flex-wrap: wrap;
  align-items: center;
}

.login-form {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
  align-items: center;
}

.login-form input {
  border: none;
  border-radius: 999px;
  padding: 0.4rem 0.8rem;
  font: inherit;
  min-width: 180px;
}

.login-msg {
  font-size: 0.82rem;
  max-width: 320px;
  flex-basis: 100%;
}

.login-msg a {
  color: #fff;
  text-decoration: underline;
  word-break: break-all;
}

/* ---- Layout ---- */
#app {
  flex: 1;
  width: 100%;
  max-width: 1100px;
  margin: 0 auto;
  padding: 1.25rem;
}

.screen.hidden,
.hidden {
  display: none !important;
}

.card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.6rem;
  max-width: 520px;
  margin: 1.25rem auto;
}

.card--wide {
  max-width: 680px;
}

.card h2 {
  margin: 0 0 1rem;
  font-size: 1.35rem;
}

.hint {
  color: var(--muted);
  font-size: 0.82rem;
  margin: 1rem 0 0;
}

/* ---- Buttons ---- */
.btn {
  font: inherit;
  font-weight: 600;
  border: none;
  border-radius: var(--radius-sm);
  padding: 0.75rem 1.2rem;
  cursor: pointer;
  background: #eef1f5;
  color: var(--text);
  transition: transform 0.05s ease, background 0.15s ease, box-shadow 0.15s ease;
}

/* Link-Buttons (<a class="btn">) im Fliesstext: als Block-Box darstellen, sonst
   „blutet" die vertikale Polsterung in die Zeile darüber (Überlappung). */
a.btn {
  display: inline-block;
  text-decoration: none;
}

@media (hover: hover) {
  .btn:hover {
    background: #e4e9ef;
  }
}

.btn:active {
  transform: translateY(1px);
}

.btn--primary {
  background: var(--primary);
  color: #fff;
  box-shadow: 0 3px 10px rgba(200, 16, 46, 0.28);
}

@media (hover: hover) {
  .btn--primary:hover {
    background: var(--primary-600);
  }
}

.btn--danger {
  background: var(--primary-tint);
  color: var(--primary-600);
}

@media (hover: hover) {
  .btn--danger:hover {
    background: #fadfe3;
  }
}

.btn--sm {
  padding: 0.35rem 0.7rem;
  font-size: 0.82rem;
  border-radius: 8px;
  box-shadow: none;
}

.btn--link {
  background: none;
  color: var(--muted);
  padding: 0.5rem 0.2rem;
  text-decoration: underline;
  box-shadow: none;
}

@media (hover: hover) {
  .btn--link:hover {
    background: none;
    color: var(--text);
  }
}

/* ---- Menü ---- */
.menu-buttons {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  margin: 0.5rem 0 0.25rem;
}

.menu-buttons .btn {
  width: 100%;
  font-size: 1.05rem;
  padding: 0.95rem 1.1rem;
  text-align: center;
}

.menu-note {
  color: var(--primary);
  font-size: 0.9rem;
  min-height: 1.1rem;
  margin: 0.6rem 0 0;
}

/* ---- Spielbildschirm ---- */
.game-grid {
  display: grid;
  grid-template-columns: 340px 1fr;
  gap: 1rem;
  align-items: start;
}

.panel {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.25rem;
}

.run-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.7rem;
}

.progress {
  font-size: 0.72rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 700;
}

.timer {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  color: var(--primary);
  background: var(--primary-tint);
  border-radius: 999px;
  padding: 0.2rem 0.7rem;
  font-size: 0.95rem;
}

.question-title {
  font-size: 1.1rem;
  margin: 0 0 1rem;
}

.options {
  list-style: none;
  margin: 0 0 0.6rem;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.option {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  text-align: left;
  width: 100%;
  min-height: 3rem;
  border: 1.5px solid var(--border);
  background: #fff;
  border-radius: var(--radius-sm);
  padding: 0.7rem 0.95rem;
  cursor: pointer;
  font: inherit;
  font-size: 1rem;
  color: var(--text);
  transition: border-color 0.12s, background 0.12s, transform 0.05s;
}

/* Hover nur auf Geräten mit echtem Zeiger. Auf Touch-Geräten „klebt" der Hover
   sonst nach dem Antippen an der zuletzt getippten Stelle – dadurch blieb die
   rote Umrandung beim Wechsel zur nächsten Frage sichtbar. */
@media (hover: hover) {
  .option:hover:not(:disabled) {
    border-color: var(--primary);
    background: #fff7f8;
  }
}

.option:active:not(:disabled) {
  transform: translateY(1px);
}

.option:disabled {
  cursor: default;
}

.option-op {
  color: var(--muted);
  font-size: 0.8em;
  white-space: nowrap;
  flex-shrink: 0;
}

.option--correct {
  border-color: var(--correct);
  background: var(--correct-tint);
  font-weight: 700;
}

.option--wrong {
  border-color: var(--wrong);
  background: var(--primary-tint);
}

.map-wrap {
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}

#map {
  height: 460px;
  width: 100%;
  background: #dfe4ea;
}

/* Die helle Positron-Karte ist recht blass. Nur die Kacheln etwas kräftiger
   und kontrastreicher rendern, damit Wasser, Wald und Strassen klarer werden –
   der Marker liegt in einer eigenen Ebene und bleibt unangetastet (scharf/farbig). */
.leaflet-tile-pane {
  filter: brightness(0.96) contrast(1.13) saturate(1.18);
}

/* Rote Kreuze der 4 anderen Optionen (Distraktoren) – Orientierungshilfe. */
.cross-marker {
  color: var(--wrong);
  font-weight: 900;
  font-size: 20px;
  line-height: 22px;
  text-align: center;
  /* Weisser Halo für Kontrast auf der hellen Karte. */
  text-shadow: 0 0 2px #fff, 0 0 3px #fff, 0 0 3px #fff;
}

/* ---- Ergebnis ---- */
.score-line {
  font-size: 1.1rem;
  margin: 0.4rem 0;
}

.score-line strong {
  font-variant-numeric: tabular-nums;
}

/* ---- Ranglisten ---- */
.lb-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-bottom: 1rem;
}

.lb-tab {
  border: 1.5px solid var(--border);
  background: #fff;
  border-radius: 999px;
  padding: 0.45rem 0.9rem;
  cursor: pointer;
  font: inherit;
  font-size: 0.9rem;
  color: var(--text);
  transition: background 0.12s, border-color 0.12s;
}

.lb-tab--active {
  border-color: var(--primary);
  background: var(--primary-tint);
  color: var(--primary-600);
  font-weight: 700;
}

/* Tages-Navigation der Rangliste (Vortage) */
.lb-daynav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.8rem;
  margin-bottom: 1rem;
}
.lb-day-label {
  min-width: 6.5rem;
  text-align: center;
  font-weight: 600;
}
.lb-daynav .btn {
  padding: 0.35rem 0.8rem;
  line-height: 1;
}
.lb-daynav .btn:disabled {
  opacity: 0.35;
  cursor: default;
}

#lb-content {
  overflow-x: auto;
}

/* Etwas Abstand über dem „Zurück"-Button (klebte an der Tabelle). */
#btn-lb-back {
  margin-top: 1.3rem;
}

.lb {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.95rem;
  table-layout: fixed;
}

.lb th,
.lb td {
  text-align: left;
  padding: 0.6rem 0.4rem;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.lb th:first-child,
.lb td:first-child {
  width: 2.6rem;
}

.lb td.num,
.lb th.num {
  width: 4.3rem;
}

/* Medaillen-Spalten: schmal, Symbol im Kopf → mehr Platz für den Namen.
   Kopf und Zahl zentriert, damit sie sauber untereinander stehen. */
.lb td.medal,
.lb th.medal {
  width: 2.9rem;
  text-align: center;
}
.lb th.medal {
  font-size: 1.05rem;
  letter-spacing: 0;
}

.lb-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lb th {
  color: var(--muted);
  font-weight: 700;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.lb td.num {
  font-variant-numeric: tabular-nums;
}

.lb-gap td {
  text-align: center;
  color: var(--muted);
  letter-spacing: 0.2em;
  padding: 0.2rem 0;
}

.lb tbody tr:last-child td {
  border-bottom: none;
}

.rank {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.7rem;
  height: 1.7rem;
  border-radius: 999px;
  background: #eef1f5;
  color: var(--muted);
  font-weight: 800;
  font-size: 0.82rem;
}

.rank--1 {
  background: var(--gold);
  color: #4a3800;
}
.rank--2 {
  background: var(--silver);
  color: #263038;
}
.rank--3 {
  background: var(--bronze);
  color: #3a2210;
}

.lb-me td {
  background: var(--primary-tint);
  font-weight: 700;
}

.lb-me td:first-child {
  border-left: 3px solid var(--primary);
}

/* Admin: Zwischenüberschriften */
.admin-h {
  margin: 1.4rem 0 0.6rem;
  font-size: 1rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.admin-h:first-of-type {
  margin-top: 0.4rem;
}

/* Admin: Statistik-Kacheln */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.6rem;
}
@media (min-width: 560px) {
  .stat-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}
.stat {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  padding: 0.7rem 0.8rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.stat-val {
  font-size: 1.5rem;
  font-weight: 700;
  line-height: 1.1;
}
.stat-label {
  font-size: 0.78rem;
  color: var(--muted);
}

/* Admin: Benutzerliste (mobil-freundlich) */
.admin-users {
  display: flex;
  flex-direction: column;
}

.admin-user {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.7rem 0;
  border-bottom: 1px solid var(--border);
}

.admin-user:last-child {
  border-bottom: none;
}

.admin-user-info {
  flex: 1;
  min-width: 0;
}

.admin-user-name {
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.admin-user-name em {
  color: var(--muted);
  font-style: normal;
  font-weight: 400;
  font-size: 0.85em;
}

.admin-user-meta {
  color: var(--muted);
  font-size: 0.82rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.admin-user .btn {
  flex-shrink: 0;
}

/* Einstellungen */
.settings-item {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  padding: 0.85rem 0;
  border-bottom: 1px solid var(--border);
}
.settings-item:last-of-type {
  border-bottom: none;
}
.settings-text {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}
.settings-text strong {
  font-weight: 600;
}
.settings-text span {
  color: var(--muted);
  font-size: 0.85rem;
}
.settings-toggle {
  cursor: pointer;
}
.settings-toggle input[type="checkbox"] {
  width: 1.5rem;
  height: 1.5rem;
  flex-shrink: 0;
  accent-color: var(--primary);
}
.settings-actions {
  display: flex;
  gap: 0.6rem;
  margin-top: 1.2rem;
  flex-wrap: wrap;
}

/* Modal (AGB-Zustimmung) */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(20, 40, 60, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.2rem;
}
.modal-box {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.5rem;
  max-width: 26rem;
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
}
.modal-box h2 {
  margin: 0;
}
.modal-box p {
  margin: 0;
  line-height: 1.5;
}

/* AGB-/Rechtsseite */
.legal h3 {
  margin: 1.3rem 0 0.3rem;
}
.legal p {
  margin: 0.3rem 0;
  line-height: 1.55;
}
/* Abstand vor dem „Zurück zum Spiel"-Button. */
.legal-back {
  margin-top: 2rem !important;
}

.footer {
  text-align: center;
  padding: 1rem;
  color: var(--muted);
  font-size: 0.8rem;
}

.footer a {
  color: var(--primary);
}

/* ---- Mobil ---- */
@media (max-width: 760px) {
  #app {
    padding: 0.9rem;
  }
  .card {
    padding: 1.25rem;
    margin: 0.75rem auto;
  }
  .game-grid {
    grid-template-columns: 1fr;
  }
  #map {
    height: 300px;
  }
  .topbar h1 {
    font-size: 1.25rem;
  }
}
