/*
 * Responsible for: the page around every screen: the banner at the top, the footer at the bottom, the main area between
 * them, and the two ways a screen sits in it (`.ia-page`, an ordinary scrolling page; `.ia-page--window`, a screen that
 * fills the laptop window and scrolls inside its own parts).
 *
 * Must never: change the banner or footer from screen to screen (same links, same place, same size), let the banner
 * leave the top of the window however far a page is scrolled, let a link grow when it is marked as the current one (the
 * bar would shift and the links beside it would move), hide a banner link behind a menu on a phone, let the four links
 * and the brand wrap or be cut off at 390 px wide, or leave wide empty margins on a laptop.
 */

@layer base {
  :root {
    --ia-head: calc(var(--head-h) + env(safe-area-inset-top, 0px));
    --ia-gutter: var(--s-4);
    --ia-wide: 1680px;
    --ia-reading: 1120px;
    --ia-window-min: 30rem;
    /* The footer's height on a laptop, where a window screen ends exactly above it. */
    --ia-foot: calc(var(--tap) + 1px);
  }

  @media (min-width: 640px) {
    :root {
      --ia-gutter: var(--s-5);
    }
  }

  /* A place the address can scroll to (the pricing section) must stop below the sticky banner, not under it. */
  [data-section] {
    scroll-margin-top: calc(var(--ia-head) + var(--s-4));
  }

  .ia-skip {
    position: absolute;
    top: var(--s-2);
    left: var(--s-2);
    z-index: var(--z-notice);
    padding: var(--s-3) var(--s-4);
    border-radius: var(--r-md);
    background: var(--panel);
    color: var(--ink);
    font-weight: 600;
    box-shadow: var(--shadow-2);
    transform: translateY(-200%);
  }

  .ia-skip:focus {
    transform: translateY(0);
  }

  /* The banner */
  .ia-banner {
    position: sticky;
    top: 0;
    z-index: var(--z-sticky);
    padding: env(safe-area-inset-top, 0px) max(var(--ia-gutter), env(safe-area-inset-right, 0px)) 0 max(var(--ia-gutter), env(safe-area-inset-left, 0px));
    border-bottom: 1px solid var(--rule);
    background: var(--panel);
  }

  .ia-banner__row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--s-3);
    height: var(--head-h);
    max-width: var(--ia-wide);
    margin-inline: auto;
  }

  .ia-banner__brand {
    display: inline-flex;
    align-items: center;
    gap: var(--s-2);
    min-height: var(--tap);
    border-radius: var(--r-md);
    color: var(--ink);
    text-decoration: none;
  }

  .ia-banner__mark {
    flex: none;
    width: var(--s-6);
    height: var(--s-6);
  }

  .ia-banner__tile {
    fill: var(--accent);
  }

  .ia-banner__block {
    fill: var(--bg);
  }

  .ia-banner__name {
    font: 500 var(--t-lg) / 1 var(--serif);
    white-space: nowrap;
  }

  .ia-banner__nav {
    display: flex;
    align-items: center;
  }

  .ia-banner__link {
    position: relative;
    isolation: isolate;
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: var(--tap);
    padding: 0 var(--s-2);
    border-radius: var(--r-md);
    color: var(--muted);
    font: 500 var(--t-sm) / 1.2 var(--sans);
    text-align: center;
    text-decoration: none;
    white-space: nowrap;
  }

  /* The current link is bolder. Its bold name is laid out (but not shown) in every link, so the link has the same width
     marked or not and its neighbours never move. */
  .ia-banner__link::after {
    content: attr(data-label);
    display: block;
    height: 0;
    overflow: hidden;
    visibility: hidden;
    font-weight: 700;
  }

  .ia-banner__link::before {
    content: "";
    position: absolute;
    inset: 0;
    z-index: -1;
    border-radius: inherit;
    background: var(--ink);
    opacity: 0;
    transition: opacity var(--fast) var(--ease);
  }

  .ia-banner__text::after {
    content: "";
    position: absolute;
    left: var(--s-2);
    right: var(--s-2);
    bottom: calc((var(--head-h) - var(--tap)) / -2);
    height: 3px;
    border-radius: 3px 3px 0 0;
    background: var(--accent);
    transform: scaleX(0);
    transition: transform var(--move) var(--ease);
  }

  .ia-banner__link[aria-current="page"] {
    color: var(--ink);
    font-weight: 700;
  }

  .ia-banner__link[aria-current="page"] .ia-banner__text::after {
    transform: scaleX(1);
  }

  @media (hover: hover) {
    .ia-banner__link:hover {
      color: var(--ink);
    }

    .ia-banner__link:hover::before {
      opacity: 0.06;
    }
  }

  .ia-banner__link:active::before {
    opacity: 0.1;
  }

  /* Demo is the one link drawn as a filled button, bolder and larger than the others, so a visitor always finds the way into
     the example. Its wash is white over the fill, as on every main button. Its marked state keeps the fill and darkens it. */
  .ia-banner__link.ia-banner__link--demo {
    padding: 0 var(--s-4);
    background: var(--demo);
    color: var(--on-accent);
    font-size: var(--t-lg);
    font-weight: 700;
    box-shadow: var(--shadow-1);
  }

  .ia-banner__link--demo::before {
    background: var(--pop);
  }

  .ia-banner__link--demo[aria-current="page"] {
    background: var(--demo-strong);
    color: var(--on-accent);
  }

  @media (hover: hover) {
    .ia-banner__link.ia-banner__link--demo:hover {
      color: var(--on-accent);
    }

    .ia-banner__link--demo:hover::before {
      opacity: 0.16;
    }
  }

  .ia-banner__link--demo:active::before {
    opacity: 0.2;
  }

  /* The marked-link bar under the text would show through the button's own foot, so it stays out of the filled button. */
  .ia-banner__link--demo .ia-banner__text::after {
    display: none;
  }

  @media (min-width: 640px) {
    .ia-banner__link {
      padding: 0 var(--s-4);
      font-size: var(--t-md);
    }

    .ia-banner__link.ia-banner__link--demo {
      padding: 0 var(--s-5);
    }

    .ia-banner__text::after {
      left: var(--s-4);
      right: var(--s-4);
    }
  }

  /* On a phone the four links keep the room and the brand shows only its mark (its name is still its accessible name). */
  @media (max-width: 559px) {
    /* The brand's press area is 44 px wide; the mark itself stands flush with the page's left edge. */
    .ia-banner__nav {
      gap: var(--s-2);
    }

    .ia-banner__brand {
      min-width: var(--tap);
      justify-content: center;
      margin-inline-start: calc((var(--s-6) - var(--tap)) / 2);
    }

    .ia-banner__name {
      position: absolute;
      width: 1px;
      height: 1px;
      overflow: hidden;
      clip-path: inset(50%);
    }
  }

  /* A narrower phone: the links give up some of their side room, then some of their size, and keep a clear gap between
     them, so all four stay in one row and no link touches the next. */
  @media (max-width: 399px) {
    .ia-banner__row {
      gap: var(--s-2);
    }

    .ia-banner__link {
      padding: 0 var(--s-1);
    }

    .ia-banner__link.ia-banner__link--demo {
      padding: 0 var(--s-3);
    }
  }

  @media (max-width: 339px) {
    .ia-banner__link {
      font-size: var(--t-xs);
    }

    .ia-banner__link.ia-banner__link--demo {
      padding: 0 var(--s-2);
      font-size: var(--t-md);
    }
  }

  /* The main area is always at least one window tall, so the footer never rides up the screen while a page is opening. */
  .ia-main {
    display: block;
    min-height: calc(100dvh - var(--ia-head));
  }

  .ia-main:focus {
    outline: none;
  }

  .ia-placeholder {
    min-height: calc(100dvh - var(--ia-head));
    background: var(--bg);
  }

  /* Ordinary scrolling page */
  .ia-page {
    width: 100%;
    max-width: calc(var(--ia-reading) + 2 * var(--s-5));
    margin-inline: auto;
    padding: var(--s-5) max(var(--ia-gutter), env(safe-area-inset-right, 0px)) var(--s-7) max(var(--ia-gutter), env(safe-area-inset-left, 0px));
  }

  /* The pages of the site itself (the landing page, "Your Map") share one content edge, wider than the reading width so the
     mail apps in the landing page's pictures can wear the desktop look. */
  .ia-page--site {
    max-width: calc(80rem + 2 * var(--ia-gutter));
  }

  /* A screen that is one window tall on a laptop and scrolls inside its own parts; on a phone an ordinary page. */
  .ia-page--window {
    max-width: var(--ia-wide);
  }

  @media (min-width: 900px) {
    .ia-page--window {
      display: flex;
      flex-direction: column;
      height: calc(100dvh - var(--ia-head) - var(--ia-foot) - 1px);
      min-height: var(--ia-window-min);
      padding-block: var(--s-4) var(--s-3);
      overflow: hidden;
    }

    .ia-page--window > * {
      min-width: 0;
      min-height: 0;
    }
  }

  /* The footer */
  .ia-footer {
    padding: var(--s-4) max(var(--ia-gutter), env(safe-area-inset-right, 0px)) calc(var(--s-4) + env(safe-area-inset-bottom, 0px)) max(var(--ia-gutter), env(safe-area-inset-left, 0px));
    border-top: 1px solid var(--rule);
    color: var(--muted);
    font-size: var(--t-sm);
  }

  .ia-footer__row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: var(--s-1) var(--s-5);
    max-width: var(--ia-wide);
    margin-inline: auto;
  }

  .ia-footer__links {
    display: flex;
    flex-wrap: wrap;
    margin-inline: calc(-1 * var(--s-2));
  }

  .ia-footer__links a {
    display: inline-flex;
    align-items: center;
    min-height: var(--tap);
    padding: 0 var(--s-2);
    color: var(--muted);
    text-decoration: none;
  }

  @media (hover: hover) {
    .ia-footer__links a:hover {
      color: var(--ink);
      text-decoration: underline;
    }
  }

  /* On a laptop the footer is one slim line, so a window screen and the footer fit the window together. */
  @media (min-width: 900px) {
    .ia-main {
      min-height: calc(100dvh - var(--ia-head) - var(--ia-foot) - 1px);
    }

    .ia-footer {
      height: var(--ia-foot);
      padding-block: 0;
    }
  }
}
