/*
 * RoxGeo rock card (rrc-*): desktop bubble anchored to the marker, phone bottom sheet (<dialog>).
 * Behaviour lives in shared/rock-map/card.ts (bundled into assets/js/rox-rock-map.js).
 *
 * Theme hooks (override on .rrc and .rrc-sheet; the sheet is attached to CardOptions.sheetParent, <body> by default):
 *   --rrc-bg  --rrc-fg  --rrc-muted  --rrc-accent  --rrc-accent-fg  --rrc-soft  --rrc-line  --rrc-focus
 * Layout variables written by the script on .rrc: --rrc-w, --rrc-maxh, --rrc-ax/--rrc-ay (arrow offset),
 * --rrc-ox/--rrc-oy (scale-in origin).
 */
.rrc,
.rrc-sheet {
  --rrc-bg: #fff;
  --rrc-fg: #1b1530;
  --rrc-muted: #5a5470;
  --rrc-accent: #4529B8;
  --rrc-accent-fg: #fff;
  --rrc-soft: #f3f0fa;
  --rrc-line: rgba(27, 21, 48, 0.22);
  --rrc-focus: #1b1530;
  --rrc-radius: 18px;
  --rrc-shadow: 0 18px 48px rgba(20, 12, 40, 0.28), 0 2px 8px rgba(20, 12, 40, 0.18);
  color: var(--rrc-fg);
  font-family: inherit;
  text-align: start;
  -webkit-text-size-adjust: 100%;
}

/* ── Bubble ─────────────────────────────────────────────────────────────── */
.rrc {
  position: absolute;
  left: 0;
  top: 0;
  z-index: 5;
  display: flex;
  flex-direction: column;
  box-sizing: border-box;
  width: var(--rrc-w, min(344px, calc(100% - 16px)));
  max-height: var(--rrc-maxh, calc(100% - 16px));
  transform-origin: var(--rrc-ox, 50%) var(--rrc-oy, 100%);
  outline: none;
}
.rrc[hidden] { display: none; }
.rrc-in { animation: rrc-in 0.26s cubic-bezier(0.2, 0.9, 0.3, 1.08) both; }
@keyframes rrc-in {
  from { opacity: 0; scale: 0.88; }
  to { opacity: 1; scale: 1; }
}

.rrc-win {
  position: relative;
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--rrc-bg);
  border: 1.5px solid var(--rrc-line);
  border-radius: var(--rrc-radius);
  box-shadow: var(--rrc-shadow);
  overflow: hidden;
}
.rrc:focus-visible .rrc-win { outline: 3px solid var(--rrc-focus); outline-offset: 2px; }

/* Arrow: a rotated square on the edge facing the marker. Positioned (absolute) so it paints over the
   window border and the two join into one shape; only the two outer sides carry the border. */
.rrc-arrow {
  position: absolute;
  width: 12px;
  height: 12px;
  background: var(--rrc-bg);
  border: 0 solid var(--rrc-line);
  rotate: 45deg;
  pointer-events: none;
}
.rrc[data-layout="top"] .rrc-arrow { bottom: -7px; left: calc(var(--rrc-ax, 50%) - 6px); border-right-width: 1.5px; border-bottom-width: 1.5px; }
.rrc[data-layout="bottom"] .rrc-arrow { top: -7px; left: calc(var(--rrc-ax, 50%) - 6px); border-left-width: 1.5px; border-top-width: 1.5px; }
.rrc[data-layout="right"] .rrc-arrow { left: -7px; top: calc(var(--rrc-ay, 50%) - 6px); border-left-width: 1.5px; border-bottom-width: 1.5px; }
.rrc[data-layout="left"] .rrc-arrow { right: -7px; top: calc(var(--rrc-ay, 50%) - 6px); border-right-width: 1.5px; border-top-width: 1.5px; }
.rrc[data-layout="corner"] .rrc-arrow,
.rrc:not([data-layout]) .rrc-arrow { display: none; }

/* ── Shared content ─────────────────────────────────────────────────────── */
.rrc-body {
  min-height: 0;
  overflow: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 14px 16px 16px;
}

.rrc-x {
  appearance: none;
  -webkit-appearance: none;
  position: absolute;
  top: 6px;
  inset-inline-end: 6px;
  z-index: 2;
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--rrc-fg);
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
.rrc-x:hover { background: var(--rrc-soft); }
.rrc-x:focus-visible { outline: 3px solid var(--rrc-focus); outline-offset: -3px; }

.rrc-title {
  margin: 0;
  font-size: 19px;
  line-height: 1.22;
  font-weight: 700;
  letter-spacing: -0.005em;
  overflow-wrap: anywhere;
  outline: none;
}
/* The close button sits in the corner: keep its space outside the heading so the focus ring does not enclose it. */
.rrc-list-title { margin-inline-end: 44px; min-height: 36px; display: flex; align-items: center; }

.rrc-pebble {
  position: relative;
  flex: none;
  display: grid;
  place-items: center;
  width: 56px;
  height: 51px;
  overflow: hidden;
  border-radius: 46% 54% 50% 50% / 55% 45% 55% 45%;
  border: 2px solid #fff;
  background: var(--rrc-soft);
  box-shadow: 0 0 0 1.5px var(--rrc-line);
}
.rrc-pebble-sm { width: 40px; height: 36px; }
.rrc-pebble-glyph { font: 400 26px/1 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
.rrc-pebble-sm .rrc-pebble-glyph { font-size: 20px; }
.rrc-pebble img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
  transition: opacity 0.25s ease;
}
.rrc-pebble-photo img { opacity: 1; }
.rrc-pebble-photo .rrc-pebble-glyph { visibility: hidden; }

/* details */
.rrc-back {
  appearance: none;
  -webkit-appearance: none;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  max-width: calc(100% - 52px);
  min-height: 44px;
  margin: -6px 0 2px -8px;
  padding: 0 12px 0 6px;
  border: 0;
  border-radius: 22px;
  background: transparent;
  color: var(--rrc-accent);
  font: inherit;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
.rrc-back span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rrc-back:hover { background: var(--rrc-soft); }
.rrc-back:focus-visible { outline: 3px solid var(--rrc-focus); outline-offset: -3px; }
.rrc-back svg { flex: none; }
.rrc-head { display: flex; align-items: center; gap: 14px; padding-inline-end: 40px; }
.rrc-back + .rrc-head { padding-inline-end: 0; }
.rrc-titles { min-width: 0; display: grid; gap: 6px; justify-items: start; }
.rrc-id {
  padding: 4px 9px;
  border-radius: 999px;
  background: var(--rrc-soft);
  color: var(--rrc-muted);
  font: 600 12px/1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  letter-spacing: 0.02em;
}
.rrc-city {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 12px 0 0;
  color: var(--rrc-muted);
  font-size: 14px;
  line-height: 1.3;
}
.rrc-city svg { flex: none; }
.rrc-city span { min-width: 0; overflow-wrap: anywhere; }
.rrc-extra { margin-top: 12px; }
.rrc-extra:empty { display: none; }
.rrc-open {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 48px;
  margin-top: 16px;
  padding: 0 20px;
  border-radius: 999px;
  background: var(--rrc-accent);
  color: var(--rrc-accent-fg);
  font-size: 16px;
  font-weight: 700;
  text-decoration: none;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
.rrc-open:hover { filter: brightness(0.94); }
.rrc-open:focus-visible { outline: 3px solid var(--rrc-focus); outline-offset: 3px; }

/* list */
.rrc-list { list-style: none; margin: 8px 0 0; padding: 0; display: grid; gap: 2px; }
.rrc-row {
  appearance: none;
  -webkit-appearance: none;
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 56px;
  margin: 0;
  padding: 8px 10px;
  border: 0;
  border-radius: 14px;
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: start;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
.rrc-row:hover { background: var(--rrc-soft); }
.rrc-row:focus-visible { outline: 3px solid var(--rrc-focus); outline-offset: -3px; background: var(--rrc-soft); }
.rrc-row-text { min-width: 0; flex: 1; display: grid; gap: 2px; }
.rrc-row-name { font-size: 15px; line-height: 1.25; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rrc-row-city { font-size: 13px; line-height: 1.25; color: var(--rrc-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rrc-row-go { flex: none; display: grid; place-items: center; color: var(--rrc-muted); }
[dir="rtl"] .rrc-row-go svg,
[dir="rtl"] .rrc-open svg,
[dir="rtl"] .rrc-back svg { transform: scaleX(-1); }
.rrc-more { padding: 10px 12px 4px; color: var(--rrc-muted); font-size: 13px; text-align: center; }

/* ── Phone sheet ────────────────────────────────────────────────────────── */
.rrc-sheet {
  position: fixed;
  inset: auto 0 0 0;
  margin: 0;
  width: 100%;
  max-width: none;
  max-height: none;
  padding: 0;
  border: 0;
  border-radius: 28px 28px 0 0;
  background: var(--rrc-bg);
  box-shadow: 0 -12px 40px rgba(20, 12, 40, 0.3);
  overflow: hidden;
  translate: 0 100%;
  transition: translate 0.3s cubic-bezier(0.2, 0.8, 0.2, 1), overlay 0.3s allow-discrete, display 0.3s allow-discrete;
}
.rrc-sheet[open] { translate: 0 0; }
@starting-style {
  .rrc-sheet[open] { translate: 0 100%; }
}
.rrc-sheet::backdrop {
  background: rgb(20 12 40 / 0.5);
  opacity: 0;
  transition: opacity 0.3s ease, overlay 0.3s allow-discrete, display 0.3s allow-discrete;
}
.rrc-sheet[open]::backdrop { opacity: 1; }
@starting-style {
  .rrc-sheet[open]::backdrop { opacity: 0; }
}
.rrc-sheet-in {
  position: relative;
  display: flex;
  flex-direction: column;
  max-height: 92vh;
  max-height: 92dvh;
  padding-bottom: env(safe-area-inset-bottom, 0px);
  box-sizing: border-box;
}
.rrc-handle {
  position: relative;
  flex: none;
  width: 44px;
  height: 5px;
  margin: 10px auto 0;
  border-radius: 3px;
  background: var(--rrc-line);
  touch-action: none;
  cursor: grab;
}
.rrc-handle::before { content: ""; position: absolute; inset: -14px -36px; }
.rrc-sheet-top { position: absolute; top: 0; inset-inline-end: 0; z-index: 2; }
.rrc-sheet .rrc-x { top: 8px; inset-inline-end: 8px; }
.rrc-sheet .rrc-body { padding: 14px 20px 22px; }

/* ── Motion, contrast ───────────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  .rrc-in { animation: none; }
  .rrc-sheet, .rrc-sheet::backdrop, .rrc-pebble img { transition: none; }
}
.rrc[data-reduced] .rrc-in,
.rrc[data-reduced].rrc-in { animation: none; }
.rrc-sheet[data-reduced],
.rrc-sheet[data-reduced]::backdrop { transition: none; }

@media (forced-colors: active) {
  .rrc-win, .rrc-sheet { border: 1.5px solid CanvasText; background: Canvas; color: CanvasText; }
  .rrc-arrow { background: Canvas; border-color: CanvasText; }
  .rrc-open { border: 2px solid CanvasText; background: ButtonFace; color: ButtonText; forced-color-adjust: none; }
  .rrc-row:focus-visible, .rrc-x:focus-visible, .rrc-back:focus-visible { outline-color: Highlight; }
}
