/* The quilt. Colours come from fabric.css, which build.py generates and checks for AA. */

:root {
  --ink: var(--ground-on);
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", "Noto Sans", Arial, sans-serif;
  --seam: 2px;
  --pad: 12px;
  --strip: 14px;
  color-scheme: light dark;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  scroll-padding-top: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--ground);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 1.0625rem;
  line-height: 1.5;
}

p {
  margin: 0;
}

/* The strip: half-square triangles in the two parents' colours, the oldest piece in quilting */

.strip {
  display: block;
  flex: none;
  height: var(--strip);
  background-image: linear-gradient(135deg, var(--a) 50%, var(--b) 50%);
  background-size: var(--strip) var(--strip);
}

/* ------------------------------------------------------------------ the band */

.band {
  position: relative;
  padding: 18px 16px 16px;
  background: var(--ground);
}

.band__rest h1 {
  margin: 0;
  font-size: 15.2vw;
  font-weight: 900;
  letter-spacing: -0.04em;
  line-height: 0.95;
}

.band__how {
  display: grid;
  gap: 6px;
  margin-top: 14px;
  color: var(--muted);
  font-size: 0.9375rem;
  line-height: 1.35;
}

.band__how p:first-child {
  color: var(--ink);
  font-weight: 600;
}

.only-hover {
  display: none;
}

@media (hover: hover) and (pointer: fine) {
  .only-hover {
    display: inline;
  }

  .only-touch {
    display: none;
  }
}

/* The reader takes over the band while someone is being read */

.reader {
  position: fixed;
  z-index: 10;
  top: 0;
  right: 0;
  left: 0;
  display: grid;
  gap: 4px;
  padding: 14px 16px;
  background: var(--f);
  color: var(--t);
  pointer-events: none;
  box-shadow: 0 8px 28px rgb(0 0 0 / 28%);
}

.reader[hidden] {
  display: none;
}

.reader.is-low {
  top: auto;
  bottom: 0;
  box-shadow: 0 -8px 28px rgb(0 0 0 / 28%);
}

.reader__name {
  font-size: 2.6rem;
  font-weight: 900;
  letter-spacing: -0.035em;
  line-height: 1;
}

.reader__text {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.reader__dates {
  font-size: 0.9375rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.reader__dates:empty {
  display: none;
}

.reader__bio {
  font-size: 1.0625rem;
  line-height: 1.35;
}

.reader__hint {
  font-size: 0.875rem;
  font-weight: 600;
}

.peek {
  display: none;
}

/* ----------------------------------------------------------------- the quilt */

/* The band and the quilt fill the screen together, whatever height the band ends up */
.home {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100svh;
}

.quilt {
  display: grid;
  flex: 1;
  gap: var(--seam);
}

.roots {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: var(--seam);
}

/* Three columns on a phone, six on a tablet, twelve on a desktop: George Jr. and Randall's
   family together make three units, and so does each of the other three families. */
.branches {
  --cols: 3;
  display: grid;
  grid-template-columns: repeat(var(--cols), minmax(0, 1fr));
  gap: var(--seam);
  margin: 0;
  padding: 0;
  list-style: none;
}

.branch,
.marriage {
  display: grid;
  grid-column: span var(--u);
  grid-template-columns: subgrid;
}

.branch {
  grid-row: span 3;
  grid-template-rows: subgrid;
}

.branch > .patch {
  grid-column: 1 / -1;
}

.branch--solo > .patch {
  grid-row: 1 / -1;
}

.marriages {
  display: grid;
  grid-column: 1 / -1;
  grid-row: 2 / span 2;
  grid-template-columns: subgrid;
  grid-template-rows: subgrid;
  margin: 0;
  padding: 0;
  list-style: none;
}

.marriage {
  grid-row: 1 / -1;
  grid-template-rows: subgrid;
}

.marriage > .patch {
  grid-column: 1 / -1;
}

.kids {
  display: grid;
  grid-column: 1 / -1;
  grid-row: 2;
  grid-template-columns: subgrid;
  margin: 0;
  padding: 0;
  list-style: none;
}

.kids > li {
  display: grid;
  min-width: 0;
}

/* A patch */

.patch {
  --fs: 1rem;
  position: relative;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--f);
  color: var(--t);
}

/* Only the script turns this on, so patches never fade in while a page is loading */
.can-fade .patch {
  transition: background-color 0.18s ease, color 0.18s ease;
}

.patch__link {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 3px;
  padding: var(--pad);
  color: inherit;
  text-decoration: none;
}

.patch__link::after {
  content: "";
  position: absolute;
  z-index: 1;
  inset: 0;
}

.patch__link:focus-visible {
  outline: none;
}

.patch__link:focus-visible::after {
  outline: 3px solid currentcolor;
  outline-offset: -6px;
}

.patch__name {
  font-size: var(--fs);
  font-weight: 750;
  letter-spacing: -0.012em;
  line-height: 1.12;
  overflow-wrap: break-word;
}

.patch__role {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: max(0.8125rem, calc(var(--fs) * 0.38));
  font-weight: 600;
  line-height: 1.2;
}

.ring {
  flex: none;
  width: 18px;
  height: 10px;
  fill: none;
  stroke: currentcolor;
  stroke-width: 1.6;
}

.patch__years {
  font-size: max(0.875rem, calc(var(--fs) * 0.42));
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}

/* The small note: same fabric, small type, no patch of its own */

.patch__note {
  position: relative;
  z-index: 2;
  padding: 0 var(--pad) 6px;
  font-size: 0.8125rem;
  line-height: 1.25;
  pointer-events: none;
}

.patch__note a {
  display: inline-block;
  padding: 4px 0;
  color: inherit;
  pointer-events: auto;
  text-underline-offset: 2px;
}

.patch__note a:hover {
  text-decoration-thickness: 2px;
}

.patch__note a:focus-visible {
  outline: 2px solid currentcolor;
  outline-offset: 1px;
}

.patch--root {
  --fs: 1.3rem;
  min-height: 118px;
}

.patch--g2 {
  --fs: 1.45rem;
  min-height: 92px;
}

.patch--g2.patch--u1 {
  --fs: clamp(0.875rem, 4.5vw, 1.0625rem);
  --pad: 10px;
}

.patch--spouse {
  --fs: 1.125rem;
  min-height: 74px;
}

.patch--spouse.patch--u1 {
  --fs: 1rem;
}

.patch--g3 {
  --fs: clamp(0.875rem, 4.2vw, 1rem);
  --pad: 10px;
  min-height: 88px;
}

/* An arrow shows on the patch being read */

.patch.is-current .patch__link::before,
.patch__link:hover::before {
  content: "→";
  position: absolute;
  right: 10px;
  bottom: 6px;
  font-size: 1.25rem;
  font-weight: 700;
  line-height: 1;
}

.patch--root .patch__link:hover::before,
.patch--root.is-current .patch__link::before {
  font-size: 2rem;
}

/* While someone is being read, only their closest family keeps its colour.
   Backgrounds change rather than opacity, so the dimmed text keeps its contrast. */

.quilt.is-reading .patch:not(.is-lit) {
  background: var(--thread);
  background: color-mix(in srgb, var(--f) 14%, var(--ground));
  color: var(--ink);
}

.quilt.is-reading .patch:not(.is-lit) .strip {
  opacity: 0.22;
}

.quilt.is-reading .patch.is-current {
  z-index: 2;
}

/* --------------------------------------------------------------- person pages */

.hero {
  position: relative;
  display: flex;
  flex-direction: column;
  background: var(--f);
  color: var(--t);
}

.hero .strip {
  --strip: 24px;
}

.hero__inner {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 36px;
  min-height: 0;
  padding: 16px 16px 26px;
}

.back {
  display: inline-flex;
  align-items: center;
  align-self: flex-start;
  gap: 12px;
  color: inherit;
  font-weight: 600;
  text-decoration: none;
}

.back__text {
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}

.back:hover .back__text {
  text-decoration-thickness: 2px;
}

.back:focus-visible,
.site-link:focus-visible {
  outline: 3px solid currentcolor;
  outline-offset: 3px;
}

/* The row with the family tree link on the left and a person's own site on the right */

.hero__top {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px 24px;
}

.site-link {
  margin-left: auto;
  color: inherit;
  font-weight: 600;
  text-decoration: none;
}

.site-link:hover .back__text {
  text-decoration-thickness: 2px;
}

/* The little map of the whole quilt, with this person marked */

.map {
  display: grid;
  flex: none;
  grid-template-columns: 1.3fr repeat(11, 1fr);
  grid-template-rows: repeat(4, 1fr);
  gap: 1px;
  width: 84px;
  height: 52px;
  padding: 3px;
  background: var(--ground);
}

.map i {
  display: block;
  min-width: 0;
  background: var(--f);
}

.map .is-here {
  background: var(--ink);
  box-shadow: 0 0 0 1.5px var(--ground), 0 0 0 3px var(--ink);
  position: relative;
  z-index: 1;
}

/* Marjorie, Elaine and Glenn have no patch, so their map marks a sliver of their partner's */
.map .is-sliver {
  position: relative;
  z-index: 1;
  align-self: end;
  height: 3px;
}

.hero h1 {
  margin: 0;
  font-size: 13.2vw;
  font-weight: 900;
  letter-spacing: -0.035em;
  line-height: 0.98;
}

.hero h1 span {
  display: block;
}

.hero__names {
  display: flex;
  flex-wrap: wrap;
  gap: 2px 18px;
  margin: 16px 0 0;
  padding: 0;
  font-size: 1rem;
  font-weight: 500;
  list-style: none;
}

.hero__dates {
  margin-top: 6px;
  font-size: 1.125rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.read {
  min-width: 0;
  padding: 28px 16px 0;
}

.read a {
  color: inherit;
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}

.read a:hover {
  text-decoration-thickness: 2px;
}

.read a:focus-visible {
  outline: 3px solid var(--ink);
  outline-offset: 2px;
}

.bio {
  max-width: 40rem;
  font-size: 1.125rem;
  line-height: 1.6;
}

.bio p + p {
  margin-top: 1em;
}

.read > section + section {
  margin-top: 38px;
}

.read h2 {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 0 14px;
  font-size: 1.375rem;
  font-weight: 800;
  letter-spacing: -0.015em;
  line-height: 1.2;
}

.read h2::before {
  content: "";
  flex: none;
  width: 14px;
  height: 14px;
  background: var(--f);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--ink) 25%, transparent);
}

.family h3 {
  margin: 16px 0 6px;
  color: var(--muted);
  font-size: 0.875rem;
  font-weight: 600;
  line-height: 1.3;
}

.family h2 + h3 {
  margin-top: 0;
}

.minis {
  display: grid;
  grid-template-columns: repeat(var(--cols), minmax(0, 1fr));
  gap: var(--seam);
}

.patch--mini {
  --pad: 10px;
  --fs: 0.9375rem;
  grid-column: span var(--span, 1);
  min-height: 74px;
}

.patch--mini .patch__link {
  color: var(--t);
}

.patch--mini .patch__link:hover {
  text-decoration: underline;
  text-decoration-thickness: 2px;
  text-underline-offset: 3px;
}

.family__note {
  margin-top: 8px;
  color: var(--muted);
  font-size: 0.875rem;
}

.timeline {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0;
  max-width: 44rem;
  margin: 0;
}

.timeline dt {
  color: var(--muted);
  font-size: 0.9375rem;
  font-variant-numeric: tabular-nums;
}

.timeline dd {
  margin: 0 0 10px;
}

.sources {
  font-size: 0.9375rem;
}

.sources ul {
  margin: 0;
  padding: 0;
  list-style: none;
}

.sources li {
  margin-bottom: 4px;
}

.foot {
  margin-top: 44px;
  padding: 16px 0 28px;
  border-top: 2px solid var(--ink);
  font-size: 0.9375rem;
  font-weight: 700;
}

/* Marjorie, Elaine and Glenn: one plain column, no field of colour, smaller type */

.person--minor .hero__inner {
  gap: 24px;
  max-width: 44rem;
  padding-bottom: 22px;
}

.person--minor .hero h1 {
  font-size: clamp(1.625rem, 6vw, 2.125rem);
  font-weight: 750;
  letter-spacing: -0.015em;
  line-height: 1.15;
}

.person--minor .hero h1 span {
  display: inline;
}

.person--minor .hero__names {
  margin-top: 6px;
  font-size: 0.9375rem;
}

.person--minor .hero__dates {
  font-size: 0.9375rem;
  font-weight: 500;
}

.person--minor .bio {
  font-size: 1.0625rem;
}

.person--minor .minis {
  max-width: 24rem;
}

.person--minor .read {
  max-width: 44rem;
}

/* Long family rows wrap when the family section itself is narrow */

.family {
  container-type: inline-size;
}

@container (max-width: 620px) {
  .minis--4 {
    --cols: 2 !important;
  }

  .minis--5 {
    --cols: 3 !important;
  }

  /* A single spouse patch spanning all their children still spans the whole row */
  .minis--5 > .patch--mini:only-child,
  .minis--4 > .patch--mini:only-child {
    grid-column: 1 / -1;
  }
}

@container (max-width: 340px) {
  .minis--5 {
    --cols: 2 !important;
  }
}

/* ---------------------------------------------------------------------- tablet */

@media (min-width: 680px) {
  :root {
    --pad: 14px;
    --strip: 16px;
  }

  .band {
    padding: 22px 20px 20px;
  }

  .band__rest h1 {
    font-size: 10vw;
  }

  .band__how {
    grid-template-columns: 1fr 1fr;
    gap: 6px 28px;
    font-size: 1rem;
  }

  .band__how p:first-child {
    grid-column: 1 / -1;
  }

  .reader {
    grid-template-columns: auto minmax(0, 1fr);
    align-items: center;
    gap: 24px;
    padding: 18px 20px;
  }

  .reader__name {
    font-size: 3.6rem;
  }

  .branches {
    --cols: 6;
    grid-template-rows: repeat(6, auto);
  }

  .patch--root {
    --fs: 2rem;
    min-height: 140px;
  }

  .patch--g2 {
    --fs: 1.75rem;
  }

  .patch--g2.patch--u2 {
    --fs: 1.5rem;
  }

  .patch--g2.patch--u1 {
    --fs: clamp(0.9375rem, 2.2vw, 1.25rem);
    --pad: 10px;
  }

  .patch--spouse {
    --fs: 1.25rem;
  }

  .patch--spouse.patch--u1 {
    --fs: 1.0625rem;
  }

  .patch--g3 {
    --fs: clamp(0.9375rem, 2.2vw, 1.0625rem);
  }

  .hero__inner {
    padding: 20px 24px 32px;
  }

  .hero h1 {
    font-size: 11vw;
  }

  .read {
    padding: 36px 24px 0;
  }

  .timeline {
    grid-template-columns: 9.5rem minmax(0, 1fr);
    gap: 8px 18px;
  }

  .timeline dd {
    margin: 0;
  }

  .timeline dt {
    font-size: 1rem;
  }
}

/* ----------------------------------------------------------------- side by side */

@media (min-width: 960px) {
  .person:not(.person--minor) {
    display: grid;
    grid-template-columns: minmax(0, 42fr) minmax(0, 58fr);
    align-items: start;
  }

  .person:not(.person--minor) .hero {
    position: sticky;
    top: 0;
    height: 100vh;
    height: 100svh;
    overflow: auto;
  }

  .person:not(.person--minor) .hero__inner {
    justify-content: space-between;
    padding: 24px clamp(24px, 3vw, 44px) clamp(28px, 4vw, 56px);
  }

  .person:not(.person--minor) .hero h1 {
    font-size: clamp(3.2rem, 5.6vw, 6.5rem);
  }

  .hero .strip {
    --strip: 32px;
  }

  .person:not(.person--minor) .hero__names {
    margin-top: 22px;
    font-size: 1.0625rem;
  }

  .person:not(.person--minor) .hero__dates {
    font-size: 1.25rem;
  }

  .person:not(.person--minor) .read {
    padding: clamp(32px, 5vw, 72px) clamp(28px, 5vw, 84px) 0;
  }

  .map {
    width: 112px;
    height: 68px;
  }

  .patch--mini {
    --fs: 1rem;
    min-height: 84px;
  }
}

/* ---------------------------------------------- the whole quilt on a single screen */

@media (min-width: 1060px) {
  :root {
    --band-height: clamp(128px, 10.8vw, 188px);
    --strip: clamp(16px, 1.45vw, 26px);
  }

  html {
    scroll-padding-top: calc(var(--band-height) + 16px);
  }

  .band {
    position: sticky;
    z-index: 5;
    top: 0;
    display: flex;
    align-items: center;
    min-height: var(--band-height);
    padding: 12px 24px;
  }

  .band__rest {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    align-items: center;
    gap: clamp(24px, 3vw, 56px);
    width: 100%;
  }

  .band__rest h1 {
    font-size: clamp(3.9rem, 6.6vw, 7rem);
    white-space: nowrap;
  }

  .band__how {
    display: grid;
    grid-template-columns: 1fr;
    gap: 3px;
    margin: 0;
    font-size: clamp(0.875rem, 1.02vw, 1.0625rem);
    line-height: 1.3;
  }

  .reader {
    position: absolute;
    inset: 0;
    gap: clamp(24px, 3vw, 56px);
    padding: 10px 24px;
    box-shadow: none;
    transition: background-color 0.18s ease;
  }

  .reader.is-low {
    top: 0;
    bottom: 0;
    box-shadow: none;
  }

  .reader__name {
    font-size: clamp(3.9rem, 6.6vw, 7rem);
    letter-spacing: -0.04em;
    line-height: 0.95;
  }

  .reader__bio {
    font-size: clamp(1rem, 1.3vw, 1.3125rem);
    line-height: 1.3;
  }

  .quilt {
    grid-template-rows: minmax(min-content, 1fr) minmax(min-content, 3fr);
  }

  /* George Jr.'s column and Randall's two children have the longest words to fit */
  .branches {
    --cols: 12;
    grid-template-columns: minmax(0, 1.25fr) repeat(2, minmax(0, 1.22fr)) repeat(9, minmax(0, 1fr));
    grid-template-rows: minmax(min-content, 1.05fr) minmax(min-content, 0.72fr) minmax(min-content, 1fr);
  }

  .patch--root {
    --fs: clamp(1.75rem, 3.1vw, 3.4rem);
    --pad: clamp(14px, 1.5vw, 26px);
    min-height: 0;
  }

  .patch--g2 {
    --fs: clamp(1.5rem, 2.25vw, 2.6rem);
    --pad: clamp(12px, 1.2vw, 20px);
    min-height: 0;
  }

  .patch--g2.patch--u2 {
    --fs: clamp(1.25rem, 1.8vw, 2.1rem);
  }

  .patch--g2.patch--u1 {
    --fs: clamp(0.875rem, 1.3vw, 1.5rem);
    --pad: clamp(8px, 0.9vw, 16px);
  }

  .patch--spouse {
    --fs: clamp(1.125rem, 1.55vw, 1.75rem);
    --pad: clamp(10px, 1.1vw, 18px);
    min-height: 0;
  }

  .patch--spouse.patch--u1 {
    --fs: clamp(0.9375rem, 1.15vw, 1.25rem);
    --pad: clamp(6px, 0.75vw, 12px);
  }

  .patch--spouse.patch--u1 .patch__role {
    font-size: 0.75rem;
  }

  .patch--spouse.patch--u1 .ring {
    display: none;
  }

  .patch--g3 {
    --fs: clamp(0.875rem, 1.15vw, 1.3125rem);
    --pad: clamp(6px, 0.75vw, 12px);
    min-height: 0;
  }
}

/* The small notes stay small in the reader too */
.reader.is-minor .reader__name {
  font-size: 1.75rem;
  font-weight: 750;
  letter-spacing: -0.015em;
}

/* ---------------------------------------------------------------------- motion */

@media (prefers-reduced-motion: no-preference) {
  /* Clicking a patch grows it into the person's page, in browsers that can do it */
  @view-transition {
    navigation: auto;
  }

  ::view-transition-group(*) {
    animation-duration: 0.42s;
    animation-timing-function: cubic-bezier(0.22, 0.8, 0.24, 1);
  }

  ::view-transition-old(*),
  ::view-transition-new(*) {
    height: 100%;
    object-fit: cover;
    object-position: left top;
  }

  .enter .patch--root,
  .enter .patch--g2,
  .enter .patch--spouse,
  .enter .patch--g3 {
    animation: piece 0.55s cubic-bezier(0.22, 0.8, 0.24, 1) backwards;
    animation-delay: calc(var(--i) * 26ms);
  }

  @keyframes piece {
    from {
      clip-path: inset(0 100% 0 0);
    }

    to {
      clip-path: inset(0 0 0 0);
    }
  }
}

@media (prefers-reduced-motion: reduce) {
  .can-fade .patch,
  .reader {
    transition: none !important;
  }
}

/* -------------------------------------------------------------- high contrast */

@media (forced-colors: active) {
  .patch,
  .reader {
    border: 1px solid CanvasText;
  }

  .strip {
    display: none;
  }
}
