/* ==========================================================================
   The Chicanes — layout and components
   Ports MainContainerView, SideMenuView, ContentView chrome,
   LocationDetailView, and the NPS page components from AppTheme.swift.
   ========================================================================== */

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

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  background: var(--background);
  color: var(--primary-text);
  font-family: var(--font-sans);
  font-size: var(--body-size);
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

button {
  font: inherit;
  color: inherit;
  border: 0;
  background: none;
  padding: 0;
  cursor: pointer;
}

:focus-visible {
  outline: 2px solid var(--tint);
  outline-offset: 2px;
  border-radius: 6px;
}

/* --------------------------------------------------------------------------
   App shell — MainContainerView.swift
   -------------------------------------------------------------------------- */

#app {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  position: relative;
  z-index: 400;
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px 8px;
  padding-top: calc(8px + env(safe-area-inset-top));
  padding-left: calc(16px + env(safe-area-inset-left));
  padding-right: calc(16px + env(safe-area-inset-right));
  background: var(--background);
  background: color-mix(in srgb, var(--background) 95%, transparent);
  border-bottom: 1px solid var(--divider);
}

.topbar__button {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 8px;
  background: var(--material);
  border: 1px solid var(--material-border);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  color: var(--primary-text);
  flex: 0 0 auto;
}

/* Balances the hamburger so the wordmark stays optically centred —
   the Color.clear spacer in MainContainerView. */
.topbar__spacer { width: 44px; height: 44px; flex: 0 0 auto; }

.topbar__wordmark {
  flex: 1 1 auto;
  display: flex;
  justify-content: center;
  min-width: 0;
}

.topbar__wordmark img {
  height: 28px;                 /* .frame(height: 28) */
  width: auto;
  max-width: 100%;
  object-fit: contain;
}

@media (prefers-color-scheme: dark) {
  /* The wordmark artwork is black; invert it so it reads on a dark bar. */
  .topbar__wordmark img { filter: invert(1); }
}

.stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
}

.view {
  position: absolute;
  inset: 0;
  display: none;
}

.view[data-active="true"] { display: block; }

/* --------------------------------------------------------------------------
   Side menu — SideMenuView.swift
   -------------------------------------------------------------------------- */

.scrim {
  position: fixed;
  inset: 0;
  z-index: 500;
  background: var(--scrim);
  opacity: 0;
  visibility: hidden;
  transition: opacity .3s ease-in-out, visibility .3s;
}

.scrim[data-open="true"] { opacity: 1; visibility: visible; }

.menu {
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  z-index: 600;
  width: var(--menu-width);
  padding-left: env(safe-area-inset-left);
  display: flex;
  flex-direction: column;
  background: var(--background);
  box-shadow: 0 0 10px var(--shadow);
  transform: translateX(-100%);
  transition: transform .3s ease-in-out;   /* .easeInOut(duration: 0.3) */
  visibility: hidden;
}

.menu[data-open="true"] { transform: translateX(0); visibility: visible; }

.menu__title {
  font-size: 22px;
  font-weight: 700;
  padding: 60px 24px 30px;
  padding-top: calc(60px + env(safe-area-inset-top));
  margin: 0;
}

.menu__divider {
  height: 1px;
  background: var(--divider);
  margin-bottom: 10px;
}

.menu__item {
  display: flex;
  align-items: center;
  gap: 16px;
  width: 100%;
  padding: 14px 24px;
  color: var(--primary-text);
  text-align: left;
}

.menu__item svg { flex: 0 0 22px; }

.menu__item[aria-current="page"] {
  color: var(--tint);
  background: var(--tint-wash);
}

.menu__footer {
  margin-top: auto;
  padding: 16px 24px calc(24px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--divider);
}

.menu__offline {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  color: var(--primary-text);
  text-align: left;
  padding: 6px 0;
}

.menu__offline svg { flex: 0 0 22px; }
.menu__offline[disabled] { opacity: .5; cursor: default; }

.menu__status {
  display: block;
  font-size: var(--caption-size);
  color: var(--secondary-text);
  margin-top: 6px;
  min-height: 1.2em;
}

.menu__version {
  display: block;
  font-size: var(--caption-size);
  color: var(--secondary-text);
  margin-top: 10px;
}

/* --------------------------------------------------------------------------
   Map — ContentView.swift
   -------------------------------------------------------------------------- */

#map {
  position: absolute;
  inset: 0;
  background: var(--secondary-background);
}

.map-badge {
  position: absolute;
  top: 16px;
  right: calc(16px + env(safe-area-inset-right));
  z-index: 450;
  font-size: var(--caption-size);
  padding: 6px 10px;
  border-radius: 999px;
  background: var(--material);
  border: 1px solid var(--material-border);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  color: var(--primary-text);
  pointer-events: none;
}

.map-controls {
  position: absolute;
  right: calc(16px + env(safe-area-inset-right));
  bottom: calc(24px + env(safe-area-inset-bottom));
  z-index: 450;
  display: flex;
  gap: 12px;
}

.map-controls__button {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--material);
  border: 1px solid var(--material-border);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  color: var(--tint);
  box-shadow: 0 2px 8px var(--shadow);
}

.map-controls__button[data-active="true"] {
  background: var(--tint);
  color: #fff;
}

/* Map pins — the 26pt circle with a white glyph drawn in
   ContentView.Coordinator.mapView(_:viewFor:) */
.pin {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .45);
}

/* Blue dot — MKMapView.showsUserLocation */
.userdot {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--tint);
  border: 3px solid #fff;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, .18), 0 1px 4px rgba(0, 0, 0, .35);
}

.leaflet-container { background: var(--secondary-background); font-family: var(--font-sans); }
.leaflet-control-attribution {
  font-size: 10px;
  background: rgba(255, 255, 255, .72);
  padding: 1px 5px;
}
.leaflet-control-attribution a { color: #333; }

/* --------------------------------------------------------------------------
   Detail sheet — LocationDetailView.swift
   Two snap points reproduce .presentationDetents([.medium, .large]).
   -------------------------------------------------------------------------- */

.sheet-scrim {
  position: fixed;
  inset: 0;
  z-index: 700;
  background: var(--scrim);
  opacity: 0;
  visibility: hidden;
  transition: opacity .3s ease, visibility .3s;
}

.sheet-scrim[data-open="true"] { opacity: 1; visibility: visible; }

.sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 800;
  height: 92vh;
  display: flex;
  flex-direction: column;
  background: var(--sheet-background);
  border-radius: 14px 14px 0 0;
  box-shadow: 0 -2px 24px var(--shadow);
  transform: translateY(100%);
  transition: transform .32s cubic-bezier(.32, .72, 0, 1);
  will-change: transform;
  touch-action: none;
}

.sheet[data-detent="medium"] { transform: translateY(50%); }
.sheet[data-detent="large"]  { transform: translateY(8%); }

.sheet.is-dragging { transition: none; }

.sheet__grabber {
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  padding: 6px 0 2px;
  cursor: grab;
}

.sheet__grabber::before {
  content: "";
  width: 36px;
  height: 5px;
  border-radius: 3px;
  background: var(--divider);
}

.sheet__header {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px;
}

.sheet__title {
  font-size: 22px;
  font-weight: 700;
  margin: 0;
  line-height: 1.2;
}

.sheet__done { color: var(--tint); font-size: 17px; }

.sheet__body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding-bottom: calc(24px + env(safe-area-inset-bottom));
  touch-action: pan-y;
}

/* Photo carousel — TabView(.page) */
.carousel {
  position: relative;
  margin: 0 16px;
  border-radius: 12px;
  overflow: hidden;
}

.carousel__track {
  display: flex;
  height: 200px;                        /* .frame(height: 200) */
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}

.carousel__track::-webkit-scrollbar { display: none; }

.carousel__slide {
  flex: 0 0 100%;
  scroll-snap-align: center;
  height: 100%;
}

.carousel__slide img {
  width: 100%;
  height: 100%;
  object-fit: cover;                    /* .scaledToFill().clipped() */
  display: block;
  background: var(--secondary-background);
}

.carousel__dots {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 8px;
  display: flex;
  justify-content: center;
  gap: 7px;
}

.carousel__dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: rgba(255, 255, 255, .45);
  transition: background .2s;
}

.carousel__dot[data-on="true"] { background: #fff; }

/* Fallback mini-map — SatellitePinMapView */
.minimap {
  height: 200px;
  margin: 0 16px;
  border-radius: 12px;
  overflow: hidden;
  background: var(--secondary-background);
}

.sheet__description {
  padding: 16px;
  margin: 0;
  line-height: 1.45;
}

.sheet__meta { padding: 0 16px 8px; }

.sheet__elevation {
  font-size: var(--caption-size);
  color: var(--secondary-text);
  margin: 0 0 10px;
}

.sheet__coords {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--tint);
  font-size: var(--caption-size);
}

/* --------------------------------------------------------------------------
   Content pages — NPSPageHeader / NPSSection / NPSDivider (AppTheme.swift)
   -------------------------------------------------------------------------- */

.page {
  height: 100%;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  background: var(--background);
}

.page__header {
  padding: var(--page-padding);
  padding-left: calc(var(--page-padding) + env(safe-area-inset-left));
  padding-right: calc(var(--page-padding) + env(safe-area-inset-right));
  background: var(--header-background);
  color: var(--header-text);
}

.page__title {
  font-family: var(--font-serif);
  font-size: var(--page-title-size);
  font-weight: 700;
  line-height: 1.15;
  margin: 0 0 4px;
}

.page__subtitle {
  font-size: var(--caption-size);
  color: rgba(255, 255, 255, .75);
  margin: 0;
}

.page__body {
  display: flex;
  flex-direction: column;
  gap: var(--section-gap);
  padding: var(--page-padding);
  padding-left: calc(var(--page-padding) + env(safe-area-inset-left));
  padding-right: calc(var(--page-padding) + env(safe-area-inset-right));
  padding-bottom: calc(var(--page-padding) + 40px + env(safe-area-inset-bottom));
  max-width: 46rem;
}

.section__label {
  font-size: var(--label-size);
  font-weight: 600;
  letter-spacing: var(--label-tracking);
  text-transform: uppercase;            /* .uppercased() */
  color: var(--accent);
  margin: 0 0 6px;
}

.section__text {
  font-size: var(--body-size);
  line-height: 1.5;
  color: var(--primary-text);
  margin: 0;
}

.section__divider {
  height: 1px;
  background: var(--divider);
  border: 0;
  margin: 0;
}

/* --------------------------------------------------------------------------
   Toast — used for GPS and offline-download feedback
   -------------------------------------------------------------------------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(90px + env(safe-area-inset-bottom));
  z-index: 900;
  transform: translate(-50%, 12px);
  max-width: min(90vw, 26rem);
  padding: 10px 16px;
  border-radius: 999px;
  background: var(--header-background);
  color: #fff;
  font-size: var(--caption-size);
  text-align: center;
  opacity: 0;
  visibility: hidden;
  transition: opacity .25s, transform .25s, visibility .25s;
}

.toast[data-open="true"] {
  opacity: 1;
  visibility: visible;
  transform: translate(-50%, 0);
}

/* --------------------------------------------------------------------------
   Splash — the launch screen, matching the app's loading video treatment
   -------------------------------------------------------------------------- */

#splash {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
  background: #0d0d0d;
  transition: opacity .5s ease;
}

#splash[data-hidden="true"] { opacity: 0; pointer-events: none; }

#splash img {
  width: min(78vw, 420px);
  height: auto;
  opacity: .92;
}

#splash::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(to bottom, rgba(13, 13, 13, 0) 35%, rgba(13, 13, 13, .85) 100%);
  pointer-events: none;
}

/* --------------------------------------------------------------------------
   Wider screens: the app was portrait-first, so the shell stays centred
   rather than stretching content to desktop widths.
   -------------------------------------------------------------------------- */

@media (min-width: 900px) {
  .sheet { left: 50%; width: min(560px, 92vw); transform: translate(-50%, 100%); }
  .sheet[data-detent="medium"] { transform: translate(-50%, 50%); }
  .sheet[data-detent="large"]  { transform: translate(-50%, 8%); }
  .sheet { border-radius: 14px 14px 0 0; }
}

@media (prefers-reduced-motion: reduce) {
  .menu, .scrim, .sheet, .sheet-scrim, .toast, #splash { transition-duration: .01ms; }
}
