/* Nico Roig: a technical data book. Visual decisions are recorded in _design/DESIGN.md. */

@font-face {
  font-family: "Archivo";
  src: url("/assets/fonts/archivo-latin-standard-normal.woff2") format("woff2");
  font-weight: 100 900;
  font-stretch: 62% 125%;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Archivo";
  src: url("/assets/fonts/archivo-latin-standard-italic.woff2") format("woff2");
  font-weight: 100 900;
  font-stretch: 62% 125%;
  font-style: italic;
  font-display: swap;
}

:root {
  color-scheme: light dark;
  --paper: #f4f5f6;
  --ink: #0e1013;
  --ink-2: #4a4f57;
  --rule: #c9ccd1;

  --navy: #1f2b4d;
  --coral: #ec6f5a;
  --cream: #f0e5d0;
  --slate: #5d7590;
  --on-dark: #ffffff;
  --on-light: #0e1013;

  --navy-text: #1f2b4d;
  --coral-text: #b5341e;
  --cream-text: #7f6128;
  --slate-text: #4f6680;

  --tint: 10%;
  --cream-tint: 55%;
  --gutter: clamp(1rem, 3.2vw, 3rem);
  --ease: cubic-bezier(.16, 1, .3, 1);
  --sans: "Archivo", "Helvetica Neue", Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #111317;
    --ink: #eceef0;
    --ink-2: #a5abb4;
    --rule: #30343b;
    --navy-text: #8da2e0;
    --coral-text: #f08070;
    --cream-text: #f0e5d0;
    --slate-text: #8ea4bd;
    --tint: 16%;
    --cream-tint: 14%;
  }
}

[data-book="messaging"]  { --book: var(--navy);  --on-book: var(--on-dark);  --book-text: var(--navy-text); }
[data-book="purchasing"] { --book: var(--coral); --on-book: var(--on-light); --book-text: var(--coral-text); }
[data-book="tax"]        { --book: var(--cream); --on-book: var(--on-light); --book-text: var(--cream-text); --tint: var(--cream-tint); }
[data-book="training"]   { --book: var(--slate); --on-book: var(--on-dark);  --book-text: var(--slate-text); }

*, *::before, *::after { box-sizing: border-box; }
html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
  scrollbar-color: var(--ink-2) var(--paper);
}
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 400 1.0625rem/1.6 var(--sans);
  font-feature-settings: "kern" 1;
  overflow-x: clip;
}
::selection { background: var(--book, var(--ink)); color: var(--on-book, var(--paper)); }
a {
  color: inherit;
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: .18em;
}
a:hover { text-decoration-thickness: 2px; }
:focus-visible { outline: 3px solid var(--book-text, var(--ink)); outline-offset: 3px; }
p { margin: 0 0 1em; max-width: 68ch; }
em { font-style: italic; }

.skip {
  position: absolute;
  left: var(--gutter);
  top: -4rem;
  z-index: 10;
  padding: .5rem .875rem;
  background: var(--paper);
  color: var(--ink);
}
.skip:focus { top: .75rem; }

/* Part plate: the label printed on every volume */
.plate {
  display: inline-block;
  padding: .28em .55em .24em;
  border: 1.5px solid currentColor;
  font-size: .8125rem;
  font-weight: 650;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* ---------- Home: masthead ---------- */

.first-view {
  display: flex;
  flex-direction: column;
  min-height: 100svh;
}
.masthead {
  display: grid;
  grid-template-columns: minmax(0, 7fr) minmax(0, 5fr);
  gap: 1.25rem var(--gutter);
  align-items: end;
  padding: clamp(1.25rem, 3.4vh, 2.5rem) var(--gutter) clamp(1.125rem, 3vh, 2.25rem);
}
.masthead h1 {
  margin: 0;
  font-size: clamp(3.25rem, min(8.4vw, 13vh), 6rem);
  font-weight: 800;
  font-stretch: 112%;
  line-height: .95;
  letter-spacing: -.035em;
}
.masthead-name p { margin: .5rem 0 0; font-size: 1.0625rem; font-weight: 500; color: var(--ink-2); }
.masthead-intro p { margin-bottom: .625rem; font-size: clamp(1.0625rem, 1.5vw, 1.3125rem); line-height: 1.38; text-wrap: pretty; }
.masthead-intro .masthead-links { margin: 0; font-size: 1rem; }
.masthead-links a { margin-right: 1.125rem; font-weight: 600; }

/* ---------- Spine stack ---------- */

main { display: block; }
.first-view > main { display: flex; flex: 1; min-height: 0; }
.stack {
  list-style: none;
  display: flex;
  flex-direction: column;
  flex: 1;
  width: 100%;
  margin: 0;
  padding: 0;
  overflow: clip;
}
.stack > li {
  display: flex;
  flex: var(--words) 1 0;
  min-height: 5.75rem;
}
.spine {
  flex: 1;
  display: grid;
  grid-template-columns: 4.75rem minmax(0, 5fr) minmax(0, 5fr) minmax(9.5rem, 2fr) 1.5rem;
  gap: 0 clamp(.875rem, 2vw, 2rem);
  align-items: center;
  padding: .75rem var(--gutter);
  background: var(--book);
  color: var(--on-book);
  text-decoration: none;
  transition: transform .55s var(--ease), box-shadow .55s var(--ease);
  --title: clamp(2rem, min(4.6vw, 8vh), 4rem);
}
[data-book="messaging"] > .spine { --title: clamp(2.25rem, min(6.4vw, 11.5vh), 6rem); }
.spine:hover, .spine:focus-visible {
  transform: translateX(clamp(1rem, 2.4vw, 2.25rem));
  box-shadow: -14px 0 28px rgb(0 0 0 / .3);
}
.spine:focus-visible { outline: 3px solid var(--on-book); outline-offset: -8px; }
.spine ::selection, .cover ::selection, .band ::selection { background: var(--on-book); color: var(--book); }
.spine .plate { justify-self: start; }
.spine-title {
  margin: 0;
  font-size: var(--title);
  font-weight: 800;
  font-stretch: 72%;
  line-height: .96;
  letter-spacing: -.012em;
}
.spine-result {
  margin: 0;
  font-size: clamp(.9375rem, 1.14vw, 1.0625rem);
  line-height: 1.36;
  text-wrap: pretty;
}
.spine-meta {
  margin: 0;
  display: flex;
  flex-direction: column;
  font-size: .875rem;
  line-height: 1.34;
  font-variant-numeric: tabular-nums;
}
.spine-meta span:first-child { font-weight: 650; }
.arrow { flex: none; display: block; }
.spine .arrow { transition: transform .55s var(--ease); }
.spine:hover .arrow { transform: translateX(-.25rem); }

.stack--end > li { flex: none; min-height: calc(var(--words) * .07px + 4rem); }
.stack--end .spine { --title: clamp(1.875rem, 3.6vw, 3.25rem); }

/* ---------- Public parts ---------- */

.parts { padding: clamp(3.5rem, 8vw, 6.5rem) var(--gutter) clamp(2.5rem, 6vw, 4.5rem); }
.parts h2 {
  margin: 0 0 .5rem;
  font-size: clamp(2.5rem, 5.4vw, 4.5rem);
  font-weight: 800;
  font-stretch: 72%;
  line-height: 1;
  letter-spacing: -.012em;
}
.parts-intro { margin-bottom: 2rem; font-size: 1.1875rem; line-height: 1.4; }
.parts table { width: 100%; border-collapse: collapse; border-top: 4px solid var(--ink); }
.parts th, .parts td { padding: .875rem 1.25rem .875rem 0; border-bottom: 1px solid var(--rule); text-align: left; vertical-align: top; font-weight: 400; line-height: 1.42; }
.parts thead th { padding-block: .5rem; font-size: .875rem; font-weight: 650; color: var(--ink-2); }
.parts tbody th { font-weight: 700; white-space: nowrap; }
.parts td:last-child { color: var(--ink-2); }

/* ---------- Colophon ---------- */

.colophon { padding: clamp(2.5rem, 6vw, 4.5rem) var(--gutter) 2.5rem; border-top: 4px solid var(--ink); }
.colophon-title { margin: 0 0 .75rem; font-size: 1.0625rem; font-weight: 650; }
.colophon-mail { margin: 0 0 .5rem; max-width: none; font-size: clamp(1.5rem, 5.6vw, 4.5rem); font-weight: 800; font-stretch: 72%; line-height: 1.05; overflow-wrap: anywhere; }
.colophon-mail a { text-decoration-thickness: .05em; }
.colophon-links { margin-bottom: 2rem; font-weight: 600; }
.colophon-note { margin: 0; font-size: .9375rem; line-height: 1.45; color: var(--ink-2); }

/* ---------- Project: cover ---------- */

.cover {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: clamp(2.5rem, 9vh, 6rem);
  min-height: 74svh;
  padding: 1.25rem var(--gutter) clamp(1.75rem, 4vh, 3rem);
  background: var(--book);
  color: var(--on-book);
  border-bottom: 4px solid var(--ink);
}
.cover-top { display: flex; justify-content: space-between; align-items: center; gap: 1rem; }
.back {
  display: inline-flex;
  align-items: center;
  gap: .5rem;
  font-weight: 650;
  text-decoration: none;
}
.back:hover span { text-decoration: underline; text-decoration-thickness: 2px; text-underline-offset: .18em; }
.back:focus-visible, .cover :focus-visible { outline-color: var(--on-book); }
.cover-body { display: grid; grid-template-columns: minmax(0, 8fr) minmax(0, 4fr); gap: 1rem var(--gutter); align-items: end; }
.cover h1 {
  grid-column: 1 / -1;
  margin: 0;
  font-size: clamp(3.5rem, min(13vw, 22vh), 6rem);
  font-weight: 800;
  font-stretch: 72%;
  line-height: .94;
  letter-spacing: -.012em;
  text-wrap: balance;
}
@media (min-width: 62rem) {
  .cover h1 { font-size: 6rem; }
}
.cover-result { margin: 0; font-size: clamp(1.25rem, 2vw, 1.75rem); font-weight: 500; line-height: 1.26; max-width: 38ch; text-wrap: pretty; }
.cover-meta { margin: 0; display: flex; flex-direction: column; justify-self: end; min-width: 11rem; font-size: 1rem; line-height: 1.38; font-variant-numeric: tabular-nums; }
.cover-meta span:first-child { font-weight: 650; }

/* ---------- Project: document ---------- */

.doc {
  display: grid;
  grid-template-columns: minmax(13rem, 18rem) minmax(0, 52rem);
  gap: 0 clamp(2rem, 5vw, 5rem);
  padding: 0 var(--gutter);
}
.toc {
  position: sticky;
  top: 0;
  align-self: start;
  max-height: 100svh;
  overflow-y: auto;
  padding: 3.5rem 0 2rem;
  scrollbar-width: thin;
  font-size: .9375rem;
  line-height: 1.3;
}
.toc-title { margin: 0 0 .75rem; font-weight: 650; color: var(--ink-2); }
.toc ol { list-style: none; margin: 0; padding: 0; }
.toc li { margin: 0 0 .625rem; }
.toc a { display: block; text-decoration: none; font-weight: 650; }
.toc a:hover { text-decoration: underline; text-underline-offset: .18em; }
.toc-sub a { padding-left: .875rem; font-size: .875rem; font-weight: 400; color: var(--ink-2); }
.toc a.is-current { color: var(--book-text); text-decoration: underline; text-decoration-thickness: 2px; text-underline-offset: .18em; }

#content { padding-bottom: clamp(3.5rem, 8vw, 6rem); min-width: 0; }
#content section { padding-top: clamp(3rem, 6vw, 4.75rem); scroll-margin-top: 0; }
#content h2 {
  margin: 0 0 1.25rem;
  padding-top: .75rem;
  border-top: 4px solid var(--ink);
  font-size: clamp(2rem, 3.6vw, 3rem);
  font-weight: 800;
  font-stretch: 72%;
  line-height: 1.04;
  letter-spacing: -.008em;
  text-wrap: balance;
}
#content h3 {
  margin: 3rem 0 1rem;
  scroll-margin-top: 1.5rem;
  font-size: 1.4375rem;
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: -.005em;
  text-wrap: balance;
  max-width: 34em;
}
#content h2 + h3 { margin-top: 1.75rem; }
.lead { font-size: clamp(1.1875rem, 1.7vw, 1.375rem); line-height: 1.42; text-wrap: pretty; }
#content ul { margin: 1.25rem 0; padding-left: 1.125rem; max-width: 68ch; }
#content li { margin: 0 0 .625rem; }
#content li::marker { color: var(--book-text); }

.spec {
  display: grid;
  grid-template-columns: minmax(7rem, 10.5rem) minmax(0, 1fr);
  margin: 0;
}
.spec dt, .spec dd { margin: 0; padding: .6875rem 0; border-bottom: 1px solid var(--rule); line-height: 1.42; }
.spec dt { padding-right: 1rem; font-weight: 650; }
.spec a { font-weight: 600; }

/* Decision rows */
#content section > dl:not(.spec) {
  display: grid;
  grid-template-columns: 5rem minmax(0, 1fr);
  margin: 0 0 1rem;
}
#content section > dl:not(.spec) dt {
  padding: .625rem 1rem .625rem 0;
  font-size: .9375rem;
  font-weight: 650;
  line-height: 1.7;
  color: var(--ink-2);
}
#content section > dl:not(.spec) dd { margin: 0; padding: .625rem 0; line-height: 1.58; }
/* The choice is what a skimming reader came for */
#content section > dl:not(.spec) dt:nth-of-type(3) { grid-column: 1; color: var(--book-text); }
#content section > dl:not(.spec) dd:nth-of-type(3) {
  padding: .875rem 1.125rem;
  background: color-mix(in srgb, var(--book) var(--tint), var(--paper));
}
#content section > dl:not(.spec) dt:nth-of-type(3) { padding-top: .875rem; }

/* Diagram */
.fig {
  margin: 0 0 1.5rem;
  padding: 1rem;
  border: 1px solid var(--rule);
  overflow-x: auto;
  scrollbar-width: thin;
}
.fig svg { display: block; width: 100%; min-width: 34rem; height: auto; }
.fig text { fill: var(--ink); font-family: var(--sans); font-size: 14.5px; }
.fig .sm { fill: var(--ink-2); font-size: 13px; }
.fig rect { fill: color-mix(in srgb, var(--book) var(--tint), var(--paper)); stroke: var(--ink); stroke-width: 1; }
.fig line, .fig path { stroke: var(--ink); stroke-width: 1.2; fill: none; }
.fig .dash { stroke: var(--book-text); stroke-dasharray: 4 4; stroke-width: 1.5; }
.fig rect.dash { fill: none; }
.fig marker path { stroke: var(--ink); }

.fig-hint { display: none; }
@media (max-width: 44rem) {
  .fig { margin-bottom: .5rem; }
  .fig-hint { display: block; margin-bottom: 1.5rem; font-size: .9375rem; color: var(--ink-2); }
}

/* Colour field: the part of the write-up nobody should skip */
#content section.band {
  margin-top: clamp(3rem, 6vw, 4.75rem);
  padding: clamp(2.5rem, 5vw, 4rem) 0;
  color: var(--on-book);
  background: var(--book);
  /* Paints past the column to the viewport edge. A shadow adds no scrollable width. */
  box-shadow: 0 0 0 100vmax var(--book);
  clip-path: inset(0 -100vmax 0 calc(clamp(1rem, 2.5vw, 2.5rem) * -1));
}
#content section.band h2 { border-top-color: var(--on-book); }
#content section.band li::marker { color: inherit; }
.pull {
  margin-bottom: 1.25em;
  font-size: clamp(1.625rem, 3vw, 2.5rem);
  font-weight: 700;
  line-height: 1.1;
  letter-spacing: -.01em;
  max-width: 24em;
  text-wrap: balance;
}
.more { border-top: 4px solid var(--ink); }

/* ---------- 404 ---------- */

.missing { display: flex; flex-direction: column; min-height: 100svh; }
.missing > main { display: flex; flex: 1; }
.missing .stack--end > li { flex: var(--words) 1 0; min-height: 5.75rem; }
.missing .masthead h1 { font-size: clamp(2.75rem, 8vw, 6rem); font-stretch: 72%; letter-spacing: -.012em; }

/* ---------- Narrow ---------- */

@media (max-width: 62rem) {
  .doc { grid-template-columns: minmax(0, 1fr); }
  .toc { position: static; max-height: none; overflow: visible; padding: 2rem 0 0; }
  .toc-sub { display: none; }
  .toc ol { display: flex; flex-wrap: wrap; gap: .25rem 1.25rem; }
  .toc li { margin: 0; }
  #content section.band { clip-path: inset(0 -100vmax); }
  .spine { grid-template-columns: 4.75rem minmax(0, 1fr) minmax(9rem, 11rem) 1.5rem; align-content: center; }
  .spine-result { grid-column: 2; grid-row: 2; margin-top: .5rem; }
  .spine-title { grid-column: 2; grid-row: 1; }
  .spine-meta { grid-column: 3; grid-row: 1 / span 2; }
  .spine .arrow { grid-column: 4; grid-row: 1 / span 2; }
  .spine .plate { grid-row: 1 / span 2; }
  .stack > li { min-height: 8rem; }
}

@media (max-width: 40rem) {
  body { font-size: 1.0625rem; }
  .masthead { grid-template-columns: minmax(0, 1fr); }
  .first-view { min-height: 0; }
  .stack > li { flex: none; min-height: calc(var(--words) * .11px + 5rem); }
  .spine {
    grid-template-columns: auto minmax(0, 1fr) 1.5rem;
    gap: .75rem;
    align-content: center;
    padding-block: 1.125rem;
    --title: clamp(2.25rem, 12vw, 3rem);
  }
  [data-book="messaging"] > .spine { --title: clamp(2.75rem, 15vw, 3.75rem); }
  .stack--end .spine { --title: clamp(2rem, 10vw, 2.5rem); }
  .spine-title { grid-column: 1 / span 2; grid-row: 1; }
  .spine .arrow { grid-column: 3; grid-row: 1; }
  .spine-result { grid-column: 1 / -1; grid-row: 2; margin: 0; }
  .spine .plate { grid-column: 1; grid-row: 3; }
  .spine-meta { grid-column: 2 / -1; grid-row: 3; flex-direction: row; flex-wrap: wrap; gap: 0 .75rem; font-size: .8125rem; }
  .spine:hover, .spine:focus-visible { transform: none; box-shadow: none; }
  .cover { min-height: 78svh; }
  .cover-body { grid-template-columns: minmax(0, 1fr); }
  .cover h1 { font-size: clamp(3.25rem, 17vw, 5rem); }
  .cover-meta { justify-self: start; flex-direction: row; flex-wrap: wrap; gap: 0 .875rem; font-size: .9375rem; }
  .spec { grid-template-columns: minmax(0, 1fr); }
  .spec dt { padding-bottom: 0; border-bottom: 0; }
  .spec dd { padding-top: .125rem; }
  #content section > dl:not(.spec) { grid-template-columns: minmax(0, 1fr); }
  #content section > dl:not(.spec) dt { padding: .75rem 0 0; grid-column: 1; }
  #content section > dl:not(.spec) dt:nth-of-type(3) { padding-top: .75rem; }
  #content section > dl:not(.spec) dd { padding: .125rem 0 .25rem; }
  #content section > dl:not(.spec) dd:nth-of-type(3) { margin-top: .25rem; padding: .75rem .875rem; }
  .parts table, .parts tbody, .parts tr, .parts td, .parts tbody th { display: block; }
  .parts thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
  .parts tr { padding: .875rem 0; border-bottom: 1px solid var(--rule); }
  .parts th, .parts td { padding: 0 0 .25rem; border: 0; }
  .parts tbody th { white-space: normal; overflow-wrap: anywhere; }
}

/* ---------- The one authored moment: a spine opens into its cover ---------- */

@view-transition { navigation: auto; }
[data-book="messaging"]  > .spine, body[data-book="messaging"]  > .cover { view-transition-name: book-messaging; }
[data-book="purchasing"] > .spine, body[data-book="purchasing"] > .cover { view-transition-name: book-purchasing; }
[data-book="tax"]        > .spine, body[data-book="tax"]        > .cover { view-transition-name: book-tax; }
[data-book="training"]   > .spine, body[data-book="training"]   > .cover { view-transition-name: book-training; }
::view-transition-group(*) { animation-duration: .55s; animation-timing-function: var(--ease); }
::view-transition-old(*), ::view-transition-new(*) { height: 100%; object-fit: cover; overflow: clip; }

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .spine, .spine .arrow { transition: none; }
  .spine:hover, .spine:focus-visible { transform: none; box-shadow: none; }
  @view-transition { navigation: none; }
}

@media print {
  .toc, .more, .skip, .back { display: none; }
  .doc { display: block; }
  .cover { min-height: 0; }
}
