﻿/* ============================================================
   前台版型：繽紛卡片
   要換顏色、圓角、陰影，只改最上面的 :root 就好
   ============================================================ */

:root {
  /* 主色：深紫，用在文字、邊框、陰影 */
  --ink: #2a1b3d;
  --surface: #fff;

  /* 背景漸層 */
  --bg: linear-gradient(135deg, #ffe66d 0%, #ff8fab 45%, #7bdff2 100%);

  /* 卡片底色，依順序輪流使用（第 7 張回到第 1 色） */
  --card-1: #fff3b0;
  --card-2: #ffd6e0;
  --card-3: #c8f2fb;
  --card-4: #d9f99d;
  --card-5: #e9d5ff;
  --card-6: #fed7aa;

  /* 卡片外框與「錯位」陰影 */
  --radius: 18px;
  --border: 3px solid var(--ink);
  --shadow-pop: 5px 5px 0 var(--ink);
  --shadow-pop-hover: 8px 8px 0 var(--ink);
}

/* ── 基本 ── */
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
/* 手機上下滑到底時不要回彈，避免露出背景以外的顏色；
   底色用漸層最上面的黃色，iPhone 狀態列（時間、訊號那一條）會跟著背景同色，不會出現一條斷層 */
html { background: #ffe66d; overscroll-behavior-y: none; }
body {
  font-family: "Noto Sans TC", system-ui, sans-serif;
  color: var(--ink);
  overflow-x: hidden;
}
/* 背景漸層：固定鋪滿整個畫面，捲動時不跟著動
   （iPhone 不支援 background-attachment: fixed，所以用一層固定的底圖代替） */
body::before { content: ""; position: fixed; inset: 0; z-index: -1; background: var(--bg); }
/* 手機點卡片時，不要出現系統預設的灰色半透明框 */
html { -webkit-tap-highlight-color: transparent; }
a { color: inherit; }

/* ── 背景漂浮的球 ── */
.balls { position: fixed; inset: 0; z-index: 0; pointer-events: none; }
.balls .ball { position: absolute; opacity: 0.85; animation: float 9s ease-in-out infinite; }
.balls .ball:nth-child(1) { left: 6%;   top: 14%;    width: 54px; }
.balls .ball:nth-child(2) { right: 8%;  top: 30%;    width: 38px; animation-delay: -3s; }
.balls .ball:nth-child(3) { left: 12%;  bottom: 12%; width: 30px; animation-delay: -6s; }
.balls .ball:nth-child(4) { right: 14%; bottom: 8%;  width: 64px; animation-delay: -1.5s; }
/* 第 5 顆：在 logo 右側偏上（畫面中線往右 170px、離頂端 85px），跟其他球一樣上下飄 */
.balls .ball.spin { left: calc(50% + 170px); top: 85px; width: 44px; animation-delay: -4.5s; }
@keyframes float {
  0%, 100% { transform: translateY(0) rotate(0deg); }
  50%      { transform: translateY(-26px) rotate(180deg); }
}

/* ── 版面 ── */
/* env(safe-area-inset-*)：iPhone 瀏海、狀態列、底部橫條佔掉的空間，電腦上是 0 */
main { position: relative; z-index: 1; max-width: 560px; margin: 0 auto;
       padding: calc(40px + env(safe-area-inset-top)) 16px calc(32px + env(safe-area-inset-bottom)); }

/* ── 標題區 ── */
.profile { text-align: center; margin-bottom: 28px; }
/* 盾牌 logo 在中間 */
.logo { width: 210px; margin: 0 auto 14px; }   /* logo 大小（電腦版） */
.logo img { display: block; width: 100%; height: auto; filter: drop-shadow(4px 5px 0 var(--ink)); }

/* ── 標題「匹克球館」：SVG 立體貼紙字，樣式寫在 index.html 的 <svg> 裡 ──
   這裡只管大小：寬度跟著螢幕縮放，最大 320px */
.title { margin: 30px auto 0; line-height: 0; }
.title svg { display: block; width: 100%; max-width: 320px; height: auto; margin: 30px auto 0; overflow: visible; user-select: none; }
.tagline { margin: 10px 0 0; opacity: 0.75; }

/* ── 連結卡片 ── */
.links { list-style: none; margin: 20px 0 0; padding: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.links li { display: flex; }     /* 卡片撐滿格子，同一排左右等高，不會一邊空出一塊 */
.links li .link { flex: 1; }
.link {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px;
  min-height: 130px; padding: 14px 18px;
  text-align: center; text-decoration: none;
  background: var(--surface); color: var(--ink);
  border: var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow-pop);
  transition: transform 0.18s, box-shadow 0.18s;
}
.link:hover, .link:focus-visible { transform: translate(-3px, -3px) rotate(-1deg); box-shadow: var(--shadow-pop-hover); outline: none; }
/* 按下去的手感：卡片往陰影方向壓下（手機沒有 hover，靠這個回饋） */
.link:active { transform: translate(3px, 3px); box-shadow: 2px 2px 0 var(--ink); transition-duration: 0.06s; }
.link .icon { font-size: 34px; line-height: 1; }
.link .icon.loading { visibility: hidden; }
.link .icon .emoji { display: block; width: 1em; height: 1em; }   /* 圖片和文字 emoji 一樣大 */
.link .icon .svg { width: 1.4em; height: 1.4em; }   /* 自己畫的 SVG 圖示稍微大一點，跟 emoji 視覺上差不多 */
/* 換行只發生在空白處（「社群」不會被拆成兩行），並讓兩行長度平均；
   單一個詞真的太長時，才在字中間斷開 */
.link .label { font-weight: 700; font-size: 16px; word-break: keep-all; overflow-wrap: anywhere; text-wrap: balance; }
.link.empty { opacity: 0.45; pointer-events: none; }

.links li:nth-child(6n+1) .link { background: var(--card-1); }
.links li:nth-child(6n+2) .link { background: var(--card-2); }
.links li:nth-child(6n+3) .link { background: var(--card-3); }
.links li:nth-child(6n+4) .link { background: var(--card-4); }
.links li:nth-child(6n+5) .link { background: var(--card-5); }
.links li:nth-child(6n+6) .link { background: var(--card-6); }

/* ── 最後一張「落單」的卡片：橫跨整排，改成橫式（圖示在左、文字在右），高度矮一點 ──
   兩欄時：卡片總數是單數 → 最後一張落單；三欄時：總數除以 3 餘 1 → 最後一張落單
   卡片數量改了也會自動判斷，不用改這裡 */
@media (min-width: 341px) and (max-width: 899px) {
  .links li:last-child:nth-child(odd) { grid-column: 1 / -1; }
  .links li:last-child:nth-child(odd) .link { flex-direction: row; gap: 12px; min-height: 64px; padding: 10px 20px; }
}
@media (min-width: 900px) {
  .links li:last-child:nth-child(3n+1) { grid-column: 1 / -1; }
  .links li:last-child:nth-child(3n+1) .link { flex-direction: row; gap: 14px; min-height: 84px; padding: 14px 24px; }
  .links li:last-child:nth-child(3n+1) .link .label { font-size: 18px; }
}

footer { text-align: center; margin-top: 36px; font-size: 13px; opacity: 0.55; }

/* ── 螢幕寬度 ── */
@media (min-width: 900px) {
  main { max-width: 820px; }
  .links { grid-template-columns: repeat(3, 1fr); }
}
/* 手機版：整頁盡量濃縮在一個畫面內，不用往下捲 */
/* 手機版：照「直接用瀏覽器開」的可視高度安排（Safari、LINE 內建瀏覽器上下都有工具列，
   實際只剩螢幕約 80%）。目前 6 張卡片 → 第一眼就看完整頁，最下排離底部工具列還有留白 */
@media (max-width: 600px) {
  main { min-height: 100dvh;   /* dvh：會扣掉瀏覽器工具列的真實可視高度 */
         padding: calc(12px + env(safe-area-inset-top)) 14px calc(24px + env(safe-area-inset-bottom)); }
         /* 底部 24px + iPhone 底部橫條的安全區；多出來的高度都給卡片，不再留一大塊空白 */
  /* 依螢幕高度自動撐滿：以 iPhone 16 Pro 為準，螢幕比較高的手機（16 Pro Max）
     卡片會跟著變高、logo 跟著變大，下面不會空一大塊 */
  main { display: flex; flex-direction: column; }
  .links { flex: 1; }   /* 卡片區吃掉剩下的高度，每一排平均分 */
  .profile { margin-bottom: 0; }
  .logo { width: clamp(160px, 23dvh, 210px); margin-bottom: 0; }   /* logo 大小（手機版）：跟著螢幕高度，最小 160、最大 210 */
  .balls .ball.spin { left: auto; right: 8%; top: 40px; width: 34px; }   /* 手機：靠右邊、logo 中段偏上 */
  .title svg { margin-top: 6px; max-width: 260px; }   /* 標題跟 logo 的距離、標題大小 */
  .tagline { margin-top: 2px; font-size: 13px; }
  .links { margin-top: 12px; gap: 10px; }
  .link { min-height: 90px; padding: 12px 8px; gap: 6px; }   /* 卡片高度、內距 */
  .link .icon { font-size: 30px; }
  .link .label { font-size: 17px; line-height: 1.35; }   /* 卡片文字大小 */
  footer { margin-top: 14px; }
}
/* 一般 iPhone（375–430px 寬）：兩側留白再收一點 */
@media (max-width: 430px) {
  main { padding-left: 12px; padding-right: 12px; }
}
@media (max-width: 340px) {
  .links { grid-template-columns: 1fr; }
}

/* ── 彈出公告（js/popup.js）── */
.popup {
  position: fixed; inset: 0; z-index: 100;
  display: flex; align-items: center; justify-content: center;
  padding: calc(24px + env(safe-area-inset-top)) 18px calc(24px + env(safe-area-inset-bottom));
  background: rgba(42, 27, 61, 0.6);   /* 後面頁面變暗 */
  animation: popup-in 0.2s ease-out;
}
@keyframes popup-in { from { opacity: 0; } }
body.popup-open { overflow: hidden; }
.popup-box {
  position: relative; width: min(100%, 560px);
  background: var(--surface); border: var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow-pop); padding: 10px;
}
/* 圖片列：左右滑動，每次停在一整張 */
.popup-track {
  display: flex; overflow-x: auto; scroll-snap-type: x mandatory;
  border-radius: calc(var(--radius) - 8px);
  scrollbar-width: none;
}
.popup-track::-webkit-scrollbar { display: none; }
.popup-slide { flex: 0 0 100%; scroll-snap-align: center; display: block; }
.popup-slide img {
  display: block; width: 100%; height: auto;
  max-height: calc(100dvh - 120px); object-fit: contain;   /* 直式長圖也不會超出畫面 */
}
/* 關閉按鈕：右上角的圓形 × */
.popup-close {
  position: absolute; top: -16px; right: -16px; z-index: 2;
  width: 40px; height: 40px; border-radius: 50%;
  border: var(--border); background: var(--surface); color: var(--ink);
  font-size: 26px; line-height: 1; cursor: pointer; box-shadow: 3px 3px 0 var(--ink);
}
/* 左右箭頭（電腦用；手機直接用手指滑） */
.popup-nav {
  position: absolute; top: 50%; transform: translateY(-50%); z-index: 1;
  width: 40px; height: 40px; border-radius: 50%;
  border: var(--border); background: var(--surface); color: var(--ink);
  font-size: 28px; line-height: 1; cursor: pointer;
}
.popup-nav.prev { left: -14px; }
.popup-nav.next { right: -14px; }
.popup-nav.off { visibility: hidden; }
@media (hover: none) { .popup-nav { display: none; } }
/* 下方圓點：目前在第幾張 */
.popup-dots { display: flex; justify-content: center; gap: 8px; padding-top: 10px; }
.popup-dots button {
  width: 10px; height: 10px; padding: 0; border-radius: 50%;
  border: 2px solid var(--ink); background: transparent; cursor: pointer;
}
.popup-dots button.active { background: var(--ink); }

/* 只放 <symbol> 圖形定義的隱藏 svg（不寫在 HTML 的 style=""，因為 CSP 不允許行內樣式） */
.svg-defs { position: absolute; width: 0; height: 0; overflow: hidden; }

/* 短暫提示（例如「目前沒有優惠活動」） */
.toast {
  position: fixed; left: 50%; bottom: calc(28px + env(safe-area-inset-bottom)); z-index: 110;
  transform: translateX(-50%); max-width: calc(100% - 32px);
  padding: 10px 18px; border: var(--border); border-radius: 999px;
  background: var(--surface); color: var(--ink); font-weight: 700; box-shadow: 3px 3px 0 var(--ink);
  animation: popup-in 0.2s ease-out;
}

/* ── 系統設定「減少動態效果」時，不播動畫 ── */
@media (prefers-reduced-motion: reduce) {
  .balls .ball, .popup { animation: none; }
  .link { transition: none; }
  .link:hover, .link:focus-visible, .link:active { transform: none; }
}
