/* ============================================================
   TinyLang Documentation - Shared Stylesheet
   Professional, responsive, with dark mode support
   ============================================================ */

/* CSS Custom Properties */
:root {
  --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --font-mono: 'SF Mono', 'Fira Code', 'JetBrains Mono', 'Cascadia Code', Consolas, monospace;

  /* Light mode colors */
  --bg-primary: #ffffff;
  --bg-secondary: #f8f9fb;
  --bg-tertiary: #f0f2f5;
  --bg-code: #f5f7fa;
  --bg-sidebar: #fbfbfd;
  --bg-hero: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  --bg-card: #ffffff;
  --bg-card-hover: #f8f9fb;
  --bg-inline-code: #eef1f6;

  --text-primary: #1a1f36;
  --text-secondary: #4a5568;
  --text-tertiary: #718096;
  --text-link: #5b6abf;
  --text-link-hover: #4c51bf;
  --text-inverse: #ffffff;
  --text-code: #1a1f36;

  --border-color: #e2e8f0;
  --border-active: #667eea;

  --accent-primary: #667eea;
  --accent-secondary: #764ba2;
  --accent-gradient: linear-gradient(135deg, #667eea 0%, #764ba2 100%);

  /* Syntax highlighting - light */
  --syn-keyword: #7c3aed;
  --syn-string: #059669;
  --syn-number: #d97706;
  --syn-comment: #6b7280;
  --syn-function: #2563eb;
  --syn-class: #dc2626;
  --syn-operator: #374151;
  --syn-punctuation: #6b7280;
  --syn-builtin: #0891b2;
  --syn-property: #b45309;

  /* Spacing */
  --sidebar-width: 280px;
  --content-max-width: 860px;
  --header-height: 60px;

  /* Shadows */
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.07);
  --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.1);

  /* Border radius */
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;
}

/* Dark mode */
[data-theme="dark"] {
  --bg-primary: #0f1219;
  --bg-secondary: #1a1f2e;
  --bg-tertiary: #242b3d;
  --bg-code: #1e2433;
  --bg-sidebar: #131824;
  --bg-card: #1a1f2e;
  --bg-card-hover: #242b3d;
  --bg-inline-code: #242b3d;

  --text-primary: #e2e8f0;
  --text-secondary: #a0aec0;
  --text-tertiary: #718096;
  --text-link: #93a8f4;
  --text-link-hover: #b3c5ff;
  --text-code: #e2e8f0;

  --border-color: #2d3748;
  --border-active: #667eea;

  /* Syntax highlighting - dark */
  --syn-keyword: #c084fc;
  --syn-string: #6ee7b7;
  --syn-number: #fbbf24;
  --syn-comment: #6b7280;
  --syn-function: #93bbfd;
  --syn-class: #fca5a5;
  --syn-operator: #e2e8f0;
  --syn-punctuation: #9ca3af;
  --syn-builtin: #67e8f9;
  --syn-property: #fcd34d;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.5);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg-primary: #0f1219;
    --bg-secondary: #1a1f2e;
    --bg-tertiary: #242b3d;
    --bg-code: #1e2433;
    --bg-sidebar: #131824;
    --bg-card: #1a1f2e;
    --bg-card-hover: #242b3d;
    --bg-inline-code: #242b3d;

    --text-primary: #e2e8f0;
    --text-secondary: #a0aec0;
    --text-tertiary: #718096;
    --text-link: #93a8f4;
    --text-link-hover: #b3c5ff;
    --text-code: #e2e8f0;

    --border-color: #2d3748;
    --border-active: #667eea;

    --syn-keyword: #c084fc;
    --syn-string: #6ee7b7;
    --syn-number: #fbbf24;
    --syn-comment: #6b7280;
    --syn-function: #93bbfd;
    --syn-class: #fca5a5;
    --syn-operator: #e2e8f0;
    --syn-punctuation: #9ca3af;
    --syn-builtin: #67e8f9;
    --syn-property: #fcd34d;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.5);
  }
}

/* ============ Reset & Base ============ */

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

html {
  font-size: 16px;
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font-sans);
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.7;
  min-height: 100vh;
}

/* ============ Layout ============ */

.layout {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  width: var(--sidebar-width);
  height: 100vh;
  overflow-y: auto;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border-color);
  padding: 24px 0;
  z-index: 100;
  transition: transform 0.3s ease;
}

.sidebar-header {
  padding: 0 24px 20px;
  border-bottom: 1px solid var(--border-color);
  margin-bottom: 16px;
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--text-primary);
}

.sidebar-logo svg {
  width: 32px;
  height: 32px;
}

.sidebar-logo-text {
  font-size: 1.2rem;
  font-weight: 700;
  background: var(--accent-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.sidebar-version {
  font-size: 0.75rem;
  color: var(--text-tertiary);
  margin-top: 2px;
}

.sidebar-nav {
  padding: 0 12px;
}

.sidebar-section {
  margin-bottom: 8px;
}

.sidebar-section-title {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-tertiary);
  padding: 8px 12px 4px;
}

.sidebar-link {
  display: block;
  padding: 7px 12px;
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 0.9rem;
  border-radius: var(--radius-sm);
  transition: all 0.15s ease;
}

.sidebar-link:hover {
  color: var(--text-primary);
  background: var(--bg-tertiary);
}

.sidebar-link.active {
  color: var(--accent-primary);
  background: rgba(102, 126, 234, 0.08);
  font-weight: 500;
}

.main-content {
  margin-left: var(--sidebar-width);
  flex: 1;
  min-width: 0;
}

.content {
  max-width: var(--content-max-width);
  margin: 0 auto;
  padding: 40px 48px 80px;
}

/* ============ Header / Theme Toggle ============ */

.top-bar {
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--bg-primary);
  border-bottom: 1px solid var(--border-color);
  padding: 12px 48px;
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 12px;
  margin-left: var(--sidebar-width);
}

.theme-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  border-radius: 20px;
  padding: 6px 12px;
  cursor: pointer;
  font-size: 0.85rem;
  color: var(--text-secondary);
  transition: all 0.2s ease;
}

.theme-toggle:hover {
  border-color: var(--accent-primary);
  color: var(--text-primary);
}

.theme-toggle svg {
  width: 16px;
  height: 16px;
}

.mobile-menu-btn {
  display: none;
  background: none;
  border: none;
  padding: 8px;
  cursor: pointer;
  color: var(--text-primary);
}

/* ============ Typography ============ */

h1 {
  font-size: 2.2rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1.2;
  margin-bottom: 16px;
  color: var(--text-primary);
}

h2 {
  font-size: 1.6rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  line-height: 1.3;
  margin-top: 48px;
  margin-bottom: 16px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border-color);
  color: var(--text-primary);
}

h3 {
  font-size: 1.25rem;
  font-weight: 600;
  line-height: 1.4;
  margin-top: 32px;
  margin-bottom: 12px;
  color: var(--text-primary);
}

h4 {
  font-size: 1.05rem;
  font-weight: 600;
  margin-top: 24px;
  margin-bottom: 8px;
  color: var(--text-primary);
}

p {
  margin-bottom: 16px;
  color: var(--text-secondary);
}

a {
  color: var(--text-link);
  text-decoration: none;
  transition: color 0.15s ease;
}

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

ul, ol {
  margin-bottom: 16px;
  padding-left: 24px;
}

li {
  margin-bottom: 6px;
  color: var(--text-secondary);
}

strong {
  color: var(--text-primary);
  font-weight: 600;
}

blockquote {
  border-left: 3px solid var(--accent-primary);
  padding: 12px 16px;
  margin: 16px 0;
  background: var(--bg-secondary);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

blockquote p {
  margin-bottom: 0;
}

hr {
  border: none;
  border-top: 1px solid var(--border-color);
  margin: 32px 0;
}

/* ============ Code ============ */

code {
  font-family: var(--font-mono);
  font-size: 0.88em;
  background: var(--bg-inline-code);
  color: var(--text-code);
  padding: 2px 6px;
  border-radius: var(--radius-sm);
}

pre {
  background: var(--bg-code);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 20px 24px;
  margin: 16px 0 24px;
  overflow-x: auto;
  line-height: 1.6;
}

pre code {
  background: none;
  padding: 0;
  font-size: 0.88rem;
  color: var(--text-code);
}

/* Syntax highlighting classes */
.kw { color: var(--syn-keyword); font-weight: 500; }
.str { color: var(--syn-string); }
.num { color: var(--syn-number); }
.cmt { color: var(--syn-comment); font-style: italic; }
.fn { color: var(--syn-function); }
.cls { color: var(--syn-class); }
.op { color: var(--syn-operator); }
.punc { color: var(--syn-punctuation); }
.bi { color: var(--syn-builtin); }
.prop { color: var(--syn-property); }

/* ============ Tables ============ */

table {
  width: 100%;
  border-collapse: collapse;
  margin: 16px 0 24px;
  font-size: 0.9rem;
}

th, td {
  padding: 10px 14px;
  text-align: left;
  border-bottom: 1px solid var(--border-color);
}

th {
  background: var(--bg-secondary);
  font-weight: 600;
  color: var(--text-primary);
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

td {
  color: var(--text-secondary);
}

td code {
  font-size: 0.85em;
}

tr:hover td {
  background: var(--bg-secondary);
}

/* ============ Cards & Boxes ============ */

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 16px;
  margin: 24px 0;
}

.card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 20px;
  transition: all 0.2s ease;
}

.card:hover {
  border-color: var(--accent-primary);
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}

.card-title {
  font-weight: 600;
  font-size: 1rem;
  margin-bottom: 6px;
  color: var(--text-primary);
}

.card-desc {
  font-size: 0.88rem;
  color: var(--text-tertiary);
}

.card a {
  text-decoration: none;
  color: inherit;
  display: block;
}

.info-box {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-left: 3px solid var(--accent-primary);
  border-radius: var(--radius-sm);
  padding: 14px 18px;
  margin: 16px 0;
}

.info-box.warning {
  border-left-color: #d97706;
}

.info-box.tip {
  border-left-color: #059669;
}

.info-box-title {
  font-weight: 600;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 4px;
  color: var(--text-primary);
}

/* ============ Hero Section (index page) ============ */

.hero {
  background: var(--accent-gradient);
  border-radius: var(--radius-lg);
  padding: 48px 40px;
  margin-bottom: 40px;
  color: white;
  position: relative;
  overflow: hidden;
}

.hero::after {
  content: '';
  position: absolute;
  top: -50%;
  right: -20%;
  width: 60%;
  height: 200%;
  background: rgba(255, 255, 255, 0.05);
  transform: rotate(15deg);
  pointer-events: none;
}

.hero h1 {
  color: white;
  font-size: 2.5rem;
  margin-bottom: 12px;
}

.hero p {
  color: rgba(255, 255, 255, 0.9);
  font-size: 1.15rem;
  max-width: 600px;
}

.hero-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 20px;
}

.badge {
  display: inline-block;
  background: rgba(255, 255, 255, 0.15);
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 20px;
  padding: 4px 12px;
  font-size: 0.8rem;
  color: rgba(255, 255, 255, 0.95);
  font-weight: 500;
}

/* ============ Function Signatures ============ */

.fn-signature {
  background: var(--bg-code);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 16px 20px;
  margin: 12px 0;
  font-family: var(--font-mono);
  font-size: 0.9rem;
}

.fn-params {
  margin: 8px 0;
  padding-left: 16px;
}

.fn-params dt {
  font-family: var(--font-mono);
  font-size: 0.88rem;
  color: var(--text-primary);
  margin-top: 8px;
}

.fn-params dd {
  font-size: 0.88rem;
  color: var(--text-secondary);
  margin-left: 16px;
}

/* ============ Breadcrumb ============ */

.breadcrumb {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  color: var(--text-tertiary);
  margin-bottom: 24px;
}

.breadcrumb a {
  color: var(--text-tertiary);
}

.breadcrumb a:hover {
  color: var(--text-link);
}

.breadcrumb-separator {
  color: var(--text-tertiary);
}

/* ============ Architecture Diagram ============ */

.diagram {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 24px;
  margin: 24px 0;
  text-align: center;
  overflow-x: auto;
}

.diagram img,
.diagram svg {
  max-width: 100%;
  height: auto;
}

/* ============ Mobile Responsive ============ */

@media (max-width: 1024px) {
  .sidebar {
    transform: translateX(-100%);
  }

  .sidebar.open {
    transform: translateX(0);
    box-shadow: var(--shadow-lg);
  }

  .main-content {
    margin-left: 0;
  }

  .top-bar {
    margin-left: 0;
    padding: 12px 24px;
    justify-content: space-between;
  }

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

  .content {
    padding: 24px;
  }

  h1 { font-size: 1.8rem; }
  h2 { font-size: 1.4rem; }

  .hero {
    padding: 32px 24px;
  }

  .hero h1 { font-size: 2rem; }

  .card-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  .content {
    padding: 16px;
  }

  pre {
    padding: 14px 16px;
    font-size: 0.82rem;
    border-radius: var(--radius-sm);
  }

  .hero {
    padding: 24px 20px;
  }

  .hero h1 { font-size: 1.6rem; }
  .hero p { font-size: 1rem; }

  table {
    font-size: 0.82rem;
  }

  th, td {
    padding: 8px 10px;
  }
}

/* ============ Scrollbar ============ */

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

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

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

/* ============ Footer ============ */

.page-footer {
  margin-top: 64px;
  padding-top: 24px;
  border-top: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.85rem;
  color: var(--text-tertiary);
}

.page-footer a {
  color: var(--text-link);
}

/* ============ Search-like filter (optional) ============ */

.sidebar-search {
  padding: 0 12px;
  margin-bottom: 12px;
}

.sidebar-search input {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  background: var(--bg-primary);
  color: var(--text-primary);
  font-size: 0.85rem;
  outline: none;
  transition: border-color 0.2s;
}

.sidebar-search input:focus {
  border-color: var(--accent-primary);
}

/* ============ Page navigation (prev/next) ============ */

.page-nav {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-top: 48px;
}

.page-nav-link {
  display: block;
  padding: 16px 20px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  text-decoration: none;
  transition: all 0.2s ease;
}

.page-nav-link:hover {
  border-color: var(--accent-primary);
  box-shadow: var(--shadow-sm);
  text-decoration: none;
}

.page-nav-label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-tertiary);
  margin-bottom: 4px;
}

.page-nav-title {
  font-weight: 600;
  color: var(--text-link);
}

.page-nav-link.next {
  text-align: right;
}

/* ============ Animations ============ */

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

.content > * {
  animation: fadeIn 0.3s ease forwards;
}

/* ============ Overlay for mobile ============ */

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 99;
}

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