:root {
  --transition: .3s ease;
}

[data-theme="dark"] {
  --bg:           #0f0e0d;
  --bg2:          #141310;
  --surface:      #1a1815;
  --surface2:     #201e1a;
  --border:       #2a2620;
  --border2:      #38332a;
  --text:         #e8e0d0;
  --text-dim:     #8a8070;
  --text-faint:   #3a3530;
  --accent:       #d4a853;
  --accent-dim:   #b8903f;
  --accent-glow:  rgba(212,168,83,0.15);
  --accent2:      #c47a4a;
  --red:          #e05555;
  --green:        #5cb85c;
  --preview-bg:   #12110f;
  --preview-text: #ddd5c5;
  --code-bg:      #1e1c18;
  --blockquote:   #2a2520;
  --scrollbar:    #2a2620;
}

[data-theme="light"] {
  --bg:           #faf8f4;
  --bg2:          #f5f2ec;
  --surface:      #ffffff;
  --surface2:     #f0ece4;
  --border:       #e0d8cc;
  --border2:      #cec5b5;
  --text:         #2a2520;
  --text-dim:     #7a7060;
  --text-faint:   #ccc5b5;
  --accent:       #b8872a;
  --accent-dim:   #9a6e1e;
  --accent-glow:  rgba(184,135,42,0.12);
  --accent2:      #a0602a;
  --red:          #c0392b;
  --green:        #27ae60;
  --preview-bg:   #ffffff;
  --preview-text: #2a2520;
  --code-bg:      #f0ece4;
  --blockquote:   #f5f0e8;
  --scrollbar:    #d0c8b8;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html { height: 100%; }

body {
  font-family: 'Lato', sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: background var(--transition), color var(--transition);
}

.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  height: 52px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
  transition: background var(--transition), border-color var(--transition);
  z-index: 100;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 16px;
}

.iv-badge {
  font-family: 'Playfair Display', serif;
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
  border: 1px solid var(--border2);
  padding: 3px 9px;
  border-radius: 3px;
  letter-spacing: 1px;
  transition: border-color var(--transition);
}
.iv-badge:hover { border-color: var(--accent); }

.logo-sep { width: 1px; height: 16px; background: var(--border2); }

.logo-title {
  font-family: 'Playfair Display', serif;
  font-size: 18px;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 1px;
}

.header-center {
  display: flex;
  align-items: center;
  gap: 4px;
}

/* TOOLBAR BUTTONS */
.tb-btn {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  padding: 5px 10px;
  border-radius: 4px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-dim);
  transition: all .2s;
  letter-spacing: 0.5px;
  white-space: nowrap;
}
.tb-btn:hover {
  background: var(--accent-glow);
  border-color: var(--border2);
  color: var(--accent);
}
.tb-btn.active {
  background: var(--accent-glow);
  border-color: var(--accent);
  color: var(--accent);
}
.tb-sep {
  width: 1px; height: 20px;
  background: var(--border);
  margin: 0 4px;
}
.tb-btn-italic { font-style: italic; }

/* WORD COUNT */
.word-count {
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px;
  color: var(--text-dim);
  letter-spacing: 1px;
  padding: 4px 10px;
  border-left: 1px solid var(--border);
  margin-left: 4px;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* THEME TOGGLE */
.theme-toggle {
  width: 44px; height: 24px;
  background: var(--surface2);
  border: 1px solid var(--border2);
  border-radius: 12px;
  position: relative;
  transition: all .3s;
}
.theme-toggle::after {
  content: '';
  position: absolute;
  top: 3px; left: 3px;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: var(--accent);
  transition: transform .3s cubic-bezier(.34,1.56,.64,1);
  box-shadow: 0 1px 4px rgba(0,0,0,0.3);
}
[data-theme="light"] .theme-toggle::after { transform: translateX(20px); }

.theme-label {
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px;
  color: var(--text-dim);
  letter-spacing: 1px;
}

.fmt-toolbar {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 6px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--bg2);
  flex-shrink: 0;
  flex-wrap: wrap;
  transition: background var(--transition), border-color var(--transition);
}

.fmt-btn {
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px;
  font-weight: 500;
  padding: 4px 10px;
  border-radius: 3px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-dim);
  transition: all .15s;
  min-width: 32px;
  text-align: center;
}
.fmt-btn:hover {
  background: var(--accent-glow);
  border-color: var(--border2);
  color: var(--accent);
}
.fmt-sep { width: 1px; height: 18px; background: var(--border); margin: 0 4px; }
.fmt-btn-bold { font-weight: 700; }
.fmt-btn-italic { font-style: italic; }
.fmt-btn-strike { text-decoration: line-through; }

.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
  border: 0;
}


.editor-layout {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* PANE */
.pane {
  display: flex;
  flex-direction: column;
  flex: 1;
  overflow: hidden;
  border-right: 1px solid var(--border);
  transition: border-color var(--transition);
}
.pane:last-child { border-right: none; }

.pane-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  transition: background var(--transition), border-color var(--transition);
}

.pane-title {
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px;
  letter-spacing: 2px;
  color: var(--text-dim);
  text-transform: uppercase;
  display: flex;
  align-items: center;
  gap: 8px;
}

.pane-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 6px var(--accent);
  animation: dotPulse 3s ease-in-out infinite;
}
.pane-dot-preview {
  background: var(--accent2);
  box-shadow: 0 0 6px var(--accent2);
}
@keyframes dotPulse {
  0%,100% { opacity:1; }
  50% { opacity:0.4; }
}

.pane-actions {
  display: flex; gap: 6px;
}

.pane-btn {
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px;
  padding: 3px 10px;
  border-radius: 3px;
  border: 1px solid var(--border2);
  background: transparent;
  color: var(--text-dim);
  transition: all .2s;
  letter-spacing: 0.5px;
}
.pane-btn:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-glow); }

/* EDITOR TEXTAREA */
.editor-wrap {
  flex: 1;
  position: relative;
  overflow: hidden;
}

textarea#mdInput {
  position: absolute;
  inset: 0;
  width: 100%; height: 100%;
  background: var(--bg);
  border: none;
  outline: none;
  resize: none;
  color: var(--text);
  font-family: 'JetBrains Mono', monospace;
  font-size: 14px;
  line-height: 1.8;
  padding: 24px 28px;
  caret-color: var(--accent);
  tab-size: 2;
  transition: background var(--transition), color var(--transition);
  scrollbar-width: thin;
  scrollbar-color: var(--scrollbar) transparent;
}
textarea#mdInput::-webkit-scrollbar { width: 4px; }
textarea#mdInput::-webkit-scrollbar-thumb { background: var(--scrollbar); border-radius: 2px; }
textarea#mdInput::selection { background: var(--accent-glow); }
textarea#mdInput::placeholder { color: var(--text-faint); }

/* PREVIEW */
.preview-area {
  flex: 1;
  overflow-y: auto;
  padding: 24px 32px;
  background: var(--preview-bg);
  color: var(--preview-text);
  transition: background var(--transition), color var(--transition);
  scrollbar-width: thin;
  scrollbar-color: var(--scrollbar) transparent;
  font-family: 'Lato', sans-serif;
}
.preview-area::-webkit-scrollbar { width: 4px; }
.preview-area::-webkit-scrollbar-thumb { background: var(--scrollbar); border-radius: 2px; }

/* PREVIEW TYPOGRAPHY */
.preview-area h1 {
  font-family: 'Playfair Display', serif;
  font-size: 2.2em;
  font-weight: 700;
  line-height: 1.2;
  margin: 0 0 20px;
  color: var(--text);
  border-bottom: 2px solid var(--accent);
  padding-bottom: 12px;
}
.preview-area h2 {
  font-family: 'Playfair Display', serif;
  font-size: 1.6em;
  font-weight: 700;
  margin: 32px 0 16px;
  color: var(--text);
}
.preview-area h3 {
  font-family: 'Playfair Display', serif;
  font-size: 1.25em;
  font-weight: 700;
  font-style: italic;
  margin: 24px 0 12px;
  color: var(--accent);
}
.preview-area h4, .preview-area h5, .preview-area h6 {
  font-family: 'Lato', sans-serif;
  font-weight: 700;
  font-size: 1em;
  margin: 20px 0 10px;
  color: var(--text);
  letter-spacing: 1px;
  text-transform: uppercase;
}
.preview-area p { margin: 0 0 16px; line-height: 1.8; font-size: 15px; }
.preview-area strong { color: var(--text); font-weight: 700; }
.preview-area em { font-style: italic; color: var(--accent2); }
.preview-area a { color: var(--accent); text-decoration: underline; text-underline-offset: 3px; }
.preview-area a:hover { color: var(--accent-dim); }

.preview-area ul, .preview-area ol {
  margin: 0 0 16px 24px;
  line-height: 1.8;
  font-size: 15px;
}
.preview-area li { margin-bottom: 4px; }
.preview-area li::marker { color: var(--accent); }

.preview-area blockquote {
  margin: 20px 0;
  padding: 16px 20px;
  border-left: 3px solid var(--accent);
  background: var(--blockquote);
  border-radius: 0 6px 6px 0;
  font-style: italic;
  color: var(--text-dim);
}
.preview-area blockquote p { margin: 0; }

.preview-area code {
  font-family: 'JetBrains Mono', monospace;
  font-size: 13px;
  background: var(--code-bg);
  color: var(--accent);
  padding: 2px 6px;
  border-radius: 3px;
  border: 1px solid var(--border);
}
.preview-area pre {
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 16px 20px;
  margin: 16px 0;
  overflow-x: auto;
  scrollbar-width: thin;
}
.preview-area pre code {
  background: none;
  border: none;
  padding: 0;
  color: var(--text);
  font-size: 13px;
  line-height: 1.6;
}
.preview-area hr {
  border: none;
  border-top: 1px solid var(--border2);
  margin: 32px 0;
}
.preview-area table {
  width: 100%;
  border-collapse: collapse;
  margin: 16px 0;
  font-size: 14px;
}
.preview-area th {
  background: var(--surface2);
  color: var(--accent);
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  letter-spacing: 1px;
  text-transform: uppercase;
  padding: 10px 14px;
  text-align: left;
  border: 1px solid var(--border);
}
.preview-area td {
  padding: 10px 14px;
  border: 1px solid var(--border);
  color: var(--preview-text);
}
.preview-area tr:nth-child(even) td { background: var(--surface2); }
.preview-area img { max-width: 100%; border-radius: 6px; margin: 12px 0; }

.preview-area input[type="checkbox"] {
  accent-color: var(--accent);
  margin-right: 6px;
}

/* EMPTY PREVIEW */
.preview-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--text-faint);
  text-align: center;
  gap: 16px;
}
.preview-empty .empty-icon {
  font-family: 'Playfair Display', serif;
  font-size: 48px;
  color: var(--border2);
}
.preview-empty p { font-size: 13px; line-height: 1.7; max-width: 280px; }


.status-bar {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 6px 24px;
  border-top: 1px solid var(--border);
  background: var(--surface);
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px;
  color: var(--text-dim);
  letter-spacing: 1px;
  flex-shrink: 0;
  flex-wrap: wrap;
  transition: background var(--transition), border-color var(--transition);
}

.stat { display: flex; align-items: center; gap: 6px; }
.stat-val { color: var(--accent); font-weight: 500; }
.stat-push { margin-left: auto; }

.toast {
  position: fixed;
  bottom: 40px;
  left: 50%;
  transform: translateX(-50%) translateY(10px);
  background: var(--surface2);
  border: 1px solid var(--accent);
  color: var(--accent);
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px;
  padding: 10px 20px;
  border-radius: 4px;
  z-index: 9999;
  opacity: 0;
  transition: all .3s;
  pointer-events: none;
  box-shadow: 0 4px 24px rgba(0,0,0,0.3);
  white-space: nowrap;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ===== FOOTER ===== */

footer {
  margin-top: 0px;
  padding: 6px 0 2px;
  border-top: 1px solid var(--border);
  text-align: center;
}

.footer-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0px;
  margin-bottom: 30px;
}

.footer-links a {
  text-decoration: none;
  color: inherit;
  font-family: 'Space Mono', monospace;
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  opacity: 0.7;
  transition: opacity 0.2s;
}

.footer-links a:hover {
  opacity: 1;
  color: #e8f542;
}

.footer-links {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 4px 0;
  align-items: center;
}

.footer-links a:not(:last-child)::after {
  content: '|';
  margin: 0 0.6em;
  opacity: 0.3;
  color: inherit;
}

.cheatsheet {
  position: fixed;
  top: 0; right: -320px;
  width: 320px; height: 100vh;
  background: var(--surface);
  border-left: 1px solid var(--border);
  z-index: 500;
  transition: right .3s cubic-bezier(.34,1.1,.64,1), background var(--transition);
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--scrollbar) transparent;
  padding-bottom: 32px;
}
.cheatsheet.open { right: 0; }

.cheatsheet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--surface);
  z-index: 1;
}

.cheatsheet-title {
  font-family: 'Playfair Display', serif;
  font-size: 16px;
  font-weight: 700;
  color: var(--accent);
}

.cheat-close {
  font-size: 18px;
  color: var(--text-dim);
  background: none;
  border: none;
  transition: color .2s;
}
.cheat-close:hover { color: var(--accent); }

.cheat-section { padding: 16px 20px 0; }
.cheat-section-title {
  font-family: 'JetBrains Mono', monospace;
  font-size: 9px;
  letter-spacing: 2px;
  color: var(--text-dim);
  text-transform: uppercase;
  margin-bottom: 10px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
}

.cheat-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 6px 0;
  transition: background .15s;
  border-radius: 3px;
}
.cheat-row:hover { background: var(--accent-glow); padding-left: 6px; }

.cheat-md {
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px;
  color: var(--accent);
  min-width: 110px;
  flex-shrink: 0;
}
.cheat-desc {
  font-size: 12px;
  color: var(--text-dim);
}

/* OVERLAY */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 499;
  opacity: 0;
  pointer-events: none;
  transition: opacity .3s;
  backdrop-filter: blur(2px);
}
.overlay.show { opacity: 1; pointer-events: all; }

@media (max-width: 768px) {
  .editor-layout { flex-direction: column; }
  .pane { min-height: 40vh; }
  .pane:first-child { border-right: none; border-bottom: 1px solid var(--border); }
  .header-center { display: none; }
  .fmt-toolbar { display: none; }
  .cheatsheet { width: 280px; right: -280px; }
}

@media (max-width: 480px) {
  .header { padding: 0 12px; }
  .status-bar { padding: 6px 12px; gap: 12px; }
}