/* ================================
   PEEPSO STORIES v6
   FIX: layout pulito, no override PeepSo, carosello unico
   ================================ */

/* ---- BARRA STORIES ---- */
.psstory-bar {
    display: flex;
    align-items: center;
    padding: 10px 12px;
    background: #111;
    border-bottom: 1px solid #222;
    /* FIX #1: width contenuto, NO overflow hidden che rompe scroll */
    width: 100%;
    box-sizing: border-box;
    gap: 6px;
    overflow: hidden; /* clip esterno, ma la row interna scrolla */
}

/* FIX #3: Riga unica scrollabile — tutti i cerchi in fila */
.psstory-row {
    display: flex;
    align-items: center;
    gap: 14px;
    flex: 1;
    overflow-x: auto;
    overflow-y: visible;
    -webkit-overflow-scrolling: touch;
    scroll-behavior: smooth;
    scrollbar-width: none;
    padding: 4px 2px;
    cursor: grab;
}
.psstory-row:active { cursor: grabbing; }
.psstory-row::-webkit-scrollbar { display: none; }
.psstory-row.dragging { user-select: none; cursor: grabbing; }

/* Lista storie inline (nessun wrapping extra) */
.psstory-stories-list {
    display: contents; /* FIX #3: si "dissolve" nella row, i figli diventano figli diretti */
}

/* ---- FRECCE ---- */
.psstory-arrow {
    background: rgba(40,40,40,0.95);
    border: 1px solid #333;
    color: #fff;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.2s;
    line-height: 1;
    padding: 0;
    z-index: 2;
}
.psstory-arrow:hover { background: #444; }

/* ---- BUBBLE GENERICO ---- */
.psstory-bubble,
.psstory-flash-bubble {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
    cursor: pointer;
    flex-shrink: 0;
    transition: transform 0.18s;
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
}
.psstory-bubble:hover,
.psstory-flash-bubble:hover { transform: scale(1.06); }

/* Ring */
.psstory-ring {
    width: 72px;
    height: 72px;
    border-radius: 50%;
    padding: 3px;
    background: linear-gradient(45deg, #ff2d55, #f0c040, #ff9500);
}
.psstory-ring-add    { background: #444; }
.psstory-ring-viewed { background: #3a3a3a; }

/* Thumb interno */
.psstory-thumb {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    overflow: hidden;
    border: 2px solid #111;
    background: #000;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
}
.psstory-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    border-radius: 50%;
}
.psstory-plus {
    position: absolute;
    bottom: 0; right: 0;
    width: 22px; height: 22px;
    background: #f0c040;
    color: #000;
    border-radius: 50%;
    font-size: 17px; font-weight: 900;
    display: flex; align-items: center; justify-content: center;
    border: 2px solid #111;
    line-height: 1;
}
.psstory-play-ico {
    position: absolute; inset: 0;
    display: flex; align-items: center; justify-content: center;
    color: rgba(255,255,255,0.9); font-size: 20px;
    background: rgba(0,0,0,0.25); border-radius: 50%;
}
.psstory-name {
    font-size: 11px; color: #ccc;
    white-space: nowrap; max-width: 76px;
    text-align: center; overflow: hidden; text-overflow: ellipsis;
}

/* Loading dots */
.psstory-dots { display: flex; gap: 5px; align-items: center; padding: 0 8px; }
.psstory-dots span {
    width: 7px; height: 7px; background: #444; border-radius: 50%;
    animation: psdot 1.2s infinite ease-in-out;
}
.psstory-dots span:nth-child(2) { animation-delay: .2s; }
.psstory-dots span:nth-child(3) { animation-delay: .4s; }
@keyframes psdot { 0%,80%,100%{opacity:.3;transform:scale(.8)} 40%{opacity:1;transform:scale(1)} }
.psstory-empty { color: #555; font-size: 13px; padding: 0 8px; }

/* ---- FLASH BUBBLES ---- */
.psstory-ring-flash {
    background: linear-gradient(135deg, #ff2d55, #ff9500) !important;
    animation: flash-glow 2s infinite;
}
.psstory-ring-flash-back {
    background: linear-gradient(135deg, #7b2ff7, #ff2d55) !important;
}
.psstory-ring-flash.recording,
.psstory-ring-flash-back.recording {
    animation: flash-glow-rec 0.5s infinite;
}
@keyframes flash-glow {
    0%,100% { box-shadow: 0 0 0 0 rgba(255,149,0,0.4); }
    50%      { box-shadow: 0 0 0 6px rgba(255,149,0,0.15); }
}
@keyframes flash-glow-rec {
    0%,100% { box-shadow: 0 0 0 4px rgba(255,45,85,0.7); }
    50%      { box-shadow: 0 0 0 12px rgba(255,45,85,0.2); }
}
.psstory-flash-thumb { background: rgba(0,0,0,0.2) !important; }
.psstory-flash-icon { font-size: 22px; line-height: 1; pointer-events: none; }

/* FIX #1: NON toccare i selettori PeepSo/Gecko.
   Solo la row interna ha bisogno di scroll. */

/* ---- SIDEBAR BTN ---- */
.psstory-sidebar-btn {
    width: 100%; padding: 12px;
    background: linear-gradient(135deg, #ff2d55, #ff9500);
    color: #fff; border: none; border-radius: 12px;
    font-size: 14px; font-weight: 700; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    gap: 8px; margin: 8px 0; transition: opacity .2s;
}
.psstory-sidebar-btn:hover { opacity: .85; }

/* ================================
   EDITOR MODAL
   ================================ */
.psstory-modal {
    position: fixed; inset: 0; z-index: 99998;
    display: flex; align-items: center; justify-content: center;
    background: rgba(0,0,0,.88); backdrop-filter: blur(4px);
}
.psstory-modal-box {
    background: #1a1a1a; border: 1px solid #2a2a2a; border-radius: 20px;
    padding: 24px 20px; width: 92%; max-width: 400px; max-height: 90vh;
    overflow-y: auto; position: relative; color: #fff; text-align: center;
    scrollbar-width: thin;
}
.psstory-modal-box h3 { margin: 0 0 4px; font-size: 18px; }
.psstory-sub { color: #888; font-size: 13px; margin: 0 0 18px; }
.psstory-modal-x {
    position: absolute; top: 14px; right: 16px;
    background: none; border: none; color: #888; font-size: 20px; cursor: pointer;
}
.psstory-modal-x:hover { color: #fff; }

.psstory-opts { display: flex; gap: 12px; justify-content: center; margin-bottom: 14px; }
.psstory-opt {
    display: flex; flex-direction: column; align-items: center; gap: 8px;
    padding: 16px 20px; border-radius: 14px; border: 1px solid #333;
    background: #222; color: #fff; cursor: pointer; font-size: 13px;
    font-weight: 600; transition: all .2s; flex: 1;
}
.psstory-opt span { font-size: 28px; }
.psstory-opt:hover { border-color: #f0c040; background: #2a2600; }

#psstory-cam-area video { width: 100%; max-height: 240px; border-radius: 12px; object-fit: cover; background: #000; }
.psstory-cam-btns { display: flex; gap: 8px; justify-content: center; margin-top: 10px; flex-wrap: wrap; }
.psstory-cam-btns button { padding: 9px 14px; border-radius: 50px; border: none; font-size: 13px; font-weight: 700; cursor: pointer; }
#psstory-snap { background: #f0c040; color: #000; }
#psstory-rec-start { background: #ff2d55; color: #fff; }
#psstory-rec-stop { background: #555; color: #fff; }
#psstory-rec-ind { color: #ff2d55; font-weight: 700; font-size: 14px; display: flex; align-items: center; justify-content: center; gap: 6px; margin-top: 8px; }
.psstory-rec-dot { width: 10px; height: 10px; background: #ff2d55; border-radius: 50%; animation: blink 1s infinite; }
@keyframes blink { 0%,100%{opacity:1} 50%{opacity:0} }

.psstory-canvas-wrap { position: relative; width: 100%; max-width: 360px; margin: 0 auto 14px; border-radius: 12px; overflow: hidden; background: #000; }
#psstory-canvas { display: block; width: 100%; height: auto; border-radius: 12px; }

.psstory-tabs { display: flex; gap: 4px; margin-bottom: 12px; overflow-x: auto; scrollbar-width: none; }
.psstory-tabs::-webkit-scrollbar { display: none; }
.psstory-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; }
.psstory-tab.active { background: #2a2600; border-color: #f0c040; color: #f0c040; }

.psstory-tab-pane { display: none; }
.psstory-tab-pane.active { display: block; }

.psstory-filters { display: grid; grid-template-columns: repeat(3,1fr); gap: 8px; }
.psstory-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; }
.psstory-filter.active { border-color: #f0c040; }
.psstory-filter-prev { width: 60px; height: 60px; border-radius: 8px; background: linear-gradient(135deg,#ff6b6b,#feca57,#48dbfb,#ff9ff3); }
.psstory-filter small { font-size: 11px; color: #aaa; }

#psstory-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; }
.psstory-colors { display: flex; align-items: center; gap: 7px; margin-bottom: 10px; flex-wrap: wrap; }
.psstory-color { width: 26px; height: 26px; border-radius: 50%; cursor: pointer; border: 2px solid transparent; transition: border-color .2s; flex-shrink: 0; }
.psstory-color.active { border-color: #fff; transform: scale(1.1); }
#psstory-text-sz { flex: 1; background: #222; border: 1px solid #333; color: #fff; border-radius: 8px; padding: 6px; font-size: 13px; }
#psstory-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; }
#psstory-add-text:hover { background: #444; }

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

.psstory-music-search-row { display: flex; gap: 8px; margin-bottom: 10px; }
#psstory-music-q { flex: 1; padding: 9px 12px; background: #222; border: 1px solid #333; color: #fff; border-radius: 8px; font-size: 13px; }
#psstory-music-search { padding: 9px 14px; background: #f0c040; color: #000; border: none; border-radius: 8px; font-size: 16px; cursor: pointer; font-weight: 700; }
#psstory-music-results { max-height: 200px; overflow-y: auto; }
.psstory-hint { color: #555; font-size: 13px; padding: 10px 0; }

.psstory-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; }
.psstory-track:hover { border-color:#444; }
.psstory-track.selected { border-color:#f0c040; background:#2a2600; }
.psstory-track-cover { width:44px; height:44px; border-radius:6px; object-fit:cover; flex-shrink:0; }
.psstory-track-cover-ph { background:#333; display:flex; align-items:center; justify-content:center; font-size:20px; }
.psstory-track-info { flex:1; text-align:left; min-width:0; }
.psstory-track-title { font-size:13px; font-weight:600; color:#fff; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
.psstory-track-dur { font-size:11px; color:#666; }
.psstory-track-actions { display:flex; gap:6px; flex-shrink:0; }
.psstory-track-preview { width:32px; height:32px; 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; }
.psstory-track-preview:hover { background:#555; }
.psstory-track-preview.playing { background:#ff2d55; }
.psstory-track-select { padding:6px 10px; border-radius:20px; background:#333; border:1px solid #444; color:#ccc; font-size:12px; cursor:pointer; transition:all .2s; white-space:nowrap; }
.psstory-track-select:hover { background:#f0c040; color:#000; border-color:#f0c040; }
.psstory-track.selected .psstory-track-select { background:#f0c040; color:#000; border-color:#f0c040; }

#psstory-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;
}
#psstory-music-remove { background: none; border: none; color: #888; cursor: pointer; font-size: 16px; }

#psstory-publish-btn {
    width: 100%; padding: 13px; background: #ff2d55; color: #fff;
    border: none; border-radius: 50px; font-size: 15px; font-weight: 700;
    cursor: pointer; margin-top: 14px; transition: background .2s;
}
#psstory-publish-btn:hover { background: #d4002d; }
.psstory-prog { margin-top: 10px; height: 4px; background: #333; border-radius: 4px; overflow: hidden; }
.psstory-prog-fill { height: 100%; background: #ff2d55; width: 0%; transition: width .3s; }
.psstory-msg { margin-top: 10px; padding: 10px; border-radius: 10px; font-size: 13px; font-weight: 600; }
.psstory-msg.ok  { background: #0d2e1a; color: #4caf50; border: 1px solid #4caf50; }
.psstory-msg.err { background: #2e0d0d; color: #f44336; border: 1px solid #f44336; }

/* ================================
   VIEWER FULLSCREEN
   ================================ */
.psstory-viewer {
    position: fixed; inset: 0; z-index: 999999;
    display: flex; align-items: center; justify-content: center; background: #000;
}
.psstory-viewer-bg {
    position: absolute; inset: 0; background-size: cover; background-position: center;
    filter: blur(24px) brightness(.3); z-index: 0;
}
.psstory-viewer-media {
    position: relative; z-index: 5; max-width: 420px; width: 100%;
    max-height: 86vh; display: flex; align-items: center; justify-content: center;
}
#psstory-viewer-img, #psstory-viewer-vid {
    max-width: 100%; max-height: 86vh; object-fit: contain; border-radius: 14px;
}
.psstory-viewer-text {
    position: absolute; bottom: 18%; left: 50%; transform: translateX(-50%);
    color: #fff; font-size: 26px; font-weight: 900;
    text-shadow: 0 2px 10px rgba(0,0,0,.9);
    white-space: nowrap; max-width: 90%; text-align: center;
    z-index: 6; pointer-events: none;
}
.psstory-segs {
    position: absolute; top: 10px; left: 12px; right: 12px;
    display: flex; gap: 4px; z-index: 10;
}
.psstory-seg { flex: 1; height: 3px; background: rgba(255,255,255,.3); border-radius: 3px; overflow: hidden; }
.psstory-seg-fill { height: 100%; background: #fff; width: 0%; }
.psstory-seg-fill.done { width: 100%; }
.psstory-viewer-hdr {
    position: absolute; top: 22px; left: 12px; right: 12px;
    display: flex; align-items: center; gap: 10px; z-index: 10;
}
.psstory-viewer-av { width: 38px; height: 38px; border-radius: 50%; object-fit: cover; border: 2px solid #fff; }
.psstory-viewer-info { flex: 1; }
.psstory-viewer-info b { display: block; color: #fff; font-size: 13px; text-shadow: 0 1px 3px rgba(0,0,0,.8); }
.psstory-viewer-info small { color: rgba(255,255,255,.7); font-size: 11px; }
#psstory-viewer-del, #psstory-viewer-x { background: none; border: none; color: #fff; font-size: 18px; cursor: pointer; padding: 4px 6px; border-radius: 6px; }
#psstory-viewer-del:hover { background: rgba(255,0,0,.3); }
#psstory-viewer-x:hover  { background: rgba(255,255,255,.2); }
.psstory-viewer-music-bar {
    position: absolute; bottom: 22px; left: 50%; transform: translateX(-50%);
    background: rgba(0,0,0,.65); color: #fff; padding: 6px 16px;
    border-radius: 20px; font-size: 13px; display: flex; align-items: center;
    gap: 6px; z-index: 10; backdrop-filter: blur(4px); white-space: nowrap;
    max-width: 80%; overflow: hidden; text-overflow: ellipsis;
}
.psstory-nav-btn {
    position: absolute; top: 50%; transform: translateY(-50%);
    background: rgba(255,255,255,.15); border: none; color: #fff; font-size: 32px;
    width: 44px; height: 44px; border-radius: 50%; cursor: pointer; z-index: 10;
    display: flex; align-items: center; justify-content: center; transition: background .2s;
}
.psstory-nav-btn:hover { background: rgba(255,255,255,.3); }
.psstory-nav-l { left: 12px; }
.psstory-nav-r { right: 12px; }

/* ================================
   FLASH OVERLAY
   FIX #4: overlay fullscreen pulito
   ================================ */
#psstory-flash-overlay {
    position: fixed !important;
    top: 0 !important; left: 0 !important;
    width: 100% !important; height: 100% !important;
    z-index: 999999 !important;
    background: #000;
    display: flex;
    flex-direction: column;
}
#psstory-flash-overlay video {
    flex: 1; width: 100%; object-fit: cover; display: block;
}
.psstory-flash-btn-x {
    position: absolute;
    top: 16px; left: 16px; z-index: 10;
    width: 44px; height: 44px; border-radius: 50%;
    background: rgba(0,0,0,0.65);
    border: 2px solid rgba(255,255,255,0.4);
    color: #fff; font-size: 18px; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
}
.psstory-flash-bar-wrap { height: 4px; background: rgba(255,255,255,0.2); flex-shrink: 0; }
.psstory-flash-bar {
    height: 100%;
    background: linear-gradient(90deg, #ff2d55, #ff9500);
    width: 0%;
    transition: width 0.9s linear;
}
.psstory-flash-msg {
    padding: 10px 16px; font-size: 13px; font-weight: 600;
    text-align: center; color: #fff;
    background: rgba(0,0,0,0.7); flex-shrink: 0;
}

/* Hint overlay (click senza tenere premuto) */
.psstory-flash-hint-overlay {
    position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    z-index: 999999; background: rgba(0,0,0,0.88);
    display: flex; align-items: center; justify-content: center;
    flex-direction: column; gap: 14px;
    color: #fff; text-align: center; padding: 32px;
}
.psstory-flash-hint-overlay .hint-icon { font-size: 3em; }
.psstory-flash-hint-overlay .hint-text { font-size: 1.2em; font-weight: 700; }
.psstory-flash-hint-overlay .hint-sub  { font-size: 0.9em; color: #aaa; }
.psstory-flash-hint-overlay .hint-close {
    margin-top: 8px; padding: 10px 28px;
    background: #ff2d55; color: #fff; border: none;
    border-radius: 50px; font-size: 14px; font-weight: 700; cursor: pointer;
}

/* Mobile */
@media (max-width: 480px) {
    .psstory-bar { padding: 8px; }
    .psstory-modal-box { padding: 18px 14px; }
    .psstory-opts { flex-direction: column; }
}

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