/* =========================================================
   Suspense Book Creator
   ========================================================= */

#sbc-book-creator {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px 15px 60px;
}

#sbc-book-creator * {
    box-sizing: border-box;
}

.sbc-section-header {
    margin-bottom: 30px;
}

.sbc-section-header h2 {
    margin: 0 0 8px;
    font-size: 42px;
    line-height: 1.1;
    color: #073db8;
}

.sbc-section-header p {
    margin: 0;
    font-size: 17px;
}


/* Character grid */

.sbc-character-list {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 20px;
    margin: 25px 0 35px;
}

.sbc-character-result {
    display: flex;
    align-items: center;
    gap: 20px;
    padding: 18px;
    margin-bottom: 15px;
    border: 1px solid #ddd;
    border-radius: 14px;
    background: #fff;
}

.sbc-character-result img {
    width: 110px;
    height: 110px;
    object-fit: cover;
    border-radius: 12px;
}

.sbc-character-result h3 {
    margin: 0 0 4px;
}

.sbc-character-result p {
    margin: 0 0 8px;
}

.sbc-upload-success {
    color: #198754;
    font-weight: 600;
}


/* Individual character */

.sbc-character-card {
    position: relative;
    padding: 20px;
    border: 2px solid #e4e4e4;
    border-radius: 16px;
    background: #fff;
    transition:
        border-color .2s ease,
        box-shadow .2s ease,
        transform .2s ease;
}

.sbc-character-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(0, 0, 0, .07);
}

.sbc-character-card.is-enabled {
    border-color: #1748c7;
    box-shadow: 0 5px 20px rgba(23, 72, 199, .10);
}
/* =========================================================
   Story Setup
   ========================================================= */

#sbc-story-setup {
    max-width: 900px;
    margin: 0 auto;
}

.sbc-story-panel {
    margin-bottom: 25px;
    padding: 24px;
    border: 1px solid #e1e1e1;
    border-radius: 16px;
    background: #fff;
}

.sbc-story-panel h3 {
    margin: 0 0 8px;
    font-size: 22px;
}

.sbc-story-panel > p {
    margin-top: 0;
    color: #666;
}


/* Story choice */

.sbc-story-choice {
    display: flex;
    align-items: center;
    gap: 18px;
    padding: 18px;
    border: 2px solid #1748c7;
    border-radius: 14px;
    background: #f7f9ff;
}

.sbc-story-choice-icon {
    font-size: 40px;
}

.sbc-story-choice > div:nth-child(2) {
    flex: 1;
}

.sbc-story-choice strong {
    font-size: 18px;
}

.sbc-story-choice p {
    margin: 4px 0 0;
    color: #666;
}


/* Cast */

#sbc-story-cast {
    display: grid;
    grid-template-columns:
        repeat(2, minmax(0, 1fr));
    gap: 12px;
    margin-top: 20px;
}

.sbc-story-cast-item {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 12px;
    border: 1px solid #ddd;
    border-radius: 12px;
}

.sbc-story-cast-item img {
    width: 65px;
    height: 65px;
    object-fit: cover;
    border-radius: 10px;
}

.sbc-story-cast-item strong,
.sbc-story-cast-item span {
    display: block;
}

.sbc-story-cast-item span {
    margin-top: 3px;
    font-size: 13px;
    color: #666;
}

.sbc-ai-character-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 65px;
    height: 65px;
    border-radius: 10px;
    background: #f3f3f3;
    font-size: 36px;
}


/* Length */

.sbc-story-length-options {
    display: grid;
    grid-template-columns:
        repeat(3, minmax(0, 1fr));
    gap: 12px;
    margin-top: 15px;
}

.sbc-length-option {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 15px;
    border: 1px solid #ddd;
    border-radius: 12px;
    cursor: pointer;
}

.sbc-length-option strong,
.sbc-length-option small {
    display: block;
}

.sbc-length-option small {
    margin-top: 3px;
    color: #666;
}


/* Dedication */

#sbc-dedication {
    width: 100%;
    min-height: 110px;
    padding: 12px;
    border: 1px solid #ccc;
    border-radius: 10px;
    resize: vertical;
    font: inherit;
}


/* Mobile */

@media (max-width: 600px) {

    #sbc-story-cast {
        grid-template-columns: 1fr;
    }

    .sbc-story-length-options {
        grid-template-columns: 1fr;
    }

}

/* Card header */

.sbc-character-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 15px;
}

.sbc-character-title {
    display: flex;
    align-items: center;
    gap: 9px;
    font-size: 18px;
    font-weight: 700;
}

.sbc-character-icon {
    font-size: 25px;
}


/* Switch */

.sbc-character-switch {
    position: relative;
    width: 48px;
    height: 26px;
    flex: 0 0 auto;
}

.sbc-character-switch input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.sbc-switch-slider {
    position: absolute;
    inset: 0;
    border-radius: 30px;
    background: #ccc;
    cursor: pointer;
    transition: .2s ease;
}

.sbc-switch-slider::before {
    content: "";
    position: absolute;
    width: 20px;
    height: 20px;
    left: 3px;
    top: 3px;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 1px 4px rgba(0, 0, 0, .25);
    transition: .2s ease;
}

.sbc-character-switch input:checked + .sbc-switch-slider {
    background: #1748c7;
}

.sbc-character-switch input:checked + .sbc-switch-slider::before {
    transform: translateX(22px);
}

.sbc-character-switch input:disabled + .sbc-switch-slider {
    cursor: default;
}


/* Character details */

.sbc-character-details {
    padding-top: 20px;
}

.sbc-field {
    margin-bottom: 18px;
}

.sbc-field label {
    display: block;
    margin-bottom: 7px;
    font-weight: 600;
}

.sbc-character-name {
    width: 100%;
    height: 44px;
    padding: 9px 12px;
    border: 1px solid #ccc;
    border-radius: 8px;
    background: #fff;
    font-size: 16px;
}

.sbc-character-name:focus {
    outline: none;
    border-color: #1748c7;
    box-shadow: 0 0 0 3px rgba(23, 72, 199, .10);
}


/* Photo upload */

.sbc-photo-area {
    position: relative;
    width: 100%;
    min-height: 190px;
    overflow: hidden;
    border: 2px dashed #cfcfcf;
    border-radius: 12px;
    background: #fafafa;
    cursor: pointer;
}

.sbc-photo-placeholder {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 20px;
    text-align: center;
    pointer-events: none;
}

.sbc-upload-icon {
    font-size: 36px;
}

.sbc-character-preview {
    display: block;
    width: 100%;
    height: 230px;
    object-fit: contain;
    background: #f3f3f3;
}

.sbc-character-image {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    cursor: pointer;
}

.sbc-photo-help {
    margin: 7px 0 0;
    font-size: 13px;
    line-height: 1.4;
    color: #666;
}


/* Buttons */

.sbc-actions {
    margin-top: 30px;
    text-align: center;
}

.sbc-primary-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 240px;
    padding: 14px 28px;
    border: 0;
    border-radius: 30px;
    background: #1748c7;
    color: #fff;
    font-size: 17px;
    font-weight: 700;
    cursor: pointer;
    transition:
        transform .15s ease,
        opacity .15s ease;
}

.sbc-primary-button:hover {
    transform: translateY(-1px);
}

.sbc-primary-button:disabled {
    opacity: .45;
    cursor: not-allowed;
    transform: none;
}
.sbc-character-result {
    display: block;
}

.sbc-character-compare {
    display: flex;
    gap: 20px;
    margin-bottom: 18px;
}

.sbc-character-image-box {
    flex: 0 0 180px;
}

.sbc-image-label {
    display: block;
    margin-bottom: 7px;
    font-size: 13px;
    font-weight: 700;
    color: #666;
}

.sbc-character-image-box img {
    width: 180px;
    height: 180px;
    object-fit: contain;
    border-radius: 12px;
    background: #f5f5f5;
}

.sbc-generated-box img {
    border: 2px solid #1748c7;
}

.sbc-character-result-info {
    margin-top: 5px;
}

.sbc-character-controls {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 15px;
}

.sbc-generate-character,
.sbc-approve-character {
    padding: 10px 18px;
    border: 0;
    border-radius: 22px;
    cursor: pointer;
    font-weight: 700;
}

.sbc-generate-character {
    background: #1748c7;
    color: #fff;
}

.sbc-approve-character {
    background: #198754;
    color: #fff;
}

.sbc-character-result.is-approved {
    border: 2px solid #198754;
}

@media (max-width: 600px) {

    .sbc-character-compare {
        flex-wrap: wrap;
    }

    .sbc-character-image-box {
        flex: 1 1 140px;
    }

    .sbc-character-image-box img {
        width: 100%;
        height: auto;
        aspect-ratio: 1 / 1;
    }

}

/* Error */

.sbc-error {
    margin: 25px 0;
    padding: 14px 18px;
    border: 1px solid #e3a1a1;
    border-radius: 8px;
    background: #fff2f2;
    color: #a00000;
}


/* Loading */

.sbc-loading {
    position: fixed;
    z-index: 999999;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: rgba(255, 255, 255, .92);
}

.sbc-loading-content {
    max-width: 420px;
    text-align: center;
}

.sbc-spinner {
    width: 54px;
    height: 54px;
    margin: 0 auto 20px;
    border: 5px solid #ddd;
    border-top-color: #1748c7;
    border-radius: 50%;
    animation: sbc-spin .8s linear infinite;
}

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


/* =========================================================
   Story Review
   ========================================================= */

#sbc-story-review {
    max-width: 900px;
    margin: 0 auto;
}

.sbc-story-review-header {
    margin-bottom: 25px;
    text-align: center;
}

.sbc-story-review-header h2 {
    margin-bottom: 5px;
}

.sbc-story-review-header p {
    margin-top: 0;
    color: #666;
}


/* Page cards */

.sbc-story-page {
    margin-bottom: 18px;
    padding: 22px;
    border: 1px solid #ddd;
    border-radius: 16px;
    background: #fff;
}

.sbc-story-page-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 15px;
    margin-bottom: 16px;
}

.sbc-page-number {
    font-size: 17px;
    font-weight: 700;
}


/* Character badges */

.sbc-page-characters {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 6px;
}

.sbc-story-character-badge {
    padding: 5px 10px;
    border-radius: 20px;
    background: #eef2ff;
    color: #1748c7;
    font-size: 12px;
    font-weight: 700;
}


/* Narration */

.sbc-story-page-text {
    font-size: 16px;
    line-height: 1.65;
}

.sbc-page-text-display {
    margin: 0;
}

.sbc-page-text-edit {
    width: 100%;
    min-height: 130px;
    padding: 12px;
    border: 1px solid #aaa;
    border-radius: 10px;
    font: inherit;
    line-height: 1.5;
    resize: vertical;
}


/* Controls */

.sbc-page-controls {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 16px;
}

.sbc-page-controls button {
    padding: 8px 14px;
    border: 0;
    border-radius: 20px;
    cursor: pointer;
    font-weight: 600;
}

.sbc-edit-page {
    background: #f1f1f1;
}

.sbc-save-page {
    background: #198754;
    color: #fff;
}

.sbc-cancel-page-edit {
    background: #eee;
}


/* Illustration details */

.sbc-scene-details {
    margin-top: 18px;
    padding-top: 15px;
    border-top: 1px solid #eee;
}

.sbc-scene-details summary {
    cursor: pointer;
    color: #666;
    font-size: 13px;
    font-weight: 600;
}

.sbc-scene-details p {
    margin: 10px 0 0;
    padding: 12px;
    border-radius: 8px;
    background: #f7f7f7;
    color: #555;
    font-size: 13px;
    line-height: 1.5;
}


/* Bottom actions */

.sbc-story-review-actions {
    display: flex;
    justify-content: space-between;
    gap: 15px;
    margin-top: 30px;
    padding-bottom: 40px;
}


@media (max-width: 600px) {

    .sbc-story-page-heading {
        align-items: flex-start;
        flex-direction: column;
    }

    .sbc-page-characters {
        justify-content: flex-start;
    }

    .sbc-story-review-actions {
        flex-direction: column;
    }

}

/* Tablet */

@media (max-width: 900px) {

    .sbc-character-list {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

}


/* Mobile */

@media (max-width: 600px) {

    #sbc-book-creator {
        padding-left: 10px;
        padding-right: 10px;
    }

    .sbc-section-header h2 {
        font-size: 32px;
    }

    .sbc-character-list {
        grid-template-columns: 1fr;
    }

    .sbc-character-card {
        padding: 17px;
    }

    .sbc-photo-area {
        min-height: 170px;
    }

}
/* Native dialog traps focus and makes the page behind the cropper inert. */
.sbc-crop-modal {
    box-sizing: border-box; width: min(720px, 96vw); max-height: 94vh;
    max-height: 94dvh; padding: 20px; border: 0; border-radius: 16px;
    background: #fff; color: #222; overflow: auto;
}
.sbc-crop-modal::backdrop { background: rgba(0, 0, 0, .7); }
.sbc-crop-modal h2 { margin: 0 0 10px; font-size: 24px; }
.sbc-crop-stage { height: min(48vh, 420px); background: #eee; }
.sbc-crop-stage > img { display: block; max-width: 100%; max-height: 100%; }
.sbc-crop-stage .cropper-container { touch-action: none; }
.sbc-crop-status { min-height: 2.8em; margin: 12px 0; }
.sbc-crop-tools, .sbc-crop-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.sbc-crop-actions { justify-content: flex-end; margin-top: 16px; }
.sbc-crop-modal button { min-height: 44px; padding: 10px 16px; cursor: pointer; }
.sbc-crop-modal button:disabled { opacity: .5; cursor: not-allowed; }
.sbc-crop-modal button:focus-visible { outline: 3px solid #1748c7; outline-offset: 2px; }
.sbc-crop-modal [data-confirm] { background: #1748c7; color: #fff; border: 0; border-radius: 8px; }
@media (max-width: 600px) {
    .sbc-crop-modal { padding: 14px; }
    .sbc-crop-actions button { flex: 1; }
}

.sbc-cover-grid { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 24px; }
.sbc-cover-card { padding: 16px; border: 1px solid #ddd; border-radius: 12px; }
.sbc-cover-preview { position: relative; aspect-ratio: 1; background: #f4eedb; container-type: inline-size; }
.sbc-cover-preview.is-landscape { aspect-ratio: 2944 / 2160; }
.sbc-cover-preview img { width: 100%; height: 100%; object-fit: cover; }
.sbc-cover-copy { position: absolute; top: 9%; left: 12%; width: 76%; text-align: center; color: #253e31; font: 4.6cqw/1.5 Georgia,serif; white-space: pre-line; overflow-wrap: anywhere; }
.sbc-cover-copy.is-front { top: 6%; font-size: 7cqw; font-weight: bold; line-height: 1.15; }
.sbc-cover-preview.is-landscape .sbc-cover-copy { top: 7.2%; left: 7.3%; width: 85.4%; font-family: Arial,sans-serif; font-size: 2.35cqw; line-height: 1.22; }
.sbc-cover-preview.is-landscape .sbc-cover-copy.is-front { font-size: 4.42cqw; }
.sbc-cover-card textarea { display: block; width: 100%; margin: 8px 0; }
.sbc-cover-card button { margin: 6px; padding: 12px; }
@media(max-width:600px) { .sbc-cover-grid { grid-template-columns: 1fr; } }
