/* 元件（D01 第 4 節） */

/* ════════════ 導覽列 ════════════ */
#site-header { min-height: var(--nav-h); }            /* JS 注入前先保留高度，避免版面跳動 */
.site-header {
  position: sticky;
  top: 0;
  z-index: 100;
  container-type: inline-size;                         /* 用容器寬度判斷手機版，styleguide 示範框也適用 */
  transition: background-color var(--t-micro) var(--ease), box-shadow var(--t-micro) var(--ease);
}
.site-header.is-scrolled {
  background: rgb(247 245 240 / .9);                   /* --paper 90% */
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  box-shadow: 0 1px 0 var(--line);
}
.site-header.is-open { background: var(--paper); }
.nav {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-4);
  height: var(--nav-h);
}
.nav__logo { display: block; flex: none; border-radius: var(--r-sm); }
.nav__logo img { width: 140px; height: auto; }
.nav__list {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  list-style: none;
  padding: 0;
}
.nav__link {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding-inline: var(--sp-3);
  border-radius: var(--r-pill);
  color: var(--ink);
  font-family: var(--font-display);
  font-weight: var(--nav-weight);
  letter-spacing: .04em;
  text-decoration: none;
  transition: color var(--t-micro) var(--ease), background-color var(--t-micro) var(--ease);
}
.nav__link:hover, .nav__link:active { color: var(--brand-dark); background: var(--brand-tint); }
.nav__link[aria-current="page"] {
  color: var(--brand-dark);
  text-decoration: underline;
  text-decoration-thickness: 2px;
  text-underline-offset: .45em;
}
.nav__toggle {
  display: none;
  width: 44px;
  height: 44px;
  margin-right: -10px;
  padding: 0;
  border: 0;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--ink);
}
.nav__toggle svg { width: 24px; height: 24px; margin: auto; }
.nav__toggle .i-close { display: none; }
.nav__toggle[aria-expanded="true"] .i-menu { display: none; }
.nav__toggle[aria-expanded="true"] .i-close { display: block; }

@container (max-width: 768px) {
  .nav__toggle { display: block; }
  .nav__panel {
    position: absolute;
    top: 100%;
    left: calc(var(--gutter) * -1);
    right: calc(var(--gutter) * -1);
    padding: var(--sp-2) var(--gutter) var(--sp-5);
    background: var(--paper);
    border-bottom: var(--border);
    box-shadow: var(--shadow);
  }
  .nav__panel:not(.is-open) { display: none; }
  .nav__list { flex-direction: column; align-items: stretch; gap: 0; }
  .nav__list li + li { border-top: var(--border); }
  .nav__link {
    width: 100%;
    min-height: 56px;
    padding-inline: var(--sp-2);
    border-radius: 0;
    font-size: 1.125rem;
  }
  .nav__link:hover, .nav__link:active { background: transparent; }
}

/* ════════════ 按鈕 ════════════ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  min-height: 44px;
  padding: 0 var(--sp-5);
  border: 1px solid transparent;
  border-radius: var(--r-pill);
  font-size: 1rem;
  font-weight: 700;
  line-height: 1;
  letter-spacing: .04em;
  text-decoration: none;
  white-space: nowrap;
  transition: background-color var(--t-micro) var(--ease), color var(--t-micro) var(--ease),
              border-color var(--t-micro) var(--ease);
}
.btn svg { width: 18px; height: 18px; flex: none; }
/* 對比修正（review 2026-11-06）：白字於 --brand 只有 3.5:1，改用 --brand-dark 底（4.95:1） */
.btn--primary { background: var(--brand-dark); color: var(--white); }
.btn--primary:hover, .btn--primary:active { background: var(--ink); color: var(--white); }
.btn--ghost { background: transparent; color: var(--brand-dark); border-color: var(--brand-dark); }
.btn--ghost:hover, .btn--ghost:active { color: var(--ink); border-color: var(--ink); }

/* ════════════ 標籤 ════════════ */
.tag {
  display: inline-flex;
  align-items: center;
  padding: .125rem .625rem;
  border-radius: var(--r-pill);
  background: var(--brand-tint);
  color: var(--ink);
  font-size: .8125rem;          /* 13px */
  font-weight: 700;
  line-height: 1.6;
  letter-spacing: .04em;
  white-space: nowrap;
}

/* ════════════ 書卡 ════════════ */
.book-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 240px), 1fr));
  gap: var(--sp-5);
  list-style: none;
  padding: 0;
}
.book-card {
  display: flex;
  flex-direction: column;
  height: 100%;
  border: var(--border);
  border-radius: var(--r-md);
  background: var(--white);
  color: var(--ink);
  text-decoration: none;
  transition: box-shadow var(--t-micro) var(--ease);
}
.book-card:hover, .book-card:active { color: var(--ink); box-shadow: var(--shadow); }
.book-card__cover {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 300px;                /* 書封統一視覺高度 260px＋上下留白 */
  padding: 20px var(--sp-4);
}
.book-card__cover img {
  height: 260px;
  width: auto;
  max-width: 100%;
  object-fit: contain;
  transition: transform var(--t-micro) var(--ease), filter var(--t-micro) var(--ease);
}
.book-card:hover .book-card__cover img,
.book-card:active .book-card__cover img,
.book-card:focus-visible .book-card__cover img {
  transform: translateY(-6px) rotate(-1.5deg);
  filter: drop-shadow(var(--shadow));
}
.book-card__body {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: var(--sp-2);
  padding: var(--sp-4) var(--sp-5) var(--sp-5);
  border-top: var(--border);
  flex: 1;
}
/* 卡片寬約 240px，書名最長 8 字：用比 h3 小一級的字級，避免被拆成兩行 */
.book-card__title { font-size: clamp(1.125rem, 1.07rem + .22vw, 1.375rem); text-wrap: pretty; }
.book-card__credit { color: var(--ink-soft); font-size: var(--fs-small); line-height: 1.6; }
.book-card__price { margin-top: auto; font-weight: 700; font-size: var(--fs-small); }

/* ════════════ 區塊標題 ════════════ */
.section-head { margin-bottom: var(--sp-6); }
.section-title {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
}
.section-title::before {
  content: "";
  flex: none;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--brand);
}
.section-sub {
  margin-top: var(--sp-2);
  padding-left: calc(12px + var(--sp-3));
  color: var(--ink-soft);
}

/* ════════════ 頁尾 ════════════ */
.site-footer {
  background: var(--ink);
  color: var(--white);
  font-size: var(--fs-small);
}
.site-footer a { color: var(--white); }
.site-footer a:hover, .site-footer a:active { color: var(--brand-tint); }
.site-footer :focus-visible { outline-color: var(--white); }
.footer {
  display: grid;
  gap: var(--sp-5);
  padding-block: var(--sp-7);
}
.footer__brand { display: flex; align-items: center; gap: var(--sp-3); }
.footer__brand img { width: 48px; height: 48px; }
.footer__name { font-family: var(--font-display); font-weight: var(--display-weight); font-size: 1.125rem; letter-spacing: .04em; }
.footer__meta { display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-2) var(--sp-5); }
.footer__copy { color: rgb(255 255 255 / .75); }
@media (min-width: 768px) {
  .footer { grid-template-columns: 1fr auto; align-items: center; }
  .footer__copy { grid-column: 1 / -1; }
}

.social { display: flex; gap: var(--sp-3); list-style: none; padding: 0; }
.social a {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: rgb(255 255 255 / .12);
  color: var(--white);
  transition: background-color var(--t-micro) var(--ease);
}
.social a:hover, .social a:active { background: var(--brand); color: var(--white); }
.social svg { width: 22px; height: 22px; fill: currentColor; }

/* ════════════ 彩蛋標記 ════════════ */
.egg { position: relative; display: inline-block; }
.egg__btn {
  position: relative;
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--brand);
  color: var(--white);
}
/* 觸控目標補到 44px，視覺仍是 28px */
.egg__btn::before { content: ""; position: absolute; inset: -8px; border-radius: 50%; }
.egg__btn::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 2px solid var(--brand);
  animation: egg-breathe 1.6s var(--ease) infinite;
  pointer-events: none;
}
.egg__btn svg { width: 16px; height: 16px; }
.egg__btn:hover, .egg__btn:active, .egg__btn[aria-expanded="true"] { background: var(--brand-dark); }
@keyframes egg-breathe {
  0%   { transform: scale(1);   opacity: .7; }
  70%  { transform: scale(1.7); opacity: 0; }
  100% { transform: scale(1.7); opacity: 0; }
}
.egg__pop {
  position: absolute;
  z-index: 20;
  bottom: calc(100% + 12px);
  left: 50%;
  translate: calc(-50% + var(--egg-shift, 0px)) 0;   /* --egg-shift 由 motion.js 計算，避免超出視窗 */
  width: min(260px, 80vw);
  padding: var(--sp-3);
  border: var(--border);
  border-radius: var(--r-md);
  background: var(--white);
  box-shadow: var(--shadow);
  color: var(--ink);
  text-align: start;
}
.egg__pop img { width: 100%; height: auto; border-radius: var(--r-sm); margin-bottom: var(--sp-2); background: var(--cats-paper); }
.egg__title { font-size: 1rem; font-weight: 700; line-height: 1.4; }
.egg__text { margin-top: var(--sp-1); font-size: var(--fs-small); line-height: 1.6; color: var(--ink-soft); }

/* ════════════ 探頭貓 ════════════ */
.peek-host { position: relative; overflow: hidden; }
.peek {
  position: absolute;
  z-index: 1;
  width: var(--peek-w, 96px);
  height: auto;
  pointer-events: none;
  transition: transform var(--t-enter) var(--ease);
}
/* 進入視窗前往邊外多藏 --peek-dist，進入後回到定位（＝探出 8–16px） */
.peek--top    { top: 0;    transform: translateY(calc(-1 * var(--peek-dist, 12px))); }
.peek--bottom { bottom: 0; transform: translateY(var(--peek-dist, 12px)); }
.peek--left   { left: 0;   transform: translateX(calc(-1 * var(--peek-dist, 12px))); }
.peek--right  { right: 0;  transform: translateX(var(--peek-dist, 12px)); }
.peek.is-peeking { transform: none; }

/* ════════════ 浮動粒子（書頁用，每組 ≤ 12 個） ════════════ */
.particles {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
}
.particles > span {
  position: absolute;
  border-radius: 50%;
  width: var(--s);
  height: var(--s);
  left: var(--x);
}
/* 國王頁：泡泡，緩慢上升 */
.particles--bubbles > span {
  bottom: calc(var(--s) * -1);
  background: rgb(255 255 255 / .28);
  border: 1px solid rgb(255 255 255 / .6);
  animation: bubble-rise var(--d) linear var(--delay) infinite;
}
@keyframes bubble-rise {
  0%   { transform: translate(0, 0);                opacity: 0; }
  10%  { opacity: 1; }
  50%  { transform: translate(12px, -55cqh); }
  90%  { opacity: 1; }
  100% { transform: translate(-8px, calc(-100cqh - 100%)); opacity: 0; }
}
.particles--bubbles { container-type: size; }
/* 鼻屎頁：綠點，隨機漂移 */
.particles--dots > span {
  top: var(--y);
  background: var(--booger-accent);
  opacity: .85;
  animation: dot-drift var(--d) ease-in-out var(--delay) infinite alternate;
}
@keyframes dot-drift {
  0%   { transform: translate(0, 0); }
  50%  { transform: translate(10px, -14px); }
  100% { transform: translate(-12px, 8px); }
}
/* 12 個粒子的位置、大小、速度（純 CSS，不需 JS 產生） */
.particles > span:nth-child(1)  { --x: 6%;  --y: 18%; --s: 22px; --d: 14s; --delay: -2s; }
.particles > span:nth-child(2)  { --x: 15%; --y: 72%; --s: 10px; --d: 11s; --delay: -7s; }
.particles > span:nth-child(3)  { --x: 24%; --y: 40%; --s: 34px; --d: 18s; --delay: -11s; }
.particles > span:nth-child(4)  { --x: 33%; --y: 86%; --s: 14px; --d: 12s; --delay: -4s; }
.particles > span:nth-child(5)  { --x: 42%; --y: 12%; --s: 26px; --d: 16s; --delay: -9s; }
.particles > span:nth-child(6)  { --x: 51%; --y: 58%; --s: 8px;  --d: 10s; --delay: -1s; }
.particles > span:nth-child(7)  { --x: 60%; --y: 30%; --s: 40px; --d: 20s; --delay: -14s; }
.particles > span:nth-child(8)  { --x: 68%; --y: 78%; --s: 12px; --d: 13s; --delay: -6s; }
.particles > span:nth-child(9)  { --x: 76%; --y: 22%; --s: 20px; --d: 15s; --delay: -3s; }
.particles > span:nth-child(10) { --x: 83%; --y: 64%; --s: 30px; --d: 17s; --delay: -12s; }
.particles > span:nth-child(11) { --x: 90%; --y: 44%; --s: 9px;  --d: 11s; --delay: -8s; }
.particles > span:nth-child(12) { --x: 95%; --y: 88%; --s: 16px; --d: 14s; --delay: -5s; }
.particles > span:nth-child(n+13) { display: none; }

/* ════════════ 減少動態 ════════════ */
@media (prefers-reduced-motion: reduce) {
  .egg__btn::after { animation: none; transform: scale(1.35); opacity: .35; }   /* 光環靜止 */
  .particles > span { animation: none !important; }
  .particles--bubbles > span { bottom: auto; top: var(--y); }                  /* 泡泡停在畫面內 */
  .peek, .peek.is-peeking { transform: none; }
  .book-card:hover .book-card__cover img,
  .book-card:active .book-card__cover img,
  .book-card:focus-visible .book-card__cover img { transform: none; }
}

/* ═════════════════════════════════════════════════════════
   T04 首頁新增元件
   ═════════════════════════════════════════════════════════ */

/* ════════════ 主視覺 hero ════════════
   只有場景圖與彩蛋，不放文字卡（T04b）。版面三段：
   - ≤ 768px：場景高 70svh、可橫向捲動（彩蛋小卡固定在螢幕底部）
   - 769–1199px：場景整張等比顯示（不裁切）
   - ≥ 1200px：場景滿版、高度 --hero-h，等同 object-fit: cover 裁切
   場景與彩蛋放在同一個 .hero__stage 裡，彩蛋以圖片百分比定位，隨圖縮放。 */
.hero { position: relative; background: var(--paper-2); }
.hero__viewport { position: relative; }
.hero__stage { position: relative; width: 100%; aspect-ratio: 2400 / 1390; }
.hero__stage > img,
.hero__stage > picture img { display: block; width: 100%; height: 100%; max-width: none; object-fit: cover; }
/* 彩蛋中心點對準座標（不用 transform，避免手機版 fixed 小卡失去視窗定位） */
.hero__stage .egg { position: absolute; z-index: 2; margin: -14px 0 0 -14px; }
/* 靠近上緣的彩蛋，小卡往下開 */
.egg--below .egg__pop { bottom: auto; top: calc(100% + 12px); }

.scroll-hint { display: none; }

@media (max-width: 768px) {
  .hero__scroller {
    overflow-x: auto;
    overflow-y: hidden;
    overscroll-behavior-x: contain;
    -webkit-overflow-scrolling: touch;
  }
  .hero__stage { --stage-h: 70vh; width: calc(var(--stage-h) * 2400 / 1390); height: var(--stage-h); aspect-ratio: auto; }
  @supports (height: 1svh) { .hero__stage { --stage-h: 70svh; } }
  .scroll-hint {
    display: block;
    position: absolute;
    left: 50%;
    bottom: var(--sp-3);
    translate: -50% 0;   /* 置中：右下角會蓋到告示牌彩蛋 */
    z-index: 3;
    padding: .25rem .75rem;
    border-radius: var(--r-pill);
    background: var(--ink);
    color: var(--white);
    font-size: .8125rem;
    font-weight: 700;
    letter-spacing: .06em;
    pointer-events: none;
    transition: opacity var(--t-enter) var(--ease);
  }
  .hero__scroller.is-scrolled ~ .scroll-hint { opacity: 0; }
  /* 手機：彩蛋小卡固定在螢幕底部，不跟著橫向捲動 */
  .hero .egg__pop {
    position: fixed;
    z-index: 150;
    left: var(--gutter);
    right: var(--gutter);
    top: auto;
    bottom: var(--gutter);
    width: auto;
    translate: none;
    display: grid;
    grid-template-columns: 96px 1fr;
    column-gap: var(--sp-3);
    align-items: start;
  }
  .hero .egg__pop img { grid-row: span 2; width: 96px; margin: 0; }
}

@media (min-width: 1200px) {
  .hero { --hero-h: max(min(78vh, 720px), 100vw / 2.1); }   /* 下限讓寬螢幕至少看到 82% 畫面，三個彩蛋都在框內 */
  .hero__viewport { height: var(--hero-h); overflow: hidden; container-type: size; }
  /* 等同 object-fit: cover，但讓彩蛋跟著同一個座標系 */
  .hero__stage {
    --sw: max(100cqw, 100cqh * 2400 / 1390);
    position: absolute;
    width: var(--sw);
    height: calc(var(--sw) * 1390 / 2400);
    aspect-ratio: auto;
    left: calc((100cqw - var(--sw)) * var(--fx, .2));
    top: calc((100cqh - var(--sw) * 1390 / 2400) * var(--fy, .55));
  }
}

/* ════════════ 書架 ════════════ */
.shelf + .shelf { margin-top: var(--sp-7); }
.shelf__head { margin-bottom: var(--sp-4); }
/* 首頁書架固定最多 3 欄（auto-fill 保留空欄，讓加寬卡維持跨兩欄） */
.book-grid--shelf { grid-template-columns: repeat(auto-fill, minmax(min(100%, 280px), 1fr)); }
.book-card__tags { display: flex; flex-wrap: wrap; gap: var(--sp-1) var(--sp-2); }
/* 首頁書名用 h4（h3 是系列名），字體比照標題 */
h4.book-card__title { font-family: var(--font-display); font-weight: var(--display-weight); letter-spacing: var(--display-tracking); line-height: var(--lh-heading); }

/* 加寬書卡（找找看遊戲書）：手機直排，≥ 640px 跨兩欄、左圖右文 */
.book-card--wide .book-card__cover { height: auto; padding: var(--sp-5) var(--sp-5) 0; }
.book-card--wide .book-card__cover img { width: 100%; max-width: 340px; height: auto; }
.book-card__title-img { display: block; width: min(100%, 240px); height: auto; }
@media (min-width: 640px) {
  .book-grid__wide { grid-column: span 2; }
  .book-card--wide { flex-direction: row; }
  .book-card--wide .book-card__cover { flex: 0 0 46%; padding: var(--sp-5); }
  .book-card--wide .book-card__body { justify-content: center; border-top: 0; border-left: var(--border); }
}

@media (prefers-reduced-motion: reduce) {
  .scroll-hint { transition: none; }
}

/* ════════════ 404 ════════════ */
.not-found { text-align: center; }
.not-found img { width: min(200px, 50vw); height: auto; margin: 0 auto var(--sp-5); }
.not-found h1 { margin-bottom: var(--sp-5); }
