/*
  site.css: the book's website, built by scripts/build_site.py.
  Colours, type and the tm- components come from tm.css; the rules are in design-guide.html.
  No rounded corners, cards, boxes behind text or motion.
*/

:root {
  color-scheme: light;
  --measure: 700px; /* about 80 characters of the 19px serif text */
  --header: 73px; /* the sticky header's height, which the player and sidebar stick below */
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--tm-white); color: var(--tm-ink); font: 400 15px/1.65 var(--tm-ui); }
a { color: var(--tm-violet); }
a:focus-visible { outline: 3px solid var(--tm-ink); outline-offset: 2px; }
img { max-width: 100%; height: auto; }

.tm-wrap { max-width: 1120px; }

.skip { position: absolute; left: -9999px; top: 0; padding: 8px 12px; background: var(--tm-white); z-index: 10; }
.skip:focus { left: 16px; }

/* ---------- Home ---------- */

.page-title { margin: 48px 0 16px; font: 700 clamp(26px, 3.6vw, 38px)/1.2 var(--tm-ui); color: var(--tm-ink); }

.home section { padding-block: 48px 8px; border-top: 1px solid var(--tm-line); }
.home section:first-child { border-top: 0; }
.intro { max-width: var(--measure); font-size: 19px; }
.intro p { margin: 0 0 16px; }
.intro .tm-button { margin-top: 8px; color: var(--tm-white); text-decoration: none; }
.intro .tm-button:hover { background: var(--tm-ink); }

.contents { list-style: none; margin: 16px 0 0; padding: 0; max-width: 820px; }
.contents li { border-bottom: 1px solid var(--tm-line); }
.contents li > a, .contents li.forthcoming { display: grid; grid-template-columns: 11em 1fr auto; gap: 4px 20px; align-items: baseline; padding: 14px 0; }
.contents a { color: var(--tm-ink); text-decoration: none; }
.contents a:hover .title, .contents a:focus-visible .title { color: var(--tm-violet); text-decoration: underline; }
.contents a[aria-current="page"] .title { color: var(--tm-violet); }
.contents .label { font-size: 12px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--tm-muted); }
.contents .title { font: 400 19px/1.35 var(--tm-serif); }
.contents .date { font-size: 13px; color: var(--tm-muted); white-space: nowrap; }
.contents .forthcoming .title { color: var(--tm-muted); }
.home .contents li:last-child { border-bottom: 0; } /* the section's own rule follows */

.people { display: flex; flex-wrap: wrap; gap: 32px; align-items: flex-end; margin: 16px 0 16px; }
.people figure { margin: 0; display: grid; justify-items: center; gap: 8px; font-size: 13px; }
/* The original portraits, square-cropped: background removal cut off hair */
.people .portrait { width: 220px; height: 220px; background: var(--tm-tint); overflow: hidden; }
.people img { display: block; width: 100%; height: 100%; object-fit: cover; object-position: center top; }

/* ---------- Chapter ---------- */

.masthead { position: sticky; top: 0; z-index: 10; background: var(--tm-white); border-bottom: 1px solid var(--tm-line); }
.masthead .tm-wrap { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding-block: 16px; }
.masthead-actions { display: flex; align-items: center; gap: 12px; }
.search-box input { width: 220px; height: 38px; padding: 0 12px; border: 1px solid var(--tm-line); border-radius: 0; background: var(--tm-white); color: var(--tm-ink); font: 400 13px/1.2 var(--tm-ui); }
.search-box input:focus { outline: 2px solid var(--tm-violet); outline-offset: -1px; border-color: var(--tm-violet); }
.search-box { position: relative; }
.search-results { position: absolute; right: 0; top: calc(100% + 6px); z-index: 20; width: min(440px, 90vw); max-height: 70vh; overflow-y: auto; background: var(--tm-white); border: 1px solid var(--tm-line); box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12); }
.search-results[hidden] { display: none; }
.search-results .result { display: block; padding: 12px 14px; border-bottom: 1px solid var(--tm-line); color: var(--tm-ink); text-decoration: none; }
.search-results .result:hover, .search-results .result:focus { background: var(--tm-tint); outline: none; }
.search-results .label { display: block; font: 400 11px/1.4 var(--tm-ui); letter-spacing: 0.08em; text-transform: uppercase; color: var(--tm-muted); }
.search-results .title { display: block; font: 600 16px/1.3 var(--tm-serif); }
.search-results .excerpt { display: block; margin-top: 4px; font: 400 14px/1.45 var(--tm-serif); color: var(--tm-muted); }
.search-results mark { background: none; color: var(--tm-violet); font-weight: 600; }
.search-results .all, .search-results .none { display: block; margin: 0; padding: 10px 14px; font: 700 12px/1.3 var(--tm-ui); color: var(--tm-violet); text-decoration: none; }
.search-results .none { color: var(--tm-muted); font-weight: 400; }
.search-results .all:hover, .search-results .all:focus { background: var(--tm-tint); outline: none; }
.search-link { display: none; align-items: center; justify-content: center; width: 38px; height: 38px; color: var(--tm-violet); }
@media (max-width: 760px) { .search-box { display: none; } .search-link { display: inline-flex; } }
.search-page { max-width: var(--measure); margin-inline: auto; padding-bottom: 32px; }
/* Pagefind's search UI, in the site's colours and type */
.search-page {
  --pagefind-ui-scale: 0.9;
  --pagefind-ui-primary: var(--tm-violet);
  --pagefind-ui-text: var(--tm-ink);
  --pagefind-ui-background: var(--tm-white);
  --pagefind-ui-border: var(--tm-line);
  --pagefind-ui-tag: var(--tm-tint);
  --pagefind-ui-border-width: 1px;
  --pagefind-ui-border-radius: 0;
  --pagefind-ui-font: var(--tm-ui);
}
.search-page .pagefind-ui__result-title { font-family: var(--tm-serif); }
.search-page .pagefind-ui__result-excerpt { font-family: var(--tm-serif); font-size: 17px; }
.search-page .pagefind-ui mark { background: var(--tm-tint); color: var(--tm-violet); font-weight: 600; }
.search-page .pagefind-ui__result-tags { display: none !important; }
.masthead .subscribe { display: inline-flex; align-items: center; height: 38px; padding: 0 16px; background: var(--tm-violet); color: var(--tm-white); font: 700 13px/1.2 var(--tm-ui); text-decoration: none; white-space: nowrap; }
.masthead .subscribe:hover { background: var(--tm-ink); }
@media (max-width: 520px) { :root { --header: 76px; } .masthead .subscribe .long { display: none; } .masthead .brand span { font-size: 13px; } }
.masthead h1 { margin: 0; font: inherit; }
.masthead .brand { font-size: 15px; }
.brand:hover span { text-decoration: underline; }

.chapter { max-width: var(--measure); margin-inline: auto; padding-top: 48px; }
.chapter > h1 { margin: 0 0 12px; font: 700 clamp(26px, 3.6vw, 38px)/1.2 var(--tm-ui); color: var(--tm-ink); text-wrap: balance; overflow-wrap: break-word; }
.byline { margin: 0 0 32px; font-size: 13px; color: var(--tm-muted); }

.text { font-size: 19px; line-height: 1.65; overflow-wrap: break-word; }
.text p { margin: 0 0 1.1em; }
.text h1, .text h2, .text h3, .text h4 { margin: 2em 0 0.6em; font: 700 22px/1.25 var(--tm-ui); text-wrap: balance; }
.text h3, .text h4 { font-size: 17px; }
.text ul, .text ol { padding-left: 1.4em; margin: 0 0 1.1em; }
.text li { margin-bottom: 0.4em; }
.text li > p { margin: 0; }
.text blockquote { margin: 0 0 1.1em; padding-left: 1.1em; border-left: 3px solid var(--tm-heliotrope); color: var(--tm-ink); }
.text hr { border: 0; height: 1px; background: var(--tm-line); margin: 2.2em auto; width: 40%; }
.text img { display: block; margin: 1.5em auto; }
.text figure { margin: 1.5em 0; }
.text code { font: 400 0.85em var(--tm-ui); background: var(--tm-tint); padding: 1px 4px; }
.text table { border-collapse: collapse; font-size: 16px; display: block; overflow-x: auto; }
.text th, .text td { text-align: left; padding: 6px 12px 6px 0; border-bottom: 1px solid var(--tm-line); vertical-align: top; }

.pager { max-width: var(--measure); margin: 48px auto 0; padding-top: 24px; border-top: 1px solid var(--tm-line); display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }
.pager a { display: block; color: var(--tm-ink); text-decoration: none; font: 400 17px/1.35 var(--tm-serif); }
.pager a:hover { color: var(--tm-violet); text-decoration: underline; }
.pager .next { text-align: right; }
.pager .tm-eyebrow { display: block; }

.chapter-contents { max-width: var(--measure); margin: 32px auto 0; }
.chapter-contents summary { cursor: pointer; font-size: 13px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--tm-violet); }
.chapter-contents .contents li > a, .chapter-contents .contents li.forthcoming { grid-template-columns: 1fr; gap: 0; padding: 10px 0; }
.chapter-contents .contents .title { font-size: 17px; }
.chapter-contents .contents .date { display: none; }

/* ---------- Sidebar: every chapter, and the current one's sections (wide screens only) ---------- */

.sidebar { display: none; }
.sidebar nav { position: sticky; top: var(--header); max-height: calc(100vh - var(--header)); overflow-y: auto; scrollbar-width: thin; padding: 48px 4px 32px 0; }
.sidebar .tm-eyebrow a { color: inherit; text-decoration: none; }
.sidebar .tm-eyebrow a:hover { color: var(--tm-violet); }
.sidebar ol { list-style: none; margin: 0; padding: 0; }
.sidebar li { margin: 0; }
.sidebar nav > ol > li > a, .sidebar .forthcoming { display: block; padding: 7px 0; color: var(--tm-ink); text-decoration: none; }
.sidebar .label { display: block; font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--tm-muted); }
.sidebar .title { display: block; font: 400 15px/1.3 var(--tm-serif); }
.sidebar a:hover .title { color: var(--tm-violet); text-decoration: underline; }
.sidebar a[aria-current="page"] .title { color: var(--tm-violet); font-weight: 600; }
.sidebar .forthcoming .title { color: var(--tm-muted); }
.sidebar .sections { margin: 2px 0 6px; border-left: 2px solid var(--tm-line); }
.sidebar .sections a { display: block; padding: 4px 0 4px 12px; margin-left: -2px; border-left: 2px solid transparent; font-size: 12px; line-height: 1.4; color: var(--tm-muted); text-decoration: none; }
.sidebar .sections a:hover { color: var(--tm-violet); }
.sidebar .sections a.current { color: var(--tm-violet); border-left-color: var(--tm-violet); }
/* Clear of the sticky header and player, whose heights player.js measures */
.text h2, .text [id^="p-"] { scroll-margin-top: calc(var(--header) + var(--stuck-player, 140px) + 24px); }
/* A search result's paragraph: a tint behind the text, which fades out after a moment */
.text [id^="p-"]:target { position: relative; isolation: isolate; }
.text [id^="p-"]:target::before { content: ""; position: absolute; z-index: -1; inset: 0 -12px; background: var(--tm-tint); animation: tm-fade 3s ease-out 1s both; }
@keyframes tm-fade { from { opacity: 1; } to { opacity: 0; } }

@media (min-width: 1100px) {
  .with-sidebar { display: grid; grid-template-columns: 230px minmax(0, 1fr); column-gap: 56px; align-items: start; }
  .with-sidebar > .sidebar { display: block; grid-column: 1; grid-row: 1 / span 3; align-self: stretch; }
  .with-sidebar > :not(.sidebar) { grid-column: 2; }
  .with-sidebar .chapter-contents { display: none; }
}

/* ---------- Footer ---------- */

.site-footer { margin-top: 72px; padding-block: 24px 40px; border-top: 1px solid var(--tm-line); font-size: 13px; color: var(--tm-muted); }
.site-footer p { margin: 8px 0 0; max-width: var(--measure); }
.brand { display: inline-flex; align-items: center; gap: 12px; color: var(--tm-ink); text-decoration: none; font-weight: 700; }

@media (max-width: 640px) {
  .contents li > a, .contents li.forthcoming { grid-template-columns: 1fr; gap: 2px; }
  .text { font-size: 18px; }
  .people .portrait { width: 160px; height: 160px; }
  .pager { grid-template-columns: 1fr; }
  .pager .next { text-align: left; }
}

@media print {
  .masthead, .pager, .chapter-contents, .site-footer, .skip { display: none; }
}

/* ---------- Audio player ---------- */

/* Sticks to the top of the window once listening has started, so it stays to hand while reading. */
.player { margin: 0 0 36px; padding: 14px 0; border-block: 1px solid var(--tm-line); background: var(--tm-white); }
.player audio { width: 100%; }
.player.enhanced audio { display: none; }
.player.started { position: sticky; top: var(--header); z-index: 5; }
.player-controls { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; }
.player-controls[hidden] { display: none; }
.player button { display: inline-flex; align-items: center; justify-content: center; height: 38px; padding: 0 12px; border: 1px solid var(--tm-violet); border-radius: 0; background: var(--tm-white); color: var(--tm-violet); font: 700 13px/1.2 var(--tm-ui); cursor: pointer; }
.player button:hover { background: var(--tm-tint); }
.player button:focus-visible, .player .seek:focus-visible { outline: 3px solid var(--tm-violet); outline-offset: 2px; }
.player .play { width: 48px; padding: 0; background: var(--tm-violet); color: var(--tm-white); }
.player .play .icon { display: block; }
.player .play:hover { background: var(--tm-ink); border-color: var(--tm-ink); }
.player .seek { flex: 1 1 100%; margin: 2px 0 0; accent-color: var(--tm-violet); }
.player .time { margin-left: auto; font: 400 13px/1.2 var(--tm-ui); color: var(--tm-muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.player .speed { min-width: 4.2em; }
.player-note { margin: 10px 0 0; font-size: 13px; color: var(--tm-muted); }
.player.started .player-note { display: none; }

/* Clickable words (player.js): the line under the pointer is underlined, with the time it plays from beside it. */
.words-clickable { cursor: pointer; }
.words-clickable a { cursor: pointer; }
.word-mark { position: absolute; z-index: 4; pointer-events: none; border-bottom: 2px solid var(--tm-violet); }
.word-mark[hidden] { display: none; }
.word-time { position: absolute; left: 0; bottom: 100%; margin-bottom: 2px; padding: 2px 5px; background: var(--tm-violet); color: var(--tm-white); font: 700 11px/1.2 var(--tm-ui); white-space: nowrap; font-variant-numeric: tabular-nums; }
.word-mark.in-margin .word-time { bottom: auto; top: 50%; margin: 0; transform: translate(-100%, -50%); }

@media (max-width: 640px) {
  .player .time { flex-basis: 100%; margin-left: 0; }
}

@media print {
  .player { display: none; }
}
