/* Web edition of Wirth, Algorithms + Data Structures = Programs.
   Layout and typography modelled on craftinginterpreters.com. */

:root {
  --text: #222;
  --light: #777;
  --lighter: #aaa;
  --rule: #e4e4e4;
  --link: #1481b8;
  --link-hover: #0b5e88;
  --accent: #c2410c;
  --code-bg: #f7f8f9;
  --nav-bg: #f3f3f3;
  --serif: 'Crimson Pro', 'Crimson Text', Georgia, serif;
  --sans: 'Source Sans 3', 'Source Sans Pro', 'Helvetica Neue', Arial, sans-serif;
  --mono: 'Source Code Pro', Menlo, Consolas, monospace;
  --col: 640px;      /* text column */
  --nav: 232px;      /* left navigation */
  --aside: 248px;    /* margin notes */
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: #fff;
  color: var(--text);
  font: 400 20px/1.55 var(--serif);
  font-feature-settings: "kern", "liga", "onum";
}
a { color: var(--link); text-decoration: none; }
a:hover { color: var(--link-hover); text-decoration: underline; }

/* ---------- navigation (left column) ---------- */
nav.wide {
  position: fixed; top: 0; left: 0; bottom: 0;
  width: var(--nav);
  padding: 24px 20px 24px 28px;
  background: var(--nav-bg);
  font: 400 15px/1.35 var(--sans);
  overflow-y: auto;
}
.logo {
  display: flex; flex-direction: column;
  font: 800 17px/1.08 var(--sans);
  letter-spacing: 0.02em; text-transform: uppercase;
  color: #111;
  margin-bottom: 26px;
}
.logo:hover { color: var(--accent); text-decoration: none; }
nav.wide h3 { font: 700 13px/1.3 var(--sans); text-transform: uppercase; letter-spacing: .05em; margin: 0 0 6px; }
nav.wide h3 a { color: var(--light); }
nav.wide h3.this a { color: #222; }
nav.wide h3.this { margin: 10px 0 10px; font-size: 15px; text-transform: none; letter-spacing: 0; }
nav.wide ul { list-style: none; padding: 0; margin: 0 0 22px; }
nav.wide li { margin: 0 0 7px; padding-left: 38px; text-indent: -38px; }
nav.wide li small { display: inline-block; width: 38px; text-indent: 0; color: var(--lighter); font-size: 13px; }
nav.wide li a { color: #444; }
nav.wide li a:hover { color: var(--link); }
.prev-next { display: flex; gap: 14px; font: 600 14px var(--sans); }
.prev-next .disabled { color: #ccc; }
nav.narrow { display: none; }

/* ---------- page ---------- */
.page {
  margin-left: var(--nav);
  padding: 0 calc(var(--aside) + 48px) 60px 72px;
  max-width: calc(var(--nav) + var(--col) + var(--aside) + 120px);
}
article.chapter { position: relative; max-width: var(--col); }

article header { padding-top: 64px; margin-bottom: 36px; }
article header .number {
  font: 800 60px/1 var(--sans);
  color: #e1e1e1;
  margin-bottom: 4px;
  letter-spacing: -0.01em;
}
article.part header .number { font-size: 96px; }
article header h1 {
  font: 700 46px/1.08 var(--serif);
  margin: 0;
  color: #111;
}

h2, h3, h4 { font-family: var(--sans); color: #111; }
article h2 { font-size: 26px; font-weight: 700; line-height: 1.2; margin: 52px 0 14px; }
article h3 { font-size: 21px; font-weight: 600; margin: 36px 0 10px; }
article h2 a.hl, article h3 a.hl { color: inherit; }

p { margin: 0 0 14px; hyphens: auto; -webkit-hyphens: auto; }
blockquote { margin: 18px 0 18px 28px; padding: 0; font-style: normal; }
ol, ul { padding-left: 30px; margin: 0 0 14px; }
li { margin-bottom: 6px; }
em, i { font-style: italic; }
strong, b { font-weight: 600; }
hr { border: 0; border-top: 1px solid var(--rule); margin: 30px 0; }

code {
  font: 400 0.8em var(--mono);
  background: var(--code-bg);
  padding: 1px 4px;
  border-radius: 3px;
  color: #333;
}

/* ---------- code listings ---------- */
.codehilite {
  position: relative;
  margin: 18px -16px 18px -16px;
  background: var(--code-bg);
  border-left: 3px solid #e4e7ea;
  border-radius: 2px;
}
.codehilite pre {
  margin: 0;
  padding: 12px 16px;
  font: 400 15px/1.5 var(--mono);
  overflow-x: auto;
  color: #333;
  tab-size: 4;
}
.codehilite .k { font-weight: 600; color: #0e2a6b; }
.codehilite .c { color: #8a8a8a; font-style: italic; }
.codehilite .s { color: #a3410f; }
.codehilite.text pre { color: #444; }
.eqno {
  position: absolute; top: 12px; right: -64px;
  font: 400 15px var(--serif); color: var(--light);
}
.caption {
  margin: -8px 0 22px;
  font: 400 15px/1.4 var(--sans);
  color: #555;
  text-align: center;
}
.caption strong { font-weight: 700; color: #333; }

/* ---------- figures from the scan ---------- */
figure { margin: 22px 0 26px; text-align: center; }
figure img {
  display: inline-block;
  max-width: 100%;
  height: auto;
  vertical-align: top;
}
figure.scan img { mix-blend-mode: multiply; }
figure img + img { margin-top: 6px; }
figcaption {
  margin-top: 10px;
  font: 400 15px/1.4 var(--sans);
  color: #555;
}
figcaption strong { color: #333; font-weight: 700; }

/* ---------- math ---------- */
.math-display { display: block; margin: 16px 0; overflow-x: auto; overflow-y: hidden; }
.katex { font-size: 1.02em; }
.katex-display { margin: 0; }

/* ---------- tables ---------- */
table { border-collapse: collapse; margin: 18px auto; font: 400 16px/1.4 var(--sans); }
th, td { padding: 4px 12px; border-bottom: 1px solid var(--rule); text-align: left; }
th { border-bottom: 2px solid #ccc; font-weight: 600; }

/* ---------- margin notes (footnotes) ---------- */
aside.note {
  float: right;
  clear: right;
  width: var(--aside);
  margin: 4px calc(-1 * var(--aside) - 48px) 12px 0;
  font: 400 14.5px/1.45 var(--sans);
  color: #666;
}
aside.note .note-num {
  display: inline-block;
  min-width: 16px;
  font-weight: 700; color: var(--accent);
  margin-right: 4px;
}
sup.fnref { font: 700 12px var(--sans); line-height: 0; }
sup.fnref a { color: var(--accent); padding: 0 1px; }

/* ---------- printed page numbers in the left gutter ---------- */
a.pg {
  position: absolute;
  left: -64px;
  width: 44px;
  text-align: right;
  font: 600 12px/2.4 var(--sans);
  color: #c8c8c8;
  letter-spacing: .02em;
}
a.pg::before { content: "p. "; font-weight: 400; }
a.pg:hover { color: var(--link); text-decoration: none; }
a.pg:target, a.pg:focus { color: var(--accent); }

/* ---------- part pages ---------- */
ol.part-sections { list-style: none; padding: 0; margin: 30px 0; font: 400 20px/1.4 var(--sans); }
ol.part-sections li { padding: 10px 0; border-bottom: 1px solid var(--rule); margin: 0; }
ol.part-sections .sn { display: inline-block; width: 64px; color: var(--lighter); font-weight: 600; }

/* ---------- footer ---------- */
article footer { margin-top: 60px; padding-top: 22px; border-top: 1px solid var(--rule); clear: both; }
.next-big { display: block; font: 600 20px/1.3 var(--sans); margin-bottom: 16px; }
.credit { font: 400 14px var(--sans); color: var(--lighter); }
.bottom-nav { display: none; }

/* ---------- table of contents ---------- */
.toc-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 48px; }
.toc-part h2 { font: 700 21px/1.25 var(--sans); margin: 18px 0 10px; }
.toc-part h2 .num { display: inline-block; min-width: 40px; color: #c9c9c9; }
.toc-part ul { list-style: none; padding: 0; margin: 0 0 18px; font: 400 17px/1.35 var(--sans); }
.toc-part li { margin: 0 0 6px; padding-left: 40px; text-indent: -40px; }
.toc-part li .num { display: inline-block; width: 40px; text-indent: 0; color: var(--lighter); font-size: 15px; }
article.toc { max-width: calc(var(--col) + var(--aside) + 48px); }

/* ---------- book index ---------- */
.book-index { columns: 2; column-gap: 40px; font: 400 16px/1.4 var(--sans); margin-top: 10px; }
.book-index .letter { font: 800 18px var(--sans); margin: 18px 0 6px; break-after: avoid; color: var(--accent); }
.book-index .letter:first-child { margin-top: 0; }
.book-index .ix { padding-left: 18px; text-indent: -18px; margin-bottom: 3px; break-inside: avoid; }
.book-index .ix.sub { padding-left: 36px; }
.book-index a.pg { display: none; }

/* ---------- home ---------- */
body.home { background: #f5f4f0; }
.home-wrap {
  max-width: 980px; margin: 0 auto; padding: 70px 32px;
  display: grid; grid-template-columns: 360px 1fr; gap: 64px; align-items: center;
  min-height: 100vh;
}
.cover {
  background: #fff;
  aspect-ratio: 249 / 323;
  padding: 44px 36px;
  box-shadow: 0 1px 2px rgba(0,0,0,.08), 0 12px 40px rgba(0,0,0,.12);
  display: flex; flex-direction: column;
}
.cover-title { display: flex; flex-direction: column; font: 800 32px/1.12 var(--sans); text-transform: uppercase; letter-spacing: .01em; color: #111; }
.cover-author { margin-top: auto; font: 800 18px var(--sans); text-transform: uppercase; letter-spacing: .04em; }
.cover-affil { margin-top: 6px; font: italic 400 15px/1.3 var(--serif); color: #555; }
.home-text .dedication { font: italic 400 26px var(--serif); margin: 0 0 6px; }
.home-text .imprint { font: 400 15px var(--sans); color: var(--light); margin-bottom: 30px; }
.home-links { display: flex; gap: 14px; flex-wrap: wrap; margin-bottom: 32px; }
.button { display: inline-block; padding: 10px 20px; border-radius: 4px; background: #111; color: #fff; font: 600 16px var(--sans); }
.button:hover { background: var(--accent); color: #fff; text-decoration: none; }
.button.ghost { background: transparent; color: #111; box-shadow: inset 0 0 0 2px #111; }
.button.ghost:hover { background: #111; color: #fff; }
.about { font: 400 16px/1.5 var(--sans); color: #666; max-width: 460px; }

/* ---------- responsive ---------- */
@media (max-width: 1340px) {
  .page { padding-right: 48px; }
  aside.note {
    float: none; width: auto; margin: 6px 0 18px;
    padding: 10px 14px; background: #faf8f4; border-left: 3px solid #ecdcc8;
  }
  .eqno { position: static; display: block; text-align: right; padding: 0 12px 8px; }
}
@media (max-width: 900px) {
  body { font-size: 18px; }
  nav.wide { display: none; }
  nav.narrow {
    display: flex; align-items: center; gap: 10px;
    position: sticky; top: 0; z-index: 10;
    padding: 10px 16px; background: var(--nav-bg);
    border-bottom: 1px solid var(--rule);
  }
  nav.narrow .logo { flex-direction: row; gap: 6px; flex-wrap: wrap; font-size: 13px; margin: 0; flex: 1; }
  nav.narrow .prev, nav.narrow .next { font: 700 22px var(--sans); padding: 0 6px; }
  .page { margin-left: 0; padding: 0 16px 40px 16px; }
  article header { padding-top: 28px; }
  article header h1 { font-size: 34px; }
  article header .number { font-size: 44px; }
  a.pg { position: static; display: inline-block; width: auto; line-height: 1; font-size: 11px; color: #bbb; margin: 0 4px; }
  .codehilite { margin-left: -16px; margin-right: -16px; }
  .codehilite pre { font-size: 13px; }
  .toc-grid { grid-template-columns: 1fr; }
  .book-index { columns: 1; }
  .bottom-nav { display: flex; justify-content: space-between; padding: 16px 0; }
  .home-wrap { grid-template-columns: 1fr; gap: 36px; padding: 32px 16px; }
  .cover { max-width: 320px; }
}
a.pg:target{outline:none;color:var(--accent)}
