/*
 * The map on the public /rocks page: stage, frame and controls.
 * The marker layer and the rock card come from rox-marker-layer.css / rox-rock-card.css (brand purple by default).
 * Behaviour: assets/js/rocks-map.js. Markup: server/lib/rocks-map-block.ts.
 *
 * Layout rule: nothing here may change size after first paint. The map has a fixed height.
 * Fullscreen rule: .rm-wrap, .rm-frame and .rm-shell must never get transform / filter / contain / backdrop-filter
 * (or a z-index), otherwise the position:fixed fullscreen shell is trapped inside them.
 */

/* ── Stage ───────────────────────────────────────────────────────────────── */
.rm-stage { width: min(75rem, 100% - 2 * clamp(1rem, 2.4vw, 2.5rem)); max-width: none; margin: 0 auto; padding: 8px 0 0; box-sizing: border-box; }
.rm-wrap { position: relative; }
.rm-frame {
  position: relative;
  border: 1px solid var(--linia, #DED3E6);
  border-radius: var(--r-m, 14px);
  background: var(--papier-2, #F1ECE2);
  box-shadow: none;
}
.rm-shell { position: relative; border-radius: inherit; }
.rm-map {
  position: relative;
  width: 100%;
  height: clamp(380px, 62vh, 640px);
  height: clamp(380px, 62svh, 640px);
  border-radius: inherit;
  overflow: hidden;
  background: var(--papier-2, #F1ECE2);
}
.rm-sr {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; border: 0;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
}

/* Loading / error / empty message: a pill over the map; it never blocks dragging the map. */
.rm-msg {
  position: absolute; inset: 0; z-index: 3; margin: 0; padding: 24px;
  display: flex; align-items: center; justify-content: center; text-align: center;
  pointer-events: none;
}
.rm-msg[hidden] { display: none; }
.rm-msg > span {
  max-width: min(100%, 420px); padding: 10px 18px; border-radius: var(--r-s, 10px);
  background: #FFFFFF; border: 1px solid var(--linia, #DED3E6); color: #29143F;
  font-weight: 700; font-size: 0.95rem; line-height: 1.4;
  box-shadow: none;
}

/* ── Controls inside the map ─────────────────────────────────────────────── */
.rm-total {
  position: absolute; z-index: 5; top: 10px; left: 10px; max-width: calc(100% - 76px); margin: 0;
  display: inline-flex; align-items: center; min-height: 44px; padding: 8px 16px; box-sizing: border-box;
  border-radius: var(--r-s, 10px); background: #FFFFFF; color: #29143F; border: 1px solid var(--linia, #DED3E6);
  font-weight: 700; font-size: 0.92rem; line-height: 1.25; font-variant-numeric: tabular-nums;
  box-shadow: none;
  pointer-events: none;
}
.rm-total[hidden] { display: none; }
/* Group picker (campaign pages): under the count pill, so it never moves the map. */
.rm-groups { position: absolute; z-index: 5; top: 62px; left: 10px; max-width: calc(100% - 76px); }
.rm-groups[hidden] { display: none; }
.rm-group-select {
  display: block; max-width: 100%; min-height: 44px; padding: 8px 36px 8px 16px; box-sizing: border-box;
  border-radius: var(--r-s, 10px); border: 1.5px solid #29143F; color: #29143F; font: inherit; font-weight: 700; font-size: 0.92rem;
  line-height: 1.2; cursor: pointer; box-shadow: none;
  -webkit-appearance: none; appearance: none; text-overflow: ellipsis;
  background: #fff url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' fill='none' stroke='%234c1d95' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") no-repeat right 14px center / 12px 8px;
}
.rm-group-select:focus-visible { outline: 3px solid #35208F; outline-offset: 2px; box-shadow: 0 0 0 5px #fff; }
.rm-fs {
  position: absolute; z-index: 6; top: 10px; right: 10px;
  display: inline-flex; align-items: center; gap: 8px; min-height: 44px; padding: 8px 14px; box-sizing: border-box;
  border-radius: var(--r-s, 10px); border: 1.5px solid #29143F; background: #FFFFFF; color: #29143F;
  font: inherit; font-weight: 700; font-size: 0.92rem; line-height: 1.2; cursor: pointer;
  box-shadow: none;
  transition: background-color 0.18s ease, color 0.18s ease, transform 0.15s ease;
}
.rm-fs:hover { background: #F3ECFA; color: #6823AD; border-color: #6823AD; }
.rm-fs:active { transform: scale(0.97); }
.rm-fs:focus-visible { outline: 3px solid #35208F; outline-offset: 2px; box-shadow: 0 0 0 5px #fff; }
.rm-map .mapboxgl-ctrl-top-right { margin-top: 58px; }
.rm-map .mapboxgl-ctrl-group button { width: 44px; height: 44px; }

@media (max-width: 520px) {
  .rm-fs { width: 44px; padding: 0; justify-content: center; }
  .rm-fs-t { display: none; }
  .rm-total { font-size: 0.85rem; padding: 8px 12px; }
  .rm-map .mapboxgl-ctrl-group button { width: 40px; height: 40px; }
}

/* ── Fullscreen (a fixed dialog: works on iOS, honours Back and Esc) ──────── */
/* Layout as the app's full-screen map (client/components/FullscreenMapFrame.tsx): a solid header under the status
   bar with the RoxGeo mark, title and rock count, and a 44 px close button; the map fills the rest. */
.rm-head { display: none; }
.rm-shell.rm-full {
  position: fixed; inset: 0; z-index: 2000; border-radius: 0; animation: rm-full-in 0.32s cubic-bezier(0.22, 1, 0.36, 1);
  display: flex; flex-direction: column; background: #FFFFFF;
}
.rm-shell.rm-full .rm-head {
  display: flex; align-items: center; gap: 12px; flex: 0 0 auto; order: -1; box-sizing: border-box;
  min-height: calc(60px + env(safe-area-inset-top));
  padding: calc(8px + env(safe-area-inset-top)) calc(76px + env(safe-area-inset-right)) 8px calc(16px + env(safe-area-inset-left));
  background: #FFFFFF; border-bottom: 1px solid var(--linia, #DED3E6); color: #29143F;
}
.rm-head-mark { width: 36px; height: 28px; flex: 0 0 auto; object-fit: contain; }
.rm-head-mark-dark { display: none; }
.rm-head-text { display: flex; flex-direction: column; min-width: 0; }
.rm-head-title {
  font-family: var(--font-display, "Literata", Georgia, serif); font-weight: 700; font-size: 1.1rem; line-height: 1.25;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.rm-head-sub { font-size: 0.82rem; line-height: 1.3; color: #5A4F66; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rm-head-sub:empty { display: none; }
.rm-shell.rm-full .rm-map { flex: 1 1 auto; height: auto; min-height: 0; border-radius: 0; }
.rm-shell.rm-full .rm-total { display: none; }
.rm-shell.rm-full .rm-groups { left: max(10px, env(safe-area-inset-left)); top: calc(70px + env(safe-area-inset-top)); }
.rm-shell.rm-full .rm-fs,
.rm-shell.rm-full .rm-fs:hover {
  right: calc(16px + env(safe-area-inset-right)); top: calc(8px + env(safe-area-inset-top));
  width: 44px; height: 44px; padding: 0; justify-content: center;
  border: 1px solid var(--linia, #DED3E6); background: #FFFFFF; color: #29143F;
}
.rm-shell.rm-full .rm-fs:hover { background: #F3ECFA; border-color: #6823AD; color: #6823AD; }
.rm-shell.rm-full .rm-fs-t { display: none; }
.rm-shell.rm-full .mapboxgl-ctrl-top-right { margin-top: 0; }
@keyframes rm-full-in { from { opacity: 0.4; transform: scale(0.97); } to { opacity: 1; transform: none; } }
html.rm-lock, html.rm-lock body { overflow: hidden; overscroll-behavior: none; }

/* ── Note under the map ──────────────────────────────────────────────────── */
.rm-note {
  margin: 0; padding: 12px 0 20px; min-height: 44px; box-sizing: border-box;
  display: flex; align-items: center;
  font-size: 0.85rem; line-height: 1.45; color: var(--rx-text-2, var(--granit, #5A5360)); overflow-wrap: anywhere;
}

@media (prefers-reduced-motion: reduce) {
  .rm-shell.rm-full { animation: none; }
  .rm-fs { transition: none; }
}

/* ── Marker contrast on the website map (WCAG 1.4.11, non-text >= 3:1) ──────
   The shared marker layer (also embedded in the app) draws an ink edge and an ochre
   focus/selection ring. On the light paper map ochre is only 1.7:1, so the website
   uses ink for keyboard focus and ultramarine for the selected pebble (both >= 7:1 on
   land, water and park). On the dark map the ink edge vanishes (1.1:1), so the edge is
   paper-coloured there and the ochre rings (7.6:1) stay. */
.rm-map .rml-layer { --rml-focus: #1f1b24; --rml-select: #4529b8; }

/* ── Dark theme (footer switch sets html.rx-dark; html.rx-light opts a page out) ─
   Same surfaces and ink as the app's dark tokens; the map style itself is repainted
   by mapbox-helper.js (roxPaper). Marker pebbles keep their cream/pigment fills
   (the emblem); only their outline flips so it stays visible on the dark map. */
@media screen {
  html.rx-dark:not(.rx-light) .rm-frame{ border-color: #4A4253; background: #26212C; box-shadow: none; }
  html.rx-dark:not(.rx-light) .rm-map{ background: #26212C; }
  html.rx-dark:not(.rx-light) .rm-map .rml-layer{ --rml-edge: #F4EFE6; --rml-focus: #E9A92A; --rml-select: #E9A92A; }
  html.rx-dark:not(.rx-light) .rm-msg > span,
  html.rx-dark:not(.rx-light) .rm-total{ background: #2C2732; border-color: #857D90; color: #F4EFE6; box-shadow: none; }
  html.rx-dark:not(.rx-light) .rm-group-select,
  html.rx-dark:not(.rx-light) .rm-fs{
    background-color: #2C2732; color: #E4DEF6; border-color: #B4A6F2; box-shadow: none;
  }
  html.rx-dark:not(.rx-light) .rm-group-select{
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' fill='none' stroke='%23E4DEF6' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  }
  html.rx-dark:not(.rx-light) .rm-fs:hover{ background: #36303D; }
  html.rx-dark:not(.rx-light) .rm-group-select:focus-visible,
  html.rx-dark:not(.rx-light) .rm-fs:focus-visible{ outline-color: #B4A6F2; box-shadow: 0 0 0 5px #1F1B24; }
  html.rx-dark:not(.rx-light) .rm-shell.rm-full,
  html.rx-dark:not(.rx-light) .rm-shell.rm-full .rm-head{ background: #29143F; border-bottom-color: #4A3A5E; color: #F9F6EE; }
  html.rx-dark:not(.rx-light) .rm-head-sub{ color: #C9BFD6; }
  html.rx-dark:not(.rx-light) .rm-head-mark-light{ display: none; }
  html.rx-dark:not(.rx-light) .rm-head-mark-dark{ display: block; }
  html.rx-dark:not(.rx-light) .rm-shell.rm-full .rm-fs{ background: #29143F; color: #F9F6EE; border-color: #9C8DAE; }
  html.rx-dark:not(.rx-light) .rm-shell.rm-full .rm-fs:hover{ background: #3A2257; border-color: #C887EF; color: #F9F6EE; }
  html.rx-dark:not(.rx-light) .rm-map .mapboxgl-ctrl-group{ background: #2C2732; box-shadow: none; border: 1.5px solid #857D90; }
  html.rx-dark:not(.rx-light) .rm-map .mapboxgl-ctrl-group button + button{ border-top-color: #4A4253; }
  html.rx-dark:not(.rx-light) .rm-map .mapboxgl-ctrl-group button .mapboxgl-ctrl-icon{ filter: invert(1); }
  html.rx-dark:not(.rx-light) .rm-map .mapboxgl-ctrl-attrib{ background: rgba(31, 27, 36, 0.8); color: #B9B1C2; }
  html.rx-dark:not(.rx-light) .rm-map .mapboxgl-ctrl-attrib a{ color: #E4DEF6; }
  html.rx-dark:not(.rx-light) .rm-map .mapboxgl-ctrl-logo{ filter: invert(1) hue-rotate(180deg); }
  /* The rock card opens over the map (and as a sheet in fullscreen). */
  html.rx-dark:not(.rx-light) .rrc,
  html.rx-dark:not(.rx-light) .rrc-sheet{
    --rrc-bg: #2C2732;
    --rrc-fg: #F4EFE6;
    --rrc-muted: #B9B1C2;
    --rrc-accent: #4529B8;
    --rrc-accent-fg: #fff;
    --rrc-soft: #36303D;
    --rrc-line: rgba(244, 239, 230, 0.28);
    --rrc-focus: #B4A6F2;
    --rrc-shadow: 0 18px 48px rgba(0, 0, 0, 0.55), 0 2px 8px rgba(0, 0, 0, 0.4);
  }
}
