/* MAM2046W — main stylesheet */

:root {
  --accent: #1a5fa8;
  --text: #222;
  --bg: #fff;
  --border: #ddd;
  --nav-bg: #f5f5f5;
  --max-width: 860px;
}

*, *::before, *::after { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Georgia", serif;
  font-size: 18px;
  line-height: 1.7;
  color: var(--text);
  background: var(--bg);
}

/* ── Navigation ── */
.site-nav {
  background: var(--nav-bg);
  border-bottom: 1px solid var(--border);
  padding: 0.6rem 1.5rem;
  display: flex;
  align-items: center;
  gap: 1.5rem;
  flex-wrap: wrap;
  position: sticky;
  top: 0;
  z-index: 100;
}

.site-title {
  font-family: "Helvetica Neue", Arial, sans-serif;
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--accent);
  text-decoration: none;
  white-space: nowrap;
}

.nav-links {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  font-family: "Helvetica Neue", Arial, sans-serif;
  font-size: 0.85rem;
}

.nav-links a {
  color: var(--text);
  text-decoration: none;
  padding: 0.15rem 0.4rem;
  border-radius: 3px;
}

.nav-links a:hover {
  background: var(--accent);
  color: #fff;
}

/* ── Main content ── */
main.content {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 2rem 1.5rem 4rem;
}

/* ── Home / Table of Contents ── */
.home h1 { font-size: 1.9rem; margin-bottom: 0.3rem; }
.home .lead { color: #555; margin-top: 0; font-size: 1rem; }

.toc { margin-top: 2rem; }
.toc h2 {
  font-size: 1.15rem;
  font-family: "Helvetica Neue", Arial, sans-serif;
  border-bottom: 1px solid var(--border);
  padding-bottom: 0.3rem;
  margin-top: 1.8rem;
  margin-bottom: 0.5rem;
}
.toc ul { padding-left: 1.2rem; list-style: none; }
.toc li { margin: 0.3rem 0; }
.toc li::before { content: ""; }
.toc a {
  color: var(--accent);
  text-decoration: none;
  font-size: 1rem;
}
.toc a:hover { text-decoration: underline; }

/* ── Notebook page ── */
.page-header h1 {
  font-size: 1.6rem;
  margin-bottom: 0.2rem;
  border-bottom: 2px solid var(--accent);
  padding-bottom: 0.4rem;
}

.page-nav {
  display: flex;
  justify-content: space-between;
  margin: 1rem 0 1.5rem;
  font-family: "Helvetica Neue", Arial, sans-serif;
  font-size: 0.9rem;
}

.page-nav.bottom {
  margin-top: 3rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
}

a.prev-next {
  color: var(--accent);
  text-decoration: none;
  border: 1px solid var(--accent);
  padding: 0.3rem 0.8rem;
  border-radius: 4px;
  transition: background 0.15s, color 0.15s;
}

a.prev-next:hover { background: var(--accent); color: #fff; }
a.prev-next.next { margin-left: auto; }

/* ── Notebook content typography ── */
.notebook-content h2 {
  font-size: 1.3rem;
  margin-top: 2.5rem;
  margin-bottom: 0.5rem;
  color: var(--accent);
}

.notebook-content h3 {
  font-size: 1.1rem;
  margin-top: 2rem;
  margin-bottom: 0.3rem;
}

.notebook-content h4 {
  font-size: 1rem;
  margin-top: 1.5rem;
  font-style: italic;
}

.notebook-content p {
  margin: 0.6rem 0 1rem;
}

.notebook-content img {
  max-width: 100%;
  height: auto;
  display: block;
  margin: 1.5rem auto;
  border-radius: 4px;
}

/* ── About page bio block ── */
.notebook-content .bio-block {
  display: flex;
  gap: 2rem;
  align-items: flex-start;
  flex-wrap: wrap;
  margin: 1rem 0 2rem;
}

.notebook-content .bio-photo {
  flex: 0 0 220px;
}

.notebook-content .bio-photo img {
  width: 100%;
  height: auto;
  margin: 0;
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
}

.notebook-content .bio-text {
  flex: 1;
  min-width: 280px;
}

.notebook-content .bio-text > p:first-child {
  margin-top: 0;
}

@media (max-width: 600px) {
  .notebook-content .bio-photo {
    flex: 0 0 100%;
    max-width: 240px;
    margin: 0 auto;
  }
}

/* ── Code blocks (Mathematica) ── */
.notebook-content pre {
  background: #f8f8f8;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.8rem 1rem;
  overflow-x: auto;
  font-size: 0.85rem;
  line-height: 1.5;
  margin: 0.8rem 0;
}

.notebook-content code {
  font-family: "SF Mono", "Menlo", "Monaco", "Consolas", monospace;
  font-size: 0.85em;
}

.notebook-content p code {
  background: #f0f0f0;
  padding: 0.1rem 0.3rem;
  border-radius: 3px;
}

/* ── Display math ── */
.notebook-content .katex-display {
  margin: 1.2rem 0;
  overflow-x: auto;
  overflow-y: hidden;
}

/* ── Lists ── */
.notebook-content ul,
.notebook-content ol {
  margin: 0.5rem 0 1rem;
  padding-left: 1.5rem;
}

.notebook-content li {
  margin: 0.3rem 0;
}

/* Nested sub-items */
.notebook-content li > ul {
  margin-top: 0.2rem;
  margin-bottom: 0.2rem;
}

/* ── Inline math spacing ── */
.katex { font-size: 1.05em; }

/* ── Bold/emphasis ── */
.notebook-content strong {
  font-weight: 700;
  color: #111;
}

/* ── Callout boxes ──
   These carry the pedagogy: each maps to one tcolorbox colour pair in the
   original LaTeX. Colour + label are the only thing distinguishing them. */
.box {
  margin: 1.6rem 0;
  padding: 0.9rem 1.2rem 1rem;
  border: 1px solid var(--box-line, var(--border));
  border-left: 4px solid var(--box-line, var(--border));
  border-radius: 4px;
  background: var(--box-fill, #fafafa);
}

.box > .box-label {
  display: block;
  font-family: "Helvetica Neue", Arial, sans-serif;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--box-line, #666);
  margin-bottom: 0.5rem;
}

.box > :last-child { margin-bottom: 0; }
.box > .box-label + * { margin-top: 0; }

.box-definition { --box-line: #1a5fa8; --box-fill: #f1f6fc; }
.box-theorem    { --box-line: #5b4b9e; --box-fill: #f4f2fb; }
.box-property   { --box-line: #0f7b7b; --box-fill: #eff8f8; }
.box-worked     { --box-line: #2e7d32; --box-fill: #f2f8f2; }
.box-cyu        { --box-line: #a8791a; --box-fill: #fdf8ee; }
.box-proof      { --box-line: #a83a3a; --box-fill: #fcf3f3; }
.box-note       { --box-line: #b4b4b4; --box-fill: #fafafa; }

/* End-of-proof marker */
.notebook-content p.qed {
  text-align: right;
  margin-top: -0.4rem;
  color: #666;
}

/* ── Collapsible solutions and answers ── */
details.reveal {
  margin: 0.8rem 0 1.2rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: #fbfbfb;
  padding: 0 1rem;
}

details.reveal > summary {
  cursor: pointer;
  padding: 0.55rem 0;
  font-family: "Helvetica Neue", Arial, sans-serif;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--accent);
  list-style: none;
}

details.reveal > summary::-webkit-details-marker { display: none; }

details.reveal > summary::before {
  content: "▸ ";
  display: inline-block;
  width: 1em;
  transition: transform 0.15s;
}

details.reveal[open] > summary::before { content: "▾ "; }
details.reveal[open] > summary { border-bottom: 1px solid var(--border); }
details.reveal > :not(summary) { margin-top: 0.8rem; }
details.reveal > :last-child { margin-bottom: 0.9rem; }

/* Reveals sit inside a coloured box, so lift them off its fill */
.box-cyu details.reveal { background: #fffdf7; }
.box-worked details.reveal { background: #fbfefb; margin-bottom: 0; }

/* ── Section checklists ── */
.checklist {
  list-style: none;
  padding-left: 0;
  margin: 1rem 0 1.5rem;
}

.checklist li { margin: 0.45rem 0; }

.checklist label {
  display: flex;
  align-items: baseline;
  gap: 0.6rem;
  cursor: pointer;
}

.checklist input[type=checkbox] {
  flex: 0 0 auto;
  width: 1.05em;
  height: 1.05em;
  accent-color: var(--accent);
  cursor: pointer;
  position: relative;
  top: 0.15em;
}

.checklist input[type=checkbox]:checked + span {
  color: #777;
}

.checklist-reset {
  font-family: "Helvetica Neue", Arial, sans-serif;
  font-size: 0.78rem;
  background: none;
  border: 1px solid var(--border);
  border-radius: 3px;
  color: #777;
  padding: 0.2rem 0.6rem;
  cursor: pointer;
}

.checklist-reset:hover { border-color: var(--accent); color: var(--accent); }

/* ── Figures ── */
.notebook-content figure {
  margin: 1.8rem 0;
  text-align: center;
}

.notebook-content figure img {
  margin: 0 auto 0.6rem;
  border: 1px solid var(--border);
}

.notebook-content figcaption {
  font-size: 0.87rem;
  color: #666;
  line-height: 1.5;
  text-align: left;
  max-width: 44rem;
  margin: 0 auto;
}

/* ── Inline (i) (ii) (iii) enumerations ──
   LaTeX's inparaenum runs items along the line and keeps their labels, so
   the labels come back as a CSS counter. */
.notebook-content .inline-enum {
  display: inline;
  list-style: none;
  padding: 0;
  margin: 0;
  counter-reset: inline-enum;
}

.notebook-content .inline-enum li {
  display: inline-block;
  margin: 0.15rem 1.6em 0.15rem 0;
  counter-increment: inline-enum;
}

.notebook-content .inline-enum li::before {
  content: "(" counter(inline-enum, lower-roman) ")\00a0";
  color: #777;
}

.notebook-content .inline-enum[type="a"] li::before {
  content: "(" counter(inline-enum, lower-alpha) ")\00a0";
}

/* ── Interactive widgets ── */
.notebook-content .cx-widget {
  margin: 1.6rem 0 0.4rem;
}

.cx-mount {
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fcfcfd;
  padding: 0.9rem 1rem 0.7rem;
}

.jxgbox.cx-board {
  width: 100%;
  height: 380px;
  border: 1px solid #e4e8ec !important;
  border-radius: 4px;
  margin: 0;
  background: #fff;
  touch-action: none;
}

/* A single board stretched to the full column leaves the diagram marooned
   in the middle, so cap it and centre it. Paired boards need the width. */
.cx-mount > .jxgbox.cx-board {
  max-width: 560px;
  margin: 0 auto;
}

.cx-pair .jxgbox.cx-board { height: 300px; }

/* Two-plane widgets: source and image side by side. */
.cx-pair {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.8rem;
}

.cx-readout {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 1.4rem;
  font-family: "SF Mono", "Menlo", "Monaco", "Consolas", monospace;
  font-size: 0.82rem;
  color: #444;
  margin-top: 0.7rem;
  padding-top: 0.6rem;
  border-top: 1px solid #eceff2;
}

.cx-readout .cx-result {
  color: #a83a3a;
  font-weight: 600;
}

.cx-hint {
  font-size: 0.82rem;
  line-height: 1.5;
  color: #777;
  margin: 0.55rem 0 0;
}

.cx-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 1.2rem;
  margin-top: 0.7rem;
}

.cx-slider {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-family: "Helvetica Neue", Arial, sans-serif;
  font-size: 0.82rem;
  color: #555;
}

.cx-slider-label { min-width: 4.2em; }

.cx-slider input[type=range] {
  width: 11rem;
  max-width: 45vw;
  accent-color: var(--accent);
  cursor: pointer;
}

/* Without JavaScript the <noscript> image stands in, so say nothing. */
.cx-widget.cx-failed .cx-mount { display: none; }

@media (max-width: 620px) {
  .cx-pair { grid-template-columns: 1fr; }
  .cx-mount { padding: 0.7rem 0.7rem 0.6rem; }
  .jxgbox.cx-board,
  .cx-pair .jxgbox.cx-board { height: 300px; }
}

/* ── Cross-reference links ── */
.notebook-content a.xref {
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px dotted var(--accent);
}

.notebook-content a.xref:hover { border-bottom-style: solid; }

/* References inside formulas: KaTeX renders \href as a plain <a>, so give it
   the same dotted underline without disturbing the maths metrics.

   The z-index is load-bearing. KaTeX lays each column of an aligned block
   out as a stack of absolutely positioned rows, and those boxes overlap
   their neighbours. Without this, a neighbouring column's .vlist paints on
   top of the link and swallows both the click and the hover, which happens
   to some rows and not others depending on the layout. */
.notebook-content .katex a {
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px dotted var(--accent);
  position: relative;
  z-index: 2;
}

.notebook-content .katex a:hover { border-bottom-style: solid; }

/* KaTeX's struts and spacers carry no glyphs but do have boxes, and those
   boxes overlap neighbouring columns. Making them pointer-transparent stops
   one intercepting a click meant for the link underneath, whatever the
   layout happens to be at a given width. Glyph spans are untouched, so
   selecting and copying maths still works. */
.notebook-content .katex .pstrut,
.notebook-content .katex .strut,
.notebook-content .katex .vlist-s,
.notebook-content .katex .mspace {
  pointer-events: none;
}

/* ── Cross-reference hover preview ── */
.xref-pop {
  position: absolute;
  z-index: 200;
  display: none;
  overflow-y: auto;
  max-width: min(30rem, calc(100vw - 24px));
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: 0 6px 26px rgba(0, 0, 0, 0.14);
  padding: 0.15rem 0.9rem 0.5rem;
  font-size: 0.92rem;
  line-height: 1.55;
  opacity: 0;
  transition: opacity 0.12s ease;
}

.xref-pop.open { opacity: 1; }

/* The preview holds a whole callout box; strip its outer chrome so the
   popover itself provides the frame. */
.xref-pop .box {
  margin: 0.5rem 0 0;
  border: none;
  border-left: 3px solid var(--box-line, var(--border));
  border-radius: 0;
  background: none;
  padding: 0.1rem 0 0.1rem 0.8rem;
}

.xref-pop .box-label { margin-bottom: 0.35rem; }
.xref-pop p { margin: 0.35rem 0; }
.xref-pop .katex-display { margin: 0.6rem 0; }

@media (hover: none) {
  .xref-pop { display: none !important; }
}

/* ── Footer ── */
footer {
  text-align: center;
  font-size: 0.82rem;
  color: #999;
  border-top: 1px solid var(--border);
  padding: 1.5rem;
  margin-top: 2rem;
  font-family: "Helvetica Neue", Arial, sans-serif;
}

footer a {
  color: #888;
  text-decoration: none;
}

footer a:hover {
  color: var(--accent);
  text-decoration: underline;
}

footer p { margin: 0.2rem 0; }

/* ── Mobile ── */
@media (max-width: 600px) {
  body { font-size: 16px; }

  main.content { padding: 1.2rem 1rem 3rem; }

  .page-header h1 { font-size: 1.3rem; }
  .notebook-content h2 { font-size: 1.15rem; }

  .page-nav { flex-direction: column; gap: 0.5rem; }
  a.prev-next.next { margin-left: 0; }
  a.prev-next { text-align: center; }

  .site-title { font-size: 0.95rem; }

  .notebook-content .katex-display {
    font-size: 0.9rem;
  }

  .box { padding: 0.8rem 0.9rem; }
  details.reveal { padding: 0 0.8rem; }
  .inline-enum li { display: block; margin: 0.3rem 0; }
}
