/* ── Reset & Base ── */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --bg: #000000;
  --bg-card: #1F1F1F;
  --bg-surface: #121212;
  --text: #FFFFFF;
  --text-secondary: #C9C9C9;
  --accent: #7CE897;
  --tab-height: 56px;
  --header-height: 52px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);

  /* Difficulty colors */
  --diff-1: #1E90FF;
  --diff-2: #32CD32;
  --diff-3: #FDD835;
  --diff-4: #FFA726;
  --diff-5: #EF5350;
  --diff-6: #BA55D3;
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}

/* ── Header ── */
#app-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--header-height);
  background: var(--bg-surface);
  display: flex;
  align-items: center;
  padding: 0 12px;
  z-index: 100;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}

#header-title {
  flex: 1;
  text-align: center;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 0.5px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.header-logo {
  height: 22px;
  width: auto;
}

.header-btn {
  background: none;
  border: none;
  color: var(--accent);
  cursor: pointer;
  padding: 6px;
  display: flex;
  align-items: center;
  width: 36px;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

a.header-app-btn {
  padding: 5px 12px;
  background: var(--accent) !important;
  color: #000 !important;
  -webkit-text-fill-color: #000 !important;
  border-radius: 14px;
  font-size: 12px;
  font-weight: 700;
  text-decoration: none !important;
  white-space: nowrap;
  -webkit-appearance: none;
  display: inline-block;
}

.header-spacer {
  width: 36px;
}

/* ── Main Content ── */
#app-content {
  position: fixed;
  top: var(--header-height);
  left: 0;
  right: 0;
  bottom: calc(var(--tab-height) + var(--safe-bottom));
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
}

.view {
  min-height: 100%;
}

.hidden {
  display: none !important;
}

/* ── Loading ── */
#loading-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  transition: opacity 0.3s;
}

#loading-overlay.fade-out {
  opacity: 0;
  pointer-events: none;
}

.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid rgba(255,255,255,0.1);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

#loading-overlay p {
  margin-top: 16px;
  color: var(--text-secondary);
  font-size: 14px;
}

/* ── Tab Bar ── */
#tab-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: calc(var(--tab-height) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: var(--bg-surface);
  display: flex;
  border-top: 1px solid rgba(255,255,255,0.06);
  z-index: 100;
}

.tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 11px;
  cursor: pointer;
  transition: color 0.2s;
}

.tab.active {
  color: var(--accent);
}

.tab-logo {
  height: 20px !important;
  width: 20px !important;
  max-height: 20px;
  max-width: 20px;
  object-fit: contain;
  opacity: 0.4;
  filter: grayscale(1) brightness(1.5);
  flex-shrink: 0;
}

.tab.active .tab-logo {
  opacity: 1;
  filter: none;
}

/* ── iOS Banner ── */
#trip-detail > .ios-banner {
  margin-top: 16px;
}

.ios-banner {
  margin: 0 16px 20px;
  padding: 14px 16px;
  background: var(--bg-card);
  border-radius: 14px;
  border: 1px solid rgba(124, 232, 151, 0.2);
  display: flex;
  align-items: center;
  gap: 14px;
}

.ios-banner-text {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.ios-banner-text strong {
  font-size: 15px;
  color: var(--accent);
}

.ios-banner-text span {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.4;
}

.ios-banner-btn {
  flex-shrink: 0;
  padding: 8px 16px;
  background: var(--accent);
  color: #000;
  -webkit-text-fill-color: #000;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 700;
  text-decoration: none;
  white-space: nowrap;
}

/* ── Explore Sections ── */
#explore-sections {
  padding: 16px 0 24px;
}

.explore-section {
  margin-bottom: 28px;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px 12px;
}

.section-title {
  font-size: 20px;
  font-weight: 700;
}

.section-see-all {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 14px;
  cursor: pointer;
}

/* Horizontal scroll row */
.trip-row {
  display: flex;
  gap: 12px;
  overflow-x: auto;
  padding: 0 16px;
  scroll-padding-left: 16px;
  scroll-snap-type: x proximity;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

.trip-row::-webkit-scrollbar {
  display: none;
}

/* ── Trip Card ── */
.trip-card {
  flex: 0 0 200px;
  scroll-snap-align: start;
  border-radius: 14px;
  overflow: hidden;
  background: var(--bg-card);
  cursor: pointer;
  transition: transform 0.15s;
  position: relative;
}

.trip-card:active {
  transform: scale(0.97);
}

.trip-card-img-wrap {
  width: 100%;
  aspect-ratio: 4/3;
  background: var(--bg-surface);
  overflow: hidden;
}

.trip-card-img-wrap img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: opacity 0.3s;
}

.trip-card-img-wrap img[src=""] {
  opacity: 0;
}

.trip-card-body {
  padding: 10px 10px 12px;
}

.trip-card-title {
  font-size: 13px;
  font-weight: 600;
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.trip-card-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 6px;
}

.difficulty-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.trip-card-distance {
  font-size: 12px;
  color: var(--text-secondary);
}

/* ── Trip Grid (for collection detail and explore sections) ── */
.trip-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  padding: 0 16px 24px;
}

.trip-grid .trip-card {
  flex: none;
}

/* ── Collection Card ── */
.collection-card {
  flex: 0 0 200px;
  scroll-snap-align: start;
  border-radius: 14px;
  overflow: hidden;
  background: var(--bg-card);
  cursor: pointer;
  transition: transform 0.15s;
  padding: 20px 16px;
  display: flex;
  align-items: flex-end;
  min-height: 100px;
  position: relative;
}

.collection-card:active {
  transform: scale(0.97);
}

.collection-card-title {
  font-size: 16px;
  font-weight: 700;
}

.collection-card-count {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 4px;
}

/* ── Trip Detail ── */
#trip-detail {
  padding-bottom: 32px;
}

.trip-detail-layout {
  display: flex;
  flex-direction: column;
}

.trip-hero {
  width: 100%;
  aspect-ratio: 2/1;
  background: var(--bg-surface);
  overflow: hidden;
}

.trip-hero img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.trip-info {
  padding: 20px 16px;
}

.trip-info h2 {
  font-size: 24px;
  font-weight: 800;
  line-height: 1.2;
  margin-bottom: 12px;
}

.trip-badges {
  display: flex;
  gap: 10px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 20px;
  background: var(--bg-surface);
  font-size: 13px;
  font-weight: 600;
}

.trip-description {
  font-size: 15px;
  line-height: 1.6;
  color: var(--text-secondary);
  margin-bottom: 20px;
}

.trip-description p {
  margin-bottom: 12px;
}

.trip-description p:last-child {
  margin-bottom: 0;
}

.trip-link {
  color: var(--accent);
  text-decoration: none;
  word-break: break-all;
}

.trip-link:hover {
  text-decoration: underline;
}

.trip-route-map {
  width: 100%;
  height: 280px;
  border-radius: 14px;
  overflow: hidden;
  margin-top: 16px;
}

/* ── Map View ── */
#view-map {
  position: absolute;
  inset: 0;
}

#map-app-banner {
  position: absolute;
  bottom: 12px;
  left: 0;
  right: 0;
  z-index: 1000;
}

#map-app-banner .ios-banner {
  margin: 0 12px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.4);
}

#map-container {
  width: 100%;
  height: 100%;
}

.gooff-pin {
  background: none !important;
  border: none !important;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.3));
}

/* Leaflet popup overrides */
.leaflet-popup-content-wrapper {
  background: var(--bg-card);
  color: var(--text);
  border-radius: 12px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.4);
}

.leaflet-popup-tip {
  background: var(--bg-card);
}

.leaflet-popup-content {
  margin: 10px 14px;
  font-size: 14px;
  line-height: 1.4;
}

.map-popup-title {
  font-weight: 700;
  font-size: 14px;
  margin-bottom: 4px;
}

.map-popup-distance {
  font-size: 12px;
  color: var(--text-secondary);
}

.map-popup-link {
  display: inline-block;
  margin-top: 8px;
  color: var(--accent);
  text-decoration: none;
  font-size: 13px;
  font-weight: 600;
}

/* ── Collection Detail ── */
#view-collection {
  padding: 16px 0;
}

#collection-title {
  font-size: 22px;
  font-weight: 800;
  padding: 0 16px 16px;
}

/* ── Responsive ── */
@media (min-width: 480px) {
  .trip-grid {
    grid-template-columns: repeat(3, 1fr);
  }
  .trip-card {
    flex: 0 0 220px;
  }
}

@media (min-width: 768px) {
  .trip-grid {
    grid-template-columns: repeat(4, 1fr);
    max-width: 900px;
    margin: 0 auto;
  }
  .trip-card {
    flex: 0 0 240px;
  }
  .trip-detail-layout {
    flex-direction: row;
    max-width: 1100px;
    margin: 0 auto;
    padding: 24px;
    gap: 32px;
  }
  .trip-hero {
    flex: 0 0 45%;
    aspect-ratio: 3/4;
    border-radius: 14px;
    max-height: 500px;
  }
  .trip-info {
    flex: 1;
    padding: 0;
  }
  .trip-route-map {
    height: 380px;
  }
}
