@layer layout {
  .wrap {
    width: 100%;
    max-width: 1120px;
    margin-inline: auto;
    padding-inline: 20px;
  }

  /* The app is a single phone-width column; from tablet width up it grows (see the end of this file). */
  .app {
    display: flex;
    flex-direction: column;
    gap: 20px;
    width: 100%;
    max-width: 480px;
    min-height: 100dvh;
    margin-inline: auto;
    padding: 20px 20px 40px;

    &.app--tabbed {
      padding-bottom: calc(var(--tabbar-height) + var(--safe-bottom) + 24px);
    }

    &.app--bottom-bar {
      padding-bottom: calc(96px + var(--safe-bottom) + 24px);
    }

    &.app--auth {
      padding-top: 24px;
    }
  }

  .stack {
    display: flex;
    flex-direction: column;
    gap: 12px;

    &.stack--lg { gap: 18px; }
  }

  .screen-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-block: 8px 0;

    &.screen-header--back {
      justify-content: flex-start;
      gap: 14px;
    }
  }

  .screen-title {
    font-size: 28px;

    &.screen-title--small { font-size: 24px; }
  }

  .eyebrow {
    font-size: 13px;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--color-muted);
  }

  .section-title {
    font-size: 18px;
  }

  .flash {
    width: calc(100% - 40px);
    max-width: 440px;
    margin: 12px auto 0;
    padding: 12px 16px;
    border: var(--border);
    border-radius: 16px;
    font-weight: 600;

    &.flash--notice { background: var(--color-mint); }
    &.flash--alert { background: var(--color-alert); }
  }

  .tabbar {
    position: fixed;
    bottom: 0;
    left: 50%;
    translate: -50% 0;
    z-index: 20;
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: min(100%, 480px);
    height: calc(var(--tabbar-height) + var(--safe-bottom));
    padding: 0 28px var(--safe-bottom);
    background: var(--color-paper);
    border-top: var(--border);
  }

  .tabbar__item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    min-width: 64px;
    min-height: 44px;
    font-size: 12px;
    font-weight: 600;
    color: var(--color-muted);

    &.tabbar__item--current {
      font-weight: 700;
      color: var(--color-ink);
    }
  }

  .tabbar__gap {
    width: 88px;
  }

  /* Drill-in screens have no tab bar on phones, only the top bar on wide screens. */
  .tabbar.tabbar--desktop {
    display: none;
  }

  /* Shown only in the desktop top bar. */
  .fab__label,
  .tabbar__write {
    display: none;
  }

  .fab {
    position: absolute;
    top: -40px;
    left: 50%;
    translate: -50% 0;
    display: grid;
    place-items: center;
    width: 80px;
    height: 80px;
    background: var(--color-orange);
    border: var(--border);
    border-radius: 50%;
    box-shadow: var(--shadow);
    transition: transform 0.08s, box-shadow 0.08s;

    &:active {
      transform: translateY(4px);
      box-shadow: 0 0 0 var(--color-ink);
    }
  }

  .bottom-bar {
    position: fixed;
    bottom: 0;
    left: 50%;
    translate: -50% 0;
    z-index: 20;
    width: min(100%, 480px);
    padding: 16px 20px calc(28px + var(--safe-bottom));
    background: var(--color-paper);
    border-top: var(--border);
  }

  /*
   * Tablet and desktop: the bottom tab bar becomes a top bar, the column widens
   * (forms and reading to 640px, the feed and the note to 1040px), and the bars
   * that were pinned to the bottom of the phone screen go back into the page.
   */
  @media (min-width: 768px) {
    .app {
      max-width: 640px;
      padding-top: 32px;

      &.app--wide { max-width: 1040px; }
      &.app--tabbed { min-height: 0; padding-bottom: 64px; }
      &.app--bottom-bar { padding-bottom: 64px; }
    }

    body:has(> .tabbar) {
      display: flex;
      flex-direction: column;
    }

    .tabbar,
    .tabbar.tabbar--desktop {
      display: flex;
      position: sticky;
      top: 0;
      left: auto;
      order: -1;
      translate: none;
      justify-content: flex-start;
      gap: 8px;
      width: 100%;
      height: auto;
      padding: 12px max(20px, (100% - 1000px) / 2);
      border-top: 0;
      border-bottom: var(--border);
    }

    .tabbar__gap {
      display: none;
    }

    .tabbar__item {
      flex-direction: row;
      gap: 8px;
      padding-inline: 14px;
      border-radius: 22px;
      font-size: 15px;

      &:hover { color: var(--color-ink); }
      &.tabbar__item--current { background: var(--color-soft); }
    }

    .fab {
      position: static;
      display: inline-flex;
      align-items: center;
      gap: 8px;
      width: auto;
      height: 48px;
      margin-inline-start: 8px;
      padding-inline: 18px 22px;
      translate: none;
      border-radius: 24px;
      font-weight: 700;

      svg { width: 22px; height: 22px; }
    }

    .fab__label {
      display: inline;
    }

    .tabbar__write {
      display: inline-flex;
      align-items: center;
      gap: 8px;
      height: 48px;
      padding-inline: 18px 22px;
      background: var(--color-paper);
      border: var(--border);
      border-radius: 24px;
      box-shadow: var(--shadow);
      font-weight: 700;
    }

    .bottom-bar {
      position: static;
      width: auto;
      padding: 0;
      translate: none;
      background: none;
      border: 0;
    }
  }
}
