/* =============================================================================
   malinin.io — stylesheet
   Newsreader (serif display) · Inter (body) · IBM Plex Mono (labels)
   ============================================================================= */

/* ---------- Fonts --------------------------------------------------------- */
@font-face {
  font-family: 'Newsreader';
  font-style: normal;
  font-weight: 400 500;
  font-display: swap;
  src: url('../fonts/Newsreader-latin-var.woff2') format('woff2');
}
@font-face {
  font-family: 'Inter';
  font-style: normal;
  font-weight: 400 500;
  font-display: swap;
  src: url('../fonts/Inter-latin-var.woff2') format('woff2');
}
@font-face {
  font-family: 'IBM Plex Mono';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('../fonts/IBMPlexMono-latin-400.woff2') format('woff2');
}
@font-face {
  font-family: 'IBM Plex Mono';
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url('../fonts/IBMPlexMono-latin-500.woff2') format('woff2');
}

/* ---------- Theme tokens -------------------------------------------------- */
:root {
  --paper:    #FAF9F6;
  --ink:      #1C1B1A;
  --muted:    #6E6B66;
  --hairline: #E5E2DC;
  --accent:   #A8432E;
  --grain-opacity: 0.03;
  --grain-blend: normal;

  --serif: 'Newsreader', Georgia, serif;
  --sans:  'Inter', system-ui, -apple-system, sans-serif;
  --mono:  'IBM Plex Mono', ui-monospace, monospace;

  /* reading column + asymmetric page indent */
  --indent-l: clamp(1.5rem, 12vw, 11rem);
  --indent-r: clamp(1.5rem, 5vw, 3rem);
  --col: 46rem;
}
[data-theme="dark"] {
  --paper:    #171614;
  --ink:      #E9E6DF;
  --muted:    #9A968E;
  --hairline: #2A2825;
  --accent:   #CB6A54;
  --grain-opacity: 0.045;
  --grain-blend: screen;
}

/* ---------- Reset --------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 17px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  transition: background-color .2s ease, color .2s ease;
}
img { max-width: 100%; }

/* ---------- Film grain ---------------------------------------------------- */
.grain {
  position: fixed;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  opacity: var(--grain-opacity);
  mix-blend-mode: var(--grain-blend);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.8' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

/* ---------- Theme toggle -------------------------------------------------- */
.theme-toggle {
  position: fixed;
  top: 1.75rem;
  right: 1.75rem;
  z-index: 5;
  width: 2.5rem;
  height: 2.5rem;
  display: grid;
  place-items: center;
  padding: 0;
  border: 1px solid var(--hairline);
  border-radius: 50%;
  background: color-mix(in srgb, var(--paper) 82%, transparent);
  color: var(--muted);
  cursor: pointer;
  backdrop-filter: blur(6px);
  transition: color .2s ease, border-color .2s ease;
}
.theme-toggle:hover { color: var(--accent); border-color: var(--accent); }
.theme-toggle svg { width: 1.15rem; height: 1.15rem; display: block; }
.theme-toggle .icon-sun  { display: none; }
[data-theme="dark"] .theme-toggle .icon-sun  { display: block; }
[data-theme="dark"] .theme-toggle .icon-moon { display: none; }

/* ---------- Layout -------------------------------------------------------- */
.wrap {
  position: relative;
  z-index: 2;
  max-width: calc(var(--col) + var(--indent-l) + var(--indent-r));
  padding-inline: var(--indent-l) var(--indent-r);
}
.wrap--home { padding-top: clamp(6rem, 18vh, 12rem); padding-bottom: clamp(3rem, 8vh, 5rem); }
.wrap--sub  { padding-top: clamp(4rem, 12vh, 7rem);  padding-bottom: clamp(4rem, 10vh, 7rem); }

/* ---------- Reveal animation ---------------------------------------------- */
@keyframes fade-up {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}
.reveal { animation: fade-up 600ms cubic-bezier(0.22, 0.61, 0.36, 1) both; }
@media (prefers-reduced-motion: reduce) {
  .reveal { animation: none; }
}

/* ---------- Links --------------------------------------------------------- */
.link {
  color: inherit;
  text-decoration: none;
  border-bottom: 1px solid color-mix(in srgb, var(--muted) 55%, transparent);
  padding-bottom: 1px;
  transition: color .2s ease, border-color .2s ease;
}
.link:hover { color: var(--accent); border-bottom-color: var(--accent); }

.footlink {
  color: var(--muted);   /* explicit — don't inherit the faint --hairline from .site-footer__sep */
  text-decoration: none;
  border-bottom: 1px solid transparent;
  padding-bottom: 1px;
  transition: color .2s ease;
}
.footlink:hover { color: var(--accent); }

.backlink {
  font-family: var(--mono);
  font-size: 0.8125rem;
  color: var(--muted);
  text-decoration: none;
  display: inline-block;
  transition: color .2s ease;
}
.backlink:hover { color: var(--accent); }

/* ---------- Shared bits --------------------------------------------------- */
.label {
  font-family: var(--mono);
  font-size: 0.8125rem;
  font-weight: 400;          /* reset <h2> default bold — visual parity */
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 0;                 /* reset <h2> default margins (bottom set by .section > .label) */
}
.mono { font-family: var(--mono); }

/* ---------- Hero ---------------------------------------------------------- */
.hero {
  display: flex;
  align-items: center;
  gap: clamp(1.75rem, 3.5vw, 2.75rem);
  padding-bottom: clamp(2rem, 4vh, 2.75rem);
  border-bottom: 1px solid var(--hairline);
}
.hero__photo {
  flex: none;
  width: clamp(9rem, 16vw, 11.5rem);
  height: clamp(9rem, 16vw, 11.5rem);
  aspect-ratio: 1 / 1;
  object-fit: cover;
  border-radius: 50%;
  filter: grayscale(1);
  background: var(--hairline);
  display: block;
}
.hero__name {
  font-family: var(--serif);
  font-weight: 500;
  font-size: clamp(2.6rem, 4.6vw, 3.65rem);
  line-height: 1.04;
  letter-spacing: -0.01em;
  margin: 0 0 0.75rem;
}
.hero__statement {
  font-family: var(--serif);
  font-weight: 400;
  font-size: clamp(1.35rem, 2.4vw, 1.85rem);
  line-height: 1.3;
  letter-spacing: -0.005em;
  text-wrap: balance;
  max-width: 34ch;
  margin: 0;
  color: var(--muted);
}

/* ---------- Generic section ----------------------------------------------- */
.section { margin-top: clamp(4rem, 10vh, 8rem); }
.section--rule {
  margin-top: clamp(3rem, 7vh, 5rem);
  padding-top: clamp(2.5rem, 6vh, 4rem);
  border-top: 1px solid var(--hairline);
}
.section__head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 1.4rem;
}
.section > .label { display: block; margin-bottom: 1.4rem; }

/* ---------- Manifesto ----------------------------------------------------- */
.manifesto { margin-top: clamp(4rem, 10vh, 8rem); }
.manifesto__lede {
  font-family: var(--serif);
  font-weight: 400;
  font-size: clamp(1.35rem, 2.4vw, 1.8rem);
  line-height: 1.4;
  letter-spacing: -0.005em;
  text-wrap: balance;
  max-width: 40ch;
  margin: 0;
}
.manifesto p + p { margin: 1.1rem 0 0; }
.manifesto__body { max-width: 36rem; margin-top: 1.6rem; }

/* ---------- Now ----------------------------------------------------------- */
.now {
  margin-top: clamp(2.5rem, 6vh, 3.5rem);
  padding-top: 1.1rem;
  border-top: 1px solid var(--hairline);
}
.now__kicker {
  display: block;
  margin-bottom: 0.55rem;
  font-family: var(--mono);
  font-size: 0.75rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--accent);
  white-space: nowrap;
}
.now__text { margin: 0; font-size: 15px; line-height: 1.55; color: var(--muted); max-width: 36rem; }

/* visually-hidden: labels a section for crawlers & screen readers without showing it */
.vh { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; border: 0; }

/* ---------- Row lists (writing, projects, publications) ------------------- */
.rows { display: flex; flex-direction: column; }
.rows--tight { margin: 0; padding: 0; list-style: none; }

.row {
  display: grid;
  grid-template-columns: 1fr auto;
  column-gap: 20px;
  align-items: baseline;
  padding: 16px 12px;
  margin: 0 -12px;
  border-top: 1px solid var(--hairline);
  text-decoration: none;
  color: inherit;
  transition: background-color .18s ease;
}
.rows > .row:last-child,
.rows--tight > li:last-child .row { border-bottom: 1px solid var(--hairline); }
a.row:hover { background: color-mix(in srgb, var(--muted) 8%, transparent); }

.row__title {
  font-family: var(--serif);
  font-weight: 500;
  font-size: 21px;
  line-height: 1.3;
  margin: 0;
  transition: color .18s ease;
}
a.row:hover .row__title { color: var(--accent); }
.row__title a { color: inherit; text-decoration: none; transition: color .18s ease; }
.row__title a:hover { color: var(--accent); }
.row__dek { color: var(--muted); font-size: 15px; line-height: 1.5; margin: 6px 0 0; max-width: 52ch; }
.row__meta { font-family: var(--mono); font-size: 13px; color: var(--muted); white-space: nowrap; }

/* numbered publication rows */
.row--numbered { grid-template-columns: 2.5rem 1fr auto; column-gap: 18px; }
.row__num { font-family: var(--mono); font-size: 13px; color: var(--accent); }
.row__sub { color: var(--muted); font-size: 14px; margin: 5px 0 0; }
.row--numbered .row__title { font-size: 19px; max-width: 44ch; }

/* work / timeline rows */
.row--work { grid-template-columns: 6.5rem 1fr; column-gap: 22px; }
.row--work .row__title { font-size: 19px; }
.row--work .row__title span { color: var(--muted); font-weight: 400; }

/* ---------- Writing scroll area (home) ------------------------------------ */
.scroller { position: relative; }
.scroller__viewport {
  max-height: 21.5rem;
  overflow: hidden auto;
  border-bottom: 1px solid var(--hairline);
  scrollbar-width: thin;
  scrollbar-color: var(--hairline) transparent;
  overscroll-behavior: contain;
}
.scroller__viewport::-webkit-scrollbar { width: 6px; }
.scroller__viewport::-webkit-scrollbar-track { background: transparent; }
.scroller__viewport::-webkit-scrollbar-thumb { background: var(--hairline); border-radius: 3px; }
/* inside the scroller, rows shouldn't add the outer negative margin's bottom border twice */
.scroller__viewport .row { margin: 0; }
.scroller__viewport .row:last-child { border-bottom: 0; }

.scroller__fade {
  position: absolute;
  left: 0;
  right: 8px;
  height: 44px;
  pointer-events: none;
  transition: opacity .2s ease;
}
.scroller__fade--top { top: 0; opacity: 0; background: linear-gradient(to top, transparent, var(--paper)); }
.scroller__fade--bottom { bottom: 1px; height: 46px; background: linear-gradient(to bottom, transparent, var(--paper)); }

.section__more { margin: 1.4rem 0 0; font-family: var(--mono); font-size: 0.9375rem; }

/* ---------- Projects page ------------------------------------------------- */
.project { padding: 1.75rem 0; border-top: 1px solid var(--hairline); }
.projects .project:last-child { border-bottom: 1px solid var(--hairline); }
.project__head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}
.project__title {
  font-family: var(--serif);
  font-weight: 500;
  font-size: clamp(1.4rem, 2.4vw, 1.9rem);
  line-height: 1.25;
  letter-spacing: -0.005em;
  margin: 0;
  transition: color .18s ease;
}
.project:hover .project__title { color: var(--accent); }
.project__meta { font-family: var(--mono); font-size: 13px; color: var(--muted); white-space: nowrap; }
.project__body { margin: 0.75rem 0 0; font-size: 16px; line-height: 1.6; max-width: 60ch; }
.project__links { margin-top: 1rem; display: flex; flex-wrap: wrap; gap: 0.5rem 1.4rem; font-family: var(--mono); font-size: 14px; }

/* ---------- Page header (sub pages) --------------------------------------- */
.page-head { margin-bottom: clamp(2.5rem, 7vh, 4rem); }
.page-title {
  font-family: var(--serif);
  font-weight: 500;
  font-size: clamp(2.5rem, 5vw, 3.5rem);
  line-height: 1.05;
  letter-spacing: -0.01em;
  margin: 0;
}
.page-lede { color: var(--muted); font-size: clamp(1.1rem, 1.8vw, 1.3rem); line-height: 1.4; margin: 1rem 0 0; max-width: 48ch; }

.year-group + .year-group { margin-top: 2.25rem; }
.year-group__label { display: block; font-family: var(--mono); font-size: 0.75rem; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); margin-bottom: 1rem; }

/* ---------- Essay reading view -------------------------------------------- */
.wrap--essay { max-width: calc(38rem + var(--indent-l) + var(--indent-r)); }
.essay__meta { font-family: var(--mono); font-size: 0.75rem; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); margin: 0 0 1.1rem; }
.essay__title {
  font-family: var(--serif);
  font-weight: 500;
  font-size: clamp(2.3rem, 4.6vw, 3.4rem);
  line-height: 1.08;
  letter-spacing: -0.01em;
  margin: 0;
  text-wrap: balance;
}
.essay__dek {
  font-family: var(--serif);
  font-weight: 400;
  font-size: clamp(1.25rem, 2.2vw, 1.55rem);
  line-height: 1.4;
  color: var(--muted);
  margin: 1.25rem 0 0;
  max-width: 40ch;
  text-wrap: pretty;
}
.essay__header { margin-bottom: clamp(2.5rem, 6vh, 3.5rem); }

.prose { max-width: 38rem; font-size: 18px; line-height: 1.72; }
.prose p { margin: 0 0 1.4rem; }
.prose h2 { font-family: var(--serif); font-weight: 500; font-size: 1.7rem; line-height: 1.25; letter-spacing: -0.005em; margin: 3rem 0 1.1rem; }
.prose strong { font-weight: 600; }
.prose em { font-style: italic; }
.prose a { color: var(--accent); text-decoration: none; border-bottom: 1px solid color-mix(in srgb, var(--accent) 45%, transparent); transition: border-color .2s ease; }
.prose a:hover { border-bottom-color: var(--accent); }
.prose blockquote {
  margin: 2rem 0;
  padding: 0.25rem 0 0.25rem 1.5rem;
  border-left: 2px solid var(--accent);
  font-family: var(--serif);
  font-size: 1.35rem;
  line-height: 1.45;
  font-style: italic;
  color: var(--ink);
}
.prose pre {
  margin: 1.75rem 0;
  padding: 1.25rem 1.4rem;
  background: color-mix(in srgb, var(--muted) 10%, transparent);
  border: 1px solid var(--hairline);
  border-radius: 5px;
  overflow-x: auto;
}
.prose pre code { font-family: var(--mono); font-size: 14px; line-height: 1.6; color: var(--ink); }

.essay-nav {
  margin-top: clamp(3.5rem, 9vh, 5.5rem);
  padding-top: 1.75rem;
  border-top: 1px solid var(--hairline);
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  font-family: var(--mono);
  font-size: 0.8125rem;
  color: var(--muted);
}

/* ---------- Footer -------------------------------------------------------- */
.site-footer {
  position: relative;
  z-index: 2;
  max-width: calc(var(--col) + var(--indent-l) + var(--indent-r));
  margin-top: clamp(5rem, 14vh, 9rem);
  padding-inline: var(--indent-l) var(--indent-r);
  padding-top: clamp(1.75rem, 4vh, 2.5rem);
  padding-bottom: clamp(3rem, 8vh, 5rem);
  border-top: 1px solid var(--hairline);
  font-family: var(--mono);
  font-size: 0.8125rem;
  color: var(--muted);
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.9rem 1.6rem;
  flex-wrap: wrap;
}
.site-footer__links { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 0.4rem 0.9rem; align-items: baseline; }
.site-footer__sep { color: var(--hairline); }

/* ---------- Small screens ------------------------------------------------- */
@media (max-width: 640px) {
  :root { --indent-l: 1.5rem; --indent-r: 1.5rem; }
  .hero { gap: 1.25rem; }
  .row--work { grid-template-columns: 4.5rem 1fr; column-gap: 14px; }
}
