/* ==========================================================================
   Surface: discover / top profiles (#page-discover, discover.js)
   --------------------------------------------------------------------------
   Owns: .dc-* (header, toolbar, grid, profile cards, ranks, empty states),
   the shared mini profile renderer .mp (NovaPagesKit.miniProfile, also used
   by the templates page; JS sets --mp-accent/--mp-bg/--mp-text/--mp-radius/
   --mp-card/--mp-blur/--mp-dim/--mp-image inline) and the action toast
   .pk-toast (undo after copy style / template apply). --tag-color is set
   inline on .dc-swatches > i. Tokens only, no !important.
   r181 (unslop): the live miniatures (.mp, the owners' own designs) are the moment and keep every
   colour and effect they choose; the chrome around them is quiet: plain cards that change only their
   hairline on hover, solid rank and Premium tags with no glass or glow, views as quiet mono meta, the
   address in the signature (.nv-address), one neutral «Копировать стиль» per card.
   ========================================================================== */

@layer surfaces {
  /* ---- Header + toolbar ---------------------------------------------------- */
  .dc-header .page-header-actions svg {
    width: 16px;
    height: 16px;
  }

  .dc-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--nv-space-3) var(--nv-space-4);
    margin-bottom: var(--nv-space-5);
  }

  .dc-search,
  .tp-search {
    position: relative;
    display: block;
    flex: 1 1 300px;
    max-width: 440px;
  }

  .dc-search > svg,
  .tp-search > svg {
    position: absolute;
    top: 50%;
    left: var(--nv-space-3);
    width: 18px;
    height: 18px;
    color: var(--nv-text-3);
    transform: translateY(-50%);
    pointer-events: none;
  }

  .dc-search input,
  .tp-search input {
    min-height: var(--nv-hit);
    padding-left: 40px; /* the 12px inset + the 18px icon + 10px: fixed, the phone spacing scale is tighter */
    border-radius: var(--nv-r-control);
  }

  .dc-count {
    color: var(--nv-text-3);
    font-size: var(--nv-fs-13);
  }

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

  /* «Копирование оформления — Premium»: Premium named once, as quiet text. */
  .dc-premium {
    display: inline-flex;
    align-items: center;
    gap: var(--nv-space-2);
    margin-left: auto;
    color: var(--nv-text-2);
    font-size: var(--nv-fs-12);
  }

  .dc-premium svg {
    width: 16px;
    height: 16px;
    color: var(--nv-text-3);
  }

  /* ---- Grid + cards -------------------------------------------------------- */
  .dc-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 288px), 1fr));
    gap: var(--nv-space-4);
  }

  /* A plain card: hover is a hairline step, nothing lifts, glows or zooms. */
  .dc-card {
    display: flex;
    flex-direction: column;
    min-width: 0;
    padding: var(--nv-space-2);
    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);
  }

  .dc-card:hover {
    border-color: var(--nv-line-strong);
  }

  /* Nested in the 16px card with 8px padding: 8px corners. */
  .dc-thumb {
    position: relative;
    display: block;
    aspect-ratio: 16 / 11;
    overflow: hidden;
    border: 1px solid var(--nv-line);
    border-radius: calc(var(--nv-r-lg) - var(--nv-space-2));
    color: inherit;
  }

  .dc-thumb:hover {
    text-decoration: none;
  }

  .dc-thumb:focus-visible {
    outline-offset: 2px;
  }

  /* The rank and the Premium crown sit on the owner's miniature as small solid tags (no glass, no glow);
     the order of the grid already says who leads. */
  .dc-rank,
  .dc-pro {
    position: absolute;
    top: var(--nv-space-2);
    min-height: 24px;
    border: 1px solid var(--nv-line-strong);
    border-radius: var(--nv-r-xs);
    background: var(--nv-bg);
  }

  .dc-rank {
    left: var(--nv-space-2);
    display: inline-flex;
    align-items: center;
    padding: 0 var(--nv-space-2);
    color: var(--nv-text);
    font-family: var(--nv-font-mono);
    font-size: var(--nv-fs-12);
    font-weight: var(--nv-fw-medium);
    font-variant-numeric: tabular-nums;
  }

  .dc-pro {
    right: var(--nv-space-2);
    display: grid;
    place-items: center;
    width: 24px;
    color: var(--nv-text-2);
  }

  .dc-pro svg {
    width: 16px;
    height: 16px;
  }

  .dc-body {
    display: flex;
    flex: 1;
    flex-direction: column;
    gap: var(--nv-space-3);
    min-width: 0;
    padding: var(--nv-space-4) var(--nv-space-3) var(--nv-space-2);
  }

  .dc-title {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: var(--nv-space-3);
    min-width: 0;
  }

  .dc-title > div {
    min-width: 0;
  }

  .dc-title h2 {
    overflow: hidden;
    font-size: var(--nv-fs-16);
    font-weight: var(--nv-fw-medium);
    letter-spacing: 0;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  /* The address in the signature: mono, the host dim, the name bright (.nv-address in components.css). */
  .dc-title p {
    margin-top: 2px;
    overflow: hidden;
    font-family: var(--nv-address-font);
    font-size: var(--nv-fs-12);
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  /* Views: quiet meta in the figure face (a count keeps its thousands space), not a pill. */
  .dc-views {
    flex: none;
    display: inline-flex;
    align-items: center;
    gap: var(--nv-space-1);
    min-height: 24px;
    color: var(--nv-text-2);
    font-family: var(--nv-font-figure);
    font-size: var(--nv-fs-12);
    font-variant-numeric: tabular-nums;
  }

  .dc-views svg {
    width: 16px;
    height: 16px;
    color: var(--nv-text-3);
  }

  .dc-tags {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--nv-space-2);
  }

  .dc-swatches {
    display: inline-flex;
  }

  /* The profile's own two colours, as two overlapping samples. */
  .dc-swatches i {
    width: 20px;
    height: 20px;
    border: 2px solid var(--nv-surface-1);
    border-radius: var(--nv-r-round);
    background: var(--tag-color);
    box-shadow: 0 0 0 1px var(--nv-line-strong);
  }

  .dc-swatches i + i {
    margin-left: calc(-1 * var(--nv-space-1));
  }

  .dc-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--nv-space-2);
    margin-top: auto;
    padding-top: var(--nv-space-3);
    border-top: 1px solid var(--nv-line-soft);
  }

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

  /* Free accounts: the same neutral button with a muted lock (the toolbar note names Premium). */
  .dc-locked {
    color: var(--nv-text-2);
  }

  .dc-locked svg {
    color: var(--nv-text-3);
  }

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

  .dc-thumb-skeleton {
    aspect-ratio: 16 / 11;
    border-radius: calc(var(--nv-r-lg) - var(--nv-space-2));
  }

  .dc-card.is-skeleton .dc-body {
    gap: var(--nv-space-3);
  }

  .dc-skel-short {
    width: 55%;
  }

  @media (pointer: coarse) {
    .dc-actions :is(a, button) {
      min-height: var(--nv-hit);
    }
  }

  /* ---- Mini profile (NovaPagesKit.miniProfile) ------------------------------ */
  .mp {
    --mp-accent: var(--nv-accent);
    --mp-bg: var(--nv-bg);
    --mp-text: var(--nv-text);
    --mp-radius: 12px;
    --mp-card: .28;
    --mp-blur: 9px;
    --mp-dim: .3;
    position: relative;
    display: grid;
    place-items: center;
    width: 100%;
    height: 100%;
    padding: 8% 10%;
    overflow: hidden;
    isolation: isolate;
    background: var(--mp-bg);
    color: var(--mp-text);
    text-align: center;
  }

  .mp-backdrop {
    position: absolute;
    inset: 0;
    z-index: -1;
    background:
      radial-gradient(80% 65% at 50% -5%, color-mix(in srgb, var(--mp-accent) 42%, transparent), transparent 70%),
      radial-gradient(60% 50% at 100% 105%, color-mix(in srgb, var(--mp-accent) 20%, transparent), transparent 70%),
      var(--mp-bg);
  }

  .mp.has-image .mp-backdrop {
    background:
      linear-gradient(rgba(0, 0, 0, var(--mp-dim)), rgba(0, 0, 0, var(--mp-dim))),
      var(--mp-image) center / cover no-repeat,
      var(--mp-bg);
  }

  .mp-backdrop::after {
    content: "";
    position: absolute;
    inset: 0;
    pointer-events: none;
  }

  .mp[data-fx="glow"] .mp-backdrop::after {
    inset: -30%;
    background:
      conic-gradient(from 210deg at 35% 45%, transparent, color-mix(in srgb, var(--mp-accent) 34%, transparent) 18%, transparent 38%),
      conic-gradient(from 20deg at 70% 60%, transparent, color-mix(in srgb, var(--mp-text) 10%, transparent) 14%, transparent 30%);
    filter: blur(18px);
  }

  .mp[data-fx="dots"] .mp-backdrop::after {
    background-image:
      radial-gradient(circle, color-mix(in srgb, var(--mp-text) 75%, transparent) 0 1px, transparent 1.6px),
      radial-gradient(circle, color-mix(in srgb, var(--mp-accent) 80%, transparent) 0 1px, transparent 1.6px);
    background-position: 0 0, 11px 13px;
    background-size: 23px 23px, 31px 29px;
    opacity: .4;
  }

  .mp[data-fx="lines"] .mp-backdrop::after {
    background: repeating-linear-gradient(90deg, transparent 0 13px, color-mix(in srgb, var(--mp-accent) 40%, transparent) 13px 14px);
    -webkit-mask: linear-gradient(transparent, black 30%, transparent);
    mask: linear-gradient(transparent, black 30%, transparent);
    opacity: .45;
  }

  .mp[data-fx="grain"] .mp-backdrop::after {
    background-image: radial-gradient(circle, color-mix(in srgb, var(--mp-text) 60%, transparent) 0 .6px, transparent 1px);
    background-size: 4px 4px;
    opacity: .18;
  }

  .mp-card {
    display: grid;
    justify-items: center;
    gap: 5px;
    width: min(66%, 220px);
    padding: 12% 9% 9%;
    border: 1px solid color-mix(in srgb, var(--mp-text) 14%, transparent);
    border-radius: var(--mp-radius);
    background: rgba(255, 255, 255, calc(.03 + var(--mp-card) * .22));
    box-shadow: 0 18px 40px -20px rgba(0, 0, 0, .75);
    -webkit-backdrop-filter: blur(var(--mp-blur));
    backdrop-filter: blur(var(--mp-blur));
  }

  .mp[data-glass="solid"] .mp-card {
    border-color: color-mix(in srgb, var(--mp-text) 10%, transparent);
    background: color-mix(in srgb, var(--mp-bg) 86%, var(--mp-text));
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
  }

  .mp[data-glass="clear"] .mp-card {
    border-color: transparent;
    background: transparent;
    box-shadow: none;
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
  }

  .mp[data-align="left"] .mp-card { justify-items: start; }
  .mp[data-align="right"] .mp-card { justify-items: end; }

  .mp-avatar {
    display: grid;
    place-items: center;
    width: 34%;
    max-width: 60px;
    aspect-ratio: 1;
    overflow: hidden;
    border-radius: 50%;
    background: linear-gradient(145deg, var(--mp-accent), color-mix(in srgb, var(--mp-accent) 32%, var(--nv-bg-deep)));
    color: var(--nv-on-accent);
    font-size: 18px;
    font-weight: var(--nv-fw-heavy);
    line-height: 1;
    box-shadow: 0 0 0 2px color-mix(in srgb, var(--mp-text) 20%, transparent), 0 8px 18px -8px color-mix(in srgb, var(--mp-accent) 80%, transparent);
  }

  .mp-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
  }

  .mp-name {
    max-width: 100%;
    margin-top: 2px;
    overflow: hidden;
    color: var(--mp-text);
    font-size: 13px;
    font-weight: var(--nv-fw-heavy);
    letter-spacing: -.01em;
    line-height: 1.2;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .mp[data-nick="gradient"] .mp-name,
  .mp[data-nick="rainbow"] .mp-name,
  .mp[data-nick="shimmer"] .mp-name {
    background: linear-gradient(95deg, var(--mp-text), var(--mp-accent) 70%);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
  }

  .mp[data-nick="glow"] .mp-name,
  .mp[data-nick="neon"] .mp-name {
    text-shadow: 0 0 10px color-mix(in srgb, var(--mp-accent) 80%, transparent);
  }

  .mp-badges {
    display: inline-flex;
    gap: 3px;
  }

  .mp-badges .nb-medal::after {
    display: none;
  }

  .mp-links {
    display: grid;
    gap: 5px;
    width: 100%;
    margin-top: 4px;
  }

  .mp-links i {
    height: 15px;
    border: 1px solid color-mix(in srgb, var(--mp-text) 11%, transparent);
    border-radius: 6px;
    background: color-mix(in srgb, var(--mp-text) 8%, transparent);
  }

  .mp-links i:first-child {
    border-color: color-mix(in srgb, var(--mp-accent) 55%, transparent);
    background: color-mix(in srgb, var(--mp-accent) 30%, transparent);
  }

  .mp-icons {
    display: flex;
    gap: 6px;
    margin-top: 4px;
  }

  .mp-icons i {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: color-mix(in srgb, var(--mp-text) 16%, transparent);
  }

  .mp-icons i:first-child {
    background: color-mix(in srgb, var(--mp-accent) 70%, transparent);
  }

  .mp.is-small .mp-name {
    font-size: 11px;
  }

  .mp.is-small .mp-links i {
    height: 11px;
  }

  /* ---- Action toast (undo) ----------------------------------------------------
     The fallback when the app's toast stack is absent: the same action and ✕ as .toast-action / .toast-close. */
  .pk-toast {
    gap: var(--nv-space-3);
    padding: var(--nv-space-2) var(--nv-space-2) var(--nv-space-2) var(--nv-space-4);
  }

  .pk-toast-text {
    min-width: 0;
  }

  .pk-toast-action {
    flex: none;
    min-height: 32px;
    padding: 0 var(--nv-space-3);
    border: 0;
    border-radius: var(--nv-r-control);
    background: var(--nv-accent-soft);
    color: var(--nv-accent-text);
    font-size: var(--nv-fs-13);
    font-weight: var(--nv-fw-medium);
    transition: background-color var(--nv-dur-1) var(--nv-ease), color var(--nv-dur-1) var(--nv-ease);
  }

  .pk-toast-action:hover {
    background: var(--nv-accent-soft-2);
    color: var(--nv-accent-text);
  }

  .pk-toast-close {
    flex: none;
    display: grid;
    place-items: center;
    width: 32px;
    height: 32px;
    border-radius: var(--nv-r-xs);
    color: var(--nv-text-3);
    transition: background-color var(--nv-dur-1) var(--nv-ease), color var(--nv-dur-1) var(--nv-ease);
  }

  .pk-toast-close:hover {
    background: var(--nv-surface-3);
    color: var(--nv-text);
  }

  .pk-toast-close svg {
    width: 16px;
    height: 16px;
  }

  @media (max-width: 640px) {
    .dc-premium {
      margin-left: 0;
    }

    .dc-search {
      max-width: none;
    }
  }

  /* ---- Phones: compact + calm (r160, r181) ------------------------------------------
     Cards become rows (portrait thumb left, details right) so a screen shows ~4 profiles
     instead of 1.5; the per-card "copy style" action is the same neutral button as on desktop. */
  @media (max-width: 640px) {
    .dc-toolbar {
      gap: var(--nv-space-2) var(--nv-space-3);
      margin-bottom: var(--nv-space-3);
    }

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

    /* The 12px row with 4px padding holds the thumb with 8px corners. */
    .dc-card {
      display: grid;
      grid-template-columns: 104px minmax(0, 1fr);
      gap: 0 var(--nv-space-3);
      padding: 4px;
      border-radius: var(--nv-r-md);
    }

    .dc-thumb,
    .dc-thumb-skeleton {
      aspect-ratio: 3 / 4;
      border-radius: calc(var(--nv-r-md) - 4px);
    }

    .dc-rank {
      top: 4px;
      left: 4px;
      min-height: 20px;
      padding: 0 6px;
      font-size: var(--nv-fs-12); /* w4: the 12px floor (was 11px) */
    }

    .dc-pro {
      top: auto;
      right: 4px;
      bottom: 4px;
    }

    .dc-thumb .mp {
      padding: 12% 7%;
    }

    .dc-thumb .mp-card {
      width: 88%;
      padding: 12% 8% 9%;
    }

    .dc-thumb .mp-name,
    .mp.is-small .mp-name {
      font-size: var(--nv-fs-12); /* w4: the 12px floor (was 11px; the name still ends in an ellipsis) */
    }

    .dc-body {
      gap: var(--nv-space-2);
      padding: 4px 2px 0 0;
    }

    .dc-title {
      gap: var(--nv-space-2);
    }

    .dc-swatches i {
      width: 16px;
      height: 16px;
    }

    .dc-actions {
      gap: var(--nv-space-1);
      padding-top: var(--nv-space-2);
    }

    /* The thumb already opens the profile: "Открыть" keeps only its icon here. */
    .dc-actions > a.ghost {
      flex: none;
      width: var(--nv-hit);
      min-width: var(--nv-hit);
      padding: 0;
    }

    .dc-actions > a.ghost > span {
      position: absolute;
      width: 1px;
      height: 1px;
      overflow: hidden;
      clip-path: inset(50%);
      white-space: nowrap;
    }

    .dc-actions > :last-child:not(:first-child) {
      flex: 1 1 auto;
      white-space: nowrap;
    }

    .mp-avatar {
      box-shadow: 0 0 0 2px color-mix(in srgb, var(--mp-text) 20%, transparent);
    }

    /* r180: every card has the same host; the slug alone tells the profiles apart. */
    .dc-host {
      display: none;
    }
  }

  /* r180: at 320 px «Копировать стиль» does not fit beside «Открыть»: it takes its own line. */
  @media (max-width: 359px) {
    .dc-actions {
      flex-wrap: wrap;
    }

    .dc-actions > :last-child:not(:first-child) {
      flex-basis: 100%;
    }

    .dc-title {
      flex-wrap: wrap;
    }
  }
}
