:root {
  color-scheme: light;
  --bg: #eef1f5;
  --surface: #ffffff;
  --surface-2: #f7f8fa;
  --surface-3: #edf0f4;
  --border: #d9dee7;
  --border-strong: #c5ccd8;
  --text: #172033;
  --muted: #687387;
  --accent: #f5a623;
  --accent-soft: #fff2d8;
  --accent-strong: #b86900;
  --navy: #111827;
  --navy-2: #1d2939;
  --green: #12a866;
  --danger: #d03f4f;
  --shadow: 0 18px 50px rgba(17,24,39,.12);
  --editor-size: 16px;
  --preview-scale: 1;
  --sidebar-width: 250px;
  --editor-ratio: 50%;
  --radius-sm: 7px;
  --radius-md: 11px;
  --radius-lg: 16px;
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0d1118;
  --surface: #151b25;
  --surface-2: #101620;
  --surface-3: #1b2431;
  --border: #293445;
  --border-strong: #3b485c;
  --text: #e7ebf2;
  --muted: #98a4b7;
  --accent-soft: #3b2b10;
  --accent-strong: #ffc35c;
  --navy: #080c12;
  --navy-2: #121923;
  --shadow: 0 18px 50px rgba(0,0,0,.32);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
::selection { color: var(--text); background: rgba(245,166,35,.34); }
body {
  margin: 0;
  overflow: hidden;
  color: var(--text);
  background: var(--bg);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input, textarea { font: inherit; }
button { color: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button:focus-visible, a:focus-visible, input:focus-visible, textarea:focus-visible, [tabindex]:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--accent) 72%, white);
  outline-offset: 2px;
}
button:disabled { opacity: .45; cursor: not-allowed; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
.skip-link { position: fixed; z-index: 1000; top: -60px; left: 16px; padding: 10px 14px; color: #111827; background: var(--accent); border-radius: 8px; font-weight: 800; }
.skip-link:focus { top: 12px; }

.app-shell {
  height: 100dvh;
  display: grid;
  grid-template-rows: 64px auto 1fr 30px;
  min-width: 0;
}

.topbar {
  position: relative;
  z-index: 20;
  display: grid;
  grid-template-columns: minmax(190px, 260px) minmax(180px, 1fr) auto;
  align-items: center;
  gap: 20px;
  padding: 0 18px;
  color: #fff;
  background: var(--navy);
  border-bottom: 1px solid rgba(255,255,255,.08);
}
.topbar::after { content: ""; position: absolute; left: 0; right: 0; bottom: -1px; height: 1px; background: linear-gradient(90deg, var(--accent), transparent 34%, transparent 66%, rgba(245,166,35,.18)); pointer-events: none; }
.brand { min-width: 0; display: flex; align-items: center; gap: 11px; color: inherit; text-decoration: none; }
.brand-mark { display: grid; place-items: center; width: 37px; height: 37px; color: #111827; background: var(--accent); border-radius: 10px; font-weight: 900; letter-spacing: -.08em; box-shadow: inset 0 -2px 0 rgba(0,0,0,.12); }
.brand > span:last-child { display: grid; line-height: 1.1; }
.brand strong { font-size: 15px; letter-spacing: -.02em; }
.brand small { margin-top: 4px; color: #8f9bae; font-size: 9px; letter-spacing: .08em; text-transform: uppercase; }
.document-title input {
  width: min(440px, 100%);
  height: 38px;
  padding: 0 12px;
  color: #e8ecf4;
  background: rgba(255,255,255,.055);
  border: 1px solid transparent;
  border-radius: 8px;
  outline: 0;
  font-weight: 650;
  text-align: center;
  transition: background .2s, border-color .2s;
}
.document-title input:hover { background: rgba(255,255,255,.09); }
.document-title input:focus { background: rgba(255,255,255,.1); border-color: rgba(245,166,35,.65); }
.file-actions { display: flex; align-items: center; justify-content: flex-end; gap: 7px; }
.action-button, .icon-button {
  min-height: 36px;
  padding: 0 12px;
  color: #dce2eb;
  background: rgba(255,255,255,.06);
  border: 1px solid rgba(255,255,255,.09);
  border-radius: 8px;
  cursor: pointer;
  font-size: 11px;
  font-weight: 750;
  transition: transform .18s, background .18s, border-color .18s;
}
.action-button:hover, .icon-button:hover { background: rgba(255,255,255,.11); border-color: rgba(255,255,255,.18); transform: translateY(-1px); }
.action-primary { color: #111827; background: var(--accent); border-color: var(--accent); }
.action-primary:hover { background: #ffbc46; border-color: #ffbc46; }
.icon-button { padding-inline: 10px; }
.theme-button { width: 36px; padding: 0; font-size: 18px; }
.menu-wrap { position: relative; }
.dropdown-menu {
  position: absolute;
  z-index: 50;
  top: calc(100% + 8px);
  right: 0;
  width: 180px;
  padding: 6px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow);
}
.dropdown-menu[hidden] { display: none; }
.dropdown-menu button { width: 100%; padding: 10px; text-align: left; color: inherit; background: transparent; border: 0; border-radius: 7px; cursor: pointer; font-size: 12px; }
.dropdown-menu button:hover { color: var(--accent-strong); background: var(--accent-soft); }

.formatbar {
  position: relative;
  z-index: 10;
  min-height: 47px;
  display: flex;
  align-items: center;
  gap: 6px;
  overflow-x: auto;
  padding: 6px 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  scrollbar-width: thin;
  overscroll-behavior-inline: contain;
  scroll-snap-type: x proximity;
}
.toolbar-group { flex: 0 0 auto; display: flex; align-items: center; gap: 2px; padding-right: 6px; margin-right: 2px; border-right: 1px solid var(--border); scroll-snap-align: start; }
.toolbar-group:last-child { border-right: 0; }
.toolbar-spacer { flex: 1 1 auto; }
.formatbar button, .pane-tools button {
  min-width: 32px;
  height: 32px;
  padding: 0 8px;
  color: var(--muted);
  background: transparent;
  border: 1px solid transparent;
  border-radius: 6px;
  cursor: pointer;
  font-size: 11px;
  font-weight: 750;
}
.formatbar button:hover, .formatbar button[aria-pressed="true"], .pane-tools button:hover { color: var(--accent-strong); background: var(--accent-soft); border-color: rgba(245,166,35,.22); }
.layout-switcher { flex: 0 0 auto; display: grid; grid-template-columns: repeat(3, auto); gap: 2px; padding: 3px; margin-right: 5px; background: var(--surface-3); border: 1px solid var(--border); border-radius: 9px; }
.layout-switcher button { height: 26px; min-width: 0; padding: 0 8px; border-radius: 5px; font-size: 9px; }
.layout-switcher button[aria-pressed="true"] { color: var(--text); background: var(--surface); border-color: var(--border); box-shadow: 0 2px 7px rgba(17,24,39,.08); }

.mobile-switcher { display: none; }
.workspace {
  min-height: 0;
  display: grid;
  grid-template-columns: var(--sidebar-width) minmax(280px, var(--editor-ratio)) 6px minmax(320px, 1fr);
  background: var(--border);
}
.sidebar, .editor-pane, .preview-pane { min-width: 0; min-height: 0; background: var(--surface); }
.sidebar { position: relative; display: grid; grid-template-rows: auto 1fr auto; border-right: 1px solid var(--border); transition: width .2s, opacity .2s; }
.sidebar-head, .pane-head {
  height: 45px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 13px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
}
.sidebar-head > div { display: grid; }
.sidebar-head span { color: var(--muted); font-size: 8px; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; }
.sidebar-head strong, .pane-head strong { font-size: 11px; }
.sidebar-head button { width: 27px; height: 27px; padding: 0; color: var(--muted); background: transparent; border: 1px solid var(--border); border-radius: 6px; cursor: pointer; font-size: 18px; }
.outline { overflow-y: auto; padding: 10px 8px 24px; }
.outline button { width: 100%; display: block; overflow: hidden; padding: 7px 9px; color: var(--muted); background: transparent; border: 0; border-radius: 6px; cursor: pointer; font-size: 11px; line-height: 1.35; text-align: left; text-overflow: ellipsis; white-space: nowrap; }
.outline button:hover { color: var(--accent-strong); background: var(--accent-soft); }
.outline button[aria-current="location"] { color: var(--accent-strong); background: var(--accent-soft); box-shadow: inset 3px 0 0 var(--accent); font-weight: 750; }
.outline button[data-level="2"] { padding-left: 20px; }
.outline button[data-level="3"] { padding-left: 32px; font-size: 10px; }
.empty-state { padding: 12px 9px; color: var(--muted); font-size: 11px; }
.document-insights { padding: 14px; background: var(--surface-2); border-top: 1px solid var(--border); }
.document-insights > strong { font-size: 10px; text-transform: uppercase; letter-spacing: .08em; }
.document-insights dl { display: grid; gap: 7px; margin: 10px 0 0; }
.document-insights dl div { display: flex; justify-content: space-between; gap: 12px; color: var(--muted); font-size: 10px; }
.document-insights dt, .document-insights dd { margin: 0; }
.document-insights dd { color: var(--text); font-weight: 750; }
.app-shell.sidebar-collapsed .workspace { --sidebar-width: 0px; }
.app-shell.sidebar-collapsed .sidebar { overflow: hidden; opacity: 0; pointer-events: none; }

.editor-pane, .preview-pane { min-height: 0; height: 100%; overflow: hidden; display: grid; grid-template-rows: auto auto minmax(0, 1fr); }
.editor-pane > .pane-head { grid-row: 1; }
.editor-pane > .find-panel { grid-row: 2; }
.editor-pane > #editor { grid-row: 3; }
.preview-pane { grid-template-rows: auto minmax(0, 1fr); }
.pane-head > div:first-child { display: flex; align-items: center; gap: 8px; }
.status-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 4px rgba(245,166,35,.12); }
.preview-dot { background: var(--green); box-shadow: 0 0 0 4px rgba(18,168,102,.12); }
.pane-tools { display: flex; align-items: center; gap: 2px; color: var(--muted); font-size: 9px; }
.pane-tools button { min-width: 25px; width: auto; height: 27px; padding-inline: 5px; }
.sync-toggle { display: flex; align-items: center; gap: 5px; margin-right: 8px; cursor: pointer; }
.sync-toggle input { accent-color: var(--accent); }

.find-panel {
  min-height: 43px;
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 6px 8px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
}
.find-panel[hidden] { display: none; }
.find-panel label { flex: 1 1 130px; }
.find-panel input { width: 100%; height: 30px; padding: 0 9px; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 6px; outline: 0; font-size: 10px; }
.find-panel input:focus { border-color: var(--accent); }
.find-panel > span { flex: 0 0 auto; min-width: 66px; color: var(--muted); font-size: 9px; text-align: center; }
.find-panel button { flex: 0 0 auto; height: 29px; padding: 0 7px; color: var(--muted); background: var(--surface); border: 1px solid var(--border); border-radius: 6px; cursor: pointer; font-size: 9px; }
.find-panel button:hover { color: var(--accent-strong); border-color: var(--accent); }

#editor {
  width: 100%;
  height: auto;
  min-height: 0;
  align-self: stretch;
  resize: none;
  padding: 28px 32px 80px;
  color: var(--text);
  background: var(--surface);
  border: 0;
  outline: 0;
  font: 400 var(--editor-size)/1.72 "Cascadia Code", "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  tab-size: 2;
  caret-color: var(--accent-strong);
}
#editor.no-wrap { white-space: pre; overflow-x: auto; }
#editor::selection { color: var(--text); background: rgba(245,166,35,.3); }

.resize-handle { position: relative; cursor: col-resize; background: var(--border); outline: 0; }
.resize-handle::after { content: ""; position: absolute; inset: 0 2px; background: transparent; transition: background .18s; }
.resize-handle:hover::after, .resize-handle:focus::after, .workspace.is-resizing .resize-handle::after { background: var(--accent); }
.workspace.is-resizing { user-select: none; cursor: col-resize; }

.preview-scroll { min-height: 0; overflow: auto; background: var(--surface); scroll-behavior: smooth; }
.markdown-body {
  width: min(820px, calc(100% - 64px));
  min-height: 100%;
  margin: 0 auto;
  padding: 42px 0 120px;
  color: var(--text);
  font-size: calc(16px * var(--preview-scale));
  line-height: 1.72;
  overflow-wrap: anywhere;
}
.markdown-body > :first-child { margin-top: 0; }
.markdown-body h1, .markdown-body h2, .markdown-body h3, .markdown-body h4 { color: var(--text); line-height: 1.2; letter-spacing: -.025em; scroll-margin-top: 24px; }
.markdown-body h1 { margin: 0 0 28px; padding-bottom: 14px; border-bottom: 2px solid var(--border); font-size: 2.25em; }
.markdown-body h2 { margin: 42px 0 18px; padding-bottom: 9px; border-bottom: 1px solid var(--border); font-size: 1.6em; }
.markdown-body h3 { margin: 30px 0 12px; font-size: 1.25em; }
.markdown-body p { margin: 0 0 18px; }
.markdown-body a { color: #c17608; text-decoration-thickness: 1px; text-underline-offset: 3px; }
.markdown-body a:hover { color: var(--accent-strong); }
.markdown-body blockquote { margin: 24px 0; padding: 10px 20px; color: var(--muted); background: var(--accent-soft); border-left: 4px solid var(--accent); border-radius: 0 8px 8px 0; }
.markdown-body blockquote > :last-child { margin-bottom: 0; }
.markdown-body code { padding: .18em .38em; color: #b75064; background: var(--surface-3); border: 1px solid var(--border); border-radius: 5px; font-family: "Cascadia Code", Consolas, monospace; font-size: .88em; }
.markdown-body pre { overflow-x: auto; margin: 24px 0; padding: 20px; color: #e7ebf2; background: #111827; border: 1px solid #263245; border-radius: 10px; box-shadow: 0 12px 28px rgba(17,24,39,.12); }
.markdown-body pre code { padding: 0; color: inherit; background: transparent; border: 0; font-size: .88em; }
.markdown-body table { width: 100%; margin: 24px 0; border-collapse: collapse; font-size: .92em; }
.markdown-body th, .markdown-body td { padding: 10px 12px; border: 1px solid var(--border); text-align: left; }
.markdown-body th { background: var(--surface-2); font-weight: 750; }
.markdown-body tr:nth-child(even) td { background: color-mix(in srgb, var(--surface-2) 60%, transparent); }
.markdown-body img { display: block; max-width: 100%; height: auto; margin: 24px auto; border-radius: 10px; box-shadow: var(--shadow); }
.markdown-body hr { height: 1px; margin: 34px 0; background: var(--border); border: 0; }
.markdown-body ul, .markdown-body ol { padding-left: 1.5em; }
.markdown-body li { margin: .35em 0; }
.markdown-body input[type="checkbox"] { margin-right: 7px; accent-color: var(--accent); }
.markdown-body .footnotes { margin-top: 50px; color: var(--muted); font-size: .9em; }

.statusbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 0 14px;
  color: #98a4b7;
  background: var(--navy);
  border-top: 1px solid rgba(255,255,255,.07);
  font-size: 9px;
}
.statusbar > div { display: flex; align-items: center; gap: 7px; min-width: 0; }
.status-separator { color: #4d596b; }
[data-save-status].is-saving { color: var(--accent); }
[data-save-status].is-saved { color: #55d697; }

.help-dialog {
  width: min(760px, calc(100% - 28px));
  max-height: calc(100dvh - 28px);
  padding: 0;
  color: var(--text);
  background: transparent;
  border: 0;
  border-radius: 16px;
}
.help-dialog::backdrop { background: rgba(5,9,15,.7); backdrop-filter: blur(4px); }
.dialog-card { overflow: auto; max-height: calc(100dvh - 28px); background: var(--surface); border: 1px solid var(--border); border-radius: 16px; box-shadow: 0 30px 100px rgba(0,0,0,.35); }
.dialog-card header, .dialog-card footer { display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 18px 22px; background: var(--surface-2); border-bottom: 1px solid var(--border); }
.dialog-card footer { border-top: 1px solid var(--border); border-bottom: 0; }
.dialog-card header span { color: var(--accent-strong); font-size: 9px; font-weight: 800; letter-spacing: .1em; text-transform: uppercase; }
.dialog-card h2 { margin: 4px 0 0; font-size: 22px; }
.dialog-card header button { width: 32px; height: 32px; color: var(--muted); background: transparent; border: 1px solid var(--border); border-radius: 50%; cursor: pointer; font-size: 20px; }
.help-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 28px; padding: 24px; }
.help-grid h3 { margin: 0 0 14px; font-size: 13px; }
.shortcut-list { display: grid; gap: 8px; margin: 0; }
.shortcut-list div { display: flex; justify-content: space-between; gap: 16px; padding-bottom: 8px; border-bottom: 1px solid var(--border); font-size: 11px; }
.shortcut-list dt, .shortcut-list dd { margin: 0; }
kbd { display: inline-block; min-width: 22px; padding: 3px 5px; color: var(--muted); background: var(--surface-2); border: 1px solid var(--border-strong); border-bottom-width: 2px; border-radius: 5px; font: 700 9px monospace; text-align: center; }
.help-grid pre { overflow: auto; margin: 0; padding: 16px; color: #dce3ed; background: #111827; border-radius: 9px; font-size: 10px; line-height: 1.55; }
.dialog-card footer button { min-height: 36px; padding: 0 13px; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 7px; cursor: pointer; font-size: 10px; font-weight: 750; }
.dialog-card footer .action-primary { color: #111827; background: var(--accent); border-color: var(--accent); }

.command-dialog {
  width: min(610px, calc(100% - 24px));
  max-height: min(680px, calc(100dvh - 24px));
  padding: 0;
  color: var(--text);
  background: transparent;
  border: 0;
  border-radius: var(--radius-lg);
}
.command-dialog::backdrop { background: rgba(5,9,15,.72); backdrop-filter: blur(7px); }
.command-card { overflow: hidden; background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--radius-lg); box-shadow: 0 34px 110px rgba(0,0,0,.4); }
.command-card header { display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 15px 18px; background: var(--surface-2); border-bottom: 1px solid var(--border); }
.command-card header > div { display: grid; }
.command-card header span { color: var(--accent-strong); font-size: 8px; font-weight: 850; letter-spacing: .12em; text-transform: uppercase; }
.command-card h2 { margin: 3px 0 0; font-size: 16px; }
.command-search { display: grid; grid-template-columns: 28px 1fr; align-items: center; gap: 4px; margin: 12px; padding: 0 11px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; }
.command-search > span:first-child { color: var(--muted); font-size: 20px; text-align: center; }
.command-search input { width: 100%; height: 46px; color: var(--text); background: transparent; border: 0; outline: 0; font-size: 13px; }
.command-results { max-height: min(420px, calc(100dvh - 235px)); overflow-y: auto; padding: 0 8px 10px; }
.command-results button { width: 100%; min-height: 48px; display: grid; grid-template-columns: 32px minmax(0,1fr) auto; align-items: center; gap: 10px; padding: 7px 10px; color: var(--text); background: transparent; border: 0; border-radius: 9px; cursor: pointer; text-align: left; }
.command-results button:hover, .command-results button.is-active { background: var(--accent-soft); }
.command-results .command-icon { display: grid; place-items: center; width: 30px; height: 30px; color: var(--accent-strong); background: var(--surface); border: 1px solid var(--border); border-radius: 7px; font-weight: 850; }
.command-copy { min-width: 0; display: grid; gap: 2px; }
.command-copy strong { overflow: hidden; font-size: 11px; text-overflow: ellipsis; white-space: nowrap; }
.command-copy small { overflow: hidden; color: var(--muted); font-size: 9px; text-overflow: ellipsis; white-space: nowrap; }
.command-results .command-shortcut { color: var(--muted); font-size: 8px; }
.command-empty { padding: 30px 18px; color: var(--muted); font-size: 11px; text-align: center; }
.command-card footer { display: flex; align-items: center; gap: 16px; padding: 10px 14px; color: var(--muted); background: var(--surface-2); border-top: 1px solid var(--border); font-size: 8px; }
.command-card footer span:last-child { margin-left: auto; }

.toast-region { position: fixed; z-index: 100; right: 16px; bottom: 44px; display: grid; gap: 8px; pointer-events: none; }
.toast { min-width: 220px; max-width: 340px; padding: 11px 14px; color: #fff; background: var(--navy-2); border: 1px solid rgba(255,255,255,.12); border-left: 3px solid var(--accent); border-radius: 9px; box-shadow: var(--shadow); font-size: 10px; animation: toast-in .25s ease both; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.app-shell.focus-mode { grid-template-rows: 0 0 1fr 30px; }
.app-shell.focus-mode .topbar, .app-shell.focus-mode .formatbar { overflow: hidden; opacity: 0; pointer-events: none; }
.app-shell.focus-mode .workspace { --sidebar-width: 0px; }
.app-shell.focus-mode .sidebar { overflow: hidden; opacity: 0; pointer-events: none; }

@media (min-width: 861px) {
  .app-shell.layout-editor .workspace { grid-template-columns: var(--sidebar-width) minmax(0, 1fr); }
  .app-shell.layout-editor .preview-pane, .app-shell.layout-editor .resize-handle { display: none; }
  .app-shell.layout-preview .workspace { grid-template-columns: var(--sidebar-width) minmax(0, 1fr); }
  .app-shell.layout-preview .editor-pane, .app-shell.layout-preview .resize-handle { display: none; }
}

@media (max-width: 1100px) {
  .topbar { grid-template-columns: 190px minmax(140px, 1fr) auto; gap: 10px; }
  .brand small { display: none; }
  .file-actions .action-button:not(.action-primary) { display: none; }
  .workspace { --sidebar-width: 210px; }
  #editor { padding-inline: 22px; }
  .markdown-body { width: calc(100% - 42px); }
  .sync-toggle span { display: none; }
}

@media (max-width: 860px) {
  body { overflow: hidden; }
  .app-shell { grid-template-rows: 58px auto 42px 1fr 30px; }
  .topbar { grid-template-columns: auto minmax(100px, 1fr) auto; padding-inline: 10px; }
  .brand > span:last-child { display: none; }
  .brand-mark { width: 36px; height: 36px; }
  .document-title input { height: 36px; padding-inline: 7px; text-align: left; font-size: 12px; }
  .file-actions { gap: 4px; }
  .file-actions .action-primary { width: 36px; overflow: hidden; padding: 0; color: transparent; }
  .file-actions .action-primary::before { content: "↓"; color: #111827; font-size: 17px; }
  .file-actions .menu-wrap { display: none; }
  .icon-button { width: 34px; padding: 0; }
  .palette-button { display: none; }
  .formatbar { min-height: 44px; padding-inline: 8px; }
  .formatbar button { min-width: 40px; min-height: 36px; }
  .toolbar-spacer { display: none; }
  .layout-switcher { display: none; }
  .mobile-switcher { display: grid; grid-template-columns: repeat(3, 1fr); background: var(--surface); border-bottom: 1px solid var(--border); }
  .mobile-switcher button { position: relative; min-height: 42px; color: var(--muted); background: transparent; border: 0; cursor: pointer; font-size: 10px; font-weight: 800; }
  .mobile-switcher button[aria-selected="true"] { color: var(--accent-strong); }
  .mobile-switcher button[aria-selected="true"]::after { content: ""; position: absolute; left: 20%; right: 20%; bottom: 0; height: 2px; background: var(--accent); }
  .workspace { display: block; position: relative; min-height: 0; background: var(--surface); }
  .sidebar, .editor-pane, .preview-pane { position: absolute; inset: 0; border: 0; }
  .resize-handle { display: none; }
  .workspace[data-mobile-active="editor"] .sidebar,
  .workspace[data-mobile-active="editor"] .preview-pane,
  .workspace[data-mobile-active="preview"] .sidebar,
  .workspace[data-mobile-active="preview"] .editor-pane,
  .workspace[data-mobile-active="outline"] .editor-pane,
  .workspace[data-mobile-active="outline"] .preview-pane { display: none; }
  .workspace[data-mobile-active="outline"] .sidebar { display: grid; opacity: 1; pointer-events: auto; }
  .sidebar-head button { display: none; }
  .outline { padding-inline: 14px; }
  .pane-head { height: 41px; }
  .pane-tools button { min-width: 34px; min-height: 34px; }
  #editor { padding: 20px 17px 90px; font-size: max(16px, var(--editor-size)); }
  .markdown-body { width: calc(100% - 34px); padding-top: 28px; }
  .find-panel { flex-wrap: wrap; }
  .find-panel label { flex-basis: calc(50% - 4px); }
  .find-panel > span { order: 3; flex: 1 1 auto; text-align: left; }
  .statusbar { padding-inline: 10px; }
  .statusbar > div:first-child .status-separator, [data-line-position] { display: none; }
  .statusbar > div:last-child span:nth-child(n+2) { display: none; }
  .help-grid { grid-template-columns: 1fr; }
  .command-results button { min-height: 54px; }
  .command-card footer span:last-child { display: none; }
  .toast-region { left: 12px; right: 12px; bottom: 40px; }
  .toast { width: 100%; max-width: none; }
  .app-shell.focus-mode { grid-template-rows: 0 0 42px 1fr 30px; }
}

@media (max-width: 410px) {
  .topbar { gap: 6px; }
  .file-actions .theme-button { display: none; }
  .document-title input { font-size: 11px; }
  .pane-tools { gap: 0; }
  .sync-toggle { margin-right: 2px; }
  .find-panel button[data-replace-one], .find-panel button[data-replace-all] { flex: 1 1 auto; }
  .dialog-card header, .dialog-card footer { padding-inline: 16px; }
  .help-grid { padding: 18px 16px; }
}

@media (max-height: 600px) and (min-width: 861px) {
  .app-shell { grid-template-rows: 54px auto 1fr 28px; }
  .topbar { min-height: 54px; }
  .formatbar { min-height: 42px; }
  .pane-head { height: 40px; }
  .markdown-body { padding-top: 28px; }
}

@media print {
  body { overflow: visible; background: #fff; }
  .topbar, .formatbar, .mobile-switcher, .sidebar, .editor-pane, .resize-handle, .pane-head, .statusbar, .toast-region { display: none !important; }
  .app-shell, .workspace, .preview-pane { display: block; height: auto; background: #fff; }
  .preview-pane { position: static; }
  .preview-scroll { overflow: visible; }
  .markdown-body { width: 100%; padding: 0; color: #111; font-size: 11pt; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

@media (prefers-contrast: more) {
  :root { --border: #aab2bf; --border-strong: #7c8798; --muted: #4f5a6d; }
  [data-theme="dark"] { --border: #59677c; --border-strong: #8491a4; --muted: #c0c9d6; }
  button, input, textarea { border-color: var(--border-strong); }
}

@media (forced-colors: active) {
  .brand-mark, .status-dot, .preview-dot { forced-color-adjust: none; }
  .outline button[aria-current="location"] { border-left: 3px solid Highlight; }
}
