:root, :root[data-theme="dark"]{
  --bg:#0a0b10; --lime:#d7e34a; --pink:#ff5c8a; --sky:#7ec8e3; --cream:#f2f0e8;
  --card:#151821; --border:rgba(255,255,255,.08); --dim:#9aa0ae; --txt:#e8e8e4;
  --body-txt:#c7cad2; --emphasis:#ffffff; --grad-a:#171a22; --grad-b:#0a0b10;
  --shadow-a:.4; --shadow-a-strong:.5;

  /* Category tile colors: identity, not theme — but still CSS variables (not
     hex baked into the HTML) so each one can be tuned separately per theme,
     e.g. `retro` needs a different tile color in light mode or it disappears
     into a cream page background. */
  --cat-hardware-bg:#d7e34a; --cat-hardware-text:#141410;
  --cat-repair-bg:#ff5c8a;   --cat-repair-text:#2b0f18;
  --cat-language-bg:#7ec8e3; --cat-language-text:#0e2233;
  --cat-retro-bg:#f2f0e8;    --cat-retro-text:#141410;
  --cat-default-bg:#9aa0ae;  --cat-default-text:#141410;
  --cat-about-bg:#b39ddb;    --cat-about-text:#1f1533;
  --cat-thinking-bg:#9aa0ae; --cat-thinking-text:#141410;

  /* Home page bio tiles (templates.js `bioTile()`) — each gets its own
     color so the three don't read as one repeated block, distinct from
     every post category above. */
  --cat-studying-bg:#7cd9c0; --cat-studying-text:#0c2b23;
  --cat-me-bg:#ffb08a;       --cat-me-text:#3a1706;
  --cat-site-bg:#f0c14b;     --cat-site-text:#2b1d05;
}
@media (prefers-color-scheme: light){
  :root{
    --bg:#f3ecd9; --card:#e8ddc2; --border:rgba(43,31,10,.14); --dim:#7a7160; --txt:#241f16;
    --body-txt:#4a4436; --emphasis:#16130c; --grad-a:#faf5e8; --grad-b:#eee2c4;
    --shadow-a:.12; --shadow-a-strong:.18;

    /* Dark mode can run these hues near-full saturation because they're
       glowing against near-black. On a light/cream page the same intensity
       next to dark text just looks loud, so light mode is a softened pastel
       pass of the same hues (lower saturation, higher lightness) rather
       than the dark-mode values lightly tweaked. `retro`/`default` are the
       exception — they stay a bit more saturated/mid-tone on purpose, or
       they'd wash out into the (also cream) page background. */
    --cat-hardware-bg:#dde8ad; --cat-hardware-text:#242807;
    --cat-repair-bg:#f3c2d1;   --cat-repair-text:#4a1420;
    --cat-language-bg:#c3e2f0; --cat-language-text:#0f2c3d;
    --cat-retro-bg:#d6c69c;    --cat-retro-text:#2b2013;
    --cat-default-bg:#c7cbd3;  --cat-default-text:#20232b;
    --cat-about-bg:#cbb0e3;    --cat-about-text:#2a1740;
    --cat-thinking-bg:#c7cbd3; --cat-thinking-text:#20232b;
    --cat-studying-bg:#b8e2d5; --cat-studying-text:#0d2b22;
    --cat-me-bg:#f4c9a9;       --cat-me-text:#3a1706;
    --cat-site-bg:#f2dfa0;     --cat-site-text:#33260a;
  }
}
/* Manual override from the theme-toggle button (templates.js), stored in
   localStorage. Attribute selectors here outrank the plain `:root` used by
   the media query above, so this wins over the system preference whichever
   way it goes; no `data-theme` attribute at all means "follow the system". */
:root[data-theme="light"]{
  --bg:#f3ecd9; --card:#e8ddc2; --border:rgba(43,31,10,.14); --dim:#7a7160; --txt:#241f16;
  --body-txt:#4a4436; --emphasis:#16130c; --grad-a:#faf5e8; --grad-b:#eee2c4;
  --shadow-a:.12; --shadow-a-strong:.18;
  --cat-hardware-bg:#dde8ad; --cat-hardware-text:#242807;
  --cat-repair-bg:#f3c2d1;   --cat-repair-text:#4a1420;
  --cat-language-bg:#c3e2f0; --cat-language-text:#0f2c3d;
  --cat-retro-bg:#d6c69c;    --cat-retro-text:#2b2013;
  --cat-default-bg:#c7cbd3;  --cat-default-text:#20232b;
  --cat-about-bg:#cbb0e3;    --cat-about-text:#2a1740;
  --cat-thinking-bg:#c7cbd3; --cat-thinking-text:#20232b;
  --cat-studying-bg:#b8e2d5; --cat-studying-text:#0d2b22;
  --cat-me-bg:#f4c9a9;       --cat-me-text:#3a1706;
  --cat-site-bg:#f2dfa0;     --cat-site-text:#33260a;
}
*{box-sizing:border-box}
/* Flipping the theme changes a lot of variables at once (page background,
   borders, every tile color); without this everything just snaps, which
   reads as a glitch rather than a deliberate toggle. Elements below that
   already declare their own `transition` (`.tile`, `.rel`, `.theme-toggle`)
   need these properties folded into that list instead — a competing
   `transition` declaration replaces this one outright, it doesn't merge. */
*{transition:background-color .35s ease, color .35s ease, border-color .35s ease, box-shadow .35s ease}
html{background:var(--bg)}
body{
  background:radial-gradient(circle at 25% -10%, var(--grad-a), var(--grad-b) 55%);
  margin:0; min-height:100vh; font-family:'Inter',sans-serif; color:var(--txt); padding:3rem 1.6rem 5rem;
  transition:background .35s ease, color .35s ease;
}
.wrap{max-width:960px; margin:0 auto}
header{display:flex; align-items:center; justify-content:space-between; margin-bottom:2rem; flex-wrap:wrap; gap:1rem}
.id{display:flex; align-items:center; gap:.7rem}
.id .name{font-family:'Space Grotesk',sans-serif; font-weight:800; font-size:1.6rem}
/* Home page only: reads as "Sohan's Blog", but the bold letters alone
   spell "Slog" (S...log) — hence the site's actual title everywhere else. */
.id .logo{font-weight:300; color:var(--dim)}
.id .logo .hl{font-weight:800; color:var(--emphasis)}
/* Home page only (`animateLogo` in templates.js adds `.collapsed` after a
   delay): shrinking `.mid`'s max-width to 0 is what visually pulls "S" and
   "log" together into "Slog" — simpler and more robust than animating two
   separate transforms toward each other, and it degrades gracefully to a
   static "Sohan's Blog" on every page that never adds `.collapsed`. */
.id .logo .mid{
  display:inline-block; overflow:hidden; white-space:nowrap; vertical-align:bottom;
  max-width:20ch; opacity:1;
  transition:max-width 1.1s cubic-bezier(.2,.8,.3,1), opacity .9s ease, color .35s ease;
}
.id .logo.collapsed .mid{max-width:0; opacity:0}
nav.top a{color:var(--dim); text-decoration:none; font-size:.85rem; margin-left:1.2rem}
nav.top a:hover{color:var(--emphasis)}

.page-title{font-family:'Space Grotesk',sans-serif; font-size:1.7rem; margin:0 0 1.4rem}

/* Bento grid: size classes + dense auto-flow, so any number of tiles just packs itself */
.grid{
  display:grid; grid-template-columns:repeat(4,1fr); grid-auto-rows:130px; grid-auto-flow:dense; gap:14px;
}
.tile{
  border-radius:16px; padding:1.2rem 1.3rem; overflow:hidden; text-decoration:none; color:inherit;
  display:flex; flex-direction:column; justify-content:flex-end; border:1px solid var(--border);
  box-shadow:0 8px 22px rgb(0 0 0 / var(--shadow-a));
  transition:transform .2s cubic-bezier(.2,.8,.3,1), box-shadow .05s ease, background-color .35s ease, color .35s ease, border-color .35s ease;
}
.tile:hover{transform:translateY(-4px); box-shadow:0 16px 32px rgb(0 0 0 / var(--shadow-a-strong))}
.size-lg{grid-column:span 2; grid-row:span 2}
.size-md{grid-column:span 2; grid-row:span 1}
.size-sm{grid-column:span 1; grid-row:span 1}
.size-wide{grid-column:span 4; grid-row:span 1}
.size-tall{grid-column:span 1; grid-row:span 2}
.tile .kicker{font-family:'Space Grotesk',sans-serif; font-size:.68rem; font-weight:700; letter-spacing:.06em; opacity:.75; margin:0 0 .3rem}
.tile h2{font-family:'Space Grotesk',sans-serif; font-size:1.1rem; margin:0 0 .2rem; line-height:1.18}
.size-lg h2{font-size:1.5rem}
.tile p{margin:0; font-size:.82rem; opacity:.9}
.meta-tile{cursor:default}
.bio h2{font-size:.95rem}

@media (max-width:700px){
  .grid{grid-template-columns:repeat(2,1fr)}
  .size-wide{grid-column:span 2}
}

/* Post page */
.back{display:inline-flex; align-items:center; gap:.4rem; color:var(--dim); text-decoration:none; font-size:.85rem; margin-bottom:1.6rem}
.back:hover{color:var(--emphasis)}
.back svg{width:14px; height:14px}
.kicker-badge{
  display:inline-flex; align-items:center; gap:.4rem; font-family:'Space Grotesk',sans-serif; font-weight:700;
  font-size:.7rem; letter-spacing:.06em; padding:.3rem .7rem; border-radius:20px; margin-bottom:1.1rem;
}
h1{font-family:'Space Grotesk',sans-serif; font-size:clamp(1.8rem,5vw,2.4rem); line-height:1.15; margin:0 0 1rem}
.post-meta{color:var(--dim); font-size:.88rem; margin:0 0 2.4rem; display:flex; gap:1rem; flex-wrap:wrap}
article{max-width:680px}
article h2{font-family:'Space Grotesk',sans-serif; font-size:1.35rem; margin:2.4rem 0 1rem}
article p{line-height:1.75; color:var(--body-txt); margin:0 0 1.2rem; font-size:1.02rem}
article a{color:var(--lime)}
article ul, article ol{padding-left:1.4rem; margin:0 0 1.2rem; color:var(--body-txt)}
article li{margin-bottom:.4rem; line-height:1.6}
article strong{color:var(--emphasis)}
article blockquote{
  border-left:3px solid var(--lime); margin:2rem 0; padding:.3rem 0 .3rem 1.3rem; font-style:italic;
  font-size:1.1rem; color:var(--txt);
}
article pre{
  background:var(--card); border:1px solid var(--border); border-radius:10px; padding:1.1rem 1.2rem;
  overflow-x:auto; margin:1.6rem 0; box-shadow:0 6px 18px rgb(0 0 0 / var(--shadow-a));
}
article code{font-family:'IBM Plex Mono',monospace; font-size:.85rem}
article :not(pre) > code{background:var(--card); padding:.15rem .4rem; border-radius:4px}

hr.div{border:none; border-top:1px solid var(--border); margin:3rem 0 2rem}
.related h3{font-family:'Space Grotesk',sans-serif; font-size:1rem; color:var(--dim); font-weight:500; margin:0 0 1rem}
.rel-grid{display:grid; grid-template-columns:1fr 1fr 1fr; gap:12px}
.rel{
  border-radius:12px; padding:1rem 1.1rem; text-decoration:none; display:block;
  border:1px solid var(--border); box-shadow:0 6px 16px rgb(0 0 0 / var(--shadow-a));
  transition:transform .15s ease, background-color .35s ease, color .35s ease, border-color .35s ease;
}
.rel:hover{transform:translateY(-3px)}
.rel .tag{font-family:'Space Grotesk',sans-serif; font-size:.65rem; font-weight:700; letter-spacing:.05em; opacity:.75; margin:0 0 .35rem}
.rel .t{font-family:'Space Grotesk',sans-serif; font-size:.92rem; font-weight:700; line-height:1.25}

footer{
  margin-top:3rem; padding-top:1.2rem; border-top:1px solid var(--border); color:var(--dim);
  font-size:.85rem; display:flex; align-items:center; justify-content:center; gap:.5rem;
}

@media (max-width:560px){
  .rel-grid{grid-template-columns:1fr}
}

/* Tucked into the footer rather than floating over the page — a quiet
   detail you notice on the way out, not a control competing for attention.
   The contrast-disc icon is still the familiar "toggle theme" convention. */
.theme-toggle{
  display:inline-flex; align-items:center; justify-content:center; width:1.6rem; height:1.6rem;
  padding:0; margin:0; border:none; border-radius:50%; background:none; color:var(--dim); cursor:pointer;
  transition:color .15s ease, background-color .15s ease;
}
.theme-toggle:hover{color:var(--emphasis); background-color:var(--card)}
.theme-toggle svg{width:.95rem; height:.95rem}

/* Comments (templates.js commentsSection). Variables only, so both themes work. */
.comments{max-width:680px; margin:3rem 0 0}
.comments h3{font-family:'Space Grotesk',sans-serif; font-size:1.2rem; margin:0 0 1rem}
.comment{background:var(--card); border:1px solid var(--border); border-radius:12px; padding:1rem 1.2rem; margin:0 0 .9rem}
.c-head{display:flex; align-items:baseline; gap:.7rem; flex-wrap:wrap}
.c-name{font-family:'Space Grotesk',sans-serif; color:var(--emphasis)}
.c-meta{font-family:'IBM Plex Mono',monospace; font-size:.78rem; color:var(--dim)}
.c-body{margin:.5rem 0 0; line-height:1.65; color:var(--body-txt); white-space:pre-wrap; overflow-wrap:anywhere}
.c-note{color:var(--dim); font-size:.88rem; margin:.4rem 0}
.c-form{margin-top:1.6rem; display:grid; gap:.9rem}
.c-form label{display:grid; gap:.3rem; font-size:.88rem; color:var(--dim)}
.c-form input, .c-form textarea{
  font:inherit; font-size:.95rem; color:var(--txt); background:var(--card);
  border:1px solid var(--border); border-radius:8px; padding:.55rem .7rem; width:100%;
}
.c-form input:focus, .c-form textarea:focus{outline:2px solid var(--dim); outline-offset:1px}
.c-form textarea{resize:vertical; min-height:7rem}
.c-form button{
  justify-self:start; font:inherit; font-weight:600; cursor:pointer;
  background:var(--emphasis); color:var(--bg); border:0; border-radius:8px; padding:.55rem 1.3rem;
}
.c-form button:disabled{opacity:.5; cursor:default}
/* Honeypot: off-screen rather than display:none, since some bots skip hidden fields. */
.c-hp{position:absolute; left:-9999px; width:1px; height:1px; overflow:hidden}
