:root {
  /* Design Tokens - Light Mode (Default) */
  --bg-body: #ffffff;
  --bg-sidebar: #f7f9fc;
  --bg-header: rgba(255, 255, 255, 0.85);
  --bg-card: #ffffff;
  --bg-code: #f1f3f5;
  --border-color: #e2e8f0;
  
  --text-primary: #1a202c;
  --text-secondary: #4a5568;
  --text-muted: #718096;
  
  --accent-color: #3b82f6;
  --accent-hover: #2563eb;
  
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
  
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
}

[data-theme="dark"] {
  /* Design Tokens - Dark Mode */
  --bg-body: #0f1115;
  --bg-sidebar: #161b22;
  --bg-header: rgba(22, 27, 34, 0.85);
  --bg-card: #161b22;
  --bg-code: #21262d;
  --border-color: #30363d;
  
  --text-primary: #f0f6fc;
  --text-secondary: #c9d1d9;
  --text-muted: #8b949e;
  
  --accent-color: #58a6ff;
  --accent-hover: #79c0ff;
  
  --shadow-sm: none;
  --shadow-md: none;
}

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

html {
  scroll-behavior: smooth;
  scroll-padding-top: 80px; /* Offset for sticky header */
}

body {
  font-family: var(--font-sans);
  background-color: var(--bg-body);
  color: var(--text-primary);
  line-height: 1.6;
  transition: background-color 0.3s ease, color 0.3s ease;
  overflow-x: hidden;
}

a {
  color: var(--accent-color);
  text-decoration: none;
  transition: color 0.2s;
}

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

/* --- Layout Grid --- */
.app-container {
  display: grid;
  grid-template-areas:
    "header header header"
    "sidebar main toc"
    "sidebar footer toc";
  grid-template-columns: 280px 1fr 240px;
  grid-template-rows: auto 1fr auto;
  min-height: 100vh;
}

/* --- Header --- */
.site-header {
  grid-area: header;
  position: sticky;
  top: 0;
  z-index: 50;
  background-color: var(--bg-header);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1.5rem;
  height: 64px;
}

.logo {
  font-weight: 700;
  font-size: 1.25rem;
  color: var(--text-primary);
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.logo span {
  color: var(--accent-color);
}

.header-controls {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.theme-toggle {
  background: none;
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  padding: 0.4rem;
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.theme-toggle:hover {
  background-color: var(--bg-code);
  color: var(--text-primary);
}

/* Mobile Menu Button */
.menu-toggle {
  display: none;
  background: none;
  border: none;
  color: var(--text-primary);
  font-size: 1.5rem;
  cursor: pointer;
}

/* --- Sidebar --- */
.site-sidebar {
  grid-area: sidebar;
  background-color: var(--bg-sidebar);
  border-right: 1px solid var(--border-color);
  padding: 2rem 1rem;
  position: sticky;
  top: 64px;
  height: calc(100vh - 64px);
  overflow-y: auto;
}

.nav-section {
  margin-bottom: 2rem;
}

.nav-title {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  font-weight: 600;
  margin-bottom: 0.75rem;
  padding-left: 0.75rem;
}

.nav-links {
  list-style: none;
}

.nav-link {
  display: block;
  padding: 0.5rem 0.75rem;
  color: var(--text-secondary);
  font-size: 0.95rem;
  border-radius: 6px;
  text-decoration: none;
  margin-bottom: 2px;
}

.nav-link:hover {
  background-color: var(--bg-code);
  color: var(--text-primary);
  text-decoration: none;
}

.nav-link.active {
  background-color: rgba(59, 130, 246, 0.1);
  color: var(--accent-color);
  font-weight: 500;
}

/* --- SPA Views --- */
.page-view {
  display: none;
}

.page-view.active {
  display: block;
  animation: fadeIn 0.3s ease-in-out;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* --- Main Content --- */
.site-main {
  grid-area: main;
  padding: 3rem 4rem;
  max-width: 900px;
  width: 100%;
}

.content-header {
  margin-bottom: 3rem;
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 1.5rem;
}

.page-title {
  font-size: 2.25rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
  letter-spacing: -0.02em;
}

.page-description {
  font-size: 1.125rem;
  color: var(--text-secondary);
}

/* Typography Content */
h2 {
  font-size: 1.5rem;
  margin-top: 2.5rem;
  margin-bottom: 1rem;
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 0.5rem;
}

h3 {
  font-size: 1.25rem;
  margin-top: 2rem;
  margin-bottom: 0.75rem;
}

p {
  margin-bottom: 1.25rem;
  color: var(--text-secondary);
}

ul, ol {
  margin-bottom: 1.5rem;
  padding-left: 1.5rem;
  color: var(--text-secondary);
}

li {
  margin-bottom: 0.5rem;
}

code {
  font-family: var(--font-mono);
  background-color: var(--bg-code);
  padding: 0.2rem 0.4rem;
  border-radius: 4px;
  font-size: 0.85em;
  color: var(--text-primary);
}

pre {
  background-color: var(--bg-code);
  padding: 1.25rem;
  border-radius: 8px;
  overflow-x: auto;
  margin-bottom: 1.5rem;
  border: 1px solid var(--border-color);
}

pre code {
  background: none;
  padding: 0;
  color: var(--text-primary);
  font-size: 0.9em;
}

blockquote {
  border-left: 4px solid var(--accent-color);
  margin-left: 0;
  margin-bottom: 1.5rem;
  font-style: italic;
  color: var(--text-secondary);
  background-color: var(--bg-sidebar);
  padding: 1rem 1rem 1rem 1.25rem;
  border-radius: 0 4px 4px 0;
}

/* --- Updates Page Specifics --- */
.update-card h2 {
  border-bottom: none;
  margin-top: 0;
  padding-bottom: 0;
  font-size: 1.25rem;
}

.update-card {
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 1.5rem;
  margin-bottom: 2rem;
  background-color: var(--bg-card);
  box-shadow: var(--shadow-sm);
}

.update-card img {
  width: 100%;
  border-radius: 6px;
  border: 1px solid var(--border-color);
  margin-bottom: 1.25rem;
}

.update-meta {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.update-date {
  font-size: 0.85rem;
  color: var(--text-muted);
  font-family: var(--font-mono);
}

.tag {
  font-size: 0.75rem;
  padding: 0.2rem 0.5rem;
  border-radius: 12px;
  font-weight: 600;
  text-transform: uppercase;
}

.tag.new { background-color: rgba(16, 185, 129, 0.1); color: #10b981; }
.tag.fix { background-color: rgba(239, 68, 68, 0.1); color: #ef4444; }
.tag.improvement { background-color: rgba(59, 130, 246, 0.1); color: #3b82f6; }
.tag.testing {
  background-color: rgba(168, 85, 247, 0.1);
  color: #a855f7;
  animation: blink 1.5s ease-in-out infinite;
}

@keyframes blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

/* --- Roadmap --- */
.roadmap-empty {
  border: 1px dashed var(--border-color);
  border-radius: 8px;
  padding: 2rem;
  text-align: center;
  color: var(--text-muted);
}

.roadmap-empty p {
  margin: 0;
  color: var(--text-muted);
}

/* --- Table of Contents (Right Sidebar) --- */
.site-toc {
  grid-area: toc;
  padding: 3rem 1.5rem 2rem 0;
  position: sticky;
  top: 64px;
  height: calc(100vh - 64px);
  overflow-y: auto;
  font-size: 0.85rem;
}

.toc-header {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  font-weight: 600;
  margin-bottom: 0.75rem;
  margin-top: 0.5rem;
}

.toc-list {
  list-style: none;
  padding: 0;
  border-left: 2px solid var(--border-color);
}

.toc-item {
  margin: 0;
}

.toc-link {
  display: block;
  padding: 0.4rem 1rem;
  color: var(--text-secondary);
  text-decoration: none;
  line-height: 1.4;
  border-left: 2px solid transparent;
  margin-left: -2px; /* Overlap border */
  transition: all 0.2s;
}

.toc-link:hover {
  color: var(--text-primary);
  text-decoration: none;
}

.toc-link.active {
  color: var(--accent-color);
  border-left-color: var(--accent-color);
  font-weight: 500;
}

/* Indent H3s */
.toc-item.h3-link .toc-link {
  padding-left: 1.5rem;
  font-size: 0.95em;
}


/* --- Footer --- */
.site-footer {
  grid-area: footer;
  margin-top: 0;
  padding: 2rem 4rem;
  border-top: 1px solid var(--border-color);
  text-align: center;
  color: var(--text-muted);
  font-size: 0.875rem;
}

/* --- Responsive Design --- */
@media (max-width: 1100px) {
  /* Tablet / Small Desktop: Hide TOC */
  .app-container {
    grid-template-columns: 260px 1fr;
    grid-template-areas:
      "header header"
      "sidebar main"
      "sidebar footer";
  }
  
  .site-toc {
    display: none;
  }
  
  .site-main {
    padding: 3rem 2rem;
  }
}

@media (max-width: 768px) {
  .app-container {
    grid-template-columns: 1fr;
    grid-template-areas:
      "header"
      "main"
      "footer";
  }

  .site-sidebar {
    position: fixed;
    left: -100%; /* Hidden by default */
    top: 64px;
    bottom: 0;
    width: 250px;
    z-index: 100;
    transition: left 0.3s ease;
    box-shadow: 2px 0 10px rgba(0,0,0,0.1);
  }

  .site-sidebar.open {
    left: 0;
  }

  .menu-toggle {
    display: block;
    margin-right: 1rem;
  }

  .site-main {
    padding: 2rem 1.5rem;
  }
}