/* Charlevoix field-test — mobile-first, wider desktop */

:root {
  --cx-bg: #eef0eb;
  --cx-surface: #ffffff;
  --cx-text: #1c1f1c;
  --cx-muted: #5f655c;
  --cx-accent: #2f5c40;
  --cx-route: #c2562a;
  --cx-cue: #1a6f8f;
  --cx-border: #e2e6df;
  --cx-banner-bg: #e8ebe4;
  --cx-banner-text: #4a5248;
  --cx-shadow: 0 1px 3px rgba(28, 36, 28, 0.06);
  --cx-radius: 12px;
  --cx-map-min-h: min(48vh, 380px);
  --cx-profile-h: 172px;
  --cx-app-pad: 0.75rem;
  --cx-max-wide: 1280px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --cx-bg: #141614;
    --cx-surface: #1e211e;
    --cx-text: #ececea;
    --cx-muted: #a3a89f;
    --cx-accent: #6db88a;
    --cx-route: #e88b55;
    --cx-cue: #5eb8d8;
    --cx-border: #2f332f;
    --cx-banner-bg: #252825;
    --cx-banner-text: #b8bdb5;
    --cx-shadow: 0 1px 4px rgba(0, 0, 0, 0.35);
  }
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  overflow-x: hidden;
}

body {
  margin: 0;
  padding: 0;
  background: var(--cx-bg);
  color: var(--cx-text);
  line-height: 1.45;
  overflow-x: hidden;
}

.cx-app {
  width: 100%;
  max-width: 100%;
  margin: 0 auto;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.cx-banner {
  background: var(--cx-banner-bg);
  color: var(--cx-banner-text);
  padding: 0.4rem var(--cx-app-pad);
  font-size: 0.72rem;
  text-align: center;
  border-bottom: 1px solid var(--cx-border);
}

.cx-card {
  background: var(--cx-surface);
  border: 1px solid var(--cx-border);
  border-radius: var(--cx-radius);
  box-shadow: var(--cx-shadow);
}

.cx-header {
  margin: var(--cx-app-pad) var(--cx-app-pad) 0;
  padding: 1rem 1.1rem 0.85rem;
  border-radius: var(--cx-radius);
}

.cx-header-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.5rem;
}

.cx-header h1 {
  margin: 0;
  font-size: 1.2rem;
  font-weight: 650;
  line-height: 1.25;
  letter-spacing: -0.02em;
  flex: 1;
  min-width: 0;
}

.cx-offline-status {
  flex-shrink: 0;
  margin: 0;
  font-size: 0.62rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 0.2rem 0.45rem;
  border-radius: 6px;
  border: 1px solid var(--cx-border);
  background: var(--cx-banner-bg);
  color: var(--cx-muted);
  max-width: 9.5rem;
  text-align: right;
  line-height: 1.25;
}

.cx-offline-status[data-mode="offline-data"],
.cx-offline-status[data-mode="offline-tiles"] {
  color: var(--cx-cue);
  border-color: color-mix(in srgb, var(--cx-cue) 35%, var(--cx-border));
}

.cx-offline-status[data-mode="online-ready"] {
  color: var(--cx-accent);
}

.cx-header-actions {
  margin: 0.4rem 0 0;
}

.cx-prepare-btn {
  font: inherit;
  font-size: 0.72rem;
  font-weight: 600;
  padding: 0.35rem 0.6rem;
  border-radius: 7px;
  border: 1px solid var(--cx-border);
  background: var(--cx-surface);
  color: var(--cx-accent);
  cursor: pointer;
}

.cx-prepare-btn:disabled {
  opacity: 0.65;
}

.cx-header-meta {
  margin: 0.35rem 0 0;
  font-size: 0.84rem;
  color: var(--cx-muted);
}

.cx-route-details {
  margin-top: 0.5rem;
  font-size: 0.78rem;
}

.cx-route-details summary {
  cursor: pointer;
  color: var(--cx-muted);
  user-select: none;
  padding: 0.15rem 0;
}

.cx-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem 0.9rem;
  margin-top: 0.45rem;
  padding-bottom: 0.35rem;
  font-size: 0.78rem;
}

.cx-stat strong {
  color: var(--cx-accent);
}

.cx-main {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  padding: 0  var(--cx-app-pad) var(--cx-app-pad);
  flex: 1;
}

.cx-map-section {
  padding: 0;
  overflow: hidden;
}

.cx-map-wrap {
  position: relative;
  height: var(--cx-map-min-h);
  min-height: 240px;
  overflow: hidden;
  border-radius: var(--cx-radius);
}

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

.cx-map-wrap.cx-map--route-only {
  background: color-mix(in srgb, var(--cx-accent) 12%, var(--cx-bg));
}

.cx-map-wrap.cx-map--route-only::after {
  content: "Route only — map tiles unavailable offline";
  position: absolute;
  left: 0.5rem;
  bottom: 2.5rem;
  z-index: 2;
  font-size: 0.65rem;
  font-weight: 600;
  color: var(--cx-muted);
  background: color-mix(in srgb, var(--cx-surface) 90%, transparent);
  padding: 0.2rem 0.45rem;
  border-radius: 4px;
  pointer-events: none;
}

.cx-gps-marker {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #2563eb;
  border: 2px solid #fff;
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.45);
}

.cx-gps-hud {
  margin: 0 0 0.35rem;
  padding: 0.3rem 0.45rem;
  border-radius: 6px;
  background: color-mix(in srgb, #2563eb 8%, var(--cx-surface));
  border: 1px solid color-mix(in srgb, #2563eb 25%, var(--cx-border));
  font-size: 0.72rem;
  line-height: 1.3;
}

.cx-gps-hud__label {
  font-weight: 700;
  color: #2563eb;
  margin-right: 0.35rem;
  text-transform: uppercase;
  font-size: 0.6rem;
  letter-spacing: 0.05em;
}

.cx-gps-error {
  margin: 0 0 0.35rem;
  font-size: 0.72rem;
  color: #a33;
}

.cx-map-controls {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  z-index: 3;
  pointer-events: none;
}

.cx-map-controls > * {
  pointer-events: auto;
}

.cx-basemap-menu {
  font-size: 0.75rem;
}

.cx-basemap-menu summary {
  list-style: none;
  cursor: pointer;
  padding: 0.35rem 0.65rem;
  border-radius: 8px;
  border: 1px solid var(--cx-border);
  background: color-mix(in srgb, var(--cx-surface) 92%, transparent);
  backdrop-filter: blur(6px);
  box-shadow: var(--cx-shadow);
  font-weight: 600;
}

.cx-basemap-menu summary::-webkit-details-marker {
  display: none;
}

.cx-basemap-menu__panel {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  margin-top: 0.3rem;
  padding: 0.4rem;
  border-radius: 8px;
  border: 1px solid var(--cx-border);
  background: var(--cx-surface);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.12);
  min-width: 9.5rem;
}

.cx-map-action-btn,
.cx-basemap-btn,
.cx-mode-btn {
  font: inherit;
  font-size: 0.75rem;
  padding: 0.4rem 0.55rem;
  border: 1px solid var(--cx-border);
  border-radius: 7px;
  background: var(--cx-surface);
  color: var(--cx-text);
  cursor: pointer;
  text-align: left;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.cx-map-action-btn:hover,
.cx-basemap-btn:hover,
.cx-mode-btn:hover {
  background: color-mix(in srgb, var(--cx-accent) 8%, var(--cx-surface));
}

.cx-map-action-btn {
  font-weight: 600;
  color: var(--cx-accent);
}

.cx-basemap-btn[aria-pressed="true"],
.cx-mode-btn[aria-pressed="true"] {
  background: var(--cx-accent);
  color: #fff;
  border-color: var(--cx-accent);
}

.cx-profile-wrap {
  padding: 0.85rem 1rem 1rem;
}

.cx-profile-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.5rem 0.75rem;
  margin-bottom: 0.5rem;
}

.cx-profile-wrap h2 {
  margin: 0;
  font-size: 0.92rem;
  font-weight: 600;
}

.cx-profile-note {
  margin: 0.15rem 0 0;
  font-size: 0.74rem;
  color: var(--cx-muted);
  max-width: 18rem;
}

.cx-profile-mode {
  display: flex;
  gap: 0.25rem;
  flex-shrink: 0;
}

.cx-mode-btn {
  text-align: center;
  padding: 0.35rem 0.5rem;
}

.cx-profile-canvas-wrap {
  position: relative;
  height: var(--cx-profile-h);
  min-height: 168px;
  border-radius: 10px;
  border: 1px solid var(--cx-border);
  background: color-mix(in srgb, var(--cx-accent) 5%, var(--cx-surface));
  touch-action: pan-y;
}

.cx-profile-canvas-wrap--dragging {
  touch-action: none;
}

#cx-profile {
  display: block;
  width: 100%;
  height: 100%;
  cursor: crosshair;
  touch-action: none;
  border-radius: 9px;
}

.cx-mission-state {
  padding: 0.55rem 0.75rem 0.6rem;
}

.cx-mission-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem;
}

.cx-mission-row--primary {
  margin-bottom: 0.35rem;
}

.cx-mission-row--grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.2rem 0.45rem;
  margin-bottom: 0.4rem;
}

.cx-mission-cell,
.cx-mission-pair {
  display: flex;
  flex-direction: column;
  gap: 0.05rem;
  min-width: 0;
}

.cx-mission-cell--end {
  align-items: flex-end;
  text-align: right;
}

.cx-mission-value {
  font-size: 1.2rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--cx-route);
  letter-spacing: -0.02em;
  line-height: 1.15;
}

.cx-mission-value--sm {
  font-size: 0.95rem;
  color: var(--cx-text);
}

.cx-mission-label {
  font-size: 0.62rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--cx-muted);
  line-height: 1.2;
}

.cx-mission-next {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.4rem 0.5rem;
  border-radius: 8px;
  background: color-mix(in srgb, var(--cx-cue) 10%, var(--cx-surface));
  border: 1px solid color-mix(in srgb, var(--cx-cue) 28%, var(--cx-border));
}

.cx-mission-next__icon {
  flex-shrink: 0;
  font-size: 0.85rem;
  color: var(--cx-cue);
  font-weight: 700;
  line-height: 1;
}

.cx-mission-next__body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.05rem;
}

.cx-mission-next__label {
  font-size: 0.6rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--cx-cue);
}

.cx-mission-next__name {
  font-size: 0.88rem;
  font-weight: 650;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.cx-mission-next__dist {
  flex-shrink: 0;
  font-size: 0.95rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--cx-cue);
}

.cx-cues-panel {
  overflow: hidden;
}

.cx-cues-panel summary {
  padding: 0.75rem 1rem;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  user-select: none;
  list-style: none;
}

.cx-cues-panel summary::-webkit-details-marker {
  display: none;
}

.cx-cues-count {
  font-weight: 500;
  color: var(--cx-muted);
}

.cx-cue-list {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 42vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  border-top: 1px solid var(--cx-border);
}

.cx-cue-item {
  display: grid;
  grid-template-columns: 3.2rem 1fr;
  gap: 0.3rem 0.55rem;
  padding: 0.55rem 1rem;
  border-top: 1px solid var(--cx-border);
  cursor: pointer;
}

.cx-cue-item:first-child {
  border-top: none;
}

.cx-cue-item:focus-visible,
.cx-cue-item.cx-cue-item--active {
  outline: none;
  background: color-mix(in srgb, var(--cx-accent) 10%, transparent);
}

.cx-cue-km {
  font-size: 0.74rem;
  font-weight: 600;
  color: var(--cx-muted);
  font-variant-numeric: tabular-nums;
}

.cx-cue-name {
  font-size: 0.88rem;
  font-weight: 500;
}

.cx-cue-type {
  grid-column: 2;
  font-size: 0.7rem;
  color: var(--cx-muted);
}

.cx-footer {
  padding: 0.75rem var(--cx-app-pad) 1.25rem;
  font-size: 0.68rem;
  color: var(--cx-muted);
  text-align: center;
}

.cx-load-error {
  padding: 1.5rem var(--cx-app-pad);
  color: #a33;
}

/* MapLibre controls — subtle */
#cx-map .maplibregl-ctrl-scale {
  margin: 0 0 0.35rem 0.35rem;
  border-radius: 4px;
  background: color-mix(in srgb, var(--cx-surface) 88%, transparent);
  border: 1px solid var(--cx-border);
  font-size: 10px;
  line-height: 1.2;
  padding: 2px 5px;
  box-shadow: var(--cx-shadow);
}

.maplibregl-ctrl-attrib {
  font-size: 9px !important;
  opacity: 0.85;
}

/* Mobile density: shorter map/profile, tighter mission card (desktop unchanged below 768px rules) */
@media (max-width: 767px) {
  :root {
    --cx-map-min-h: min(35vh, 278px);
    --cx-profile-h: 128px;
    --cx-app-pad: 0.6rem;
  }

  .cx-map-wrap {
    min-height: 188px;
  }

  .cx-profile-canvas-wrap {
    min-height: 118px;
  }

  .cx-banner {
    padding: 0.25rem var(--cx-app-pad);
    font-size: 0.65rem;
  }

  .cx-header {
    margin-top: 0.5rem;
    padding: 0.5rem 0.75rem 0.45rem;
  }

  .cx-header h1 {
    font-size: 1rem;
  }

  .cx-header-meta {
    font-size: 0.75rem;
    margin-top: 0.15rem;
  }

  .cx-route-details {
    margin-top: 0.35rem;
  }

  .cx-main {
    gap: 0.35rem;
    padding-bottom: 0.5rem;
  }

  .cx-profile-wrap {
    padding: 0.45rem 0.65rem 0.5rem;
  }

  .cx-profile-head {
    margin-bottom: 0.25rem;
    gap: 0.25rem 0.4rem;
  }

  .cx-profile-wrap h2 {
    font-size: 0.84rem;
  }

  .cx-profile-note {
    display: none;
  }

  .cx-mode-btn {
    padding: 0.3rem 0.45rem;
    font-size: 0.7rem;
  }

  .cx-mission-state {
    padding: 0.45rem 0.6rem 0.5rem;
  }

  .cx-mission-value {
    font-size: 1.05rem;
  }

  .cx-mission-row--primary {
    margin-bottom: 0.28rem;
  }

  .cx-mission-row--grid {
    margin-bottom: 0.32rem;
  }

  .cx-mission-next {
    padding: 0.32rem 0.45rem;
  }

  .cx-cues-panel summary {
    padding: 0.45rem 0.65rem;
    font-size: 0.82rem;
  }
}

@media (min-width: 768px) {
  :root {
    --cx-app-pad: 1rem;
    --cx-map-min-h: min(52vh, 520px);
    --cx-profile-h: 200px;
  }

  .cx-mission-state {
    padding: 0.85rem 1rem;
  }

  .cx-mission-value {
    font-size: 1.35rem;
  }

  .cx-mission-value--sm {
    font-size: 1rem;
  }

  .cx-mission-next__name {
    font-size: 0.92rem;
  }

  .cx-header {
    margin-top: 1rem;
  }

  .cx-main {
    gap: 0.85rem;
  }

  .cx-cues-panel[open] .cx-cue-list {
    max-height: 360px;
  }
}

@media (min-width: 1024px) {
  :root {
    --cx-map-min-h: 520px;
    --cx-profile-h: 220px;
  }

  .cx-app {
    max-width: var(--cx-max-wide);
    padding: 0 1.25rem;
  }

  .cx-banner {
    border-radius: var(--cx-radius);
    margin-top: 0.75rem;
  }

  .cx-header {
    margin-left: 0;
    margin-right: 0;
  }

  .cx-main {
    display: grid;
    grid-template-columns: minmax(0, 1.55fr) minmax(300px, 0.95fr);
    grid-template-rows: auto auto auto;
    gap: 0.85rem 1rem;
    padding-left: 0;
    padding-right: 0;
  }

  .cx-map-section {
    grid-column: 1;
    grid-row: 1 / span 2;
  }

  .cx-map-wrap {
    min-height: 520px;
    height: 100%;
  }

  .cx-profile-wrap {
    grid-column: 2;
    grid-row: 1;
  }

  .cx-mission-state {
    grid-column: 2;
    grid-row: 2;
    align-self: start;
  }

  .cx-cues-panel {
    grid-column: 1 / -1;
    grid-row: 3;
  }

  .cx-cues-panel[open] .cx-cue-list {
    max-height: 280px;
  }
}

@media (min-width: 1280px) {
  :root {
    --cx-max-wide: 1440px;
    --cx-map-min-h: 580px;
  }

  .cx-main {
    grid-template-columns: minmax(0, 1.7fr) minmax(320px, 1fr);
  }
}
