@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap');

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

:root {
  --bg:           #0e0f13;
  --surface:      #151821;
  --surface-2:    #1c1f2e;
  --border:       rgba(255,255,255,0.07);
  --border-hover: rgba(124,92,255,0.45);
  --accent:       #7c5cff;
  --accent-hover: #9579ff;
  --accent-glow:  rgba(124,92,255,0.18);
  --text:         #e6e6e6;
  --muted:        #6b7280;
  --red:          #f06a6a;
  --green:        #4caf7d;
  --toolbar-h:    48px;
  --radius:       12px;
  --radius-lg:    16px;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', 'Segoe UI', system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

/* ── Logo mark ─────────────────────────────────────────────────────────────── */
.logo-mark {
  width: 28px; height: 28px;
  border-radius: 7px;
  background: linear-gradient(135deg, #7c5cff 0%, #a78bfa 100%);
  display: flex; align-items: center; justify-content: center;
  font-size: .8rem; font-weight: 700;
  color: #fff;
  flex-shrink: 0;
  user-select: none;
  letter-spacing: -.02em;
}

/* ── Modal ──────────────────────────────────────────────────────────────────── */
#modal-overlay {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: rgba(0,0,0,.65);
  backdrop-filter: blur(10px);
  z-index: 100;
}

#modal {
  background: var(--surface);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: var(--radius-lg);
  padding: 40px 36px;
  width: min(420px, 92vw);
  display: flex; flex-direction: column; gap: 16px;
  box-shadow: 0 24px 60px rgba(0,0,0,.5), 0 0 0 1px rgba(255,255,255,.03);
}

#modal h2 { font-size: 1.2rem; font-weight: 600; letter-spacing: -.02em; }
#modal p  { font-size: .875rem; color: var(--muted); line-height: 1.6; }

.modal-input {
  width: 100%; padding: 11px 14px;
  background: var(--bg);
  border: 1px solid rgba(255,255,255,0.09);
  border-radius: 10px;
  color: var(--text);
  font-size: .95rem;
  font-family: 'Inter', 'Segoe UI', sans-serif;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.modal-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}
.modal-input.input-error { border-color: var(--red); }
.modal-input::placeholder { color: rgba(255,255,255,.2); }

#modal-error { color: var(--red); font-size: .8rem; min-height: 1em; font-weight: 500; }

#modal-btn {
  padding: 11px;
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-hover) 100%);
  color: #fff;
  border: none;
  border-radius: 10px;
  font-size: .95rem;
  font-weight: 600;
  font-family: 'Inter', 'Segoe UI', sans-serif;
  cursor: pointer;
  transition: opacity .15s, transform .12s, box-shadow .15s;
  letter-spacing: -.01em;
}
#modal-btn:hover:not(:disabled) {
  opacity: .88;
  transform: translateY(-1px);
  box-shadow: 0 6px 20px var(--accent-glow);
}
#modal-btn:active:not(:disabled) { transform: translateY(0); box-shadow: none; }
#modal-btn:disabled { opacity: .45; cursor: not-allowed; }

/* ── App ────────────────────────────────────────────────────────────────────── */
#app { display: flex; flex-direction: column; height: 100vh; }
#app.hidden { display: none; }

/* Toolbar */
#toolbar {
  height: var(--toolbar-h);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 16px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
}

#note-id-label {
  font-size: .75rem;
  color: var(--muted);
  font-family: 'JetBrains Mono', monospace;
}

#toolbar-right { display: flex; align-items: center; gap: 6px; }

/* Visual divider between toolbar groups */
.toolbar-divider {
  width: 1px; height: 18px;
  background: rgba(255,255,255,0.09);
  margin: 0 4px;
  flex-shrink: 0;
}

#status-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--red);
  transition: background .35s;
  flex-shrink: 0;
  margin-right: 4px;
}
#status-dot.connected { background: var(--green); }

#toolbar button {
  padding: 5px 11px;
  background: transparent;
  border: 1px solid rgba(255,255,255,0.09);
  border-radius: 7px;
  color: var(--muted);
  font-size: .77rem;
  font-family: 'Inter', 'Segoe UI', sans-serif;
  font-weight: 500;
  cursor: pointer;
  transition: border-color .15s, color .15s, background .15s;
  white-space: nowrap;
}
#toolbar button:hover {
  border-color: var(--border-hover);
  color: var(--text);
  background: rgba(124,92,255,0.07);
}

/* Editor area */
#editor-area { flex: 1; display: flex; overflow: hidden; }

#editor {
  flex: 1; width: 100%; height: 100%;
  padding: 28px 32px;
  background: var(--bg);
  color: var(--text);
  border: none; outline: none; resize: none;
  font-family: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', monospace;
  font-size: .95rem;
  line-height: 1.85;
  tab-size: 2;
  caret-color: var(--accent);
}
#editor::placeholder { color: rgba(255,255,255,.15); }

/* Preview */
#preview {
  flex: 1; overflow-y: auto;
  padding: 28px 32px;
  background: var(--surface);
  border-left: 1px solid var(--border);
  font-size: .975rem;
  line-height: 1.8;
  max-width: 860px;
}
#preview.hidden { display: none; }

/* Markdown styles inside preview */
#preview h1,#preview h2,#preview h3 { margin: 1.4em 0 .5em; font-weight: 700; letter-spacing: -.02em; }
#preview h1 { font-size: 1.75rem; } #preview h2 { font-size: 1.35rem; } #preview h3 { font-size: 1.1rem; }
#preview p  { margin-bottom: 1em; }
#preview ul,#preview ol { padding-left: 1.5em; margin-bottom: 1em; }
#preview li { margin-bottom: .35em; }
#preview code {
  background: var(--surface-2); padding: 2px 7px; border-radius: 5px;
  font-family: 'JetBrains Mono', monospace; font-size: .88em; color: #c9b8ff;
}
#preview pre {
  background: var(--surface-2); padding: 16px 20px; border-radius: 10px;
  overflow-x: auto; margin-bottom: 1.2em;
  border: 1px solid var(--border);
}
#preview pre code { background: none; padding: 0; color: inherit; }
#preview pre code.hljs { background: transparent; padding: 0; overflow-x: visible; }
#preview blockquote {
  border-left: 3px solid var(--accent);
  padding: 2px 0 2px 16px;
  color: var(--muted); margin-bottom: 1em;
}
#preview a  { color: var(--accent); text-decoration: underline; text-underline-offset: 2px; }
#preview hr { border: none; border-top: 1px solid var(--border); margin: 1.8em 0; }
#preview table { border-collapse: collapse; width: 100%; margin-bottom: 1.2em; }
#preview th,#preview td { border: 1px solid var(--border); padding: 9px 14px; }
#preview th { background: var(--surface-2); font-weight: 600; font-size: .88rem; }

.hidden { display: none !important; }

/* ── Footer ─────────────────────────────────────────────────────────────────── */
#site-footer {
  position: fixed; bottom: 12px; right: 18px;
  font-size: .7rem; color: var(--muted);
  opacity: .4; pointer-events: none;
  transition: opacity .2s;
  z-index: 10;
  letter-spacing: .01em;
}
#site-footer:hover { opacity: .85; }
#site-footer a { color: inherit; text-decoration: none; pointer-events: all; }
#site-footer a:hover { color: var(--accent); }

/* ── Home icon button ───────────────────────────────────────────────────────── */
.home-btn {
  display: flex; align-items: center; justify-content: center;
  width: 32px; height: 32px; border-radius: 8px;
  color: var(--muted); text-decoration: none;
  transition: background .15s, color .15s;
  flex-shrink: 0;
}
.home-btn:hover { background: rgba(255,255,255,0.06); color: var(--text); }
.home-btn svg { display: block; }

/* ── Field labels & errors ──────────────────────────────────────────────────── */
.field-label {
  font-size: .72rem;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: .06em;
  text-transform: uppercase;
}

.field-error {
  font-size: .78rem;
  color: var(--red);
  min-height: 1em;
  font-weight: 500;
}

/* ── Toast ──────────────────────────────────────────────────────────────────── */
#toast {
  position: fixed; bottom: 24px; left: 50%;
  transform: translateX(-50%) translateY(16px);
  background: rgba(20,8,8,0.92);
  border: 1px solid rgba(240,106,106,0.35);
  color: var(--red);
  padding: 10px 20px;
  border-radius: 10px;
  font-size: .84rem;
  opacity: 0;
  transition: opacity .2s, transform .2s;
  pointer-events: none;
  z-index: 200;
  backdrop-filter: blur(8px);
  white-space: nowrap;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ── Markdown Help Modal ────────────────────────────────────────────────────── */
#md-overlay {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: rgba(0,0,0,.7);
  backdrop-filter: blur(8px);
  z-index: 150;
}

#md-modal {
  background: var(--surface);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: var(--radius-lg);
  width: min(660px, 95vw);
  max-height: 82vh;
  display: flex; flex-direction: column;
  overflow: hidden;
  box-shadow: 0 24px 60px rgba(0,0,0,.5);
}

#md-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 24px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

#md-close {
  background: none; border: none; cursor: pointer;
  color: var(--muted); font-size: .95rem; line-height: 1;
  padding: 5px 9px; border-radius: 7px;
  transition: background .15s, color .15s;
}
#md-close:hover { background: rgba(255,255,255,0.07); color: var(--text); }

#md-body { overflow-y: auto; }

.md-guide-table {
  width: 100%; border-collapse: collapse; font-size: .875rem;
}
.md-guide-table thead th {
  padding: 10px 20px;
  font-size: .68rem; font-weight: 600;
  letter-spacing: .08em; text-transform: uppercase;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
  text-align: left;
}
.md-guide-table tbody td {
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.md-guide-table tbody tr:last-child td { border-bottom: none; }
.md-guide-table td:nth-child(1) { color: var(--muted); width: 24%; font-size: .82rem; }
.md-guide-table td:nth-child(2) { width: 38%; }
.md-guide-table td:nth-child(3) { width: 38%; }

.md-syn {
  font-family: 'JetBrains Mono', monospace;
  font-size: .78rem;
  background: var(--bg); color: #93c5fd;
  padding: 3px 8px; border-radius: 5px;
  display: inline-block; white-space: pre;
  line-height: 1.6;
}

.md-r-h1 { font-size: 1.25rem; font-weight: 700; letter-spacing: -.02em; }
.md-r-h2 { font-size: 1rem;    font-weight: 700; }
.md-r-h3 { font-size: .88rem;  font-weight: 700; }
.md-r-code {
  background: var(--bg); padding: 2px 7px; border-radius: 5px;
  font-family: 'JetBrains Mono', monospace; font-size: .82rem; color: #c9b8ff;
}
.md-r-pre {
  background: var(--bg); padding: 8px 12px; border-radius: 7px;
  font-family: 'JetBrains Mono', monospace; font-size: .78rem; margin: 0;
}
.md-r-quote { border-left: 3px solid var(--accent); padding-left: 10px; color: var(--muted); }
.md-r-hr    { border: none; border-top: 1px solid var(--border); margin: 4px 0; }
.md-r-list  { padding-left: 1.2em; margin: 0; }
.md-r-list li { margin: 0; }
