:root {
  --bg: #fbfaf7;
  --surface: #f3f0ea;
  --card: #ffffff;
  --text: #1c1b1f;
  --muted: #66646c;
  --border: #e6e1d8;
  --accent: #d9480f;
  --accent-soft: #fdede4;
  --code-bg: #f1eee7;
  --tone-0: #fdede4;
  --tone-1: #e7f0ec;
  --tone-2: #e9ecf6;
  --tone-3: #f4ecdc;
  --tone-ink: #3a3640;
  --shadow: 0 1px 2px rgb(28 27 31 / 4%), 0 8px 24px rgb(28 27 31 / 6%);
  --sans: "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", system-ui, sans-serif;
  --serif: "Noto Serif TC", "Songti TC", "PMingLiU", serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #131315;
    --surface: #1b1b1e;
    --card: #19191c;
    --text: #ecebef;
    --muted: #a3a1ab;
    --border: #2b2a30;
    --accent: #ff8a4c;
    --accent-soft: #2d1b12;
    --code-bg: #1e1e22;
    --tone-0: #2d1b12;
    --tone-1: #16261f;
    --tone-2: #1a1f30;
    --tone-3: #2a2416;
    --tone-ink: #e4e1ea;
    --shadow: 0 1px 2px rgb(0 0 0 / 30%), 0 8px 24px rgb(0 0 0 / 25%);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font-family: var(--sans); line-height: 1.7; }
a { color: var(--accent); text-underline-offset: 3px; text-decoration-thickness: 1px; }
img { max-width: 100%; height: auto; }
.wrap { max-width: 1080px; margin: 0 auto; padding: 0 16px; }
.skip { position: absolute; left: -999px; }
.skip:focus { left: 16px; top: 8px; background: var(--bg); padding: 4px 8px; z-index: 10; }

/* 頁首 */
.site-header { position: sticky; top: 0; z-index: 5; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: saturate(1.4) blur(10px); border-bottom: 1px solid var(--border); }
.header-row { display: flex; align-items: center; gap: 28px; min-height: 64px; }
.brand, .footer-brand { display: inline-flex; align-items: center; gap: 10px; font-family: var(--serif); font-weight: 700; font-size: 1.2rem; color: var(--text); text-decoration: none; white-space: nowrap; letter-spacing: 0.02em; }
.brand-mark { width: 12px; height: 12px; background: var(--accent); border-radius: 3px; transform: rotate(45deg); flex: none; }
.site-header nav { display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none; flex: 1; min-width: 0; }
.site-header nav::-webkit-scrollbar { display: none; }
.site-header nav a { color: var(--muted); text-decoration: none; padding: 6px 12px; white-space: nowrap; border-radius: 999px; font-size: 0.94rem; transition: color 0.15s, background 0.15s; }
.site-header nav a:hover { color: var(--text); background: var(--surface); }
.site-header nav a[aria-current] { color: var(--accent); background: var(--accent-soft); }

main.wrap { padding-top: 40px; padding-bottom: 104px; min-height: 60vh; }

/* 首頁 */
.hero { padding: 32px 0 48px; max-width: 760px; }
.eyebrow { margin: 0 0 14px; color: var(--accent); font-size: 0.85rem; font-weight: 600; letter-spacing: 0.12em; }
.hero h1 { margin: 0; font-family: var(--serif); font-size: clamp(2.4rem, 6vw, 3.6rem); line-height: 1.2; letter-spacing: 0.01em; }
.hero-lede { margin: 16px 0 0; font-size: clamp(1.1rem, 2.4vw, 1.3rem); color: var(--text); }

.section-head { display: flex; justify-content: space-between; align-items: baseline; gap: 16px; margin: 64px 0 20px; }
.section-head h2 { margin: 0; font-family: var(--serif); font-size: 1.5rem; display: flex; align-items: center; gap: 12px; }
.section-head h2::before { content: ""; width: 24px; height: 3px; background: var(--accent); border-radius: 2px; }
.muted, .empty { color: var(--muted); }

/* 卡片 */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 24px; }
.card { position: relative; display: flex; flex-direction: column; background: var(--card); border: 1px solid var(--border); border-radius: 14px; overflow: hidden; transition: transform 0.2s, box-shadow 0.2s; }
.card:hover { transform: translateY(-3px); box-shadow: var(--shadow); }
.card-cover { display: block; aspect-ratio: 16 / 9; overflow: hidden; background: var(--surface); }
.card-cover img { display: block; width: 100%; height: 100%; object-fit: cover; }
.placeholder { display: flex; align-items: flex-end; padding: 18px 20px; text-decoration: none; color: var(--tone-ink); font-family: var(--serif); font-size: 1.35rem; font-weight: 700; }
.tone-0 { background: radial-gradient(circle at 85% 20%, color-mix(in srgb, var(--accent) 22%, transparent), transparent 55%), var(--tone-0); }
.tone-1 { background: radial-gradient(circle at 85% 20%, rgb(16 122 87 / 20%), transparent 55%), var(--tone-1); }
.tone-2 { background: radial-gradient(circle at 85% 20%, rgb(59 91 219 / 20%), transparent 55%), var(--tone-2); }
.tone-3 { background: radial-gradient(circle at 85% 20%, rgb(194 140 20 / 22%), transparent 55%), var(--tone-3); }
.card-body { display: flex; flex-direction: column; flex: 1; padding: 18px 20px 20px; }
.card h2, .card h3 { margin: 10px 0 8px; font-family: var(--serif); font-size: 1.18rem; line-height: 1.5; }
.card h2 a, .card h3 a { color: var(--text); text-decoration: none; }
.card h2 a::after, .card h3 a::after { content: ""; position: absolute; inset: 0; }
.card h2 a:hover, .card h3 a:hover { color: var(--accent); }
.card p { margin: 0 0 12px; color: var(--muted); font-size: 0.95rem; line-height: 1.75; }
.card .meta { margin: auto 0 0; }
.card .tag { position: relative; z-index: 1; align-self: flex-start; }
.tag { display: inline-block; background: var(--accent-soft); color: var(--accent); font-size: 0.78rem; font-weight: 600; padding: 3px 10px; border-radius: 999px; text-decoration: none; letter-spacing: 0.04em; }
.meta { display: flex; flex-wrap: wrap; gap: 4px 14px; color: var(--muted); font-size: 0.86rem; }
.draft { color: #b45309; font-weight: 600; }

.card.featured { display: grid; grid-template-columns: minmax(0, 1.55fr) minmax(0, 1fr); }
.card.featured .card-cover { position: relative; aspect-ratio: auto; }
.card.featured .card-cover::before { content: ""; display: block; padding-top: 56.25%; }
.card.featured .card-cover img { position: absolute; inset: 0; }
.card.featured .card-body { padding: 28px 32px; justify-content: center; }
.card.featured h2 { font-size: clamp(1.35rem, 2.2vw, 1.7rem); line-height: 1.45; margin: 14px 0 12px; }
.card.featured .excerpt { font-size: 1rem; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 3; overflow: hidden; }
.card.featured .meta { margin-top: 8px; }


/* 分類頁、關於頁 */
.page-head { max-width: 760px; margin-bottom: 36px; }
.page-head h1 { margin: 0 0 12px; font-family: var(--serif); font-size: clamp(2rem, 5vw, 2.6rem); line-height: 1.3; }

/* 文章頁 */
.post { max-width: 740px; margin: 0 auto; }
.crumbs { font-size: 0.86rem; color: var(--muted); margin-bottom: 20px; }
.crumbs a { color: var(--muted); text-decoration: none; }
.crumbs a:hover { color: var(--accent); }
.post-head h1 { margin: 16px 0 16px; font-family: var(--serif); font-size: clamp(1.8rem, 4.4vw, 2.5rem); line-height: 1.38; letter-spacing: 0.01em; }
.lede { font-size: 1.12rem; line-height: 1.85; color: var(--muted); margin: 18px 0 28px; }
.post-cover { margin: 0 0 32px; }
.post-cover img { display: block; width: 100%; border-radius: 14px; border: 1px solid var(--border); }
.tldr { position: relative; background: var(--card); border: 1px solid var(--border); border-radius: 14px; padding: 22px 24px 18px; margin: 28px 0; box-shadow: var(--shadow); }
.tldr::before { content: ""; position: absolute; left: 0; top: 18px; bottom: 18px; width: 4px; background: var(--accent); border-radius: 0 3px 3px 0; }
.tldr h2 { margin: 0 0 8px; font-size: 0.85rem; letter-spacing: 0.12em; color: var(--accent); }
.tldr ul { margin: 0; padding-left: 1.2em; }
.tldr li { margin: 6px 0; line-height: 1.75; }
.toc { border-top: 1px solid var(--border); border-bottom: 1px solid var(--border); padding: 18px 0; margin: 28px 0 8px; }
.toc-title { margin: 0 0 8px; font-size: 0.85rem; letter-spacing: 0.12em; color: var(--muted); }
.toc ul { margin: 0; padding: 0; list-style: none; columns: 2; column-gap: 32px; }
.toc li { margin: 0 0 6px; break-inside: avoid; }
.toc a { color: var(--text); text-decoration: none; font-size: 0.95rem; }
.toc a:hover { color: var(--accent); }
.toc li.l3 { margin-left: 1.1em; font-size: 0.9rem; }
.toc li.l3 a { color: var(--muted); }

.prose { font-size: 1.125rem; line-height: 1.9; overflow-wrap: anywhere; }
.prose p { margin: 1.15em 0; }
.prose h2 { font-family: var(--serif); font-size: 1.6rem; margin: 2.4em 0 0.7em; line-height: 1.45; }
.prose h3 { font-family: var(--serif); font-size: 1.28rem; margin: 1.9em 0 0.5em; line-height: 1.5; }
.prose h4 { font-size: 1.1rem; margin: 1.5em 0 0.4em; }
.prose h2, .prose h3, .prose h4 { scroll-margin-top: 84px; }
.anchor { margin-left: 8px; font-family: var(--sans); font-weight: 400; text-decoration: none; opacity: 0; font-size: 0.75em; }
:is(h2, h3, h4):hover .anchor, .anchor:focus { opacity: 0.6; }
.prose strong { font-weight: 700; color: var(--text); }
.prose ul, .prose ol { padding-left: 1.5em; }
.prose li { margin: 0.4em 0; }
.prose li::marker { color: var(--accent); }
.prose blockquote { margin: 1.6em 0; padding: 14px 22px; border-left: 3px solid var(--accent); background: var(--surface); border-radius: 0 10px 10px 0; color: var(--text); }
.prose blockquote p { margin: 0.4em 0; }
.prose hr { border: 0; text-align: center; margin: 2.6em 0; }
.prose hr::after { content: "・・・"; color: var(--muted); letter-spacing: 0.6em; }
.prose code { font-family: var(--mono); font-size: 0.86em; background: var(--code-bg); padding: 2px 6px; border-radius: 5px; overflow-wrap: anywhere; }
.prose pre { background: var(--code-bg); border: 1px solid var(--border); border-radius: 10px; padding: 16px 18px; overflow-x: auto; line-height: 1.65; }
.prose pre code { background: none; padding: 0; font-size: 0.88rem; overflow-wrap: normal; }
.prose pre:has(> code.language-text) { white-space: pre-wrap; overflow-wrap: anywhere; }
.table-wrap { overflow-x: auto; margin: 1.6em 0; border: 1px solid var(--border); border-radius: 10px; }
.prose table { border-collapse: collapse; min-width: 100%; font-size: 0.95rem; }
.prose th, .prose td { border-bottom: 1px solid var(--border); padding: 10px 14px; text-align: left; line-height: 1.65; overflow-wrap: break-word; vertical-align: top; }
.prose tr:last-child td { border-bottom: 0; }
.prose th { background: var(--surface); font-weight: 600; }
.prose td code, .prose th code { white-space: nowrap; overflow-wrap: normal; }
.prose img { display: block; margin: 1.6em auto; border-radius: 10px; border: 1px solid var(--border); }

.post-foot { margin-top: 56px; padding-top: 24px; border-top: 1px solid var(--border); font-size: 0.95rem; }
.tags { list-style: none; padding: 0; margin: 0 0 20px; display: flex; flex-wrap: wrap; gap: 8px; }
.tags li { background: var(--surface); border-radius: 999px; padding: 3px 12px; font-size: 0.84rem; color: var(--muted); }
.tags li::before { content: "#"; margin-right: 2px; opacity: 0.6; }
.ai-actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 28px; }
.ai-btn { display: inline-flex; align-items: center; min-height: 34px; padding: 0 14px; border: 1px solid var(--border); border-radius: 999px; background: var(--card); color: var(--text); font: inherit; font-size: 0.86rem; text-decoration: none; cursor: pointer; transition: border-color 0.15s, color 0.15s; }
.ai-btn:hover { border-color: var(--accent); color: var(--accent); }
.ai-btn[data-copy-md] { background: var(--text); border-color: var(--text); color: var(--bg); }
.ai-btn[data-copy-md]:hover { background: var(--accent); border-color: var(--accent); color: #fff; }
.ai-btn[hidden] { display: none; }
.ai-foot { margin-top: 24px; padding: 20px 22px 6px; background: var(--surface); border-radius: 14px; }
.ai-foot p { margin: 0 0 12px; color: var(--muted); font-size: 0.92rem; }
.ai-foot .ai-actions { margin-bottom: 14px; }
.related { max-width: 1080px; margin: 72px auto 0; }

/* 頁尾 */
.site-footer { border-top: 1px solid var(--border); color: var(--muted); font-size: 0.86rem; padding: 24px 0 28px; }
.footer-row { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 24px; }
.site-footer .footer-brand { font-size: 1rem; }
.footer-nav { display: flex; flex-wrap: wrap; gap: 4px 18px; }
.footer-nav a { color: var(--muted); text-decoration: none; }
.footer-nav a:hover { color: var(--accent); }
.footer-note { margin: 10px 0 0; font-size: 0.8rem; }

@media (max-width: 1000px) {
  .card.featured { grid-template-columns: 1fr; }
  .card.featured .card-body { padding: 24px; }
}
@media (max-width: 760px) {
  main.wrap { padding-top: 24px; padding-bottom: 80px; }
  .header-row { gap: 14px; min-height: 56px; }
  .hero { padding: 16px 0 32px; }
  .card.featured .card-body { padding: 20px; }
  .grid { grid-template-columns: 1fr; gap: 16px; }
  .card-cover.placeholder { aspect-ratio: 3 / 1; }
  .section-head { margin-top: 48px; }
  .toc ul { columns: 1; }
  .prose { font-size: 1.0625rem; }
}
@media (prefers-reduced-motion: reduce) {
  .card { transition: none; }
  .card:hover { transform: none; }
}
