/* zinked.ai — a landing page that is a book.

   The book is one long page that scrolls, with or without scripts. With
   them (html.js) it also takes marks, reads aloud and so on; and if the
   reader asks for pages (html.paged) it is laid out in columns, one column
   to a page, and js/pages.js shows one or two at a time. Chrome is black,
   blunt and square; the page is paper and a serif. One accent, ink blue.

   This file is the page and its words. reader.css is the controls and the
   paged layout; figures.css is everything drawn. */

/* ---------- Colours and type ---------- */

:root {
  --paper: #F6F2E9;
  --ink: #0B0B0B;
  --soft: #5E584E;
  --accent: #27408B;
  --on-accent: #FFFDF8;
  --quiet: #77726A;
  --tone: #000000;
  --agent: #1F6F5C;
  --on-agent: #FFFDF8;

  --sans: system-ui, -apple-system, "Helvetica Neue", "Segoe UI", Roboto, Arial, sans-serif;
  --serif: ui-serif, "New York", "Iowan Old Style", "Palatino Linotype", Georgia, serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --hand: "Bradley Hand", "Noteworthy", "Segoe Print", "Chalkboard SE", "Comic Sans MS", cursive;
  --face: var(--serif);
  --base: clamp(18px, 0.4vw + 16.4px, 21px);
  --scale: 1;

  --rule: 3px;
  --bar: calc(56px + env(safe-area-inset-top, 0px));
  --band: calc(52px + env(safe-area-inset-bottom, 0px));
}

:root[data-theme="white"] { --paper: #FFFFFF; --soft: #55524C; --quiet: #747474; }

:root[data-theme="dusk"] {
  --paper: #26272A; --ink: #E4E0D6; --soft: #A8A296;
  --accent: #A3B8FF; --on-accent: #10162B; --quiet: #8F8B83; --tone: #FFFFFF;
  --agent: #74CDB3; --on-agent: #0B1512;
}

:root[data-theme="black"] {
  --paper: #000000; --ink: #EFEBE2; --soft: #A39C8E;
  --accent: #A3B8FF; --on-accent: #10162B; --quiet: #86827A; --tone: #FFFFFF;
  --agent: #74CDB3; --on-agent: #0B1512;
}

/* With no paper chosen, a dark system gets the black one. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --paper: #000000; --ink: #EFEBE2; --soft: #A39C8E;
    --accent: #A3B8FF; --on-accent: #10162B; --quiet: #86827A; --tone: #FFFFFF;
    --agent: #74CDB3; --on-agent: #0B1512;
  }
}

:root[data-face="sans"] { --face: var(--sans); }
:root[data-face="mono"] { --face: var(--mono); }
:root[data-size="0"] { --scale: 0.86; }
:root[data-size="1"] { --scale: 0.93; }
:root[data-size="3"] { --scale: 1.1; }
:root[data-size="4"] { --scale: 1.22; }
:root[data-size="5"] { --scale: 1.36; }

/* ---------- Ground rules ---------- */

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html {
  background: var(--paper);
  color: var(--ink);
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  /* A chapter, or a word found by the browser, lands below the bar. */
  scroll-padding-top: calc(var(--bar) + 14px);
}
@media (prefers-reduced-motion: no-preference) {
  html { scroll-behavior: smooth; }
}

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 16px/1.4 var(--sans);
}

::selection { background: color-mix(in srgb, var(--accent) 32%, transparent); }

:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

.vh {
  position: absolute;
  width: 1px; height: 1px;
  margin: -1px; padding: 0; border: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.skip {
  position: absolute; left: 8px; top: -80px; z-index: 50;
  padding: 12px 14px;
  background: var(--ink); color: var(--paper);
  font-weight: 800;
}
.skip:focus { top: 8px; }

/* ---------- Buttons ---------- */

.btn {
  min-height: 44px; min-width: 44px;
  padding: 0 12px;
  border: 2px solid var(--ink); border-radius: 0;
  background: var(--paper); color: var(--ink);
  font: 800 13px/1 var(--sans);
  letter-spacing: 0.06em; text-transform: uppercase; white-space: nowrap;
  cursor: pointer;
}
.btn[aria-pressed="true"], .btn[aria-expanded="true"], .btn.solid { background: var(--ink); color: var(--paper); }

.count {
  display: inline-block; min-width: 1.5em;
  margin-left: 2px; padding: 2px 4px;
  background: var(--ink); color: var(--paper);
  font-variant-numeric: tabular-nums; text-align: center;
}
.btn[aria-expanded="true"] .count { background: var(--paper); color: var(--ink); }
.count.bump { animation: bump 0.32s steps(4, end); }
@keyframes bump { 50% { transform: scale(1.5); } }

.narrow { display: none; }

/* ---------- The bar at the top ---------- */

.bar {
  position: sticky; top: 0; z-index: 15;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  height: var(--bar);
  padding: env(safe-area-inset-top, 0px) max(14px, env(safe-area-inset-right, 0px)) 0 max(14px, env(safe-area-inset-left, 0px));
  border-bottom: var(--rule) solid var(--ink);
  background: var(--paper);
}

.brand {
  display: flex; align-items: center; gap: 10px;
  min-height: 44px;
  color: inherit; text-decoration: none;
}
.mark { display: block; flex: none; width: 30px; height: 30px; }
.mark-tile { fill: #0B0B0B; }
.mark-frame { fill: none; stroke: var(--ink); stroke-width: 6; }
.mark-z { fill: #FFFFFF; }
.wordmark { font: 900 23px/1 var(--sans); letter-spacing: -0.02em; }

.bar-tools { display: flex; gap: 8px; }

/* ---------- The book: one scroll of chapters ---------- */

.plain-note {
  max-width: 34em; margin: 0 auto; padding: 14px 24px;
  border-bottom: 2px solid var(--ink);
  font-size: 14px;
}

.book {
  margin: 0 auto;
  padding: 32px 24px 120px;
  counter-reset: chapter;
  font-family: var(--face);
  font-size: calc(var(--base) * var(--scale));
  line-height: 1.5;
  text-align: justify;
  hyphens: auto; -webkit-hyphens: auto;
  hyphenate-limit-chars: 7 3 3;
  overflow-wrap: break-word;
  orphans: 2; widows: 2;
  font-kerning: normal;
}
:root[data-face="mono"] .book { font-size: calc(var(--base) * var(--scale) * 0.88); text-align: left; hyphens: manual; -webkit-hyphens: manual; }

/* A column a comfortable line wide, in the middle of the screen. */
.book > section { max-width: 34em; margin-left: auto; margin-right: auto; }
.book section:focus { outline: none; }

.book p { margin: 0; }
.book p + p, .book p + .keep > p:first-child, .book p + .noted > p:first-child, .book .noted + p { text-indent: 1.5em; }
.book a { color: inherit; text-decoration-thickness: 0.1em; text-underline-offset: 0.18em; }
.book em { font-style: italic; }

/* A box or a figure that cannot be cut in two is kept on one page with the
   short paragraph beside it, so that as pages it is never alone on one. */
.keep, .try, .object, .contents, .live, .notebook-page, .shelf li, .margin, .do { -webkit-column-break-inside: avoid; break-inside: avoid; }
.keep > :first-child { margin-top: 0; }
.keep > .try:first-child, .keep > .object:first-child { margin-top: 1.05em; }

html:not(.paged) .chapter { margin-top: 4.5em; }
/* A chapter that is the first thing on its page starts at the top of it. */
html:not(.paged) .book > .chapter:first-child { margin-top: 0 !important; }
html:not(.js) .try, html:not(.js) .notebook-page, html:not(.js) .first-do { display: none; }

@media (min-width: 700px) {
  html:not(.paged) .book { padding-top: 56px; padding-bottom: 180px; }
  html:not(.paged) .chapter { margin-top: 6em; }
}

/* ---------- The opening ---------- */

.cover-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.cover-mark { display: block; flex: none; width: 3.4em; height: 3.4em; }

.cover h1 {
  margin: 0.2em 0 0.16em;
  font: 900 4.7em/0.86 var(--sans);
  letter-spacing: -0.03em;
  text-align: left; hyphens: manual; -webkit-hyphens: manual;
}
.cover .lede {
  padding-top: 0.6em;
  border-top: 6px solid var(--ink);
  font-size: 1.12em; line-height: 1.34;
  text-align: left; text-indent: 0; hyphens: manual; -webkit-hyphens: manual; text-wrap: pretty;
}
.cover .lede-more { margin-top: 0.7em; font-size: 0.92em; text-align: left; text-indent: 0; hyphens: manual; -webkit-hyphens: manual; text-wrap: pretty; }

.contents {
  display: grid; grid-auto-flow: column; grid-template-rows: repeat(6, auto); column-gap: 1.2em;
  margin: 1.5em 0 0; padding: 0;
  list-style: none; counter-reset: entry;
  border-top: 2px solid var(--ink);
  font: 800 0.76em/1.2 var(--sans);
  text-align: left; hyphens: manual; -webkit-hyphens: manual;
}
.contents li { counter-increment: entry; border-bottom: 2px solid var(--ink); }
.contents a { display: flex; align-items: center; gap: 0.7em; min-height: 44px; text-decoration: none; }
.contents a::before { content: counter(entry); min-width: 1.3em; font-variant-numeric: tabular-nums; color: var(--accent); }

.book .stamp {
  display: table;
  padding: 0.55em 0.75em 0.5em;
  background: var(--ink); color: var(--paper);
  font: 800 0.7em/1 var(--sans);
  letter-spacing: 0.11em; text-transform: uppercase;
  text-indent: 0;
}

/* The title page of a work from the shelf. */
.cover.work h1 { margin-top: 0.5em; font-size: 3.1em; line-height: 0.92; letter-spacing: -0.035em; text-wrap: balance; }
.cover.work h1.long { font-size: 2.5em; }

/* ---------- Chapters ---------- */

.chapter { -webkit-column-break-before: always; break-before: column; }

.chapter h2 {
  margin: 0 0 0.62em;
  padding-top: 0.3em;
  border-top: 6px solid var(--ink);
  font: 900 1.9em/1 var(--sans);
  letter-spacing: -0.035em;
  text-align: left; hyphens: manual; -webkit-hyphens: manual; text-wrap: balance;
  break-after: avoid;
}
.chapter:not(.plain) h2 { counter-increment: chapter; }
.chapter:not(.plain) h2::before {
  content: counter(chapter);
  display: block;
  margin-bottom: 0.06em;
  font-size: 2.3em; line-height: 0.92; letter-spacing: -0.05em;
}
/* As pages, a short screen gets a smaller numeral, to leave room for text. */
.paged .chapter:not(.plain) h2::before { font-size: min(2.3em, 11vh); }
/* In a scroll on a wide screen there is margin to spare, and the numeral
   hangs in it, level with the rule. */
@media (min-width: 1100px) {
  html:not(.paged) .chapter:not(.plain) h2 { position: relative; }
  html:not(.paged) .chapter:not(.plain) h2::before { position: absolute; top: -6px; right: 100%; margin: 0 0.32em 0 0; line-height: 0.8; }
}
.chapter.plain h2 { font-size: 1.55em; }

.book h3 {
  margin: 1.5em 0 0.45em;
  font: 800 1em/1.2 var(--sans);
  text-align: left; hyphens: manual; -webkit-hyphens: manual;
  break-after: avoid;
}
.book h3 + p { text-indent: 0; }

/* A note from the page about itself, beside the text and not part of it. */
.kicker {
  margin: 0 0 1em !important; padding-left: 10px;
  border-left: 4px solid var(--ink);
  font: 0.76em/1.42 var(--sans);
  text-align: left; text-indent: 0 !important; hyphens: manual; -webkit-hyphens: manual;
}

/* An invitation to do the thing on this page. It is the page talking about
   itself, so it is set in the chrome's face and boxed. */
.try {
  margin: 1.05em 0;
  padding: 0 12px 11px;
  border: 2px solid var(--ink);
  font: 0.8em/1.45 var(--sans);
  text-align: left; hyphens: manual; -webkit-hyphens: manual;
}
.try::before {
  content: "Try it";
  display: table;
  margin: 0 0 9px -12px;
  padding: 5px 9px 4px;
  background: var(--ink); color: var(--paper);
  font-weight: 800; font-size: 11px; line-height: 1;
  letter-spacing: 0.11em; text-transform: uppercase;
}
.book .try p + p { margin-top: 0.7em; text-indent: 0; }
.book .try + p, .book .object + p, .book .notebook-page + p { text-indent: 0; }
/* A line of things to press. */
.do { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 0.75em !important; text-indent: 0 !important; }
/* A button that is not offered yet keeps its place, so that nothing moves
   (and no page is cut differently) when it is. */
.btn.waiting { visibility: hidden; }
/* The two things to do first, under the opening words. */
.first-do { margin-top: 1.1em !important; }

/* Things a paper is full of: an equation, a table, code, a figure. */
.object { margin: 1.15em 0; }
.object figcaption { margin-top: 0.55em; font: 0.76em/1.42 var(--sans); text-align: left; hyphens: manual; -webkit-hyphens: manual; }
.object figcaption b {
  display: block;
  font-weight: 800; font-size: 11px; line-height: 1.6;
  letter-spacing: 0.11em; text-transform: uppercase;
}
.object q { font: italic 1.14em/1.38 var(--face); }

.display {
  padding: 0.75em 0 0.6em;
  border-top: 2px solid var(--ink); border-bottom: 2px solid var(--ink);
  font-size: 1.08em; text-align: center;
  overflow: hidden;
}
math { font-size: 1.05em; }

.book table {
  width: 100%;
  border-collapse: collapse; border-top: 2px solid var(--ink);
  font: 0.76em/1.3 var(--sans);
  text-align: left; hyphens: manual; -webkit-hyphens: manual;
}
.book th {
  padding: 0.55em 0.8em 0.5em 0;
  border-bottom: 2px solid var(--ink);
  font-weight: 800; font-size: 11px; line-height: 1.25; letter-spacing: 0.09em; text-transform: uppercase;
  vertical-align: bottom;
}
.book td { padding: 0.5em 0.8em 0.5em 0; border-bottom: 1px solid var(--ink); vertical-align: top; }
.book td:first-child { font-weight: 700; }
.book .n { text-align: right; font-variant-numeric: tabular-nums; }
.book td.n { white-space: nowrap; }
.book tr > :last-child { padding-right: 0; }
.book th.n + th:not(.n), .book td.n + td:not(.n) { padding-left: 0.8em; }
.book code { font: 0.92em/1.3 var(--mono); }

.book pre {
  margin: 0; padding: 0.9em;
  border: 2px solid var(--ink);
  font: 0.64em/1.6 var(--mono);
  text-align: left; white-space: pre-wrap; overflow-wrap: anywhere; hyphens: manual; -webkit-hyphens: manual;
}
.book pre code { font: inherit; }

.references ol { margin: 0; padding-left: 1.4em; font-size: 0.86em; text-align: left; hyphens: manual; -webkit-hyphens: manual; }
.references li { margin-bottom: 0.4em; }

.stars { display: flex; gap: 2px; margin: 0.5em 0 0 -8px; padding: 0; border: 0; }
.stars label { position: relative; display: grid; place-items: center; width: 44px; height: 44px; cursor: pointer; }
.stars input { position: absolute; inset: 0; margin: 0; opacity: 0; cursor: pointer; }
.star { width: 30px; height: 30px; fill: none; stroke: var(--ink); stroke-width: 1.8; }
/* A star is filled when it, or one after it, is the one chosen. */
.stars label:has(input:checked) .star, .stars label:has(~ label input:checked) .star { fill: var(--accent); stroke: var(--accent); }
.stars label:has(input:focus-visible) { outline: 3px solid var(--accent); outline-offset: -3px; }

/* Plain answers: the question blunt, the answer in the book's own voice. */
.answers { margin: 0; }
.answers dt {
  margin-top: 1.3em; padding-top: 0.5em;
  border-top: 2px solid var(--ink);
  font: 800 0.92em/1.25 var(--sans);
  text-align: left; hyphens: manual; -webkit-hyphens: manual;
  break-after: avoid;
}
.answers dt:first-child { margin-top: 0; }
.answers dd { margin: 0.35em 0 0; }
.answers dd + dd { margin-top: 0.6em; }

.price {
  margin-top: 0.5em !important; padding-top: 0.32em;
  border-top: 6px solid var(--ink);
  font: 800 0.9em/1.1 var(--sans);
  text-align: left; text-indent: 0 !important;
}
.price b { display: block; font-weight: 900; font-size: 3.1em; line-height: 0.95; letter-spacing: -0.05em; }
.price + .price { margin-top: 0.7em !important; }
.price + .stamp { margin-top: 1.4em; }
.fin { margin-top: 1.3em !important; font-size: 0.86em; text-align: left; text-indent: 0 !important; }

/* ---------- Marks ---------- */

.mk { --mark: var(--accent); --on-mark: var(--on-accent); cursor: pointer; }
.mk[data-by] { --mark: var(--agent); --on-mark: var(--on-agent); }
.mk-highlight { background: var(--mark); color: var(--on-mark); }
.mk-underline { text-decoration: underline var(--mark) 0.13em; text-underline-offset: 0.2em; text-decoration-skip-ink: none; }
.mk-strike { text-decoration: line-through var(--mark) 0.12em; }
.mk-circle { outline: 0.12em solid var(--mark); outline-offset: 0.1em; border-radius: 999px; }
.mk-end[data-by]::after {
  content: attr(data-by);
  margin-left: 0.5em; padding: 0.15em 0.45em;
  border: 2px solid var(--agent);
  background: var(--paper); color: var(--agent);
  font: 800 0.56em/1 var(--sans);
  letter-spacing: 0.08em; text-transform: uppercase; white-space: nowrap;
  vertical-align: 0.22em;
}

/* ---------- The page's own marks ---------- */

/* What a reader's copy comes to have: a line underlined in pen, a term
   circled, a note in the margin in a hand, and an agent's note in green
   answering it. They are in the page as it is written, so with scripts off
   they are simply there. With scripts, each waits until the reader has got
   to it (js/margin.js gives it the class "read"), and then it is drawn. */
.pm-line {
  background: linear-gradient(var(--accent), var(--accent)) no-repeat 0 96% / 100% 0.11em;
  transition: background-size 0.8s cubic-bezier(0.3, 0.6, 0.3, 1);
}
/* A ring goes round its words whole: they are not broken across lines. */
.pm-ring { outline: 0.11em solid var(--accent); outline-offset: 0.12em; border-radius: 999px; white-space: nowrap; transition: outline-color 0.5s; }

.noted { position: relative; }
.margin { margin: 0.5em 0 0.8em 1.5em; text-align: left; hyphens: manual; -webkit-hyphens: manual; }
.book .margin p { text-indent: 0; }
.hand {
  color: var(--accent);
  font: 1.02em/1.25 var(--hand);
  transform: rotate(-1.5deg); transform-origin: 0 100%;
  transition: clip-path 0.9s steps(22, end);
}
.agent-note {
  margin-top: 0.55em !important; padding-left: 0.6em;
  border-left: 3px solid var(--agent);
  color: var(--agent);
  font: 0.72em/1.4 var(--sans);
  transition: opacity 0.5s 1.5s, transform 0.5s 1.5s;
}
.agent-note b {
  display: table; margin-bottom: 0.3em; padding: 0.15em 0.45em;
  border: 2px solid var(--agent);
  font-weight: 800; font-size: 0.78em; line-height: 1; letter-spacing: 0.08em; text-transform: uppercase;
}

/* Not yet read: not yet drawn. Only where things may move. */
@media (prefers-reduced-motion: no-preference) {
  .js .pm-line:not(.read) { background-size: 0% 0.11em; }
  .js .pm-ring:not(.read) { outline-color: transparent; }
  .js .margin:not(.read) .hand { clip-path: inset(-0.4em 100% -0.4em 0); }
  .js .margin.read .hand { clip-path: inset(-0.4em -0.4em -0.4em 0); }
  .js .margin:not(.read) .agent-note { opacity: 0; transform: translateY(0.3em); transition: none; }
}

/* On a wide screen a note stands in the margin, beside its words. */
@media (min-width: 1240px) {
  html:not(.paged):not(.notes-open) .noted > .margin {
    position: absolute; top: 0.25em; left: calc(100% + 2em);
    width: min(13.5em, (100vw - 34em) / 2 - 3.2em);
    margin: 0;
  }
}

/* ---------- Following along ---------- */

/* While the book is read aloud, the sentence being said stays in full ink
   and the rest of the text eases back. A firm rule stands in the margin
   beside the sentence, and a short flat rule runs under the word being said
   where the voice says which it is. Only colours and those two rules move:
   no line is set again, so nothing jumps. (.s is a sentence of the book;
   .ls a sentence of the page at the top that reads itself.) */
.s, .ls, .object, .kicker, .shelf, .references ol, .try, .lede-more, .contents { transition: color 0.35s ease; }
.following .s, .following .object, .ls { color: var(--quiet); }
/* What is never said eases back with the rest. */
.following .kicker, .following .shelf, .following .references ol, .following .try, .following [data-silent].lede-more, .following .contents { color: var(--quiet); }
.following .s.now, .following .object.now, .ls.now { color: var(--ink); }
.following .mk-highlight .s { color: inherit; }

.js .strip { position: relative; }
.voice-rule, .voice-word {
  position: absolute; left: 0; top: 0; z-index: 1;
  background: var(--accent);
  opacity: 0;
  pointer-events: none;
}
.voice-rule {
  width: 4px; height: 0;
  transition: transform 0.32s cubic-bezier(0.3, 0.7, 0.2, 1), height 0.32s cubic-bezier(0.3, 0.7, 0.2, 1), opacity 0.25s;
}
.voice-word {
  width: 0; height: 2px;
  transition: transform 0.11s linear, width 0.11s linear, opacity 0.2s;
}
.voice-rule.on, .voice-word.on { opacity: 1; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}
