/*
 * performance-card.css — the unified PerformanceCard widget (PERFORMANCE_CARD_CONTRACT.md §6,
 * COMPONENT_CATALOG.md § PerformanceCard). Every surface that renders a performance card
 * (Community carousels + expanded list, My Profile rows, My Recordings grid, Explorer / member
 * profile lists, musician dashboard tracks, the standalone performances window, Web feed) shares
 * this one sheet.
 *
 * Extracted from styles.css on 2026-09-03 (THEMES_CONTRACT §5.3 draft row "Unified performance
 * card") and re-laid-out as a fixed three-row grid so every card has the same form factor no
 * matter its type:
 *
 *   ┌──────────────────────────┐
 *   │ media   (16:9, fixed)    │  row 1 — thumbnail or placeholder, same height on every card
 *   ├──────────────────────────┤
 *   │ info    (fills the rest) │  row 2 — title · subtitle · details | badge column
 *   ├──────────────────────────┤
 *   │ actions (one neat row)   │  row 3 — pinned to the bottom, uniform control height
 *   └──────────────────────────┘
 *
 * Cards in one carousel row / grid row stretch to the tallest sibling (flex/grid `stretch`);
 * only the info row absorbs that extra height, so media tops and action bars line up across
 * solo, open-duet and full-duet cards alike. Nothing is truncated: titles and names wrap.
 *
 * Mirrored byte-for-byte to web/public/desktop/performance-card.css (TH-008 / registry id
 * `performance-card-css-th008`). Semantic tokens only (.claude/rules/ui-tokens.md); neutral
 * black/white scrims are the documented exception (tools/check-css-semantic-tokens.js).
 */

:root {
    /* Component tokens (Layer 3, DESIGN_TOKENS.md) — reference semantic tokens only. */
    --performance-card-radius: var(--primitive-radius-lg);
    --performance-card-action-height: var(--primitive-size-component-xl-sm);
    --performance-card-media-ratio: 16 / 9;
}

/* ---- card shell ---- */

.performance-card {
    position: relative;
    display: grid;
    grid-template-rows: auto minmax(0, 1fr) auto;
    min-width: 0;
    background: var(--card-background);
    border: var(--primitive-size-border-thin) solid var(--border);
    border-radius: var(--performance-card-radius);
    overflow: hidden;
    color: var(--text-primary);
    cursor: pointer;
    isolation: isolate;
    transition:
        border-color var(--primitive-duration-base) var(--primitive-easing-ease-out),
        transform var(--primitive-duration-base) var(--primitive-easing-ease-out),
        box-shadow var(--primitive-duration-base) var(--primitive-easing-ease-out);
}

.performance-card:hover {
    border-color: var(--accent);
    transform: translateY(calc(-1 * var(--semantic-spacing-2xs)));
    box-shadow: 0 var(--semantic-spacing-sm) var(--semantic-spacing-lg) rgba(0, 0, 0, 0.35);
}

.performance-card--pinned {
    border-color: var(--primary-button);
    box-shadow: 0 0 0 var(--primitive-size-border-sm) color-mix(in srgb, var(--primary-button) 40%, transparent);
}

.performance-card--pinned:hover {
    border-color: var(--primary-button);
}

/* ---- row 1: media ---- */

.performance-card-bg {
    display: block;
    width: 100%;
    aspect-ratio: var(--performance-card-media-ratio);
    object-fit: cover;
    object-position: center;
    background: color-mix(in srgb, var(--card-background) 70%, var(--semantic-color-neutral-dark));
}

/* No thumbnail (legacy rows, fetch failure, unpublished local cache): a brand-gradient tile
   of the same 16:9 size with a faded microphone watermark keeps the row's rhythm intact. */
.performance-card.no-thumbnail .performance-thumbnail-placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    aspect-ratio: var(--performance-card-media-ratio);
    background: linear-gradient(135deg, var(--primary-gradient-start), var(--primary-gradient-end));
    /* Theme text colour, not hard-coded white: neumorphism/minimalism paint this gradient near-white
       (PR 2012 review), and --text-primary is dark there and light on the dark-gradient themes. */
    color: var(--text-primary);
}

.performance-card.no-thumbnail .performance-thumbnail-placeholder .sc-icon {
    --sc-icon-size: 2.75em;
    --sc-icon-accent: currentColor;
    opacity: var(--semantic-opacity-low);
}

/* Hide old-style thumbnail element - we use the media row now */
.performance-thumbnail {
    display: none;
}

/* Optional caller overlay (buildPerformanceCardHtml topOverlayHtml): rendered as the card's LAST
   child and taken out of flow, so it can never occupy a grid row or shift media/info/actions —
   it floats over the media cell. The wrapper itself is click-transparent so it never blocks
   the card-face click, but whatever a caller puts inside it stays interactive. */
.performance-card-top-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    z-index: 2;
    pointer-events: none;
}

.performance-card-top-overlay > * {
    pointer-events: auto;
}

/* ---- row 2: info ---- */

.performance-info {
    display: flex;
    flex-direction: column;
    gap: var(--semantic-spacing-2xs);
    min-width: 0;
    min-height: 0;
    padding: var(--semantic-spacing-sm) var(--semantic-spacing-md) var(--semantic-spacing-sm);
}

.performance-title {
    font-weight: 700;
    font-size: var(--semantic-typography-body-sm-size);
    line-height: 1.3;
    letter-spacing: 0.2px;
    color: var(--text-primary);
    overflow-wrap: break-word;
}

/* Subtitle line: mode label + date */
.performance-subtitle {
    font-size: var(--semantic-typography-caption-size);
    color: var(--text-secondary);
    line-height: 1.4;
    overflow-wrap: break-word;
}

/* Two real flex columns (content, badges) — not an absolutely-positioned badge overlay —
   so a taller left column (e.g. a wrapped duet collaborator name) always pushes the row
   taller instead of the badges sitting on top of it at a fixed offset. */
.performance-meta {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: var(--semantic-spacing-sm);
    margin-top: var(--semantic-spacing-xs);
    min-width: 0;
}

.meta-content-column {
    display: flex;
    flex-direction: column;
    gap: var(--semantic-spacing-2xs);
    min-width: 0;
    flex: 1 1 auto;
}

/* Left column: detail rows stacked vertically */
.meta-details-left {
    display: flex;
    flex-direction: column;
    gap: var(--semantic-spacing-2xs);
}

.meta-detail {
    font-size: var(--semantic-typography-caption-size);
    color: var(--text-secondary);
    line-height: 1.45;
    overflow-wrap: break-word;
}

/* Right column: badges + expiry */
.meta-sidebar {
    display: flex;
    flex-direction: column;
    gap: var(--semantic-spacing-xs);
    align-items: flex-end;
    flex: 0 0 auto;
    max-width: 48%;
}

/* Stats row: time + plays inline */
.meta-stats {
    display: flex;
    flex-wrap: wrap;
    gap: var(--semantic-spacing-2xs) var(--semantic-spacing-sm);
}

.meta-stats .meta-detail {
    flex-shrink: 0;
}

/* Completions count */
.meta-completions {
    font-size: var(--semantic-typography-caption-size);
    color: var(--text-secondary);
    line-height: 1.45;
}

.performance-duet-collaborators {
    width: 100%;
    min-width: 0;
    margin-bottom: var(--semantic-spacing-2xs);
}

/* One full-width line per collaborator ("Started by: Name"), stacked vertically. The old
   side-by-side 48% column pair shattered labels and names into mid-word fragments
   ("Complet/ed by:", "Ikemus/prime") once the badge sidebar squeezed the content column
   at card width. Full-width lines wrap at word boundaries; overflow-wrap still guards a
   single unbroken token longer than the line. Nothing is truncated: .meta-sidebar is a
   real flex sibling, so extra wrapped lines push the row taller. */
.duet-part-one,
.duet-part-two {
    display: block;
    font-size: var(--semantic-typography-caption-size);
    color: var(--text-secondary);
    line-height: 1.45;
    min-width: 0;
}

.duet-part-label,
.duet-part-name {
    overflow-wrap: break-word;
}

.duet-part-label {
    font-weight: 600;
}

.duet-part-name {
    color: var(--text-primary);
    font-weight: 600;
}

/* Legacy .meta-badges for pages still using it */
.meta-badges {
    display: flex;
    flex-wrap: wrap;
    gap: var(--primitive-radius-sm);
    margin-bottom: var(--semantic-spacing-xs);
}

/* ---- badges ---- */

/*
 * Mode/status pills share one theme-aware recipe: each variant only declares a
 * `--badge-hue`, and the base rule darkens it against the neutral-dark token so
 * white label text always clears WCAG AA (>= 4.5:1) on every theme.
 * Prior bug: .badge-solo / .badge-full / .badge-cloud painted white text on
 * --semantic-color-neutral-light (near-white) — a ~1.03:1 invisible pill.
 */
.performance-badge {
    display: inline-flex;
    align-items: center;
    padding: var(--primitive-radius-xs) var(--semantic-spacing-sm);
    border-radius: var(--primitive-radius-full);
    font-size: var(--semantic-typography-caption-size);
    font-weight: 700;
    white-space: nowrap;
    letter-spacing: 0.3px;
    line-height: 1.35;
    width: fit-content;
    background: color-mix(in srgb, var(--badge-hue, var(--accent)) 70%, var(--semantic-color-neutral-dark));
    color: var(--semantic-color-neutral-white);
    border: var(--primitive-size-border-thin) solid color-mix(in srgb, var(--badge-hue, var(--accent)) 85%, transparent);
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
}

.badge-solo,
.badge-full {
    --badge-hue: var(--info);
}

.badge-duet-first,
.badge-seed {
    --badge-hue: var(--semantic-color-secondary-button);
}

.badge-duet-second {
    --badge-hue: var(--warning);
}

.badge-party {
    --badge-hue: color-mix(in srgb, var(--accent) 72%, var(--semantic-color-discord-blue));
}

.badge-complete {
    --badge-hue: var(--success);
}

.badge-local {
    --badge-hue: var(--success);
}

.badge-cloud {
    --badge-hue: var(--info);
}

.badge-published {
    --badge-hue: var(--success);
}

.badge-upload-failed {
    --badge-hue: var(--error);
    font-weight: 800;
    cursor: help;
}

.badge-upload-pending {
    /* Round-34 fix: a background publish that hasn't been attempted yet must not read as
       failed (see resolveFailedUploadSidebarHtml) — neutral/info hue, no alarm weight. */
    --badge-hue: var(--info);
    cursor: help;
}

.badge-sync-legacy {
    --badge-hue: var(--warning);
    font-weight: 800;
    cursor: help;
}

.badge-unpublished {
    /* Neutral hue needs a heavier darkening than the shared 58% to clear AA. */
    --badge-hue: var(--semantic-color-neutral-medium);
    background: color-mix(in srgb, var(--badge-hue) 40%, var(--semantic-color-neutral-dark));
}

/* Expiry pill sits on the card surface (light or dark theme), so it reads in the theme's
   own text colour over a translucent tint instead of white-on-tint. */
.performance-expiry {
    display: inline-flex;
    align-items: center;
    gap: var(--semantic-spacing-2xs);
    padding: var(--primitive-radius-xs) var(--semantic-spacing-sm);
    border-radius: var(--primitive-radius-full);
    background: color-mix(in srgb, var(--expiry-hue, var(--warning)) 18%, transparent);
    color: var(--text-primary);
    border: var(--primitive-size-border-thin) solid color-mix(in srgb, var(--expiry-hue, var(--warning)) 55%, transparent);
    font-size: var(--semantic-typography-caption-size);
    font-weight: 600;
    line-height: 1.35;
    white-space: nowrap;
    width: fit-content;
    cursor: default;
}

.performance-expiry .sc-icon {
    --sc-icon-accent: var(--expiry-hue, var(--warning));
    --sc-icon-accent-opacity: 0.6;
}

.performance-expiry--urgent {
    --expiry-hue: var(--error);
}

.performance-expiry--permanent {
    --expiry-hue: var(--info);
}

/* Expiry badge in recording cards */
.recording-meta .performance-expiry {
    display: inline-flex;
    width: fit-content;
    margin-top: var(--semantic-spacing-xs);
}

/* ---- row 3: actions bar ---- */

/* One neat row along the bottom of every card: uniform control height, content-sized
   controls, PLAY stretches to soak up the slack. Wrapping only ever kicks in for the rare
   five-control My Recordings combo (pin + play + complete duet + delete + publish). */
.performance-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--semantic-spacing-xs);
    padding: var(--semantic-spacing-xs) var(--semantic-spacing-sm);
    min-height: calc(var(--performance-card-action-height) + 2 * var(--semantic-spacing-xs));
    border-top: var(--primitive-size-border-thin) solid var(--border);
    background: var(--card-background);
}

.performance-actions .btn,
.performance-actions .star-btn,
.performance-actions .visibility-toggle-label {
    box-sizing: border-box;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--semantic-spacing-2xs);
    flex: 0 0 auto;
    min-width: 0;
    min-height: var(--performance-card-action-height);
    height: var(--performance-card-action-height);
    padding: 0 var(--semantic-spacing-sm);
    margin: 0;
    border-radius: var(--primitive-radius-md);
    font-size: var(--semantic-typography-caption-size);
    font-weight: 700;
    line-height: 1;
    letter-spacing: 0.2px;
    white-space: nowrap;
}

/* PLAY is the one primary action per card — it fills whatever the row leaves over. */
.performance-actions .btn-primary {
    flex: 1 1 auto;
    min-width: max-content;
}

/* Icon-only controls (View Profile, Delete) are square and rely on their aria-label/title. */
.performance-actions .btn-icon {
    width: var(--performance-card-action-height);
    padding: 0;
}

.performance-actions .btn > .sc-icon {
    --sc-icon-size: 1.15em;
    margin: 0;
}

.performance-actions .btn > .sc-icon + span,
.performance-actions .btn > .sc-icon:not(:last-child) {
    margin-inline-end: var(--semantic-spacing-2xs);
}

.pin-performance-btn {
    flex-shrink: 0;
}

.pin-performance-btn.is-active {
    background: color-mix(in srgb, var(--primary-button) 22%, var(--card-background));
    color: var(--text-primary);
    border: var(--primitive-size-border-thin) solid color-mix(in srgb, var(--primary-button) 60%, transparent);
    text-shadow: none;
}

/* Star / like pill */
.star-btn {
    border: var(--primitive-size-border-thin) solid var(--border);
    border-radius: var(--primitive-radius-full);
    background: color-mix(in srgb, var(--text-primary) 6%, transparent);
    color: var(--text-secondary);
    cursor: pointer;
    font-variant-numeric: tabular-nums;
    transition:
        background var(--primitive-duration-base) var(--primitive-easing-ease-out),
        border-color var(--primitive-duration-base) var(--primitive-easing-ease-out),
        color var(--primitive-duration-base) var(--primitive-easing-ease-out),
        transform var(--primitive-duration-base) var(--primitive-easing-ease-out);
}

.star-btn:hover:not(:disabled) {
    border-color: var(--warning);
    color: var(--warning);
    background: color-mix(in srgb, var(--warning) 12%, transparent);
}

.star-btn:disabled {
    cursor: not-allowed;
    opacity: var(--semantic-opacity-low);
}

.star-btn.liked {
    border-color: color-mix(in srgb, var(--warning) 65%, transparent);
    background: color-mix(in srgb, var(--warning) 16%, transparent);
    color: var(--warning);
}

.star-btn.liked:hover:not(:disabled) {
    background: color-mix(in srgb, var(--warning) 24%, transparent);
}

.star-btn:focus-visible {
    outline: var(--primitive-size-border-sm) solid var(--accent);
    outline-offset: var(--primitive-size-border-sm);
}

.star-icon {
    display: inline-flex;
    align-items: center;
    line-height: 0;
}

.star-icon .sc-icon {
    --sc-icon-size: 1.15em;
    --sc-icon-accent: currentColor;
    transition: transform var(--primitive-duration-base) var(--primitive-easing-ease-out);
}

.star-btn:hover:not(:disabled) .star-icon .sc-icon {
    transform: scale(1.15);
}

.star-count {
    font-weight: 700;
    min-width: 1.2em;
    text-align: center;
}

/* Publish toggle (My Recordings): a labelled checkbox chip that may wrap its own text. */
.performance-actions .visibility-toggle-label {
    flex: 1 1 auto;
    height: auto;
    padding: var(--semantic-spacing-2xs) var(--semantic-spacing-sm);
    justify-content: flex-start;
    gap: var(--semantic-spacing-xs);
    border: var(--primitive-size-border-thin) solid var(--border);
    background: color-mix(in srgb, var(--text-primary) 6%, transparent);
    color: var(--text-secondary);
    font-weight: 600;
    white-space: normal;
    cursor: pointer;
}

.visibility-toggle {
    margin: 0;
    flex: 0 0 auto;
    accent-color: var(--accent);
}

.visibility-toggle-text {
    display: inline-flex;
    align-items: center;
    gap: var(--semantic-spacing-2xs);
    min-width: 0;
    overflow-wrap: break-word;
    line-height: 1.25;
}

.visibility-toggle-text .sc-icon {
    margin: 0;
}

/* ---- reduced motion ---- */

@media (prefers-reduced-motion: reduce) {
    .performance-card,
    .star-btn,
    .star-icon .sc-icon {
        transition: none;
    }

    .performance-card:hover {
        transform: none;
    }
}
