/* michaeldewong.com — site stylesheet
   A text-led page on a two-column grid: a narrow margin column for labels
   and metadata, and a reading column for everything else. */

/* ---------- Fonts (self-hosted, Latin subset) ---------- */

@font-face {
  font-family: "Source Serif 4";
  src: url("/assets/fonts/source-serif-4-latin-opsz-normal.woff2") format("woff2-variations");
  font-weight: 200 900;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Source Serif 4";
  src: url("/assets/fonts/source-serif-4-latin-opsz-italic.woff2") format("woff2-variations");
  font-weight: 200 900;
  font-style: italic;
  font-display: swap;
}
@font-face {
  font-family: "IBM Plex Sans";
  src: url("/assets/fonts/ibm-plex-sans-latin-400-normal.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "IBM Plex Sans";
  src: url("/assets/fonts/ibm-plex-sans-latin-500-normal.woff2") format("woff2");
  font-weight: 500;
  font-style: normal;
  font-display: swap;
}

/* ---------- Tokens ---------- */

:root {
  --paper: #f7f5f0;
  --ink: #1c1b18;
  --ink-2: #57534b;          /* secondary text */
  --rule: #d6d0c4;           /* hairlines */
  --accent: #1e3a62;         /* ink blue: links and focus only */
  --accent-soft: rgb(30 58 98 / 0.35);

  --serif: "Source Serif 4", Georgia, "Times New Roman", serif;
  --sans: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", sans-serif;

  --step--1: 0.8125rem;      /* labels, metadata */
  --step-0: 1.1875rem;       /* body */
  --step-1: 1.375rem;        /* lead paragraph, masthead name */
  --step-2: 1.625rem;        /* entry titles */
  --step-3: clamp(2rem, 1.2rem + 3.2vw, 3.25rem); /* lead statement */

  --gutter: 1.25rem;
  --margin-col: 11.5rem;
  --col-gap: 3rem;
  --measure: 37rem;
  --section-space: clamp(3rem, 2rem + 3vw, 4.5rem);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #151412;
    --ink: #ebe7df;
    --ink-2: #a9a397;
    --rule: #3a3731;
    --accent: #a8c0e2;
    --accent-soft: rgb(168 192 226 / 0.4);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper: #151412;
  --ink: #ebe7df;
  --ink-2: #a9a397;
  --rule: #3a3731;
  --accent: #a8c0e2;
  --accent-soft: rgb(168 192 226 / 0.4);
  color-scheme: dark;
}

/* ---------- Base ---------- */

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

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

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--serif);
  font-size: var(--step-0);
  line-height: 1.6;
  font-optical-sizing: auto;
  font-variant-numeric: lining-nums proportional-nums;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, p, ul, ol, figure { margin: 0; }
ul, ol { padding: 0; list-style: none; }

a {
  color: var(--accent);
  text-decoration-line: underline;
  text-decoration-thickness: 1px;
  text-decoration-color: var(--accent-soft);
  text-underline-offset: 0.2em;
  transition: text-decoration-color 0.15s ease;
}
a:hover { text-decoration-color: currentColor; }

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

.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
}

.skip-link {
  position: absolute;
  left: var(--gutter);
  top: 0.75rem;
  padding: 0.5rem 0.75rem;
  background: var(--paper);
  font-family: var(--sans);
  font-size: var(--step--1);
  transform: translateY(-200%);
}
.skip-link:focus { transform: none; }

.arrow { display: inline-block; margin-left: 0.3em; text-decoration: none; }
.arrow--back { margin: 0 0.3em 0 0; }

/* ---------- Grid ----------
   Desktop: [ gutter | margin column | gap | reading column | wider right space ]
   The extra space on the right keeps the composition off-centre. */

.grid {
  display: grid;
  grid-template-columns:
    [full-start] minmax(var(--gutter), 1fr)
    [margin-start] var(--margin-col)
    [margin-end] var(--col-gap)
    [text-start] minmax(0, var(--measure))
    [text-end] minmax(var(--gutter), 1.6fr)
    [full-end];
}

@media (max-width: 52rem) {
  :root { --step-0: 1.125rem; --step-1: 1.25rem; --step-2: 1.4375rem; }
  .grid {
    grid-template-columns:
      [full-start] var(--gutter)
      [margin-start text-start] minmax(0, 1fr)
      [margin-end text-end] var(--gutter)
      [full-end];
  }
}

/* ---------- Masthead ---------- */

.masthead {
  align-items: baseline;
  padding-top: clamp(1.75rem, 1rem + 2.5vw, 3rem);
}
.masthead__name {
  grid-column: margin-start / text-end;
  font-size: var(--step-1);
  font-weight: 600;
  line-height: 1.2;
  letter-spacing: -0.005em;
}
.masthead__name a { color: inherit; text-decoration: none; }
.masthead__name a:hover { text-decoration: underline; text-decoration-color: var(--rule); }
.masthead__descriptor {
  grid-column: margin-start / text-end;
  margin-top: 0.3rem;
  font-family: var(--sans);
  font-size: 0.875rem;
  color: var(--ink-2);
  letter-spacing: 0.01em;
}

@media (min-width: 52.0625rem) {
  /* Name and descriptor share one line: name in the margin column,
     descriptor at the start of the reading column. */
  .masthead__name { grid-column: margin-start / margin-end; white-space: nowrap; }
  .masthead__descriptor { grid-column: text-start / text-end; margin-top: 0; }
}

/* ---------- Lead ---------- */

.lead {
  padding-top: clamp(3.5rem, 2rem + 6vw, 7rem);
  padding-bottom: var(--section-space);
}
.lead__statement {
  grid-column: margin-start / text-end;
  max-width: 32ch;
  font-size: var(--step-3);
  font-weight: 500;
  line-height: 1.12;
  letter-spacing: -0.015em;
  text-wrap: balance;
}
.lead__body {
  grid-column: text-start / text-end;
  margin-top: 1.75rem;
  font-size: var(--step-1);
  line-height: 1.55;
  text-wrap: pretty;
}
.lead__aside {
  grid-column: margin-start / margin-end;
  grid-row: 2;
  align-self: start;
  margin-top: 2.1rem;
  font-family: var(--sans);
  font-size: var(--step--1);
  color: var(--ink-2);
}
.lead--short { padding-bottom: clamp(5rem, 3rem + 8vw, 9rem); }

@media (max-width: 52rem) {
  .lead__aside { grid-row: 3; margin-top: 1.25rem; }
}

/* ---------- Sections ---------- */

.section {
  position: relative;
  padding-block: 1.25rem var(--section-space);
  row-gap: 0;
}
.section::before {
  /* Hairline across both columns */
  content: "";
  grid-column: margin-start / text-end;
  grid-row: 1;
  align-self: start;
  height: 1px;
  margin-top: -1.25rem;
  background: var(--rule);
}
.section__label {
  grid-column: margin-start / margin-end;
  grid-row: 1;
  font-family: var(--sans);
  font-size: var(--step--1);
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-2);
  line-height: 1.6;
}
.section__body {
  grid-column: text-start / text-end;
  grid-row: 1 / span 2;
}

@media (max-width: 52rem) {
  .section__label { margin-bottom: 1.25rem; }
  .section__body { grid-row: 2; }
}

/* ---------- Writing entries ---------- */

.entry {
  grid-column: margin-start / text-end;
  display: grid;
  grid-template-columns: subgrid;
  padding-block: 1.75rem 0;
}
.entry:first-of-type { padding-top: 1.75rem; }
.entry + .entry { margin-top: 2.5rem; border-top: 1px solid var(--rule); }

.entry__aside { grid-column: margin-start / margin-end; }
.entry__main  { grid-column: text-start / text-end; }

.entry__meta {
  font-family: var(--sans);
  font-size: var(--step--1);
  color: var(--ink-2);
  font-variant-numeric: tabular-nums;
  padding-top: 0.45rem;
}
.entry__series { display: block; }

.entry__title {
  font-size: var(--step-2);
  font-weight: 600;
  line-height: 1.22;
  letter-spacing: -0.01em;
  text-wrap: balance;
}
.entry__title a { color: var(--ink); text-decoration-color: var(--rule); }
.entry__title a:hover { color: var(--accent); text-decoration-color: var(--accent-soft); }

.entry__summary {
  margin-top: 0.85rem;
  color: var(--ink);
  text-wrap: pretty;
}
.entry__more {
  margin-top: 1rem;
  font-family: var(--sans);
  font-size: 0.9375rem;
  font-weight: 500;
}

/* The figures that anchor an entry, set like a short quote sheet. */
.figures { margin-top: 1.5rem; }
.figures__caption {
  font-family: var(--sans);
  font-size: 0.75rem;
  letter-spacing: 0.02em;
  color: var(--ink-2);
  padding-bottom: 0.4rem;
  border-bottom: 1px solid var(--rule);
}
.figures__values li {
  font-size: 1.25rem;
  font-variant-numeric: lining-nums tabular-nums;
  line-height: 1;
  padding: 0.55rem 0;
  border-bottom: 1px solid var(--rule);
  text-align: right;
}

@media (max-width: 52rem) {
  .entry__aside { margin-bottom: 0.5rem; }
  .entry__meta { padding-top: 0; }
  .entry:first-of-type { padding-top: 0; }
  /* On narrow screens the summary already carries the figures in context. */
  .entry__aside .figures { display: none; }
}

/* ---------- Contact ---------- */

.contact__text { text-wrap: pretty; }
.contact__invite { margin-top: 1.25rem; color: var(--ink-2); }
.contact__email {
  margin-top: 0.35rem;
  font-size: var(--step-1);
}

/* ---------- Footer ---------- */

.site-footer {
  padding-block: 1.25rem 3rem;
  font-family: var(--sans);
  font-size: var(--step--1);
  color: var(--ink-2);
}
.site-footer::before {
  content: "";
  grid-column: margin-start / text-end;
  grid-row: 1;
  height: 1px;
  margin-top: -1.25rem;
  background: var(--rule);
}
.site-footer__name { grid-column: margin-start / text-end; grid-row: 1; }
.site-footer a { color: var(--ink-2); text-decoration-color: var(--rule); }
.site-footer a:hover { color: var(--accent); }

/* ---------- Prose (on-site articles, background) ---------- */

.prose > * + * { margin-top: 1.1em; }
.prose h2 {
  margin-top: 2em;
  font-size: var(--step-1);
  font-weight: 600;
  line-height: 1.3;
}
.prose h3 { margin-top: 1.6em; font-size: var(--step-0); font-weight: 600; }
.prose ul, .prose ol { padding-left: 1.25em; }
.prose ul { list-style: disc; }
.prose ol { list-style: decimal; }
.prose li + li { margin-top: 0.4em; }
.prose blockquote {
  margin: 1.5em 0;
  padding-left: 1.1em;
  border-left: 2px solid var(--rule);
  color: var(--ink-2);
}
.prose table {
  width: 100%;
  border-collapse: collapse;
  font-variant-numeric: lining-nums tabular-nums;
  font-size: 1rem;
}
.prose th, .prose td {
  padding: 0.55em 0.75em 0.55em 0;
  border-bottom: 1px solid var(--rule);
  text-align: left;
  vertical-align: top;
}
.prose th {
  font-family: var(--sans);
  font-size: var(--step--1);
  font-weight: 500;
  color: var(--ink-2);
}
.prose td.num, .prose th.num { text-align: right; }
.prose hr { border: 0; height: 1px; background: var(--rule); margin: 2.5em 0; }

/* ---------- On-site article ---------- */

.article { padding-top: clamp(3rem, 2rem + 4vw, 5.5rem); padding-bottom: var(--section-space); }
.article__header { grid-column: text-start / text-end; }
.article__title {
  font-size: clamp(1.875rem, 1.3rem + 2.2vw, 2.625rem);
  font-weight: 600;
  line-height: 1.15;
  letter-spacing: -0.015em;
  text-wrap: balance;
}
.article__dek { margin-top: 1rem; font-size: var(--step-1); color: var(--ink-2); line-height: 1.45; }
.article__aside { grid-column: margin-start / margin-end; grid-row: 2; padding-top: 2.6rem; }
.article__origin { margin-top: 0.5rem; font-family: var(--sans); font-size: var(--step--1); color: var(--ink-2); }
.article__body { grid-column: text-start / text-end; grid-row: 2; padding-top: 2.5rem; }
.article__footer {
  grid-column: text-start / text-end;
  margin-top: 3rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--rule);
  font-family: var(--sans);
  font-size: 0.9375rem;
  color: var(--ink-2);
}
.article__footer p + p { margin-top: 0.75rem; }

@media (max-width: 52rem) {
  .article__aside { grid-row: 2; padding-top: 1.5rem; }
  .article__body { grid-row: 3; padding-top: 1.75rem; }
}

/* ---------- Print ---------- */

@media print {
  :root { --paper: #fff; --ink: #000; --ink-2: #333; --accent: #000; }
  .skip-link, .entry__more { display: none; }
}

/* Wide tables scroll inside the column instead of widening the page. */
@media (max-width: 52rem) {
  .prose table { display: block; overflow-x: auto; }
}
