/* ═══════════════════════════════════════════════════════════
   Bento 目錄
   格子由 JS 依 DOM 裡 .project / .project-mini 的順序自動產生，
   這裡只負責「第幾格長什麼樣」，跟是哪個專案無關 ——
   所以搬動專案區塊時版面形狀不變，只有內容換位置。
   ═══════════════════════════════════════════════════════════ */

.bento {
  padding-block: var(--sp-6);
}

.bento__grid {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  grid-auto-rows: minmax(11rem, auto);
  grid-auto-flow: row dense;
  gap: 0.75rem;
}

/* ── 格子尺寸 ─────────────────────────────────────────── */
/* 專案格一律同尺寸 —— 盤面上唯一特別的是中心那塊，
   有了強勢的中心就不需要再挑一個專案當旗艦格，
   也省掉「第一個專案會長得不一樣」這個跟順序綁死的耦合。

   例外只有最後一列：中心佔兩格，格數通常湊不滿，
   所以 site.js 會讓那一列的格子均分（見那支檔案的說明）。 */
.bento__cell { grid-column: var(--start, auto) / span var(--span, 4); }

/* ── 中心 ─────────────────────────────────────────────── */
.bento__core {
  grid-column: span 4;
  grid-row: span 2;
  display: grid;
  align-content: center;
  justify-items: center;
  gap: var(--sp-1);
  padding: var(--sp-3) var(--sp-2);
  text-align: center;
  /* 刻意沒有底色也沒有框：它是整盤的地面，不是又一塊磚。
     周圍的格子自然會把它框起來。 */
}
.bento__core h2 {
  font-size: var(--t-h3);
  letter-spacing: -0.01em;
}
.bento__count {
  margin: 0;
  font-size: clamp(3.5rem, 7vw, 5.5rem);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 1;
  letter-spacing: -0.05em;
  background: linear-gradient(180deg, #ffffff 25%, #6e6e73 100%);
  -webkit-background-clip: text;
          background-clip: text;
  color: transparent;
}
.bento__hint {
  margin: 0;
  font-size: var(--t-small);
  color: var(--ink-faint);
}
.bento__mark { width: 2.5rem; height: 2.5rem; margin-bottom: var(--sp-1); }
.bento__mark * {
  fill: none; stroke: var(--stroke-dim); stroke-width: 1.5;
  stroke-linecap: round; stroke-linejoin: round;
  vector-effect: non-scaling-stroke;
}
.bento__mark .bento__mark-dot { stroke: var(--accent); }

/* 窄螢幕：一列兩格／一格，--span 的補滿規則不適用，直接覆蓋掉 */
@media (max-width: 62rem) {
  .bento__cell { grid-column: span 6; }
  .bento__core { grid-column: span 12; grid-row: span 1; padding-block: var(--sp-4); }
}
@media (max-width: 38rem) {
  .bento__cell { grid-column: span 12; }
}

/* ── 格子本體 ─────────────────────────────────────────
   Apple 的磚：大圓角、比底色亮一階的材質、上緣一道光。
   被指到時整塊往前浮一點點、亮一階，右下角的箭頭鈕點亮 —— 回饋在材質上，
   不是在某一條細線上。 */
.bento__cell {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  padding: var(--sp-3);
  min-height: 11rem;
  background: linear-gradient(180deg, var(--bg-lift), var(--bg-raised) 70%);
  border: 0;
  border-radius: var(--r-lg);
  text-decoration: none;
  text-align: left;
  font: inherit;
  color: inherit;
  cursor: pointer;
  overflow: hidden;
  transition: background var(--dur-ui) var(--ease-out),
              box-shadow var(--dur-ui) var(--ease-out),
              translate var(--dur-ui) var(--spring),
              transform var(--dur-tap) var(--ease-out);
}

.bento__cell:hover {
  translate: 0 -3px;
  box-shadow: inset 0 1px 0 #ffffff1f, inset 0 0 0 1px #ffffff14,
              0 20px 44px #000000b3;
}
/* 回饋在按下的瞬間，不是放開之後。
   限定 button —— 聯絡格是連結的容器，整塊不該有按壓回饋。 */
button.bento__cell:active { transform: scale(0.985); }

/* 右下角的圓鈕：Apple 磚上那顆「可以點」的記號 */
.bento__go {
  position: absolute;
  right: var(--sp-2); bottom: var(--sp-2);
  width: 28px; height: 28px;
  display: grid; place-items: center;
  border-radius: 50%;
  background: #ffffff1a;
  color: var(--ink-muted);
  transition: background var(--dur-ui) var(--ease-out),
              color var(--dur-ui) var(--ease-out),
              transform var(--dur-ui) var(--spring);
}
.bento__go svg {
  width: 12px; height: 12px;
  fill: none; stroke: currentColor; stroke-width: 2;
  stroke-linecap: round; stroke-linejoin: round;
}
.bento__cell:hover .bento__go,
.bento__cell:focus-visible .bento__go {
  background: var(--ink);
  color: #000;
  transform: translateY(2px);
}

.bento__idx {
  font-size: var(--t-small);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--ink-faint);
}
.bento__title {
  font-size: var(--t-h3);
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.2;
  margin-top: auto;
  padding-right: 2.5rem;           /* 讓出右下角的圓鈕 */
  word-break: keep-all;
  overflow-wrap: anywhere;
}
.bento__tag {
  font-size: var(--t-small);
  color: var(--ink-muted);
  padding-right: 2.5rem;
}

/* ── 聯絡格 ───────────────────────────────────────────
   盤面最後一格。不是專案，所以不編號、不整塊可點、
   也沒有底部那條 accent 線 —— 可點的只有裡面的連結。 */
.bento__cell--contact {
  cursor: default;
  background: transparent;
  box-shadow: inset 0 0 0 1px var(--hairline);
}
.bento__cell--contact:hover {
  translate: none;
  background: transparent;
  box-shadow: inset 0 0 0 1px var(--hairline);
}
/* 標題壓到跟同一列的輕量專案一樣大 —— 它是收尾不是主角，
   字級比鄰居大的話，剛解決掉的「哪格比較重要」又會冒出來 */
.bento__cell--contact .bento__title { font-size: var(--t-body); }

.bento__links {
  display: flex; flex-wrap: wrap;
  gap: var(--sp-1) var(--sp-2);
}
.bento__links { gap: 0.4rem; }
.bento__links a {
  font-size: var(--t-label);
  font-weight: 500;
  color: var(--ink);
  text-decoration: none;
  padding: 0.45em 0.95em;
  border-radius: 999px;
  background: #ffffff14;
  transition: background var(--dur-ui) var(--ease-out),
              color var(--dur-ui) var(--ease-out);
}
.bento__links a:hover { background: var(--ink); color: #000; }

/* 輕量專案：視覺上刻意收斂，讓詳細專案站在前面 */
.bento__cell--mini {
  background: transparent;
  box-shadow: inset 0 0 0 1px var(--hairline);
}
.bento__cell--mini:hover { background: var(--bg-raised); }
.bento__cell--mini .bento__title { font-size: var(--t-body); font-weight: 600; }

/* 專案的線稿 icon（有的話，JS 從 section 的 <template> 搬過來） */
.bento__icon { width: 2rem; height: 2rem; color: var(--stroke-dim); }
.bento__icon svg { width: 100%; height: 100%; display: block; }
.bento__icon path, .bento__icon circle, .bento__icon rect, .bento__icon line {
  fill: none; stroke: currentColor; stroke-width: 1.5;
  stroke-linecap: round; stroke-linejoin: round;
  vector-effect: non-scaling-stroke;
}

/* ═══ 首次進場 ══════════════════════════════════════════
   編排：旗艦格一開始就在，其餘格子從畫面外滑進來繞著它就位。
   曲線用 --brake（臨界阻尼）不是彈簧 —— 這裡要的是煞車，不是彈一下。

   只播一次 —— 捲離開後 JS 就解除觀察，向上回捲不會重播。
   （重新整理會再播一次，這是刻意的：全黑不動的頁面會像壞掉。）*/
.bento__grid .bento__cell {
  opacity: 0;
  transform: translate(var(--fx, 0), var(--fy, 0)) scale(0.96);
}
.bento__grid.is-in .bento__cell {
  opacity: 1;
  transform: none;
  transition:
    opacity 0.7s var(--ease-out) calc(var(--i, 0) * 100ms),
    transform 1.15s var(--brake) calc(var(--i, 0) * 100ms),
    background var(--dur-ui) var(--ease-out),
    box-shadow var(--dur-ui) var(--ease-out),
    translate var(--dur-ui) var(--spring);
}

/* 方向與順序由 site.js 依格子在盤面上的實際位置算出來（見那支檔案）：
   每一格都是沿著「自己到中心」那條線被推到畫面外，再沿原路滑回來，
   離中心近的先到。寫死 nth-child 的話，專案增減或換行就會錯位。

   ⚠️ 預設值必須是 0：getBoundingClientRect() 會把 transform 算進去，
   如果這裡先給一個位移，site.js 量到的位置就是「已經被推開之後」的，
   算出來的方向會整組偏掉（症狀：上排的格子也從下面飛進來）。
   量不到位置時的退化行為就是原地淡入，這樣也還可以看。 */
.bento__grid .bento__cell { --fx: 0; --fy: 0; }

/* 進場跑完之後把 transition 換回按壓用的快速曲線 ——
   不換的話，按下格子的縮放回饋會跟著用 1.15s 的進場曲線，手感整個糊掉。
   （site.js 依格子數算好時間再加上 is-settled。） */
.bento__grid.is-settled .bento__cell {
  transition:
    background var(--dur-ui) var(--ease-out),
    box-shadow var(--dur-ui) var(--ease-out),
    translate var(--dur-ui) var(--spring),
    transform var(--dur-tap) var(--ease-out);
}

/* 降低動態偏好：不做大位移，改成純淡入 */
@media (prefers-reduced-motion: reduce) {
  .bento__grid .bento__cell { transform: none; }
  .bento__grid.is-in .bento__cell {
    transition: opacity 0.3s ease calc(var(--i, 0) * 25ms);
  }
}
