/* story-loop.css — the Story Studio's matrix panel (refounding-story-studio S3).
 *
 * The 2 × n matrix: each chapter is a row of two cells — its pictures | the member's own words. Phone-first:
 * on the phone (and any narrow window) the two cells stack inside the chapter; 44 px touch targets throughout.
 * Colour carries meaning only: the state line says where the story stands (amber = still being written,
 * blue = handed to the Vault, green = a version to watch, slate = on hold, violet = published).
 */

/* The panel's own NON-MODAL window (no backdrop, no focus trap): beside Fergi AI on the desktop and the iPad
   (docked to the left of the App Panel; Fergi compacts bottom-right), a full-height sheet on the phone. */
.sl-window {
    display: none;
    position: fixed;
    z-index: 10340;                              /* under Fergi AI (10350); on a narrow canvas (iPad) the two windows overlap a little and focus order decides */
    left: calc(var(--ffa-canvas-x, 172px) + 14px);
    top: calc(var(--ffa-canvas-y, 60px) + 14px);
    width: min(max(calc(var(--ffa-canvas-w, 1268px) * 0.56), 440px), 780px, calc(100vw - 28px));
    container-type: inline-size;                 /* the cells stack by the PANEL's width, not the viewport's */
    height: calc(var(--ffa-canvas-h, 840px) - 28px);
    flex-direction: column;
    border-radius: 14px;
    overflow: hidden;
    background: #f6f3ee;
    border: 1px solid rgba(131, 24, 67, 0.35);
    box-shadow: 0 18px 48px rgba(0, 0, 0, 0.35);
}
.sl-window.is-open { display: flex; }
.sl-window-head {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px 8px 16px;
    background: #831843;
    color: #fff;
}
/* The title wraps to a second line rather than clipping (homing-demo-findings S4, D-8: "Story Studio — Tho…" in iPad
   portrait). Two lines at most; only a title longer than that ends in "…". min-width: 0 lets it yield to the ✕. */
.sl-window-title {
    flex: 1 1 auto; min-width: 0; margin: 0; font-size: 1rem; font-weight: 600; line-height: 1.3;
    overflow: hidden; overflow-wrap: anywhere;
    display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; line-clamp: 2;
}
.sl-window-close {
    flex: 0 0 auto;
    width: 44px;
    height: 44px;
    border: 0;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.12);
    color: #fff;
    font-size: 1.5rem;
    line-height: 1;
    cursor: pointer;
}
.sl-window-body { flex: 1 1 auto; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; }
/* The phone: between the app's own top bar and its bottom bar (both stay — they are the way out). Before
   this the bars covered the sheet's title and its "Hand it to the Vault" footer (the S3 walk's frame). */
.sl-window.sl-window-pocket {
    left: 0; right: 0;
    top: var(--mobile-top-bar-total-height, 60px);
    bottom: var(--mobile-control-panel-height, var(--mobile-tab-bar-total-height, 56px));
    width: auto; height: auto;
    border-radius: 0;
    border: 0;
}
.sl-window-pocket .sl-story-title, .sl-window-pocket .sl-story-title-ro { font-size: 1.1rem; }

.sl-panel {
    --sl-ink: #1f2933;
    --sl-soft: #5b6670;
    --sl-line: rgba(31, 41, 51, 0.12);
    --sl-card: #ffffff;
    --sl-wash: #f6f3ee;
    --sl-accent: #831843;          /* the Fergi AI wine — this panel is Fergi's child */
    --sl-drafting: #b45309;
    --sl-committed: #1d4ed8;
    --sl-ready: #047857;
    --sl-held: #475569;
    --sl-published: #6d28d9;
    color: var(--sl-ink);
    background: var(--sl-wash);
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 14px 16px 16px;
    min-height: 100%;
    box-sizing: border-box;
}

.sl-top { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; }
.sl-story-title, .sl-story-title-ro {
    flex: 1 1 260px;
    margin: 0;
    font-size: 1.35rem;
    font-weight: 700;
    line-height: 1.25;
    color: var(--sl-ink);
}
.sl-story-title {
    /* A wrapping one-line field (a textarea that grows to its lines; story-loop-panel.js _growTitle), so a long
       title wraps instead of being cut (S4, D-8). */
    display: block;
    box-sizing: border-box;
    resize: none;
    overflow: hidden;
    overflow-wrap: anywhere;
    font-size: 1.35rem;
    font-weight: 700;
    line-height: 1.25;
    color: var(--sl-ink);
    min-height: 44px;
    border: 1px solid transparent;
    border-radius: 8px;
    background: transparent;
    padding: 4px 8px;
    font-family: inherit;
}
.sl-story-title:hover, .sl-story-title:focus { border-color: var(--sl-line); background: var(--sl-card); outline: none; }

.sl-state {
    flex: 1 1 100%;
    margin: 0;
    padding: 6px 10px;
    border-left: 4px solid currentColor;
    border-radius: 4px;
    background: var(--sl-card);
    font-size: 0.92rem;
}
.sl-state-drafting  { color: var(--sl-drafting); }
.sl-state-committed { color: var(--sl-committed); }
.sl-state-producing { color: var(--sl-committed); }
.sl-state-ready     { color: var(--sl-ready); }
.sl-state-held      { color: var(--sl-held); }
.sl-state-published { color: var(--sl-published); }

.sl-matrix { display: flex; flex-direction: column; gap: 12px; }
.sl-empty, .sl-empty-cell { color: var(--sl-soft); font-size: 0.92rem; }
.sl-empty { padding: 18px; text-align: center; background: var(--sl-card); border-radius: 10px; border: 1px dashed var(--sl-line); }

.sl-chapter {
    background: var(--sl-card);
    border: 1px solid var(--sl-line);
    border-radius: 12px;
    padding: 10px 12px 12px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}
.sl-chapter-head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.sl-chapter-num {
    flex: 0 0 auto;
    font-size: 0.78rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--sl-accent);
}
.sl-chapter-title, .sl-chapter-title-ro {
    flex: 1 1 auto;
    min-width: 0;
    margin: 0;
    font-size: 1.05rem;
    font-weight: 600;
    color: var(--sl-ink);
}
.sl-chapter-title {
    min-height: 44px;
    border: 1px solid transparent;
    border-radius: 8px;
    background: transparent;
    padding: 4px 8px;
    font-family: inherit;
}
.sl-chapter-title:hover, .sl-chapter-title:focus { border-color: var(--sl-line); background: var(--sl-wash); outline: none; }
.sl-chapter-tools { display: flex; gap: 4px; flex: 0 0 auto; }

.sl-chapter-cells {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);   /* pictures | words — the matrix's two columns */
    gap: 12px;
}
.sl-cell-label {
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--sl-soft);
    margin-bottom: 6px;
}

.sl-thumbs { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 8px; margin-bottom: 8px; }
.sl-thumb { position: relative; margin: 0; }
.sl-thumb-open {
    display: block;
    width: 100%;
    aspect-ratio: 1 / 1;
    padding: 0;
    border: 0;
    border-radius: 8px;
    overflow: hidden;
    background: #e5e1da;
    cursor: pointer;
}
.sl-thumb-open img { width: 100%; height: 100%; object-fit: cover; display: block; }
.sl-thumb-missing { display: flex; align-items: center; justify-content: center; height: 100%; font-size: 1.6rem; }
.sl-thumb figcaption {
    font-size: 0.72rem;
    color: var(--sl-soft);
    margin-top: 3px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.sl-thumb-remove {
    position: absolute;
    top: -6px;
    right: -6px;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: 2px solid #fff;
    background: #991b1b;
    color: #fff;
    font-size: 1rem;
    line-height: 1;
    cursor: pointer;
}

.sl-words {
    width: 100%;
    box-sizing: border-box;
    min-height: 120px;
    resize: vertical;
    border: 1px solid var(--sl-line);
    border-radius: 8px;
    padding: 10px;
    font-family: inherit;
    font-size: 1rem;
    line-height: 1.45;
    color: var(--sl-ink);
    background: #fffdf9;
}
.sl-words:focus { outline: 2px solid var(--sl-accent); outline-offset: 1px; }
.sl-words-ro { font-size: 1rem; line-height: 1.45; white-space: normal; }
.sl-words-foot { display: flex; align-items: center; justify-content: flex-end; gap: 8px; margin-top: 6px; }
.sl-saved { color: var(--sl-ready); font-size: 0.85rem; }

.sl-btn, .sl-icon-btn, .sl-door {
    min-height: 44px;
    border-radius: 10px;
    border: 1px solid var(--sl-line);
    background: var(--sl-card);
    color: var(--sl-ink);
    font: inherit;
    font-weight: 600;
    padding: 0 14px;
    cursor: pointer;
}
.sl-icon-btn { min-width: 44px; padding: 0; font-size: 1.05rem; }
.sl-icon-btn:disabled { opacity: 0.35; cursor: default; }
.sl-btn:hover, .sl-icon-btn:hover:not(:disabled), .sl-door:hover { border-color: var(--sl-accent); }
.sl-btn-quiet { background: transparent; border-style: dashed; font-weight: 500; }
.sl-btn-primary { background: var(--sl-accent); border-color: var(--sl-accent); color: #fff; }
.sl-btn-primary:hover { filter: brightness(1.08); }
.sl-btn-talk { margin-left: auto; }
.sl-danger:hover:not(:disabled) { border-color: #991b1b; color: #991b1b; }

.sl-foot {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: space-between;
    position: sticky;
    bottom: 0;
    padding-top: 10px;
    background: linear-gradient(to bottom, rgba(246, 243, 238, 0), var(--sl-wash) 30%);
}

/* the Stories lists' door */
.sl-door {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    color: #fff;
    background: var(--sl-accent, #831843);
    border-color: transparent;
}
.sl-doors-msl { display: flex; gap: 8px; margin: 10px 12px 4px; }
.sl-door-msl { display: flex; justify-content: center; flex: 1 1 0; }
.sl-door-mine { background: #fff; color: var(--sl-accent, #831843); border: 1px solid var(--sl-accent, #831843); }
.sl-btn-publish { background: #6d28d9; border-color: #6d28d9; color: #fff; }     /* published = the panel's violet */
.sl-btn-publish:hover { filter: brightness(1.08); }

/* ── My Stories (refounding-story-studio S6): the owner's own stories, Pocket-first ──────────────────────── */
.ms-sheet {
    display: none;
    position: fixed; inset: 0;
    z-index: 10330;                                   /* under the Story Studio panel (10340) and Fergi AI (10350) */
    background: rgba(17, 24, 39, 0.45);
    align-items: center; justify-content: center;
}
.ms-sheet.is-open { display: flex; }
.ms-panel {
    --ms-accent: #831843; --ms-ink: #1f2933; --ms-soft: #5b6670; --ms-line: rgba(31, 41, 51, 0.12);
    width: min(680px, calc(100vw - 32px)); max-height: calc(100vh - 64px);
    display: flex; flex-direction: column;
    background: #f6f3ee; color: var(--ms-ink);
    border-radius: 14px; overflow: hidden;
    box-shadow: 0 18px 48px rgba(0, 0, 0, 0.28);
}
.ms-sheet.ms-pocket { align-items: stretch; background: transparent; }
.ms-pocket .ms-panel {
    position: fixed; left: 0; right: 0; width: auto; max-height: none;
    top: var(--mobile-top-bar-total-height, 60px);
    bottom: var(--mobile-control-panel-height, var(--mobile-tab-bar-total-height, 56px));
    border-radius: 0; box-shadow: none;
}
.ms-head { flex: 0 0 auto; display: flex; align-items: center; gap: 10px; padding: 8px 10px 8px 16px; background: var(--ms-accent); color: #fff; }
.ms-title { flex: 1 1 auto; margin: 0; font-size: 1.05rem; font-weight: 600; }
.ms-close { width: 44px; height: 44px; border: 0; border-radius: 10px; background: rgba(255, 255, 255, 0.12); color: #fff; font-size: 1.5rem; cursor: pointer; }
.ms-scroll { flex: 1 1 auto; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.ms-body { padding: 12px 14px 20px; }
.ms-intro, .ms-note { color: var(--ms-soft); font-size: 0.92rem; margin: 0 0 10px; }
.ms-stories { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 12px; }
.ms-story { background: #fff; border: 1px solid var(--ms-line); border-left: 5px solid #b45309; border-radius: 12px; padding: 12px; }
.ms-story[data-state="committed"], .ms-story[data-state="producing"] { border-left-color: #1d4ed8; }
.ms-story[data-state="ready"] { border-left-color: #047857; }
.ms-story[data-state="held"] { border-left-color: #475569; }
.ms-story[data-state="published"] { border-left-color: #6d28d9; }
.ms-story-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 10px; }
.ms-story-title { margin: 0; font-size: 1.05rem; flex: 1 1 12rem; }
.ms-state { font-size: 0.85rem; font-weight: 600; padding: 2px 10px; border-radius: 999px; background: #fef3c7; color: #92400e; }
.ms-state-committed, .ms-state-producing { background: #dbeafe; color: #1e3a8a; }
.ms-state-ready { background: #d1fae5; color: #065f46; }
.ms-state-held { background: #e2e8f0; color: #334155; }
.ms-state-published { background: #ede9fe; color: #5b21b6; }
.ms-meta { margin: 6px 0 0; color: var(--ms-soft); font-size: 0.88rem; }
.ms-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.ms-btn { min-height: 44px; padding: 0 14px; border-radius: 10px; border: 1px solid var(--ms-line); background: #fff; color: var(--ms-ink); font: inherit; font-weight: 600; cursor: pointer; }
.ms-btn:hover { border-color: var(--ms-accent); }
.ms-btn-primary { background: var(--ms-accent); border-color: var(--ms-accent); color: #fff; }
.ms-btn-publish { background: #6d28d9; border-color: #6d28d9; color: #fff; }
.ms-btn-quiet { background: transparent; border-style: dashed; font-weight: 500; }
.ms-make { margin-top: 14px; width: 100%; }
.ms-pocket .ms-actions .ms-btn { flex: 1 1 auto; }
.ms-comments { margin-top: 10px; border-top: 1px solid var(--ms-line); padding-top: 10px; }
.ms-comments-h { margin: 8px 0 4px; font-size: 0.95rem; }
.ms-list { list-style: none; margin: 0 0 8px; padding: 0; }
.ms-comment { padding: 6px 0; border-bottom: 1px dashed var(--ms-line); }
.ms-carry { display: flex; gap: 10px; align-items: flex-start; min-height: 44px; cursor: pointer; }
.ms-carry input { width: 22px; height: 22px; margin-top: 2px; flex: 0 0 auto; }
.ms-comment-at { color: var(--ms-soft); font-size: 0.85rem; }
.ms-empty { text-align: center; padding: 28px 18px; }

/* the conversation's "See your story" chip (the phone) */
.sl-chat-chip {
    display: block;
    margin: 6px 12px 10px auto;
    min-height: 44px;
    padding: 0 16px;
    border-radius: 22px;
    border: 1px solid #831843;
    background: #fdf2f8;
    color: #831843;
    font: inherit;
    font-weight: 600;
    cursor: pointer;
}

/* the Browse Media picker's one action */
.bm-story-pick-bar .bm-story-pick-btn { font-weight: 700; }
.bm-story-pick-bar .bm-story-pick-btn:disabled { opacity: 0.5; }

/* phone + narrow windows: the two cells stack inside each chapter */
@media (max-width: 640px) {
    .sl-chapter-cells { grid-template-columns: minmax(0, 1fr); }
    .sl-panel { padding: 12px; }
    .sl-story-title, .sl-story-title-ro { font-size: 1.2rem; }
}
.sl-pocket .sl-chapter-cells { grid-template-columns: minmax(0, 1fr); }
.sl-pocket .sl-thumbs { grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); }
.sl-pocket .sl-foot .sl-btn { flex: 1 1 auto; }

/* A narrow panel (the iPad's canvas, a small window): the two cells stack and the chapter header wraps, so a
   title is never cut to "The tre" beside the three chapter buttons (the S3 walk's iPad frame). */
@container (max-width: 560px) {
    .sl-chapter-cells { grid-template-columns: minmax(0, 1fr); }
    .sl-chapter-head { flex-wrap: wrap; }
    .sl-chapter-title, .sl-chapter-title-ro { flex-basis: 100%; order: 3; }
}

/* The comments on a story the Vault has made (refounding-story-studio S5): the owner's own, and the family's with a
   checkbox each to carry into the next version. Each family row is a 44 px target (the whole row is the label). */
.sl-comments { margin: 16px 0 4px; padding: 12px 14px; border-radius: 12px;
               background: rgba(42, 117, 117, 0.08); border: 1px solid rgba(42, 117, 117, 0.25); }
.sl-comments-h { margin: 8px 0 2px; font-size: 1rem; }
.sl-comments-note { margin: 0 0 6px; font-size: 0.9rem; opacity: 0.8; }
.sl-comment-list { list-style: none; margin: 0; padding: 0; }
.sl-comment { padding: 6px 0; line-height: 1.4; overflow-wrap: anywhere; }
.sl-comment-at { opacity: 0.7; font-size: 0.9em; }
.sl-carry { display: flex; align-items: flex-start; gap: 10px; min-height: 44px; cursor: pointer; }
.sl-carry input[type="checkbox"] { width: 22px; height: 22px; margin: 2px 0 0; flex: 0 0 auto; }
