/* ═══════════════════════════════════════════════════════════════════════════
   Berkeley Mono + Johnny.Decimal Layout
   ═══════════════════════════════════════════════════════════════════════════ */

@font-face {
  font-family: 'Berkeley Mono';
  src: url('fonts/berkeley-mono-typeface/berkeley-mono/WEB/BerkeleyMono-Regular.woff2') format('woff2'),
       url('fonts/berkeley-mono-typeface/berkeley-mono/WEB/BerkeleyMono-Regular.woff') format('woff');
  font-weight: normal;
  font-style: normal;
}

@font-face {
  font-family: 'Berkeley Mono';
  src: url('fonts/berkeley-mono-typeface/berkeley-mono/WEB/BerkeleyMono-Bold.woff2') format('woff2'),
       url('fonts/berkeley-mono-typeface/berkeley-mono/WEB/BerkeleyMono-Bold.woff') format('woff');
  font-weight: bold;
  font-style: normal;
}

:root {
  --font-family: "Berkeley Mono", monospace;
  --line-height: 1.20rem;
  --border-thickness: 2px;
  --text-color: #000;
  --text-color-alt: #666;
  --text-color-bright: #000;
  --background-color: #fff;
  --background-color-alt: #eee;
  --highlight-bg: #ddd;

  --font-weight-normal: 500;
  --font-weight-medium: 600;
  --font-weight-bold: 800;

  font-family: var(--font-family);
  font-optical-sizing: auto;
  font-weight: var(--font-weight-normal);
  font-style: normal;
  font-variant-numeric: tabular-nums lining-nums;
  font-size: 16px;

  --sidebar-width: 32ch;
  --spacing: 2ch;
}

/* Dark mode disabled - black and white only */

* {
  box-sizing: border-box;
}

* + * {
  margin-top: var(--line-height);
}

html {
  display: flex;
  width: 100%;
  margin: 0;
  padding: 0;
  flex-direction: column;
  align-items: center;
  background: var(--background-color);
  color: var(--text-color);
  scroll-behavior: smooth;
}

body {
  position: relative;
  width: 100%;
  margin: 0;
  padding: var(--spacing);
  max-width: 130ch;
  line-height: var(--line-height);
  overflow-x: hidden;
}

/* Ensure layout container takes full body width */
body > .layout {
  width: 100%;
}

/* ═══════════════════════════════════════════════════════════════════════════
   Two-Column Layout
   ═══════════════════════════════════════════════════════════════════════════ */

.layout {
  display: flex !important;
  flex-direction: row !important;
  flex-wrap: nowrap !important;
  gap: var(--spacing);
  width: 100%;
  margin: 0 !important;
  padding: 0;
  align-items: flex-start;
}

.layout > * {
  margin-top: 0 !important;
}

/* Sidebar */
.sidebar {
  display: block !important;
  position: sticky;
  top: var(--spacing);
  height: fit-content;
  max-height: calc(100vh - var(--spacing) * 2);
  overflow-y: auto;
  flex: 0 0 var(--sidebar-width) !important;
  width: var(--sidebar-width) !important;
  min-width: var(--sidebar-width) !important;
  margin: 0 !important;
  padding-top: calc(0.5 * var(--line-height));  /* Room for box header above border */
}

.sidebar::-webkit-scrollbar {
  width: 1ch;
}

.sidebar::-webkit-scrollbar-track {
  background: var(--background-color-alt);
}

.sidebar::-webkit-scrollbar-thumb {
  background: var(--text-color-alt);
}

/* Main content */
.content {
  display: block !important;
  flex: 1 1 auto !important;
  min-width: 0;
  max-width: 80ch;
  margin: 0 !important;
  padding-top: calc(0.5 * var(--line-height));  /* Match sidebar for alignment */
}

/* ═══════════════════════════════════════════════════════════════════════════
   Box Components (ASCII-style borders)
   ═══════════════════════════════════════════════════════════════════════════ */

.sidebar-box,
.content-box {
  position: relative;
  border: var(--border-thickness) solid var(--text-color);
  padding: calc(var(--line-height) * 1.5) 1ch 1ch 1ch;
  margin: 0;
}

.box-header {
  position: absolute;
  top: calc(-0.4 * var(--line-height));
  left: 1ch;
  background: var(--background-color);
  padding: 0 1ch;
  color: var(--text-color-alt);
  font-size: 1rem;
  margin: 0;
  margin-top: 0vh;
}

/* ═══════════════════════════════════════════════════════════════════════════
   Sidebar Navigation
   ═══════════════════════════════════════════════════════════════════════════ */

.sidebar-nav {
  font-size: 0.9rem;
  margin: 0;
}

.nav-tree {
  list-style: none;
  padding: 0;
  margin: 0;
}

.nav-tree ul {
  list-style: none;
  padding-left: 2ch;
  margin: 0;
}

.nav-tree li {
  position: relative;
  padding: 0;
  margin: 0;
}

.nav-tree li + li {
  margin-top: 0;
}

/* Area level (top level groups like 00-09, 10-19) */
.area {
  margin-bottom: var(--line-height);
}

.area-code {
  color: var(--text-color-bright);
  font-weight: var(--font-weight-bold);
  display: inline;
}

.area-code a {
  color: var(--text-color-bright);
  text-decoration: none;
  pointer-events: auto;
  display: inline;
}

.area-code a:hover {
  text-decoration: underline;
}

.area-title {
  color: var(--text-color-bright);
  display: inline;
}

a.area-title {
  color: var(--text-color-bright);
  text-decoration: none;
  display: inline;
}

a.area-title:hover {
  text-decoration: underline;
}

/* Category level */
.category {
  margin: calc(var(--line-height) / 2) 0;
}

/* Make nav links block-level to ensure they receive clicks */
.nav-tree .category ul > li > a {
  display: block;
}

.cat-code {
  color: var(--text-color);
}

.cat-title {
  color: var(--text-color);
  text-decoration: underline;
}

/* ID codes */
.id-code {
  color: var(--text-color-alt);
  margin-right: 0.5ch;
}

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

.nav-tree a:hover {
  color: var(--text-color-bright);
  text-decoration: underline;
}


/* Active/current item */
.nav-tree li.active {
  background: var(--highlight-bg);
}

.nav-tree li.active > a {
  color: var(--text-color-bright);
}

/* Tree lines */
.nav-tree .category > ul {
  border-left: var(--border-thickness) solid var(--text-color-alt);
  margin-left: 0.5ch;
  padding-left: 1.5ch;
}

.nav-tree .category > ul > li::before {
  content: "";
  position: absolute;
  left: calc(-1.5ch - var(--border-thickness) / 2);
  top: calc(var(--line-height) / 2);
  width: 1ch;
  border-bottom: var(--border-thickness) solid var(--text-color-alt);
}

/* ═══════════════════════════════════════════════════════════════════════════
   Page Navigation (in-page section links)
   ═══════════════════════════════════════════════════════════════════════════ */

.page-nav {
  margin: 0 0 var(--line-height) 0;
  padding-bottom: var(--line-height);
  border-bottom: var(--border-thickness) dashed var(--text-color-alt);
}

.page-nav a {
  display: block;
  color: var(--text-color);
  text-decoration: underline;
  margin: 0;
}

.page-nav a + a {
  margin-top: 0;
}

.page-nav a:hover {
  color: var(--text-color-bright);
}

/* ═══════════════════════════════════════════════════════════════════════════
   Content Styles
   ═══════════════════════════════════════════════════════════════════════════ */

.page-content {
  margin: 0;
}

.page-content > *:first-child {
  margin-top: 0;
}

h1, h2, h3, h4, h5, h6 {
  font-weight: var(--font-weight-bold);
  margin: calc(var(--line-height) * 2) 0 var(--line-height);
  line-height: var(--line-height);
}

h1 {
  font-size: 1.5rem;
  line-height: calc(2 * var(--line-height));
  margin-bottom: var(--line-height);
  color: var(--text-color-bright);
}

h2 {
  font-size: 1rem;
  text-transform: uppercase;
  color: var(--text-color-bright);
  padding-top: var(--line-height);
  border-top: var(--border-thickness) dashed var(--text-color-alt);
}

h2:first-of-type {
  border-top: none;
  padding-top: 0;
}

hr {
  position: relative;
  display: block;
  height: var(--line-height);
  margin: calc(var(--line-height) * 1.5) 0;
  border: none;
  color: var(--text-color);
}

hr:after {
  display: block;
  content: "";
  position: absolute;
  top: calc(var(--line-height) / 2 - var(--border-thickness));
  left: 0;
  width: 100%;
  border-top: calc(var(--border-thickness) * 3) double var(--text-color);
  height: 0;
}

a {
  text-decoration-thickness: var(--border-thickness);
}

a:link, a:visited {
  color: var(--text-color);
}

p {
  margin-bottom: var(--line-height);
}

strong {
  font-weight: var(--font-weight-bold);
  color: var(--text-color-bright);
}

em {
  font-style: italic;
  color: var(--text-color-bright);
}

code {
  font-family: var(--font-family);
  font-weight: var(--font-weight-medium);
  background: var(--background-color-alt);
  padding: 0 0.5ch;
}

pre {
  white-space: pre;
  overflow-x: auto;
  margin: var(--line-height) 0;
  overflow-y: hidden;
  background: var(--background-color-alt);
  padding: 1ch;
  border: var(--border-thickness) solid var(--text-color-alt);
}

pre code {
  background: none;
  padding: 0;
}

figure {
  margin: calc(var(--line-height) * 2) 0;
  overflow-x: auto;
  overflow-y: hidden;
}

figure pre {
  margin: 0;
  border: var(--border-thickness) solid var(--text-color);
}

figcaption {
  display: block;
  font-style: italic;
  margin-top: var(--line-height);
  color: var(--text-color-alt);
}

/* Tables */
table {
  position: relative;
  top: calc(var(--line-height) / 2);
  width: calc(round(down, 100%, 1ch));
  border-collapse: collapse;
  margin: 0 0 calc(var(--line-height) * 2);
}

th, td {
  border: var(--border-thickness) solid var(--text-color);
  padding: calc((var(--line-height) / 2)) calc(1ch - var(--border-thickness) / 2) calc((var(--line-height) / 2) - (var(--border-thickness)));
  line-height: var(--line-height);
  vertical-align: top;
  text-align: left;
}

th {
  font-weight: var(--font-weight-bold);
  background: var(--background-color-alt);
}

/* Lists */
ul, ol {
  padding: 0;
  margin: 0 0 var(--line-height);
}

ul {
  list-style-type: square;
  padding: 0 0 0 2ch;
}

ol {
  list-style-type: none;
  counter-reset: item;
  padding: 0;
}

ol li:before {
  content: counters(item, ".") ". ";
  counter-increment: item;
  font-weight: var(--font-weight-medium);
}

li {
  margin: 0;
  padding: 0;
}

ol ul, ol ol, ul ol, ul ul {
  padding: 0 0 0 3ch;
  margin: 0;
}

/* Details */
details {
  border: var(--border-thickness) solid var(--text-color);
  padding: calc(var(--line-height) - var(--border-thickness)) 1ch;
  margin-bottom: var(--line-height);
}

summary {
  font-weight: var(--font-weight-medium);
  cursor: pointer;
}

details[open] summary {
  margin-bottom: var(--line-height);
}

/* Media */
img, video {
  display: block;
  width: 100%;
  object-fit: contain;
  overflow: hidden;
}

img {
  font-style: italic;
  color: var(--text-color-alt);
}

/* Forms */
input, button, textarea {
  border: var(--border-thickness) solid var(--text-color);
  padding: calc(var(--line-height) / 2 - var(--border-thickness)) calc(1ch - var(--border-thickness));
  margin: 0;
  font: inherit;
  font-weight: inherit;
  height: calc(var(--line-height) * 2);
  width: auto;
  overflow: visible;
  background: var(--background-color);
  color: var(--text-color);
  line-height: normal;
  -webkit-appearance: none;
}

button {
  text-transform: uppercase;
  font-weight: var(--font-weight-medium);
  cursor: pointer;
}

button:hover {
  background: var(--background-color-alt);
}

input:focus, button:focus {
  outline: var(--border-thickness) solid var(--text-color-bright);
  outline-offset: 1px;
}

label {
  display: block;
  width: calc(round(down, 100%, 1ch));
  height: auto;
  line-height: var(--line-height);
  font-weight: var(--font-weight-medium);
  margin: 0;
}

label input {
  width: 100%;
}

/* Grid */
.grid {
  --grid-cells: 0;
  display: flex;
  gap: 1ch;
  width: calc(round(down, 100%, (1ch * var(--grid-cells)) - (1ch * var(--grid-cells) - 1)));
  margin-bottom: var(--line-height);
}

.grid > *, .grid > input {
  flex: 0 0 calc(round(down, (100% - (1ch * (var(--grid-cells) - 1))) / var(--grid-cells), 1ch));
}

.grid:has(> :last-child:nth-child(1)) { --grid-cells: 1; }
.grid:has(> :last-child:nth-child(2)) { --grid-cells: 2; }
.grid:has(> :last-child:nth-child(3)) { --grid-cells: 3; }
.grid:has(> :last-child:nth-child(4)) { --grid-cells: 4; }
.grid:has(> :last-child:nth-child(5)) { --grid-cells: 5; }
.grid:has(> :last-child:nth-child(6)) { --grid-cells: 6; }

/* Tree visualization */
.tree, .tree ul {
  position: relative;
  padding-left: 0;
  list-style-type: none;
  line-height: var(--line-height);
}

.tree ul {
  margin: 0;
}

.tree ul li {
  position: relative;
  padding-left: 1.5ch;
  margin-left: 1.5ch;
  border-left: var(--border-thickness) solid var(--text-color);
}

.tree ul li:before {
  position: absolute;
  display: block;
  top: calc(var(--line-height) / 2);
  left: 0;
  content: "";
  width: 1ch;
  border-bottom: var(--border-thickness) solid var(--text-color);
}

.tree ul li:last-child {
  border-left: none;
}

.tree ul li:last-child:after {
  position: absolute;
  display: block;
  top: 0;
  left: 0;
  content: "";
  height: calc(var(--line-height) / 2);
  border-left: var(--border-thickness) solid var(--text-color);
}

/* ═══════════════════════════════════════════════════════════════════════════
   Responsive Design
   ═══════════════════════════════════════════════════════════════════════════ */

@media screen and (max-width: 900px) {
  .layout {
    flex-direction: column !important;
  }
  
  .sidebar {
    position: static !important;
    width: 100% !important;
    min-width: 100% !important;
    flex: 0 0 auto !important;
    max-height: none;
    overflow: visible;
  }
  
  .sidebar-box {
    max-height: 50vh;
    overflow-y: auto;
  }
  
  .content {
    width: 100% !important;
    max-width: 100% !important;
  }
}

@media screen and (max-width: 480px) {
  :root {
    font-size: 14px;
  }
  
  body {
    padding: var(--line-height) 1ch;
  }
}

/* Debug utilities removed */

:target {
  scroll-margin-top: 2em;
}

::selection {
  background: var(--text-color);
  color: var(--background-color);
}

.page-content > p {
  margin-bottom: 3.0rem;
}