/**
 * Front styles for the static Store map on the TOP page.
 * The PHP renderer supplies each bubble's size through local custom
 * properties; this file controls map coordinates and scoped presentation.
 *
 * @prop {number} --store-map--bubble-size--compact [required] - Bubble diameter in the compact layout unit.
 * @prop {number} --store-map--bubble-size---spacious [required] - Bubble diameter in the spacious layout unit.
 * @prop {number} --store-map--bubble-blur--compact [required] - Figma inner-shadow blur in the compact layout unit.
 * @prop {number} --store-map--bubble-blur--spacious [required] - Figma inner-shadow blur in the spacious layout unit.
 * @prop {time}   --store-map--ripple-duration [optional] - Ripple / glow cycle length. Defaults to 2400ms.
 */

@property --_bubble-glow-blur {
  syntax: "<number>";
  inherits: false;
  initial-value: 18;
}

@property --_bubble-glow-alpha {
  syntax: "<percentage>";
  inherits: false;
  initial-value: 20%;
}

@keyframes --store-map-bubble-glow {
  from {
    --_bubble-glow-alpha: 15%;
  }

  to {
    --_bubble-glow-blur: 36;
    --_bubble-glow-alpha: 45%;
  }
}

@keyframes --store-map-bubble-ripple {
  0% {
    opacity: 0;
    transform: scale(0);
  }

  /* 広がりの途中までは濃度を保ち、末尾で線形に消す */
  66% {
    opacity: 1;
    animation-timing-function: linear;
  }

  91% {
    opacity: 0;
    transform: scale(1);
  }

  100% {
    opacity: 0;
    transform: scale(1);
  }
}

@scope (.scoped.home-store) to (.scoped) {
  :scope {
    color: var(--wp--preset--color--ink);

    @container style(--screen: --compact) {
      padding-block-start: calc(40 * var(--px));
    }
  }

  ._pile {
    isolation: isolate;

    @container style(--screen: --compact) {
      & > * + ._map-layer {
        margin-block-start: calc(-60 * var(--px));
      }
    }

    @container style(--screen: --spacious) {
      display: block grid;
      grid-template-areas: "--pile";

      & > * {
        grid-area: --pile;
      }
    }

    & > ._map-layer {
      z-index: var(--wp--custom--z--backwards);
    }
  }

  /*
   * SPでリード（._paragraphs）が空のときは、ボタンを地図の下へ置く（Figma 552:10034）。
   * 空のリード（`<p></p>` 等）は render.php が ._paragraphs ごと出力しない。
   * DOM順（見出し→ボタン→地図）は保ち、行をsubgridで共有して表示順だけを
   * 「見出し → 地図 → ボタン」にする。地図は装飾（aria-hidden）なので読み上げ順に影響しない。
   */
  ._pile:not(:has(._paragraphs)) {
    @container style(--screen: --compact) {
      display: block grid;
      grid-template-rows: repeat(3, auto);
      padding-block-end: calc(85.8 * var(--px));

      & > * {
        grid-column: 1;
      }

      & > .primary-layout {
        grid-template-rows: subgrid;
        grid-row: 1 / -1;
      }

      & > ._map-layer {
        grid-row: 2;
        margin-block-start: calc(-49.4 * var(--px));
      }
    }
  }

  ._prose:not(:has(._paragraphs)) {
    @container style(--screen: --compact) {
      display: block grid;
      grid-template-rows: subgrid;
      grid-row: 1 / -1;

      & > ._more {
        grid-row: 3;
        margin-block-start: calc(18.6 * var(--px));
      }
    }
  }

  ._prose {
    @container style(--screen: --compact) {
      & > * + ._paragraphs {
        margin-block-start: calc(30 * var(--rem));
      }

      & > * + ._more {
        margin-block-start: calc(30 * var(--rem));
      }
    }

    @container style(--screen: --spacious) {
      padding-block-start: calc(72 * var(--px));

      & > * + * {
        margin-block-start: calc(50 * var(--rem));
      }
    }
  }

  ._heading {
    display: block flex;
    flex-direction: column;
    row-gap: calc(8 * var(--rem));

    @container style(--screen: --spacious) {
      row-gap: calc(14 * var(--rem));
      align-items: center;
    }
  }

  ._index-en {
    font-family: var(--wp--preset--font-family--sans-en);
    font-size: calc(34 * var(--rem));
    font-weight: var(--wp--custom--font-weight--medium);
    line-height: var(--wp--custom--leading--tight);
    text-box: trim-both cap alphabetic;
    letter-spacing: var(--wp--custom--tracking--snug);

    @container style(--screen: --spacious) {
      font-size: calc(54 * var(--rem));
    }
  }

  ._index-jp {
    font-size: calc(12 * var(--rem));
    font-weight: var(--wp--custom--font-weight--bold);
    line-height: var(--wp--custom--leading--tight);
    text-box-trim: trim-both;
    letter-spacing: calc(0.48 * var(--px));

    @container style(--screen: --spacious) {
      font-size: calc(16 * var(--rem));
      letter-spacing: calc(0.64 * var(--px));
    }
  }

  ._paragraphs {
    font-size: calc(13 * var(--rem));
    font-weight: var(--wp--custom--font-weight--medium);
    line-height: var(--wp--custom--leading--relaxed);

    @container style(--screen: --spacious) {
      font-size: calc(16 * var(--rem));
      line-height: var(--wp--custom--leading--normal);
      text-align: center;
      text-wrap: balance;
    }
  }

  ._more .wp-block-buttons {
    @container style(--screen: --spacious) {
      align-items: center;
    }
  }

  ._map-layer {
    @container style(--screen: --spacious) {
      --store-map--density: --spacious;

      margin-block-start: calc(-90 * var(--rem));
    }
  }
}

@scope (.scoped.store-map) to (.scoped) {
  :scope {
    --_density: var(--store-map--density, --compact);
    --_container-width--compact: 375;
    --_container-width--spacious: 1280;
    --_ripple-duration: var(--store-map--ripple-duration, 2400ms);
    --_ripple-delay: calc(var(--_ripple-duration) * 0.09);

    container: --scoped-map / inline-size;
    isolation: isolate;
  }

  ._canvas {
    position: relative;
    overflow: clip;

    @container style(--_density: --compact) {
      aspect-ratio: 375 / 221;

      & > ._map {
        inset: calc(-153 / var(--_container-width--compact) * 100cqi) auto auto
          calc(50% + 98.41 / var(--_container-width--compact) * 100cqi);
        inline-size: calc(398 / var(--_container-width--compact) * 100cqi);
        block-size: calc(448 / var(--_container-width--compact) * 100cqi);
      }
    }

    @container style(--_density: --spacious) {
      aspect-ratio: 1280 / 644;

      & > ._map {
        inset: calc(-341 / var(--_container-width--spacious) * 100cqi) auto auto
          calc(50% + 158.31 / var(--_container-width--spacious) * 100cqi);
        inline-size: calc(1090 / var(--_container-width--spacious) * 100cqi);
        block-size: calc(1228 / var(--_container-width--spacious) * 100cqi);
      }
    }

    & > ._map {
      position: absolute;
      translate: -50%;
      rotate: 32.2deg;
    }

    & > ._bubbles-group {
      position: absolute;
      inset: 0;
      z-index: var(--wp--custom--z--forwards);
    }
  }

  ._bubbles-group {
    @container style(--_density: --compact) {
      & > ._bubble {
        inset-block-start: calc(var(--_bubble-center-y--compact) / var(--_container-width--compact) * 100cqi);
        inset-inline-start: calc(var(--_bubble-center-x--compact) / var(--_container-width--compact) * 100cqi);
        inline-size: calc(var(--store-map--bubble-size--compact) / var(--_container-width--compact) * 100cqi);
      }
    }

    @container style(--_density: --spacious) {
      & > ._bubble {
        inset-block-start: calc(var(--_bubble-center-y--spacious) / var(--_container-width--spacious) * 100cqi);
        inset-inline-start: calc(var(--_bubble-center-x--spacious) / var(--_container-width--spacious) * 100cqi);
        inline-size: calc(var(--store-map--bubble-size---spacious) / var(--_container-width--spacious) * 100cqi);
      }
    }

    & > ._bubble {
      position: absolute;
      z-index: var(--wp--custom--z--forwards);
      translate: -50% -50%;
    }
  }

  ._bubble {
    --_bubble-center-x--compact: 0;
    --_bubble-center-y--compact: 0;
    --_bubble-center-x--spacious: 0;
    --_bubble-center-y--spacious: 0;

    display: block grid;
    place-items: center;
    aspect-ratio: 1;
    border-radius: var(--wp--custom--rounded--full);
    isolation: isolate;

    @container style(--_density: --compact) {
      --_bubble-glow-blur: var(--store-map--bubble-blur--compact, 18);

      @media (prefers-reduced-motion: no-preference) {
        animation: --store-map-bubble-glow var(--_ripple-duration) ease-in-out infinite alternate;
      }

      & > ._bubble-count {
        position: absolute;
        inset-block-start: calc(50% - 9 / var(--_container-width--compact) * 100cqi);
        inset-inline-start: calc(50% + 2.5 / var(--_container-width--compact) * 100cqi);
      }
    }

    @container style(--_density: --spacious) {
      --_bubble-glow-blur: var(--store-map--bubble-blur--spacious, 20);

      @media (prefers-reduced-motion: no-preference) {
        animation: --store-map-bubble-glow var(--_ripple-duration) ease-in-out infinite alternate;
      }

      & ._bubble-count {
        inset-block-start: calc(50% - 20 / var(--_container-width--spacious) * 100cqi);
        inset-inline-start: calc(50% + 3.5 / var(--_container-width--spacious) * 100cqi);
      }
    }

    &::before {
      content: "";
      position: absolute;
      aspect-ratio: 1;
      border-radius: var(--wp--custom--rounded--full);
      background-color: var(--wp--preset--color--ink);

      @container style(--_density: --compact) {
        inset-block-start: calc(50% - 1.6 / var(--_container-width--compact) * 100cqi);
        inset-inline-start: calc(50% - 1.6 / var(--_container-width--compact) * 100cqi);
        inline-size: calc(3.21 / var(--_container-width--compact) * 100cqi);
      }

      @container style(--_density: --spacious) {
        inset-block-start: calc(50% - 3.5 / var(--_container-width--spacious) * 100cqi);
        inset-inline-start: calc(50% - 3.5 / var(--_container-width--spacious) * 100cqi);
        inline-size: calc(7 / var(--_container-width--spacious) * 100cqi);
      }
    }

    &[data-region="kanto"] {
      --_bubble-center-x--compact: 297.5;
      --_bubble-center-y--compact: 151.5;

      @container style(--_density: --spacious) {
        --_bubble-center-x--spacious: 810.5;
        --_bubble-center-y--spacious: 508.5;
      }
    }

    &[data-region="chubu"] {
      --_bubble-center-x--compact: 245.5;
      --_bubble-center-y--compact: 140.5;

      @container style(--_density: --spacious) {
        --_bubble-center-x--spacious: 661.5;
        --_bubble-center-y--spacious: 477.5;
      }
    }

    &[data-region="kinki"] {
      --_bubble-center-x--compact: 187.5;
      --_bubble-center-y--compact: 150.5;

      @container style(--_density: --spacious) {
        --_bubble-center-x--spacious: 533.5;
        --_bubble-center-y--spacious: 481.5;
      }
    }

    &[data-region="chugoku"] {
      --_bubble-center-x--compact: 141.5;
      --_bubble-center-y--compact: 108.5;

      @container style(--_density: --spacious) {
        --_bubble-center-x--spacious: 395.5;
        --_bubble-center-y--spacious: 375.5;
      }
    }

    &[data-region="shikoku"] {
      --_bubble-center-x--compact: 123.5;
      --_bubble-center-y--compact: 139.5;

      @container style(--_density: --spacious) {
        --_bubble-center-x--spacious: 346.5;
        --_bubble-center-y--spacious: 465.5;
      }
    }

    &[data-region="kyushu"] {
      --_bubble-center-x--compact: 59.5;
      --_bubble-center-y--compact: 128.5;

      @container style(--_density: --spacious) {
        --_bubble-center-x--spacious: 182.5;
        --_bubble-center-y--spacious: 444.5;
      }
    }

    & > ._bubble-count {
      position: absolute;
      z-index: var(--wp--custom--z--forwards);
    }
  }

  /*
   * 波紋。1周期のうち ::after が先頭、._bubble-ripple が
   * --_ripple-delay ぶん遅れて発火し、2連のリズムを作る。
   * 色と動きはモーション許可時のみ与える。
   */
  ._bubble::after,
  ._bubble > ._bubble-ripple {
    position: absolute;
    inset: 0;
    z-index: -1;
    border-radius: inherit;
    backdrop-filter: blur(1px);
    pointer-events: none;
  }

  ._bubble::after {
    content: "";
    background-color: rgb(243 243 243 / 20%);

    @container style(--_density: --compact) {
      box-shadow: inset 0 0 calc(var(--store-map--bubble-blur--compact) * var(--px))
        oklch(from var(--wp--preset--color--keycolor) l c h / 12%);
    }

    @container style(--_density: --spacious) {
      box-shadow: inset 0 0 calc(var(--store-map--bubble-blur--spacious) * var(--px))
        oklch(from var(--wp--preset--color--keycolor) l c h / 12%);
    }

    @media (prefers-reduced-motion: no-preference) {
      opacity: 0;
      animation: --store-map-bubble-ripple var(--_ripple-duration) cubic-bezier(0.2, 0.6, 0.3, 1) infinite;
    }
  }

  ._bubble > ._bubble-ripple {
    background-color: rgb(243 243 243 / 5%);

    @container style(--_density: --compact) {
      box-shadow: inset 0 0 calc(var(--store-map--bubble-blur--compact) * var(--px))
        oklch(from var(--wp--preset--color--keycolor) l c h / 10%);
    }

    @container style(--_density: --spacious) {
      box-shadow: inset 0 0 calc(var(--store-map--bubble-blur--spacious) * var(--px))
        oklch(from var(--wp--preset--color--keycolor) l c h / 10%);
    }
  }

  ._bubble-count {
    color: var(--wp--preset--color--ink);
    font-family: var(--wp--preset--font-family--sans-en);
    font-size: calc(10 * var(--rem));
    font-weight: var(--wp--custom--font-weight--medium);
    line-height: 1;
    letter-spacing: var(--wp--custom--tracking--snug);

    @container style(--_density: --spacious) {
      font-size: calc(13 * var(--rem));
    }
  }
}

