/*
 * site.css -- the one stylesheet for the CS 434 site: home page,
 * doc pages (lab, codegen, ...), and handouts (hw, pa, icspec).
 *
 * A standalone "clean document" style: a slim sticky blue header on
 * every page, a readable article column, and (on handout/doc pages)
 * a sticky, always-visible TOC in the left margin.  No framework
 * dependencies.
 */

:root {
  --measure: 46em;            /* article column width */
  --measure-wide: 62em;       /* home page column width */
  --toc-width: 16em;
  --col-gap: 2.5rem;          /* grid column gap (3 gaps across the 4 tracks) */
  /* Widest the content column may grow before the fixed TOC track plus the
     three column gaps would push past the right edge of the viewport. */
  --content-cap: calc(100% - var(--toc-width) - 3 * var(--col-gap));
  --header: #284366;          /* the course blue */
  --accent: #284366;
  --accent-soft: #3e5f8a;
  --rule: #d5d9e0;
  --ink: #1c1b1f;
  --ink-soft: #5b5f68;
  --paper: #ffffff;
  --code-bg: #f6f8fa;
  --sol-edge: #2e7d32; --sol-bg: #f2f8f2;
  --hint-edge: #f9a825; --hint-bg: #fffcf0;
  --note-edge: #1565c0; --note-bg: #f1f6fc;
  --obj-edge: #2e7d32; --obj-bg: #f2f8f2;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  color: var(--ink);
  background: var(--paper);
  font: 17px/1.55 "Charter", "Georgia", "Times New Roman", serif;
  display: grid;
  /* tracks: margin | TOC | content | margin */
  grid-template-columns: 1fr var(--toc-width) min(var(--measure), var(--content-cap)) 1fr;
  column-gap: var(--col-gap);
}

/*--------------------------- site header ---------------------------*/

header.site-header {
  grid-column: 1 / -1;
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.25rem 1.4rem;
  padding: 0.55rem 1.25rem;
  background: var(--header);
  color: #fff;
  font-family: system-ui, -apple-system, "Helvetica Neue", sans-serif;
  font-size: 0.9rem;
}
header.site-header a { color: #fff; text-decoration: none; }
header.site-header a:hover { text-decoration: underline; }
header.site-header .brand { font-weight: 650; margin-right: 0.6rem; }
header.site-header nav.site-nav { display: flex; flex-wrap: wrap; gap: 0 1.1rem; }
header.site-header .external {
  margin-left: auto;
  display: flex;
  gap: 0 1.1rem;
  opacity: 0.85;
}
header.site-header .term { opacity: 0.85; }

/*----------------------------- article -----------------------------*/

/* The page title (h1 + due line) is its own grid block so the
   narrow-screen layout can slot the TOC between it and the article. */
#page-title {
  grid-column: 3;
  grid-row: 2;
  min-width: 0;
  padding-top: 1.5rem;
}

main {
  grid-column: 3;
  grid-row: 3;
  min-width: 0;
  padding: 0 0 4rem;
}

.banner { margin: 0.5rem 0 1rem; }
.banner img { width: 100%; height: auto; display: block; }

main h1, #page-title h1 {
  font-family: system-ui, -apple-system, "Helvetica Neue", sans-serif;
  font-size: 1.9rem;
  line-height: 1.2;
  margin: 0.4em 0 0.1em;
  letter-spacing: -0.01em;
}
p.due {
  margin: 0 0 1.5em;
  color: var(--ink-soft);
  font-style: italic;
}
/* Intermediate checkpoints: a small indented block under the Due line,
   in the same quiet voice. */
.milestones {
  margin: -1.1em 0 1.5em;
  font-size: 0.85rem;
  color: var(--ink-soft);
  font-style: italic;
}
.milestones ul { list-style: none; margin: 0; padding-left: 1.5em; }
.milestones li { margin: 0.1em 0; }

main h2 {
  font-family: system-ui, -apple-system, "Helvetica Neue", sans-serif;
  font-size: 1.3rem;
  margin: 2em 0 0.6em;
  padding-bottom: 0.25em;
  border-bottom: 2px solid var(--rule);
}
main h3 {
  font-family: system-ui, -apple-system, "Helvetica Neue", sans-serif;
  font-size: 1.05rem;
  margin: 1em 0 -1em;
}
main h4 {
  font-family: system-ui, -apple-system, "Helvetica Neue", sans-serif;
  font-size: 1rem;
  margin: 1.4em 0 0.4em;
}

main a { color: var(--accent); }
main a:hover { color: var(--accent-soft); }

ol > li::marker { font-weight: 600; }

/*------------------------------- code ------------------------------*/

code, pre, kbd {
  font-family: "SF Mono", "Menlo", "Consolas", monospace;
  font-size: 0.86em;
}
code { background: var(--code-bg); padding: 0.1em 0.3em; border-radius: 3px; }
pre {
  background: var(--code-bg);
  border: 1px solid var(--rule);
  border-radius: 6px;
  padding: 0.8em 1em;
  overflow-x: auto;
  line-height: 1.4;
}
pre code { background: none; padding: 0; }

/* grammar blocks (icspec) */
pre.grammar { background: #fbfaf7; }

/*------------------------------ tables -----------------------------*/

table {
  border-collapse: collapse;
  margin: 1em 0;
  font-size: 0.95em;
}
th, td {
  border: 1px solid var(--rule);
  padding: 0.3em 0.7em;
  text-align: left;
  vertical-align: top;
}
th { background: #eef1f6; font-family: system-ui, sans-serif; font-size: 0.85em; }

/* borderless layout tables */
table.plain th, table.plain td { border: none; }

/* wide content (parse traces, big tables): scroll, don't squeeze */
.wide { max-width: 100%; overflow-x: auto; }
.wide table { min-width: max-content; }

/* aside under a reading entry (handout.lua's ::: readings ::: list);
   the span starts its own line after a <br/>, and inline-block keeps
   wrapped note lines indented too */
.reading-note { font-style: italic; display: inline-block; margin-left: 1.25em; }

/*----------------------------- callouts ----------------------------*/

.callout {
  border-left: 4px solid var(--rule);
  border-radius: 6px;
  padding: 0.75em 1em;
  margin: 1em 0;
  background: #f7f7f8;
}
.callout .callout-title {
  font-family: system-ui, -apple-system, sans-serif;
  font-weight: 650;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 0.4em;
}
.callout > :last-child { margin-bottom: 0; }

.callout.solution { border-color: var(--sol-edge); background: var(--sol-bg); }
.callout.solution .callout-title { color: var(--sol-edge); }
.callout.hint { border-color: var(--hint-edge); background: var(--hint-bg); }
.callout.hint .callout-title { color: #9c7000; }
.callout.note { border-color: var(--note-edge); background: var(--note-bg); }
.callout.note .callout-title { color: var(--note-edge); }
.callout.objectives { border-color: var(--obj-edge); background: var(--obj-bg); }
.callout.objectives .callout-title { color: var(--obj-edge); }

/*------------------------------ figures ----------------------------*/

figure { margin: 1.2em auto; text-align: center; }
p > img { display: block; margin: 1.2em auto; }
main img { width: 75%; max-width: 100%; height: auto; }
figcaption { font-size: 0.85em; color: var(--ink-soft); }

/*-------------------------------- TOC ------------------------------*/

nav#toc {
  grid-column: 2;
  grid-row: 2 / 4;             /* beside the title row and the article */
  position: sticky;
  top: 3.2rem;
  align-self: start;
  max-height: calc(100vh - 4rem);
  overflow-y: auto;
  padding: 1.5rem 0 1rem 0.5rem;
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 0.8rem;
  line-height: 1.5;
}
nav#toc .toc-title { font-weight: 700; color: var(--ink); margin: 0 0 0.5em; }
nav#toc ul { list-style: none; margin: 0; padding-left: 0; }
nav#toc ul ul { padding-left: 1em; }
nav#toc li { margin: 0.25em 0; }
nav#toc a { color: var(--ink-soft); text-decoration: none; }
nav#toc a:hover { color: var(--accent); }

/* course logo: sits above the TOC in the left margin on every page */
#toc-logo-pic { display: block; }
#toc-logo {
  display: block;
  width: 100%;
  height: auto;
  margin: 0 0 1.2rem;
}

/*----------------------------- home page ---------------------------*/

body.home {
  grid-template-columns: 1fr var(--toc-width) min(var(--measure-wide), var(--content-cap)) 1fr;
}
body.home main, body.home #page-title { grid-column: 3; }

/* hero block on the home page (::: hero in index.md) */
.hero {
  background: #eef1f6;
  border-radius: 8px;
  padding: 1.2rem 2rem;
  margin: 1.5rem 0;
}

/* Per-week headings exist only to give each calendar card a TOC entry
   and an anchor: visually hidden, but kept in flow position so the
   TOC link scrolls to the card (scroll-margin clears the sticky
   header). */
.toc-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: 0;
  padding: 0;
  border: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  scroll-margin-top: 3.5rem;
}

/* calendar week cards (WEEK_ENTRY macro keeps its .card markup) */
.card {
  border: 1px solid var(--rule);
  border-radius: 8px;
  margin: 1em 0;
  overflow: hidden;
}
.card-header {
  background: #e9ecf1;
  color: var(--ink);
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 0.95rem;
  padding: 0.5em 1em;
}
.card-body { padding: 0.8em 1em; }
.card-body table, .card-body th, .card-body td { border: none; }
.card-body th {
  background: none;
  color: var(--ink-soft);
  white-space: nowrap;
  padding-right: 1.6em;        /* gap between the label and the list */
  /* The label is set smaller than the body text, so give its line box the
     height of one body line: that puts its baseline on the first bullet's. */
  line-height: calc(1.55 / 0.85);
}
.card ul, .card li { margin: 0.15em 0; }
.card-body ul { margin: 0; padding-left: 1.1em; }
.card-body ul ul { margin: 0.1em 0 0.35em; }
.card-body li:first-child { margin-top: 0; }   /* keeps it level with the label */

/*----------------------------- narrow screens ----------------------*/

@media (max-width: 68em) {
  /* Two gaps remain in the 3-track layout; cap the content column so the
     tracks plus gaps never exceed the viewport. */
  body, body.home { grid-template-columns: 1fr min(var(--measure), calc(100% - 2 * var(--col-gap))) 1fr; }
  #page-title, main, body.home #page-title, body.home main { grid-column: 2; }
  main { grid-row: 3; }
  nav#toc {
    grid-column: 2;
    grid-row: 3;               /* below the page title... */
    position: static;
    max-height: none;
    border: 1px solid var(--rule);
    border-radius: 6px;
    padding: 0.6rem 1rem;
    margin-top: 1rem;
  }
  nav#toc ~ main { grid-row: 4; }   /* ...and above the article */

  /* The logo moves inside the TOC box, to the left of the text.  It is
     positioned, so it never makes the box any taller than the text: it
     shrinks to the text's height (object-fit keeps it square). */
  nav#toc {
    position: relative;        /* containing block for the logo */
    top: auto;                 /* drop the sticky offset from the base rule */
    padding-left: 9.5rem;
    min-height: 9.2rem;        /* the logo's minimum height plus padding */
  }
  #toc-logo {
    position: absolute;
    left: 0.9rem;
    top: 0.6rem;
    width: 8rem;
    height: calc(100% - 1.2rem);
    margin: 0;
    object-fit: contain;
    object-position: left top;
  }
}

/*-------------------------------- print ----------------------------*/

@media print {
  body { display: block; font-size: 11pt; }
  header.site-header, nav#toc { display: none; }
  main { max-width: none; padding: 0; }
  .callout, pre, table, figure { break-inside: avoid; }
  main a { color: inherit; text-decoration: none; }
  .banner { max-height: 1.2in; overflow: hidden; }
}
