/* ---------------------------------------------------------------------
   Shared design system for riyarathore's research/writing site.
   Every article under /articles links this file directly: nothing here
   should assume article-specific markup beyond the shared template
   (site-head / wrap / site-foot) and the small set of reusable classes
   below (.viz, .controls, .note, .lead, .byline, ...). Page-local <style>
   blocks in individual articles are for that article's own visualization
   only (canvas rigs, 3D scenes, tables) and intentionally don't live here.
   --------------------------------------------------------------------- */

/* The whole site sits on black: light text on a pure-black ground, in both
   system themes (the site no longer flips to a light palette). */
:root {
  --bg:          #000000;
  --bg-soft:     #121110;
  --fg:          #e8e3d8;
  --fg-soft:     #b7b1a3;
  --fg-faint:    #7c766a;
  --rule:        #2a2823;
  --accent:      #8fb4ff;
  --accent-soft: #263452;
  --link:        #8fb4ff;

  --canvas-bg:   #0d0c0a;
  --canvas-ink:  #e8e3d8;
  --canvas-grid: #2a2823;

  --font-serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, "Times New Roman", serif;
  --font-sans:  -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  --font-mono:  "SF Mono", ui-monospace, Menlo, Consolas, "Liberation Mono", monospace;

  --max-prose: 42rem;
  --max-wide:  56rem;
}

* { box-sizing: border-box; }

html { color-scheme: dark; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-serif);
  font-size: 1.08rem;
  line-height: 1.65;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}

.wrap {
  max-width: var(--max-prose);
  margin: 0 auto;
  padding: 0 1.4rem 5rem;
}

/* ---------------------------------------------------------------- head */

.site-head {
  max-width: var(--max-prose);
  margin: 0 auto;
  padding: 2.2rem 1.4rem 1.4rem;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  font-family: var(--font-sans);
}

.site-head .brand {
  font-family: var(--font-serif);
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--fg);
  text-decoration: none;
  letter-spacing: 0.01em;
}
.site-head .brand:hover { color: var(--accent); }

.site-nav {
  display: flex;
  gap: 1.2rem;
  font-size: 0.86rem;
}
.site-nav a {
  color: var(--fg-soft);
  text-decoration: none;
  border-bottom: 1px solid transparent;
}
.site-nav a:hover { color: var(--fg); border-bottom-color: var(--rule); }

/* -------------------------------------------------------------- prose */

h1, h2, h3 {
  font-family: var(--font-serif);
  font-weight: 700;
  line-height: 1.25;
  color: var(--fg);
}
h1 { font-size: 1.9rem; margin: 0.4rem 0 0.9rem; letter-spacing: -0.01em; }
h2 { font-size: 1.3rem; margin: 2.4rem 0 0.9rem; }
h3 { font-size: 1.08rem; margin: 1.8rem 0 0.7rem; }

p { margin: 0 0 1.1rem; }

a { color: var(--link); text-decoration-color: var(--rule); }
a:hover { text-decoration-color: currentColor; }

em { color: var(--fg); }
strong { font-weight: 700; }

code, pre, kbd {
  font-family: var(--font-mono);
  font-size: 0.86em;
}
code {
  background: var(--bg-soft);
  padding: 0.1em 0.35em;
  border-radius: 3px;
}
pre {
  background: var(--bg-soft);
  border: 1px solid var(--rule);
  border-radius: 6px;
  padding: 1rem 1.1rem;
  overflow-x: auto;
  line-height: 1.55;
}
pre code { background: none; padding: 0; }

blockquote {
  margin: 1.2rem 0;
  padding-left: 1rem;
  border-left: 2px solid var(--rule);
  color: var(--fg-soft);
}

hr { border: none; border-top: 1px solid var(--rule); margin: 2.6rem 0; }

/* KaTeX display math can overflow narrow viewports; let it scroll rather
   than break layout. */
.katex-display { overflow-x: auto; overflow-y: hidden; padding: 0.2rem 0; }

/* --------------------------------------------------------- article meta */

.backlink {
  font-family: var(--font-sans);
  font-size: 0.86rem;
  margin: 0 0 1.6rem;
}
.backlink a { color: var(--fg-soft); }

.byline {
  font-family: var(--font-sans);
  font-size: 0.86rem;
  color: var(--fg-faint);
  margin: 0 0 1.8rem;
}
.byline .dot { margin: 0 0.5em; opacity: 0.6; }

.lead {
  font-size: 1.18rem;
  color: var(--fg-soft);
  margin-bottom: 1.8rem;
}

.contact {
  font-family: var(--font-sans);
  font-size: 0.9rem;
  color: var(--fg-faint);
  margin-bottom: 1.8rem;
}

.fine {
  font-family: var(--font-sans);
  font-size: 0.78rem;
  color: var(--fg-faint);
  margin-top: 2.2rem;
}

.tag {
  display: inline-block;
  font-family: var(--font-sans);
  font-size: 0.7rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--fg-soft);
  background: var(--bg-soft);
  border: 1px solid var(--rule);
  border-radius: 999px;
  padding: 0.2em 0.75em;
}

.sep { color: var(--fg-faint); margin: 0 0.4em; }

/* -------------------------------------------------------------- note box */

.note {
  font-family: var(--font-sans);
  font-size: 0.94rem;
  background: var(--bg-soft);
  border: 1px solid var(--rule);
  border-radius: 8px;
  padding: 1.1rem 1.3rem;
  margin: 1.6rem 0;
  color: var(--fg-soft);
}
.note p:last-child { margin-bottom: 0; }
.note .label {
  display: block;
  font-size: 0.72rem;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 0.4em;
  font-weight: 620;
}

/* ------------------------------------------------------- visualizations */

.viz-fig {
  margin: 1.8rem 0;
  max-width: 100%;
}
/* .wide figures are allowed to break out of the prose column, up to the
   wider max-width, on viewports that have the room for it. */
.viz-fig.wide {
  margin-left: calc((var(--max-prose) - var(--max-wide)) / 2);
  width: var(--max-wide);
  max-width: var(--max-wide);
}
@media (max-width: 60rem) {
  .viz-fig.wide { margin-left: 0; width: 100%; max-width: 100%; }
}

.viz {
  background: var(--canvas-bg);
  border: 1px solid var(--rule);
  border-radius: 8px;
  padding: 0.6rem;
  overflow: hidden;
}
.viz canvas { display: block; width: 100%; height: auto; }

figcaption {
  font-family: var(--font-sans);
  font-size: 0.82rem;
  color: var(--fg-faint);
  margin-top: 0.6rem;
  line-height: 1.5;
}

.controls {
  font-family: var(--font-sans);
  font-size: 0.86rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.9rem;
  margin-top: 0.7rem;
  color: var(--fg-soft);
}
.controls label {
  display: inline-flex;
  align-items: center;
  gap: 0.5em;
}
.controls input[type="range"] {
  accent-color: var(--accent);
  width: 8.5rem;
  vertical-align: middle;
}
.controls .val {
  font-family: var(--font-mono);
  font-size: 0.82rem;
  color: var(--fg);
  min-width: 2.4em;
  display: inline-block;
}
.controls button {
  font-family: var(--font-sans);
  font-size: 0.82rem;
  background: var(--bg-soft);
  color: var(--fg);
  border: 1px solid var(--rule);
  border-radius: 5px;
  padding: 0.35em 0.9em;
  cursor: pointer;
}
.controls button:hover { border-color: var(--fg-faint); }
.controls button:active { background: var(--rule); }

/* generic fallbacks for legend/readout/swatch. Individual articles may
   still define their own richer versions in a page-local <style> block */
.legend {
  font-family: var(--font-sans);
  font-size: 0.82rem;
  color: var(--fg-soft);
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  margin: 0.6rem 0 0;
}
.legend .swatch {
  display: inline-block;
  width: 0.7em;
  height: 0.7em;
  border-radius: 50%;
  margin-right: 0.45em;
  vertical-align: -0.05em;
  background: var(--fg-faint);
}
.readout {
  font-family: var(--font-mono);
  font-size: 0.85rem;
  color: var(--fg-soft);
  margin-top: 0.5rem;
}
.readout b { color: var(--fg); }

/* ---------------------------------------------------------------- foot */

.site-foot {
  max-width: var(--max-prose);
  margin: 0 auto;
  padding: 2.4rem 1.4rem 3.5rem;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 0.6rem;
  font-family: var(--font-sans);
  font-size: 0.8rem;
  color: var(--fg-faint);
  border-top: 1px solid var(--rule);
}
.site-foot a { color: var(--fg-faint); }
.site-foot a:hover { color: var(--fg-soft); }

/* --------------------------------------------------------------- home */

.post-list { margin: 0; padding: 0; list-style: none; }
.post-list li {
  display: flex;
  flex-direction: column;
  padding: 1.8rem 0;
  border-bottom: 1px solid var(--rule);
}
.post-list li:first-child { padding-top: 0; }
/* the live preview: an interactive embed sitting in a fixed-ratio frame */
.post-thumb {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  margin-bottom: 1rem;
  border: 1px solid var(--rule);
  border-radius: 10px;
  overflow: hidden;
  background: var(--bg-soft);
  box-shadow: 0 6px 22px rgba(0, 0, 0, 0.06);
  transition: box-shadow 0.2s ease, border-color 0.2s ease;
}
.post-list li:hover .post-thumb {
  border-color: var(--accent);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.12);
}
.post-thumb iframe,
.post-thumb video {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  border: 0; display: block;
  object-fit: cover;
}
.post-list a.post-title {
  font-family: var(--font-serif);
  font-size: 1.18rem;
  font-weight: 700;
  color: var(--fg);
  text-decoration: none;
}
.post-list a.post-title:hover { color: var(--accent); }
.post-list .post-dek {
  margin: 0.4rem 0 0.5rem;
  color: var(--fg-soft);
  font-size: 0.98rem;
}
.post-list .post-meta {
  font-family: var(--font-sans);
  font-size: 0.78rem;
  color: var(--fg-faint);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-top: auto;
}

.section-label {
  font-family: var(--font-sans);
  font-size: 0.76rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--fg-faint);
  margin: 2.6rem 0 0.8rem;
}
.section-label:first-of-type { margin-top: 0; }

/* -------------------------------------------------------------- motion */

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.001ms !important; animation-iteration-count: 1 !important; }
}

@media (max-width: 30rem) {
  h1 { font-size: 1.6rem; }
  body { font-size: 1.02rem; }
}
