/* Reset & Base */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --zinc-50: #fafafa;
  --zinc-100: #f4f4f5;
  --zinc-200: #e4e4e7;
  --zinc-300: #d4d4d8;
  --zinc-400: #a1a1aa;
  --zinc-500: #71717a;
  --zinc-600: #52525b;
  --zinc-700: #3f3f46;
  --zinc-800: #27272a;
  --zinc-900: #18181b;
  --zinc-950: #09090b;
  --emerald-600: #059669;
  --emerald-700: #047857;
  --sidebar-width: 240px;
  --header-height: 64px;
  --content-max-width: 780px;
}

html {
  scroll-behavior: smooth;
  scroll-padding-top: calc(var(--header-height) + 24px);
}

body {
  font-family: 'Geist', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 16px;
  line-height: 1.6;
  color: var(--zinc-900);
  background: var(--zinc-50);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Header */
.header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(250, 250, 250, 0.85);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--zinc-200);
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--header-height);
  padding: 0 24px;
  max-width: 1400px;
  margin: 0 auto;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--zinc-950);
  font-weight: 600;
  font-size: 1.1rem;
  letter-spacing: -0.02em;
}

.logo svg {
  color: var(--emerald-600);
}

/* Search */
.search-container {
  position: relative;
  width: 280px;
}

.search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--zinc-400);
  pointer-events: none;
}

.search-input {
  width: 100%;
  height: 40px;
  padding: 0 36px;
  border: 1px solid var(--zinc-200);
  border-radius: 8px;
  background: white;
  font-family: inherit;
  font-size: 0.875rem;
  color: var(--zinc-900);
  transition: border-color 0.2s, box-shadow 0.2s;
}

.search-input:focus {
  outline: none;
  border-color: var(--emerald-600);
  box-shadow: 0 0 0 3px rgba(5, 150, 105, 0.1);
}

.search-input::placeholder {
  color: var(--zinc-400);
}

.search-clear {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  display: none;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border: none;
  background: none;
  color: var(--zinc-400);
  cursor: pointer;
  border-radius: 4px;
}

.search-clear:hover {
  color: var(--zinc-600);
  background: var(--zinc-100);
}

.search-clear.visible {
  display: flex;
}

/* Layout */
.layout {
  display: flex;
  max-width: 1400px;
  margin: 0 auto;
  min-height: calc(100vh - var(--header-height));
}

/* Sidebar */
.sidebar {
  width: var(--sidebar-width);
  flex-shrink: 0;
  position: sticky;
  top: var(--header-height);
  height: calc(100vh - var(--header-height));
  overflow-y: auto;
  padding: 24px 0 24px 24px;
  border-right: 1px solid var(--zinc-100);
}

.toc {
  font-size: 0.875rem;
}

.toc-section {
  margin-bottom: 24px;
}

.toc-section-title {
  font-weight: 600;
  color: var(--zinc-950);
  margin-bottom: 8px;
  letter-spacing: -0.01em;
}

.toc-list {
  list-style: none;
}

.toc-item {
  margin: 2px 0;
}

.toc-link {
  display: block;
  padding: 4px 8px;
  color: var(--zinc-500);
  text-decoration: none;
  border-radius: 6px;
  transition: color 0.15s, background 0.15s;
}

.toc-link:hover {
  color: var(--zinc-900);
  background: var(--zinc-100);
}

.toc-link.active {
  color: var(--emerald-700);
  background: rgba(5, 150, 105, 0.08);
  font-weight: 500;
}

/* Main */
.main {
  flex: 1;
  min-width: 0;
  padding: 32px 48px;
}

.content {
  max-width: var(--content-max-width);
  margin: 0 auto;
}

/* Sections */
.section {
  margin-bottom: 48px;
}

.section-title {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--zinc-950);
  letter-spacing: -0.03em;
  margin-bottom: 24px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--zinc-200);
}

/* Term Cards */
.term-card {
  margin-bottom: 24px;
  padding: 20px;
  background: white;
  border: 1px solid var(--zinc-200);
  border-radius: 12px;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.term-card:hover {
  border-color: var(--zinc-300);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
}

.term-header {
  display: flex;
  align-items: baseline;
  gap: 12px;
  margin-bottom: 8px;
}

.term-name {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--zinc-950);
  letter-spacing: -0.01em;
}

.term-definition {
  font-size: 0.95rem;
  color: var(--zinc-600);
  line-height: 1.5;
}

.term-content {
  display: none;
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--zinc-100);
  font-size: 0.9rem;
  color: var(--zinc-700);
  line-height: 1.7;
  white-space: pre-wrap;
}

.term-card.expanded .term-content {
  display: block;
}

/* Content formatting */
.term-content p {
  margin-bottom: 12px;
  line-height: 1.7;
}

.term-content p:last-child {
  margin-bottom: 0;
}

.term-content ul, .term-content ol {
  margin: 12px 0;
  padding-left: 24px;
}

.term-content li {
  margin-bottom: 6px;
  line-height: 1.6;
}

.term-content strong {
  font-weight: 600;
  color: var(--zinc-900);
}

.term-content em {
  font-style: italic;
  color: var(--zinc-600);
}

.term-content code {
  background: var(--zinc-100);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.9em;
  font-family: 'JetBrains Mono', monospace;
}

.term-content table {
  width: 100%;
  margin: 16px 0;
  border-collapse: collapse;
  font-size: 0.875rem;
}

.term-content td {
  padding: 8px 12px;
  border: 1px solid var(--zinc-200);
  text-align: left;
}

.term-content tr:nth-child(even) {
  background: var(--zinc-50);
}

.term-content a {
  color: var(--emerald-600);
  text-decoration: none;
}

.term-content a:hover {
  text-decoration: underline;
}

.term-toggle {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-top: 12px;
  font-size: 0.8rem;
  color: var(--emerald-600);
  background: none;
  border: none;
  cursor: pointer;
  font-family: inherit;
  font-weight: 500;
}

.term-toggle:hover {
  color: var(--emerald-700);
}

.term-toggle svg {
  transition: transform 0.2s;
}

.term-card.expanded .term-toggle svg {
  transform: rotate(180deg);
}

/* Search Results */
.search-results {
  display: none;
}

.search-results.active {
  display: block;
}

.search-result-item {
  padding: 12px 16px;
  background: white;
  border: 1px solid var(--zinc-200);
  border-radius: 8px;
  margin-bottom: 8px;
  cursor: pointer;
  transition: border-color 0.15s;
}

.search-result-item:hover {
  border-color: var(--emerald-600);
}

.search-result-term {
  font-weight: 600;
  color: var(--zinc-950);
  margin-bottom: 4px;
}

.search-result-definition {
  font-size: 0.875rem;
  color: var(--zinc-500);
}

.search-result-highlight {
  background: rgba(5, 150, 105, 0.15);
  padding: 0 2px;
  border-radius: 2px;
}

.search-no-results {
  text-align: center;
  padding: 32px;
  color: var(--zinc-500);
  font-size: 0.9rem;
}

/* Loading */
.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 48px;
  color: var(--zinc-500);
}

.skeleton {
  background: linear-gradient(90deg, var(--zinc-100) 25%, var(--zinc-200) 50%, var(--zinc-100) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: 8px;
}

@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* Mobile Menu Button */
.mobile-menu-btn {
  display: none;
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--zinc-950);
  color: white;
  border: none;
  cursor: pointer;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  z-index: 200;
  transition: transform 0.2s;
}

.mobile-menu-btn:hover {
  transform: scale(1.05);
}

/* Mobile Responsive */
@media (max-width: 768px) {
  .header-inner {
    padding: 0 16px;
  }

  .logo-text {
    display: none;
  }

  .search-container {
    width: 100%;
  }

  .sidebar {
    position: fixed;
    top: var(--header-height);
    left: 0;
    width: 280px;
    height: calc(100vh - var(--header-height));
    background: white;
    border-right: 1px solid var(--zinc-200);
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    z-index: 150;
    padding: 16px;
  }

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

  .sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    top: var(--header-height);
    background: rgba(0, 0, 0, 0.3);
    z-index: 140;
  }

  .sidebar-overlay.active {
    display: block;
  }

  .main {
    padding: 24px 16px;
  }

  .mobile-menu-btn {
    display: flex;
  }

  .section-title {
    font-size: 1.25rem;
  }

  .term-card {
    padding: 16px;
  }
}

/* Scrollbar */
.sidebar::-webkit-scrollbar {
  width: 4px;
}

.sidebar::-webkit-scrollbar-track {
  background: transparent;
}

.sidebar::-webkit-scrollbar-thumb {
  background: var(--zinc-200);
  border-radius: 2px;
}

.sidebar::-webkit-scrollbar-thumb:hover {
  background: var(--zinc-300);
}
