/* Minimal academic blog style, modelled on henrygwb.github.io:
   single 740px text column, Palatino serif, purple headings.
   LLM notes pages add a left sidebar (see the end of this file and llm/nav.js). */

html {
  font-family: 'Palatino Linotype', Palatino, Georgia, 'Songti SC', 'Noto Serif SC', 'SimSun', serif;
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
}

body {
  background-color: #ffffff;
  color: #1a1a1a;
  max-width: 740px;
  margin: 20px auto 60px auto;
  padding: 0 clamp(14px, 4vw, 20px);
  box-sizing: border-box;
  line-height: 1.75;
  overflow-wrap: break-word;
}

img, svg { max-width: 100%; height: auto; }

a { color: #1a0dab; }
a:visited { color: #5b2c86; }

/* Headings */
h1, h2, h3, h4, h5 { color: purple; line-height: 1.35; }
h1 { font-size: clamp(1.5rem, 5vw, 2rem); margin: 0.6em 0 0.3em; }
h2 { font-size: clamp(1.3rem, 4.8vw, 1.7rem); margin: 1.6em 0 0.6em; scroll-margin-top: 16px; }
h3 { font-size: clamp(1.25rem, 4.6vw, 1.6rem); margin: 0.7em 0 0.3em; }
h4 { font-size: clamp(1.12rem, 4.2vw, 1.4rem); margin: 1.6em 0 0.6em; scroll-margin-top: 16px; }
h5 { font-size: clamp(1.02rem, 3.8vw, 1.15rem); margin: 1.2em 0 0.4em; }

p { margin: 0 0 0.9em; }
ul, ol { margin: 0.5em 0 0.9em; padding-left: 1.6em; }
li { margin: 0.35em 0; }

code {
  font-family: Consolas, "Courier New", monospace;
  font-size: 85%;
  background: #f4f4f6;
  padding: 1px 4px;
  border-radius: 3px;
}

.post-date { color: gray; margin-top: 0; }
.series-crumb { font-size: 14px; color: gray; margin: 0 0 0.4em; }
.series-crumb a { color: gray; }
.intro { font-size: 1.02em; }

/* Display equations */
.equation {
  overflow-x: auto;
  overflow-y: hidden;
  margin: 0.8em 0 1em;
  padding: 2px 0;
}
mjx-container[display="true"] { margin: 0.4em 0 !important; max-width: 100%; overflow-x: auto; overflow-y: hidden; }

/* Notes and examples */
.note, .example {
  padding: 10px 14px;
  border-radius: 4px;
  margin: 1em 0;
}
.note { background: #faf6fb; border-left: 3px solid purple; }
.example { background: #f5f8fb; border-left: 3px solid #4a6fa5; }

/* Tables */
.table-wrap { overflow-x: auto; margin: 1em 0 1.2em; }
.table-wrap table { border-collapse: collapse; width: 100%; font-size: 0.93em; line-height: 1.55; }
.table-wrap th, .table-wrap td { border: 1px solid #ddd; padding: 6px 10px; text-align: left; vertical-align: top; }
.table-wrap thead th { background: #f6f3f8; white-space: nowrap; }

/* Series navigation (prev / index / next) */
.series-nav {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  border-top: 1px solid #e5e5e5;
  margin-top: 3em;
  padding-top: 1em;
  font-size: 15px;
}

/* Post list on posts.html and the series index */
.post-list { list-style: none; padding: 0; }
.post-list li { margin: 0 0 1.1em; }
.post-list .date { color: gray; font-size: 14px; margin-right: 8px; }
.post-list .desc { color: #555; font-size: 0.95em; margin: 0.2em 0 0; }

/* Callout boxes and tables used by the advanced OPD post */
.box { border-left: 3px solid #ccc; border-radius: 0 4px 4px 0; padding: 10px 14px 2px; margin: 1em 0; }
.box .box-t { font-size: 13px; font-weight: bold; letter-spacing: 0.06em; margin: 0 0 4px; }
.box.def { background: #f5f7fc; border-color: #4a6fa5; } .box.def .box-t { color: #4a6fa5; }
.box.why { background: #fcf8f1; border-color: #a8691a; } .box.why .box-t { color: #a8691a; }
.box.eg { background: #f2f8f4; border-color: #2e7650; } .box.eg .box-t { color: #2e7650; }
.box.warn { background: #fcf2f2; border-color: #a83434; } .box.warn .box-t { color: #a83434; }
.tbl { overflow-x: auto; margin: 1em 0 1.2em; }
.tbl table { border-collapse: collapse; width: 100%; font-size: 0.93em; line-height: 1.55; }
.tbl th, .tbl td { border: 1px solid #ddd; padding: 6px 10px; text-align: left; vertical-align: top; }
.tbl thead th { background: #f6f3f8; }

/* ---------- LLM notes: left sidebar (built by llm/nav.js) ---------- */
:root { --sb-w: 264px; }

.sidebar {
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  width: var(--sb-w);
  box-sizing: border-box;
  padding: 22px 14px 48px 18px;
  overflow-y: auto;
  overscroll-behavior: contain;
  background: #fafafa;
  border-right: 1px solid #ececec;
  font-size: 14.5px;
  line-height: 1.5;
  z-index: 1002;
}
.sidebar a { color: #333; text-decoration: none; }
.sidebar a:hover { color: purple; }
.sidebar .sb-home { display: inline-block; font-size: 13px; color: gray; margin-bottom: 10px; }
.sidebar .sb-title { display: block; font-size: 17px; font-weight: bold; color: purple; margin-bottom: 14px; }

.sb-section { margin: 0 0 10px; }
.sb-section > summary {
  cursor: pointer;
  list-style: none;
  font-weight: bold;
  color: #222;
  padding: 4px 0;
}
.sb-section > summary::-webkit-details-marker { display: none; }
.sb-section > summary::before {
  content: "▸";
  display: inline-block;
  width: 1em;
  color: #999;
  transition: transform 0.15s;
}
.sb-section[open] > summary::before { transform: rotate(90deg); }

.sb-list, .sb-toc { list-style: none; margin: 0; padding: 0; }
.sb-list li, .sb-toc li { margin: 0; }
.sb-list > li > a {
  display: block;
  padding: 4px 8px;
  border-left: 2px solid transparent;
  border-radius: 0 4px 4px 0;
}
.sb-list > li > a.active {
  color: purple;
  font-weight: bold;
  background: #f3ecf6;
  border-left-color: purple;
}
.sb-toc {
  margin: 4px 0 8px 12px;
  padding-left: 8px;
  border-left: 1px solid #e3e3e3;
  font-size: 13px;
  line-height: 1.45;
}
.sb-toc a { display: block; padding: 3px 4px; color: #666; }
.sb-toc a.current { color: purple; }

.nav-toggle {
  position: fixed;
  left: 20px;
  bottom: 20px;
  background-color: #f6f8f9;
  color: #000;
  border: 0;
  padding: 10px 15px;
  border-radius: 25px;
  font-family: inherit;
  font-size: 14px;
  font-weight: bold;
  line-height: 1.2;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.28);
  cursor: pointer;
  z-index: 1003;
}
.nav-toggle:hover { background-color: #e6eaee; }
.sb-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.25);
  z-index: 1001;
}

/* Wide screens: sidebar always visible, text column centred in the remaining space. */
@media (min-width: 1100px) {
  body.with-sidebar {
    margin-left: calc(var(--sb-w) + max(32px, (100vw - var(--sb-w) - 740px) / 2));
    margin-right: auto;
  }
  /* the sidebar lists this page's sections; nav.js adds .no-sb-toc when it could not */
  body.with-sidebar:not(.no-sb-toc) .page-toc { display: none; }
  .nav-toggle, .sb-backdrop { display: none !important; }
}

/* Narrow screens: sidebar becomes a drawer opened by the "目录" button. */
@media (max-width: 1099.98px) {
  .sidebar {
    width: min(var(--sb-w), 85vw);
    padding-bottom: 90px; /* keep the last items clear of the floating toggle button */
    transform: translateX(-100%);
    visibility: hidden;
    transition: transform 0.2s ease, visibility 0s linear 0.2s;
  }
  .sidebar.open {
    transform: none;
    visibility: visible;
    box-shadow: 2px 0 14px rgba(0, 0, 0, 0.2);
    transition: transform 0.2s ease, visibility 0s;
  }
  .sb-backdrop.show { display: block; }
}
@media (prefers-reduced-motion: reduce) {
  .sidebar, .sidebar.open, .sb-section > summary::before { transition: none !important; }
}

@media print {
  .sidebar, .nav-toggle, .sb-backdrop { display: none !important; }
  body.with-sidebar { margin-left: auto; margin-right: auto; }
  body.with-sidebar .page-toc { display: block; }
}

/* Interview Q&A (面试八股): question shown, answer folded for self-testing */
details.qa {
  border: 1px solid #e8e1ed;
  border-radius: 6px;
  background: #fcfbfd;
  margin: 0.6em 0;
  padding: 0 14px;
}
details.qa > summary {
  cursor: pointer;
  list-style: none;
  font-weight: bold;
  padding: 9px 0;
}
details.qa > summary::-webkit-details-marker { display: none; }
details.qa > summary::before {
  content: "▸";
  display: inline-block;
  width: 1.1em;
  color: purple;
  transition: transform 0.15s;
}
details.qa[open] > summary::before { transform: rotate(90deg); }
details.qa[open] > summary { border-bottom: 1px solid #eee; margin-bottom: 8px; }
details.qa > :last-child { margin-bottom: 12px; }
@media (prefers-reduced-motion: reduce) {
  details.qa > summary::before { transition: none; }
}
