/* ===========================================================
   Dillinger clone — application styles
   Two-pane markdown editor: Monaco/CodeMirror on the left,
   rendered preview on the right. Dark UI with gold accents.
   =========================================================== */

:root {
  --bg: #1b1b1b;
  --bg-elev: #232323;
  --bg-elev-2: #2b2b2b;
  --pane-bg: #1f1f1f;
  --border: #343434;
  --border-soft: #2a2a2a;
  --text: #e8e8e8;
  --text-dim: #a8a8a8;
  --text-faint: #6f6f6f;
  --gold: #c69a3f;
  --gold-dim: #8a6f30;
  --gold-soft: rgba(198, 154, 63, 0.15);
  --accent: #4a9eff;
  --danger: #e05d5d;
  --shadow: 0 6px 24px rgba(0, 0, 0, 0.4);
  --radius: 6px;
  --topbar-h: 52px;
  --statusbar-h: 30px;
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-mono: "SF Mono", "Fira Code", "JetBrains Mono", Consolas, "Liberation Mono", Menlo, monospace;
  --font-serif: Georgia, "Times New Roman", serif;
}

/* Light theme overrides */
body.theme-light {
  --bg: #f7f7f5;
  --bg-elev: #ffffff;
  --bg-elev-2: #efefe9;
  --pane-bg: #ffffff;
  --border: #e0e0d8;
  --border-soft: #ececea;
  --text: #1f1f1f;
  --text-dim: #555;
  --text-faint: #999;
  --gold: #b5862f;
  --gold-dim: #c69a3f;
  --shadow: 0 6px 24px rgba(0, 0, 0, 0.12);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.5;
  overflow: hidden;
}

button { font-family: inherit; cursor: pointer; }
a { color: var(--gold); }

/* ---------- Top bar ---------- */
.topbar {
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 14px;
  background: var(--bg-elev);
  border-bottom: 1px solid var(--border);
  position: relative;
  z-index: 30;
  gap: 12px;
}

.topbar-left { flex: 0 0 auto; }

.brand {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
  color: var(--text);
}
.brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  background: var(--gold);
  color: #1b1b1b;
  font-family: var(--font-serif);
  font-weight: 700;
  font-size: 20px;
  border-radius: 6px;
  line-height: 1;
}
.brand-name {
  font-family: var(--font-serif);
  font-size: 19px;
  font-weight: 600;
  letter-spacing: 0.2px;
}

.topbar-center { flex: 1 1 auto; display: flex; justify-content: center; }

.doc-title {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text);
  font-size: 14px;
  text-align: center;
  padding: 6px 10px;
  border-radius: var(--radius);
  width: 280px;
  max-width: 40vw;
  outline: none;
  transition: border-color 0.15s, background 0.15s;
}
.doc-title:hover { border-color: var(--border); }
.doc-title:focus { border-color: var(--gold-dim); background: var(--bg-elev-2); }

.topbar-right { flex: 0 0 auto; display: flex; align-items: center; gap: 10px; }

/* Segmented view toggle */
.view-toggle {
  display: inline-flex;
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2px;
  gap: 2px;
}
.seg {
  background: transparent;
  border: none;
  color: var(--text-dim);
  padding: 5px 14px;
  font-size: 12.5px;
  font-weight: 500;
  border-radius: 4px;
  transition: all 0.15s;
}
.seg:hover { color: var(--text); }
.seg.active { background: var(--gold); color: #1b1b1b; }

/* Hamburger */
.icon-btn {
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: 34px;
  height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.icon-btn:hover { border-color: var(--gold-dim); }
.hamburger, .hamburger::before, .hamburger::after {
  display: block;
  width: 16px;
  height: 2px;
  background: var(--text);
  border-radius: 1px;
  position: relative;
}
.hamburger::before, .hamburger::after { content: ""; position: absolute; }
.hamburger::before { top: -5px; }
.hamburger::after { top: 5px; }

/* ---------- Slide menu ---------- */
.slide-menu {
  position: absolute;
  top: calc(var(--topbar-h) - 1px);
  right: 14px;
  width: 240px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 0 0 var(--radius) var(--radius);
  box-shadow: var(--shadow);
  padding: 8px 0;
  z-index: 40;
  animation: menuIn 0.14s ease-out;
}
@keyframes menuIn { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: none; } }

.menu-group { padding: 4px 0; }
.menu-label {
  display: block;
  padding: 6px 16px 4px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-faint);
  font-weight: 600;
}
.menu-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  background: transparent;
  border: none;
  color: var(--text);
  padding: 8px 16px;
  font-size: 13px;
  text-align: left;
  transition: background 0.12s;
}
.menu-item:hover { background: var(--bg-elev-2); }
.menu-divider { height: 1px; background: var(--border); margin: 4px 0; }
.kbd-state {
  font-size: 11px;
  padding: 1px 6px;
  border-radius: 3px;
  background: var(--bg-elev-2);
  color: var(--text-dim);
  border: 1px solid var(--border);
}
.kbd-state.on { background: var(--gold-soft); color: var(--gold); border-color: var(--gold-dim); }

/* ---------- Split layout ---------- */
.split {
  display: flex;
  height: calc(100vh - var(--topbar-h) - var(--statusbar-h));
  width: 100%;
  overflow: hidden;
}

.pane {
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--pane-bg);
}
.editor-pane { flex: 1 1 50%; }
.preview-pane { flex: 1 1 50%; border-left: 1px solid var(--border); }

.pane-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 14px;
  border-bottom: 1px solid var(--border-soft);
  background: var(--bg-elev);
  height: 36px;
  flex: 0 0 auto;
}
.pane-title {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-faint);
  font-weight: 600;
}
.pane-actions { display: flex; gap: 6px; }

.mini-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-size: 11px;
  padding: 3px 9px;
  border-radius: 4px;
  transition: all 0.12s;
}
.mini-btn:hover { color: var(--gold); border-color: var(--gold-dim); }

.editor-host { flex: 1 1 auto; overflow: hidden; position: relative; }
.editor-host .cm-editor { height: 100%; }
.editor-host .cm-scroller { font-family: var(--font-mono); font-size: 14px; line-height: 1.6; }

.preview-scroll {
  flex: 1 1 auto;
  overflow: auto;
  padding: 28px 40px 80px;
}
.html-source {
  flex: 1 1 auto;
  margin: 0;
  padding: 20px 28px;
  overflow: auto;
  font-family: var(--font-mono);
  font-size: 12.5px;
  line-height: 1.6;
  color: var(--text);
  background: var(--pane-bg);
  white-space: pre-wrap;
  word-break: break-word;
}

/* Resizer */
.resizer {
  width: 6px;
  background: var(--border-soft);
  cursor: col-resize;
  flex: 0 0 auto;
  position: relative;
  z-index: 5;
  transition: background 0.15s;
}
.resizer:hover, .resizer.active { background: var(--gold-dim); }
.resizer::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 2px;
  height: 28px;
  background: var(--text-faint);
  border-radius: 1px;
  opacity: 0.4;
}

/* ---------- Status bar ---------- */
.statusbar {
  height: var(--statusbar-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  background: var(--bg-elev);
  border-top: 1px solid var(--border);
  font-size: 11.5px;
  color: var(--text-dim);
  flex: 0 0 auto;
}
.status-left, .status-right { display: flex; gap: 16px; align-items: center; }
.status-item { white-space: nowrap; }
.status-item.flash { color: var(--gold); }
kbd {
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 1px 5px;
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--text-dim);
}

/* ---------- Zen mode ---------- */
body.zen .topbar,
body.zen .statusbar,
body.zen .pane-head { display: none; }
body.zen .split { height: 100vh; }
body.zen .preview-pane { border-left: none; }
.zen-exit {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 50;
  background: rgba(0,0,0,0.5);
  color: #fff;
  border: 1px solid var(--gold-dim);
  border-radius: var(--radius);
  padding: 6px 12px;
  font-size: 12px;
  opacity: 0.5;
  transition: opacity 0.2s;
}
.zen-exit:hover { opacity: 1; }

/* ---------- Preview / Markdown body ---------- */
.markdown-body {
  font-family: var(--font-sans);
  color: var(--text);
  line-height: 1.7;
  max-width: 760px;
  margin: 0 auto;
}
.markdown-body h1, .markdown-body h2, .markdown-body h3,
.markdown-body h4, .markdown-body h5, .markdown-body h6 {
  font-family: var(--font-serif);
  font-weight: 600;
  line-height: 1.3;
  margin: 1.6em 0 0.6em;
  color: var(--text);
}
.markdown-body h1 { font-size: 2.1em; border-bottom: 1px solid var(--border); padding-bottom: 0.3em; }
.markdown-body h2 { font-size: 1.6em; border-bottom: 1px solid var(--border-soft); padding-bottom: 0.3em; }
.markdown-body h3 { font-size: 1.3em; }
.markdown-body h4 { font-size: 1.1em; }
.markdown-body h5 { font-size: 1em; }
.markdown-body h6 { font-size: 0.9em; color: var(--text-dim); }
.markdown-body h1:first-child, .markdown-body h2:first-child { margin-top: 0; }
.markdown-body p { margin: 0 0 1em; }
.markdown-body a { color: var(--gold); text-decoration: none; }
.markdown-body a:hover { text-decoration: underline; }
.markdown-body strong { font-weight: 700; }
.markdown-body em { font-style: italic; }
.markdown-body del { color: var(--text-faint); }
.markdown-body ul, .markdown-body ol { margin: 0 0 1em; padding-left: 2em; }
.markdown-body li { margin: 0.25em 0; }
.markdown-body li > ul, .markdown-body li > ol { margin: 0.25em 0; }
.markdown-body blockquote {
  margin: 0 0 1em;
  padding: 0.4em 1em;
  border-left: 4px solid var(--gold-dim);
  background: var(--gold-soft);
  color: var(--text-dim);
  border-radius: 0 4px 4px 0;
}
.markdown-body blockquote p { margin: 0.3em 0; }
.markdown-body code {
  font-family: var(--font-mono);
  font-size: 0.88em;
  background: var(--bg-elev-2);
  padding: 0.15em 0.4em;
  border-radius: 3px;
  border: 1px solid var(--border-soft);
}
.markdown-body pre {
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  overflow: auto;
  margin: 0 0 1em;
}
.markdown-body pre code {
  background: transparent;
  border: none;
  padding: 0;
  font-size: 0.86em;
  line-height: 1.5;
  color: var(--text);
}
.markdown-body table {
  border-collapse: collapse;
  width: 100%;
  margin: 0 0 1em;
  display: block;
  overflow-x: auto;
}
.markdown-body th, .markdown-body td {
  border: 1px solid var(--border);
  padding: 8px 12px;
  text-align: left;
}
.markdown-body th { background: var(--bg-elev-2); font-weight: 600; }
.markdown-body tr:nth-child(even) td { background: rgba(255,255,255,0.02); }
body.theme-light .markdown-body tr:nth-child(even) td { background: rgba(0,0,0,0.02); }
.markdown-body img { max-width: 100%; height: auto; border-radius: var(--radius); }
.markdown-body hr { border: none; border-top: 1px solid var(--border); margin: 2em 0; }
.markdown-body input[type="checkbox"] { margin-right: 0.4em; }

/* Task lists */
.markdown-body .task-list-item { list-style-type: none; }
.markdown-body .task-list-item input { margin: 0 0.5em 0 -1.4em; vertical-align: middle; }

/* ---------- Responsive ---------- */
@media (max-width: 820px) {
  .split { flex-direction: column; height: calc(100vh - var(--topbar-h) - var(--statusbar-h)); }
  .editor-pane, .preview-pane { flex: 1 1 50%; min-height: 0; }
  .preview-pane { border-left: none; border-top: 1px solid var(--border); }
  .resizer { display: none; }
  .doc-title { width: 160px; }
  .brand-name { display: none; }
  .preview-scroll { padding: 18px 18px 60px; }
}

/* Scrollbar styling */
.preview-scroll::-webkit-scrollbar,
.html-source::-webkit-scrollbar { width: 10px; height: 10px; }
.preview-scroll::-webkit-scrollbar-thumb,
.html-source::-webkit-scrollbar-thumb { background: var(--border); border-radius: 5px; }
.preview-scroll::-webkit-scrollbar-thumb:hover,
.html-source::-webkit-scrollbar-thumb:hover { background: var(--gold-dim); }
.preview-scroll::-webkit-scrollbar-track,
.html-source::-webkit-scrollbar-track { background: transparent; }

/* Toast */
.toast {
  position: fixed;
  bottom: 44px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--bg-elev);
  border: 1px solid var(--gold-dim);
  color: var(--text);
  padding: 10px 18px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  font-size: 13px;
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
