html {
  scroll-behavior: smooth;
}

* {
  box-sizing: border-box;
}

:root {
  --bg: #fcfcfc;
  --sidebar-bg: #f7f7f7;
  --sidebar-border: #dcdcdc;
  --text: #2b2b2b;
  --muted: #666666;
  --heading: #2f6b2f;
  --accent: #2f6b2f;
  --accent-light: #eaf3e4;
  --accent-gold: #f4d03f;
  --card-bg: #fafafa;
  --card-border: #e3e3e3;
  --table-border: #cfcfcf;
  --table-head-bg: #f3f6ef;
  --table-row-alt: #fbfbfb;
  --link: #2980b9;
  --link-hover: #1f5f87;
}

body {
  margin: 0;
  font-family: Arial, Helvetica, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.65;
}

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

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

.page {
  display: grid;
  grid-template-columns: 280px 1fr;
  min-height: 100vh;
}

/* Sidebar */

.sidebar {
  background: var(--sidebar-bg);
  border-right: 1px solid var(--sidebar-border);
  padding: 24px 18px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.sidebar-title {
  margin-bottom: 22px;
}

.sidebar-title h1 {
  margin: 0;
  font-size: 1.25rem;
  color: var(--heading);
  line-height: 1.3;
}

.sidebar-title p {
  margin: 6px 0 0;
  color: #777;
  font-size: 0.95rem;
}

.nav-group {
  margin-bottom: 6px;
}

.sidebar-nav > a,
.sidebar-nav > .nav-group > a {
  display: block;
  padding: 9px 12px;
  margin-bottom: 6px;
  border-radius: 8px;
  color: #333;
  font-weight: 600;
  transition: background 0.2s ease, color 0.2s ease;
}

.sidebar-nav > a:hover,
.sidebar-nav > .nav-group > a:hover {
  background: var(--accent-light);
  color: var(--accent);
  text-decoration: none;
}

.sidebar-nav > a.active,
.sidebar-nav > .nav-group > a.active {
  background: var(--accent);
  color: var(--accent-gold);
}

.sidebar-nav > .nav-group > a.active::after {
  content: "▾";
  float: right;
  font-size: 0.85rem;
}

.sidebar-subnav {
  margin: -2px 0 10px 18px;
  padding-left: 12px;
  border-left: 2px solid #d7e4cd;
}

.sidebar-subnav a {
  display: block;
  padding: 6px 10px;
  margin-bottom: 4px;
  border-radius: 6px;
  color: #555;
  font-size: 0.92rem;
  font-weight: 500;
  line-height: 1.35;
  transition: background 0.2s ease, color 0.2s ease;
}

.sidebar-subnav a:hover {
  background: var(--accent-light);
  color: var(--accent);
  text-decoration: none;
}

.sidebar-subnav a.sub-active {
  background: #f3f6ef;
  color: var(--accent);
  font-weight: 700;
}

/* Main content */

.content {
  padding: 28px 36px 48px;
  max-width: 1000px;
}

.doc-header {
  margin-bottom: 28px;
}

.doc-header h1 {
  margin: 0 0 8px;
  font-size: 2rem;
  color: var(--heading);
  line-height: 1.2;
}

.subtitle {
  margin: 0;
  color: var(--muted);
  font-size: 1rem;
}

.doc-section {
  margin-bottom: 38px;
}

.doc-section h2 {
  color: var(--heading);
  margin: 0 0 16px;
  border-bottom: 2px solid #e5e5e5;
  padding-bottom: 8px;
  font-size: 1.55rem;
}

.doc-section h3 {
  margin: 26px 0 10px;
  color: #333;
  font-size: 1.15rem;
}

.doc-section p {
  margin: 0 0 14px;
  max-width: 850px;
}

.doc-section ul,
.doc-section ol {
  padding-left: 22px;
  margin: 0 0 16px;
}

.doc-section li {
  margin-bottom: 8px;
}

/* Figures */

.doc-figure {
  margin: 18px 0 26px;
}

.doc-figure img {
  width: 100%;
  max-width: 760px;
  height: auto;
  display: block;
  border: 1px solid #ddd;
  border-radius: 8px;
  background: white;
}

.doc-figure figcaption {
  margin-top: 8px;
  font-size: 0.95rem;
  color: var(--muted);
  font-style: italic;
}

/* Note box */

.note-box {
  background: #f9fbf6;
  border-left: 4px solid var(--accent);
  padding: 14px 16px;
  margin: 18px 0;
  border-radius: 6px;
}

/* Cards / grids */

.code-grid,
.diagram-grid,
.quick-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
  margin-top: 16px;
}

.code-card,
.diagram-card,
.quick-card {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 10px;
  padding: 16px;
}

.code-card h3,
.diagram-card h3,
.quick-card h3 {
  margin-top: 0;
  color: var(--heading);
}

.diagram-card img {
  width: 100%;
  height: auto;
  border-radius: 8px;
  border: 1px solid #ddd;
  background: white;
  display: block;
}

.diagram-card figcaption {
  margin-top: 10px;
  font-size: 0.95rem;
  color: #555;
}

.quick-card p,
.code-card p {
  margin-bottom: 10px;
}

/* Stats */

.stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(220px, 1fr));
  gap: 16px;
  max-width: 700px;
  margin: 18px 0 24px;
}

.stat {
  background: #eef5e8;
  border: 1px solid #d7e4cd;
  border-radius: 10px;
  padding: 16px;
  text-align: center;
}

.stat-label {
  display: block;
  font-size: 0.95rem;
  color: var(--heading);
  font-weight: 700;
  margin-bottom: 6px;
}

.stat-value {
  display: block;
  font-size: 1.35rem;
  font-weight: 700;
}

/* Buttons */

.repo-button {
  display: inline-block;
  background: var(--accent);
  color: var(--accent-gold);
  padding: 10px 16px;
  border-radius: 8px;
  font-weight: 700;
}

.repo-button:hover {
  background: #255625;
  color: var(--accent-gold);
  text-decoration: none;
}

/* Tables */

.table-wrap {
  overflow-x: auto;
  margin: 18px 0 24px;
}

.doc-table {
  width: 100%;
  min-width: 620px;
  border-collapse: collapse;
  font-size: 0.97rem;
  background: white;
  border: 1px solid var(--table-border);
}

.doc-table thead th {
  background: var(--table-head-bg);
  color: var(--heading);
  font-weight: 700;
  border: 1px solid var(--table-border);
  padding: 12px 14px;
  text-align: left;
  vertical-align: top;
}

.doc-table tbody td {
  border: 1px solid var(--table-border);
  padding: 12px 14px;
  text-align: left;
  vertical-align: top;
}

.doc-table tbody tr:nth-child(even) {
  background: var(--table-row-alt);
}

.doc-table tbody tr:hover {
  background: #f5f9f1;
}

.doc-table + .doc-figure,
.doc-figure + .doc-table,
.table-wrap + .doc-figure,
.doc-figure + .table-wrap {
  margin-top: 20px;
}

/* Exact wire-color classes */

.pin-red {
  background: #ff0000;
  color: #ffffff;
  font-weight: 700;
}

.pin-black {
  background: #000000;
  color: #ffffff;
  font-weight: 700;
}

.pin-yellow {
  background: #ffff00;
  color: #000000;
  font-weight: 700;
}

.pin-blue {
  background: #00b0f0;
  color: #000000;
  font-weight: 700;
}

.pin-green {
  background: #00b050;
  color: #000000;
  font-weight: 700;
}

.pin-orange {
  background: #ffc000;
  color: #000000;
  font-weight: 700;
}

.pin-brown {
  background: #a65e2e;
  color: #ffffff;
  font-weight: 700;
}

.pin-gray {
  background: #bfbfbf;
  color: #000000;
  font-weight: 700;
}

.pin-purple {
  background: #cc66cc;
  color: #000000;
  font-weight: 700;
}

.pin-white {
  background: #ffffff;
  color: #000000;
  font-weight: 700;
}

/* Old classes kept for compatibility */

.pin-power {
  background: #ffd9d9;
  font-weight: 700;
}

.pin-ground {
  background: #e6e6e6;
  font-weight: 700;
}

.pin-motor {
  background: #d9ead3;
  font-weight: 700;
}

.pin-encoder {
  background: #cfe2ff;
  font-weight: 700;
}

.pin-line {
  background: #fff2cc;
  font-weight: 700;
}

.pin-imu {
  background: #ead1ff;
  font-weight: 700;
}

.pin-bump {
  background: #d9f2f2;
  font-weight: 700;
}

/* Optional legend */

.color-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 14px;
  margin: 12px 0 18px;
  padding: 0;
  list-style: none;
}

.color-legend li {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
}

.legend-swatch {
  width: 18px;
  height: 18px;
  border: 1px solid #bbb;
  border-radius: 4px;
  display: inline-block;
}

.legend-red { background: #ff0000; }
.legend-black { background: #000000; }
.legend-yellow { background: #ffff00; }
.legend-blue { background: #00b0f0; }
.legend-green { background: #00b050; }
.legend-orange { background: #ffc000; }
.legend-brown { background: #a65e2e; }
.legend-gray { background: #bfbfbf; }
.legend-purple { background: #cc66cc; }
.legend-white { background: #ffffff; }

/* Results badges */

.results-table .status-badge {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.88rem;
  font-weight: 700;
  line-height: 1.2;
}

.results-table .status-yes {
  background: #eaf3e4;
  color: var(--accent);
  border: 1px solid #cfe0c2;
}

.results-table .status-no {
  background: #fbeaea;
  color: #9b2c2c;
  border: 1px solid #e6bcbc;
}

/* Embedded video */

.video-embed {
  position: relative;
  width: 100%;
  max-width: 760px;
  aspect-ratio: 16 / 9;
  margin: 18px 0 26px;
  border: 1px solid #ddd;
  border-radius: 8px;
  overflow: hidden;
  background: #000;
}

.video-embed iframe {
  width: 100%;
  height: 100%;
  border: 0;
  display: block;
}

.large-video {
  max-width: 900px;
}

.video-caption {
  max-width: 900px;
  text-align: center;
  font-style: italic;
  color: var(--muted);
  margin: -4px 0 0;
}

/* Responsive */

@media (max-width: 900px) {
  .page {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
    border-right: none;
    border-bottom: 1px solid var(--sidebar-border);
  }

  .content {
    padding: 24px 18px 40px;
  }

  .code-grid,
  .diagram-grid,
  .quick-grid,
  .stats {
    grid-template-columns: 1fr;
  }

  .sidebar-subnav {
    margin-left: 12px;
  }
}

@media (max-width: 700px) {
  .doc-header h1 {
    font-size: 1.7rem;
  }

  .doc-section h2 {
    font-size: 1.35rem;
  }

  .doc-section h3 {
    font-size: 1.05rem;
  }

  .doc-table {
    font-size: 0.92rem;
    min-width: 560px;
  }

  .doc-table th,
  .doc-table td,
  .doc-table thead th,
  .doc-table tbody td {
    padding: 10px 10px;
  }
}
