/* ===========================
   PEEPSO REEL - CSS
   =========================== */

:root {
    --reel-bg: #0a0a0a;
    --reel-card-bg: #1a1a1a;
    --reel-accent: #ff2d55;
    --reel-gold: #f0c040;
    --reel-text: #ffffff;
    --reel-muted: #aaaaaa;
    --reel-border: #2a2a2a;
    --reel-radius: 16px;
}

.psreel-wrap {
    max-width: 520px;
    margin: 0 auto;
    padding: 16px;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

/* ---- UPLOAD BOX ---- */
.psreel-upload-box {
    background: var(--reel-card-bg);
    border: 1px solid var(--reel-border);
    border-radius: var(--reel-radius);
    padding: 20px;
    margin-bottom: 24px;
    color: var(--reel-text);
}

.psreel-upload-box h3 {
    margin: 0 0 16px;
    font-size: 16px;
    color: var(--reel-text);
}

.psreel-upload-options {
    display: flex;
    gap: 12px;
    margin-bottom: 16px;
}

/* ---- BUTTONS ---- */
.psreel-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 18px;
    border-radius: 50px;
    border: none;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    transition: all 0.2s ease;
    text-decoration: none;
}

.psreel-btn-upload {
    background: var(--reel-gold);
    color: #000;
}

.psreel-btn-upload:hover {
    background: #d4a800;
    transform: translateY(-1px);
}

.psreel-btn-record {
    background: var(--reel-accent);
    color: #fff;
}

.psreel-btn-record:hover {
    background: #d4002d;
    transform: translateY(-1px);
}

.psreel-btn-publish {
    background: var(--reel-accent);
    color: #fff;
    flex: 1;
}

.psreel-btn-cancel {
    background: var(--reel-border);
    color: var(--reel-muted);
}

.psreel-btn-loadmore {
    background: var(--reel-card-bg);
    color: var(--reel-text);
    border: 1px solid var(--reel-border);
    width: 100%;
    justify-content: center;
    padding: 14px;
    border-radius: var(--reel-radius);
}

/* ---- PREVIEW VIDEO ---- */
.psreel-preview-wrap {
    margin: 12px 0;
    border-radius: 12px;
    overflow: hidden;
    background: #000;
    position: relative;
}

.psreel-wrap .psreel-preview-wrap video {
    width: 100% !important;
    height: 70vw !important;
    max-height: 75vh !important;
    min-height: 300px !important;
    object-fit: cover !important;
    display: block !important;
    border-radius: 0 !important;
}

/* Camera live: riempie il wrapper aspect-ratio 9/16 */
.psreel-wrap .psreel-camera-wrap video {
    position: absolute !important;
    top: 0 !important;
    left: 0 !important;
    width: 100% !important;
    height: 100% !important;
    object-fit: cover !important;
    display: block !important;
    border-radius: 0 !important;
}

.psreel-preview-info {
    padding: 8px 12px;
    font-size: 13px;
    color: var(--reel-muted);
}

/* ---- CAMERA LIVE ---- */
/* Padding-top trick per aspect ratio 9:16, compatibile tutti i browser mobile */
.psreel-camera-wrap {
    display: none;
    margin: 0;
    position: relative;
    border-radius: 12px;
    overflow: hidden;
    background: #000;
    width: 100%;
    padding-top: 177.78%; /* 16/9 * 100 */
    height: 0;
}

/* Il video occupa tutta l'area del wrapper */
#psreel-camera {
    position: absolute !important;
    top: 0 !important;
    left: 0 !important;
    width: 100% !important;
    height: 100% !important;
    object-fit: contain !important; /* contain: non taglia, non ingrandisce oltre il reale */
    display: block !important;
    background: #000 !important;
}

/* Pulsante flip fotocamera */
#psreel-flip-camera {
    position: absolute;
    top: 12px;
    right: 12px;
    z-index: 20;
    background: rgba(0,0,0,0.6);
    border: none;
    color: #fff;
    font-size: 20px;
    width: 42px;
    height: 42px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Timer e stop: assoluti dentro il wrapper */
.psreel-record-controls {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    z-index: 10;
    white-space: nowrap;
}

.psreel-flip-btn:hover { background: rgba(255,255,255,0.2); }

.psreel-record-timer {
    background: rgba(0,0,0,0.7);
    color: #fff;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 16px;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

.psreel-btn-stop {
    background: var(--reel-accent);
    color: #fff;
    border: none;
    padding: 12px 24px;
    border-radius: 50px;
    font-size: 15px;
    font-weight: 700;
    cursor: pointer;
}

.psreel-record-bar {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: rgba(255,255,255,0.2);
}

.psreel-record-progress {
    height: 100%;
    background: var(--reel-accent);
    width: 0%;
    transition: width 1s linear;
}

/* ---- CAPTION ---- */
.psreel-caption-wrap {
    margin-top: 12px;
}

.psreel-caption-wrap textarea {
    width: 100%;
    background: #111;
    border: 1px solid var(--reel-border);
    color: var(--reel-text);
    border-radius: 10px;
    padding: 12px;
    font-size: 14px;
    resize: none;
    height: 80px;
    box-sizing: border-box;
}

.psreel-upload-actions {
    display: flex;
    gap: 10px;
    margin-top: 10px;
}

/* ---- PROGRESS BAR ---- */
.psreel-progress-bar {
    margin-top: 10px;
    background: var(--reel-border);
    border-radius: 10px;
    height: 6px;
    position: relative;
    overflow: hidden;
}

.psreel-progress-fill {
    height: 100%;
    background: var(--reel-accent);
    width: 0%;
    transition: width 0.3s ease;
    border-radius: 10px;
}

#psreel-progress-text {
    font-size: 12px;
    color: var(--reel-muted);
    display: block;
    text-align: center;
    margin-top: 4px;
}

/* ---- MESSAGE ---- */
.psreel-message {
    margin-top: 12px;
    padding: 10px 16px;
    border-radius: 10px;
    font-size: 14px;
    font-weight: 600;
}

.psreel-message.success {
    background: #0d2e1a;
    color: #4caf50;
    border: 1px solid #4caf50;
}

.psreel-message.error {
    background: #2e0d0d;
    color: #f44336;
    border: 1px solid #f44336;
}

/* ---- FEED ---- */
.psreel-feed {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

/* ---- REEL CARD ---- */
.psreel-card {
    background: var(--reel-card-bg);
    border: 1px solid var(--reel-border);
    border-radius: var(--reel-radius);
    overflow: visible !important;
    position: relative;
}
/* header e footer mantengono il clipping del border-radius della card */
.psreel-card-footer,
.psreel-card-hashtags,
.psreel-caption,
.psreel-comments-section {
    border-radius: 0 0 var(--reel-radius) var(--reel-radius);
    overflow: hidden;
}

.psreel-card-header {
    border-radius: var(--reel-radius) var(--reel-radius) 0 0;
    overflow: hidden;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
}

.psreel-card-header img {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid var(--reel-accent);
}

.psreel-author-info {
    flex: 1;
}

.psreel-author-name {
    font-weight: 700;
    font-size: 14px;
    color: var(--reel-text);
    text-decoration: none;
}

.psreel-author-name:hover {
    color: var(--reel-gold);
}

.psreel-date {
    font-size: 12px;
    color: var(--reel-muted);
}

/* ---- VIDEO ---- */
.psreel-video-wrap {
    position: relative;
    background: #000;
    cursor: pointer;
    overflow: visible !important;
}

.psreel-video-wrap video {
    width: 100%;
    max-height: 560px;
    min-height: 200px;
    object-fit: cover;
    display: block;
}

.psreel-play-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0,0,0,0.3);
    opacity: 0;
    transition: opacity 0.2s;
}

.psreel-video-wrap:hover .psreel-play-overlay,
.psreel-video-wrap.paused .psreel-play-overlay {
    opacity: 1;
}

.psreel-play-icon {
    width: 60px;
    height: 60px;
    background: rgba(255,255,255,0.9);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
}

/* ---- CARD FOOTER ---- */
.psreel-card-footer {
    padding: 12px 16px;
    display: flex;
    align-items: center;
    gap: 16px;
}

.psreel-caption {
    padding: 0 16px 12px;
    font-size: 14px;
    color: var(--reel-text);
    line-height: 1.4;
}

.psreel-like-btn {
    background: none;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    color: var(--reel-muted);
    font-size: 15px;
    font-weight: 600;
    padding: 6px 12px;
    border-radius: 20px;
    transition: all 0.2s;
}

.psreel-like-btn:hover,
.psreel-like-btn.liked {
    color: var(--reel-accent);
    background: rgba(255,45,85,0.1);
}

.psreel-like-btn.liked .psreel-heart {
    animation: heartbeat 0.3s ease;
}

@keyframes heartbeat {
    0%   { transform: scale(1); }
    50%  { transform: scale(1.4); }
    100% { transform: scale(1); }
}

.psreel-delete-btn {
    margin-left: auto;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--reel-muted);
    font-size: 13px;
    padding: 4px 8px;
    border-radius: 6px;
    transition: color 0.2s;
}

.psreel-delete-btn:hover {
    color: var(--reel-accent);
}

/* ---- LOGIN NOTICE ---- */
.psreel-login-notice {
    background: var(--reel-card-bg);
    border: 1px solid var(--reel-border);
    border-radius: var(--reel-radius);
    padding: 20px;
    text-align: center;
    color: var(--reel-muted);
    margin-bottom: 24px;
}

.psreel-login-notice a {
    color: var(--reel-gold);
    font-weight: 700;
}

/* ---- LOADING ---- */
.psreel-loading {
    display: flex;
    justify-content: center;
    padding: 40px;
}

.psreel-spinner {
    width: 36px;
    height: 36px;
    border: 3px solid var(--reel-border);
    border-top-color: var(--reel-accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.psreel-empty {
    text-align: center;
    color: var(--reel-muted);
    padding: 40px;
    font-size: 15px;
}

.psreel-load-more-wrap {
    margin-top: 16px;
}

/* ---- PROFILO GRID ---- */
.psreel-profile-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 4px;
}

.psreel-profile-item {
    position: relative;
    aspect-ratio: 9/16;
    overflow: hidden;
    cursor: pointer;
    border-radius: 8px;
    background: #000;
}

.psreel-profile-item video {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.psreel-profile-likes {
    position: absolute;
    bottom: 6px;
    left: 6px;
    font-size: 12px;
    color: #fff;
    text-shadow: 0 1px 3px rgba(0,0,0,0.8);
    font-weight: 600;
}

/* ---- RESPONSIVE ---- */
@media (max-width: 480px) {
    .psreel-wrap {
        padding: 8px;
    }

    .psreel-upload-options {
        flex-direction: column;
    }

    .psreel-btn-upload,
    .psreel-btn-record {
        justify-content: center;
        width: 100%;
    }
}

/* ===== REEL v2 - EDITOR =====  */
.psreel-editor-tabs { display:flex; gap:4px; margin:12px 0 10px; overflow-x:auto; scrollbar-width:none; }
.psreel-editor-tabs::-webkit-scrollbar { display:none; }
.psreel-tab { flex:1; padding:8px 4px; background:#222; border:1px solid #333; color:#aaa; border-radius:8px; cursor:pointer; font-size:12px; white-space:nowrap; transition:all .2s; }
.psreel-tab.active { background:#2a2600; border-color:#f0c040; color:#f0c040; }
.psreel-tab-pane { display:none; }
.psreel-tab-pane.active { display:block; }

/* Filtri */
.psreel-filters-grid { display:grid; grid-template-columns:repeat(3,1fr); gap:8px; margin-bottom:10px; }
.psreel-filter { display:flex; flex-direction:column; align-items:center; gap:4px; cursor:pointer; padding:6px; border-radius:8px; border:2px solid transparent; transition:border-color .2s; }
.psreel-filter.active { border-color:#f0c040; }
.psreel-filter-prev { width:56px; height:56px; border-radius:8px; background:linear-gradient(135deg,#ff6b6b,#feca57,#48dbfb,#ff9ff3); }
.psreel-filter small { font-size:11px; color:#aaa; }

/* Testo */
#psreel-text-inp { width:100%; padding:10px 12px; background:#222; border:1px solid #333; color:#fff; border-radius:8px; font-size:14px; box-sizing:border-box; margin-bottom:8px; }
.psreel-colors { display:flex; align-items:center; gap:7px; margin-bottom:10px; flex-wrap:wrap; }
.psreel-color { width:26px; height:26px; border-radius:50%; cursor:pointer; border:2px solid transparent; transition:border-color .2s; flex-shrink:0; }
.psreel-color.active { border-color:#fff; transform:scale(1.1); }
#psreel-text-sz { flex:1; background:#222; border:1px solid #333; color:#fff; border-radius:8px; padding:6px; font-size:13px; }
#psreel-add-text { width:100%; padding:10px; background:#333; border:1px solid #444; color:#fff; border-radius:8px; cursor:pointer; font-size:13px; font-weight:600; }
#psreel-add-text:hover { background:#444; }

/* Sticker */
.psreel-stickers-grid { display:grid; grid-template-columns:repeat(5,1fr); gap:6px; }
.psreel-sticker { font-size:28px; cursor:pointer; padding:6px; border-radius:8px; transition:transform .2s; text-align:center; }
.psreel-sticker:hover { transform:scale(1.3); background:#222; }

/* Musica */
.psreel-music-search-row { display:flex; gap:8px; margin-bottom:10px; }
#psreel-music-q { flex:1; padding:9px 12px; background:#222; border:1px solid #333; color:#fff; border-radius:8px; font-size:13px; }
#psreel-music-search { padding:9px 14px; background:#f0c040; color:#000; border:none; border-radius:8px; font-size:16px; cursor:pointer; font-weight:700; }
#psreel-music-results { max-height:200px; overflow-y:auto; }
.psreel-hint { color:#555; font-size:13px; padding:10px 0; }
.psreel-track { display:flex; align-items:center; gap:10px; padding:8px 10px; background:#222; border-radius:8px; margin-bottom:6px; border:1px solid transparent; transition:border-color .2s; }
.psreel-track:hover { border-color:#444; }
.psreel-track.selected { border-color:#f0c040; background:#2a2600; }
.psreel-track-cover { width:40px; height:40px; border-radius:6px; object-fit:cover; flex-shrink:0; }
.psreel-track-ph { background:#333; display:flex; align-items:center; justify-content:center; font-size:18px; }
.psreel-track-info { flex:1; text-align:left; min-width:0; }
.psreel-track-title { font-size:13px; font-weight:600; color:#fff; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
.psreel-track-dur { font-size:11px; color:#666; }
.psreel-track-actions { display:flex; gap:6px; flex-shrink:0; }
.psreel-track-prev { width:30px; height:30px; border-radius:50%; background:#333; border:none; color:#fff; font-size:13px; cursor:pointer; display:flex; align-items:center; justify-content:center; transition:background .2s; }
.psreel-track-prev:hover { background:#555; }
.psreel-track-prev.playing { background:#ff2d55; }
.psreel-track-sel { padding:5px 10px; border-radius:20px; background:#333; border:1px solid #444; color:#ccc; font-size:12px; cursor:pointer; transition:all .2s; }
.psreel-track-sel:hover { background:#f0c040; color:#000; border-color:#f0c040; }
.psreel-track.selected .psreel-track-sel { background:#f0c040; color:#000; border-color:#f0c040; }
#psreel-music-chosen { display:flex; align-items:center; gap:8px; padding:8px 12px; background:#2a2600; border:1px solid #f0c040; border-radius:8px; color:#f0c040; font-size:13px; font-weight:600; margin-top:8px; justify-content:space-between; }
#psreel-music-remove { background:none; border:none; color:#888; cursor:pointer; font-size:16px; }

/* Preview con overlay */
.psreel-preview-wrap { position:relative; }
.psreel-preview-text-overlay {
    position:absolute; bottom:20%; left:50%; transform:translateX(-50%);
    font-weight:900; text-shadow:0 2px 8px rgba(0,0,0,.9);
    white-space:nowrap; pointer-events:none; z-index:5;
    max-width:90%; text-align:center;
}
.psreel-preview-sticker-overlay {
    position:absolute; top:10%; left:50%; transform:translateX(-50%);
    font-size:52px; pointer-events:none; z-index:5;
}

/* Card overlay nel feed */
.psreel-card-text-overlay {
    position:absolute; bottom:20%; left:50%; transform:translateX(-50%);
    font-weight:900; text-shadow:0 2px 8px rgba(0,0,0,.9);
    white-space:nowrap; pointer-events:none; z-index:5;
    max-width:90%; text-align:center;
}
.psreel-card-sticker-overlay {
    position:absolute; top:10%; left:50%; transform:translateX(-50%);
    font-size:52px; pointer-events:none; z-index:5;
}
.psreel-card-music {
    position:absolute; bottom:6%; left:50%; transform:translateX(-50%);
    background:rgba(0,0,0,.6); color:#fff; padding:5px 14px;
    border-radius:20px; font-size:12px; z-index:5;
    backdrop-filter:blur(4px); white-space:nowrap;
    max-width:85%; overflow:hidden; text-overflow:ellipsis;
}

/* ---- STICKY BAR ---- */
.reel-sticky-bar {
    position: sticky;
    top: 0;
    z-index: 99;
    display: flex;
    gap: 8px;
    padding: 10px 16px;
    background: rgba(10,10,10,0.92);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid #2a2a2a;
    justify-content: center;
    flex-wrap: wrap;
}

.reel-sticky-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 9px 18px;
    border-radius: 50px;
    font-size: 14px;
    font-weight: 700;
    text-decoration: none;
    cursor: pointer;
    border: none;
    transition: all 0.2s ease;
    white-space: nowrap;
}

.reel-sticky-home {
    background: #1a1a1a;
    color: #fff;
    border: 1px solid #2a2a2a;
}
.reel-sticky-home:hover { background: #2a2a2a; color: #fff; }

.reel-sticky-upload {
    background: #f0c040;
    color: #000;
}
.reel-sticky-upload:hover { background: #d4a800; transform: translateY(-1px); color: #000; }

.reel-sticky-record {
    background: #ff2d55;
    color: #fff;
}
.reel-sticky-record:hover { background: #d4002d; transform: translateY(-1px); color: #fff; }

/* ---- Music drawer ---- */
#psreel-music-drawer {
    background: #161616;
    border: 1px solid #2a2a2a;
    border-radius: 12px;
    margin-top: 10px;
    overflow: hidden;
}
.psreel-music-drawer-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    border-bottom: 1px solid #2a2a2a;
    background: #1a1a1a;
}
.psreel-music-drawer-header input[type="text"] {
    flex: 1;
    background: #111;
    border: 1px solid #2a2a2a;
    border-radius: 8px;
    padding: 7px 12px;
    color: #fff;
    font-size: 13px;
    outline: none;
}
.psreel-music-drawer-header input[type="text"]:focus { border-color: #f97316; }
.psreel-music-drawer-header button {
    background: none;
    border: none;
    color: #888;
    font-size: 18px;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 6px;
    transition: color .15s;
}
.psreel-music-drawer-header button:hover { color: #fff; }
#psreel-music-list {
    max-height: 260px;
    overflow-y: auto;
    padding: 4px 0;
}
#psreel-music-list::-webkit-scrollbar { width: 4px; }
#psreel-music-list::-webkit-scrollbar-track { background: transparent; }
#psreel-music-list::-webkit-scrollbar-thumb { background: #333; border-radius: 2px; }

/* ===== v3 ADDITIONS ===== */

/* Sticker layer nel preview editor */
.psreel-stickers-layer {
    position: absolute; inset: 0;
    pointer-events: none;
    z-index: 8;
}
/* Wrapper sticker: intercetta touch/click */
.psreel-sticker-placed {
    pointer-events: all;
    touch-action: none;
    -webkit-user-select: none;
    user-select: none;
}
/* Emoji dentro il wrapper */
.psreel-sticker-emoji {
    display: block;
    line-height: 1;
    pointer-events: none;
}
/* Pulsante × e handle resize: display gestito via JS */
.psreel-sticker-del {
    touch-action: auto; /* tap normale */
}
.psreel-sticker-resize {
    touch-action: none; /* il drag del resize blocca scroll — ok */
}
.psreel-preview-wrap {
    /* touch-action lasciato al default: solo gli sticker hanno touch-action:none */
}

/* Sticker nella card del feed */
.psreel-card-stickers-layer {
    position: absolute; inset: 0; pointer-events: none; z-index: 4;
}
.psreel-card-sticker {
    position: absolute; transform: translate(-50%, -50%); line-height: 1;
}

/* Hashtag chips nell'editor */
.psreel-hashtag-chips {
    display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px;
}
.psreel-hashtag-chip {
    background: #1a1a2e; color: #a78bfa; padding: 4px 10px;
    border-radius: 20px; font-size: 13px; display: inline-flex; align-items: center; gap: 5px;
}
.psreel-hashtag-chip-del { cursor: pointer; opacity: 0.7; }
.psreel-hashtag-chip-del:hover { opacity: 1; }

/* Hashtag nella card feed */
.psreel-card-hashtags { padding: 4px 12px 6px; }
.psreel-hashtag-link { color: #a78bfa; text-decoration: none; font-size: 13px; margin-right: 4px; }
.psreel-hashtag-link:hover { text-decoration: underline; }

/* Azioni verticali sulla card (reazioni + share) */
.psreel-card-actions {
    position: absolute; right: 10px; bottom: 60px;
    display: flex; flex-direction: column; align-items: center; gap: 16px;
    z-index: 10;
}
.psreel-reactions-wrap, .psreel-share-wrap {
    position: relative; display: flex; flex-direction: column; align-items: center; gap: 2px;
}
.psreel-react-toggle, .psreel-share-btn {
    background: rgba(0,0,0,0.5); border: none; color: #fff;
    font-size: 22px; width: 44px; height: 44px; border-radius: 50%;
    cursor: pointer; display: flex; align-items: center; justify-content: center;
    backdrop-filter: blur(4px); transition: transform 0.15s;
}
.psreel-react-toggle:hover, .psreel-share-btn:hover { transform: scale(1.1); }
.psreel-react-count { color: #fff; font-size: 12px; font-weight: 700; text-shadow: 0 1px 3px #000; }

/* Pannello reazioni */
.psreel-reaction-panel {
    position: absolute; right: 54px; bottom: 0;
    background: rgba(20,20,20,0.95); border-radius: 30px;
    padding: 6px 10px; display: flex; gap: 6px; align-items: center;
    backdrop-filter: blur(8px); border: 1px solid rgba(255,255,255,0.1);
    white-space: nowrap; z-index: 20;
}
.psreel-reaction-emoji {
    font-size: 24px; cursor: pointer; transition: transform 0.15s;
    padding: 2px; border-radius: 50%;
}
.psreel-reaction-emoji:hover, .psreel-reaction-emoji.active { transform: scale(1.3); }
.psreel-reaction-emoji.active { background: rgba(167,139,250,0.25); }

/* Share sheet */
.psreel-share-sheet {
    position: absolute; right: 54px; bottom: 0;
    background: rgba(20,20,20,0.97); border-radius: 14px;
    padding: 6px 0; min-width: 160px; z-index: 20;
    border: 1px solid rgba(255,255,255,0.1); backdrop-filter: blur(8px);
}
.psreel-share-option {
    display: block; padding: 10px 16px; color: #fff; text-decoration: none;
    font-size: 14px; transition: background 0.15s; cursor: pointer;
}
.psreel-share-option:hover { background: rgba(255,255,255,0.08); }

/* Summary reazioni nel footer */
.psreel-reaction-summary { font-size: 14px; color: #aaa; padding: 0 2px; }

/* Badge brano custom */
.psreel-custom-badge {
    background: #a78bfa; color: #111; font-size: 10px; padding: 2px 6px;
    border-radius: 8px; margin-left: 6px; vertical-align: middle;
}

/* Caption textarea */
#psreel-caption-inp { margin-top: 10px; }

/* ===== ADMIN ===== */
.psreel-admin-wrap h1 { font-size: 22px; margin-bottom: 16px; }
.psreel-admin-stats { display: flex; gap: 16px; margin-bottom: 24px; flex-wrap: wrap; }
.psreel-stat-box {
    background: #1e1e2e; border-radius: 12px; padding: 16px 24px;
    display: flex; flex-direction: column; align-items: center; gap: 4px;
    min-width: 120px; border: 1px solid #333;
}
.psreel-stat-num { font-size: 28px; font-weight: 700; color: #a78bfa; }
.psreel-admin-table { margin-top: 8px; }
.psreel-admin-table th { background: #1a1a2e; color: #a78bfa; }
.psreel-admin-table td { vertical-align: middle; }
.psreel-admin-music-add { background: #1a1a2e; border-radius: 12px; padding: 20px; margin-bottom: 20px; border: 1px solid #333; }
.psreel-admin-music-add h2 { color: #a78bfa; margin-top: 0; }

/* ===== v5: pulsanti laterali, popup fixed, commenti ===== */

/* --- Pulsanti laterali sovrapposti al video (FIX 1) --- */
.psreel-card-side-actions {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 22px;
    z-index: 30;
    pointer-events: auto;
}

.psreel-side-action-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}

.psreel-side-btn {
    width: 52px;
    height: 52px;
    border-radius: 50%;
    border: none;
    background: rgba(0,0,0,0.65);
    color: #fff;
    font-size: 24px;
    line-height: 52px;
    text-align: center;
    padding: 0;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    transition: transform 0.15s, background 0.15s;
    box-shadow: 0 2px 12px rgba(0,0,0,0.6);
    overflow: visible;
    flex-shrink: 0;
}
.psreel-side-btn:hover,
.psreel-side-btn:active { transform: scale(1.1); background: rgba(0,0,0,0.85); }

.psreel-side-count {
    color: #fff;
    font-size: 13px;
    font-weight: 700;
    text-shadow: 0 1px 4px rgba(0,0,0,0.9);
    text-align: center;
    line-height: 1.2;
}

/* --- Popup fixed globale (FIX 1: reazioni e share) --- */
#psreel-popup-overlay {
    position: fixed;
    inset: 0;
    z-index: 9998;
    background: transparent;
}

#psreel-popup-fixed {
    position: fixed;
    z-index: 9999;
    filter: drop-shadow(0 4px 16px rgba(0,0,0,0.5));
}

.psreel-fpopup-reactions {
    display: flex;
    gap: 8px;
    align-items: center;
    background: rgba(18,18,18,0.97);
    border-radius: 36px;
    padding: 8px 14px;
    border: 1px solid rgba(255,255,255,0.12);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
}

.psreel-fp-emoji {
    font-size: 26px;
    cursor: pointer;
    transition: transform 0.15s;
    padding: 3px;
    border-radius: 50%;
    line-height: 1;
}
.psreel-fp-emoji:hover { transform: scale(1.35); }
.psreel-fp-emoji.active {
    background: rgba(167,139,250,0.3);
    transform: scale(1.2);
}

.psreel-fpopup-share {
    background: rgba(18,18,18,0.97);
    border-radius: 14px;
    padding: 6px 0;
    min-width: 175px;
    border: 1px solid rgba(255,255,255,0.12);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
}
.psreel-fpopup-share .psreel-share-option {
    display: block;
    padding: 10px 18px;
    color: #fff;
    text-decoration: none;
    font-size: 14px;
    cursor: pointer;
    transition: background 0.1s;
    white-space: nowrap;
}
.psreel-fpopup-share .psreel-share-option:hover {
    background: rgba(255,255,255,0.09);
}

/* --- Commenti (FIX 2 + 3) --- */
.psreel-comments-section {
    border-top: 1px solid var(--reel-border);
    background: #111;
}

.psreel-comments-list {
    max-height: 320px;
    overflow-y: auto;
    padding: 10px 14px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    scrollbar-width: thin;
    scrollbar-color: #333 transparent;
}

.psreel-no-comments {
    color: var(--reel-muted);
    font-size: 13px;
    text-align: center;
    padding: 16px 0;
}

.psreel-comments-loading {
    color: var(--reel-muted);
    font-size: 13px;
    text-align: center;
    padding: 12px 0;
}

.psreel-comment {
    display: flex;
    gap: 10px;
    align-items: flex-start;
}

.psreel-comment-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
    border: 1.5px solid var(--reel-border);
}

.psreel-comment-body {
    flex: 1;
    min-width: 0;
}

.psreel-comment-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 3px;
}

.psreel-comment-author {
    font-size: 12px;
    font-weight: 700;
    color: var(--reel-text);
}

.psreel-comment-date {
    font-size: 11px;
    color: var(--reel-muted);
}

.psreel-comment-delete {
    margin-left: auto;
    background: none;
    border: none;
    cursor: pointer;
    font-size: 12px;
    opacity: 0.5;
    padding: 0;
    line-height: 1;
}
.psreel-comment-delete:hover { opacity: 1; }

.psreel-comment-text {
    font-size: 13px;
    color: #ddd;
    line-height: 1.45;
    word-break: break-word;
}

/* Reazioni al commento (FIX 3) */
.psreel-comment-reactions-row {
    margin-top: 5px;
}

.psreel-comment-react-btn {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 13px;
    color: var(--reel-muted);
    padding: 2px 6px;
    border-radius: 12px;
    transition: background 0.15s;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}
.psreel-comment-react-btn:hover {
    background: rgba(255,255,255,0.07);
    color: #fff;
}
.psreel-comment-react-summary {
    font-size: 12px;
    color: #888;
}

.psreel-fpopup-comment-reactions {
    padding: 6px 12px;
}

/* Form commento */
.psreel-comment-form {
    display: flex;
    gap: 8px;
    align-items: center;
    padding: 10px 14px;
    border-top: 1px solid var(--reel-border);
    background: #0d0d0d;
}

.psreel-comment-input {
    flex: 1;
    background: #1a1a1a;
    border: 1px solid var(--reel-border);
    border-radius: 20px;
    padding: 8px 14px;
    color: #fff;
    font-size: 13px;
    outline: none;
    transition: border-color 0.15s;
}
.psreel-comment-input:focus { border-color: var(--reel-accent); }
.psreel-comment-input::placeholder { color: #555; }

.psreel-comment-submit {
    background: var(--reel-accent);
    border: none;
    border-radius: 50%;
    width: 34px;
    height: 34px;
    color: #fff;
    font-size: 14px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: transform 0.15s;
}
.psreel-comment-submit:hover { transform: scale(1.1); }
.psreel-comment-submit:disabled { opacity: 0.5; }

.psreel-comment-login {
    padding: 12px 14px;
    font-size: 13px;
    color: var(--reel-muted);
    text-align: center;
}
.psreel-comment-login a { color: var(--reel-accent); }

/* Aggiusta card footer quando ci sono commenti */
.psreel-card-footer {
    padding: 8px 14px 10px;
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 0;
}
.psreel-reaction-summary {
    font-size: 13px;
    color: #888;
}

/* ===== TRIMMER VIDEO ===== */
.psreel-trimmer-wrap {
    margin: 12px 0;
    background: #111;
    border-radius: 12px;
    padding: 12px 14px;
    border: 1px solid #2a2a2a;
}
.psreel-trimmer-label {
    font-size: 13px;
    font-weight: 700;
    color: #fff;
    margin-bottom: 10px;
}
.psreel-trimmer-timeline {
    position: relative;
    height: 36px;
    cursor: pointer;
    user-select: none;
}
.psreel-trimmer-track {
    position: absolute;
    inset: 12px 0;
    background: #333;
    border-radius: 4px;
}
.psreel-trimmer-selection {
    position: absolute;
    top: 0; bottom: 0;
    background: rgba(232,0,45,0.45);
    border-top: 2px solid var(--reel-accent);
    border-bottom: 2px solid var(--reel-accent);
    pointer-events: none;
}
.psreel-trimmer-handle {
    position: absolute;
    top: -6px; bottom: -6px;
    width: 14px;
    background: var(--reel-accent);
    border-radius: 4px;
    cursor: ew-resize;
    transform: translateX(-50%);
    touch-action: none;
    z-index: 2;
    box-shadow: 0 2px 6px rgba(0,0,0,0.4);
}
.psreel-trimmer-handle::after {
    content: '|||';
    position: absolute;
    top: 50%; left: 50%;
    transform: translate(-50%,-50%);
    font-size: 8px;
    color: rgba(255,255,255,0.7);
    letter-spacing: -1px;
}
/* Lineetta verticale posizione corrente video */
.psreel-trimmer-playhead {
    position: absolute;
    top: -4px; bottom: -4px;
    width: 2px;
    background: #fff;
    left: 0%;
    transform: translateX(-50%);
    pointer-events: none;
    z-index: 3;
    border-radius: 2px;
    box-shadow: 0 0 4px rgba(255,255,255,0.8);
}
.psreel-trimmer-times {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 8px;
    font-size: 12px;
    color: #aaa;
}

/* ===== SCRUBBER VIDEO ===== */
.psreel-scrubber-wrap {
    margin-top: 14px;
}
.psreel-scrubber-bar {
    position: relative;
    height: 6px;
    background: #333;
    border-radius: 3px;
    cursor: pointer;
    user-select: none;
    touch-action: none;
}
.psreel-scrubber-progress {
    position: absolute;
    left: 0; top: 0; bottom: 0;
    background: var(--reel-accent);
    border-radius: 3px;
    pointer-events: none;
    width: 0%;
}
.psreel-scrubber-thumb {
    position: absolute;
    top: 50%;
    width: 16px;
    height: 16px;
    background: #fff;
    border: 2px solid var(--reel-accent);
    border-radius: 50%;
    transform: translate(-50%, -50%);
    cursor: grab;
    pointer-events: none;
    left: 0%;
    box-shadow: 0 1px 4px rgba(0,0,0,0.5);
    transition: transform 0.1s;
}
.psreel-scrubber-bar:active .psreel-scrubber-thumb {
    cursor: grabbing;
    transform: translate(-50%, -50%) scale(1.2);
}
.psreel-scrubber-times {
    display: flex;
    justify-content: space-between;
    font-size: 11px;
    color: #888;
    margin-top: 5px;
}



/* Scrubber row con play/pause */
.psreel-scrubber-row {
    display: flex;
    align-items: center;
    gap: 10px;
}
.psreel-scrubber-playpause {
    flex-shrink: 0;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    border: none;
    background: var(--reel-accent);
    color: #fff;
    font-size: 14px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.1s;
}
.psreel-scrubber-playpause:hover { transform: scale(1.1); }
.psreel-scrubber-bar {
    flex: 1; /* occupa tutto lo spazio rimanente nella row */
}

/* Badge reel pinnato (condiviso via link) */
.psreel-pinned-badge {
    font-size: 11px;
    background: rgba(167,139,250,0.2);
    color: #a78bfa;
    border: 1px solid rgba(167,139,250,0.4);
    border-radius: 20px;
    padding: 2px 8px;
    margin-left: auto;
    margin-right: 6px;
    white-space: nowrap;
}

/* ===== OVERRIDE FINALE: overflow chain per side-buttons ===== */
.psreel-wrap .psreel-feed .psreel-card,
.psreel-feed .psreel-card,
div.psreel-card {
    overflow: visible !important;
}
.psreel-wrap .psreel-feed .psreel-card .psreel-video-wrap,
.psreel-feed .psreel-card .psreel-video-wrap,
div.psreel-card .psreel-video-wrap {
    overflow: visible !important;
    position: relative !important;
}
/* side-actions centrati verticalmente sul video */
div.psreel-card .psreel-video-wrap .psreel-card-side-actions {
    position: absolute !important;
    right: 8px !important;
    top: 50% !important;
    bottom: auto !important;
    transform: translateY(-50%) !important;
    z-index: 30 !important;
}



/* ---- GENERAZIONE VIDEO AI (aggiunta) ---- */
.psreel-btn-ai {
    background: linear-gradient(135deg, #7b2ff7, #f72fbf);
    color: #fff;
}
.psreel-btn-ai:hover {
    filter: brightness(1.08);
    transform: translateY(-1px);
}

/* Modal a schermo intero (era un bottom-sheet parziale, ora copre tutto il viewport) */
.psreel-ai-modal {
    display: none;
    flex-direction: column;
    position: fixed;
    inset: 0;
    background: #000;
    z-index: 9999;
}
.psreel-ai-modal-inner {
    background: #0a0a0a;
    width: 100%;
    flex: 1 1 auto;
    min-height: 0; /* necessario perché flex+overflow funzionino insieme */
    overflow-y: auto;
    padding: 18px 18px 24px;
    box-sizing: border-box;
    -webkit-overflow-scrolling: touch;
}
/* Barra fissa in fondo, FUORI dall'area scrollabile: non copre mai la lista musica */
.psreel-ai-footer-bar {
    flex: 0 0 auto;
    background: #0a0a0a;
    border-top: 1px solid #222;
    padding: 12px 18px calc(12px + env(safe-area-inset-bottom, 0px));
    box-sizing: border-box;
}
.psreel-ai-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    position: sticky;
    top: -18px;
    background: #0a0a0a;
    padding: 18px 0 10px;
    z-index: 2;
}
.psreel-ai-modal-header h4 { margin: 0; color: #fff; font-size: 17px; }
.psreel-ai-modal-header button {
    background: #222; border: none; color: #fff;
    width: 34px; height: 34px; border-radius: 50%; cursor: pointer;
    font-size: 16px; flex-shrink: 0;
}

.psreel-ai-section { margin-bottom: 20px; }
.psreel-ai-section-label {
    font-size: 13px; color: #999; margin-bottom: 10px; font-weight: 600;
    text-transform: uppercase; letter-spacing: 0.3px;
}

.psreel-ai-photo-preview {
    display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px;
}
.psreel-ai-photo-thumb {
    width: 60px; height: 60px; object-fit: cover; border-radius: 8px;
}

.psreel-ai-grid-templates {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
}
.psreel-ai-card {
    background: #1a1a1a;
    border: 1.5px solid #2a2a2a;
    border-radius: 10px;
    padding: 6px 4px 8px;
    text-align: center;
    font-size: 10.5px;
    color: #ddd;
    cursor: pointer;
    transition: border-color 0.15s ease, transform 0.1s ease;
}
.psreel-ai-card:active { transform: scale(0.96); }
.psreel-ai-card-preview {
    width: 100%;
    aspect-ratio: 3/4;
    border-radius: 7px;
    margin-bottom: 5px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid transparent;
}
.psreel-ai-card.active {
    border-color: #f72fbf;
    box-shadow: 0 0 0 1px #f72fbf;
}
.psreel-ai-card.active::after {
    content: "✓";
    display: block;
    margin-top: 2px;
    color: #f72fbf;
    font-weight: 700;
    font-size: 11px;
}

/* Messaggi dentro il modal AI (prima finivano nascosti dietro l'overlay) */
.psreel-ai-message {
    padding: 10px 14px;
    border-radius: 10px;
    font-size: 13px;
    margin-bottom: 14px;
}
.psreel-ai-message.error { background: #3a1414; color: #ff8080; border: 1px solid #5a2020; }
.psreel-ai-message.success { background: #143a1c; color: #7fe89a; border: 1px solid #205a2c; }

/* Box anteprima video live */
.psreel-ai-preview-box {
    position: relative;
    width: 100%;
    max-width: 220px;
    margin: 0 auto 18px;
    aspect-ratio: 9/16;
    background: #000;
    border-radius: 14px;
    overflow: hidden;
    border: 1.5px solid #2a2a2a;
}
.psreel-ai-preview-canvas {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    display: block;
}
.psreel-ai-preview-placeholder {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    color: #666;
    text-align: center;
    padding: 0 16px;
}
.psreel-ai-preview-play {
    position: absolute;
    bottom: 10px;
    right: 10px;
    width: 38px; height: 38px;
    border-radius: 50%;
    background: rgba(0,0,0,0.6);
    border: 1.5px solid rgba(255,255,255,0.4);
    color: #fff;
    font-size: 14px;
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    backdrop-filter: blur(4px);
}

/* Ricerca musica + riuso lista compatta .psreel-track già esistente nel plugin */
.psreel-ai-music-search {
    width: 100%;
    padding: 9px 12px;
    border-radius: 10px;
    border: 1.5px solid #333;
    background: #111;
    color: #fff;
    font-size: 13px;
    box-sizing: border-box;
    margin-bottom: 10px;
}
.psreel-ai-music-list {
    max-height: 260px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.psreel-ai-progress {
    text-align: center;
    color: #aaa;
    font-size: 13px;
    margin-top: 8px;
}

.psreel-ai-duration-slider {
    width: 100%;
    accent-color: #f72fbf;
    height: 4px;
}
