/**
 * Secret Detail Page Styles
 *
 * Matches Figma designs: desktop 1440px, mobile 375px.
 * Dark-mode by default (black bg, light-grey text).
 * Responsive, accessible, respects reduced motion.
 *
 * @package PostSecret
 */

/* ==========================================================================
   Figma spacing tokens (responsive via clamp)
   ========================================================================== */

.ps-secret-detail {
    --sd-space-8: clamp(4px, 0.5vw, 8px);
    --sd-space-12: clamp(8px, 0.75vw, 12px);
    --sd-space-16: clamp(12px, 1vw, 16px);
    --sd-space-24: clamp(20px, 1.5vw, 24px);
    --sd-space-32: clamp(24px, 2vw, 32px);
    --sd-space-40: clamp(32px, 2.5vw, 40px);
    --sd-space-48: clamp(40px, 3vw, 48px);
    --sd-space-64: clamp(48px, 4vw, 64px);
    --sd-space-80: clamp(56px, 5vw, 80px);

    /* Colors from Figma tokens — defaults target dark mode (the active theme
       today). Light-mode override below swaps in tokens with sufficient
       contrast against #ffffff per WCAG 1.4.3. */
    --sd-light-grey: #c5c5c5;
    --sd-dark-grey: #404040;

    /* Content widths */
    --sd-content-width: 802px;
}

/* ==========================================================================
   Page Layout
   ========================================================================== */

.ps-secret-detail {
    max-width: var(--content-max-width, 1216px);
    margin: 0 auto;
    padding: clamp(24px, 4vw, 48px) var(--breathing-room, clamp(1rem, 3vw, 2rem)) 0;
}

.ps-secret-detail__top {
    position: relative;
    max-width: var(--content-max-width, 1216px);
    margin: 0 auto;
}

.ps-back-circle {
    position: absolute;
    top: 0;
    left: 0;
    width: 48px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--ps-scrim-20);
    border: none;
    border-radius: 50%;
    color: #fff;
    font-size: 18px;
    text-decoration: none;
    transition: background 0.15s ease;
    z-index: 5;
}

.ps-back-circle:hover {
    background: rgba(255, 255, 255, 0.35);
}

/* WCAG 2.4.7 — include :focus fallback for legacy browsers.
   WCAG 1.4.11 — increase back-circle opacity from 0.2 to 0.6 to ensure
   the button is visible against bright postcard backgrounds (addresses
   audit finding #25). Dark halo improves contrast against any content. */
.ps-back-circle {
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}
.ps-back-circle:hover {
    background: rgba(0, 0, 0, 0.75);
}
.ps-back-circle:focus,
.ps-back-circle:focus-visible {
    outline: 3px solid var(--ps-red);
    outline-offset: 2px;
}
.ps-back-circle:focus:not(:focus-visible) {
    outline: none;
}

.ps-secret {
    display: flex;
    flex-direction: column;
    align-items: center;
    max-width: var(--sd-content-width);
    margin: 0 auto;
}

/* ==========================================================================
   Hero Image / Media
   ========================================================================== */

.ps-secret__media {
    position: relative;
    width: 100%;
}

.ps-secret__figure {
    position: relative;
    width: 100%;
    margin: 0;
}

.ps-secret__zoom-trigger {
    position: relative;
    width: 100%;
    background: transparent;
    border: none;
    padding: 0;
    cursor: zoom-in;
    display: block;
}

/* WCAG 2.4.7 — include :focus fallback for browsers without :focus-visible
   (older Safari/Edge/Firefox, some AT browsers, kiosks). Clear the outline
   for mouse focus only. */
.ps-secret__zoom-trigger:focus,
.ps-secret__zoom-trigger:focus-visible {
    outline: 3px solid var(--ps-red);
    outline-offset: 4px;
}
.ps-secret__zoom-trigger:focus:not(:focus-visible) {
    outline: none;
}

.ps-secret__img {
    display: block;
    width: 100%;
    height: auto;
    max-height: 80vh;
    object-fit: contain;
    transition: transform 0.3s ease;
}

.ps-secret__zoom-trigger:hover .ps-secret__img {
    transform: scale(1.02);
}

.ps-secret__zoom-hint {
    position: absolute;
    bottom: 1rem;
    right: 1rem;
    background: rgba(0, 0, 0, 0.75);
    color: #fff;
    padding: 0.5rem 1rem;
    border-radius: 4px;
    font-size: 0.875rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    opacity: 0;
    transition: opacity 0.2s ease;
    pointer-events: none;
}

.ps-secret__zoom-trigger:hover .ps-secret__zoom-hint,
.ps-secret__zoom-trigger:focus-visible .ps-secret__zoom-hint {
    opacity: 1;
}

/* Flip button */
.ps-secret__flip-btn {
    position: absolute;
    top: 1rem;
    right: 1rem;
    background: #fff;
    color: #000;
    border: none;
    border-radius: 50%;
    width: 48px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 1.25rem;
    transition: all 0.2s ease;
    z-index: 10;
}

.ps-secret__flip-btn:hover {
    background: var(--sd-light-grey);
    transform: rotate(180deg);
}

.ps-secret__flip-btn:focus-visible {
    outline: 3px solid var(--ps-red);
    outline-offset: 2px;
}

/* ==========================================================================
   Body Content
   ========================================================================== */

.ps-secret__body {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: var(--sd-space-64);
    padding-top: var(--sd-space-40);
}

/* ==========================================================================
   Text + Action Buttons (two-column desktop)
   ========================================================================== */

.ps-secret__text-actions {
    display: flex;
    gap: var(--sd-space-80);
    align-items: flex-start;
}

.ps-secret__text {
    flex: 1;
    min-width: 0;
}

.ps-secret__text-content {
    font-size: clamp(16px, 1.125vw, 18px);
    line-height: 1.6;
    color: var(--wp--preset--color--text, #fff);
}

.ps-secret__text-content p:last-child {
    margin-bottom: 0;
}

.ps-secret__language-label {
    margin-top: 1rem;
    font-size: 0.875rem;
    color: var(--sd-light-grey);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* Action buttons (right column) */
.ps-secret__actions {
    display: flex;
    flex-direction: column;
    gap: var(--sd-space-12);
    flex-shrink: 0;
}

.ps-action-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    height: 47px;
    background: #fff;
    color: #000;
    border: none;
    border-radius: 4px;
    font-size: 14px;
    font-weight: 600;
    font-family: var(--font-main, Inter, sans-serif);
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.15s ease;
}

.ps-action-btn:hover {
    background: var(--sd-light-grey);
}

.ps-action-btn:focus-visible {
    outline: 3px solid var(--ps-red);
    outline-offset: 2px;
}

.ps-action-btn i {
    font-size: 16px;
}

/* ==========================================================================
   Facet Pills
   ========================================================================== */

.ps-facet-list {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
}

.ps-facet {
    border: 1px solid var(--sd-light-grey);
    color: var(--sd-light-grey);
    padding: 6px 16px;
    border-radius: 4px;
    font-size: 14px;
    font-weight: 400;
    text-transform: capitalize;
    background: transparent;
}

.ps-facet--link {
    padding: 0;
}

.ps-facet--link a {
    display: block;
    padding: 6px 16px;
    color: inherit;
    text-decoration: none;
}

.ps-facet--link:hover {
    border-color: var(--wp--preset--color--accent, var(--ps-red));
    color: var(--wp--preset--color--accent, var(--ps-red));
    cursor: pointer;
}

/* ==========================================================================
   Date
   ========================================================================== */

.ps-secret__date {
    display: block;
    font-family: var(--font-mono, 'DM Mono', monospace);
    font-size: 14px;
    color: var(--sd-light-grey);
}

/* ==========================================================================
   AI Metadata Rows
   ========================================================================== */

.ps-secret__ai-meta {
    display: flex;
    flex-direction: column;
    gap: var(--sd-space-32);

    /* Element is now <dl> for a11y; reset UA default `margin: 1em 0`
       so the wrapper change doesn't shift spacing. */
    margin: 0;
}

.ps-secret__ai-row {
    display: flex;
    gap: var(--sd-space-24);
    padding-top: var(--sd-space-16);
    border-top: 1px solid var(--sd-dark-grey);
}

.ps-secret__ai-label {
    flex-shrink: 0;
    width: 128px;
    font-size: 18px;
    font-weight: 700;
    color: var(--sd-light-grey);
    display: flex;
    align-items: baseline;
    gap: 8px;
}

.ps-secret__ai-label i {
    font-size: 14px;
    color: var(--sd-light-grey);
}

.ps-secret__ai-value {
    flex: 1;
    margin: 0;
    font-size: 18px;
    line-height: 1.6;
    color: var(--wp--preset--color--text, #fff);
}

.ps-secret__ai-value--italic {
    font-style: italic;
}

/* Style sub-rows */
.ps-secret__style-list {
    display: flex;
    flex-direction: column;
    gap: var(--sd-space-16);
    margin: 0;
}

.ps-secret__style-row {
    display: flex;
    gap: var(--sd-space-24);
}

.ps-secret__style-row dt {
    flex-shrink: 0;
    width: 94px;
    font-size: 16px;
    font-weight: 700;
    color: var(--sd-light-grey);
}

.ps-secret__style-row dd {
    margin: 0;
    font-size: 16px;
    color: var(--wp--preset--color--text, #fff);
    display: flex;
    align-items: center;
    gap: 8px;
}

.ps-color-swatch {
    display: inline-block;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    border: 2px solid var(--sd-dark-grey);
    flex-shrink: 0;
}

/* ==========================================================================
   Bottom Navigation
   ========================================================================== */

.ps-secret__nav {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-top: var(--sd-space-32);
}

.ps-back-link {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    color: var(--wp--preset--color--text, #fff);
    text-decoration: underline;
    font-weight: 700;
    font-size: 16px;
    transition: color 0.15s ease;
}

.ps-back-link:hover {
    color: var(--ps-red);
}

.ps-back-link:focus-visible {
    outline: 2px solid var(--ps-red);
    outline-offset: 4px;
}

.ps-secret__nav-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* Scroll-to-similar button: mobile only */
.ps-scroll-similar-btn {
    display: none;
}

/* Nav buttons inherit .ps-action-btn styles via shared class in HTML */

.ps-copy-feedback {
    display: none;
    font-size: 14px;
    font-weight: 500;
    color: var(--sd-light-grey);
}

.ps-copy-feedback--success {
    display: inline;
    color: #10b981;
}

.ps-copy-feedback--error {
    display: inline;
    color: #ef4444;
}

/* ==========================================================================
   Similar Secrets
   ========================================================================== */

.ps-similar-secrets[hidden] {
    display: none;
}

.ps-similar-secrets {
    padding: 80px 0 80px;
    border-top: 1px solid var(--sd-dark-grey);
}

.ps-similar-secrets .ps-secret__section-title {
    font-size: clamp(26px, 2.5vw, 36px);
    font-weight: 500;
    margin: 0 auto 80px;
    max-width: var(--ps-layout-wide, 1216px);
    padding: 0 var(--ps-layout-gutter, 24px);
    color: var(--wp--preset--color--text, #fff);
    text-align: center;
}

.ps-similar-secrets .ps-stream {
    max-width: var(--ps-layout-wide, 1216px);
}

.ps-similar-secrets__container[data-loading="true"] {
    text-align: center;
    padding: 2rem;
}

.ps-loading-indicator {
    color: var(--sd-light-grey);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

/* Terminal empty/error state for the similar-secrets section. Replaces the
   spinner when the fetch times out or fails so the user is never stuck on a
   hanging loader. */
.ps-similar-secrets__empty {
    color: var(--sd-light-grey);
    text-align: center;
    padding: 1.5rem;
    margin: 0;
    font-size: 0.95rem;
    max-width: 48ch;
    margin-inline: auto;
    line-height: 1.5;
}

/* ps-latest class on section enables ps-stream.css card/row styles + hides unwanted elements */

/* Load more / Explore all actions */
.ps-similar-actions {
    display: flex;
    gap: var(--sd-space-16);
    justify-content: center;
    padding: 80px 0 80px;
}

.ps-similar-load-more,
.ps-similar-explore {
    text-decoration: none;
}

/* Search prompt bars use .ps-search-prompt styles from ps-stream.css */

/* Screen reader only (for ARIA live region) */
.ps-similar-live.screen-reader-text {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* ==========================================================================
   Lightbox
   ========================================================================== */

.ps-lightbox {
    position: fixed;
    inset: 0;
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: ps-fadeIn 0.2s ease;
}

.ps-lightbox[hidden] {
    display: none;
}

@keyframes ps-fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.ps-lightbox__backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.9);
    cursor: zoom-out;
}

.ps-lightbox__content {
    position: relative;
    max-width: 95vw;
    max-height: 95vh;
    z-index: 1;
}

.ps-lightbox__img {
    display: block;
    max-width: 100%;
    max-height: 95vh;
    object-fit: contain;
}

.ps-lightbox__close {
    position: absolute;
    top: 1rem;
    right: 1rem;
    background: var(--ps-scrim-90);
    color: #000;
    border: none;
    border-radius: 50%;
    width: 48px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 1.5rem;
    transition: all 0.2s ease;
    z-index: 2;
}

.ps-lightbox__close:hover {
    background: #fff;
    transform: rotate(90deg);
}

.ps-lightbox__close:focus-visible {
    outline: 3px solid var(--ps-red);
    outline-offset: 2px;
}

/* ==========================================================================
   Gated / Advisory Messages
   ========================================================================== */

.ps-gated-content,
.ps-advisory-content {
    min-height: 60vh;
    display: flex;
    align-items: center;
    justify-content: center;
}

.ps-message {
    max-width: 600px;
    text-align: center;
    padding: 3rem 2rem;
}

.ps-message__icon {
    font-size: 4rem;
    color: var(--sd-light-grey);
    margin-bottom: 1.5rem;
}

.ps-message--advisory .ps-message__icon {
    color: var(--ps-red);
}

.ps-message__title {
    font-size: clamp(1.75rem, 3vw, 2.5rem);
    font-weight: 700;
    margin: 0 0 1rem 0;
}

.ps-message__text {
    font-size: 1.125rem;
    line-height: 1.6;
    color: var(--sd-light-grey);
    margin-bottom: 2rem;
}

.ps-message__actions {
    display: flex;
    gap: 1rem;
    justify-content: center;
    flex-wrap: wrap;
}

.ps-button {
    display: inline-block;
    padding: 0.75rem 2rem;
    background: var(--ps-red);
    color: #fff;
    text-decoration: none;
    border: none;
    border-radius: 4px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s ease;
}

.ps-button:hover {
    background: var(--ps-red-dark);
}

.ps-button--secondary {
    background: transparent;
    color: var(--wp--preset--color--text, #fff);
    border: 2px solid var(--sd-dark-grey);
}

.ps-button--secondary:hover {
    background: var(--sd-dark-grey);
}

/* ==========================================================================
   Responsive — Mobile (≤768px)
   ========================================================================== */

@media (max-width: 768px) {
    .ps-back-circle {
        position: static;
        margin-bottom: var(--sd-space-16);
    }

    .ps-secret__text-actions {
        flex-direction: column;
        gap: var(--sd-space-32);
    }

    .ps-secret__actions {
        flex-direction: row;
        flex-wrap: wrap;
    }

    .ps-action-btn {
        height: 40px;
        padding: 6px 12px;
        font-size: 13px;
    }

    .ps-secret__ai-row {
        flex-direction: column;
        gap: var(--sd-space-8);
    }

    .ps-secret__ai-label {
        width: auto;
    }

    .ps-secret__style-row {
        flex-direction: column;
        gap: 4px;
    }

    .ps-secret__style-row dt {
        width: auto;
    }

    .ps-secret__nav {
        flex-direction: column-reverse;
        gap: var(--sd-space-16);
        align-items: stretch;
    }

    .ps-secret__nav-actions {
        justify-content: flex-end;
    }

    /* Show scroll-to-similar on mobile */
    .ps-scroll-similar-btn {
        display: flex;
    }

    /* Hide button labels on small screens — icon-only */
    .ps-secret__nav .ps-action-btn__label {
        display: none;
    }

    .ps-similar-actions {
        flex-direction: column;
        align-items: stretch;
    }

    .ps-facet {
        font-size: 12px;
        padding: 4px 12px;
    }

    .ps-secret__date {
        font-size: 12px;
    }
}

/* ==========================================================================
   Reduced Motion
   ========================================================================== */

@media (prefers-reduced-motion: reduce) {
    .ps-secret__img,
    .ps-secret__zoom-hint,
    .ps-secret__flip-btn,
    .ps-copy-link,
    .ps-action-btn,
    .ps-back-link,
    .ps-similar-secrets .ps-card,
    .ps-lightbox {
        transition: none !important;
        animation: none !important;
    }

    .ps-secret__flip-btn:hover,
    .ps-lightbox__close:hover {
        transform: none !important;
    }
}

/* ==========================================================================
   Print Styles
   ========================================================================== */

@media print {
    .ps-secret__zoom-hint,
    .ps-secret__flip-btn,
    .ps-lightbox,
    .ps-copy-link,
    .ps-back-circle,
    .ps-back-link,
    .ps-secret__actions,
    .ps-secret__nav,
    .ps-similar-secrets,
    .ps-similar-actions {
        display: none !important;
    }
}
