* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}
:root {
  --bg: #0e0f11;
  --surface: #141618;
  --surface2: #1a1c1f;
  --surface3: #202328;
  --border: rgba(255, 255, 255, 0.07);
  --border2: rgba(255, 255, 255, 0.12);
  --accent: #7ee8a2;
  --accent2: #5bcf85;
  --accent-dim: rgba(126, 232, 162, 0.12);
  --amber: #f5c97a;
  --blue: #7ab8f5;
  --pink: #f57ab8;
  --text: #e2e4e8;
  --text-soft: #8890a0;
  --text-faint: #454c58;
  --mono: "JetBrains Mono", monospace;
  --serif: "Fraunces", Georgia, serif;
}

html,
body {
  height: 100%;
  overflow: hidden;
  background: var(--bg);
}
body {
  font-family: var(--mono);
  color: var(--text);
  display: flex;
  flex-direction: column;
}

/* ══ HEADER ══ */
#header {
  height: 48px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 12px;
  flex-shrink: 0;
  z-index: 100;
}

.logo {
  font-family: var(--serif);
  font-size: 1.1rem;
  font-style: italic;
  font-weight: 300;
  color: var(--accent);
  letter-spacing: 1px;
  margin-right: 4px;
  flex-shrink: 0;
}

#doc-title {
  font-family: var(--mono);
  font-size: 0.8rem;
  font-weight: 300;
  color: var(--text-soft);
  background: transparent;
  border: none;
  outline: none;
  padding: 4px 8px;
  border-radius: 6px;
  transition:
    background 0.2s,
    color 0.2s;
  width: 200px;
}
#doc-title:hover,
#doc-title:focus {
  background: var(--surface3);
  color: var(--text);
}

.saved-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
  flex-shrink: 0;
  transition: background 0.3s;
  box-shadow: 0 0 6px var(--accent);
}
.saved-dot.dirty {
  background: var(--amber);
  box-shadow: 0 0 6px var(--amber);
}

.h-sep {
  width: 1px;
  height: 22px;
  background: var(--border);
  flex-shrink: 0;
}
.spacer {
  flex: 1;
}

/* toolbar buttons */
.tb {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 4px 6px;
  border-radius: 6px;
  border: none;
  background: transparent;
  color: var(--text-soft);
  font-family: var(--mono);
  font-size: 0.72rem;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
  height: 30px;
}
.tb:hover {
  background: var(--surface3);
  color: var(--text);
}
.tb.active {
  background: var(--accent-dim);
  color: var(--accent);
}
.tb svg {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
}

.tb-group {
  display: flex;
  align-items: center;
  gap: 1px;
  background: var(--surface2);
  border-radius: 8px;
  padding: 2px;
}

/* action buttons */
.btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 8px;
  border: 1px solid var(--border2);
  background: var(--surface2);
  color: var(--text-soft);
  font-family: var(--mono);
  font-size: 0.72rem;
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}
.btn:hover {
  background: var(--surface3);
  color: var(--text);
  border-color: var(--border2);
}
.btn.primary {
  background: var(--accent-dim);
  color: var(--accent);
  border-color: rgba(126, 232, 162, 0.3);
}
.btn.primary:hover {
  background: rgba(126, 232, 162, 0.2);
}
.btn svg {
  width: 13px;
  height: 13px;
}

/* view toggles */
.view-toggle {
  display: flex;
  gap: 1px;
  background: var(--surface2);
  border-radius: 8px;
  padding: 2px;
}
.vt {
  padding: 4px 10px;
  border-radius: 6px;
  border: none;
  background: transparent;
  color: var(--text-faint);
  font-family: var(--mono);
  font-size: 0.68rem;
  cursor: pointer;
  transition: all 0.15s;
}
.vt.active {
  background: var(--surface3);
  color: var(--text);
}

/* ══ TOOLBAR ══ */
#toolbar {
  height: 38px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 14px;
  gap: 6px;
  flex-shrink: 0;
  overflow-x: auto;
}
#toolbar::-webkit-scrollbar {
  display: none;
}

.fmt-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 26px;
  border-radius: 5px;
  border: none;
  background: transparent;
  color: var(--text-soft);
  font-family: var(--mono);
  font-size: 0.75rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  flex-shrink: 0;
}
.fmt-btn:hover {
  background: var(--surface3);
  color: var(--text);
}
.fmt-btn.with-label {
  width: auto;
  padding: 0 8px;
  gap: 4px;
  font-size: 0.68rem;
}
.fmt-btn svg {
  width: 13px;
  height: 13px;
}
.fmt-sep {
  width: 1px;
  height: 18px;
  background: var(--border);
  flex-shrink: 0;
  margin: 0 3px;
}

/* ══ MAIN AREA ══ */
#main {
  flex: 1;
  display: flex;
  overflow: hidden;
  position: relative;
}

/* ══ EDITOR PANE ══ */
#editor-pane {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  border-right: 1px solid var(--border);
  transition: flex 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}
#editor-pane.hidden {
  flex: 0;
  overflow: hidden;
  border: none;
}

#editor {
  flex: 1;
  padding: 32px 40px;
  font-family: var(--mono);
  font-size: 0.88rem;
  line-height: 1.85;
  color: var(--text);
  background: var(--bg);
  border: none;
  outline: none;
  resize: none;
  tab-size: 2;
  caret-color: var(--accent);
  transition: padding 0.2s;
}
#editor::selection {
  background: rgba(126, 232, 162, 0.18);
}
#editor::placeholder {
  color: var(--text-faint);
}

/* line numbers */
#editor-wrap {
  flex: 1;
  display: flex;
  overflow: hidden;
  position: relative;
}
#line-nums {
  width: 48px;
  flex-shrink: 0;
  padding: 32px 0;
  background: var(--bg);
  border-right: 1px solid var(--border);
  overflow: hidden;
  text-align: right;
}
.ln {
  display: block;
  font-size: 0.72rem;
  color: var(--text-faint);
  line-height: 1.85;
  padding: 0 10px;
  font-family: var(--mono);
  height: calc(0.88rem * 1.85);
}
.ln.active-line {
  color: var(--accent);
  opacity: 0.7;
}

/* ══ DIVIDER ══ */
#divider {
  width: 4px;
  flex-shrink: 0;
  background: var(--border);
  cursor: col-resize;
  position: relative;
  transition: background 0.2s;
}
#divider:hover,
#divider.dragging {
  background: var(--accent-dim);
}
#divider::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 2px;
  height: 40px;
  border-radius: 1px;
  background: var(--text-faint);
  transition: background 0.2s;
}
#divider:hover::after,
#divider.dragging::after {
  background: var(--accent);
}

/* ══ PREVIEW PANE ══ */
#preview-pane {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--surface);
  transition: flex 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  overflow: hidden;
}
#preview-pane.hidden {
  flex: 0;
  overflow: hidden;
}

#preview-label {
  height: 28px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  padding: 0 20px;
  font-size: 0.65rem;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--text-faint);
  border-bottom: 1px solid var(--border);
}

#preview {
  flex: 1;
  overflow-y: auto;
  padding: 32px 48px;
  font-family: var(--serif);
  font-size: 1rem;
  line-height: 1.8;
  color: var(--text);
}
#preview::-webkit-scrollbar {
  width: 4px;
}
#preview::-webkit-scrollbar-track {
  background: transparent;
}
#preview::-webkit-scrollbar-thumb {
  background: var(--surface3);
  border-radius: 2px;
}

/* ── Markdown rendered styles ── */
#preview h1 {
  font-family: var(--serif);
  font-size: 2rem;
  font-weight: 300;
  font-style: italic;
  color: var(--accent);
  margin: 0 0 24px;
  line-height: 1.2;
  border-bottom: 1px solid var(--border);
  padding-bottom: 12px;
}
#preview h2 {
  font-family: var(--serif);
  font-size: 1.4rem;
  font-weight: 300;
  color: var(--amber);
  margin: 32px 0 14px;
  line-height: 1.3;
}
#preview h3 {
  font-family: var(--serif);
  font-size: 1.15rem;
  font-weight: 300;
  font-style: italic;
  color: var(--blue);
  margin: 24px 0 10px;
}
#preview h4,
#preview h5,
#preview h6 {
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text-soft);
  margin: 18px 0 8px;
  text-transform: uppercase;
  letter-spacing: 1px;
}
#preview p {
  margin: 0 0 16px;
}
#preview strong {
  color: var(--text);
  font-weight: 500;
}
#preview em {
  color: var(--text-soft);
  font-style: italic;
}
#preview a {
  color: var(--blue);
  text-decoration: none;
  border-bottom: 1px solid rgba(122, 184, 245, 0.3);
  transition: border-color 0.2s;
}
#preview a:hover {
  border-color: var(--blue);
}
#preview code {
  font-family: var(--mono);
  font-size: 0.8rem;
  background: var(--surface3);
  color: var(--pink);
  padding: 2px 7px;
  border-radius: 4px;
  border: 1px solid var(--border);
}
#preview pre {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px 24px;
  margin: 18px 0;
  overflow-x: auto;
  position: relative;
}
#preview pre::before {
  content: "";
  position: absolute;
  top: 10px;
  left: 14px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #ff5f57;
  box-shadow:
    14px 0 0 #febc2e,
    28px 0 0 #28c840;
}
#preview pre code {
  background: none;
  color: var(--text);
  padding: 0;
  border: none;
  font-size: 0.82rem;
  line-height: 1.7;
}
#preview blockquote {
  border-left: 3px solid var(--accent);
  margin: 18px 0;
  padding: 12px 20px;
  background: var(--accent-dim);
  border-radius: 0 8px 8px 0;
  color: var(--text-soft);
  font-style: italic;
}
#preview ul,
#preview ol {
  margin: 0 0 16px 20px;
}
#preview li {
  margin-bottom: 6px;
}
#preview li::marker {
  color: var(--accent);
}
#preview hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 28px 0;
}
#preview table {
  width: 100%;
  border-collapse: collapse;
  margin: 18px 0;
  font-size: 0.88rem;
  font-family: var(--mono);
}
#preview th {
  background: var(--surface2);
  color: var(--text-soft);
  padding: 10px 14px;
  text-align: left;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  border-bottom: 2px solid var(--border2);
}
#preview td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
}
#preview tr:hover td {
  background: var(--surface2);
}
#preview img {
  max-width: 100%;
  border-radius: 8px;
  margin: 12px 0;
}
#preview input[type="checkbox"] {
  accent-color: var(--accent);
  margin-right: 6px;
}

/* ══ STATUSBAR ══ */
#statusbar {
  height: 26px;
  flex-shrink: 0;
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 16px;
  font-size: 0.65rem;
  color: var(--text-faint);
  letter-spacing: 0.5px;
}
.stat {
  display: flex;
  align-items: center;
  gap: 5px;
}
.stat-val {
  color: var(--text-soft);
}
.stat-sep {
  color: var(--border2);
}
#cursor-pos {
  margin-left: auto;
  color: var(--text-faint);
}
#autosave-status {
  color: var(--text-faint);
  transition: color 0.3s;
}
#autosave-status.saving {
  color: var(--accent);
}

/* ══ TOAST ══ */
#toast {
  position: fixed;
  bottom: 36px;
  left: 50%;
  transform: translateX(-50%) translateY(8px);
  background: var(--surface3);
  color: var(--text);
  border: 1px solid var(--border2);
  padding: 9px 18px;
  border-radius: 20px;
  font-size: 0.75rem;
  letter-spacing: 0.5px;
  opacity: 0;
  pointer-events: none;
  transition:
    opacity 0.2s,
    transform 0.2s;
  z-index: 9999;
  white-space: nowrap;
}
#toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ══ DROPDOWN ══ */
.dropdown {
  position: relative;
  display: inline-flex;
}
.dd-menu {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  background: var(--surface2);
  border: 1px solid var(--border2);
  border-radius: 10px;
  padding: 6px;
  min-width: 180px;
  z-index: 500;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
  display: none;
  animation: ddPop 0.15s cubic-bezier(0.2, 0, 0.2, 1.5);
}
.dd-menu.open {
  display: block;
}
@keyframes ddPop {
  from {
    opacity: 0;
    transform: translateY(-6px) scale(0.97);
  }
  to {
    opacity: 1;
    transform: none;
  }
}
.dd-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 7px;
  cursor: pointer;
  color: var(--text-soft);
  font-size: 0.75rem;
  transition:
    background 0.12s,
    color 0.12s;
}
.dd-item:hover {
  background: var(--surface3);
  color: var(--text);
}
.dd-item svg {
  width: 13px;
  height: 13px;
  flex-shrink: 0;
}
.dd-kbd {
  margin-left: auto;
  font-size: 0.62rem;
  color: var(--text-faint);
  background: var(--surface3);
  padding: 1px 5px;
  border-radius: 3px;
}

/* scrollbar editor */
#editor::-webkit-scrollbar {
  width: 4px;
}
#editor::-webkit-scrollbar-track {
  background: transparent;
}
#editor::-webkit-scrollbar-thumb {
  background: var(--surface3);
  border-radius: 2px;
}

/* focus mode */
body.focus-mode #toolbar,
body.focus-mode #header {
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.4s;
}
body.focus-mode:hover #toolbar,
body.focus-mode:hover #header {
  opacity: 1;
  pointer-events: all;
}
body.focus-mode #statusbar {
  opacity: 0;
}
body.focus-mode:hover #statusbar {
  opacity: 1;
}

/* ═════════ RESPONSIVE (MOBILE/TABLET) ═════════ */
@media (max-width: 1100px) {
  #doc-title {
    width: auto;
    flex: 1 1 140px;
    min-width: 120px;
    max-width: 220px;
  }

  .btn {
    padding: 6px 10px;
  }
}

@media (max-width: 900px) {
  #main {
    flex-direction: column;
  }

  #divider {
    display: none;
  }

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

  #preview-pane {
    border-left: none;
  }

  #editor,
  #preview {
    padding: 20px 22px;
  }

  #preview-label {
    height: 24px;
    padding: 0 16px;
  }

  #preview table {
    display: block;
    overflow-x: auto;
  }
}

@media (max-width: 720px) {
  #header {
    height: auto;
    padding: 8px 10px;
    gap: 8px;
    row-gap: 8px;
    flex-wrap: wrap;
  }

  .h-sep {
    display: none;
  }

  .tb,
  .btn,
  .vt {
    font-size: 0.66rem;
  }

  .tb {
    height: 28px;
    padding: 4px 6px;
  }

  .tb svg,
  .btn svg {
    width: 12px;
    height: 12px;
  }

  #toolbar {
    height: auto;
    padding: 6px 10px;
    gap: 4px;
  }

  .fmt-btn {
    width: 26px;
    height: 24px;
  }

  .fmt-btn.with-label {
    padding: 0 6px;
    font-size: 0.64rem;
  }

  #statusbar {
    height: auto;
    padding: 6px 10px;
    gap: 8px;
    flex-wrap: wrap;
  }

  .stat-sep {
    display: none;
  }

  #cursor-pos {
    margin-left: 0;
  }
}

@media (max-width: 520px) {
  #line-nums {
    display: none;
  }

  #editor {
    padding: 18px 16px;
    font-size: 0.84rem;
  }

  #preview {
    padding: 18px 16px;
    font-size: 0.95rem;
  }

  #preview h1 {
    font-size: 1.6rem;
  }

  #preview h2 {
    font-size: 1.2rem;
  }

  #preview h3 {
    font-size: 1.05rem;
  }

  #preview pre {
    padding: 16px;
  }

  #toast {
    max-width: calc(100% - 24px);
    white-space: normal;
    text-align: center;
  }
}
