/* Design system: ui-ux-pro-max "Leo Yu" — Brutalism, monochrome + blue accent,
   Archivo / Space Grotesk, spacious density, subtle motion. */
:root {
  --bg: #FAFAFA;
  --fg: #09090B;
  --secondary: #3F3F46;
  --muted: #475569;
  --muted-bg: #E8ECF0;
  --border: #E4E4E7;
  --accent: #2563EB;
  --on-accent: #FFFFFF;
  --ok: #15803D;

  --sans: "Space Grotesk", "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", sans-serif;
  --display: "Archivo", "Noto Sans TC", sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, monospace;

  --rule: 2px solid var(--fg);
  --hair: 1px solid var(--fg);
  --gutter: clamp(16px, 5vw, 64px);
  --measure: 38em;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #18181B;
    --fg: #FAFAFA;
    --secondary: #D4D4D8;
    --muted: #A1A1AA;
    --muted-bg: #27272A;
    --border: #3F3F46;
    --accent: #60A5FA;
    --on-accent: #09090B;
    --ok: #4ADE80;
  }
}
:root[data-theme="dark"] {
  --bg: #18181B;
  --fg: #FAFAFA;
  --secondary: #D4D4D8;
  --muted: #A1A1AA;
  --muted-bg: #27272A;
  --border: #3F3F46;
  --accent: #60A5FA;
  --on-accent: #09090B;
  --ok: #4ADE80;
}

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

html { scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--sans);
  font-size: 17px;
  line-height: 1.75;
  -webkit-font-smoothing: antialiased;
}

a {
  color: inherit;
  text-decoration-thickness: 1.5px;
  text-underline-offset: 0.22em;
  cursor: pointer;
}
a:hover { background: var(--fg); color: var(--bg); text-decoration: none; }
a:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

h1, h2, h3 { margin: 0; line-height: 1.2; }
p { margin: 0; }

/* Reading progress, where scroll-driven animations exist */
@supports (animation-timeline: scroll()) {
  @media (prefers-reduced-motion: no-preference) {
    body::before {
      content: "";
      position: fixed;
      inset: 0 0 auto 0;
      height: 4px;
      background: var(--accent);
      transform-origin: left;
      z-index: 10;
      animation: draw linear both;
      animation-timeline: scroll(root);
    }
  }
}

/* Header */
.top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 var(--gutter);
  border-bottom: var(--rule);
}
.top-name {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 56px;
  font-family: var(--display);
  font-weight: 700;
  text-decoration: none;
}
.top-name:hover { background: none; color: var(--accent); }
.top-name img { border: var(--hair); background: #fff; }
.top nav { display: flex; }
.top nav a {
  display: flex;
  align-items: center;
  min-height: 56px;
  padding: 0 16px;
  font-weight: 500;
  text-decoration: none;
  border-left: var(--hair);
}
.top nav a:last-child { border-right: var(--hair); }

/* Hero */
.hero {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  border-bottom: var(--rule);
}
.hero-text {
  padding: clamp(48px, 9vh, 112px) var(--gutter);
  border-right: var(--rule);
  align-self: stretch;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

h1 { display: flex; flex-direction: column; gap: 6px; }
.name-zh {
  font-family: var(--display);
  font-size: clamp(52px, 8.5vw, 112px);
  font-weight: 800;
  letter-spacing: 0.02em;
  line-height: 1.05;
}
.name-en {
  font-family: var(--display);
  font-stretch: 125%;
  font-weight: 700;
  font-size: clamp(22px, 3vw, 34px);
  color: var(--accent);
}
.lede {
  margin-top: 36px;
  font-size: clamp(18px, 1.6vw, 21px);
  max-width: 24em;
}
.hero-meta { margin-top: 16px; color: var(--muted); font-size: 15px; }

/* Ladder diagram on graph paper */
.ladder {
  margin: 0;
  padding: clamp(40px, 7vh, 88px) clamp(20px, 4vw, 56px);
  background-color: var(--muted-bg);
  background-image:
    linear-gradient(var(--border) 1px, transparent 1px),
    linear-gradient(90deg, var(--border) 1px, transparent 1px);
  background-size: 24px 24px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}
.ladder-ends {
  display: flex;
  justify-content: space-between;
  font-family: var(--mono);
  font-size: 13px;
  font-weight: 500;
}
.ladder-ends span {
  padding: 6px 12px;
  border: var(--rule);
  background: var(--bg);
  position: relative;
  z-index: 1;
}
.ladder-ends span:first-child { min-width: 64px; text-align: center; }

.ladder-msgs {
  list-style: none;
  margin: 0;
  padding: 12px 0 20px;
  position: relative;
}
/* lifelines, drawn from the centre of each endpoint box */
.ladder-msgs::before,
.ladder-msgs::after {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  border-left: 2px dashed var(--fg);
}
.ladder-msgs::before { left: 31px; }
.ladder-msgs::after { right: 63px; }

.msg {
  position: relative;
  margin: 0 64px 0 32px;
  height: 52px;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding-bottom: 12px;
  color: var(--accent);
}
.msg.provisional { color: var(--secondary); }
.msg.ok { color: var(--ok); }

.msg code {
  font-family: var(--mono);
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  background: var(--muted-bg);
  padding: 0 6px;
  animation: label-in 300ms ease-out both;
  animation-delay: calc(var(--i) * 420ms + 220ms);
}

/* arrow shaft */
.msg::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 2px;
  background: currentColor;
  transform-origin: left;
  animation: draw 380ms cubic-bezier(.4, 0, .2, 1) both;
  animation-delay: calc(var(--i) * 420ms);
}
/* arrow head */
.msg::after {
  content: "";
  position: absolute;
  bottom: -5px;
  border-top: 6px solid transparent;
  border-bottom: 6px solid transparent;
  animation: label-in 120ms linear both;
  animation-delay: calc(var(--i) * 420ms + 340ms);
}
.msg.to-right::after { right: 0; border-left: 10px solid currentColor; }
.msg.to-left::after { left: 0; border-right: 10px solid currentColor; }
.msg.to-left::before { transform-origin: right; }

.ladder figcaption {
  font-size: 15px;
  text-align: center;
  animation: label-in 400ms ease-out both;
  animation-delay: 2300ms;
}
.ladder figcaption a { font-weight: 700; }

@keyframes draw { from { transform: scaleX(0); } to { transform: scaleX(1); } }
@keyframes label-in { from { opacity: 0; } to { opacity: 1; } }

/* Content blocks: a two-column grid with visible rules */
.block {
  display: grid;
  grid-template-columns: minmax(160px, 1fr) minmax(0, 3fr);
  border-bottom: var(--rule);
}
.block > h2 {
  grid-row: 1 / span 20;
  padding: clamp(40px, 7vw, 88px) var(--gutter);
  border-right: var(--rule);
  font-family: var(--display);
  font-size: clamp(28px, 3vw, 40px);
  font-weight: 800;
}
.block > :not(h2) {
  grid-column: 2;
  margin-left: clamp(24px, 5vw, 72px);
  margin-right: var(--gutter);
}
.block > :nth-child(2) { margin-top: clamp(40px, 7vw, 88px); }
.block > :last-child { margin-bottom: clamp(40px, 7vw, 88px); }
.block-intro { color: var(--muted); max-width: var(--measure); margin-bottom: 32px; }

/* Featured projects */
.features {
  display: grid;
  border: var(--rule);
}
.feature { padding: 28px; display: flex; flex-direction: column; gap: 14px; }
.feature + .feature { border-top: var(--rule); }
@media (min-width: 1100px) {
  .features { grid-template-columns: 1fr 1fr; }
  .feature + .feature { border-top: 0; border-left: var(--rule); }
}
.feature-head { display: flex; flex-direction: column; gap: 4px; }
.feature h3 {
  font-family: var(--display);
  font-size: clamp(28px, 3.2vw, 40px);
  font-weight: 800;
  font-stretch: 112%;
}
.feature h3 a { text-decoration: none; }
.stack {
  font-size: 14px;
  font-weight: 500;
  color: var(--accent);
}
.facts {
  margin: auto 0 0;
  padding: 14px 0 0 1.1em;
  border-top: var(--hair);
  color: var(--muted);
  font-size: 15px;
}
.facts li::marker { color: var(--accent); }

/* Smaller projects: cells divided by a visible grid */
.minor {
  list-style: none;
  padding: 0;
  margin-top: 40px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 2px;
  background: var(--fg);
  border: var(--rule);
}
.minor li { background: var(--bg); padding: 20px 22px; }
.minor a { font-family: var(--display); font-weight: 700; font-size: 18px; }
.minor p { margin-top: 6px; font-size: 15px; color: var(--muted); }

/* Skills */
.skills { margin: 0; max-width: 46em; border-top: var(--hair); }
.skills div {
  display: grid;
  grid-template-columns: 8em 1fr;
  gap: 16px;
  padding: 16px 0;
  border-bottom: var(--hair);
}
.skills dt { font-weight: 700; }
.skills dd { margin: 0; color: var(--secondary); }

/* Timeline */
.timeline { list-style: none; padding: 0; max-width: 46em; border-top: var(--hair); }
.timeline li {
  display: grid;
  grid-template-columns: 9em 1fr;
  gap: 16px;
  padding: 20px 0;
  border-bottom: var(--hair);
}
.timeline time {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--accent);
  font-size: 15px;
  padding-top: 2px;
}
.timeline h3 { font-size: 18px; font-weight: 700; }
.timeline p { color: var(--muted); margin-top: 4px; }

/* Contact: the closing call to action */
.contact { background: var(--accent); color: var(--on-accent); }
.contact > h2 { border-right-color: var(--on-accent); }
.contact .block-intro { color: inherit; }
.contact a:hover { background: var(--on-accent); color: var(--accent); }
.mail {
  display: inline-block;
  font-family: var(--display);
  font-stretch: 110%;
  font-size: clamp(22px, 4vw, 48px);
  font-weight: 800;
  word-break: break-all;
  line-height: 1.3;
}
.links { list-style: none; display: flex; gap: 0; padding: 0; margin-top: 28px; }
.links a {
  display: inline-flex;
  align-items: center;
  min-height: 48px;
  padding: 0 20px;
  border: 2px solid var(--on-accent);
  font-weight: 700;
  text-decoration: none;
}
.links li + li a { border-left: 0; }

.foot {
  padding: 28px var(--gutter);
  font-family: var(--mono);
  font-size: 13px;
  color: var(--muted);
}
.foot span { color: var(--ok); margin-left: 12px; }

/* Responsive */
@media (max-width: 860px) {
  .hero { grid-template-columns: 1fr; }
  .hero-text { border-right: 0; border-bottom: var(--rule); padding-top: 40px; padding-bottom: 40px; }
  .ladder { padding-top: 32px; padding-bottom: 32px; }
  .block { grid-template-columns: 1fr; }
  .block > h2 {
    grid-row: auto;
    border-right: 0;
    border-bottom: var(--rule);
    padding-top: 24px;
    padding-bottom: 24px;
  }
  .contact > h2 { border-bottom-color: var(--on-accent); }
  .block > :not(h2) { grid-column: 1; margin-left: var(--gutter); }
  .block > :nth-child(2) { margin-top: 32px; }
  .block > :last-child { margin-bottom: 48px; }
}
@media (max-width: 520px) {
  .top nav a { padding: 0 12px; }
  .ladder { padding-left: 12px; padding-right: 12px; }
  .msg { margin: 0 56px 0 28px; }
  .ladder-msgs::before { left: 27px; }
  .ladder-msgs::after { right: 55px; }
  .ladder-ends span { padding: 6px 8px; }
  .ladder-ends span:first-child { min-width: 56px; }
  .msg code { font-size: 12px; }
  .feature { padding: 22px 18px; }
  .skills div, .timeline li { grid-template-columns: 1fr; gap: 2px; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .msg::before, .msg::after, .msg code, .ladder figcaption { animation: none; }
}
