/* Karthik Subramanian — personal site. Mobile-first. No build step, no authored JS. */
:root {
  --paper: #FBFBF8;
  --ink: #1D2420;
  --muted: #58675E;
  --accent: #1E5945;
  --line: #D8DED8;
  --paper-2: #F2F5F0;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Helvetica, Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Code", Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #121814;
    --ink: #E7ECE7;
    --muted: #9DABA1;
    --accent: #85C2A4;
    --line: #2A342E;
    --paper-2: #171E19;
  }
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  * { transition: none !important; }
}
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--serif);
  font-size: 1.0625rem;
  line-height: 1.65;
}
.wrap { max-width: 58rem; margin-inline: auto; padding-inline: 1.25rem; }
.wrap--wide { max-width: 72rem; }

a { color: var(--accent); text-decoration: underline; text-underline-offset: 3px; text-decoration-thickness: 1px; transition: text-decoration-thickness 120ms; }
a:hover { text-decoration-thickness: 2px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 2px; }

/* Header / nav — mobile: name stacks above a scrollable nav row with 44px targets */
.site-header { position: sticky; top: 0; z-index: 20; background: var(--paper); border-bottom: 1px solid var(--line); padding: 0.35rem 0; }
.site-header .wrap { display: flex; flex-direction: column; align-items: stretch; gap: 0.15rem; }
.site-name { font-family: var(--sans); font-weight: 650; font-size: 0.95rem; letter-spacing: 0.02em; color: var(--ink); text-decoration: none; padding: 0.4rem 0; }
.site-nav { display: flex; gap: 0.15rem; overflow-x: auto; white-space: nowrap; margin-inline: -1.25rem; padding-inline: 1rem; scrollbar-width: none; -webkit-overflow-scrolling: touch; font-family: var(--sans); font-size: 0.85rem; }
.site-nav::-webkit-scrollbar { display: none; }
.site-nav a { color: var(--muted); text-decoration: none; display: inline-flex; align-items: center; min-height: 2.75rem; padding: 0 0.55rem; }
.site-nav a:hover, .site-nav a[aria-current="page"] { color: var(--accent); text-decoration: underline; text-underline-offset: 3px; }
@media (min-width: 46rem) {
  .site-header { padding: 0.6rem 0; }
  .site-header .wrap { flex-direction: row; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 1rem; }
  .site-name { padding: 0; }
  .site-nav { gap: 1.1rem; margin-inline: 0; padding-inline: 0; overflow: visible; }
  .site-nav a { min-height: 0; padding: 0; }
}

/* Hero — photo up top, beside the name */
.hero { padding: 2.5rem 0 2.25rem; border-bottom: 1px solid var(--line); }
.hero h1 { font-size: clamp(1.9rem, 4.2vw, 2.9rem); line-height: 1.15; font-weight: 600; }
.hero p { max-width: 58ch; color: var(--muted); margin: 0; }
.hero p strong { color: var(--ink); font-weight: 600; }
@media (min-width: 46rem) {
  .hero { padding: 4rem 0 3rem; }
}

.eyebrow { font-family: var(--sans); font-size: 0.8rem; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); margin: 0 0 1rem; }

/* Sections */
section { padding: 2.25rem 0; border-bottom: 1px solid var(--line); }
section:last-of-type { border-bottom: none; }
h2 { font-family: var(--sans); font-size: 0.85rem; letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); font-weight: 650; margin: 0 0 1.25rem; }
h3 { font-size: 1.3rem; font-weight: 600; line-height: 1.3; margin: 0 0 0.4rem; }
h3 a { color: var(--ink); text-decoration: none; }
h3 a:hover { color: var(--accent); text-decoration: underline; text-underline-offset: 4px; }
.sec-lede { font-family: var(--sans); font-size: 0.9rem; color: var(--muted); margin: -0.5rem 0 1rem; max-width: 55ch; }
@media (min-width: 46rem) {
  section { padding: 3rem 0; }
  h2 { margin-bottom: 2rem; }
  .sec-lede { margin-top: -1.25rem; }
}

/* Entries — mobile: single column, rail as inline row; desktop: signature margin rail */
.entry { display: grid; grid-template-columns: 1fr; gap: 0.4rem; padding: 1.4rem 0; }
.entry + .entry { border-top: 1px dashed var(--line); }
.rail { text-align: left; display: flex; flex-wrap: wrap; gap: 0.35rem 1rem; align-items: baseline; }
.rail .stat { font-family: var(--mono); font-variant-numeric: tabular-nums; font-size: 1.05rem; font-weight: 600; color: var(--accent); line-height: 1.35; }
.rail .label { font-family: var(--sans); font-size: 0.72rem; letter-spacing: 0.05em; text-transform: uppercase; color: var(--muted); line-height: 1.4; }
.body p { margin: 0.3rem 0 0; color: var(--muted); max-width: 60ch; }
.body p:first-child { margin-top: 0; }
@media (min-width: 46rem) {
  .entry { grid-template-columns: 10.5rem minmax(0, 1fr); gap: 0.5rem 2.5rem; padding: 1.6rem 0; }
  .entry > .rail { display: block; text-align: right; }
  .entry > .rail .stat { display: block; }
  .entry > .rail .label { display: block; margin-top: 0.15rem; }
  .entry > .rail .label-gap { margin-top: 1rem; }
}

/* Prose pages (work stories) */
.prose { max-width: 42rem; }
.prose p, .prose li { color: var(--ink); }
.prose h2 { margin-top: 2.5rem; }
.prose .lede { font-size: 1.2rem; line-height: 1.55; }
.footnote { font-family: var(--sans); font-size: 0.85rem; color: var(--muted); }

.btn { display: inline-block; font-family: var(--sans); font-size: 0.9rem; font-weight: 600; color: var(--paper); background: var(--accent); padding: 0.55rem 1rem; border-radius: 4px; text-decoration: none; }
.btn:hover { text-decoration: none; opacity: 0.92; }

/* Footer — mobile: stacked; desktop: 3 columns */
.site-footer { border-top: 1px solid var(--line); margin-top: 1rem; padding: 2.25rem 0 3rem; font-family: var(--sans); font-size: 0.8rem; color: var(--muted); }
.foot-grid { display: grid; grid-template-columns: 1fr; gap: 1.25rem; }
.foot-h { font-family: var(--sans); font-size: 0.7rem; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); margin: 0 0 0.35rem; font-weight: 650; }
.site-footer p { margin: 0.2rem 0; line-height: 1.7; }
.site-footer a { display: inline-block; padding-block: 0.35rem; }
@media (min-width: 46rem) {
  .foot-grid { grid-template-columns: 1fr 1.1fr 1.3fr; gap: 2rem; }
  .site-footer a { padding-block: 0; }
}

/* Writing archive — full-height tap rows; 2 columns on desktop */
.archive { display: grid; grid-template-columns: 1fr; margin-top: 0.75rem; }
.archive p { margin: 0; padding: 0; border-bottom: 1px dashed var(--line); font-size: 0.92rem; display: flex; gap: 0.7rem; align-items: baseline; }
.archive a { flex: 1; padding-block: 0.7rem; }
.archive .yr { font-family: var(--mono); font-size: 0.78rem; color: var(--muted); flex: none; min-width: 4.4rem; align-self: center; }
@media (min-width: 46rem) {
  .archive { grid-template-columns: 1fr 1fr; gap: 0 2.5rem; }
}

/* Napkin diagrams */
figure.diagram { margin: 2rem 0 2.25rem; }
figure.diagram svg { width: 100%; height: auto; display: block; }
figure.diagram figcaption { font-family: var(--mono); font-size: 0.74rem; color: var(--muted); margin-top: 0.6rem; }

/* Sub-links — tappable chips */
.sub-links { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-top: 0.6rem; font-family: var(--mono); font-size: 0.82rem; }
.sub-links a { display: inline-flex; align-items: center; min-height: 2.75rem; padding: 0 0.8rem; border: 1px solid var(--line); border-radius: 999px; text-decoration: none; }
.sub-links a:hover { border-color: var(--accent); text-decoration: underline; text-underline-offset: 3px; }
@media (min-width: 46rem) { .sub-links a { min-height: 2.1rem; } }

/* Snap carousel → card grid. Markup: <div class="snap"><article class="entry card">…</article>×N</div> */
.snap {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: min(84%, 22rem);
  gap: 0.75rem;
  margin-inline: -1.25rem;
  padding-inline: 1.25rem;
  padding-block: 0.25rem 0.75rem;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  scroll-padding-inline: 1.25rem;
  overscroll-behavior-x: contain;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.snap::-webkit-scrollbar { display: none; }
.snap > .card { scroll-snap-align: start; }
.card { border: 1px solid var(--line); border-radius: 8px; padding: 1.05rem 1.15rem 1.2rem; background: var(--paper); }
.snap > .entry + .entry { border-top: 1px solid var(--line); }
.card > .rail, .entry.card > .rail { display: flex; text-align: left; flex-wrap: wrap; gap: 0.35rem 1rem; align-items: baseline; margin-bottom: 0.35rem; }
.card > .rail .stat { display: inline; font-size: 0.9rem; }
.card > .rail .label { display: inline; margin-top: 0; }
.card > .rail .label-gap { margin-top: 0; }
.card .body { display: flex; flex-direction: column; height: 100%; }
.card .body h3 { font-size: 1.15rem; }
.card .body p { font-size: 0.95rem; max-width: none; }
.card .sub-links { margin-top: auto; padding-top: 0.65rem; }
@media (min-width: 46rem) {
  .snap { grid-auto-flow: row; grid-auto-columns: unset; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1.1rem; margin-inline: 0; padding-inline: 0; overflow: visible; scroll-snap-type: none; }
  .entry.card { grid-template-columns: 1fr; padding: 1.05rem 1.15rem 1.2rem; }
}
@media (min-width: 64rem) {
  .snap { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

/* In-page video: lite YouTube facade (no authored JS; nothing loads until play) */
.yt-facade { display: block; width: 100%; aspect-ratio: 16 / 9; border: 1px solid var(--line); border-radius: 4px; background: #000; }
.video-carousel {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: min(85%, 24rem);
  gap: 1.25rem;
  margin-inline: -1.25rem;
  padding-inline: 1.25rem;
  padding-block: 0.25rem 0.75rem;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  scroll-padding-inline: 1.25rem;
  overscroll-behavior-x: contain;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  margin-top: 0.75rem;
}
.video-carousel::-webkit-scrollbar { display: none; }
.video-carousel > figure { margin: 0; scroll-snap-align: start; }
.video-carousel figcaption { margin-top: 0.55rem; font-size: 0.92rem; display: flex; gap: 0.7rem; align-items: baseline; font-family: var(--sans); }
.video-carousel .yr { font-family: var(--mono); font-size: 0.78rem; color: var(--muted); flex: none; }
@media (min-width: 46rem) {
  .video-carousel { grid-auto-flow: row; grid-auto-columns: unset; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1.5rem; margin-inline: 0; padding-inline: 0; overflow: visible; scroll-snap-type: none; }
}

/* Work-story pager */
.pager { display: grid; grid-template-columns: 1fr 1fr; gap: 2rem; border-top: 1px solid var(--line); margin-top: 2.5rem; padding-top: 1.25rem; }
.pager .label { display: block; font-family: var(--sans); font-size: 0.72rem; letter-spacing: 0.05em; text-transform: uppercase; color: var(--muted); }
.pager a { text-decoration: none; }
.pager a:hover { text-decoration: underline; text-underline-offset: 3px; }
.pager .next { text-align: right; }

/* About: plate-framed photo beside prose */
.about-grid { display: grid; grid-template-columns: 1fr; gap: 1.5rem; align-items: start; }
.about-grid img { width: 9rem; height: auto; border-radius: 4px; border: 1px solid var(--line); padding: 4px; background: var(--paper); }
@media (min-width: 46rem) {
  .about-grid { grid-template-columns: 11rem minmax(0, 1fr); gap: 2rem; }
  .about-grid img { width: 100%; }
}

/* Exhibit: the museum plate under the hero */
#play { padding: 2rem 0; }
.exhibit { margin: 0; }
.exhibit a { display: block; }
.exhibit img { width: 100%; height: auto; display: block; border-radius: 6px; border: 1px solid var(--line); padding: 4px; background: var(--paper); box-sizing: border-box; transition: transform 200ms ease; }
.exhibit a:hover img { transform: scale(1.005); }
@media (prefers-reduced-motion: reduce) { .exhibit a:hover img { transform: none; } }
.exhibit figcaption { margin-top: 0.9rem; }
.exhibit figcaption .label { font-family: var(--sans); font-size: 0.72rem; letter-spacing: 0.05em; text-transform: uppercase; color: var(--muted); }
.exhibit figcaption p { margin: 0.35rem 0 0; color: var(--muted); max-width: 62ch; }
@media (min-width: 46rem) {
  .exhibit figcaption { display: grid; grid-template-columns: 12rem minmax(0, 1fr); gap: 2.5rem; align-items: start; margin-top: 1rem; }
  .exhibit figcaption .label { text-align: right; padding-top: 0.3rem; }
  .exhibit figcaption p:first-of-type { margin-top: 0; }
  .exhibit figcaption .sub-links { grid-column: 2; }
  .exhibit .sub-links a { white-space: nowrap; }
}

/* Alternating section tint so sections read as bands */
main > section:nth-of-type(even) { background: var(--paper-2); }

/* Back-to-top: appears after scrolling (CSS scroll-driven animation, no JS) */
.to-top { position: fixed; right: 1rem; bottom: 1rem; z-index: 20; display: grid; place-items: center; width: 2.75rem; height: 2.75rem; border-radius: 50%; border: 1px solid var(--line); background: var(--paper); color: var(--accent); text-decoration: none; font-family: var(--sans); font-size: 1.15rem; visibility: hidden; }
.to-top:hover { border-color: var(--accent); }
@supports (animation-timeline: scroll()) {
  .to-top { visibility: visible; opacity: 0; animation: totop-fade linear both; animation-timeline: scroll(); animation-range: 200px 600px; }
}
@keyframes totop-fade { from { opacity: 0; visibility: hidden; } to { opacity: 1; visibility: visible; } }
@media (prefers-reduced-motion: reduce) { .to-top { animation: none; opacity: 1; visibility: visible; } }
