/* ── Lattice Language Specification ── */

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

:root {
  --bg: #08080d;
  --bg-card: #0e0e18;
  --border: #1a1a2e;
  --text: #c8c8d4;
  --text-dim: #6a6a80;
  --heading: #e8e8f0;
  --accent: #4fc3f7;
  --accent-dim: #2a7ea8;
  --keyword: #c792ea;
  --string: #c3e88d;
  --comment: #546e7a;
  --type: #ffcb6b;
  --number: #f78c6c;
  --fn: #82aaff;
  --op: #89ddff;
  --mono: 'SF Mono', 'Cascadia Code', 'JetBrains Mono', 'Fira Code', Consolas, monospace;
  --sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
}

html { scroll-behavior: smooth; height: 100%; }

body {
  font-family: var(--sans);
  background: var(--bg);
  color: var(--text);
  line-height: 1.7;
  height: 100%;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* Lattice background pattern */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  background:
    linear-gradient(rgba(79,195,247,0.03) 1px, transparent 1px),
    linear-gradient(90deg, rgba(79,195,247,0.03) 1px, transparent 1px);
  background-size: 60px 60px;
  pointer-events: none;
  z-index: 0;
}

/* ── Header ── */
.spec-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-card);
  position: relative;
  z-index: 10;
  flex-shrink: 0;
}

.spec-header-left {
  display: flex;
  align-items: center;
  gap: 16px;
}

.spec-logo {
  font-family: var(--mono);
  font-size: 1rem;
  font-weight: 700;
  color: var(--heading);
  text-decoration: none;
  background: linear-gradient(135deg, var(--heading), var(--accent));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  display: flex;
  align-items: center;
  gap: 8px;
}

.spec-logo-img {
  width: 24px;
  height: 24px;
  filter: drop-shadow(0 0 4px rgba(79, 195, 247, 0.3));
}

.spec-sep {
  color: var(--border);
  font-size: 1.2rem;
  user-select: none;
}

.spec-title {
  font-family: var(--mono);
  font-size: 0.85rem;
  color: var(--text-dim);
}

.spec-header-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.spec-btn {
  font-family: var(--mono);
  font-size: 0.75rem;
  padding: 6px 14px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
  text-decoration: none;
  transition: all 0.2s;
}
.spec-btn:hover {
  border-color: var(--accent-dim);
  color: var(--accent);
}

/* ── Layout ── */
.spec-layout {
  display: flex;
  flex: 1;
  overflow: hidden;
  position: relative;
  z-index: 1;
}

/* ── Sidebar ── */
.spec-sidebar {
  width: 260px;
  flex-shrink: 0;
  border-right: 1px solid var(--border);
  background: var(--bg-card);
  overflow-y: auto;
  padding: 20px 0;
}

.spec-sidebar::-webkit-scrollbar { width: 6px; }
.spec-sidebar::-webkit-scrollbar-track { background: transparent; }
.spec-sidebar::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
.spec-sidebar::-webkit-scrollbar-thumb:hover { background: var(--text-dim); }

.spec-sidebar-heading {
  font-family: var(--mono);
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--text-dim);
  padding: 12px 20px 6px;
}

.spec-sidebar-link {
  display: flex;
  align-items: center;
  padding: 6px 20px;
  font-size: 0.82rem;
  color: var(--text);
  text-decoration: none;
  transition: all 0.15s;
  gap: 8px;
}
.spec-sidebar-link:hover {
  color: var(--accent);
  background: rgba(79,195,247,0.04);
}
.spec-sidebar-link.active {
  color: var(--accent);
  background: rgba(79,195,247,0.08);
  border-right: 2px solid var(--accent);
}

.spec-sidebar-num {
  font-family: var(--mono);
  font-size: 0.65rem;
  color: var(--text-dim);
  min-width: 18px;
}

/* ── Content ── */
.spec-content {
  flex: 1;
  overflow-y: auto;
  padding: 32px 48px 80px;
  max-width: 100%;
}

.spec-content::-webkit-scrollbar { width: 8px; }
.spec-content::-webkit-scrollbar-track { background: transparent; }
.spec-content::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
.spec-content::-webkit-scrollbar-thumb:hover { background: var(--text-dim); }

.spec-content > h1 {
  font-size: 2rem;
  font-weight: 700;
  color: var(--heading);
  margin-bottom: 8px;
  letter-spacing: -0.01em;
}

.spec-content > .spec-chapter-num {
  font-family: var(--mono);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.15em;
  color: var(--accent);
  margin-bottom: 8px;
  display: block;
}

.spec-content h2 {
  font-size: 1.4rem;
  font-weight: 600;
  color: var(--heading);
  margin-top: 48px;
  margin-bottom: 16px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

.spec-content h3 {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--heading);
  margin-top: 32px;
  margin-bottom: 12px;
}

.spec-content h4 {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--heading);
  margin-top: 24px;
  margin-bottom: 8px;
}

.spec-content p {
  margin-bottom: 16px;
  max-width: 720px;
}

.spec-content ul, .spec-content ol {
  margin-bottom: 16px;
  padding-left: 24px;
  max-width: 720px;
}

.spec-content li {
  margin-bottom: 6px;
}

.spec-content code {
  font-family: var(--mono);
  font-size: 0.85em;
  background: rgba(79,195,247,0.06);
  border: 1px solid var(--border);
  padding: 2px 6px;
  border-radius: 4px;
  color: var(--accent);
}

.spec-content a {
  color: var(--accent);
  text-decoration: none;
}
.spec-content a:hover {
  text-decoration: underline;
}

/* ── Grammar blocks (EBNF) ── */
.spec-grammar {
  font-family: var(--mono);
  font-size: 0.82rem;
  line-height: 1.8;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 20px 24px;
  margin-bottom: 24px;
  overflow-x: auto;
  max-width: 720px;
  color: var(--text);
}

.spec-grammar .nt {
  color: var(--accent);
  font-style: italic;
}

.spec-grammar .t {
  color: var(--string);
}

.spec-grammar .kw {
  color: var(--keyword);
}

.spec-grammar .cm {
  color: var(--comment);
  font-style: italic;
}

/* ── Code blocks ── */
.spec-code {
  font-family: var(--mono);
  font-size: 0.82rem;
  line-height: 1.7;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 20px 24px;
  margin-bottom: 24px;
  overflow-x: auto;
  max-width: 720px;
  color: var(--text);
  tab-size: 4;
}

/* Syntax highlighting (same as main site) */
.kw { color: var(--keyword); }
.str { color: var(--string); }
.cmt { color: var(--comment); font-style: italic; }
.typ { color: var(--type); }
.num { color: var(--number); }
.fn { color: var(--fn); }
.op { color: var(--text-dim); }

/* ── Tables ── */
.spec-table {
  width: 100%;
  max-width: 720px;
  border-collapse: collapse;
  margin-bottom: 24px;
  font-size: 0.88rem;
}

.spec-table th {
  text-align: left;
  font-weight: 600;
  color: var(--heading);
  padding: 10px 16px;
  border-bottom: 2px solid var(--border);
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.spec-table td {
  padding: 8px 16px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

.spec-table tr:last-child td {
  border-bottom: none;
}

.spec-table code {
  font-size: 0.82em;
}

.spec-table tbody tr:hover {
  background: rgba(79,195,247,0.03);
}

/* ── Callout boxes ── */
.spec-note {
  background: rgba(79,195,247,0.05);
  border: 1px solid rgba(79,195,247,0.15);
  border-left: 3px solid var(--accent);
  border-radius: 6px;
  padding: 16px 20px;
  margin-bottom: 24px;
  max-width: 720px;
  font-size: 0.9rem;
}

.spec-note strong {
  color: var(--accent);
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  display: block;
  margin-bottom: 4px;
}

.spec-warning {
  background: rgba(247,140,108,0.05);
  border: 1px solid rgba(247,140,108,0.15);
  border-left: 3px solid var(--number);
  border-radius: 6px;
  padding: 16px 20px;
  margin-bottom: 24px;
  max-width: 720px;
  font-size: 0.9rem;
}

.spec-warning strong {
  color: var(--number);
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  display: block;
  margin-bottom: 4px;
}

/* ── Prev/Next Navigation ── */
.spec-prev-next {
  display: flex;
  justify-content: space-between;
  margin-top: 64px;
  padding-top: 24px;
  border-top: 1px solid var(--border);
  max-width: 720px;
}

.spec-prev-next a {
  font-family: var(--mono);
  font-size: 0.82rem;
  color: var(--text-dim);
  text-decoration: none;
  padding: 8px 16px;
  border: 1px solid var(--border);
  border-radius: 6px;
  transition: all 0.2s;
}
.spec-prev-next a:hover {
  border-color: var(--accent-dim);
  color: var(--accent);
}

.spec-prev-next .next {
  margin-left: auto;
}

/* ── Mobile sidebar toggle ── */
.sidebar-toggle {
  display: none;
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 20;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--accent);
  font-size: 1.2rem;
  cursor: pointer;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 12px rgba(0,0,0,0.4);
}

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

/* ── Responsive ── */
@media (max-width: 768px) {
  .spec-sidebar {
    position: fixed;
    left: -280px;
    top: 0;
    bottom: 0;
    z-index: 15;
    transition: left 0.25s ease;
    box-shadow: none;
  }
  .spec-sidebar.open {
    left: 0;
    box-shadow: 4px 0 20px rgba(0,0,0,0.5);
  }

  .sidebar-toggle {
    display: flex;
  }

  .spec-content {
    padding: 24px 16px 60px;
  }

  .spec-header {
    padding: 10px 16px;
  }

  .spec-title { display: none; }
  .spec-sep { display: none; }

  .spec-content > h1 {
    font-size: 1.5rem;
  }

  .spec-prev-next {
    flex-direction: column;
    gap: 8px;
  }

  .spec-prev-next a {
    text-align: center;
  }

  .spec-table {
    font-size: 0.8rem;
  }
  .spec-table th, .spec-table td {
    padding: 6px 10px;
  }
}

@media (max-width: 480px) {
  .spec-header-right a:not(:last-child) { display: none; }

  .spec-grammar, .spec-code {
    font-size: 0.75rem;
    padding: 14px 16px;
  }
}
