/* Fahrrad-App – bewusst schlicht: Schwarz/Weiß, eine Akzentfarbe für Track und Position. */

:root {
  --bg: #ffffff;
  --surface: #f2f2f5;
  --text: #0b0b0c;
  --muted: #6b6b73;
  --line: #e2e2e7;
  --accent: #2563eb;
  --danger: #d0281b;
  --ok: #16a34a;
  --warn: #d97706;
  --btn-bg: #0b0b0c;
  --btn-text: #ffffff;
  --shadow: 0 1px 3px rgb(0 0 0 / 0.12);
  --radius: 14px;
  --map-filter: none;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    --bg: #000000;
    --surface: #161618;
    --text: #f5f5f7;
    --muted: #9b9ba3;
    --line: #2a2a2f;
    --accent: #5b93ff;
    --danger: #ff5a4e;
    --ok: #34c759;
    --warn: #ffb020;
    --btn-bg: #f5f5f7;
    --btn-text: #000000;
    --shadow: 0 1px 3px rgb(0 0 0 / 0.6);
    --map-filter: invert(1) hue-rotate(180deg) brightness(0.95) contrast(0.9);
    color-scheme: dark;
  }
}

:root[data-theme='dark'] {
  --bg: #000000;
  --surface: #161618;
  --text: #f5f5f7;
  --muted: #9b9ba3;
  --line: #2a2a2f;
  --accent: #5b93ff;
  --danger: #ff5a4e;
  --ok: #34c759;
  --warn: #ffb020;
  --btn-bg: #f5f5f7;
  --btn-text: #000000;
  --shadow: 0 1px 3px rgb(0 0 0 / 0.6);
  --map-filter: invert(1) hue-rotate(180deg) brightness(0.95) contrast(0.9);
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Helvetica Neue', Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
}

body {
  overflow: hidden;
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
}

/* --- Hauptansicht ---------------------------------------------------------- */

.app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  padding: env(safe-area-inset-top) max(16px, env(safe-area-inset-right))
    env(safe-area-inset-bottom) max(16px, env(safe-area-inset-left));
}

.bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 52px;
}

.status {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-width: 0;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border-radius: 999px;
  background: var(--surface);
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
  white-space: nowrap;
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted);
  flex: none;
}

.pill[data-level='good'] .dot {
  background: var(--ok);
}
.pill[data-level='warn'] .dot {
  background: var(--warn);
}
.pill[data-level='bad'] .dot {
  background: var(--danger);
}

.bar-actions {
  display: flex;
  gap: 4px;
  flex: none;
}

.icon-btn {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 50%;
  background: transparent;
}

.icon-btn:active {
  background: var(--surface);
}

.icon-btn svg {
  width: 24px;
  height: 24px;
}

.speed {
  text-align: center;
  padding: 4px 0 6px;
}

.speed-value {
  font-size: clamp(88px, 30vw, 132px);
  font-weight: 700;
  line-height: 0.95;
  letter-spacing: -0.04em;
  font-variant-numeric: tabular-nums;
}

.speed-dec {
  font-size: 0.42em;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--muted);
}

.speed-unit {
  margin-top: 2px;
  font-size: 17px;
  font-weight: 600;
  color: var(--muted);
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
}

.badge {
  padding: 2px 8px;
  border-radius: 6px;
  background: var(--text);
  color: var(--bg);
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  margin-bottom: 12px;
}

.stat {
  padding: 10px 4px 12px;
  text-align: center;
}

.stat + .stat {
  border-left: 1px solid var(--line);
}

.stat-label {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.stat-value {
  margin-top: 2px;
  font-size: 28px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
  white-space: nowrap;
}

.stat-value small {
  margin-left: 3px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: 0;
}

.map-wrap {
  position: relative;
  flex: 1;
  min-height: 140px;
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--surface);
}

.map {
  position: absolute;
  inset: 0;
}

.map-btn {
  position: absolute;
  right: 10px;
  bottom: 10px;
  z-index: 500;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 40px;
  padding: 0 14px;
  border: 0;
  border-radius: 999px;
  background: var(--bg);
  box-shadow: var(--shadow);
  font-size: 15px;
  font-weight: 600;
}

.map-btn svg {
  width: 18px;
  height: 18px;
}

.controls {
  display: flex;
  gap: 10px;
  padding: 12px 0 10px;
}

.btn {
  flex: 1;
  height: 64px;
  border: 0;
  border-radius: var(--radius);
  background: var(--surface);
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 0.01em;
}

.btn.primary {
  background: var(--btn-bg);
  color: var(--btn-text);
}

.btn.danger {
  color: var(--danger);
}

.btn:active {
  opacity: 0.7;
}

/* --- Leaflet --------------------------------------------------------------- */

.leaflet-container {
  background: var(--surface);
  font: inherit;
}

.leaflet-tile-pane {
  filter: var(--map-filter);
}

.leaflet-control-attribution {
  font-size: 10px;
  background: color-mix(in srgb, var(--bg) 75%, transparent) !important;
  color: var(--muted);
}

.leaflet-control-attribution a {
  color: inherit;
}

.leaflet-bar a,
.leaflet-bar a:hover {
  background: var(--bg);
  color: var(--text);
  border-bottom-color: var(--line);
}

/* --- Sheets (Fahrtenliste, Details) --------------------------------------- */

.sheet {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  padding-top: env(safe-area-inset-top);
  animation: slide-up 0.22s ease-out;
}

@keyframes slide-up {
  from {
    transform: translateY(24px);
    opacity: 0;
  }
}

.sheet-bar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  min-height: 52px;
  padding: 0 max(8px, env(safe-area-inset-right)) 0 max(8px, env(safe-area-inset-left));
  border-bottom: 1px solid var(--line);
}

.sheet-bar h1 {
  grid-column: 2;
  margin: 0;
  font-size: 17px;
  font-weight: 600;
}

#rides .sheet-bar .text-btn {
  grid-column: 3;
  justify-self: end;
}

.text-btn {
  min-height: 44px;
  padding: 0 8px;
  border: 0;
  background: transparent;
  color: var(--accent);
  font-size: 17px;
  font-weight: 600;
}

.text-btn.back {
  justify-self: start;
}

.sheet-body {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 0 max(16px, env(safe-area-inset-right)) calc(24px + env(safe-area-inset-bottom))
    max(16px, env(safe-area-inset-left));
}

.ride-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.ride-list li + li {
  border-top: 1px solid var(--line);
}

.ride-item {
  display: flex;
  align-items: center;
  width: 100%;
  gap: 12px;
  padding: 14px 0;
  border: 0;
  background: transparent;
  text-align: left;
}

.ride-item .ride-main {
  flex: 1;
  min-width: 0;
}

.ride-date {
  font-size: 16px;
  font-weight: 600;
}

.ride-meta {
  margin-top: 3px;
  font-size: 15px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.ride-km {
  font-size: 22px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.ride-km small {
  font-size: 13px;
  color: var(--muted);
  margin-left: 2px;
}

.chevron {
  color: var(--muted);
  font-size: 22px;
}

.empty,
.version {
  text-align: center;
  color: var(--muted);
}

.empty {
  margin-top: 48px;
  font-size: 16px;
}

.version {
  margin-top: 32px;
  font-size: 12px;
}

.detail-map {
  height: 42vh;
  margin: 16px 0;
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--surface);
}

.detail-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0;
  margin: 0;
  border-top: 1px solid var(--line);
}

.detail-stats div {
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}

.detail-stats div:nth-child(odd) {
  padding-right: 12px;
}

.detail-stats div:nth-child(even) {
  padding-left: 12px;
  border-left: 1px solid var(--line);
}

.detail-stats dt {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.detail-stats dd {
  margin: 2px 0 0;
  font-size: 22px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.detail-actions {
  display: grid;
  gap: 10px;
  margin-top: 20px;
}

.detail-actions .btn {
  height: 56px;
  font-size: 17px;
}

/* --- Dialog & Toast -------------------------------------------------------- */

.dialog {
  width: min(340px, calc(100vw - 48px));
  padding: 20px;
  border: 0;
  border-radius: 18px;
  background: var(--bg);
  color: var(--text);
  box-shadow: 0 10px 40px rgb(0 0 0 / 0.3);
}

.dialog::backdrop {
  background: rgb(0 0 0 / 0.45);
}

.dialog h2 {
  margin: 0 0 6px;
  font-size: 19px;
}

.dialog p {
  margin: 0 0 18px;
  color: var(--muted);
  font-size: 15px;
  line-height: 1.4;
}

.dialog-buttons {
  display: grid;
  gap: 8px;
}

.dialog-buttons .btn {
  height: 52px;
  font-size: 17px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(96px + env(safe-area-inset-bottom));
  z-index: 2000;
  max-width: calc(100vw - 32px);
  padding: 10px 16px;
  border-radius: 12px;
  background: var(--text);
  color: var(--bg);
  font-size: 15px;
  font-weight: 600;
  transform: translate(-50%, 12px);
  opacity: 0;
  pointer-events: none;
  transition:
    opacity 0.2s,
    transform 0.2s;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* Sehr niedrige Displays (z. B. Querformat): Karte nicht völlig zerdrücken. */
@media (max-height: 560px) {
  .speed-value {
    font-size: 72px;
  }
  .btn {
    height: 52px;
  }
}

/* --- Start-Overlay ------------------------------------------------------------ */

.ready {
  position: fixed;
  inset: 0;
  z-index: 1500;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  width: 100%;
  padding: calc(24px + env(safe-area-inset-top)) 32px calc(24px + env(safe-area-inset-bottom));
  border: 0;
  background: color-mix(in srgb, var(--bg) 94%, transparent);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  text-align: center;
  cursor: pointer;
  -webkit-user-select: none;
  user-select: none;
  animation: fade-in 0.2s ease-out;
}

@keyframes fade-in {
  from {
    opacity: 0;
  }
}

.ready-icon {
  width: 96px;
  height: 96px;
  margin-bottom: 4px;
}

.ready-title {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.ready-text {
  max-width: 300px;
  font-size: 17px;
  line-height: 1.4;
  color: var(--muted);
}

.ready-cta {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-top: 20px;
  width: min(100%, 320px);
  height: 64px;
  border-radius: var(--radius);
  background: var(--btn-bg);
  color: var(--btn-text);
  font-size: 20px;
  font-weight: 700;
}

.ready-skip {
  margin-top: 4px;
  color: var(--muted);
  font-weight: 500;
}
