/* ==========================================================================
   Blue Lagoon Resort — 2D map view
   --------------------------------------------------------------------------
   A flat, pan-and-zoom view of the resort built from the owner's aerial
   artwork (assets/map/map-2d.jpg).  The image lives in a scaled "world" layer;
   the pins live in a separate screen-space layer, so they keep a constant
   size at every zoom level exactly like a real map app.

   The view is switched on by html[data-view="2d"] (js/map2d/map2d.js).
   ========================================================================== */

/* ---------- the pane ------------------------------------------------- */
.map2d {
  position: absolute;
  inset: 0;
  z-index: 1;
  overflow: hidden;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.28s ease, visibility 0s linear 0.28s;
}

html[data-view='2d'] .map2d {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transition: opacity 0.28s ease;
}

/* the 3D canvas stays in the layer but goes quiet while 2D is up */
.map3d__stage { transition: opacity 0.28s ease; }
html[data-view='2d'] .map3d__stage { opacity: 0; pointer-events: none; }

/* the five-colour 3D legend has no meaning on the photo map */
html[data-view='2d'] .map3d__legend { display: none; }

/* a soft, blurred copy of the photo fills the letterbox on wide screens */
.map2d__backdrop {
  position: absolute;
  inset: -40px;
  background-image: url('../assets/map/map-2d-tiny.jpg');
  background-position: center;
  background-size: cover;
  filter: blur(26px) saturate(1.05);
  transform: scale(1.06);
  opacity: 0.85;
  pointer-events: none;
}

html[data-theme='dark'] .map2d__backdrop {
  filter: blur(26px) saturate(0.75) brightness(0.5);
  opacity: 1;
}

/* ---------- pan / zoom stage ---------------------------------------- */
.map2d__viewport {
  position: absolute;
  inset: 0;
  overflow: hidden;
  touch-action: none;
  overscroll-behavior: contain;
  cursor: grab;
}

.map2d.is-dragging .map2d__viewport { cursor: grabbing; }

.map2d__world {
  position: absolute;
  top: 0;
  left: 0;
  width: var(--art-size, 2048px);
  height: var(--art-size, 2048px);
  transform-origin: 0 0;
  will-change: transform;
}

.map2d__art {
  display: block;
  width: 100%;
  height: 100%;
  opacity: 0;
  user-select: none;
  -webkit-user-drag: none;
  box-shadow: 0 18px 60px rgba(30, 26, 20, 0.34);
  transition: opacity 0.45s ease;
}

.map2d.is-ready .map2d__art { opacity: 1; }

/* "Khlong Phrao" lettering painted on the river, as in the mock-ups.
   It is positioned in artwork space, but js/map2d/map2d.js counter-scales it
   on zoom so it keeps its screen size, exactly like the pins. */
.map2d__river {
  position: absolute;
  left: 557px;
  top: 1175px;
  /* Wide enough that the whole name fits on the curve; text on an SVG
     textPath is cut off where the path ends. */
  width: 640px;
  height: 150px;
  overflow: visible;
  transform-origin: 50% 50%;
  transform: translate(-50%, -50%) rotate(48deg);
  will-change: transform;
  pointer-events: none;
}

.map2d__river text {
  font-family: var(--font-map);
  font-weight: 800;
  font-size: 58px;
  letter-spacing: 1px;
  dominant-baseline: middle;
  fill: #2fa3d8;
  stroke: #202a2e;
  stroke-width: 5.5px;
  stroke-linejoin: round;
  paint-order: stroke fill;
}

html[data-theme='dark'] .map2d__river text {
  fill: #58b7e0;
  stroke: #101c22;
}

/* ---------- pins ----------------------------------------------------- */
.map2d__pins {
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.map2d__pins.is-on { opacity: 1; }

.p2d-pin {
  position: absolute;
  top: 0;
  left: 0;
  width: 0;
  height: 0;
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
  pointer-events: auto;
  -webkit-tap-highlight-color: transparent;
}

/* the wrapper is the clickable box; the inner layer is anchored on the
   projected point by the inline translate3d() the engine writes */
.p2d-pin__inner {
  position: absolute;
  top: 0;
  left: 0;
  display: flex;
  align-items: center;
  gap: 6px;
  transform: translate(calc(-1 * var(--half, 15px)), -50%);
}

.p2d-pin--left .p2d-pin__inner {
  flex-direction: row-reverse;
  transform: translate(calc(-100% + var(--half, 15px)), -50%);
}

.p2d-pin__badge {
  position: relative;
  display: grid;
  place-items: center;
  width: var(--size, 30px);
  height: var(--size, 30px);
  flex: none;
  border-radius: 50%;
  background:
    radial-gradient(circle at 32% 24%, var(--c1) 0%, var(--c2) 82%);
  box-shadow:
    0 0 0 2px #41505f,
    0 2px 7px rgba(0, 0, 0, 0.38);
  color: var(--pin-ink, #151515);
  font-family: var(--font-map);
  font-weight: 700;
  line-height: 1;
  transition: transform 0.16s ease, box-shadow 0.16s ease;
}

/* a comfortable touch target around the small badge */
.p2d-pin__badge::after {
  content: '';
  position: absolute;
  inset: -9px;
  border-radius: 50%;
}

.p2d-pin__badge svg { width: 56%; height: 56%; display: block; }

/* the owner's drawn badges already include the ring and the gradient */
.p2d-pin__img {
  display: block;
  width: 112%;
  height: 112%;
  border-radius: 50%;
  pointer-events: none;
  user-select: none;
  -webkit-user-drag: none;
}

.p2d-pin--img .p2d-pin__badge {
  background: none;
  box-shadow: none;
}

.p2d-pin__letter {
  font-size: calc(var(--size, 30px) * 0.55);
  transform: translateY(0.5px);
}

.p2d-pin__code {
  font-size: calc(var(--size, 30px) * 0.43);
  letter-spacing: -0.02em;
  transform: translateY(0.5px);
}

.p2d-pin__code--wide { font-size: calc(var(--size, 30px) * 0.31); }

.p2d-pin:hover .p2d-pin__badge,
.p2d-pin:focus-visible .p2d-pin__badge { transform: scale(1.08); }

.p2d-pin:focus-visible { outline: none; }
.p2d-pin:focus-visible .p2d-pin__badge {
  box-shadow:
    0 0 0 3px #ffffff,
    0 0 0 5px rgba(21, 31, 44, 0.7),
    0 3px 10px rgba(0, 0, 0, 0.4);
}

.p2d-pin.is-active .p2d-pin__badge {
  box-shadow:
    0 0 0 3px #ffffff,
    0 0 0 6px rgba(21, 31, 44, 0.5),
    0 4px 12px rgba(0, 0, 0, 0.45);
  transform: scale(1.06);
}

/* ---- the long label used by the normal-zoom tier -------------------- */
.p2d-pin__text {
  position: relative;
  display: inline-block;
  white-space: nowrap;
  color: var(--label);
  font-family: var(--font-map);
  font-size: var(--label-size, 14px);
  font-weight: 700;
  line-height: 1;
  letter-spacing: 0.005em;
  filter: drop-shadow(0 1px 1.5px rgba(0, 0, 0, 0.5));
}

/* dark outline: a duplicate of the text underneath the coloured fill.
   The owner's mock-ups outline the letters in near-black, not white, which
   keeps them readable over bright foliage.  The stroke is derived from the
   label size so it stays a thin hairline instead of swallowing the glyphs
   (a fixed 2.6px stroke blobs up an 11px label). */
.p2d-pin__stroke {
  position: absolute;
  inset: 0;
  color: #1b211a;
  -webkit-text-stroke: calc(var(--label-size, 14px) * 0.12) #1b211a;
  user-select: none;
}

.p2d-pin__fill { position: relative; }

/* labels that would collide with another badge are dropped, exactly like a
   map app culls labels when it runs out of room */
.p2d-pin__text.is-hidden { display: none; }

/* ---- tone palette (taken from the owner's mock-ups) ----------------- */
.p2d-pin {
  --c1: #d8d8d8;
  --c2: #8a8a8a;
  --label: #ffffff;
  --pin-ink: #151515;
}

.p2d-pin[data-tone='a'] { --c1: #f2d489; --c2: #c4922f; --label: #f0c960; }
.p2d-pin[data-tone='b'] { --c1: #8ecb6a; --c2: #3d7a2a; --label: #95cf63; }
.p2d-pin[data-tone='d'] { --c1: #eda96a; --c2: #b4661f; --label: #d89963; }
.p2d-pin[data-tone='f'] { --c1: #bb90db; --c2: #6a4590; --label: #bd92e2; }
.p2d-pin[data-tone='restaurant'] { --c1: #eda96a; --c2: #b4661f; --label: #e2a06b; }
.p2d-pin[data-tone='reception'] { --c1: #565656; --c2: #232323; --label: #f2f2f2; --pin-ink: #111111; }
.p2d-pin[data-tone='bathroom'] { --c1: #a8a8a8; --c2: #5d5d5d; --label: #f0f0f0; }
.p2d-pin[data-tone='parking'] { --c1: #6aa5e0; --c2: #1f5198; --label: #c2dcf7; --pin-ink: #ffffff; }
.p2d-pin[data-tone='beach'] { --c1: #74bdd6; --c2: #267895; --label: #7fd0e6; --pin-ink: #0d1416; }

/* ---- overview tier: bigger badge + long label ----------------------- */
.map2d__pins[data-map2d-pins='1'] .p2d-pin {
  --size: 30px;
  --half: 15px;
  --label-size: 14px;
}

/* ---- detail tier: compact badge with the room code ------------------ */
.map2d__pins[data-map2d-pins='2'] .p2d-pin {
  --size: 23px;
  --half: 11.5px;
  --label-size: 10px;
}

/* ==========================================================================
   View switch (2D / 3D)
   ========================================================================== */
/* In 2D the hint floats over a photo, so give it a quiet chip for contrast. */
@media (min-width: 600px) {
  html[data-view='2d'] .map3d__hint {
    padding: 9px 11px;
    border-radius: 14px;
    background: rgba(248, 240, 228, 0.82);
    -webkit-backdrop-filter: blur(4px);
    backdrop-filter: blur(4px);
    box-shadow: 0 4px 16px rgba(30, 26, 20, 0.12);
  }

  html[data-theme='dark'][data-view='2d'] .map3d__hint {
    background: rgba(24, 30, 24, 0.74);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
  }
}

.map3d__view {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  display: flex;
  gap: 2px;
  padding: 2px;
  border: 1px solid var(--swatch-ring);
  border-radius: 999px;
  background: rgba(248, 240, 228, 0.72);
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
  pointer-events: auto;
}

html[data-theme='dark'] .map3d__view {
  background: rgba(34, 42, 34, 0.74);
}

.map3d__view-btn {
  min-width: 34px;
  height: 22px;
  padding: 0 7px;
  border: 0;
  border-radius: 999px;
  background: none;
  color: var(--muted);
  font-family: var(--font-body);
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  line-height: 1;
  cursor: pointer;
  transition: background-color 0.2s ease, color 0.2s ease;
}

.map3d__view-btn:hover { color: var(--ink-soft); }

.map3d__view-btn[aria-pressed='true'] {
  background: var(--ink-soft);
  color: var(--cream);
}

html[data-theme='dark'] .map3d__view-btn[aria-pressed='true'] {
  background: #e8e6d8;
  color: #1a201a;
}

.map3d__view-btn:focus-visible {
  outline: 2px solid var(--ink-soft);
  outline-offset: 1px;
}

/* ==========================================================================
   Responsive
   ========================================================================== */
@media (max-width: 599px) {
  .map2d__pins[data-map2d-pins='1'] .p2d-pin {
    --size: 26px;
    --half: 13px;
    --label-size: 11.5px;
  }

  .map2d__pins[data-map2d-pins='2'] .p2d-pin {
    --size: 21px;
    --half: 10.5px;
    --label-size: 10px;
  }

  .p2d-pin__inner { gap: 5px; }

  .map3d__view {
    top: calc(100% + 7px);
  }

  .map3d__view-btn {
    min-width: 32px;
    height: 21px;
    font-size: 8.5px;
  }

  /* On a phone the flat map is full-bleed, so the two-line hint would sit on
     top of the beach pin.  The toggle and the 2D/3D switch speak for
     themselves; pan and pinch are standard gestures. */
  html[data-view='2d'] .map3d__hint-text { display: none; }

  /* Keep the zoom stack over the river in 2D, where there are no pins. */
  html[data-view='2d'] .map3d__reset { right: auto; left: 16px; }
  html[data-view='2d'] .map3d__zoom { right: auto; left: 16px; }
}

@media (prefers-reduced-motion: reduce) {
  .map2d,
  .map2d__pins,
  .map2d__art,
  .p2d-pin__badge,
  .map3d__stage {
    transition-duration: 0.001ms !important;
  }
}
