/* =========================================================
   Ivan Huang — portfolio
   Light "engineering drawing sheet" theme: paper, ink, ruled lines,
   one vermilion mark-up accent.
   ========================================================= */
:root {
  --paper: #f4f2ec;
  --sheet: #fbfaf7;
  --ink: #1a1a19;
  --ink-2: #3a3935;
  --muted: #5f5d57;
  --dim: #8f8c83;
  --rule: #d9d5ca;
  --rule-2: #b9b4a8;
  --mark: #c8371a;

  --c-silicon: #5a3fb0;
  --c-fpga: #b8325f;
  --c-embedded: #1f7a45;
  --c-robotics: #b86e00;
  --c-perf: #1f5fbf;

  --font-body: "Schibsted Grotesk", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  --max: 1200px;
  --gutter: 16px;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; scroll-padding-top: 72px; }
body {
  margin: 0; background: var(--paper); color: var(--ink);
  font: 400 16px/1.6 var(--font-body);
  -webkit-font-smoothing: antialiased; overflow-x: hidden;
}
img { max-width: 100%; display: block; }
a { color: inherit; }
h1, h2, h3, h4 { margin: 0; font-family: var(--font-body); letter-spacing: -0.02em; }
.mono { font-family: var(--font-mono); }
b { font-weight: 600; }
.skip { position: absolute; left: -999px; top: 8px; background: var(--ink); color: var(--sheet); padding: 8px 12px; z-index: 100; }
.skip:focus { left: 8px; }
:focus-visible { outline: 2px solid var(--mark); outline-offset: 2px; }

/* ---------- nav ---------- */
.nav {
  position: sticky; top: 0; z-index: 50;
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px max(var(--gutter), calc((100vw - var(--max)) / 2));
  background: var(--paper); border-bottom: 1px solid var(--rule);
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; font-weight: 700; font-size: 16px; letter-spacing: -0.01em; }
.brand-mark { width: 30px; height: 19px; fill: none; stroke: var(--ink); stroke-width: 2.2; }
.nav-links { display: flex; gap: 2px; }
.nav-links a { text-decoration: none; font-size: 13px; color: var(--ink-2); padding: 6px 10px; border: 1px solid transparent; }
.nav-links a span { color: var(--mark); }
.nav-links a:hover { border-color: var(--rule-2); background: var(--sheet); }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 8px; text-decoration: none; cursor: pointer;
  font: 600 15px var(--font-body); padding: 11px 18px; border: 1.5px solid var(--ink);
  transition: background .15s, color .15s;
}
.btn-ink { background: var(--ink); color: var(--sheet); }
.btn-ink:hover { background: var(--mark); border-color: var(--mark); }
.btn-line { background: transparent; color: var(--ink); }
.btn-line:hover { background: var(--sheet); }

/* ---------- hero sheet ---------- */
.hero { padding: 36px var(--gutter) 16px; }
.sheet {
  position: relative; max-width: var(--max); margin: 0 auto; background: var(--sheet);
  border: 1.5px solid var(--ink); padding: 40px 40px 32px;
}
.zones { position: absolute; inset: 0 0 auto 0; display: flex; height: 18px; border-bottom: 1px solid var(--rule); }
.zones span { flex: 1; text-align: center; font-size: 10px; line-height: 18px; color: var(--dim); }
.zones span + span { border-left: 1px solid var(--rule); }

.hero-grid { display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); gap: 48px; align-items: end; padding-top: 22px; }
.eyebrow { margin: 0 0 16px; font-size: 12px; color: var(--mark); letter-spacing: .04em; text-transform: uppercase; }
.hero h1 { font-size: clamp(48px, 7.6vw, 96px); line-height: .95; font-weight: 800; letter-spacing: -0.045em; }
.lede { font-size: clamp(16px, 1.5vw, 18.5px); color: var(--ink-2); max-width: 560px; margin: 22px 0 28px; }
.lede b { color: var(--ink); }
.hero-cta { display: flex; flex-wrap: wrap; gap: 10px; }

.titleblock { width: 100%; border-collapse: collapse; border: 1.5px solid var(--ink); font-size: 12.5px; }
.titleblock th, .titleblock td { border: 1px solid var(--rule-2); padding: 9px 12px; text-align: left; vertical-align: top; }
.titleblock th { width: 96px; font-weight: 500; font-size: 10.5px; letter-spacing: .06em; text-transform: uppercase; color: var(--dim); background: var(--paper); }
.titleblock td { color: var(--ink); }

/* timing diagram */
.wave { margin: 36px 0 0; border: 1px solid var(--rule-2); }
.wave figcaption, .fig figcaption, .modal-fig figcaption {
  display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  font-size: 11px; color: var(--muted); padding: 7px 12px; border-bottom: 1px solid var(--rule);
  background: var(--paper);
}
.wave-tip b { color: var(--mark); font-weight: 500; }
#wave { display: block; width: 100%; height: 148px; cursor: default; }

/* index table */
.toc { margin-top: 28px; }
.toc-head, .toc li { display: grid; grid-template-columns: 56px minmax(0, 1fr) 110px 24px; gap: 16px; align-items: baseline; }
.toc-head { font-size: 10.5px; letter-spacing: .06em; text-transform: uppercase; color: var(--dim); padding: 0 8px 8px; border-bottom: 1.5px solid var(--ink); }
.toc-head span:nth-child(3) { grid-column: 3 / 5; }
.toc ol { list-style: none; margin: 0; padding: 0; }
.toc li { padding: 13px 8px; border-bottom: 1px solid var(--rule); cursor: pointer; transition: background .15s; }
.toc li:hover, .toc li:focus-visible { background: var(--paper); }
.toc .num { font: 500 13px var(--font-mono); color: var(--accent); }
.toc .name b { display: block; font-size: 17px; font-weight: 600; letter-spacing: -0.01em; }
.toc .name small { color: var(--muted); font-size: 14px; }
.toc .count { font: 400 12.5px var(--font-mono); color: var(--muted); }
.toc .go { font-size: 16px; color: var(--dim); transition: transform .15s, color .15s; }
.toc li:hover .go { color: var(--mark); transform: translateX(4px); }

/* ---------- sections ---------- */
section.projects, section.about, section.contact { max-width: calc(var(--max) + 2 * var(--gutter)); margin: 0 auto; padding: 56px var(--gutter); }
.section-head { display: grid; grid-template-columns: 64px minmax(0, 1fr); gap: 8px; align-items: baseline; border-top: 1.5px solid var(--ink); padding-top: 18px; margin-bottom: 28px; }
.sec { font-size: 15px; color: var(--mark); }
.section-head h2 { font-size: clamp(30px, 4vw, 44px); font-weight: 800; letter-spacing: -0.035em; line-height: 1.05; }
.section-sub { color: var(--muted); max-width: 640px; margin: 8px 0 0; }
.section-sub b { color: var(--ink); }

/* filters: a straight segmented bar */
.filters {
  position: sticky; top: 55px; z-index: 20; display: flex; overflow-x: auto; scrollbar-width: none;
  margin: 0 0 40px; background: var(--paper); border: 1px solid var(--rule-2);
}
.filters::-webkit-scrollbar { display: none; }
.tab {
  --accent: var(--ink);
  flex: 1 0 auto; display: inline-flex; align-items: center; justify-content: center; gap: 8px; cursor: pointer;
  padding: 10px 16px; border: 0; border-right: 1px solid var(--rule-2); background: transparent;
  font: 500 12.5px var(--font-mono); color: var(--muted); white-space: nowrap;
}
.tab:last-child { border-right: 0; }
.tab i { width: 8px; height: 8px; background: var(--accent); }
.tab span { color: var(--dim); }
.tab:hover { background: var(--sheet); color: var(--ink); }
.tab[aria-selected="true"] { background: var(--ink); color: var(--sheet); }
.tab[aria-selected="true"] span { color: var(--rule-2); }

/* ---------- catalog ---------- */
.category { margin-bottom: 64px; }
.category[hidden] { display: none; }
.cat-head { display: grid; grid-template-columns: 64px minmax(0, 1fr) auto; gap: 8px; align-items: baseline; padding-bottom: 14px; margin-bottom: 22px; border-bottom: 1px solid var(--rule-2); }
.cat-head .num { font: 500 13px var(--font-mono); color: var(--accent); }
.cat-head h3 { font-size: 24px; font-weight: 700; display: flex; align-items: center; gap: 10px; }
.cat-head h3::before { content: ""; width: 10px; height: 10px; background: var(--accent); }
.cat-head p { margin: 4px 0 0; color: var(--muted); font-size: 14.5px; }
.cat-num { font: 400 12px var(--font-mono); color: var(--dim); white-space: nowrap; }

.grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 24px; }

.card {
  --accent: var(--ink);
  display: flex; flex-direction: column; background: var(--sheet); border: 1px solid var(--rule-2);
  transition: border-color .15s, box-shadow .15s;
}
.card:hover { border-color: var(--ink); box-shadow: 6px 6px 0 var(--rule); }
.fig { margin: 0; border-bottom: 1px solid var(--rule-2); }
.fig figcaption { border-bottom: 0; border-top: 1px solid var(--rule); }
.fig figcaption .pn { color: var(--accent); font-weight: 500; }
.demo { position: relative; aspect-ratio: 16 / 9.4; background: #fbfaf7; }
.demo canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

.card-body { display: flex; flex-direction: column; gap: 12px; padding: 20px 22px 20px; flex: 1; }
.card-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; font: 400 12px var(--font-mono); color: var(--muted); }
.pn-box { font-weight: 600; color: var(--accent); border: 1px solid currentColor; padding: 0 6px; }
.tag-status { color: var(--mark); border: 1px dashed var(--mark); padding: 0 6px; font-size: 11px; }
.card h4 { margin: 0; font-size: 21px; line-height: 1.25; font-weight: 700; letter-spacing: -0.02em; }
.card p { margin: 0; color: var(--ink-2); font-size: 15px; }
.card p.how { color: var(--muted); font-size: 14.5px; }
.card p.how b { color: var(--ink); }

/* key specs: a ruled three-column strip */
.specs { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); border-top: 1px solid var(--rule-2); border-bottom: 1px solid var(--rule-2); margin-top: 4px; }
.specs div { padding: 9px 12px 9px 0; line-height: 1.25; }
.specs div + div { padding-left: 12px; border-left: 1px solid var(--rule); }
.specs strong { display: block; font-size: 16px; font-weight: 700; letter-spacing: -0.01em; }
.specs small { font-size: 12px; color: var(--muted); }

.card-foot { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; margin-top: auto; padding-top: 4px; }
.tags { display: flex; flex-wrap: wrap; gap: 4px 0; }
.tags span { font: 400 11.5px var(--font-mono); color: var(--dim); }
.tags span + span::before { content: "/"; margin: 0 7px; color: var(--rule-2); }
.card-actions { flex: none; display: flex; gap: 8px; }
.details-btn {
  display: inline-flex; align-items: center; gap: 6px; cursor: pointer; text-decoration: none;
  font: 500 12.5px var(--font-mono); color: var(--ink); background: var(--sheet); border: 1px solid var(--ink);
  padding: 6px 12px; transition: background .15s, color .15s;
}
.details-btn:hover { background: var(--ink); color: var(--sheet); }
.code-btn { border-color: var(--rule-2); color: var(--ink-2); }
.code-btn:hover { background: var(--paper); color: var(--ink); border-color: var(--ink); }

/* ---------- about ---------- */
.about-grid { display: grid; grid-template-columns: 280px minmax(0, 1fr); gap: 48px; align-items: start; }
.portrait { margin: 0; border: 1px solid var(--rule-2); background: var(--sheet); position: sticky; top: 120px; }
.portrait img { width: 100%; aspect-ratio: 1; object-fit: cover; filter: saturate(.92); }
.portrait figcaption { font-size: 11px; color: var(--muted); padding: 8px 10px; border-top: 1px solid var(--rule); }
.about-copy > p { color: var(--ink-2); font-size: 17px; margin: 0 0 14px; max-width: 760px; }
.about-copy > p b { color: var(--ink); }
.table-title { margin: 34px 0 0; font-size: 11px; font-weight: 500; letter-spacing: .06em; text-transform: uppercase; color: var(--dim); padding-bottom: 8px; border-bottom: 1.5px solid var(--ink); }

.spec-table { width: 100%; border-collapse: collapse; }
.spec-table th, .spec-table td { text-align: left; vertical-align: top; padding: 12px 0; border-bottom: 1px solid var(--rule); }
.spec-table th { width: 150px; padding-right: 16px; font-size: 12px; font-weight: 500; color: var(--accent, var(--muted)); }
.spec-table td b { display: block; font-weight: 600; }
.spec-table td span { font-size: 14px; color: var(--muted); }
.spec-table td ul { margin: 0; padding: 0; list-style: none; display: flex; flex-wrap: wrap; gap: 4px 0; font-size: 14.5px; color: var(--ink-2); }
.spec-table td li + li::before { content: "·"; margin: 0 8px; color: var(--dim); }

/* ---------- contact / footer ---------- */
.contact-table { max-width: 720px; margin-left: 72px; }
.contact-table a { text-decoration: none; border-bottom: 1px solid var(--rule-2); font-size: 16px; }
.contact-table a:hover { color: var(--mark); border-color: var(--mark); }
.footer {
  max-width: var(--max); margin: 24px auto 0; padding: 18px var(--gutter) 36px;
  display: flex; justify-content: space-between; flex-wrap: wrap; gap: 8px;
  font-size: 11.5px; color: var(--dim); border-top: 1px solid var(--rule-2);
}

/* ---------- modal ---------- */
.modal {
  --accent: var(--ink);
  width: min(1100px, calc(100vw - 32px)); max-height: calc(100vh - 48px); padding: 0;
  border: 1.5px solid var(--ink); background: var(--sheet); color: var(--ink); overflow: hidden;
  box-shadow: 10px 10px 0 rgba(26, 26, 25, .12);
}
.modal::backdrop { background: rgba(26, 26, 25, .38); }
.modal[open] { animation: modal-in .2s ease-out; }
@keyframes modal-in { from { opacity: 0; transform: translateY(10px); } }
.modal-shell { display: grid; grid-template-columns: 1.05fr 1fr; max-height: calc(100vh - 48px); }
.modal-fig { margin: 0; display: flex; flex-direction: column; border-right: 1px solid var(--rule-2); }
.modal-demo { position: relative; flex: 1; min-height: 360px; background: #fbfaf7; }
.modal-demo canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.modal-fig figcaption { border-bottom: 0; border-top: 1px solid var(--rule); }
.modal-body { padding: 30px 32px 28px; overflow-y: auto; max-height: calc(100vh - 48px); }
.modal-close {
  position: absolute; top: 12px; right: 12px; z-index: 3; width: 34px; height: 34px; cursor: pointer;
  background: var(--sheet); color: var(--ink); border: 1px solid var(--ink); font-size: 14px;
}
.modal-close:hover { background: var(--ink); color: var(--sheet); }
.modal-body .card-meta { margin-bottom: 10px; padding-right: 40px; }
.modal-body h3 { font-size: 30px; line-height: 1.1; font-weight: 800; letter-spacing: -0.03em; margin-bottom: 12px; }
.modal-body .purpose { color: var(--ink-2); font-size: 16px; margin: 0 0 16px; }
.modal-body h5 { font: 500 11px var(--font-mono); color: var(--dim); letter-spacing: .06em; text-transform: uppercase; margin: 26px 0 10px; padding-bottom: 6px; border-bottom: 1px solid var(--ink); }
.steps { list-style: none; margin: 0; padding: 0; counter-reset: s; }
.steps li { counter-increment: s; display: grid; grid-template-columns: 34px minmax(0, 1fr); padding: 9px 0; border-bottom: 1px solid var(--rule); color: var(--muted); font-size: 14.5px; }
.steps li::before { content: counter(s, decimal-leading-zero); font: 500 11.5px/1.9 var(--font-mono); color: var(--accent); }
.steps li b { color: var(--ink); font-weight: 600; }
.figs { display: grid; gap: 14px; }
.figs figure { margin: 0; border: 1px solid var(--rule-2); background: #fff; }
.figs figure.dark { background: #111; }
.figs img { width: 100%; height: auto; }
.figs figcaption { font: 400 11.5px var(--font-mono); color: var(--muted); padding: 7px 10px; border-top: 1px solid var(--rule); background: var(--paper); }
.links { display: flex; flex-wrap: wrap; gap: 8px; }
.links a { font: 500 12.5px var(--font-mono); text-decoration: none; padding: 6px 12px; border: 1px solid var(--ink); }
.links a:hover { background: var(--ink); color: var(--sheet); }
.note { font-size: 12.5px; color: var(--dim); margin-top: 18px; }

/* ---------- responsive ---------- */
@media (max-width: 1020px) {
  .hero-grid { grid-template-columns: 1fr; gap: 32px; }
  .grid { grid-template-columns: 1fr; }
  .modal-shell { grid-template-columns: 1fr; overflow-y: auto; }
  .modal-fig { border-right: 0; border-bottom: 1px solid var(--rule-2); }
  .modal-demo { flex: none; min-height: 0; aspect-ratio: 16 / 10; }
  .modal-body { max-height: none; overflow: visible; }
}
@media (max-width: 720px) {
  .hero { padding-top: 20px; }
  .sheet { padding: 32px 18px 22px; }
  .nav-links a { padding: 6px 6px; font-size: 12px; }
  .nav-links a span { display: none; }
  .titleblock th { width: 78px; }
  .toc-head, .toc li { grid-template-columns: 34px minmax(0, 1fr) 20px; }
  .toc .count, .toc-head span:nth-child(3) { display: none; }
  .section-head, .cat-head { grid-template-columns: 1fr; gap: 2px; }
  .cat-num { display: none; }
  .about-grid { grid-template-columns: 1fr; gap: 24px; }
  .portrait { position: static; max-width: 240px; }
  .spec-table th { width: 92px; }
  .contact-table { margin-left: 0; }
  .card-body { padding: 18px; }
  .fig figcaption > span:last-child, .modal-fig figcaption > span:last-child { display: none; }
  .specs strong { font-size: 14.5px; }
  .modal-body { padding: 22px 18px; }
  .modal-body h3 { font-size: 24px; }
}
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
