:root {
  color-scheme: dark;
  --bg: #111214;
  --panel: #181a1f;
  --panel-soft: #20242b;
  --line: #303640;
  --text: #eceff4;
  --muted: #9aa4b2;
  --accent: #35c2a1;
  --accent-strong: #6ee7c8;
  --danger: #ff6b7a;
  --shadow: 0 18px 60px rgba(0, 0, 0, 0.38);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
}

button,
input,
select,
textarea {
  font: inherit;
}

.app-shell {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  border-right: 1px solid var(--line);
  background: #14161a;
  padding: 22px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

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

.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border: 1px solid rgba(53, 194, 161, 0.4);
  border-radius: 8px;
  background: #1d2b28;
  color: var(--accent-strong);
  font-weight: 800;
}

.brand h1 {
  margin: 0;
  font-size: 20px;
  letter-spacing: 0;
}

.brand p,
.status-line,
.search-box span,
.meta-grid label,
.page-excerpt {
  color: var(--muted);
}

.brand p {
  margin: 2px 0 0;
  font-size: 13px;
}

.primary-btn,
.ghost-btn,
.toolbar button {
  min-height: 38px;
  border: 1px solid transparent;
  border-radius: 7px;
  color: var(--text);
  cursor: pointer;
}

.primary-btn {
  background: var(--accent);
  color: #071412;
  font-weight: 750;
  padding: 0 14px;
}

.ghost-btn {
  background: var(--panel-soft);
  border-color: var(--line);
  padding: 0 14px;
}

.version-select {
  min-height: 38px;
  max-width: 190px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #101216;
  color: var(--text);
  padding: 0 10px;
}

.danger {
  color: var(--danger);
}

.sidebar-actions {
  display: grid;
  gap: 8px;
}

.sidebar-actions .primary-btn,
.sidebar-actions .ghost-btn {
  width: 100%;
}

.search-box {
  display: grid;
  gap: 8px;
  font-size: 13px;
}

.search-box input,
.search-box select,
.meta-grid input,
.title-input,
.dialog input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #101216;
  color: var(--text);
  outline: none;
}

.search-box input,
.search-box select {
  height: 40px;
  padding: 0 12px;
}

.search-box input:focus,
.search-box select:focus,
.meta-grid input:focus,
.title-input:focus,
.dialog input:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(53, 194, 161, 0.15);
}

.page-list {
  display: grid;
  gap: 8px;
  overflow: auto;
  padding-right: 4px;
}

.page-item {
  display: grid;
  gap: 4px;
  width: 100%;
  text-align: left;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  padding: 12px;
  cursor: pointer;
}

.page-item:hover,
.page-item.active {
  background: var(--panel-soft);
  border-color: var(--line);
}

.page-title {
  font-weight: 750;
}

.page-taxonomy {
  color: var(--accent-strong);
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.page-excerpt {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
}

.workspace {
  min-width: 0;
  display: grid;
  grid-template-rows: auto 1fr;
}

.home-view {
  min-height: 0;
  overflow: auto;
  padding: 28px;
  background: #111318;
}

.home-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--line);
}

.home-header h2 {
  margin: 0;
  font-size: 28px;
  letter-spacing: 0;
}

.home-header p {
  margin: 6px 0 0;
  color: var(--muted);
}

.article-index {
  display: grid;
  gap: 2px;
  margin-top: 16px;
}

.article-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(140px, 260px) 150px;
  gap: 16px;
  align-items: center;
  width: 100%;
  min-height: 64px;
  border: 1px solid transparent;
  border-bottom-color: rgba(48, 54, 64, 0.7);
  background: transparent;
  color: var(--text);
  text-align: left;
  padding: 12px 10px;
  cursor: pointer;
}

.article-row:hover {
  background: var(--panel-soft);
  border-color: var(--line);
  border-radius: 8px;
}

.article-main {
  min-width: 0;
  display: grid;
  gap: 4px;
}

.article-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 800;
}

.article-excerpt,
.article-date,
.empty-state {
  color: var(--muted);
}

.article-excerpt,
.article-taxonomy {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
}

.article-taxonomy {
  color: var(--accent-strong);
}

.article-date {
  text-align: right;
  font-size: 13px;
}

.home-more {
  margin-top: 18px;
  width: 100%;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  padding: 20px 24px;
  border-bottom: 1px solid var(--line);
  background: rgba(17, 18, 20, 0.9);
}

.title-wrap {
  min-width: 0;
  flex: 1;
}

.title-input {
  height: 48px;
  padding: 0 14px;
  font-size: 24px;
  font-weight: 800;
}

.read-title {
  min-height: 48px;
  display: flex;
  align-items: center;
  font-size: 28px;
  font-weight: 850;
}

.read-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.read-meta span {
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #101216;
  color: var(--accent-strong);
  padding: 5px 10px;
  font-size: 13px;
}

.meta-grid {
  display: grid;
  grid-template-columns: minmax(0, 220px) minmax(0, 1fr);
  gap: 10px;
  margin-top: 10px;
}

.meta-grid label {
  display: grid;
  gap: 6px;
  font-size: 12px;
}

.meta-grid input {
  height: 36px;
  padding: 0 10px;
}

.status-line {
  display: flex;
  gap: 14px;
  margin-top: 8px;
  font-size: 13px;
}

.topbar-actions {
  display: flex;
  align-items: flex-start;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px;
}

.editor-shell {
  min-height: 0;
  display: grid;
  grid-template-rows: auto 1fr;
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

.toolbar button {
  min-width: 38px;
  background: #12151a;
  border-color: var(--line);
  padding: 0 10px;
}

.toolbar button:hover,
.mode-btn.active {
  border-color: rgba(53, 194, 161, 0.75);
  color: var(--accent-strong);
}

.toolbar-spacer {
  flex: 1;
}

.mode-btn {
  min-width: 72px;
}

.editor-grid {
  min-height: 0;
  display: grid;
  background: #0f1114;
}

.editor-grid.split {
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
}

.editor-grid.edit-only {
  grid-template-columns: 1fr;
}

.editor-grid.preview-only {
  grid-template-columns: 1fr;
}

.editor-grid.read-mode {
  grid-template-columns: 280px minmax(0, 1fr);
}

textarea,
.preview,
.toc-panel {
  min-width: 0;
  min-height: 0;
  height: 100%;
  overflow: auto;
  padding: 28px;
}

textarea {
  resize: none;
  border: 0;
  border-right: 1px solid var(--line);
  outline: none;
  background: #101216;
  color: var(--text);
  line-height: 1.62;
  tab-size: 2;
}

.preview {
  background: #15181d;
}

.toc-panel {
  border-right: 1px solid var(--line);
  background: #12151a;
  padding: 24px 18px;
}

.toc-panel h2 {
  margin: 0 0 14px;
  color: var(--muted);
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0;
}

.toc-panel nav {
  display: grid;
  gap: 4px;
}

.toc-link {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  border-left: 2px solid transparent;
  color: var(--text);
  text-decoration: none;
  padding: 7px 8px;
  font-size: 13px;
}

.toc-link:hover {
  border-left-color: var(--accent);
  background: var(--panel-soft);
  color: var(--accent-strong);
}

.toc-link.level-2 {
  padding-left: 18px;
  color: #c5ccd6;
}

.toc-link.level-3 {
  padding-left: 28px;
  color: var(--muted);
}

.toc-empty {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.edit-only .preview,
.preview-only textarea,
.read-mode textarea {
  display: none;
}

.read-mode .preview {
  display: block;
  padding: 34px 42px;
}

.markdown-body {
  line-height: 1.7;
  color: #e4e8ee;
}

.markdown-body h1,
.markdown-body h2,
.markdown-body h3 {
  line-height: 1.2;
}

.markdown-body a {
  color: var(--accent-strong);
}

.markdown-body figure {
  margin: 20px 0;
}

.markdown-body img {
  display: block;
  max-width: 100%;
  max-height: 70vh;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #0d1014;
}

.markdown-body figcaption {
  margin-top: 8px;
  color: var(--muted);
  font-size: 13px;
}

.markdown-body code {
  background: #0d1014;
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 2px 5px;
}

.markdown-body pre {
  overflow: auto;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #0d1014;
}

.markdown-body blockquote {
  margin-left: 0;
  padding-left: 16px;
  border-left: 3px solid var(--accent);
  color: var(--muted);
}

.markdown-body table {
  width: 100%;
  border-collapse: collapse;
}

.markdown-body th,
.markdown-body td {
  border: 1px solid var(--line);
  padding: 8px 10px;
}

.dialog-backdrop {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(0, 0, 0, 0.62);
  padding: 20px;
}

.dialog {
  width: min(440px, 100%);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  padding: 22px;
}

.dialog h2 {
  margin: 0 0 18px;
}

.dialog label {
  display: grid;
  gap: 8px;
}

.dialog input {
  height: 42px;
  padding: 0 12px;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 20px;
}

@media (max-width: 860px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--line);
    max-height: 42vh;
  }

  .topbar {
    flex-direction: column;
  }

  .home-view {
    padding: 20px;
  }

  .home-header {
    flex-direction: column;
  }

  .article-row {
    grid-template-columns: 1fr;
    gap: 6px;
  }

  .article-date {
    text-align: left;
  }

  .meta-grid {
    grid-template-columns: 1fr;
  }

  .topbar-actions {
    align-items: stretch;
    justify-content: stretch;
  }

  .version-select {
    max-width: none;
    width: 100%;
  }

  .editor-grid.split {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(280px, 1fr) minmax(280px, 1fr);
  }

  .editor-grid.read-mode {
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(0, 1fr);
  }

  .toc-panel {
    height: auto;
    max-height: 220px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .read-mode .preview {
    padding: 24px;
  }

  textarea {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .toolbar {
    flex-wrap: wrap;
  }
}
