/* The Little Opticist, as Scribble prints it.
   Set after the Little books: two voices in ruled frames, the question on
   the left, the answer on the right; text in Baskerville, programs in Gill
   Sans with their keywords bold; laws in boxes. Black on white, nothing else.
   One sheet serves the website (one page a chapter) and the printed book
   (one long page, cut by the @page rules at the bottom). */

:root {
  --ink: #000;
  --serif: Baskerville, "Baskerville Old Face", "Libre Baskerville", "Hoefler Text", "Iowan Old Style", Palatino, Georgia, serif;
  --sans: "Gill Sans", "Gill Sans MT", "Gill Sans Nova", "Avenir Next", Optima, "Segoe UI", "Helvetica Neue", sans-serif;
  --measure: 48rem;   /* on paper, 172mm: the same forty ems of text */
}
* { box-sizing: border-box; }
html { background: #fff; -webkit-text-size-adjust: 100%; }
body { margin: 0; color: var(--ink); background: #fff; }

/* ---- Scribble's own furniture, put away ---- */
.tocset, #contextindicator, .versionbox, .button-group, .nosearchform, .tocsettoggle, .SAuthorListBox { display: none; }
.maincolumn { width: auto; max-width: var(--measure); margin: 0 auto; padding: 0 16px 20mm; }
.maincolumn, .main { font-family: var(--serif); }
.main { font-size: 18px; line-height: 1.4; font-kerning: normal; font-variant-ligatures: common-ligatures;
        font-variant-numeric: lining-nums; text-align: left; }
.main p, .main .SIntrapara { margin: 0 0 .5em; }
.main a { color: inherit; text-decoration: none; }
.main a:hover { text-decoration: underline; }
.main .emph { font-style: italic; }
.main b, .main strong { font-weight: 600; }
.main .heading { font: inherit; margin: 0; }

/* prev, up, next: three equal thirds of the measure, so that prev starts
   where the text starts, up sits over its middle and next ends where it
   ends. Scribble puts spaces between the three; at size 0 they take no room. */
.navsettop, .navsetbottom, .LOnav { background: none; border: 0; padding: 4mm 0; margin: 0; font-family: var(--sans);
                                    letter-spacing: .04em; overflow: hidden; font-size: 0; }
.navsetbottom, .LOnav.LOfoot { border-top: .5pt solid var(--ink); margin-top: 12mm; }
.navleft { display: none; }
.navright, .LOnav { float: none; display: flex; margin: 0; white-space: normal; }
.navright > *, .LOnav > * { flex: 1 1 0; font-size: 13px; text-align: center; }
.navright > :first-child, .LOnav > :first-child { text-align: left; }
.navright > :last-child, .LOnav > :last-child { text-align: right; }
.nonavigation, .LOnav .LOnowhere { visibility: hidden; }

/* a page that is more than the book keeps its own title and sections plain */
.SsectionLevel1 > h1.heading:not(:has(.LObook)) { text-align: center; font-variant: small-caps; letter-spacing: .2em;
                                                  font-size: 1.1em; margin: 10mm 0 3mm; }
.main .SsectionLevel2 > h2.heading:not(:has(.LOtitle)) { text-align: left; font-style: italic; font-size: 1.33em; margin: 12mm 0 3mm; }

/* one long page, read a chapter at a time: what is not being read is away.
   Only on a screen, and only once press.js has said so; paper gets it all. */
.LOpaged { display: none; }
@media screen { .LOaway { display: none !important; } }
/* a link to a chapter lands on its heading; leave room above for prev and next */
.LOpaging .SsectionLevel2 > .heading a[name] { scroll-margin-top: 60mm; }

/* ---- the cover ---- */
.LObook, .main p.LObook { display: block; font-size: 2.9em; line-height: 1; text-align: center; margin: 18mm 0 5mm; letter-spacing: .015em; }
.LOcover { text-align: center; margin: 0 0 12mm; }
.main .LOcover p { margin: 0; }
.LOcover .LOsub { font-style: italic; font-size: 1.2em; }
.LOcover .LOsub::after { content: ""; display: block; width: 24mm; border-top: .6pt solid var(--ink); margin: 6mm auto 0; }
.LOcover .LOart img { display: block; width: min(184mm, 100%); height: auto; margin: 3mm auto 0; }
.LOcover .LOauthor { font-size: 1.25em; font-variant: small-caps; letter-spacing: .2em; margin-top: 5mm; }
.LOcover .LOmotto { font-family: var(--sans); font-size: .8em; margin-top: 12mm; }

/* ---- the contents ---- */
.LOcontents { margin: 0 0 10mm; columns: 2; column-gap: 12mm; }
.main p.LOcontentshead { font-size: 1.8em; font-style: italic; margin: 10mm 0 8mm; }
.main .LOcontents p { margin: 0 0 1.6mm; break-inside: avoid; }
.LOcontents .LOnum { display: inline-block; min-width: 7mm; }
.LOcontents .LOkind { font-style: italic; }
.LOcontents .LOkind::after { content: ":"; }
.main p.LOcolophon { font-size: .88em; font-style: italic; max-width: 120mm; margin: 14mm auto 0; text-align: center; }
.LOcolophon::before { content: ""; display: block; width: 24mm; border-top: .6pt solid var(--ink); margin: 0 auto 5mm; }
.main p.LOdownloads { text-align: center; font-family: var(--sans); font-size: .8em; letter-spacing: .04em; margin: 8mm 0 0; }
.main .LOdownloads a { text-decoration: underline; }

/* ---- a chapter opens ---- */
.SsectionLevel2 > .heading { text-align: center; margin: 12mm 0 5mm; }
.heading .LOnum { display: block; font-size: 4.5em; line-height: 1; margin-bottom: 4mm; }
.heading .LOkind { display: block; font-variant: small-caps; letter-spacing: .14em; margin-bottom: 4mm; }
.heading .LOtitle { display: block; font-style: italic; font-size: 2.25em; line-height: 1.1; }
.main p.LOlede { text-align: center; font-style: italic; font-size: 1.04em; margin: 0 auto 11mm; max-width: 120mm; }
.LOlede::after { content: ""; display: block; width: 24mm; border-top: .6pt solid var(--ink); margin: 6mm auto 0; }
.heading .LOhead { display: block; font-style: italic; font-size: 1.33em; margin: 9mm 0 3mm; }

/* ---- the frame: a rule, a question, an answer ---- */
.LOframe { display: grid; grid-template-columns: 1fr 1fr; column-gap: 8mm; border-top: .5pt solid var(--ink);
           padding: 2.6mm 0 2.2mm; margin: 0; break-inside: avoid; }
.LOframe > div { min-width: 0; margin: 0; }
.LOframe > div > :last-child { margin-bottom: 0; }
.LOframe:has(+ :not(.LOframe)), .LOframe:last-child { border-bottom: .5pt solid var(--ink); margin-bottom: 5mm; }
:not(.LOframe) + .LOframe { margin-top: 5mm; }

/* ---- programs ---- */
.LOcode, .LOprogram { font-family: var(--sans); font-variant-numeric: lining-nums; font-variant-ligatures: none; }
.LOcode { font-size: .93em; }
.LOprogram { margin: 1.6mm 0 2.2mm; font-size: .85em; line-height: 1.28; }
.LOln { white-space: pre-wrap; overflow-wrap: anywhere; min-height: 1.28em; margin: 0; }
.LOln b { font-weight: 600; }
.LOln .LOcm { font-style: italic; }
.LOind { display: inline-block; white-space: pre; overflow: hidden; vertical-align: top; }
.LOrepl .LOtyped::first-letter { font-weight: 600; }
.LOsketch, .LOlook { border-left: .5pt solid var(--ink); padding-left: 2.4mm; }
.main p.LOfilename { font-family: var(--sans); font-size: .83em; margin: 7mm 0 1mm; font-weight: 600; }
.LOkit { font-size: .75em; }

/* ---- laws and commandments stand in boxes ---- */
.LOlaw { margin: 6mm auto; padding: 3.2mm 6mm 3.4mm; border: .8pt solid var(--ink); max-width: 118mm; text-align: center; break-inside: avoid; }
.main .LOlaw p { margin: 0; }
.main .LOlaw p.LOlawname { font-weight: 600; font-size: 1.04em; margin-bottom: 1.2mm; }
.main .LOlaw p + p { margin-top: 1mm; }
.main .LOlaw p.LOlawname + p { margin-top: 0; }

.main p.LOsnack { text-align: center; font-style: italic; margin: 8mm 0; }
.LOsnack::before { content: "\2766"; display: block; font-style: normal; font-size: 1.08em; margin-bottom: 1.5mm; }

/* ---- exercises, tables, figures, lists ---- */
.LOexercises { margin: 10mm 0 0; font-size: .92em; }
.main p.LOexhead { font-variant: small-caps; letter-spacing: .12em; font-size: 1.09em; text-align: center; margin: 0 0 3mm; }
.LOexhead::before { content: ""; display: block; width: 100%; border-top: .6pt solid var(--ink); margin-bottom: 5mm; }
.LOex { font-weight: 600; }
table.LOgrid { border-collapse: collapse; margin: 4mm auto 6mm; font-size: .88em; line-height: 1.3; width: 100%; }
table.LOgrid td { vertical-align: top; padding: 1.1mm 2mm 1.1mm 0; border-bottom: .25pt solid var(--ink); }
table.LOgrid:not(.LOplain) tr:first-child td { font-variant: small-caps; letter-spacing: .08em; border-bottom: .6pt solid var(--ink); }
table.LOgrid tr { break-inside: avoid; }
.main table.LOgrid p { margin: 0; }
.LOfigure { margin: 6mm 0; text-align: center; break-inside: avoid; }
.LOfigure img { max-width: 100%; height: auto; }
.main p.LOcaption { font-style: italic; font-size: .875em; margin-top: 2mm; }
.main ul, .main ol { margin: 0 0 .5em; padding-left: 5mm; }

/* ---- a narrow screen: the answer goes under the question ---- */
@media screen and (max-width: 640px) {
  .main { font-size: 17px; }
  .LOframe { grid-template-columns: 1fr; row-gap: 1.5mm; }
  .LOframe > .LOanswer { padding-left: 5mm; }
  .LOcontents { columns: 1; }
  .heading .LOnum { font-size: 3.4em; }
  .heading .LOtitle { font-size: 1.8em; }
}

/* ---- paper ---- */
@page { size: A4; margin: 22mm 19mm 24mm 19mm;
        @bottom-center { content: counter(page); font-family: Baskerville, Georgia, serif; font-size: 10pt; } }
@page :first { @bottom-center { content: ""; } }
@media print {
  .navsettop, .navsetbottom, .LOnav, .main p.LOdownloads { display: none; }
  .maincolumn { max-width: none; padding: 0; margin: 0; width: 172mm; }
  .main { font-size: 12pt; line-height: 1.36; }
  .main a:hover { text-decoration: none; }
  /* on paper the page is the book alone: the site's own title, its line and
     its sections that are not chapters stay behind */
  .SsectionLevel1 > h1.heading, .SsectionLevel1 > p.LOlede,
  .SsectionLevel2:not(:has(.LOtitle)) { display: none; }
  /* the cover has the whole first page */
  .main p.LObook { margin: 0 0 5mm; padding-top: 4mm; font-size: 46pt; }
  .LOcover { height: 250mm; margin: 0; display: flex; flex-direction: column; align-items: center; break-after: page; }
  .LOcover .LOsub { font-size: 14.5pt; }
  .LOcover .LOart img { width: 172mm; max-width: none; margin-top: 2mm; }
  .LOcover .LOauthor { font-size: 15pt; }
  .LOcover .LOmotto { font-size: 9.5pt; margin-top: auto; }
  .main p.LOcontentshead { margin-top: 18mm; }
  .SsectionLevel2 { break-before: page; }
  .SsectionLevel2 > .heading { margin-top: 20mm; }
  .heading .LOnum { font-size: 54pt; }
  .heading .LOtitle { font-size: 27pt; }
  .heading .LOhead { break-after: avoid; }
}
