/* ==========================================================================
   Surface: badges page + badge commerce dialogs (badges.js)
   --------------------------------------------------------------------------
   Owns: #page-badges .bp-* (layout, slot meter, order row with drag chips,
   collection tiles, live preview with --pv-accent/--pv-bg/--pv-text set by
   JS, position radio tiles, shop rows) and dialog.bp-dialog (slot / Donor /
   gift / paid custom badge checkout, "how to get", gift claim).
   The medallion itself (.nb-medal, --nb-* vars) lives in components.css.
   Tokens only, no !important.
   r181 (unslop): the medals and the live preview are the moment; the chrome around them is quiet —
   no washes, glows, icon tiles or pills; a choice is a surface step with an accent hairline; figures in
   the figure face (mono). Medals move only in the preview (.nb-live) or on hover / focus.
   ========================================================================== */

@layer surfaces {
  /* ---- Layout: main column + sticky preview ----------------------------- */
  .bp-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 340px;
    gap: var(--nv-space-8);
    align-items: start;
  }

  .bp-main {
    display: grid;
    gap: var(--nv-space-8);
    min-width: 0;
  }

  .bp-header {
    margin-bottom: 0;
  }

  .bp-aside {
    position: sticky;
    top: calc(var(--nv-topbar-h) + var(--nv-space-6));
    display: grid;
    gap: var(--nv-space-4);
    min-width: 0;
  }

  @media (max-width: 1099px) {
    .bp-layout {
      display: flex;
      flex-direction: column;
      align-items: stretch;
      gap: var(--nv-space-6);
    }

    .bp-main {
      display: contents;
    }

    .bp-header { order: 0; }
    .bp-slots { order: 1; }
    .bp-aside { order: 2; position: static; }
    .bp-section { order: 3; }
  }

  /* r166 (B2): the row that opens the locked badges from «Получены». */
  .bp-more-locked {
    grid-column: 1 / -1;
    justify-content: space-between;
    width: 100%;
    min-height: var(--nv-hit);
  }

  .bp-more-locked b {
    margin-left: auto;
    color: var(--nv-text-3);
  }

  /* r166 (B1): phones open with the badges themselves (preview, order, collection); buying slots and
     more badges comes after them. */
  @media (max-width: 640px) {
    .bp-aside { order: 1; }
    .bp-slots { order: 4; }
    .bp-section.bp-shop { order: 5; }
  }

  /* ---- Slot meter --------------------------------------------------------- */
  .bp-slots {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: start;
    gap: var(--nv-space-4) var(--nv-space-6);
  }

  .bp-slots-copy {
    display: grid;
    gap: var(--nv-space-2);
    min-width: 0;
  }

  .bp-label {
    color: var(--nv-text-2);
    font-size: var(--nv-fs-13);
    font-weight: var(--nv-fw-medium);
    letter-spacing: 0;
  }

  /* «6 / 8»: the figure face (Onest, tabular), 500, the limit a step quieter than the count. */
  .bp-slots-value {
    display: flex;
    align-items: baseline;
    gap: var(--nv-space-2);
    color: var(--nv-text);
    font-family: var(--nv-font-figure);
    font-size: var(--nv-fs-36);
    font-weight: var(--nv-fw-medium);
    line-height: 1;
    letter-spacing: 0;
    font-variant-numeric: tabular-nums;
  }

  .bp-slots-value span {
    color: var(--nv-text-3);
    font-weight: var(--nv-fw-regular);
  }

  .bp-slots-value b:last-child {
    color: var(--nv-text-2);
  }

  /* Where the places come from: quiet meta (the meter above is the picture). */
  .bp-slot-sources {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--nv-space-1) var(--nv-space-4);
    color: var(--nv-text-3);
    font-size: var(--nv-fs-12);
  }

  .bp-slot-sources > span {
    display: inline-flex;
    align-items: baseline;
    gap: var(--nv-space-1);
  }

  .bp-slot-sources b {
    color: var(--nv-text);
    font-family: var(--nv-font-figure);
    font-weight: var(--nv-fw-medium);
    font-variant-numeric: tabular-nums;
  }

  .bp-slot-sources i {
    display: none;
  }

  /* «С Premium — ещё одно место»: quiet text; the taken cells keep the page's accent. */
  .bp-slot-upsell {
    color: var(--nv-text-2);
  }

  /* One cell per place: taken = the accent, free = a surface step. */
  .bp-meter {
    grid-column: 1 / -1;
    display: flex;
    gap: var(--nv-space-1);
  }

  .bp-meter i {
    flex: 1;
    height: 8px;
    border-radius: var(--nv-r-round);
    background: var(--nv-surface-3);
    transition: background-color var(--nv-dur-2) var(--nv-ease);
  }

  .bp-meter i.is-on {
    background: var(--nv-accent);
  }

  .bp-buy-slot {
    grid-column: 2;
    grid-row: 1;
  }

  @media (max-width: 520px) {
    .bp-slots {
      grid-template-columns: minmax(0, 1fr);
    }

    .bp-buy-slot {
      grid-column: 1;
      grid-row: auto;
      width: 100%;
    }
  }

  /* ---- Sections ------------------------------------------------------------ */
  .bp-section {
    display: grid;
    gap: var(--nv-space-4);
    min-width: 0;
  }

  .bp-section-head {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    justify-content: space-between;
    gap: var(--nv-space-3) var(--nv-space-4);
  }

  .bp-section-head h2 {
    font-size: var(--nv-fs-18);
    font-weight: var(--nv-fw-medium);
    letter-spacing: 0;
  }

  .bp-section-head p {
    margin-top: var(--nv-space-1);
    color: var(--nv-text-3);
    font-size: var(--nv-fs-13);
  }

  .bp-section-head p b {
    color: var(--nv-text);
    font-family: var(--nv-font-figure);
    font-weight: var(--nv-fw-medium);
    font-variant-numeric: tabular-nums;
  }

  .bp-save-state {
    min-height: 20px;
    color: var(--nv-text-3);
    font-size: var(--nv-fs-12);
  }

  .bp-save-state[data-state="saved"] { color: var(--nv-success); }
  .bp-save-state[data-state="error"] { color: var(--nv-danger); }

  /* ---- Order row (drag to reorder) ----------------------------------------
     A well one step below the card; the chips' 8px corners are its 16px minus its 8px padding. */
  .bp-order {
    display: flex;
    flex-wrap: wrap;
    gap: var(--nv-space-2);
    min-height: 72px;
    margin: 0;
    padding: var(--nv-space-2);
    border: 1px solid var(--nv-line);
    border-radius: var(--nv-r-lg);
    background: var(--nv-bg-deep);
    list-style: none;
  }

  .bp-chip {
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: var(--nv-space-2);
    min-height: 48px;
    padding: var(--nv-space-1);
    border: 1px solid var(--nv-line-strong);
    border-radius: calc(var(--nv-r-lg) - var(--nv-space-2));
    background: var(--nv-surface-2);
    color: var(--nv-text);
    cursor: grab;
    user-select: none;
    transition: border-color var(--nv-dur-1) var(--nv-ease), background-color var(--nv-dur-1) var(--nv-ease);
  }

  .bp-chip:hover {
    border-color: var(--nv-field-line-hover);
    background: var(--nv-surface-3);
  }

  .bp-chip:focus-visible {
    outline: 2px solid var(--nv-focus);
    outline-offset: 2px;
  }

  /* A chip in the hand floats: a soft neutral shadow and the accent hairline of a selection. */
  .bp-chip.is-dragging {
    z-index: var(--nv-z-raised);
    border-color: var(--nv-accent-line);
    background: var(--nv-surface-3);
    box-shadow: var(--nv-shadow-2);
    cursor: grabbing;
    transition: none;
  }

  .bp-order.is-sorting .bp-chip:not(.is-dragging) {
    transition: transform var(--nv-dur-2) var(--nv-ease);
  }

  .bp-chip-grip {
    display: grid;
    place-items: center;
    width: 24px;
    height: 36px;
    color: var(--nv-text-3);
    touch-action: none;
  }

  .bp-chip-grip svg {
    width: 16px;
    height: 16px;
  }

  .bp-chip-index {
    min-width: 12px;
    color: var(--nv-text-3);
    font-family: var(--nv-font-mono);
    font-size: var(--nv-fs-12);
  }

  .bp-chip > b {
    font-size: var(--nv-fs-13);
    font-weight: var(--nv-fw-medium);
    white-space: nowrap;
  }

  .bp-chip-remove {
    display: grid;
    place-items: center;
    width: 32px;
    height: 32px;
    border-radius: calc(var(--nv-r-lg) - var(--nv-space-2) - var(--nv-space-1));
    color: var(--nv-text-3);
    transition: background-color var(--nv-dur-1) var(--nv-ease), color var(--nv-dur-1) var(--nv-ease);
  }

  .bp-chip-remove:hover {
    background: var(--nv-surface-4);
    color: var(--nv-text);
  }

  .bp-chip-remove svg {
    width: 16px;
    height: 16px;
  }

  .bp-chip.is-empty {
    justify-content: center;
    min-width: 104px;
    padding: 0 var(--nv-space-4);
    border-style: dashed;
    background: transparent;
    color: var(--nv-text-3);
    font-size: var(--nv-fs-12);
    cursor: default;
  }

  .bp-order-empty {
    align-self: center;
    padding: 0 var(--nv-space-2);
    color: var(--nv-text-2);
    font-size: var(--nv-fs-13);
    flex-basis: 100%;
  }

  @media (pointer: coarse) {
    .bp-chip-grip {
      width: 32px;
      height: 44px;
    }

    .bp-chip-remove {
      width: 40px;
      height: 40px;
    }
  }

  /* ---- Collection grid ------------------------------------------------------ */
  .bp-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 236px), 1fr));
    gap: var(--nv-space-3);
  }

  /* A tile is a plain card; the switch says whether the badge is shown, the medal carries the colour. */
  .bp-tile {
    position: relative;
    display: flex;
    flex-direction: column;
    gap: var(--nv-space-3);
    min-width: 0;
    padding: var(--nv-space-5) var(--nv-space-5) var(--nv-space-4);
    border: 1px solid var(--nv-line);
    border-radius: var(--nv-r-lg);
    background: var(--nv-surface-1);
    transition: border-color var(--nv-dur-1) var(--nv-ease);
  }

  .bp-tile:hover,
  .bp-tile.is-selected {
    border-color: var(--nv-line-strong);
  }

  .bp-tile-top {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: var(--nv-space-3);
  }

  /* The medal stands on the card itself: no tile behind it. */
  .bp-tile-art {
    display: grid;
    flex: none;
    place-items: center;
  }

  .bp-switch {
    display: inline-grid;
    place-items: center;
    min-width: var(--nv-hit);
    min-height: var(--nv-hit);
    margin: -6px -8px 0 0;
    cursor: pointer;
  }

  /* Not owned yet: a bare lock in the muted role where the switch would be. */
  .bp-lock {
    display: grid;
    place-items: center;
    width: 24px;
    height: 24px;
    color: var(--nv-text-3);
  }

  .bp-lock svg {
    width: 16px;
    height: 16px;
  }

  .bp-tile-body h3 {
    font-size: var(--nv-fs-16);
    font-weight: var(--nv-fw-medium);
    letter-spacing: 0;
  }

  .bp-tile-body p {
    margin-top: var(--nv-space-1);
    color: var(--nv-text-2);
    font-size: var(--nv-fs-13);
    line-height: 1.5;
  }

  .bp-tile-foot {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: var(--nv-space-2);
    min-height: 44px;
    margin-top: auto;
    padding-top: var(--nv-space-3);
    border-top: 1px solid var(--nv-line-soft);
  }

  .bp-tile-foot small {
    color: var(--nv-text-3);
    font-size: var(--nv-fs-12);
  }

  .bp-tile-foot .link-button {
    padding-left: 0;
  }

  /* «Виден в профиле · 2»: a neutral tag (the switch already says it is shown), the place in mono. */
  .bp-tile-pos {
    border-color: var(--nv-line);
    background: var(--nv-surface-2);
    color: var(--nv-text-2);
  }

  .bp-tile-pos b {
    color: var(--nv-text);
    font-family: var(--nv-font-mono);
    font-variant-numeric: tabular-nums;
  }

  .bp-tile-hidden {
    color: var(--nv-text-3);
    font-size: var(--nv-fs-12);
  }

  .bp-tile.is-locked .bp-tile-art .nb-medal {
    filter: grayscale(.85) brightness(.72);
    opacity: .7;
  }

  .bp-tile.is-locked .bp-tile-body h3 {
    color: var(--nv-text-2);
  }

  .bp-tile.is-skeleton {
    gap: var(--nv-space-3);
    min-height: 208px;
  }

  .bp-tile.is-skeleton .skeleton.circle {
    width: 48px;
    height: 48px;
    border-radius: var(--nv-r-lg);
  }

  .bp-grid-empty {
    grid-column: 1 / -1;
  }

  .bp-howto-btn svg {
    width: 16px;
    height: 16px;
  }

  /* Phones: compact rows instead of tall cards; the order row becomes a
     vertical sortable list (empty slots are shown by the meter instead). */
  @media (max-width: 640px) {
    .bp-tile {
      display: grid;
      grid-template-columns: 56px minmax(0, 1fr) auto;
      grid-template-areas: "art body control" "foot foot foot";
      align-items: center;
      gap: var(--nv-space-2) var(--nv-space-3);
      padding: var(--nv-space-3) var(--nv-space-3) var(--nv-space-2) var(--nv-space-3);
    }

    .bp-tile-top {
      display: contents;
    }

    .bp-tile-art {
      grid-area: art;
    }

    .bp-tile-art .nb-medal {
      width: 40px;
      height: 40px;
    }

    .bp-tile-top > :not(.bp-tile-art) {
      grid-area: control;
      margin: 0;
    }

    .bp-tile-body {
      grid-area: body;
    }

    .bp-tile-body h3 {
      font-size: var(--nv-fs-14);
    }

    .bp-tile-body p {
      margin-top: 2px;
      font-size: var(--nv-fs-12);
      line-height: 1.4;
    }

    .bp-tile-foot {
      grid-area: foot;
      min-height: 40px;
      padding-top: var(--nv-space-2);
    }

    .bp-tile.is-skeleton {
      display: flex;
      min-height: 96px;
    }

    .bp-order {
      flex-direction: column;
      flex-wrap: nowrap;
    }

    .bp-chip {
      width: 100%;
    }

    .bp-chip > b {
      flex: 1;
    }

    .bp-chip.is-empty {
      display: none;
    }
  }

  /* ---- Preview card ----------------------------------------------------- */
  .bp-preview-card {
    display: grid;
    gap: var(--nv-space-4);
    padding: var(--nv-space-5);
  }

  .bp-preview-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--nv-space-2);
  }

  .bp-preview-head h2 {
    font-size: var(--nv-fs-16);
    font-weight: var(--nv-fw-medium);
    letter-spacing: 0;
  }

  /* «Применяется сразу» is a fact about the preview, not a live status: quiet meta with the small dot. */
  .bp-preview-head .chip {
    padding: 0;
    border: 0;
    background: transparent;
    color: var(--nv-text-3);
    font-weight: var(--nv-fw-regular);
  }

  .bp-preview-head .chip.dot::before {
    background: var(--nv-success);
  }

  .bp-preview-skeleton {
    height: 420px;
  }

  /* The moment of this page: the owner's own colours (--pv-* from the editor) with the medals alive
     (.nb-live). The stage is their page background; the card a solid step of their text colour. */
  .bp-preview {
    --pv-accent: var(--nv-accent);
    --pv-bg: var(--nv-bg);
    --pv-text: var(--nv-text);
    position: relative;
    display: grid;
    place-items: center;
    min-height: 248px;
    padding: var(--nv-space-6) var(--nv-space-5) var(--nv-space-8);
    overflow: hidden;
    border: 1px solid var(--nv-line);
    border-radius: var(--nv-r-md);
    background: var(--pv-bg);
    color: var(--pv-text);
  }

  .bp-pv-card {
    display: grid;
    justify-items: center;
    gap: var(--nv-space-1);
    width: 100%;
    max-width: 236px;
    padding: var(--nv-space-6) var(--nv-space-4) var(--nv-space-4);
    border: 1px solid color-mix(in srgb, var(--pv-text) 12%, transparent);
    border-radius: var(--nv-r-xl);
    background: color-mix(in srgb, var(--pv-text) 6%, var(--pv-bg));
    text-align: center;
  }

  .bp-pv-avatar {
    position: relative;
    width: 84px;
    height: 84px;
    margin-bottom: var(--nv-space-2);
  }

  .bp-pv-avatar > img,
  .bp-pv-avatar > span:first-child {
    display: grid;
    place-items: center;
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
    background: var(--pv-accent);
    color: var(--nv-on-accent);
    font-size: 32px;
    font-weight: var(--nv-fw-medium);
    box-shadow: 0 0 0 2px color-mix(in srgb, var(--pv-text) 16%, transparent);
  }

  .bp-pv-medals {
    display: inline-flex;
    align-items: center;
    gap: var(--nv-space-1);
  }

  .bp-pv-medals.at-top-right,
  .bp-pv-medals.at-bottom-left {
    position: absolute;
    gap: 2px;
    padding: 2px;
    border-radius: var(--nv-r-round);
    background: color-mix(in srgb, var(--pv-bg) 70%, transparent);
  }

  .bp-pv-medals.at-top-right {
    top: -6px;
    left: 60%;
  }

  .bp-pv-medals.at-bottom-left {
    right: 60%;
    bottom: -6px;
  }

  .bp-pv-medals.is-under {
    flex-wrap: wrap;
    justify-content: center;
    margin: 2px 0 var(--nv-space-1);
  }

  .bp-pv-name {
    display: inline-flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: var(--nv-space-2);
    max-width: 100%;
    color: var(--pv-text);
    font-size: var(--nv-fs-18);
    font-weight: var(--nv-fw-medium);
    letter-spacing: 0;
    line-height: 1.2;
  }

  .bp-pv-name b {
    overflow-wrap: anywhere;
  }

  .bp-pv-handle {
    color: color-mix(in srgb, var(--pv-text) 62%, transparent);
    font-size: var(--nv-fs-12);
  }

  /* «+3» more medals: a quiet count in the figure face. */
  .bp-more {
    display: inline-grid;
    place-items: center;
    min-width: 20px;
    height: 18px;
    padding: 0 var(--nv-space-1);
    border-radius: var(--nv-r-xs);
    background: color-mix(in srgb, var(--pv-text) 14%, transparent);
    color: var(--pv-text);
    font-family: var(--nv-font-mono);
    font-size: var(--nv-fs-12);
    font-weight: var(--nv-fw-medium);
  }

  .bp-pv-links {
    display: grid;
    gap: var(--nv-space-2);
    width: 100%;
    margin-top: var(--nv-space-3);
  }

  .bp-pv-links i {
    height: 24px;
    border: 1px solid color-mix(in srgb, var(--pv-text) 10%, transparent);
    border-radius: var(--nv-r-sm);
    background: color-mix(in srgb, var(--pv-text) 7%, transparent);
  }

  .bp-pv-links i:first-child {
    border-color: color-mix(in srgb, var(--pv-accent) 50%, transparent);
    background: color-mix(in srgb, var(--pv-accent) 26%, transparent);
  }

  .bp-pv-empty {
    position: absolute;
    right: 0;
    bottom: var(--nv-space-2);
    left: 0;
    color: color-mix(in srgb, var(--pv-text) 70%, transparent);
    font-size: var(--nv-fs-12);
    text-align: center;
  }

  /* ---- Position radio tiles ---------------------------------------------- */
  .bp-positions {
    display: grid;
    gap: var(--nv-space-3);
    margin: 0;
    padding: 0;
    border: 0;
  }

  .bp-positions legend {
    margin-bottom: var(--nv-space-3);
    padding: 0;
    color: var(--nv-text-2);
    font-size: var(--nv-fs-13);
    font-weight: var(--nv-fw-medium);
  }

  .bp-position-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: var(--nv-space-2);
  }

  /* A placement is a radio tile: the chosen one is a surface step with an accent hairline and accent dots. */
  .bp-position {
    display: grid;
    justify-items: center;
    gap: var(--nv-space-2);
    min-height: var(--nv-hit);
    padding: var(--nv-space-3) var(--nv-space-2) var(--nv-space-2);
    border: 1px solid var(--nv-line);
    border-radius: var(--nv-r-md);
    background: var(--nv-surface-2);
    color: var(--nv-text-2);
    font-size: var(--nv-fs-12);
    line-height: 1.25;
    text-align: center;
    transition: border-color var(--nv-dur-1) var(--nv-ease), background-color var(--nv-dur-1) var(--nv-ease), color var(--nv-dur-1) var(--nv-ease);
  }

  .bp-position:hover {
    border-color: var(--nv-line-strong);
    color: var(--nv-text);
  }

  .bp-position[aria-checked="true"] {
    border-color: var(--nv-accent-line);
    background: var(--nv-surface-3);
    color: var(--nv-text);
  }

  .bp-position-art {
    position: relative;
    width: 64px;
    height: 44px;
  }

  .bp-position-art i,
  .bp-position-art u,
  .bp-position-art em {
    position: absolute;
    display: block;
  }

  .bp-position-art i {
    top: 2px;
    left: calc(50% - 11px);
    width: 22px;
    height: 22px;
    border: 1px solid var(--nv-line-strong);
    border-radius: 50%;
    background: var(--nv-surface-4);
  }

  .bp-position-art u {
    bottom: 3px;
    left: calc(50% - 15px);
    width: 30px;
    height: 5px;
    border-radius: 3px;
    background: var(--nv-surface-4);
  }

  .bp-position-art em {
    width: 7px;
    height: 7px;
    border-radius: 2px;
    background: var(--nv-text-3);
    transition: background-color var(--nv-dur-1) var(--nv-ease);
  }

  .bp-position[aria-checked="true"] .bp-position-art em {
    background: var(--nv-accent);
  }

  .pos-inline em { bottom: 2px; left: calc(50% + 18px); }
  .pos-inline em + em { left: calc(50% + 27px); }
  .pos-bottom u { bottom: 2px; }
  .pos-bottom em { top: 28px; left: calc(50% - 8px); }
  .pos-bottom em + em { left: calc(50% + 1px); }
  .pos-top-right em { top: 0; left: calc(50% + 6px); }
  .pos-top-right em + em { left: calc(50% + 14px); }
  .pos-bottom-left em { top: 19px; left: calc(50% - 13px); }
  .pos-bottom-left em + em { left: calc(50% - 21px); }

  /* ---- Side cards: gift link, shop ---------------------------------------- */
  .bp-gift-link {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--nv-space-3);
    padding: var(--nv-space-4);
  }

  .bp-gift-link > div {
    display: grid;
    gap: 2px;
    min-width: 0;
  }

  .bp-gift-link b {
    font-size: var(--nv-fs-14);
  }

  .bp-gift-link small {
    color: var(--nv-text-3);
  }

  .bp-shop-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 280px), 1fr));
    gap: var(--nv-space-3);
  }

  /* Shop rows: plain cards with the medal as the only colour; hover is a surface step, nothing moves. */
  .bp-shop-row {
    display: flex;
    align-items: center;
    gap: var(--nv-space-4);
    width: 100%;
    min-height: 80px;
    padding: var(--nv-space-4) var(--nv-space-5);
    border: 1px solid var(--nv-line);
    border-radius: var(--nv-r-lg);
    background: var(--nv-surface-1);
    color: var(--nv-text);
    text-align: left;
    transition: border-color var(--nv-dur-1) var(--nv-ease), background-color var(--nv-dur-1) var(--nv-ease);
  }

  .bp-shop-row:hover {
    border-color: var(--nv-line-strong);
    background: var(--nv-surface-2);
  }

  .bp-shop-row > span:not(.nb-medal) {
    display: grid;
    flex: 1;
    gap: 2px;
    min-width: 0;
  }

  .bp-shop-row b {
    font-size: var(--nv-fs-14);
    font-weight: var(--nv-fw-medium);
  }

  .bp-shop-row small {
    color: var(--nv-text-3);
    font-size: var(--nv-fs-12);
  }

  .bp-shop-row > svg {
    flex: none;
    width: 16px;
    height: 16px;
    color: var(--nv-text-3);
    transition: color var(--nv-dur-1) var(--nv-ease);
  }

  .bp-shop-row:hover > svg {
    color: var(--nv-text);
  }

  /* ---- Dialogs ------------------------------------------------------------- */
  .bp-dialog .dialog-header .eyebrow {
    margin-bottom: var(--nv-space-1);
  }

  .bp-dialog .dialog-close svg {
    width: 18px;
    height: 18px;
  }

  .bp-pay {
    display: grid;
    gap: var(--nv-space-2);
    margin: 0;
    padding: 0;
    border: 0;
  }

  .bp-pay legend {
    margin-bottom: var(--nv-space-2);
    padding: 0;
    color: var(--nv-text-2);
    font-size: var(--nv-fs-13);
    font-weight: var(--nv-fw-medium);
  }

  .bp-providers {
    display: grid;
    gap: var(--nv-space-2);
  }

  /* Same radio rows as the Premium checkout: the chosen one is a surface step, an accent hairline and the dot. */
  .bp-provider {
    display: flex;
    align-items: center;
    gap: var(--nv-space-3);
    width: 100%;
    min-height: 56px;
    padding: var(--nv-space-3) var(--nv-space-4);
    border: 1px solid var(--nv-line-strong);
    border-radius: var(--nv-r-md);
    background: var(--nv-surface-2);
    color: var(--nv-text);
    text-align: left;
    transition: border-color var(--nv-dur-1) var(--nv-ease), background-color var(--nv-dur-1) var(--nv-ease);
  }

  .bp-provider:hover {
    border-color: var(--nv-field-line-hover);
    background: var(--nv-surface-3);
  }

  .bp-provider > i {
    flex: none;
    width: 18px;
    height: 18px;
    border: 1.5px solid var(--nv-text-disabled);
    border-radius: var(--nv-r-round);
  }

  .bp-provider[aria-checked="true"] {
    border-color: var(--nv-accent-line);
    background: var(--nv-surface-3);
  }

  .bp-provider[aria-checked="true"] > i {
    border-color: var(--nv-accent);
    background: radial-gradient(circle, var(--nv-accent) 0 4px, transparent 4.5px);
  }

  .bp-provider > span {
    display: grid;
    gap: 2px;
  }

  .bp-provider b {
    font-size: var(--nv-fs-14);
    font-weight: var(--nv-fw-medium);
  }

  .bp-provider small {
    color: var(--nv-text-3);
    font-size: var(--nv-fs-12);
  }

  .bp-total {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: var(--nv-space-3);
    padding: var(--nv-space-3) var(--nv-space-4);
    border: 1px solid var(--nv-line);
    border-radius: var(--nv-r-md);
    background: var(--nv-bg-deep);
  }

  .bp-total span {
    color: var(--nv-text-2);
    font-size: var(--nv-fs-13);
  }

  .bp-total strong {
    color: var(--nv-text);
    font-family: var(--nv-font-figure);
    font-size: var(--nv-fs-22);
    font-weight: var(--nv-fw-medium);
    letter-spacing: 0;
    font-variant-numeric: tabular-nums;
  }

  .bp-perk {
    display: flex;
    align-items: center;
    gap: var(--nv-space-3);
    padding: var(--nv-space-3);
    border: 1px solid var(--nv-line);
    border-radius: var(--nv-r-md);
    background: var(--nv-surface-2);
  }

  .bp-perk.is-hero {
    padding: var(--nv-space-5);
  }

  .bp-perk > span:not(.nb-medal) {
    display: grid;
    gap: var(--nv-space-1);
    min-width: 0;
  }

  .bp-perk b {
    font-size: var(--nv-fs-16);
    font-weight: var(--nv-fw-medium);
  }

  .bp-perk small {
    color: var(--nv-text-2);
    font-size: var(--nv-fs-13);
    line-height: 1.45;
  }

  .bp-gift-mode {
    display: flex;
    width: 100%;
  }

  .bp-stepper {
    display: flex;
    align-items: center;
    gap: var(--nv-space-2);
  }

  .bp-stepper input {
    max-width: 96px;
    font-family: var(--nv-font-figure);
    font-size: var(--nv-fs-16);
    font-variant-numeric: tabular-nums;
    text-align: center;
    -moz-appearance: textfield;
  }

  .bp-stepper input::-webkit-inner-spin-button,
  .bp-stepper input::-webkit-outer-spin-button {
    margin: 0;
    -webkit-appearance: none;
  }

  .bp-stepper .icon-btn svg {
    width: 16px;
    height: 16px;
  }

  .bp-dialog-note {
    margin-top: var(--nv-space-3);
    color: var(--nv-text-3);
    font-size: var(--nv-fs-12);
    line-height: var(--nv-lh-body);
    text-align: right;
  }

  .bp-howto {
    --dialog-w: 440px;
  }

  .bp-howto-head {
    display: flex;
    align-items: center;
    gap: var(--nv-space-4);
  }

  .bp-howto-desc {
    color: var(--nv-text-2);
    font-size: var(--nv-fs-14);
    line-height: var(--nv-lh-body);
  }

  /* r180: the gift-link claim dialog (.bp-gift-claim, badges.js giftFromUrl) opens on the landing too, where this
     sheet stays disabled: its rules live in ui/landing.css. */

  @media (max-width: 640px) {
    .bp-dialog-note {
      text-align: center;
    }
  }

  /* ---- Own badge (release 162): create / upsell card, own tile, editor sheet ----
     .bp-custom section, .bp-own-tile in the collection grid and dialog.bp-own-dialog
     (a bottom sheet on phones through dialogs.css). */
  /* A plain card: the three sample medals are its only colour. */
  .bp-create-card {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: center;
    gap: var(--nv-space-5);
    padding: var(--nv-space-5) var(--nv-space-6);
    border: 1px solid var(--nv-line);
    border-radius: var(--nv-r-lg);
    background: var(--nv-surface-1);
  }

  .bp-create-art {
    display: flex;
    align-items: center;
    padding: var(--nv-space-1) var(--nv-space-2) 0;
  }

  .bp-create-art .nb-medal:first-child {
    transform: translateY(5px) rotate(-10deg);
  }

  .bp-create-art .nb-medal:nth-child(2) {
    z-index: 1;
    margin-inline: -8px;
  }

  .bp-create-art .nb-medal:last-child {
    transform: translateY(5px) rotate(10deg);
  }

  .bp-create-card.is-upsell .bp-create-art .nb-medal:not(:nth-child(2)) {
    filter: saturate(.75);
    opacity: .85;
  }

  .bp-create-copy {
    display: grid;
    justify-items: start;
    gap: var(--nv-space-1);
    min-width: 0;
  }

  .bp-create-copy h2 {
    font-size: var(--nv-fs-16);
    font-weight: var(--nv-fw-medium);
    letter-spacing: 0;
  }

  .bp-create-copy p {
    max-width: 56ch;
    color: var(--nv-text-2);
    font-size: var(--nv-fs-13);
    line-height: 1.5;
  }

  .bp-create-btn {
    white-space: nowrap;
  }

  .bp-create-btn svg {
    width: 16px;
    height: 16px;
  }

  /* «Ваш значок» sits where a built-in badge shows its rarity: the same quiet word. */
  .bp-own-tag {
    display: block;
    margin-bottom: 2px;
    color: var(--nv-text-3);
    font-size: var(--nv-fs-12);
  }

  .bp-own-tile .bp-tile-body h3,
  .bp-own-tile .bp-tile-body p {
    overflow-wrap: anywhere;
  }

  .bp-own-tile.is-hidden .bp-tile-art .nb-medal {
    filter: grayscale(.65) brightness(.8);
    opacity: .75;
  }

  .bp-own-notice {
    display: grid;
    justify-items: start;
    gap: var(--nv-space-2);
    padding: var(--nv-space-3);
    font-size: var(--nv-fs-12);
    line-height: 1.45;
    text-align: left;
  }

  .bp-own-notice .link-button {
    display: inline-flex;
    align-items: center;
    justify-self: start;
    gap: var(--nv-space-1);
    min-height: var(--nv-h-sm);
    padding: 0;
  }

  .bp-own-notice .link-button svg {
    width: 16px;
    height: 16px;
  }

  .bp-own-reason q {
    color: var(--nv-text);
  }

  .bp-own-actions {
    display: inline-flex;
    gap: var(--nv-space-2);
    margin-left: auto;
  }

  .bp-own-actions svg {
    width: 16px;
    height: 16px;
  }

  .bp-own-delete:hover {
    color: var(--nv-danger);
  }

  .bp-own-dialog {
    --dialog-w: 540px;
  }

  .bp-own-dialog .dialog-footer svg {
    width: 16px;
    height: 16px;
  }

  /* The creator's stage: a plain well where the new medal is alive (.nb-live), shown big, in a name row
     and with its tooltip. */
  .bp-own-stage {
    display: grid;
    justify-items: center;
    gap: var(--nv-space-3);
    padding: var(--nv-space-5) var(--nv-space-4) var(--nv-space-4);
    border: 1px solid var(--nv-line);
    border-radius: var(--nv-r-lg);
    background: var(--nv-bg-deep);
  }

  .bp-own-stage-medal {
    display: grid;
    min-height: 76px;
    place-items: center;
  }

  .bp-own-stage-row {
    display: inline-flex;
    align-items: center;
    gap: var(--nv-space-2);
    max-width: 100%;
    padding: var(--nv-space-1) var(--nv-space-3) var(--nv-space-1) var(--nv-space-1);
    border: 1px solid var(--nv-line);
    border-radius: var(--nv-r-control);
    background: var(--nv-surface-2);
  }

  .bp-own-stage-avatar {
    display: grid;
    flex: none;
    place-items: center;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: var(--nv-surface-4);
    color: var(--nv-text);
    font-size: var(--nv-fs-12);
    font-weight: var(--nv-fw-medium);
  }

  .bp-own-stage-row b {
    overflow: hidden;
    font-size: var(--nv-fs-14);
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .bp-own-stage-inline {
    display: inline-flex;
    flex: none;
  }

  .bp-own-stage-tip {
    max-width: 100%;
    padding: var(--nv-space-1) var(--nv-space-2);
    border-radius: var(--nv-r-xs);
    background: var(--nv-surface-4);
    color: var(--nv-text);
    font-size: var(--nv-fs-12);
    line-height: 1.4;
    text-align: center;
    overflow-wrap: anywhere;
  }

  .bp-own-label {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: var(--nv-space-2);
  }

  .bp-own-optional {
    color: var(--nv-text-3);
    font-weight: var(--nv-fw-regular);
  }

  .bp-own-dialog .field-counter.is-over {
    color: var(--nv-danger);
  }

  .bp-own-fieldset {
    display: grid;
    gap: var(--nv-space-3);
    min-width: 0;
    margin: 0;
    padding: 0;
    border: 0;
  }

  .bp-own-fieldset legend {
    margin-bottom: var(--nv-space-2);
    padding: 0;
    color: var(--nv-text-2);
    font-size: var(--nv-fs-13);
    font-weight: var(--nv-fw-medium);
  }

  .bp-own-mode {
    justify-self: start;
  }

  .bp-own-icons {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(44px, 1fr));
    gap: var(--nv-space-2);
  }

  .bp-own-icon,
  .bp-own-tone {
    position: relative;
    display: grid;
    place-items: center;
    cursor: pointer;
  }

  .bp-own-icon {
    min-height: 48px;
    border: 1px solid var(--nv-line);
    border-radius: var(--nv-r-md);
    background: var(--nv-surface-2);
    transition: border-color var(--nv-dur-1) var(--nv-ease), background-color var(--nv-dur-1) var(--nv-ease);
  }

  .bp-own-icon:hover {
    border-color: var(--nv-line-strong);
    background: var(--nv-surface-3);
  }

  .bp-own-icon input,
  .bp-own-tone input {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    margin: 0;
    opacity: 0;
    cursor: pointer;
  }

  .bp-own-icon:has(input:checked) {
    border-color: var(--nv-accent-line);
    background: var(--nv-surface-3);
  }

  .bp-own-icon:has(input:focus-visible),
  .bp-own-tone:has(input:focus-visible) {
    box-shadow: var(--nv-focus-ring);
  }

  .bp-own-icon-art {
    display: grid;
    pointer-events: none;
  }

  .bp-own-tones {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
  }

  .bp-own-tone {
    width: var(--nv-hit);
    height: var(--nv-hit);
    border-radius: 50%;
  }

  /* A swatch is a sample of the medal's own two tones (its material), so it keeps their light-to-deep fall. */
  .bp-own-swatch {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: radial-gradient(120% 90% at 30% 18%, var(--sw-a), var(--sw-b));
    box-shadow: inset 0 0 0 1px rgb(255 255 255 / 18%);
    pointer-events: none;
  }

  .bp-own-tone:has(input:checked) .bp-own-swatch {
    box-shadow: 0 0 0 2px var(--nv-surface-1), 0 0 0 4px var(--nv-text);
  }

  .bp-own-accent {
    display: grid;
    gap: var(--nv-space-2);
  }

  .bp-own-accent .color-control {
    justify-self: start;
  }

  .bp-own-hex {
    width: 10ch;
    min-height: 0;
    padding: var(--nv-space-1) var(--nv-space-2);
    border: 0;
    background: transparent;
    font-family: var(--nv-font-mono);
    font-size: var(--nv-fs-13);
  }

  .bp-own-upload {
    display: grid;
    gap: var(--nv-space-2);
  }

  .bp-own-drop {
    position: relative;
    display: flex;
    align-items: center;
    gap: var(--nv-space-3);
    padding: var(--nv-space-4);
    border: 1px dashed var(--nv-line-strong);
    border-radius: var(--nv-r-md);
    background: var(--nv-surface-2);
    cursor: pointer;
    transition: border-color var(--nv-dur-1) var(--nv-ease), background-color var(--nv-dur-1) var(--nv-ease);
  }

  .bp-own-drop:hover {
    border-color: var(--nv-field-line-hover);
    background: var(--nv-surface-3);
  }

  .bp-own-drop:focus-within {
    box-shadow: var(--nv-focus-ring);
  }

  .bp-own-file {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    cursor: pointer;
  }

  .bp-own-drop-icon {
    display: grid;
    flex: none;
    place-items: center;
    width: 18px;
    height: 18px;
    color: var(--nv-text-3);
  }

  .bp-own-drop-icon svg {
    width: 18px;
    height: 18px;
  }

  .bp-own-drop-copy {
    display: grid;
    gap: 2px;
    min-width: 0;
  }

  .bp-own-drop-copy b {
    overflow: hidden;
    color: var(--nv-text);
    font-size: var(--nv-fs-14);
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .bp-own-drop-copy small {
    color: var(--nv-text-3);
    font-size: var(--nv-fs-12);
  }

  @media (max-width: 640px) {
    .bp-create-card {
      grid-template-columns: auto minmax(0, 1fr);
      gap: var(--nv-space-3);
      padding: var(--nv-space-4);
      border-radius: var(--nv-r-md);
    }

    .bp-create-art {
      padding: 0;
    }

    .bp-create-art .nb-medal {
      width: 32px;
      height: 32px;
    }

    .bp-create-art .nb-medal:nth-child(2) {
      width: 40px;
      height: 40px;
    }

    .bp-create-copy h2 {
      font-size: var(--nv-fs-14);
    }

    .bp-create-copy p {
      font-size: var(--nv-fs-12);
    }

    .bp-create-btn {
      grid-column: 1 / -1;
      width: 100%;
    }

    .bp-own-stage {
      gap: var(--nv-space-2);
      padding: var(--nv-space-4) var(--nv-space-3) var(--nv-space-3);
    }

    .bp-own-icons {
      gap: var(--nv-space-1);
    }

    .bp-own-icon {
      min-height: var(--nv-hit);
    }
  }

  /* r180: on narrow phones the card is one column, so the three pack tiles get the full width
     (beside the art they were 51 px wide and «5 значков» ran out of its tile). */
  @media (max-width: 400px) {
    .bp-create-card {
      grid-template-columns: minmax(0, 1fr);
    }

    .bp-create-art {
      justify-self: start;
    }
  }

  /* r180: 409 «unconfirmed» in the gift dialog: send anyway, or as a gift link (a row under the message). */
  .bp-dialog [data-error]:has(> .bp-error-actions) {
    flex-wrap: wrap;
  }

  .bp-error-actions {
    display: flex;
    flex: 1 1 100%;
    flex-wrap: wrap;
    justify-content: center;
    gap: var(--nv-space-2);
    margin-top: var(--nv-space-2);
  }

  /* ---- Phones: compact + calm (r160, r181) ------------------------------------
     Collection as a 2-up grid of short tiles, a smaller live preview, the four
     placements in one row. Same quiet chrome as on desktop, tighter steps. */
  @media (max-width: 640px) {
    .bp-layout {
      gap: var(--nv-space-4);
    }

    .bp-slots {
      gap: var(--nv-space-3);
    }

    .bp-meter i {
      height: 6px;
    }

    .bp-section {
      gap: var(--nv-space-3);
    }

    .bp-section-head h2 {
      font-size: var(--nv-fs-16);
    }

    .bp-section-head p {
      margin-top: 2px;
      font-size: var(--nv-fs-12);
    }

    /* The well's 12px corners minus its 4px padding give the chips the same 8px corners as on desktop. */
    .bp-order {
      gap: var(--nv-space-1);
      min-height: 0;
      padding: var(--nv-space-1);
      border-radius: var(--nv-r-md);
    }

    .bp-chip {
      min-height: var(--nv-hit);
      padding-block: var(--nv-space-1);
    }

    /* Collection: two compact tiles per row. */
    .bp-grid {
      grid-template-columns: repeat(2, minmax(0, 1fr));
      gap: var(--nv-space-2);
    }

    .bp-save-state {
      min-height: 0;
    }

    .bp-tile {
      display: flex;
      flex-direction: column;
      align-items: stretch;
      gap: var(--nv-space-2);
      padding: var(--nv-space-3) var(--nv-space-3) var(--nv-space-2);
      border-radius: var(--nv-r-md);
    }

    .bp-tile-top {
      display: flex;
    }

    .bp-tile-art .nb-medal {
      width: 32px;
      height: 32px;
    }

    .bp-tile-top > :not(.bp-tile-art) {
      margin: -6px -8px 0 0;
    }

    .bp-lock {
      width: 24px;
      height: 24px;
      margin: 0;
    }

    .bp-tile-body h3 {
      font-size: var(--nv-fs-13);
    }

    .bp-tile-body p {
      display: -webkit-box;
      margin-top: 2px;
      overflow: hidden;
      font-size: var(--nv-fs-12);
      line-height: 1.35;
      -webkit-line-clamp: 2;
      -webkit-box-orient: vertical;
    }

    /* r166 (B1): an owned tile's switch already says whether it is shown; the position chip and the
       «Получен: …» date were a second and third signal on a 170px tile. */
    .bp-tile.is-owned .bp-tile-foot {
      display: none;
    }

    .bp-tile-foot {
      flex-direction: column;
      flex-wrap: nowrap;
      align-items: flex-start;
      justify-content: flex-end;
      gap: var(--nv-space-1);
      min-height: 0;
      padding-top: var(--nv-space-2);
    }

    .bp-tile-foot small {
      font-size: var(--nv-fs-12);
    }

    .bp-tile-foot .bp-howto-btn {
      width: 100%;
      min-height: 36px;
    }

    .bp-tile.is-skeleton {
      min-height: 150px;
    }

    /* Live preview: shorter stage, smaller card. */
    .bp-preview-card {
      gap: var(--nv-space-3);
      padding: var(--nv-space-3);
    }

    .bp-preview-skeleton {
      height: 260px;
    }

    .bp-preview {
      min-height: 0;
      padding: var(--nv-space-4) var(--nv-space-3) var(--nv-space-6);
    }

    .bp-pv-card {
      max-width: 220px;
      padding: var(--nv-space-4) var(--nv-space-3) var(--nv-space-3);
      border-radius: var(--nv-r-lg);
    }

    .bp-pv-avatar {
      width: 64px;
      height: 64px;
      margin-bottom: var(--nv-space-1);
    }

    .bp-pv-avatar > img,
    .bp-pv-avatar > span:first-child {
      font-size: 24px;
    }

    .bp-pv-links {
      gap: var(--nv-space-1);
      margin-top: var(--nv-space-2);
    }

    .bp-pv-links i {
      height: 16px;
      border-radius: var(--nv-r-xs);
    }

    .bp-positions legend {
      margin-bottom: var(--nv-space-2);
    }

    .bp-position-grid {
      grid-template-columns: repeat(4, minmax(0, 1fr));
      gap: var(--nv-space-1);
    }

    .bp-position {
      gap: var(--nv-space-1);
      padding: var(--nv-space-2) var(--nv-space-1);
      font-size: var(--nv-fs-12);
      line-height: 1.2;
    }

    .bp-position-art {
      width: 60px;
      height: 40px;
    }

    .bp-gift-link {
      padding: var(--nv-space-3);
    }

    .bp-shop-grid {
      gap: var(--nv-space-2);
    }

    .bp-shop-row {
      gap: var(--nv-space-3);
      min-height: 64px;
      padding: var(--nv-space-3);
      border-radius: var(--nv-r-md);
    }

    /* Release 162: the own badge spans the row so its actions fit. */
    .bp-own-tile {
      grid-column: 1 / -1;
    }

    .bp-tile-foot.bp-own-foot {
      flex-direction: row;
      flex-wrap: wrap;
      align-items: center;
      justify-content: space-between;
    }
  }
}
