/* Branch Story Compose Widget Styles
    Aligned to reverie.house modal style language (share/login/create-dreamer). */

/* ── Overlay ──────────────────────────────────────────────── */
.branchstory-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.78);
    backdrop-filter: blur(8px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 10600;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.branchstory-overlay.visible {
    opacity: 1;
}

/* ── Box ──────────────────────────────────────────────────── */
.branchstory-box {
    background: #ffffff;
    border: 1.5px solid color-mix(in srgb, var(--reverie-core-color, #734ba1) 55%, white);
    max-width: 620px;
    width: 92%;
    max-height: min(90vh, 820px);
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    animation: branchstorySlideUp 0.3s ease-out;
    box-shadow:
        0 4px 6px rgba(0, 0, 0, 0.07),
        0 10px 20px rgba(0, 0, 0, 0.1),
        0 20px 40px rgba(115, 75, 161, 0.16);
}

@keyframes branchstorySlideUp {
    from { transform: translateY(-16px) scale(0.97); opacity: 0; }
    to   { transform: translateY(0) scale(1); opacity: 1; }
}

/* ── Header (user identity) ───────────────────────────────── */
.branchstory-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 18px 24px 16px;
    border-bottom: 1px solid color-mix(in srgb, var(--reverie-core-color, #734ba1) 24%, white);
    background:
        radial-gradient(100% 140% at 0% 0%, color-mix(in srgb, var(--reverie-core-color, #734ba1) 14%, white) 0%, transparent 70%),
        radial-gradient(120% 140% at 100% 0%, color-mix(in srgb, var(--reverie-core-color, #734ba1) 10%, white) 0%, transparent 72%),
        linear-gradient(180deg, #ffffff 0%, #faf9fc 100%);
    flex-shrink: 0;
}

.branchstory-header-text {
    flex: 1;
}

.branchstory-header-title {
    font-family: Arial, sans-serif;
    font-size: 1.08rem;
    font-weight: 700;
    color: #2d2d2d;
}

.branchstory-header-sub {
    font-family: 'Courier New', monospace;
    font-size: 12px;
    color: color-mix(in srgb, var(--reverie-core-color, #734ba1) 70%, #5a5a5a);
    margin-top: 2px;
}

.branchstory-close {
    width: 34px;
    height: 34px;
    background: #ffffff;
    border: 1.5px solid #d0c7f0;
    color: #5a4a7a;
    font-size: 24px;
    line-height: 1;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.branchstory-close:hover {
    border-color: var(--reverie-core-color, #734ba1);
    background: color-mix(in srgb, var(--reverie-core-color, #734ba1) 10%, white);
}

/* ── Parent Story Strip ───────────────────────────────────── */
.branchstory-parent {
    margin: 18px 24px 0;
    padding: 11px 14px;
    background: linear-gradient(135deg, #faf9fc 0%, #f5f3f9 100%);
    border: 1px solid #e8e4f0;
    border-left: 3px solid color-mix(in srgb, var(--reverie-core-color, #734ba1) 64%, white);
}

.branchstory-parent-label {
    font-family: 'Courier New', monospace;
    font-size: 10px;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: #7a6a98;
    margin-bottom: 5px;
}

.branchstory-parent-title {
    font-family: Arial, sans-serif;
    font-size: 13px;
    font-weight: 600;
    color: #2d2d2d;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.branchstory-parent-author {
    font-family: 'Courier New', monospace;
    font-size: 11px;
    color: #7b7b7b;
    margin-top: 3px;
}

/* ── Content ──────────────────────────────────────────────── */
.branchstory-content {
    padding: 18px 24px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* Title row */
.branchstory-title-row {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.branchstory-label {
    font-family: 'Courier New', monospace;
    font-size: 10px;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: #6f6f6f;
}

.branchstory-title-input {
    width: 100%;
    padding: 10px 14px;
    background: #fafafa;
    border: 2px solid #e5e5e5;
    color: #222;
    font-family: Arial, sans-serif;
    font-size: 15px;
    font-weight: 600;
    outline: none;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
    box-sizing: border-box;
}

.branchstory-title-input::placeholder {
    color: #9b9b9b;
    font-weight: 400;
}

.branchstory-title-input:focus {
    border-color: var(--reverie-core-color, #734ba1);
    background: #ffffff;
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--reverie-core-color, #734ba1) 16%, white);
}

/* Rich editor */
.branchstory-editor-row {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.branchstory-editor {
    width: 100%;
    min-height: 190px;
    max-height: 300px;
    overflow-y: auto;
    padding: 14px 16px;
    background: #ffffff;
    border: 1.5px solid #d8d2e8;
    color: #202020;
    font-family: Arial, sans-serif;
    font-size: 15px;
    line-height: 1.6;
    outline: none;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
    box-sizing: border-box;
    white-space: pre-wrap;
    word-wrap: break-word;
    text-align: left;
}

.branchstory-editor:focus {
    border-color: var(--reverie-core-color, #734ba1);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--reverie-core-color, #734ba1) 16%, white);
}

.branchstory-editor:empty::before {
    content: attr(data-placeholder);
    color: #989898;
    pointer-events: none;
}

.branchstory-editor strong,
.branchstory-editor b {
    font-weight: 700;
    color: color-mix(in srgb, var(--reverie-core-color, #734ba1) 75%, black);
}

.branchstory-editor em,
.branchstory-editor i {
    font-style: italic;
    color: #3c3c3c;
}

.branchstory-editor u {
    text-decoration: underline;
}

/* Formatting hint */
.branchstory-format-hint {
    font-family: 'Courier New', monospace;
    font-size: 10px;
    color: #888;
    letter-spacing: 0.04em;
}

/* ── Meta row (char count + posting note) ─────────────────── */
.branchstory-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    text-align: left;
}

.branchstory-charcount {
    font-family: 'Courier New', monospace;
    font-size: 12px;
    color: #6f6f6f;
}

.branchstory-charcount.warning {
    color: #f5a623;
}

.branchstory-charcount.over {
    color: #ff6b6b;
}

/* ── Error ────────────────────────────────────────────────── */
.branchstory-error {
    margin: 0 24px;
    padding: 11px 15px;
    background: #fff2f2;
    border: 1px solid #f5b5b5;
    color: #b42318;
    font-family: Arial, sans-serif;
    font-size: 13px;
    animation: branchstoryShake 0.4s ease;
    display: none;
}

.branchstory-error.visible {
    display: block;
}

@keyframes branchstoryShake {
    0%, 100% { transform: translateX(0); }
    10%, 30%, 50%, 70%, 90% { transform: translateX(-4px); }
    20%, 40%, 60%, 80% { transform: translateX(4px); }
}

/* ── Success ──────────────────────────────────────────────── */
.branchstory-success {
    margin: 0 24px;
    padding: 11px 15px;
    background: #ecfdf3;
    border: 1px solid #9ee5b9;
    color: #067647;
    font-family: Arial, sans-serif;
    font-size: 13px;
    display: none;
}

.branchstory-success.visible {
    display: block;
}

/* ── Actions footer ───────────────────────────────────────── */
.branchstory-actions {
    display: flex;
    gap: 12px;
    padding: 16px 24px 20px;
    border-top: 1px solid #efecf7;
    background: linear-gradient(180deg, #ffffff 0%, #faf9fc 100%);
    flex-shrink: 0;
}

.branchstory-btn {
    flex: 1;
    padding: 12px 20px;
    font-family: Arial, sans-serif;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    border: 1px solid;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.branchstory-btn.primary {
    background: var(--reverie-core-color, #734ba1);
    border-color: var(--reverie-core-color, #734ba1);
    color: white;
}

.branchstory-btn.primary:hover:not(:disabled) {
    background: #8a5cbd;
    border-color: #8a5cbd;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(115, 75, 161, 0.35);
}

.branchstory-btn.primary:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

.branchstory-btn.secondary {
    background: #ffffff;
    border-color: #d5cee6;
    color: #5f4b82;
}

.branchstory-btn.secondary:hover:not(:disabled) {
    border-color: var(--reverie-core-color, #734ba1);
    color: #4f3c72;
    background: color-mix(in srgb, var(--reverie-core-color, #734ba1) 8%, white);
}

/* ── Spinner ──────────────────────────────────────────────── */
.branchstory-spinner {
    animation: branchstorySpin 1s linear infinite;
}

@keyframes branchstorySpin {
    from { transform: rotate(0deg); }
    to   { transform: rotate(360deg); }
}

/* ── Mobile ───────────────────────────────────────────────── */
@media (max-width: 768px) {
    .branchstory-box {
        width: 96%;
        max-height: 95vh;
    }

    .branchstory-header,
    .branchstory-content,
    .branchstory-actions {
        padding-left: 16px;
        padding-right: 16px;
    }

    .branchstory-parent {
        margin-left: 16px;
        margin-right: 16px;
    }

    .branchstory-error,
    .branchstory-success {
        margin-left: 16px;
        margin-right: 16px;
    }

    .branchstory-editor {
        min-height: 140px;
        font-size: 16px; /* prevent iOS zoom */
    }

    .branchstory-title-input {
        font-size: 16px;
    }

    .branchstory-actions {
        flex-direction: column-reverse;
    }

    .branchstory-btn {
        width: 100%;
    }
}

@media (prefers-reduced-motion: reduce) {
    .branchstory-box {
        animation: none;
    }
}
