/* Blog posts (_layouts/post.html): a calm, single-column reading layout.
   One accent colour (the site's link blue), used for links and the thin
   left rule on notes. Everything else is the normal text colour or muted grey.
   Every rule is scoped to .essay so the rest of the site is untouched. */

.essay {
  --e-accent: #007bff;
  --e-text: #343a40;
  --e-muted: #6c757d;
  --e-line: rgba(0, 0, 0, 0.1);
  --e-note: rgba(0, 0, 0, 0.035);
  --e-code: #f6f7f9;
  --e-figure: transparent;
  --e-page: #ffffff;

  /* the one container that sets the text width (79ch: ~890px, about 95 characters a line) */
  max-width: 79ch;
  margin: 3rem auto 4rem;
  color: var(--e-text);
  font-size: 1.125rem;
  line-height: 1.75;
  overflow-wrap: break-word;
}

[data-theme="dark"] .essay {
  --e-accent: #4da3ff;
  --e-text: rgba(255, 255, 255, 0.88);
  --e-muted: #a0a6ad;
  --e-line: rgba(255, 255, 255, 0.12);
  --e-note: rgba(255, 255, 255, 0.045);
  --e-code: #202325;
  --e-figure: #f3f4f6;      /* plots are drawn for a light page */
  --e-page: #17191a;
}

/* ---------- header ---------- */
.essay-header { margin-bottom: 2.5rem; }
.essay-title {
  font-size: clamp(2rem, 5.5vw, 2.6rem);
  font-weight: 600;
  line-height: 1.2;
  margin: 0;
  color: inherit;
}
.essay-subtitle {
  color: var(--e-muted);
  font-size: 1.25rem;
  line-height: 1.4;
  margin: 0.5rem 0 0;
}
.essay-meta {
  color: var(--e-muted);
  font-size: 0.9rem;
  margin: 0.9rem 0 0;
}

/* ---------- text ---------- */
.essay p, .essay ul, .essay ol { margin: 0 0 1.2em; }
.essay ul, .essay ol { padding-left: 1.4em; }
.essay li { margin-bottom: 0.3em; }
.essay li::marker { color: inherit; }
.essay strong, .essay b { font-weight: 600; }
.essay .hl { color: inherit; font-weight: 600; }   /* emphasis by weight, not colour */
.essay hr { border: 0; border-top: 1px solid var(--e-line); margin: 2.5rem 0; }

.essay a { color: var(--e-accent); text-decoration: none; }
.essay a:hover, .essay a:focus-visible { text-decoration: underline; text-underline-offset: 0.15em; }

/* ---------- headings: plain, with room above ---------- */
.essay h2, .essay h3, .essay h4 {
  display: block;
  background: none;
  color: inherit;
  padding: 0;
  border-radius: 0;
  line-height: 1.3;
}
.essay h2 { font-size: 1.55rem; font-weight: 600; margin: 2.8rem 0 0.8rem; }
.essay h3 { font-size: 1.25rem; font-weight: 600; margin: 2.2rem 0 0.6rem; }
.essay h4 { font-size: 1.1rem;  font-weight: 600; margin: 1.8rem 0 0.5rem; }

/* ---------- notes and callouts: one style for all of them ----------
   .kbox (any colour), .krule and blockquote all render the same way. */
.essay .kbox,
.essay .krule,
.essay blockquote {
  background: var(--e-note);
  border-left: 3px solid var(--e-accent);
  border-radius: 0 6px 6px 0;
  color: inherit;
  padding: 0.9rem 1.2rem;
  margin: 1.6rem 0;
  font-size: inherit;           /* same size as the body text */
  text-align: left;
}
.essay .kbox > :last-child,
.essay blockquote > :last-child { margin-bottom: 0; }
.essay .kbox .kbox-title { color: inherit; font-weight: 600; margin-bottom: 0.4rem; }
.essay .kgrid { display: block; }                 /* side-by-side boxes stack in one column */
.essay .krule .big { font-weight: 600; font-size: inherit; line-height: inherit; }
.essay .krule .small { font-size: inherit; margin-top: 0.25rem; }   /* Bootstrap's .small is 80% */

/* ---------- tables ---------- */
.essay .ktable { overflow-x: auto; margin: 1.6rem 0; }
.essay table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.95rem;
  line-height: 1.55;
  margin: 1.6rem 0;
}
.essay .ktable table { margin: 0; }
.essay th, .essay td {
  border: 0;
  border-bottom: 1px solid var(--e-line);
  padding: 0.55rem 0.75rem;
  vertical-align: top;
  text-align: left;
  background: none;
  color: inherit;
}
.essay th { font-weight: 600; border-bottom-width: 2px; }
/* the theme stripes table rows (and does so more specifically in dark mode) */
[data-theme] .essay table:not(.highlight) tr,
[data-theme] .essay table:not(.highlight) tr:nth-child(odd),
[data-theme] .essay table:not(.highlight) tr:nth-child(even) { background: none; }

/* ---------- code and poems in fenced blocks ---------- */
.essay pre {
  background: var(--e-code);
  border: 1px solid var(--e-line);
  border-radius: 6px;
  color: inherit;
  font-size: 0.92rem;
  line-height: 1.6;
  padding: 1rem 1.25rem;
  overflow-x: auto;
  margin: 0 0 1.4em;
}
.essay code { font-size: 0.9em; }
/* keyboard keys: small key caps in the body font (Bootstrap's default is a dark block) */
.essay kbd {
  display: inline-block;
  font-family: inherit;
  font-size: 0.8em;
  font-weight: 600;
  line-height: 1.4;
  color: inherit;
  background: var(--e-code);
  border: 1px solid var(--e-line);
  border-bottom-width: 2px;
  border-radius: 5px;
  box-shadow: none;
  padding: 0.05em 0.45em;
  white-space: nowrap;
}
.essay :not(pre) > code { background: var(--e-code); border-radius: 4px; padding: 0.1em 0.35em; color: inherit; }

/* ---------- figures: centred, full column width at most, small muted caption ---------- */
.essay figure, .essay .kfig {
  margin: 2rem auto;
  text-align: center;
  background: none;
  padding: 0;
}
.essay figure img, .essay .kfig img, .essay p > img {
  display: block;
  max-width: 100%;
  height: auto;
  margin: 0 auto;
}
.essay .kfig img { width: 100%; background: var(--e-figure); border-radius: 6px; }
.essay figcaption {
  color: var(--e-muted);
  font-size: 0.88rem;
  line-height: 1.5;
  margin-top: 0.6rem;
}

/* ---------- a poem beside its picture (<div class="poem-pair">: figure + fenced poem) ----------
   The poem reads as plain text in the site font, a little larger so Devanagari
   is comfortable; the picture sits beside it and stays in view while you read. */
.essay .poem-pair {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr);
  gap: 2.5rem;
  align-items: start;
  margin: 2rem 0;
}
/* the poem: kramdown wraps the fenced block in div.highlighter-rouge > div.highlight > pre */
.essay .poem-pair > .highlighter-rouge,
.essay .poem-pair > pre { grid-column: 1; grid-row: 1; }
.essay .poem-pair .highlight { background: none; margin: 0; }
.essay .poem-pair pre {
  margin: 0;
  padding: 0;
  background: none;
  border: 0;
  font-family: "Poppins", system-ui, sans-serif;
  font-size: 1.1rem;
  line-height: 1.9;
  white-space: pre-wrap;
  overflow: visible;
}
.essay .poem-pair pre code { font-family: inherit; font-size: inherit; background: none; padding: 0; color: inherit; }
.essay .poem-pair .poem-art {
  grid-column: 2;
  grid-row: 1;
  max-width: none;
  margin: 0;
  position: sticky;
  top: 1.5rem;
}
@media (max-width: 767.98px) {
  .essay .poem-pair { grid-template-columns: 1fr; gap: 1.5rem; }
  .essay .poem-pair .poem-art { grid-row: 1; grid-column: 1; max-width: 420px; margin: 0 auto; position: static; }
  .essay .poem-pair > .highlighter-rouge,
  .essay .poem-pair > pre { grid-row: 2; }
  .essay .poem-pair pre { font-size: 1.05rem; }
}

/* ---------- maths (MathJax) ---------- */
.essay mjx-container[display="true"] {
  display: block;
  text-align: center;
  margin: 1.2em 0 !important;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 0.3em 0;            /* room for glyphs that poke outside MathJax's box */
  max-width: 100%;
}
/* a bracket or closing punctuation glued to its formula (see _layouts/post.html) */
.essay .mjx-glue { white-space: nowrap; }
/* ...unless the formula itself needs its own scrolling line */
.essay .mjx-glue:has(> .mjx-wide) { white-space: normal; }

/* an inline formula wider than the column (marked .mjx-wide by the script in
   _layouts/post.html) gets its own line and scrolls, instead of widening the page */
.essay mjx-container.mjx-wide {
  display: block;
  max-width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 0.3em 0;
}
/* plain tables (not wrapped in .ktable) scroll on their own too */
.essay table { display: block; max-width: 100%; overflow-x: auto; }
.essay .ktable table { display: table; }
.essay img { max-width: 100%; height: auto; }

/* ---------- breakout: equations, figures and tables may be wider than the text ----------
   Up to 900px (never wider than the screen), centred on the same axis as the text.
   Only top-level ones: an equation inside a note stays inside the note.
   (Placed after the maths rules: same specificity, so the later !important wins.) */
.essay > mjx-container[display="true"],
.essay > .kfig,
.essay > figure:not(.poem-art),
.essay > .ktable,
.essay > table {
  width: min(900px, 100vw - 2rem);
  max-width: none;
  margin-left: calc(50% - min(450px, 50vw - 1rem)) !important;
  margin-right: 0 !important;
}

/* ---------- in-text charts kept from the original posts (figures, so they keep their colours) ---------- */
.essay .c-blue   { --fg: #3D9BE9; }
.essay .c-pink   { --fg: #E84470; }
.essay .c-purple { --fg: #8E5BD6; }
.essay .c-green  { --fg: #3E9B4F; }
.essay .c-orange { --fg: #F2A100; }
.essay .kbars { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; margin: 1.6rem 0; }
.essay .kbm .name { text-align: center; font-weight: 600; color: var(--fg); margin-bottom: 6px; font-size: 0.95rem; }
.essay .kbm .plot { position: relative; height: 96px; display: flex; align-items: flex-end; gap: 6px; padding: 0 4px; border-bottom: 2px solid var(--e-muted); }
.essay .kbm .plot span { flex: 1; background: var(--fg); border-radius: 3px 3px 0 0; min-height: 2px; }
.essay .kbm .mae { position: absolute; left: 0; right: 0; border-top: 2px dashed var(--e-text); }
.essay .kbm .mae b { position: absolute; left: 0; top: -1.25rem; font-size: 0.7rem; font-weight: 600; }
.essay .kbm .cap { text-align: center; font-size: 0.8rem; margin-top: 4px; color: var(--e-muted); }
.essay .kratio { position: relative; height: 14px; border-radius: 7px; background: linear-gradient(90deg, #3E9B4F, #F2A100, #E84470); margin: 40px 14px 10px; }
/* markers: a letter above, a dot on the bar, all on one line (no pills, so close values don't collide) */
.essay .kratio .m { position: absolute; top: -26px; transform: translateX(-50%); color: var(--e-text); font-size: 0.78rem; font-weight: 600; line-height: 1; white-space: nowrap; }
.essay .kratio .m::after { content: ""; position: absolute; left: 50%; top: 26px; width: 10px; height: 10px; margin-left: -7px; border-radius: 50%; background: var(--e-page); border: 2px solid var(--e-text); }
.essay .kratio .m.end::after { left: auto; right: -7px; margin-left: 0; }
.essay .kratio .m.end { transform: translateX(-100%); padding-right: 0; }
.essay .kratio-labels { display: flex; justify-content: space-between; font-size: 0.8rem; color: var(--e-muted); margin: 0 4px 1.4rem; }
.essay .kratio-labels div:last-child { text-align: right; }
.essay .kvote { display: grid; grid-template-columns: auto 1fr; gap: 6px 10px; align-items: center; margin: 0.6rem 0 0; }
.essay .kvote .lab { font-weight: 600; font-size: 0.85rem; }
.essay .kvote .bar { display: flex; height: 26px; border-radius: 6px; overflow: hidden; font-size: 0.75rem; font-weight: 600; }
.essay .kvote .bar span { display: flex; align-items: center; justify-content: center; color: #fff; white-space: nowrap; overflow: hidden; }

/* ---------- "In this post": the sections as stops on a route ----------
   A thin line joins one dot per section; folds away on phones (see post.html). */
.essay-toc { margin: 0 0 2.6rem; font-size: 0.98rem; }
.essay-toc summary {
  color: var(--e-muted);
  font-size: 0.9rem;
  cursor: pointer;
  list-style: none;
  margin: 0 0 0.7rem;
  width: max-content;
}
.essay-toc summary::-webkit-details-marker { display: none; }
.essay-toc summary::after { content: " \25BE"; }            /* ▾ */
.essay-toc:not([open]) summary::after { content: " \25B8"; } /* ▸ */
.essay-toc:not([open]) summary { margin-bottom: 0; }
.essay-toc summary:hover, .essay-toc summary:focus-visible { color: var(--e-accent); }
.essay-toc ul { list-style: none; margin: 0; padding: 0; position: relative; }
.essay-toc ul::before {                      /* the route */
  content: "";
  position: absolute;
  left: 5px;
  top: 0.85em;
  bottom: 0.85em;
  border-left: 2px dotted var(--e-line);
}
.essay-toc li {
  position: relative;
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0 0.6rem;
  padding-left: 1.75rem;
  margin: 0 0 0.45rem;
  line-height: 1.5;
}
.essay-toc li::before {                      /* a stop */
  content: "";
  position: absolute;
  left: 0;
  top: 0.42em;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 2px solid var(--e-muted);
  background: var(--e-page);
  transition: background-color 0.2s, border-color 0.2s;
}
.essay-toc li:first-child::before { background: var(--e-muted); }   /* start here */
.essay-toc li:hover::before { border-color: var(--e-accent); background: var(--e-accent); }

/* ---------- series box at the end ---------- */
.essay-series {
  border-top: 1px solid var(--e-line);
  margin-top: 3.5rem;
  padding-top: 1.5rem;
  font-size: 1rem;
}
.essay-series-title { font-weight: 600; margin: 0 0 0.6rem; }
.essay-series ol { margin: 0 0 1rem; padding-left: 1.4em; }
.essay-series li { margin-bottom: 0.2em; }
.essay-series [aria-current="page"] { font-weight: 600; }
.essay-series .here { color: var(--e-muted); font-size: 0.9rem; }
.essay-series-nav { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 0.5rem 1.5rem; margin: 0; }
.essay-series-nav .next { margin-left: auto; text-align: right; }

/* ---------- subscribe / book-a-session block (styled like the notes) ---------- */
.essay .essay-subscribe { margin-top: 2rem; }

/* ---------- phones ---------- */
@media (max-width: 575.98px) {
  .essay { margin-top: 2rem; font-size: 1rem; }
  .essay .kbox, .essay .krule, .essay blockquote { padding: 0.8rem 1rem; }
  .essay .kbars { gap: 8px; }
  .essay th, .essay td { padding: 0.5rem 0.5rem; }
}
