/* ==================================================================
   Tan Xin Lin: personal site
   Shared by every page. The site is a descent: each page sits at a
   different depth, light stone at the top and dark espresso at the bottom.
   The five motion techniques are labelled TECHNIQUE 1 to 5 below.
================================================================== */

/* ---------- Tokens ---------- */
:root {
  color-scheme: light;
  --paper:    #F9F7F3;   /* background on every page */
  --ink:      #2A2623;   /* text */
  --muted:    #6E6760;   /* secondary text */

  /* two accents, both pale: use for lines, dots and fills, not for text */
  --accent:   #A6A9D0;   /* periwinkle */
  --accent-2: #E5AEA9;   /* blush */

  --display: "Cormorant Garamond", "Iowan Old Style", Georgia, serif;
  --body: "Instrument Sans", system-ui, -apple-system, "Segoe UI", sans-serif;

  /* TECHNIQUE 5: linear() easing. A spring curve sampled into points,
     used when the depth marker and project titles move. */
  --spring: linear(
    0, 0.009, 0.035 2.1%, 0.141 4.4%, 0.723 12.9%, 0.938 16.7%, 1.017,
    1.077, 1.121, 1.149 24.3%, 1.159, 1.163, 1.161, 1.154 29.9%,
    1.129 32.8%, 1.051 39.6%, 1.017 43.1%, 0.991, 0.977 51%,
    0.974 53.8%, 0.975 57.1%, 0.997 69.8%, 1.003 76.9%, 1.004 83.8%, 1
  );
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html { background: var(--paper); }
body {
  margin: 0;
  min-height: 100svh;
  font-family: var(--body);
  font-size: clamp(1rem, 0.95rem + 0.3vw, 1.1875rem);
  line-height: 1.65;
  background: var(--paper);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { font-family: var(--display); line-height: 1.05; margin: 0; text-wrap: balance; }
h1 { font-size: clamp(2.75rem, 1.5rem + 6vw, 6rem); font-weight: 300; letter-spacing: -0.01em; }
h3 { font-size: clamp(1.5rem, 1.2rem + 1.4vw, 2.125rem); font-weight: 400; line-height: 1.15; }
p  { margin: 0; max-width: 34em; text-wrap: pretty; }
a  {
  color: var(--ink);
  text-decoration-color: var(--accent);
  text-decoration-thickness: 2px;
  text-underline-offset: 0.25em;
}
a:hover { text-decoration-color: var(--accent-2); }
:focus-visible { outline: 3px solid currentColor; outline-offset: 4px; border-radius: 4px; }

main {
  width: min(100% - 3rem, 62rem);
  margin-inline: auto;
  padding-block: 9rem 5rem;
  min-height: 100svh;
}
.lead { font-size: 1.25em; margin-top: 1.5rem; }

.button {
  font: inherit; font-weight: 500;
  display: inline-block; padding: 0.75em 1.5em;
  border: 1px solid currentColor; border-radius: 999px;
  background: transparent; color: var(--ink);
  text-decoration: none; cursor: pointer;
  transition: background-color .2s, color .2s, border-color .2s;
}
.button:hover { background: var(--accent); color: var(--ink); border-color: var(--accent); }
.button:nth-child(2):hover { background: var(--accent-2); border-color: var(--accent-2); }

/* link to the next page down, at the foot of each page */
.next {
  display: inline-block; margin-top: 5rem;
  font-family: var(--display); font-weight: 400; font-style: italic;
  font-size: clamp(1.5rem, 1.2rem + 1.4vw, 2.125rem);
}

/* ---------- Nav ---------- */
.nav {
  position: fixed; z-index: 6; top: 0; left: 0; right: 0;
  display: flex; gap: 1.25rem;
  padding: 1rem clamp(1rem, 3vw, 2rem);
  font-weight: 400; font-size: 0.9375rem; letter-spacing: 0.01em;
  background: color-mix(in srgb, var(--paper) 85%, transparent);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  overflow-x: auto;
}
.nav a {
  color: var(--ink); text-decoration: none; white-space: nowrap;
  padding-block: 0.25rem;
  border-bottom: 2px solid transparent;
  opacity: 0.6;
}
.nav a:hover { opacity: 1; }
.nav a[aria-current="page"] { opacity: 1; border-bottom-color: var(--accent); }

/* ==================================================================
   TECHNIQUE 1: cross-page view transitions.
   This one rule makes ordinary links between pages animate. The
   browser snapshots the old page and the new page and crossfades.
   Anything with the same view-transition-name on both pages is
   treated as one object and glides from its old place to its new
   one: the nav stays put, and the depth marker sinks or rises.
   (Needs a real server, so it works on Vercel but not when you open
   the files straight from your laptop.)
================================================================== */
@view-transition { navigation: auto; }

.nav     { view-transition-name: site-nav; }
.gauge i { view-transition-name: depth-marker; }

::view-transition-old(root),
::view-transition-new(root) { animation-duration: 0.45s; }

::view-transition-group(depth-marker) {
  animation-duration: 0.9s;
  animation-timing-function: var(--spring);
}

/* ---------- Depth gauge ---------- */
.gauge {
  position: fixed; z-index: 5;
  right: clamp(0.75rem, 2vw, 2rem); top: 6rem; bottom: 4rem;
  width: 1px;
  background: color-mix(in srgb, var(--ink) 40%, transparent);
  pointer-events: none;
}
.gauge i {
  position: absolute; right: -4px;
  top: calc(var(--d) * 20%); translate: 0 -50%;
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--accent);
}
.gauge i::after {
  content: attr(data-depth);
  position: absolute; right: 18px; top: 50%; translate: 0 -50%;
  font: 400 0.8125rem/1 var(--body); color: var(--ink);
  white-space: nowrap;
}
@media (max-width: 48rem) {
  .gauge { right: 0.5rem; }
  .gauge i::after { display: none; }
}

/* ==================================================================
   TECHNIQUE 2: scroll() timeline.
   The bar's animation is tied to how far the page has scrolled, not
   to time. On pages too short to scroll it simply stays hidden.
================================================================== */
.progress {
  position: fixed; z-index: 7; top: 0; left: 0; right: 0; height: 3px;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  transform-origin: left; scale: 0 1;
}
@supports (animation-timeline: scroll()) {
  .progress {
    animation: grow linear both;
    animation-timeline: scroll(root);
  }
  @keyframes grow { to { scale: 1 1; } }
}

/* ---------- Home ---------- */
.page-home main { display: grid; align-content: end; }
.page-home h1 {
  font-size: clamp(5rem, 22vw, 15rem);
  font-weight: 300; letter-spacing: -0.02em; margin-left: -0.04em;
}
.actions { display: flex; flex-wrap: wrap; gap: 0.75rem; margin-top: 2.25rem; }

/* ---------- Expertise ---------- */
.areas { margin: 3.5rem 0 0; display: grid; }
.areas > div {
  display: grid; gap: 0.75rem 3rem;
  grid-template-columns: minmax(0, 5fr) minmax(0, 7fr);
  padding-block: 2rem;
  border-top: 1px solid color-mix(in srgb, var(--ink) 15%, transparent);
}
.areas dt {
  font-family: var(--display); font-weight: 400;
  font-size: clamp(1.5rem, 1.2rem + 1.4vw, 2.125rem);
  line-height: 1.15;
}
.areas dd { margin: 0; max-width: 34em; }
@media (max-width: 40rem) { .areas > div { grid-template-columns: 1fr; } }

/* ---------- Career ---------- */
.timeline {
  list-style: none; position: relative;
  margin: 4rem 0 0; padding: 0 0 0 2.25rem;
  display: grid; gap: 3.25rem; max-width: 44rem;
}
.timeline::before {            /* the line */
  content: ""; position: absolute; left: 0; top: 0.6rem; bottom: 0.6rem;
  width: 1px; background: var(--accent); transform-origin: top;
}
.timeline li { position: relative; }
.timeline li::before {         /* the dot */
  content: ""; position: absolute; left: calc(-2.25rem - 4px); top: 0.45em;
  width: 10px; height: 10px; border-radius: 50%; background: var(--accent-2);
}
.timeline .when { display: block; font-size: 0.875em; letter-spacing: 0.04em; text-transform: uppercase; color: var(--muted); }
.timeline h3 { margin-block: 0.4rem 0.6rem; }

/* ==================================================================
   TECHNIQUE 3: view() timeline.
   Progress is tied to an element's own trip through the viewport.
   Wrapped so that browsers without support, and people who have
   asked for less motion, just see the finished timeline.
================================================================== */
@media (prefers-reduced-motion: no-preference) {
  @supports (animation-timeline: view()) {
    .timeline::before {
      animation: draw linear both;
      animation-timeline: view();
      animation-range: cover 15% cover 65%;
    }
    @keyframes draw { from { scale: 1 0; } }

    .timeline li {
      animation: surface linear both;
      animation-timeline: view();
      animation-range: entry 10% cover 30%;
    }
    @keyframes surface { from { opacity: 0; translate: -1.5rem 0; } }
  }
}

/* ---------- About ---------- */
.prose { display: grid; gap: 1.25rem; margin-top: 2.5rem; font-size: 1.125em; }

/* ---------- Projects ---------- */
.projects { list-style: none; padding: 0; margin: 3rem 0 0; display: grid; gap: 1rem; }
.project {
  font: inherit; color: inherit; text-align: left; width: 100%;
  display: grid; gap: 0.75rem; padding: 2rem;
  background: #FFFFFF;
  border: 1px solid color-mix(in srgb, var(--ink) 12%, transparent);
  border-radius: 14px;
  cursor: pointer; transition: border-color .2s;
}
.project:hover { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 30%, transparent); }
.project span { color: var(--muted); max-width: 34em; }

.detail { margin-top: 3rem; display: grid; gap: 1.5rem; }
.detail h2 { font-size: clamp(2.25rem, 1.4rem + 5vw, 5rem); font-weight: 300; }
.detail dl { display: grid; grid-template-columns: max-content 1fr; gap: 0.5rem 2rem; margin: 0; }
.detail dt { color: var(--muted); }
.detail dd { margin: 0; }
.back {
  font: inherit; color: var(--ink); background: none; border: 0; padding: 0;
  cursor: pointer; text-decoration: underline; text-decoration-color: var(--accent);
  text-decoration-thickness: 2px; text-underline-offset: 0.25em;
  justify-self: start;
}

/* ==================================================================
   TECHNIQUE 4: same-page view transitions.
   On the Projects page, site.js swaps the list for a detail view
   inside document.startViewTransition(). The clicked title and the
   detail title share a name, so one morphs into the other.
================================================================== */
.detail h2 { view-transition-name: project-title; }
::view-transition-group(project-title) {
  animation-duration: 0.7s;
  animation-timing-function: var(--spring);
}

/* ---------- Contact ---------- */
.email {
  display: inline-block; margin-top: 2.5rem;
  font-family: var(--display); font-weight: 300; font-style: italic;
  font-size: clamp(1.75rem, 0.9rem + 4.5vw, 4rem);
  line-height: 1.1;
  overflow-wrap: anywhere;
}
.elsewhere { list-style: none; padding: 0; margin: 2.5rem 0 0; display: flex; flex-wrap: wrap; gap: 0.75rem; }

/* ---------- Less motion on request ---------- */
@media (prefers-reduced-motion: reduce) {
  @view-transition { navigation: none; }
  ::view-transition-group(*),
  ::view-transition-old(*),
  ::view-transition-new(*) { animation: none !important; }
}
