/* ============================================================
   風格模板庫 · 平台樣式（首頁 + 預覽頁共用）
   低調深灰底、單一強調色、一套無襯線字，把舞台讓給模板
   ============================================================ */

:root {
  --bg: #151515;
  --bg-raised: #1d1d1d;
  --bg-hover: #262626;
  --line: #2e2e2e;
  --line-strong: #444;
  --text: #ececea;
  --text-muted: #9b9b97;
  --text-faint: #6c6c69;
  --accent: #ff6a3d;
  --accent-ink: #160b06;
  --radius: 14px;
  --gutter: clamp(16px, 4vw, 48px);
  --maxw: 1440px;
  --ease: cubic-bezier(.2, .7, .1, 1);
  --font: "Inter", -apple-system, BlinkMacSystemFont, "Helvetica Neue", "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", sans-serif;
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
img { display: block; max-width: 100%; }
a { color: inherit; }
button { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 6px; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.skip-link {
  position: absolute; left: 12px; top: -60px; z-index: 10;
  background: var(--accent); color: var(--accent-ink); padding: 8px 14px; border-radius: 8px;
  text-decoration: none; font-weight: 600;
}
.skip-link:focus { top: 12px; }

/* ---------- 首頁 ---------- */
.site-head {
  max-width: var(--maxw); margin: 0 auto;
  padding: 20px var(--gutter);
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
}
.wordmark {
  font-weight: 600; letter-spacing: .02em; font-size: 15px; text-decoration: none;
  display: inline-flex; align-items: center; gap: 10px;
}
.wordmark::before {
  content: ""; width: 10px; height: 10px; border-radius: 50%; background: var(--accent);
}
.site-head__meta { color: var(--text-muted); font-size: 13px; }

.intro {
  max-width: var(--maxw); margin: 0 auto;
  padding: clamp(48px, 12vh, 140px) var(--gutter) clamp(40px, 8vh, 96px);
}
.intro__eyebrow {
  color: var(--text-muted); font-size: 13px; letter-spacing: .14em; text-transform: uppercase; margin: 0 0 20px;
}
.intro__title {
  margin: 0; max-width: 17em;
  font-size: clamp(32px, 5.4vw, 76px); line-height: 1.12; font-weight: 600; letter-spacing: -.02em;
  text-wrap: balance;
}
.intro__title em { font-style: normal; color: var(--accent); }
.nb { display: inline-block; }
.intro__row {
  margin-top: clamp(28px, 5vh, 48px);
  display: flex; flex-wrap: wrap; align-items: center; gap: 20px 32px;
}
.btn {
  display: inline-flex; align-items: center; gap: 10px;
  min-height: 48px; padding: 0 22px; border-radius: 999px;
  border: 1px solid transparent; cursor: pointer; text-decoration: none;
  font-size: 15px; font-weight: 600;
  transition: background-color .25s var(--ease), border-color .25s var(--ease), transform .25s var(--ease);
}
.btn--primary { background: var(--accent); color: var(--accent-ink); }
.btn--primary:hover { background: #ff835e; }
.btn--ghost { border-color: var(--line-strong); background: transparent; }
.btn--ghost:hover { background: var(--bg-hover); }
.btn svg { width: 16px; height: 16px; flex: none; }
.steps {
  list-style: none; margin: 0; padding: 0;
  display: flex; flex-wrap: wrap; gap: 8px 24px; color: var(--text-muted); font-size: 14px;
}
.steps li { display: flex; gap: 8px; align-items: baseline; }
.steps b { color: var(--text-faint); font-weight: 500; font-variant-numeric: tabular-nums; }

/* 篩選列 */
.library { max-width: var(--maxw); margin: 0 auto; padding: 0 var(--gutter) 96px; scroll-margin-top: 16px; }
.filters {
  border-top: 1px solid var(--line);
  padding: 24px 0 8px;
  display: grid; gap: 14px;
}
.filter-group { display: grid; grid-template-columns: 56px 1fr; gap: 12px; align-items: start; border: 0; margin: 0; padding: 0; min-width: 0; }
.filter-group legend { float: left; padding: 0; }
.filter-group__label { color: var(--text-muted); font-size: 13px; padding-top: 7px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  min-height: 36px; padding: 0 14px; border-radius: 999px;
  background: transparent; border: 1px solid var(--line-strong); color: var(--text);
  font-size: 14px; cursor: pointer;
  display: inline-flex; align-items: center; gap: 6px;
  transition: background-color .2s var(--ease), border-color .2s var(--ease), color .2s var(--ease);
}
.chip:hover { background: var(--bg-hover); }
.chip[aria-pressed="true"] { background: var(--text); border-color: var(--text); color: var(--bg); }
.chip__count { color: var(--text-faint); font-size: 12px; font-variant-numeric: tabular-nums; }
.chip[aria-pressed="true"] .chip__count { color: #555; }
.result-bar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 16px 0 24px; color: var(--text-muted); font-size: 14px; min-height: 68px;
}
@media (max-width: 479px) {
  .filter-group { grid-template-columns: 1fr; gap: 8px; }
  .filter-group__label { padding-top: 0; }
}
.link-btn {
  background: none; border: 0; padding: 6px 0; cursor: pointer; color: var(--text);
  text-decoration: underline; text-underline-offset: 4px; text-decoration-color: var(--line-strong);
  font-size: 14px;
}
.link-btn:hover { text-decoration-color: var(--accent); }

/* 模板牆 */
.grid {
  display: grid; gap: clamp(28px, 3vw, 40px) clamp(16px, 2vw, 28px);
  grid-template-columns: 1fr;
}
@media (min-width: 640px) { .grid { grid-template-columns: repeat(2, 1fr); } }
@media (min-width: 1024px) { .grid { grid-template-columns: repeat(3, 1fr); } }

.card { display: block; text-decoration: none; color: inherit; border-radius: var(--radius); }
.card:focus-visible { outline-offset: 6px; }
.card__media {
  position: relative; aspect-ratio: 16 / 10; overflow: hidden;
  border-radius: var(--radius); background: var(--bg-raised);
  isolation: isolate;
}
.card__media img {
  width: 100%; height: 100%; object-fit: cover;
  transition: transform .9s var(--ease);
}
.card__media::after { /* 細邊，讓亮色縮圖在深底上收得住 */
  content: ""; position: absolute; inset: 0; border-radius: inherit;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.06); pointer-events: none;
}
@media (hover: hover) {
  .card:hover .card__media img { transform: scale(1.045); }
  .card:hover .card__cta { opacity: 1; transform: none; }
}
.card:focus-visible .card__media img { transform: scale(1.045); }
.card__cta {
  position: absolute; right: 14px; bottom: 14px; z-index: 1;
  background: rgba(15,15,15,.78); color: #fff; font-size: 13px; font-weight: 600;
  padding: 8px 14px; border-radius: 999px;
  -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px);
  opacity: 0; transform: translateY(6px);
  transition: opacity .35s var(--ease), transform .35s var(--ease);
}
.card:focus-visible .card__cta { opacity: 1; transform: none; }
@media (hover: none) { .card__cta { display: none; } }
.card__head { display: flex; align-items: baseline; gap: 12px; margin-top: 16px; }
.card__num { color: var(--text-faint); font-size: 13px; font-variant-numeric: tabular-nums; }
.card__name { margin: 0; font-size: 19px; font-weight: 600; letter-spacing: -.005em; line-height: 1.3; }
.card__tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; padding: 0; list-style: none; }
.card__tags li {
  font-size: 12px; color: var(--text-muted);
  border: 1px solid var(--line); border-radius: 999px; padding: 2px 10px;
}
.card__highlight { margin: 10px 0 0; color: var(--text-muted); font-size: 14px; line-height: 1.6; }

.card { animation: card-in .5s var(--ease) both; }
@keyframes card-in { from { opacity: 0; transform: translateY(10px); } }

.empty, .load-error {
  border: 1px dashed var(--line-strong); border-radius: var(--radius);
  padding: clamp(40px, 8vw, 80px) 24px; text-align: center;
}
.empty h2, .load-error h2 { margin: 0 0 8px; font-size: 20px; font-weight: 600; }
.empty p, .load-error p { margin: 0 0 24px; color: var(--text-muted); font-size: 14px; }

.site-foot {
  max-width: var(--maxw); margin: 0 auto; padding: 32px var(--gutter) 48px;
  border-top: 1px solid var(--line); color: var(--text-faint); font-size: 13px;
  display: flex; flex-wrap: wrap; justify-content: space-between; gap: 8px;
}

/* ---------- 預覽頁 ---------- */
.pv { height: 100vh; height: 100dvh; display: flex; flex-direction: column; overflow: hidden; }
.pv-bar {
  flex: none; height: 60px; padding: 0 12px;
  display: flex; align-items: center; gap: 8px;
  border-bottom: 1px solid var(--line); background: var(--bg);
  position: relative; z-index: 2;
}
.pv-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 40px; min-width: 40px; padding: 0 14px; border-radius: 10px;
  border: 1px solid transparent; background: transparent; color: var(--text);
  font-size: 14px; font-weight: 500; text-decoration: none; cursor: pointer; white-space: nowrap;
  transition: background-color .2s var(--ease), border-color .2s var(--ease);
}
.pv-btn:hover { background: var(--bg-hover); }
.pv-btn svg { width: 18px; height: 18px; flex: none; }
.pv-btn--outline { border-color: var(--line-strong); }
.pv-btn--accent { background: var(--accent); color: var(--accent-ink); font-weight: 600; }
.pv-btn--accent:hover { background: #ff835e; }
.pv-btn.is-done { background: #2f6f4f; color: #fff; }
.pv-title {
  flex: 1; min-width: 0; display: flex; align-items: baseline; gap: 10px; padding: 0 8px;
  overflow: hidden; white-space: nowrap;
}
.pv-title__num { color: var(--text-faint); font-size: 13px; font-variant-numeric: tabular-nums; }
.pv-title__name { font-weight: 600; font-size: 15px; overflow: hidden; text-overflow: ellipsis; }
.pv-title__tags { color: var(--text-muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; }
.pv-seg {
  display: inline-flex; padding: 3px; gap: 2px; border-radius: 12px; background: var(--bg-raised);
  border: 1px solid var(--line);
}
.pv-seg button {
  height: 32px; padding: 0 12px; border: 0; border-radius: 9px; background: transparent; cursor: pointer;
  display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text-muted);
}
.pv-seg button svg { width: 16px; height: 16px; }
.pv-seg button[aria-pressed="true"] { background: var(--bg-hover); color: var(--text); }
.pv-actions { display: flex; align-items: center; gap: 6px; }

.pv-stage {
  flex: 1; min-height: 0; position: relative; background: #0e0e0e;
  display: flex; align-items: flex-start; justify-content: center;
}
.pv-shell { position: relative; width: 100%; height: 100%; }
.pv-device { position: absolute; inset: 0; }
.pv-frame { display: block; width: 100%; height: 100%; border: 0; background: #fff; }

/* 手機視角：外框 390×844 + 機身邊框，JS 算出 --scale */
.pv-stage[data-view="mobile"] { align-items: center; padding: 24px; }
.pv-stage[data-view="mobile"] .pv-shell {
  width: calc(var(--device-w) * var(--scale, 1));
  height: calc(var(--device-h) * var(--scale, 1));
}
.pv-stage[data-view="mobile"] .pv-device {
  inset: auto; left: 0; top: 0;
  width: var(--device-w); height: var(--device-h);
  padding: var(--bezel); border-radius: 56px;
  background: #050505;
  box-shadow: 0 0 0 1px #3a3a3a, 0 0 0 5px #1b1b1b, 0 40px 80px rgba(0,0,0,.55);
  transform: scale(var(--scale, 1)); transform-origin: 0 0;
}
.pv-stage[data-view="mobile"] .pv-frame { border-radius: 42px; }
.pv-stage { --device-w: 418px; --device-h: 872px; --bezel: 14px; } /* 390+14*2, 844+14*2 */

.pv-loading {
  position: absolute; inset: 0; display: grid; place-items: center; pointer-events: none;
  color: var(--text-muted); font-size: 13px; background: #0e0e0e;
  transition: opacity .4s var(--ease);
}
.pv-loading.is-hidden { opacity: 0; }
.pv-loading span::before {
  content: ""; display: inline-block; width: 14px; height: 14px; margin-right: 10px; vertical-align: -2px;
  border: 2px solid var(--line-strong); border-top-color: var(--accent); border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.pv-missing {
  flex: 1; display: grid; place-content: center; text-align: center; gap: 8px; padding: 24px;
}
.pv-missing h1 { margin: 0; font-size: clamp(22px, 3vw, 30px); font-weight: 600; }
.pv-missing p { margin: 0 0 20px; color: var(--text-muted); }
.pv-missing .btn { justify-self: center; }

/* 視窗 < 768px：工具列 48px，只留三個圖示按鈕，iframe 填滿，不顯示手機框 */
@media (max-width: 767px) {
  .pv-bar { height: 48px; padding: 0 6px; gap: 4px; }
  .pv-title, .pv-seg { display: none; }
  .pv-bar .pv-label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  .pv-btn { width: 40px; padding: 0; border-color: transparent; background: transparent; color: var(--text); }
  .pv-btn--accent { background: transparent; color: var(--accent); }
  .pv-btn.is-done { background: #2f6f4f; color: #fff; }
  .pv-back { margin-right: auto; }
  .pv-stage[data-view] { padding: 0; align-items: stretch; }
  .pv-stage[data-view] .pv-shell { width: 100%; height: 100%; }
  .pv-stage[data-view] .pv-device {
    inset: 0; width: auto; height: auto; padding: 0; border-radius: 0;
    background: none; box-shadow: none; transform: none;
  }
  .pv-stage[data-view] .pv-frame { border-radius: 0; }
}
@media (min-width: 768px) and (max-width: 1023px) {
  .pv-title__tags { display: none; }
  .pv-seg .pv-label { display: none; }
}

.toast {
  position: fixed; left: 50%; bottom: 24px; z-index: 5; transform: translate(-50%, 16px);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-size: 14px;
  opacity: 0; pointer-events: none; transition: opacity .25s var(--ease), transform .25s var(--ease);
  max-width: calc(100vw - 32px); overflow-wrap: anywhere;
}
.toast.is-visible { opacity: 1; transform: translate(-50%, 0); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; scroll-behavior: auto !important; }
}
html { scroll-behavior: smooth; }
