/* The bead field behind every page (field.js draws it), and the blocks that hold the content.
   Every part of a page sits in its own block: the head of a section, a run of text, a list, a figure,
   and each column of a two-column part. The beads show in the gaps between the blocks, and faintly
   through the blocks themselves. */
:root {
  --pad: clamp(16px, 2.2vw, 24px);     /* space inside a block */
  --gap: 14px;                         /* space between the blocks of one part */
  --space: clamp(30px, 4vw, 46px);     /* space between the parts of a page */
  --block: rgba(213, 216, 220, .86);   /* the page color (--ground), a little faded */
  --block-paper: rgba(228, 230, 233, .9);   /* --paper, a little faded */
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) { --block: rgba(0, 0, 0, .8); --block-paper: rgba(20, 23, 27, .86); }
}
:root[data-theme="dark"] { --block: rgba(0, 0, 0, .8); --block-paper: rgba(20, 23, 27, .86); }

#field { position: fixed; left: 0; top: 0; z-index: 0; display: block; width: 100%; height: 100vh; height: 100lvh; pointer-events: none; }
.field-scale {
  position: fixed; z-index: 0; left: 18px; bottom: 16px; display: flex; flex-direction: column; align-items: flex-start; gap: 6px;
  font: .72rem/1.35 var(--mono); color: var(--muted); pointer-events: none;
  padding: 6px 8px; background: var(--block);
}
.field-scale p { display: flex; align-items: flex-end; gap: 8px; margin: 0; line-height: 1; }
.field-scale i { display: block; height: 7px; border: 2px solid var(--ink); border-top: 0; }
.field-scale b { color: var(--ink); font-weight: 500; white-space: nowrap; }
@media (max-width: 899px) { .field-scale { display: none; } }

/* ------------------------------------------------------------------ the parts of a page */
/* A part is a top-level part of a page, or a group of projects on the projects page (.wrap > div > section). */
.wrap { position: relative; z-index: 1; }
.wrap > * + *, .wrap > div > section + section { margin-top: var(--space) !important; }
/* the menu stays one solid bar, since the page scrolls under it */
.wrap > .nav { padding: 11px var(--pad); border: 1px solid var(--rule); }
/* a part with several blocks lines them up with the same gap between them */
:is(.wrap, .wrap > div) > section:not(.lesson) { display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--gap); align-content: start; }
:is(.wrap, .wrap > div) > section > :is(.paper, .ind) { border-top: 0; padding-top: 0; }
.wrap > .lesson { border-top: 0; padding-top: 0; }
:is(.paper, .ind) > .figs, :is(.wrap, .wrap > div) > section > .tracks { display: grid; gap: var(--gap); }
/* blocks side by side keep their own height, so the field shows below the shorter one */
:is(.wrap, .wrap > div) > section > :is(.methods, .cv, .chooser, .demos, .overview, .teaser) { align-items: start; }

/* ------------------------------------------------------------------ the blocks */
.wrap > :is(.pagehead, .pillars, .facts, .pager, footer),
.wrap > .top > *,
:is(.wrap, .wrap > div) > section > :not(.teaser, .overview, .paper, .ind, .methods, .cv, .chooser, .demos, .tracks),
:is(.wrap, .wrap > div) > section > :is(.teaser, .overview, .methods, .cv, .chooser, .demos, .tracks) > *,
:is(.wrap, .wrap > div) > section > :is(.paper, .ind) > :not(.figs),
:is(.paper, .ind) > .figs > * {
  margin-block: 0 !important; padding: var(--pad); border: 1px solid var(--rule); background: var(--block);
}
.wrap > :is(.pagehead, .pillars, .facts, .pager, footer) { margin-block: var(--space) 0 !important; }

/* the same space at the top and the bottom of every block: no extra margin or padding after the last line */
:is(.wrap > *, .wrap > * > *, section > *, section > * > *, .figs > *) > :first-child { margin-top: 0; }
.wrap :is(section, .top, .pagehead, footer, .pillars, .facts) :last-child { margin-bottom: 0; }
.wrap :is(section, .top) :is(li, .item, .row):last-child { padding-bottom: 0; }
.wrap .cases { border-top: 0; }
.wrap .cases > li:last-child { border-bottom: 0; }
/* a list at the top of a block starts right at the padding, without the line above its first item */
:is(.wrap, .wrap > div) > section > :is(ul, ol, div):not(.indnav) > :is(li, .item, .row):first-child:not(.lead),
:is(.wrap, .wrap > div) > section > * > :is(ul, ol):first-child > li:first-child { padding-top: 0; border-top: 0; }
#thesis > .w:first-child { display: block; line-height: 1.3; }

/* blocks that hug their text, so the field shows beside them */
:is(.wrap, .wrap > div) > section > .head { width: fit-content; max-width: 100%; gap: 6px 32px; padding-block: 12px; border-bottom: 2px solid var(--ink); }
.wrap > .pagehead { max-width: calc(46em + 2 * var(--pad) + 2px); }
.wrap > .pagehead > * { max-width: 46em; }
section > :is(.intro, .upload, .warn, .qa, .steps) { max-width: calc(46em + 2 * var(--pad) + 2px) !important; }
section > .also { max-width: calc(52em + 2 * var(--pad) + 2px); }
:is(.wrap, .wrap > div) > section > :is(.upload, .warn) { border: 1px dashed var(--b); padding-block: 14px; }
/* boxes that stand out keep their lighter color, faded like the rest */
:is(.wrap, .wrap > div) > section > .thesis, :is(.wrap, .wrap > div) > section > .chooser > .answer, .repos li.lead { background: var(--block-paper); }
.wrap > .pillars a { padding-top: 4px; }

/* small parts that belong to the block before them are joined to it */
:is(.wrap, .wrap > div) > section > :is(.sub:has(+ .repos), .beads:has(+ .legend), .phases:has(+ p), .intro:has(+ .intro), .indnav:has(+ .also)) {
  border-bottom: 0; padding-bottom: 0;
}
:is(.wrap, .wrap > div) > section > :is(.sub + .repos, .beads + .legend, .phases + p, .intro + .intro, .indnav + .also) {
  border-top: 0; margin-top: calc(-1 * var(--gap)) !important;
}
:is(.wrap, .wrap > div) > section > .sub + .repos { padding-top: 12px; }
:is(.wrap, .wrap > div) > section > .beads + .legend { padding-top: 8px; }
:is(.wrap, .wrap > div) > section > :is(.phases + p, .intro + .intro, .indnav + .also) { padding-top: 16px; }
:is(.wrap, .wrap > div) > section > .indnav + .also { max-width: none; }

/* on phones the blocks almost reach the edges of the screen, with a thin line of beads beside them */
@media (max-width: 699px) {
  :root { --gap: 10px; --space: 28px; }
  .wrap { padding-left: max(8px, env(safe-area-inset-left, 0px)); padding-right: max(8px, env(safe-area-inset-right, 0px)); }
}

@media print {
  #field, .field-scale { display: none; }
  :root, :root:not([data-theme="light"]), :root[data-theme="dark"] { --block: transparent; --block-paper: transparent; }
}
@media (forced-colors: active) { #field, .field-scale { display: none; } }
