:root {
  --bg: #1c1917;
  --bg-elevated: #292524;
  --bg-pane: #0c0a09;
  --border: #44403c;
  --text: #fafaf9;
  --text-muted: #a8a29e;
  --accent: #d97706;
  --accent-text: #1c1917;
  --link: #fbbf24;
  --code-bg: #292524;
  --selection: rgba(217, 119, 6, 0.35);
  --font-ui: "Avenir Next", "Segoe UI", "Helvetica Neue", sans-serif;
  --font-mono: "SF Mono", "Menlo", "Consolas", "Liberation Mono", monospace;
  --font-prose: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --toolbar-h: 3.25rem;
  --radius: 6px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
}

#app {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 100dvh;
}

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

.toolbar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 0.75rem;
  min-height: var(--toolbar-h);
  padding: 0.5rem 0.85rem;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
}

.toolbar-brand {
  display: flex;
  align-items: baseline;
  gap: 0.65rem;
  min-width: 0;
}

.brand {
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--accent);
  flex-shrink: 0;
}

.file-name {
  color: var(--text-muted);
  font-size: 0.875rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-name.is-dirty::after {
  content: " •";
  color: var(--accent);
}

.toolbar-actions {
  display: flex;
  gap: 0.4rem;
  justify-content: center;
}

.view-toggle {
  display: flex;
  gap: 0.25rem;
  justify-content: flex-end;
}

.btn {
  appearance: none;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  border-radius: var(--radius);
  padding: 0.35rem 0.7rem;
  font: inherit;
  font-size: 0.85rem;
  cursor: pointer;
  line-height: 1.2;
}

.btn:hover {
  border-color: var(--text-muted);
  background: rgba(255, 255, 255, 0.04);
}

.btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
  font-weight: 600;
}

.btn-primary:hover {
  filter: brightness(1.08);
  background: var(--accent);
  border-color: var(--accent);
}

.btn-toggle.is-active {
  background: var(--bg-pane);
  border-color: var(--text-muted);
  color: var(--text);
}

.workspace {
  position: relative;
  flex: 1;
  display: grid;
  min-height: 0;
  background: var(--bg-pane);
}

.drop-overlay {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  background: rgba(28, 25, 23, 0.82);
  border: 2px dashed var(--accent);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 1.1rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  pointer-events: none;
}

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

.workspace.is-dragover .drop-overlay {
  display: grid;
}

.workspace.view-split {
  grid-template-columns: 1fr 1fr;
}

.workspace.view-edit .pane-preview,
.workspace.view-preview .pane-editor {
  display: none;
}

.workspace.view-edit,
.workspace.view-preview {
  grid-template-columns: 1fr;
}

.pane {
  min-width: 0;
  min-height: 0;
  overflow: auto;
}

.pane-editor {
  border-right: 1px solid var(--border);
}

.workspace.view-edit .pane-editor {
  border-right: none;
}

#editor {
  display: block;
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 1.25rem 1.35rem;
  border: 0;
  resize: none;
  background: transparent;
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 0.95rem;
  line-height: 1.55;
  tab-size: 2;
  caret-color: var(--accent);
}

#editor:focus {
  outline: none;
}

#editor::selection {
  background: var(--selection);
}

#editor::placeholder {
  color: var(--text-muted);
}

.preview {
  padding: 1.25rem 1.5rem 2.5rem;
  max-width: 48rem;
}

.prose {
  font-family: var(--font-prose);
  font-size: 1.05rem;
  line-height: 1.65;
  color: var(--text);
}

.prose > :first-child {
  margin-top: 0;
}

.prose h1,
.prose h2,
.prose h3,
.prose h4 {
  font-family: var(--font-ui);
  line-height: 1.25;
  margin: 1.4em 0 0.5em;
}

.prose h1 {
  font-size: 1.85rem;
  border-bottom: 1px solid var(--border);
  padding-bottom: 0.35em;
}

.prose h2 {
  font-size: 1.45rem;
}

.prose h3 {
  font-size: 1.2rem;
}

.prose a {
  color: var(--link);
}

.prose code {
  font-family: var(--font-mono);
  font-size: 0.88em;
  background: var(--code-bg);
  padding: 0.12em 0.35em;
  border-radius: 4px;
}

.prose pre {
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.9rem 1rem;
  overflow-x: auto;
}

.prose pre code {
  background: none;
  padding: 0;
  font-size: 0.85rem;
}

.prose blockquote {
  margin: 1em 0;
  padding: 0.15em 0 0.15em 1em;
  border-left: 3px solid var(--accent);
  color: var(--text-muted);
}

.prose table {
  border-collapse: collapse;
  width: 100%;
  margin: 1em 0;
  font-family: var(--font-ui);
  font-size: 0.95rem;
}

.prose th,
.prose td {
  border: 1px solid var(--border);
  padding: 0.45rem 0.65rem;
  text-align: left;
}

.prose th {
  background: var(--bg-elevated);
}

.prose hr {
  border: 0;
  border-top: 1px solid var(--border);
  margin: 1.75em 0;
}

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

.prose ul,
.prose ol {
  padding-left: 1.4em;
}

.prose li + li {
  margin-top: 0.25em;
}

@media (max-width: 800px) {
  .toolbar {
    grid-template-columns: 1fr;
    gap: 0.5rem;
  }

  .toolbar-brand,
  .toolbar-actions,
  .view-toggle {
    justify-content: flex-start;
  }

  .view-toggle {
    width: 100%;
  }

  .view-toggle .btn {
    flex: 1;
  }

  .workspace.view-split {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr 1fr;
  }

  .pane-editor {
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
}
