:root[data-theme="dark"] {
  --bg-color: #0f1219;
  --surface-color: #171c28;
  --surface-border: #283044;
  --text-main: #e2e8f0;
  --text-muted: #94a3b8;
  --accent-color: #c99a4e;
  --accent-hover: #e6b364;
  --primary-color: #3b82f6;
  --link-color: #60a5fa;
  --link-hover: #93c5fd;
  --code-bg: #1e2536;
  --tree-hover: #222a3d;
  --tree-active: #2d374d;
}

:root[data-theme="light"] {
  --bg-color: #f8fafc;
  --surface-color: #ffffff;
  --surface-border: #e2e8f0;
  --text-main: #1e293b;
  --text-muted: #64748b;
  --accent-color: #b45309;
  --accent-hover: #d97706;
  --primary-color: #2563eb;
  --link-color: #2563eb;
  --link-hover: #1d4ed8;
  --code-bg: #f1f5f9;
  --tree-hover: #f1f5f9;
  --tree-active: #e2e8f0;
}

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

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background-color: var(--bg-color);
  color: var(--text-main);
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Header */
.app-header {
  height: 60px;
  background-color: var(--surface-color);
  border-bottom: 1px solid var(--surface-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  position: sticky;
  top: 0;
  z-index: 100;
}

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

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
  color: var(--accent-color);
  font-family: 'Cinzel', serif;
  font-weight: 700;
  font-size: 1.25rem;
}

.header-center { flex: 1; max-width: 480px; margin: 0 20px; }

.search-box {
  position: relative;
  display: flex;
  align-items: center;
}

.search-box svg {
  position: absolute;
  left: 12px;
  color: var(--text-muted);
}

.search-box input {
  width: 100%;
  padding: 8px 12px 8px 36px;
  border-radius: 8px;
  border: 1px solid var(--surface-border);
  background: var(--bg-color);
  color: var(--text-main);
  outline: none;
}

.search-results {
  position: absolute;
  top: 45px;
  left: 0;
  right: 0;
  background: var(--surface-color);
  border: 1px solid var(--surface-border);
  border-radius: 8px;
  box-shadow: 0 10px 25px rgba(0,0,0,0.3);
  max-height: 360px;
  overflow-y: auto;
  display: none;
  z-index: 200;
}

.search-item {
  display: block;
  padding: 10px 14px;
  text-decoration: none;
  border-bottom: 1px solid var(--surface-border);
  color: var(--text-main);
}
.search-item:hover { background: var(--tree-hover); }
.search-title { font-weight: 600; color: var(--accent-color); font-size: 0.95rem; }
.search-path { font-size: 0.75rem; color: var(--text-muted); }
.search-snippet { font-size: 0.85rem; margin-top: 4px; color: var(--text-muted); }

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

/* Buttons */
.btn {
  padding: 8px 16px;
  border-radius: 6px;
  border: none;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: all 0.2s;
}
.btn-primary { background: var(--accent-color); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-secondary { background: var(--surface-border); color: var(--text-main); }
.btn-secondary:hover { background: var(--tree-active); }
.btn-outline { border: 1px solid var(--surface-border); background: transparent; color: var(--text-main); }
.btn-danger { background: #dc3545; color: #fff; }
.btn-danger:hover { background: #c82333; }
.btn-sm { padding: 6px 12px; font-size: 0.85rem; }

.btn-oauth {
  text-decoration: none;
  justify-content: center;
  margin-bottom: 10px;
  font-size: 0.9rem;
}
.btn-google {
  background: #ffffff;
  color: #3c4043;
  border: 1px solid #dadce0;
}
.btn-google:hover {
  background: #f8f9fa;
  color: #202124;
}
.btn-discord {
  background: #5865F2;
  color: #ffffff;
}
.btn-discord:hover {
  background: #4752C4;
}

.auth-divider {
  display: flex;
  align-items: center;
  text-align: center;
  margin: 16px 0;
  color: var(--text-muted);
  font-size: 0.75rem;
  font-weight: 600;
}
.auth-divider::before, .auth-divider::after {
  content: '';
  flex: 1;
  border-bottom: 1px solid var(--surface-border);
}
.auth-divider span {
  padding: 0 10px;
}

.icon-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 6px;
  border-radius: 6px;
}
.icon-btn:hover { background: var(--tree-hover); color: var(--text-main); }

.mobile-menu-toggle { display: none; }

/* User Badge */
.user-badge { display: flex; align-items: center; gap: 10px; font-size: 0.85rem; }
.group-tag {
  background: var(--surface-border);
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 0.75rem;
  color: var(--accent-color);
}

/* Layout Container */
.app-container {
  display: flex;
  flex: 1;
}

/* Sidebar */
.sidebar {
  width: 280px;
  background: var(--surface-color);
  border-right: 1px solid var(--surface-border);
  padding: 16px 12px;
  overflow-y: auto;
}
.sidebar-header { margin-bottom: 12px; padding: 0 8px; }
.sidebar-header h3 {
  font-family: 'Cinzel', serif;
  font-size: 0.9rem;
  text-transform: uppercase;
  color: var(--text-muted);
  letter-spacing: 0.05em;
}

.file-tree ul { list-style: none; padding-left: 12px; }
.file-tree > ul { padding-left: 0; }
.file-tree li { margin: 2px 0; }

.file-tree summary {
  cursor: pointer;
  padding: 6px 8px;
  border-radius: 6px;
  font-weight: 500;
  font-size: 0.9rem;
  color: var(--text-main);
}
.file-tree summary:hover { background: var(--tree-hover); }

.file-tree a {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  border-radius: 6px;
  text-decoration: none;
  color: var(--text-main);
  font-size: 0.9rem;
}
.file-tree a:hover { background: var(--tree-hover); }
.file-tree li.active > a { background: var(--tree-active); color: var(--accent-color); font-weight: 600; }

/* Main Content */
.main-content {
  flex: 1;
  padding: 24px 32px;
  max-width: 960px;
  margin: 0 auto;
}

.content-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--surface-border);
}

.breadcrumbs { font-size: 0.85rem; color: var(--text-muted); }
.breadcrumbs a { color: var(--accent-color); text-decoration: none; }

/* Markdown Body */
.markdown-body { font-size: 1rem; color: var(--text-main); }
.markdown-body a {
  color: var(--link-color);
  text-decoration: underline;
  text-underline-offset: 3px;
  text-decoration-thickness: 1px;
  transition: color 0.15s ease, text-decoration-color 0.15s ease;
}
.markdown-body a:hover,
.markdown-body a:focus {
  color: var(--link-hover);
  text-decoration-thickness: 2px;
}
.markdown-body a:visited {
  color: var(--link-color);
}
.markdown-body h1, .markdown-body h2, .markdown-body h3 {
  font-family: 'Cinzel', serif;
  color: var(--accent-color);
  margin-top: 1.5em;
  margin-bottom: 0.6em;
  line-height: 1.3;
  scroll-margin-top: 85px;
}
.markdown-body h1 { font-size: 2.2rem; border-bottom: 1px solid var(--surface-border); padding-bottom: 8px; }
.markdown-body h2 { font-size: 1.6rem; }
.markdown-body h3 { font-size: 1.25rem; }

.markdown-body p { margin-bottom: 1.2em; }
.markdown-body img {
  max-width: 100%;
  height: auto;
  border-radius: 8px;
  box-shadow: 0 4px 15px rgba(0,0,0,0.2);
  margin: 16px 0;
  display: block;
}

.markdown-body blockquote {
  border-left: 4px solid var(--accent-color);
  padding: 10px 16px;
  background: var(--surface-color);
  margin: 16px 0;
  border-radius: 0 8px 8px 0;
  font-style: italic;
}

.markdown-body code {
  background: var(--code-bg);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: 'Fira Code', monospace;
  font-size: 0.9em;
}

.markdown-body pre code { display: block; padding: 14px; overflow-x: auto; }

/* Table of Contents Sidebar */
.toc-sidebar {
  width: 240px;
  padding: 24px 16px;
  border-left: 1px solid var(--surface-border);
}
.toc-title { font-weight: 700; font-size: 0.85rem; text-transform: uppercase; color: var(--text-muted); margin-bottom: 12px; }
.toc-list { list-style: none; }
.toc-item { margin: 6px 0; }
.toc-item a { text-decoration: none; color: var(--text-muted); font-size: 0.85rem; transition: color 0.2s, font-weight 0.2s; }
.toc-item a:hover, .toc-item.active a { color: var(--accent-color); }
.toc-item.active a { font-weight: 600; }
.toc-item.level-2 { padding-left: 12px; }
.toc-item.level-3 { padding-left: 24px; }

/* Modal */
.modal-backdrop {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.7);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 500;
  padding: 20px;
}
.modal-backdrop.active {
  display: flex;
}

.modal-card {
  background: var(--surface-color);
  border-radius: 12px;
  width: 100%;
  max-width: 440px;
  border: 1px solid var(--surface-border);
  box-shadow: 0 20px 40px rgba(0,0,0,0.4);
  padding: 24px;
}

.modal-card.modal-lg { max-width: 900px; height: 80vh; display: flex; flex-direction: column; }

.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.modal-header h3 { font-family: 'Cinzel', serif; color: var(--accent-color); }
.close-btn { background: none; border: none; font-size: 1.5rem; color: var(--text-muted); cursor: pointer; }

.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 0.85rem; margin-bottom: 6px; color: var(--text-muted); }
.form-group input {
  width: 100%;
  padding: 10px;
  border-radius: 6px;
  border: 1px solid var(--surface-border);
  background: var(--bg-color);
  color: var(--text-main);
}

.editor-toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 10px;
  padding: 8px 12px;
  background: var(--surface-bg);
  border: 1px solid var(--surface-border);
  border-radius: 6px;
}

.editor-upload-hint {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.editor-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  margin-bottom: 16px;
  position: relative;
}

#editorTextarea {
  flex: 1;
  width: 100%;
  background: var(--bg-color);
  color: var(--text-main);
  border: 1px solid var(--surface-border);
  border-radius: 8px;
  padding: 16px;
  font-family: 'Fira Code', monospace;
  font-size: 0.95rem;
  resize: none;
  outline: none;
}

.editor-drop-overlay {
  display: none;
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(15, 23, 42, 0.85);
  border: 2px dashed #6366f1;
  border-radius: 8px;
  z-index: 10;
  justify-content: center;
  align-items: center;
  pointer-events: none;
}

.editor-drop-overlay.active {
  display: flex;
}

.drop-message {
  font-size: 1.1rem;
  font-weight: 600;
  color: #818cf8;
  background: var(--surface-bg);
  padding: 12px 24px;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}

.modal-footer { display: flex; justify-content: flex-end; gap: 12px; }
.btn-block { width: 100%; }
.error-msg { color: #ef4444; font-size: 0.85rem; margin-bottom: 12px; }

@media (max-width: 992px) {
  .toc-sidebar { display: none; }
  .mobile-menu-toggle { display: block; }
  .sidebar {
    position: fixed;
    top: 60px; bottom: 0; left: -280px;
    z-index: 300;
    transition: left 0.3s ease;
  }
  .sidebar.open { left: 0; }
}

/* Sidebar header with "+" button */
.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.sidebar-add-btn {
  padding: 4px;
  border-radius: 5px;
  color: var(--text-muted);
  flex-shrink: 0;
  transition: background 0.15s, color 0.15s;
}
.sidebar-add-btn:hover {
  background: var(--tree-hover);
  color: var(--accent-color);
}

/* Context Menu */
.context-menu {
  position: fixed;
  z-index: 1000;
  background: var(--surface-color);
  border: 1px solid var(--surface-border);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.35);
  padding: 4px;
  min-width: 160px;
  animation: ctxFadeIn 0.12s ease;
}

@keyframes ctxFadeIn {
  from { opacity: 0; transform: scale(0.96) translateY(-4px); }
  to   { opacity: 1; transform: scale(1)   translateY(0); }
}

.context-menu-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 8px 12px;
  background: none;
  border: none;
  border-radius: 5px;
  color: var(--text-main);
  font-size: 0.88rem;
  font-family: inherit;
  cursor: pointer;
  text-align: left;
  transition: background 0.12s, color 0.12s;
}
.context-menu-item:hover {
  background: var(--tree-hover);
  color: var(--accent-color);
}
.context-menu-item svg {
  flex-shrink: 0;
  color: var(--text-muted);
}
.context-menu-item:hover svg {
  color: var(--accent-color);
}

/* History Modal & Commit List Styles */
.history-commit-card {
  background: var(--bg-color);
  border: 1px solid var(--surface-border);
  border-radius: 6px;
  padding: 12px;
  margin-bottom: 10px;
  transition: border-color 0.15s ease;
}

.history-commit-card:hover {
  border-color: var(--accent-color);
}

.history-commit-header {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.history-commit-title {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
}

.commit-subject {
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--text-main);
  word-break: break-word;
}

.commit-hash {
  font-family: 'Fira Code', monospace;
  font-size: 0.8rem;
  padding: 2px 6px;
  background: var(--surface-color);
  border: 1px solid var(--surface-border);
  border-radius: 4px;
  color: var(--accent-color);
  flex-shrink: 0;
}

.history-commit-meta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-top: 4px;
}

.btn-xs {
  padding: 2px 8px;
  font-size: 0.75rem;
  border-radius: 3px;
  margin-left: auto;
}

.history-commit-diff {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px dashed var(--surface-border);
}

.diff-block {
  background: #1e1e1e;
  color: #d4d4d4;
  font-family: 'Fira Code', monospace;
  font-size: 0.82rem;
  padding: 12px;
  border-radius: 6px;
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: break-all;
  line-height: 1.4;
  max-height: 350px;
  overflow-y: auto;
}

[data-theme="light"] .diff-block {
  background: #f6f8fa;
  color: #24292e;
}

.diff-add {
  color: #4ec9b0;
  background-color: rgba(78, 201, 176, 0.15);
  display: block;
}

.diff-del {
  color: #f14c4c;
  background-color: rgba(241, 76, 76, 0.15);
  display: block;
}

.diff-hunk {
  color: #569cd6;
  font-weight: bold;
  display: block;
}

.diff-header {
  color: #ce9178;
  font-weight: bold;
  display: block;
}

/* Changelog Badge & Modal */
.changelog-badge {
  background: var(--accent-color);
  color: #fff;
  font-size: 0.65rem;
  font-weight: 700;
  padding: 1px 5px;
  border-radius: 10px;
  margin-left: 4px;
  text-transform: uppercase;
}

.changelog-release {
  background: var(--bg-color);
  border: 1px solid var(--surface-border);
  border-radius: 8px;
  padding: 16px;
  margin-bottom: 16px;
}

.changelog-release-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--surface-border);
  padding-bottom: 8px;
  margin-bottom: 12px;
}

.changelog-version {
  font-family: 'Cinzel', serif;
  font-weight: 700;
  color: var(--accent-color);
  font-size: 1.1rem;
}

.changelog-date {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.changelog-section-title {
  font-weight: 600;
  font-size: 0.9rem;
  margin: 10px 0 6px 0;
  color: var(--text-main);
}

.changelog-list {
  list-style-type: disc;
  padding-left: 20px;
  font-size: 0.88rem;
  color: var(--text-muted);
}

.changelog-list li {
  margin-bottom: 4px;
}


