/* ============================================================
   Hero — 滿版視窗產品輪播
   做法沿用 montech-test/page2.html
   ============================================================ */
.hero {
  position: relative;
  background: var(--c-black);
}

/* stage 的定位公式（--hero-top + (100dvh − --hero-top)/2）是以「視窗頂端」
   為基準算的，所以這個容器必須就是一整個視窗高；
   先前寫死 600px，stage 算出來 800 多會被 overflow 切掉一大截。 */
.hero__viewport {
  position: relative;
  width: 100%;
  /* --hero-h = 這個框實際可用的高度，預設就是一整個視窗。
     ⚠️ 貼進 CMS 時 hero 並不是從視窗頂端開始 —— 樣板的 .banner 佔了約 150px
        讓 fixed header 不蓋住內容。那一段沒扣掉的話，100dvh 會把 hero 整個
        往下推出第一屏，stage 置中後與 header 的距離會變成設計稿的兩倍以上
        （實測本機 131px、線上約 290px）。由 fitHeroToViewport() 實測後覆寫。 */
  height: var(--hero-h, 100vh);
  height: var(--hero-h, 100dvh);
  overflow: hidden;
}

/* stage = 底圖的實際範圍（等同 contain）。
   底圖是 1840×800 的寬幅版面，用 cover 會把左右裁掉、標題就貼到邊了，
   所以整張完整顯示、置中，四周不足的部分由底色補。

   --hero-top 是浮動 header 佔用的高度（top 30 + 高 120 + 20 緩衝）；
   寬度取「視窗寬」與「扣掉 header 後可用高度換算出的寬」兩者較小值，
   底圖就不會在矮視窗頂到導覽列。 */
.hero__stage {
  --hero-top: 170px;            /* 由 fitHeroToViewport() 依實際 header 覆寫 */
  /* 左右間距沿用 --edge（38px），與導覽列同寬（1844）*/
  --hero-gutter: var(--edge);
  --hero-radius: 30px;          /* 同 .site-header__bar */

  /* 依主題切換的介面顏色（控制項都在 stage 內，變數掛這一層即可）*/
  --hero-fg: var(--c-white);
  --hero-fg-soft: var(--c-gray-200);
  --hero-fg-dim: rgba(255, 255, 255, 0.45);
  --hero-ring: rgba(128, 128, 128, 0.5);
  /* 主標題填色。黑白兩款的方向與色標都不同，整個 gradient 當一個變數換。
     色標百分比是相對「行框」而不是字身，換算見 §5.1a。 */
  --hero-title-fill: linear-gradient(180deg,   /* 黑款：銀色，上→下 */
      #f2f2f2 14.22%, #898989 85.45%);

  position: absolute;
  left: 50%;
  top: calc(var(--hero-top) + (var(--hero-h, 100vh) - var(--hero-top)) / 2);
  top: calc(var(--hero-top) + (var(--hero-h, 100dvh) - var(--hero-top)) / 2);
  transform: translate(-50%, -50%);
  /* 三者取最小：左右各留 --edge、與導覽列同上限、扣掉 header 後的可用高度 */
  width: min(100% - var(--hero-gutter) * 2, var(--container-wide),
             (var(--hero-h, 100vh) - var(--hero-top)) * 1840 / 800);
  width: min(100% - var(--hero-gutter) * 2, var(--container-wide),
             (var(--hero-h, 100dvh) - var(--hero-top)) * 1840 / 800);
  aspect-ratio: 1840 / 800;
  border-radius: var(--hero-radius);
  overflow: hidden;
}

/* --- 底圖（黑／白交叉淡入）-------------------------------- */
/* 這一層同時是主標題的定位框：
   桌機版它是 inset:0，等同整個 stage；≤900px 版型它變成 aspect-ratio 1840/800
   的一般區塊。兩種情況下它都剛好是「底圖的實際範圍」，
   所以主標題掛在這一層就不必寫兩套座標。
   --hu = 1840×800 設計框裡的 1px。 */
.hero__bgs {
  position: absolute;
  inset: 0;
  container-type: inline-size;
  --hu: calc(100cqw / 1840);
}

.hero__bg {
  position: absolute;
  inset: 0;
  background-repeat: no-repeat;
  background-position: center;
  background-size: 100% 100%;
  transition: opacity 0.5s ease;
}
.hero__bg--black { background-image: url("../images/01-hero/banner_bg_black.webp"); opacity: 1; }
.hero__bg--white { background-image: url("../images/01-hero/banner_bg_white.webp"); opacity: 0; }

.hero__stage.is-white .hero__bg--black { opacity: 0; }
.hero__stage.is-white .hero__bg--white { opacity: 1; }

/* --- 主標題 --------------------------------------------------
   舊的 bg_black/bg_white 把標題燒在圖裡；banner_bg_* 是無字版本，
   標題改成真文字（Audiowide），顏色跟著 --hero-fg 一起換黑白。

   座標對齊舊圖燒入的字（量測自 bg_black.png，1840×800）：
     ink 左緣 x=79、右緣 x=1752（寬 1673）、大寫高 137（y 80→216）
   Audiowide 比原本的粗黑體寬、大寫比較矮，無法同時對齊寬度與字高；
   這裡以「寬度對齊」為主 —— 170.28px 時 ink 寬剛好 1673 —— 
   高度則讓大寫帶的視覺中線落在原本的 y=148。
   ------------------------------------------------------------ */
.hero__title {
  position: absolute;
  z-index: 1;                          /* 在底圖之上、產品輪播之下（同燒字版的疊法）*/
  left: calc(66.45 * var(--hu));        /* 66.45 + Audiowide 的 ink 左偏移 12.55 = 79 */
  top:  calc(62.89 * var(--hu));        /* line-height:1 時大寫上緣離行框頂 25.5 → 88.4 */
  margin: 0;
  font-family: "Audiowide", var(--font-sans);
  font-size: calc(170.28 * var(--hu));
  font-weight: 400;
  line-height: 1;
  letter-spacing: 0;
  white-space: nowrap;

  /* 漸層字。背景框是「行框」（line-height:1 → 高 = font-size、寬 = 字的
     advance width），不是字身的 ink 範圍，所以色標百分比都要換算過，
     色標本身定義在 --hero-title-fill（見 §5.1a）。 */
  background-image: var(--hero-title-fill);
  -webkit-background-clip: text;
          background-clip: text;
  color: transparent;
  transition: background-image 0.5s ease;
}
/* 不支援 background-clip:text 時整行字會變透明，退回實色（同本頁其他漸層字的做法）*/
@supports not ((-webkit-background-clip: text) or (background-clip: text)) {
  .hero__title { background: none; color: var(--hero-fg); }
}

/* 白色款：底圖是亮白，底圖上的控制項要轉深色 */
.hero__stage.is-white {
  --hero-fg: #2b2b2b;
  --hero-fg-soft: #4a4a4a;
  --hero-fg-dim: rgba(43, 43, 43, 0.38);
  --hero-ring: rgba(80, 80, 80, 0.45);
  /* 白款：薄荷綠 → 墨藍綠，左→右（量自設計稿，見 §5.1a）*/
  --hero-title-fill: linear-gradient(90deg,
      #69d9bb 0.74%, #1e4544 62.93%, #181a1b 99.45%);
}

/* --- 產品輪播 ------------------------------------------------
   底圖中央本來就留了一塊暗圓區域給產品。
   每張圖套同一個框並以 contain 縮放，換圖時大小不跳動。
   ------------------------------------------------------------ */
.hero__slides {
  position: absolute;
  left: 0;
  right: 0;
  top: 22%;
  bottom: 10%;
  /* 輪播圖不攔截指標事件，滑動由 stage 接收 */
  pointer-events: none;
}

.hero__slide {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  visibility: hidden;
  transform: translateX(3%) scale(0.97);
  transition: opacity 0.5s ease,
              transform 0.6s cubic-bezier(0.22, 0.8, 0.28, 1),
              visibility 0s linear 0.6s;
}
.hero__slide.is-active {
  opacity: 1;
  visibility: visible;
  transform: none;
  transition: opacity 0.5s ease,
              transform 0.6s cubic-bezier(0.22, 0.8, 0.28, 1),
              visibility 0s;
}
.hero__slide img {
  width: 62%;
  height: 100%;
  object-fit: contain;
  object-position: center;
  filter: drop-shadow(0 24px 40px rgba(0, 0, 0, 0.35));
}
.hero__stage.is-white .hero__slide img {
  filter: drop-shadow(0 24px 40px rgba(0, 0, 0, 0.12));
}

/* --- 底部控制列（貼齊底圖的下緣）-------------------------- */
/* 三欄：左 Color、中副標、右頁籤（對應 Figma 同一列的
   646:5426 x=102 / 646:5719 x=960 / 646:5416 x=1702）*/
.hero__controls {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 6%;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 1em;
  padding: 0 3.5%;
  font-size: clamp(12px, 1.05vw, 18px);
  z-index: 5;
}
.hero__colors { justify-self: start; }
.hero__dots   { justify-self: end; }

/* 副標 646:5719 — Figtree 48px，壓在輪播之上 */
.hero__subtitle {
  justify-self: center;
  font-size: 2.6em;                /* ≈48px @1920 */
  font-weight: 400;
  letter-spacing: 0.03em;          /* 1.44px @48px */
  line-height: 1.2;
  white-space: nowrap;
  color: var(--hero-fg-soft);
  transition: color 0.5s ease;
}

/* 左下：顏色切換 */
.hero__colors {
  display: flex;
  align-items: center;
  gap: 0.85em;
  color: var(--hero-fg);
  transition: color 0.5s ease;
}
.hero__color-label { letter-spacing: 0.06em; }

.swatch {
  position: relative;
  width: 1.3em;
  height: 1.3em;
  padding: 0;
  border: 1px solid var(--hero-ring);
  border-radius: 50%;
  transition: transform 0.25s ease, border-color 0.5s ease;
  -webkit-tap-highlight-color: transparent;
}
/* 放大實際可點範圍（視覺不變） */
.swatch::before {
  content: "";
  position: absolute;
  inset: -0.6em;
  border-radius: 50%;
}
.swatch:hover { transform: scale(1.12); }
.swatch:active { transform: scale(0.95); }
.swatch:focus-visible { outline: 2px solid var(--hero-fg); outline-offset: 0.5em; }

/* 選取狀態：外圈光環 */
.swatch::after {
  content: "";
  position: absolute;
  inset: -0.34em;
  border-radius: 50%;
  border: 1px solid var(--hero-fg);
  opacity: 0;
  transform: scale(0.8);
  transition: opacity 0.25s ease, transform 0.25s ease, border-color 0.5s ease;
}
.swatch.is-active::after { opacity: 1; transform: scale(1); }

/* 右下：輪播頁籤 */
.hero__dots {
  display: flex;
  align-items: center;
  gap: 0.5em;
}
.dot {
  position: relative;
  width: 0.62em;
  height: 0.62em;
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: var(--hero-fg-dim);
  transition: width 0.35s cubic-bezier(0.22, 0.8, 0.28, 1),
              background-color 0.3s ease;
  -webkit-tap-highlight-color: transparent;
}
.dot::before {
  content: "";
  position: absolute;
  inset: -0.7em -0.22em;
}
.dot:hover { background: var(--hero-fg); }
.dot:focus-visible { outline: 2px solid var(--hero-fg); outline-offset: 0.3em; }
.dot.is-active {
  width: 1.9em;               /* 目前這張拉長成膠囊 */
  background: var(--hero-fg);
}

/* ============================================================
   視窗下方文案 — 字級沿用 Figma（基準寬 1920）
   副標 646:5719 48px／內文 648:5727 32-46px／特色列 648:5729 24px
   ============================================================ */
.hero__copy {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: clamp(28px, 3vw, 56px);
  padding: clamp(56px, 6vw, 120px) var(--gutter) clamp(64px, 8vw, 160px);
  text-align: center;
}

.hero__lead {
  width: min(100%, 1222px);
  font-weight: 300;
  font-size: clamp(15px, 1.667vw, 32px);  /* 32/1920 */
  line-height: 1.4375;                    /* 46/32 */
  letter-spacing: 0.02em;
  color: var(--c-white);
}

/* 1447:343 — 1532 寬、2×4。每格 295 寬，欄距 (1532−295×4)/3 = 117、列距 60。 */
.hero__features {
  --icon: clamp(56px, 6.25vw, 120px);     /* 120/1920 */
  width: min(100%, 1532px);
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  column-gap: clamp(10px, 6.094vw, 117px);  /* 117/1920 */
  row-gap: clamp(20px, 3.125vw, 60px);      /*  60/1920 */
}
.feature {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: clamp(8px, 0.677vw, 13px);
}
/* ⚠️ 這些 SVG 匯出的是 120 框裡的**內層群組**，不是 120×120 的整框，
   而且帶著 preserveAspectRatio="none"。實際尺寸各不相同
   （磁鐵 116×102.2、Infinity 106×106.6、PWM 112.9×97.9…），
   而那個內在尺寸**就是設計稿畫出來的大小**。

   所以不能寫死 width/height 120（會拉伸成正方形：磁鐵縱向 +17%、Infinity +13%），
   也不能只給 object-fit: contain 不留內距（會整批放大 0~15%，而且各圖放大倍率
   不同，看起來大小不齊）。

   正解是每張各自留它在設計稿裡的 inset —— 由 HTML 的 --pad 給，
   % 會跟著框等比縮放，所以任何螢幕寬度下都是 0 誤差。 */
.feature__icon {
  width:  var(--icon);
  height: var(--icon);
  /* ⚠️ 百分比 padding 是相對於**容器**的寬（這裡是 295 的格子），不是元素自己的
     120，所以不能直接把設計稿的 inset 當 % 寫上去。改成用 --icon 算：
     格子縮到 --icon × --s，object-fit: contain 依長邊貼齊 ⇒
     畫出來剛好是 內在尺寸 × (--icon ÷ 120)，也就是 1:1 的設計尺寸。 */
  padding: calc((1 - var(--s, 1)) / 2 * var(--icon));
  box-sizing: border-box;
  object-fit: contain;
}
.feature__label {
  font-size: clamp(13px, 1.25vw, 24px);   /* 24/1920 */
  letter-spacing: 0.01em;
  color: var(--c-gray-200);
}

/* ============================================================
   RWD — 手機的視窗又高又窄，底圖 contain 後只剩細細一條，
   輪播與控制列會被壓到不能用；改為正常流堆疊。
   ============================================================ */
@media (max-width: 900px) {
  .hero__viewport { height: auto; overflow: visible; }

  .hero__stage {
    position: static;
    transform: none;
    width: 100%;
    aspect-ratio: auto;
    display: flex;
    flex-direction: column;
    gap: 20px;
    padding: 92px var(--gutter) 0;   /* 讓開浮動 header */
    /* 這裡 stage 是正常流容器，圓角改掛在底圖上 */
    border-radius: 0;
    overflow: visible;
  }

  .hero__bgs {
    position: relative;
    inset: auto;
    width: 100%;
    aspect-ratio: 1840 / 800;
    border-radius: 20px;             /* 同行動版導覽列 */
    overflow: hidden;
  }

  .hero__slides {
    position: relative;
    left: auto; right: auto; top: auto; bottom: auto;
    width: 100%;
    aspect-ratio: 4 / 3;
  }
  .hero__slide img {
    width: 100%;
    filter: none;
  }

  .hero__controls {
    position: static;
    padding: 0;
    font-size: 15px;
    /* 窄螢幕塞不下三欄，副標獨立一行 */
    grid-template-columns: auto auto;
    grid-template-areas:
      "sub  sub"
      "col  dot";
    row-gap: 16px;
  }
  .hero__subtitle {
    grid-area: sub;
    font-size: clamp(18px, 4.4vw, 30px);
    white-space: normal;
    text-align: center;
  }
  .hero__colors { grid-area: col; }
  .hero__dots   { grid-area: dot; }

  .hero__copy { gap: 24px; padding-top: 40px; }
  .hero__features { grid-template-columns: repeat(2, 1fr); column-gap: 12px; row-gap: 28px; }
}

/* 手機版架構對照 Figma 1793:189：滿版背景，標題兩行疊在上方，
   風扇壓在背景中段，副標、切色、輪播點收在背景底部。
   底圖、標題、輪播、控制列疊在 stage 同一個 grid，標題那列只負責留高度。 */
@media (max-width: 900px) {
  .hero__stage {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: 27vw auto auto;
    gap: 0;
    /* 上距 = header 底 + 20（main.js fitHeroToViewport 量），並把樣板在上面留的空白收掉 */
    padding-top: var(--hero-pad, 92px);
  }
  .hero { margin-top: calc(-1 * var(--hero-pull, 0px)); }
  .hero__bgs {
    grid-area: 1 / 1 / 4 / 2;
    width: auto;
    height: 100%;
    aspect-ratio: auto;
    margin-inline: calc(-1 * var(--gutter));
    border-radius: 0;
  }
  .hero__bg { background-size: cover; }
  .hero__title {
    left: 0; right: 0;
    top: 3vw;
    padding-inline: var(--gutter);
    font-size: 13vw;               /* 扣掉左右內距後「LINK FAN INF」放不下一行，正好斷成 LINK FAN / INF 120 */
    line-height: 1.15;
    white-space: normal;
    text-align: center;
  }
  .hero__slides { grid-area: 2 / 1; z-index: 2; }
  .hero__controls { grid-area: 3 / 1; z-index: 3; padding-bottom: 20px; }
}

@media (prefers-reduced-motion: reduce) {
  .hero__bg, .hero__slide, .dot, .swatch, .swatch::after { transition-duration: 0.01s; }
}
