/* Phong Huỳnh, personal introduction.
   Light and dark: near-white or dark drafting paper, blue-black or silver ink, formwork ochre.
   Layout: the model is pinned on the left; the story runs down the right as one timeline,
   every chapter a node on a single rail that is drawn as the reader scrolls. */

:root {
  --paper: #fafbfc;
  --paper-2: #eef1f5;
  --ink: #161d2b;
  --ink-2: #5a6474;
  --ink-3: #98a1b0;
  --ink-dim: #7d8798;
  --line: #d9dee5;
  --accent: #b48c2c;
  --accent-fill: rgba(180, 140, 44, 0.2);
  --tag-bg: rgba(250, 251, 252, 0.88);
  --tag-bg-hover: rgba(250, 251, 252, 0.95);
  --ease-out: cubic-bezier(0.2, 0.7, 0.2, 1);
  --gutter: clamp(20px, 5vw, 64px);
  --rail-x: clamp(24px, 4vw, 64px);   /* the timeline, in from the left edge of the text column */
  --rail-gap: 40px;                    /* from the rail to the text */
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #111820;
    --paper-2: #192030;
    --ink: #d8dee8;
    --ink-2: #8d99aa;
    --ink-3: #586878;
    --ink-dim: #687888;
    --line: #253040;
    --accent: #d4a83c;
    --accent-fill: rgba(212, 168, 60, 0.15);
    --tag-bg: rgba(17, 24, 32, 0.88);
    --tag-bg-hover: rgba(17, 24, 32, 0.95);
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --paper: #111820;
  --paper-2: #192030;
  --ink: #d8dee8;
  --ink-2: #8d99aa;
  --ink-3: #586878;
  --ink-dim: #687888;
  --line: #253040;
  --accent: #d4a83c;
  --accent-fill: rgba(212, 168, 60, 0.15);
  --tag-bg: rgba(17, 24, 32, 0.88);
  --tag-bg-hover: rgba(17, 24, 32, 0.95);
  color-scheme: dark;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: "Be Vietnam Pro", "Segoe UI", system-ui, sans-serif;
  font-size: 17px;
  font-weight: 400;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  transition: background-color 400ms ease-out, color 400ms ease-out;
}

a {
  color: inherit;
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-decoration-color: var(--ink-3);
  text-underline-offset: 0.2em;
  transition: text-decoration-color 200ms ease-out, color 200ms ease-out;
}

a:hover {
  text-decoration-color: var(--accent);
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

::selection {
  background: var(--accent-fill);
}

/* Overlapping layout: the viewer spans 80% as a backdrop, the story floats over its right side */

.scrolly {
  display: grid;
  grid-template-columns: 1fr;
}

.pin {
  position: sticky;
  top: 0;
  grid-column: 1;
  grid-row: 1;
  align-self: start;
  height: 100vh;
  height: 100svh;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  pointer-events: none;
  padding-left: var(--gutter);
  overflow: visible;
}

.steps {
  grid-column: 1;
  grid-row: 1;
  justify-self: end;
}

.pin .model {
  width: 80vw;
  width: min(80vw, calc((100svh - 100px) * 4 / 3));
  margin: 0;
  transition: width 400ms var(--ease-out);
}

/* Focused state: viewer goes full width, steps hidden */

.scrolly.is-focused .pin {
  align-items: center;
  padding-left: 0;
}

.scrolly.is-focused .pin .model {
  width: 100%;
}

.scrolly.is-focused .steps {
  opacity: 0;
  pointer-events: none;
}

.stage-wrap {
  position: relative;
}

.stage {
  position: relative;
  aspect-ratio: 4 / 3;
}

/* Floating building tags over the model */

.tags {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  z-index: 1;
}

.tag-group {
  position: absolute;
  left: 0;
  top: 0;
  pointer-events: none;
  will-change: transform;
}

.tag-group[hidden] {
  display: none !important;
}

.tag-line {
  position: absolute;
  left: 0;
  bottom: 0;
  width: 1px;
  background: var(--ink-3);
  transform-origin: bottom center;
}

.tag-dot {
  position: absolute;
  left: -2.5px;
  bottom: -2.5px;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--ink-3);
}

.tag {
  position: absolute;
  left: 0;
  top: 0;
  pointer-events: auto;
  padding: 4px 10px;
  font: 500 11px/1.2 "Be Vietnam Pro", "Segoe UI", system-ui, sans-serif;
  letter-spacing: 0.02em;
  color: var(--ink-2);
  background: var(--tag-bg);
  border: 1px solid var(--line);
  border-radius: 3px;
  white-space: nowrap;
  cursor: pointer;
  transform: translateX(-50%);
  transition: color 200ms ease-out, border-color 200ms ease-out, background-color 200ms ease-out;
}

.tag:hover {
  color: var(--ink);
  border-color: var(--accent);
  background: var(--tag-bg-hover);
}

.tag-group:hover .tag-line,
.tag-group:hover .tag-dot {
  background: var(--accent);
}

/* Back button: returns camera from a focused building view to the overview */

.back-toggle {
  position: fixed;
  top: 20px;
  left: 20px;
  z-index: 10;
  display: none;
  align-items: center;
  gap: 6px;
  min-height: 44px;
  padding: 0 16px 0 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--paper);
  color: var(--ink-2);
  font: 500 13px/1 "Be Vietnam Pro", "Segoe UI", system-ui, sans-serif;
  letter-spacing: 0.01em;
  cursor: pointer;
  pointer-events: auto;
  touch-action: manipulation;
  transition: color 200ms ease-out, border-color 200ms ease-out, background-color 200ms ease-out, opacity 300ms ease-out;
}

.model.is-live .back-toggle.is-visible {
  display: inline-flex;
}

.back-toggle svg {
  width: 16px;
  height: 16px;
  flex: none;
}

.back-toggle:hover {
  color: var(--ink);
  border-color: var(--ink);
}

/* Free rotation: a quiet toggle on the stage. While it is on, the viewer takes the pointer
   and a drag orbits the model; the wheel still scrolls the page. */

.orbit-toggle {
  position: absolute;
  right: 12px;
  bottom: 12px;
  display: none;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 16px 0 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--paper);
  color: var(--ink-2);
  font: 500 13px/1 "Be Vietnam Pro", "Segoe UI", system-ui, sans-serif;
  letter-spacing: 0.01em;
  cursor: pointer;
  pointer-events: auto;
  touch-action: manipulation;
  transition: color 200ms ease-out, border-color 200ms ease-out, background-color 200ms ease-out;
}

.model.is-live .orbit-toggle {
  display: inline-flex;
}

.orbit-toggle svg {
  width: 16px;
  height: 16px;
  flex: none;
}

.orbit-toggle:hover {
  color: var(--ink);
  border-color: var(--ink);
}

.orbit-toggle[aria-pressed="true"] {
  color: var(--paper);
  background: var(--ink);
  border-color: var(--ink);
}

.stage.is-free .viewer {
  pointer-events: auto;
  cursor: grab;
}

.stage.is-free .viewer:active {
  cursor: grabbing;
}

#frame {
  display: none;
}

/* Loading screen: game-style progress while the 3D model streams in */

.loader {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: var(--paper);
  color: var(--ink-3);
  z-index: 2;
  overflow: hidden;
  transition: opacity 800ms ease-out;
}

.loader-grid {
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(var(--line) 1px, transparent 1px),
    linear-gradient(90deg, var(--line) 1px, transparent 1px);
  background-size: 48px 48px;
  opacity: 0.4;
  animation: loader-grid-drift 20s linear infinite;
}

@keyframes loader-grid-drift {
  to { background-position: 48px 48px; }
}

.loader-scanline {
  position: absolute;
  inset: 0;
  background: linear-gradient(
    to bottom,
    transparent 0%,
    transparent 45%,
    var(--accent-fill) 50%,
    transparent 55%,
    transparent 100%
  );
  background-size: 100% 200%;
  opacity: 0.6;
  animation: loader-scan 3s ease-in-out infinite;
}

@keyframes loader-scan {
  0%, 100% { background-position: 0 -100%; }
  50% { background-position: 0 100%; }
}

.loader-content {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}

.loader-pct {
  font-family: Spectral, Georgia, serif;
  font-weight: 300;
  font-size: clamp(48px, 6vw, 72px);
  line-height: 1;
  color: var(--ink);
  letter-spacing: -0.02em;
}

.loader-pct::after {
  content: '%';
  font-size: 0.5em;
  color: var(--ink-3);
  margin-left: 2px;
}

.loader-status {
  font: 400 12px/1 "Be Vietnam Pro", "Segoe UI", system-ui, sans-serif;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-3);
  min-height: 1em;
}

.loader-bar-track {
  width: 50%;
  height: 2px;
  background: var(--line);
  border-radius: 1px;
}

.loader-bar-fill {
  height: 100%;
  width: 0%;
  background: var(--accent);
}

.stage.is-live .loader {
  opacity: 0;
  pointer-events: none;
}

/* The live model renders behind the loader and takes over once it has loaded. */

.viewer {
  position: absolute;
  inset: 0;
  overflow: hidden;
  opacity: 0;
  transition: opacity 600ms ease-out;
}

.viewer canvas {
  display: block;
}

.stage.is-live .viewer {
  opacity: 1;
}

.model figcaption {
  font-size: 13px;
  line-height: 1.5;
  color: var(--ink-3);
  text-align: center;
  margin: 10px auto 0;
  max-width: 36em;
}

.cap-live {
  display: inline;
}

/* Theme toggle: fixed top-right, matches the drafting-control style of the orbit toggle */

.theme-toggle {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--ink-2);
  cursor: pointer;
  touch-action: manipulation;
  transition: color 200ms ease-out;
}

.theme-toggle:hover {
  color: var(--ink);
}

.theme-toggle svg {
  width: 18px;
  height: 18px;
  position: absolute;
  transition: transform 450ms cubic-bezier(0.4, 0, 0.2, 1), opacity 250ms ease;
}

.theme-toggle .icon-sun {
  opacity: 1;
  transform: rotate(0deg) scale(1);
}

.theme-toggle .icon-moon {
  opacity: 0;
  transform: rotate(-90deg) scale(0.4);
}

:root[data-theme="dark"] .theme-toggle .icon-sun {
  opacity: 0;
  transform: rotate(90deg) scale(0.4);
}

:root[data-theme="dark"] .theme-toggle .icon-moon {
  opacity: 1;
  transform: rotate(0deg) scale(1);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-toggle .icon-sun {
    opacity: 0;
    transform: rotate(90deg) scale(0.4);
  }
  :root:not([data-theme="light"]) .theme-toggle .icon-moon {
    opacity: 1;
    transform: rotate(0deg) scale(1);
  }
}

/* The timeline: one rail down the left of the text, a node for every chapter.
   The light rail spans first node to last; the ink line over it grows with the scroll. */

.steps {
  position: relative;
  width: 42%;
  padding-right: var(--gutter);
  background: none;
  transition: opacity 300ms ease-out;
  --line-top: 0px;
  --line-bottom: 0px;
  --line-p: 0;
}

.steps::before,
.steps::after {
  content: "";
  position: absolute;
  left: var(--rail-x);
  top: var(--line-top);
  bottom: var(--line-bottom);
  width: 1px;
  pointer-events: none;
}

.steps::before {
  background: var(--line);
}

.steps::after {
  background: var(--ink);
  transform: scaleY(var(--line-p));
  transform-origin: 50% 0;
}

.steps:not(.has-js)::after {
  display: none;
}

.step {
  position: relative;
  box-sizing: border-box;
  min-height: 58vh;
  display: flex;
  align-items: center;
  padding: 6vh 0;
}

.step-hero {
  min-height: 100vh;
  min-height: 100svh;
  padding-bottom: 14vh;   /* a touch above centre, so the line begins on the name at load */
}

.step-contact {
  min-height: 80vh;
}

.step-body {
  --fg: var(--ink);
  --fg-2: var(--ink-2);
  box-sizing: border-box;
  width: 100%;
  max-width: calc(30em + var(--rail-x) + var(--rail-gap));
  padding-left: calc(var(--rail-x) + var(--rail-gap));
  color: var(--fg);
  transition: color 400ms ease-out;
}

.role,
.year,
.step-body > p:last-child,
.contact-list {
  color: var(--fg-2);
  transition: color 400ms ease-out;
}

/* Chapters away from the tip of the line recede to a lighter ink */

.steps.has-js .step:not(.is-active) .step-body {
  --fg: var(--ink-dim);
  --fg-2: var(--ink-dim);
}

.steps.has-js .step:not(.is-active) .portrait {
  opacity: 0.5;
}

/* Nodes sit on the rail, level with the first line of their heading */

.node {
  position: absolute;
  left: calc(0.5px - var(--rail-gap));
  top: 0.6em;
  box-sizing: border-box;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: 1px solid var(--ink-3);
  background: var(--paper);
  transform: translate(-50%, -50%);
  transition: background-color 300ms ease-out, border-color 300ms ease-out;
}

h1 .node {
  top: 0.525em;
}

.step.is-seen .node {
  background: var(--ink);
  border-color: var(--ink);
}

/* Hero step */

.portrait {
  width: 112px;
  margin: 0 0 28px 8px;
  outline: 1px solid var(--ink);
  outline-offset: 8px;
  transition: opacity 400ms ease-out;
}

.portrait img {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 1;
  object-fit: cover;
  object-position: 80% 40%;
}

h1 {
  position: relative;
  font-family: Spectral, Georgia, serif;
  font-weight: 300;
  font-size: clamp(38px, 3.6vw, 56px);
  line-height: 1.05;
  letter-spacing: -0.015em;
  margin: 0 0 12px;
}

.role {
  font-size: 15px;
  margin: 0 0 24px;
}

.lead {
  font-size: 18px;
  font-weight: 300;
  line-height: 1.55;
  margin: 0;
}

/* Timeline steps */

.year {
  font-family: Spectral, Georgia, serif;
  font-size: 17px;
  margin: 0 0 6px;
  font-variant-numeric: tabular-nums;
}

.step h2 {
  position: relative;
  font-family: Spectral, Georgia, serif;
  font-weight: 400;
  font-size: clamp(26px, 2.2vw, 32px);
  line-height: 1.2;
  letter-spacing: -0.005em;
  margin: 0 0 10px;
}

.step-body > p:last-child {
  margin: 0;
  font-size: 16px;
}

/* Title link: small outbound arrow inline with h2 product names */

.title-link {
  display: inline-flex;
  align-items: center;
  vertical-align: baseline;
  margin-left: 8px;
  color: var(--ink-3);
  text-decoration: none;
  transition: color 200ms ease-out;
}

.title-link:hover {
  color: var(--accent);
  text-decoration: none;
}

.title-link svg {
  width: 0.55em;
  height: 0.55em;
  flex: none;
  transition: transform 200ms ease-out;
}

.title-link:hover svg {
  transform: translate(2px, -2px);
}

/* Stats row: compact grid that reads like a callout table on a drafting sheet */

.stats-note {
  font-size: 12px;
  color: var(--ink-3);
  margin: 18px 0 6px;
  letter-spacing: 0.02em;
}

.stats {
  display: grid;
  grid-template-columns: repeat(5, max-content);
  gap: 0;
  margin-top: 0;
  border-top: 1px solid var(--line);
  border-left: 1px solid var(--line);
}

.stat {
  display: flex;
  flex-direction: column;
  padding: 12px 18px 14px;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.stat-num {
  font-family: Spectral, Georgia, serif;
  font-weight: 400;
  font-size: clamp(22px, 1.8vw, 28px);
  line-height: 1.1;
  letter-spacing: -0.01em;
  color: var(--fg, var(--ink));
  font-variant-numeric: tabular-nums;
  transition: color 400ms ease-out;
}

.stat-plus {
  color: var(--accent);
}

.stat-label {
  font-size: 11.5px;
  letter-spacing: 0.04em;
  color: var(--fg-2, var(--ink-3));
  margin-top: 4px;
  transition: color 400ms ease-out;
}

@media (max-width: 900px) {
  .stats {
    grid-template-columns: repeat(3, 1fr);
  }
}

@media (max-width: 420px) {
  .stats {
    grid-template-columns: repeat(2, 1fr);
  }

  .stat {
    padding: 10px 14px 12px;
  }
}

/* Contact step */

.contact-intro {
  margin: 0 0 22px;
}

.contact-channels {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  border-top: 1px solid var(--line);
  border-left: 1px solid var(--line);
  font-style: normal;
}

.contact-channel {
  display: flex;
  min-width: 0;
  min-height: 94px;
  flex-direction: column;
  justify-content: space-between;
  gap: 14px;
  padding: 14px 16px 16px;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  color: var(--fg, var(--ink));
  text-decoration: none;
  transition: background-color 180ms ease-out, color 180ms ease-out;
}

.contact-channel:first-child {
  grid-column: 1 / -1;
}

.contact-channel:hover,
.contact-channel:focus-visible {
  color: var(--ink);
  background: color-mix(in srgb, var(--accent) 10%, transparent);
  outline: none;
}

.contact-channel:focus-visible {
  box-shadow: inset 0 0 0 2px var(--accent);
}

.contact-label {
  color: var(--fg-2, var(--ink-3));
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.contact-value {
  font-family: Spectral, Georgia, serif;
  font-size: clamp(20px, 1.6vw, 26px);
  font-weight: 300;
  letter-spacing: -0.01em;
  line-height: 1.1;
  overflow-wrap: anywhere;
}

.contact-location {
  margin: 20px 0 0;
  font-size: 15px;
}

@media (max-width: 480px) {
  .contact-channels {
    grid-template-columns: 1fr;
  }

  .contact-channel:first-child {
    grid-column: auto;
  }
}

/* Title block: closes the right column, its left edge on the rail */

.colophon {
  padding: 4vh 0 48px;
}

.titleblock {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin-left: var(--rail-x);
  border-top: 1px solid var(--ink);
  border-left: 1px solid var(--ink);
  font-size: 14px;
}

.titleblock div {
  padding: 10px 14px 12px;
  border-right: 1px solid var(--ink);
  border-bottom: 1px solid var(--ink);
  min-width: 0;
}

.titleblock small {
  display: block;
  font-size: 11.5px;
  color: var(--ink-3);
  margin-bottom: 2px;
}

/* Large screens: wider viewer, 16:9 stage */

@media (min-width: 2400px) {
  .pin .model {
    width: min(80vw, calc((100svh - 120px) * 16 / 9));
  }

  #frame {
    aspect-ratio: 16 / 9;
  }
}

/* Narrow screens: model pinned at the top, the timeline scrolls beneath it */

@media (max-width: 900px) {
  :root {
    --rail-x: 22px;
    --rail-gap: 26px;
  }

  .scrolly {
    display: block;
    max-width: none;
  }

  .pin {
    height: 44vh;
    height: 44svh;
    align-items: flex-start;
    padding-left: 0;
    padding-top: 8px;
    background: var(--paper);
    z-index: 2;
  }

  .pin .model {
    width: 100%;
  }

  .model figcaption {
    display: none;
  }

  .steps {
    width: 100%;
    background: none;
    padding-right: clamp(20px, 5vw, 40px);
    grid-column: auto;
    grid-row: auto;
    justify-self: auto;
  }

  .step,
  .step-hero,
  .step-contact {
    min-height: 0;
    padding: 28px 0;
  }

  .step-body {
    max-width: calc(34em + var(--rail-x) + var(--rail-gap));
  }

  .steps.has-js .step:not(.is-active) .step-body {
    --fg: var(--ink);
    --fg-2: var(--ink-2);
  }

  .steps.has-js .step:not(.is-active) .portrait {
    opacity: 1;
  }

  .step-hero {
    padding-top: 36px;
  }

  .step-contact {
    padding-bottom: 8px;
  }
}

@media (max-width: 560px) {
  .titleblock {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

/* Reduced motion: everything at rest, the line fully drawn, nothing waits on scroll */

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  body,
  .theme-toggle,
  .theme-toggle svg,
  .node,
  .step-body,
  .role,
  .year,
  .step-body > p:last-child,
  .contact-list,
  .portrait,
  a,
  .contact-email,
  #frame,
  .viewer,
  .loader,
  .stat-num,
  .stat-label {
    transition: none;
  }

  .loader-grid,
  .loader-scanline {
    animation: none;
  }

  .steps.has-js .step:not(.is-active) .step-body {
    --fg: var(--ink);
    --fg-2: var(--ink-2);
  }

  .steps.has-js .step:not(.is-active) .portrait {
    opacity: 1;
  }

  .steps::after {
    transform: none;
  }
}
