/* =========================================================
   Quiet Frames — 編輯設計風格作品集
   結構：1.變數 2.基礎 3.頁首/主視覺 4.作品網格 5.載入更多 6.燈箱(PhotoSwipe)/回頂 7.頁尾 8.無障礙/動態偏好
   ========================================================= */

/* ---------- 1. 設計變數 ---------- */
:root {
  --bg: #e8eaed;
  /* 淺灰底色 */
  --paper: #f6f6f4;
  /* 內頁紙色 */
  --ink: #1b1b1a;
  --muted: #6b6b67;
  --gray: #999;
  --hair: rgba(27, 27, 26, .2);
  --placeholder: #dcdcd9;

  --serif: "Cormorant Garamond", "Noto Serif TC", "Songti TC", "PMingLiU", Georgia, serif;
  --sans: "Inter", "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", system-ui, sans-serif;

  --pad: clamp(20px, 5vw, 72px);
  /* 內頁左右留白 */
  --gap-x: clamp(10px, 1.6vw, 24px);
  /* 網格欄距 */
  --gap-y: clamp(40px, 7vw, 112px);
  /* 網格列距（大留白） */
  --shift-unit: clamp(20px, 4.5vw, 72px);
  /* 垂直錯位單位：shift 1 = 1 單位 */

  /* 欄數：JS 會讀取此變數來計算每張圖的欄位，請與下方 media query 同步 */
  --cols: 12;
}
@media (max-width: 1024px) {
  :root {
    --cols: 6;
    --gap-y: clamp(36px, 8vw, 80px);
  }
}
@media (max-width: 640px) {
  :root {
    --cols: 4;
    --shift-unit: 18px;
    --gap-y: 40px;
  }
}

/* ---------- 2. 基礎 ---------- */
*,
*::before,
*::after {
  box-sizing: border-box;
}
html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
  scroll-padding-top: 88px;
  /* 鍵盤聚焦/錨點跳轉時，避免被置頂的分類列擋住 */
}
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 400 1rem/1.7 var(--sans);
  overflow-x: clip;
  /* 保險：不允許水平捲動 */
}
[hidden] {
  display: none !important;
}
img {
  max-width: 100%;
}
a {
  color: inherit;
}
ul,
ol {
  margin: 0;
  padding: 0;
  list-style: none;
}
a,
button {
  transition: background ease-in .3s, color ease-in .3s;
}

/* 小型英文標籤 */
.label {
  margin: 0;
  font: 500 .68rem/1.5 var(--sans);
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--muted);
}

.skip-link {
  position: absolute;
  left: 12px;
  top: -60px;
  z-index: 100;
  background: var(--ink);
  color: #fff;
  padding: .6rem 1rem;
  text-decoration: none;
}
.skip-link:focus {
  top: 12px;
}

/* 紙張外框（呼應參考圖三：灰底上的白頁） */
.sheet {
  max-width: 1520px;
  margin: clamp(0px, 3vw, 40px) auto;
  padding-inline: var(--pad);
  background: var(--paper);
}

/* ---------- 3. 頁首 / 主視覺 ---------- */
.site-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 1rem;
  padding-block: 1.4rem;
  border-bottom: 1px solid var(--ink);
}
.brand img {
  width: min(80%, 160px);
  display: block;
  padding-top: 1.5rem;
}
.site-header ul {
  display: flex;
  gap: clamp(1rem, 3vw, 2.4rem);
}
.site-header nav a {
  font: 500 .72rem/1 var(--sans);
  letter-spacing: .14em;
  text-transform: uppercase;
  text-decoration: none;
  padding: .5rem 0;
  border-bottom: 1px solid transparent;
}
.site-header nav a:hover {
  border-color: var(--ink);
}

.hero {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  column-gap: var(--gap-x);
  padding-block: clamp(48px, 9vw, 140px) clamp(48px, 8vw, 120px);
}
.hero__label {
  grid-column: 1 / 4;
  grid-row: 1 / 4;
  padding-top: .9rem;
  border-right: 1px solid var(--ink);
  /* 細線分割（參考圖一） */
}
.hero__title {
  grid-column: 4 / 13;
  margin: 0;
  font: 400 clamp(3.2rem, 10.5vw, 9.5rem)/.95 var(--serif);
  letter-spacing: -.02em;
  overflow-wrap: anywhere;
}
.hero__title em {
  font-style: italic;
}
.hero__lead {
  grid-column: 4 / 10;
  margin: clamp(24px, 4vw, 56px) 0 0;
  font: 300 1.1rem/1.8 var(--serif);
  max-width: 32ch;
}
.hero__years {
  grid-column: 7 / 13;
  margin: clamp(32px, 6vw, 80px) 0 0;
  text-align: right;
  font: italic 400 clamp(1.6rem, 4vw, 3.4rem)/1 var(--serif);
  color: var(--muted);
}
@media (max-width: 640px) {
  .hero {
    display: block;
    border-top: 1px solid var(--ink);
    margin-top: 0;
  }
  .hero__label {
    border: 0;
    padding: 1rem 0 2.5rem;
  }
  .hero__years {
    margin-top: 2rem;
  }
}

/* ---------- 4. 作品網格 ---------- */
/* 分類列：捲動時固定在視窗頂端（sticky） */
.works__head {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: .4rem 2rem;
  background: var(--paper);
  border-top: 1px solid var(--ink);
  border-bottom: 1px solid var(--hair);
}
.works__head .label:first-child {
  flex: none;
}
#works-count {
  flex: none;
  margin-left: auto;
}
.filters {
  display: flex;
  gap: .2rem 1.4rem;
  flex: 1 1 auto;
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: none;
  /* 窄螢幕時分類可橫向滑動，不會撐破頁面 */
}
.filters::-webkit-scrollbar {
  display: none;
}
.filters button {
  background: none;
  border: 0;
  border-bottom: 1px solid transparent;
  padding: .8rem .1rem;
  min-height: 50px;
  font: 500 .8rem/1.4 var(--sans);
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--muted);
  cursor: pointer;
  white-space: nowrap;
  flex: none;
}
.filters button:hover {
  color: var(--ink);
}
.filters button[aria-pressed="true"] {
  color: var(--ink);
  border-color: var(--ink);
}

/* 核心：12 欄（平板 6 欄、手機 4 欄）網格。
   每個 li 的 grid-column 由 JS 依 size / pos 計算，網格本身絕不重疊。 */
.grid {
  display: grid;
  grid-template-columns: repeat(var(--cols), minmax(0, 1fr));
  /* minmax(0,…) 防止內容撐破造成水平溢位 */
  column-gap: var(--gap-x);
  row-gap: var(--gap-y);
  align-items: start;
  margin-top: clamp(48px, 8vw, 120px);
}
.work {
  min-width: 0;
  margin: 0;
  margin-top: calc(var(--shift-unit) * var(--shift, 0));
  /* 垂直錯位 */
}
.js .work {
  opacity: 0;
  transform: translateY(22px);
  transition: opacity .8s ease, transform .8s ease;
}
.js .work.is-visible {
  opacity: 1;
  transform: none;
}

.work__figure {
  margin: 0;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: flex-start;
}
.work__open {
  position: relative;
  display: block;
  width: 100%;
  padding: 0;
  border: 0;
  margin: 0;
  background: var(--placeholder);
  cursor: zoom-in;
  overflow: hidden;
  box-shadow: 0 1px 2px rgba(27, 27, 26, .06), 0 8px 22px -6px rgba(27, 27, 26, .14);
  /* 淺陰影 */
  transition: box-shadow .35s ease;
  /* aspect-ratio 由 JS 依 width/height 設定：圖片載入失敗（<img> 被移除）時仍保留版面 */
}
.work__open.is-error {
  cursor: default;
}
.work__open.is-error::after {
  content: "Image unavailable";
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font: 500 .62rem/1 var(--sans);
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--muted);
}
.work__badge {
  position: absolute;
  right: .6rem;
  bottom: .6rem;
  padding: .25rem .5rem;
  background: rgba(246, 246, 244, .92);
  color: var(--ink);
  font: 500 .6rem/1 var(--sans);
  letter-spacing: .12em;
  text-transform: uppercase;
}
.work__open img {
  display: block;
  width: 100%;
  height: auto;
  /* width/height 屬性提供比例，載入前不會跳動 */
  opacity: 0;
  transition: opacity .6s ease, transform .9s ease;
}
.work__open img.is-loaded {
  opacity: 1;
}
@media (hover: hover) {
  .work__open:hover img {
    transform: scale(1.025);
  }
  .work__open:hover {
    box-shadow: 0 2px 4px rgba(27, 27, 26, .08), 0 14px 30px -8px rgba(27, 27, 26, .2);
  }
}

.work__cap {
  margin-top: 1rem;
  display: grid;
  gap: .25rem;
}
.work__title {
  font: 400 clamp(1rem, 2.6vw, 1.08rem)/1.35 var(--serif);
  margin: 0;
}
.work__meta {
  display: flex;
  flex-wrap: wrap;
  gap: .1rem .5rem;
  color: var(--ink);
}
/* 標籤：灰字、無 #，以中間點分隔（分隔符改 --tag-sep 即可） */
.work__tags {
  display: flex;
  flex-wrap: wrap;
  color: var(--gray);
  --tag-sep: "·";
}
.work__tags span+span::before {
  content: var(--tag-sep);
  content: var(--tag-sep) / "";
  /* 後者讓螢幕閱讀器略過裝飾符號 */
  margin-inline: .3em;
}
.work__link {
  justify-self: start;
  margin-top: 1rem;
  padding-block: .3rem;
  text-decoration: none;
  font: 500 .66rem/1 var(--sans);
  letter-spacing: .14em;
  text-transform: uppercase;
  border-bottom: 1px solid var(--ink);
}
.work__link:hover {
  background: var(--ink);
  color: var(--paper);
}

.notice {
  text-align: center;
  color: var(--muted);
  padding: 3rem 0;
}

/* ---------- 5. 載入更多 ---------- */
.more {
  display: grid;
  justify-items: center;
  gap: 1rem;
  padding-block: clamp(64px, 10vw, 140px) clamp(40px, 6vw, 80px);
}
.btn-more {
  display: inline-flex;
  align-items: baseline;
  gap: .9rem;
  min-height: 48px;
  padding: .9rem 2.2rem;
  background: none;
  color: var(--ink);
  border: 1px solid var(--ink);
  cursor: pointer;
  transition: background .25s, color .25s;
}
.btn-more:hover {
  background: var(--ink);
  color: var(--paper);
}
.btn-more__en {
  font: 500 .72rem/1 var(--sans);
  letter-spacing: .16em;
  text-transform: uppercase;
}
.switch {
  display: inline-flex;
  align-items: center;
  gap: .6rem;
  cursor: pointer;
  min-height: 32px;
  position: relative;
}
.switch input {
  position: absolute;
  opacity: 0;
  inset: 0;
  margin: 0;
  cursor: pointer;
}
.switch__track {
  width: 30px;
  height: 16px;
  border: 1px solid var(--ink);
  position: relative;
  transition: background .2s;
}
.switch__track::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 10px;
  height: 10px;
  background: var(--ink);
  transition: transform .2s, background .2s;
}
.switch input:checked+.switch__track {
  background: var(--ink);
}
.switch input:checked+.switch__track::after {
  transform: translateX(14px);
  background: var(--paper);
}
.switch input:focus-visible+.switch__track {
  outline: 2px solid var(--ink);
  outline-offset: 3px;
}
.btn-more__zh {
  font: 400 .95rem/1 var(--serif);
}

/* ---------- About ---------- */
.about {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  column-gap: var(--gap-x);
  padding-block: 1rem clamp(64px, 10vw, 100px);
  border-top: 1px solid var(--ink);
}
.about__label {
  grid-column: 1 / 3;
  padding-top: .3rem;
}
.about__text {
  grid-column: 3 / 11;
  margin: 0;
  font: 300 clamp(1rem, 2.6vw, 1.2rem)/1.6 var(--serif);
  max-width: 50rem;
}
.about__meta {
  grid-column: 3 / 11;
  margin-top: 1rem;
}
@media (max-width: 640px) {
  .about {
    display: block;
  }
  .about__label {
    padding-bottom: 1.5rem;
  }
}

/* ---------- 7. 頁尾 ---------- */
.site-footer {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: baseline;
  gap: .8rem 2rem;
  padding-block: 1.4rem 2rem;
  border-top: 1px solid var(--ink);
}
.site-footer__mail {
  font: 400 1.2rem/1 var(--serif);
  text-decoration: none;
  border-bottom: 1px solid var(--ink);
  padding-bottom: .15rem;
}

/* ---------- 6. 燈箱（PhotoSwipe 主題：淺色、安靜） ---------- */
.pswp {
  --pswp-bg: #f6f6f4;
  --pswp-placeholder-bg: #dcdcd9;
  --pswp-icon-color: #1b1b1a;
  --pswp-icon-color-secondary: transparent;
  /* 去掉預設的描邊陰影 */
  --pswp-icon-stroke-color: transparent;
  --pswp-icon-stroke-width: 0px;
  --pswp-preloader-color: rgba(27, 27, 26, .18);
  --pswp-preloader-color-secondary: #1b1b1a;
  /* loading 轉圈顏色 */
  --pswp-error-text-color: #6b6b67;
  font-family: var(--sans);
}
.pswp__counter {
  color: #1b1b1a;
  text-shadow: none;
  opacity: 1;
  font: 500 .68rem/1 var(--sans);
  letter-spacing: .14em;
}
.pswp__button {
  opacity: .85;
  transition: opacity .2s;
}
.pswp__button:hover {
  opacity: 1;
}
.pswp__button:focus-visible,
.pswp__visit:focus-visible {
  outline: 2px solid #1b1b1a;
  outline-offset: -4px;
}

/* 專案連結按鈕（上方工具列） */
.pswp__visit {
  display: inline-flex;
  align-items: center;
  height: 60px;
  padding-inline: .9rem;
  color: #1b1b1a;
  text-decoration: none;
  font: 500 .68rem/1 var(--sans);
  letter-spacing: .14em;
  text-transform: uppercase;
  border-bottom: 1px solid transparent;
}
.pswp__visit:hover {
  background: #1b1b1a;
  color: #f6f6f4;
}

/* 說明文字（只顯示 description）：底部置中，切換圖片時淡入 */
.pswp__caption {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 10;
  padding: 1rem clamp(56px, 10vw, 140px) 1.4rem;
  text-align: center;
  pointer-events: none;
  font: 300 1.05rem/1.7 var(--serif);
  color: #1b1b1a;
  animation: caption-in .5s ease both;
}
.pswp__caption[hidden] {
  display: none;
}
@keyframes caption-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}
.pswp--ui-visible .pswp__caption {
  opacity: 1;
}
.pswp:not(.pswp--ui-visible) .pswp__caption {
  opacity: 0;
  transition: opacity .3s;
}

/* ---------- 回到頂端按鈕 ---------- */
.to-top {
  position: fixed;
  right: clamp(12px, 2.5vw, 32px);
  bottom: clamp(12px, 2.5vw, 32px);
  z-index: 40;
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: .15rem;
  width: 52px;
  height: 52px;
  padding: 0;
  background: var(--paper);
  color: var(--ink);
  border: 1px solid var(--ink);
  cursor: pointer;
  opacity: 0;
  transform: translateY(12px);
  pointer-events: none;
  transition: opacity .3s, transform .3s, background .2s, color .2s;
}
.to-top.is-shown {
  opacity: 1;
  transform: none;
  pointer-events: auto;
}
.to-top:hover {
  background: var(--ink);
  color: var(--paper);
}
.to-top span:first-child {
  font-size: 1rem;
  line-height: 1;
}
.to-top__text {
  font: 500 .55rem/1 var(--sans);
  letter-spacing: .14em;
  text-transform: uppercase;
}

/* ---------- 8. 焦點 / 動態偏好 ---------- */
:focus {
  outline: none;
}
:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 4px;
}
.work__open:focus-visible {
  outline-offset: 5px;
}

@media (max-width: 640px) {
  .works__head>.label:first-child {
    display: none;
  }
  /* 窄螢幕省空間（仍可作為區塊名稱供輔助科技使用） */
  .to-top {
    width: 44px;
    height: 44px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .pswp__caption,
  .to-top {
    animation: none;
  }
  html {
    scroll-behavior: auto;
  }
  *,
  *::before,
  *::after {
    transition-duration: .01ms !important;
    animation-duration: .01ms !important;
  }
  .js .work {
    opacity: 1;
    transform: none;
  }
}