@import url("https://fonts.googleapis.com/css2?family=Abril+Fatface&family=Cinzel:wght@400;600;700&family=Cormorant+Garamond:wght@400;500;600;700&family=Crimson+Text:wght@400;600;700&family=EB+Garamond:wght@400;500;600;700&family=Inter:wght@400;500;600;700&family=Lato:wght@400;700&family=Libre+Baskerville:wght@400;700&family=Lora:wght@400;500;600;700&family=Merriweather:wght@400;700&family=Noto+Serif:wght@400;600;700&family=Open+Sans:wght@400;600;700&family=Playfair+Display:wght@400;600;700&family=Roboto:wght@400;700&family=Source+Sans+3:wght@400;600;700&family=Source+Serif+4:wght@400;600;700&display=swap");

:root {
  --bg: #f5f3ee;
  --surface: #fffdf8;
  --ink: #1d2329;
  --muted: #65706d;
  --line: #d9d4ca;
  --accent: #256f65;
  --accent-dark: #15534b;
  --danger: #9d3429;
  --shadow: 0 16px 38px rgba(27, 35, 34, 0.12);
  --page-width: 6in;
  --page-height: 9in;
  --page-margin-top: 0.72in;
  --page-margin-side: 0.62in;
  --page-margin-bottom: 0.78in;
  --page-font: Georgia, "Times New Roman", serif;
  --page-font-size: 11pt;
  --page-line-height: 1.48;
  --preview-zoom: 0.58;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: Arial, Helvetica, sans-serif;
}

button,
input,
select {
  font: inherit;
}

button,
input,
select {
  border: 1px solid var(--line);
  border-radius: 6px;
}

button {
  min-height: 34px;
  padding: 0 10px;
  background: #ffffff;
  color: var(--ink);
  cursor: pointer;
  transition: background 160ms ease, border-color 160ms ease, transform 160ms ease;
}

button:hover {
  border-color: #a8aaa1;
  background: #f9faf7;
}

button:active {
  transform: translateY(1px);
}

input,
select {
  min-height: 34px;
  padding: 0 9px;
  background: #ffffff;
  color: var(--ink);
}

label {
  color: var(--muted);
  font-size: 12px;
}

label span {
  display: block;
  margin-bottom: 4px;
}

.primary-button {
  border-color: var(--accent);
  background: var(--accent);
  color: #ffffff;
  font-weight: 700;
}

.primary-button:hover {
  border-color: var(--accent-dark);
  background: var(--accent-dark);
}

.danger-button {
  color: var(--danger);
}

.app-header {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) minmax(420px, 1.1fr) auto;
  gap: 18px;
  align-items: end;
  padding: 18px 22px;
  border-bottom: 1px solid var(--line);
  background: #faf8f1;
}

.app-header h1 {
  margin: 4px 0 0;
  font-size: 23px;
  letter-spacing: 0;
}

.project-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}

.project-bar select {
  width: min(240px, 100%);
}

.project-bar button,
.header-actions button {
  white-space: nowrap;
}

.eyebrow,
.section-kicker {
  margin: 0;
  color: var(--accent-dark);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.book-meta {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(145px, 1fr));
  gap: 8px;
}

.book-meta input {
  width: 100%;
}

.header-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

.download-link {
  color: var(--accent-dark);
  font-size: 13px;
  font-weight: 700;
  text-decoration: none;
}

.app-shell {
  display: grid;
  grid-template-columns: 260px minmax(360px, 1.05fr) 305px minmax(380px, 0.95fr);
  gap: 14px;
  padding: 14px;
}

.structure-panel,
.editor-panel,
.settings-panel,
.preview-panel {
  min-width: 0;
}

.panel-heading,
.section-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.panel-heading h2,
.section-heading h2 {
  margin: 2px 0 0;
  font-size: 17px;
}

.save-state,
.page-counter,
.small-note {
  color: var(--muted);
  font-size: 12px;
}

.editor-heading-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
}

.add-picture-button {
  min-width: 128px;
}

.structure-panel,
.settings-section {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 10px 28px rgba(27, 35, 34, 0.08);
}

.structure-panel {
  position: sticky;
  top: 12px;
  align-self: start;
  max-height: calc(100vh - 118px);
  overflow: auto;
}

.wide-button {
  width: 100%;
}

.add-menu {
  margin-top: 8px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.add-menu h3 {
  margin: 10px 0 6px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--accent-dark);
}

.add-menu h3:first-child {
  margin-top: 0;
}

.add-menu button {
  width: 100%;
  margin-bottom: 5px;
  text-align: left;
}

.generate-actions {
  display: grid;
  gap: 6px;
  margin: 10px 0;
}

.section-list {
  display: grid;
  gap: 7px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.section-item {
  display: grid;
  grid-template-columns: 1fr;
  gap: 6px;
  padding: 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.section-item.drag-over {
  border-color: var(--accent);
  background: #eef8f5;
}

.section-main {
  width: 100%;
  min-height: auto;
  padding: 0;
  border: 0;
  background: transparent;
  text-align: left;
}

.section-main:hover {
  background: transparent;
}

.section-title {
  display: block;
  color: var(--ink);
  font-weight: 700;
}

.section-type {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 11px;
  text-transform: capitalize;
}

.section-item.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(37, 111, 101, 0.16);
}

.section-actions {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 4px;
}

.section-actions button {
  min-width: 0;
  min-height: 28px;
  padding: 0;
  font-size: 12px;
}

.title-editor {
  display: block;
  margin-bottom: 8px;
}

.title-editor input {
  width: 100%;
  min-height: 40px;
  font-size: 18px;
  font-weight: 700;
}

.section-options {
  display: grid;
  grid-template-columns: 1fr 1fr 150px;
  gap: 8px;
  align-items: end;
  margin-bottom: 8px;
}

.section-options label {
  min-height: 34px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.section-options label:last-child {
  display: block;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 8px;
  border: 1px solid var(--line);
  border-bottom: 0;
  border-radius: 8px 8px 0 0;
  background: var(--surface);
}

.toolbar button {
  min-width: 36px;
}

.toolbar .active-tool {
  border-color: var(--accent);
  background: #e7f3ef;
  color: var(--accent-dark);
  font-weight: 800;
}

.picture-toolbar-button {
  min-width: 104px;
  border-color: var(--accent);
  color: var(--accent-dark);
  font-weight: 700;
}

.toolbar-select {
  width: 128px;
  min-height: 34px;
}

.toolbar-select.size-select {
  width: 76px;
}

.toolbar-select.compact-select {
  width: 92px;
}

.spacing-inspector {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 8px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-top: 0;
  background: #f7f5ef;
}

.spacing-inspector strong {
  align-self: center;
  margin-right: 4px;
  color: var(--ink);
  font-size: 13px;
}

.spacing-inspector label {
  display: grid;
  gap: 3px;
}

.spacing-inspector select {
  min-height: 30px;
  min-width: 88px;
}

.custom-layout-builder {
  display: grid;
  gap: 8px;
  margin-top: 10px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f7f5ef;
}

.custom-layout-builder h3 {
  margin: 0;
  font-size: 14px;
}

.custom-layout-builder label {
  display: grid;
  gap: 4px;
}

.custom-layout-builder label:has(input[type="checkbox"]) {
  display: flex;
  align-items: center;
  gap: 7px;
}

.focus-mode .structure-panel,
.focus-mode .settings-panel,
.focus-mode .preview-panel,
.focus-mode .book-meta,
.focus-mode .project-bar,
.focus-mode .header-actions {
  display: none;
}

.focus-mode .app-header {
  grid-template-columns: 1fr;
}

.focus-mode .app-shell {
  grid-template-columns: minmax(360px, 860px);
  justify-content: center;
}

.focus-mode .editor {
  min-height: calc(100vh - 220px);
  max-height: calc(100vh - 220px);
}

.image-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 8px;
  border: 1px solid var(--line);
  border-bottom: 0;
  background: #f8faf6;
  position: sticky;
  top: 0;
  z-index: 2;
}

.image-controls button {
  min-height: 30px;
  font-size: 12px;
}

.toolbar-divider {
  width: 1px;
  min-height: 30px;
  background: var(--line);
}

.editor {
  min-height: calc(100vh - 276px);
  max-height: calc(100vh - 276px);
  overflow: auto;
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: 0 0 8px 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
  font-family: Georgia, "Times New Roman", serif;
  font-size: 17px;
  line-height: 1.65;
  outline: none;
}

.editor:empty::before {
  content: "Write this section here...";
  color: #8c928b;
}

.editor.show-formatting-marks p,
.editor.show-formatting-marks h1,
.editor.show-formatting-marks h2,
.editor.show-formatting-marks h3,
.editor.show-formatting-marks blockquote,
.editor.show-formatting-marks li {
  position: relative;
}

.editor.show-formatting-marks p::after,
.editor.show-formatting-marks h1::after,
.editor.show-formatting-marks h2::after,
.editor.show-formatting-marks h3::after,
.editor.show-formatting-marks blockquote::after,
.editor.show-formatting-marks li::after {
  content: " ¶";
  color: #9aa1a0;
  font-family: Arial, Helvetica, sans-serif;
  font-size: 0.8em;
}

.editor.show-formatting-marks p:empty {
  min-height: 1.4em;
  outline: 1px dashed #d09a45;
  background: rgba(208, 154, 69, 0.08);
}

.editor.show-formatting-marks p:empty::before {
  content: "empty paragraph";
  color: #b7791f;
  font-family: Arial, Helvetica, sans-serif;
  font-size: 12px;
}

.spelling-error,
.grammar-error,
.style-error {
  text-decoration-line: underline;
  text-decoration-style: wavy;
  text-decoration-thickness: 1.5px;
  cursor: context-menu;
}

.spelling-error {
  text-decoration-color: #d21f1f;
}

.grammar-error {
  text-decoration-color: #2563eb;
}

.style-error {
  text-decoration-color: #d97706;
}

.proof-menu {
  position: fixed;
  z-index: 40;
  min-width: 210px;
  max-width: 280px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  box-shadow: var(--shadow);
}

.proof-menu p {
  margin: 4px 8px 6px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.proof-menu button {
  display: block;
  width: 100%;
  min-height: 30px;
  padding: 0 8px;
  border: 0;
  background: transparent;
  text-align: left;
  font-size: 13px;
}

.proof-menu button:hover {
  background: #eef6f3;
}

.editor h1,
.editor h2,
.editor h3 {
  font-family: Arial, Helvetica, sans-serif;
  line-height: 1.2;
}

.editor blockquote {
  margin: 1.2em 0;
  padding: 0.2em 0 0.2em 1em;
  border-left: 3px solid var(--accent);
  color: #38423f;
}

.book-image {
  display: block;
  margin: 1.1em 0;
  padding: 8px;
  border: 1px solid transparent;
  cursor: pointer;
}

.book-image.selected {
  border-color: var(--accent);
  background: #eef8f5;
  box-shadow: 0 0 0 3px rgba(37, 111, 101, 0.14);
}

.book-image img {
  display: block;
  max-width: 100%;
  height: auto;
}

.book-image.align-left img,
.book-image.align-left figcaption {
  margin-right: auto;
}

.book-image.align-center img,
.book-image.align-center figcaption {
  margin-left: auto;
  margin-right: auto;
}

.book-image.align-right img,
.book-image.align-right figcaption {
  margin-left: auto;
}

.book-image figcaption {
  max-width: 100%;
  margin-top: 6px;
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}

.book-image {
  break-inside: avoid;
  page-break-inside: avoid;
}

.book-image img {
  max-width: 100%;
  height: auto;
}

@media print {
  .preview-guide,
  .margin-guide,
  .safe-area-guide,
  .bleed-warning,
  .page-border,
  .debug-overlay {
    display: none !important;
  }
}

.settings-panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-height: calc(100vh - 118px);
  overflow: auto;
}

.size-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.size-option,
.layout-card {
  width: 100%;
  text-align: left;
}

.size-option {
  padding: 9px;
}

.size-option strong {
  display: block;
}

.size-option span {
  color: var(--muted);
  font-size: 11px;
}

.selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(37, 111, 101, 0.16);
}

.compact-settings {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.compact-settings select {
  width: 100%;
}

.layout-list {
  display: grid;
  gap: 9px;
}

#compareLayoutsButton {
  margin-bottom: 9px;
}

.layout-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  display: grid;
  gap: 8px;
  padding: 9px;
}

.layout-card.selected,
.layout-card.active-layout {
  border-color: #275c7a;
  background: linear-gradient(180deg, #eef6fb 0%, #ffffff 58%);
  box-shadow: 0 0 0 3px rgba(39, 92, 122, 0.22), 0 10px 24px rgba(39, 92, 122, 0.12);
}

.layout-card.selected {
  transform: translateY(-1px);
}

.layout-card.active-layout {
  border-left: 5px solid #1f4f6d;
}

.layout-select-area {
  display: grid;
  grid-template-columns: 56px 1fr;
  gap: 10px;
  min-height: 0;
  padding: 0;
  border: 0;
  background: transparent;
  text-align: left;
}

.layout-select-area:hover {
  background: transparent;
}

.sample-page {
  height: 76px;
  border: 1px solid #d8d4ca;
  background: #fffefb;
  padding: 8px;
}

.sample-line {
  display: block;
  height: 4px;
  margin-bottom: 6px;
  background: #aeb5ad;
}

.sample-line.short {
  width: 62%;
}

.sample-line.tiny {
  width: 36%;
}

.sample-line.title {
  height: 7px;
  width: 72%;
  background: var(--accent);
}

.sample-reflectionLight .sample-line,
.sample-reflectionDeep .sample-line {
  margin-bottom: 9px;
}

.sample-reflectionDeep .sample-line.short,
.sample-reflectionDeep .sample-line.tiny {
  margin-left: auto;
  margin-right: auto;
}

.sample-storyBook .sample-line {
  width: 88%;
  height: 3px;
  margin-left: 8px;
}

.sample-workbook .sample-line.short {
  height: 10px;
  border-left: 3px solid var(--accent);
  background: #dfeee8;
}

.sample-conversationBook .sample-line.title,
.sample-conversationBook .sample-line.tiny {
  width: 48%;
  background: var(--accent);
}

.sample-conversationBook .sample-line.short {
  width: 82%;
  margin-bottom: 10px;
}

.layout-copy strong {
  display: block;
  margin-bottom: 3px;
}

.layout-copy span,
.layout-copy p {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.layout-copy small {
  display: block;
  margin-top: 5px;
  color: #596461;
  font-size: 11px;
  line-height: 1.35;
}

.layout-state-row {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  min-height: 20px;
}

.layout-state {
  display: inline-flex;
  align-items: center;
  min-height: 18px;
  padding: 0 7px;
  border-radius: 999px;
  font-size: 10px;
  font-style: normal;
  font-weight: 800;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.layout-state.active {
  background: #1f4f6d;
  color: #ffffff;
}

.layout-state.selected {
  background: #d6e6ef;
  color: #183f58;
  border: 1px solid #7da8bd;
}

.layout-change-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  padding-top: 6px;
  border-top: 1px solid #ece7dd;
}

.layout-chip {
  min-height: 26px;
  padding: 0 8px;
  border-color: #cfc8bc;
  background: #ffffff;
  color: var(--muted);
  font-size: 11px;
}

.layout-chip.active {
  border-color: var(--accent);
  background: #e7f3ef;
  color: var(--accent-dark);
  font-weight: 700;
}

.apply-controls {
  display: grid;
  grid-template-columns: 1fr;
  gap: 9px;
}

.layout-settings-title {
  margin: 2px 0 8px;
  color: var(--ink);
  font-size: 13px;
  font-weight: 700;
}

.layout-toggle-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
}

.layout-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 28px;
  color: var(--ink);
  font-size: 12px;
}

.layout-toggle span {
  margin: 0;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(24, 29, 30, 0.46);
}

.compare-modal {
  width: min(1180px, 100%);
  max-height: calc(100vh - 36px);
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.improve-modal {
  width: min(1120px, 100%);
  max-height: calc(100vh - 36px);
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.stats-modal {
  width: min(1120px, 100%);
  max-height: calc(100vh - 36px);
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.find-modal {
  width: min(760px, 100%);
  max-height: calc(100vh - 36px);
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.kdp-modal {
  width: min(1120px, 100%);
  max-height: calc(100vh - 36px);
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.compare-header,
.compare-controls,
.compare-apply-panel {
  padding: 14px;
  border-bottom: 1px solid var(--line);
}

.compare-header {
  display: flex;
  justify-content: space-between;
  gap: 14px;
}

.compare-header h2,
.compare-header p,
.compare-apply-panel h3 {
  margin: 0;
}

.compare-header p {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
}

.compare-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 12px;
}

.compare-controls label {
  min-width: 260px;
}

.compare-controls select,
.compare-apply-controls select {
  width: 100%;
}

.compare-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  padding: 14px;
}

.compare-card {
  display: grid;
  gap: 10px;
  align-content: start;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #ffffff;
}

.compare-card h3,
.compare-card p,
.compare-card ul {
  margin: 0;
}

.compare-card p,
.compare-card li {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.compare-card ul {
  display: grid;
  gap: 3px;
  padding-left: 17px;
}

.compare-mini-page {
  height: 300px;
  overflow: hidden;
  padding: 22px 26px;
  border: 1px solid #d8d4ca;
  background: #fffefb;
  color: #161616;
  font-family: var(--compare-font, Georgia, serif);
  font-size: var(--compare-size, 11px);
  line-height: var(--compare-line, 1.3);
}

.compare-mini-page h1,
.compare-mini-page h2,
.compare-mini-page h3 {
  margin: 0 0 12px;
  font-family: Arial, Helvetica, sans-serif;
  line-height: 1.2;
}

.compare-mini-page h1 {
  text-align: center;
  font-size: 18px;
}

.compare-mini-page h2,
.compare-mini-page h3 {
  font-size: 15px;
}

.compare-mini-page p {
  margin: 0 0 var(--compare-gap, 8px);
}

.compare-mini-page ul,
.compare-mini-page ol {
  margin: 0 0 8px 18px;
  padding: 0;
}

.compare-mini-page blockquote {
  margin: 8px 0;
  padding-left: 10px;
  border-left: 3px solid var(--accent);
  color: #363f3c;
}

.compare-mini-page .book-image {
  max-height: 120px;
  overflow: hidden;
}

.compare-mini-page .book-image img {
  max-height: 90px;
}

.compare-mini-page.layout-reflection-light {
  text-align: left;
}

.compare-mini-page.layout-reflection-light .standalone,
.compare-mini-page.layout-reflection-deep .standalone {
  margin: 18px 0;
  text-align: center;
}

.compare-mini-page.layout-reflection-deep h1,
.compare-mini-page.layout-reflection-deep h2,
.compare-mini-page.layout-reflection-deep h3 {
  text-align: center;
  font-weight: 400;
}

.compare-mini-page.layout-story p {
  margin-bottom: 2px;
  text-indent: 18px;
}

.compare-mini-page.layout-story h1,
.compare-mini-page.layout-story h2,
.compare-mini-page.layout-story h3 {
  text-align: center;
  text-transform: uppercase;
}

.compare-mini-page.layout-conversation p {
  margin-bottom: 10px;
}

.compare-mini-page.layout-workbook p:nth-of-type(2),
.compare-mini-page.layout-workbook p:nth-of-type(4) {
  padding: 8px;
  border-left: 3px solid var(--accent);
  background: #eef6f3;
}

.compare-apply-panel {
  display: grid;
  gap: 10px;
}

.compare-apply-controls {
  max-width: 280px;
}

.compare-apply-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.improve-notice {
  margin: 14px;
  padding: 10px 12px;
  border: 1px solid #ead8b8;
  border-radius: 8px;
  background: #fff7e8;
  color: #6d4a13;
}

.improve-body {
  display: grid;
  grid-template-columns: minmax(260px, 0.8fr) minmax(260px, 1fr);
  gap: 12px;
  padding: 14px;
  border-bottom: 1px solid var(--line);
}

.improve-options,
.improve-summary,
.improve-preview-grid section {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  padding: 12px;
}

.improve-options {
  display: grid;
  gap: 9px;
}

.improve-options h3,
.improve-summary h3,
.improve-preview-grid h3 {
  margin: 0;
}

.improve-options label {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--ink);
  font-size: 13px;
}

.improve-summary ul {
  display: grid;
  gap: 5px;
  min-height: 80px;
  margin: 10px 0 0;
  padding-left: 18px;
  color: var(--muted);
  font-size: 13px;
}

.improve-preview-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  padding: 14px;
}

.chapter-preview {
  height: 360px;
  overflow: auto;
  margin-top: 10px;
  padding: 18px;
  border: 1px solid #d8d4ca;
  background: #fffefb;
  color: #161616;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 14px;
  line-height: 1.45;
}

.chapter-preview h1,
.chapter-preview h2,
.chapter-preview h3 {
  margin: 0 0 12px;
  font-family: Arial, Helvetica, sans-serif;
  line-height: 1.2;
}

.chapter-preview p,
.chapter-preview blockquote {
  margin: 0 0 11px;
}

.chapter-preview blockquote {
  padding-left: 12px;
  border-left: 3px solid var(--accent);
}

.chapter-preview .reflection-pause {
  text-align: center;
  color: var(--accent-dark);
}

.improve-actions {
  padding: 0 14px 14px;
}

.stats-body {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  padding: 14px;
}

.stats-section {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  padding: 12px;
}

.stats-section h3,
.stats-section p {
  margin: 0;
}

.stats-wide {
  grid-column: 1 / -1;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-top: 10px;
}

.stat-tile {
  padding: 9px;
  border: 1px solid #ece7dd;
  border-radius: 8px;
  background: #fbfaf6;
}

.stat-tile span {
  display: block;
  color: var(--muted);
  font-size: 11px;
}

.stat-tile strong {
  display: block;
  margin-top: 3px;
  font-size: 18px;
}

.stats-goals,
.stats-heading-row {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  justify-content: space-between;
  gap: 8px;
  margin-top: 10px;
}

.stats-goals label {
  flex: 1 1 160px;
}

.stats-goals input {
  width: 100%;
}

.progress-track {
  height: 12px;
  margin: 12px 0 8px;
  overflow: hidden;
  border-radius: 999px;
  background: #e7e2d8;
}

.progress-track span {
  display: block;
  width: 0%;
  height: 100%;
  background: var(--accent);
}

.chapter-stats-list,
.chapter-balance-graph {
  display: grid;
  gap: 8px;
  margin-top: 10px;
}

.chapter-stat-row,
.chapter-balance-row {
  display: grid;
  grid-template-columns: minmax(120px, 1fr) auto;
  gap: 10px;
  align-items: center;
  padding: 8px;
  border: 1px solid #ece7dd;
  border-radius: 8px;
  background: #fbfaf6;
}

.chapter-stat-row strong,
.chapter-stat-row span,
.chapter-balance-row strong,
.chapter-balance-row span {
  display: block;
}

.chapter-stat-row span,
.chapter-balance-row span {
  color: var(--muted);
  font-size: 12px;
}

.balance-bar {
  min-width: 160px;
  height: 12px;
  overflow: hidden;
  border-radius: 999px;
  background: #e7e2d8;
}

.balance-bar span {
  height: 100%;
  background: var(--accent);
}

.future-metrics {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.future-metrics span {
  padding: 6px 9px;
  border: 1px dashed #c9c2b6;
  border-radius: 999px;
  color: var(--muted);
  font-size: 12px;
}

.stats-actions {
  padding: 0 14px 14px;
}

.find-body {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  padding: 14px;
  border-bottom: 1px solid var(--line);
}

.find-body label:nth-child(3),
.find-options,
#findStatus {
  grid-column: 1 / -1;
}

.find-body input,
.find-body select {
  width: 100%;
}

.find-options {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.find-options label {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--ink);
}

.find-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
  padding: 14px;
}

.find-match {
  background: #fff3a3;
  border-radius: 2px;
}

.find-match.current {
  background: #f6b94b;
  box-shadow: 0 0 0 2px rgba(246, 185, 75, 0.28);
}

.kdp-score-panel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px;
  border-bottom: 1px solid var(--line);
}

.kdp-score-panel > div {
  display: flex;
  align-items: center;
  gap: 12px;
}

.kdp-score-badge {
  min-width: 78px;
  min-height: 54px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  background: var(--accent);
  color: #ffffff;
  font-size: 24px;
  font-weight: 800;
}

.kdp-score-badge.review {
  background: #b7791f;
}

.kdp-score-badge.error {
  background: var(--danger);
}

.kdp-issue-layout {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  padding: 14px;
}

.kdp-issue-layout section,
.kdp-autofix-placeholders {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  padding: 12px;
}

.kdp-issue-layout h3,
.kdp-autofix-placeholders h3 {
  margin: 0 0 10px;
}

.kdp-issue-list {
  display: grid;
  gap: 8px;
}

.kdp-issue-card {
  display: grid;
  gap: 6px;
  padding: 9px;
  border: 1px solid #ece7dd;
  border-left-width: 4px;
  border-radius: 8px;
  background: #fbfaf6;
}

.kdp-issue-card.pass {
  border-left-color: var(--accent);
}

.kdp-issue-card.warning {
  border-left-color: #b7791f;
}

.kdp-issue-card.error {
  border-left-color: var(--danger);
}

.kdp-issue-card strong,
.kdp-issue-card span,
.kdp-issue-card p {
  margin: 0;
}

.kdp-issue-card span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
}

.kdp-issue-card p {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.kdp-issue-card button {
  justify-self: start;
  min-height: 28px;
  font-size: 12px;
}

.kdp-autofix-placeholders {
  margin: 0 14px 14px;
}

.kdp-autofix-placeholders button {
  margin: 0 6px 6px 0;
}

@media (max-width: 1180px) {
  .compare-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 760px) {
  .compare-grid {
    grid-template-columns: 1fr;
  }

  .compare-header {
    display: grid;
  }

  .improve-body,
  .improve-preview-grid,
  .stats-body,
  .kdp-issue-layout {
    grid-template-columns: 1fr;
  }
}

.preview-panel {
  min-height: calc(100vh - 118px);
}

.preview-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 8px;
  margin-bottom: 10px;
}

#previewEditToggle[aria-pressed="true"] {
  border-color: var(--accent-dark);
  background: var(--accent);
  color: #ffffff;
  font-weight: 700;
}

.preview-edit-banner {
  display: grid;
  gap: 3px;
  margin: 0 0 10px;
  padding: 10px 12px;
  border: 1px solid #8fc7bd;
  border-radius: 8px;
  background: #e8f7f3;
  color: #174d45;
  font-size: 13px;
}

.page-jump {
  display: flex;
  align-items: center;
  gap: 6px;
}

.page-jump span {
  margin: 0;
}

.page-jump input {
  width: 76px;
}

.zoom-level {
  min-width: 48px;
  min-height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #ffffff;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.preview-trim-label {
  min-height: 34px;
  display: inline-flex;
  align-items: center;
  padding: 0 10px;
  border: 1px solid #7da8bd;
  border-radius: 6px;
  background: #eef6fb;
  color: #183f58;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.preview-stage {
  min-height: calc(100vh - 190px);
  overflow: auto;
  display: grid;
  place-items: start center;
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #e8e4db;
}

.book-page {
  position: relative;
  width: calc(var(--page-width) * var(--preview-zoom));
  height: calc(var(--page-height) * var(--preview-zoom));
  min-height: calc(var(--page-height) * var(--preview-zoom));
  overflow: hidden;
  padding: calc(var(--page-margin-top) * var(--preview-zoom)) calc(var(--page-margin-side) * var(--preview-zoom)) calc(var(--page-margin-bottom) * var(--preview-zoom));
  background: #fffefb;
  box-shadow: 0 22px 50px rgba(39, 39, 34, 0.22);
  font-family: var(--page-font);
  font-size: calc(var(--page-font-size) * var(--preview-zoom));
  line-height: var(--page-line-height);
  color: #161616;
}

.page-content p,
.page-content h1,
.page-content h2,
.page-content blockquote {
  white-space: pre-wrap;
}

.page-content {
  height: calc((var(--page-height) - var(--page-margin-top) - var(--page-margin-bottom)) * var(--preview-zoom));
  max-height: calc((var(--page-height) - var(--page-margin-top) - var(--page-margin-bottom)) * var(--preview-zoom));
  overflow: hidden;
}

.preview-edit-mode [contenteditable="true"] {
  cursor: text;
  border-radius: 3px;
}

.preview-edit-mode [contenteditable="true"]:hover {
  outline: 1px dashed #94a3b8;
}

.preview-edit-mode [contenteditable="true"]:focus {
  outline: 2px solid #3b82f6;
  outline-offset: 2px;
}

.preview-edit-mode [data-preview-locked] {
  cursor: not-allowed;
}

.preview-edit-mode [data-preview-locked]:hover {
  outline: 1px dashed #d09a45;
}

.page-header,
.page-footer {
  position: absolute;
  left: calc(var(--page-margin-side) * var(--preview-zoom));
  right: calc(var(--page-margin-side) * var(--preview-zoom));
  color: #66635e;
  font-family: Arial, Helvetica, sans-serif;
  font-size: calc(8pt * var(--preview-zoom));
}

.page-header {
  top: calc(0.34in * var(--preview-zoom));
}

.page-footer {
  bottom: calc(0.34in * var(--preview-zoom));
  text-align: center;
}

.page-footer.outside,
.page-header.outside {
  text-align: right;
}

.page-content h1,
.page-content h2 {
  margin: 0 0 calc(0.22in * var(--preview-zoom));
  font-family: Arial, Helvetica, sans-serif;
  line-height: 1.2;
}

.page-content h1 {
  font-size: calc(22pt * var(--preview-zoom));
  text-align: center;
}

.page-content h2 {
  font-size: calc(17pt * var(--preview-zoom));
}

.page-content p,
.page-content li {
  margin: 0;
}

.page-content .continued-line {
  margin-top: 0 !important;
  margin-bottom: 0 !important;
  padding-top: 0 !important;
  padding-bottom: 0 !important;
}

.page-content blockquote {
  margin: 0;
  padding-left: calc(0.18in * var(--preview-zoom));
  border-left: calc(0.03in * var(--preview-zoom)) solid var(--accent);
  color: #363f3c;
}

.page-content .spacer-line {
  min-height: calc(var(--page-font-size) * var(--page-line-height) * var(--preview-zoom));
}

.page-content .standalone {
  text-align: center;
}

.page-content .align-left {
  text-align: left;
}

.page-content .align-center {
  text-align: center;
}

.page-content .align-right {
  text-align: right;
}

.page-content .align-justify {
  text-align: justify;
}

.preview-image {
  margin: 0;
}

.preview-image img {
  display: block;
  max-width: 100%;
  height: auto;
}

.preview-image.align-left img,
.preview-image.align-left figcaption {
  margin-right: auto;
}

.preview-image.align-center img,
.preview-image.align-center figcaption {
  margin-left: auto;
  margin-right: auto;
}

.preview-image.align-right img,
.preview-image.align-right figcaption {
  margin-left: auto;
}

.preview-image figcaption {
  margin-top: calc(0.08in * var(--preview-zoom));
  color: #5f635d;
  font-family: Arial, Helvetica, sans-serif;
  font-size: calc(8.5pt * var(--preview-zoom));
  text-align: center;
}

.toc-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 14px;
  border-bottom: 1px dotted #c6c0b8;
  margin-bottom: 0;
}

.layout-clean .chapter-title {
  margin-top: calc(0.25in * var(--preview-zoom));
  padding-bottom: calc(0.12in * var(--preview-zoom));
  border-bottom: 1px solid #d8d4ca;
}

.layout-reflection-light {
  --page-line-height: 1.3;
}

.layout-reflection-light .chapter-title {
  margin-top: calc(0.38in * var(--preview-zoom));
  font-weight: 500;
  text-align: center;
}

.layout-reflection-light p {
  margin-bottom: 0;
}

.layout-reflection-light .standalone {
  margin: calc(0.04in * var(--preview-zoom)) 0;
  text-align: center;
}

.layout-reflection-deep {
  --page-line-height: 1.35;
}

.layout-reflection-deep .chapter-title {
  margin-top: calc(0.42in * var(--preview-zoom));
  font-weight: 400;
  text-align: center;
}

.layout-reflection-deep p {
  margin-bottom: 0;
}

.layout-reflection-deep .standalone {
  margin: calc(0.2in * var(--preview-zoom)) 0;
  text-align: center;
}

.layout-story .chapter-title {
  margin-top: calc(0.5in * var(--preview-zoom));
  text-align: center;
  text-transform: uppercase;
}

.layout-story .story-line {
  margin-bottom: 0;
  text-indent: calc(0.22in * var(--preview-zoom));
}

.layout-story .story-line.continued {
  text-indent: 0;
}

.layout-story .chapter-title + .story-line,
.layout-story blockquote + .story-line {
  text-indent: 0;
}

.layout-workbook .chapter-title {
  margin-top: calc(0.22in * var(--preview-zoom));
  padding-bottom: calc(0.1in * var(--preview-zoom));
  border-bottom: 2px solid rgba(37, 111, 101, 0.28);
}

.layout-workbook .callout-line {
  margin: calc(0.04in * var(--preview-zoom)) 0;
  padding: calc(0.05in * var(--preview-zoom)) calc(0.08in * var(--preview-zoom));
  border-left: calc(0.04in * var(--preview-zoom)) solid var(--accent);
  background: #eef6f3;
}

.layout-conversation p {
  margin-bottom: calc(0.08in * var(--preview-zoom));
}

.layout-conversation .chapter-title {
  border-bottom: 1px solid #d8d4ca;
  padding-bottom: calc(0.1in * var(--preview-zoom));
}

.layout-compact p {
  margin-bottom: 0;
}

.layout-compact .chapter-title,
.layout-custom .chapter-title {
  text-align: center;
}

@media (max-width: 1380px) {
  .app-shell {
    grid-template-columns: 250px minmax(360px, 1fr) minmax(360px, 0.95fr);
  }

  .settings-panel {
    grid-column: 1 / 2;
    max-height: none;
  }

  .preview-panel {
    grid-column: 3 / 4;
    grid-row: 1 / span 2;
  }
}

@media (max-width: 980px) {
  .app-header,
  .book-meta,
  .app-shell {
    grid-template-columns: 1fr;
  }

  .structure-panel,
  .settings-panel,
  .preview-panel {
    position: static;
    max-height: none;
    grid-column: auto;
    grid-row: auto;
  }

  .section-options,
  .compact-settings {
    grid-template-columns: 1fr;
  }

  .editor {
    min-height: 460px;
    max-height: none;
  }
}
