@font-face {
    font-family: 'Manrope';
    font-style: normal;
    font-weight: 200;
    font-display: swap;
    src: url('../fonts/manrope-v20-latin-200.woff2') format('woff2');
}

@font-face {
    font-family: 'Manrope';
    font-style: normal;
    font-weight: 400;
    font-display: swap;
    src: url('../fonts/manrope-v20-latin-regular.woff2') format('woff2');
}

@font-face {
    font-family: 'Manrope';
    font-style: normal;
    font-weight: 600;
    font-display: swap;
    src: url('../fonts/manrope-v20-latin-600.woff2') format('woff2');
}

/* General Background */
body {
    background-color: #fdf8f1;
    margin: 0;
    padding: 0;
    font-family: 'Manrope', 'Segoe UI', sans-serif; /* Global font family */
}

/* Container for the entire form */
.personalize-form-container {
    background-color: #fdf8f1;
    padding: 16px;
    max-width: 100%;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    align-items: center;
    box-sizing: border-box;
}

.personalize-form-section .wr-journey-header {
    margin-bottom: 20px;
}

.generated-preview-img {
    max-width: var(--preview-max-width-desktop, 950px); /* fixed max width on desktop */
    width: 100%;      /* scale down on smaller screens */
    height: auto;     /* maintain aspect ratio */
    display: block;
    margin: 0 auto;   /* center the image */
}

/* Spread preview handling */
.spread-split {
    display: flex;
    width: 100%;
    max-width: var(--preview-max-width-desktop, 950px);
    margin: 0 auto;
}

.spread-panel {
    flex: 1 1 50%;
    position: relative;
    overflow: visible;
    border-radius: inherit;
}

.spread-panel-img-wrapper {
    position: relative;
    overflow: hidden;
    width: 100%;
    border-radius: inherit;
}

.spread-panel-left .spread-panel-img-wrapper {
    border-top-left-radius: inherit;
    border-bottom-left-radius: inherit;
}

.spread-panel-right .spread-panel-img-wrapper {
    border-top-right-radius: inherit;
    border-bottom-right-radius: inherit;
}

.spread-panel-img {
    display: block;
    width: 200%;
    max-width: none;
    height: auto;
}

.spread-panel-right .spread-panel-img {
    transform: translateX(-50%);
}

/* Overlay button sizing defaults */
:root {
    --preview-max-width-desktop: 950px;
    --cover-preview-max-width: 450px;
    --cover-overlay-button-width: 140px;
    --cover-overlay-button-height: 46px;
    --cover-overlay-button-width-mobile: 120px;
    --cover-overlay-button-height-mobile: 42px;
    --add-name-button-width: var(--cover-overlay-button-width);
    --add-name-button-height: var(--cover-overlay-button-height);
    --dedication-button-width: var(--cover-overlay-button-width);
    --dedication-button-height: var(--cover-overlay-button-height);
    --dedication-button-width: 180px;
    --add-name-button-width-mobile: var(--cover-overlay-button-width-mobile);
    --add-name-button-height-mobile: var(--cover-overlay-button-height-mobile);
    --dedication-button-width-mobile: var(--cover-overlay-button-width-mobile);
    --dedication-button-height-mobile: var(--cover-overlay-button-height-mobile);
    --dedication-button-width-mobile: 150px;
}

@media (max-width: 768px) {
    .spread-split {
        flex-direction: column;
        gap: 12px;
    }

    .spread-panel + .spread-panel {
        border-left: none;
    }

    .spread-panel-right .spread-panel-img {
        transform: translateX(-50%);
    }
}

/* Title Styles */
.step-title {
    font-weight: normal;
    font-size: 1.3rem;
    margin: 0;
    margin-bottom: 0.5rem;
    color: #23231e;
}

.subtitle {
    font-size: 2rem;
    text-align: center;
    color: #23231e;
    margin: 0;
    margin-bottom: 16px;
}

/* Labels */
.label {
    font-size: 1.2rem;
    color: #23231e;
    margin-bottom: 8px;
    font-weight: 700;
    display: block;
}

/* Input Field */
.input-field {
    width: 100%;
    max-width: 544px;  /* Control the max width here */
    padding: 1.2rem;
    border: 2px solid #bdbdbb;
    border-radius: 4px;
    margin-bottom: 16px;
    font-size: 1.4rem;
    box-sizing: border-box;
}

.field-help {
    width: 100%;
    max-width: 544px;
    margin: -8px auto 16px;
    color: #656560;
    font-size: 1rem;
    line-height: 1.45;
}

.child-age-field {
    width: 100%;
    max-width: 544px;
    margin: 0 auto 16px;
    padding: 0;
    border: 0;
}

.child-age-buttons {
    display: flex;
    gap: 8px;
}

.child-age-button {
    flex: 1;
    position: relative;
    cursor: pointer;
}

.child-age-button input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.child-age-button span {
    display: flex;
    min-height: 48px;
    align-items: center;
    justify-content: center;
    padding: 8px 10px;
    border: 2px solid #bdbdbb;
    border-radius: 4px;
    background: #fdf8f1;
    font-size: 1.2rem;
    box-sizing: border-box;
}

.child-age-button input:checked + span {
    border-color: #1e5751;
    background: #1e5751;
    color: #fff;
}

.child-age-button input:focus-visible + span {
    outline: 3px solid rgba(30, 87, 81, 0.3);
    outline-offset: 2px;
}

.child-age-select {
    margin-bottom: 0;
    background-color: #fff;
}

/* Gender Selection Container */
.gender-selection {
    display: flex;
    max-width: 544px;
    width: 100%;
    margin: 0 auto 16px;
    box-sizing: border-box;
    gap: 8px;
}

/* Gender Buttons */
.gender-btn {
    flex: 1;
    text-align: center;
    padding: 1.2rem;
    font-size: 1.4rem;
    background-color: #fdf8f1;
    border: 2px solid #bdbdbb;
    cursor: pointer;
    transition: all 0.2s ease;
}

.gender-btn.active {
    border-color: #1e5751;
    background-color: #1e5751;
    color: #fff;
}

.custom-character-form > .label,
.custom-character-form .autocomplete,
.custom-character-form .gender-selection,
.custom-character-form .photo-upload-field,
.custom-character-form .consent-checkbox,
.custom-character-form .form-inline-error {
    width: 100%;
    max-width: 544px;
    margin-left: auto;
    margin-right: auto;
    box-sizing: border-box;
}

/* Character Selection Grid */
.character-selection-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
    margin-bottom: 16px;
    max-width: 544px;
    width: 100%;
    box-sizing: border-box;
}

.character-option {
    display: flex;
    justify-content: center;
    align-items: center;
    border: 2px solid #bdbdbb;
    padding: 8px;
    transition: all 0.2s ease;
    cursor: pointer;
}

.character-option:hover {
    border-color: #1e5751;
}

.character-option.selected {
    outline: 3px solid #1e5751;
}

#personalization-form:not(.siblings-form):not(.custom-character-form) .character-option {
    position: relative;
    flex-direction: column;
}

#personalization-form:not(.siblings-form):not(.custom-character-form) .character-option:focus-visible {
    outline: 3px solid #1e5751;
    outline-offset: 3px;
}

.character-option__selected {
    display: flex;
    min-height: 22px;
    align-items: center;
    justify-content: center;
    gap: 5px;
    margin-top: 6px;
    color: #1e5751;
    font-size: 0.875rem;
    font-weight: 600;
    line-height: 1.2;
    visibility: hidden;
}

.character-option.selected .character-option__selected {
    visibility: visible;
}

.character-option__check {
    font-size: 1rem;
    line-height: 1;
}

.form-inline-error {
    width: 100%;
    max-width: 544px;
    color: #c0392b;
    font-size: 1rem;
    margin: 0 0 12px;
}

.age-selection-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
}

.age-option {
    min-height: 84px;
    padding: 10px;
    font-size: 2rem;
    font-family: inherit;
    line-height: 1.15;
    background-color: #fdf8f1;
    white-space: nowrap;
}

.age-option[hidden] {
    display: none !important;
}

.age-option--under-1 {
    font-size: 1.55rem;
}

@media (max-width: 768px) {
    .siblings-form,
    .siblings-step {
        width: 100%;
        max-width: 544px;
    }
}

.character-img {
    width: 148px;
    height: auto;
}

/* Continue Button */
.continue-btn {
    background-color: #23231E;
    color: white;
    padding: 12px 24px;
    border: none;
    font-size: 1.4rem;
    cursor: pointer;
    transition: background-color 0.2s ease;
    width: 100%;
    max-width: 544px;
    box-sizing: border-box;
    margin: 0 auto;
    position: relative;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    min-height: 52px;
}

.continue-btn:hover {
    background-color: #14473d;
}

.continue-btn:disabled,
.continue-btn.is-loading {
    cursor: not-allowed;
}

@media (max-width: 767px) {
    #personalization-form:not(.siblings-form):not(.custom-character-form) .character-img {
        width: 100%;
        max-width: 100%;
        height: auto;
    }
}

@media (min-width: 360px) and (max-width: 767px) {
    #personalization-form:not(.siblings-form):not(.custom-character-form) .character-selection-grid {
        width: calc(100% + 32px);
        grid-template-columns: repeat(3, minmax(0, 1fr));
        gap: 12px;
        margin-left: -16px;
        margin-right: -16px;
    }

    #personalization-form:not(.siblings-form):not(.custom-character-form) .character-option {
        min-width: 0;
        padding: 6px;
    }

}

.continue-btn__text {
    position: relative;
    z-index: 2;
    text-align: center;
    line-height: 1.3;
}

.continue-btn__text--loading {
    display: none;
}

.continue-btn.is-loading .continue-btn__text--default {
    display: none;
}

.continue-btn.is-loading .continue-btn__text--loading {
    display: block;
}

.continue-btn__progress {
    position: absolute;
    inset: 0;
    width: 0;
    background: linear-gradient(90deg, #1e5751 0%, #2e8c6a 100%);
    z-index: 1;
    opacity: 0.85;
}

.continue-btn.is-loading .continue-btn__progress {
    animation: continue-loading-fill 1.6s linear infinite;
}

@keyframes continue-loading-fill {
    0% {
        width: 0%;
    }
    100% {
        width: 100%;
    }
}

/* Back to Product Page Link */
.back-to-product-page {
    color: #7b7b78;
    margin-top: 16px;
    margin-bottom: 24px;
    font-size: 1.2rem;
    text-decoration: none;
    display: block;
    text-align: center;
}

.back-to-product-page:hover {
    text-decoration: none;
}

.back-to-product-page.is-hidden {
    display: none;
}

/* Header */
.personalize-header {
    width: 100%;
    background-color: #000;
    color: #fff;
    display: flex;
    justify-content: center;
    align-items: center;
    height: 3.5rem;
    position: relative;
    padding: 0 1rem;
    box-sizing: border-box;
}

.header-title {
    font-size: 1.2rem;
    margin: 0;
    padding: 0;
}

.header-close {
    position: absolute;
    right: 1rem;
    background: none;
    border: none;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 3rem;
    height: 3rem;
    top: 50%;
    transform: translateY(-50%);
    padding: 0;
}

.header-close svg {
    width: 1.8rem;
    height: 1.8rem;
}

/* Autocomplete */
.autocomplete {
    position: relative;
    display: inline-block;
    width: 100%;
}

.autocomplete-items {
    position: absolute;
    border: 1px solid #bdbdbb;
    border-bottom: none;
    border-top: none;
    z-index: 99;
    top: 100%;
    left: 0;
    right: 0;
    max-height: 200px;
    overflow-y: auto;
    background-color: #fff;
}

.autocomplete-items div {
    padding: 10px;
    cursor: pointer;
    border-bottom: 1px solid #bdbdbb;
}

.autocomplete-items div:hover {
    background-color: #f1f1f1;
}

.autocomplete-active {
    background-color: #1e5751 !important;
    color: #ffffff;
}

/* Validation Icon */
.validation-icon {
    position: absolute;
    right: 16px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 1.8rem;
    pointer-events: none;
}

.validation-icon.valid {
    color: green;
}

.validation-icon.invalid {
    color: red;
}

/* Footer */
footer {
    background-color: #fdf8f1;
    padding: 1rem 0;
    width: 100%;
    box-sizing: border-box;
}

/* Footer content container */
.footer-content {
    display: flex;
    align-items: center;
    justify-content: center; 
    gap: 1rem;
    max-width: 1000px;
    margin: 0 auto;
}

.footer-logo {
    width: 30px;
    height: 30px;
}

.footer-text {
    font-size: 12px;
    color: #555;
    margin: 0;
}

/* Responsive for bigger screens */
@media (min-width: 48rem) {
    .step-title {
        font-size: 1.5rem;
    }
    .subtitle {
        font-size: 2.2rem;
    }
    .gender-btn {
        font-size: 1.7rem;
    }
    .continue-btn {
        font-size: 1.7rem;
        width: 544px;
    }
    .character-selection-grid {
        grid-template-columns: repeat(3, 1fr);
    }
    .age-selection-grid {
        grid-template-columns: repeat(7, 1fr);
    }
    .header-title {
        font-size: 1.5rem;
    }
    .header-close {
        width: 5rem;
        height: 5rem;
    }
    .header-close svg {
        width: 2.5rem;
        height: 2.5rem;
    }
}

/* --------------------------------------------------------------------
   Sticky Footer - Book Personalization Progress Tracker
--------------------------------------------------------------------- */
.wr-hybrid-progress-summary {
    display: none;
}

.personalization-progress-footer {
    position: sticky;
    bottom: 0;
    left: 0;
    width: 100%;
    background-color: #ffffff;
    height: 107px;
    border-top: 1px solid #e5e5e5;
    padding: 12px 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.05);
    z-index: 100;
    box-sizing: border-box;
}

.progress-items {
    display: flex;
    gap: 16px;
    flex: 1;
}

.progress-steps {
    flex: 1;
    margin-right: 16px;
    min-width: 0;
}

.progress-action {
    flex-shrink: 0;
    display: flex;
    align-items: center;
}

.progress-item {
    display: flex;
    align-items: center;
    gap: 8px;
    height: 70px;
    border: 1px solid #e5e5e5;
    border-radius: 0;
    padding: 6px;
    flex: 1 1 0;
    min-width: 0;
}

@media (min-width: 1024px) {
    .personalization-progress-footer {
        padding: 12px 100px;
    }
}

.progress-icon {
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.progress-icon-svg {
    width: 24px;
    height: 24px;
}

.progress-icon-ring {
    stroke: currentColor;
    fill: currentColor;
    stroke-width: 2;
    color: #bdbdbb;
}

.progress-icon-check {
    fill: none;
    stroke: #ffffff;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.progress-content {
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
}

.progress-label {
    font-weight: bold;
    font-size: 14px;
    color: #23231e;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.progress-value {
    font-size: 14px;
    color: #7b7b78;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.progress-continue-btn {
    background-color: #23231E;
    color: white;
    padding: 12px 24px;
    border: none;
    font-size: 16px;
    cursor: pointer;
    transition: all 0.2s ease;
    border-radius: 0;
    min-width: 200px;
}

.progress-continue-btn:hover {
    background-color: #14473d;
}

/* Completed and pending states */
/* Clickable progress items */
.progress-item-clickable {
    cursor: pointer;
    transition: all 0.2s ease;
    border-radius: 0;
    padding: 4px 10px;
}

.progress-item-clickable:hover {
    background-color: rgba(30, 87, 81, 0.1);
}

.progress-item-clickable:focus {
    outline: 2px solid #1e5751;
    outline-offset: 2px;
}

/* Enhanced progress item states with borders */
.progress-item.completed {
    border: 1px solid #23231e;
}

.progress-item.pending {
    border: 1px solid #e5e5e5;
}

.progress-item.completed .progress-icon-ring {
    color: #1e5751;
}

.progress-item.completed .progress-icon-check,
.progress-icon-check[data-visible="true"] {
    opacity: 1;
}

.progress-item.pending .progress-icon-ring {
    color: #bdbdbb;
}

/* Responsive adjustments for the sticky footer */
@media (max-width: 768px) {
    .personalization-progress-footer {
        flex-direction: column;
        align-items: stretch;
        gap: 12px;
        height: auto;
        padding: 16px;
    }

    .progress-steps {
        width: 100%;
        overflow-x: auto;
        padding-bottom: 4px;
        -webkit-overflow-scrolling: touch;
    }

    .progress-items {
        flex-wrap: nowrap;
        gap: 12px;
        min-width: max-content;
    }

    .progress-item {
        flex: 0 0 220px;
        height: auto;
        min-width: 220px;
    }

    .progress-action,
    .progress-continue-btn {
        width: 100%;
        min-width: 0;
    }
}

@media (max-width: 600px), (orientation: landscape) and (max-height: 500px) {
    .progress-continue-btn {
        min-height: 52px;
    }

    body:not(.wr-mobile-hybrid-active) .personalization-progress-footer .progress-item {
        min-height: 56px;
        box-sizing: border-box;
        padding-top: 8px;
        padding-bottom: 8px;
    }

}

body.wr-single-cover .progress-item[data-modal-type="coverColor"],
body.wr-single-cover #edit-cover-button,
body.wr-single-cover #wr-hybrid-preview-edit[data-modal-type="coverColor"] {
    display: none;
}

body.wr-mobile-preview-personalization .progress-item-clickable.wr-mobile-restored-focus:focus:not(:focus-visible) {
    outline: none;
}

body.wr-mobile-preview-personalization .progress-item-clickable.wr-mobile-touch-focus:focus {
    outline: none;
}

body.wr-mobile-preview-personalization [data-preview-legacy-gallery] .endpapers-container {
    left: 50%;
    width: calc(100vw - 20px);
    max-width: calc(100vw - 20px);
    margin-right: 0;
    margin-left: 0;
    transform: translateX(-50%);
}

/* --------------------------------------------------------------------
   Modal System Styles
--------------------------------------------------------------------- */

/* Modal overlay */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.45);
    z-index: 1000;
    display: none;
}

.modal-overlay.active {
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Modal root container */
.modal-root {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: none;
    z-index: 1001;
}

.modal-root.active {
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-root.active[data-modal-type="dedication"]:not(.wr-mobile-modal-optimized) {
    align-items: flex-start;
    padding-top: clamp(20px, 6vh, 64px);
    box-sizing: border-box;
}

body[data-debug-mode="true"] .modal-overlay {
    z-index: 1300;
}

body[data-debug-mode="true"] .modal-root {
    z-index: 1301;
}

/* Modal panel - main content area */
.modal-panel {
    background-color: #ffffff;
    width: 90%;
    max-width: 600px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    border-radius: 0; /* Square corners as specified */
    box-shadow: none; /* No shadow as specified */
    overflow: hidden;
}

/* Modal top bar */
.modal-topbar {
    background-color: #f8f9fa;
    padding: 16px 20px;
    border-bottom: 1px solid #e5e5e5;
    display: flex;
    justify-content: space-between;
    align-items: center;
    min-height: 56px;
    box-sizing: border-box;
}

.modal-title {
    font-size: 1.2rem;
    font-weight: 600;
    color: #23231e;
    margin: 0;
}

.modal-cancel-btn {
    background: none;
    border: none;
    font-size: 1rem;
    color: #7b7b78;
    cursor: pointer;
    padding: 8px;
    min-width: 48px;
    min-height: 48px;
    border-radius: 4px;
    transition: all 0.2s ease;
}

.modal-cancel-btn:hover {
    background-color: rgba(0, 0, 0, 0.05);
    color: #23231e;
}

.modal-cancel-btn:focus {
    outline: 2px solid #1e5751;
    outline-offset: 2px;
}

body:not(.wr-mobile-hybrid-active) .modal-cancel-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    min-width: 104px;
    min-height: 48px;
    padding: 0 13px;
    border: 1.5px solid #52716d;
    border-radius: 9px;
    background-color: #f7fbfa;
    color: #163f3b;
    font-size: 1rem;
    font-weight: 600;
}

body:not(.wr-mobile-hybrid-active) .modal-cancel-btn:hover {
    border-color: #1e5751;
    background-color: #eef6f4;
    color: #163f3b;
}

.modal-cancel-icon {
    font-size: 1.45rem;
    line-height: 1;
    transform: translateY(-1px);
}

body.wr-mobile-hybrid-active .modal-cancel-icon {
    display: none;
}

/* Modal content area */
.modal-content {
    background-color: #fff7ef;
    padding: 24px;
    flex: 1;
    overflow-y: auto;
    box-sizing: border-box;
}

/* Modal footer */
.modal-footer {
    background-color: #f8f9fa;
    padding: 16px 20px;
    border-top: 1px solid #e5e5e5;
    display: flex;
    justify-content: flex-end;
    min-height: 56px;
    box-sizing: border-box;
}

.modal-continue-btn {
    background-color: #23231e;
    color: white;
    border: none;
    padding: 12px 24px;
    font-size: 1rem;
    cursor: pointer;
    border-radius: 4px;
    min-width: 120px;
    min-height: 48px;
    transition: all 0.2s ease;
}

.modal-continue-btn:hover {
    background-color: #14473d;
}

.modal-continue-btn:focus {
    outline: 2px solid #1e5751;
    outline-offset: 2px;
}

.modal-continue-btn:disabled {
    background-color: #bdbdbb;
    cursor: not-allowed;
}

/* Form elements within modals */
.modal-form-group {
    margin-bottom: 20px;
}

.modal-label {
    display: block;
    font-size: 1.1rem;
    font-weight: 600;
    color: #23231e;
    margin-bottom: 8px;
}

.modal-input {
    width: 100%;
    padding: 12px;
    border: 2px solid #bdbdbb;
    border-radius: 4px;
    font-size: 1rem;
    box-sizing: border-box;
    transition: border-color 0.2s ease;
}

.modal-input:focus {
    outline: none;
    border-color: #1e5751;
}

.modal-textarea {
    width: 100%;
    padding: 12px;
    border: 2px solid #bdbdbb;
    border-radius: 4px;
    font-size: 1rem;
    box-sizing: border-box;
    transition: border-color 0.2s ease;
    resize: none;
    min-height: 80px;
}

.modal-root[data-modal-type="dedication"] .modal-textarea {
    display: block;
    overflow-y: auto;
}

.dedication-reset-button {
    border: 0;
    padding: 4px 0;
    background: transparent;
    color: #1e5751;
    font: inherit;
    text-decoration: underline;
    cursor: pointer;
}

.modal-textarea:focus {
    outline: none;
    border-color: #1e5751;
}

/* Color selection grid */
.color-selection-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
    margin-top: 16px;
}

.color-option {
    aspect-ratio: 1;
    border: 2px solid #bdbdbb;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s ease;
    position: relative;
    min-height: 64px;
}

.color-option:hover {
    border-color: #1e5751;
}

.color-option.selected {
    border-color: #1e5751;
    outline: 3px solid #1e5751;
}

.color-option:focus {
    outline: 2px solid #1e5751;
    outline-offset: 2px;
}

/* Cover thumbnail grid */
.cover-thumbnail-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
    margin-top: 16px;
    max-width: 520px; /* Accommodate larger thumbnails */
    margin-left: auto;
    margin-right: auto;
}

.cover-thumbnail-option {
    border: 2px solid #bdbdbb;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s ease;
    position: relative;
    overflow: hidden;
    background-color: #f8f9fa;
    padding: 4px;
}

.cover-thumbnail-option:hover {
    border-color: #1e5751;
    box-shadow: 0 2px 8px rgba(30, 87, 81, 0.2);
}

.cover-thumbnail-option.selected {
    border-color: #1e5751;
    outline: 3px solid #1e5751;
    outline-offset: 1px;
}

.cover-thumbnail-option:focus {
    outline: 2px solid #1e5751;
    outline-offset: 2px;
}

.cover-thumbnail-image {
    width: 100%;
    height: auto;
    display: block;
    border-radius: 2px;
    aspect-ratio: 1/1; /* Square aspect ratio */
    object-fit: cover;
}

/* Price badge styling */
.cover-price-badge {
    position: absolute;
    top: 8px;
    right: 8px;
    background-color: #FFD54F;
    border: none;
    border-radius: 0; /* No rounded corners */
    z-index: 10;
    pointer-events: none; /* Don't interfere with thumbnail selection */
}

.price-badge-content {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 4px 8px;
    gap: 4px;
}

.price-badge-star {
    width: 14px;
    height: 14px;
    flex-shrink: 0;
    fill: #000000;
}

.price-badge-text {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    font-weight: bold;
    font-size: 14px;
    color: #000000;
    line-height: 1;
    white-space: nowrap;
}

.cover-thumbnail-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 120px;
}

.cover-thumbnail-error {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 120px;
}

/* Loading spinner for thumbnails */
.cover-thumbnail-spinner {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 2px solid #f3f3f3;
    border-top: 2px solid #1e5751;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-right: 10px;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Mobile optimizations */
@media (max-width: 768px) {
    .modal-panel {
        width: 95%;
        max-height: 95vh;
    }
    
    .modal-topbar,
    .modal-footer {
        position: sticky;
        z-index: 10;
    }
    
    .modal-topbar {
        top: 0;
    }
    
    .modal-footer {
        bottom: 0;
    }
    
    .modal-content {
        padding: 20px 16px;
    }
    
    .color-selection-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 480px) {
    .modal-panel {
        width: 100%;
        height: 100vh;
        max-height: 100vh;
        border-radius: 0;
    }
    
    .color-selection-grid {
        grid-template-columns: 1fr 1fr;
        gap: 8px;
    }
}

/* Phone Legacy/Double modal sizing. Added at runtime only after the shared
   modal manager confirms a phone screen and explicitly excludes Hybrid. */
.modal-root.wr-mobile-modal-optimized {
    top: var(--wr-modal-visible-top, 0px);
    left: var(--wr-modal-visible-left, 0px);
    width: var(--wr-modal-visible-width, 100%);
    height: var(--wr-modal-visible-height, 100dvh);
    align-items: stretch;
    justify-content: stretch;
}

.modal-root.wr-mobile-modal-optimized .modal-panel {
    width: 100%;
    height: 100%;
    max-width: none;
    max-height: none;
    min-height: 0;
}

.modal-root.wr-mobile-modal-optimized .modal-topbar,
.modal-root.wr-mobile-modal-optimized .modal-footer {
    position: relative;
    flex: 0 0 auto;
}

.modal-root.wr-mobile-modal-optimized .modal-content {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    scroll-padding-block: 12px;
}

.modal-root.wr-mobile-modal-optimized .cover-thumbnail-grid {
    align-content: start;
}

.modal-root.wr-mobile-modal-optimized[data-modal-type="coverColor"] .modal-title {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.modal-root.wr-mobile-modal-optimized[data-modal-type="coverColor"] .modal-topbar {
    justify-content: flex-end;
}

.modal-root.wr-mobile-modal-optimized:focus {
    outline: none;
}

.modal-root.wr-mobile-modal-optimized[data-modal-type="dedication"] .modal-textarea {
    min-height: 160px;
}

/* Safe area handling for devices with notches */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
    @media (max-width: 480px) {
        .modal-footer {
            padding-bottom: calc(16px + env(safe-area-inset-bottom));
        }
    }
}

/* Focus trap and accessibility improvements */
.modal-root[aria-hidden="true"] {
    display: none;
}

.modal-root[aria-hidden="false"] {
    display: flex;
}

/* Screen reader only text */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Mobile layout: center the logo below the text. */
@media (max-width: 47.99rem) {
    .footer-content {
        flex-direction: column;
    }
    .footer-logo {
        margin-top: 1rem;
    }

    .cover-edit-button {
        width: var(--cover-overlay-button-width-mobile);
        height: var(--cover-overlay-button-height-mobile);
        bottom: -8px;
        font-size: 0.95rem;
    }

    .endpapers-add-name-button {
        bottom: -22px;
        width: var(--add-name-button-width-mobile);
        height: var(--add-name-button-height-mobile);
    }

    .copyrights-dedication-button {
        bottom: -22px;
        width: var(--dedication-button-width-mobile);
        height: var(--dedication-button-height-mobile);
    }

    /* Disable the desktop spread overlays; mobile uses page-level gutter shading below. */
    .endpapers-container {
        box-shadow: none;
    }

    .endpapers-container::before,
    .endpapers-container::after {
        display: none;
    }

    .endpapers-container .spread-panel-left .spread-panel-img-wrapper::after,
    .endpapers-container .spread-panel-right .spread-panel-img-wrapper::after {
        content: "";
        position: absolute;
        inset: 0;
        pointer-events: none;
        z-index: 2;
    }

    .endpapers-container .spread-panel-left .spread-panel-img-wrapper::after {
        background: linear-gradient(
            270deg,
            rgba(0, 0, 0, var(--gutter-first-stop-opacity, 0.1)) 0%,
            rgba(255, 255, 255, 0.1) 20px,
            rgba(0, 0, 0, 0.04) 42px,
            rgba(0, 0, 0, 0) 146px
        );
    }

    .endpapers-container .spread-panel-right .spread-panel-img-wrapper::after {
        left: 0;
        right: auto;
        width: 146px;
        background: linear-gradient(
            90deg,
            rgba(0, 0, 0, var(--gutter-first-stop-opacity, 0.1)) 0%,
            rgba(255, 255, 255, 0.1) 20px,
            rgba(0, 0, 0, 0.04) 42px,
            rgba(0, 0, 0, 0) 146px
        );
    }
}

/* --------------------------------------------------------------------
   New Styles for the Dual-Gradient Effect (used by several image containers)
--------------------------------------------------------------------- */
.endpapers-container {
    position: relative;
    overflow: visible;
    border-radius: 5px;
    box-shadow: 0 4px 18px rgba(0, 0, 0, 0.2);
}

.endpapers-container .spread-split {
    border-radius: inherit;
}

.endpapers-container::after {
    content: '';
    position: absolute;
    top: 0;
    bottom: 0;
    left: 20%;
    width: 60%;
    transform: translateX(-50%);
    pointer-events: none;
    background: linear-gradient(270deg, 
                  rgba(0, 0, 0, var(--gutter-first-stop-opacity, 0.1)) 0%, 
                  rgba(255, 255, 255, 0.1) 20px, 
                  rgba(0, 0, 0, 0.04) 42px, 
                  rgba(0, 0, 0, 0) 146px);
    z-index: 2;
    border-radius: inherit;
}

.endpapers-container::before {
    content: none;
}

.endpapers-container .spread-panel-right .spread-panel-img-wrapper::after {
    content: "";
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    width: 146px;
    pointer-events: none;
    z-index: 2;
    background: linear-gradient(
        90deg,
        rgba(0, 0, 0, var(--gutter-first-stop-opacity, 0.1)) 0%,
        rgba(255, 255, 255, 0.1) 20px,
        rgba(0, 0, 0, 0.04) 42px,
        rgba(0, 0, 0, 0) 146px
    );
}

/* --------------------------------------------------------------------
   Existing Glitter Page Styles (for reference)
--------------------------------------------------------------------- */
.page {
    width: 50%;
    position: relative;
    box-shadow: 0 4px 18px rgba(0, 0, 0, 0.2);
    overflow: hidden;
    border-radius: 5px;
}

.page-left::after {
    content: '';
    position: absolute;
    inset: 0;
    pointer-events: none;
    background: linear-gradient(270deg, rgba(0,0,0,0.3) 0%, rgba(255,255,255,0.1) 20px, rgba(0,0,0,0.04) 42px, rgba(0,0,0,0) 146px);
}

.page-right::after {
    content: '';
    position: absolute;
    inset: 0;
    pointer-events: none;
    background: linear-gradient(90deg, rgba(0,0,0,0.1) 0%, rgba(255,255,255,0.3) 20px, rgba(0,0,0,0.04) 42px, rgba(0,0,0,0) 146px);
}

/* Book Cover Effect for Matisse Image (Cover) */
.cover-wrapper {
    text-align: center;
    width: 100%;
    margin-bottom: 80px;
}

.cover-container {
    position: relative;
    display: inline-block;
    transform: perspective(800px) rotateY(1.35deg);
    transform-origin: center left;
    width: 100%;
    max-width: var(--cover-preview-max-width, 450px);
}

.front-cover-stack {
    position: relative;
    display: block;
    width: 100%;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    background: #fff;
}

.front-cover-stack .front-cover-image {
    position: relative;
    z-index: 1;
    display: block;
    border-radius: 8px;
}

.front-cover-logo-overlay {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: contain;
    pointer-events: none;
    z-index: 3;
}

.cover-edit-button {
    position: absolute;
    left: 50%;
    bottom: -22px;
    transform: translateX(-50%);
    width: var(--cover-overlay-button-width);
    height: var(--cover-overlay-button-height);
    border: none;
    border-radius: 0;
    background-color: #1f1f1f;
    color: #ffffff;
    font-size: 1rem;
    font-weight: 400;
    font-family: 'Manrope', sans-serif;
    cursor: pointer;
    z-index: 4;
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.18);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.18s ease, box-shadow 0.18s ease, background-color 0.18s ease;
}

.cover-edit-button:hover,
.cover-edit-button:focus-visible {
    background-color: #343434;
    transform: translateX(-50%) translateY(-1px);
    box-shadow: 0 10px 24px rgba(0, 0, 0, 0.24);
    outline: none;
}

.cover-edit-button:focus-visible {
    box-shadow: 0 0 0 3px rgba(111, 66, 193, 0.35);
}

.endpapers-add-name-button,
.copyrights-dedication-button {
    bottom: -22px;
    transform: translate(-50%, 0);
    z-index: 5;
}

.endpapers-add-name-button {
    width: var(--add-name-button-width);
    height: var(--add-name-button-height);
}

.copyrights-dedication-button {
    width: var(--dedication-button-width);
    height: var(--dedication-button-height);
}

.wr-photo-overlay { z-index: 1500; }
.wr-photo-modal { max-width: 620px; width: min(94vw, 620px); max-height: min(92dvh, 800px); overflow: hidden; }
.wr-photo-header, .wr-photo-footer { padding: 10px 18px; background: #fff; }
.wr-photo-header { flex: none; border-bottom: 1px solid #ddd; }
.wr-photo-footer { flex: none; border-top: 1px solid #ddd; }
.wr-photo-body { min-height: 0; overflow-y: auto; padding: 14px 20px; text-align: center; }
.wr-photo-body h2 { margin: 0 0 6px; font-size: 1.6rem; }
.wr-photo-body p { margin: 8px 0; line-height: 1.35; }
.wr-photo-actions button, .wr-photo-choice { min-height: 48px; padding: 8px 18px; border: 1px solid #555; background: #fff; color: #222; font: inherit; cursor: pointer; }
.wr-photo-choice { width: 100%; min-height: 110px; border: 2px dashed #777; }
.wr-photo-footer button { width: 100%; min-height: 54px; background: #232320; border: 0; color: #fff; font: inherit; font-size: 1.1rem; cursor: pointer; }
.wr-photo-footer button:disabled { opacity: .55; }
.wr-photo-crop { width: max(160px, min(300px, calc(92dvh - 460px), calc(100vw - 48px))); max-width: 100%; aspect-ratio: 1; margin: 8px auto; overflow: hidden; position: relative; touch-action: none; background: #ddd; cursor: grab; }
.wr-photo-crop:active { cursor: grabbing; }
.wr-photo-crop img { position: absolute; left: 0; top: 0; max-width: none; pointer-events: none; user-select: none; }
.wr-photo-zoom { display: flex; align-items: center; justify-content: center; gap: 16px; margin: 8px auto 12px; }
.wr-photo-zoom button { width: 52px; height: 52px; border: 1px solid #555; background: #fff; color: #222; font: inherit; font-size: 1.7rem; line-height: 1; cursor: pointer; }
.wr-photo-zoom button:disabled { opacity: .4; cursor: default; }
.wr-photo-zoom span { min-width: 48px; }
.wr-photo-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.wr-photo-error { color: #a01a24; font-weight: 600; }
.wr-photo-confirmation { position: fixed; left: 50%; bottom: max(24px, env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 1600; padding: 12px 22px; background: #232320; color: #fff; font-size: 1rem; text-align: center; }
.wr-photo-confirmation[hidden] { display: none; }
@media (max-width: 600px) {
  .wr-photo-overlay { align-items: flex-start; }
  .wr-photo-modal { width: 100%; max-width: none; max-height: 100dvh; height: 100dvh; border-radius: 0; }
  .wr-photo-body { flex: 1; padding: 12px 16px; }
  .wr-photo-crop { width: max(160px, min(300px, calc(100dvh - 410px), calc(100vw - 32px))); }
  .wr-photo-header, .wr-photo-footer { flex: none; }
}

.cover-container.is-loading img,
.back-cover-container.is-loading img {
    opacity: 0.9;
}

.cover-loading-indicator {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.2);
    border-radius: inherit;
    z-index: 3;
    pointer-events: none;
}

.cover-loading-indicator[hidden] {
    display: none;
}

.cover-loading-spinner {
    width: 28px;
    height: 28px;
    border: 3px solid rgba(255, 255, 255, 0.55);
    border-top-color: #ffffff;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

.matisse-cover {
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    width: 100%;
    max-width: var(--cover-preview-max-width, 450px);
    height: auto;
    display: block;
    margin: 0 auto;
}

.cover-container::before {
    content: "";
    position: absolute;
    left: 10px;
    top: 0;
    bottom: 0;
    width: 6px;
    background: linear-gradient(to right, rgba(0, 0, 0, 0.3), transparent);
    border-radius: 8px 0 0 8px;
    z-index: 2;
}

.cover-container::after {
    content: none;
}

/* --------------------------------------------------------------------
   New Styles for Back Cover with Matisse Cover Effect (applied to the right)
--------------------------------------------------------------------- */
.back-cover-wrapper {
    text-align: center;
    width: 100%;
    margin-bottom: 20px;
}

.back-cover-container {
    position: relative;
    display: inline-block;
    transform: perspective(800px) rotateY(-1deg);
    width: 100%;
    max-width: var(--cover-preview-max-width, 450px);
}

.back-cover-container img {
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    width: 100%;
    height: auto;
}

.back-cover-container::after {
    content: "";
    position: absolute;
    right: 10px;
    top: 0;
    bottom: 0;
    width: 6px; /* Adjust as needed */
    background: linear-gradient(to left, rgba(0, 0, 0, 0.3), transparent);
    border-radius: 0 8px 8px 0;
}

.back-cover-container::before {
    content: none;
}

@media (max-width: 600px) {
    .cover-container,
    .back-cover-container {
        width: 100%;
        max-width: 100%;
    }
}

/* --------------------------------------------------------------------
   Print Protection Notice
--------------------------------------------------------------------- */
.preview-print-legal {
    display: none;
}

.preview-print-legal__inner {
    max-width: 640px;
    margin: 0 auto;
    text-align: left;
}

.preview-print-legal__headline {
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.preview-print-legal__body {
    font-size: 0.95rem;
    line-height: 1.6;
    margin-bottom: 0.75rem;
}

.photo-upload-field {
    position: relative;
    display: grid;
    gap: 8px;
    margin-bottom: 18px;
}

.custom-character-form .photo-upload-field input[type="file"] {
    position: absolute;
    inline-size: 1px;
    block-size: 1px;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    border: 0;
    opacity: 0;
    overflow: hidden;
    clip: rect(0 0 0 0);
    clip-path: inset(50%);
    pointer-events: none;
    white-space: nowrap;
}

.photo-upload-field__control {
    display: grid;
    grid-template-columns: 44px minmax(0, 1fr) auto;
    align-items: center;
    gap: 14px;
    min-height: 76px;
    padding: 14px 16px;
    border: 2px solid #bdbdbb;
    border-radius: 4px;
    background: #fdf8f1;
    color: #23231e;
    box-sizing: border-box;
    cursor: pointer;
}

.photo-upload-field__control:hover {
    border-color: #8f8f8b;
    background: #fffbf5;
}

.photo-upload-field__icon {
    width: 44px;
    height: 44px;
    border: 1px solid #d8d3ca;
    border-radius: 4px;
    display: grid;
    place-items: center;
    background: #fff;
    color: #55524c;
    font-size: 24px;
    line-height: 1;
}

.photo-upload-field__copy {
    min-width: 0;
    display: grid;
    gap: 3px;
}

.photo-upload-field__title {
    font-size: 1.08rem;
    font-weight: 700;
    line-height: 1.2;
}

.photo-upload-field__help {
    color: #77746e;
    font-size: 0.9rem;
    line-height: 1.3;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.photo-upload-field__action {
    color: #23231e;
    font-size: 0.95rem;
    font-weight: 700;
    text-decoration: underline;
    white-space: nowrap;
}

.photo-upload-field__meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    color: #7b7b78;
    font-size: 0.9rem;
}

.photo-upload-field__remove {
    border: 0;
    background: transparent;
    color: #851926;
    cursor: pointer;
    font: inherit;
    padding: 0;
    text-decoration: underline;
}

@media (max-width: 480px) {
    .photo-upload-field__control {
        grid-template-columns: 40px minmax(0, 1fr);
    }

    .photo-upload-field__action {
        grid-column: 2;
        justify-self: start;
    }
}

.consent-checkbox {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    color: #4c4a45;
    font-size: 0.95rem;
    line-height: 1.4;
    margin: 8px 0 18px;
}

.consent-checkbox input {
    flex: 0 0 auto;
    margin-top: 3px;
}

@media print {
    body {
        background: #ffffff;
        margin: 0;
    }

    .preview-print-legal {
        display: flex !important;
        align-items: center;
        justify-content: center;
        min-height: 100vh;
        padding: 48px;
    }

    .preview-print-legal__headline,
    .preview-print-legal__body {
        color: #1a1a1a !important;
    }

    .personalize-form-section,
    .personalization-progress-footer,
    .layout-container,
    .metrics-toggle-container,
    .debug-storage-button,
    #preview-timestamp-marker,
    .modal,
    .modal-backdrop {
        display: none !important;
    }
}
