/* ============================================================
   Open Margins — Patrick Lei
   Pearl canvas, rounded display serif, sparse curves.
   No gradients, no shadows.
   ============================================================ */

/* ---- Tokens ---------------------------------------------- */
:root {
  --pearl: #f7f5f1;
  --pearl-raised: #fbfaf7;
  --soft-black: #1e201f;
  --ink-blue: #304a67;
  --lilac: #b9aec9;
  --apricot: #e8a77c;

  /* Derived neutrals, all mixed from the five approved colours. */
  --muted: #6a6b66;
  /* Quietest text tone that still clears WCAG AA (4.51:1) on the pearl canvas. */
  --muted-soft: #727168;
  --rule: #e2ded4;
  --rule-strong: #cfcabd;
  --stripe: #f0ebe1;

  --serif: "Young Serif", "Songti SC", Georgia, "Times New Roman", serif;
  --sans: "Source Sans 3", -apple-system, BlinkMacSystemFont, "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, monospace;

  --display-axes: normal;

  --measure: 34rem;
}

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

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

body {
  margin: 0;
  background: var(--pearl);
  color: var(--soft-black);
  font-family: var(--sans);
  font-size: 1.125rem;
  line-height: 1.7;
  font-synthesis-weight: none;
  -webkit-font-smoothing: antialiased;
}

h1,
h2,
h3,
h4,
p,
ul,
ol,
figure {
  margin: 0;
}

ul,
ol {
  padding: 0;
}

a {
  color: var(--ink-blue);
  text-underline-offset: 0.2em;
  text-decoration-thickness: 1px;
  text-decoration-color: color-mix(in srgb, var(--ink-blue) 35%, transparent);
}

a:hover {
  text-decoration-color: currentColor;
}

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

img {
  max-width: 100%;
  height: auto;
}

.skip-link {
  position: absolute;
  left: 1rem;
  top: -4rem;
  z-index: 100;
  background: var(--soft-black);
  color: var(--pearl);
  padding: 0.6rem 1rem;
  border-radius: 999px;
  font: 500 0.8rem/1 var(--sans);
  text-decoration: none;
  transition: top 0.15s ease;
}

.skip-link:focus {
  top: 1rem;
}

/* ---- The asymmetric column -------------------------------
   Wider gutter on the left than the right: the left margin is
   where the floating nav rail lives. -------------------------- */
.wrap {
  margin-inline: 1.5rem;
}

@media (min-width: 62rem) {
  .wrap {
    margin-left: clamp(9rem, 14vw, 15rem);
    margin-right: clamp(4rem, 7vw, 8rem);
  }
}

/* ---- Masthead --------------------------------------------- */
.masthead {
  padding-top: 2.25rem;
}

.masthead-inner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 1rem 2rem;
}

.wordmark {
  font-family: var(--mono);
  font-size: 0.78rem;
  font-weight: 500;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--soft-black);
  text-decoration: none;
  white-space: nowrap;
}

.wordmark:hover {
  color: var(--ink-blue);
}

.masthead-links {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem clamp(0.9rem, 1.8vw, 1.8rem);
  font-family: var(--mono);
  font-size: 0.8rem;
}

.masthead-links > a {
  color: var(--muted);
  text-decoration: none;
  white-space: nowrap;
}

.masthead-links > a:hover {
  color: var(--soft-black);
}

/* ---- EN / 中文 segmented switch ---------------------------- */
.langswitch {
  display: inline-flex;
  align-items: stretch;
  gap: 2px;
  padding: 2px;
  border: 1px solid var(--rule-strong);
  border-radius: 0.55rem;
  background: var(--pearl-raised);
}

.langswitch a {
  padding: 0.22rem 0.5rem;
  border-radius: 0.4rem;
  font-family: var(--mono);
  font-size: 0.7rem;
  font-weight: 500;
  letter-spacing: 0.06em;
  line-height: 1.5;
  color: var(--muted);
  text-decoration: none;
}

.langswitch a:hover {
  color: var(--soft-black);
}

.langswitch a[aria-current="true"] {
  background: var(--soft-black);
  color: var(--pearl);
}

.langswitch .lang-zh {
  font-family: var(--sans);
  letter-spacing: 0.02em;
}

/* ---- Floating nav rail ------------------------------------ */
.rail {
  margin: 1.75rem 1.5rem 0;
}

.rail-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.15rem 0.35rem;
  list-style: none;
  margin: 0;
  padding: 0.5rem 0.6rem;
  border: 1px solid var(--rule);
  border-radius: 1.6rem;
  background: var(--pearl-raised);
}

.rail-link {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.28rem 0.6rem;
  border-radius: 999px;
  font-size: 0.84rem;
  font-weight: 500;
  line-height: 1.5;
  color: var(--soft-black);
  text-decoration: none;
  white-space: nowrap;
}

.rail-link:hover {
  background: color-mix(in srgb, var(--lilac) 22%, transparent);
}

.rail-link[aria-current="page"] {
  background: var(--apricot);
}

.rail-link[aria-current="page"]:hover {
  background: color-mix(in srgb, var(--apricot) 85%, var(--soft-black));
}

.marker {
  width: 0.5rem;
  height: 0.5rem;
  flex: none;
  border-radius: 50%;
  background: transparent;
}

.marker--apricot {
  background: var(--apricot);
}

.marker--lilac {
  background: var(--lilac);
}

.marker--ink {
  background: var(--ink-blue);
}

.marker--hollow {
  border: 1.5px solid var(--soft-black);
}

.rail-link[aria-current="page"] .marker {
  background: var(--pearl);
  border-color: var(--pearl);
}

@media (min-width: 62rem) {
  .rail {
    position: fixed;
    left: clamp(0.75rem, 1.5vw, 2.25rem);
    top: 50%;
    transform: translateY(-50%);
    margin: 0;
    z-index: 20;
  }

  .rail-list {
    flex-direction: column;
    flex-wrap: nowrap;
    gap: 0.1rem;
    padding: 0.85rem 0.7rem;
    border-radius: 1.9rem;
  }
}

/* ---- Hero -------------------------------------------------- */
.hero {
  position: relative;
  padding-top: clamp(2.25rem, 6.6vw, 6.25rem);
  padding-bottom: clamp(2rem, 4.5vw, 4.5rem);
}

.hero-name {
  font-family: var(--serif);
  font-variation-settings: var(--display-axes);
  font-weight: 600;
  font-size: clamp(3.25rem, 11.6vw, 10.5rem);
  line-height: 0.9;
  letter-spacing: -0.012em;
  margin: 0;
}

.hero-line {
  display: block;
  position: relative;
}

.hero-line--indent {
  padding-left: clamp(0.75rem, 6.6vw, 6rem);
}

.hero-word {
  position: relative;
  z-index: 1;
}

.hero-disc {
  position: absolute;
  z-index: 0;
  left: clamp(0.75rem, 6.6vw, 6rem);
  top: 0.17em;
  width: 0.86em;
  height: 0.86em;
  margin-left: -0.29em;
  border-radius: 50%;
  background: var(--lilac);
  opacity: 0.5;
}

.hero-intro {
  font-family: var(--serif);
  font-variation-settings: "SOFT" 70, "WONK" 1, "opsz" 60;
  font-weight: 600;
  font-size: clamp(1.6rem, 2.9vw, 2.55rem);
  line-height: 1.18;
  letter-spacing: -0.012em;
  max-width: 12em;
  text-wrap: balance;
  margin-top: clamp(2rem, 4.5vw, 4rem);
}

.hero-lede {
  max-width: var(--measure);
  margin-top: 1.6rem;
  color: var(--soft-black);
}

/* ---- Portrait placeholder ---------------------------------- */
.portrait {
  display: none;
}

@media (min-width: 62rem) {
  .portrait {
    display: grid;
    place-items: center;
    position: absolute;
    /* Sits higher than the name's cap line, as in the approved design. */
    top: clamp(1.25rem, 3.9vw, 3.5rem);
    right: 8%;
    width: clamp(8rem, 12.5vw, 11.5rem);
    aspect-ratio: 1;
    border: 1px solid var(--rule);
    border-radius: 50%;
    /* Hard-stop stripes, not a gradient. */
    background-image: repeating-linear-gradient(
      -45deg,
      var(--stripe) 0 5px,
      var(--pearl-raised) 5px 11px
    );
    font-family: var(--mono);
    font-size: 0.72rem;
    color: var(--muted-soft);
    overflow: hidden;
  }

  .portrait img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 50%;
  }
}

/* ---- Bowed divider ----------------------------------------- */
.bow {
  display: block;
  width: 100%;
  height: clamp(1.5rem, 3.2vw, 2.75rem);
  color: var(--rule-strong);
}

.bow svg {
  display: block;
  width: 100%;
  height: 100%;
}

/* ---- Sections ---------------------------------------------- */
.section {
  padding-top: clamp(3rem, 7vw, 6rem);
}

.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1.5rem;
  flex-wrap: wrap;
  margin-bottom: clamp(1.75rem, 3.5vw, 3rem);
}

.section-title {
  display: flex;
  align-items: baseline;
  gap: 0.85rem;
  font-family: var(--serif);
  font-variation-settings: var(--display-axes);
  font-weight: 600;
  font-size: clamp(1.75rem, 3.3vw, 2.9rem);
  line-height: 1.1;
  letter-spacing: -0.015em;
}

.section-title .marker {
  position: relative;
  top: -0.1em;
}

.section-more {
  font-size: 0.9rem;
  color: var(--ink-blue);
  text-decoration: none;
  white-space: nowrap;
}

.section-more:hover {
  text-decoration: underline;
}

.section--tight {
  padding-top: clamp(1.25rem, 2.5vw, 2.25rem);
}

.section-lede {
  max-width: var(--measure);
  margin-top: -1rem;
  margin-bottom: clamp(1.75rem, 3.5vw, 3rem);
  color: var(--muted);
}

/* ---- Page hero (interior pages) ---------------------------- */
.page-head {
  padding-top: clamp(2.5rem, 7vw, 6rem);
  padding-bottom: clamp(1.5rem, 3vw, 2.5rem);
}

.page-title {
  font-family: var(--serif);
  font-variation-settings: var(--display-axes);
  font-weight: 600;
  font-size: clamp(2.6rem, 7vw, 5.5rem);
  line-height: 0.98;
  letter-spacing: -0.022em;
  display: flex;
  align-items: baseline;
  gap: 0.7rem;
}

.page-title .marker {
  position: relative;
  top: -0.11em;
  width: 0.62rem;
  height: 0.62rem;
}

.page-title--sm {
  font-size: clamp(2rem, 4.4vw, 3.6rem);
  line-height: 1.06;
}

.page-title--sm .marker {
  top: -0.1em;
  width: 0.55rem;
  height: 0.55rem;
}

.page-eyebrow {
  font-family: var(--mono);
  font-size: 0.8rem;
  letter-spacing: 0.06em;
  color: var(--muted-soft);
  margin-bottom: 0.9rem;
}

.page-lede {
  max-width: var(--measure);
  margin-top: 1.5rem;
  color: var(--muted);
}

/* ---- Paper rows -------------------------------------------- */
.rows {
  list-style: none;
  margin: 0;
  padding: 0;
}

.row {
  display: grid;
  gap: 0.35rem 1.5rem;
  padding: clamp(1.5rem, 2.6vw, 2.25rem) 0;
  border-top: 1px solid var(--rule);
}

.rows > .row:last-child {
  border-bottom: 1px solid var(--rule);
}

/* The homepage reproduces Claude Design's soft, alternating paper bands.
   Other index pages keep the quieter ruled treatment. */
.rows--featured {
  display: grid;
  gap: 0.75rem;
}

.rows--featured .row {
  padding-inline: clamp(1.5rem, 2.3vw, 2.25rem);
  border: 0;
  border-radius: 1.5rem;
  background: color-mix(in srgb, var(--apricot) 20%, var(--pearl));
}

.rows--featured .row:nth-child(3n + 2) {
  background: color-mix(in srgb, var(--lilac) 24%, var(--pearl));
}

.rows--featured .row:nth-child(3n) {
  background: color-mix(in srgb, var(--ink-blue) 8%, var(--pearl));
}

.rows--featured > .row:last-child {
  border-bottom: 0;
}

.rows--home-notes .row {
  grid-template-columns: 4.5rem minmax(0, 1fr) 11rem 5.5rem;
  padding-block: 1.15rem;
}

.section--home-notes {
  padding-bottom: clamp(3rem, 6vw, 5.5rem);
}

@media (min-width: 62rem) {
  .section--about {
    display: grid;
    grid-template-columns: minmax(11rem, 0.28fr) minmax(0, 1fr);
    gap: clamp(3rem, 7vw, 7.5rem);
    align-items: start;
  }

  .section-head--about {
    margin: 0;
  }

  .section--about .prose {
    max-width: 42rem;
  }
}

@media (max-width: 47.999rem) {
  .rows--home-notes .row {
    grid-template-columns: 1fr;
  }
}

@media (min-width: 48rem) {
  .row {
    grid-template-columns: 5.5rem minmax(0, 1fr) 9rem 11rem;
    align-items: start;
  }

  .row--notes {
    grid-template-columns: 7.5rem minmax(0, 1fr) 9rem;
  }

  .row--pair {
    grid-template-columns: 7.5rem minmax(0, 1fr);
  }
}

.row-date {
  font-family: var(--mono);
  font-size: 0.82rem;
  color: var(--muted-soft);
  line-height: 1.9;
}

.row-date span {
  display: block;
}

.row-title {
  font-family: var(--serif);
  font-variation-settings: "SOFT" 70, "WONK" 1, "opsz" 48;
  font-weight: 600;
  font-size: clamp(1.2rem, 2.05vw, 1.7rem);
  line-height: 1.22;
  letter-spacing: -0.01em;
}

.row-title a {
  color: inherit;
  text-decoration: none;
}

.row-title a:hover {
  color: var(--ink-blue);
}

.row-meta,
.row-links {
  font-family: var(--mono);
  font-size: 0.78rem;
  line-height: 1.75;
  color: var(--muted);
}

.row-meta span,
.row-links a {
  display: block;
}

.row-links a {
  color: var(--ink-blue);
  text-decoration: none;
}

.row-links a:hover {
  text-decoration: underline;
}

.row-body {
  color: var(--muted);
  font-size: 0.98rem;
  max-width: 40rem;
}

/* ---- Prose (about, seminar pages, now) --------------------- */
.prose {
  max-width: 40rem;
}

.prose p,
.prose ul,
.prose ol,
.prose table {
  margin-bottom: 1.15rem;
}

.prose ul,
.prose ol {
  padding-left: 1.25rem;
}

.prose li {
  margin-bottom: 0.35rem;
}

.prose h1,
.prose h2,
.prose h3,
.prose h4,
.prose h5 {
  font-family: var(--serif);
  font-variation-settings: var(--display-axes);
  font-weight: 600;
  line-height: 1.15;
  letter-spacing: -0.012em;
  margin: 2.25rem 0 0.9rem;
}

.prose h1 {
  font-size: 1.9rem;
}

.prose h2 {
  font-size: 1.6rem;
}

.prose h3,
.prose h4,
.prose h5 {
  font-size: 1.3rem;
}

.prose > :first-child {
  margin-top: 0;
}

.prose code {
  font-family: var(--mono);
  font-size: 0.9em;
}

.prose blockquote {
  margin: 0 0 1.15rem;
  padding-left: 1.25rem;
  border-left: 2px solid var(--lilac);
  color: var(--muted);
}

/* Seminar pages carry wide schedule tables, so the block itself is full width,
   but running text keeps a readable measure. */
.prose--wide {
  max-width: none;
}

.prose--wide > p,
.prose--wide > ul,
.prose--wide > ol,
.prose--wide > blockquote,
.prose--wide > h1,
.prose--wide > h2,
.prose--wide > h3,
.prose--wide > h4,
.prose--wide > h5 {
  max-width: 42rem;
}

.table-scroll {
  overflow-x: auto;
  margin-bottom: 1.5rem;
}

/* Wide enough that the schedule stays legible; on desktop the 100% width
   below wins, on narrow screens this makes the wrapper scroll. */
.table-scroll table {
  min-width: 38rem;
  margin-bottom: 0;
}

.prose table {
  border-collapse: collapse;
  width: 100%;
  font-size: 0.92rem;
  line-height: 1.6;
}

.prose th,
.prose td {
  text-align: left;
  vertical-align: top;
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--rule);
}

.prose th {
  font-family: var(--mono);
  font-size: 0.72rem;
  font-weight: 500;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted-soft);
  white-space: nowrap;
}

.prose td:first-child {
  font-family: var(--mono);
  font-size: 0.8rem;
  white-space: nowrap;
  color: var(--muted);
}

/* ---- Now list ---------------------------------------------- */
.now-list {
  list-style: none;
  margin: 0;
  padding: 0;
  max-width: 40rem;
}

.now-list li {
  display: flex;
  align-items: baseline;
  gap: 1rem;
  padding: 1.1rem 0;
  border-top: 1px solid var(--rule);
  font-family: var(--serif);
  font-variation-settings: "SOFT" 70, "WONK" 1, "opsz" 48;
  font-weight: 600;
  font-size: clamp(1.15rem, 1.9vw, 1.55rem);
  line-height: 1.3;
  letter-spacing: -0.008em;
}

.now-list li:last-child {
  border-bottom: 1px solid var(--rule);
}

/* ---- Travel globe ------------------------------------------ */
#globe-container {
  width: 100%;
  min-height: 480px;
}

#globe-container svg {
  display: block;
  max-width: 100%;
  height: auto;
  margin-inline: auto;
}

.globe-motion-toggle {
  display: block;
  margin: 0.9rem auto 0;
  padding: 0.45rem 0.8rem;
  border: 1px solid var(--rule);
  border-radius: 999px;
  color: var(--ink-blue);
  background: var(--paper);
  font-family: var(--mono);
  font-size: 0.72rem;
  letter-spacing: 0.04em;
  cursor: pointer;
}

.globe-motion-toggle:hover {
  border-color: var(--ink-blue);
}

.globe-motion-toggle:focus-visible {
  outline: 2px solid var(--orange);
  outline-offset: 3px;
}

/* ---- Contact strip ----------------------------------------- */
.contact-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem 2.5rem;
  font-family: var(--mono);
  font-size: 0.85rem;
}

.contact-row a {
  color: var(--ink-blue);
  text-decoration: none;
}

.contact-row a:hover {
  text-decoration: underline;
}

/* ---- Footer ------------------------------------------------ */
.site-footer {
  margin-top: clamp(4rem, 9vw, 8rem);
  padding: 2rem 0 3.5rem;
  border-top: 1px solid var(--rule);
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 0.5rem 2rem;
  font-family: var(--mono);
  font-size: 0.76rem;
  color: var(--muted-soft);
}

.site-footer a {
  color: var(--muted-soft);
  text-decoration: none;
}

.site-footer a:hover {
  color: var(--soft-black);
}

/* ---- Utilities --------------------------------------------- */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* Chinese pages: Fraunces has no CJK coverage, so let the CJK serif carry
   the display sizes without the variable-axis settings. */
/* CJK breaks between any two characters, so the Latin balancing/measure rules
   would chop phrases mid-word. Let the line run instead. */
:lang(zh) .hero-intro {
  max-width: none;
  text-wrap: normal;
}

:lang(zh) .hero-intro,
:lang(zh) .section-title,
:lang(zh) .page-title,
:lang(zh) .now-list li,
:lang(zh) .row-title {
  font-variation-settings: normal;
  letter-spacing: 0;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}
