/* ============================================================
   Albert Cai — shared design system
   Near-monochrome light. Source Serif 4 (prose) + Archivo (labels).
   ============================================================ */

:root {
  --font-serif: "Source Serif 4", Georgia, "Times New Roman", serif;
  --font-sans: "Archivo", system-ui, -apple-system, sans-serif;

  /* Near-monochrome, light. True off-white at chroma 0, not cream. */
  --bg: oklch(0.985 0 0);
  --bg-sunken: oklch(0.968 0 0);
  --ink: oklch(0.28 0 0);
  --ink-strong: oklch(0.20 0 0);
  --muted: oklch(0.46 0 0);
  --line: oklch(0.90 0 0);
  --line-soft: oklch(0.94 0 0);

  /* The one restrained accent: a deep ink-blue, interaction only. */
  --accent: oklch(0.50 0.14 256);
  --accent-strong: oklch(0.43 0.15 256);

  --measure: 64ch;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
}

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

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background-color: var(--bg);
  color: var(--ink);
  font-family: var(--font-serif);
  font-optical-sizing: auto;
  font-size: clamp(1.0625rem, 0.98rem + 0.4vw, 1.1875rem);
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

.page {
  max-width: 42rem;
  margin: 0 auto;
  padding: clamp(1.5rem, 4vw, 2.75rem) clamp(1.25rem, 5vw, 2rem) 4rem;
}

a {
  color: inherit;
  text-decoration: none;
}

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

/* ---- Top nav ---- */
.topbar {
  display: flex;
  justify-content: flex-end;
  margin-bottom: clamp(2.75rem, 8vw, 4.5rem);
}

.nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 1.4rem;
  font-family: var(--font-sans);
  font-size: 0.875rem;
  font-weight: 500;
  letter-spacing: 0.005em;
}

.nav a {
  color: var(--muted);
  padding-block: 0.15rem;
  position: relative;
  transition: color 0.2s var(--ease);
}

.nav a::after {
  content: "";
  position: absolute;
  left: 0;
  right: 100%;
  bottom: -1px;
  height: 1.5px;
  background: var(--ink-strong);
  transition: right 0.28s var(--ease);
}

.nav a:hover { color: var(--ink-strong); }
.nav a:hover::after { right: 0; }

.nav a[aria-current="page"] { color: var(--ink-strong); }
.nav a[aria-current="page"]::after { right: 0; background: var(--line); }

/* ---- Hero (home) ---- */
.hero {
  display: flex;
  align-items: center;
  gap: clamp(1rem, 4vw, 1.6rem);
  margin-bottom: 2.25rem;
}

.avatar {
  flex: none;
  width: clamp(64px, 16vw, 84px);
  height: clamp(64px, 16vw, 84px);
  border-radius: 50%;
  object-fit: cover;
  box-shadow: 0 0 0 1px var(--line), 0 8px 24px -16px oklch(0.2 0 0 / 0.5);
}

/* ---- Page header (interior pages) ---- */
.page-header { margin-bottom: clamp(2rem, 6vw, 2.75rem); }

h1 {
  margin: 0;
  font-weight: 600;
  font-size: clamp(2.25rem, 1.6rem + 3vw, 3.25rem);
  line-height: 1.04;
  letter-spacing: -0.02em;
  color: var(--ink-strong);
  text-wrap: balance;
}

.tagline {
  margin: 0.5rem 0 0;
  max-width: var(--measure);
  font-family: var(--font-sans);
  font-size: clamp(0.9rem, 0.85rem + 0.3vw, 1rem);
  font-weight: 500;
  line-height: 1.4;
  letter-spacing: 0.005em;
  color: var(--muted);
  text-wrap: balance;
}

/* ---- Prose ---- */
.prose { max-width: var(--measure); }

.prose p {
  margin: 0 0 1.15em;
  text-wrap: pretty;
}

.prose p:last-child { margin-bottom: 0; }

.prose a {
  color: var(--ink-strong);
  font-weight: 500;
  text-decoration: underline;
  text-decoration-thickness: 0.06em;
  text-underline-offset: 0.18em;
  text-decoration-color: color-mix(in oklch, var(--accent) 42%, transparent);
  transition: color 0.2s var(--ease), text-decoration-color 0.2s var(--ease);
}

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

/* ---- Section scaffolding ---- */
section + section,
.prose + section { margin-top: clamp(2.75rem, 7vw, 3.75rem); }

.label {
  position: relative;
  font-family: var(--font-sans);
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--muted);
  margin: 0 0 1.25rem;
  padding-top: 1.25rem;
}

/* The section rule is a pseudo-element so it can wipe in on first load */
.label::before {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  height: 1px;
  background: var(--line);
  transform-origin: left center;
}

/* ---- Feature / entry titles ---- */
.feature-title {
  font-family: var(--font-serif);
  font-size: clamp(1.3rem, 1.1rem + 0.9vw, 1.6rem);
  font-weight: 600;
  line-height: 1.2;
  letter-spacing: -0.01em;
  margin: 0;
  max-width: var(--measure);
}

/* Two underline layers: an accent line that draws in over a resting hairline.
   The accent layer is invisible (width 0) at rest; first-load motion sweeps it. */
.feature-title a {
  color: var(--ink-strong);
  background-image:
    linear-gradient(var(--accent), var(--accent)),
    linear-gradient(var(--line), var(--line));
  background-size: 0 1.5px, 100% 1.5px;
  background-position: 0 100%, 0 100%;
  background-repeat: no-repeat;
  transition: background-size 0.3s var(--ease), color 0.2s var(--ease);
}

.feature-title a:hover {
  color: var(--accent-strong);
  background-image:
    linear-gradient(var(--accent), var(--accent)),
    linear-gradient(var(--accent), var(--accent));
}

.feature-desc {
  max-width: var(--measure);
  color: var(--muted);
  margin: 0.7rem 0 1.1rem;
  font-size: 0.95em;
  line-height: 1.55;
}

.more-link {
  font-family: var(--font-sans);
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--accent-strong);
  display: inline-flex;
  align-items: baseline;
  gap: 0.35em;
}

.more-link .arrow { transition: transform 0.25s var(--ease); }
.more-link:hover .arrow { transform: translateX(3px); }

/* ---- Writing index (list of entries) ---- */
.entries {
  list-style: none;
  margin: 0;
  padding: 0;
}

.entry {
  padding: clamp(1.5rem, 4vw, 2rem) 0;
  border-top: 1px solid var(--line);
}

.entry:first-child {
  padding-top: 0;
  border-top: none;
}

.entry .meta {
  font-family: var(--font-sans);
  font-size: 0.8rem;
  color: var(--muted);
}

.entry .meta em { font-style: italic; }

.note {
  font-family: var(--font-sans);
  font-size: 0.85rem;
  color: var(--muted);
  margin: clamp(1.75rem, 5vw, 2.5rem) 0 0;
}

/* ---- Elsewhere index (home) ---- */
.index {
  list-style: none;
  margin: 0;
  padding: 0;
}

.index li {
  display: grid;
  grid-template-columns: 11rem 1fr;
  align-items: baseline;
  gap: 0.2rem 1.5rem;
  padding: 0.85rem 0;
  border-top: 1px solid var(--line-soft);
}

.index li:first-child { border-top: none; }

.index .term {
  font-family: var(--font-sans);
  font-weight: 500;
  font-size: 0.95rem;
  color: var(--ink-strong);
  position: relative;
  width: max-content;
}

.index .term::after {
  content: "";
  position: absolute;
  left: 0;
  right: 100%;
  bottom: -2px;
  height: 1.5px;
  background: var(--accent);
  transition: right 0.28s var(--ease);
}

.index .term:hover { color: var(--accent-strong); }
.index .term:hover::after { right: 0; }

.index .gloss {
  font-family: var(--font-sans);
  font-size: 0.875rem;
  line-height: 1.4;
  color: var(--muted);
}

/* ---- Calendly widget (debate) ---- */
.cal-wrap {
  margin-top: clamp(1.75rem, 5vw, 2.5rem);
  border-top: 1px solid var(--line);
  padding-top: clamp(1.5rem, 4vw, 2rem);
}

.calendly-inline-widget {
  min-width: 320px;
  height: 700px;
}

/* ---- Contact ---- */
.contact {
  color: var(--muted);
  font-size: 0.95em;
}

.contact p {
  max-width: var(--measure);
  margin: 0;
}

.contact a {
  color: var(--ink-strong);
  font-weight: 500;
  text-decoration: underline;
  text-decoration-thickness: 0.06em;
  text-underline-offset: 0.18em;
  text-decoration-color: color-mix(in oklch, var(--accent) 42%, transparent);
  transition: color 0.2s var(--ease), text-decoration-color 0.2s var(--ease);
}

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

/* ---- Footer ---- */
footer {
  margin-top: clamp(3rem, 8vw, 4.5rem);
  padding-top: 1.25rem;
  border-top: 1px solid var(--line);
  font-family: var(--font-sans);
  font-size: 0.8rem;
  color: var(--muted);
}

/* ---- Motion: the page sets itself, like type being composed ----
   A quiet base wash carries the blocks; bespoke accents give each element
   the motion that fits it. Everything settles to the static rest state,
   so the page is fully legible the instant it stops. ---- */
@media (prefers-reduced-motion: no-preference) {
  /* Base arrival for whole blocks (nav, sections, footer). */
  .reveal {
    opacity: 0;
    transform: translateY(12px);
    animation: rise 0.75s var(--ease) both;
    animation-delay: calc(var(--d, 0) * 90ms);
  }

  /* Hero: the name is set with a top-down wipe; the portrait resolves. */
  .hero h1 {
    animation: name-set 0.85s var(--ease) both;
    animation-delay: calc(var(--d, 0) * 90ms + 60ms);
  }
  .hero .avatar {
    animation: portrait-resolve 0.9s var(--ease) both;
    animation-delay: calc(var(--d, 0) * 90ms + 20ms);
  }

  /* Prose and the Elsewhere rows settle in reading order, not all at once. */
  .prose p {
    animation: lift 0.7s var(--ease) both;
    animation-delay: calc(var(--d, 0) * 90ms + var(--i, 0) * 80ms);
  }
  .index li {
    animation: lift 0.65s var(--ease) both;
    animation-delay: calc(var(--d, 0) * 90ms + var(--i, 0) * 70ms);
  }

  /* Each section's hairline rule wipes in from the left as the label lands. */
  .label::before {
    transform: scaleX(0);
    animation: rule-wipe 0.7s var(--ease) both;
    animation-delay: calc(var(--d, 0) * 90ms + 80ms);
  }

  /* The teaching moment fires when a section scrolls into view (JS adds
     .in-view), not on load, so a first-time reader actually catches their links
     announcing themselves. The links rest fully visible and clickable; this
     only pulses the accent once. Skipped under reduced motion or with JS off. */
  .prose.in-view a,
  .contact.in-view a {
    animation: link-teach 1.1s var(--ease) 1;
  }
  .writing.in-view .feature-title a {
    animation: title-teach 1.15s var(--ease) 1;
    animation-delay: 0.18s;
  }
  .elsewhere.in-view .term::after {
    animation: term-teach 1.3s var(--ease) 1;
    animation-delay: calc(var(--i, 0) * 70ms);
  }
}

@keyframes rise {
  to { opacity: 1; transform: none; }
}

@keyframes lift {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: none; }
}

/* The serif name is revealed top-down through a mask, as if just printed. */
@keyframes name-set {
  from {
    opacity: 0;
    clip-path: inset(0 0 100% 0);
    transform: translateY(0.1em);
  }
  to {
    opacity: 1;
    clip-path: inset(0 0 0 0);
    transform: none;
  }
}

@keyframes portrait-resolve {
  from { opacity: 0; transform: scale(0.94); }
  to   { opacity: 1; transform: none; }
}

@keyframes rule-wipe {
  from { transform: scaleX(0); }
  to   { transform: scaleX(1); }
}

/* Accent underline sweeps across the link, then leaves the resting hairline. */
@keyframes title-teach {
  0%   { background-size: 0 1.5px, 100% 1.5px; }
  45%  { background-size: 100% 1.5px, 100% 1.5px; }
  100% { background-size: 0 1.5px, 100% 1.5px; }
}

/* The Elsewhere term draws its accent rule from the left, holds, then fades. */
@keyframes term-teach {
  0%   { right: 100%; opacity: 1; }
  38%  { right: 0;    opacity: 1; }
  72%  { right: 0;    opacity: 1; }
  100% { right: 0;    opacity: 0; }
}

/* Inline links pulse their underline to full accent once, then settle back. */
@keyframes link-teach {
  0%, 18% { text-decoration-color: color-mix(in oklch, var(--accent) 42%, transparent); }
  50%     { text-decoration-color: var(--accent); }
  100%    { text-decoration-color: color-mix(in oklch, var(--accent) 42%, transparent); }
}

/* ---- Narrow viewports ---- */
@media (max-width: 34rem) {
  .hero {
    flex-direction: column;
    align-items: flex-start;
    gap: 1.1rem;
  }
  .index li {
    grid-template-columns: 1fr;
    gap: 0.25rem;
  }
}
