/* Norseman Xtreme Triathlon — Interactive Race Map */

@font-face {
  font-family: 'Maison Mono';
  src: url('../fonts/MaisonMono-Bold.woff2') format('woff2'),
       url('../fonts/MaisonMono-Bold.woff') format('woff');
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: 'Maison Mono';
  src: url('../fonts/MaisonMono-Light.woff2') format('woff2'),
       url('../fonts/MaisonMono-Light.woff') format('woff');
  font-weight: 300;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: 'Maison Mono';
  src: url('../fonts/MaisonMono-Regular.woff2') format('woff2'),
       url('../fonts/MaisonMono-Regular.woff') format('woff');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --black: #000000;
  --white: #ffffff;
  --turquoise: #00b3ae;
  --grey: #939598;
  --dark-bg: #0a0a0a;
  --dark-surface: #111111;
  --dark-border: #1a1a1a;
}

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--black);
  color: var(--white);
  font-family: 'Maison Mono', 'SF Mono', 'Fira Code', monospace;
  font-weight: 300;
  -webkit-font-smoothing: antialiased;
}

/* Loading screen */
.loading-screen {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: var(--black);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  transition: opacity 0.6s ease, visibility 0.6s ease;
}

.loading-screen.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.loading-screen img {
  width: 60px;
  height: 60px;
  animation: pulse 2s ease-in-out infinite;
}

.loading-screen .loading-text {
  margin-top: 16px;
  font-size: 11px;
  font-weight: 300;
  letter-spacing: 2px;
  color: var(--grey);
  text-transform: uppercase;
}

@keyframes pulse {
  0%, 100% { opacity: 0.3; }
  50% { opacity: 1; }
}

/* Layout */
.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh; /* Dynamic viewport height — excludes iOS Safari chrome */
}

/* Header */
.header {
  height: 48px;
  max-height: 48px;
  background: var(--black);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 20px;
  border-bottom: 1px solid var(--dark-border);
  flex-shrink: 0;
  z-index: 10;
  overflow: hidden;
}

.header-wordmark {
  height: 14px;
  width: auto;
}

/* Map container */
.map-container {
  position: relative;
  flex: 1 1 0%;
  min-height: 200px;
  overflow: hidden;
}

#map {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
}

/* Segment pills */
.segment-pills {
  position: absolute;
  top: 16px;
  left: 16px;
  display: flex;
  gap: 6px;
  z-index: 5;
  flex-wrap: wrap;
}

.segment-pill {
  background: rgba(0, 0, 0, 0.85);
  border: 1px solid rgba(255, 255, 255, 0.3);
  color: var(--white);
  font-family: 'Maison Mono', monospace;
  font-weight: 700;
  font-size: 10px;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  padding: 6px 12px;
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
}

.segment-pill:hover {
  border-color: var(--white);
}

.segment-pill.active {
  background: var(--white);
  color: var(--black);
  border-color: var(--white);
}

.segment-pill[data-segment="swim"] {
  border-color: rgba(0, 179, 174, 0.5);
}

.segment-pill[data-segment="swim"].active {
  background: var(--turquoise);
  color: var(--black);
  border-color: var(--turquoise);
}

/* Legend control button */
.legend-ctrl {
  background: var(--turquoise) !important;
  color: var(--black) !important;
  border-color: var(--turquoise) !important;
}

.legend-ctrl .control-icon {
  color: var(--black) !important;
}

/* Legend panel */
.legend-panel {
  position: absolute;
  top: 16px;
  right: 60px;
  z-index: 5;
  background: rgba(0, 0, 0, 0.85);
  border: 1px solid rgba(255, 255, 255, 0.15);
  padding: 10px 14px;
  backdrop-filter: blur(8px);
}

.legend-panel.hidden { display: none; }

.legend-content {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.legend-filter {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 9px;
  font-weight: 300;
  color: rgba(255, 255, 255, 0.8);
  cursor: pointer;
  padding: 2px 0;
}

.legend-filter:hover { color: var(--white); }

.legend-filter.locked {
  opacity: 0.6;
  cursor: default;
}

.legend-filter input[type="checkbox"] {
  accent-color: var(--turquoise);
  width: 12px;
  height: 12px;
  flex-shrink: 0;
}

.legend-line {
  width: 24px;
  height: 6px;
  flex-shrink: 0;
}

.legend-no-support {
  background: repeating-linear-gradient(
    -45deg,
    #ff4444,
    #ff4444 3px,
    #ffffff 3px,
    #ffffff 6px
  );
  opacity: 0.8;
}

.legend-icon-sample {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #000;
  border: 2px solid var(--turquoise);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 8px;
  font-weight: 700;
  color: var(--white);
  flex-shrink: 0;
}

.legend-rec-sample {
  width: 18px;
  height: 18px;
  background: #000;
  border: 2px solid var(--turquoise);
  color: var(--white);
  font-size: 8px;
}

.legend-danger-sample {
  border-color: #ff4444;
}

.legend-finish-sample {
  background: #fff;
  border-color: #fff;
  color: #000;
}

.legend-bottom {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 8px;
  padding-top: 6px;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.legend-show-all {
  background: none;
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: var(--grey);
  font-family: 'Maison Mono', monospace;
  font-weight: 700;
  font-size: 8px;
  padding: 3px 8px;
  cursor: pointer;
  text-transform: uppercase;
}

.legend-show-all:hover { color: var(--turquoise); border-color: var(--turquoise); }

.legend-close {
  background: none;
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: var(--grey);
  font-family: 'Maison Mono', monospace;
  font-weight: 700;
  font-size: 9px;
  width: 20px;
  height: 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.legend-close:hover { color: var(--white); border-color: var(--white); }

/* Recommended Support marker (larger) */
.marker-recommended {
  width: 24px !important;
  height: 24px !important;
  border-radius: 50%;
  background: #fff !important;
  border: 3px solid var(--turquoise) !important;
  color: var(--turquoise) !important;
  font-size: 11px !important;
}

/* Coordinate overlay */
.coord-overlay {
  position: absolute;
  bottom: 16px;
  left: 16px;
  z-index: 5;
  font-size: 10px;
  font-weight: 300;
  color: rgba(255, 255, 255, 0.6);
  line-height: 1.6;
  pointer-events: none;
}

/* Elevation profile */
.elevation-container {
  height: 180px;
  background: var(--black);
  border-top: 1px solid var(--dark-border);
  position: relative;
  flex-shrink: 0;
}

.elevation-container svg {
  width: 100%;
  height: 100%;
}


.elevation-segment-labels {
  position: absolute;
  top: 8px;
  left: 16px;
  display: flex;
  gap: 16px;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  pointer-events: none;
}

.elevation-segment-labels span {
  color: var(--turquoise);
}

/* Hover stats bar */
.hover-stats {
  height: 32px;
  background: var(--black);
  border-top: 1px solid var(--dark-border);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 32px;
  flex-shrink: 0;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: -0.3px;
  text-transform: uppercase;
  color: var(--white);
  transition: opacity 0.15s ease;
}

.hover-stats:empty {
  opacity: 0.3;
}

.hover-stats .hs-label {
  font-weight: 300;
  color: var(--grey);
  font-size: 9px;
  letter-spacing: 0.5px;
  margin-right: 4px;
}

.hover-stats .hs-value {
  color: var(--turquoise);
  font-weight: 700;
}

/* Map marker styles */
.marker {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--black);
  border: 2px solid var(--white);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Maison Mono', monospace;
  font-weight: 700;
  font-size: 9px;
  color: var(--white);
  transition: transform 0.2s ease;
}

.marker:hover { transform: scale(1.3); }
.marker-circle { border-radius: 50%; }
.marker-square { border-radius: 2px; }
.marker-triangle {
  border-radius: 0;
  clip-path: polygon(50% 0%, 0% 100%, 100% 100%);
  border: none !important;
  display: flex;
  align-items: flex-end;
  padding-bottom: 1px;
}

.marker.finish-black {
  background: var(--white);
  color: var(--black);
  border-color: var(--white);
}

.marker.transition {
  border-color: var(--grey);
}

.marker.swim-marker {
  border-color: var(--turquoise);
}

/* Popup */
.mapboxgl-popup-content {
  background: var(--black) !important;
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: var(--white);
  font-family: 'Maison Mono', monospace;
  padding: 12px 16px !important;
  border-radius: 0 !important;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5) !important;
}

.mapboxgl-popup-tip {
  border-top-color: rgba(255, 255, 255, 0.2) !important;
}

.mapboxgl-popup-close-button {
  color: var(--grey) !important;
  font-size: 16px;
}

@media (pointer: coarse) {
  .mapboxgl-popup-close-button {
    color: var(--turquoise) !important;
    font-size: 22px;
    width: 28px;
    height: 28px;
    line-height: 28px;
  }
}

.popup-title {
  font-weight: 700;
  font-size: 11px;
  letter-spacing: -0.3px;
  text-transform: uppercase;
  margin-bottom: 4px;
}

.popup-location {
  font-weight: 300;
  font-size: 10px;
  color: var(--grey);
  margin-bottom: 8px;
}

.popup-data {
  font-weight: 300;
  font-size: 10px;
  line-height: 1.6;
  color: rgba(255, 255, 255, 0.7);
}

/* Map hover marker (synced with elevation profile) */
.hover-marker {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--turquoise);
  border: 2px solid var(--white);
  pointer-events: none;
  box-shadow: 0 0 12px rgba(0, 179, 174, 0.7);
}

/* User location marker (smooth GPS follow) */
.user-location-marker {
  position: relative;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--turquoise);
  border: 3px solid var(--white);
  box-shadow:
    0 0 0 4px rgba(0, 179, 174, 0.25),
    0 0 16px rgba(0, 179, 174, 0.6);
  pointer-events: none;
}
.user-location-marker::after {
  content: '';
  position: absolute;
  inset: -8px;
  border-radius: 50%;
  border: 2px solid var(--turquoise);
  opacity: 0;
  animation: locPulse 2.4s ease-out infinite;
  pointer-events: none;
}
@keyframes locPulse {
  0%   { transform: scale(0.8); opacity: 0.7; }
  100% { transform: scale(2.2); opacity: 0; }
}

.map-control-btn .control-icon-svg { display: block; margin: auto; }

/* Map controls (style toggle, fullscreen) */
.map-controls {
  position: absolute;
  bottom: 100px;
  right: 16px;
  z-index: 5;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.map-control-btn {
  width: 40px;
  height: 32px;
  background: rgba(0, 0, 0, 0.85);
  border: 1px solid var(--dark-border);
  color: var(--white);
  font-family: 'Maison Mono', monospace;
  font-weight: 700;
  font-size: 8px;
  letter-spacing: 0.3px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}

.map-control-btn:hover {
  border-color: var(--white);
  background: rgba(0, 0, 0, 0.95);
}

/* Fly-over trigger */
.fly-trigger {
  border-color: rgba(0, 179, 174, 0.5) !important;
}

.fly-trigger:hover {
  border-color: var(--turquoise) !important;
}

.fly-trigger.active {
  background: var(--turquoise) !important;
  color: var(--black) !important;
  border-color: var(--turquoise) !important;
}

.map-control-btn.fly-trigger .control-icon {
  color: var(--turquoise);
}

/* Fly-over panel */
.fly-panel {
  position: absolute;
  bottom: 16px;
  left: 16px;
  z-index: 10;
  background: rgba(0, 0, 0, 0.92);
  border: 1px solid rgba(255, 255, 255, 0.15);
  padding: 12px 16px;
  min-width: 300px;
  backdrop-filter: blur(8px);
}

.fly-panel.hidden {
  display: none;
}

.fly-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.fly-panel-title {
  font-weight: 700;
  font-size: 11px;
  letter-spacing: 0.5px;
  text-transform: uppercase;
}

.fly-panel-close {
  background: none;
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: var(--grey);
  font-family: 'Maison Mono', monospace;
  font-weight: 700;
  font-size: 10px;
  width: 24px;
  height: 24px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
}

.fly-panel-close:hover {
  color: var(--white);
  border-color: var(--white);
}

.fly-controls {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 10px;
}

.fly-btn {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: var(--white);
  font-family: 'Maison Mono', monospace;
  font-weight: 700;
  font-size: 9px;
  padding: 5px 8px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.fly-btn:hover {
  border-color: var(--white);
  background: rgba(255, 255, 255, 0.1);
}

.fly-btn-main {
  background: var(--turquoise);
  color: var(--black);
  border-color: var(--turquoise);
  padding: 5px 14px;
  font-size: 10px;
}

.fly-btn-main:hover {
  background: #00ccc7;
  border-color: #00ccc7;
}

.fly-speeds {
  display: flex;
  gap: 2px;
  margin-left: auto;
}

.fly-speed {
  background: none;
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: var(--grey);
  font-family: 'Maison Mono', monospace;
  font-weight: 400;
  font-size: 9px;
  padding: 4px 6px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.fly-speed:hover {
  color: var(--white);
  border-color: rgba(255, 255, 255, 0.3);
}

.fly-speed.active {
  color: var(--white);
  border-color: var(--turquoise);
  font-weight: 700;
}

.fly-progress-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.fly-progress {
  flex: 1;
  -webkit-appearance: none;
  appearance: none;
  height: 3px;
  background: rgba(255, 255, 255, 0.15);
  outline: none;
  cursor: pointer;
}

.fly-progress::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--white);
  cursor: pointer;
  border: none;
}

.fly-progress::-moz-range-thumb {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--white);
  cursor: pointer;
  border: none;
}

.fly-km {
  font-size: 10px;
  font-weight: 700;
  white-space: nowrap;
  min-width: 60px;
  text-align: right;
}

/* Mapbox controls styling */
.mapboxgl-ctrl-group {
  background: var(--black) !important;
  border: 1px solid var(--dark-border) !important;
  border-radius: 0 !important;
}

.mapboxgl-ctrl-group button {
  border-bottom: 1px solid var(--dark-border) !important;
}

.mapboxgl-ctrl-group button + button {
  border-top: none !important;
}

.mapboxgl-ctrl button .mapboxgl-ctrl-icon {
  filter: invert(1);
}

/* Responsive */
@media (max-width: 768px) {
  .header-title {
    font-size: 11px;
  }

  .header-subtitle {
    display: none;
  }

  .segment-pills {
    top: 12px;
    left: 12px;
    gap: 4px;
    max-width: calc(100% - 24px);
    overflow-x: auto;
    flex-wrap: nowrap;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }

  .segment-pills::-webkit-scrollbar {
    display: none;
  }

  .segment-pill {
    font-size: 9px;
    padding: 5px 8px;
    flex-shrink: 0;
  }

  .elevation-container {
    height: 120px;
    min-height: 120px;
    touch-action: none;
  }

  .elevation-segment-labels {
    font-size: 8px;
    gap: 8px;
  }

  .elevation-tooltip {
    font-size: 9px;
    top: 4px;
    right: 8px;
  }

  .hover-stats {
    gap: 12px;
    height: 28px;
    padding: 0 8px;
    font-size: 9px;
  }

  .coord-overlay {
    display: none;
  }

  .map-controls {
    bottom: 80px;
    right: 8px;
  }

  .fly-panel {
    left: 8px;
    right: 8px;
    bottom: 8px;
    min-width: auto;
  }
}

@media (max-width: 480px) {
  .header {
    height: 40px;
    padding: 0 12px;
  }

  .header-logo {
    height: 20px;
    width: 20px;
    margin-right: 8px;
  }

  .header-title {
    font-size: 10px;
  }

  .elevation-container {
    height: 100px;
    min-height: 100px;
  }

  .hover-stats {
    height: 24px;
    gap: 8px;
    font-size: 8px;
  }

  .stat {
    font-size: 8px;
  }
}

/* iOS safe area (notch) */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
  .hover-stats {
    padding-bottom: env(safe-area-inset-bottom);
  }
}
