/* ==========================================================================
   諾蘭筆記 — 全站樣式
   原則：手機優先、任何元素都不得撐破版面、HERO 圖等比例且不超過內文欄寬。
   ========================================================================== */

:root {
  /* 內容文字區的寬度。HERO 圖的最大寬度也綁在這個值，確保不會比內文寬。 */
  --content: 46rem;
  --gutter: clamp(1rem, 5vw, 2rem);
  --radius: 14px;

  /* 冷調藍灰：對應諾蘭作品一貫的低飽和、高反差質感 */
  --bg: #f6f7f9;
  --surface: #ffffff;
  --ink: #15181d;
  --ink-soft: #515964;
  --ink-faint: #838c99;
  --line: #e0e4ea;
  --accent: #1f5f8b;
  --accent-soft: #eaf1f7;
  --shadow: 0 1px 2px rgba(21, 24, 29, .05), 0 8px 24px -12px rgba(21, 24, 29, .22);

  /* HERO 為直式照片時的高度上限，避免一進站就被整頁大頭照佔滿 */
  --hero-portrait-max: 30rem;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101318;
    --surface: #181c23;
    --ink: #e9edf2;
    --ink-soft: #a8b2bf;
    --ink-faint: #78838f;
    --line: #2a303a;
    --accent: #6fb0d8;
    --accent-soft: #16242f;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px -12px rgba(0, 0, 0, .7);
  }
}

*, *::before, *::after { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", -apple-system,
               BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  font-size: 17px;
  line-height: 1.8;
  /* 中文長字串與長網址一律斷行，避免橫向捲動 */
  overflow-wrap: break-word;
  word-break: break-word;
}

/* 任何內嵌媒體都不得超出容器 */
img, svg, video, iframe, canvas {
  max-width: 100%;
  height: auto;
}

a { color: var(--accent); text-decoration-thickness: 1px; text-underline-offset: 3px; }
a:hover { text-decoration-thickness: 2px; }

.skip {
  position: absolute; left: -9999px;
  background: var(--accent); color: #fff; padding: .6rem 1rem; border-radius: 0 0 8px 0; z-index: 99;
}
.skip:focus { left: 0; top: 0; }

/* ---------- 版面容器 ---------- */

.wrap {
  width: 100%;
  max-width: var(--content);
  margin-inline: auto;
  padding-inline: var(--gutter);
  /* grid/flex 子元素的縮小保險 */
  min-width: 0;
}

/* ---------- 頁首 ---------- */

.site-header {
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  position: sticky; top: 0; z-index: 10;
  backdrop-filter: saturate(160%) blur(10px);
}

.brand {
  display: flex; align-items: center; gap: .65rem;
  padding: .85rem 0;
  color: inherit; text-decoration: none;
  min-width: 0;
}
.brand-mark { font-size: 1.5rem; line-height: 1; flex: none; }
.brand-text { display: flex; flex-direction: column; min-width: 0; }
.brand-text strong { font-size: 1.05rem; letter-spacing: .02em; }
.brand-text small {
  color: var(--ink-faint); font-size: .78rem; line-height: 1.4;
  /* 手機窄螢幕時副標題單行省略，不換行破版 */
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* ---------- HERO ---------- */

.hero-wrap { padding-top: clamp(1.5rem, 6vw, 3rem); }

/*
  HERO 圖：等比例縮放（height:auto，不裁切），
  寬度上限 = 內文欄寬（.wrap 已經限制在 --content，這裡再保險一次）。
*/
.hero {
  margin: 0 0 clamp(1.25rem, 4vw, 2rem);
  width: 100%;
  max-width: var(--content);
  margin-inline: auto;
}
.hero img {
  display: block;
  width: 100%;
  max-width: var(--content);
  height: auto;               /* 等比例，永不變形 */
  margin-inline: auto;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  background: var(--line);
}

/*
  直式 HERO（高 > 寬）：改用高度收斂。
  width:auto + max-height 一樣是等比例縮放（沒有裁切、沒有變形），
  只是改由高度決定尺寸，寬度自然會小於內文欄寬，仍然符合「不超過內文寬」。
*/
.hero.is-portrait img {
  width: auto;
  max-height: var(--hero-portrait-max);
  max-width: 100%;
}

.site-title {
  font-size: clamp(1.7rem, 6.5vw, 2.6rem);
  line-height: 1.25;
  margin: 0 0 .6rem;
  letter-spacing: -.01em;
}
.site-desc { color: var(--ink-soft); margin: 0 0 .9rem; }
.site-views {
  margin: 0; font-size: .85rem; color: var(--ink-faint);
  font-variant-numeric: tabular-nums;
}

/* ---------- 卡片索引 ---------- */

.section-title {
  display: flex; align-items: center; gap: .55rem;
  font-size: 1.05rem; letter-spacing: .04em; color: var(--ink-soft);
  margin: clamp(2rem, 7vw, 3.25rem) 0 1rem;
}
.section-title::after {
  content: ""; flex: 1; height: 1px; background: var(--line);
}
.section-title .count {
  order: 3; flex: none;
  background: var(--accent-soft); color: var(--accent);
  border-radius: 999px; padding: .1rem .6rem; font-size: .8rem; font-weight: 700;
}

.cards {
  list-style: none; margin: 0 0 clamp(2.5rem, 8vw, 4rem); padding: 0;
  display: grid; gap: 1rem;
  grid-template-columns: 1fr;              /* 手機：單欄 */
}
@media (min-width: 40rem) {
  .cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }  /* minmax(0,·) 防止內容撐破格線 */
}

.card { min-width: 0; }
.card-link {
  display: flex; flex-direction: column; height: 100%;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.15rem 1.25rem 1rem;
  color: inherit; text-decoration: none;
  box-shadow: var(--shadow);
  transition: transform .18s ease, border-color .18s ease;
}
.card-link:hover { transform: translateY(-2px); border-color: var(--accent); }

.card-title { font-size: 1.12rem; line-height: 1.45; margin: 0 0 .45rem; }
.card-excerpt {
  margin: 0 0 .9rem; color: var(--ink-soft); font-size: .92rem; line-height: 1.7; flex: 1;
}
.card-meta {
  display: flex; flex-wrap: wrap; gap: .4rem;      /* 換行而不是撐破 */
  margin-top: auto;
}
.chip {
  font-size: .74rem; color: var(--ink-faint);
  border: 1px solid var(--line); border-radius: 999px;
  padding: .15rem .55rem; white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.chip.views { border-color: transparent; background: var(--accent-soft); color: var(--accent); }

.card.empty {
  border: 1px dashed var(--line); border-radius: var(--radius);
  padding: 1.5rem; color: var(--ink-faint); font-size: .9rem;
}

/* ---------- 文章頁 ---------- */

.post { padding-top: clamp(1.5rem, 6vw, 3rem); padding-bottom: clamp(2rem, 8vw, 4rem); }

.post-title {
  font-size: clamp(1.55rem, 6vw, 2.35rem);
  line-height: 1.3; margin: 0 0 1rem; letter-spacing: -.01em;
}

/* 作者標示：內容區的最前面 */
.byline {
  border-left: 3px solid var(--accent);
  padding: .1rem 0 .1rem .9rem;
  margin: 0 0 clamp(1.5rem, 5vw, 2.25rem);
}
.byline-author { margin: 0 0 .25rem; font-size: .95rem; }
.byline-author strong { font-weight: 700; }
.byline-dates {
  margin: 0; font-size: .82rem; color: var(--ink-faint);
  display: flex; flex-wrap: wrap; gap: .4rem;     /* 手機自動換行 */
  font-variant-numeric: tabular-nums;
}
.byline-dates > span[aria-hidden] { opacity: .5; }
.tags { margin: .5rem 0 0; display: flex; flex-wrap: wrap; gap: .35rem; }
.tag { font-size: .74rem; color: var(--accent); background: var(--accent-soft); border-radius: 999px; padding: .1rem .55rem; }

/* ---------- 內文排版 ---------- */

.prose > :first-child { margin-top: 0; }
.prose h2 {
  font-size: clamp(1.25rem, 4.5vw, 1.5rem); line-height: 1.4;
  margin: 2.4rem 0 .8rem; padding-bottom: .4rem; border-bottom: 1px solid var(--line);
}
.prose h3 { font-size: clamp(1.08rem, 4vw, 1.2rem); margin: 1.9rem 0 .6rem; }
.prose p { margin: 0 0 1.15rem; }
.prose ul, .prose ol { margin: 0 0 1.15rem; padding-left: 1.4rem; }
.prose li { margin-bottom: .4rem; }
.prose li::marker { color: var(--accent); }

.prose blockquote {
  margin: 1.5rem 0; padding: .1rem 0 .1rem 1rem;
  border-left: 3px solid var(--line); color: var(--ink-soft);
}

.prose img { border-radius: 10px; display: block; margin: 1.5rem auto; }

.prose hr { border: 0; border-top: 1px solid var(--line); margin: 2.5rem 0; }

.prose code {
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  font-size: .875em; background: var(--accent-soft); color: var(--accent);
  padding: .12em .4em; border-radius: 5px;
}
.prose pre {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 1rem; margin: 0 0 1.15rem;
  overflow-x: auto;                       /* 長程式碼自己捲，不撐破頁面 */
  -webkit-overflow-scrolling: touch;
}
.prose pre code { background: none; color: inherit; padding: 0; font-size: .85rem; }

/* 表格：外層容器橫向捲動，手機不破版 */
.table-scroll {
  overflow-x: auto; -webkit-overflow-scrolling: touch;
  margin: 0 0 1.15rem; border: 1px solid var(--line); border-radius: var(--radius);
}
.prose table { border-collapse: collapse; width: 100%; min-width: 30rem; font-size: .9rem; }
.prose th, .prose td { padding: .6rem .8rem; text-align: left; border-bottom: 1px solid var(--line); }
.prose th { background: var(--accent-soft); color: var(--accent); font-weight: 700; white-space: nowrap; }
.prose tr:last-child td { border-bottom: 0; }

.back { margin: clamp(2.5rem, 8vw, 4rem) 0 0; font-size: .9rem; }

/* ---------- 頁尾 ---------- */

.site-footer {
  border-top: 1px solid var(--line);
  padding: clamp(1.75rem, 6vw, 2.5rem) 0 clamp(2rem, 8vw, 3rem);
  margin-top: auto;
  color: var(--ink-faint); font-size: .82rem; line-height: 1.75;
}
.site-footer p { margin: 0 0 .5rem; }
.site-footer a { color: var(--ink-soft); }
.credit { max-width: 100%; }
.copy { color: var(--ink-faint); }

/* ---------- 動態偏好 ---------- */

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  * { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
