/* Reader formatting shared with the chapter editor. */
@media(max-width:800px){body:has(.reader)>header{position:relative;top:auto;height:auto}body:has(.reader)>main{padding-top:24px}.reader .reader-head{position:static;height:auto;padding:0;background:transparent;display:block}}
.reader .reader-head{position:static;top:auto;height:auto;display:block;padding:0;border:0;background:transparent;z-index:auto}
.reader-novel-link{display:inline-flex;align-items:center;gap:.75rem;max-width:100%;color:var(--deep-emerald);border-radius:5px}.reader-novel-link img{flex:0 0 auto;width:48px;height:72px;aspect-ratio:2/3;object-fit:cover;border:1px solid var(--soft-gold);border-radius:3px}.reader-novel-link span{display:grid;min-width:0}.reader-novel-link small{color:var(--muted);font-size:.75rem}.reader-novel-link strong{font-family:Georgia,"Noto Serif Thai",serif;overflow-wrap:anywhere}.reader-novel-link:hover strong{color:var(--emerald)}
.reader-preferences{margin:1.2rem 0;position:relative}.reader-toolbar{display:flex;align-items:flex-start;justify-content:space-between;gap:.75rem}.reader-preferences button,.format-tools button,.preview-heading button{border:1px solid var(--gold);background:var(--ivory);color:var(--emerald);border-radius:5px;padding:.45rem .8rem}.reader-toolbar-button{min-width:44px;min-height:44px;display:inline-grid;place-items:center}.reader-toolbar-button svg{width:22px;height:22px;fill:none;stroke:currentColor;stroke-width:1.8;stroke-linecap:round;stroke-linejoin:round}.reader-preferences #reader-settings{padding:1rem;background:var(--cream);border:1px solid var(--gold);max-width:370px}.reader-preferences label{display:flex;justify-content:space-between;gap:1rem;align-items:center;margin:.5rem 0}.reader-preferences input{max-width:50%}.reader-tts{position:relative;margin-left:auto}.reader-tts-panel{width:min(390px,calc(100vw - 2rem));margin-top:.45rem;padding:.85rem;background:var(--cream);border:1px solid var(--gold);border-radius:6px;box-shadow:0 10px 24px rgba(5,99,74,.16)}.reader-tts-panel[hidden]{display:none}.reader-tts-controls{display:flex;flex-wrap:wrap;gap:.4rem}.reader-tts-controls button{min-height:44px;flex:1 1 auto}.reader-tts-settings{display:grid;grid-template-columns:1fr 1fr;gap:.65rem;margin-top:.65rem}.reader-tts-settings label{display:grid;gap:.25rem;margin:0;font-size:.85rem}.reader-tts-settings select{min-width:0;width:100%;min-height:44px;border:1px solid var(--gold);background:var(--ivory);color:var(--charcoal);font:inherit}.reader-tts-panel[data-state="error"] .reader-tts-status{position:static;width:auto;height:auto;margin:.55rem 0 0;overflow:visible;clip:auto;white-space:normal;color:var(--deep-emerald);font-size:.85rem}.reader .chapter-content{font-size:var(--reader-size,1.18rem);line-height:var(--reader-leading,2)}.reader-nav{flex-wrap:wrap;align-items:center;gap:.8rem}.reader-nav a{max-width:none}.reader-nav span{color:var(--muted)}.sr-only{position:absolute;width:1px;height:1px;overflow:hidden;clip:rect(0,0,0,0);white-space:nowrap}
.reader-tts-icon-pause,.reader-tts-icon-resume{display:none}.reader-tts-toggle[aria-label="พักการอ่าน"] .reader-tts-icon-speak,.reader-tts-toggle[aria-label="อ่านต่อ"] .reader-tts-icon-speak{display:none}.reader-tts-toggle[aria-label="พักการอ่าน"] .reader-tts-icon-pause,.reader-tts-toggle[aria-label="อ่านต่อ"] .reader-tts-icon-resume{display:block}.reader-tts-primary{display:flex;justify-content:flex-end}.reader-tts-more label{display:grid;align-items:stretch;gap:.25rem;margin:0;font-size:.85rem}.reader-tts-more select{width:100%;min-width:0;min-height:44px;border:1px solid var(--gold);background:var(--ivory);color:var(--charcoal);font:inherit}.reader-tts-primary button{min-width:64px;min-height:44px}.reader-tts-more{margin-top:.55rem}.reader-tts-more summary{min-height:44px;display:flex;align-items:center;color:var(--deep-emerald);font-weight:650;cursor:pointer}.reader-tts-more label{padding-top:.35rem}
.reader-tts-actions{display:flex;gap:.4rem}.reader-tts-toggle .reader-tts-icon{display:none}.reader-tts-toggle[data-state="idle"] .reader-tts-icon-speak,.reader-tts-toggle[data-state="error"] .reader-tts-icon-speak{display:block}.reader-tts-toggle[data-state="starting"] .reader-tts-icon-pause,.reader-tts-toggle[data-state="reading"] .reader-tts-icon-pause{display:block}.reader-tts-toggle[data-state="paused"] .reader-tts-icon-resume{display:block}.reader-tts-panel{position:absolute;z-index:6;top:100%;right:0;max-width:calc(100vw - 2rem);overflow:hidden}.reader-tts-primary{min-width:0}.reader-tts-status:empty{display:none}
.chapter-content ul,.chapter-content ol{padding-inline-start:1.8em}.chapter-content blockquote{margin:1.3em 0;padding:.3em 1em;border-inline-start:3px solid var(--gold);color:var(--muted)}.chapter-content .chapter-align-center{text-align:center}.chapter-content .chapter-align-right{text-align:right}.chapter-content a{text-decoration:underline;color:var(--emerald)}

/* Long-form chapter workspace. */
body:has(.chapter-workspace)>header{min-height:56px;height:56px;padding-block:0}body:has(.chapter-workspace)>main{width:min(1500px,96%);padding:24px 0 48px}body:has(.chapter-workspace)>footer{display:none}
.chapter-workspace{display:grid;grid-template-columns:minmax(0,1fr) 260px;gap:24px;align-items:start}.chapter-main{min-width:0}.chapter-back{display:inline-block;margin-bottom:.55rem;color:var(--deep-emerald)}.chapter-heading{position:static;height:auto;display:block;padding:0;border:0;background:transparent}.chapter-heading h1{margin:.15rem 0 .4rem;font:2.15rem Georgia,serif;color:var(--emerald)}.chapter-story-title{margin:0;color:var(--deep-emerald);font:700 1rem Georgia,serif}.chapter-statuses{display:flex;gap:.6rem;flex-wrap:wrap;color:var(--muted);font-size:.88rem}.chapter-statuses span{padding:.25rem .55rem;border:1px solid var(--line);border-radius:999px;background:var(--ivory)}.chapter-publication-status[data-status=published]{color:var(--deep-emerald);border-color:var(--gold)}
.chapter-main form{margin-top:1rem}.chapter-main label{display:block;font-weight:650;margin:.7rem 0}.chapter-main input:not([type=radio]){display:block;width:100%;padding:11px 12px;border:1px solid var(--gold);font:inherit;background:var(--surface);margin-top:6px}.chapter-commandbar{position:sticky;top:56px;z-index:8;display:flex;align-items:center;justify-content:space-between;gap:.75rem;padding:.65rem .75rem;margin-bottom:1rem;background:rgba(255,249,238,.98);border:1px solid var(--gold);box-shadow:0 4px 14px rgba(5,99,74,.08)}.chapter-command-actions{display:flex;align-items:center;gap:.45rem;flex-wrap:wrap}.chapter-commandbar .button{margin:0;padding:.65rem 1rem}.chapter-commandbar #save-state{font-size:.85rem;color:var(--muted);white-space:nowrap}.chapter-commandbar #save-state[data-state=dirty]{color:#7a5200}.chapter-commandbar #save-state[data-state=saving]{color:var(--deep-emerald)}.chapter-commandbar #save-state[data-state=saved]{color:var(--emerald);font-weight:700}.chapter-commandbar #save-state[data-state=error]{color:#a12622;font-weight:700}
.chapter-meta{display:grid;grid-template-columns:minmax(110px,150px) minmax(0,1fr);gap:16px;width:min(820px,100%);margin:0 auto 1rem}.chapter-paper{width:min(820px,100%);margin:auto;padding:0 clamp(22px,5vw,64px) clamp(32px,6vw,70px);background:var(--ivory);border:1px solid var(--soft-gold);box-shadow:0 12px 35px rgba(38,41,35,.08)}.format-tools{position:sticky;top:122px;z-index:7;display:flex;align-items:center;gap:.3rem;flex-wrap:wrap;margin:0 calc(clamp(22px,5vw,64px)*-1) 1.1rem;padding:.55rem clamp(22px,5vw,64px);background:var(--cream);border-bottom:1px solid var(--gold)}.format-group{display:flex;align-items:center;gap:.25rem}.format-tools button{position:relative;width:44px;height:44px;min-width:44px;min-height:44px;display:inline-grid;place-items:center;padding:0;font-size:.96rem}.format-tools button::after{position:absolute;left:50%;bottom:calc(100% + 7px);z-index:10;padding:.3rem .48rem;border-radius:4px;color:var(--ivory);background:var(--deep-emerald);font-size:.72rem;font-weight:650;line-height:1.2;content:attr(data-tooltip);opacity:0;pointer-events:none;transform:translate(-50%,3px);transition:opacity .12s,transform .12s;white-space:nowrap}.format-tools button:hover::after,.format-tools button:focus-visible::after{opacity:1;transform:translate(-50%,0)}.format-tools button:hover,.format-tools button[aria-pressed=true]{background:var(--emerald);color:white}.format-tools button:focus-visible{color:var(--emerald);background:var(--ivory);outline:3px solid var(--gold);outline-offset:2px}.format-tools button[aria-pressed=true]:focus-visible{color:white;background:var(--emerald)}.format-icon{width:23px;height:23px;fill:none;stroke:currentColor;stroke-width:1.8;stroke-linecap:round}.format-paragraph-icon{font:700 1.3rem/1 Georgia,serif}.format-divider{align-self:stretch;width:1px;background:var(--gold);margin:0 .2rem}.chapter-editor-label{display:flex;align-items:center;justify-content:space-between;gap:1rem;color:var(--muted)}.chapter-editor-label label{color:var(--ink)}#chapter-char-count{font-size:.84rem;white-space:nowrap}.chapter-visual{display:block;min-height:72vh;height:auto;padding:8px 0 40vh;border:0;background:transparent;outline-offset:6px;white-space:normal;overflow:visible;overflow-wrap:anywhere;font:1.12rem/2 Georgia,"Noto Serif Thai",serif;-webkit-user-select:text;user-select:text;pointer-events:auto}.chapter-visual p{margin:0 0 1.45em}.chapter-visual p:last-child{margin-bottom:0}.chapter-visual:focus-visible{outline:2px solid var(--emerald)}.chapter-visual:empty::before{content:'เริ่มเขียนเนื้อหาตอนที่นี่…';color:var(--muted)}.chapter-source[hidden]{display:none!important}
.chapter-settings{width:min(820px,100%);margin:1.25rem auto 0;padding:1rem;border:1px solid var(--line);background:var(--cream)}.chapter-settings summary,.chapter-sidebar summary{cursor:pointer;color:var(--emerald);font-weight:700}.chapter-extra-actions{display:flex;flex-wrap:wrap;gap:.7rem}.chapter-sidebar{position:sticky;top:76px;max-height:calc(100vh - 96px);overflow:auto;padding:1rem;border:1px solid var(--line);background:var(--cream)}.chapter-sidebar nav{display:grid;gap:.4rem;margin-top:.85rem}.chapter-sidebar nav a{display:grid;gap:.12rem;padding:.6rem;border-radius:4px;overflow-wrap:anywhere}.chapter-sidebar nav a small{color:var(--muted)}.chapter-sidebar nav a:hover{background:rgba(201,164,76,.2)}.chapter-sidebar nav a[aria-current=page]{background:var(--emerald);color:white}.chapter-sidebar nav a[aria-current=page] small{color:var(--cream)}.chapter-add-link{margin-top:.4rem;border:1px solid var(--gold);color:var(--emerald)}
#chapter-preview-dialog{width:min(760px,94vw);max-height:90vh;padding:1.5rem;background:var(--ivory);border:1px solid var(--gold);border-radius:8px}#chapter-preview-dialog::backdrop{background:rgba(0,0,0,.55)}.preview-heading{display:flex;justify-content:space-between;align-items:center;gap:1rem;flex-wrap:wrap}.preview-heading h2{min-width:0;max-width:100%;overflow-wrap:anywhere}

@media(max-width:850px){body:has(.chapter-workspace)>header{height:auto;min-height:58px}body:has(.chapter-workspace)>main{width:94%;padding-top:16px}.chapter-workspace{grid-template-columns:minmax(0,1fr);gap:14px}.chapter-sidebar{position:static;max-height:none;grid-row:1}.chapter-sidebar details:not([open]) nav{display:none}.chapter-sidebar details{max-height:230px;overflow:auto}.chapter-commandbar{top:0}.format-tools{top:70px;flex-wrap:nowrap;overflow-x:auto;overscroll-behavior-inline:contain;scrollbar-width:thin}.format-group{flex:0 0 auto}.format-tools button{flex:0 0 44px}.format-divider{flex:0 0 1px}.chapter-visual{min-height:70vh;padding-bottom:35vh}}
@media(max-width:520px){body:has(.chapter-workspace)>main{width:100%;padding-inline:10px}.chapter-heading h1{font-size:1.65rem}.chapter-statuses{gap:.35rem}.chapter-statuses span{font-size:.78rem}.chapter-commandbar{align-items:stretch;margin-inline:-10px;padding:.5rem 10px;border-inline:0}.chapter-command-actions{display:grid;grid-template-columns:1fr 1fr 1fr;width:100%;gap:.35rem}.chapter-commandbar .button{padding:.58rem .35rem;font-size:.78rem;text-align:center}.chapter-commandbar #save-state{position:absolute;left:10px;top:100%;padding:.15rem .45rem;background:var(--ivory);border:1px solid var(--line);border-top:0}.chapter-meta{grid-template-columns:92px minmax(0,1fr);gap:10px;margin-top:1.5rem}.chapter-paper{padding-inline:14px;border-inline:0;box-shadow:none}.format-tools{top:58px;margin-inline:-14px;padding-inline:14px}.chapter-editor-label{margin-top:.2rem}.chapter-visual{font-size:1.06rem;line-height:1.95;padding-bottom:45vh}.chapter-settings{border-inline:0}.reader-nav a{max-width:100%}}

/* Extended chapter tools share the existing toolbar and reader language. */
.format-icon{stroke-linejoin:round}.chapter-main .format-tools .format-color-input{position:absolute;display:block;width:1px;height:1px;margin:0;padding:0;border:0;opacity:0;pointer-events:none}.chapter-content .chapter-align-justify{text-align:justify}.chapter-content .chapter-indent-1{margin-inline-start:2rem}.chapter-content .chapter-indent-2{margin-inline-start:4rem}.chapter-content .chapter-indent-3{margin-inline-start:6rem}.chapter-content .chapter-indent-4{margin-inline-start:8rem}.chapter-divider{border:0;border-top:1px solid var(--gold);margin:2rem 0}.chapter-media{margin:1.5rem auto;text-align:center}.chapter-media img,.chapter-media video{display:block;max-width:100%;height:auto;margin:auto}.chapter-media figcaption{margin-top:.5rem;color:var(--muted);font-size:.9em}.chapter-table-wrap{max-width:100%;overflow-x:auto}.chapter-content table{width:100%;border-collapse:collapse;margin:1.4rem 0}.chapter-content td{min-width:7rem;padding:.55rem;border:1px solid var(--gold);vertical-align:top}@media(max-width:520px){.chapter-content .chapter-indent-3,.chapter-content .chapter-indent-4{margin-inline-start:3rem}}
@media(max-width:520px){body:has(.reader-page){overflow-x:hidden}.reader-page{width:100%;max-width:100%;min-width:0}.reader-novel-link{gap:.6rem}.reader-novel-link img{width:40px;height:60px}.reader-toolbar{width:100%;min-width:0;gap:.5rem}.reader-toolbar>div:first-child{min-width:0}.reader-tts{flex:0 0 auto}.reader-tts-panel{width:calc(100vw - 8vw);max-width:390px}.reader-tts-settings{grid-template-columns:1fr}}
.reader-toolbar-button[title]{position:relative}.reader-toolbar-button[title]::after{position:absolute;top:calc(100% + .4rem);right:0;z-index:4;width:max-content;max-width:12rem;padding:.25rem .5rem;border-radius:4px;background:var(--deep-emerald);color:var(--ivory);content:attr(title);font-size:.75rem;line-height:1.4;opacity:0;pointer-events:none;transform:translateY(-2px);transition:opacity .12s ease,transform .12s ease}.reader-toolbar-button[title]:hover::after,.reader-toolbar-button[title]:focus-visible::after{opacity:1;transform:translateY(0)}
.reader-tts-language{display:grid!important;grid-template-columns:auto minmax(0,1fr);gap:.6rem!important;align-items:center!important;margin:0 0 .55rem!important;font-size:.85rem}.reader-tts-language select{width:100%;min-width:0;min-height:44px;border:1px solid var(--gold);background:var(--ivory);color:var(--charcoal);font:inherit}@media(max-width:520px){.reader-tts-language{grid-template-columns:1fr}.reader-tts-panel{max-height:calc(100vh - 110px);overflow:auto}}
.reader-page .reader-head h1{font-size:clamp(1.8rem,4vw,2.6rem);line-height:1.2;overflow-wrap:anywhere;word-break:normal}

/* Shared long-form defaults for editor, preview, and chapter reader. */
.chapter-visual,.reader .chapter-content{width:min(720px,100%);margin-inline:auto;font-size:1.125rem;line-height:1.8;text-align:left;text-indent:0;overflow-wrap:anywhere;word-break:normal}
.reader .chapter-content{font-size:var(--reader-size,1.125rem);line-height:var(--reader-leading,1.8)}
.chapter-visual p,.reader .chapter-content p{margin:0 0 1em;text-indent:2em}
.chapter-visual p:is(.chapter-align-center,.chapter-align-right,.chapter-align-justify),.reader .chapter-content p:is(.chapter-align-center,.chapter-align-right,.chapter-align-justify){text-indent:0}
.chapter-visual p:last-child,.reader .chapter-content p:last-child{margin-bottom:0}
#chapter-preview-dialog .reader{width:100%;min-width:0}#chapter-preview-dialog .chapter-content{width:100%;max-width:720px;min-width:0;overflow-wrap:anywhere;word-break:normal}
@media(max-width:520px){.chapter-paper{padding-inline:10px}.format-tools{margin-inline:-10px;padding-inline:10px}.chapter-visual{font-size:1.125rem;line-height:1.8}.reader-page .chapter-content{width:min(720px,calc(100vw - 40px))}.chapter-workspace .chapter-price-grid{grid-template-columns:minmax(0,1fr)}.chapter-workspace .chapter-price-grid>*{min-width:0;max-width:100%}.chapter-workspace .chapter-price-grid>strong{width:auto;overflow-wrap:anywhere}}
