/* Portage SDK developer page (site/docs/). Builds on ../styles.css tokens; diagrams are inline SVG
   drawn by tools/site/sdk-diagrams.py and themed here. */
.docs {
  --mono: 'JetBrains Mono', ui-monospace, 'SFMono-Regular', Menlo, Consolas, monospace;
  --code-bg: #0f1720;
  --code-text: #e6edf3;
  --ok: var(--vault);
  --soon: #7a4d00;
  --soon-bg: #fff3dc;
  --pre-bg: color-mix(in srgb, var(--ink-3) 16%, transparent);
  font-size: 16px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) .docs {
    --soon: #f0b866;
    --soon-bg: #3a2a10;
    --code-bg: #0a0b0a;
  }
}
:root[data-theme='dark'] .docs {
  --soon: #f0b866;
  --soon-bg: #3a2a10;
  --code-bg: #0a0b0a;
}

.wrap-wide {
  width: min(1280px, 100% - 32px);
  margin-inline: auto;
}
.docs-tag {
  font: 600 0.78rem var(--sans);
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px 10px;
  margin-left: 4px;
}

/* Layout: sticky contents on the left, the document on the right */
.docs-layout {
  display: grid;
  grid-template-columns: 240px minmax(0, 1fr);
  gap: 56px;
  padding: 32px 0 80px;
}
.toc {
  position: sticky;
  top: 92px;
  align-self: start;
  max-height: calc(100vh - 110px);
  overflow: auto;
}
.toc-box summary {
  font: 700 0.95rem var(--display);
  cursor: pointer;
  list-style: none;
  padding: 6px 0 10px;
}
.toc-box summary::-webkit-details-marker {
  display: none;
}
.toc nav {
  display: grid;
  gap: 2px;
}
.toc-h {
  font: 700 0.72rem var(--sans);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin: 14px 0 6px;
}
.toc a {
  color: var(--muted);
  text-decoration: none;
  font-size: 0.92rem;
  padding: 5px 10px;
  border-left: 2px solid var(--line);
}
.toc a:hover {
  color: var(--text);
}
.toc a[aria-current='true'] {
  color: var(--primary);
  border-left-color: var(--primary);
  font-weight: 600;
}

/* The document */
.doc {
  min-width: 0;
  max-width: 900px;
}
.doc section {
  padding-top: 8px;
  margin-bottom: 56px;
  scroll-margin-top: 90px;
}
.doc h1 {
  font-size: clamp(2.1rem, 4.6vw, 3.2rem);
  font-weight: 800;
  letter-spacing: -0.04em;
}
.doc h2 {
  font-size: clamp(1.6rem, 3vw, 2.1rem);
  margin-bottom: 14px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}
.doc h3 {
  margin: 28px 0 10px;
  scroll-margin-top: 90px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}
.doc p,
.doc li {
  color: var(--text);
  line-height: 1.7;
}
.doc p + p {
  margin-top: 12px;
}
.doc ul,
.doc ol {
  padding-left: 22px;
  display: grid;
  gap: 8px;
  margin: 12px 0;
}
.doc code {
  font: 500 0.86em var(--mono);
  background: var(--surface-2);
  border-radius: 6px;
  padding: 1px 6px;
  overflow-wrap: anywhere;
}
.eyebrow-sm {
  font: 600 0.82rem var(--sans);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--primary);
  margin-bottom: 12px;
}
.lede-sm {
  font-size: 1.1rem;
  color: var(--muted) !important;
  margin: 16px 0 22px;
  max-width: 760px;
}
.note {
  color: var(--muted) !important;
  font-size: 0.94rem;
}

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  font: 700 0.7rem var(--sans);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  border-radius: 999px;
  padding: 3px 9px;
  white-space: nowrap;
  vertical-align: middle;
}
.badge.soon {
  color: var(--soon);
  background: var(--soon-bg);
}
.badge.ok {
  color: var(--ok);
  background: color-mix(in srgb, var(--ok) 14%, transparent);
}
.badge.pre {
  color: var(--primary);
  background: var(--pre-bg);
}
.tier {
  display: inline-block;
  font: 700 0.74rem var(--mono);
  border-radius: 6px;
  padding: 1px 6px;
  margin-right: 4px;
}
.tier.t0 {
  color: var(--unsecured);
  background: color-mix(in srgb, var(--unsecured) 14%, transparent);
}
.tier.t1 {
  color: var(--vault);
  background: color-mix(in srgb, var(--vault) 14%, transparent);
}

/* Callouts and cards */
.callout {
  border: 1px solid var(--line);
  border-left: 4px solid var(--primary);
  background: var(--surface);
  border-radius: 12px;
  padding: 14px 18px;
  margin: 18px 0;
  line-height: 1.6;
}
.callout-warn {
  border-left-color: var(--soon);
}
.cards3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
  margin-top: 22px;
}
.card-link {
  display: grid;
  gap: 6px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
  color: var(--text);
  text-decoration: none;
  transition:
    border-color 0.2s,
    transform 0.15s;
}
.card-link:hover {
  border-color: var(--primary);
  transform: translateY(-1px);
}
.card-link b {
  font-family: var(--display);
}
.card-link span {
  color: var(--muted);
  font-size: 0.92rem;
}

/* Tables */
.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 14px;
  margin: 14px 0;
}
.doc table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
}
.doc th,
.doc td {
  text-align: left;
  vertical-align: top;
  padding: 11px 14px;
  border-bottom: 1px solid var(--line);
}
.doc thead th {
  background: var(--surface);
  font-weight: 600;
  white-space: nowrap;
}
.doc tbody th {
  font-weight: 600;
  white-space: nowrap;
  width: 1%;
}
.doc tr:last-child td,
.doc tr:last-child th {
  border-bottom: 0;
}
.addr code {
  font-size: 0.82em;
}

/* Code blocks: dark in both themes */
.code {
  position: relative;
  background: var(--code-bg);
  border-radius: 14px;
  margin: 14px 0;
  border: 1px solid color-mix(in srgb, var(--code-text) 10%, transparent);
}
.code::before {
  content: attr(data-lang);
  display: block;
  font: 600 0.72rem var(--sans);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: color-mix(in srgb, var(--code-text) 55%, transparent);
  padding: 10px 16px 0;
}
.code pre {
  margin: 0;
  padding: 10px 16px 16px;
  overflow-x: auto;
}
.code pre code {
  background: none;
  padding: 0;
  color: var(--code-text);
  font: 400 0.84rem/1.65 var(--mono);
  overflow-wrap: normal;
  white-space: pre;
}
.copy-code {
  position: absolute;
  top: 7px;
  right: 8px;
  border: 1px solid color-mix(in srgb, var(--code-text) 20%, transparent);
  background: transparent;
  color: var(--code-text);
  border-radius: 999px;
  padding: 3px 11px;
  font: 600 0.74rem var(--sans);
  cursor: pointer;
}
.copy-code:hover {
  background: color-mix(in srgb, var(--code-text) 12%, transparent);
}

/* Steps, rules, timeline */
.steps li::marker {
  font-weight: 700;
  color: var(--primary);
}
.rules {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 14px;
}
.rules div {
  display: grid;
  gap: 6px;
  padding: 16px 18px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
}
.rules span {
  color: var(--muted);
  font-size: 0.93rem;
  line-height: 1.6;
}
.timeline {
  list-style: none;
  padding-left: 0 !important;
  border-left: 2px solid var(--line);
  margin-left: 8px !important;
  gap: 18px !important;
}
.timeline li {
  position: relative;
  padding-left: 24px;
  display: grid;
  gap: 4px;
}
.timeline li::before {
  content: '';
  position: absolute;
  left: -8px;
  top: 6px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--bg);
  border: 2px solid var(--line);
}
.timeline li.done::before {
  background: var(--ok);
  border-color: var(--ok);
}
.timeline li.now::before {
  background: var(--primary);
  border-color: var(--primary);
  box-shadow: 0 0 0 5px color-mix(in srgb, var(--primary) 22%, transparent);
}
.timeline li > span:last-child {
  color: var(--muted);
}
.timeline .badge {
  justify-self: start;
}

/* API reference */
.api details {
  border: 1px solid var(--line);
  border-radius: 14px;
  margin-bottom: 10px;
  background: var(--surface);
}
.api summary {
  cursor: pointer;
  padding: 14px 18px;
  font-weight: 600;
}
.api dl {
  margin: 0;
  padding: 0 18px 14px;
}
.api dt {
  margin-top: 10px;
}
.api dd {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.93rem;
  line-height: 1.6;
}

/* Wire format */
.bytes {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 16px 0;
}
.byte {
  display: grid;
  gap: 2px;
  min-width: 96px;
  padding: 10px 14px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--surface);
}
.byte.wide {
  min-width: 150px;
}
.byte.rest {
  flex: 1;
  border-style: dashed;
}
.byte b {
  font: 600 0.9rem var(--mono);
}
.byte i {
  font-style: normal;
  font-size: 0.78rem;
  color: var(--muted);
}
.codes {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.codes code.warn {
  color: var(--unsecured);
}

/* Diagrams */
.diagram {
  margin: 18px 0 22px;
}
.dg-scroll {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
  padding: 8px;
}
.dg {
  width: 100%;
  min-width: 680px;
  height: auto;
}
.diagram figcaption {
  color: var(--muted);
  font-size: 0.88rem;
  margin-top: 8px;
}
.dg-t {
  font-family: var(--sans);
  font-size: 13px;
  fill: var(--text);
}
.dg-strong {
  font-weight: 600;
}
.dg-small {
  font-size: 11px;
  fill: var(--muted);
}
.dg-label {
  font-size: 11.5px;
  fill: var(--muted);
}
.dg-group-t {
  font-size: 12px;
  font-weight: 600;
  fill: var(--muted);
}
.dg-box {
  fill: var(--bg);
  stroke: var(--line);
  stroke-width: 1.2;
}
.dg-actor,
.dg-you {
  fill: var(--surface-2);
}
.dg-chip {
  fill: var(--bg);
}
.dg-soon {
  stroke-dasharray: 5 4;
  stroke: var(--soon);
}
.dg-core {
  fill: color-mix(in srgb, var(--ink-3) 14%, var(--bg));
  stroke: color-mix(in srgb, var(--primary) 45%, transparent);
}
.dg-ext {
  fill: var(--surface-2);
}
.dg-chain {
  fill: color-mix(in srgb, var(--primary) 12%, var(--bg));
  stroke: color-mix(in srgb, var(--primary) 45%, transparent);
}
.dg-ok {
  fill: color-mix(in srgb, var(--vault) 12%, var(--bg));
  stroke: color-mix(in srgb, var(--vault) 55%, transparent);
}
.dg-bad {
  fill: color-mix(in srgb, var(--unsecured) 10%, var(--bg));
  stroke: color-mix(in srgb, var(--unsecured) 50%, transparent);
}
.dg-pending {
  fill: color-mix(in srgb, var(--ink-3) 12%, var(--bg));
  stroke: color-mix(in srgb, var(--primary) 40%, transparent);
}
.dg-group {
  fill: none;
  stroke: var(--line);
  stroke-width: 1.2;
  stroke-dasharray: 6 5;
}
.dg-line {
  fill: none;
  stroke: var(--primary);
  stroke-width: 1.5;
}
.dg-dash {
  stroke-dasharray: 6 5;
}
.dg-head {
  fill: var(--primary);
}
.dg-life {
  stroke: var(--line);
  stroke-width: 1.2;
  stroke-dasharray: 4 5;
}
.dg-note {
  fill: var(--soon-bg);
  stroke: color-mix(in srgb, var(--soon) 35%, transparent);
}
.dg-note-t {
  font-size: 12px;
  fill: var(--soon);
}
.dg-sep {
  stroke: var(--line);
  stroke-dasharray: 2 4;
}
.dg-sep-bg {
  fill: var(--surface-2);
}
.dg-sep-t {
  font-size: 11.5px;
  font-weight: 600;
  fill: var(--muted);
}

/* Small screens: contents become a collapsible box above the document */
@media (max-width: 980px) {
  .docs-layout {
    grid-template-columns: minmax(0, 1fr);
    gap: 8px;
    padding-top: 16px;
  }
  .toc {
    position: static;
    max-height: none;
  }
  .toc-box {
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 6px 16px 12px;
    background: var(--surface);
  }
  .toc nav {
    grid-template-columns: 1fr 1fr;
  }
  .toc-h {
    grid-column: 1 / -1;
  }
  .docs-tag {
    display: none;
  }
}
@media (max-width: 640px) {
  .cards3,
  .rules {
    grid-template-columns: 1fr;
  }
  .nav-tools .btn span {
    display: none;
  }
  .toc nav {
    grid-template-columns: 1fr;
  }
}
