:root {
    --bg-body: #fdfcf8;
    --bg-sidebar: #f5f3e9;
    --bg-surface: #ffffff;
    --text-main: #1d2421;
    --text-muted: #5c6a66;
    --accent-primary: #042a21;
    --accent-hover: #0a4537;
    --border-color: #e6e2d6;
    --danger: #d9534f;
    --success-bg: #ebf2ed;
    --radius-md: 12px;
    --radius-lg: 20px;
    --shadow-sm: 0 4px 12px rgba(4, 42, 33, 0.04);
    --shadow-md: 0 8px 24px rgba(4, 42, 33, 0.08);
    font-family: "Manrope", sans-serif;
    color: var(--text-main);
    background-color: var(--bg-body);
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
}

body {
    margin: 0;
    display: flex;
    min-height: 100vh;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    background: var(--bg-body);
    color: var(--text-main);
}

h1,
h2,
h3,
.brand,
.btn {
    font-family: "Fraunces", serif;
}

h1,
h2,
h3,
p {
    margin: 0;
}

a {
    color: inherit;
    text-decoration: none;
}

img {
    display: block;
    max-width: 100%;
}

button,
input,
select,
textarea {
    font: inherit;
}

button {
    cursor: pointer;
}

.sidebar {
    width: 280px;
    background-color: var(--bg-sidebar);
    border-right: 1px solid var(--border-color);
    position: fixed;
    height: 100vh;
    display: flex;
    flex-direction: column;
    padding: 32px 24px;
    overflow-y: auto;
}

.brand {
    font-size: 1.5rem;
    font-weight: 500;
    color: var(--accent-primary);
    margin-bottom: 48px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.brand-dot {
    width: 12px;
    height: 12px;
    background-color: var(--accent-primary);
    border-radius: 50%;
}

.nav-menu {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex-grow: 1;
    margin: 0;
    padding: 0;
}

.nav-item a {
    display: block;
    padding: 12px 16px;
    color: var(--text-muted);
    font-weight: 500;
    border-radius: var(--radius-md);
    transition: all 0.2s;
}

.nav-item a:hover,
.nav-item a.active {
    background-color: var(--bg-surface);
    color: var(--accent-primary);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.02);
}

.sidebar-footer {
    margin-top: auto;
    display: grid;
    gap: 14px;
}

.sidebar-button {
    width: 100%;
    text-align: center;
}

.sidebar-inline-form {
    margin: 0;
}

.main-content {
    margin-left: 280px;
    flex-grow: 1;
    padding: 64px 80px;
    max-width: 1000px;
    width: 100%;
}

.main-content-narrow {
    max-width: 760px;
}

.main-content-creator {
    max-width: 1240px;
}

.flash-stack {
    display: grid;
    gap: 16px;
    margin-bottom: 28px;
}

.flash {
    padding: 16px 18px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    background: var(--bg-surface);
    box-shadow: var(--shadow-sm);
}

.flash-success {
    background: var(--success-bg);
    color: var(--accent-primary);
}

.flash-error {
    color: var(--danger);
}

.hero {
    margin-bottom: 56px;
}

.eyebrow {
    font-size: 0.8rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.1em;
    font-weight: 600;
    margin-bottom: 12px;
    display: inline-block;
}

.hero h1 {
    font-size: 3.5rem;
    font-weight: 400;
    color: var(--accent-primary);
    line-height: 1.1;
    margin-bottom: 16px;
}

.hero p {
    color: var(--text-muted);
    font-size: 1.2rem;
    font-family: "Fraunces", serif;
    font-style: italic;
}

.section-header {
    margin-bottom: 32px;
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    gap: 24px;
}

.section-header h2 {
    font-size: 2rem;
    font-weight: 400;
    color: var(--accent-primary);
}

.section-header-actions {
    display: flex;
    gap: 12px;
    align-items: center;
    flex-wrap: wrap;
}

.section-header-actions form {
    margin: 0;
}

.card {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 40px;
    margin-bottom: 56px;
    box-shadow: var(--shadow-sm);
}

.compact-card {
    padding: 32px;
}

.stack-lg,
.stack-md {
    display: grid;
}

.stack-lg {
    gap: 28px;
}

.stack-md {
    gap: 20px;
}

.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 32px;
}

.form-grid-single,
.story-form-grid {
    grid-template-columns: 1fr 1fr;
}

.field {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.field.full-width,
.full-width {
    grid-column: span 2;
}

.section-header-tight {
    margin-bottom: 16px;
}

label {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

input,
select,
textarea {
    width: 100%;
    padding: 14px 16px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    font-size: 1rem;
    background-color: var(--bg-body);
    color: var(--text-main);
    transition: all 0.2s;
    outline: none;
}

input:focus,
select:focus,
textarea:focus {
    border-color: var(--accent-primary);
    background-color: var(--bg-surface);
    box-shadow: 0 0 0 3px rgba(4, 42, 33, 0.05);
}

textarea {
    resize: vertical;
    min-height: 120px;
    font-family: "Fraunces", serif;
    font-size: 1.1rem;
    line-height: 1.6;
}

textarea[data-contributor-body] {
    min-height: 360px;
}

.input-shell[readonly] {
    background: var(--bg-body);
}

.input-shell[data-richtext-source] {
    display: block;
    min-height: 360px;
    padding: 26px 28px;
    border-radius: var(--radius-lg);
    background: linear-gradient(180deg, #fffdf8 0%, #fcfaf4 100%);
    font-family: "Fraunces", serif;
    font-size: 1.12rem;
    line-height: 1.9;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.7);
}

.input-shell[data-richtext-source][hidden],
[data-richtext-source][hidden] {
    display: none !important;
}

.richtext-shell[data-editor-scale="story"] .input-shell[data-richtext-source] {
    min-height: 340px;
}

.richtext-shell[data-editor-scale="contributor"] .input-shell[data-richtext-source] {
    min-height: 560px;
}

.richtext-toolbar {
    display: flex;
    gap: 10px;
    margin-bottom: 10px;
    flex-wrap: wrap;
}

.richtext-button {
    min-width: 42px;
    height: 42px;
    border-radius: 999px;
    border: 1px solid var(--accent-primary);
    background: transparent;
    color: var(--accent-primary);
    font-family: "Fraunces", serif;
    font-size: 1.1rem;
    font-weight: 700;
    padding: 0 14px;
}

.richtext-button:hover,
.richtext-button.is-active {
    background: var(--accent-primary);
    color: var(--bg-surface);
}

.richtext-button-italic {
    font-style: italic;
}

.richtext-button-wide {
    font-family: "Manrope", sans-serif;
    font-size: 0.88rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.richtext-shell {
    display: grid;
    gap: 12px;
}

.richtext-editor {
    min-height: 220px;
    padding: 28px 30px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    background: linear-gradient(180deg, #fffdf8 0%, #fcfaf4 100%);
    color: var(--text-main);
    font-family: "Fraunces", serif;
    font-size: 1.18rem;
    line-height: 1.9;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.7);
    overflow-y: auto;
}

.richtext-compose {
    cursor: text;
    outline: none;
    white-space: normal;
}

.richtext-compose:focus {
    border-color: var(--accent-primary);
    background: var(--bg-surface);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.7), 0 0 0 3px rgba(4, 42, 33, 0.05);
}

.richtext-preview-card {
    display: grid;
    gap: 10px;
}

.richtext-preview-label {
    margin: 0;
    color: var(--text-muted);
    font-size: 0.78rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.richtext-preview[data-empty="true"]::before {
    content: attr(data-placeholder);
    color: var(--text-muted);
    font-family: "Manrope", sans-serif;
    font-size: 1rem;
    line-height: 1.6;
    pointer-events: none;
}

.richtext-editor p,
.richtext-editor blockquote,
.richtext-editor h3 {
    margin: 0 0 1em;
}

.richtext-editor p:last-child,
.richtext-editor blockquote:last-child,
.richtext-editor h3:last-child {
    margin-bottom: 0;
}

.richtext-editor h3 {
    color: var(--accent-primary);
    font-family: "Fraunces", serif;
    font-size: 1.55rem;
    font-weight: 500;
    line-height: 1.3;
}

.richtext-editor blockquote {
    border-left: 3px solid rgba(4, 42, 33, 0.18);
    padding-left: 18px;
    color: var(--text-muted);
    font-style: italic;
}

.richtext-editor strong,
.richtext-editor b {
    font-weight: 800;
    color: var(--accent-primary);
}

.richtext-editor em,
.richtext-editor i {
    font-style: italic;
    color: #40524d;
}

.contributor-richtext-preview {
    min-height: 280px;
}

.btn {
    display: inline-flex;
    justify-content: center;
    align-items: center;
    padding: 14px 28px;
    font-size: 1.05rem;
    font-weight: 500;
    border-radius: 99px;
    cursor: pointer;
    transition: all 0.2s;
    border: none;
}

.btn-primary {
    background-color: var(--accent-primary);
    color: white;
}

.btn-primary:hover {
    background-color: var(--accent-hover);
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.btn-secondary {
    background-color: transparent;
    color: var(--accent-primary);
    border: 1px solid var(--accent-primary);
}

.btn-secondary:hover {
    background-color: var(--bg-sidebar);
}

.btn-danger {
    background-color: var(--danger);
    color: white;
}

.btn-danger:hover {
    filter: brightness(0.96);
}

.btn-text {
    font-family: "Manrope", sans-serif;
    background: transparent;
    color: var(--text-muted);
    padding: 0;
    font-size: 0.9rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    border: none;
}

.btn-text:hover {
    color: var(--accent-primary);
}

.danger-text:hover {
    color: var(--danger);
}

.actions {
    margin-top: 32px;
    display: flex;
    gap: 16px;
    align-items: center;
    flex-wrap: wrap;
}

.actions-secondary {
    margin-top: 18px;
}

.contributor-workspace {
    display: grid;
    grid-template-columns: minmax(220px, 0.34fr) minmax(0, 1fr);
    gap: 24px;
    align-items: start;
}

.contributor-index {
    position: sticky;
    top: 32px;
    display: grid;
    gap: 16px;
}

.contributor-index-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
}

.contributor-index-head h3 {
    font-size: 1.15rem;
    color: var(--accent-primary);
}

.contributor-index-head span {
    color: var(--text-muted);
    font-size: 0.85rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.contributor-index-list,
.story-list {
    display: grid;
    gap: 14px;
}

.contributor-chip {
    width: 100%;
    display: grid;
    gap: 4px;
    padding: 16px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background: var(--bg-surface);
    color: var(--text-main);
    text-align: left;
    box-shadow: var(--shadow-sm);
    transition: border-color 0.2s, box-shadow 0.2s, transform 0.2s;
}

.contributor-chip:hover,
.contributor-chip.is-active {
    border-color: var(--accent-primary);
    box-shadow: var(--shadow-md);
    transform: translateY(-1px);
}

.contributor-chip strong {
    color: var(--accent-primary);
    font-size: 1rem;
}

.contributor-chip span {
    color: var(--text-muted);
    font-size: 0.84rem;
}

.contributor-workspace.is-filtered .story-item {
    display: none;
}

.contributor-workspace.is-filtered .story-item.is-current {
    display: block;
}

.story-item {
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 32px;
    margin-bottom: 24px;
    background-color: var(--bg-surface);
    transition: box-shadow 0.2s;
    box-shadow: var(--shadow-sm);
}

.story-list .story-item {
    margin-bottom: 0;
}

.story-item.is-current {
    border-color: rgba(4, 42, 33, 0.28);
}

.story-item:hover {
    box-shadow: var(--shadow-md);
}

.story-inline-gallery {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(92px, 1fr));
    gap: 12px;
    margin-top: 20px;
}

.story-inline-gallery-item {
    border-radius: 10px;
    overflow: hidden;
    border: 1px solid var(--border-color);
    aspect-ratio: 4 / 3;
}

.story-inline-gallery-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.story-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 18px;
    margin-bottom: 24px;
}

.story-header-actions {
    display: flex;
    align-items: center;
    gap: 14px;
    flex-wrap: wrap;
}

.story-header-actions form,
.photo-card-actions form {
    margin: 0;
}

.story-title h3 {
    font-size: 1.4rem;
    color: var(--accent-primary);
    margin-bottom: 4px;
}

.story-author-label {
    display: inline-block;
    margin-bottom: 8px;
    color: var(--text-muted);
    font-size: 0.78rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.1em;
}

.story-meta {
    font-size: 0.9rem;
    color: var(--text-muted);
}

.story-preview-text,
.lede,
.feature-row p,
.project-card p,
.project-summary p,
.preview-secondary,
.preview-meta,
.help-note,
.photo-caption span,
.field-error,
.photo-preview-meta span {
    color: var(--text-muted);
}

.story-preview-text {
    font-family: "Fraunces", serif;
    font-size: 1.1rem;
    line-height: 1.6;
}

.story-book-preview {
    padding: 24px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background: #fdfbf6;
}

.story-preview-subtitle {
    margin-bottom: 12px;
    color: var(--text-muted);
    font-family: "Fraunces", serif;
    font-size: 1rem;
    font-style: italic;
}

.story-editor-panel {
    display: none;
    margin-top: 28px;
    padding-top: 28px;
    border-top: 1px solid var(--border-color);
}

.story-item.is-open .story-editor-panel {
    display: block;
}

.visual-story-form {
    grid-template-columns: minmax(0, 1fr) minmax(250px, 300px);
    gap: 18px;
    align-items: start;
}

.visual-book-editor.field.full-width {
    grid-column: 1 / 2;
    min-width: 0;
}

.visual-photo-library.field.full-width {
    grid-column: 2 / 3;
    min-width: 0;
}

.visual-story-form .actions {
    grid-column: 1 / -1;
}

.visual-book-editor {
    padding: 14px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    background: #f7f4ed;
    box-shadow: 0 18px 48px rgba(30, 28, 24, 0.08);
}

.visual-story-toolbar {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    align-items: center;
    flex-wrap: wrap;
    padding: 10px;
    margin-bottom: 12px;
    border: 1px solid rgba(28, 28, 24, 0.08);
    border-radius: var(--radius-md);
    background: rgba(255, 253, 249, 0.92);
}

.visual-story-toolbar .richtext-toolbar {
    margin-bottom: 0;
}

.visual-story-controls {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
}

.visual-story-controls label {
    color: var(--text-muted);
    font-size: 0.68rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.visual-story-controls select {
    width: auto;
    min-width: 132px;
    padding: 8px 10px;
    font-size: 0.82rem;
}

.visual-book-spread {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    overflow: hidden;
    background: #e5e0d6;
    box-shadow: 0 12px 30px rgba(30, 28, 24, 0.08);
    min-width: 0;
}

.visual-book-page {
    position: relative;
    min-width: 0;
    min-height: 650px;
    padding: 48px 44px 68px;
    background: #fffdf9;
}

.visual-book-page + .visual-book-page {
    border-left: 1px solid rgba(28, 28, 24, 0.08);
    box-shadow: inset 18px 0 24px rgba(45, 42, 36, 0.035);
}

.visual-page-kicker {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    color: #918a83;
    font-size: 0.66rem;
    font-weight: 700;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    margin-bottom: 28px;
}

.visual-page-author,
.visual-photo-page-head {
    color: #8f8880;
    font-size: 0.78rem;
    font-weight: 700;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    margin-bottom: 20px;
}

.visual-page-title {
    color: #2f2a28;
    font-family: "Fraunces", serif;
    font-size: clamp(2rem, 3vw, 3rem);
    line-height: 1.12;
    outline: none;
    margin-bottom: 18px;
    overflow-wrap: normal;
    word-break: normal;
    hyphens: none;
}

.visual-page-subtitle {
    color: #968f88;
    font-family: "Fraunces", serif;
    font-size: 1.18rem;
    font-style: italic;
    line-height: 1.5;
    min-height: 2.1em;
    outline: none;
    margin-bottom: 28px;
}

.visual-page-title:focus,
.visual-page-subtitle:focus,
.visual-page-body:focus {
    box-shadow: 0 0 0 3px rgba(4, 42, 33, 0.07);
    border-radius: 8px;
}

.visual-page-title[data-empty="true"]::before,
.visual-page-subtitle[data-empty="true"]::before {
    content: attr(data-placeholder);
    color: rgba(92, 106, 102, 0.56);
}

.visual-page-body.richtext-editor {
    min-height: 300px;
    height: 330px;
    max-height: 330px;
    padding: 0;
    border: 0;
    border-radius: 0;
    background: transparent;
    box-shadow: none;
    overflow: hidden;
    font-size: 1rem;
    line-height: 1.68;
}

.visual-page-body.richtext-editor::first-letter {
    color: #d4a81e;
    float: left;
    font-family: "Fraunces", serif;
    font-size: 2.8rem;
    line-height: 0.84;
    padding: 0.1em 0.12em 0 0;
}

.visual-photo-page-head {
    display: flex;
    justify-content: flex-start;
    align-items: flex-start;
    gap: 12px;
    flex-direction: column;
}

.visual-book-photo-page .story-layout-stage {
    height: 410px;
    min-height: 0;
    margin-top: 12px;
    padding: 18px 26px;
    align-content: center;
    align-items: stretch;
    background: transparent !important;
    grid-auto-rows: minmax(0, 1fr);
}

.visual-book-photo-page .story-layout-slot {
    height: 100%;
    min-height: 0;
    overflow: hidden;
    border-color: rgba(4, 42, 33, 0.16);
    background: #faf8f2;
}

.visual-book-photo-page .story-layout-stage[data-layout-count="1"] .story-layout-slot {
    max-width: 64%;
    width: 64%;
    justify-self: center;
}

.visual-book-photo-page .story-layout-stage[data-layout-count="2"] .story-layout-slot,
.visual-book-photo-page .story-layout-stage[data-layout-count="3"] .story-layout-slot:not(:first-child) {
    min-height: 0;
}

.visual-book-photo-page .story-layout-tile {
    display: grid;
    place-items: center;
    user-select: none;
    touch-action: none;
    border-radius: 0;
    background: #f7f4ed;
    box-shadow: 0 14px 30px rgba(46, 42, 35, 0.12);
}

.visual-book-photo-page .story-layout-tile.is-cropping {
    cursor: grabbing;
}

.visual-book-photo-page .story-layout-tile img {
    min-height: 100%;
    object-fit: cover;
    background: #f7f4ed;
}

/* Shared printed-book geometry used by both the full preview and story editor. */
.main-content-preview {
    max-width: none;
    width: 100%;
    min-height: 100vh;
    padding: 0;
    background-color: #f4efe6;
}

.preview-shell {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.book-preview-stage {
    --bg-color: #f4efe6;
    --paper-color: #fdfbf7;
    --text-main: #2c2825;
    --text-muted: #8c857d;
    --accent-color: #d4af37;
    --page-screen-width: 148mm;
    --page-screen-height: 210mm;
    --page-padding-top: 19mm;
    --page-padding-x: 18mm;
    --page-padding-bottom: 20mm;
    --page-footer-bottom: 42px;
    --content-footer-gap: 34px;
    --story-text-reserve: 74px;
    --story-font-size: 10pt;
    --story-line-height: 1.42;
    width: 100%;
    display: grid;
    justify-items: center;
    gap: 10px;
    color: var(--text-main);
    font-family: Georgia, serif;
}

.book-preview-stage .book-viewport {
    width: 100%;
    overflow-x: auto;
    overflow-y: hidden;
}

.book-preview-stage .book-track {
    display: flex;
    width: 100%;
    transition: transform 0.4s cubic-bezier(0.25, 1, 0.5, 1);
}

.book-preview-stage .book-frame {
    min-width: 100%;
    width: 100%;
    display: flex;
    justify-content: center;
    padding: 30px 20px 60px 20px;
}

.book-preview-stage .book-spread {
    display: flex;
    background: var(--paper-color);
    width: calc(var(--page-screen-width) * 2);
    min-width: calc(var(--page-screen-width) * 2);
    height: var(--page-screen-height);
    max-width: calc(var(--page-screen-width) * 2);
    border-radius: 0;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.15), 0 0 0 1px rgba(0, 0, 0, 0.05);
    position: relative;
    margin: 0 auto;
}

.book-preview-stage .book-spread::after {
    content: "";
    position: absolute;
    top: 0;
    bottom: 0;
    left: 50%;
    width: 50px;
    transform: translateX(-50%);
    background: linear-gradient(
        to right,
        rgba(0, 0, 0, 0) 0%,
        rgba(0, 0, 0, 0.03) 45%,
        rgba(0, 0, 0, 0.08) 50%,
        rgba(0, 0, 0, 0.03) 55%,
        rgba(0, 0, 0, 0) 100%
    );
    pointer-events: none;
}

.book-preview-stage .book-spread.is-single {
    width: var(--page-screen-width);
    min-width: var(--page-screen-width);
    height: var(--page-screen-height);
    max-width: var(--page-screen-width);
    border-radius: 0;
    box-shadow: inset 8px 0 15px rgba(0, 0, 0, 0.08), 0 20px 40px rgba(0, 0, 0, 0.15);
}

.book-preview-stage .book-spread.is-single::after {
    display: none;
}

.book-preview-stage .book-frame:last-child .book-spread.is-single {
    border-radius: 0;
    box-shadow: inset -8px 0 15px rgba(0, 0, 0, 0.08), 0 20px 40px rgba(0, 0, 0, 0.15);
}

.book-preview-stage .page {
    flex: 0 0 var(--page-screen-width);
    width: var(--page-screen-width);
    min-width: var(--page-screen-width);
    height: var(--page-screen-height);
    min-height: var(--page-screen-height);
    max-height: var(--page-screen-height);
    padding: var(--page-padding-top) var(--page-padding-x) var(--page-padding-bottom);
    display: flex;
    flex-direction: column;
    position: relative;
    overflow: hidden;
    box-sizing: border-box;
}

.book-preview-stage .book-spread.is-single .page {
    flex: 0 0 var(--page-screen-width);
    width: var(--page-screen-width);
}

.book-preview-stage .content {
    flex: 1;
    overflow: hidden;
    margin-bottom: var(--content-footer-gap);
    min-height: 0;
}

.book-preview-stage .story-text-content {
    flex: 0 1 auto;
    max-height: calc(100% - var(--story-text-reserve));
    padding-bottom: 16px;
    box-sizing: border-box;
}

.book-preview-stage .page-header {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    text-transform: uppercase;
    font-size: 8pt;
    letter-spacing: 1.5px;
    color: var(--text-muted);
    margin-bottom: 20px;
    font-family: Arial, sans-serif;
    flex-shrink: 0;
}

.book-preview-stage .page-footer {
    position: absolute;
    bottom: var(--page-footer-bottom);
    left: 0;
    width: 100%;
    text-align: center;
    font-size: 10pt;
    color: var(--text-muted);
}

.book-preview-stage .titolo {
    font-size: 20pt;
    font-weight: normal;
    color: var(--text-main);
    margin: 0 0 10px 0;
    line-height: 1.1;
    font-family: Georgia, serif;
}

.book-preview-stage .sottotitolo {
    font-size: 12pt;
    font-style: italic;
    color: var(--text-muted);
    margin: 0 0 30px 0;
    font-weight: normal;
    font-family: Georgia, serif;
}

.book-preview-stage .meta-note {
    margin: 0 0 18px 0;
    font-size: 8.2pt;
    letter-spacing: 1.1px;
    text-transform: uppercase;
    color: var(--text-muted);
    font-family: Arial, sans-serif;
}

.book-preview-stage .storia,
.book-preview-stage .cover-body,
.book-preview-stage .ending-body {
    font-size: var(--story-font-size);
    line-height: var(--story-line-height);
    text-align: justify;
    margin: 0;
    font-family: Georgia, serif;
    hyphens: auto;
}

.book-preview-stage .storia::first-letter {
    float: none;
    font-size: inherit;
    line-height: inherit;
    padding-right: 0;
    color: inherit;
    font-family: inherit;
}

.book-preview-stage .storia p,
.book-preview-stage .storia blockquote,
.book-preview-stage .storia h3 {
    margin: 0 0 0.72em;
}

.book-preview-stage .storia p:last-child,
.book-preview-stage .storia blockquote:last-child,
.book-preview-stage .storia h3:last-child {
    margin-bottom: 0;
}

.book-preview-stage .storia.no-dropcap::first-letter {
    float: none;
    font-size: inherit;
    line-height: inherit;
    padding-right: 0;
    color: inherit;
    font-family: inherit;
}

.book-preview-stage .preview-photo-stage {
    display: grid;
    width: 100%;
    height: calc(100% - 38px);
    min-height: 0;
    margin-top: 18px;
    padding: 0;
    gap: 16px;
    align-content: stretch;
    align-items: stretch;
    grid-auto-rows: minmax(0, 1fr);
}

.book-preview-stage .preview-photo-stage[data-layout-count="1"] {
    grid-template-columns: 1fr;
}

.book-preview-stage .preview-photo-stage[data-layout-count="2"],
.book-preview-stage .preview-photo-stage[data-layout-count="3"],
.book-preview-stage .preview-photo-stage[data-layout-count="4"] {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.book-preview-stage .preview-photo-stage[data-layout-count="3"] .story-layout-slot:first-child {
    grid-column: span 2;
}

.book-preview-stage .preview-photo-stage .story-layout-slot {
    display: grid;
    height: 100%;
    min-height: 0;
    overflow: hidden;
    place-items: center;
    border: 0;
    border-radius: 0;
    background: transparent;
}

.book-preview-stage .preview-photo-stage .story-layout-tile {
    display: grid;
    width: 100%;
    height: 100%;
    min-height: 0;
    margin: 0;
    place-items: center;
    border: 0;
    border-radius: 0;
    overflow: hidden;
    background: #f7f4ed;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.1);
}

.book-preview-stage .preview-photo-stage .story-layout-tile img {
    display: block;
    width: 100%;
    height: 100%;
    min-height: 100%;
    object-fit: cover;
    background: #f7f4ed;
}

.book-preview-stage .image-caption {
    font-size: 9pt;
    color: var(--text-muted);
    font-style: italic;
    margin-top: 10px;
    text-align: center;
}

.book-preview-stage .quote-content {
    display: flex;
    height: 100%;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
}

.book-preview-stage .quote-mark {
    margin: 0 0 18px;
    color: var(--accent-color);
    font-size: 42pt;
    line-height: 0.8;
}

.book-preview-stage .quote-body {
    max-width: 82%;
    margin: 0;
    color: var(--text-main);
    font-size: 15pt;
    font-style: italic;
    line-height: 1.55;
}

.book-preview-stage .quote-meta {
    margin-top: 22px;
    color: var(--text-muted);
    font-family: Arial, sans-serif;
    font-size: 8pt;
    letter-spacing: 1.2px;
    text-transform: uppercase;
}

.book-preview-stage .cover-content,
.book-preview-stage .ending-content {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
    height: 100%;
    padding-bottom: 20px;
}

.book-preview-stage .cover-title {
    font-size: 36pt;
    color: var(--accent-color);
}

.book-preview-stage .cover-photo {
    width: 74%;
    max-height: 44%;
    margin: 0 auto 24px;
    overflow: hidden;
    border-radius: 0;
    box-shadow: 0 10px 28px rgba(0, 0, 0, 0.14);
}

.book-preview-stage .cover-photo img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.book-preview-stage .ending-page {
    justify-content: center;
    text-align: center;
}

.controls {
    margin-top: 0;
    display: flex;
    gap: 15px;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
}

.preview-nav-btn {
    padding: 10px 20px;
    border: 1px solid #8c857d;
    background: transparent;
    color: #2c2825;
    border-radius: 20px;
    cursor: pointer;
    font-family: Georgia, serif;
    transition: 0.2s;
}

.preview-nav-btn:hover:not(:disabled) {
    background: #2c2825;
    color: #fdfbf7;
}

.preview-nav-btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.page-indicator {
    font-family: Arial, sans-serif;
    font-size: 9pt;
    color: #8c857d;
    text-transform: uppercase;
    letter-spacing: 1.2px;
}

.book-preview-stage .storia.richtext-compose:focus,
.book-preview-stage .titolo[contenteditable]:focus,
.book-preview-stage .sottotitolo[contenteditable]:focus {
    border-color: transparent;
    background: transparent;
    box-shadow: none;
    outline: none;
}

.book-preview-stage .titolo[data-empty="true"]::before,
.book-preview-stage .sottotitolo[data-empty="true"]::before,
.book-preview-stage .storia[data-empty="true"]::before {
    content: attr(data-placeholder);
    color: #8c857d;
}

.visual-photo-actions {
    display: flex;
    gap: 12px;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
    margin-top: 16px;
    padding-top: 14px;
    border-top: 1px solid rgba(28, 28, 24, 0.08);
}

.visual-photo-library-actions {
    justify-content: flex-start;
    margin-top: 0;
    margin-bottom: 18px;
    padding-top: 0;
    padding-bottom: 14px;
    border-top: 0;
    border-bottom: 1px solid rgba(28, 28, 24, 0.08);
}

.visual-page-number {
    position: absolute;
    left: 50%;
    bottom: 28px;
    transform: translateX(-50%);
    color: #918a83;
    font-family: "Fraunces", serif;
    font-size: 1.05rem;
}

.visual-photo-library {
    position: sticky;
    top: 24px;
    max-height: min(760px, calc(100vh - 48px));
    overflow-y: auto;
    padding: 14px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    background: #fbfaf5;
    box-shadow: var(--shadow-sm);
}

.legacy-editor-disabled {
    display: none;
}

.confirm-panel {
    display: none;
    margin-top: 20px;
    padding: 18px;
    border-radius: var(--radius-md);
    border: 1px solid rgba(217, 83, 79, 0.18);
    background: rgba(217, 83, 79, 0.05);
}

.confirm-panel.is-open {
    display: block;
}

.inventor-card {
    display: grid;
    gap: 28px;
}

.inventor-stepper {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.inventor-step {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    border: 1px solid var(--accent-primary);
    background: transparent;
    color: var(--accent-primary);
    font-weight: 800;
}

.inventor-step.is-active {
    background: var(--accent-primary);
    color: var(--bg-surface);
}

.inventor-form {
    display: grid;
    gap: 24px;
}

.inventor-panel {
    display: none;
}

.inventor-panel.is-active {
    display: block;
}

.inventor-suggest {
    align-self: flex-start;
    margin-top: 4px;
}

.inventor-prompt-row {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    margin-top: 10px;
}

.inventor-chip {
    border: 1px solid var(--border-color);
    border-radius: 999px;
    background: var(--bg-body);
    color: var(--accent-primary);
    padding: 8px 12px;
    font-size: 0.86rem;
    font-weight: 700;
}

.inventor-chip:hover {
    border-color: var(--accent-primary);
    background: var(--bg-sidebar);
}

.inventor-notes {
    display: grid;
    gap: 10px;
    margin-top: 22px;
    padding: 18px;
    border-radius: var(--radius-md);
    background: var(--bg-body);
    border: 1px solid var(--border-color);
}

.inventor-notes strong {
    color: var(--accent-primary);
}

.inventor-output {
    min-height: 360px;
    font-family: "Fraunces", serif;
    font-size: 1.12rem;
    line-height: 1.75;
}

.inventor-actions {
    display: flex;
    gap: 14px;
    align-items: center;
    flex-wrap: wrap;
}

.inventor-actions [hidden] {
    display: none !important;
}

.confirm-stack {
    display: grid;
    gap: 12px;
}

.confirm-stack input[type="checkbox"] {
    width: auto;
}

.status-pill {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 4px 12px;
    border-radius: 99px;
    background-color: var(--success-bg);
    color: var(--accent-primary);
    font-size: 0.8rem;
    font-weight: 600;
    font-family: "Manrope", sans-serif;
}

.photo-grid,
.project-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 24px;
    margin-top: 24px;
}

.project-grid {
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
}

.photo-card,
.project-card {
    border-radius: var(--radius-md);
    overflow: hidden;
    border: 1px solid var(--border-color);
    background: var(--bg-body);
}

.project-card {
    padding: 24px;
    background: var(--bg-surface);
    box-shadow: var(--shadow-sm);
    transition: box-shadow 0.2s, transform 0.2s;
}

.project-card:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
}

.project-card h3,
.invite-item h3,
.project-summary h3 {
    font-size: 1.35rem;
    color: var(--accent-primary);
    margin: 12px 0 6px;
}

.project-card-top,
.project-meta-line,
.summary-metrics,
.photo-card-actions,
.copy-shell,
.pricing-box,
.invite-actions {
    display: flex;
    gap: 12px;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
}

.invite-actions {
    align-items: flex-start;
}

.project-metric,
.summary-metrics span {
    font-size: 0.88rem;
    color: var(--text-muted);
}

.photo-card img {
    width: 100%;
    height: 160px;
    object-fit: cover;
}

.photo-caption {
    padding: 12px;
    font-size: 0.85rem;
    color: var(--text-muted);
    text-align: center;
    display: grid;
    gap: 4px;
}

.photo-card-actions {
    padding: 0 12px 14px;
    justify-content: space-between;
}

.photo-card-placeholder {
    min-height: 220px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-sidebar);
    border: 1px dashed var(--border-color);
}

.photo-card-placeholder span {
    color: var(--text-muted);
    font-weight: 500;
}

.field-error {
    display: block;
    margin-top: 4px;
    color: var(--danger);
}

.invite-stack {
    display: grid;
    gap: 20px;
    margin-top: 32px;
}

.invite-item {
    padding-top: 24px;
    border-top: 1px solid var(--border-color);
    display: grid;
    gap: 14px;
}

.copy-shell {
    align-items: stretch;
}

.copy-shell input {
    flex: 1 1 320px;
}

.generic-link-card {
    padding-bottom: 24px;
    margin-bottom: 24px;
    border-bottom: 1px solid var(--border-color);
}

.feature-list {
    display: grid;
    gap: 22px;
}

.feature-row {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 18px;
    align-items: start;
}

.feature-row h3 {
    font-size: 1.4rem;
    color: var(--accent-primary);
    margin-bottom: 4px;
}

.editorial-list {
    margin: 0;
    padding-left: 20px;
    color: var(--text-muted);
    display: grid;
    gap: 8px;
}

.pricing-value {
    font-family: "Fraunces", serif;
    font-size: 3rem;
    color: var(--accent-primary);
}

.mood-card .photo-swatch {
    height: 160px;
}

.mood-card-cream .photo-swatch {
    background: linear-gradient(180deg, #f7f2e7, #ede0cf);
}

.mood-card-coast .photo-swatch {
    background: linear-gradient(180deg, #edf5f4, #d9e6e2);
}

.mood-card-midnight .photo-swatch {
    background: linear-gradient(180deg, #21322d, #495e58);
}

.mood-card .photo-caption {
    text-align: left;
}

.mood-card .photo-caption strong {
    color: var(--accent-primary);
}

.empty-card {
    text-align: center;
    display: grid;
    gap: 8px;
}

.danger-card {
    border-color: rgba(217, 83, 79, 0.15);
}

.form-error {
    padding: 14px 16px;
    border: 1px solid rgba(217, 83, 79, 0.2);
    border-radius: var(--radius-md);
    background: rgba(217, 83, 79, 0.06);
    color: var(--danger);
}

.project-summary {
    display: grid;
    gap: 10px;
}

.upload-zone {
    border: 2px dashed var(--border-color);
    border-radius: var(--radius-md);
    padding: 40px 24px;
    text-align: center;
    background-color: var(--bg-body);
    transition: all 0.2s ease;
    cursor: pointer;
    margin-top: 8px;
}

.upload-zone:hover,
.upload-zone.is-dragover {
    border-color: var(--accent-primary);
    background-color: var(--bg-surface);
}

.upload-zone.is-full {
    opacity: 0.72;
}

.upload-zone-icon {
    font-size: 24px;
    display: block;
    margin-bottom: 8px;
}

.upload-zone-title {
    font-weight: 600;
    color: var(--accent-primary);
    margin-bottom: 4px;
}

.upload-zone-desc,
.upload-zone-meta {
    font-size: 0.85rem;
    color: var(--text-muted);
}

.upload-zone-meta {
    margin-top: 10px;
    font-weight: 600;
}

.photo-preview-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 16px;
    margin-top: 16px;
}

.photo-preview-card {
    border-radius: var(--radius-md);
    overflow: hidden;
    border: 1px solid var(--border-color);
    position: relative;
    background: var(--bg-surface);
    box-shadow: var(--shadow-sm);
    min-height: 210px;
}

.photo-preview-card img {
    width: 100%;
    height: 150px;
    object-fit: cover;
}

.photo-preview-meta {
    padding: 12px;
    display: grid;
    gap: 4px;
}

.photo-preview-meta strong {
    font-size: 0.92rem;
    color: var(--accent-primary);
    word-break: break-word;
}

.photo-remove-btn {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 28px;
    height: 28px;
    border: none;
    border-radius: 50%;
    background: rgba(4, 42, 33, 0.7);
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
}

.photo-remove-btn:hover {
    background: var(--danger);
}

.photo-add-card {
    min-height: 210px;
    border: 1px dashed var(--border-color);
    background: var(--bg-sidebar);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    font-weight: 600;
    transition: all 0.2s;
}

.photo-add-card:hover {
    border-color: var(--accent-primary);
    color: var(--accent-primary);
    background: var(--bg-surface);
}

.photo-add-card:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

.preview-cover,
.preview-cover-image {
    margin-top: 20px;
    border-radius: var(--radius-lg);
    overflow: hidden;
    border: 1px solid var(--border-color);
}

.preview-cover img,
.preview-cover-image img,
.story-gallery-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.book-preview {
    display: grid;
    gap: 24px;
}

.book-page {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}

.book-page-inner {
    padding: 40px;
    display: grid;
    gap: 18px;
}

.book-page.theme-midnight,
.theme-midnight .book-page {
    background: #f7f3ea;
}

.preview-prose {
    font-family: "Fraunces", serif;
    font-size: 1.1rem;
    line-height: 1.75;
}

.story-gallery {
    display: grid;
    gap: 16px;
}

.gallery-count-1 {
    grid-template-columns: 1fr;
}

.gallery-count-2,
.gallery-count-4 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

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

.story-gallery-item {
    border-radius: var(--radius-md);
    overflow: hidden;
    aspect-ratio: 4 / 3;
    border: 1px solid var(--border-color);
}

.author-cloud {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.author-cloud span {
    padding: 8px 14px;
    border-radius: 999px;
    background: var(--bg-sidebar);
    color: var(--accent-primary);
    font-size: 0.9rem;
    font-weight: 600;
}

.gallery-metrics {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    margin-top: 24px;
}

.gallery-metrics span,
.picker-count {
    padding: 8px 14px;
    border-radius: 999px;
    background: var(--bg-sidebar);
    color: var(--accent-primary);
    font-size: 0.88rem;
    font-weight: 600;
}

.asset-library-group {
    margin-top: 36px;
    padding-top: 24px;
    border-top: 1px solid var(--border-color);
}

.asset-library-head {
    margin-bottom: 20px;
}

.asset-library-head h3,
.asset-picker-header h4,
.story-layout-preview-head strong {
    font-size: 1.15rem;
    color: var(--accent-primary);
    margin: 0;
}

.photo-card.is-disabled {
    opacity: 0.58;
}

.picker-topline,
.story-layout-preview-head,
.flipbook-toolbar,
.preview-mode-switch,
.flipbook-actions {
    display: flex;
    gap: 14px;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
}

.asset-picker-group {
    margin-top: 24px;
}

.photo-composer {
    display: grid;
    grid-template-columns: minmax(220px, 0.42fr) minmax(0, 1fr);
    gap: 24px;
    align-items: start;
}

.photo-composer-library {
    display: grid;
    gap: 18px;
}

.photo-composer-library .asset-picker-group {
    margin-top: 0;
}

.asset-picker-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 16px;
    margin-top: 14px;
}

.photo-composer-library .asset-picker-grid {
    grid-template-columns: repeat(auto-fill, minmax(112px, 1fr));
    gap: 12px;
}

.asset-picker-card {
    position: relative;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    overflow: hidden;
    background: var(--bg-surface);
    box-shadow: var(--shadow-sm);
    padding: 0;
    text-align: left;
    cursor: grab;
}

.asset-picker-card img {
    width: 100%;
    height: 140px;
    object-fit: cover;
}

.photo-composer-library .asset-picker-card img {
    height: 106px;
}

.asset-picker-card:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.asset-picker-card:active {
    cursor: grabbing;
}

.asset-picker-card.is-selected {
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 2px rgba(4, 42, 33, 0.08);
}

.asset-picker-order {
    position: absolute;
    top: 10px;
    right: 10px;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: rgba(4, 42, 33, 0.76);
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.85rem;
}

.asset-picker-copy {
    display: grid;
    gap: 4px;
    padding: 12px;
}

.photo-composer-library .asset-picker-copy {
    padding: 10px;
}

.asset-picker-copy strong {
    color: var(--accent-primary);
    font-size: 0.92rem;
}

.asset-picker-copy small {
    color: var(--text-muted);
}

.story-layout-preview {
    margin-top: 28px;
    padding: 20px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    background: linear-gradient(180deg, #fcfbf7 0%, #f6f1e5 100%);
}

.photo-composer .story-layout-preview {
    margin-top: 0;
}

.photo-layout-controls {
    display: inline-flex;
    gap: 6px;
    padding: 4px;
    border: 1px solid var(--border-color);
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.7);
}

.layout-btn {
    min-width: 34px;
    height: 34px;
    border: 0;
    border-radius: 999px;
    background: transparent;
    color: var(--accent-primary);
    font-weight: 800;
}

.layout-btn:hover,
.layout-btn.is-active {
    background: var(--accent-primary);
    color: #fff;
}

.layout-btn:disabled {
    cursor: not-allowed;
    opacity: 0.4;
}

.story-layout-stage {
    display: grid;
    gap: 12px;
    margin-top: 18px;
    min-height: 360px;
}

.story-layout-stage[data-layout-count="1"] {
    grid-template-columns: 1fr;
}

.story-layout-stage[data-layout-count="2"] {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.story-layout-stage[data-layout-count="3"] {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.story-layout-stage[data-layout-count="3"] .story-layout-slot:first-child {
    grid-column: span 2;
}

.story-layout-stage[data-layout-count="4"] {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.story-layout-stage[data-height="hero"] .story-layout-slot:first-child {
    min-height: 320px;
}

.story-layout-stage[data-height="compact"] .story-layout-slot {
    min-height: 120px;
}

.story-layout-stage[data-height="balanced"] .story-layout-slot {
    min-height: 180px;
}

.story-layout-stage[data-position="above"],
.story-layout-stage[data-position="below"] {
    padding: 12px;
    border-radius: 0;
}

.story-layout-stage[data-position="above"] {
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.95), rgba(245, 243, 233, 0.92));
}

.story-layout-stage[data-position="below"] {
    background: linear-gradient(180deg, rgba(245, 243, 233, 0.92), rgba(255, 255, 255, 0.95));
}

.story-layout-slot {
    min-height: 180px;
    border: 1px dashed rgba(4, 42, 33, 0.22);
    border-radius: 0;
    display: grid;
    place-items: center;
    background: rgba(255, 255, 255, 0.58);
    transition: border-color 0.2s, background 0.2s, transform 0.2s;
}

.story-layout-slot.is-dragover {
    border-color: var(--accent-primary);
    background: rgba(235, 242, 237, 0.92);
    transform: scale(1.01);
}

.story-layout-slot.has-image {
    border-style: solid;
    background: transparent;
}

.story-layout-tile {
    position: relative;
    width: 100%;
    height: 100%;
    margin: 0;
    border-radius: 0;
    overflow: hidden;
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-sm);
    cursor: grab;
}

.story-layout-tile img {
    width: 100%;
    height: 100%;
    min-height: 100%;
    object-fit: cover;
}

.story-layout-tile:active {
    cursor: grabbing;
}

.story-layout-remove {
    position: absolute;
    top: 10px;
    right: 10px;
    width: 30px;
    height: 30px;
    border: 0;
    border-radius: 50%;
    background: rgba(4, 42, 33, 0.82);
    color: #fff;
    font-size: 1.15rem;
    line-height: 1;
}

.story-layout-slot .story-layout-empty {
    padding: 0;
    background: transparent;
    color: var(--text-muted);
    font-size: 0.92rem;
    font-weight: 700;
}

.story-layout-empty,
.empty-inline-state {
    padding: 18px;
    border-radius: var(--radius-md);
    background: var(--bg-sidebar);
    color: var(--text-muted);
}

body.story-editor-open {
    overflow: hidden;
}

.story-item.is-open .story-editor-panel {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: block;
    margin: 0;
    padding: 32px max(24px, calc((100vw - 1400px) / 2)) 60px;
    overflow-y: auto;
    border: 0;
    background: #f4f2eb;
}

.story-editor-shell-header {
    position: sticky;
    top: -32px;
    z-index: 20;
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    gap: 18px;
    width: min(1400px, 100%);
    margin: 0 auto 32px;
    padding: 18px 0 16px;
    background: rgba(244, 242, 235, 0.96);
    backdrop-filter: blur(10px);
}

.story-editor-shell-header h2 {
    margin-top: 4px;
    color: var(--accent-primary);
    font-family: "Fraunces", serif;
    font-size: clamp(1.8rem, 4vw, 3.4rem);
    line-height: 1.08;
}

.story-editor-shell-header p {
    max-width: 520px;
    margin-top: 8px;
    color: var(--text-muted);
    font-size: 1rem;
}

.story-editor-shell-actions {
    display: flex;
    gap: 12px;
    align-items: center;
    justify-content: flex-end;
    flex-wrap: wrap;
}

.story-editor-panel .visual-story-form {
    display: flex;
    flex-direction: column;
    gap: 32px;
    width: min(1400px, 100%);
    margin: 0 auto;
}

.story-editor-panel .visual-book-editor.field.full-width,
.story-editor-panel .visual-photo-library.field.full-width {
    grid-column: auto;
    width: 100%;
    min-width: 0;
}

.story-editor-panel .visual-form-footer {
    display: none;
}

.story-editor-panel .visual-book-editor {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    padding: 24px;
    overflow-x: auto;
    overflow-y: hidden;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    background: rgba(255, 255, 255, 0.4);
    box-shadow: inset 0 2px 10px rgba(0, 0, 0, 0.02);
}

.story-editor-panel .visual-story-toolbar {
    width: 100%;
    max-width: 960px;
    padding: 12px 16px;
    margin-bottom: 24px;
    border-radius: 16px;
    background: #fff;
    box-shadow: var(--shadow-sm);
}

.story-editor-panel .book-preview-stage {
    width: 100%;
    display: grid;
    justify-items: center;
    gap: 10px;
    color: var(--text-main);
    font-family: Georgia, serif;
}

.story-editor-panel .book-viewport {
    width: 100%;
    overflow-x: auto;
    overflow-y: hidden;
}

.story-editor-panel .book-track {
    display: flex;
    width: 100%;
    transition: none;
}

.story-editor-panel .book-frame {
    min-width: 100%;
    width: 100%;
    display: flex;
    justify-content: center;
    padding: 30px 20px 60px 20px;
}

.story-editor-panel .book-spread,
.story-editor-panel .visual-book-spread {
    display: flex;
    position: relative;
    width: calc(var(--page-screen-width) * 2);
    min-width: calc(var(--page-screen-width) * 2);
    height: var(--page-screen-height);
    max-width: calc(var(--page-screen-width) * 2);
    border: 0;
    border-radius: 0;
    overflow: hidden;
    background: var(--paper-color);
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.15), 0 0 0 1px rgba(0, 0, 0, 0.05);
    margin: 0 auto;
}

.story-editor-panel .book-spread::after {
    content: "";
    position: absolute;
    top: 0;
    bottom: 0;
    left: 50%;
    width: 50px;
    transform: translateX(-50%);
    background: linear-gradient(
        to right,
        rgba(0, 0, 0, 0) 0%,
        rgba(0, 0, 0, 0.03) 45%,
        rgba(0, 0, 0, 0.08) 50%,
        rgba(0, 0, 0, 0.03) 55%,
        rgba(0, 0, 0, 0) 100%
    );
    pointer-events: none;
}

.story-editor-panel .page,
.story-editor-panel .visual-book-page {
    flex: 0 0 var(--page-screen-width);
    width: var(--page-screen-width);
    height: var(--page-screen-height);
    min-width: var(--page-screen-width);
    min-height: var(--page-screen-height);
    max-height: var(--page-screen-height);
    padding: var(--page-padding-top) var(--page-padding-x) var(--page-padding-bottom);
    display: flex;
    flex-direction: column;
    box-sizing: border-box;
    overflow: hidden;
    background: var(--paper-color);
    box-shadow: none;
}

.story-editor-panel .content {
    flex: 1;
    overflow: hidden;
    margin-bottom: 34px;
    min-height: 0;
}

.story-editor-panel .story-text-content {
    flex: 0 1 auto;
    max-height: calc(100% - var(--story-text-reserve));
    padding-bottom: 16px;
}

.story-editor-panel .visual-book-page:nth-child(odd) {
    border-radius: 0;
    background: var(--paper-color);
}

.story-editor-panel .visual-book-page:nth-child(even) {
    border-left: 0;
    border-radius: 0;
    background: var(--paper-color);
}

.story-editor-panel .visual-book-page:nth-child(odd):last-child {
    border-radius: 0;
}

.story-editor-panel .visual-page-kicker {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    color: var(--text-muted);
    font-family: Arial, sans-serif;
    font-size: 8pt;
    font-weight: 400;
    letter-spacing: 1.5px;
    text-transform: uppercase;
    margin-bottom: 20px;
    flex-shrink: 0;
}

.story-editor-panel .visual-page-author,
.story-editor-panel .visual-photo-page-head {
    display: block;
    color: var(--text-muted);
    font-family: Arial, sans-serif;
    font-size: 9pt;
    letter-spacing: 1.1px;
    text-transform: uppercase;
    margin-bottom: 18px;
    font-weight: 400;
}

.story-editor-panel .visual-page-title {
    color: var(--text-main);
    font-family: Georgia, serif;
    font-size: 24pt;
    font-weight: normal;
    line-height: 1.1;
    margin: 0 0 10px 0;
}

.story-editor-panel .visual-page-subtitle {
    color: var(--text-muted);
    font-family: Georgia, serif;
    font-size: 14pt;
    font-weight: normal;
    line-height: 1.4;
    margin: 0 0 30px 0;
}

.story-editor-panel .visual-page-body.richtext-editor {
    min-height: 0;
    height: auto;
    max-height: none;
    padding: 0 0 16px;
    overflow: hidden !important;
    box-sizing: border-box;
    scrollbar-width: none;
    color: var(--text-main);
    font-family: Georgia, serif;
    font-size: var(--story-font-size);
    line-height: var(--story-line-height);
    text-align: justify;
}

.story-editor-panel .visual-page-body.richtext-editor::-webkit-scrollbar {
    display: none;
}

.story-editor-panel [data-generated-text-page] .visual-page-body.richtext-editor {
    min-height: 0;
    height: auto;
    max-height: none;
    padding: 0 0 16px;
}

.story-editor-panel .visual-page-body.richtext-editor::first-letter {
    font-size: 29pt;
    line-height: 0.8;
    color: var(--accent-color);
    font-family: "Times New Roman", Times, serif;
}

.story-editor-panel .visual-photo-page-head {
    flex-direction: initial;
    align-items: initial;
    justify-content: initial;
}

.story-editor-panel .visual-book-photo-page .story-layout-stage,
.story-editor-panel .preview-photo-stage {
    width: 100%;
    height: calc(100% - 38px);
    min-height: 0;
    margin-top: 18px;
    padding: 0;
    gap: 16px;
    align-content: stretch;
    align-items: stretch;
    grid-auto-rows: minmax(0, 1fr);
}

.story-editor-panel .page-footer {
    position: absolute;
    bottom: 42px;
    left: 0;
    width: 100%;
    text-align: center;
    font-size: 10pt;
    color: #8c857d;
}

.story-editor-panel .page-footer .visual-page-number {
    position: static;
    transform: none;
    color: inherit;
    font-family: Georgia, serif;
    font-size: inherit;
    font-weight: 400;
}

.story-editor-panel .story-layout-slot {
    height: 100%;
    min-height: 0;
    overflow: hidden;
    border: 0;
    border-radius: 0;
    background: transparent;
}

.story-editor-panel .story-layout-stage[data-height] .story-layout-slot,
.story-editor-panel .story-layout-stage[data-height="hero"] .story-layout-slot:first-child,
.story-editor-panel .story-layout-stage[data-height="compact"] .story-layout-slot,
.story-editor-panel .story-layout-stage[data-height="balanced"] .story-layout-slot {
    min-height: 0;
}

.story-editor-panel .story-layout-slot.has-image {
    border: 0;
    background: transparent;
}

.story-editor-panel .story-layout-tile {
    display: grid;
    place-items: center;
    height: 100%;
    min-height: 0;
    user-select: none;
    touch-action: none;
    border: 0;
    border-radius: 0;
    background: #f7f4ed;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.1);
}

.story-editor-panel .story-layout-tile.is-cropping {
    cursor: grabbing;
}

.story-editor-panel .story-layout-tile img {
    min-height: 100%;
    object-fit: cover;
    background: #f7f4ed;
}

.story-editor-panel .story-layout-remove {
    top: 12px;
    right: 12px;
    width: 32px;
    height: 32px;
    background: rgba(255, 255, 255, 0.9);
    color: var(--accent-primary);
    font-weight: 800;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

.story-editor-panel .story-layout-remove:hover {
    background: #fff;
    color: var(--danger);
    transform: scale(1.08);
}

.story-editor-panel .visual-page-number {
    bottom: 32px;
    color: #a39c92;
    font-family: "Manrope", sans-serif;
    font-size: 0.9rem;
    font-weight: 700;
}

.story-editor-panel .visual-photo-actions {
    gap: 16px;
    margin-top: 32px;
    padding-top: 24px;
    border-top: 1px solid rgba(0, 0, 0, 0.05);
}

.story-editor-panel .visual-photo-library-actions {
    margin-top: 0;
    padding-top: 0;
    border-top: 0;
}

.story-editor-panel .visual-photo-library {
    position: static;
    width: 100%;
    max-height: none;
    padding: 24px 32px;
    overflow: hidden;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    background: #fff;
    box-shadow: var(--shadow-sm);
}

.story-editor-panel .photo-composer-library {
    display: block;
}

.story-editor-panel .photo-composer-library .asset-picker-grid {
    display: flex;
    gap: 16px;
    margin-top: 14px;
    padding-bottom: 16px;
    overflow-x: auto;
    scrollbar-color: rgba(4, 42, 33, 0.2) transparent;
    scrollbar-width: thin;
}

.story-editor-panel .photo-composer-library .asset-picker-grid::-webkit-scrollbar {
    height: 8px;
}

.story-editor-panel .photo-composer-library .asset-picker-grid::-webkit-scrollbar-track {
    background: transparent;
}

.story-editor-panel .photo-composer-library .asset-picker-grid::-webkit-scrollbar-thumb {
    border-radius: 10px;
    background-color: rgba(4, 42, 33, 0.2);
}

.story-editor-panel .visual-photo-library .asset-picker-card {
    flex: 0 0 160px;
    border-radius: 10px;
    background: var(--bg-body);
    transition: transform 0.2s, box-shadow 0.2s;
}

.story-editor-panel .visual-photo-library .asset-picker-card:hover {
    transform: translateY(-3px);
}

.story-editor-panel .visual-photo-library .asset-picker-card img {
    height: 120px;
    border-bottom: 1px solid var(--border-color);
}

.story-editor-panel .visual-photo-library .asset-picker-copy {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 12px;
}

.story-editor-panel .visual-photo-library .asset-picker-copy strong {
    overflow: hidden;
    font-size: 0.85rem;
    font-weight: 700;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.story-editor-panel .visual-photo-library .asset-picker-copy small {
    font-size: 0.75rem;
}

.story-editor-panel > .actions-secondary,
.story-editor-panel > .confirm-panel {
    width: min(1400px, 100%);
    margin-right: auto;
    margin-left: auto;
}

.story-editor-panel > .actions-secondary {
    justify-content: flex-end;
}

.preview-mode-switch {
    margin-bottom: 24px;
}

.preview-mode-button {
    border: 1px solid var(--accent-primary);
    background: transparent;
    color: var(--accent-primary);
    border-radius: 999px;
    padding: 12px 20px;
    font-weight: 700;
}

.preview-mode-button.is-active {
    background: var(--accent-primary);
    color: #fff;
}

.preview-panel {
    display: none;
}

.preview-panel.is-active {
    display: block;
}

.flipbook-shell {
    display: grid;
    gap: 20px;
}

.flipbook-viewport {
    overflow: hidden;
}

.flipbook-track {
    display: flex;
    transition: transform 0.28s ease;
}

.flipbook-spread {
    min-width: 100%;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 24px;
}

.flipbook-page,
.flipbook-page-empty {
    min-width: 0;
}

.flipbook-page .book-page,
.flipbook-page-empty .book-page {
    height: 100%;
}

.photo-height-hero .story-gallery-item:first-child {
    aspect-ratio: 16 / 10;
}

.photo-height-compact .story-gallery-item {
    aspect-ratio: 1;
}

@media (max-width: 1080px) {
    .main-content {
        padding: 48px 40px;
    }
}

@media (max-width: 920px) {
    body {
        display: block;
    }

    .sidebar {
        position: static;
        width: 100%;
        height: auto;
        border-right: 0;
        border-bottom: 1px solid var(--border-color);
        padding: 24px 20px;
    }

    .nav-menu {
        flex-direction: row;
        flex-wrap: wrap;
        margin-bottom: 18px;
    }

    .sidebar-footer {
        margin-top: 8px;
    }

    .main-content {
        margin-left: 0;
        max-width: none;
        padding: 40px 20px 56px;
    }

    .contributor-workspace,
    .photo-composer,
    .visual-story-form {
        grid-template-columns: 1fr;
    }

    .visual-book-editor.field.full-width,
    .visual-photo-library.field.full-width {
        grid-column: 1 / -1;
    }

    .visual-photo-library {
        position: static;
        max-height: none;
    }

    .contributor-index {
        position: static;
    }

    .contributor-index-list {
        grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    }

    .visual-book-spread {
        grid-template-columns: 1fr;
    }

    .visual-book-page + .visual-book-page {
        border-left: 0;
        border-top: 1px solid rgba(28, 28, 24, 0.08);
        box-shadow: inset 0 18px 24px rgba(45, 42, 36, 0.035);
    }

    .book-preview-stage .visual-book-spread {
        display: flex;
    }

    .book-preview-stage .visual-book-page + .visual-book-page {
        border-top: 0;
        box-shadow: none;
    }
}

@media (max-width: 720px) {
    .hero h1 {
        font-size: 2.6rem;
    }

    .section-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .card,
    .story-item {
        padding: 24px;
    }

    .form-grid,
    .form-grid-single,
    .story-form-grid,
    .feature-row {
        grid-template-columns: 1fr;
    }

    .field.full-width,
    .full-width {
        grid-column: auto;
    }

    .story-header {
        flex-direction: column;
    }

    .visual-book-page {
        min-height: 640px;
        padding: 46px 28px 76px;
    }

    .visual-page-kicker,
    .visual-photo-page-head,
    .visual-story-toolbar,
    .visual-story-controls {
        flex-direction: column;
        align-items: flex-start;
    }

    .visual-book-photo-page .story-layout-stage {
        padding: 18px 0;
    }

    .book-preview-stage .visual-book-page {
        min-height: var(--page-screen-height);
        padding: var(--page-padding-top) var(--page-padding-x) var(--page-padding-bottom);
    }

    .book-preview-stage .visual-book-photo-page .story-layout-stage {
        padding: 0;
    }

    .copy-shell,
    .pricing-box,
    .project-card-top,
    .section-header-actions,
    .project-meta-line,
    .summary-metrics,
    .inventor-actions,
    .picker-topline,
    .story-layout-preview-head,
    .flipbook-toolbar {
        align-items: flex-start;
        flex-direction: column;
    }

    .gallery-count-2,
    .gallery-count-3,
    .gallery-count-4,
    .asset-picker-grid,
    .flipbook-spread,
    .photo-preview-grid,
    .photo-grid,
    .project-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 768px) {
    .main-content-preview {
        padding: 0;
    }

    .preview-shell {
        padding: 0;
    }

    .book-preview-stage .book-frame {
        padding: 20px 15px 40px 15px;
    }

    .book-preview-stage .book-spread {
        flex-direction: row;
        min-width: calc(var(--page-screen-width) * 2);
        background: var(--paper-color);
        gap: 0;
    }

    .book-preview-stage .book-spread.is-single {
        min-width: var(--page-screen-width);
    }

    .book-preview-stage .book-spread::after {
        display: none;
    }

    .book-preview-stage .page,
    .book-preview-stage .book-spread.is-single .page {
        width: var(--page-screen-width);
        min-width: var(--page-screen-width);
        min-height: var(--page-screen-height);
        background: var(--paper-color);
        box-shadow: none;
        border-radius: 0;
        padding: var(--page-padding-top) var(--page-padding-x) var(--page-padding-bottom);
    }
}

@media print {
    @page {
        size: A5;
        margin: 0;
    }

    html,
    body {
        width: 148mm;
        min-width: 148mm;
        margin: 0 !important;
        padding: 0 !important;
        background: #fff !important;
    }

    body {
        display: block;
        background: #fff;
    }

    .sidebar,
    .btn,
    .btn-text,
    .controls,
    .flash-stack {
        display: none !important;
    }

    .main-content {
        margin: 0;
        padding: 0;
        max-width: none;
    }

    .book-page {
        break-inside: avoid;
        box-shadow: none;
    }

    .main-content-preview {
        margin: 0;
        padding: 0;
        background: #fff;
    }

    .preview-shell,
    .book-preview-stage,
    .book-preview-stage .book-viewport,
    .book-preview-stage .book-track,
    .book-preview-stage .book-frame,
    .book-preview-stage .book-spread {
        display: block !important;
        width: auto !important;
        max-width: none !important;
        min-width: 0 !important;
        height: auto !important;
        min-height: 0 !important;
        aspect-ratio: auto !important;
        padding: 0 !important;
        margin: 0 !important;
        overflow: visible !important;
        transform: none !important;
        background: #fff !important;
        border-radius: 0 !important;
        box-shadow: none !important;
    }

    .book-preview-stage .book-spread::after {
        display: none !important;
    }

    .book-preview-stage .page,
    .book-preview-stage .book-spread.is-single .page {
        display: flex !important;
        width: 148mm !important;
        height: 210mm !important;
        padding: 18mm 17mm 20mm !important;
        overflow: hidden !important;
        break-after: page;
        page-break-after: always;
        background: var(--paper-color) !important;
        box-shadow: none !important;
    }

    .book-preview-stage .book-frame:last-child .page:last-child {
        break-after: auto;
        page-break-after: auto;
    }

    .book-preview-stage .page-header {
        font-size: 7.5pt;
    }

    .book-preview-stage .titolo {
        font-size: 20pt;
    }

    .book-preview-stage .storia,
    .book-preview-stage .cover-body,
    .book-preview-stage .ending-body {
        font-size: 10pt;
        line-height: 1.42;
    }

    .book-preview-stage .story-text-content {
        max-height: calc(100% - 74px);
        padding-bottom: 16px;
    }

    .book-preview-stage .preview-photo-stage {
        height: calc(100% - 34px);
    }
}
