:root {
  --canvas: #e8e7e2;
  --paper: #fffefa;
  --ink: #171b1e;
  --muted: #5d6265;
  --navy: #21394b;
  --burgundy: #7d2731;
  --rule: #c9c8c2;
  --rule-dark: #8f9393;
  --soft: #f3f1eb;
  --serif: Georgia, "Times New Roman", "PMingLiU", "Noto Serif TC", serif;
  --sans: Inter, "Segoe UI", "Noto Sans TC", Arial, sans-serif;
  color-scheme: light;
  font-synthesis: none;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; scroll-padding-top: 5rem; }
body { margin: 0; overflow-x: hidden; background: var(--canvas); color: var(--ink); font-family: var(--serif); font-size: 17px; line-height: 1.75; text-rendering: optimizeLegibility; }
body.drawer-open { overflow: hidden; }
a { color: var(--navy); }
a:hover { color: var(--burgundy); }
button { font: inherit; }

.skip-link { position: fixed; z-index: 100; top: .5rem; left: .5rem; padding: .55rem .8rem; background: var(--ink); color: #fff; font: 700 .75rem var(--sans); transform: translateY(-150%); }
.skip-link:focus { transform: none; }

.site-bar { position: sticky; z-index: 40; top: 0; display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; min-height: 60px; padding: .65rem max(1rem, calc((100vw - 1120px) / 2)); border-bottom: 1px solid #bbbcb8; background: rgba(246,245,241,.96); backdrop-filter: blur(10px); font-family: var(--sans); }
.site-name { color: var(--ink); font-size: .85rem; font-weight: 800; letter-spacing: .13em; text-decoration: none; text-transform: lowercase; }
.drawer-trigger, .github-link { color: var(--ink); font-size: .72rem; font-weight: 750; letter-spacing: .06em; text-decoration: none; text-transform: uppercase; }
.drawer-trigger { justify-self: start; display: inline-flex; align-items: center; gap: .55rem; padding: .35rem 0; border: 0; background: transparent; cursor: pointer; }
.drawer-trigger span:first-child { color: var(--burgundy); font-size: 1rem; }
.github-link { justify-self: end; }

.drawer-backdrop { position: fixed; z-index: 70; inset: 0; background: rgba(20,22,23,.54); opacity: 0; transition: opacity .22s ease; }
.drawer-backdrop.visible { opacity: 1; }
.project-drawer { position: fixed; z-index: 80; top: 0; left: 0; display: flex; flex-direction: column; width: min(390px,92vw); height: 100dvh; padding: 1.4rem 1.2rem; border-right: 1px solid var(--rule-dark); background: var(--paper); box-shadow: 16px 0 55px rgba(20,23,25,.22); transform: translateX(-105%); transition: transform .24s ease; }
.project-drawer.open { transform: none; }
.drawer-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; padding: .2rem .35rem 1.25rem; border-bottom: 2px solid var(--ink); }
.drawer-head strong { display: block; margin-top: .25rem; font-size: 1.25rem; font-weight: 500; }
.drawer-close { padding: .2rem; border: 0; background: transparent; font: 700 .7rem var(--sans); cursor: pointer; }
.drawer-nav { display: grid; margin-top: .7rem; }
.drawer-nav a { display: grid; grid-template-columns: 2.1rem 1fr; gap: 0 .8rem; padding: 1rem .35rem; border-bottom: 1px solid var(--rule); color: var(--ink); text-decoration: none; }
.drawer-nav a:hover, .drawer-nav a.active { background: var(--soft); }
.drawer-nav a.active { box-shadow: inset 3px 0 var(--burgundy); }
.drawer-nav span { grid-row: 1 / 3; color: var(--burgundy); font: 750 .68rem var(--sans); }
.drawer-nav b { font-size: .96rem; font-weight: 600; line-height: 1.4; }
.drawer-nav small { margin-top: .15rem; color: var(--muted); font: .7rem/1.45 var(--sans); }
.drawer-note { margin: auto .35rem 0; padding-top: 1rem; border-top: 1px solid var(--rule); color: var(--muted); font-size: .72rem; line-height: 1.55; }

.home-shell, .article-shell { width: min(1120px,calc(100vw - 2rem)); margin: 0 auto; padding: 2.5rem 0 4rem; }
.home-paper, .article-paper { margin-bottom: 2rem; border: 1px solid #d2d1cb; background: var(--paper); box-shadow: 0 12px 35px rgba(27,31,33,.1), 0 2px 5px rgba(27,31,33,.06); }
.intro-card { display: grid; grid-template-columns: minmax(0,1.65fr) minmax(260px,.7fr); gap: 4rem; min-height: 690px; padding: 5.5rem 5.6rem 4.5rem; }
.intro-copy { align-self: center; }
.eyebrow { color: var(--burgundy); font: 750 .67rem/1.4 var(--sans); letter-spacing: .14em; text-transform: uppercase; }
.intro-card h1 { margin: 1.25rem 0 1.6rem; font-size: clamp(3.4rem,7vw,6.6rem); font-weight: 500; letter-spacing: -.055em; line-height: .98; }
.intro-card h1 em { color: var(--navy); font-weight: 500; }
.intro-lead { max-width: 650px; margin: 0 0 1.2rem; font-size: 1.25rem; line-height: 1.65; }
.intro-copy > p:not(.intro-lead) { max-width: 650px; color: #42484b; }
.intro-actions { display: flex; flex-wrap: wrap; align-items: center; gap: .8rem 1.2rem; margin-top: 2rem; font-family: var(--sans); }
.primary-button { padding: .7rem 1rem; border: 1px solid var(--ink); background: var(--ink); color: #fff; font: 750 .74rem var(--sans); cursor: pointer; }
.primary-button:hover { border-color: var(--burgundy); background: var(--burgundy); }
.text-link { color: var(--ink); font-size: .73rem; font-weight: 750; text-underline-offset: .25rem; }
.margin-note { align-self: center; padding: 1.3rem 1.2rem 1.5rem; border-top: 3px solid var(--navy); border-bottom: 1px solid var(--rule); background: var(--soft); }
.note-number { color: var(--burgundy); font: 750 .62rem var(--sans); letter-spacing: .1em; }
.margin-note h2 { margin: .7rem 0 .75rem; font-size: 1.05rem; }
.margin-note ul { margin: 0; padding-left: 1.1rem; }
.margin-note li { margin: .65rem 0; font-size: .86rem; line-height: 1.55; }

.project-index, .working-note { padding: 4rem 5rem; }
.index-heading { display: grid; grid-template-columns: 1.3fr .7fr; align-items: end; gap: 3rem; padding-bottom: 2rem; border-bottom: 2px solid var(--ink); }
.index-heading h2, .working-note h2 { margin: .55rem 0 0; font-size: clamp(2rem,4vw,3.35rem); font-weight: 500; line-height: 1.18; letter-spacing: -.03em; }
.index-heading p { margin: 0; color: var(--muted); font-size: .88rem; line-height: 1.6; }
.project-row { display: grid; grid-template-columns: 3.5rem 1fr auto; gap: 1.6rem; align-items: center; padding: 2.2rem 0; border-bottom: 1px solid var(--rule); }
.project-row:last-child { border-bottom-color: var(--ink); }
.project-no { color: var(--burgundy); font: 750 .72rem var(--sans); }
.project-type { color: var(--muted); font: 700 .64rem var(--sans); letter-spacing: .09em; text-transform: uppercase; }
.project-summary h3 { margin: .35rem 0 .55rem; font-size: 1.42rem; font-weight: 500; line-height: 1.35; }
.project-summary h3 a { color: var(--ink); text-decoration: none; }
.project-summary h3 a:hover { color: var(--burgundy); }
.project-summary p { max-width: 720px; margin: 0; color: #454a4d; font-size: .9rem; line-height: 1.6; }
.row-link { white-space: nowrap; color: var(--ink); font: 750 .69rem var(--sans); text-decoration: none; }
.principle-grid { display: grid; grid-template-columns: repeat(3,1fr); margin-top: 2.2rem; border-top: 2px solid var(--ink); border-bottom: 1px solid var(--ink); }
.principle-grid > div { padding: 1.4rem; border-right: 1px solid var(--rule); }
.principle-grid > div:last-child { border-right: 0; }
.principle-grid b { color: var(--burgundy); font: 750 .67rem var(--sans); }
.principle-grid h3 { margin: .55rem 0 .45rem; font-size: 1rem; }
.principle-grid p { margin: 0; color: var(--muted); font-size: .82rem; line-height: 1.58; }

.site-footer { display: flex; justify-content: space-between; gap: 1rem; width: min(1120px,calc(100vw - 2rem)); margin: -1rem auto 3rem; color: #555b5e; font: 650 .67rem var(--sans); letter-spacing: .04em; }

/* Plain personal homepage — intentionally document-like, not portfolio-like. */
.simple-home { width: min(820px, calc(100vw - 2rem)); margin: 0 auto; padding: 2.5rem 0 4rem; }
.profile-document { min-height: 760px; padding: 5rem 5.4rem; border: 1px solid #d2d1cb; background: var(--paper); box-shadow: 0 8px 24px rgba(27,31,33,.08); }
.profile-header { margin-bottom: 3.2rem; padding-bottom: 1.5rem; border-bottom: 2px solid var(--ink); }
.profile-header h1 { margin: 0; font-size: clamp(2.2rem,6vw,3.3rem); font-weight: 500; line-height: 1.2; letter-spacing: -.025em; }
.profile-header p { margin: .55rem 0 0; color: var(--muted); font-size: 1rem; }
.profile-document section { margin-top: 2.8rem; }
.profile-document section h2 { margin: 0 0 .85rem; font-size: 1.25rem; font-weight: 650; }
.profile-document section > p { margin: 0; }
.contact-list { margin: 0; padding: 0; list-style: none; }
.contact-list li { display: grid; grid-template-columns: 6rem 1fr; gap: 1rem; padding: .6rem 0; border-bottom: 1px solid var(--rule); }
.contact-list span { font-weight: 650; }
.contact-list a { overflow-wrap: anywhere; }
.post-list { border-top: 1px solid var(--ink); }
.post-entry { padding: 1.5rem 0; border-bottom: 1px solid var(--rule); }
.post-entry time { display: block; margin-bottom: .35rem; color: var(--muted); font: 650 .68rem var(--sans); }
.post-entry h3 { margin: 0 0 .4rem; font-size: 1.08rem; font-weight: 650; }
.post-entry h3 a { color: var(--ink); text-decoration-thickness: 1px; text-underline-offset: .2rem; }
.post-entry p { margin: 0; color: var(--muted); font-size: .86rem; line-height: 1.6; }
.simple-footer { width: min(820px, calc(100vw - 2rem)); }

/* Project article */
.article-paper { padding: 4.5rem 5.7rem; }
.article-head { padding-bottom: 2.6rem; border-bottom: 2px solid var(--ink); }
.article-kicker { display: flex; justify-content: space-between; gap: 1rem; font: 700 .67rem var(--sans); letter-spacing: .1em; text-transform: uppercase; }
.article-kicker span:first-child { color: var(--burgundy); }
.article-kicker span:last-child { color: var(--muted); }
.article-head h1 { max-width: 850px; margin: 2rem 0 1rem; font-size: clamp(2.7rem,5.5vw,5.1rem); font-weight: 500; line-height: 1.08; letter-spacing: -.045em; }
.article-deck { max-width: 800px; margin: 0; color: var(--navy); font-size: 1.18rem; line-height: 1.65; }
.article-meta { display: flex; flex-wrap: wrap; gap: .5rem 1rem; margin-top: 1.6rem; color: var(--muted); font: 650 .68rem var(--sans); }
.orientation { display: grid; grid-template-columns: 1fr .72fr; gap: 2.4rem; margin: 2.8rem 0; }
.orientation-main { padding: 1.35rem 1.5rem; border-left: 4px solid var(--burgundy); background: var(--soft); }
.orientation-main h2 { margin: 0 0 .55rem; font-size: 1.1rem; }
.orientation-main p { margin: 0; font-size: .95rem; }
.orientation-aside { padding-top: 1rem; border-top: 2px solid var(--navy); }
.orientation-aside b { font: 750 .68rem var(--sans); letter-spacing: .08em; text-transform: uppercase; }
.orientation-aside p { margin: .55rem 0 0; color: var(--muted); font-size: .82rem; line-height: 1.55; }
.article-toc { margin: 2.5rem 0 3rem; padding: 1.1rem 1.3rem; border-top: 1px solid var(--rule-dark); border-bottom: 1px solid var(--rule-dark); }
.article-toc strong { font: 750 .68rem var(--sans); letter-spacing: .08em; text-transform: uppercase; }
.article-toc ol { display: grid; grid-template-columns: repeat(2,1fr); gap: .35rem 2rem; margin: .8rem 0 0; padding-left: 1.25rem; }
.article-toc a { color: var(--ink); font-size: .82rem; text-decoration: none; }
.article-section { max-width: 860px; margin: 4.5rem auto 0; }
.section-label { display: block; margin-bottom: .55rem; color: var(--burgundy); font: 750 .66rem var(--sans); letter-spacing: .13em; text-transform: uppercase; }
.article-section h2 { margin: 0 0 1.2rem; font-size: clamp(1.8rem,3.5vw,2.8rem); font-weight: 500; line-height: 1.22; letter-spacing: -.025em; }
.article-section h3 { margin: 2rem 0 .65rem; font-size: 1.2rem; }
.article-section p { margin: 0 0 1.15rem; }
.article-section .lead { font-size: 1.1rem; }
.article-section ul, .article-section ol { padding-left: 1.35rem; }
.article-section li { margin: .55rem 0; }
.problem-grid, .layer-grid, .metric-grid { display: grid; gap: 1rem; margin: 1.6rem 0 2rem; }
.problem-grid { grid-template-columns: repeat(3,1fr); }
.layer-grid { grid-template-columns: repeat(2,1fr); }
.metric-grid { grid-template-columns: repeat(4,1fr); gap: 0; border-top: 2px solid var(--ink); border-bottom: 1px solid var(--ink); }
.problem-grid > div, .layer-grid > div { padding: 1.1rem 1.2rem; border-top: 2px solid var(--navy); background: var(--soft); }
.problem-grid b, .layer-grid b { color: var(--burgundy); font: 750 .68rem var(--sans); }
.problem-grid h3, .layer-grid h3 { margin: .45rem 0 .4rem; font-size: 1rem; }
.problem-grid p, .layer-grid p { margin: 0; color: var(--muted); font-size: .82rem; line-height: 1.55; }
.metric-grid > div { padding: 1rem .8rem; border-right: 1px solid var(--rule); }
.metric-grid > div:last-child { border-right: 0; }
.metric-grid strong { display: block; font-size: 1.35rem; font-weight: 500; line-height: 1.2; }
.metric-grid span { color: var(--muted); font: 650 .66rem var(--sans); }
.flow-line { display: grid; grid-template-columns: repeat(5,1fr); margin: 1.8rem 0; padding: 1.2rem; border-top: 2px solid var(--navy); border-bottom: 1px solid var(--rule); background: var(--soft); }
.flow-line div { padding: .35rem .7rem; border-right: 1px solid var(--rule); text-align: center; font: 700 .72rem/1.45 var(--sans); }
.flow-line div:last-child { border-right: 0; }
.flow-line small { display: block; margin-top: .25rem; color: var(--muted); font-weight: 500; }
.code-block { position: relative; margin: 1.8rem 0; border: 1px solid var(--rule-dark); background: #f5f4ef; }
.code-block > span { display: block; padding: .55rem .8rem; border-bottom: 1px solid var(--rule); color: var(--navy); font: 750 .65rem var(--sans); letter-spacing: .1em; text-transform: uppercase; }
.code-block pre { overflow-x: auto; margin: 0; padding: 1.1rem; font: 500 .78rem/1.65 Consolas,"SFMono-Regular",monospace; white-space: pre; }
.copy-button { position: absolute; top: .35rem; right: .5rem; padding: .28rem .6rem; border: 1px solid var(--rule-dark); background: var(--paper); font: 700 .63rem var(--sans); cursor: pointer; }
.article-table-wrap { overflow-x: auto; margin: 1.8rem 0; }
.article-table { width: 100%; border-collapse: collapse; font-size: .8rem; line-height: 1.45; }
.article-table caption { margin-bottom: .6rem; text-align: left; font-size: .77rem; }
.article-table th, .article-table td { padding: .65rem .7rem; border-bottom: 1px solid var(--rule); text-align: left; vertical-align: top; }
.article-table thead th { border-top: 2px solid var(--ink); border-bottom: 1px solid var(--ink); font: 750 .67rem var(--sans); }
.article-table tbody tr:last-child td { border-bottom-color: var(--ink); }
.article-table .highlight td { background: #f4ece9; font-weight: 700; }
.figure-grid { display: grid; grid-template-columns: repeat(2,1fr); gap: 1.3rem; margin: 2rem 0; }
.figure-grid figure, .full-figure { min-width: 0; margin: 0; }
.figure-grid .wide { grid-column: 1 / -1; }
.figure-button { display: block; width: 100%; padding: 0; border: 1px solid var(--rule); background: #fff; cursor: zoom-in; }
.figure-button:hover { border-color: var(--burgundy); box-shadow: 0 5px 16px rgba(35,31,30,.12); }
.figure-button img, .full-figure img { display: block; width: 100%; height: auto; }
figcaption { margin-top: .55rem; color: var(--muted); font-size: .76rem; line-height: 1.5; }
figcaption b { color: var(--ink); font-family: var(--sans); }
.callout { margin: 1.8rem 0; padding: 1.15rem 1.3rem; border-left: 4px solid var(--burgundy); background: var(--soft); }
.callout strong { font: 750 .7rem var(--sans); letter-spacing: .05em; text-transform: uppercase; }
.callout p { margin: .4rem 0 0; }
.next-project { display: flex; justify-content: space-between; align-items: center; gap: 1rem; max-width: 860px; margin: 4.5rem auto 0; padding-top: 1.2rem; border-top: 2px solid var(--ink); font-family: var(--sans); }
.next-project span { color: var(--muted); font-size: .67rem; text-transform: uppercase; letter-spacing: .08em; }
.next-project a { color: var(--ink); font-size: .82rem; font-weight: 750; text-decoration: none; }
.lightbox { width: min(1220px,94vw); max-height: 92vh; padding: 2.6rem 1rem 1rem; border: 0; background: var(--paper); box-shadow: 0 20px 70px rgba(0,0,0,.35); }
.lightbox::backdrop { background: rgba(15,18,20,.78); }
.lightbox img { display: block; max-width: 100%; max-height: calc(92vh - 4rem); margin: auto; }
.lightbox-close { position: absolute; top: .55rem; right: .75rem; border: 0; background: transparent; font: 700 .72rem var(--sans); cursor: pointer; }

@media (max-width: 840px) {
  body { font-size: 16px; }
  .home-shell, .article-shell { padding-top: 1.2rem; }
  .intro-card { grid-template-columns: 1fr; gap: 2.5rem; min-height: 0; padding: 4rem 2.5rem; }
  .intro-card h1 { font-size: clamp(3rem,12vw,5rem); }
  .project-index, .working-note, .article-paper { padding: 3.2rem 2.5rem; }
  .index-heading { grid-template-columns: 1fr; gap: 1rem; }
  .project-row { grid-template-columns: 2.5rem 1fr; }
  .row-link { grid-column: 2; }
  .principle-grid { grid-template-columns: 1fr; }
  .principle-grid > div { border-right: 0; border-bottom: 1px solid var(--rule); }
  .principle-grid > div:last-child { border-bottom: 0; }
  .orientation { grid-template-columns: 1fr; gap: 1rem; }
  .problem-grid { grid-template-columns: 1fr; }
  .metric-grid { grid-template-columns: repeat(2,1fr); }
  .metric-grid > div:nth-child(2) { border-right: 0; }
  .metric-grid > div:nth-child(-n+2) { border-bottom: 1px solid var(--rule); }
  .flow-line { grid-template-columns: 1fr; }
  .flow-line div { padding: .65rem; border-right: 0; border-bottom: 1px solid var(--rule); }
  .flow-line div:last-child { border-bottom: 0; }
}

@media (max-width: 560px) {
  .site-bar { grid-template-columns: 1fr auto; }
  .site-name { justify-self: end; }
  .github-link { display: none; }
  .drawer-trigger span:last-child { display: none; }
  .home-shell, .article-shell { width: min(100% - 1rem,1120px); }
  .simple-home { width: min(100% - 1rem,820px); padding-top: 1rem; }
  .profile-document { min-height: 0; padding: 3rem 1.4rem; }
  .contact-list li { grid-template-columns: 1fr; gap: .15rem; }
  .intro-card, .project-index, .working-note, .article-paper { padding: 2.8rem 1.25rem; }
  .intro-card h1 { font-size: 3rem; }
  .intro-lead { font-size: 1.08rem; }
  .project-row { grid-template-columns: 1fr; gap: .5rem; }
  .project-no, .row-link { grid-column: auto; }
  .article-head h1 { font-size: 2.65rem; }
  .article-kicker { flex-direction: column; }
  .article-toc ol, .layer-grid, .figure-grid { grid-template-columns: 1fr; }
  .figure-grid .wide { grid-column: auto; }
  .metric-grid { grid-template-columns: 1fr; }
  .metric-grid > div { border-right: 0; border-bottom: 1px solid var(--rule); }
  .metric-grid > div:last-child { border-bottom: 0; }
  .site-footer, .next-project { align-items: flex-start; flex-direction: column; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .project-drawer, .drawer-backdrop { transition: none; }
}
