/* ============================================================
   DOWNLOAD POPOVER — anchored to the ⬇ button
   Shares the .panel-surface look with animated mesh gradient,
   size controls, and a bento card grid for format selection.
   ============================================================ */

.download-popover {
    position-anchor: --download-anchor;
    position-area: inline-start center;
    margin-inline-end: var(--space-3);
    margin-top: 60px;
}

@supports not (anchor-name: --a) {
    .download-popover {
        position-area: center;
        inset: auto;
        margin: auto;
    }
}

/* ===== Size controls row ===== */

.size-row {
    display: flex;
    align-items: center;
    gap: var(--space-4);
    padding-bottom: var(--space-3);
    margin: 0 64px;
}

.size-field {
    display: flex;
    gap: 8px;
}

.size-field > span {
    font-size: var(--text-xs);
    color: var(--color-text-muted);
    font-family: var(--font-mono);
    text-transform: uppercase;
    align-content: center;
}

.size-input {
    width: 128px;
    min-width: 64px;
    font-family: var(--font-mono);
    font-size: var(--text-sm);
    color: var(--color-text);
    background: var(--color-surface-2);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    padding: 4px;
    outline: none;
    text-align: end;
}

.size-input:focus {
    border-color: var(--color-primary);
    box-shadow: var(--focus-ring);
}

.size-input::-webkit-inner-spin-button {
    opacity: 0.35;
}

.size-chain,
.size-reset {
    width: 28px;
    height: 28px;
    display: grid;
    place-items: center;
    border-radius: var(--radius-sm);
    background: transparent;
    border: none;
    cursor: pointer;
    color: var(--color-text-muted);
    flex-shrink: 0;
}

.size-chain:hover,
.size-reset:hover {
    color: --lighter(var(--color-text-muted), 0.24);
    background: --tint(var(--color-text-muted), 0.12);
}

.size-chain[aria-pressed="true"] {
    color: var(--color-primary);
    background: --tint(var(--color-primary), 0.12);
}

.size-chain svg,
.size-reset svg {
    width: 16px;
    height: 16px;
}

/* ===== Download body (shared empty state) ===== */

.download-body {
    flex: 1;
    min-height: 0;
    padding: var(--space-3) var(--space-4) var(--space-4);
    display: flex;
    flex-direction: column;
}

/* ===== Bento grid ===== */

.download-grid {
    border-block-start: 1px solid var(--color-border);
    padding-top: 16px;
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    grid-template-rows: repeat(2, 1fr);
    gap: var(--space-3);
    aspect-ratio: 2 / 1;
    flex: 1;
}

/* ===== Card ===== */

.download-card {
    --accent: var(--color-primary);

    position: relative;
    display: flex;
    flex-direction: column;
    text-align: start;
    padding: var(--space-2);
    gap: 3px;
    background: var(--color-surface-2);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    cursor: pointer;
    color: var(--color-text);
    font: inherit;
    outline: none;
}

.download-card:focus-visible {
    outline: none;
    box-shadow: var(--focus-ring);
    border-radius: var(--radius-md);
}

.download-card:hover {
    transform: translateY(-4px);
    border-color: --tint(var(--accent), 0.5);
    box-shadow:
        0 10px 24px --tint(var(--accent), 0.3),
        0 0 0 1px --tint(var(--accent), 0.4);
}

.download-card[aria-disabled="true"] {
    cursor: not-allowed;
    pointer-events: none;
    opacity: 0.35;
    filter: grayscale(0.4);
}

/* Per-format accent colours (OKLCH) */

.download-card--svg {
    --accent: oklch(70% 0.2 145);
}
.download-card--png {
    --accent: oklch(70% 0.2 250);
}
.download-card--jpg {
    --accent: oklch(50% 0.2 285);
}
.download-card--webp {
    --accent: oklch(70% 0.2 320);
}

/* Preview tile */

.download-card-preview {
    position: relative;
    flex: 1;
    min-height: 0;
    border-radius: var(--radius-sm);
    --grid-size: 12px;
    background-image:
        repeating-linear-gradient(
            0deg,
            transparent 0 calc(var(--grid-size) - 1px),
            var(--grid-line) calc(var(--grid-size) - 1px) var(--grid-size)
        ),
        repeating-linear-gradient(
            90deg,
            transparent 0 calc(var(--grid-size) - 1px),
            var(--grid-line) calc(var(--grid-size) - 1px) var(--grid-size)
        );
    background-size: var(--grid-size) var(--grid-size);
    display: grid;
    place-items: center;
    overflow: hidden;
}

.download-card--jpg .download-card-preview {
    background: white;
}

.download-card-preview img {
    max-height: 88%;
    margin-bottom: auto;
    object-fit: contain;
    pointer-events: none;
}

/* Overlay chips */

.download-card-ext {
    position: absolute;
    inset: auto 2px 2px auto;
    font-size: 0.8rem;
    padding: 0 7px 1px 4px;
    border-radius: var(--radius-sm);
    background: --tint(var(--accent), 0.18);
    color: var(--accent);
    font-family: var(--font-mono);
    font-weight: 600;
    pointer-events: none;
}

.download-card-size {
    position: absolute;
    inset: auto auto 2px 2px;
    font-family: var(--font-mono);
    font-size: var(--text-xs);
    color: var(--color-text);
    padding: 0 6px;
    border-radius: var(--radius-sm);
    background: oklch(from var(--color-surface) l c h / 0.72);
    pointer-events: none;
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        transition-duration: 0.01ms !important;
        animation-duration: 0.01ms !important;
    }
}
