/* Keep the workbench inside the viewport; only each column's content scrolls. */
body {
  height: 100vh;
  height: 100dvh;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  overflow: hidden;
}
header { height: 72px; flex-shrink: 0; padding: 0 12px; gap: 20px; }
.header-brand { display: flex; align-items: center; gap: 24px; min-width: 0; }
.brand { white-space: nowrap; flex-shrink: 0; }
.header-copy { padding-left: 24px; border-left: 1px solid var(--line); }
.header-copy h1 { margin: 0 0 5px; font-size: 17px; line-height: 1.3; font-weight: 650; white-space: nowrap; }
.header-copy p { margin: 0; font-size: 12px; line-height: 1.5; color: var(--muted); white-space: nowrap; }
header .step { margin-left: auto; font-size: 11px; letter-spacing: 0; white-space: nowrap; }
.top-actions { flex-shrink: 0; margin-left: auto; }
main {
  --settings-width: 240px;
  width: 100%;
  max-width: none;
  margin: 0;
  padding: 8px;
  min-height: 0;
  grid-template-columns: var(--settings-width) minmax(0, 1fr) minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr);
  gap: 6px;
  align-items: stretch;
}
body.settings-collapsed main { --settings-width: 56px; }
.panel { min-width: 0; min-height: 0; }
.settings { padding: 0; display: flex; flex-direction: column; }
.settings-head {
  height: 62px;
  flex: 0 0 62px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  border-bottom: 1px solid var(--line);
}
.settings-head strong { font-size: 15px; white-space: nowrap; }
#toggle-settings {
  width: 30px;
  height: 30px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: white;
  color: var(--green);
  font-size: 24px;
  line-height: 1;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}
.settings-content { padding: 23px 18px; overflow-y: auto; min-height: 0; flex: 1; }
.settings-content[hidden], .settings-help[hidden] { display: none; }
.settings-help { flex: 0 0 auto; padding: 14px 18px; border-top: 1px solid var(--line); background: #f9fbf8; }
.settings-help h3 { margin: 0 0 7px; font-size: 12px; font-weight: 600; color: #64736b; }
.settings-help p { margin: 0; font-size: 11px; line-height: 1.65; overflow-wrap: anywhere; }
.settings-help p + p { margin-top: 7px; }
.settings-rail { display: none; }
.settings-collapsed .settings-head { padding: 0; justify-content: center; }
.settings-collapsed .settings-head strong { display: none; }
.settings-collapsed .settings-rail {
  display: block;
  margin: 24px auto;
  writing-mode: vertical-rl;
  letter-spacing: 4px;
  color: var(--muted);
  font-size: 12px;
}
.editor-panel, .preview-panel { display: flex; flex-direction: column; }
.panel-head { flex: 0 0 62px; padding: 0 18px; }
.toolbar { flex: 0 0 auto; padding: 10px 12px; gap: 5px; }
.toolbar button { padding: 6px 9px; }
.editor-body { flex: 1 1 0; min-height: 100px; display: flex; flex-direction: column; padding: 18px 20px 0; }
.title-input { flex-shrink: 0; font-size: 20px; padding-bottom: 12px; }
.editor-hint { flex-shrink:0; margin:12px 0 0; font-size:12px; line-height:1.6; color:#718078; }
.editor-hint strong { font-weight:600; color:var(--green); }
.editor-body textarea { flex: 1 1 0; min-height: 0; resize: none; overflow-y: auto; padding-top: 14px; }
.editor-foot { flex: 0 0 auto; gap: 10px; padding: 12px 18px; }
.editor-foot span:last-child { text-align: right; }
.preview-wrap { flex: 1 1 0; min-height: 0; max-height: none; overflow-y: auto; padding: 22px 16px; }
.settings-content, .editor-body textarea, .preview-wrap { overscroll-behavior: contain; scrollbar-gutter: stable; }
.phone { min-height: 100%; }
@media (max-width: 1100px) {
  main { --settings-width: 216px; gap: 6px; padding: 8px; }
  .step { display: none; }
  .brand span { display: none; }
  .header-brand { gap: 18px; }
  .header-copy { padding-left: 18px; }
  .settings-content { padding: 18px 14px; }
  .settings-help { padding: 12px 14px; }
  .editor-foot span:last-child { display: none; }
  .preview-wrap { padding: 16px 10px; }
  #preview { padding: 24px 18px; }
}
@media (max-height: 700px) and (min-width: 721px) {
  header { height: 60px; }
  .header-copy h1 { font-size: 16px; margin-bottom: 3px; }
  .editor-body { padding-top: 12px; }
}
@media (min-width: 721px) and (max-width: 900px) {
  .saved { display: none; }
}
/* Narrow screens retain an accessible vertical arrangement. */
@media (max-width: 720px) {
  body { height: auto; min-height: 100dvh; display: block; overflow: auto; }
  header { height: auto; min-height: 72px; padding: 16px 12px; gap: 16px; flex-wrap: wrap; }
  .saved { display: none; }
  .header-brand { width: 100%; }
  .header-copy h1 { font-size: 16px; }
  main, body.settings-collapsed main { display: flex; flex-direction: column; padding: 8px; }
  .settings-content { max-height: 45vh; }
  .settings-head { height: 50px; flex-basis: 50px; }
  .settings-collapsed .settings-head { padding: 0 16px; justify-content: space-between; }
  .settings-collapsed .settings-head strong { display: block; }
  .settings-collapsed .settings-rail { display: none; }
  .theme { width: calc(33.33% - 4px); padding: 9px; vertical-align: top; }
  .theme small { display: none; }
  .field { display: inline-flex; margin: 10px 12px 10px 0; gap: 10px; }
  .divider { margin: 14px 0; }
  .editor-panel, .preview-panel { height: 680px; height: min(80dvh, 680px); min-height: 400px; }
}

/* Structured editing keeps its own scroll area inside the existing workbench. */
.rich-editor { flex: 1 1 0; min-height: 0; overflow-y: auto; padding: 14px 0; overscroll-behavior: contain; scrollbar-gutter: stable; }
.ProseMirror { position: relative; min-height: 100%; outline: none; line-height: 1.9; font-size: 14px; color: #526059; word-wrap: break-word; white-space: pre-wrap; white-space: break-spaces; font-variant-ligatures: none; }
.ProseMirror:focus-visible { outline: none; }
.ProseMirror p { margin: 0 0 18px; }
.ProseMirror h1, .ProseMirror h2 { font-size: 20px; margin: 24px 0 12px; color: var(--green); }
.ProseMirror h3 { font-size: 17px; margin: 20px 0 10px; color: var(--green); }
.ProseMirror blockquote { margin: 18px 0; border-left: 3px solid #a6bcae; padding: 8px 14px; background: #f6f8f4; }
.ProseMirror blockquote p:last-child, .ProseMirror li > p { margin-bottom: 0; }
.ProseMirror ul, .ProseMirror ol { padding-left: 25px; }
.ProseMirror li { position: relative; }
.ProseMirror pre { white-space: pre-wrap; padding: 10px; background: #f4f6f3; }
.ProseMirror a { color: var(--green); text-decoration: underline; }
.ProseMirror hr { border: 0; border-top: 1px solid var(--line); margin: 24px 0; }
.ProseMirror table { border-collapse: collapse; table-layout: fixed; width: 100%; margin: 18px 0; white-space: normal; }
.ProseMirror .tableWrapper { overflow-x: auto; margin: 18px 0; }
.ProseMirror .tableWrapper table { margin: 0; }
/* Paint the entire handle above the neighbouring header cell's background. */
.ProseMirror .column-resize-handle { position: absolute; right: -3px; top: 0; bottom: 0; width: 6px; background: #79a18b; pointer-events: none; z-index: 2; }
.ProseMirror.resize-cursor, .ProseMirror.resize-cursor * { cursor: col-resize !important; }
.ProseMirror .column-resize-dragging { background: #eef5ef; }
.ProseMirror td, .ProseMirror th { position: relative; vertical-align: top; border: 1px solid #dce3dd; padding: 8px; min-width: 40px; }
.ProseMirror th { background: #edf3ed; }
.ProseMirror td p, .ProseMirror th p { margin: 0; }
.ProseMirror .selectedCell:after { position: absolute; inset: 0; content: ''; background: #97bcaa40; pointer-events: none; }
.ProseMirror-selectednode { outline: 2px solid #97bcaa; }
.ProseMirror-hideselection *::selection { background: transparent; }
.ProseMirror-hideselection { caret-color: transparent; }
img.ProseMirror-separator { display: inline !important; border: 0 !important; margin: 0 !important; }
.formula-chip { display: inline-block; max-width: 100%; white-space: pre-wrap; word-break: break-word; background: #eef4ee; border: 1px solid #d5e2d6; border-radius: 5px; padding: 2px 7px; font-family: monospace; color: #38644e; cursor: pointer; }
div.formula-chip { display: block; text-align: center; margin: 18px 0; padding: 12px; }
.editor-image { margin: 18px 0; background: #f7f9f5; padding: 8px; border-radius: 5px; text-align: center; cursor: pointer; }
.editor-image img { display: block; max-width: 100%; max-height: 280px; margin: auto; }
.editor-image figcaption { font-size: 12px; color: var(--muted); margin-top: 6px; }
.editor-import { border: 1px solid var(--line); border-radius: 5px; background: #f9fbf8; color: #64736b; padding: 5px 8px; font-size: 11px; }
.toolbar button:disabled { opacity: .4; cursor: default; }
.toolbar button[aria-pressed=true] { background: #dcebdd; color: #244d3b; }
.table-tools { font-size: 12px; color: #4c6356; }
.table-tools summary { cursor: pointer; padding: 6px 9px; border-radius: 5px; background: #f5f7f3; }
.table-tools > div { display: flex; gap: 5px; flex-wrap: wrap; margin-top: 5px; }
dialog { width: min(560px, calc(100vw - 32px)); border: 1px solid var(--line); border-radius: 12px; padding: 24px; color: var(--ink); box-shadow: 0 20px 80px #24382e30; }
dialog::backdrop { background: #22332f66; }
dialog h2 { font-size: 18px; margin: 0 0 18px; }
dialog label { display: block; margin-bottom: 8px; font-size: 13px; }
dialog textarea, dialog input { width: 100%; border: 1px solid #d7dfd7; border-radius: 6px; padding: 10px; color: var(--ink); background: white; }
dialog textarea { min-height: 100px; resize: vertical; }
#markdown-source { min-height: 300px; font-family: monospace; line-height: 1.7; }
.markdown-tools { display: flex; justify-content: flex-end; gap: 8px; margin: 12px 0 8px; }
.markdown-tools .btn { padding: 7px 14px; }
.markdown-tools button:disabled { opacity: .5; cursor: wait; }
#markdown-status:empty { display: none; }
#dialog-value { margin-bottom: 12px; }
#dialog-error { color: #b34236; font-size: 12px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }
[hidden] { display: none !important; }

/* Device preview changes the reading canvas, without changing exported styles. */
.preview-controls { display: flex; align-items: center; gap: 10px; }
.preview-panel .panel-head { flex-wrap: wrap; align-content: center; gap: 4px 8px; }
.scroll-sync { border: 1px solid var(--line); border-radius: 6px; background: white; padding: 6px 8px; font-size: 11px; color: #7c8984; white-space: nowrap; }
.scroll-sync[aria-pressed=true] { background: #edf4ee; border-color: #aac5b2; color: var(--green); }
.preview-modes { display: flex; gap: 2px; padding: 3px; border: 1px solid var(--line); border-radius: 7px; background: #f5f7f3; }
.preview-modes button { border: 0; border-radius: 4px; background: transparent; color: #718078; padding: 5px 10px; font-size: 12px; }
.preview-modes button[aria-pressed=true] { background: var(--green); color: white; }
.preview-panel[data-mode=desktop] .phone { max-width: 720px; }
.preview-panel[data-mode=desktop] #preview { padding: 32px clamp(18px, 3vw, 36px); }
@media (max-width: 1100px) {
  .preview-controls { gap: 6px; }
  #preview-width { display: none; }
}

/* Compact visual choices keep all eight styles easy to scan. */
#themes { display:grid; grid-template-columns:repeat(2,minmax(0,1fr)); gap:6px; }
#themes .theme { width:100%; margin:0; padding:6px 8px; min-width:0; }
#themes .theme strong { font-size:12px; margin:0 0 5px; }
#themes .theme small { display:block; font-size:10px; line-height:1.6; }
.theme-mini { display:block; overflow:hidden; white-space:nowrap; }
@media(max-width:720px) { #themes { grid-template-columns:repeat(2,minmax(0,1fr)); } }
