/* ==========================================================================
   Manan Sharma — Blog stylesheet
   Tufte-style layout modeled on ermongroup.github.io/cs228-notes: a narrow
   text column on the left with numbered sidenotes in the right margin.
   Accented with the site's Stanford Cardinal (#8C1515).
   ========================================================================== */

:root {
  --cardinal: #8C1515;
  --cardinal-dark: #6f1010;
  --ink: #2E2D29;          /* body text */
  --ink-soft: #4D4F53;     /* secondary text */
  --muted: #767676;        /* meta / captions */
  --rule: #e4e4e4;         /* hairlines */
  --code-bg: #f6f8fa;      /* code + dropdown backgrounds */
  --page: #ffffff;
  --sel: rgba(140, 21, 21, 0.12);

  /* Tufte column geometry -------------------------------------------------- */
  --content-col: 680px;    /* main text column (left)  */
  --margin-col: 280px;     /* sidenote column (right)  */
  --col-gap: 40px;         /* gutter between them      */
  --shell: 1080px;         /* content-col + gap + margin-col + side padding */

  --serif: Charter, Georgia, "Times New Roman", "Noto Serif", serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  --mono: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, Courier, monospace;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font-family: var(--serif);
  font-size: 18px;
  line-height: 1.7;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}

::selection { background: var(--sel); }

/* ---- Top navigation bar --------------------------------------------------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--cardinal);
  border-bottom: 3px solid var(--cardinal-dark);
}
.topbar .bar {
  max-width: var(--shell);
  margin: 0 auto;
  padding: 0 32px;
  height: 54px;
  display: flex;
  align-items: center;
  gap: 22px;
}
.topbar .brand {
  font-family: var(--sans);
  font-weight: 700;
  letter-spacing: 0.2px;
  color: #fff;
  text-decoration: none;
  margin-right: auto;
  font-size: 16px;
}
.topbar .brand span { opacity: 0.72; font-weight: 400; font-style: italic; }
.topbar a.navlink {
  font-family: var(--sans);
  font-size: 14px;
  color: rgba(255, 255, 255, 0.82);
  text-decoration: none;
  padding: 4px 2px;
  border-bottom: 2px solid transparent;
  transition: color 0.15s, border-color 0.15s;
}
.topbar a.navlink:hover { color: #fff; }
.topbar a.navlink.active { color: #fff; border-bottom-color: #fff; }

/* ---- Page shell ----------------------------------------------------------- */
/* The shell is wide enough to hold both columns; content stays left-aligned
   and sidenotes float out into the right margin via negative margins.        */
.wrap {
  max-width: var(--shell);
  margin: 0 auto;
  padding: 0 32px 96px;
}

/* Constrain the flowing content to the left text column. Block-level children
   of the article (and the landing-page blocks) sit in this column; sidenotes
   escape rightward from inside them.                                          */
article > *,
.post-header,
.intro,
.postlist {
  max-width: var(--content-col);
}

/* ---- Links ---------------------------------------------------------------- */
a { color: var(--cardinal); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 2px; }

/* ---- Headings ------------------------------------------------------------- */
h1, h2, h3, h4 {
  font-family: var(--serif);
  line-height: 1.25;
  color: var(--ink);
  font-weight: 700;
}
h1 { font-size: 2.15rem; margin: 0.2em 0 0.15em; letter-spacing: -0.4px; }
h2 {
  font-size: 1.55rem;
  margin: 2.2rem 0 0.8rem;
  padding-bottom: 0.3rem;
  border-bottom: 1px solid var(--rule);
}
h3 { font-size: 1.22rem; margin: 1.8rem 0 0.6rem; }
h4 { font-size: 1.05rem; margin: 1.4rem 0 0.4rem; color: var(--ink-soft); }

/* anchor targets clear the sticky bar */
h2[id], h3[id] { scroll-margin-top: 70px; }

p { margin: 0 0 1.1rem; }

hr { border: 0; border-top: 1px solid var(--rule); margin: 2.5rem 0; }

blockquote {
  margin: 1.4rem 0;
  padding: 0.2rem 1.1rem;
  border-left: 3px solid var(--cardinal);
  color: var(--ink-soft);
  font-style: italic;
}

ul, ol { padding-left: 1.4rem; }
li { margin: 0.3rem 0; }

/* ==========================================================================
   SIDENOTES & MARGIN NOTES  (the Tufte right column)
   Authoring:
     …text needing a note<span class="sn-ref"></span>
     <span class="sidenote">The note. Auto-numbered to match the marker.</span>
   Unnumbered aside:
     <span class="marginnote">A note with no reference marker.</span>
   ========================================================================== */
article { counter-reset: sidenote-counter; }

/* in-body superscript reference marker */
.sn-ref { counter-increment: sidenote-counter; }
.sn-ref::after {
  content: counter(sidenote-counter);
  font-family: var(--sans);
  font-size: 0.62em;
  vertical-align: super;
  color: var(--cardinal);
  padding-left: 1px;
}

.sidenote,
.marginnote {
  float: right;
  clear: right;
  width: var(--margin-col);
  /* push the note out of the text column into the right margin */
  margin-right: calc(-1 * (var(--margin-col) + var(--col-gap)));
  margin-top: 0.3rem;
  margin-bottom: 1.2rem;
  font-size: 0.8em;
  line-height: 1.5;
  color: var(--ink-soft);
  position: relative;
  text-align: left;
}
/* numbered prefix on the sidenote, matching its in-body marker */
.sidenote::before {
  content: counter(sidenote-counter) ".";
  font-family: var(--sans);
  font-size: 0.85em;
  color: var(--cardinal);
  margin-right: 0.4em;
}
.sidenote code, .marginnote code { font-size: 0.9em; }

/* ==========================================================================
   LANDING PAGE
   ========================================================================== */
.intro {
  padding: 46px 0 8px;
  border-bottom: 1px solid var(--rule);
  margin-bottom: 8px;
}
.intro h1 { font-size: 2.4rem; margin-bottom: 0.35rem; }
.intro .tagline { color: var(--ink-soft); font-size: 1.12rem; margin-bottom: 1rem; }
.intro .social a {
  font-family: var(--sans);
  font-size: 13.5px;
  margin-right: 14px;
  color: var(--ink-soft);
}
.intro .social a:hover { color: var(--cardinal); }

.postlist { list-style: none; padding: 0; margin: 0; }
.postlist > li { padding: 30px 0; border-bottom: 1px solid var(--rule); }
.postlist h2 {
  border: 0;
  padding: 0;
  margin: 0 0 0.35rem;
  font-size: 1.6rem;
  max-width: none;
}
.postlist h2 a { color: var(--ink); }
.postlist h2 a:hover { color: var(--cardinal); text-decoration: none; }
.post-meta {
  font-family: var(--sans);
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 0.7rem;
}
.post-meta .dot { margin: 0 7px; opacity: 0.5; }
.excerpt { color: var(--ink-soft); margin: 0; }
.tags { margin-top: 0.7rem; }
.tag {
  display: inline-block;
  font-family: var(--sans);
  font-size: 11.5px;
  letter-spacing: 0.3px;
  text-transform: uppercase;
  color: var(--cardinal);
  background: var(--sel);
  border-radius: 3px;
  padding: 2px 8px;
  margin-right: 6px;
}

/* ==========================================================================
   ARTICLE / POST PAGE
   ========================================================================== */
.post-header { padding: 44px 0 8px; }
.post-header h1 { margin-bottom: 0.4rem; }
.post-header .post-meta { font-size: 14px; margin-bottom: 0; }

article { font-size: 18px; }

/* Table of contents */
.toc {
  font-family: var(--sans);
  font-size: 14px;
  background: var(--code-bg);
  border: 1px solid var(--rule);
  border-radius: 6px;
  padding: 16px 20px 16px 40px;
  margin: 1.6rem 0 2.2rem;
}
.toc-title {
  font-family: var(--sans);
  font-weight: 700;
  font-size: 12px;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  color: var(--muted);
  margin: 0 0 0.5rem -18px;
}
.toc ol { margin: 0; }
.toc a { color: var(--ink-soft); }
.toc a:hover { color: var(--cardinal); }

/* ---- Figures with captions ------------------------------------------------ */
figure {
  margin: 2rem 0;
  text-align: center;
}
figure img {
  max-width: 100%;
  height: auto;
  border-radius: 4px;
}
figcaption {
  font-family: var(--sans);
  font-size: 14px;
  color: var(--muted);
  line-height: 1.5;
  margin-top: 0.7rem;
  padding: 0 8%;
}
figcaption .figlabel { color: var(--ink-soft); font-weight: 600; }

/* ---- Inline & block code -------------------------------------------------- */
code {
  font-family: var(--mono);
  font-size: 0.86em;
  background: var(--code-bg);
  padding: 0.15em 0.4em;
  border-radius: 4px;
}
pre {
  background: var(--code-bg);
  border: 1px solid var(--rule);
  border-radius: 6px;
  padding: 14px 16px;
  overflow-x: auto;
  font-size: 13.5px;
  line-height: 1.55;
}
pre code {
  background: none;
  padding: 0;
  font-size: inherit;
}

/* ---- Collapsible dropdowns (proofs / algorithms / code) ------------------- */
details.drop {
  border: 1px solid var(--rule);
  border-left: 3px solid var(--cardinal);
  border-radius: 6px;
  background: var(--code-bg);
  margin: 1.6rem 0;
  overflow: hidden;
}
details.drop > summary {
  font-family: var(--sans);
  font-size: 14px;
  font-weight: 600;
  color: var(--ink);
  padding: 11px 16px;
  cursor: pointer;
  list-style: none;
  user-select: none;
  display: flex;
  align-items: center;
  gap: 9px;
  background: #fff;
}
details.drop > summary:hover { color: var(--cardinal); }
details.drop > summary::-webkit-details-marker { display: none; }
/* custom disclosure triangle */
details.drop > summary::before {
  content: "";
  width: 0; height: 0;
  border-left: 6px solid var(--cardinal);
  border-top: 4px solid transparent;
  border-bottom: 4px solid transparent;
  transition: transform 0.18s ease;
  flex: none;
}
details.drop[open] > summary::before { transform: rotate(90deg); }
/* label chip on the left of the summary text */
details.drop > summary .kind {
  font-size: 11px;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  color: #fff;
  background: var(--cardinal);
  border-radius: 3px;
  padding: 1px 7px;
}
details.drop .drop-body {
  padding: 4px 18px 6px;
  border-top: 1px solid var(--rule);
}
details.drop .drop-body > pre { margin: 12px 0; }
/* kind-specific accent tints */
details.drop.algo { border-left-color: #0b6b57; }
details.drop.algo > summary .kind { background: #0b6b57; }
details.drop.code { border-left-color: #4D4F53; }
details.drop.code > summary .kind { background: #4D4F53; }

/* LaTeX-style algorithm environment (algorithm2e "ruled" look):
   serif type, bold keywords, real math via MathJax, numbered lines,
   thick top/bottom rules and a captioned header.                             */
.algorithm {
  font-family: var(--serif);
  font-size: 15px;
  line-height: 1.6;
  background: #fff;
  border-top: 2px solid var(--ink);
  border-bottom: 2px solid var(--ink);
  margin: 14px 0;
  overflow-x: auto;
}
.algo-caption {
  padding: 7px 14px;
  border-bottom: 1px solid var(--ink);
  font-size: 14px;
}
.algo-caption .anum { font-weight: 700; }
.algo-caption .anum::after { content: ": "; }
.algorithm table { border-collapse: collapse; width: 100%; margin: 0; }
.algorithm td { vertical-align: baseline; padding: 1px 0; border: 0; }
.algorithm td.ln {
  width: 2.6em;
  text-align: right;
  padding: 1px 12px 1px 12px;
  color: var(--muted);
  font-family: var(--sans);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  user-select: none;
}
.algorithm td.code { padding-right: 18px; white-space: nowrap; }
.algorithm td.cmt {
  color: var(--muted);
  font-style: italic;
  font-size: 13px;
  white-space: nowrap;
  padding-right: 14px;
}
.algorithm td.cmt::before { content: "\25B9\00a0"; font-style: normal; }
.algorithm tr.io td { padding-bottom: 2px; }
.algorithm tr.io td.code { white-space: normal; }
.algorithm tr.first td { padding-top: 6px; }
.algorithm tr:last-child td { padding-bottom: 7px; }
.algorithm .kw { font-weight: 700; }                 /* for / do / end / return */
.algorithm .io { font-weight: 700; }                 /* Input / Output labels   */
/* vertical rule marking an indented block, as algorithm2e draws */
.algorithm .blk {
  display: inline-block;
  border-left: 1px solid var(--rule);
  margin-left: 4px;
  padding-left: 15px;
}

/* ---- Callout / note box --------------------------------------------------- */
.note {
  background: var(--sel);
  border-radius: 6px;
  padding: 14px 18px;
  margin: 1.6rem 0;
  font-size: 0.96em;
}
.note strong { color: var(--cardinal-dark); }

/* ---- Aside / "side note" callout (for blockquote-style remarks) ----------- */
.aside {
  background: var(--code-bg);
  border-left: 3px solid var(--cardinal);
  border-radius: 0 6px 6px 0;
  padding: 12px 18px;
  margin: 1.6rem 0;
  font-size: 0.95em;
  line-height: 1.62;
}
.aside > :first-child { margin-top: 0; }
.aside > :last-child { margin-bottom: 0; }
.aside .lead { color: var(--cardinal-dark); font-weight: 700; }
.aside ol, .aside ul { margin: 0.4rem 0; }

/* ---- Theorem / definition lead-ins ---------------------------------------- */
.thm { font-weight: 700; }
.thm-name { font-weight: 700; }

/* ---- Data tables ---------------------------------------------------------- */
.tbl-wrap { overflow-x: auto; margin: 1.5rem 0; }
table.tbl {
  border-collapse: collapse;
  width: 100%;
  font-family: var(--sans);
  font-size: 13.5px;
  line-height: 1.45;
}
table.tbl th,
table.tbl td {
  border: 1px solid var(--rule);
  padding: 6px 11px;
  text-align: left;
  vertical-align: top;
}
table.tbl thead th {
  background: var(--code-bg);
  font-weight: 700;
  border-bottom: 2px solid #d0d0d0;
}
table.tbl tbody tr:nth-child(even) { background: #fafafa; }
table.tbl code { font-size: 0.92em; }

/* ---- ASCII diagram (dependency map) --------------------------------------- */
pre.diagram {
  font-family: var(--mono);
  font-size: 11.5px;
  line-height: 1.35;
  background: var(--code-bg);
  border: 1px solid var(--rule);
  border-radius: 6px;
  padding: 16px;
  overflow-x: auto;
  white-space: pre;
  color: var(--ink);
}

/* ---- MathJax display spacing ---------------------------------------------- */
mjx-container[display="true"] { margin: 1.3rem 0 !important; overflow-x: auto; overflow-y: hidden; }

/* ---- Prev / next navigation ----------------------------------------------- */
.pagenav {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  margin-top: 3.5rem;
  padding-top: 1.6rem;
  border-top: 1px solid var(--rule);
  font-family: var(--sans);
}
.pagenav a {
  flex: 1 1 0;
  max-width: 48%;
  padding: 12px 16px;
  border: 1px solid var(--rule);
  border-radius: 6px;
  color: var(--ink-soft);
  transition: border-color 0.15s, color 0.15s;
}
.pagenav a:hover { border-color: var(--cardinal); color: var(--cardinal); text-decoration: none; }
.pagenav a.next { text-align: right; margin-left: auto; }
.pagenav .dir {
  display: block;
  font-size: 11px;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 2px;
}
.pagenav a.disabled { visibility: hidden; }

/* ---- Site footer ---------------------------------------------------------- */
.sitefooter {
  border-top: 1px solid var(--rule);
  margin-top: 40px;
  padding: 24px 0;
  font-family: var(--sans);
  font-size: 13px;
  color: var(--muted);
  text-align: center;
  max-width: var(--content-col);
}
.sitefooter a { color: var(--muted); text-decoration: underline; }

/* ==========================================================================
   RESPONSIVE
   Below the shell width there isn't room for a true right margin, so sidenotes
   collapse inline (as indented footnote-style blocks) and content goes full width.
   ========================================================================== */
@media (max-width: 1080px) {
  article > *,
  .post-header,
  .intro,
  .postlist,
  .sitefooter { max-width: 100%; }

  .sidenote,
  .marginnote {
    float: none;
    width: auto;
    margin: 1rem 0;
    display: block;
    border-left: 3px solid var(--rule);
    background: var(--code-bg);
    border-radius: 0 4px 4px 0;
    padding: 0.5rem 0.9rem;
  }
}

@media (max-width: 640px) {
  body { font-size: 17px; }
  .topbar .bar { gap: 14px; padding: 0 16px; }
  .topbar .brand span { display: none; }
  .wrap { padding: 0 18px 64px; }
  h1 { font-size: 1.9rem; }
  .pagenav { flex-direction: column; }
  .pagenav a, .pagenav a.next { max-width: 100%; text-align: left; }
}
