:root {
    color-scheme: light;
    font: 16px/1.5 system-ui, sans-serif;
    color: #192437;
    background: #f6f7fb;
    --line: #dce2ed;
    --muted: #48566c;
    --blue: #224dd0;
}
* { box-sizing: border-box; }
body { margin: 0; }
a { color: inherit; }
button, .primary, .quiet { font: inherit; font-weight: 650; }
button, .primary {
    border: 1px solid var(--line); background: white; color: inherit; border-radius: .65rem;
    padding: .55rem .85rem; cursor: pointer; display: inline-block; text-decoration: none;
}
button:disabled { opacity: .5; cursor: default; }
.primary { background: var(--blue); border-color: var(--blue); color: white; }
.quiet, .back { color: var(--blue); }
:focus-visible { outline: 3px solid #536df3; outline-offset: 3px; }
.top {
    display: flex; align-items: center; justify-content: space-between; gap: .75rem;
    padding: 1rem clamp(1rem, 5vw, 4rem); background: white; border-bottom: 1px solid var(--line);
}
.top a { text-decoration: none; }
.brand { font-weight: 750; }
.brand span { color: var(--blue); margin-right: .25rem; }
.shell { max-width: 1440px; margin: auto; padding: clamp(1rem, 4vw, 3.5rem); }
.hero {
    display: grid; grid-template-columns: 1fr 1fr; gap: clamp(2rem, 5vw, 5rem); align-items: center;
    padding: clamp(1.5rem, 5vw, 4rem); border: 1px solid var(--line); border-radius: 1.4rem; background: #edf1ff;
}
h1, h2, h3, p { margin: 0; overflow-wrap: anywhere; }
h1 { font-size: clamp(2rem, 5vw, 4.4rem); line-height: 1.04; letter-spacing: -.055em; }
.hero p { color: var(--muted); margin: 1.25rem 0 1.6rem; font-size: 1.1rem; max-width: 45ch; }
.hero .quiet { display: inline-block; margin: .75rem .4rem; }
.sample {
    display: grid; grid-template-columns: 1fr .95fr; align-items: center; min-width: 0;
    filter: drop-shadow(0 18px 22px #17284d25);
}
.cover {
    display: flex; flex-direction: column; justify-content: space-between; gap: 1.4rem;
    min-height: 14rem; padding: clamp(1rem, 2vw, 1.8rem); overflow-wrap: anywhere;
    border-radius: .3rem .8rem .8rem .3rem; color: #fff; background: #193872;
}
.cover span { font-size: .75rem; letter-spacing: .12em; }
.cover strong { font: 600 clamp(1.55rem, 3vw, 3rem)/1.1 Georgia, serif; }
.cover i { display: block; width: 65%; height: 2rem; border-top: 1px solid #ffffff99; border-radius: 50%; transform: rotate(-13deg); }
.cover.clay { background: #883e2f; } .cover.forest { background: #23513f; }
.sample-page, .preview-page {
    color: #203047; background: #fffdf6; padding: clamp(.85rem, 2vw, 1.5rem); font-family: Georgia, serif;
}
.sample-page h2 { margin: .5rem 0; font-size: clamp(1rem, 2vw, 1.6rem); }
.sample-page p { margin: .6rem 0; font-size: .82rem; }
.sample-page small, .sample-page span { font-size: .62rem; }
.features, .books { display: grid; gap: 1rem; margin-top: 1.3rem; }
.features { grid-template-columns: repeat(3, 1fr); }
.features article, .empty, .panel, .book-card { background: white; border: 1px solid var(--line); border-radius: .9rem; }
.features article, .empty, .panel, .book-card { padding: 1rem; }
.features h2, .panel h2 { font-size: 1.05rem; }
.features p, .section-head p, .hint, .status { color: var(--muted); margin-top: .35rem; }
.books { grid-template-columns: repeat(auto-fill, minmax(205px, 1fr)); }
.book-card { text-decoration: none; }
.book-card .cover strong { font-size: 1.65rem; }
.card-caption { display: flex; justify-content: space-between; gap: .5rem; margin-top: .75rem; color: var(--muted); }
.section-head, .pane-head, .actions { display: flex; align-items: center; justify-content: space-between; gap: .7rem; }
.section-head { align-items: end; flex-wrap: wrap; }
.editor-head h1 { margin-top: .3rem; font-size: clamp(2rem, 3.6vw, 3.4rem); }
.actions { flex-wrap: wrap; justify-content: start; }
.status { min-height: 1.5rem; margin: .65rem 0; }
.editor-grid { display: grid; grid-template-columns: minmax(160px, .7fr) minmax(290px, 1.8fr) minmax(190px, 1fr); gap: 1rem; align-items: start; }
.panel { min-width: 0; }
.chapters ol { list-style: none; margin: .65rem 0; padding: 0; }
.chapters li + li { margin-top: .35rem; }
.chapters li button { text-align: left; width: 100%; overflow-wrap: anywhere; }
.chapters [aria-current="true"] { background: #eaf0ff; border-color: #9babee; }
.hint { font-size: .8rem; }
details { border-bottom: 1px solid var(--line); margin-bottom: .85rem; padding-bottom: .8rem; }
summary { cursor: pointer; font-weight: 650; }
.settings { display: grid; grid-template-columns: 1fr 1fr; gap: 0 .65rem; }
.wide { grid-column: 1 / -1; }
label { display: grid; gap: .25rem; margin: .65rem 0; font-size: .88rem; font-weight: 650; }
input, textarea, select {
    width: 100%; font: inherit; font-weight: 400; color: inherit; background: #fff;
    border: 1px solid #b8c2d3; border-radius: .5rem; padding: .5rem .65rem;
}
textarea { resize: vertical; }
.uploaded-cover { display: block; margin: .6rem auto; max-width: 100%; max-height: 18rem; }
.uploaded-cover[hidden] { display: none; }
.preview-page { margin-top: .6rem; border: 1px solid var(--line); max-height: 23rem; overflow: auto; }
#preview-body { white-space: pre-wrap; overflow-wrap: anywhere; margin-top: .5rem; }
.delete-book { margin-top: .9rem; }
.delete-book button { color: #982c35; }
@media (max-width: 900px) {
    .hero, .editor-grid { grid-template-columns: 1fr; }
    .sample { max-width: 31rem; }
    .features { grid-template-columns: 1fr; }
}
.step-nav {
    display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: .55rem;
    margin-top: 1.2rem;
}
.step-nav button { display: flex; align-items: center; gap: .5rem; text-align: left; }
.step-nav button span {
    display: grid; flex: 0 0 1.5rem; height: 1.5rem; place-items: center;
    border-radius: 50%; font-size: .75rem; background: #eaf0ff; color: #224dd0;
}
.step-nav [aria-current="step"] { border-color: var(--blue); background: #edf1ff; }
.wizard-panel { max-width: 46rem; }
.wizard-panel.chapter-step, .wizard-panel.image-step { max-width: 66rem; }
.wizard-panel .editor-grid { grid-template-columns: minmax(160px, .7fr) minmax(290px, 1.8fr); }
.wizard-panel .chapter-head { margin: 0 0 .85rem; }
.image-step .preview { max-width: 46rem; }
.image-step .preview > .primary { margin-top: .75rem; }
.image-step .cover, .image-step .uploaded-cover { max-width: 22rem; }
.wizard-footer { margin-top: 1rem; }
.workspace [hidden] { display: none; }
@media (max-width: 650px) {
    .step-nav { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .wizard-panel .editor-grid { grid-template-columns: 1fr; }
}
.image-prompt { margin-top: 1rem; border-bottom: 0; padding-bottom: 0; }

/* Workspace theme */
:root {
    --studio-bg: #f7f8fb; --studio-nav: #fff; --studio-surface: #fff; --studio-raised: #f0f3f8;
    --studio-text: #192437; --studio-muted: #526179; --studio-line: #dce2ed;
    --studio-accent: #1d46cb; --studio-primary: #294fda; --studio-active: #e8eeff;
}
:root[data-theme="dark"] {
    color-scheme: dark;
    --studio-bg: #141518; --studio-nav: #191a1e; --studio-surface: #1d1f24; --studio-raised: #252830;
    --studio-text: #f0f2f7; --studio-muted: #a7afc1; --studio-line: #343840;
    --studio-accent: #a1b5ff; --studio-primary: #345eea; --studio-active: #272f50;
}
body { background: var(--studio-bg); color: var(--studio-text); }
.studio-layout { display: grid; grid-template-columns: 220px minmax(0, 1fr); min-height: 100dvh; }
.studio-main { min-width: 0; }
.studio-sidebar {
    position: sticky; top: 0; display: flex; flex-direction: column; height: 100dvh; gap: .9rem;
    padding: 1.15rem .8rem 1rem; border-right: 1px solid var(--studio-line); background: var(--studio-nav);
    overflow: auto;
}
.studio-brand { display: flex; align-items: center; gap: .55rem; margin: .2rem .55rem .6rem; font-size: 1.13rem; font-weight: 730; text-decoration: none; }
.studio-brand img { object-fit: contain; }
.studio-nav-group { margin: 0 0 .85rem; }
.studio-nav-group p { padding: .3rem .6rem; color: var(--studio-muted); font-size: .68rem; font-weight: 750; letter-spacing: .1em; text-transform: uppercase; }
.studio-nav-group a, .theme-toggle {
    display: flex; align-items: center; gap: .65rem; padding: .48rem .6rem; border-radius: .5rem;
    text-decoration: none; color: var(--studio-muted); font-size: .87rem; line-height: 1.4;
}
.studio-nav-group a:hover, .theme-toggle:hover { background: var(--studio-raised); color: var(--studio-text); }
.studio-nav-group a[aria-current] { background: var(--studio-active); color: var(--studio-accent); font-weight: 700; }
.studio-nav-group svg, .theme-toggle svg { width: 1.04rem; height: 1.04rem; flex: 0 0 1.04rem; }
.studio-account { margin-top: auto; padding: .6rem .25rem 0; border-top: 1px solid var(--studio-line); }
.studio-account-info { display: flex; align-items: center; gap: .55rem; padding: .5rem .3rem .35rem; min-width: 0; }
.studio-account-info div { min-width: 0; }
.studio-account-info strong, .studio-account-info small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.studio-account-info strong { font-size: .85rem; }
.studio-account-info small, .studio-credit-link { color: var(--studio-muted); font-size: .76rem; }
.studio-avatar { display: grid; place-items: center; min-width: 2rem; height: 2rem; border-radius: 50%; background: var(--studio-active); color: var(--studio-accent); }
.studio-credit-link { display: inline-block; padding: .35rem .4rem; }
.studio-sidebar .theme-toggle { background: transparent; border: 0; width: 100%; }
.studio-mobile-header { display: none; }
.workspace button, .studio-home button, .studio-mobile-header button {
    background: var(--studio-raised); border-color: var(--studio-line); color: var(--studio-text);
}
.workspace .primary, .studio-home .primary { background: var(--studio-primary); border-color: var(--studio-primary); color: white; }
.workspace .quiet, .studio-home .quiet, .workspace .back { color: var(--studio-accent); }
.workspace .panel, .studio-home .book-card, .studio-home .empty { background: var(--studio-surface); border-color: var(--studio-line); }
.workspace .hint, .workspace .status, .studio-home .hint, .studio-home p, .workspace .section-head p, .studio-home .card-caption { color: var(--studio-muted); }
.workspace input, .workspace textarea, .workspace select, .studio-home input, .studio-home select, .studio-home textarea {
    color: var(--studio-text); background: var(--studio-bg); border-color: var(--studio-line);
}
.workspace .step-nav [aria-current], .workspace .chapters [aria-current] { background: var(--studio-active); border-color: var(--studio-accent); }
.workspace .step-nav button span { background: var(--studio-active); color: var(--studio-accent); }
.workspace details, .studio-home details { border-color: var(--studio-line); }
.studio-home { max-width: 1320px; }
.studio-home-intro { padding: clamp(2rem, 6vw, 5rem) 0 clamp(2rem, 4vw, 3.4rem); }
.studio-home-intro h1 { font-size: clamp(2.4rem, 5.3vw, 4.65rem); margin: .65rem 0 1.1rem; }
.studio-home-intro p { max-width: 60ch; font-size: 1.08rem; }
.studio-home-intro .studio-tagline { color: var(--studio-accent); font-size: .86rem; font-weight: 650; }
.studio-home-intro .actions { margin-top: 1.25rem; }
.studio-section { margin: 0 0 2.2rem; }
.studio-section .section-head { margin: 0 0 .9rem; }
.studio-section h2, .studio-featured h2, .studio-composer h2 { font-size: 1.2rem; letter-spacing: -.025em; }
.studio-tools { display: grid; grid-template-columns: repeat(auto-fit, minmax(125px, 1fr)); gap: .7rem; }
.studio-tool { display: flex; flex-direction: column; gap: .4rem; min-width: 0; }
.studio-tool > a, .studio-tool > span { font-size: .9rem; font-weight: 650; overflow-wrap: anywhere; }
.studio-tool small { font-size: .72rem; color: var(--studio-muted); }
.studio-tool-art, .studio-featured-art {
    display: grid; place-items: center; overflow: hidden; min-height: 8.8rem;
    border-radius: .7rem; background: #d8cbb2 url("editorial-surface.jpg") center 48% / cover no-repeat;
}
.studio-tool-art { border: 1px solid var(--studio-line); }
.studio-sample-book {
    display: grid; align-items: center; width: 61%; height: 76%; min-height: 5.75rem;
    padding: .52rem; border-left: .3rem solid #1a284a; background: #193872; color: #fff9ec;
    box-shadow: .2rem .25rem 0 #e7dcc6, .35rem .45rem .45rem #30221970;
}
.studio-sample-book strong { font: 650 clamp(.7rem, 1.1vw, 1.1rem)/1.07 Georgia, serif; overflow-wrap: anywhere; }
.studio-tool-art.clay .studio-sample-book, .studio-sample-book.clay { background: #883e2f; border-left-color: #58291c; }
.studio-tool-art.forest .studio-sample-book, .studio-sample-book.forest { background: #23513f; border-left-color: #172f25; }
.studio-tool-art.violet .studio-sample-book { background: #573d76; border-left-color: #38294f; }
.studio-tool-art.course .studio-sample-book { width: 80%; height: 63%; border-left-width: 0; border-radius: .35rem; }
.studio-tool-art.template .studio-sample-book, .studio-tool-art.workbook .studio-sample-book { background: #f6edde; color: #2b2536; }
.studio-featured {
    display: grid; grid-template-columns: 1fr .85fr; align-items: center; gap: 1rem; margin: 1rem 0 2.3rem;
    padding: clamp(1rem, 2.5vw, 2rem); background: var(--studio-surface);
    border: 1px solid var(--studio-line); border-radius: .8rem;
}
.studio-featured p, .studio-composer p { margin: .5rem 0 1rem; max-width: 56ch; }
.studio-featured-art { grid-template-columns: 1fr 1fr; min-height: 10rem; padding: .7rem; }
.studio-featured-art .studio-sample-book { width: 78%; height: 85%; }
.studio-sample-page { padding: .72rem; background: #fff9e9; color: #252934; font: .78rem Georgia, serif; transform: rotate(4deg); box-shadow: .3rem .4rem .8rem #493b3440; }
.studio-sample-page p { color: #393e4d; margin: .35rem 0; }
.studio-home .book-card { padding: .7rem; min-width: 0; }
.studio-home .book-card a { display: block; text-decoration: none; }
.studio-home .book-card .cover { min-height: 8rem; }
.studio-home .book-card button { margin-top: .65rem; font-size: .8rem; padding: .35rem .55rem; }
.project-art { display: block; width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: .55rem; }
.studio-composer { padding: clamp(1rem, 2.5vw, 1.65rem); background: var(--studio-surface); border: 1px solid var(--studio-line); border-radius: 1rem; }
.studio-composer textarea { margin-top: .65rem; }
.studio-composer-controls { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: .55rem; }
.studio-composer-controls label { color: var(--studio-muted); min-width: 0; }
.studio-errors { color: #db5e63; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; white-space: nowrap; clip-path: inset(50%); }
@media (max-width: 850px) {
    .studio-layout { grid-template-columns: 1fr; }
    .studio-mobile-header { display: flex; align-items: center; justify-content: space-between; padding: .8rem 1rem; border-bottom: 1px solid var(--studio-line); background: var(--studio-nav); }
    .studio-mobile-header a { text-decoration: none; font-weight: 720; }
    .studio-sidebar { display: none; position: static; height: auto; border-right: 0; border-bottom: 1px solid var(--studio-line); }
    .studio-menu-open .studio-sidebar { display: flex; }
}
@media (max-width: 560px) {
    .studio-featured, .studio-composer-controls { grid-template-columns: 1fr; }
}
.workspace .chapter-step { max-width: none; }
.studio-editor {
    display: grid; grid-template-columns: minmax(140px, .75fr) minmax(290px, 2.4fr) minmax(165px, .95fr);
    gap: .75rem; align-items: start;
}
.studio-editor .panel { padding: .8rem; }
.chapter-cover-link { width: 100%; margin-top: .55rem; text-align: left; }
.chapter-actions button { padding: .25rem .4rem; font-size: .73rem; }
.document-toolbar { margin-bottom: .7rem; flex-wrap: wrap; }
.document-toolbar button { padding: .2rem .55rem; }
.document-scroll { overflow: auto; padding: 1rem; background: var(--studio-bg); border-radius: .6rem; }
.document-sheet {
    --document-size: 1rem; --document-font: Georgia, serif;
    display: flex; flex-direction: column; width: 100%; min-width: 13rem; min-height: 23rem;
    padding: clamp(1.05rem, 3vw, 2.4rem); background: #fffaf0; color: #24252b;
    border-radius: .15rem; box-shadow: .1rem .2rem .8rem #15182146;
}
.document-sheet[data-font="sans"] { --document-font: system-ui, sans-serif; }
.document-sheet input, .document-sheet textarea {
    color: #24252b; background: transparent; border: 0; border-radius: 0; padding: 0;
    font: var(--document-size)/1.8 var(--document-font);
}
.document-sheet input { font: bold calc(var(--document-size) * 1.53)/1.2 var(--document-font); padding-bottom: .8rem; border-bottom: 1px solid #e0d9ce; }
.document-sheet textarea { padding-top: .9rem; flex: 1; resize: vertical; }
.studio-customize button { font-size: .78rem; padding: .3rem .46rem; }
.studio-customize summary { padding: .6rem 0; }
.studio-ai-actions { margin-top: .6rem; gap: .3rem; }
.studio-dialog {
    width: min(94vw, 36rem); max-height: 90dvh; overflow: auto; padding: clamp(1rem, 3vw, 1.75rem);
    color: var(--studio-text); background: var(--studio-surface); border: 1px solid var(--studio-line); border-radius: .95rem;
}
.studio-dialog::backdrop { background: #08090ac0; }
.studio-dialog .actions { margin-top: .8rem; }
@media (max-width: 1180px) {
    .studio-editor { grid-template-columns: minmax(130px, .8fr) minmax(260px, 2fr); }
    .studio-customize { grid-column: 2; }
}
@media (max-width: 640px) {
    .studio-editor { grid-template-columns: minmax(0, 1fr); }
    .studio-customize { grid-column: 1; }
    .document-scroll { padding: .45rem; }
}
.workspace[aria-busy="true"] > .status::before {
    display: inline-block; vertical-align: -.1em; margin-right: .45rem; width: .75rem; height: .75rem;
    border-radius: 50%; border: 2px solid currentColor; border-right-color: transparent;
    content: ""; animation: studio-spin .8s linear infinite;
}
@keyframes studio-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
    .workspace[aria-busy="true"] > .status::before { animation: none; }
}
.studio-publish-preview { display: flex; align-items: center; gap: .75rem; margin: .7rem 0; }
.studio-publish-preview img { width: 4.25rem; height: 4.25rem; object-fit: cover; border-radius: .45rem; }
