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

/* Ensure the hidden attribute always wins over display: flex/block/etc */
[hidden] { display: none !important; }

:root {
  --c-bg:               #F9F7F4;
  --c-card:             #FFFFFF;
  --c-text:             #1C1C1C;
  --c-text-sub:         #4B5563;
  --c-text-muted:       #9CA3AF;
  --c-border:           #E5E7EB;

  --c-navigate:         #1B4332;
  --c-navigate-text:    #FFFFFF;

  --c-visited:          #F3F4F6;
  --c-visited-text:     #374151;
  --c-visited-active:   #DCFCE7;
  --c-visited-active-text: #166534;
  --c-visited-active-border: #86EFAC;

  --c-badge-approx-bg:  #FEF3C7;
  --c-badge-approx-text:#92400E;

  --c-banner-est-bg:    #991B1B;
  --c-banner-est-text:  #FFFFFF;

  --c-error-bg:         #FEE2E2;
  --c-error-text:       #991B1B;

  --c-spinner:          #1B4332;
  --c-spinner-track:    #D1FAE5;

  --radius-card:        16px;
  --shadow-card:        0 -4px 24px rgba(0, 0, 0, 0.10), 0 -1px 4px rgba(0, 0, 0, 0.06);
}

html, body {
  height: 100%;
  background: var(--c-bg);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  color: var(--c-text);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ── Wordmark ────────────────────────────────────────────────────────────── */
.wordmark {
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 50;
  display: flex;
  flex-direction: column;
  background: rgba(255, 255, 255, 0.88);
  backdrop-filter: blur(4px);
  padding: 7px 12px 6px;
  border-radius: 10px;
  box-shadow: 0 1px 6px rgba(0, 0, 0, 0.12);
  line-height: 1;
  pointer-events: none;
}

.wordmark-name {
  font-size: 15px;
  font-weight: 700;
  color: var(--c-navigate);
  letter-spacing: -0.2px;
}

.wordmark-tagline {
  font-size: 10px;
  color: var(--c-text-sub);
  margin-top: 2px;
  letter-spacing: 0.2px;
  text-transform: uppercase;
  font-weight: 500;
}

/* ── Map ─────────────────────────────────────────────────────────────────── */
#map {
  position: fixed;
  inset: 0;
  z-index: 1;
}

/* Custom Leaflet pin marker */
.painting-marker-icon {
  width: 44px !important;
  height: 44px !important;
  margin-left: -22px !important;
  margin-top: -38px !important;
  display: flex;
  align-items: center;
  justify-content: center;
}

.painting-pin {
  width: 28px;
  height: 28px;
  background: var(--c-navigate);
  border: 2.5px solid #FFFFFF;
  border-radius: 50% 50% 50% 0;
  transform: rotate(-45deg);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
  transition: transform 0.15s ease;
}

.painting-marker-icon:hover .painting-pin,
.painting-marker-icon:focus .painting-pin {
  transform: rotate(-45deg) scale(1.15);
}

/* ── Loading overlay ─────────────────────────────────────────────────────── */
.loading-overlay {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 100;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  background: rgba(255, 255, 255, 0.94);
  padding: 20px 28px;
  border-radius: 14px;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.12);
  backdrop-filter: blur(4px);
}

.loading-overlay p {
  font-size: 14px;
  color: var(--c-text-sub);
  white-space: nowrap;
}

.loading-spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--c-spinner-track);
  border-top-color: var(--c-spinner);
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
}

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

/* ── Error banner ────────────────────────────────────────────────────────── */
.error-banner {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 200;
  background: var(--c-error-bg);
  color: var(--c-error-text);
  text-align: center;
  padding: 12px 16px;
  font-size: 14px;
  font-weight: 500;
  line-height: 1.4;
}

/* ── Empty state ─────────────────────────────────────────────────────────── */
.empty-state {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 100;
  background: rgba(255, 255, 255, 0.94);
  padding: 20px 28px;
  border-radius: 14px;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.12);
  font-size: 15px;
  color: var(--c-text-sub);
  backdrop-filter: blur(4px);
}

/* ── Detail card (bottom sheet) ──────────────────────────────────────────── */
.detail-card {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 300;
  background: var(--c-card);
  border-radius: var(--radius-card) var(--radius-card) 0 0;
  box-shadow: var(--shadow-card);
  max-height: 88vh;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  transform: translateY(100%);
  transition: transform 0.3s cubic-bezier(0.32, 0.72, 0, 1);
}

.detail-card.visible {
  transform: translateY(0);
}

/* On wider screens, float as a bottom-right panel */
@media (min-width: 600px) {
  .detail-card {
    left: auto;
    right: 16px;
    bottom: 16px;
    width: 400px;
    border-radius: var(--radius-card);
    max-height: 82vh;
    transform: translateY(calc(100% + 32px));
  }

  .detail-card.visible {
    transform: translateY(0);
  }

  .card-drag-handle {
    display: none;
  }
}

.card-drag-handle {
  width: 40px;
  height: 4px;
  background: #D1D5DB;
  border-radius: 2px;
  margin: 10px auto 0;
  flex-shrink: 0;
}

.card-close {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 30px;
  height: 30px;
  border: none;
  background: #F3F4F6;
  border-radius: 50%;
  cursor: pointer;
  font-size: 13px;
  color: var(--c-text-sub);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  line-height: 1;
}

.card-close:hover {
  background: #E5E7EB;
}

.card-content {
  padding-bottom: 36px;
}

/* ── Card image ──────────────────────────────────────────────────────────── */
.card-image-wrap {
  width: 100%;
  height: 220px;
  overflow: hidden;
  background: #F3F4F6;
  margin-top: 8px;
}

.card-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.card-image-placeholder {
  width: 100%;
  height: 100%;
  background: #E5E7EB;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  text-align: center;
  color: var(--c-text-muted);
  font-size: 14px;
  font-style: italic;
}

/* ── Card text sections ──────────────────────────────────────────────────── */
.card-attribution {
  font-size: 12px;
  color: var(--c-text-muted);
  padding: 8px 16px 0;
  font-style: italic;
}

.card-identifiers {
  padding: 12px 16px 0;
}

.card-title {
  font-size: 20px;
  font-weight: 700;
  line-height: 1.2;
  color: var(--c-text);
}

.card-artist-year {
  font-size: 14px;
  color: var(--c-text-sub);
  margin-top: 3px;
}

/* ── coord_accuracy indicators ───────────────────────────────────────────── */
.card-accuracy-wrap {
  /* Padding set dynamically in app.js based on accuracy type */
}

.badge-approximate {
  display: inline-block;
  background: var(--c-badge-approx-bg);
  color: var(--c-badge-approx-text);
  font-size: 12px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 20px;
  line-height: 1;
}

.banner-estimated {
  display: block;
  background: var(--c-banner-est-bg);
  color: var(--c-banner-est-text);
  font-size: 13px;
  font-weight: 600;
  text-align: center;
  padding: 10px 16px;
  line-height: 1.4;
}

/* ── Trail info ──────────────────────────────────────────────────────────── */
.card-trail {
  margin: 12px 16px 0;
  padding: 12px 14px;
  background: #F0FDF4;
  border: 1.5px solid #BBF7D0;
  border-radius: 10px;
}

.trail-header {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.trail-icon {
  font-size: 15px;
  flex-shrink: 0;
}

.trail-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--c-text);
  flex: 1;
  min-width: 0;
}

.trail-difficulty-badge {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 20px;
  white-space: nowrap;
  text-transform: capitalize;
  flex-shrink: 0;
}

.trail-difficulty-badge.easy {
  background: #DCFCE7;
  color: #166534;
}

.trail-difficulty-badge.moderate {
  background: #DBEAFE;
  color: #1E40AF;
}

.trail-difficulty-badge.hard {
  background: #FEF3C7;
  color: #92400E;
}

.trail-meta {
  margin-top: 5px;
}

.trail-stats {
  font-size: 13px;
  color: var(--c-text-sub);
}

.trail-alltrails-link {
  display: inline-block;
  margin-top: 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--c-navigate);
  text-decoration: none;
  border-bottom: 1px solid currentColor;
  line-height: 1;
}

/* ── Waypoint note ───────────────────────────────────────────────────────── */
.card-waypoint-note {
  margin: 10px 16px 0;
  padding: 10px 12px;
  font-size: 13px;
  color: #374151;
  background: #F9FAFB;
  border-left: 3px solid #9CA3AF;
  border-radius: 0 6px 6px 0;
  line-height: 1.5;
}

/* ── Historical note ─────────────────────────────────────────────────────── */
.card-historical-note {
  padding: 10px 16px 0;
  font-size: 14px;
  color: var(--c-text-sub);
  line-height: 1.55;
}

/* ── Navigate button (primary CTA) ──────────────────────────────────────── */
.btn-navigate {
  display: block;
  width: calc(100% - 32px);
  margin: 16px 16px 0;
  min-height: 56px;
  background: var(--c-navigate);
  color: var(--c-navigate-text);
  border: none;
  border-radius: 12px;
  font-size: 17px;
  font-weight: 600;
  cursor: pointer;
  letter-spacing: 0.2px;
  /* WCAG 2.1 AA: #1B4332 on white = 9.1:1 contrast */
  transition: opacity 0.1s;
}

.btn-navigate:active {
  opacity: 0.88;
}

/* ── Visited toggle ──────────────────────────────────────────────────────── */
.btn-visited {
  display: block;
  width: calc(100% - 32px);
  margin: 10px 16px 0;
  min-height: 44px;
  background: var(--c-visited);
  color: var(--c-visited-text);
  border: 1.5px solid var(--c-border);
  border-radius: 12px;
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.btn-visited[aria-pressed="true"] {
  background: var(--c-visited-active);
  color: var(--c-visited-active-text);
  border-color: var(--c-visited-active-border);
}

/* ── Footer ──────────────────────────────────────────────────────────────── */
.site-footer {
  position: fixed;
  bottom: 12px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 50;
  pointer-events: none;
  white-space: nowrap;
}

.feedback-link {
  pointer-events: all;
  font-size: 12px;
  color: #374151;
  text-decoration: underline;
  background: rgba(255, 255, 255, 0.88);
  padding: 5px 12px;
  border-radius: 20px;
  box-shadow: 0 1px 6px rgba(0, 0, 0, 0.12);
  backdrop-filter: blur(4px);
}

/* ── Dialog overlay ──────────────────────────────────────────────────────── */
.dialog-overlay {
  position: fixed;
  inset: 0;
  z-index: 500;
  background: rgba(0, 0, 0, 0.50);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.dialog-box {
  background: var(--c-card);
  border-radius: 16px;
  padding: 24px;
  width: 100%;
  max-width: 340px;
  text-align: center;
}

.dialog-message {
  font-size: 15px;
  line-height: 1.5;
  color: var(--c-text);
  margin-bottom: 20px;
}

.dialog-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.btn-dialog-primary {
  min-height: 48px;
  background: var(--c-navigate);
  color: #FFFFFF;
  border: none;
  border-radius: 10px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
}

.btn-dialog-cancel {
  min-height: 44px;
  background: transparent;
  color: var(--c-text-sub);
  border: none;
  font-size: 15px;
  cursor: pointer;
}

/* ── In-app browser fallback coords ─────────────────────────────────────── */
.fallback-coords {
  font-family: 'SF Mono', 'Fira Code', 'Fira Mono', Menlo, monospace;
  font-size: 13px;
  background: #F3F4F6;
  padding: 12px 14px;
  border-radius: 8px;
  margin-bottom: 14px;
  word-break: break-all;
  color: var(--c-text);
  text-align: left;
  user-select: all;
}

.btn-copy-coords {
  display: block;
  width: 100%;
  min-height: 44px;
  background: var(--c-navigate);
  color: #FFFFFF;
  border: none;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  margin-bottom: 8px;
}
