@scope (#water-map-section) {
  /* ------------------------------------------------------------------------
   * Theme and scoped defaults
   * --------------------------------------------------------------------- */

  :scope {
    --ink: #173d35;
    --cream: #fffaf0;
    --coral: #ef735c;
    --mint: #b9ded2;
    --yellow: #f7c858;
    --color-filter-all: #365d52;
    --color-heritage: #dba843;
    --color-waterscape: #2b87bb;
    --color-infrastructure: #80a09d;
    --color-entrance: #d9894f;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    min-height: 100vh;
    min-height: 100dvh;
    padding: 20px 40px;
    overflow: hidden;
    /* background: #d9e5d6; */
    font-family: 'Noto Sans TC', sans-serif;
    color: var(--ink);
  }

  * {
    box-sizing: border-box;
  }

  button {
    font: inherit;
  }

  button:focus-visible {
    outline: 3px solid #173d35;
    outline-offset: 3px;
  }

  /* ------------------------------------------------------------------------
   * Map canvas and visual layers
   * --------------------------------------------------------------------- */

  .map-shell {
    position: relative;
    width: min(1500px, calc(100vw - 80px), calc((100vh - 40px) * 16 / 9));
    max-width: 1500px;
    margin-inline: auto;
    isolation: isolate;
    overflow: hidden;
    border-radius: 24px;
    /* box-shadow: 0 24px 80px rgba(28, 67, 57, .2); */
  }

  .map-stage {
    position: relative;
    width: 100%;
    aspect-ratio: 1920/1080;
    overflow: hidden;
  }

  .map-art {
    position: absolute;
    inset: 0;
    display: block;
    width: 100%;
    height: 100%;
    object-fit: contain;
    user-select: none;
    pointer-events: none;
  }

  .map-tint {
    position: absolute;
    inset: 0;
    pointer-events: none;
    background: linear-gradient(90deg, rgba(251, 247, 231, .92) 0%, rgba(251, 247, 231, .24) 21%, transparent 37%), linear-gradient(0deg, rgba(16, 58, 50, .28), transparent 18%);
    mix-blend-mode: multiply;
  }

  .markers-layer,
  .stickers-layer {
    position: absolute;
    inset: 0;
    pointer-events: none;
  }

  .marker {
    pointer-events: auto;
  }

  /* ------------------------------------------------------------------------
   * Category filters
   * --------------------------------------------------------------------- */

  .filter-panel {
    position: absolute;
    z-index: 30;
    right: clamp(20px, 2vw, 36px);
    bottom: clamp(38px, 3vw, 52px);
    width: 250px;
    padding: 18px 16px;
    border: 1px solid rgba(255, 255, 255, .72);
    border-radius: 22px;
    background: rgba(255, 250, 240, .58);
    box-shadow: 0 18px 50px rgba(29, 68, 58, .15);
    backdrop-filter: blur(12px);
  }

  .filter-label {
    margin: 0 8px 12px;
    color: #6b837a;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: .24em;
  }

  .filter-list {
    display: grid;
    gap: 7px;
  }

  .filter-button {
    --filter-color: var(--color-filter-all);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    width: 100%;
    padding: 9px 11px;
    border: 1px solid color-mix(in srgb, var(--filter-color) 58%, transparent);
    border-radius: 12px;
    color: var(--filter-color);
    background: color-mix(in srgb, var(--filter-color) 7%, transparent);
    text-align: left;
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
    transition: background .2s, color .2s, transform .2s, box-shadow .2s;
  }

  .filter-button[data-filter=heritage] {
    --filter-color: var(--color-heritage);
  }

  .filter-button[data-filter=waterscape] {
    --filter-color: var(--color-waterscape);
  }

  .filter-button[data-filter=infrastructure] {
    --filter-color: var(--color-infrastructure);
  }

  .filter-button:hover {
    background: color-mix(in srgb, var(--filter-color) 18%, transparent);
    transform: translateX(3px);
  }

  .filter-button b {
    display: grid;
    place-items: center;
    min-width: 25px;
    height: 25px;
    border-radius: 50%;
    color: var(--filter-color);
    background: color-mix(in srgb, var(--filter-color) 14%, white);
    font: 700 11px 'Outfit';
  }

  .filter-button.is-active {
    color: #fffdf5;
    border-color: var(--filter-color);
    background: var(--filter-color);
    box-shadow: 0 7px 18px color-mix(in srgb, var(--filter-color) 35%, transparent);
    font-weight: 900;
  }

  .filter-button.is-active b {
    color: var(--filter-color);
    background: #fffaf0;
  }

  /* ------------------------------------------------------------------------
   * Interactive markers and labels
   * --------------------------------------------------------------------- */

  .marker {
    --marker-color: var(--ink);
    position: absolute;
    z-index: 12;
    display: grid;
    place-items: center;
    width: 38px;
    height: 46px;
    padding: 0;
    transform: translate(-50%, -50%);
    transform-origin: center bottom;
    border: 0;
    background: transparent;
    cursor: pointer;
    filter: drop-shadow(0 4px 3px rgba(25, 45, 35, .18));
  }

  .marker::after {
    content: '';
    position: absolute;
    left: 50%;
    bottom: 0;
    width: 11px;
    height: 11px;
    background: var(--marker-color);
    border-right: 3px solid #fff8e8;
    border-bottom: 3px solid #fff8e8;
    transform: translateX(-50%) rotate(45deg);
    border-radius: 0 0 3px;
  }

  .marker-ring {
    position: absolute;
    z-index: 1;
    top: 0;
    width: 38px;
    height: 38px;
    border: 3px solid #fff8e8;
    border-radius: 50% 48% 46% 52%;
    background: var(--marker-color);
    box-shadow: 0 0 0 2px var(--marker-color);
  }

  .marker-number {
    position: relative;
    z-index: 2;
    margin-top: -8px;
    color: #fffdf5;
    text-shadow: 0 1px 2px rgba(31, 44, 38, .35);
    font: 900 14px 'Outfit';
  }

  .marker[data-category=heritage] {
    --marker-color: var(--color-heritage);
  }

  .marker[data-category=waterscape] {
    --marker-color: var(--color-waterscape);
  }

  .marker[data-category=infrastructure] {
    --marker-color: var(--color-infrastructure);
  }

  .marker[data-category=entrance] {
    --marker-color: var(--color-entrance);
  }

  .marker:hover .marker-ring,
  .marker.is-active .marker-ring {
    filter: brightness(1.12) saturate(1.05);
    box-shadow: 0 0 0 3px #fffaf0, 0 0 0 6px var(--marker-color), 0 10px 18px rgba(22, 52, 44, .28);
  }

  .marker.is-active {
    z-index: 25;
  }

  .marker[data-id=entrance] .marker-number {
    color: #fff;
    font-family: 'Noto Sans TC';
    font-size: 12px;
  }

  .marker-label {
    position: absolute;
    z-index: 0;
    width: max-content;
    max-width: clamp(120px, 10vw, 170px);
    padding: 5px 9px;
    border: 1px solid color-mix(in srgb, var(--marker-color) 48%, white);
    border-radius: 10px;
    color: #264d43;
    background: rgba(255, 250, 240, .88);
    box-shadow: 0 3px 10px rgba(26, 58, 49, .13);
    font-size: clamp(10px, .72vw, 13px);
    font-weight: 700;
    line-height: 1.35;
    white-space: normal;
    backdrop-filter: blur(5px);
  }

  .marker-label--right {
    left: calc(100% + var(--label-x));
    top: calc(50% + var(--label-y));
    transform: translateY(-50%);
  }

  .marker-label--left {
    right: calc(100% - var(--label-x));
    top: calc(50% + var(--label-y));
    transform: translateY(-50%);
    text-align: right;
  }

  .marker-label--top {
    left: calc(50% + var(--label-x));
    bottom: calc(100% - var(--label-y));
    transform: translateX(-50%);
    text-align: center;
  }

  .marker-label--bottom {
    left: calc(50% + var(--label-x));
    top: calc(100% + var(--label-y));
    transform: translateX(-50%);
    text-align: center;
  }

  .map-sticker {
    position: absolute;
    z-index: 12;
    left: calc(var(--x) + var(--offset-x));
    top: calc(var(--y) + var(--offset-y));
    display: flex;
    flex-direction: column;
    align-items: center;
    width: var(--sticker-width);
    transform: translate(-50%, -50%) rotate(var(--r));
    transform-origin: center bottom;
    pointer-events: none;
    filter: drop-shadow(0 6px 3px rgba(38, 68, 50, .2));
  }

  .map-sticker img {
    display: block;
    width: 100%;
    height: auto;
    object-fit: contain;
  }

  .map-sticker span {
    margin-top: -4px;
    padding: 4px 9px;
    border: 2px solid var(--ink);
    border-radius: 7px 9px 6px 8px;
    color: var(--ink);
    background: #fff8e8;
    font-size: 10px;
    font-weight: 900;
    white-space: nowrap;
    box-shadow: 2px 3px 0 var(--ink);
  }

  /* ------------------------------------------------------------------------
   * Spot information card
   * --------------------------------------------------------------------- */

  .spot-card {
    position: absolute;
    z-index: 50;
    overflow: hidden;
    border: 1px solid rgba(255, 255, 255, .7);
    border-radius: 24px;
    background: #fffaf2;
    box-shadow: 0 24px 70px rgba(20, 49, 42, .32);
    visibility: hidden;
  }

  .card-close {
    position: absolute;
    z-index: 2;
    top: 13px;
    right: 13px;
    display: grid;
    place-items: center;
    width: 34px;
    height: 34px;
    border: 0;
    border-radius: 50%;
    color: #fff;
    background: rgba(18, 51, 43, .82);
    font-size: 23px;
    cursor: pointer;
  }

  .card-image {
    position: relative;
    height: 148px;
    overflow: hidden;
  }

  .card-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
  }

  .card-image span {
    position: absolute;
    z-index: 1;
    left: 19px;
    bottom: 14px;
    color: #fff;
    font: 700 11px 'Outfit';
    letter-spacing: .18em;
  }

  .card-body {
    padding: 20px 22px 18px;
  }

  .card-category {
    margin: 0 0 6px !important;
    color: #cd5c4d !important;
    font-size: 11px !important;
    font-weight: 900;
  }

  .card-body h2 {
    margin: 0 0 10px;
    font-size: 25px;
  }

  .card-body>p {
    margin: 0;
    color: #536e66;
    font-size: 13px;
    line-height: 1.75;
  }

  .card-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 17px;
    padding-top: 13px;
    border-top: 1px dashed #bfd0c7;
    color: #6a8179;
    font-size: 11px;
  }

  .card-meta i {
    display: grid;
    place-items: center;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    color: #fff;
    background: var(--coral);
    font-style: normal;
  }

  /* ------------------------------------------------------------------------
   * Map branding
   * --------------------------------------------------------------------- */

  .map-footer {
    position: absolute;
    z-index: 20;
    right: 320px;
    bottom: 25px;
    left: 43px;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 7px;
    color: #fff;
    text-shadow: 0 2px 8px rgba(0, 0, 0, .4);
    font: 700 10px 'Outfit';
    letter-spacing: .18em;
    pointer-events: none;
  }

  .map-footer-logo {
    display: block;
    width: clamp(130px, 11vw, 180px);
    height: auto;
    filter: drop-shadow(0 2px 6px rgba(0, 0, 0, .6));
  }

  .map-footer p {
    margin: 0;
  }

  /* ------------------------------------------------------------------------
   * Desktop and tablet sizing
   * --------------------------------------------------------------------- */

  @supports(height:100dvh) {
    .map-shell {
      width: min(1500px, calc(100vw - 80px), calc((100dvh - 40px) * 16 / 9));
    }
  }

  @media(max-width:1300px) {
    body {
      padding-inline: 24px;
    }

    .map-shell {
      width: min(calc(100vw - 48px), calc((100vh - 40px) * 16 / 9));
    }

    .filter-panel {
      right: 20px;
      bottom: 34px;
      transform: scale(.88);
      transform-origin: bottom right;
    }

    .map-sticker {
      transform: translate(-50%, -50%) rotate(var(--r)) scale(.84);
    }

    .map-footer {
      right: 280px;
    }
  }

  @supports(height:100dvh) {
    @media(max-width:1300px) {
      .map-shell {
        width: min(calc(100vw - 48px), calc((100dvh - 40px) * 16 / 9));
      }
    }
  }

  .map-viewport {
    width: 100%;
    height: 100%;
  }

  /* ------------------------------------------------------------------------
   * Scrollable map layout: phones and tablets
   * --------------------------------------------------------------------- */

  @media(max-width:1023px) {
    :scope {
      display: block;
      position: relative;
      width: 100%;
      min-height: 0;
      padding: 24px 0;
      overflow: visible;
      overscroll-behavior-y: auto;
      scroll-margin-top: 130px;
    }

    .map-shell {
      --map-stage-width: clamp(960px, 260vw, 1120px);
      position: relative;
      width: 100%;
      max-width: none;
      height: min(760px, 85vh);
      height: min(760px, 85dvh);
      min-height: 520px;
      margin: 0;
      border-radius: 0;
      box-shadow: none;
      overflow: hidden;
    }

    .map-viewport {
      position: relative;
      display: flex;
      align-items: center;
      width: 100%;
      height: 100%;
      overflow-x: auto;
      overflow-y: hidden;
      touch-action: pan-x pan-y;
      overscroll-behavior-x: contain;
      overscroll-behavior-y: auto;
      -webkit-overflow-scrolling: touch;
      scrollbar-width: none;
      cursor: grab;
    }

    .map-viewport.is-dragging {
      cursor: grabbing;
      user-select: none;
    }

    .map-viewport::-webkit-scrollbar {
      display: none;
    }

    .map-stage {
      flex: 0 0 auto;
      width: var(--map-stage-width);
      max-width: none;
      height: auto;
      aspect-ratio: 1920/1080;
      overflow: hidden;
    }

    .marker {
      width: 44px;
      height: 44px;
      filter: drop-shadow(0 3px 2px rgba(25, 45, 35, .18));
    }

    .marker::before {
      content: '';
      position: absolute;
      inset: 0;
      border-radius: 50%;
    }

    .marker::after {
      bottom: 3px;
      width: 8px;
      height: 8px;
      border-width: 0 2px 2px 0;
    }

    .marker-ring {
      top: 5px;
      width: 26px;
      height: 26px;
      border-width: 2px;
      box-shadow: 0 0 0 1.5px var(--marker-color);
    }

    .marker-number {
      margin-top: -5px;
      font-size: clamp(9px, 2.5vw, 11px);
    }

    .marker[data-id=entrance] .marker-number {
      font-size: 10px;
    }

    .marker-label {
      max-width: 120px;
      padding: 3px 6px;
      border-radius: 7px;
      font-size: clamp(10px, 2.7vw, 12px);
      line-height: 1.25;
    }

    .map-sticker {
      width: calc(var(--sticker-width) * .66);
      transform: translate(-50%, -50%) rotate(var(--r));
      filter: drop-shadow(0 4px 2px rgba(38, 68, 50, .18));
      pointer-events: none;
    }

    .map-sticker span {
      margin-top: -2px;
      padding: 2px 5px;
      border-width: 1px;
      font-size: clamp(9px, 2.5vw, 11px);
      box-shadow: 1px 2px 0 var(--ink);
    }

    .filter-panel {
      z-index: 60;
      top: max(12px, env(safe-area-inset-top));
      right: 12px;
      bottom: auto;
      left: 12px;
      width: auto;
      padding: 8px;
      border-radius: 16px;
      transform: none;
      overflow-x: auto;
      overscroll-behavior: contain;
      touch-action: pan-x;
      scrollbar-width: none;
    }

    .filter-panel::-webkit-scrollbar {
      display: none;
    }

    .filter-label {
      display: none;
    }

    .filter-list {
      display: flex;
      gap: 6px;
      width: max-content;
    }

    .filter-button {
      flex: 0 0 auto;
      width: auto;
      min-height: 44px;
      padding: 8px 11px;
      white-space: nowrap;
    }

    .filter-button:hover {
      transform: none;
    }

    .spot-card {
      z-index: 80;
      top: auto !important;
      right: 8px;
      bottom: max(8px, env(safe-area-inset-bottom));
      left: 8px !important;
      width: auto !important;
      max-height: min(58dvh, 520px);
      border-radius: 22px;
      touch-action: pan-y;
      overscroll-behavior: contain;
    }

    .card-image {
      height: clamp(110px, 24dvh, 150px);
    }

    .card-body {
      max-height: 34dvh;
      padding: 14px 18px 16px;
      overflow-y: auto;
      overscroll-behavior: contain;
      touch-action: pan-y;
      -webkit-overflow-scrolling: touch;
    }

    .card-body h2 {
      font-size: 21px;
    }

    .card-body>p {
      font-size: 12px;
      line-height: 1.65;
    }

    .card-meta {
      margin-top: 11px;
      padding-top: 10px;
    }

    .map-footer {
      z-index: 40;
      right: auto;
      bottom: max(var(--map-footer-bottom, 14px), env(safe-area-inset-bottom));
      left: 16px;
    }

    .map-footer-logo {
      width: 120px;
    }
  }

  @media(max-width:639px) {
    :scope {
      scroll-margin-top: 100px;
    }
  }

  /* Compact mode for narrow phones. */
  @media(max-width:430px) {
    .marker-label {
      display: none;
    }

    .marker.is-active .marker-label {
      display: block;
    }

    .map-sticker {
      width: calc(var(--sticker-width) * .6);
    }

    .map-footer p {
      display: none;
    }
  }

  /* Accessibility: retain functionality while minimizing movement. */
  @media(prefers-reduced-motion:reduce) {

    *,
    *::before,
    *::after {
      animation-duration: .01ms !important;
      animation-iteration-count: 1 !important;
      scroll-behavior: auto !important;
    }
  }
}
