:root {
  --bg:     #fcfbf9;
  --fg:     #1d1d1f;
  --muted:  #6b6a67;
  --faint:  #9a9893;
  --line:   #ececea;
  --accent: #c75a35;
  --code:   #f3f1ec;
  --hover:  rgba(0, 0, 0, .04);
  --surface: #ffffff;
  --terra:      #faeee6;
  --terra-line: #eed7c8;
  color-scheme: light;
}
/* dark palette — system preference (unless user forced light) or explicit toggle */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #161514; --fg: #f2f1ee; --muted: #a3a19b; --faint: #76746e;
    --line: #292723; --accent: #f0855c; --code: #211f1c;
    --hover: rgba(255, 255, 255, .055);
    --surface: #1e1c1a;
    --terra: #251a15; --terra-line: #3d2a20;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #161514; --fg: #f2f1ee; --muted: #a3a19b; --faint: #76746e;
  --line: #292723; --accent: #f0855c; --code: #211f1c;
  --hover: rgba(255, 255, 255, .055);
  --surface: #1e1c1a;
  --terra: #251a15; --terra-line: #3d2a20;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 400 17px/1.65 -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display", "Segoe UI", Roboto, "Noto Sans Devanagari", Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  transition: background .4s ease, color .4s ease;
}

main {
  max-width: 720px;
  margin: 0 auto;
  padding: clamp(3.5rem, 9vh, 7rem) 1.5rem 5rem;
  animation: rise .55s cubic-bezier(.21,.6,.35,1) both;
}
@keyframes rise {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: none; }
}

/* --- block cascade ---
   app.js stamps each block with --td (its position in the stack). Theme changes
   apply that as a transition-delay so the new palette sweeps down the page one
   panel at a time; language changes fade each panel as its text is replaced.
   The delays are scoped to .theming so hover states never feel laggy. */
/* transition-property is restated for every participant, not just duration and
   delay. Elements already carrying a narrower transition — .rowlist li > a only
   lists `background` — would otherwise keep their own property list, so their
   colour changed the instant :root's tokens flipped while the panels were still
   cascading, leaving dark text on an already-dark card. --td inherits, so a
   panel and everything inside it move together. */
:root.theming .card,
:root.theming .card *,
:root.theming h1,
:root.theming h1 *,
:root.theming footer,
:root.theming footer *,
:root.theming .postcard,
:root.theming .postcard * {
  transition-property: background-color, border-color, color, fill, stroke, outline-color;
  transition-duration: .6s;
  transition-timing-function: ease;
  transition-delay: var(--td, 0ms);
}
/* The page ground leads, so the panels read as sweeping across a settled backdrop. */
:root.theming body { transition: background-color .45s ease, color .45s ease; }

@keyframes swapin {
  from { opacity: .15; transform: translateY(4px); }
  to   { opacity: 1; transform: none; }
}
.swapping { animation: swapin .45s cubic-bezier(.21,.6,.35,1) both; }

/* --- top controls --- */
.topbar { display: flex; align-items: center; justify-content: flex-end; gap: .4rem; margin-bottom: 2.5rem; }

/* Segmented language picker: both languages stay visible, the active one is
   filled in — so the control never has to imply a direction. */
.langswitch {
  display: inline-flex; align-items: center; gap: 2px;
  padding: 2px; border: 1px solid var(--line); border-radius: 980px;
}
.langopt {
  -webkit-appearance: none; appearance: none;
  font-family: inherit; font-size: .74rem; font-weight: 600; letter-spacing: .02em;
  line-height: 1.4; color: var(--faint); background: transparent; border: 0;
  padding: .26rem .62rem; border-radius: 980px; cursor: pointer;
  transition: color .2s ease, background .2s ease;
}
.langopt:hover { color: var(--fg); }
.langopt[aria-checked="true"] { color: var(--bg); background: var(--fg); cursor: default; }
.langopt:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.ctrl {
  -webkit-appearance: none; appearance: none;
  font-family: inherit; font-size: .78rem; font-weight: 600; letter-spacing: .01em;
  color: var(--muted); background: transparent; border: 1px solid var(--line);
  padding: .34rem .72rem; border-radius: 980px; cursor: pointer;
  transition: color .2s ease, border-color .2s ease, background .2s ease;
}
.ctrl:hover { color: var(--fg); border-color: var(--faint); }
.ctrl-icon { display: inline-flex; align-items: center; justify-content: center; padding: .3rem .48rem; }
.ctrl-icon svg { display: block; width: 16px; height: 16px; }
.ctrl:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Moon while the page is light, sun while it is dark — mirroring the palette's own
   light/dark conditions, so the glyph is correct before any script runs. */
#themeBtn .icon-sun { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) #themeBtn .icon-moon { display: none; }
  :root:not([data-theme="light"]) #themeBtn .icon-sun  { display: block; }
}
:root[data-theme="dark"] #themeBtn .icon-moon { display: none; }
:root[data-theme="dark"] #themeBtn .icon-sun  { display: block; }

/* --- headings / hero --- */
h1 {
  font-size: clamp(2.4rem, 6vw, 3.3rem);
  font-weight: 700; letter-spacing: -.03em; line-height: 1.05; margin: 0;
}
h1.name::after { content: "."; color: var(--accent); }
.intro {
  margin: 1.6rem 0 0; max-width: 36rem;
  font-size: 1.2rem; line-height: 1.55; letter-spacing: -.003em; color: var(--fg);
}
/* The lede as its own module, so it opens the stack instead of floating above it. */
.intro.card { max-width: none; margin-top: 1.9rem; padding: 1.3rem 1.4rem; }
.intro a { font-weight: 500; }

/* --- links --- */
a { color: var(--accent); text-decoration: none; font-weight: 500; transition: color .15s ease; }
a:hover { text-decoration: underline; text-underline-offset: .18em; text-decoration-thickness: 1px; }
.muted { color: var(--muted); }
.desc { color: var(--muted); font-weight: 400; }

/* --- homepage sections ---
   Each section is a self-contained module: its own surface, border and padding,
   so the page reads as a stack of panels rather than one continuous column.
   Deliberately plain — the Mithila painting appears in exactly one place on the
   page, the Contact panel, and stays the stronger for it. */
/* colour is stated, not inherited from body — body changes on its own clock, and
   inheriting a mid-transition colour makes a panel chase a moving target. */
.card {
  background: var(--surface); color: var(--fg);
  border: 1px solid var(--line);
  border-radius: 14px; padding: 1.25rem 1.35rem;
}
.sections {
  margin-top: 2.5rem; display: grid; grid-template-columns: 1fr; gap: 1rem;
}
@media (min-width: 680px) { .sections { grid-template-columns: 1fr 1fr; } }
/* Cards in the same row stretch to match, so columns never end ragged. */
.sections section { margin: 0; display: flex; flex-direction: column; }
/* Sections whose content reads better across the full measure than in a column. */
.sections .full { grid-column: 1 / -1; }
.sections h2 {
  font-size: .72rem; text-transform: uppercase; letter-spacing: .14em;
  font-weight: 600; color: var(--muted); margin: 0 0 .55rem;
}
/* --- row list: one padded link per row, shared by the homepage and /blog ---
   Rows are pulled out to the padding edge so the hover tint reads as a full-bleed
   row while the text stays optically aligned with the headings above it.
   These are all explicit classes, so none of it reaches Markdown post content. */
.rowlist { list-style: none; margin: 0 -.7rem; padding: 0; }
.rowlist li { margin: 0; }
.rowlist li > a {
  display: block; padding: .5rem .7rem; border-radius: 10px;
  transition: background .18s ease;
}
.rowlist li > a:hover { background: var(--hover); text-decoration: none; }
.rowlist li > a:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
/* Rows carrying an icon lay out as icon + text block. */
.item-icon {
  flex: none; width: 21px; height: 21px; margin-top: .12rem;
  color: var(--faint); transition: color .18s ease;
}
.item-body { min-width: 0; }
.iconlist li > a { display: flex; align-items: flex-start; gap: .65rem; }
.iconlist li > a:hover .item-icon { color: var(--accent); }
.item-name {
  display: block; color: var(--fg); font-weight: 600;
  font-size: 1.02rem; line-height: 1.4; letter-spacing: -.005em;
  transition: color .18s ease;
}
.rowlist li > a:hover .item-name { color: var(--accent); }
.item-name + .desc, .item-head + .desc {
  display: block; margin-top: .1rem; font-size: .92rem; line-height: 1.45;
}
/* Title and date share a baseline; the date holds a scannable right-hand column. */
.item-head { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; }
.item-date {
  flex: none; font-size: .74rem; font-weight: 600; letter-spacing: .08em;
  text-transform: uppercase; color: var(--faint);
}
/* Sits outside the list's negative margin, so it needs no padding to align. */
.sections .more { margin: .7rem 0 0; font-size: .95rem; }
.sections .more a { color: var(--accent); font-weight: 600; }
.sections .more a:hover { text-decoration: none; }
.sections .more .arrow { display: inline-block; transition: transform .18s ease; }
.sections .more a:hover .arrow { transform: translateX(3px); }
/* Elsewhere is navigation, not content — a compact row rather than a tall column. */
.sections .linkrow { display: flex; flex-wrap: wrap; gap: .1rem .5rem; }
.sections .linkrow li > a { padding: .38rem .7rem; }

/* --- contact ---
   Warm terracotta ground, framed by the woven border lifted straight out of the
   Mithila painting. border-image slices the outer 11.75% of the 1600px artwork —
   the vine-and-bud band, the corner sun-wheel and the triangle band — and tiles
   it around the panel, so the frame fits any height without distorting. Square
   corners, because border-image ignores border-radius. */
.sections .contact {
  background: var(--terra);
  border: 30px solid transparent;
  border-image: url("mithila.svg") 11.75% round;
  border-radius: 0;
  padding: 1.1rem 1.2rem;
}
@media (max-width: 559px) {
  .sections .contact { border-width: 17px; padding: .9rem .75rem; }
}
.contact-grid {
  display: grid; grid-template-columns: 1fr; gap: 1.1rem; align-items: center;
}
@media (min-width: 560px) {
  .contact-grid { grid-template-columns: 1fr auto; gap: 1.4rem; }
  /* Text hugs the heading; the taller plate centres itself against it. */
  .contact-text { align-self: start; }
}
/* No colour of its own: it inherits the card's, which cascades as one piece.
   Resolving --fg here instead made it drift out of step with its own panel. */
.contact-text p { margin: 0; font-size: 1rem; line-height: 1.55; }
.contact-mail { margin-top: .7rem !important; }
.contact-mail a {
  font-weight: 600; font-size: 1.02rem;
  border-bottom: 1px solid var(--terra-line);
}
.contact-mail a:hover { text-decoration: none; border-bottom-color: var(--accent); }
/* The painting's border is now the panel's frame, so the image beside the text
   shows only what is inside it. Cropping to the innermost frame (inset 292 of
   1600 = 18.25%) means scaling to 1/0.635 and pulling the excess off each edge,
   rather than shipping a second cropped copy of the artwork. */
/* Definite width, not 100% — in a grid `auto` column that would resolve to zero.
   The hairline makes the plate's edge deliberate: the painting's cream ground sits
   a shade off the terracotta, which without it reads as a stray patch. */
.contact-art-wrap {
  position: relative; overflow: hidden;
  width: 180px; max-width: 100%; aspect-ratio: 1;
  justify-self: center; align-self: center;
  border-radius: 6px; border: 1px solid var(--terra-line);
}
.contact-art {
  position: absolute; display: block;
  width: 157.48%; height: 157.48%; left: -28.74%; top: -28.74%;
}

/* Marks a post that lives on another site, so the off-site jump is not a surprise. */
.tag {
  display: inline-block; margin-right: .45rem; padding: .1em .42em;
  border: 1px solid var(--line); border-radius: 5px;
  font-size: .72em; font-weight: 600; letter-spacing: .02em;
  color: var(--faint); vertical-align: .08em; white-space: nowrap;
}

/* --- blog index --- */
.backlink { margin: 0 0 2.5rem; font-size: .9rem; }
.backlink a { color: var(--faint); font-weight: 600; }
.backlink a:hover { color: var(--accent); text-decoration: none; }
/* Same row pattern as the homepage, one size up and separated by rules. */
.postcard { margin-top: 2rem; }
.postlist { margin: 0 -.7rem; }
.postlist li + li { border-top: 1px solid var(--line); }
.postlist li > a { padding: 1rem .7rem; }
.postlist .item-name { font-size: 1.2rem; font-weight: 700; letter-spacing: -.015em; }
.postlist .item-head + .desc { margin-top: .25rem; font-size: .96rem; }

/* --- single post --- */
.post { max-width: 40rem; }
.post h1 { font-size: clamp(1.9rem, 5vw, 2.5rem); letter-spacing: -.02em; margin: 0; }
.postmeta {
  margin: .6rem 0 2.5rem; font-size: .8rem; text-transform: uppercase;
  letter-spacing: .09em; color: var(--faint); font-weight: 600;
}
.post h2 { font-size: 1.5rem; font-weight: 700; letter-spacing: -.01em; margin: 2.6rem 0 .8rem; }
.post h3 { font-size: 1.2rem; font-weight: 700; margin: 2rem 0 .6rem; }
.post p { margin: 1.15rem 0; }
.post ul, .post ol { margin: 1.15rem 0; padding-left: 1.4rem; }
.post li { margin: .4rem 0; }
.post a { text-decoration: underline; text-underline-offset: .18em; text-decoration-thickness: 1px; }
.post img { max-width: 100%; height: auto; border-radius: 8px; }
.post blockquote {
  margin: 1.6rem 0; padding: .1rem 0 .1rem 1.2rem;
  border-left: 3px solid var(--accent); color: var(--muted); font-style: italic;
}
.post code {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: .88em; background: var(--code); padding: .14em .4em; border-radius: 5px;
}
.post pre {
  background: var(--code); padding: 1rem 1.1rem; border-radius: 10px;
  overflow-x: auto; line-height: 1.55; font-size: .92rem; margin: 1.4rem 0;
}
.post pre code { background: none; padding: 0; font-size: inherit; }
.post hr { border: none; border-top: 1px solid var(--line); margin: 2.6rem 0; }

/* --- footer --- */
footer {
  margin-top: 4.5rem; padding-top: 1.5rem; border-top: 1px solid var(--line);
  font-size: .85rem; color: var(--faint);
}
footer a { color: var(--faint); font-weight: 500; }
footer a:hover { color: var(--accent); text-decoration: none; }

@media (prefers-reduced-motion: reduce) {
  main { animation: none; }
  * { transition: none !important; }
  /* No cascade either — app.js skips the stagger, this covers the CSS half. */
  .swapping { animation: none !important; }
  :root.theming *, :root.theming { transition-delay: 0ms !important; }
}
