:root {
  --bg: #0f1419;
  --bg-elev: #161b22;
  --bg-elev-2: #1c232c;
  --border: #232b36;
  --border-strong: #2f3947;
  --text: #e6edf3;
  --text-muted: #9aa6b2;
  --accent: #7c9cff;
  --accent-strong: #5b7cff;
  --accent-fg: #0a0f1a;
  --danger: #ff6b6b;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue",
    Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "JetBrains Mono", Menlo, Consolas, monospace;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
}

body {
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.55;
  overflow: hidden;
}

/* ---------- Header ---------- */

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 20px;
  background: var(--bg-elev);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.brand {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.logo {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 18px;
  letter-spacing: -0.02em;
}

.logo-accent {
  color: var(--accent);
  margin: 0 2px;
}

.tagline {
  font-size: 12px;
  color: var(--text-muted);
}

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

#filename {
  background: var(--bg-elev-2);
  border: 1px solid var(--border-strong);
  color: var(--text);
  padding: 8px 10px;
  font-family: var(--font-mono);
  font-size: 13px;
  border-radius: var(--radius-sm);
  width: 180px;
  outline: none;
  transition: border-color 0.15s;
}

#filename:focus {
  border-color: var(--accent);
}

.ext {
  font-family: var(--font-mono);
  color: var(--text-muted);
  font-size: 13px;
  margin-left: -6px;
  margin-right: 4px;
}

.btn {
  border: 1px solid var(--border-strong);
  background: var(--bg-elev-2);
  color: var(--text);
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.05s;
  font-family: inherit;
}

.btn:hover {
  background: #232b36;
  border-color: #3a4757;
}

.btn:active {
  transform: translateY(1px);
}

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

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

.btn-primary:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.btn-ghost {
  background: transparent;
}

/* ---------- Privacy note ---------- */

.privacy-note {
  margin: 0;
  padding: 8px 20px;
  font-size: 12px;
  color: var(--text-muted);
  background: var(--bg-elev-2);
  border-bottom: 1px solid var(--border);
  text-align: center;
  flex-shrink: 0;
}

/* ---------- Workspace ---------- */

.workspace {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 1px 1fr;
  min-height: 0;
}

.pane {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background: var(--bg);
}

.pane-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 16px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  background: var(--bg-elev);
  flex-shrink: 0;
}

.pane-hint {
  font-size: 11px;
  text-transform: none;
  letter-spacing: 0;
  color: var(--text-muted);
}

#editor {
  flex: 1;
  width: 100%;
  border: none;
  outline: none;
  resize: none;
  padding: 20px;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 14px;
  line-height: 1.6;
  tab-size: 2;
}

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

.divider {
  background: var(--border);
}

.preview {
  flex: 1;
  overflow-y: auto;
  padding: 32px 40px;
  background: #ffffff;
  color: #1f2328;
}

/* ---------- Markdown content (preview + PDF) ---------- */

.markdown-body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial,
    sans-serif;
  font-size: 14px;
  line-height: 1.6;
  color: #1f2328;
  word-wrap: break-word;
}

.markdown-body h1,
.markdown-body h2,
.markdown-body h3,
.markdown-body h4,
.markdown-body h5,
.markdown-body h6 {
  margin-top: 1.6em;
  margin-bottom: 0.6em;
  font-weight: 600;
  line-height: 1.25;
}

.markdown-body h1 {
  font-size: 2em;
  padding-bottom: 0.3em;
  border-bottom: 1px solid #d0d7de;
}

.markdown-body h2 {
  font-size: 1.5em;
  padding-bottom: 0.3em;
  border-bottom: 1px solid #d0d7de;
}

.markdown-body h3 { font-size: 1.25em; }
.markdown-body h4 { font-size: 1em; }
.markdown-body h5 { font-size: 0.875em; }
.markdown-body h6 { font-size: 0.85em; color: #57606a; }

.markdown-body p {
  margin: 0 0 1em;
}

.markdown-body a {
  color: #0969da;
  text-decoration: none;
}

.markdown-body a:hover {
  text-decoration: underline;
}

.markdown-body strong { font-weight: 600; }

.markdown-body ul,
.markdown-body ol {
  padding-left: 2em;
  margin: 0 0 1em;
}

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

.markdown-body blockquote {
  margin: 0 0 1em;
  padding: 0 1em;
  color: #57606a;
  border-left: 4px solid #d0d7de;
}

.markdown-body code {
  font-family: var(--font-mono);
  font-size: 0.9em;
  background: rgba(175, 184, 193, 0.2);
  padding: 0.15em 0.4em;
  border-radius: 4px;
}

.markdown-body pre {
  background: #f6f8fa;
  padding: 14px 16px;
  border-radius: 6px;
  overflow-x: auto;
  margin: 0 0 1em;
  font-size: 13px;
  line-height: 1.5;
}

.markdown-body pre code {
  background: transparent;
  padding: 0;
  font-size: inherit;
  border-radius: 0;
}

.markdown-body table {
  border-collapse: collapse;
  margin: 0 0 1em;
  display: block;
  overflow-x: auto;
  max-width: 100%;
}

.markdown-body th,
.markdown-body td {
  border: 1px solid #d0d7de;
  padding: 6px 13px;
}

.markdown-body th {
  background: #f6f8fa;
  font-weight: 600;
}

.markdown-body tr:nth-child(2n) { background: #f6f8fa; }

.markdown-body hr {
  border: 0;
  border-top: 1px solid #d0d7de;
  margin: 1.5em 0;
}

.markdown-body img {
  max-width: 100%;
}

.markdown-body input[type="checkbox"] {
  margin-right: 0.3em;
}

/* ---------- PDF stage ---------- */

/* Off-screen render target with a sane page width (~A4 minus margins) */
.pdf-stage {
  position: fixed;
  top: 0;
  left: -10000px;
  width: 794px; /* A4 width @ 96dpi */
  padding: 48px 56px;
  background: #ffffff;
  color: #1f2328;
}

/* ---------- Toast ---------- */

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translate(-50%, 20px);
  background: var(--bg-elev-2);
  color: var(--text);
  border: 1px solid var(--border-strong);
  padding: 10px 16px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  font-size: 13px;
  z-index: 100;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

.toast.error {
  border-color: var(--danger);
}

/* ---------- Responsive ---------- */

@media (max-width: 860px) {
  .app-header {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }

  .toolbar {
    justify-content: flex-start;
  }

  #filename {
    flex: 1;
    min-width: 0;
    width: auto;
  }

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