/*
  Pico spaces elements. This spaces the page.

  Everything here is distance and width — a measure that stays readable, air
  around a heading proportional to what it opens, and a hero that is more than
  an h1 sitting on top of a paragraph. No new colours and no new type: Pico's
  own variables, so light and dark keep working without a second palette to
  maintain.
*/

:root {
  --pico-font-size: 106.25%;
  /* The rhythm between one section and the next, which is the thing Pico has
     no opinion about. */
  --gap: clamp(2.5rem, 7vw, 4.5rem);
}

/* About 75 characters, rather than the width of the window. Pico's container
   grows to 1200px at the top breakpoint, which is a fine width for an app and
   a poor one for a paragraph. */
.container {
  max-width: 44rem;
}

/* Nav ------------------------------------------------------------------- */

body > header {
  padding-block: 0;
}

.site-name {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 700;
  color: var(--pico-contrast);
  text-decoration: none;
}

.site-name img {
  width: 28px;
  height: 28px;
  border-radius: 22%;
}

/* Hero ------------------------------------------------------------------ */

.hero {
  padding-block: clamp(3rem, 9vw, 6rem);
  text-align: center;
  /* The sectioning colour rather than the card one, which in the light theme
     is the same white as the page and made the hero a band of nothing. */
  background: var(--pico-card-sectioning-background-color);
  border-block: 1px solid var(--pico-muted-border-color);
}

.hero img {
  width: 128px;
  height: 128px;
  border-radius: 22%;
  margin-bottom: 1.5rem;
}

.hero h1 {
  margin-bottom: 1rem;
}

.hero .lede {
  max-width: 30rem;
  margin-inline: auto;
  font-size: 1.15rem;
  color: var(--pico-muted-color);
}

/* The badge and the line under it are one thing, so the space between them
   isn't two paragraph margins arguing. */
.hero-cta {
  display: grid;
  justify-items: center;
  gap: 0.5rem;
  margin-top: 2rem;
}

.aside {
  margin: 0;
  font-size: 0.875rem;
  color: var(--pico-muted-color);
}

/* Prose ----------------------------------------------------------------- */

/* A heading takes its space from above, so a section reads as a heading and
   its own body rather than as a line floating between two of them. */
main h2 {
  margin-top: var(--gap);
}

main h3 {
  margin-top: calc(var(--gap) / 2);
}

/* The gap above the first thing on a page, hero or not, so a title never sits
   directly under the navigation. */
main > .container {
  padding-block-start: var(--gap);
}

/* Except the first, which already has the hero or the page title above it. */
main .container > :first-child {
  margin-top: 0;
}

main h1 {
  margin-bottom: 2rem;
}

/* The second ask, at the end of the page rather than tucked under the
   paragraph before it. */
.cta {
  margin-top: 2.5rem;
}

/* Cards ----------------------------------------------------------------- */

/* Wider than the prose it sits among, because three columns of text at
   reading width are three narrow columns. Only where there's room for it. */
@media (min-width: 1024px) {
  main .grid {
    margin-inline: -3rem;
  }
}

/* A border rather than Pico's shadow: three shadows side by side read as one
   smudge behind the row. */
.grid > article {
  margin-bottom: 0;
  border: 1px solid var(--pico-muted-border-color);
  box-shadow: none;
}

.grid > article h3 {
  margin-top: 0;
  font-size: 1.15rem;
}

.grid > article p:last-child {
  margin-bottom: 0;
}

/* Pictures --------------------------------------------------------------- */

main img {
  max-width: 100%;
  height: auto;
  border-radius: 12px;
}

/* An illustration on its own line at 260px left half the column empty, which
   reads as a layout that didn't finish. Centring it only moves the gap to
   both sides. So it goes in the margin and the prose comes up beside it —
   the text keeps its left edge, and the space is used rather than balanced.
   No class to remember: any image alone in a paragraph gets this. */
@media (min-width: 768px) {
  main .container > p > img {
    float: right;
    margin: 0.5rem 0 1.5rem 2rem;
  }

  /* The paragraph is empty once its image floats out of it, and an empty
     paragraph's margin is a gap above the text that's meant to be alongside. */
  main .container > p:has(> img:only-child) {
    margin: 0;
  }

  /* A heading starts its own section, beside nothing. */
  main h2 {
    clear: both;
  }

  /* And the last float has to end inside the page rather than over the
     footer. */
  main > .container {
    display: flow-root;
  }
}

/* On a phone there's no margin to put anything in, so it spans the column
   instead — 260px in a 330px column left a ragged strip down one side. */
@media (max-width: 767px) {
  main .container > p > img {
    width: 100%;
  }
}

/* Out into the gutter, where there's room for it. */
@media (min-width: 1024px) {
  main .container > p > img {
    margin-right: -3rem;
  }
}

/* A phone screenshot in the middle of prose, at the size it would be in a
   hand rather than the width of the column. */
main .shot {
  display: block;
  margin-inline: auto;
  max-width: 15rem;
}

/* The carousel ---------------------------------------------------------- */

/* An iOS paged tab view, which is scroll-snap and nothing else — the browser
   does the paging, the momentum and the rubber-banding. What it doesn't do is
   say where you are, which is what the dots are for. */
.carousel {
  margin-bottom: var(--gap);
}

.carousel-pages {
  display: flex;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  scroll-behavior: smooth;
  /* No scrollbar. A paged view is told apart from a scrolling one by the
     dots, and a bar under the phone gives away that it's a web page. */
  scrollbar-width: none;
}

.carousel-pages::-webkit-scrollbar {
  display: none;
}

/* Whole pages, never a sliver of the next one. The strip that showed part of
   the second screenshot read as a layout bug rather than as an invitation. */
.carousel-pages > figure {
  flex: 0 0 100%;
  scroll-snap-align: center;
  display: grid;
  justify-items: center;
  gap: 0.75rem;
  margin: 0;
}

/* A phone at about the size of a phone, rather than filling the page it sits
   on. */
.carousel img {
  width: 280px;
  max-width: 80%;
  height: auto;
  border-radius: 18px;
  border: 1px solid var(--pico-muted-border-color);
}

.carousel figcaption {
  max-width: 22rem;
  text-align: center;
  font-size: 0.9375rem;
  /* Room for the longest caption, so the dots don't move as you page. */
  min-height: 3em;
}

.carousel-dots {
  display: flex;
  justify-content: center;
  padding-top: 0.5rem;
}

/* The dot is the content box and the padding is the target: 8px to look at,
   24px to hit. `content-box` is load-bearing — under Pico's global
   `border-box` the padding eats the width, the content box collapses to
   nothing, and `background-clip: content-box` then paints nothing at all. */
.carousel-dots a {
  box-sizing: content-box;
  width: 8px;
  height: 8px;
  padding: 8px;
  border-radius: 50%;
  background: var(--pico-muted-border-color);
  background-clip: content-box;
}

.carousel-dots a[aria-current="true"] {
  background: var(--pico-muted-color);
  background-clip: content-box;
}

@media (prefers-reduced-motion: reduce) {
  .carousel-pages {
    scroll-behavior: auto;
  }
}

/* The badge ------------------------------------------------------------- */

/* Apple's clear space, a tenth of the badge height, and no styling of the art
   itself — it's their trademark and it arrives finished. */
.app-store {
  display: inline-block;
  padding: 4px;
}

.app-store img {
  display: block;
  height: 40px;
  width: auto;
  border-radius: 0;
}

/* Accordions ------------------------------------------------------------ */

/* Pico draws these; the spacing is what stops six of them reading as one
   block. */
details {
  border-top: 1px solid var(--pico-muted-border-color);
  border-bottom: none;
  padding-block: 0.5rem;
}

details:last-of-type {
  border-bottom: 1px solid var(--pico-muted-border-color);
}

details summary {
  font-weight: 600;
}

details[open] summary {
  margin-bottom: 1rem;
}

details > :last-child {
  margin-bottom: 1rem;
}

/* Tables and code ------------------------------------------------------- */

figure,
table {
  margin-block: 2rem;
}

/* A comparison table is read down its columns, so the ticks want to line up
   under the heading that names them rather than under the feature. */
table td:not(:first-child),
table th:not(:first-child) {
  text-align: center;
  width: 7rem;
}

pre {
  margin-block: 2rem;
}

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

body > footer {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 2rem;
  justify-content: space-between;
  margin-top: var(--gap);
  padding-block: 2rem;
  border-top: 1px solid var(--pico-muted-border-color);
  color: var(--pico-muted-color);
}
