@layer components {
  /* Buttons */
  .btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    min-height: 56px;
    padding: 0 28px;
    background: var(--color-paper);
    border: var(--border);
    border-radius: 28px;
    font-size: 17px;
    font-weight: 700;
    line-height: 1;
    color: var(--color-ink);
    transition: transform 0.08s, box-shadow 0.08s;

    &.btn--primary {
      background: var(--color-orange);
      box-shadow: var(--shadow);

      &:hover {
        transform: translateY(1px);
        box-shadow: 0 3px 0 var(--color-ink);
      }

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

    &.btn--block { width: 100%; }

    &.btn--quiet {
      border-color: transparent;
      background: none;
      box-shadow: none;
    }

    &.btn--small {
      min-height: 44px;
      padding: 0 20px;
      border-radius: 22px;
      font-size: 16px;
    }
  }

  .icon-btn {
    display: grid;
    place-items: center;
    flex-shrink: 0;
    width: 44px;
    height: 44px;
    padding: 0;
    background: var(--color-paper);
    border: var(--border);
    border-radius: 50%;
    /* Its own color: on a dark card (blue) the inherited white would vanish on the white button. */
    color: var(--color-ink);
    list-style: none;

    &::-webkit-details-marker { display: none; }
    &.icon-btn--soft { background: var(--color-soft); }
    &[data-copied] { background: var(--color-mint); }
  }

  .avatar {
    display: grid;
    place-items: center;
    flex-shrink: 0;
    width: 44px;
    height: 44px;
    background: var(--color-lilac);
    border: var(--border);
    border-radius: 50%;
    font-size: 18px;
    font-weight: 700;

    &.avatar--large {
      width: 56px;
      height: 56px;
      background: var(--color-paper);
      font-size: 22px;
    }
  }

  .link {
    font-weight: 600;
    text-decoration: underline;
    text-underline-offset: 3px;

    &:is(button) { padding: 0; background: none; border: 0; }
  }

  /* Chips */
  .chip {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 3px 10px;
    background: var(--color-soft);
    border-radius: 12px;
    font-size: 12px;
    font-weight: 700;
    line-height: 1.5;

    &.chip--large {
      padding: 6px 14px;
      border-radius: 20px;
      font-size: 14px;
    }

    &.chip--yellow { background: var(--color-yellow); }
    &.chip--pink { background: var(--color-pink); }
    &.chip--mint { background: var(--color-mint); }
    &.chip--lilac { background: var(--color-lilac); }
    &.chip--orange { background: var(--color-orange); }
    &.chip--blue { background: var(--color-blue); color: var(--color-paper); }
    &.chip--ink { background: var(--color-ink); color: var(--color-paper); }
  }

  /* Cards */
  .card {
    padding: 16px;
    background: var(--color-paper);
    border: var(--border);
    border-radius: var(--radius);

    /* Only links need it: on a section it would beat .stack (an earlier layer) and drop the gaps. */
    &:is(a) { display: block; }

    &.card--shadow { box-shadow: var(--shadow); }

    &.card--link {
      box-shadow: var(--shadow);
      transition: transform 0.08s, box-shadow 0.08s;

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

    &.card--big {
      padding: 24px;
      border-radius: 28px;
      box-shadow: var(--shadow-big);
    }

    &.card--pending { background: var(--color-lilac-soft); }
    &.card--alert { background: var(--color-alert); }
    &.card--pink { background: var(--color-pink); }
    &.card--mint { background: var(--color-mint); }
    &.card--yellow { background: var(--color-yellow); }
    &.card--lilac { background: var(--color-lilac); }
    &.card--orange { background: var(--color-orange); }
    &.card--blue { background: var(--color-blue); color: var(--color-paper); }

    /* Grey .muted fails contrast on saturated cards (1.2:1 on blue): use the card's own
       text colour, slightly faded. 85% keeps WCAG AA (4.5:1) even on blue and orange. */
    &:is(.card--pink, .card--mint, .card--yellow, .card--lilac, .card--orange, .card--blue) {
      --color-muted: color-mix(in srgb, currentColor 85%, transparent);
    }
  }

  .card__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
  }

  .card__title {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 4px 10px;
  }

  .card__title {
    font-size: 15px;
    font-weight: 600;
  }

  /* Forms */
  .field {
    display: flex;
    flex-direction: column;
    gap: 8px;

    label {
      font-size: 15px;
      font-weight: 700;
    }

    input {
      width: 100%;
      height: 56px;
      padding: 0 18px;
      background: var(--color-soft);
      border: var(--border);
      border-radius: 18px;
      font-size: 17px;
    }

    .code-input {
      font-family: var(--font-display);
      font-size: 28px;
      font-weight: 600;
      letter-spacing: 0.4em;
      text-align: center;
      text-indent: 0.4em;
    }
  }

  .textarea {
    width: 100%;
    min-height: 150px;
    padding: 16px;
    background: var(--color-paper);
    border: var(--border);
    border-radius: var(--radius);
    font-size: 17px;
    line-height: 1.45;
    resize: none;

    /* A whole note: tall enough to read what was pasted. */
    &.textarea--tall { min-height: 340px; }

    &[aria-invalid] {
      background: var(--color-alert);
      border-color: var(--color-danger);
    }
  }

  .counter {
    text-align: right;
  }

  /* An error on the left, the counter on the right, under a field. */
  .field__footer {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 12px;

    .counter { flex-shrink: 0; margin-inline-start: auto; }
  }

  /* Two halves of one page, like a segmented control: the current one is filled. */
  .switcher {
    display: flex;
    gap: 4px;
    padding: 4px;
    background: var(--color-soft);
    border: var(--border);
    border-radius: 28px;
  }

  .switcher__item {
    flex: 1 1 0;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 44px;
    border-radius: 22px;
    font-size: 15px;
    font-weight: 700;

    &[aria-current="page"] {
      background: var(--color-ink);
      color: var(--color-paper);
    }
  }

  .info {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    font-size: 14px;
    color: var(--color-muted);

    svg {
      flex-shrink: 0;
      margin-top: 1px;
      color: var(--color-ink);
    }
  }

  .dropzone {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    padding: 24px;
    background: var(--color-soft);
    border: 2px dashed var(--color-ink);
    border-radius: 24px;
    text-align: center;
  }

  .dropzone__title {
    font-weight: 700;
  }

  .dropzone__input {
    max-width: 100%;
    font-size: 15px;

    &::file-selector-button {
      min-height: 44px;
      margin-right: 12px;
      padding: 0 18px;
      background: var(--color-yellow);
      border: var(--border);
      border-radius: 22px;
      font: inherit;
      font-weight: 700;
      cursor: pointer;
    }
  }

  .suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
  }

  .suggestion {
    min-height: 44px;
    padding: 0 16px;
    background: var(--color-paper);
    border: var(--border);
    border-radius: 22px;
    font-size: 15px;
    font-weight: 600;

    &.suggestion--yellow { background: var(--color-yellow); }
    &.suggestion--mint { background: var(--color-mint); }
    &.suggestion--lilac { background: var(--color-lilac); }
    &.suggestion--pink { background: var(--color-pink); }
  }

  /* Format tiles */
  .tiles {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;

    &.tiles--grid {
      display: grid;
      grid-template-columns: repeat(2, minmax(0, 1fr));

      .button_to { display: contents; }
    }
  }

  .tile {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    min-height: 72px;
    padding: 12px 14px;
    background: var(--color-paper);
    border: var(--border);
    border-radius: 18px;
    font-size: 15px;
    font-weight: 700;
    line-height: 1.2;
    text-align: left;

    svg { flex-shrink: 0; }

    &.tile--blue { background: var(--color-blue); color: var(--color-paper); }
    /* Light tiles set their ink: on a dark band (the landing's formats) they would inherit white text. */
    &.tile--pink { background: var(--color-pink); color: var(--color-ink); }
    &.tile--mint { background: var(--color-mint); color: var(--color-ink); }
    &.tile--yellow { background: var(--color-yellow); color: var(--color-ink); }
    &.tile--lilac { background: var(--color-lilac); color: var(--color-ink); }
    &.tile--orange { background: var(--color-orange); color: var(--color-ink); }
    &.tile--ink { background: var(--color-ink); color: var(--color-paper); }

    &:is(button, a):active { translate: 0 2px; }

    &.tile--static {
      flex: 1 1 160px;
      flex-direction: column;
      align-items: stretch;
      justify-content: space-between;
      gap: 16px;
      width: auto;
      min-height: 150px;
      padding: 16px;
      border-radius: 20px;
    }
  }

  .tile--static .tile__label {
    font-family: var(--font-display);
    font-size: 15px;
    font-weight: 600;
    line-height: 1.25;
  }

  .tile__text {
    margin-top: 6px;
    font-size: 14px;
    font-weight: 400;
    line-height: 1.5;
  }

  /* Banners, progress, waveform */
  .banner {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    font-size: 14px;
    font-weight: 600;

    svg { flex-shrink: 0; }

    &.banner--yellow {
      background: var(--color-yellow);
      border-top: var(--border);
    }

    &.banner--soft {
      background: var(--color-soft);
      border-radius: 16px;
    }
  }

  .progress {
    display: block;
    height: 12px;
    overflow: hidden;
    background: var(--color-paper);
    border: var(--border);
    border-radius: 6px;
  }

  .progress__bar {
    display: block;
    width: 40%;
    height: 100%;
    background: var(--color-blue);
    animation: progress-slide 1.4s ease-in-out infinite;
  }

  @keyframes progress-slide {
    from { transform: translateX(-100%); }
    to { transform: translateX(250%); }
  }

  @media (prefers-reduced-motion: reduce) {
    .progress__bar {
      width: 60%;
      animation: none;
    }
  }

  .wave {
    display: flex;
    flex-grow: 1;
    align-items: center;
    gap: 3px;
    height: 48px;
  }

  .wave__bar {
    flex-shrink: 0;
    width: 4px;
    height: var(--h);
    background: var(--color-blue);
    border-radius: 2px;
  }

  /* Dropdown menu (details/summary) */
  .menu {
    position: relative;
  }

  .menu__popup {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    z-index: 10;
    min-width: 230px;
    padding: 6px;
    background: var(--color-paper);
    border: var(--border);
    border-radius: 16px;
    box-shadow: var(--shadow);

    .button_to { display: block; }
  }

  .menu__item {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    min-height: 48px;
    padding: 0 12px;
    background: none;
    border: 0;
    border-radius: 10px;
    font-weight: 600;
    text-align: left;

    &:hover { background: var(--color-soft); }
    &.menu__item--danger { color: var(--color-danger); }
  }

  /* Settings list */
  .list {
    overflow: hidden;
    border: var(--border);
    border-radius: var(--radius);

    .button_to { display: contents; }
  }

  .list__row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    min-height: 56px;
    padding: 0 16px;
    background: var(--color-paper);
    border: 0;
    font-size: 16px;
    text-align: left;

    & + &,
    &.list__row--button {
      border-top: 1px solid var(--color-line);
    }
  }

  .list__label {
    font-weight: 600;
  }

  /* Bottom sheet: a <dialog> opened with showModal(), sliding up from the bottom on phones. */
  .sheet {
    width: min(100%, 520px);
    max-width: 100%;
    max-height: 90dvh;
    margin: auto auto 0;
    padding: 0;
    border: var(--border);
    border-bottom: 0;
    border-radius: 28px 28px 0 0;
    background: var(--color-paper);
    color: var(--color-ink);

    &::backdrop { background: rgb(17 17 17 / 0.45); }

    /* The sheet takes focus itself when it opens (see the controllers), so no button lights up
       with a ring on a tap; keyboard users still get the ring once they Tab to a button. */
    &:focus { outline: none; }

    &[open] { animation: sheet-up 0.18s ease-out; }

    @media (min-width: 640px) {
      margin: auto;
      border-bottom: var(--border);
      border-radius: 28px;
    }
  }

  .sheet__body {
    padding: 24px 20px calc(24px + var(--safe-bottom));
  }

  .sheet__head {
    display: flex;
    align-items: center;
    gap: 12px;

    &[hidden] { display: none; }
  }

  .sheet__icon {
    display: grid;
    place-items: center;
    flex-shrink: 0;
    width: 48px;
    height: 48px;
    border: var(--border);
    border-radius: 14px;
  }

  .sheet__title {
    font-family: var(--font-display);
    font-size: 20px;
  }

  .cost {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 16px;
    border: var(--border);
    border-radius: var(--radius);
    background: var(--color-soft);

    &.cost--short { background: var(--color-alert); }
  }

  .cost__line {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
  }

  .cost__points {
    flex-shrink: 0;
    font-family: var(--font-display);
    font-size: 20px;
  }

  @keyframes sheet-up {
    from { translate: 0 40px; opacity: 0; }
  }
}
