/* ============================================================
   Keel Documentation — style.css
   Design tokens and layout for the GitHub Pages docs site
   ============================================================ */

/* ============================================================
   Design Tokens
   ============================================================ */
:root {
  /* Sidebar */
  --sidebar-bg: #0f172a;
  --sidebar-text: #94a3b8;
  --sidebar-label: #7a8fa3;
  --sidebar-active: #38bdf8;
  --sidebar-width: 280px;
  --sidebar-hover: #cbd5e1;

  /* Header */
  --header-height: 56px;
  --header-bg: #0f172a;
  --header-border: #1e293b;

  /* Content */
  --content-bg: #ffffff;
  --content-max-width: 740px;

  /* Typography */
  --body-text: #1e293b;
  --body-muted: #5c6a7d;
  --body-line-length: 65ch;

  /* Accent */
  --accent: #0ea5e9;
  --accent-hover: #38bdf8;

  /* Borders */
  --border: #e2e8f0;

  /* Code */
  --code-bg: #1e293b;
  --code-text: #e2e8f0;
  --code-comment: #94a3b8;

  /* Surface */
  --surface-light: #f8fafc;
  --ink-bright: #f1f5f9;
  --success: #4ade80;

  /* Spacing */
  --spacing-xs: 4px;
  --spacing-sm: 8px;
  --spacing-md: 16px;
  --spacing-lg: 24px;
  --spacing-xl: 48px;

  /* Transitions */
  --transition-speed: 200ms;
  --transition-ease: ease-in-out;
}

@media (prefers-color-scheme: dark) {
  :root {
    --content-bg: #0d1117;
    --body-text: #cdd6e4;
    --body-muted: #8897aa;
    --border: #2d3748;
    --surface-light: #161b22;
    --ink-bright: #e2e8f0;
  }
}

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

html {
  font-size: 16px;
  scroll-behavior: smooth;
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

body {
  font-family: 'Mulish', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 1rem;
  line-height: 1.7;
  color: var(--body-text);
  background: var(--content-bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ============================================================
   Skip Link
   ============================================================ */
.skip-link {
  position: absolute;
  top: -100%;
  left: var(--spacing-md);
  padding: var(--spacing-sm) var(--spacing-md);
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  text-decoration: none;
  border-radius: 4px;
  z-index: 9999;
  transition: top var(--transition-speed) var(--transition-ease);
}

.skip-link:focus {
  top: var(--spacing-sm);
}

/* ============================================================
   Header
   ============================================================ */
.site-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--header-height);
  background: var(--header-bg);
  border-bottom: 1px solid var(--header-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--spacing-lg);
  z-index: 100;
}

.site-logo {
  display: flex;
  align-items: center;
  gap: var(--spacing-sm);
  font-family: 'Barlow', sans-serif;
  font-size: 1.125rem;
  font-weight: 700;
  color: var(--ink-bright);
  text-decoration: none;
  letter-spacing: -0.01em;
}

.site-logo:hover,
.site-logo:focus {
  color: var(--sidebar-active);
  outline: none;
}

.site-logo:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: var(--spacing-md);
}

.version-badge {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--sidebar-text);
  background: rgba(148, 163, 184, 0.15);
  padding: 2px 8px;
  border-radius: 9999px;
  border: 1px solid rgba(148, 163, 184, 0.2);
}

.github-link {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--sidebar-text);
  text-decoration: none;
  padding: 6px 12px;
  border-radius: 6px;
  border: 1px solid rgba(148, 163, 184, 0.25);
  transition: color var(--transition-speed) var(--transition-ease),
              border-color var(--transition-speed) var(--transition-ease);
  min-height: 44px;
  min-width: 44px;
}

@media (prefers-reduced-motion: reduce) {
  .github-link {
    transition: none;
  }
}

.github-link:hover {
  color: var(--ink-bright);
  border-color: rgba(148, 163, 184, 0.5);
}

.github-link:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.github-icon {
  width: 18px;
  height: 18px;
  fill: currentColor;
  flex-shrink: 0;
}

/* Hamburger */
.hamburger {
  display: none;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 5px;
  width: 44px;
  height: 44px;
  background: none;
  border: none;
  cursor: pointer;
  padding: var(--spacing-sm);
  border-radius: 6px;
  color: var(--sidebar-text);
}

.hamburger:hover {
  background: rgba(148, 163, 184, 0.1);
}

.hamburger:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.hamburger-bar {
  display: block;
  width: 20px;
  height: 2px;
  background: currentColor;
  border-radius: 2px;
  transition: transform var(--transition-speed) var(--transition-ease),
              opacity var(--transition-speed) var(--transition-ease);
}

@media (prefers-reduced-motion: reduce) {
  .hamburger-bar {
    transition: none;
  }
}

body.sidebar-open .hamburger-bar:nth-child(1) {
  transform: translateY(7px) rotate(45deg);
}

body.sidebar-open .hamburger-bar:nth-child(2) {
  opacity: 0;
}

body.sidebar-open .hamburger-bar:nth-child(3) {
  transform: translateY(-7px) rotate(-45deg);
}

/* ============================================================
   Layout Shell
   ============================================================ */
.layout {
  display: flex;
  padding-top: var(--header-height);
  min-height: 100vh;
}

/* ============================================================
   Sidebar
   ============================================================ */
.sidebar {
  position: fixed;
  top: var(--header-height);
  left: 0;
  bottom: 0;
  width: var(--sidebar-width);
  background: var(--sidebar-bg);
  overflow-y: auto;
  overflow-x: hidden;
  padding: var(--spacing-lg) 0 var(--spacing-xl);
  z-index: 90;
  border-right: 1px solid rgba(148, 163, 184, 0.08);
  -webkit-overflow-scrolling: touch;
}

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

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

.sidebar::-webkit-scrollbar-thumb {
  background: rgba(148, 163, 184, 0.2);
  border-radius: 2px;
}

.nav-group {
  margin-bottom: var(--spacing-lg);
}

.nav-group-label {
  display: block;
  font-size: 0.6875rem;
  font-weight: 600;
  color: var(--sidebar-label);
  letter-spacing: 0.06em;
  padding: 0 var(--spacing-lg) var(--spacing-xs);
  text-transform: uppercase;
}

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

.nav-link {
  display: block;
  font-size: 0.875rem;
  font-weight: 400;
  color: var(--sidebar-text);
  text-decoration: none;
  padding: 7px var(--spacing-lg);
  border-left: 1px solid transparent;
  transition: color var(--transition-speed) var(--transition-ease),
              border-color var(--transition-speed) var(--transition-ease),
              background var(--transition-speed) var(--transition-ease);
  min-height: 44px;
  display: flex;
  align-items: center;
}

@media (prefers-reduced-motion: reduce) {
  .nav-link {
    transition: none;
  }
}

.nav-link:hover {
  color: var(--sidebar-hover);
  background: rgba(148, 163, 184, 0.05);
}

.nav-link:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

.nav-link.active {
  color: var(--sidebar-active);
  border-left-color: var(--sidebar-active);
  background: rgba(56, 189, 248, 0.08);
  font-weight: 600;
}

.nav-link-child {
  padding-left: calc(var(--spacing-lg) + 12px);
  font-size: 0.8125rem;
}

/* Sidebar overlay on mobile */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 80;
}

/* ============================================================
   Main Content
   ============================================================ */
.main-content {
  flex: 1;
  margin-left: var(--sidebar-width);
  padding: var(--spacing-xl);
  min-width: 0;
}

.content-section {
  display: none;
  max-width: var(--content-max-width);
  margin: 0 auto;
  animation: fadeIn var(--transition-speed) var(--transition-ease);
}

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

@media (prefers-reduced-motion: reduce) {
  .content-section {
    animation: none;
  }
}

.content-section.active {
  display: block;
}

/* ============================================================
   Typography
   ============================================================ */
.content-section h1 {
  font-family: 'Barlow', sans-serif;
  font-size: 2rem;
  font-weight: 700;
  color: var(--body-text);
  line-height: 1.2;
  letter-spacing: -0.02em;
  margin-bottom: var(--spacing-md);
}

.content-section h2 {
  font-family: 'Barlow', sans-serif;
  font-size: 1.375rem;
  font-weight: 600;
  color: var(--body-text);
  line-height: 1.3;
  letter-spacing: -0.01em;
  margin-top: var(--spacing-xl);
  margin-bottom: var(--spacing-md);
  padding-bottom: var(--spacing-sm);
  border-bottom: 1px solid var(--border);
}

.content-section h3 {
  font-family: 'Barlow', sans-serif;
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--body-text);
  line-height: 1.4;
  margin-top: var(--spacing-lg);
  margin-bottom: var(--spacing-sm);
}

.content-section p {
  color: var(--body-text);
  margin-bottom: var(--spacing-md);
  max-width: var(--body-line-length);
}

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

.lead {
  font-size: 1.125rem;
  color: var(--body-muted);
  line-height: 1.6;
  margin-bottom: var(--spacing-lg);
  max-width: var(--body-line-length);
}

/* ============================================================
   Lists
   ============================================================ */
.content-section ul,
.content-section ol {
  color: var(--body-text);
  padding-left: 1.5rem;
  margin-bottom: var(--spacing-md);
  max-width: var(--body-line-length);
}

.content-section li {
  margin-bottom: var(--spacing-xs);
  line-height: 1.6;
}

.content-section li + li {
  margin-top: var(--spacing-xs);
}

/* Feature list — clean, no bullets become icons */
.feature-list {
  list-style: none;
  padding-left: 0;
}

.feature-list li {
  display: flex;
  gap: var(--spacing-sm);
  align-items: baseline;
  padding: var(--spacing-sm) 0;
  border-bottom: 1px solid var(--border);
}

.feature-list li:last-child {
  border-bottom: none;
}

.feature-list .feature-key {
  font-weight: 600;
  color: var(--body-text);
  white-space: nowrap;
  flex-shrink: 0;
  min-width: 160px;
}

.feature-list .feature-desc {
  color: var(--body-muted);
  font-size: 0.9375rem;
}

/* Phase list */
.phase-list {
  list-style: none;
  padding-left: 0;
  margin-bottom: var(--spacing-md);
}

.phase-list li {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: var(--spacing-sm) var(--spacing-md);
  padding: var(--spacing-sm) 0;
  border-bottom: 1px solid var(--border);
  align-items: baseline;
}

.phase-list li:last-child {
  border-bottom: none;
}

.phase-label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--accent);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.phase-desc {
  color: var(--body-text);
  font-size: 0.9375rem;
}

/* ============================================================
   Code
   ============================================================ */
pre {
  background: var(--code-bg);
  color: var(--code-text);
  border-radius: 8px;
  padding: var(--spacing-lg);
  overflow-x: auto;
  margin-bottom: var(--spacing-md);
  position: relative;
  font-size: 0.875rem;
  line-height: 1.6;
  border: 1px solid rgba(148, 163, 184, 0.1);
}

pre code {
  font-family: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', 'SF Mono', 'Monaco',
    'Inconsolata', 'Roboto Mono', 'Courier New', Courier, monospace;
  font-size: inherit;
  color: inherit;
  background: none;
  padding: 0;
  border-radius: 0;
  white-space: pre;
  font-variant-ligatures: contextual;
}

code {
  font-family: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', 'SF Mono', 'Monaco',
    'Inconsolata', 'Roboto Mono', 'Courier New', Courier, monospace;
  font-size: 0.875em;
  color: var(--accent);
  background: rgba(14, 165, 233, 0.08);
  padding: 1px 5px;
  border-radius: 4px;
}

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

/* Copy button */
.code-wrapper {
  position: relative;
}

.copy-btn {
  position: absolute;
  top: var(--spacing-sm);
  right: var(--spacing-sm);
  padding: 4px 10px;
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--sidebar-text);
  background: rgba(148, 163, 184, 0.1);
  border: 1px solid rgba(148, 163, 184, 0.2);
  border-radius: 4px;
  cursor: pointer;
  transition: color var(--transition-speed) var(--transition-ease),
              background var(--transition-speed) var(--transition-ease);
  min-height: 44px;
  min-width: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
}

@media (prefers-reduced-motion: reduce) {
  .copy-btn {
    transition: none;
  }
}

.copy-btn:hover {
  color: var(--ink-bright);
  background: rgba(148, 163, 184, 0.2);
}

.copy-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.copy-btn.copied {
  color: var(--success);
  border-color: rgba(74, 222, 128, 0.3);
}

/* ============================================================
   Tables
   ============================================================ */
.table-wrapper {
  width: 100%;
  overflow-x: auto;
  margin-bottom: var(--spacing-md);
  border-radius: 8px;
  border: 1px solid var(--border);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9375rem;
  min-width: 560px;
}

thead {
  background: var(--surface-light);
}

th {
  text-align: left;
  padding: 12px var(--spacing-md);
  font-weight: 600;
  font-size: 0.8125rem;
  color: var(--body-muted);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

td {
  padding: 12px var(--spacing-md);
  color: var(--body-text);
  vertical-align: top;
  border-bottom: 1px solid var(--border);
  line-height: 1.5;
}

td:first-child {
  font-family: 'JetBrains Mono', 'Fira Code', 'SF Mono', monospace;
  font-size: 0.8125rem;
  color: var(--accent);
  white-space: nowrap;
  font-weight: 500;
}

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

tbody tr:hover {
  background: var(--surface-light);
}

/* ============================================================
   Callout / Note boxes
   ============================================================ */
.callout {
  padding: var(--spacing-md) var(--spacing-lg);
  border: 1px solid rgba(14, 165, 233, 0.3);
  background: rgba(14, 165, 233, 0.06);
  border-radius: 6px;
  margin-bottom: var(--spacing-md);
}

.callout p {
  margin-bottom: 0;
  font-size: 0.9375rem;
  color: var(--body-text);
}

.callout-note {
  border-color: rgba(100, 116, 139, 0.3);
  background: rgba(100, 116, 139, 0.06);
}

/* ============================================================
   Anchors
   ============================================================ */
.content-section a {
  color: var(--accent);
  text-decoration: underline;
  text-decoration-color: rgba(14, 165, 233, 0.4);
  text-underline-offset: 2px;
  transition: color var(--transition-speed) var(--transition-ease),
              text-decoration-color var(--transition-speed) var(--transition-ease);
}

@media (prefers-reduced-motion: reduce) {
  .content-section a {
    transition: none;
  }
}

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

.content-section a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 2px;
}

/* ============================================================
   Horizontal Rule
   ============================================================ */
hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: var(--spacing-xl) 0;
}

/* ============================================================
   Directory tree (for contributing)
   ============================================================ */
.dir-tree {
  font-family: 'JetBrains Mono', 'Fira Code', 'SF Mono', monospace;
  font-size: 0.875rem;
  color: var(--code-text);
  background: var(--code-bg);
  border-radius: 8px;
  padding: var(--spacing-lg);
  overflow-x: auto;
  border: 1px solid rgba(148, 163, 184, 0.1);
  margin-bottom: var(--spacing-md);
  line-height: 1.8;
  white-space: pre;
}

.dir-tree .dir-name {
  color: var(--sidebar-active);
}

.dir-tree .file-name {
  color: var(--code-text);
}

.dir-tree .comment {
  color: var(--code-comment);
}

/* ============================================================
   Footer
   ============================================================ */
.content-footer {
  margin-top: var(--spacing-xl);
  padding-top: var(--spacing-lg);
  border-top: 1px solid var(--border);
  font-size: 0.875rem;
  color: var(--body-muted);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: var(--spacing-sm);
}

.content-footer a {
  color: var(--body-muted);
  text-decoration: none;
}

.content-footer a:hover {
  color: var(--accent);
}

/* ============================================================
   Mobile / Responsive
   ============================================================ */
@media (max-width: 767px) {
  .hamburger {
    display: flex;
  }

  .sidebar {
    transform: translateX(-100%);
    transition: transform var(--transition-speed) var(--transition-ease);
    z-index: 95;
  }

  @media (prefers-reduced-motion: reduce) {
    .sidebar {
      transition: none;
    }
  }

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

  body.sidebar-open .sidebar-overlay {
    display: block;
  }

  .main-content {
    margin-left: 0;
    padding: var(--spacing-lg) var(--spacing-md);
  }

  .content-section h1 {
    font-size: 1.625rem;
  }

  .content-section h2 {
    font-size: 1.25rem;
  }

  .feature-list .feature-key {
    min-width: 120px;
  }

  .version-badge {
    display: none;
  }
}

@media (min-width: 768px) and (max-width: 1024px) {
  :root {
    --sidebar-width: 240px;
  }

  .main-content {
    padding: var(--spacing-xl) var(--spacing-lg);
  }
}
