*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --color-bg: #0a0a0f;
  --color-bg-secondary: #12121a;
  --color-surface: #16161f;
  --color-surface-hover: #1c1c28;
  --color-text: #e4e4e7;
  --color-text-secondary: #a1a1aa;
  --color-text-tertiary: #71717a;
  --color-border: rgba(255,255,255,0.08);
  --color-border-hover: rgba(255,255,255,0.15);
  --color-accent: #818cf8;
  --color-accent-glow: rgba(129,140,248,0.15);
  --color-accent-secondary: #a78bfa;
  --color-accent-gradient: linear-gradient(135deg, #818cf8, #a78bfa);
  --color-accent-hover: #a5b4fc;
  --color-tag-bg: rgba(129,140,248,0.1);
  --color-success: #34d399;
  --color-warning: #fbbf24;
  --color-danger: #f87171;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.3);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.4);
  --shadow-lg: 0 8px 32px rgba(0,0,0,0.5);
  --shadow-glow: 0 0 20px rgba(129,140,248,0.1);
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans SC", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  --font-mono: "SF Mono", "Fira Code", "Fira Mono", "Roboto Mono", "Consolas", monospace;
  --sidebar-width: 300px;
  --header-height: 56px;
}

html {
  scroll-behavior: smooth;
  height: 100%;
}

body {
  font-family: var(--font-sans);
  background: var(--color-bg);
  color: var(--color-text);
  line-height: 1.6;
  min-height: 100vh;
  height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

a { color: inherit; text-decoration: none; }

/* ===== Header ===== */
.app-header {
  position: relative;
  z-index: 200;
  background: rgba(10,10,15,0.9);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--color-border);
  height: var(--header-height);
  flex-shrink: 0;
}

.header-inner {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.sidebar-toggle {
  display: none;
  width: 36px;
  height: 36px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  color: var(--color-text-secondary);
  cursor: pointer;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
}

.sidebar-toggle:hover {
  color: var(--color-accent);
  border-color: var(--color-accent);
}

.logo {
  font-size: 16px;
  font-weight: 700;
  background: var(--color-accent-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  letter-spacing: -0.02em;
  white-space: nowrap;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 16px;
}

.header-search {
  position: relative;
  width: 280px;
}

.header-search input {
  width: 100%;
  padding: 8px 12px 8px 34px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-family: var(--font-sans);
  background: var(--color-surface);
  color: var(--color-text);
  outline: none;
  transition: all 0.2s ease;
}

.header-search input:focus {
  border-color: var(--color-accent);
  box-shadow: 0 0 0 2px var(--color-accent-glow);
}

.header-search input::placeholder { color: var(--color-text-tertiary); }

.header-search .search-icon {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--color-text-tertiary);
  pointer-events: none;
}

.header-stats {
  font-size: 12px;
  color: var(--color-text-tertiary);
  white-space: nowrap;
}

.theme-toggle {
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  color: var(--color-text-secondary);
  height: 34px;
  padding: 0 12px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}

.theme-toggle:hover {
  color: var(--color-accent);
  border-color: var(--color-accent);
  box-shadow: var(--shadow-glow);
}

/* ===== Layout ===== */
.app-layout {
  display: flex;
  flex: 1;
  overflow: hidden;
  min-height: 0;
  height: calc(100vh - var(--header-height));
}

/* ===== Sidebar ===== */
.sidebar {
  width: var(--sidebar-width);
  flex-shrink: 0;
  background: var(--color-bg-secondary);
  border-right: 1px solid var(--color-border);
  overflow-y: scroll;
  overflow-x: hidden;
  height: calc(100vh - var(--header-height));
  scrollbar-gutter: stable;
  scrollbar-width: thin;
  transition: transform 0.3s ease, width 0.3s ease;
}

/* ===== Content Panel ===== */
.content-panel {
  flex: 1 1 0%;
  overflow-y: scroll;
  overflow-x: hidden;
  background: var(--color-bg);
  min-height: 0;
  height: calc(100vh - var(--header-height));
  scrollbar-gutter: stable;
  scrollbar-width: thin;
}

.sidebar::-webkit-scrollbar { width: 4px; }
.sidebar::-webkit-scrollbar-track { background: transparent; }
.sidebar::-webkit-scrollbar-thumb { background: var(--color-border); border-radius: 4px; }
.sidebar::-webkit-scrollbar-thumb:hover { background: var(--color-text-tertiary); }

.content-panel::-webkit-scrollbar { width: 6px; }
.content-panel::-webkit-scrollbar-track { background: transparent; }
.content-panel::-webkit-scrollbar-thumb { background: var(--color-border); border-radius: 6px; }
.content-panel::-webkit-scrollbar-thumb:hover { background: var(--color-text-tertiary); }

.tree-nav { padding: 12px 0; }

.tree-category {
  margin-bottom: 4px;
}

.tree-category-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  color: var(--color-text-secondary);
  transition: all 0.15s ease;
  user-select: none;
}

.tree-category-header:hover {
  color: var(--color-text);
  background: rgba(255,255,255,0.03);
}

.tree-category-header .arrow {
  font-size: 10px;
  transition: transform 0.2s ease;
  color: var(--color-text-tertiary);
}

.tree-category-header.collapsed .arrow {
  transform: rotate(-90deg);
}

.tree-category-header .cat-label {
  display: flex;
  flex-direction: column;
  line-height: 1.3;
}

.tree-category-header .cat-en {
  font-size: 10px;
  font-weight: 400;
  color: var(--color-text-tertiary);
  opacity: 0.7;
}

.tree-category-header .count {
  margin-left: auto;
  font-size: 11px;
  font-weight: 400;
  color: var(--color-text-tertiary);
  background: rgba(255,255,255,0.05);
  padding: 1px 6px;
  border-radius: 10px;
}

.tree-items {
  overflow: hidden;
  transition: max-height 0.3s ease;
}

.tree-items.collapsed {
  max-height: 0 !important;
}

.tree-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 16px 6px 32px;
  cursor: pointer;
  font-size: 13px;
  color: var(--color-text-secondary);
  transition: all 0.15s ease;
  border-left: 2px solid transparent;
}

.tree-item:hover {
  color: var(--color-text);
  background: rgba(255,255,255,0.03);
}

.tree-item.active {
  color: var(--color-accent);
  background: var(--color-accent-glow);
  border-left-color: var(--color-accent);
  font-weight: 500;
}

.tree-item .item-en {
  margin-left: auto;
  font-size: 11px;
  color: var(--color-text-tertiary);
  opacity: 0.6;
}

/* ===== Welcome View ===== */
.welcome-view {
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 40px;
}

/* ===== Search Dropdown ===== */
.search-dropdown {
  position: absolute;
  top: 100%;
  left: 0;
  width: 520px;
  max-width: calc(100vw - 24px);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 0 0 var(--radius-sm) var(--radius-sm);
  max-height: 360px;
  overflow-y: auto;
  z-index: 300;
  box-shadow: var(--shadow-lg);
  display: none;
}

.search-dropdown.visible {
  display: block;
}

.search-dropdown-item {
  display: block;
  padding: 10px 12px;
  cursor: pointer;
  transition: background 0.15s ease;
  border-bottom: 1px solid var(--color-border);
}

.search-dropdown-item:last-child {
  border-bottom: none;
}

.search-dropdown-item:hover,
.search-dropdown-item.highlighted {
  background: var(--color-accent-glow);
}

.search-dropdown-item .sd-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--color-text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.search-dropdown-item .sd-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 4px;
}

.search-dropdown-item .sd-match {
  font-size: 10px;
  color: var(--color-text-tertiary);
  background: rgba(255,255,255,0.04);
  padding: 2px 6px;
  border-radius: 3px;
  white-space: nowrap;
}

.search-dropdown-item .sd-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.search-dropdown-item .sd-en {
  font-size: 12px;
  color: var(--color-text-secondary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.search-dropdown-item .sd-sep {
  color: var(--color-text-tertiary);
  font-size: 11px;
}

.search-dropdown-item .sd-cat {
  font-size: 10px;
  color: var(--color-accent);
  background: var(--color-tag-bg);
  padding: 1px 6px;
  border-radius: 3px;
  white-space: nowrap;
}

.header-search {
  position: relative;
  width: 280px;
}

.welcome-content {
  max-width: 700px;
  text-align: center;
}

.welcome-content h1 {
  font-size: 36px;
  font-weight: 800;
  letter-spacing: -0.03em;
  margin-bottom: 12px;
  background: var(--color-accent-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.welcome-subtitle {
  font-size: 16px;
  color: var(--color-text-secondary);
  margin-bottom: 40px;
}

.welcome-stats {
  display: flex;
  justify-content: center;
  gap: 32px;
  margin-bottom: 40px;
}

.stat-item {
  text-align: center;
}

.stat-value {
  font-size: 28px;
  font-weight: 700;
  color: var(--color-accent);
}

.stat-label {
  font-size: 12px;
  color: var(--color-text-tertiary);
  margin-top: 4px;
}

.welcome-categories {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 40px;
}

.welcome-cat-card {
  padding: 16px 12px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  cursor: pointer;
  transition: all 0.2s ease;
  text-align: center;
}

.welcome-cat-card:hover {
  border-color: var(--color-accent);
  box-shadow: var(--shadow-glow);
}

.welcome-cat-card .cat-name {
  font-size: 12px;
  font-weight: 600;
  color: var(--color-text);
  margin-bottom: 4px;
}

.welcome-cat-card .cat-count {
  font-size: 11px;
  color: var(--color-text-tertiary);
}

.welcome-recent h3 {
  font-size: 14px;
  font-weight: 600;
  color: var(--color-text-secondary);
  margin-bottom: 16px;
}

.recent-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
}

.recent-chip {
  padding: 6px 14px;
  border: 1px solid var(--color-border);
  border-radius: 999px;
  font-size: 12px;
  color: var(--color-text-secondary);
  cursor: pointer;
  transition: all 0.15s ease;
  background: var(--color-surface);
}

.recent-chip:hover {
  border-color: var(--color-accent);
  color: var(--color-accent);
}

/* ===== Detail View ===== */
.detail-view {
  padding: 40px;
  max-width: 860px;
  width: 100%;
}

.detail-header {
  margin-bottom: 32px;
  padding-bottom: 24px;
  border-bottom: 1px solid var(--color-border);
}

.detail-category {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--color-accent);
  background: var(--color-tag-bg);
  padding: 3px 8px;
  border-radius: 4px;
  margin-bottom: 12px;
  letter-spacing: 0.02em;
}

.detail-title {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.03em;
  margin-bottom: 4px;
  line-height: 1.3;
}

.detail-title-en {
  font-size: 14px;
  color: var(--color-text-tertiary);
  font-weight: 400;
  margin-bottom: 8px;
}

.detail-proposer {
  font-size: 12px;
  color: var(--color-text-secondary);
  margin-bottom: 12px;
}

.detail-proposer strong { color: var(--color-text); }

.detail-summary {
  font-size: 16px;
  color: var(--color-text-secondary);
  line-height: 1.6;
}

.detail-aliases {
  margin-top: 12px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.alias-tag {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 4px;
  background: rgba(255,255,255,0.05);
  color: var(--color-text-tertiary);
  border: 1px solid var(--color-border);
}

/* ===== Content Blocks ===== */
.content-block {
  margin-bottom: 32px;
}

.content-block h2 {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 14px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  gap: 8px;
}

.content-block h2::before {
  content: '';
  width: 3px;
  height: 16px;
  background: var(--color-accent-gradient);
  border-radius: 2px;
}

.content-block p {
  font-size: 14px;
  line-height: 1.8;
  color: var(--color-text);
  margin-bottom: 10px;
}

.content-block ul {
  padding-left: 20px;
  margin-bottom: 10px;
}

.content-block li {
  font-size: 14px;
  line-height: 1.7;
  margin-bottom: 6px;
  color: var(--color-text-secondary);
}

.analogy-box {
  background: var(--color-accent-glow);
  border-left: 3px solid var(--color-accent);
  padding: 14px 18px;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  font-size: 14px;
  line-height: 1.7;
}

.code-block {
  background: #0d0d14;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  overflow: hidden;
  margin-bottom: 14px;
}

.code-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 14px;
  background: rgba(255,255,255,0.03);
  border-bottom: 1px solid var(--color-border);
}

.code-lang {
  font-size: 11px;
  font-weight: 600;
  color: var(--color-accent);
  text-transform: uppercase;
}

.code-body {
  padding: 14px;
  overflow-x: auto;
}

.code-body pre {
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.6;
  color: #e4e4e7;
  margin: 0;
  white-space: pre;
}

.code-body .comment { color: #6b7280; }
.code-body .keyword { color: #c084fc; }
.code-body .string { color: #4ade80; }
.code-body .function { color: #60a5fa; }

.code-explanation {
  font-size: 13px;
  color: var(--color-text-secondary);
  line-height: 1.6;
  margin-top: 10px;
  padding: 10px 14px;
  background: var(--color-surface);
  border-radius: var(--radius-sm);
  border: 1px solid var(--color-border);
}

.misunderstanding-item {
  padding: 12px 14px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  margin-bottom: 10px;
  background: var(--color-surface);
}

.misunderstanding-item .wrong {
  color: var(--color-danger);
  font-weight: 500;
  font-size: 13px;
  margin-bottom: 3px;
}

.misunderstanding-item .wrong::before { content: "✕ "; }

.misunderstanding-item .right {
  color: var(--color-success);
  font-size: 13px;
}

.misunderstanding-item .right::before { content: "✓ "; }

/* ===== Related Concepts ===== */
.related-section {
  margin-top: 40px;
  padding-top: 24px;
  border-top: 1px solid var(--color-border);
}

.related-section h2 {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 14px;
}

.related-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.related-card {
  padding: 12px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  cursor: pointer;
  transition: all 0.15s ease;
}

.related-card:hover {
  border-color: var(--color-accent);
  box-shadow: var(--shadow-glow);
  background: var(--color-surface-hover);
}

.related-card-title {
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 3px;
}

.related-card-type {
  font-size: 10px;
  color: var(--color-text-tertiary);
}

/* ===== Search Results ===== */
.search-results {
  padding: 24px 40px;
}

.search-results h2 {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 16px;
  color: var(--color-text-secondary);
}

.search-results .result-count {
  color: var(--color-accent);
}

.search-result-item {
  padding: 14px 16px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  margin-bottom: 8px;
  cursor: pointer;
  transition: all 0.15s ease;
  background: var(--color-surface);
}

.search-result-item:hover {
  border-color: var(--color-accent);
  background: var(--color-surface-hover);
}

.search-result-item .result-title {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 4px;
}

.search-result-item .result-summary {
  font-size: 12px;
  color: var(--color-text-secondary);
  margin-bottom: 6px;
}

.search-result-item .result-meta {
  font-size: 11px;
  color: var(--color-text-tertiary);
}

/* ===== Responsive ===== */
@media (max-width: 900px) {
  .welcome-categories {
    grid-template-columns: repeat(2, 1fr);
  }
  .related-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 768px) {
  .sidebar-toggle { display: flex; }

  .sidebar {
    position: fixed;
    top: var(--header-height);
    left: 0;
    bottom: 0;
    z-index: 150;
    transform: translateX(-100%);
    box-shadow: var(--shadow-lg);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    top: var(--header-height);
    background: rgba(0,0,0,0.5);
    z-index: 140;
  }

  .sidebar-overlay.visible { display: block; }

  .header-search { width: 200px; }
  .search-dropdown {
    left: -12px;
    width: calc(100vw - 24px);
    max-width: calc(100vw - 24px);
  }
  .theme-toggle { padding: 0 10px; }
  .header-stats { display: none; }

  .detail-view { padding: 24px 20px; }
  .welcome-view { padding: 24px 20px; }
  .welcome-content h1 { font-size: 28px; }
  .welcome-stats { gap: 20px; }
  .stat-value { font-size: 22px; }
  .search-results { padding: 20px; }
}

@media (max-width: 480px) {
  .header-search { width: 140px; }
  .search-dropdown-item .sd-meta {
    gap: 6px;
  }
  .welcome-categories { grid-template-columns: 1fr 1fr; }
  .related-grid { grid-template-columns: 1fr; }
  .detail-title { font-size: 22px; }
}
