html, body {
  color: #1f2328;
  overflow: hidden;
  margin: 0;
  padding: 0;
  font-family: Inter, Helvetica, Arial, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  background-color: #ffffff;
  overscroll-behavior-y: none;
}

* {
  box-sizing: border-box;
}

body {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

button,
select,
input {
  font: inherit;
}

button {
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid #d0d7de;
  background: linear-gradient(180deg, #ffffff 0%, #f6f8fa 100%);
  color: #1f2328;
  border-radius: 10px;
  padding: 8px 12px;
  cursor: pointer;
  font-weight: 600;
  box-shadow: 0 1px 0 rgba(31, 35, 40, 0.04);
  transition: background 0.18s ease, border-color 0.18s ease, transform 0.12s ease, box-shadow 0.18s ease;
}

button:hover {
  background: linear-gradient(180deg, #ffffff 0%, #eef2f6 100%);
  border-color: #b8c2cc;
  box-shadow: 0 2px 8px rgba(31, 35, 40, 0.06);
}

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

a {
  color: inherit;
  text-decoration: none;
}

input[type="text"],
input[type="number"],
select {
  min-height: 38px;
  border: 1px solid #d0d7de;
  border-radius: 10px;
  padding: 0 10px;
  background: #fff;
  color: #1f2328;
}

input[type="range"] {
  width: 110px;
}

label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

kbd {
  display: inline-block;
  padding: 2px 6px;
  border-radius: 6px;
  background: #f6f8fa;
  border: 1px solid #d0d7de;
  font-size: 12px;
}

pre {
  position: relative;
}

.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;
}

#app-header {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px 16px;
  background: linear-gradient(180deg, #f8fafc 0%, #f2f5f9 100%);
  border-bottom: 1px solid #d8dee4;
}

.toolbar-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  padding: 10px;
  border: 1px solid #d8dee4;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 6px 18px rgba(15, 23, 42, 0.04);
}

.compact-toolbar {
  gap: 10px;
}

.more-options-panel {
  gap: 10px;
}

.more-options-panel[hidden] {
  display: none !important;
}

.more-options-panel:not([hidden]) {
  display: grid;
}

.toolbar-group {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.grouped-controls {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: start;
  gap: 8px 12px;
  padding: 8px 10px;
  border: 1px solid #e2e8f0;
  border-radius: 14px;
  background: #f8fafc;
}

.compact-group {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 6px;
}

.compact-group .toolbar-label {
  margin-bottom: 0;
}

.compact-group .section-body,
.compact-group select,
.compact-group input {
  width: 100%;
}

.quick-actions-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  width: 100%;
}

.quick-actions-row > button {
  flex: 0 0 auto;
}

.section-header {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 38px;
  white-space: nowrap;
}

.section-body {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  align-content: center;
  gap: 8px;
  min-width: 0;
}

.grouped-controls.is-collapsed {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
}

.grouped-controls.is-collapsed .section-body {
  display: none;
}

.section-toggle-button {
  min-width: 26px;
  min-height: 26px;
  width: 26px;
  height: 26px;
  padding: 0;
  border-radius: 999px;
  font-size: 16px;
  font-weight: 700;
  line-height: 1;
  box-shadow: none;
}

.brand-block {
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-width: 180px;
  padding-right: 4px;
}

.brand-link {
  font-size: 18px;
  font-weight: 700;
}

.brand-subtitle {
  font-size: 12px;
  color: #59636e;
}

.document-switcher {
  flex: 1 1 220px;
  min-width: 220px;
}

.title-group {
  flex: 1 1 260px;
  min-width: 220px;
}

#document-title-input {
  width: 100%;
}

.quick-actions {
  flex: 0 1 auto;
  align-items: end;
}

.file-actions,
.export-actions,
.history-group,
.document-actions {
  justify-content: flex-start;
}

.format-toolbar {
  flex: 1 1 420px;
}

.format-toolbar button {
  min-width: 42px;
}

.preferences-group {
  flex: 1 1 260px;
}

.pdf-settings-group {
  flex: 1 1 420px;
}

.toolbar-label {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #59636e;
}

.field-suffix {
  color: #59636e;
  font-size: 13px;
}

#pdf-page-size-select,
#pdf-orientation-select,
#pdf-theme-select {
  min-width: 92px;
}

#pdf-margin-input {
  width: 68px;
}

#pdf-header-input,
#pdf-footer-input {
  width: 150px;
  max-width: 100%;
}

#export-button {
  background: linear-gradient(180deg, #1f7ae0 0%, #0969da 100%);
  border-color: #0969da;
  color: #ffffff;
}

#export-button:hover {
  background: linear-gradient(180deg, #1b6bc4 0%, #0550ae 100%);
  border-color: #0550ae;
}

#export-docx-button {
  background: linear-gradient(180deg, #1a8f5a 0%, #157347 100%);
  border-color: #157347;
  color: #ffffff;
}

#export-docx-button:hover {
  background: linear-gradient(180deg, #187f51 0%, #12643e 100%);
  border-color: #12643e;
}

#delete-doc-button,
#reset-button {
  color: #b42318;
  background: linear-gradient(180deg, #fff7f6 0%, #fdecec 100%);
  border-color: #f3c4c1;
}

#delete-doc-button:hover,
#reset-button:hover {
  background: linear-gradient(180deg, #fff1ef 0%, #fbdada 100%);
  border-color: #e9a9a4;
}

#more-options-button {
  background: linear-gradient(180deg, #ffffff 0%, #eef2f6 100%);
}

.metrics-group {
  margin-left: auto;
  color: #59636e;
  font-size: 13px;
}

.metrics-group span {
  padding: 4px 8px;
  border-radius: 999px;
  background: #ffffff;
  border: 1px solid #d0d7de;
}

.history-group select {
  min-width: 220px;
}

.status-message {
  flex: 1 1 180px;
  min-height: 24px;
  color: #0969da;
  font-size: 13px;
  padding: 0 6px;
}

.drop-overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(9, 105, 218, 0.14);
  color: #0b3d91;
  font-size: 18px;
  text-align: center;
  padding: 24px;
  z-index: 30;
  backdrop-filter: blur(2px);
  pointer-events: none;
}

.drop-overlay[hidden] {
  display: none;
}

#container {
  flex: 1;
  overflow: hidden;
  width: 100%;
  background: #ffffff;
  display: flex;
  min-height: 0;
}

.column {
  min-width: 0;
  min-height: 0;
}

.editor-pane,
.preview-pane {
  height: 100%;
}

#editor-wrapper,
#editor {
  height: 100%;
}

#edit {
  width: 50%;
}

#preview {
  width: 50%;
  display: flex;
  overflow: hidden;
  background: #fff;
}

#preview-wrapper {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px 48px;
  min-width: 0;
}

#output {
  margin: 0 auto;
  max-width: 920px;
}

.toc-panel {
  width: 260px;
  flex-shrink: 0;
  border-right: 1px solid #d8dee4;
  background: #fafbfc;
  padding: 16px 12px;
  overflow-y: auto;
}

.toc-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.toc-content {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.toc-content button {
  text-align: left;
  background: transparent;
  border: none;
  border-radius: 6px;
  padding: 6px 8px;
  box-shadow: none;
}

.toc-content button:hover {
  background: #e7edf3;
}

.toc-level-1 { padding-left: 4px; font-weight: 700; }
.toc-level-2 { padding-left: 16px; }
.toc-level-3 { padding-left: 28px; }
.toc-level-4 { padding-left: 40px; }
.toc-level-5 { padding-left: 52px; }
.toc-level-6 { padding-left: 64px; }

.split-container {
  display: flex;
  height: 100%;
  width: 100%;
}

.split-divider {
  width: 6px;
  background: #d8dee4;
  cursor: col-resize;
  z-index: 2;
  transition: background 0.15s ease;
}

.split-divider.hover {
  background: #8c959f;
}

.split-divider.active {
  background: #57606a;
}

.heading-anchor {
  margin-left: 8px;
  border: none;
  background: transparent;
  color: #0969da;
  opacity: 0;
  padding: 0;
  cursor: pointer;
  box-shadow: none;
}

.markdown-body h1:hover .heading-anchor,
.markdown-body h2:hover .heading-anchor,
.markdown-body h3:hover .heading-anchor,
.markdown-body h4:hover .heading-anchor,
.markdown-body h5:hover .heading-anchor,
.markdown-body h6:hover .heading-anchor {
  opacity: 1;
}

.code-copy-button {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 1;
  padding: 4px 8px;
  font-size: 12px;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 40;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
}

.modal-content {
  position: relative;
  margin: 5vh auto 0;
  width: min(900px, calc(100vw - 32px));
  max-height: 90vh;
  overflow: auto;
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 20px 50px rgba(15, 23, 42, 0.25);
}

.modal-header {
  position: sticky;
  top: 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 16px 20px;
  border-bottom: 1px solid #d8dee4;
  background: #fff;
}

.modal-body {
  padding: 20px;
  display: grid;
  gap: 20px;
}

.modal-section {
  display: grid;
  gap: 12px;
}

.hljs {
  color: #24292f;
  background: transparent;
}

.hljs-comment,
.hljs-quote {
  color: #6e7781;
  font-style: italic;
}

.hljs-keyword,
.hljs-selector-tag,
.hljs-literal,
.hljs-section,
.hljs-link {
  color: #cf222e;
}

.hljs-string,
.hljs-title,
.hljs-name,
.hljs-type,
.hljs-attribute,
.hljs-symbol,
.hljs-bullet,
.hljs-addition {
  color: #0a7c42;
}

.hljs-number,
.hljs-variable,
.hljs-template-variable,
.hljs-tag .hljs-attr,
.hljs-attr {
  color: #953800;
}

.hljs-built_in,
.hljs-doctag,
.hljs-code,
.hljs-formula {
  color: #0550ae;
}

body[data-focus-mode="editor"] #preview,
body[data-focus-mode="preview"] #edit,
body[data-focus-mode="editor"] .split-divider,
body[data-focus-mode="preview"] .split-divider {
  display: none;
}

body[data-focus-mode="editor"] #edit,
body[data-focus-mode="preview"] #preview {
  width: 100% !important;
}

body[data-focus-mode="editor"] #container,
body[data-focus-mode="preview"] #container {
  display: block;
}

body[data-focus-mode="editor"] #app-header,
body[data-focus-mode="preview"] #app-header {
  padding-bottom: 10px;
}

body.toc-collapsed .toc-panel {
  display: none;
}

[data-theme="dark"] html,
[data-theme="dark"] body {
  background: #0d1117;
  color: #e6edf3;
}

[data-theme="dark"] #app-header {
  background: linear-gradient(180deg, #11161d 0%, #0d1117 100%);
  border-bottom-color: #30363d;
}

[data-theme="dark"] .toolbar-row {
  background: rgba(22, 27, 34, 0.92);
  border-color: #30363d;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
}

[data-theme="dark"] .grouped-controls {
  background: #11161d;
  border-color: #30363d;
}

[data-theme="dark"] .brand-subtitle,
[data-theme="dark"] .metrics-group,
[data-theme="dark"] .status-message,
[data-theme="dark"] .toolbar-label,
[data-theme="dark"] .field-suffix {
  color: #9da7b3;
}

[data-theme="dark"] button,
[data-theme="dark"] select,
[data-theme="dark"] input[type="text"],
[data-theme="dark"] input[type="number"] {
  background: #21262d;
  color: #e6edf3;
  border-color: #30363d;
}

[data-theme="dark"] button:hover {
  background: #30363d;
  border-color: #57606a;
}

[data-theme="dark"] .section-toggle-button {
  background: #161b22;
}

[data-theme="dark"] #export-button {
  background: linear-gradient(180deg, #1f7ae0 0%, #0969da 100%);
  border-color: #1f7ae0;
}

[data-theme="dark"] #export-button:hover {
  background: linear-gradient(180deg, #1d6dca 0%, #0858b6 100%);
  border-color: #1d6dca;
}

[data-theme="dark"] #export-docx-button {
  background: linear-gradient(180deg, #238e63 0%, #1a7f53 100%);
  border-color: #238e63;
}

[data-theme="dark"] #export-docx-button:hover {
  background: linear-gradient(180deg, #1f8159 0%, #166947 100%);
  border-color: #1f8159;
}

[data-theme="dark"] #delete-doc-button,
[data-theme="dark"] #reset-button {
  color: #ffb4ab;
  background: #3a1f22;
  border-color: #6e2e35;
}

[data-theme="dark"] #container,
[data-theme="dark"] #preview {
  background: #0d1117;
}

[data-theme="dark"] .split-divider {
  background: #30363d;
}

[data-theme="dark"] .split-divider.hover {
  background: #57606a;
}

[data-theme="dark"] .split-divider.active {
  background: #768390;
}

[data-theme="dark"] .toc-panel {
  background: #11161d;
  border-right-color: #30363d;
}

[data-theme="dark"] .toc-content button:hover {
  background: #1f2937;
}

[data-theme="dark"] .modal-content,
[data-theme="dark"] .modal-header {
  background: #161b22;
  border-color: #30363d;
}

[data-theme="dark"] kbd,
[data-theme="dark"] .metrics-group span {
  background: #21262d;
  border-color: #30363d;
  color: #e6edf3;
}

[data-theme="dark"] .drop-overlay {
  background: rgba(88, 166, 255, 0.16);
  color: #c9d1d9;
}

[data-theme="dark"] .hljs {
  color: #c9d1d9;
}

[data-theme="dark"] .hljs-comment,
[data-theme="dark"] .hljs-quote {
  color: #8b949e;
}

[data-theme="dark"] .hljs-keyword,
[data-theme="dark"] .hljs-selector-tag,
[data-theme="dark"] .hljs-literal,
[data-theme="dark"] .hljs-section,
[data-theme="dark"] .hljs-link {
  color: #ff7b72;
}

[data-theme="dark"] .hljs-string,
[data-theme="dark"] .hljs-title,
[data-theme="dark"] .hljs-name,
[data-theme="dark"] .hljs-type,
[data-theme="dark"] .hljs-attribute,
[data-theme="dark"] .hljs-symbol,
[data-theme="dark"] .hljs-bullet,
[data-theme="dark"] .hljs-addition {
  color: #7ee787;
}

[data-theme="dark"] .hljs-number,
[data-theme="dark"] .hljs-variable,
[data-theme="dark"] .hljs-template-variable,
[data-theme="dark"] .hljs-tag .hljs-attr,
[data-theme="dark"] .hljs-attr {
  color: #ffa657;
}

[data-theme="dark"] .hljs-built_in,
[data-theme="dark"] .hljs-doctag,
[data-theme="dark"] .hljs-code,
[data-theme="dark"] .hljs-formula {
  color: #79c0ff;
}

@media (max-width: 1100px) {
  .metrics-group {
    margin-left: 0;
  }

  #preview {
    flex-direction: column;
  }

  .toc-panel {
    width: 100%;
    max-height: 180px;
    border-right: none;
    border-bottom: 1px solid #d8dee4;
  }
}

@media (max-width: 900px) {
  html, body {
    overflow: auto;
  }

  body {
    height: auto;
    min-height: 100vh;
  }

  #container {
    flex-direction: column;
    overflow: visible;
  }

  #edit,
  #preview {
    width: 100% !important;
    min-height: 50vh;
  }

  #preview {
    min-height: 45vh;
  }

  .split-divider {
    display: none;
  }

  body[data-focus-mode="split"] #container {
    display: flex;
  }

  body[data-focus-mode="editor"] #preview,
  body[data-focus-mode="preview"] #edit {
    display: none;
  }

  .toolbar-row {
    align-items: stretch;
    padding: 10px;
  }

  .toolbar-group,
  .title-group,
  .document-switcher,
  .file-actions,
  .export-actions,
  .history-group,
  .grouped-controls,
  .quick-actions,
  .status-message {
    width: 100%;
  }

  .grouped-controls,
  .compact-group {
    display: flex;
    flex-direction: column;
    padding: 10px;
  }

  .section-header,
  .section-body {
    width: 100%;
  }

  #pdf-margin-input,
  #pdf-header-input,
  #pdf-footer-input,
  #document-title-input,
  .document-switcher select,
  .history-group select {
    width: 100%;
  }

  #pdf-page-size-select,
  #pdf-orientation-select,
  #pdf-theme-select {
    min-width: 0;
  }
}