:root {
  color-scheme: dark;
  --bg: #111111;
  --text: #ececec;
  --muted: #9a9a9a;
  --faint: #6e6e6e;
  --line: #2a2a2a;
  --fill: #1a1a1a;
  --accent: #6ea8ff;
  --ok: #4caf7a;
  --warn: #d4a017;
  --danger: #d35a5a;
  --overlay: rgba(0, 0, 0, 0.62);
  --grid-dot: rgba(255, 255, 255, 0.14);
  --wire: #4dabf7;
}

html[data-theme="light"] {
  color-scheme: light;
  --bg: #f4f4f2;
  --text: #171717;
  --muted: #5a5a5a;
  --faint: #8b8b8b;
  --line: #d8d8d2;
  --fill: #ffffff;
  --accent: #2c6fd4;
  --ok: #2e8a58;
  --warn: #b57a00;
  --danger: #c43c3c;
  --overlay: rgba(20, 20, 20, 0.38);
  --grid-dot: rgba(0, 0, 0, 0.1);
  --wire: #228be6;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 ui-sans-serif, system-ui, -apple-system, sans-serif;
}

html {
  scroll-padding-top: 6.5rem;
}

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

a:hover {
  text-decoration: underline;
}

.chrome {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
  padding-bottom: 0.75rem;
}

.top {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.15rem 0;
  max-width: 880px;
  margin: 0 auto;
  padding: 1rem 1.25rem 0;
  color: var(--muted);
  font-size: 0.85rem;
}

.top .sep {
  margin: 0 0.4rem;
  color: var(--faint);
}

.top .home {
  color: var(--muted);
}

.top strong {
  color: var(--text);
  font-weight: 600;
}

.top-actions {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
}

.theme-toggle,
.edit-toggle {
  appearance: none;
  width: 1.55rem;
  height: 1.55rem;
  margin-left: 0;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.theme-toggle:hover,
.edit-toggle:hover {
  color: var(--text);
}

.theme-toggle svg,
.edit-toggle svg {
  width: 0.95rem;
  height: 0.95rem;
  display: block;
}

html[data-theme="dark"] .theme-toggle .icon-moon,
html:not([data-theme]) .theme-toggle .icon-moon {
  display: none;
}

html[data-theme="light"] .theme-toggle .icon-sun {
  display: none;
}

.edit-actions {
  display: inline-flex;
  align-items: center;
  gap: 0.65rem;
}

.edit-actions[hidden],
.edit-toggle[hidden] {
  display: none;
}

.edit-save {
  appearance: none;
  border: 1px solid color-mix(in srgb, var(--ok) 55%, transparent);
  background: color-mix(in srgb, var(--ok) 22%, var(--fill));
  color: var(--text);
  border-radius: 999px;
  padding: 0.28rem 0.85rem;
  font: inherit;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
}

.edit-save:hover {
  background: color-mix(in srgb, var(--ok) 34%, var(--fill));
}

.edit-save:disabled {
  opacity: 0.6;
  cursor: wait;
}

.edit-cancel {
  color: var(--muted);
  font-size: 0.8rem;
  text-decoration: none;
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
  font: inherit;
}

.edit-cancel:hover {
  color: var(--text);
  text-decoration: underline;
}

body.is-editing main.page.doc {
  outline: 1px dashed color-mix(in srgb, var(--accent) 55%, transparent);
  outline-offset: 6px;
  border-radius: 4px;
}

body.is-editing main.page.doc:focus {
  outline-color: var(--accent);
}

.nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  max-width: 880px;
  margin: 0.85rem auto 0;
  padding: 0 1.25rem;
}

.nav a {
  display: inline-flex;
  align-items: center;
  height: 28px;
  padding: 0 0.65rem;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  font-size: 0.8rem;
  text-decoration: none;
}

.nav a:hover {
  color: var(--text);
  text-decoration: none;
}

.nav a.is-active {
  border-color: var(--accent);
  color: var(--text);
  background: var(--fill);
}

.page {
  max-width: 880px;
  margin: 0 auto;
  padding: 1.25rem 1.25rem 3.5rem;
}

.meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin: 0 0 1.1rem;
}

.pill {
  display: inline-flex;
  align-items: center;
  height: 22px;
  padding: 0 0.5rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.72rem;
  letter-spacing: 0.02em;
}

h1 {
  margin: 0 0 0.55rem;
  font-size: 1.55rem;
  font-weight: 650;
  letter-spacing: -0.02em;
  line-height: 1.25;
}

h2 {
  margin: 1.75rem 0 0.65rem;
  font-size: 1.15rem;
  font-weight: 650;
}

h3 {
  margin: 1.2rem 0 0.45rem;
  font-size: 0.98rem;
  font-weight: 650;
}

p {
  margin: 0 0 0.85rem;
}

.lead {
  color: var(--muted);
  font-size: 0.98rem;
}

ul,
ol {
  margin: 0 0 1rem;
  padding-left: 1.2rem;
}

li {
  margin: 0.22rem 0;
}

li + li {
  margin-top: 0.28rem;
}

pre {
  margin: 0 0 1rem;
  padding: 0.85rem 0.95rem;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--fill);
  font: 12.5px/1.45 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  white-space: pre;
}

code {
  font: 0.9em/1.4 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

p code,
li code,
td code {
  padding: 0.05rem 0.28rem;
  border-radius: 4px;
  background: var(--fill);
  border: 1px solid var(--line);
}

table {
  width: 100%;
  border-collapse: collapse;
  margin: 0 0 1.1rem;
  font-size: 0.9rem;
}

th,
td {
  text-align: left;
  vertical-align: top;
  padding: 0.5rem 0.55rem;
  border-bottom: 1px solid var(--line);
}

th {
  color: var(--muted);
  font-weight: 600;
  font-size: 0.78rem;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.callout {
  margin: 0 0 1.1rem;
  padding: 0.8rem 0.9rem;
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  border-radius: 8px;
  background: var(--fill);
}

.callout.warn {
  border-left-color: var(--warn);
}

.callout strong {
  display: block;
  margin-bottom: 0.25rem;
}

.toc {
  display: grid;
  gap: 0.55rem;
  margin: 1rem 0 0;
}

.toc a {
  display: block;
  padding: 0.75rem 0.85rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--fill);
  color: var(--text);
  text-decoration: none;
}

.toc a:hover {
  border-color: var(--accent);
  text-decoration: none;
}

.toc a span {
  display: block;
  color: var(--muted);
  font-size: 0.82rem;
  margin-top: 0.2rem;
}

.pager {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 0.75rem;
  margin-top: 2rem;
  padding-top: 1rem;
  border-top: 1px solid var(--line);
}

.pager a {
  color: var(--accent);
}

.muted {
  color: var(--muted);
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--overlay);
  padding: 1rem;
}

.modal-backdrop[hidden] {
  display: none;
}

.modal {
  width: min(22rem, 100%);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 1.1rem 1.15rem 1.15rem;
}

.modal h2 {
  margin: 0 0 0.35rem;
  font-size: 1.05rem;
}

.modal p {
  margin: 0 0 0.85rem;
  color: var(--muted);
}

.modal input[type="password"] {
  width: 100%;
  background: var(--fill);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 6px;
  padding: 0.45rem 0.65rem;
  font: inherit;
  margin-bottom: 0.75rem;
}

.auth-error {
  color: var(--danger);
  font-size: 0.85rem;
  margin: -0.35rem 0 0.7rem;
}

.auth-error[hidden] {
  display: none;
}

.row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

button.ghost,
button.sec {
  appearance: none;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--text);
  border-radius: 6px;
  padding: 0.3rem 0.65rem;
  font: inherit;
  font-size: 0.85rem;
  cursor: pointer;
}

button.sec {
  background: var(--fill);
}

.page.doc h1 {
  font-size: 1.45rem;
  margin-top: 0.35rem;
}

.page.doc h2 {
  scroll-margin-top: 1rem;
  padding-top: 0.35rem;
  border-top: 1px solid var(--line);
}

.page.doc h2:first-of-type {
  border-top: 0;
}

.page.doc hr {
  border: 0;
  border-top: 1px solid var(--line);
  margin: 1.4rem 0;
}

.page.doc table th:empty,
.page.doc table td:empty {
  display: none;
}

.arch-board {
  position: relative;
  margin: 1.1rem 0 1.4rem;
  padding: 1.1rem 0.85rem 1.25rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background-color: var(--bg);
  background-image: radial-gradient(circle, var(--grid-dot) 0.8px, transparent 1px);
  background-size: 10px 10px;
  overflow: hidden;
}

.arch-wires {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 1;
  overflow: visible;
}

.arch-wire {
  fill: none;
  stroke: var(--wire);
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.arch-wire-arrow {
  fill: none;
  stroke: var(--wire);
  stroke-width: 1.15;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.arch-wire-label {
  fill: var(--muted);
  font-size: 11px;
  font-family: ui-sans-serif, system-ui, -apple-system, sans-serif;
}

.arch-items {
  position: relative;
  z-index: 2;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  column-gap: 1.4rem;
  row-gap: 2.4rem;
  max-width: 34rem;
  margin: 0 auto;
  padding: 0.35rem 0 0.5rem;
}

.arch-slot-portal,
.arch-slot-shell {
  grid-column: 1 / -1;
  justify-self: center;
  width: min(100%, 18rem);
}

.arch-slot-mav,
.arch-slot-fc {
  grid-column: 1;
}

.arch-slot-rtsp,
.arch-slot-cam {
  grid-column: 2;
}

.arch-card {
  position: relative;
  border: 1px solid var(--card-accent, var(--line));
  border-radius: 8px;
  background:
    linear-gradient(
      color-mix(in srgb, var(--card-accent, transparent) 14%, transparent),
      color-mix(in srgb, var(--card-accent, transparent) 14%, transparent)
    ),
    var(--fill);
  padding: 0.65rem 0.7rem;
  width: 100%;
  min-width: 0;
}

.arch-card h3 {
  margin: 0 0 0.25rem;
  font-size: 0.72rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 600;
}

.arch-card p {
  margin: 0;
  padding-right: 1.15rem;
  color: var(--text);
  font-size: 0.82rem;
  line-height: 1.35;
}

.arch-card .card-gear {
  appearance: none;
  position: absolute;
  right: 0.28rem;
  bottom: 0.28rem;
  z-index: 2;
  width: 1.2rem;
  height: 1.2rem;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  opacity: 0.5;
}

.arch-card .card-gear:hover,
.arch-card .card-gear:focus-visible,
.arch-card.is-picking .card-gear {
  opacity: 1;
  color: var(--text);
  outline: none;
}

.arch-card .card-gear svg {
  width: 0.8rem;
  height: 0.8rem;
  display: block;
}

.arch-card .card-swatches {
  display: none;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem;
  margin-top: 0.55rem;
  padding-top: 0.5rem;
  padding-right: 1.35rem;
  border-top: 1px solid color-mix(in srgb, var(--line) 80%, transparent);
}

.arch-card.is-picking .card-swatches {
  display: flex;
}

.arch-card.is-picking .card-gear {
  bottom: 0.42rem;
}

.arch-card .swatch {
  appearance: none;
  width: 1rem;
  height: 1rem;
  margin: 0;
  padding: 0;
  border-radius: 50%;
  border: 1px solid color-mix(in srgb, var(--text) 18%, transparent);
  background: var(--swatch);
  cursor: pointer;
  box-shadow: inset 0 0 0 1px color-mix(in srgb, #fff 35%, transparent);
}

.arch-card .swatch:hover,
.arch-card .swatch:focus-visible {
  outline: none;
  box-shadow:
    0 0 0 2px var(--bg),
    0 0 0 3.5px color-mix(in srgb, var(--swatch) 70%, var(--text));
}

.arch-card .swatch.is-active {
  box-shadow:
    0 0 0 2px var(--bg),
    0 0 0 3.5px var(--text);
}

.arch-card .swatch-reset {
  background:
    linear-gradient(
      135deg,
      transparent 46%,
      color-mix(in srgb, var(--muted) 70%, transparent) 46%,
      color-mix(in srgb, var(--muted) 70%, transparent) 54%,
      transparent 54%
    ),
    var(--fill);
  border-style: dashed;
}

@media (max-width: 640px) {
  table {
    display: block;
    overflow-x: auto;
  }

  .arch-items {
    grid-template-columns: 1fr;
    max-width: 18rem;
  }

  .arch-slot-portal,
  .arch-slot-shell,
  .arch-slot-mav,
  .arch-slot-rtsp,
  .arch-slot-fc,
  .arch-slot-cam {
    grid-column: 1;
    width: 100%;
    justify-self: stretch;
  }
}
