/* ==========================================================================
   SHEET
   Every detail on the site opens in a sheet: a modal <dialog> that fills the
   screen without painting it, so only its panel moves. On a phone the panel
   rises from the foot with a grip to drag it back down; from 900px it is a
   card in the middle. The menu is the panel variant: the whole screen on a
   phone, uncovered downwards from the bar, and a panel from the right on a
   computer.

   Without scripts a sheet is set out on the page where it stands, as a card,
   and the panel opens with :target.
   ========================================================================== */

.sheet {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  max-width: none;
  max-height: none;
  margin: 0;
  padding: 0;
  border: 0;
  background-color: transparent;
  color: var(--ink);
  overflow: clip; /* not hidden: a hidden box can still be scrolled, and the browser scrolls it to show the focused close button while the panel waits off screen, which throws the panel off course */
}

.sheet::backdrop {
  background-color: transparent;
}

.sheet__scrim {
  position: absolute;
  inset: 0;
  background-color: color-mix(in srgb, var(--ink) 46%, transparent);
  opacity: 0;
  transition: opacity var(--duration-lg) var(--ease-out);
}

.sheet.is-open .sheet__scrim {
  opacity: 1;
}

/* PANEL */

.sheet__panel {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  max-height: calc(100svh - 2.5rem);
  padding-top: 0.5rem;
  padding-left: 1.5rem;
  padding-right: 1.5rem;
  padding-bottom: calc(env(safe-area-inset-bottom) + 2rem);
  border-radius: 28px 28px 0 0;
  background-color: var(--paper);
  box-shadow: 0 -20px 60px -30px color-mix(in srgb, var(--ink) 60%, transparent);
  overflow-y: auto;
  overscroll-behavior: contain;
  transform: translateY(100%);
  transition: transform var(--duration-lg) var(--ease-screen);
}

/* Tablet Landscape Up - Min 900px */
@media (min-width: 900px) {
  .sheet__panel {
    left: 50%;
    right: auto;
    top: 50%;
    bottom: auto;
    width: 560px;
    max-height: calc(100svh - 6rem);
    padding-top: 1.25rem;
    padding-left: 2.5rem;
    padding-right: 2.5rem;
    padding-bottom: 2.5rem;
    border-radius: 36px;
    opacity: 0;
    transform: translate(-50%, -46%) scale(0.96);
    transition: transform var(--duration-lg) var(--ease-out), opacity var(--duration-md) ease;
  }
}

.sheet.is-open .sheet__panel {
  transform: translateY(var(--sheet-drag, 0px));
}

/* Tablet Landscape Up - Min 900px */
@media (min-width: 900px) {
  .sheet.is-open .sheet__panel {
    opacity: 1;
    transform: translate(-50%, -50%);
  }
}

.sheet.is-dragging .sheet__panel {
  transition: none;
}

/* GRIP */

/* The top of the panel: a handle to drag on a phone, and the close button. */
.sheet__grip {
  position: sticky;
  top: -0.5rem;
  z-index: 2;
  display: flex;
  justify-content: flex-end;
  margin-left: -1.5rem;
  margin-right: -1.5rem;
  padding-top: 0.5rem;
  padding-right: 0.875rem;
  padding-bottom: 0.25rem;
  padding-left: 0.875rem;
  background-color: var(--paper);
  touch-action: none;
}

/* Tablet Landscape Up - Min 900px */
@media (min-width: 900px) {
  .sheet__grip {
    position: static;
    margin-left: 0;
    margin-right: -1.25rem;
    padding: 0;
    background-color: transparent;
  }
}

.sheet__grip::before {
  content: "";
  position: absolute;
  top: 0.375rem;
  left: 50%;
  width: 40px;
  height: 5px;
  margin-left: -20px;
  border-radius: 999px;
  background-color: color-mix(in srgb, var(--ink) 18%, transparent);
}

/* Tablet Landscape Up - Min 900px */
@media (min-width: 900px) {
  .sheet__grip::before {
    display: none;
  }
}

.sheet__close {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 999px;
  background-color: color-mix(in srgb, var(--ink) 7%, transparent);
  color: var(--ink);
  transition: background-color var(--duration-sm) ease, transform var(--duration-sm) var(--ease-out);
}

.sheet__close:hover {
  background-color: color-mix(in srgb, var(--ink) 12%, transparent);
}

.sheet__close:active {
  transform: scale(0.9);
}

/* CONTENT */

/* What most sheets hold: a heading, a sentence or two, and a line of facts. */
.sheet__content h2 {
  margin-top: 0.25rem;
  font-size: 34px;
}

/* Tablet Landscape Up - Min 900px */
@media (min-width: 900px) {
  .sheet__content h2 {
    font-size: 40px;
  }
}

.sheet__content > p {
  margin-top: 0.875rem;
  font-size: 18px;
  line-height: 1.45;
  color: var(--ink-lighter);
}

.sheet__content figure {
  margin-top: 0.25rem;
  margin-bottom: 1.25rem;
  overflow: hidden;
  border-radius: 20px;
  aspect-ratio: 16 / 10;
}

.sheet__content figure img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.sheet__content ul {
  margin-top: 1.5rem;
  border-top: 1px solid color-mix(in srgb, var(--ink) 10%, transparent);
}

.sheet__content li {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding-top: 0.875rem;
  padding-bottom: 0.875rem;
  border-bottom: 1px solid color-mix(in srgb, var(--ink) 10%, transparent);
  font-size: 16px;
}

.sheet__content li span:first-child {
  color: var(--slate);
}

.sheet__content li span:last-child {
  font-weight: 650;
  text-align: right;
}

.sheet__content .button {
  margin-top: 1.75rem;
}

/* PANEL */

.sheet--panel .sheet__panel {
  top: 0;
  bottom: 0;
  max-height: none;
  padding-top: env(safe-area-inset-top);
  padding-left: 1.25rem;
  padding-right: 1.25rem;
  padding-bottom: calc(env(safe-area-inset-bottom) + 2.5rem);
  border-radius: 0;
  box-shadow: none;
  clip-path: inset(0 0 100% 0);
  transform: none;
  transition: clip-path var(--duration-lg) var(--ease-screen);
}

/* Tablet Landscape Up - Min 900px */
@media (min-width: 900px) {
  .sheet--panel .sheet__panel {
    top: 0;
    bottom: 0;
    left: auto;
    right: 0;
    width: 440px;
    padding-left: 2.5rem;
    padding-right: 2.5rem;
    padding-bottom: 2.5rem;
    border-radius: 32px 0 0 32px;
    box-shadow: -20px 0 60px -30px color-mix(in srgb, var(--ink) 60%, transparent);
    clip-path: none;
    opacity: 1;
    transform: translateX(100%);
    transition: transform var(--duration-lg) var(--ease-screen);
  }
}

.sheet--panel.is-open .sheet__panel {
  clip-path: inset(0 0 0 0);
  transform: none;
}

/* Tablet Landscape Up - Min 900px */
@media (min-width: 900px) {
  .sheet--panel.is-open .sheet__panel {
    clip-path: none;
    transform: none;
  }
}

/* On a phone the whole screen is the panel, so there is no shade. */
.sheet--panel .sheet__scrim {
  display: none;
}

/* Tablet Landscape Up - Min 900px */
@media (min-width: 900px) {
  .sheet--panel .sheet__scrim {
    display: block;
  }
}

/* REDUCED MOTION */

@media (prefers-reduced-motion: reduce) {
  .sheet__panel {
    transition: opacity var(--duration-sm) linear;
  }
}

/* WITHOUT SCRIPTS */

.no-js .sheet:not(.sheet--panel) {
  position: static;
  display: block;
  width: auto;
  height: auto;
  overflow: visible;
}

.no-js .sheet:not(.sheet--panel) .sheet__panel {
  position: static;
  max-height: none;
  margin-top: 1rem;
  border-radius: 24px;
  background-color: var(--white);
  color: var(--ink);
  opacity: 1;
  transform: none;
}

.no-js .sheet__scrim,
.no-js .sheet__grip {
  display: none;
}

.no-js .sheet--panel:target {
  z-index: 60;
  display: block;
}

.no-js .sheet--panel:target .sheet__panel {
  clip-path: none;
  transform: none;
}

/* While a sheet is open the page behind it does not scroll. */
.is-sheet-open,
.is-sheet-open body {
  overflow: hidden;
}
