/* ==========================================================================
   Surface: templates marketplace (#page-templates, templates.js)
   --------------------------------------------------------------------------
   Owns: .tp-* (tabs, toolbar, tag chips, template cards, empty states),
   dialog.tp-preview (live renderer iframe + info / success panel) and
   dialog.tp-publish (publish my style form with tag chips + visibility).
   The card thumbnails are the r175 live pages .tp-live (templates.js attach() / pump());
   the publish dialog still uses the shared mini profile (.mp in ui/discover.css)
   and the search field shares .tp-search rules with .dc-search there.
   Tokens only, no !important.
   ========================================================================== */

@layer surfaces {
  /* r181 (unslop): the live pages on the cards and in the preview are the colour on this screen; the chrome
     around them is quiet (no lift, no glass, no orange wash), one solid orange action per view («Опубликовать
     свой стиль» / «Применить к черновику»), tags and flags are quiet text, icons 16/18 at the 1.5 stroke. */
  .tp-tabs {
    margin-bottom: var(--nv-space-5);
  }

  /* r166 (T1): nothing published yet → only the empty state and its one «Опубликовать свой стиль». */
  .tp-is-empty :is(.tp-toolbar, .tp-tags, .tp-header .page-header-actions) {
    display: none;
  }

  .tp-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: var(--nv-space-3) var(--nv-space-4);
    margin-bottom: var(--nv-space-4);
  }

  .tp-tags {
    display: flex;
    flex-wrap: wrap;
    gap: var(--nv-space-2);
    margin-bottom: var(--nv-space-4);
  }

  .tp-count {
    margin-bottom: var(--nv-space-3);
    color: var(--nv-text-3);
    font-size: var(--nv-fs-13);
  }

  .tp-count:empty {
    display: none;
  }

  .tp-count b {
    color: var(--nv-text);
    font-variant-numeric: tabular-nums;
  }

  /* ---- Cards ------------------------------------------------------------------ */
  .tp-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 232px), 1fr));
    gap: var(--nv-space-4);
  }

  /* A card stays put on hover: only its hairline gets stronger. */
  .tp-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);
  }

  .tp-card:not(.is-skeleton):hover {
    border-color: var(--nv-line-strong);
  }

  /* ---- Live thumb (r175, templates.js attach()) ---------------------------------------
     The real profile renderer per card at a phone viewport (390 × 700 = LIVE_W × LIVE_H),
     scaled to the thumb width by --tp-live-scale (set by JS once for the whole grid). The
     frame takes no input: the transparent button over it opens the preview dialog. Until
     the frame is ready the thumb shows the template's background colour (--tp-bg). */
  /* Nested in the 16px card with 8px padding: 8px corners. */
  .tp-thumb {
    position: relative;
    aspect-ratio: 390 / 700;
    overflow: hidden;
    border: 1px solid var(--nv-line);
    border-radius: calc(var(--nv-r-lg) - var(--nv-space-2));
    background: var(--tp-bg, var(--nv-bg-deep));
    isolation: isolate;
  }

  .tp-live {
    position: absolute;
    inset: 0;
    overflow: hidden;
    pointer-events: none;
  }

  /* A soft sweep only while a card near the viewport waits for its page (.is-loading). */
  .tp-live::before {
    content: "";
    position: absolute;
    inset: 0;
    display: none;
    background: linear-gradient(110deg, transparent 30%, rgba(255, 255, 255, .07) 50%, transparent 70%);
    background-size: 220% 100%;
    animation: tp-live-wait 1.4s linear infinite;
  }

  .tp-live.is-loading::before {
    display: block;
  }

  /* Under the open preview dialog the grid's pages stop rendering; their documents stay. */
  .tp-grid.is-paused .tp-live {
    content-visibility: hidden;
  }

  .tp-live iframe {
    position: absolute;
    top: 0;
    left: 0;
    width: 390px;
    height: 700px;
    max-width: none;
    border: 0;
    background: transparent;
    opacity: 0;
    transform: scale(var(--tp-live-scale, .5));
    transform-origin: 0 0;
    transition: opacity var(--nv-dur-3) var(--nv-ease);
  }

  .tp-live.is-ready iframe {
    opacity: 1;
  }

  .tp-thumb-btn {
    position: absolute;
    inset: 0;
    z-index: 1;
    display: block;
    width: 100%;
    height: 100%;
    padding: 0;
    border-radius: inherit;
    background: transparent;
    cursor: zoom-in;
  }

  .tp-thumb-btn:focus-visible {
    outline-offset: -3px;
  }

  @media (prefers-reduced-motion: reduce) {
    .tp-live::before {
      animation: none;
    }
  }

  /* r175: the flags sit above the title, so they never cover the live page. */
  .tp-flags {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-bottom: -4px;
  }

  /* Flags are quiet tags; «Новый» reads like the others (no orange). */
  .tp-flags :is(.chip, .chip-premium) {
    min-height: 0;
    padding: 2px 8px;
    font-size: var(--nv-fs-12);
    line-height: 1.4;
  }

  .tp-flags .chip.accent {
    border-color: var(--nv-line);
    background: var(--nv-surface-2);
    color: var(--nv-text-2);
  }

  .tp-flags .chip svg {
    width: 12px;
    height: 12px;
  }

  /* The heart over the live page: a solid dark disc with a hairline (no glass, no zoom); saved = the accent. */
  .tp-fav {
    position: absolute;
    top: var(--nv-space-2);
    right: var(--nv-space-2);
    z-index: 2;
    display: grid;
    place-items: center;
    width: 40px;
    height: 40px;
    border: 1px solid var(--nv-line-strong);
    border-radius: 50%;
    background: color-mix(in srgb, var(--nv-bg) 76%, transparent);
    color: var(--nv-text);
    transition: color var(--nv-dur-1) var(--nv-ease), background-color var(--nv-dur-1) var(--nv-ease), border-color var(--nv-dur-1) var(--nv-ease), transform var(--nv-dur-1) var(--nv-ease);
  }

  .tp-fav:hover {
    background: color-mix(in srgb, var(--nv-bg) 92%, transparent);
  }

  .tp-fav:active {
    transform: scale(var(--nv-press-scale));
  }

  .tp-fav svg {
    width: 18px;
    height: 18px;
  }

  .tp-fav[aria-pressed="true"] {
    border-color: var(--nv-accent-line);
    color: var(--nv-accent-text);
  }

  .tp-fav[aria-pressed="true"] svg {
    fill: currentColor;
  }

  /* Column flex so the action row lines up across cards of one grid row. */
  .tp-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);
  }

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

  /* Always two lines tall, so author and tags line up across one grid row. */
  .tp-desc {
    display: -webkit-box;
    overflow: hidden;
    min-height: 3em;
    color: var(--nv-text-2);
    font-size: var(--nv-fs-13);
    line-height: 1.5;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
  }

  .tp-meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--nv-space-2);
    min-width: 0;
  }

  .tp-author {
    display: inline-flex;
    align-items: center;
    gap: var(--nv-space-2);
    min-width: 0;
    color: var(--nv-text-2);
    font-size: var(--nv-fs-12);
    font-weight: var(--nv-fw-medium);
  }

  .tp-author > span:last-child {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .tp-avatar {
    --av: 24px;
    font-size: var(--nv-fs-12);
  }

  .tp-stats {
    flex: none;
    display: inline-flex;
    gap: var(--nv-space-3);
    color: var(--nv-text-3);
    font-size: var(--nv-fs-12);
  }

  .tp-stats > span {
    display: inline-flex;
    align-items: center;
    gap: 4px;
  }

  .tp-stats svg {
    width: 16px;
    height: 16px;
  }

  .tp-stats b {
    color: var(--nv-text-2);
    font-family: var(--nv-font-figure);
    font-weight: var(--nv-fw-regular);
    font-variant-numeric: tabular-nums;
  }

  /* Tags are quiet meta (muted text); hover underlines them in the primary role. */
  .tp-tag-list {
    display: flex;
    flex-wrap: wrap;
    gap: var(--nv-space-1) var(--nv-space-3);
  }

  .tp-tag-list > :is(button, span) {
    padding: 2px 0;
    color: var(--nv-text-3);
    font-size: var(--nv-fs-12);
    font-weight: var(--nv-fw-regular);
    transition: color var(--nv-dur-1) var(--nv-ease);
  }

  .tp-tag-list > button:hover {
    color: var(--nv-text);
    text-decoration: underline;
    text-underline-offset: 3px;
  }

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

  .tp-actions > :is(.primary, .secondary) {
    flex: 1;
  }

  /* «Применить» repeats on every card, so it is the raised neutral button here; the solid orange stays for
     the one action of the view («Опубликовать свой стиль», «Применить к черновику» in the preview). */
  .tp-actions > .primary {
    --btn-fg: var(--nv-text);
    border-color: var(--nv-line-strong);
    background: var(--nv-surface-2);
  }

  .tp-actions > .primary:hover {
    color: var(--nv-text);
    background: var(--nv-surface-3);
  }

  .tp-actions > .primary:active {
    background: var(--nv-surface-2);
  }

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

  /* r175: «Предпросмотр» is its eye icon on every width (the live thumb opens the preview too). */
  .tp-actions > .secondary {
    flex: none;
    width: var(--nv-hit);
    min-width: var(--nv-hit);
    padding: 0;
  }

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

  .tp-delete:hover {
    background: var(--nv-danger-soft);
    color: var(--nv-danger);
  }

  .tp-more {
    display: flex;
    justify-content: center;
    margin-top: var(--nv-space-6);
  }

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

  .tp-empty .empty-icon svg,
  .tp-empty > svg {
    width: 24px;
    height: 24px;
  }

  .tp-thumb-skeleton {
    aspect-ratio: 390 / 700;
    border-radius: calc(var(--nv-r-lg) - var(--nv-space-2));
  }

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

  .tp-skel-short {
    width: 50%;
  }

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

    /* Round icon buttons grow both ways, otherwise the circle turns into a pill. */
    .tp-actions > .icon-btn {
      flex: none;
      min-width: var(--nv-hit);
    }

    .tp-fav {
      width: var(--nv-hit);
      height: var(--nv-hit);
    }
  }

  @media (max-width: 640px) {
    .tp-toolbar .tp-search {
      flex-basis: 100%;
      max-width: none;
    }

    .tp-sort {
      width: 100%;
    }

    .tp-tags {
      flex-wrap: nowrap;
      margin-inline: calc(var(--nv-gutter) * -1);
      padding-inline: var(--nv-gutter);
      overflow-x: auto;
      scrollbar-width: none;
    }

    .tp-tags::-webkit-scrollbar {
      display: none;
    }

    .tp-tags > .chip {
      flex: none;
    }
  }

  /* ---- Phones: compact + calm (r160) -----------------------------------------------
     Two template cards per row with square thumbs; "Применить" repeated per card is a
     soft button and "Предпросмотр" collapses to its eye icon (the thumb opens it too). */
  @media (max-width: 640px) {
    .tp-tabs {
      margin-bottom: var(--nv-space-3);
    }

    .tp-toolbar {
      gap: var(--nv-space-2);
      margin-bottom: var(--nv-space-3);
    }

    .tp-tags {
      margin-bottom: var(--nv-space-3);
    }

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

    /* Nested in the 12px card with 4px padding: 8px corners. */
    .tp-card {
      padding: var(--nv-space-1);
      border-radius: var(--nv-r-md);
    }

    .tp-thumb,
    .tp-thumb-skeleton {
      border-radius: calc(var(--nv-r-md) - var(--nv-space-1));
    }

    .tp-flags :is(.chip, .chip-premium) {
      padding: 2px 6px;
      font-size: var(--nv-fs-12);
    }

    .tp-fav {
      top: var(--nv-space-1);
      right: var(--nv-space-1);
    }

    .tp-body {
      gap: var(--nv-space-2);
      padding: var(--nv-space-2) var(--nv-space-1) var(--nv-space-1);
    }

    .tp-title :is(h2, h3) {
      font-size: var(--nv-fs-14);
    }

    .tp-desc,
    .tp-tag-list:not(.is-static) {
      display: none;
    }

    .tp-meta {
      flex-wrap: wrap;
      gap: 4px var(--nv-space-2);
    }

    .tp-stats {
      gap: var(--nv-space-2);
    }

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

    /* Own templates also carry a delete button: the thumbnail is the preview there. */
    .tp-actions:has(> .tp-delete) > .secondary {
      display: none;
    }

    .tp-actions > .primary {
      --btn-px: var(--nv-space-2);
      min-width: 0;
    }

    .tp-more {
      margin-top: var(--nv-space-4);
    }
  }

  /* ---- Preview dialog --------------------------------------------------------------- */
  /* dialogs.css size classes are :where()-wrapped and lose to the base dialog
     rule, so the surface sets its own width. */
  /* r175: on a short screen (landscape phone, small laptop) the dialog scrolls, so the actions stay reachable;
     side by side (> 860px) the row is capped to the dialog and the info column scrolls on its own. */
  .tp-preview {
    --dialog-w: 980px;
    --dialog-pad: 0;
    overflow-x: hidden;
    overflow-y: auto;
  }

  .tp-publish {
    --dialog-w: 560px;
  }

  .tp-pv {
    display: grid;
    grid-template-columns: minmax(0, 1.15fr) minmax(300px, .85fr);
    grid-template-rows: minmax(0, 1fr);
    max-height: calc(100dvh - 50px);
  }

  .tp-pv-stage {
    display: grid;
    grid-template-rows: auto 1fr;
    justify-items: center;
    gap: var(--nv-space-4);
    min-width: 0;
    padding: var(--nv-space-5);
    border-right: 1px solid var(--nv-line);
    background: var(--nv-bg-deep);
  }

  .tp-pv-controls {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: var(--nv-space-2);
    width: 100%;
  }

  .tp-pv-controls svg {
    width: 16px;
    height: 16px;
  }

  .tp-pv-screen {
    position: relative;
    overflow: hidden;
    width: 320px;
    max-width: 100%;
    height: min(620px, calc(100dvh - 170px));
    border: 1px solid var(--nv-line-strong);
    border-radius: 28px;
    background: var(--nv-bg);
    box-shadow: var(--nv-shadow-3);
  }

  .tp-pv-screen[data-device="desktop"] {
    width: 100%;
    height: auto;
    aspect-ratio: 16 / 10;
    align-self: center;
    border-radius: var(--nv-r-md);
  }

  .tp-pv-screen iframe {
    position: absolute;
    top: 0;
    left: 0;
    max-width: none;
    border: 0;
    background: transparent;
    transform-origin: top left;
    opacity: 0;
    transition: opacity var(--nv-dur-3) var(--nv-ease);
  }

  .tp-pv-screen.is-ready iframe {
    opacity: 1;
  }

  .tp-pv-spinner {
    position: absolute;
    inset: 0;
    margin: auto;
  }

  .tp-pv-screen.is-ready .tp-pv-spinner {
    display: none;
  }

  .tp-pv-info {
    display: flex;
    flex-direction: column;
    gap: var(--nv-space-4);
    min-width: 0;
    padding: var(--nv-space-6);
    overflow-y: auto;
  }

  .tp-pv-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: var(--nv-space-3);
  }

  .tp-pv-head .eyebrow {
    margin-bottom: var(--nv-space-1);
  }

  .tp-pv-head .dialog-title {
    overflow-wrap: anywhere;
  }

  .tp-preview .dialog-close svg,
  .tp-publish .dialog-close svg {
    width: 18px;
    height: 18px;
  }

  .tp-pv-author {
    display: flex;
    align-items: center;
    gap: var(--nv-space-3);
  }

  .tp-pv-author .tp-avatar {
    --av: 40px;
    font-size: 16px;
  }

  .tp-pv-who {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 2px;
    min-width: 0;
  }

  .tp-pv-who > * {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .tp-pv-author .tp-pv-chip {
    margin-left: auto;
  }

  /* r175: «Подробнее» folds the details out on phones; on wider screens they are always shown. */
  .tp-pv-toggle {
    display: none;
  }

  .tp-pv-more {
    display: flex;
    flex-direction: column;
    gap: var(--nv-space-4);
  }

  .tp-pv-author b {
    font-size: var(--nv-fs-14);
  }

  .tp-pv-author a {
    font-family: var(--nv-font-mono);
    font-size: var(--nv-fs-12);
  }

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

  .tp-pv-stats {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: var(--nv-space-2);
    margin: 0;
  }

  /* Three small figures: a muted label over the value (no box chrome beyond one hairline step). */
  .tp-pv-stats > div {
    padding: var(--nv-space-3);
    border: 1px solid var(--nv-line);
    border-radius: var(--nv-r-md);
    background: var(--nv-surface-2);
  }

  .tp-pv-stats dt {
    color: var(--nv-text-3);
    font-size: var(--nv-fs-12);
  }

  .tp-pv-stats dd {
    margin: var(--nv-space-1) 0 0;
    color: var(--nv-text);
    font-size: var(--nv-fs-14);
    font-weight: var(--nv-fw-medium);
    font-variant-numeric: tabular-nums;
  }

  .tp-pv-premium ul,
  .tp-pv-success ul {
    margin: var(--nv-space-2) 0;
    padding-left: 1.2em;
  }

  .tp-pv-premium p {
    margin-top: 2px;
  }

  .tp-pv-note {
    color: var(--nv-text-3);
    font-size: var(--nv-fs-12);
    line-height: var(--nv-lh-body);
  }

  .tp-pv-actions {
    display: flex;
    flex-wrap: wrap;
    gap: var(--nv-space-2);
    margin-top: auto;
    padding-top: var(--nv-space-2);
  }

  .tp-pv-actions svg {
    width: 18px;
    height: 18px;
  }

  .tp-pv-apply,
  .tp-pv-success .tp-pv-actions .primary {
    flex: 1 1 180px;
  }

  .tp-pv-fav[aria-pressed="true"] {
    border-color: var(--nv-accent-line);
    color: var(--nv-accent-text);
  }

  .tp-pv-fav[aria-pressed="true"] svg {
    fill: currentColor;
  }

  .tp-pv-success {
    display: flex;
    flex: 1;
    flex-direction: column;
    align-items: center;
    gap: var(--nv-space-3);
    text-align: center;
  }

  .tp-pv-success > p {
    color: var(--nv-text-2);
    font-size: var(--nv-fs-14);
    line-height: var(--nv-lh-body);
  }

  .tp-pv-success .notice {
    text-align: left;
  }

  .tp-pv-success .tp-pv-actions {
    width: 100%;
  }

  /* A plain check in the success role (no tinted disc, no glow). */
  .tp-pv-success-icon {
    display: grid;
    place-items: center;
    width: 48px;
    height: 48px;
    margin-top: var(--nv-space-6);
    border: 1px solid var(--nv-success-line);
    border-radius: 50%;
    color: var(--nv-success);
  }

  .tp-pv-success-icon svg {
    width: 24px;
    height: 24px;
  }

  @media (max-width: 860px) {
    .tp-pv {
      grid-template-columns: minmax(0, 1fr);
      grid-template-rows: none;
      max-height: none;
    }

    .tp-pv-stage {
      border-right: 0;
      border-bottom: 1px solid var(--nv-line);
    }

    .tp-pv-screen {
      width: min(320px, 100%);
      height: 56dvh;
    }

    .tp-pv-info {
      overflow: visible;
    }
  }

  /* r180: a landscape phone keeps the page beside its details (stacked, «Применить» was two screens down),
     and the actions stay pinned under the details while they scroll. */
  @media (min-width: 641px) and (max-width: 860px) and (max-height: 500px) {
    .tp-pv {
      grid-template-columns: minmax(0, 1.15fr) minmax(280px, .85fr);
      grid-template-rows: minmax(0, 1fr);
      max-height: calc(100dvh - 50px);
    }

    .tp-pv-stage {
      gap: var(--nv-space-3);
      min-height: 0;
      padding: var(--nv-space-3);
      border-right: 1px solid var(--nv-line);
      border-bottom: 0;
    }

    .tp-pv-screen {
      height: 100%;
      min-height: 0;
    }

    .tp-pv-info {
      padding: var(--nv-space-4) var(--nv-space-4) 0;
      overflow-y: auto;
    }

    .tp-pv-actions {
      position: sticky;
      bottom: 0;
      z-index: 2;
      margin-inline: calc(var(--nv-space-4) * -1);
      padding: var(--nv-space-2) var(--nv-space-4) var(--nv-space-3);
      background: var(--nv-surface-1);
    }
  }

  /* ---- r175: phones — the preview is the page itself, full screen -----------------------
     The page fills the screen above a compact sheet (name, author, actions; details under
     «Подробнее»); «Пример / Мой профиль» and the close button float over the page. */
  @media (max-width: 640px) {
    .tp-preview:not(.center) {
      width: 100%;
      height: 100dvh;
      max-height: none;
      margin: 0;
      padding: 0;
      overflow: hidden;
      border: 0;
      border-radius: 0;
      background: var(--nv-bg-deep);
    }

    .tp-preview:not(.center)::before {
      display: none;
    }

    .tp-pv {
      position: relative;
      display: flex;
      flex-direction: column;
      height: 100%;
      max-height: none;
    }

    .tp-pv-stage {
      position: relative;
      display: block;
      flex: 1 1 auto;
      min-height: 0;
      padding: 0;
      border: 0;
      background: var(--nv-bg-deep);
    }

    .tp-pv-screen {
      width: 100%;
      height: 100%;
      border: 0;
      border-radius: 0;
      box-shadow: none;
    }

    .tp-pv-device {
      display: none;
    }

    /* The controls float over the page: solid dark plates with a hairline (no glass blur). */
    .tp-pv-controls {
      position: absolute;
      top: max(var(--nv-space-2), env(safe-area-inset-top));
      right: 64px;
      left: var(--nv-space-2);
      z-index: 2;
      justify-content: flex-start;
      width: auto;
    }

    .tp-pv-source {
      border-color: var(--nv-line-strong);
      background: color-mix(in srgb, var(--nv-bg) 84%, transparent);
    }

    .tp-pv-head .dialog-close {
      position: absolute;
      top: max(var(--nv-space-2), env(safe-area-inset-top));
      right: var(--nv-space-2);
      z-index: 3;
      display: grid;
      place-items: center;
      width: var(--nv-hit);
      height: var(--nv-hit);
      border: 1px solid var(--nv-line-strong);
      border-radius: 50%;
      background: color-mix(in srgb, var(--nv-bg) 84%, transparent);
      color: var(--nv-text);
    }

    .tp-pv-info {
      flex: none;
      gap: var(--nv-space-3);
      max-height: 62dvh;
      padding: var(--nv-space-3) var(--nv-space-4) max(var(--nv-space-3), env(safe-area-inset-bottom));
      overflow-y: auto;
      overscroll-behavior: contain;
      border-top: 1px solid var(--nv-line);
      background: var(--nv-surface-1);
    }

    .tp-pv-head .eyebrow {
      display: none;
    }

    .tp-pv-head .dialog-title {
      font-size: var(--nv-fs-18);
    }

    .tp-pv-author {
      gap: var(--nv-space-2);
    }

    .tp-pv-author .tp-avatar {
      --av: 32px;
      font-size: var(--nv-fs-12);
    }

    .tp-pv-author b {
      font-size: var(--nv-fs-13);
    }

    .tp-pv-author .tp-pv-chip {
      margin-left: 0;
    }

    .tp-pv-toggle {
      display: inline-flex;
      flex: none;
      align-items: center;
      gap: 4px;
      min-height: var(--nv-hit);
      margin-left: auto;
      font-size: var(--nv-fs-13);
    }

    .tp-pv-toggle svg {
      width: 16px;
      height: 16px;
      transition: transform var(--nv-dur-2) var(--nv-ease);
    }

    .tp-pv-toggle[aria-expanded="true"] svg {
      transform: rotate(180deg);
    }

    .tp-pv-info:not(.is-open) .tp-pv-more {
      display: none;
    }

    .tp-pv-more {
      gap: var(--nv-space-3);
    }

    .tp-pv-stats > div {
      padding: var(--nv-space-2) var(--nv-space-3);
    }

    .tp-pv-actions {
      flex-wrap: nowrap;
      padding-top: 0;
    }

    .tp-pv-fav {
      flex: none;
      width: var(--nv-hit);
      min-width: var(--nv-hit);
      padding: 0;
    }

    .tp-pv-fav > span {
      position: absolute;
      width: 1px;
      height: 1px;
      overflow: hidden;
      clip-path: inset(50%);
      white-space: nowrap;
    }

    .tp-pv-apply {
      flex: 1 1 auto;
      min-width: 0;
    }

    .tp-pv-success {
      gap: var(--nv-space-2);
    }

    .tp-pv-success-icon {
      width: 40px;
      height: 40px;
      margin-top: 0;
    }

    .tp-pv-success-icon svg {
      width: 20px;
      height: 20px;
    }

    .tp-pv-success .tp-pv-actions {
      flex-wrap: wrap;
    }

    .tp-pv-success .tp-pv-actions > * {
      flex: 1 1 140px;
    }
  }

  /* ---- Publish dialog ---------------------------------------------------------------- */
  .tp-publish .dialog-header .eyebrow {
    margin-bottom: var(--nv-space-1);
  }

  .tp-pub-preview {
    height: 216px;
    overflow: hidden;
    border: 1px solid var(--nv-line);
    border-radius: var(--nv-r-md);
  }

  .tp-pub-preview > .skeleton {
    height: 100%;
    border-radius: 0;
  }

  /* A field like the others (no inner shadow): 10px corners, 4px in, the tags inside are 6px tags. */
  .tp-tag-input {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--nv-space-1);
    min-height: var(--nv-hit);
    padding: var(--nv-space-1);
    border: 1px solid var(--nv-field-line);
    border-radius: var(--nv-r-control);
    background: var(--nv-field);
    cursor: text;
    transition: border-color var(--nv-dur-1) var(--nv-ease);
  }

  .tp-tag-input:hover {
    border-color: var(--nv-field-line-hover);
  }

  .tp-tag-input:focus-within {
    border-color: var(--nv-accent);
    box-shadow: var(--nv-field-ring);
  }

  .tp-tag-input > input {
    flex: 1;
    min-width: 120px;
    min-height: 32px;
    padding: 0 var(--nv-space-2);
    border: 0;
    background: transparent;
    box-shadow: none;
  }

  .tp-tag-input > input:is(:hover, :focus, :focus-visible) {
    border: 0;
    background: transparent;
    box-shadow: none;
  }

  /* A tag you typed is a neutral tag (the orange is kept for the action), its ✕ a small square button. */
  .tp-tag-chip {
    gap: var(--nv-space-1);
    padding-right: var(--nv-space-1);
  }

  .tp-tag-chip.accent {
    border-color: var(--nv-line-strong);
    background: var(--nv-surface-3);
    color: var(--nv-text);
  }

  .tp-tag-chip button {
    display: grid;
    place-items: center;
    width: 20px;
    height: 20px;
    border-radius: calc(var(--nv-r-xs) - 2px);
    color: var(--nv-text-3);
    transition: background-color var(--nv-dur-1) var(--nv-ease), color var(--nv-dur-1) var(--nv-ease);
  }

  .tp-tag-chip button:hover {
    background: var(--nv-surface-4);
    color: var(--nv-text);
  }

  .tp-tag-chip button svg {
    width: 12px;
    height: 12px;
  }

  .tp-visibility {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: var(--nv-space-2);
    margin: 0;
    padding: 0;
    border: 0;
  }

  .tp-visibility legend {
    grid-column: 1 / -1;
    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);
  }

  /* The chosen option: an accent hairline on the same surface (no orange wash). */
  .tp-radio {
    display: flex;
    align-items: flex-start;
    gap: var(--nv-space-3);
    padding: var(--nv-space-3);
    border: 1px solid 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);
  }

  .tp-radio:hover {
    background: var(--nv-surface-3);
  }

  .tp-radio:has(input:checked) {
    border-color: var(--nv-accent);
  }

  .tp-radio input {
    margin-top: 2px;
  }

  .tp-radio > span {
    display: grid;
    gap: 2px;
  }

  .tp-radio b {
    color: var(--nv-text);
    font-size: var(--nv-fs-14);
  }

  .tp-radio small {
    color: var(--nv-text-3);
    font-size: var(--nv-fs-12);
    line-height: 1.4;
  }

  @media (max-width: 480px) {
    .tp-visibility {
      grid-template-columns: minmax(0, 1fr);
    }
  }
}

@keyframes tp-live-wait {
  from { background-position: 120% 0; }
  to { background-position: -120% 0; }
}
