/* Box Archive Format Specification - Stylesheet */

@import url('https://fonts.googleapis.com/css2?family=Archivo:ital,wght@0,400;0,500;0,600;0,700;1,400;1,500&display=swap');
@import url('https://cdn.jsdelivr.net/npm/iosevka-webfont@13.0.1/iosevka.min.css');

:root {
  --text-primary: #1a1a1a;
  --text-secondary: #4a4a4a;
  --text-muted: #6a6a6a;
  --bg-body: #ffffff;
  --bg-code: #f6f8fa;
  --bg-table-header: #f0f2f4;
  --bg-table-alt: #fafbfc;
  --border-color: #d0d7de;
  --border-light: #e5e7eb;
  --accent: #0969da;
  --accent-hover: #0550ae;
  --content-width: 52rem;
  --sidebar-width: 20rem;
  --gap: 2.5rem;
}

* {
  box-sizing: border-box;
}

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: 'Archivo', system-ui, -apple-system, sans-serif;
  font-size: 1rem;
  line-height: 1.7;
  color: var(--text-primary);
  background: var(--bg-body);
  max-width: var(--content-width);
  margin: 0 auto;
  padding: 3rem 2rem 6rem;
}

/* Large screen: sidebar layout */
@media (min-width: 1100px) {
  body {
    max-width: var(--content-width);
    margin-left: calc(var(--sidebar-width) + var(--gap) + ((100vw - var(--content-width) - var(--sidebar-width) - var(--gap)) / 2));
    margin-right: auto;
    padding-right: 2rem;
  }

  /* TOC becomes fixed sidebar */
  nav[role="doc-toc"] {
    position: fixed;
    left: calc((100vw - var(--content-width) - var(--sidebar-width) - var(--gap)) / 2);
    top: 3rem;
    width: var(--sidebar-width);
    max-height: calc(100vh - 6rem);
    overflow-y: auto;
    margin: 0;
    padding: 1.25rem 1.5rem;
    font-size: 0.875rem;
    border-radius: 8px;
  }

  nav[role="doc-toc"] h2 {
    font-size: 0.8rem;
    margin-bottom: 0.75rem;
  }

  nav[role="doc-toc"] a {
    font-size: 0.8rem;
  }

  nav[role="doc-toc"] .prefix {
    min-width: 2rem;
  }

  nav[role="doc-toc"] > ol > li {
    margin: 0.5rem 0;
  }

  nav[role="doc-toc"] > ol > li > ol {
    padding-left: 1.25rem;
  }

  /* Scrollbar styling for TOC */
  nav[role="doc-toc"]::-webkit-scrollbar {
    width: 6px;
  }

  nav[role="doc-toc"]::-webkit-scrollbar-track {
    background: transparent;
  }

  nav[role="doc-toc"]::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 3px;
  }

  nav[role="doc-toc"]::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
  }
}

/* Title block */
body > div:first-child {
  margin-bottom: 3rem;
  padding-bottom: 2rem;
  border-bottom: 1px solid var(--border-color);
}

body > div:first-child > p:first-child {
  font-size: 2.25rem;
  font-weight: 700;
  line-height: 1.2;
  margin: 0 0 1rem;
  letter-spacing: -0.02em;
}

body > div:first-child > p:last-child {
  font-size: 0.95rem;
  color: var(--text-secondary);
  margin: 0;
}

/* Table of contents */
nav[role="doc-toc"] {
  background: var(--bg-code);
  border: 1px solid var(--border-light);
  border-radius: 6px;
  padding: 1.5rem 2rem;
  margin-bottom: 3rem;
}

nav[role="doc-toc"] h2 {
  font-size: 1rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin: 0 0 1rem;
  padding: 0;
  border: none;
}

nav[role="doc-toc"] ol {
  margin: 0;
  padding: 0;
}

nav[role="doc-toc"] li {
  margin: 0.25rem 0;
  line-height: 1.5;
}

nav[role="doc-toc"] > ol > li {
  margin: 0.75rem 0;
}

nav[role="doc-toc"] > ol > li > ol {
  margin-top: 0.25rem;
  padding-left: 1.5rem;
}

nav[role="doc-toc"] a {
  color: var(--text-primary);
  text-decoration: none;
  font-size: 0.9rem;
}

nav[role="doc-toc"] a:hover {
  color: var(--accent);
}

nav[role="doc-toc"] span[style] {
  text-decoration: none !important;
}

nav[role="doc-toc"] .prefix {
  display: inline-block;
  min-width: 2.5rem;
  color: var(--text-muted);
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}

/* Headings */
h2, h3, h4, h5, h6 {
  font-family: 'Archivo', system-ui, sans-serif;
  font-weight: 600;
  line-height: 1.3;
  color: var(--text-primary);
  margin-top: 3rem;
  margin-bottom: 1rem;
}

h2 {
  font-size: 1.75rem;
  padding-bottom: 0.5rem;
  border-bottom: 2px solid var(--border-color);
  letter-spacing: -0.01em;
}

h3 {
  font-size: 1.25rem;
  margin-top: 2.5rem;
}

h4 {
  font-size: 1.1rem;
  margin-top: 2rem;
}

/* Paragraphs */
p {
  margin: 0 0 1rem;
}

/* Links */
a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

span[style*="underline"] {
  text-decoration: none !important;
}

span[style*="underline"] a {
  text-decoration: none;
}

span[style*="underline"] a:hover {
  text-decoration: underline;
}

/* Strong/emphasis */
strong {
  font-weight: 600;
}

em {
  font-style: italic;
}

/* Lists */
ul, ol {
  margin: 0 0 1rem;
  padding-left: 1.75rem;
}

li {
  margin: 0.35rem 0;
}

li > ul,
li > ol {
  margin: 0.35rem 0;
}

/* Inline code */
code {
  font-family: 'Iosevka', 'SF Mono', 'Consolas', monospace;
  font-size: 0.875em;
}

span[style*="inline-block"] code {
  background: var(--bg-code);
  padding: 0.15em 0.4em;
  border-radius: 4px;
  font-size: 0.85em;
}

/* Code blocks */
div > pre {
  background: var(--bg-code);
  border: 1px solid var(--border-light);
  border-radius: 6px;
  padding: 1rem 1.25rem;
  overflow-x: auto;
  margin: 0 0 1rem;
}

div > pre code {
  background: none;
  padding: 0;
  font-size: 0.875rem;
  line-height: 1.6;
}

/* Tables */
table {
  width: 100%;
  border-collapse: collapse;
  margin: 0 0 1rem;
  font-size: 0.925rem;
}

thead {
  background: var(--bg-table-header);
}

th {
  font-weight: 600;
  text-align: left;
  padding: 0.75rem 1rem;
  border: 1px solid var(--border-color);
}

td {
  padding: 0.6rem 1rem;
  border: 1px solid var(--border-color);
  vertical-align: top;
  text-align: left;
}

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

/* Figures with captions */
figure {
  margin: 1.5rem 0;
}

figcaption {
  font-size: 0.875rem;
  color: var(--text-secondary);
  margin-top: 0.5rem;
  font-style: italic;
}

/* Structure diagram tables (in figures, no thead) */
figure > table:not(:has(thead)) {
  width: auto;
}

figure > table:not(:has(thead)) td:first-child {
  font-family: 'Iosevka', 'SF Mono', 'Consolas', monospace;
  font-size: 0.9rem;
  color: var(--text-muted);
  white-space: nowrap;
  text-align: right;
  padding-right: 1.5rem;
}

figure > table:not(:has(thead)) td:nth-child(2) {
  font-weight: 600;
  text-align: left;
}

figure > table:not(:has(thead)) td:last-child:not(:nth-child(2)) {
  color: var(--text-secondary);
  font-size: 0.9rem;
  text-align: left;
}

/* Nested tables in divs (binary layouts) */
div > table {
  width: auto;
  margin: 0 0 1rem;
}

div > table td {
  padding: 0.35rem 0.75rem;
  border: none;
  border-bottom: 1px solid var(--border-light);
}

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

/* Hex dump table (binary layout in figure) */
figure > table:has(thead) td {
  text-align: center;
  font-family: 'Iosevka', monospace;
  font-size: 0.85rem;
  padding: 0.4rem 0.5rem;
}

figure > table:has(thead) td:first-child {
  text-align: right;
  font-weight: 500;
  color: var(--text-primary);
}

/* Responsive */
@media (max-width: 768px) {
  body {
    padding: 2rem 1.25rem 4rem;
  }

  body > div:first-child > p:first-child {
    font-size: 1.75rem;
  }

  h2 {
    font-size: 1.5rem;
  }

  h3 {
    font-size: 1.15rem;
  }

  nav[role="doc-toc"] {
    padding: 1.25rem 1.5rem;
  }

  table {
    font-size: 0.85rem;
  }

  th, td {
    padding: 0.5rem 0.75rem;
  }

  div > pre {
    padding: 0.875rem 1rem;
  }
}

/* Print styles */
@media print {
  body {
    display: block;
    max-width: none;
    padding: 0;
    font-size: 11pt;
  }

  nav[role="doc-toc"] {
    position: static;
    max-height: none;
    overflow: visible;
    page-break-after: always;
  }

  h2, h3 {
    page-break-after: avoid;
  }

  table, figure {
    page-break-inside: avoid;
  }

  a {
    color: var(--text-primary);
  }
}
