:root {
  --bg-desktop: #eef2f6;
  --bg-window: #ffffff;
  --bg-chrome: #f6f8fa;
  --bg-hover: #e5effb;
  --bg-code: #f4f6f8;
  --border: #d8dee6;
  --border-hover: #9ec5f8;
  --text-main: #1f2328;
  --text-muted: #656d76;
  --accent: #0969da;
  --shadow: 0 10px 30px rgba(15, 23, 42, 0.08);
  --radius: 10px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg-desktop: #12151a;
    --bg-window: #1c2128;
    --bg-chrome: #22272e;
    --bg-hover: #26364a;
    --bg-code: #161b22;
    --border: #373e47;
    --border-hover: #539bf5;
    --text-main: #e6edf3;
    --text-muted: #8b949e;
    --accent: #58a6ff;
    --shadow: 0 12px 32px rgba(0, 0, 0, 0.45);
  }
}

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

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg-desktop);
  color: var(--text-main);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

body {
  padding: 20px 14px;
  min-height: 100vh;
}

.explorer-window {
  max-width: 1040px;
  min-height: calc(100vh - 40px);
  margin: 0 auto;
  background: var(--bg-window);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Top title bar */
.titlebar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  background: var(--bg-chrome);
  border-bottom: 1px solid var(--border);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: inherit;
  text-decoration: none;
  font-weight: 600;
  font-size: 15px;
}

.titlebar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.view-switch {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
  background: var(--bg-window);
}

.view-btn {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--text-muted);
  padding: 4px 10px;
  font-size: 12px;
  cursor: pointer;
}

.view-btn.is-active {
  background: var(--bg-hover);
  color: var(--text-main);
  font-weight: 600;
}

.toolbar-link {
  font-size: 13px;
  color: var(--accent);
  text-decoration: none;
  padding: 4px 10px;
  border-radius: 6px;
}

.toolbar-link:hover {
  background: var(--bg-hover);
}

/* Address bar / breadcrumbs */
.addressbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 16px;
  background: var(--bg-window);
  border-bottom: 1px solid var(--border);
}

.up-btn {
  flex: 0 0 auto;
  font-size: 13px;
  padding: 4px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  text-decoration: none;
  color: var(--text-main);
  background: var(--bg-chrome);
}

.up-btn:hover:not(.is-disabled) {
  background: var(--bg-hover);
  border-color: var(--border-hover);
}

.up-btn.is-disabled {
  opacity: 0.45;
  cursor: default;
}

.breadcrumbs {
  flex: 1 1 auto;
  list-style: none;
  margin: 0;
  padding: 5px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-chrome);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
  font-size: 13px;
}

.breadcrumbs li + li::before {
  content: "/";
  margin-right: 6px;
  color: var(--text-muted);
}

.breadcrumbs a {
  color: var(--text-main);
  text-decoration: none;
  padding: 1px 4px;
  border-radius: 4px;
}

.breadcrumbs a:hover {
  background: var(--bg-hover);
  color: var(--accent);
}

.breadcrumbs li[aria-current="page"] {
  color: var(--text-muted);
  font-weight: 500;
}

/* Workspace */
.workspace {
  flex: 1 1 auto;
  padding: 20px 24px 32px;
}

.folder-intro {
  margin-bottom: 16px;
  padding: 10px 14px;
  border-left: 3px solid var(--accent);
  background: var(--bg-chrome);
  border-radius: 0 6px 6px 0;
  font-size: 14px;
  color: var(--text-muted);
}

.folder-intro p {
  margin: 0;
}

/* Explorer Grid View */
.explorer-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(126px, 1fr));
  gap: 12px;
}

.item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 14px 10px 12px;
  text-decoration: none;
  text-align: center;
  color: inherit;
  border: 1px solid transparent;
  border-radius: 8px;
  overflow-wrap: anywhere;
  transition: background-color 0.12s ease, border-color 0.12s ease;
}

.item:hover, .item:focus-visible {
  background: var(--bg-hover);
  border-color: var(--border-hover);
  outline: none;
}

.item-icon {
  width: 60px;
  height: 60px;
  object-fit: contain;
  flex-shrink: 0;
}

.item-name {
  font-size: 14px;
  line-height: 1.35;
  font-weight: 500;
}

.item-meta {
  font-size: 12px;
  color: var(--text-muted);
}

/* Explorer List View */
.explorer-grid[data-view="list"] {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.explorer-grid[data-view="list"] .item {
  flex-direction: row;
  text-align: left;
  padding: 8px 12px;
  gap: 12px;
}

.explorer-grid[data-view="list"] .item-icon {
  width: 24px;
  height: 24px;
}

.explorer-grid[data-view="list"] .item-name {
  flex: 1 1 auto;
}

.explorer-grid[data-view="list"] .item-meta {
  flex: 0 0 auto;
}

.empty-state {
  text-align: center;
  color: var(--text-muted);
  padding: 48px 0;
  font-size: 14px;
}

/* Article reading view */
.article {
  max-width: 740px;
  margin: 0 auto;
}

.article-header {
  padding-bottom: 16px;
  margin-bottom: 24px;
  border-bottom: 1px solid var(--border);
}

.article-header h1 {
  margin: 0 0 8px;
  font-size: 28px;
  line-height: 1.3;
}

.article-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  font-size: 13px;
  color: var(--text-muted);
}

.article-meta a {
  color: var(--accent);
  text-decoration: none;
}

.toc {
  margin: 0 0 24px;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-chrome);
  font-size: 14px;
}

.toc summary {
  cursor: pointer;
  font-weight: 600;
}

.toc ul {
  margin: 8px 0 0;
  padding-left: 18px;
}

.toc a {
  color: var(--text-main);
  text-decoration: none;
}

.toc a:hover {
  color: var(--accent);
  text-decoration: underline;
}

.prose {
  font-size: 16px;
  line-height: 1.8;
}

.prose h2, .prose h3, .prose h4 {
  margin-top: 1.8em;
  margin-bottom: 0.6em;
  line-height: 1.35;
}

.prose h2 {
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
}

.prose a {
  color: var(--accent);
}

.prose img {
  display: block;
  max-width: 100%;
  height: auto;
  margin: 18px auto;
  border-radius: 6px;
  border: 1px solid var(--border);
  cursor: zoom-in;
}

.prose blockquote {
  margin: 16px 0;
  padding: 4px 16px;
  border-left: 3px solid var(--accent);
  background: var(--bg-chrome);
  color: var(--text-muted);
}

.prose code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.9em;
  padding: 2px 5px;
  border-radius: 4px;
  background: var(--bg-code);
}

.prose pre {
  position: relative;
  overflow-x: auto;
  padding: 14px 16px;
  border-radius: 8px;
  background: var(--bg-code);
  border: 1px solid var(--border);
  line-height: 1.5;
}

.prose pre code {
  padding: 0;
  background: transparent;
}

.copy-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  border: 1px solid var(--border);
  background: var(--bg-window);
  color: var(--text-muted);
  border-radius: 5px;
  padding: 2px 8px;
  font-size: 12px;
  cursor: pointer;
}

.copy-btn:hover {
  color: var(--text-main);
  border-color: var(--border-hover);
}

.prose table {
  width: 100%;
  border-collapse: collapse;
  margin: 18px 0;
  font-size: 14px;
}

.prose th, .prose td {
  border: 1px solid var(--border);
  padding: 8px 12px;
  text-align: left;
}

.prose th {
  background: var(--bg-chrome);
}

.article-footer {
  margin-top: 36px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 12px;
  font-size: 14px;
}

.article-footer a {
  color: var(--accent);
  text-decoration: none;
}

.article-footer a:hover {
  text-decoration: underline;
}

.sibling-links {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
}

/* Status bar */
.statusbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 16px;
  font-size: 12px;
  color: var(--text-muted);
  background: var(--bg-chrome);
  border-top: 1px solid var(--border);
}

/* Lightbox overlay */
.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 999;
  cursor: zoom-out;
}

.lightbox img {
  max-width: 94vw;
  max-height: 92vh;
  border-radius: 8px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
}

@media (max-width: 640px) {
  body {
    padding: 0;
  }
  .explorer-window {
    min-height: 100vh;
    border: 0;
    border-radius: 0;
  }
  .workspace {
    padding: 16px;
  }
  .explorer-grid {
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
  }
}
