/* ===================================================================
   Share Buttons — clean, polished, Medium/Substack-inspired
   =================================================================== */

/* ── Section wrapper ── */
.share-section {
    margin: 32px 0 12px;
    overflow: visible;
}

.share-label {
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--secondary);
    margin-bottom: 12px;
}

/* ── Container card ── */
.share-container {
    display: inline-flex;
    flex-direction: column;
    gap: 0;
    background: var(--code-bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 10px 12px;
    overflow: visible;
}

/* ── Primary row ── */
.share-primary {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: nowrap;
}

/* ── Secondary expand panel ── */
.share-secondary {
    display: grid;
    grid-template-rows: 0fr;
    transition: grid-template-rows 350ms cubic-bezier(0.4, 0, 0.2, 1);
    overflow: hidden;
}

.share-secondary.is-open {
    grid-template-rows: 1fr;
    overflow: visible;
}

.share-secondary-inner {
    overflow: visible;
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    /* extra padding revealed only when open */
    padding-top: 0;
    transition: padding-top 350ms cubic-bezier(0.4, 0, 0.2, 1);
}

.share-secondary.is-open .share-secondary-inner {
    padding-top: 8px;
}

/* ── Base button ── */
.share-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    flex-shrink: 0;
    border-radius: 6px;
    background: transparent;
    color: var(--secondary);
    border: 1px solid transparent;
    cursor: pointer;
    position: relative;
    text-decoration: none;
    padding: 0;
    font-family: inherit;
    font-size: inherit;
    /* Color-only transition — no lift, no shadow */
    transition: color 150ms ease, background-color 150ms ease, border-color 150ms ease;
}

.share-btn svg {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
    /* inherit stroke/fill from color */
}

/* Hover: unified brand-neutral style */
.share-btn:hover {
    color: var(--primary);
    background-color: var(--entry);
    border-color: var(--border);
}

/* Active: slight dim */
.share-btn:active {
    opacity: 0.75;
}

/* More button rotates when open */
.share-btn--more svg {
    transition: transform 300ms cubic-bezier(0.4, 0, 0.2, 1);
}
#share-secondary.is-open ~ .share-primary .share-btn--more svg,
.share-btn--more[aria-expanded="true"] svg {
    transform: rotate(180deg);
}

/* Web share hidden until JS enables */
.share-btn--webshare {
    display: none;
}

/* ── CSS Tooltips ── */
.share-btn::before {
    content: attr(data-tooltip);
    position: absolute;
    bottom: calc(100% + 8px);
    left: 50%;
    transform: translateX(-50%) translateY(4px);
    background: var(--primary);
    color: var(--theme);
    padding: 4px 9px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 500;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 150ms ease, transform 150ms ease;
    z-index: 200;
}

.share-btn::after {
    content: '';
    position: absolute;
    bottom: calc(100% + 4px);
    left: 50%;
    transform: translateX(-50%);
    border: 4px solid transparent;
    border-top-color: var(--primary);
    opacity: 0;
    transition: opacity 150ms ease;
    pointer-events: none;
    z-index: 200;
}

.share-btn:hover::before {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}
.share-btn:hover::after {
    opacity: 1;
}

/* ── Copy toast ── */
.share-toast {
    position: fixed;
    bottom: 32px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--primary);
    color: var(--theme);
    padding: 10px 20px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    z-index: 9999;
    pointer-events: none;
    animation: shareToastIn 0.2s ease forwards,
               shareToastOut 0.3s ease 2s forwards;
}

@keyframes shareToastIn {
    from { opacity: 0; transform: translateX(-50%) translateY(8px); }
    to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}

@keyframes shareToastOut {
    from { opacity: 1; }
    to   { opacity: 0; }
}

/* ── Mobile bottom sheet ── */
.share-sheet-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: 1000;
    opacity: 0;
    transition: opacity 300ms ease;
}

.share-sheet-backdrop.is-open {
    opacity: 1;
}

.share-sheet {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--theme);
    border-top: 1px solid var(--border);
    border-radius: 16px 16px 0 0;
    padding: 12px 20px 32px;
    z-index: 1001;
    transform: translateY(100%);
    transition: transform 350ms cubic-bezier(0.4, 0, 0.2, 1);
    max-height: 80vh;
    overflow-y: auto;
}

.share-sheet.is-open {
    transform: translateY(0);
}

.share-sheet-handle {
    width: 36px;
    height: 4px;
    background: var(--border);
    border-radius: 2px;
    margin: 0 auto 16px;
}

.share-sheet-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--secondary);
    letter-spacing: 0.06em;
    text-transform: uppercase;
    margin-bottom: 16px;
}

.share-sheet-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 12px 8px;
}

.share-sheet-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
}

.share-sheet-item .share-btn {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    background: var(--code-bg);
    border-color: var(--border);
    color: var(--secondary);
}

.share-sheet-item .share-btn:hover {
    color: var(--primary);
    background: var(--entry);
}

.share-sheet-item span {
    font-size: 10px;
    color: var(--secondary);
    text-align: center;
    line-height: 1.2;
    max-width: 56px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ── Responsive ── */
@media (max-width: 640px) {
    .share-container {
        /* Full width on mobile */
        display: flex;
        width: 100%;
        box-sizing: border-box;
    }

    .share-primary {
        flex-wrap: wrap;
        gap: 8px;
    }

    .share-btn {
        width: 44px;
        height: 44px;
    }

    .share-btn svg {
        width: 20px;
        height: 20px;
    }

    /* Tooltips off on mobile (touch has no hover) */
    .share-btn::before,
    .share-btn::after {
        display: none;
    }

    /* Show bottom sheet elements on mobile */
    .share-sheet-backdrop,
    .share-sheet {
        display: block;
    }

    .share-sheet-backdrop {
        pointer-events: none;
    }

    .share-sheet-backdrop.is-open {
        pointer-events: auto;
    }

    /* Hide desktop expand panel on mobile */
    .share-secondary {
        display: none;
    }
}

/* ===================================================================
   WeChat QR Code Modal
   =================================================================== */

/* ── Backdrop ── */
.wechat-qr-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    z-index: 2000;
    align-items: center;
    justify-content: center;
    padding: 16px;
}

.wechat-qr-backdrop.is-open {
    display: flex;
    animation: wqrBackdropIn 200ms ease forwards;
}

@keyframes wqrBackdropIn {
    from { opacity: 0; }
    to   { opacity: 1; }
}

/* ── Modal card ── */
.wechat-qr-modal {
    position: relative;
    background: var(--theme);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 28px 24px 20px;
    max-width: 340px;
    width: 100%;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.18), 0 4px 16px rgba(0, 0, 0, 0.08);
    animation: wqrModalIn 250ms cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

@keyframes wqrModalIn {
    from { opacity: 0; transform: scale(0.92); }
    to   { opacity: 1; transform: scale(1); }
}

/* ── Close button ── */
.wechat-qr-close {
    position: absolute;
    top: 12px;
    right: 12px;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--code-bg);
    border: 1px solid var(--border);
    color: var(--secondary);
    cursor: pointer;
    font-size: 18px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    font-family: inherit;
    transition: background-color 150ms ease, color 150ms ease;
}

.wechat-qr-close:hover {
    background: var(--entry);
    color: var(--primary);
}

/* ── Header (logo + platform name) ── */
.wechat-qr-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 16px;
}

.wechat-qr-logo {
    width: 22px;
    height: 22px;
    flex-shrink: 0;
    color: #07C160;
}

.wechat-qr-platform {
    font-size: 14px;
    font-weight: 600;
    color: var(--primary);
    letter-spacing: 0.01em;
}

/* ── QR body ── */
.wechat-qr-body {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    margin-bottom: 16px;
}

/* QR image wrapper — loading skeleton */
.wechat-qr-img-wrap {
    width: 180px;
    height: 180px;
    border-radius: 12px;
    border: 1px solid var(--border);
    background: var(--code-bg);
    overflow: hidden;
    position: relative;
}

.wechat-qr-img-wrap::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(
        90deg,
        transparent 0%,
        rgba(128,128,128,0.08) 50%,
        transparent 100%
    );
    background-size: 200% 100%;
    animation: wqrSkeleton 1.4s ease infinite;
}

@keyframes wqrSkeleton {
    0%   { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* Stop skeleton once image loads */
.wechat-qr-img-wrap.loaded::before {
    display: none;
}

.wechat-qr-img {
    width: 180px;
    height: 180px;
    display: block;
    border-radius: 11px;
    position: relative;
    z-index: 1;
}

.wechat-qr-hint {
    margin: 0;
    font-size: 13px;
    font-weight: 500;
    color: var(--primary);
    text-align: center;
}

.wechat-qr-hint-en {
    margin: 0;
    font-size: 11px;
    color: var(--secondary);
    text-align: center;
}

/* ── Article info ── */
.wechat-qr-article {
    border-top: 1px solid var(--border);
    padding-top: 12px;
    margin-bottom: 16px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.wechat-qr-title {
    margin: 0;
    font-size: 13px;
    font-weight: 600;
    color: var(--primary);
    overflow: hidden;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    line-height: 1.4;
}

.wechat-qr-desc {
    margin: 0;
    font-size: 11px;
    color: var(--secondary);
    overflow: hidden;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    line-height: 1.4;
}

.wechat-qr-meta {
    display: flex;
    flex-direction: column;
    gap: 5px;
    margin-top: 8px;
}

.wechat-qr-cats,
.wechat-qr-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}

.wechat-qr-chip {
    display: inline-block;
    font-size: 10px;
    font-weight: 500;
    padding: 2px 7px;
    border-radius: 3px;
    line-height: 1.5;
    letter-spacing: 0.02em;
}

.wechat-qr-chip--cat {
    background: #07C160;
    color: #fff;
}

.wechat-qr-chip--tag {
    background: transparent;
    border: 1px solid rgba(7, 193, 96, 0.4);
    color: #07C160;
}

.wechat-qr-source {
    margin: 6px 0 0;
    font-size: 10px;
    color: var(--secondary);
    font-weight: 400;
    letter-spacing: 0.02em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    opacity: 0.6;
}

/* ── Footer (copy button) ── */
.wechat-qr-footer {
    display: flex;
}

.wechat-qr-copy-btn {
    width: 100%;
    padding: 10px 16px;
    background: var(--code-bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--secondary);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    font-family: inherit;
    transition: background-color 180ms ease, color 180ms ease, border-color 180ms ease;
}

.wechat-qr-copy-btn:hover {
    background: #07C160;
    border-color: #07C160;
    color: #fff;
}

/* ── Responsive ── */
@media (max-width: 400px) {
    .wechat-qr-modal {
        padding: 24px 16px 16px;
    }

    .wechat-qr-img-wrap,
    .wechat-qr-img {
        width: 160px;
        height: 160px;
    }
}

/* ============================================================
   Reduced motion: stop the QR skeleton shimmer. It is a transient
   loading sweep with no end-state to keep, so freezing it is safe.
   ============================================================ */
@media (prefers-reduced-motion: reduce) {
  .wechat-qr-img-wrap::before {
    animation: none !important;
  }
}
