:root {
  --bg: #141210;
  --bg-elevated: #1d1916;
  --bg-hover: #29231e;
  --border: #332b24;
  --text: #f4efe9;
  --text-muted: #a6998d;
  --accent: #f97316;
  --accent-hover: #fb923c;
  --accent-soft: rgba(249, 115, 22, 0.14);
  --danger: #ef4444;
  --radius: 10px;
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  line-height: 1.55;
}

.hidden {
  display: none !important;
}

.app-shell {
  display: flex;
  flex-direction: column;
  height: 100dvh;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.65rem 1rem;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.brand-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 10px var(--accent);
}

.brand-title {
  font-weight: 700;
  letter-spacing: 0.01em;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 0.45rem;
}

.icon-btn {
  display: none;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 0.35rem 0.6rem;
  font-size: 1rem;
  cursor: pointer;
}

.btn {
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 0.42rem 0.8rem;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.btn-ghost {
  background: transparent;
  border-color: var(--border);
  color: var(--text);
}

.btn-ghost:hover {
  background: var(--bg-hover);
}

.btn-accent {
  background: var(--accent);
  color: #141210;
}

.btn-accent:hover {
  background: var(--accent-hover);
}

.btn-danger {
  background: transparent;
  border-color: rgba(239, 68, 68, 0.4);
  color: var(--danger);
}

.btn-danger:hover {
  background: rgba(239, 68, 68, 0.12);
}

.workspace {
  display: flex;
  flex: 1;
  min-height: 0;
  position: relative;
}

.sidebar {
  width: 290px;
  flex-shrink: 0;
  background: var(--bg-elevated);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.sidebar-search {
  padding: 0.75rem;
  border-bottom: 1px solid var(--border);
}

.sidebar-search input,
.modal-card input {
  width: 100%;
  padding: 0.55rem 0.75rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 0.9rem;
}

.sidebar-search input:focus,
.modal-card input:focus,
.note-editor:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
}

.note-list {
  flex: 1;
  overflow-y: auto;
  padding: 0.5rem;
}

.folder-label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  padding: 0.65rem 0.6rem 0.25rem;
  font-weight: 700;
}

.note-item {
  display: block;
  width: 100%;
  text-align: left;
  background: transparent;
  border: none;
  color: var(--text);
  padding: 0.45rem 0.65rem;
  border-radius: 7px;
  font-size: 0.88rem;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.note-item:hover {
  background: var(--bg-hover);
}

.note-item.active {
  background: var(--accent-soft);
  color: var(--accent-hover);
  font-weight: 600;
}

.main-pane {
  flex: 1;
  min-width: 0;
  overflow-y: auto;
  padding: 1.5rem 2rem;
}

.empty-state {
  max-width: 560px;
  margin: 4rem auto;
  text-align: center;
  color: var(--text-muted);
}

.empty-state h1 {
  color: var(--text);
}

.note-view {
  max-width: 820px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  height: 100%;
}

.note-header {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
  padding-bottom: 0.85rem;
  border-bottom: 1px solid var(--border);
}

.note-title {
  margin: 0;
  font-size: 1.5rem;
  word-break: break-word;
}

.note-meta {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 0.2rem;
}

.note-actions {
  display: flex;
  gap: 0.45rem;
  flex-wrap: wrap;
}

.markdown-body {
  line-height: 1.7;
  font-size: 1rem;
  word-wrap: break-word;
}

.markdown-body h1,
.markdown-body h2,
.markdown-body h3 {
  color: #fff7ed;
  margin-top: 1.5em;
}

.markdown-body a,
.wikilink {
  color: var(--accent-hover);
  text-decoration: underline;
  cursor: pointer;
}

.markdown-body code {
  font-family: var(--font-mono);
  background: var(--bg-elevated);
  padding: 0.15rem 0.35rem;
  border-radius: 5px;
  font-size: 0.88em;
}

.markdown-body pre {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  padding: 0.9rem 1rem;
  border-radius: var(--radius);
  overflow-x: auto;
}

.markdown-body pre code {
  background: transparent;
  padding: 0;
}

.markdown-body blockquote {
  margin: 1rem 0;
  padding: 0.4rem 1rem;
  border-left: 3px solid var(--accent);
  background: var(--accent-soft);
  border-radius: 0 8px 8px 0;
}

.note-editor {
  width: 100%;
  flex: 1;
  min-height: 60vh;
  resize: vertical;
  background: var(--bg-elevated);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  font-family: var(--font-mono);
  font-size: 0.94rem;
  line-height: 1.6;
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.72);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  z-index: 40;
}

.modal-card {
  width: 100%;
  max-width: 400px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
}

.modal-card h2 {
  margin: 0 0 0.4rem;
}

.modal-desc {
  margin: 0 0 1rem;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 1rem;
}

.error-msg {
  color: var(--danger);
  font-size: 0.85rem;
  margin: 0.5rem 0 0;
}

.muted-msg {
  color: var(--text-muted);
  font-size: 0.9rem;
  padding: 0.75rem;
}

.toast {
  position: fixed;
  bottom: 1rem;
  right: 1rem;
  background: var(--bg-elevated);
  border: 1px solid var(--accent);
  color: var(--text);
  padding: 0.65rem 1rem;
  border-radius: 8px;
  z-index: 50;
  font-size: 0.88rem;
}

@media (max-width: 768px) {
  .icon-btn {
    display: inline-flex;
  }

  .sidebar {
    position: fixed;
    top: 53px;
    bottom: 0;
    left: 0;
    z-index: 30;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    width: min(82vw, 310px);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .sidebar-backdrop {
    position: fixed;
    inset: 53px 0 0 0;
    background: rgba(0, 0, 0, 0.55);
    z-index: 20;
  }

  .main-pane {
    padding: 1rem;
  }
}
