/* WriteMind: warm paper, quiet controls, and a centered writing measure. */
:root {
  --paper: #f8f6f1; --paper-deep: #efede6; --paper-dark: #e3e0d6;
  --white: #fdfcf8; --ink: #353b34; --ink-soft: #50584d; --muted: #70756b;
  --line: #dedfd5; --accent: #65745b; --accent-soft: #e8ecdf;
  --green: #566d4b; --danger: #a14235;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --mono: "SFMono-Regular", Consolas, monospace;
  --shadow: 0 24px 90px rgba(37, 45, 30, .14);
}
* { box-sizing: border-box; }
html, body, #scribe-root { height: 100%; }
html, body { background: var(--paper); }
body { margin: 0; overflow: hidden; color: var(--ink); font: 16px/1.5 var(--sans); -webkit-font-smoothing: antialiased; }
button, input, textarea, select { font: inherit; color: inherit; }
button, summary { cursor: pointer; }
button { transition: background .18s ease, color .18s ease; }
[hidden] { display: none !important; }
::selection { background: #dce4d0; }
.sr-only { position: absolute !important; width: 1px !important; height: 1px !important; padding: 0 !important; margin: -1px !important; overflow: hidden !important; clip: rect(0,0,0,0) !important; white-space: nowrap !important; border: 0 !important; }
.skip-link { position: fixed; left: 12px; top: 10px; z-index: 300; transform: translateY(-160%); padding: 8px 13px; background: var(--ink); color: var(--white); }
.skip-link:focus { transform: none; }
:where(button, input, select, summary, a, [tabindex]):focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
#app { height: 100dvh; display: flex; flex-direction: column; background: var(--paper); isolation: isolate; }
.topbar { min-height: 88px; padding: 16px 40px; display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 8px 20px; flex: none; z-index: 40; }
.topbar-primary, .topbar-actions { display: flex; align-items: center; gap: 16px; min-width: 0; }
.topbar-actions { gap: 6px; }
.brand { margin-right: 12px; color: var(--ink); text-decoration: none; }
.brand-name { font: 500 25px/1 var(--serif); letter-spacing: -.04em; }
.quiet-button, .icon-button { display: inline-flex; align-items: center; justify-content: center; min-height: 44px; padding: 0 13px; border: 0; border-radius: 6px; background: transparent; color: var(--muted); font: 14px/1.2 var(--sans); }
.icon-button { width: 44px; padding: 0; flex: none; font-size: 23px; }
.quiet-button:hover, .icon-button:hover, .quiet-button[aria-expanded="true"] { background: var(--paper-deep); color: var(--ink); }
.format-toggle { font: 21px/1 var(--serif); }
.tools-menu { position: relative; }
.tools-menu summary { list-style: none; }
.tools-menu summary::-webkit-details-marker { display: none; }
.tools-popover { position: absolute; right: 0; top: calc(100% + 8px); width: 224px; max-height: calc(100dvh - 100px); overflow-y: auto; padding: 8px; border: 1px solid var(--line); border-radius: 12px; background: var(--white); box-shadow: var(--shadow); }
.tools-popover button { width: 100%; min-height: 44px; padding: 10px 12px; border: 0; border-radius: 6px; background: transparent; text-align: left; font-size: 14px; color: var(--ink-soft); }
.tools-popover button:hover, .tools-popover button.active { background: var(--paper-deep); }
.tools-popover .grade-button { display: flex; justify-content: space-between; gap: 12px; }
.tools-popover .danger-action { color: var(--danger); }
.tools-popover hr { margin: 6px 10px; border: 0; border-top: 1px solid var(--line); }
.workspace { flex: 1; display: flex; min-height: 0; }
.writing-area { flex: 1; min-width: 0; min-height: 0; display: flex; flex-direction: column; }
.panes { flex: 1; min-height: 0; min-width: 0; display: flex; position: relative; }
.editor-pane, .second-editor-pane, .coach-pane { min-width: 0; min-height: 0; display: flex; flex-direction: column; }
.editor-pane { flex: 1; }
.second-editor-pane { flex: 1; border-left: 1px solid var(--line); }
.coach-pane { flex: 0 0 min(360px, 36vw); overflow: hidden; border-left: 1px solid var(--line); background: var(--paper-deep); }
.document-heading { flex: none; padding: clamp(24px, 6vh, 72px) max(32px, calc((100% - 680px) / 2)) 22px; }
.document-title { display: block; width: 100%; min-width: 0; padding: 4px 0; border: 0; background: transparent; color: var(--ink); font: 400 clamp(28px, 3vw, 36px)/1.3 var(--serif); letter-spacing: -.035em; text-align: left; overflow-wrap: anywhere; }
.document-title:hover { color: var(--accent); }
.editor-toolbar { align-self: center; display: flex; flex: none; gap: 4px; margin: 8px 20px 0; padding: 4px 8px; border: 1px solid var(--line); border-radius: 10px; background: var(--white); max-width: calc(100% - 40px); overflow-x: auto; }
.editor-toolbar button { width: 44px; height: 44px; flex: none; border: 0; border-radius: 6px; background: transparent; color: var(--ink-soft); font: 16px/1 var(--serif); }
.editor-toolbar button:hover { background: var(--paper-deep); }
#editor, #editorSecondary { flex: 1; width: 100%; min-height: 0; overflow-y: auto; padding: 0 max(32px, calc((100% - 680px) / 2)) 24vh; border: 0; outline: 0; background: var(--paper); color: var(--ink); caret-color: var(--accent); white-space: pre-wrap; overflow-wrap: anywhere; font: 21px/1.85 var(--serif); letter-spacing: .003em; scrollbar-width: thin; scrollbar-color: var(--line) transparent; scroll-padding-block: 30px; }
#editor:focus-visible, #editorSecondary:focus-visible { box-shadow: inset 2px 0 var(--line); }
#editorSecondary { padding-top: 28px; }
.rich-editor:empty::before { content: attr(data-placeholder); color: var(--muted); pointer-events: none; }
.second-editor-header { min-height: 68px; padding: 10px 18px; display: flex; flex-wrap: wrap; align-items: center; gap: 8px; border-bottom: 1px solid var(--line); }
.second-editor-header > label { color: var(--muted); font-size: 12px; }
.second-editor-header select { flex: 1; min-width: 100px; max-width: 100%; min-height: 44px; padding: 8px; border: 1px solid var(--line); border-radius: 6px; background: var(--paper); }
.text-action { min-height: 44px; padding: 8px; border: 0; background: transparent; color: var(--muted); font-size: 14px; }
.statusbar { min-height: 60px; padding: 12px 40px max(12px, env(safe-area-inset-bottom)); display: flex; flex: none; align-items: center; gap: 20px; color: var(--muted); font: 12px/1.5 var(--sans); }
.status-spacer { flex: 1; }
#statChars { display: none; }
.keyboard-hint { font: italic 14px/1.5 var(--serif); }
.exit-focus { position: fixed; top: max(20px, env(safe-area-inset-top)); right: 28px; z-index: 60; gap: 12px; background: var(--paper); }
#app.focus-mode .topbar, #app.focus-mode .statusbar, #app.focus-mode .editor-toolbar { display: none; }
#app.focus-mode .document-heading { padding-top: clamp(80px, 13vh, 150px); }
#app:fullscreen { background: var(--paper); }
.library-dialog { width: min(580px, calc(100vw - 32px)); max-height: min(720px, calc(100dvh - 48px)); padding: 24px; border: 1px solid var(--line); border-radius: 16px; color: var(--ink); background: var(--paper); box-shadow: var(--shadow); }
.library-dialog[open] { display: flex; flex-direction: column; }
.library-dialog::backdrop { background: rgba(37,45,30,.22); backdrop-filter: blur(5px); }
.sidebar-header { display: flex; align-items: center; justify-content: space-between; padding-bottom: 20px; }
.sidebar-header > div { display: flex; align-items: center; gap: 12px; }
.sidebar-header h2 { margin: 0; font: 400 28px/1.3 var(--serif); letter-spacing: -.025em; }
.document-count { color: var(--muted); font-size: 13px; }
.search-box { display: flex; align-items: center; gap: 12px; flex: none; min-height: 48px; padding: 0 14px; margin-bottom: 16px; border: 1px solid var(--line); border-radius: 8px; background: var(--white); }
.search-box span { font-size: 24px; }
.search-box input { width: 100%; min-width: 0; border: 0; background: transparent; font-size: 16px; }
.document-list { flex: 1; min-height: 50px; overflow-y: auto; }
.document-item { width: 100%; padding: 15px 12px; display: flex; gap: 12px; border: 0; border-radius: 8px; background: transparent; color: var(--ink-soft); text-align: left; }
.document-item:hover, .document-row.active .document-item { background: var(--accent-soft); }
.document-row.secondary:not(.active) .document-item { box-shadow: inset 2px 0 var(--accent); }
.document-icon { display: none; }
.document-labels { display: flex; flex-direction: column; min-width: 0; gap: 5px; }
.document-name { font: 500 19px/1.3 var(--serif); overflow-wrap: anywhere; }
.document-row-meta { color: var(--muted); font-size: 12px; }
.empty-search { padding: 20px 0; color: var(--muted); font-size: 14px; }
.new-document { flex: none; margin: 18px 0; min-height: 46px; border: 1px solid var(--line); border-radius: 8px; background: transparent; font-size: 14px; }
.new-document:hover { background: var(--accent-soft); }
.sidebar-footer { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; padding-top: 12px; border-top: 1px solid var(--line); }
.local-message { color: var(--muted); font-size: 12px; }
.local-dot { display: none; }
.data-actions { display: flex; gap: 12px; }
.data-actions button { min-height: 44px; padding: 0; border: 0; background: transparent; font-size: 14px; }
.eyebrow { color: var(--muted); font: 12px/1.5 var(--sans); }
.rich-editor p { margin: 0 0 1em; }
.rich-editor h1, .rich-editor h2, .rich-editor h3 { margin: 1.2em 0 0.55em; font-weight: 650; line-height: 1.18; letter-spacing: -0.02em; }
.rich-editor h1:first-child, .rich-editor h2:first-child, .rich-editor h3:first-child { margin-top: 0; }
.rich-editor h1 { font-size: 2em; }
.rich-editor h2 { font-size: 1.48em; }
.rich-editor h3 { font-size: 1.18em; }
.rich-editor blockquote { margin: 1.2em 0; padding: 0.1em 1em; border-left: 3px solid var(--accent); color: var(--ink-soft); font-style: italic; }
.rich-editor ul, .rich-editor ol { margin: 0 0 1em; padding-left: 1.5em; }
.rich-editor li[data-task] { position: relative; list-style: none; }
.rich-editor li[data-task] > input[type="checkbox"] { position: absolute; left: -1.45em; top: calc((1lh - .9em) / 2); width: .9em; height: .9em; margin: 0; padding: 0; accent-color: var(--accent); cursor: pointer; font: inherit; }
.rich-editor li[data-task]:has(> input:checked) { color: var(--muted); text-decoration: line-through; }
.rich-editor mark { border-radius: 2px; padding: .04em 0; box-decoration-break: clone; -webkit-box-decoration-break: clone; }
.rich-editor mark::selection, .rich-editor mark *::selection { background: transparent; }
.rich-editor a { color: var(--accent); text-underline-offset: 3px; }
.rich-editor code { padding: 0.1em 0.35em; border: 1px solid var(--line); border-radius: 5px; background: var(--paper-deep); font: 0.8em var(--mono); }
.rich-editor hr { margin: 1.5em 0; border: 0; border-top: 1px solid var(--line); }
.coach-header { padding: 20px 19px 16px; display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; border-bottom: 1px solid var(--line); background: var(--white); }
.coach-header h2 { margin: 5px 0 2px; font: 650 30px/1.1 var(--serif); letter-spacing: -0.03em; }
.coach-header p { margin: 6px 0 0; color: var(--muted); font-size: 11px; line-height: 1.5; }
.coach-header .icon-button { width: 30px; height: 30px; flex: none; }
.coach-stats { min-height: 42px; padding: 0 17px; display: flex; align-items: center; gap: 13px; border-bottom: 1px solid var(--line); background: var(--white); color: var(--muted); font: 8.5px/1 var(--mono); }
.coach-stats strong { color: var(--ink); font-weight: 700; }
.coach-summary { padding: 12px; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 7px; border-bottom: 1px solid var(--line); }
.coach-summary-item { min-height: 54px; padding: 9px 10px; display: flex; flex-direction: column; justify-content: center; gap: 2px; border: 1px solid var(--line); border-radius: 9px; background: var(--white); }
.coach-summary-item strong { font: 700 18px/1 var(--serif); }
.coach-summary-item span { color: var(--muted); font: 8px/1.2 var(--mono); text-transform: uppercase; }
.coach-summary-item.red { border-left: 4px solid #e46a61; }
.coach-summary-item.yellow { border-left: 4px solid #e7bd58; }
.coach-summary-item.spelling { border-left: 4px solid #d44848; }
.coach-summary-item.green { border-left: 4px solid #55a86f; }
.coach-summary-item.orange { border-left: 4px solid #df8a4b; }
.coach-summary-item.blue { border-left: 4px solid #5aa3cf; }
.coach-summary-item.purple { border-left: 4px solid #a985c7; }
.coach-issues { flex: 1; overflow-y: auto; padding: 11px 12px 20px; }
.coach-issue { margin-bottom: 8px; overflow: hidden; border: 1px solid var(--line); border-left-width: 4px; border-radius: 10px; background: var(--white); }
.coach-issue.issue-very-hard { border-left-color: #e46a61; background: #fff5f3; }
.coach-issue.issue-hard { border-left-color: #e7bd58; background: #fffaf0; }
.coach-issue.issue-spelling { border-left-color: #d44848; background: #fff5f5; }
.coach-issue.issue-grammar { border-left-color: #55a86f; background: #f2fbf4; }
.coach-issue.issue-unclear { border-left-color: #df8a4b; background: #fff7f0; }
.coach-issue.issue-weakener { border-left-color: #5aa3cf; background: #f3faff; }
.coach-issue.issue-simpler { border-left-color: #a985c7; background: #faf6ff; }
.coach-issue-open { width: 100%; padding: 11px 12px 9px; display: flex; flex-direction: column; gap: 5px; border: 0; background: transparent; color: var(--ink); text-align: left; }
.coach-issue-open:hover { background: rgba(255, 255, 255, 0.55); }
.coach-issue-label { color: var(--muted); font: 8px/1.2 var(--mono); letter-spacing: 0.06em; text-transform: uppercase; }
.coach-issue-open strong { font: 600 13px/1.4 var(--serif); }
.coach-issue-advice { color: var(--ink-soft); font-size: 10.5px; line-height: 1.45; }
.coach-fix { margin: 0 10px 10px; min-height: 28px; padding: 0 9px; border: 1px solid var(--line); border-radius: 7px; background: var(--white); color: var(--ink); font-size: 10px; font-weight: 700; }
.coach-fix:hover { border-color: var(--ink); }
.coach-clear { min-height: 120px; padding: 22px 16px; display: flex; align-items: flex-start; gap: 11px; border: 1px solid var(--line); border-radius: 11px; background: var(--white); }
.coach-clear > span { width: 26px; height: 26px; flex: none; display: grid; place-items: center; border-radius: 50%; background: #e7f3e9; color: var(--green); font-weight: 800; }
.coach-clear strong { font: 600 15px/1.3 var(--serif); }
.coach-clear p { margin: 5px 0 0; color: var(--muted); font-size: 11px; line-height: 1.5; }

::highlight(scribe-very-hard) { background: rgba(228, 106, 97, 0.4); }
::highlight(scribe-hard) { background: rgba(231, 189, 88, 0.42); }
::highlight(scribe-spelling) { text-decoration: underline wavy #d43f3f 1.5px; text-underline-offset: 3px; background: rgba(212, 63, 63, 0.08); }
::highlight(scribe-grammar) { background: rgba(85, 168, 111, 0.22); text-decoration: underline wavy #3f8d58; }
::highlight(scribe-unclear) { background: rgba(223, 138, 75, 0.3); }
::highlight(scribe-weakener) { background: rgba(90, 163, 207, 0.3); }
::highlight(scribe-simpler) { background: rgba(169, 133, 199, 0.3); }
.rich-editor::spelling-error { text-decoration: underline wavy #d43f3f 1.5px; text-underline-offset: 3px; background: rgba(212, 63, 63, 0.06); }
.rich-editor::grammar-error { text-decoration: underline wavy #3f8d58 1.5px; text-underline-offset: 3px; }

.template-dialog { width: min(690px, calc(100vw - 32px)); max-height: calc(100dvh - 32px); padding: 0; border: 1px solid var(--ink); border-radius: 18px; background: var(--paper); color: var(--ink); box-shadow: var(--shadow); }
.template-dialog::backdrop { background: rgba(28, 27, 25, 0.36); backdrop-filter: blur(2px); }
.template-dialog form { padding: 24px; }
.dialog-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; }
.dialog-header h2 { margin: 5px 0 0; font: 600 27px/1.1 var(--serif); letter-spacing: -0.02em; }
.template-grid { margin-top: 21px; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px; }
.template-card { min-height: 92px; padding: 14px; display: flex; align-items: center; gap: 13px; border: 1px solid var(--line); border-radius: 12px; background: var(--white); text-align: left; }
.template-card:hover { border-color: var(--ink); transform: translateY(-1px); box-shadow: 0 8px 22px rgba(48, 38, 28, 0.08); }
.template-icon { width: 40px; height: 40px; flex: none; display: grid; place-items: center; border-radius: 11px; background: var(--accent-soft); color: #78391f; font: 18px/1 var(--serif); }
.template-copy { display: flex; flex-direction: column; gap: 4px; }
.template-copy strong { font: 600 16px/1.2 var(--serif); }
.template-copy > span { color: var(--muted); font-size: 11px; line-height: 1.4; }
.toast { position: fixed; z-index: 250; left: 50%; bottom: 48px; transform: translateX(-50%); padding: 9px 13px; border: 1px solid #45413c; border-radius: 9px; background: var(--ink); color: var(--paper); box-shadow: var(--shadow); font-size: 11px; font-weight: 650; }


/* Keep secondary tools readable without competing with the page. */
.coach-header p, .coach-stats, .coach-summary-item span, .coach-issue-label, .coach-issue-advice, .coach-fix { font-size: 13px; line-height: 1.5; }
.coach-header .icon-button { width: 44px; height: 44px; }
.coach-fix { min-height: 44px; }
.template-dialog { border-color: var(--line); }
.template-copy > span { font-size: 14px; }
.template-icon { color: var(--accent); }
.toast { max-width: calc(100vw - 32px); font-size: 14px; line-height: 1.5; }
@media (max-width: 820px) {
  .topbar { min-height: 76px; padding: 12px 24px; }
  .topbar-primary { gap: 4px; }
  .brand { margin-right: 8px; }
  .panes { flex-direction: column; }
  .second-editor-pane, .coach-pane { flex: 1 1 45%; border-left: 0; border-top: 1px solid var(--line); }
  .panes[data-split="true"] .editor-pane, .panes[data-coach="true"] .editor-pane { flex: 1 1 55%; }
  .document-heading { padding: 30px max(24px, calc((100% - 620px) / 2)) 18px; }
  #editor, #editorSecondary { padding-inline: max(24px, calc((100% - 620px) / 2)); }
  .statusbar { padding-inline: 24px; }
}
@media (max-width: 560px) {
  .topbar { padding-inline: 14px; gap: 4px; }
  .topbar-primary, .topbar-actions { gap: 0; }
  .brand { margin-right: 8px; }
  .brand-name { font-size: 23px; }
  .quiet-button { padding-inline: 10px; }
  .icon-button { width: 44px; }
  .document-heading { padding-top: 26px; }
  #editor, #editorSecondary { font-size: 19px; line-height: 1.8; }
  .statusbar { min-height: 48px; gap: 16px; }
  .keyboard-hint { display: none; }
  .library-dialog { padding: 20px; }
  .template-grid { grid-template-columns: 1fr; }
  .template-dialog form { padding: 20px; }
  .second-editor-header > label { display: none; }
  .exit-focus { right: 14px; }
}
@media (max-width: 360px) { .brand { margin-right: 0; } .brand-name { font-size: 20px; } .quiet-button { padding-inline: 7px; } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; } }

/* Insert and music are on demand; the writing canvas stays unchanged. */
.media-dialog { width: min(460px, calc(100vw - 32px)); max-height: calc(100dvh - 32px); overflow-y: auto; padding: 24px; border: 1px solid var(--line); border-radius: 16px; color: var(--ink); background: var(--paper); box-shadow: var(--shadow); }
.media-dialog::backdrop { background: rgba(37,45,30,.22); backdrop-filter: blur(4px); }
.media-dialog .dialog-header { align-items: center; margin-bottom: 20px; }
.media-dialog h2 { font: 400 27px/1.2 var(--serif); margin: 0; }
.media-dialog label { display: block; font-size: 14px; margin: 16px 0 7px; }
.media-dialog input:not([type="range"]), .media-dialog select { width: 100%; min-height: 46px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 7px; background: var(--white); font-size: 16px; }
.media-dialog input[type="range"] { width: 100%; min-height: 44px; accent-color: var(--accent); }
.field-help { color: var(--muted); font-size: 13px; line-height: 1.5; }
.field-error { color: var(--danger); font-size: 14px; }
.action-button { min-height: 46px; margin-top: 20px; padding: 10px 18px; border: 0; border-radius: 7px; background: var(--accent); color: white; font-size: 14px; }
.action-button:hover { background: var(--ink-soft); }
.action-button:disabled, .upload-zone:disabled { opacity: .6; cursor: wait; }
.upload-zone { width: 100%; min-height: 130px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 7px; padding: 16px; border: 1px dashed var(--accent); border-radius: 10px; background: var(--accent-soft); }
.upload-zone strong { font: 400 23px/1.3 var(--serif); }
.upload-zone span, .upload-zone small { font-size: 13px; color: var(--ink-soft); }
.upload-zone:hover, .upload-zone.dragging { background: var(--paper-dark); }
.dialog-actions, .volume-label { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.volume-label output { padding-top: 10px; color: var(--muted); font-size: 13px; }
.danger-action { color: var(--danger); }
.focus-sound { display: none; position: fixed; top: max(20px, env(safe-area-inset-top)); left: 24px; z-index: 60; background: var(--paper); }
#app.focus-mode .focus-sound { display: inline-flex; }
#soundToggle.playing, #focusSound.playing { color: var(--accent); }
.storage-warning { position: fixed; bottom: 12px; left: 16px; right: 16px; z-index: 260; max-width: 700px; margin: auto; padding: 14px 20px; border: 1px solid var(--danger); border-radius: 8px; background: var(--white); font-size: 14px; color: var(--danger); }
.rich-editor figure { display: block; margin: 1.4em 0; white-space: normal; }
.rich-editor figure img { display: block; width: auto; max-width: 100%; height: auto; max-height: 65vh; border-radius: 5px; cursor: pointer; }
.rich-editor figure img:hover { outline: 2px solid var(--line); outline-offset: 4px; }
.rich-editor figcaption { margin-top: 10px; font: 14px/1.5 var(--sans); color: var(--muted); }
.rich-editor .link-card { display: block; margin: 1.1em 0; padding: 18px 20px; border: 1px solid var(--line); border-radius: 8px; background: var(--white); white-space: normal; font: 16px/1.6 var(--sans); }
.rich-editor .link-card a { display: block; text-decoration: none; color: var(--ink); overflow-wrap: anywhere; }
.rich-editor .link-card span { color: var(--muted); font-size: 13px; }
.rich-editor .link-card:hover { border-color: var(--accent); }
@media (max-width: 560px) { .keyboard-hint { display: none; } .topbar-primary { flex: 1 1 100%; justify-content: space-between; } .topbar-actions { width: 100%; justify-content: space-between; } .topbar { min-height: 108px; gap: 0; } .document-heading { padding-top: 14px; } }

.rich-editor figure:focus-visible { outline: 2px solid var(--accent); outline-offset: 5px; border-radius: 5px; }

/* Reading appearances: each style changes type, measure, rhythm, and palette. */
:root {
  color-scheme: light;
  --paper: #fdfdfb; --paper-deep: #f3f3ef; --paper-dark: #e8e8e2; --white: #ffffff;
  --ink: #242424; --ink-soft: #42423e; --muted: #686864; --line: #dcdcd6;
  --accent: #178344; --accent-soft: #e7f2e9; --on-accent: #ffffff; --green: #267044; --danger: #a3342d;
  --selection: #d8eadb; --writing-font: Georgia, "Times New Roman", serif; --heading-font: var(--sans);
  --writing-width: 680px; --writing-size: 1.3125rem; --mobile-writing-size: 1.1875rem;
  --writing-leading: 1.75; --writing-tracking: -.003em; --paragraph-space: 1.25em;
  --title-size: 2.625rem; --title-weight: 700; --title-tracking: -.045em;
}
:root[data-appearance="paper"] {
  --paper: #f8f4eb; --paper-deep: #efeadf; --paper-dark: #e3ddcf; --white: #fdfaf3;
  --ink: #3c392f; --ink-soft: #555043; --muted: #6b6558; --line: #ddd5c5;
  --accent: #646f4e; --accent-soft: #e7eadb; --on-accent: #ffffff; --selection: #e1e6ce;
  --writing-font: "Iowan Old Style", Palatino, Georgia, serif; --heading-font: var(--serif);
  --writing-width: 640px; --writing-size: 1.375rem; --mobile-writing-size: 1.25rem;
  --writing-leading: 1.95; --writing-tracking: .005em; --paragraph-space: 1.1em;
  --title-size: 2.5rem; --title-weight: 400; --title-tracking: -.03em;
}
:root[data-appearance="journal"] {
  --paper: #f4f7f7; --paper-deep: #eaf0ef; --paper-dark: #dce5e3; --white: #fcfefe;
  --ink: #263436; --ink-soft: #425254; --muted: #5c696c; --line: #d0dcda;
  --accent: #315e67; --accent-soft: #ddebed; --on-accent: #ffffff; --selection: #d5e6e9;
  --writing-font: var(--sans); --heading-font: var(--sans);
  --writing-width: 720px; --writing-size: 1.1875rem; --mobile-writing-size: 1.125rem;
  --writing-leading: 1.85; --writing-tracking: -.015em; --paragraph-space: 1.5em;
  --title-size: 2.25rem; --title-weight: 500; --title-tracking: -.04em;
}
:root[data-appearance="typewriter"] {
  --paper: #f5f3ef; --paper-deep: #ebe7e0; --paper-dark: #ded8cd; --white: #fcfaf6;
  --ink: #37332d; --ink-soft: #504b43; --muted: #686155; --line: #d7d0c4;
  --accent: #795e41; --accent-soft: #ece3d4; --on-accent: #ffffff; --selection: #e7d8bf;
  --writing-font: "SFMono-Regular", Consolas, "Liberation Mono", monospace; --heading-font: var(--writing-font);
  --writing-width: 760px; --writing-size: 1.0625rem; --mobile-writing-size: 1rem;
  --writing-leading: 2; --writing-tracking: 0; --paragraph-space: 1.2em;
  --title-size: 1.75rem; --title-weight: 500; --title-tracking: -.025em;
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --paper: #191a18; --paper-deep: #222420; --paper-dark: #30332d; --white: #20221e;
  --ink: #e6e7e0; --ink-soft: #c7cbbf; --muted: #a2a99a; --line: #44483e;
  --accent: #86c99b; --accent-soft: #293c2c; --on-accent: #132419; --green: #93cea2; --danger: #f1a098;
  --selection: #344f3c; --shadow: 0 24px 90px rgba(0,0,0,.36);
}
:root[data-theme="dark"][data-appearance="paper"] {
  --paper: #211f1a; --paper-deep: #2a2821; --paper-dark: #39362b; --white: #29261f;
  --ink: #eae4d5; --ink-soft: #cdc4b1; --muted: #b0a58f; --line: #4c4536;
  --accent: #c3ca94; --accent-soft: #383d28; --on-accent: #232815; --selection: #474e33;
}
:root[data-theme="dark"][data-appearance="journal"] {
  --paper: #172024; --paper-deep: #202b30; --paper-dark: #2d3b41; --white: #1d282d;
  --ink: #e0ebee; --ink-soft: #bfced3; --muted: #9db2ba; --line: #3a5059;
  --accent: #95cbd5; --accent-soft: #263e45; --on-accent: #142b31; --selection: #345560;
}
:root[data-theme="dark"][data-appearance="typewriter"] {
  --paper: #211d1b; --paper-deep: #2b2522; --paper-dark: #3a302a; --white: #29221f;
  --ink: #eae0d4; --ink-soft: #d0c0ae; --muted: #b2a08d; --line: #4b3d32;
  --accent: #d8b287; --accent-soft: #443324; --on-accent: #302012; --selection: #57422e;
}
::selection { background: var(--selection); }
.document-heading { padding-inline: max(32px, calc((100% - var(--writing-width)) / 2)); }
.document-title { font-family: var(--heading-font); font-size: clamp(1.75rem, 3.2vw, var(--title-size)); font-weight: var(--title-weight); letter-spacing: var(--title-tracking); }
#editor, #editorSecondary { padding-inline: max(32px, calc((100% - var(--writing-width)) / 2)); font-family: var(--writing-font); font-size: var(--writing-size); line-height: var(--writing-leading); letter-spacing: var(--writing-tracking); }
.rich-editor p { margin-bottom: var(--paragraph-space); }
.rich-editor li > p { margin-block: 0; }
.rich-editor h1, .rich-editor h2, .rich-editor h3 { font-family: var(--heading-font); }
.action-button { color: var(--on-accent); }
.action-button:hover { background: var(--accent); filter: brightness(.92); }
.coach-clear > span { background: var(--accent-soft); }
:root[data-theme="dark"] .coach-issue { background: var(--white); }
:root[data-theme="dark"] .coach-issue-open:hover { background: var(--paper-dark); }
:root[data-theme="dark"] .coach-fix { background: var(--paper-deep); color: var(--ink); border-color: var(--line); }
:root[data-theme="dark"] .coach-fix:hover { background: var(--paper-dark); }
:root[data-theme="dark"] .template-dialog::backdrop { background: rgba(0,0,0,.5); }
.appearance-dialog { width: min(580px, calc(100vw - 32px)); }
.appearance-dialog fieldset { border: 0; margin: 20px 0 0; padding: 0; min-width: 0; }
.appearance-dialog legend { padding: 0; margin-bottom: 12px; font: 14px/1.5 var(--sans); color: var(--ink-soft); }
.appearance-choices { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.appearance-dialog .appearance-choice { position: relative; display: flex; flex-direction: column; margin: 0; padding: 10px; border: 1px solid var(--line); border-radius: 10px; cursor: pointer; min-width: 0; }
.appearance-choice:has(input:checked) { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); background: var(--accent-soft); }
.appearance-choice:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 4px; }
.appearance-dialog .appearance-choice input { position: absolute; top: 18px; right: 18px; width: 18px; height: 18px; min-height: 0; margin: 0; padding: 0; accent-color: var(--accent); }
.appearance-choice > strong { margin-top: 10px; font: 500 14px/1.5 var(--sans); }
.appearance-choice > small { margin-top: 3px; color: var(--muted); font: 12px/1.5 var(--sans); }
.style-sample { display: flex; flex-direction: column; justify-content: center; gap: 10px; min-height: 110px; padding: 26px 12px 12px; border-radius: 5px; overflow: hidden; }
.style-sample b { font-weight: inherit; line-height: 1.3; }
.style-sample > span { font-size: 12px; line-height: 1.5; }
.sample-editorial { background: #ffffff; color: #242424; font: 18px Georgia,serif; }
.sample-editorial b { font: 700 17px/1.3 var(--sans); }
.sample-paper { background: #f8f4eb; color: #3c392f; font: 20px Palatino,Georgia,serif; }
.sample-journal { background: #f4f7f7; color: #263436; font: 16px var(--sans); }
.sample-typewriter { background: #f5f3ef; color: #37332d; font: 14px var(--mono); }
:root[data-theme="dark"] .sample-editorial { background: #191a18; color: #e6e7e0; }
:root[data-theme="dark"] .sample-paper { background: #211f1a; color: #eae4d5; }
:root[data-theme="dark"] .sample-journal { background: #172024; color: #e0ebee; }
:root[data-theme="dark"] .sample-typewriter { background: #211d1b; color: #eae0d4; }
.theme-choices { display: flex; gap: 8px; }
.appearance-dialog .theme-choices label { display: flex; flex: 1; justify-content: center; align-items: center; gap: 8px; margin: 0; min-height: 46px; border: 1px solid var(--line); border-radius: 7px; cursor: pointer; }
.appearance-dialog .theme-choices input { width: 16px; height: 16px; min-height: 0; margin: 0; padding: 0; accent-color: var(--accent); }
.theme-choices label:has(input:checked) { background: var(--accent-soft); border-color: var(--accent); }
@media (max-width: 820px) {
  .document-heading, #editor, #editorSecondary { padding-inline: max(24px, calc((100% - var(--writing-width)) / 2)); }
  .keyboard-hint { display: none; }
}
@media (max-width: 560px) {
  #editor, #editorSecondary { font-size: var(--mobile-writing-size); }
  .document-title { font-size: min(var(--title-size), 2rem); }
  .statusbar { padding-inline: 16px; gap: 8px; }
  #statRead { display: none; }
  .appearance-shortcut { padding-inline: 8px; }
}
@media (max-width: 380px) { .appearance-choices { grid-template-columns: 1fr; } .style-sample { min-height: 90px; } }

/* The title is part of the page, with the same type as the writing appearance. */
textarea.document-title { resize: none; overflow: hidden; min-height: 44px; border-radius: 0; cursor: text; }
textarea.document-title::placeholder { color: var(--muted); opacity: 1; }
textarea.document-title:hover { color: var(--ink); }
textarea.document-title:focus { outline: none; box-shadow: 0 1px 0 var(--line); }
.second-document-title { min-width: 0; flex: 1; min-height: 44px; padding: 8px; border: 0; border-bottom: 1px solid var(--accent); background: transparent; color: var(--ink); font-family: var(--heading-font); }

/* Title and draft belong to one continuous scrolling page. */
.document-scroll { flex: 1; min-height: 0; display: flex; flex-direction: column; overflow-y: auto; overflow-x: hidden; scrollbar-width: thin; scrollbar-color: var(--line) transparent; scroll-padding-block: 32px; }
.document-scroll #editor { flex: 1 0 auto; min-height: 12rem; overflow: visible; }

.history-actions { display: flex; align-items: center; gap: 0; }
.history-actions button:disabled { opacity: .35; cursor: default; background: transparent; }

.editor-toolbar { flex-wrap: wrap; justify-content: center; overflow: visible; }
.editor-toolbar select { min-height: 44px; max-width: 150px; padding: 0 26px 0 10px; border: 1px solid var(--line); border-radius: 6px; background: var(--white); color: var(--ink); font: 14px var(--sans); }
.editor-toolbar button.clear-formatting { width: auto; padding: 0 10px; font: 13px var(--sans); }
.editor-toolbar button[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); box-shadow: inset 0 -2px var(--accent); }

/* Personal typography, in one quiet panel. */
.format-toggle { font: 14px/1.2 var(--sans); }
.editor-toolbar button { display: inline-flex; align-items: center; justify-content: center; }
.appearance-dialog { width: min(580px, calc(100vw - 32px)); padding: 24px; }
.appearance-intro { margin: 6px 0 18px; }
.appearance-tabs { display: flex; gap: 24px; border-bottom: 1px solid var(--line); margin-bottom: 20px; }
.appearance-tabs button { min-height: 44px; padding: 0 0 12px; border: 0; border-bottom: 2px solid transparent; border-radius: 0; background: transparent; color: var(--muted); font: 14px/1.4 var(--sans); }
.appearance-tabs button[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--accent); }
.appearance-tabs button:hover { color: var(--ink); }
.font-preview { padding: 22px 0; margin: 8px 0 0; border-bottom: 1px solid var(--line); color: var(--ink); overflow-wrap: anywhere; }
.font-preview strong { display: block; margin-bottom: .6em; font: 600 1.25em/1.3 var(--heading-font); letter-spacing: -.025em; }
.font-preview p { max-width: min(100%, calc(var(--writing-width) * .65)); margin: 0; font-family: var(--writing-font); font-size: var(--writing-size); line-height: var(--writing-leading); letter-spacing: var(--writing-tracking); }
.type-size-label { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.type-size-label output { font: 13px/1.5 var(--sans); color: var(--muted); }
.type-size-control { display: flex; align-items: center; gap: 16px; }
.type-size-control input { width: 100%; min-width: 0; min-height: 44px; accent-color: var(--accent); cursor: pointer; }
.type-size-control span { font: 15px/1 var(--sans); color: var(--ink-soft); }
.type-size-control span:last-child { font-size: 24px; }
.type-options { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.type-options > div { min-width: 0; }
.appearance-dialog .reset-typography { padding-left: 0; margin-top: 10px; font-size: 13px; text-decoration: underline; text-underline-offset: 4px; }
.reset-typography:disabled { opacity: .5; cursor: default; text-decoration: none; }
.appearance-footer { display: flex; align-items: center; justify-content: space-between; gap: 20px; margin-top: 12px; border-top: 1px solid var(--line); padding-top: 16px; }
.appearance-footer .action-button { flex: none; margin: 0; }
.appearance-footer p { margin: 0; }
.focus-appearance { display: none; position: fixed; left: 92px; top: max(20px, env(safe-area-inset-top)); z-index: 60; background: var(--paper); }
#app.focus-mode .focus-appearance { display: inline-flex; }
@media (max-width: 560px) {
  .appearance-dialog { padding: 20px; }
  .appearance-dialog .dialog-header h2 { font-size: 23px; }
  .font-preview p { font-size: var(--mobile-writing-size); }
  .type-options { gap: 12px; }
  .topbar-actions { gap: 2px; }
}
@media (max-width: 380px) {
  .type-options { grid-template-columns: 1fr; gap: 0; }
  .appearance-tabs { gap: 20px; }
}

/* Selection tools stay close to the text without shifting the page. */
#app .editor-toolbar.selection-toolbar {
  position: fixed; z-index: 80; display: flex; margin: 0; align-self: auto;
  width: 390px; max-width: calc(100vw - 24px);
  padding: 5px; gap: 2px; border-radius: 10px; box-shadow: 0 6px 24px rgba(0,0,0,.14);
}
#app.focus-mode .editor-toolbar.selection-toolbar { display: flex; }
.editor-toolbar.selection-toolbar select { max-width: 134px; }
.editor-toolbar.selection-toolbar button.clear-formatting { font-size: 12px; }
.selection-extras { display: flex; flex-wrap: wrap; flex-basis: 100%; align-items: center; justify-content: center; gap: 4px; border-top: 1px solid var(--line); padding-top: 3px; }
.editor-toolbar .selection-extras button { width: auto; padding: 0 10px; font: 13px var(--sans); }
.highlight-colors { display: flex; align-items: center; }
.editor-toolbar .highlight-colors button { width: 40px; height: 44px; padding: 0; }
.highlight-colors button span { position: relative; display: block; width: 20px; height: 20px; border-radius: 50%; background: var(--highlight-dot); box-shadow: inset 0 0 0 1px rgba(0,0,0,.12); }
[data-highlight-color="yellow"] { --highlight-dot: #f8e69a; }
[data-highlight-color="green"] { --highlight-dot: #c8e8bd; }
[data-highlight-color="blue"] { --highlight-dot: #c5dff5; }
[data-highlight-color="pink"] { --highlight-dot: #f5c9dc; }
[data-highlight-color="none"] { --highlight-dot: var(--white); }
[data-highlight-color="none"] span::after { content: ""; position: absolute; left: 9px; top: 2px; width: 1px; height: 16px; background: var(--muted); transform: rotate(45deg); }
.editor-toolbar .highlight-colors button[aria-pressed="true"] { background: transparent; box-shadow: none; }
.highlight-colors button[aria-pressed="true"] span { outline: 2px solid var(--ink-soft); outline-offset: 3px; }
.highlight-colors button:disabled { opacity: .45; }
@media (max-width: 560px) {
  #app .editor-toolbar.selection-toolbar { max-width: calc(100vw - 24px); }
}

/* Quiet icon controls keep the writing surface light. */
.minimal-control { position: relative; width: 44px; height: 44px; min-width: 44px; padding: 0; flex: none; }
.minimal-control svg { display: block; flex: none; }
.topbar-primary { gap: 8px; }
.topbar-actions { gap: 4px; }
.statusbar .minimal-control { padding: 0; }
.minimal-control.playing::after { content: ""; position: absolute; right: 7px; top: 7px; width: 5px; height: 5px; border-radius: 50%; background: var(--accent); }
.minimal-control[aria-pressed="true"] { color: var(--accent); background: var(--accent-soft); }
.editor-toolbar button.clear-formatting { width: 44px; padding: 0; }
.focus-appearance { left: 76px; }
@media (max-width: 560px) {
  .topbar-primary, .topbar-actions { gap: 0; }
  .minimal-control { padding: 0; }
}

.dictionary-words { list-style: none; margin: 16px 0 0; padding: 0; max-height: 260px; overflow-y: auto; }
.dictionary-words li { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 2px 0; border-bottom: 1px solid var(--line); }
.dictionary-words li > span { overflow-wrap: anywhere; font-size: 15px; }
.rich-editor [data-scribe-word]::spelling-error { text-decoration: none; background: transparent; }

/* A quieter editorial frame: open space, fine rules, and a single reading column. */
:root { --shadow: 0 12px 48px rgba(24, 28, 20, .10); }
:root[data-theme="dark"] { --shadow: 0 12px 48px rgba(0, 0, 0, .28); }
:root[data-appearance="editorial"] { --title-weight: 600; --title-tracking: -.04em; }
.topbar {
  width: min(1120px, 100%); align-self: center;
  min-height: 76px; padding: 12px 32px; gap: 8px 24px;
}
.brand { margin-right: 16px; }
.brand-name { font-size: 27px; font-style: italic; font-weight: 400; letter-spacing: -.045em; }
.topbar-primary { gap: 4px; }
.topbar-actions { gap: 2px; }
.topbar .icon-button, .statusbar .icon-button, .exit-focus, .focus-sound, .focus-appearance { border-radius: 50%; }
.topbar .icon-button svg, .statusbar .icon-button svg { width: 18px; height: 18px; }
.document-heading { padding-top: clamp(32px, 7vh, 80px); padding-bottom: 30px; }
textarea.document-title { line-height: 1.2; padding-block: 6px; }
#editor, #editorSecondary { padding-bottom: 28vh; }
.rich-editor h1, .rich-editor h2, .rich-editor h3 {
  margin-top: 1.8em; margin-bottom: .65em; font-weight: 600; line-height: 1.3; letter-spacing: -.025em;
}
.rich-editor h1 { font-size: 1.7em; margin-top: .65em; }
.rich-editor h2 { font-size: 1.28em; }
.rich-editor h3 { font-size: 1.08em; }
.rich-editor blockquote { margin-block: 1.5em; padding: .1em 0 .1em 1.15em; border-left-width: 1px; }
.rich-editor li { padding-left: .15em; margin-bottom: .25em; }
.rich-editor li::marker { color: var(--muted); }
.rich-editor a { text-decoration-thickness: 1px; text-underline-offset: .18em; }
.rich-editor hr { width: 48px; margin: 2em auto; }
.statusbar {
  width: min(1120px, 100%); align-self: center; min-height: 56px;
  padding: 6px 32px max(6px, env(safe-area-inset-bottom)); gap: 16px; font-variant-numeric: tabular-nums;
}
#statRead::before { content: "·"; margin-right: 16px; color: var(--muted); }
.tools-popover { width: 232px; padding: 8px; border-radius: 12px; }
.tools-popover button { padding-inline: 14px; border-radius: 6px; }
.tools-popover hr { margin: 8px 14px; }
.editor-toolbar { border-radius: 12px; padding: 4px 6px; }
.editor-toolbar select { border-color: transparent; background: transparent; }
.editor-toolbar select:hover, .editor-toolbar select:focus-visible { background: var(--paper-deep); }
#app .editor-toolbar.selection-toolbar { border-radius: 12px; box-shadow: var(--shadow); }
.library-dialog, .media-dialog { padding: 28px; border-radius: 14px; }
.library-dialog::backdrop, .media-dialog::backdrop, .template-dialog::backdrop { background: rgba(20, 24, 18, .18); backdrop-filter: blur(4px); }
:root[data-theme="dark"] dialog::backdrop { background: rgba(0, 0, 0, .4); }
.sidebar-header { padding-bottom: 24px; }
.sidebar-header h2, .media-dialog h2 { font-weight: 400; letter-spacing: -.035em; }
.search-box { border-radius: 0; border-width: 0 0 1px; padding-inline: 0; background: transparent; margin-bottom: 8px; }
.search-box span { font-size: 21px; }
.document-item { padding: 20px 8px; border-radius: 0; border-bottom: 1px solid var(--line); }
.document-item:hover, .document-row.active .document-item { background: transparent; }
.document-item:hover .document-name, .document-row.active .document-name { color: var(--accent); }
.document-row.active .document-name::after { content: ""; display: inline-block; width: 5px; height: 5px; margin: 0 0 3px 10px; border-radius: 50%; background: var(--accent); }
.document-name { font-weight: 400; font-size: 20px; letter-spacing: -.015em; }
.document-row-meta { line-height: 1.5; }
.new-document { border: 0; border-radius: 7px; background: var(--accent-soft); color: var(--accent); margin-block: 20px; }
.new-document:hover { color: var(--ink); }
.template-dialog { width: min(540px, calc(100vw - 32px)); border-radius: 14px; }
.template-dialog form { padding: 28px; }
.template-grid { grid-template-columns: 1fr; gap: 0; margin-top: 20px; }
.template-card { min-height: 80px; padding: 16px 8px; border: 0; border-bottom: 1px solid var(--line); border-radius: 0; background: transparent; }
.template-card:hover { transform: none; box-shadow: none; border-color: var(--line); background: var(--paper-deep); }
.template-icon { display: none; }
.template-copy strong { font: 400 20px/1.3 var(--serif); letter-spacing: -.02em; }
.template-copy > span { font-size: 13px; line-height: 1.5; }
.appearance-dialog .appearance-choice { padding: 8px; border-radius: 8px; }
.appearance-choice:has(input:checked) { box-shadow: none; }
.appearance-choice > small { line-height: 1.5; }
.appearance-footer { margin-top: 18px; }
.action-button { border-radius: 7px; }
.toast { border: 0; border-radius: 8px; font-weight: 400; box-shadow: var(--shadow); }
@media (max-width: 820px) {
  .topbar { padding-inline: 24px; }
  .statusbar { padding-inline: 24px; }
  .document-heading { padding-top: 36px; padding-bottom: 24px; }
}
@media (max-width: 560px) {
  .topbar { min-height: 100px; padding: 6px 16px; gap: 0; }
  .topbar-primary { flex: 1 1 100%; justify-content: space-between; }
  .topbar-actions { width: 100%; justify-content: space-between; }
  .brand { margin-right: auto; }
  .brand-name { font-size: 25px; }
  .history-actions { margin-left: 12px; }
  .document-heading { padding-top: 28px; padding-bottom: 22px; }
  .statusbar { min-height: 52px; padding-inline: 16px; gap: 10px; }
  .library-dialog, .media-dialog, .template-dialog form { padding: 22px; }
  .document-item { padding-block: 18px; }
  .template-card { min-height: 76px; }
  .rich-editor blockquote { padding-left: .85em; }
}

/* Focus controls must remain outside the scrolling document and the flex layout. */
#app > .minimal-control.exit-focus,
#app > .minimal-control.focus-sound,
#app > .minimal-control.focus-appearance { position: fixed; top: max(16px, env(safe-area-inset-top)); z-index: 60; }
#app > .exit-focus { right: max(16px, env(safe-area-inset-right)); left: auto; }
#app > .focus-sound { left: max(16px, env(safe-area-inset-left)); }
#app > .focus-appearance { left: max(68px, calc(env(safe-area-inset-left) + 52px)); }
#app.focus-mode .document-scroll { scroll-padding-top: 76px; }
#app:fullscreen { width: 100%; height: 100dvh; }

/* One quiet home for optional typing sounds and ambient music. */
.sound-section-heading { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.sound-section-heading h3, .sound-section-title { margin: 0; font: 500 15px/1.4 var(--sans); color: var(--ink); }
.keyboard-sound-section { padding: 6px 0 24px; margin-bottom: 24px; border-bottom: 1px solid var(--line); }
#keyboardEnabled { min-width: 56px; }
#keyboardEnabled[aria-pressed="true"] { color: var(--accent); background: var(--accent-soft); }
#keyboardPreview { margin-top: 8px; }

/* Split writing uses two matching pages, with one readable page on small screens. */
.split-main-header { display: none; }
.panes[data-split="true"] .split-main-header, .second-editor-header { display: flex; align-items: center; flex: 0 0 56px; min-height: 56px; padding: 6px 24px; gap: 8px; border-bottom: 1px solid var(--line); font: 14px/1.4 var(--sans); color: var(--muted); }
.second-editor-header { flex-wrap: nowrap; }
.second-editor-header select { min-width: 0; padding: 8px 4px; border: 0; background: transparent; color: var(--ink-soft); font: 14px/1.4 var(--sans); text-overflow: ellipsis; }
.second-editor-header .icon-button { flex: none; width: 36px; padding: 0; }
.panes[data-split="true"] .document-heading { padding-top: clamp(28px, 5vh, 52px); padding-bottom: 24px; }
.panes[data-split="true"] .document-heading,
.panes[data-split="true"] #editor,
.panes[data-split="true"] #editorSecondary { padding-inline: clamp(24px, 3vw, 56px); }
#secondaryDocumentScroll #editorSecondary { flex: 1 0 auto; min-height: 12rem; overflow: visible; padding-top: 0; }
.split-mobile-tabs { display: none; }
@media (max-width: 820px) {
  .split-mobile-tabs:not([hidden]) { display: flex; align-items: center; gap: 4px; padding: 0 16px; border-bottom: 1px solid var(--line); }
  .split-mobile-tabs > button { flex: 1; min-width: 0; min-height: 48px; padding: 0 10px; border: 0; border-bottom: 2px solid transparent; background: transparent; color: var(--muted); font: 14px/1.4 var(--sans); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .split-mobile-tabs > button[aria-pressed="true"] { color: var(--ink); border-bottom-color: var(--accent); }
  .split-mobile-tabs > .icon-button { flex: 0 0 40px; }
  .panes[data-split="true"] .split-main-header { display: none; }
  .panes[data-split="true"] .editor-pane, .panes[data-split="true"] .second-editor-pane { flex: 1 1 100%; border: 0; }
  .panes[data-split="true"][data-active-pane="secondary"] .editor-pane, .panes[data-split="true"][data-active-pane="main"] .second-editor-pane { display: none; }
  .second-editor-header { padding-inline: 20px; }
  .second-editor-header #closeSplit { display: none; }
}

/* Separate, anchored sound controls; writing stays visible behind them. */
.audio-popover { position: fixed; inset: auto; margin: 0; width: min(310px, calc(100vw - 24px)); max-height: calc(100dvh - 24px); padding: 18px; z-index: 240; border-radius: 12px; box-shadow: 0 8px 32px rgb(0 0 0 / .12); }
.audio-popover .dialog-header { align-items: center; gap: 12px; margin-bottom: 12px; }
.audio-popover .dialog-header h2 { font: 500 16px/1.4 var(--sans); letter-spacing: 0; }
.audio-popover .dialog-header .icon-button { width: 32px; min-height: 32px; padding: 0; }
.audio-popover .field-help { margin: 0 0 12px; font-size: 13px; line-height: 1.5; }
.audio-popover select { min-height: 42px; font-size: 14px; }
.audio-popover label { margin-top: 12px; }
.audio-popover .sound-section-heading { font-size: 14px; }
.audio-popover #keyboardPreview { margin-top: 0; }
#keyboardToggle.playing, #focusKeyboard.playing { color: var(--accent); }
#app > .minimal-control.focus-keyboard { display: none; position: fixed; top: max(16px, env(safe-area-inset-top)); left: max(120px, calc(env(safe-area-inset-left) + 104px)); z-index: 60; border-radius: 50%; background: var(--paper); }
#app.focus-mode > .focus-keyboard { display: inline-flex; }
/* Keep live reading statistics quiet and in flow in both focus and full screen. */
#app.focus-mode .statusbar { display: flex; justify-content: center; min-height: 44px; padding: 8px 20px max(12px, env(safe-area-inset-bottom)); gap: 16px; }
#app.focus-mode .statusbar .icon-button, #app.focus-mode .status-spacer, #app.focus-mode .keyboard-hint { display: none; }
#app.focus-mode #statRead { display: inline; }

/* Phone writing: a quiet header and editing controls within thumb reach. */
.mobile-writing-tools { display: none; }
.slash-menu { position: fixed; z-index: 230; display: flex; flex-direction: column; padding: 8px; overflow: hidden; border: 1px solid var(--line); border-radius: 12px; background: var(--white); color: var(--ink); box-shadow: var(--shadow); font: 14px/1.4 var(--sans); }
#slashOptions { position: relative; min-height: 0; overflow-y: auto; overscroll-behavior: contain; }
.slash-menu-heading, .slash-menu-help { flex: none; }
.slash-menu-heading { margin: 4px 8px 8px; color: var(--muted); font-size: 12px; }
.slash-menu-help { margin: 8px 8px 4px; padding-top: 8px; border-top: 1px solid var(--line); color: var(--muted); font-size: 11px; }
#slashOptions button { display: flex; align-items: center; gap: 12px; width: 100%; min-height: 44px; padding: 6px 8px; border: 0; border-radius: 6px; background: transparent; text-align: left; font: inherit; }
#slashOptions button:hover, #slashOptions button[aria-selected="true"] { background: var(--accent-soft); color: var(--accent); }
.slash-option-mark { display: inline-flex; justify-content: center; align-items: center; flex: 0 0 28px; min-height: 28px; font: 500 14px/1 var(--sans); }
#slashEmpty { padding: 0 8px; }
.install-dialog { width: min(460px, calc(100vw - 32px)); }
.install-icon { display: block; border-radius: 14px; margin: 4px 0 20px; }
.install-dialog > p { line-height: 1.65; }
.install-status { padding-top: 16px; border-top: 1px solid var(--line); color: var(--accent); font-size: 14px; }
@media (max-width: 560px), (max-width: 920px) and (pointer: coarse) and (orientation: landscape) {
  html { -webkit-text-size-adjust: 100%; }
  #app, #app:fullscreen { position: relative; top: var(--visible-top, 0px); height: var(--visible-height, 100dvh); }
  .topbar { min-height: 60px; padding: max(6px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) 6px max(16px, env(safe-area-inset-left)); flex-wrap: nowrap; gap: 8px; }
  .topbar-primary { flex: 1; gap: 8px; justify-content: flex-start; }
  .topbar-actions { width: auto; gap: 4px; }
  .brand { margin-right: auto; }
  .brand-name { font-size: 24px; }
  .history-actions { display: none; }
  .document-heading, .panes[data-split="true"] .document-heading { padding: 22px max(20px, env(safe-area-inset-right)) 18px max(20px, env(safe-area-inset-left)); }
  textarea.document-title { font-size: 28px; line-height: 1.2; letter-spacing: -.035em; }
  #editor, #editorSecondary, .panes[data-split="true"] #editor, .panes[data-split="true"] #editorSecondary {
    padding-inline: max(20px, env(safe-area-inset-left)) max(20px, env(safe-area-inset-right));
    padding-bottom: max(100px, calc(var(--visible-height, 100dvh) * .3));
    font-size: max(16px, var(--mobile-writing-size)); line-height: var(--writing-leading);
  }
  .rich-editor p { margin-top: 0; }
  .document-scroll { overscroll-behavior-y: contain; scroll-padding-block: 24px 80px; }
  .mobile-writing-tools { display: flex; flex: none; align-items: center; justify-content: space-between; gap: 8px; padding: 4px max(16px, env(safe-area-inset-right)) 0 max(16px, env(safe-area-inset-left)); border-top: 1px solid var(--line); background: var(--paper); }
  .mobile-writing-tools .icon-button { border-radius: 8px; }
  .mobile-writing-tools button:disabled { opacity: .3; cursor: default; }
  #doneWriting { color: var(--accent); font-size: 15px; font-weight: 500; min-width: 48px; }
  .statusbar { min-height: 44px; padding: 0 max(16px, env(safe-area-inset-right)) max(4px, env(safe-area-inset-bottom)) max(20px, env(safe-area-inset-left)); gap: 4px; font-size: 12px; }
  .statusbar .icon-button { width: 44px; min-width: 44px; }
  #statRead { display: inline; white-space: nowrap; }
  #statWords { white-space: nowrap; }
  #statRead::before { margin-right: 4px; }
  #app.mobile-typing .topbar { display: none; }
  #app.mobile-typing .statusbar, #app.focus-mode .statusbar { min-height: 28px; padding-block: 4px; justify-content: center; gap: 6px; }
  #app.mobile-typing .statusbar .icon-button, #app.mobile-typing .status-spacer { display: none; }
  #app.mobile-typing .document-heading { padding-top: 16px; }
  #app.focus-mode .document-heading { padding-top: 76px; }
  #app > .minimal-control.exit-focus, #app > .minimal-control.focus-sound, #app > .minimal-control.focus-appearance, #app > .minimal-control.focus-keyboard { top: calc(var(--visible-top, 0px) + max(8px, env(safe-area-inset-top))); }
  #app .editor-toolbar:not([hidden]) {
    position: fixed; display: flex; flex-wrap: wrap; justify-content: center; align-self: auto;
    left: 12px; right: auto; top: auto; bottom: calc(100dvh - var(--visible-top, 0px) - var(--visible-height, 100dvh) + 104px + env(safe-area-inset-bottom));
    width: calc(100vw - 24px); max-width: calc(100vw - 24px); margin: 0; padding: 5px; gap: 4px;
    overflow: visible; z-index: 80; box-shadow: var(--shadow);
  }
  #app.mobile-typing .editor-toolbar:not(.selection-toolbar), #app.focus-mode .editor-toolbar:not(.selection-toolbar) { bottom: calc(100dvh - var(--visible-top, 0px) - var(--visible-height, 100dvh) + 84px); }
  #app .editor-toolbar.selection-toolbar { bottom: auto; }
  #app .editor-toolbar select { flex: 0 0 136px; max-width: 136px; font-size: 16px; }
  #app .editor-toolbar > button { width: 40px; }
  #app .editor-toolbar > select { flex-basis: 128px; max-width: 128px; padding-inline: 6px 18px; font-size: 14px; }
  .tools-popover { max-height: calc(var(--visible-height, 100dvh) - 80px); }
  .toast, .storage-warning { bottom: calc(100dvh - var(--visible-top, 0px) - var(--visible-height, 100dvh) + 108px + env(safe-area-inset-bottom)); }
  #app.mobile-typing .toast, #app.mobile-typing .storage-warning, #app.focus-mode .toast, #app.focus-mode .storage-warning { bottom: calc(100dvh - var(--visible-top, 0px) - var(--visible-height, 100dvh) + 88px); }
  dialog { max-height: calc(var(--visible-height, 100dvh) - 24px); overflow-y: auto; overscroll-behavior: contain; }
  .library-dialog, .media-dialog, .appearance-dialog, .template-dialog form { padding: 20px; }
  dialog input:not([type="range"]), dialog textarea, dialog select, .second-editor-header select { font-size: 16px; }
  .audio-popover .dialog-header .icon-button, .second-editor-header .icon-button { min-height: 44px; width: 44px; }
  button, summary { touch-action: manipulation; }
  button:active:not(:disabled), summary:active { background: var(--paper-deep); color: var(--ink); }
}
@media (max-width: 360px) {
  .statusbar { gap: 2px; padding-inline: 12px; font-size: 11px; }
  .statusbar .icon-button { width: 40px; min-width: 40px; }
}

/* An optional second look, with the draft remaining the main event. */
.coach-pane { flex-basis: min(390px, 38vw); background: var(--paper); }
.coach-header { padding: 22px 22px 16px; background: transparent; align-items: center; }
.coach-header h2 { margin: 6px 0 0; font: 400 26px/1.2 var(--serif); }
.coach-body { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 20px 22px 32px; }
.coach-reading { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.coach-kicker { color: var(--muted); font: 12px/1.5 var(--sans); }
.coach-grade { margin: 4px 0; font: 400 26px/1.2 var(--serif); white-space: nowrap; }
.coach-grade strong { font-weight: 500; }
.coach-target { color: var(--muted); font: 12px/1.5 var(--sans); min-width: 0; }
.coach-target select { display: block; max-width: 100%; min-height: 44px; padding: 6px; border: 1px solid var(--line); border-radius: 6px; color: var(--ink); background: var(--paper); font: 12px var(--sans); }
#gradeMessage, .coach-thought p, .coach-method p { color: var(--ink-soft); font: 13px/1.65 var(--sans); }
#gradeMessage { margin: 12px 0; }
.coach-stats { padding: 0 0 18px; min-height: 0; gap: 12px; background: transparent; font: 12px/1.5 var(--sans); flex-wrap: wrap; }
.coach-thought { padding-top: 18px; }
.coach-thought p { margin: 5px 0 12px; }
.coach-method { border-bottom: 1px solid var(--line); padding-bottom: 12px; }
.coach-method summary { min-height: 44px; align-content: center; cursor: pointer; color: var(--muted); font-size: 12px; }
.coach-summary { display: flex; flex-wrap: wrap; gap: 6px; border: 0; padding: 18px 0 4px; }
.coach-summary button { min-height: 44px; padding: 8px 12px; border: 1px solid var(--line); border-radius: 24px; background: transparent; color: var(--ink-soft); font: 12px/1.4 var(--sans); }
.coach-summary button:hover { background: var(--paper-deep); }
.coach-summary button[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); color: var(--ink); }
.coach-result-count { color: var(--muted); margin: 12px 0; font: 12px/1.5 var(--sans); }
.coach-issues { overflow: visible; padding: 0; }
.coach-issue { border-radius: 8px; margin-bottom: 10px; }
.coach-issue-open { padding: 14px; gap: 8px; }
.coach-issue-label { font: 11px/1.4 var(--sans); letter-spacing: .02em; }
.coach-issue-open strong { font: 500 16px/1.5 var(--serif); overflow-wrap: anywhere; }
.coach-issue-advice { font: 13px/1.55 var(--sans); }
.coach-fix { max-width: calc(100% - 28px); margin: 0 14px 14px; overflow-wrap: anywhere; }
.coach-clear { min-height: 0; padding: 16px; }
.coach-clear p { font-size: 13px; line-height: 1.6; }
@media (max-width: 820px) {
  .panes[data-coach="true"] .editor-pane { display: none; }
  .coach-pane { flex: 1 1 auto; width: 100%; border: 0; }
  .coach-header { padding: 14px 20px; }
  .coach-body { padding: 18px max(20px, env(safe-area-inset-right)) 28px max(20px, env(safe-area-inset-left)); }
  .coach-target select { font-size: 16px; }
  #app:has(.panes[data-coach="true"]) .mobile-writing-tools { display: none; }
}
@media (max-width: 380px) {
  .statusbar #appearanceShortcut { display: none; }
  .coach-reading { align-items: flex-start; flex-direction: column; }
}

.coach-header > div { min-width: 0; }
#coachDocument { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 250px; }
.toast { pointer-events: none; }

/* Quiet coaching: open typography, modest accents, and corrections at the word. */
.coach-pane { background: var(--paper); }
.coach-header { padding-bottom: 18px; }
.coach-header h2 { font-size: 28px; letter-spacing: -.04em; }
.coach-review-intro { padding-bottom: 20px; }
.coach-review-intro p { margin: 0 0 10px; color: var(--muted); font: 13px/1.6 var(--sans); }
.coach-review-intro button { min-height: 44px; padding: 9px 14px; display: flex; align-items: center; justify-content: space-between; gap: 24px; border: 1px solid var(--line); border-radius: 8px; color: var(--ink); background: transparent; font: 13px var(--sans); }
.coach-review-intro button:hover { background: var(--accent-soft); border-color: var(--accent); }
.coach-grade { font-size: 34px; letter-spacing: -.04em; }
.coach-target select { border: 0; border-bottom: 1px solid var(--line); border-radius: 0; padding-inline: 0; }
.coach-thought { padding: 0; border-bottom: 1px solid var(--line); }
.coach-thought summary { min-height: 48px; align-content: center; color: var(--ink-soft); font: 13px var(--sans); cursor: pointer; }
.coach-method { margin-top: 20px; border-top: 1px solid var(--line); border-bottom: 0; padding: 8px 0 0; }
.coach-summary { gap: 0 12px; padding-top: 12px; }
.coach-summary button { display: flex; align-items: center; gap: 5px; border: 0; border-bottom: 2px solid transparent; border-radius: 0; padding: 8px 0; background: transparent; }
.coach-summary button[aria-pressed="true"] { background: transparent; border-color: var(--accent); }
.coach-filter-count { font-size: 10px; color: var(--muted); font-variant-numeric: tabular-nums; }
.coach-result-count { margin: 16px 0 4px; }
.coach-issues .coach-issue, :root[data-theme="dark"] .coach-issue { border: 0; border-bottom: 1px solid var(--line); border-radius: 0; background: transparent; margin: 0; }
.coach-issue-open { padding: 18px 0 12px; gap: 8px; }
.coach-issue-open:hover, :root[data-theme="dark"] .coach-issue-open:hover { background: transparent; }
.coach-issue-open:hover strong { text-decoration: underline; text-decoration-color: var(--accent); text-underline-offset: 4px; }
.coach-issue-label { display: flex; align-items: center; gap: 8px; text-transform: none; letter-spacing: 0; font-size: 12px; }
.coach-issue-label::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: var(--coach-tone, var(--accent)); flex: none; }
.issue-grammar { --coach-tone: #55a86f; }.issue-spelling { --coach-tone: #d44848; }.issue-unclear { --coach-tone: #df8a4b; }.issue-hard { --coach-tone: #c8a243; }.issue-very-hard { --coach-tone: #e46a61; }.issue-weakener { --coach-tone: #5aa3cf; }.issue-simpler { --coach-tone: #a985c7; }
.coach-fix { margin: 0 0 16px; border-radius: 6px; font-weight: 500; font-size: 12px; background: var(--accent-soft); }
.coach-clear { border: 0; border-radius: 0; padding: 20px 0; background: transparent; }
.coach-review-bar { flex: none; display: flex; align-items: center; gap: 8px; min-height: 48px; padding: 0 24px; border-bottom: 1px solid var(--line); color: var(--muted); font: 12px/1.5 var(--sans); }
.coach-review-bar span { flex: 1; }.coach-review-bar button { min-height: 44px; padding: 8px; border: 0; background: transparent; color: var(--ink); font: 12px var(--sans); }
.coach-popover { position: fixed; z-index: 240; width: 320px; max-width: calc(100vw - 24px); overflow-y: auto; overscroll-behavior: contain; padding: 14px 16px 16px; border: 1px solid var(--line); border-radius: 12px; background: var(--paper); color: var(--ink); box-shadow: var(--shadow); font: 13px/1.5 var(--sans); }
.coach-popover-heading { display: flex; align-items: center; justify-content: space-between; gap: 8px; color: var(--muted); font-size: 12px; }
.coach-popover-heading .icon-button { width: 32px; min-height: 32px; height: 32px; flex: none; font-size: 20px; }
.coach-change { display: flex; flex-direction: column; gap: 6px; padding: 10px 0; font: 500 18px/1.45 var(--serif); overflow-wrap: anywhere; }
#coachOriginal.has-replacement { color: var(--muted); text-decoration: line-through; text-decoration-thickness: 1px; font-size: 15px; }
#coachReplacement { color: var(--accent); }
#coachPopoverAdvice { margin: 0 0 16px; color: var(--ink-soft); font-size: 13px; }
.coach-popover-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.coach-popover-actions button { min-height: 44px; padding: 8px 12px; border: 1px solid var(--line); border-radius: 7px; color: var(--ink); background: var(--accent-soft); font: 500 13px var(--sans); }
.coach-popover-actions button:hover { border-color: var(--accent); }
#nextCoachSuggestion { border: 0; margin-left: auto; padding-inline: 4px; background: transparent; color: var(--muted); font-size: 11px; }
@media (max-width: 820px) { .coach-review-bar { padding-inline: 16px; }.coach-popover-heading .icon-button { width: 44px; height: 44px; }.coach-body { padding-top: 16px; } }

/* WriteMind pairs a thought bubble and a pen with a quiet wordmark. */
.brand { display: inline-flex; align-items: center; gap: 8px; flex: none; }
.brand-mark { width: 28px; height: 28px; flex: none; }
.brand-name { font-style: normal; font-size: 25px; letter-spacing: -.045em; }
@media (max-width: 560px) { .brand { gap: 5px; }.brand-mark { width: 24px; height: 24px; }.brand-name { font-size: 21px; }.topbar-primary { gap: 4px; } }
@media (max-width: 360px) { .brand-mark { width: 21px; height: 21px; }.brand-name { font-size: 19px; }.topbar-actions { gap: 0; }.topbar { gap: 4px; padding-left: 12px; } }

.tools-popover .tools-link{display:flex;align-items:center;min-height:44px;padding:10px 14px;color:var(--ink-soft);font:14px/1.5 var(--sans);text-decoration:none;border-radius:6px}.tools-popover .tools-link:hover{background:var(--paper-deep);color:var(--ink)}.no-script{max-width:680px;margin:40px auto;padding:24px;font:16px/1.7 var(--sans)}
.legal-menu-links{display:flex;gap:20px;padding-inline:14px}.legal-menu-links a{display:inline-flex;align-items:center;min-height:44px;color:var(--ink-soft);font:12px/1.5 var(--sans);text-underline-offset:3px}.legal-menu-links a:hover{color:var(--ink)}.legal-menu-links a:focus-visible{outline:2px solid var(--ink-soft);outline-offset:3px}

.rich-editor figure img[width][height] { width: min(100%, var(--image-width), calc(65vh * var(--image-ratio))); max-height: none; aspect-ratio: var(--image-ratio); }

/* Embedded video keeps its space while the provider loads. */
.rich-editor .embed-card { display: block; margin: 1.5em 0; white-space: normal; }
.rich-editor .embed-card iframe { display: block; width: 100%; aspect-ratio: 16 / 9; height: auto; border: 0; border-radius: 8px; background: var(--line); }
.rich-editor .embed-caption { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-top: 6px; font: 13px/1.5 var(--sans); color: var(--muted); }
.rich-editor .embed-caption a { color: var(--muted); }
.rich-editor [data-remove-embed] { min-height: 36px; padding: 4px 8px; border: 0; background: transparent; color: var(--muted); cursor: pointer; font: inherit; }
.rich-editor [data-remove-embed]:hover { color: var(--ink); }
.rich-editor [data-remove-embed]:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.help-menu { z-index: 240; flex: none; }
.help-menu .help-popover { top: auto; bottom: calc(100% + 10px); width: min(232px, calc(100vw - 32px)); max-height: calc(var(--visible-height, 100dvh) - 100px); }
#app.focus-mode .help-menu, #app.mobile-typing .help-menu { display: none; }
