/* Page layout */

body {
  font-family: "Noto Serif", serif;
  font-size: 16px;
  line-height: 1.5;
  color: #333;
  margin: 0;
}

.page {
  display: grid;
  /* 320px TOC, and 'minmax(0, 1fr)' prevents content from forcing width */
  grid-template-columns: 320px minmax(0, 1fr);
  grid-template-rows: auto 1fr;
  grid-template-areas:
    "toc header"
    "toc main";
  gap: 0 60px; /* Increased horizontal gap for breathing room */
  max-width: 1240px; /* Widened to accommodate larger TOC */
  margin: 0 auto;
}

main {
  grid-area: main;
  max-width: 760px;
  margin-bottom: 40px;
}

/* Title block */

.title-block {
  grid-area: header;
  max-width: 760px;
  width: 100%;
  text-align: left;
}

.title-block h1 {
  font-weight: 600;
  margin-bottom: 0.3em;
}

.title-block p {
  color: #555;
  font-size: 0.9em;
  margin: 0.2em 0;
}

.author,
.date {
  color: #555;
  font-size: 0.9em;
}

/* Table of contents */

#TOC {
  grid-area: toc;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  font-size: 0.9em;
  line-height: 1.4em;
  padding: 40px 20px 20px 20px;
  box-sizing: border-box;
  font-family: sans-serif;
  font-size: 0.85em;
  text-transform: none;
}

#TOC ul {
  list-style: none;
  padding-left: 0;
  margin-left: 1.5em;
}

#TOC li {
  margin: 4px 0;
}

#TOC a {
  text-decoration: none;
  color: #0645ad;
}

/* Headings */

h1,
h2,
h3,
h4 {
  font-family: "Charter", "Bitstream Charter", serif;
  font-weight: bold;
  color: #000;
  margin-top: 1.5em;
}

h1 {
  border-bottom: 1px solid #ddd;
  padding-bottom: 0.3em;
}

/* Tables */
table {
  border-collapse: collapse;
  margin: 2em 0;
  width: 100%;
  font-size: 0.95em; /* Slightly smaller for technical data */
  /* Remove outer side borders for a cleaner, modern technical look */
  border-left: none;
  border-right: none;
}

/* Header Row */
thead th {
  background-color: #f0f0f0; /* Distinct light gray header */
  color: #111;
  font-weight: 700;
  text-align: left;
  border-bottom: 2px solid #ccc; /* Thicker line under header */
}

th,
td {
  padding: 8px 12px;
  border: 1px solid #eee;
}

tbody tr:nth-child(even) {
  background-color: #f9f9f9; /* Subtle alternating row color */
}

/* Links */

a {
  color: #0645ad;
}

a:hover {
  text-decoration: underline;
}

/* Blockquotes */

blockquote {
  margin-left: 1em;
  border-left: 3px solid #ccc;
  padding-left: 1em;
  color: #555;
}

.header-link {
  text-decoration: none;
  margin-left: 0.4em;
  color: #aaa;
  font-size: 0.8em;
  visibility: hidden;
}

h1:hover .header-link,
h2:hover .header-link,
h3:hover .header-link,
h4:hover .header-link {
  visibility: visible;
}

/* Responsive Breakpoint: Tablet & Mobile (< 1000px) */
@media (max-width: 1000px) {
  .page {
    display: block; /* Stack everything vertically */
    padding: 0 20px;
  }

  .title-block,
  main {
    max-width: 100%; /* Allow content to fill the screen */
  }

  #TOC {
    position: relative;
    height: auto;
    width: 100%;
    border-right: none;
    border-bottom: 1px solid #ddd;
    margin-bottom: 2em;
    padding: 10px 0;
    background: #fdfdfd;
  }

  /* Close the TOC by default on mobile */
  #TOC details:not([open]) {
    margin-bottom: 0;
  }

  #TOC details summary {
    cursor: pointer;
    font-weight: bold;
    padding: 10px;
    background: #eee;
    list-style: none; /* Hides default arrow */
  }

  #TOC details summary::-webkit-details-marker {
    display: none;
  }

  #TOC details summary::before {
    content: "☰ "; /* Mobile menu icon */
  }
}

@media (min-width: 1001px) {
  #TOC {
    grid-area: toc;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
    padding: 40px 25px;
    border-right: 1px solid #ddd;
    box-sizing: border-box;
    background-color: #fafafa;
  }

  /* 1. Force the TOC list to show even if <details> is closed */
  #TOC details > ul,
  #TOC details > div {
    display: block !important;
  }

  /* 2. Style the summary to look like a static header, not a button */
  #TOC summary {
    display: block; /* Removes the 'list-item' arrow behavior */
    font-weight: bold;
    font-size: 1.1em;
    margin-bottom: 1em;
    cursor: default;
    pointer-events: none; /* Prevents accidental closing on desktop */
  }

  /* 3. Hide the arrow icon specifically for Chrome/Safari */
  #TOC summary::-webkit-details-marker {
    display: none;
  }
}

/* Math Styles */

.math.inline {
  font-family: inherit;
  /* background-color: #fffcf5; */
  padding: 0 0.15em;
  color: #222;
  /* vertical-align: middle; */
}

/* .math.display {
  display: block;
  font-family: inherit;
  background-color: #fffaf0;
  border-left: 2px solid #eaddca;
  color: #332d2d;
  text-align: left;
  overflow-x: auto;
  line-height: 1.2;
} */

/* Ensure complex symbols like ⟦ ⟧ don't look cramped */
.math {
  line-height: 1;
  letter-spacing: 0.02em;
}

.header-section-number::after {
  content: ".";
}

.toc-section-number::after {
  content: ".";
}

/* Strip MathJax default spacing */
mjx-container[display="true"] {
  margin: 0 !important;
  padding: 0 !important;
}

code {
  font-family:
    "SFMono-Regular", "Consolas", "Liberation Mono", "Menlo", monospace;
  font-size: 0.95em;
  background: #f8f8f8;
  padding: 2px 4px;
}

pre code {
  background: none;
  padding: 0;
}

pre,
.math.display,
.peg,
pre.peg {
  margin: 1em 0 1.5em 0;
  padding: 1em 1.5em;
  width: 100%;
  box-sizing: border-box;
  border-radius: 2px;
  overflow-x: auto;
  color: #332d2d;
}

pre {
  background: #f8f8f8;
  border-left: 4px solid #ccc;
  font-family: "SFMono-Regular", "Consolas", monospace;
  font-size: 0.9em;
}

.math.display {
  display: block;
  background-color: #fffaf0;
  border-left: 4px solid #eaddca;
  font-family: inherit;
  /* font-size: 0.9em; */
  text-align: left;
  line-height: 1.2;
}

.peg,
pre.peg {
  background-color: #f5faff;
  border-left: 4px solid #9eb1bc;
  font-family: "SFMono-Regular", "Consolas", monospace;
  font-size: 0.9em;
  white-space: pre;
}
