/* CSS Variables for theming */
:root {
  --primary-color: #2563eb;
  --primary-hover: #1d4ed8;
  --secondary-color: #64748b;
  --accent-color: #f59e0b;
  --success-color: #10b981;
  --warning-color: #f59e0b;
  --error-color: #ef4444;

  --bg-primary: #ffffff;
  --bg-secondary: #f8fafc;
  --bg-tertiary: #f1f5f9;
  --bg-nav: #ffffff;
  --bg-code: #1e293b;

  --text-primary: #1e293b;
  --text-secondary: #64748b;
  --text-muted: #94a3b8;
  --text-inverse: #ffffff;

  --border-color: #e2e8f0;
  --border-hover: #cbd5e1;
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1),
    0 4px 6px -4px rgb(0 0 0 / 0.1);

  --font-family-sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI",
    Roboto, sans-serif;
  --font-family-mono: "JetBrains Mono", "Fira Code", Consolas, monospace;

  --nav-width: 320px;
  --transition: all 0.2s ease-in-out;
}

/* Dark theme variables */
.dark-theme {
  --bg-primary: #0f172a;
  --bg-secondary: #1e293b;
  --bg-tertiary: #334155;
  --bg-nav: #1e293b;
  --bg-code: #0f172a;

  --text-primary: #f1f5f9;
  --text-secondary: #cbd5e1;
  --text-muted: #64748b;
  --text-inverse: #1e293b;

  --border-color: #334155;
  --border-hover: #475569;
}

/* Base styles */
* {
  box-sizing: border-box;
}

body {
  margin: 0;
  padding: 0;
  font-family: var(--font-family-sans);
  font-size: 16px;
  line-height: 1.6;
  color: var(--text-primary);
  background-color: var(--bg-primary);
  display: flex;
  transition: var(--transition);
}

/* Navigation Styles */
#navbar {
  position: fixed;
  top: 0;
  left: 0;
  width: var(--nav-width);
  height: 100vh;
  background-color: var(--bg-nav);
  border-right: 1px solid var(--border-color);
  box-shadow: var(--shadow-md);
  z-index: 1000;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* Navigation Header */
.nav-header {
  padding: 1.5rem 1.25rem 1rem;
  border-bottom: 1px solid var(--border-color);
  background: linear-gradient(
    135deg,
    var(--primary-color),
    var(--primary-hover)
  );
  color: var(--text-inverse);
}

.nav-header h1 {
  margin: 0;
  font-size: 1.5rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.nav-subtitle {
  margin: 0.25rem 0 0 0;
  font-size: 0.875rem;
  opacity: 0.9;
  font-weight: 400;
}

/* Search Container */
.search-container {
  position: relative;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border-color);
  background-color: var(--bg-secondary);
}

#search-box {
  width: 100%;
  padding: 0.75rem 2.5rem 0.75rem 1rem;
  border: 1px solid var(--border-color);
  border-radius: 0.5rem;
  background-color: var(--bg-primary);
  color: var(--text-primary);
  font-size: 0.875rem;
  font-family: var(--font-family-sans);
  transition: var(--transition);
}

#search-box:focus {
  outline: none;
  border-color: var(--primary-color);
  box-shadow: 0 0 0 3px rgb(37 99 235 / 0.1);
}

#search-box::placeholder {
  color: var(--text-muted);
}

.search-clear {
  position: absolute;
  right: 1.75rem;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.25rem;
  cursor: pointer;
  padding: 0.25rem;
  border-radius: 0.25rem;
  display: none;
  transition: var(--transition);
}

.search-clear:hover {
  color: var(--text-primary);
  background-color: var(--bg-tertiary);
}

/* Navigation List */
#navbar ul {
  flex: 1;
  margin: 0;
  padding: 0;
  list-style: none;
  overflow-y: auto;
  overflow-x: hidden;
}

#navbar ul::-webkit-scrollbar {
  width: 4px;
}

#navbar ul::-webkit-scrollbar-track {
  background: var(--bg-secondary);
}

#navbar ul::-webkit-scrollbar-thumb {
  background: var(--border-color);
  border-radius: 2px;
}

#navbar ul::-webkit-scrollbar-thumb:hover {
  background: var(--border-hover);
}

#navbar li {
  list-style: none;
  margin: 0;
  border-bottom: 1px solid var(--border-color);
}

#navbar li:last-child {
  border-bottom: none;
}

/* Navigation Links */
.nav-link {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 1rem 1.25rem;
  color: var(--text-primary);
  text-decoration: none;
  font-weight: 500;
  font-size: 0.875rem;
  transition: var(--transition);
  position: relative;
}

.nav-link:hover {
  background-color: var(--bg-secondary);
  color: var(--primary-color);
  transform: translateX(2px);
}

.nav-link.active {
  background-color: var(--primary-color);
  color: var(--text-inverse);
  font-weight: 600;
}

.nav-link.active::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 3px;
  background-color: var(--accent-color);
}

.nav-icon {
  font-size: 1rem;
  min-width: 1.25rem;
  text-align: center;
}

/* Theme Toggle Button */
.theme-toggle {
  position: fixed;
  top: 1rem;
  right: 1rem;
  width: 3rem;
  height: 3rem;
  border: none;
  border-radius: 50%;
  background-color: var(--bg-secondary);
  color: var(--text-primary);
  font-size: 1.25rem;
  cursor: pointer;
  box-shadow: var(--shadow-md);
  transition: var(--transition);
  z-index: 1001;
  display: flex;
  align-items: center;
  justify-content: center;
}

.theme-toggle:hover {
  background-color: var(--bg-tertiary);
  transform: scale(1.05);
}

/* Back to Top Button */
.back-to-top {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  width: 3rem;
  height: 3rem;
  border: none;
  border-radius: 50%;
  background-color: var(--primary-color);
  color: var(--text-inverse);
  font-size: 1.25rem;
  font-weight: bold;
  cursor: pointer;
  box-shadow: var(--shadow-lg);
  transition: var(--transition);
  z-index: 1001;
  display: none;
}

.back-to-top:hover {
  background-color: var(--primary-hover);
  transform: translateY(-2px);
}

/* Main Content */
#main-doc {
  margin-left: var(--nav-width);
  padding: 2rem;
  width: calc(100% - var(--nav-width));
  min-height: 100vh;
  background-color: var(--bg-primary);
}
/* Hero Section */
.hero-section {
  background: linear-gradient(
    135deg,
    var(--primary-color),
    var(--primary-hover)
  );
  color: var(--text-inverse);
  padding: 4rem 2rem;
  margin: -2rem -2rem 3rem -2rem;
  border-radius: 0 0 1rem 1rem;
}

.hero-content {
  max-width: 800px;
  margin: 0 auto;
  text-align: center;
}

.hero-title {
  font-size: 3rem;
  font-weight: 800;
  margin: 0 0 1rem 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
}

.hero-emoji {
  font-size: 3.5rem;
}

.hero-description {
  font-size: 1.25rem;
  margin: 0 0 2rem 0;
  opacity: 0.9;
  line-height: 1.7;
}

.hero-stats {
  display: flex;
  justify-content: center;
  gap: 2rem;
  margin-top: 2rem;
}

.stat {
  text-align: center;
}

.stat-number {
  display: block;
  font-size: 2rem;
  font-weight: 700;
  color: var(--accent-color);
}

.stat-label {
  font-size: 0.875rem;
  opacity: 0.8;
}

/* Section Styles */
.main-section {
  margin-bottom: 4rem;
  scroll-margin-top: 2rem;
}

.main-section header {
  margin-bottom: 2rem;
}

.main-section h2 {
  font-size: 2.25rem;
  font-weight: 700;
  margin: 0 0 0.5rem 0;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.section-meta {
  display: flex;
  gap: 1rem;
  margin-top: 0.5rem;
}

.reading-time,
.difficulty {
  font-size: 0.875rem;
  color: var(--text-secondary);
  background-color: var(--bg-secondary);
  padding: 0.25rem 0.75rem;
  border-radius: 1rem;
  font-weight: 500;
}

.content-wrapper {
  max-width: none;
}

.lead-paragraph {
  font-size: 1.125rem;
  line-height: 1.8;
  color: var(--text-secondary);
  margin-bottom: 2rem;
}

/* Code Styles */
.code-example {
  position: relative;
  margin: 1.5rem 0;
  border-radius: 0.75rem;
  overflow: hidden;
  box-shadow: var(--shadow-md);
}

.code-example pre {
  margin: 0;
  padding: 1.5rem;
  background-color: var(--bg-code) !important;
  overflow-x: auto;
  font-family: var(--font-family-mono);
  font-size: 0.875rem;
  line-height: 1.6;
}

.code-example.mini {
  margin: 1rem 0;
}

.code-example.mini pre {
  padding: 1rem;
  font-size: 0.8rem;
}

.code-example.small {
  margin: 1rem 0;
}

.code-example.small pre {
  padding: 1.25rem;
  font-size: 0.8rem;
}

.code-example.error {
  border-left: 4px solid var(--error-color);
}

.inline-code {
  background-color: var(--bg-secondary);
  color: var(--primary-color);
  padding: 0.125rem 0.375rem;
  border-radius: 0.25rem;
  font-family: var(--font-family-mono);
  font-size: 0.875em;
  font-weight: 600;
}

.copy-btn {
  position: absolute;
  top: 1rem;
  right: 1rem;
  background-color: var(--bg-secondary);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
  padding: 0.5rem 1rem;
  border-radius: 0.375rem;
  font-size: 0.75rem;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
  opacity: 0.8;
}

.copy-btn:hover {
  background-color: var(--bg-tertiary);
  opacity: 1;
}

/* Box Styles */
.highlight-box {
  background-color: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 0.75rem;
  padding: 1.5rem;
  margin: 2rem 0;
}

.highlight-box.info {
  background-color: rgb(59 130 246 / 0.05);
  border-color: rgb(59 130 246 / 0.2);
}

.warning-box {
  background-color: rgb(245 158 11 / 0.05);
  border: 1px solid rgb(245 158 11 / 0.2);
  border-left: 4px solid var(--warning-color);
  border-radius: 0.75rem;
  padding: 1.5rem;
  margin: 2rem 0;
}

.info-box {
  background-color: rgb(59 130 246 / 0.05);
  border: 1px solid rgb(59 130 246 / 0.2);
  border-left: 4px solid var(--primary-color);
  border-radius: 0.75rem;
  padding: 1.5rem;
  margin: 2rem 0;
}

.best-practices-box {
  background-color: rgb(16 185 129 / 0.05);
  border: 1px solid rgb(16 185 129 / 0.2);
  border-left: 4px solid var(--success-color);
  border-radius: 0.75rem;
  padding: 1.5rem;
  margin: 2rem 0;
}

/* Grid Layouts */
.two-column-layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2rem;
  margin: 2rem 0;
}

.column h4 {
  color: var(--text-primary);
  margin-top: 0;
}

.data-types-grid {
  display: grid;
  gap: 2rem;
  margin: 2rem 0;
}

.data-type-card {
  background-color: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 0.75rem;
  padding: 1.5rem;
}

.data-type-card h3 {
  margin-top: 0;
  color: var(--text-primary);
}

.type-list {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.type-item {
  display: flex;
  gap: 1rem;
  align-items: flex-start;
}

.type-icon {
  font-size: 1.25rem;
  min-width: 2rem;
  text-align: center;
}

.type-item strong {
  color: var(--primary-color);
  font-weight: 600;
}

.type-item p {
  margin: 0.25rem 0 0.75rem 0;
  color: var(--text-secondary);
  font-size: 0.875rem;
}

/* Tables */
.comparison-table {
  margin: 2rem 0;
}

.comparison-table table {
  width: 100%;
  border-collapse: collapse;
  background-color: var(--bg-secondary);
  border-radius: 0.75rem;
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

.comparison-table th,
.comparison-table td {
  padding: 1rem;
  text-align: left;
  border-bottom: 1px solid var(--border-color);
}

.comparison-table th {
  background-color: var(--bg-tertiary);
  font-weight: 600;
  color: var(--text-primary);
}

.comparison-table td {
  color: var(--text-secondary);
}

.comparison-table tr:last-child td {
  border-bottom: none;
}

/* Responsive Design */
@media (max-width: 1024px) {
  :root {
    --nav-width: 280px;
  }

  .hero-title {
    font-size: 2.5rem;
  }

  .hero-stats {
    gap: 1.5rem;
  }

  .two-column-layout {
    grid-template-columns: 1fr;
    gap: 1.5rem;
  }
}

@media (max-width: 768px) {
  body {
    flex-direction: column;
  }

  #navbar {
    position: relative;
    width: 100%;
    height: auto;
    border-right: none;
    border-bottom: 1px solid var(--border-color);
  }

  #main-doc {
    margin-left: 0;
    padding: 1rem;
    width: 100%;
  }

  .nav-header {
    padding: 1rem;
  }

  .nav-header h1 {
    font-size: 1.25rem;
  }

  .search-container {
    padding: 0.75rem 1rem;
  }

  #navbar ul {
    max-height: 300px;
  }

  .nav-link {
    padding: 0.75rem 1rem;
    font-size: 0.8rem;
  }

  .theme-toggle,
  .back-to-top {
    width: 2.5rem;
    height: 2.5rem;
    font-size: 1rem;
  }

  .theme-toggle {
    top: 0.5rem;
    right: 0.5rem;
  }

  .back-to-top {
    bottom: 1rem;
    right: 1rem;
  }

  .hero-section {
    padding: 2rem 1rem;
    margin: -1rem -1rem 2rem -1rem;
  }

  .hero-title {
    font-size: 2rem;
    flex-direction: column;
    gap: 0.5rem;
  }

  .hero-emoji {
    font-size: 2.5rem;
  }

  .hero-description {
    font-size: 1rem;
  }

  .hero-stats {
    flex-direction: column;
    gap: 1rem;
  }

  .main-section h2 {
    font-size: 1.75rem;
  }

  .section-meta {
    flex-direction: column;
    gap: 0.5rem;
  }

  .code-example pre {
    padding: 1rem;
    font-size: 0.75rem;
  }

  .copy-btn {
    position: static;
    margin-top: 0.5rem;
    width: 100%;
  }

  .comparison-table {
    overflow-x: auto;
  }

  .comparison-table table {
    min-width: 500px;
  }
}

/* Additional Component Styles */

/* Rules Grid */
.rules-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 1.5rem;
  margin: 1.5rem 0;
}

.rule-item {
  display: flex;
  gap: 1rem;
  align-items: flex-start;
  background-color: var(--bg-primary);
  padding: 1rem;
  border-radius: 0.5rem;
  border: 1px solid var(--border-color);
}

.rule-icon {
  font-size: 1.25rem;
  min-width: 2rem;
  text-align: center;
}

.rule-item strong {
  color: var(--text-primary);
  font-weight: 600;
}

.rule-item ul {
  margin: 0.5rem 0 0 0;
  padding-left: 1.25rem;
}

.rule-item li {
  color: var(--text-secondary);
  font-size: 0.875rem;
  margin: 0.25rem 0;
}

/* Practices Grid */
.practices-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 2rem;
  margin: 2rem 0;
}

.practice {
  background-color: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: 0.75rem;
  padding: 1.5rem;
}

.practice h4 {
  margin-top: 0;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.practice-category {
  background-color: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: 0.75rem;
  padding: 1.5rem;
}

.practice-category h3 {
  margin-top: 0;
  color: var(--text-primary);
}

/* Practices List */
.practices-list {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  margin: 1.5rem 0;
}

.practice-item {
  display: flex;
  gap: 1rem;
  align-items: flex-start;
  background-color: var(--bg-primary);
  padding: 1rem;
  border-radius: 0.5rem;
  border: 1px solid var(--border-color);
}

.practice-icon {
  font-size: 1.5rem;
  min-width: 2rem;
  text-align: center;
}

.practice-item strong {
  color: var(--text-primary);
  font-weight: 600;
  display: block;
  margin-bottom: 0.25rem;
}

.practice-item p {
  margin: 0;
  color: var(--text-secondary);
  font-size: 0.875rem;
}

/* Declaration Methods */
.declaration-methods {
  display: grid;
  gap: 2rem;
  margin: 2rem 0;
}

.method-card {
  background-color: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 0.75rem;
  padding: 1.5rem;
}

.method-card h3 {
  margin-top: 0;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.method-card p {
  color: var(--text-secondary);
  margin-bottom: 1rem;
}

/* Rules Section */
.rules-section {
  margin: 2rem 0;
}

.rule-card {
  background-color: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: 0.5rem;
  padding: 1rem;
}

.rule-card h4 {
  margin: 0.5rem 0;
  color: var(--text-primary);
  font-size: 0.875rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* Advantages Grid */
.advantages-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2rem;
  margin: 2rem 0;
}

.advantage-card {
  background-color: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 0.75rem;
  padding: 1.5rem;
}

.advantage-card h4 {
  margin-top: 0;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.advantage-card ul {
  margin: 1rem 0 0 0;
  padding-left: 1.25rem;
}

.advantage-card li {
  color: var(--text-secondary);
  margin: 0.5rem 0;
}

/* Function Types */
.function-types {
  margin: 2rem 0;
}

.function-type {
  margin: 2rem 0;
}

.function-type h4 {
  color: var(--text-primary);
  margin-bottom: 1rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* Feature List */
.feature-list {
  list-style: none;
  padding: 0;
  margin: 1rem 0;
}

.feature-list li {
  padding: 0.5rem 0;
  color: var(--text-secondary);
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
}

/* Type Checking Section */
.type-checking-section {
  margin: 2rem 0;
}

.type-checking-section h3 {
  color: var(--text-primary);
  margin-bottom: 1rem;
}

/* Scope Example */
.scope-example {
  margin: 2rem 0;
}

.scope-comparison {
  margin: 2rem 0;
}

.scope-example h3,
.scope-comparison h3 {
  color: var(--text-primary);
  margin-bottom: 1rem;
}

/* Function Features */
.function-features {
  margin: 2rem 0;
}

.function-features h3 {
  color: var(--text-primary);
  margin-bottom: 1rem;
}

/* Responsive adjustments for new components */
@media (max-width: 768px) {
  .rules-grid {
    grid-template-columns: 1fr;
    gap: 1rem;
  }

  .practices-grid {
    grid-template-columns: 1fr;
    gap: 1.5rem;
  }

  .advantages-grid {
    grid-template-columns: 1fr;
    gap: 1.5rem;
  }

  .rule-item,
  .practice-item {
    padding: 0.75rem;
  }

  .practice,
  .practice-category,
  .method-card,
  .advantage-card {
    padding: 1rem;
  }

  .hero-stats {
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: center;
  }

  .stat {
    min-width: 80px;
  }
}

/* Print styles */
@media print {
  .theme-toggle,
  .back-to-top,
  .search-container,
  .copy-btn {
    display: none !important;
  }

  #navbar {
    position: static;
    width: 100%;
    height: auto;
    border-right: none;
    box-shadow: none;
  }

  #main-doc {
    margin-left: 0;
    width: 100%;
  }

  .hero-section {
    background: none !important;
    color: var(--text-primary) !important;
  }

  .code-example pre {
    background-color: #f8f9fa !important;
    color: #333 !important;
    border: 1px solid #ddd;
  }
}
