/* ==========================================================================
   Santhosh Suresh — personal site · v1
   Design tokens: see the project brief (§3).
   Fonts: Space Mono (headings), Schibsted Grotesk (body), JetBrains Mono (labels/code)
   Colors: Paper & Ink + Signal Orange · light/dark follow the visitor's system setting
   ========================================================================== */

/* Light theme (default) */
:root, :root[data-theme="light"] {
  --bg: #F3F0E8;
  --surface: #FBF9F4;
  --text: #161512;
  --muted: #4E4A42;
  --line: #D0C8B6;
  --accent: #A33508;
  --on-accent: #FFFFFF;
  --accent-2: #2B48D6;
  /* tonal section layers: paper getting slightly deeper */
  --tone-1: #F5F2EA;
  --tone-2: #EAE5D8;
  --tone-3: #DED7C6;
  --tone-4: #D1C9B5;
  --tone-5: #C6BDA6;
  --glow: rgba(255, 255, 255, .6);
  --shadow: 0 1px 0 rgba(22,21,18,.04), 0 14px 34px -18px rgba(22,21,18,.28);

  --font-head: "Space Mono", ui-monospace, Menlo, monospace;
  --font-body: "Schibsted Grotesk", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, Menlo, Consolas, monospace;

  --radius: 14px;
  --radius-sm: 8px;
  --max: 1200px;
  --read: 700px;
  --pad: clamp(20px, 5vw, 64px);
  --ease: cubic-bezier(.2, .8, .2, 1);
  color-scheme: light;
}

/* Dark theme: chosen with the switch, or from the device when JS is off */
:root[data-theme="dark"] {
  --bg: #141412;
  --surface: #1E1D1A;
  --text: #EDE9DF;
  --muted: #ADA89B;
  --line: #3A3833;
  --accent: #FF7A45;
  --on-accent: #141412;
  --accent-2: #8EA2FF;
  --tone-1: #121210;
  --tone-2: #1B1A17;
  --tone-3: #25231F;
  --tone-4: #2F2D28;
  --tone-5: #383530;
  --glow: rgba(255, 255, 255, .045);
  --shadow: 0 1px 0 rgba(0,0,0,.3), 0 18px 40px -20px rgba(0,0,0,.8);
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --bg: #121210; --surface: #1E1D1A; --text: #EDE9DF; --muted: #ADA89B; --line: #3A3833;
    --accent: #FF7A45; --on-accent: #141412; --accent-2: #8EA2FF;
    --tone-1: #121210; --tone-2: #1B1A17; --tone-3: #25231F; --tone-4: #2F2D28; --tone-5: #383530; --glow: rgba(255,255,255,.045);
    color-scheme: dark;
  }
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body {
  margin: 0;
  background: var(--tone-1);
  color: var(--text);
  font: 400 18px/1.65 var(--font-body);
  transition: background-color .4s var(--ease), color .4s var(--ease);
  -webkit-font-smoothing: antialiased;
}
img, svg { max-width: 100%; display: block; }
a { color: var(--accent); text-underline-offset: 3px; text-decoration-thickness: 1.5px; }
a:hover { text-decoration-thickness: 2.5px; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; border-radius: 4px; }
::selection { background: var(--accent); color: var(--on-accent); }

h1, h2, h3 { font-family: var(--font-head); font-weight: 700; letter-spacing: -0.04em; line-height: 1.08; margin: 0; }
h2 { font-size: clamp(26px, 3.2vw, 34px); }
h3 { font-size: 21px; letter-spacing: -0.03em; }
p { margin: 0; }

.label {
  font: 500 12px/1.3 var(--font-mono);
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--muted);
}
.mono { font-family: var(--font-mono); }
.muted { color: var(--muted); }

.skip {
  position: absolute; left: -9999px; top: 0;
  background: var(--accent); color: var(--on-accent); padding: 12px 18px; z-index: 100;
}
.skip:focus { left: 12px; top: 12px; }

.wrap { max-width: var(--max); margin: 0 auto; padding: 0 var(--pad); }

/* ---------- Header ---------- */
.site-header { border-bottom: 1px solid var(--line); }
.site-header .wrap {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px 56px; flex-wrap: wrap; padding-top: 18px; padding-bottom: 18px;
}
.brand { display: flex; align-items: center; gap: 12px; text-decoration: none; color: var(--text); }
.avatar {
  width: 44px; height: 44px; border-radius: 50%; flex: none;
  display: grid; place-items: center;
  background: var(--text); color: var(--bg);
  font: 700 15px/1 var(--font-head); letter-spacing: -0.04em;
}
.brand { min-height: 44px; }
.brand-name { display: block; font-weight: 600; font-size: 17px; line-height: 1.2; letter-spacing: -0.01em; }
.brand-role { display: block; font-size: 14px; color: var(--muted); line-height: 1.3; }

.nav { display: flex; gap: 6px 26px; flex-wrap: wrap; font-size: 15px; }
.nav a, .nav span { display: inline-flex; align-items: center; gap: 6px; min-height: 44px; text-decoration: none; color: var(--text); }
.nav a:hover { color: var(--accent); }
.nav i { font: normal 500 11px var(--font-mono); color: var(--muted); }
.nav [aria-current="page"] { box-shadow: inset 0 -2px 0 var(--accent); }
.nav .soon { color: var(--muted); cursor: default; }
.nav .soon small { font: 500 10px var(--font-mono); letter-spacing: .08em; text-transform: uppercase; border: 1px solid var(--line); border-radius: 999px; padding: 1px 6px; }

/* ---------- Buttons & chips ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 0 22px; border-radius: 999px;
  font: 600 16px/1 var(--font-body); text-decoration: none; cursor: pointer;
  border: 1.5px solid var(--text); color: var(--text); background: transparent;
  transition: transform .15s ease, background .15s ease;
}
.btn:hover { transform: translateY(-1px); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.depth { font: 500 12px/1.4 var(--font-mono); color: var(--text); letter-spacing: .02em; }
.tag { display: inline-flex; align-items: center; gap: 8px; }
.tag::before { content: ""; width: 9px; height: 9px; border-radius: 50%; background: var(--accent); }

/* ---------- Home ---------- */
.hero { padding: clamp(56px, 10vw, 140px) 0 clamp(88px, 10vw, 140px); }
.hero-grid { display: grid; grid-template-columns: minmax(0, 7fr) minmax(0, 5fr); gap: 32px 56px; align-items: end; }
.hero h1 { font-size: clamp(44px, 7.4vw, 100px); line-height: 1.0; margin-top: 18px; }
.hero h1 em { font-style: normal; color: var(--accent); }
.hero p { font-size: 19px; color: var(--muted); }
.hero .actions { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 24px; }

.section { padding: clamp(88px, 10vw, 140px) 0 clamp(96px, 11vw, 150px); }
.section-head { display: flex; justify-content: space-between; align-items: baseline; gap: 16px; margin-bottom: 40px; flex-wrap: wrap; }

.feature {
  display: grid; grid-template-columns: minmax(0, 5fr) minmax(0, 6fr); gap: 0;
  border: 1px solid var(--line); border-radius: 20px; overflow: hidden;
  background: var(--surface); text-decoration: none; color: var(--text);
  transition: border-color .2s ease;
}
.feature:hover { border-color: var(--accent); }
.feature-art { background: var(--bg); border-right: 1px solid var(--line); padding: 24px; display: grid; place-items: center; min-height: 280px; }
.feature-body { padding: clamp(24px, 3.5vw, 44px); display: flex; flex-direction: column; gap: 14px; }
.feature-body h3 { font-size: clamp(24px, 2.8vw, 34px); line-height: 1.12; }
.feature-body .cta { margin-top: auto; font-weight: 600; color: var(--accent); }

.cards { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 28px; margin-top: 36px; }
.card {
  border: 1px solid var(--line); border-radius: var(--radius); padding: 22px;
  display: flex; flex-direction: column; gap: 10px; background: var(--surface);
}
.card.ghost { background: transparent; border-style: dashed; }
.card h3 { font-size: 20px; line-height: 1.2; }

.about-strip { display: grid; grid-template-columns: minmax(0, 4fr) minmax(0, 7fr); gap: 32px 56px; }
.about-strip .links { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 20px; }
.ph { background: color-mix(in srgb, var(--accent) 12%, transparent); border-radius: 4px; padding: 0 4px; }

.site-footer { padding: 36px 0 44px; font-size: 14px; color: var(--muted); }
.site-footer .wrap { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; }

/* ---------- Article ---------- */
.progress { position: fixed; top: 0; left: 0; height: 4px; width: 0; background: var(--accent); z-index: 50; }
.article-head { padding: clamp(40px, 7vw, 88px) 0 32px; }
.article-head .inner { max-width: 900px; }
.article-head h1 { font-size: clamp(34px, 5.2vw, 62px); line-height: 1.04; margin: 16px 0 18px; }
.meta { display: flex; gap: 10px 18px; flex-wrap: wrap; align-items: center; }

.article-layout { display: grid; grid-template-columns: 210px minmax(0, var(--read)); gap: 56px; justify-content: start; padding-bottom: 80px; }
.toc { position: sticky; top: 104px; align-self: start; display: flex; flex-direction: column; gap: 2px; }
.toc a { display: flex; gap: 10px; align-items: center; min-height: 40px; text-decoration: none; color: var(--muted); font-size: 15px; }
.toc a b { font: 500 11px var(--font-mono); width: 26px; height: 26px; border: 1.5px solid var(--line); border-radius: 50%; display: grid; place-items: center; flex: none; }
.toc a.active { color: var(--text); font-weight: 600; }
.toc a.active b { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }

.prose { display: flex; flex-direction: column; gap: 22px; min-width: 0; }
.prose h2 { margin-top: 30px; scroll-margin-top: 80px; }
.prose ul, .prose ol { margin: 0; padding-left: 22px; display: flex; flex-direction: column; gap: 10px; }
.prose li::marker { color: var(--accent); }
.prose .lead { font-size: 21px; line-height: 1.55; }
.stage { display: block; margin-bottom: -10px; }

.tldr { border: 2px solid var(--text); border-radius: var(--radius); padding: 22px 24px; display: flex; flex-direction: column; gap: 10px; }
.tldr .label { color: var(--accent); }

.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); }
table { border-collapse: collapse; width: 100%; font-size: 16px; }
th, td { text-align: left; padding: 12px 16px; border-bottom: 1px solid var(--line); vertical-align: top; }
tr:last-child td { border-bottom: none; }
th { font: 500 12px var(--font-mono); letter-spacing: .08em; text-transform: uppercase; color: var(--muted); background: var(--surface); }

.eq {
  font: 500 clamp(16px, 2.3vw, 21px)/1.6 var(--font-mono);
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px 22px; overflow-x: auto; white-space: nowrap;
}
.eq sub { font-size: .7em; }
.frac { display: inline-flex; flex-direction: column; vertical-align: middle; text-align: center; margin: 0 2px; }
.frac > span:first-child { border-bottom: 1.5px solid currentColor; padding: 0 4px; }
.frac > span { line-height: 1.3; }

details.math { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
details.math summary { min-height: 52px; padding: 0 20px; display: flex; align-items: center; gap: 10px; cursor: pointer; font-weight: 600; list-style: none; }
details.math summary::-webkit-details-marker { display: none; }
details.math summary::before { content: "+"; font: 700 18px var(--font-mono); color: var(--accent); width: 18px; }
details.math[open] summary::before { content: "−"; }
details.math .body { padding: 0 20px 20px; display: flex; flex-direction: column; gap: 14px; }

figure { margin: 0; }
figcaption { font-size: 14px; color: var(--muted); margin-top: 10px; }
.diagram { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.diagram svg text { font-family: var(--font-mono); }

/* Interactive R-X lab */
.lab { background: var(--surface); border: 1px solid var(--line); border-radius: 20px; padding: clamp(16px, 2.5vw, 28px); display: flex; flex-direction: column; gap: 18px; }
.lab-grid { display: grid; grid-template-columns: minmax(0, 1fr); gap: 18px; }
.lab svg { width: 100%; height: auto; background: var(--bg); border-radius: var(--radius-sm); border: 1px solid var(--line); touch-action: none; }
.lab svg text { font-family: var(--font-mono); }
.controls { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 18px; }
.control { display: flex; flex-direction: column; gap: 6px; }
.control label { font-size: 14px; font-weight: 600; display: flex; justify-content: space-between; gap: 8px; }
.control output { font: 500 14px var(--font-mono); color: var(--accent); white-space: nowrap; }
input[type="range"] { width: 100%; accent-color: var(--accent); min-height: 32px; }
.readout { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.readout div { border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 12px 14px; display: flex; flex-direction: column; gap: 4px; }
.readout b { font: 700 20px var(--font-mono); letter-spacing: -0.02em; }
.verdict { font: 700 15px var(--font-mono); padding: 12px 16px; border-radius: var(--radius-sm); border: 2px solid var(--text); }
.verdict.miss { border-color: var(--accent); color: var(--accent); }
.presets { display: flex; gap: 8px; flex-wrap: wrap; }
.chip { min-height: 40px; padding: 0 14px; border-radius: 999px; border: 1.5px solid var(--line); background: transparent; color: var(--text); font: 500 14px var(--font-body); cursor: pointer; }
.chip:hover { border-color: var(--text); }

/* Quiz */
.quiz { border: 1.5px solid var(--line); border-radius: var(--radius); padding: 22px 24px; display: flex; flex-direction: column; gap: 14px; }
.quiz .q { font-weight: 600; font-size: 18px; }
.quiz .opts { display: flex; flex-direction: column; gap: 8px; }
.quiz button.opt { text-align: left; min-height: 48px; padding: 10px 16px; border-radius: 10px; border: 1.5px solid var(--line); background: transparent; color: var(--text); font: 400 16px/1.4 var(--font-body); cursor: pointer; }
.quiz button.opt:hover { border-color: var(--text); }
.quiz button.opt[aria-pressed="true"].right { border-color: var(--text); background: var(--text); color: var(--bg); }
.quiz button.opt[aria-pressed="true"].wrong { border-color: var(--accent); }
.quiz .fb { font-size: 16px; min-height: 1.6em; }

.sources { font-size: 15px; }
.next-up { border-top: 1px solid var(--line); padding-top: 28px; display: flex; flex-direction: column; gap: 10px; }

/* ---------- Responsive ---------- */
@media (max-width: 960px) {
  .hero-grid, .about-strip, .feature { grid-template-columns: minmax(0, 1fr); }
  .feature-art { border-right: none; border-bottom: 1px solid var(--line); min-height: 220px; }
  .cards { grid-template-columns: minmax(0, 1fr); }
  .article-layout { grid-template-columns: minmax(0, 1fr); gap: 0; }
  .toc {
    position: sticky; top: 0; z-index: 20; flex-direction: row; overflow-x: auto; gap: 6px;
    background: var(--bg); border-bottom: 1px solid var(--line); margin: 0 calc(var(--pad) * -1) 24px; padding: 8px var(--pad);
  }
  .toc .label { display: none; }
  .toc a { white-space: nowrap; flex: none; padding-right: 8px; }
  .controls, .readout { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 560px) {
  body { font-size: 17px; }
  .prose .lead { font-size: 19px; }
  .brand-role { display: none; }
}

/* ==========================================================================
   v1.1 — tonal layers, theme switch, reveals, playful hovers
   ========================================================================== */

/* Tonal layers: each section is a sheet of slightly deeper paper/ink,
   overlapping the one above with rounded top corners. */
.layer {
  position: relative;
  border-radius: 32px 32px 0 0;
  margin-top: -32px;
  box-shadow: 0 -1px 0 var(--line), 0 -18px 40px -30px rgba(0,0,0,.35);
  transition: background-color .4s var(--ease);
}
.layer-1 { background: radial-gradient(90% 70% at 15% 0%, var(--glow), transparent 60%), linear-gradient(180deg, var(--tone-1) 10%, var(--tone-2)); }
.layer-2 { background: radial-gradient(80% 60% at 85% 0%, var(--glow), transparent 60%), linear-gradient(180deg, var(--tone-2), var(--tone-3)); }
.layer-3 { background: radial-gradient(80% 60% at 15% 0%, var(--glow), transparent 60%), linear-gradient(180deg, var(--tone-3), var(--tone-4)); }
.layer-4 { background: linear-gradient(180deg, var(--tone-4), var(--tone-5)); }
.layer-top { margin-top: 0; border-radius: 0; box-shadow: none; }
.layer .card, .layer .feature { box-shadow: var(--shadow); }
.layer-3 .btn:not(.btn-primary) { background: color-mix(in srgb, var(--tone-1) 55%, transparent); }
.section-num {
  font: 700 clamp(44px, 6vw, 84px)/0.8 var(--font-head); letter-spacing: -0.06em;
  color: transparent; -webkit-text-stroke: 1.5px var(--line);
  position: absolute; right: var(--pad); top: 18px; pointer-events: none; user-select: none;
}

/* Header becomes a glassy bar that stays on top */
.site-header {
  position: relative; z-index: 40;
  background: color-mix(in srgb, var(--tone-1) 82%, transparent);
  -webkit-backdrop-filter: saturate(140%) blur(12px); backdrop-filter: saturate(140%) blur(12px);
}
@media (min-width: 961px) { .site-header { position: sticky; top: 0; } }
.header-right { display: flex; flex: 1; align-items: center; justify-content: space-between; gap: 12px 28px; flex-wrap: wrap; }
.header-right .theme-switch { margin-left: auto; }

/* Light / Dark pill switch */
.theme-switch {
  position: relative; display: inline-grid; grid-template-columns: 1fr 1fr; align-items: center;
  min-height: 40px; padding: 3px; border-radius: 999px; cursor: pointer;
  border: 1.5px solid var(--text); background: transparent; color: var(--text);
  font: 500 12px/1 var(--font-mono); letter-spacing: .06em; text-transform: uppercase;
}
.theme-switch span { position: relative; z-index: 1; padding: 10px 14px; display: inline-flex; align-items: center; gap: 6px; transition: color .35s var(--ease); }
.theme-switch svg { width: 14px; height: 14px; }
.theme-switch::before {
  content: ""; position: absolute; top: 3px; bottom: 3px; left: 3px; width: calc(50% - 3px);
  border-radius: 999px; background: var(--text); transition: transform .45s var(--ease);
}
.theme-switch[aria-checked="true"]::before { transform: translateX(100%); }
.theme-switch[aria-checked="false"] .t-light, .theme-switch[aria-checked="true"] .t-dark { color: var(--tone-1); }
.theme-switch:hover::before { filter: brightness(1.15); }

/* Circular wipe when switching theme (browsers with View Transitions) */
::view-transition-old(root), ::view-transition-new(root) { animation: none; mix-blend-mode: normal; }
::view-transition-new(root) { z-index: 2; }

/* Scroll reveals: only hidden when JS is running */
.js [data-reveal] { opacity: 0; transform: translateY(56px) scale(.97); filter: blur(6px); transition: opacity 1s var(--ease), transform 1.1s var(--ease), filter 1s var(--ease); transition-delay: calc(var(--d, 0) * 120ms); }
.js [data-reveal].in { opacity: 1; transform: none; filter: none; }
/* Each new section sheet slides up over the one before it */
.js .layer:not(.layer-top) { transform: translateY(90px); transition: transform 1.2s var(--ease), background-color .4s var(--ease); }
.js .layer:not(.layer-top).in { transform: none; }
.js .split .w { display: inline-block; opacity: 0; transform: translateY(0.45em) rotate(2deg); transition: opacity .7s var(--ease), transform .7s var(--ease); transition-delay: calc(var(--i) * 70ms + 120ms); }
.js .split.in .w { opacity: 1; transform: none; }

/* Playful hovers (mouse/trackpad only) */
@media (hover: hover) and (pointer: fine) {
  .btn { transform: translate(var(--mx, 0), var(--my, 0)); transition: transform .35s var(--ease), background .2s ease, color .2s ease, box-shadow .3s ease; }
  .btn:hover { box-shadow: 0 10px 24px -12px var(--accent); }
  .btn:not(.btn-primary):hover { background: var(--text); color: var(--tone-1); }
  .tilt { transform: perspective(1000px) rotateX(var(--rx, 0deg)) rotateY(var(--ry, 0deg)) translateY(var(--lift, 0)); transition: transform .5s var(--ease), box-shadow .4s ease, border-color .2s ease; will-change: transform; }
  .tilt:hover { --lift: -4px; }
  .feature .cta { transition: letter-spacing .3s var(--ease); }
  .feature:hover .cta { letter-spacing: .02em; }
  .nav a { position: relative; }
  .nav a::after { content: ""; position: absolute; left: 0; right: 0; bottom: 8px; height: 2px; background: var(--accent); transform: scaleX(0); transform-origin: right; transition: transform .35s var(--ease); }
  .nav a:hover::after { transform: scaleX(1); transform-origin: left; }
  .prose a { text-decoration: none; background: linear-gradient(var(--accent), var(--accent)) 0 100% / 100% 1.5px no-repeat; transition: background-size .3s var(--ease); }
  .prose a:hover { background-size: 100% 100%; color: var(--on-accent); }
}

/* Tablet + mobile header: name + switch on one row, nav (left) on the row below */
@media (max-width: 960px) {
  .site-header .wrap { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 6px 12px; padding-top: 12px; padding-bottom: 6px; }
  .header-right { display: contents; }
  .theme-switch { grid-column: 2; grid-row: 1; }
  .nav { grid-column: 1 / -1; grid-row: 2; flex-wrap: nowrap; overflow-x: auto; gap: 20px; scrollbar-width: none; }
  .nav a, .nav span { white-space: nowrap; flex: none; }
}
@media (max-width: 600px) {
  .theme-switch span { padding: 8px 10px; }
  .theme-switch svg { display: none; }
  .brand-role { display: none; }
}
@media (max-width: 960px) { .toc { background: var(--tone-2); } }

@media (prefers-reduced-motion: reduce) {
  .js [data-reveal], .js .split .w, .js .layer { opacity: 1 !important; transform: none !important; filter: none !important; }
  .btn, .tilt { transform: none !important; }
  *, *::before, *::after { transition: none !important; animation: none !important; scroll-behavior: auto !important; }
}
