/* ==========================================================================
   NPCAgent — command deck
   One hand-written stylesheet. No framework, no build step, no remote assets.
   ========================================================================== */

/* --- tokens ------------------------------------------------------------- */

:root {
  color-scheme: light dark;

  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas,
    "Liberation Mono", "Courier New", monospace;

  --measure: 78ch;
  --rail: 16rem;
  --gap: clamp(1rem, 2.4vw, 2rem);

  /* page surface — flips with theme */
  --bg: #f2f0e9;
  --bg2: #e9e6dc;
  --panel: #fcfbf7;
  --ink: #171b19;
  --ink2: #3b4340;
  --dim: #656e69;
  --rule: #d9d5c9;
  --rule2: #c6c1b2;
  --accent: #0e6b45;
  --accent2: #8a5511;
  --mark: rgba(233, 196, 106, 0.4);
  --shadow: 0 1px 0 rgba(23, 27, 25, 0.06), 0 10px 30px -18px rgba(23, 27, 25, 0.5);

  /* terminal surface — intentionally constant across themes.
     A terminal on your desk does not repaint itself for light mode. */
  --t-bg: #0b100e;
  --t-chrome: #161d1a;
  --t-ink: #cfe0d6;
  --t-dim: #7f9189;
  --t-rule: #24302c;
  --t-green: #6fe3a4;
  --t-cyan: #62d2cf;
  --t-blue: #85b3ec;
  --t-magenta: #dc9dd4;
  --t-yellow: #ebc46c;
  --t-red: #f28d7c;

  /* diagram palette — readable on both page themes */
  --d-line: #7c857f;
  --d-fill: #ffffff;
  --d-fill2: #efece2;
  --d-ink: #171b19;
  --d-dim: #656e69;
  --d-a: #0e6b45; /* kernel / primary */
  --d-a-fill: #dcefe4;
  --d-b: #1f5f86; /* planner */
  --d-b-fill: #dbeaf3;
  --d-c: #8a5511; /* plugins */
  --d-c-fill: #f5e8d4;
  --d-d: #7a2f4a; /* terminal / failure */
  --d-d-fill: #f4dde4;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #090c0b;
    --bg2: #0d1211;
    --panel: #101614;
    --ink: #d5e3db;
    --ink2: #aec0b7;
    --dim: #7f8f88;
    --rule: #1c2724;
    --rule2: #2a3733;
    --accent: #6fe3a4;
    --accent2: #ebc46c;
    --mark: rgba(111, 227, 164, 0.24);
    --shadow: 0 1px 0 rgba(255, 255, 255, 0.03), 0 18px 40px -24px #000;

    --d-line: #63736c;
    --d-fill: #101614;
    --d-fill2: #16201d;
    --d-ink: #d5e3db;
    --d-dim: #8f9f98;
    --d-a: #6fe3a4;
    --d-a-fill: #12261d;
    --d-b: #85b3ec;
    --d-b-fill: #131e2b;
    --d-c: #ebc46c;
    --d-c-fill: #251e10;
    --d-d: #f28d7c;
    --d-d-fill: #26150f;
  }
}

/* --- reset -------------------------------------------------------------- */

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--mono);
  font-size: clamp(0.875rem, 0.82rem + 0.2vw, 0.95rem);
  line-height: 1.7;
  font-variant-ligatures: none;
}

img {
  max-width: 100%;
  height: auto;
}

svg {
  max-width: 100%;
  height: auto;
  display: block;
}

a {
  color: var(--accent);
  text-underline-offset: 0.2em;
  text-decoration-thickness: 1px;
}

a:hover {
  background: var(--mark);
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 2px;
}

hr {
  border: 0;
  border-top: 1px solid var(--rule);
  margin: 2rem 0;
}

/* --- skip link ---------------------------------------------------------- */

.skip {
  position: absolute;
  left: -9999px;
  top: 0;
  z-index: 100;
  background: var(--panel);
  color: var(--ink);
  padding: 0.6rem 1rem;
  border: 1px solid var(--rule2);
}

.skip:focus {
  left: 0.5rem;
  top: 0.5rem;
}

/* ==========================================================================
   DECK — rail + page. No top nav bar; the command index is a persistent rail.
   ========================================================================== */

.deck {
  display: grid;
  grid-template-columns: var(--rail) minmax(0, 1fr);
  gap: var(--gap);
  max-width: 1680px;
  margin: 0 auto;
  padding: var(--gap);
  align-items: start;
}

@media (max-width: 60rem) {
  .deck {
    grid-template-columns: minmax(0, 1fr);
    padding: 0.75rem;
    gap: 0.75rem;
  }
}

/* --- rail --------------------------------------------------------------- */

.rail {
  position: sticky;
  top: var(--gap);
  border: 1px solid var(--rule);
  background: var(--panel);
  padding: 0.9rem 0.9rem 1rem;
  font-size: 0.82rem;
  box-shadow: var(--shadow);
}

@media (max-width: 60rem) {
  .rail {
    position: static;
    padding: 0.7rem;
  }
}

.rail__brand {
  display: block;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--ink);
  text-decoration: none;
  border-bottom: 1px solid var(--rule);
  padding-bottom: 0.6rem;
  margin-bottom: 0.7rem;
}

.rail__brand:hover {
  background: none;
  color: var(--accent);
}

.rail__brand b {
  color: var(--accent);
  font-weight: 700;
}

.rail__meta {
  color: var(--dim);
  font-size: 0.72rem;
  letter-spacing: 0.02em;
  font-weight: 400;
  display: block;
  margin-top: 0.15rem;
}

.rail__label {
  color: var(--dim);
  font-size: 0.68rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  margin: 0.9rem 0 0.4rem;
}

.rail__label:first-of-type {
  margin-top: 0;
}

.rail ul {
  list-style: none;
  margin: 0;
  padding: 0;
}

.rail li {
  margin: 0;
}

.rail__nav a {
  display: flex;
  gap: 0.55rem;
  align-items: baseline;
  padding: 0.24rem 0.4rem;
  color: var(--ink2);
  text-decoration: none;
  border-left: 2px solid transparent;
}

.rail__nav a:hover {
  background: var(--bg2);
  color: var(--ink);
}

.rail__nav a[aria-current="page"] {
  border-left-color: var(--accent);
  background: var(--bg2);
  color: var(--ink);
  font-weight: 700;
}

.rail__n {
  color: var(--dim);
  font-size: 0.72rem;
  flex: none;
}

.rail__nav a[aria-current="page"] .rail__n {
  color: var(--accent);
}

@media (max-width: 60rem) {
  .rail__nav {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(11rem, 1fr));
    gap: 0.1rem;
  }
}

/* ==========================================================================
   MAN PAGE
   ========================================================================== */

.page {
  min-width: 0;
}

.manhead,
.manfoot {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  font-size: 0.72rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--dim);
  border-bottom: 1px solid var(--rule);
  padding-bottom: 0.5rem;
  margin-bottom: 1.6rem;
}

.manfoot {
  border-bottom: 0;
  border-top: 1px solid var(--rule);
  padding: 0.5rem 0 0;
  margin: 2.5rem 0 0;
}

.manhead span:nth-child(2),
.manfoot span:nth-child(2) {
  text-align: center;
  flex: 1;
}

.manhead span:last-child,
.manfoot span:last-child {
  text-align: right;
}

@media (max-width: 34rem) {
  .manhead span:nth-child(2),
  .manfoot span:nth-child(2) {
    display: none;
  }
}

/* man-page section: uppercase flush-left heading, indented body */
.sec {
  margin: 0 0 2.4rem;
}

h1,
h2,
h3,
h4 {
  font-family: var(--mono);
  font-weight: 700;
  line-height: 1.3;
  margin: 0;
}

h1 {
  font-size: clamp(1.15rem, 1rem + 0.9vw, 1.6rem);
  letter-spacing: 0.02em;
  margin-bottom: 0.9rem;
}

.sec > h2 {
  font-size: 0.86rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--ink);
  border-bottom: 1px solid var(--rule);
  padding-bottom: 0.4rem;
  margin-bottom: 1rem;
}

.sec__body {
  padding-left: clamp(0rem, 2vw, 2.2rem);
}

@media (max-width: 34rem) {
  .sec__body {
    padding-left: 0;
  }
}

h3 {
  font-size: 0.92rem;
  letter-spacing: 0.06em;
  margin: 2rem 0 0.7rem;
  color: var(--ink);
}

h3::before {
  content: "› ";
  color: var(--accent);
}

h4 {
  font-size: 0.85rem;
  margin: 1.4rem 0 0.5rem;
  color: var(--ink2);
  letter-spacing: 0.04em;
}

p {
  margin: 0 0 1rem;
  max-width: var(--measure);
}

.lede {
  font-size: 1.02rem;
  color: var(--ink);
  max-width: 70ch;
}

ul,
ol {
  max-width: var(--measure);
  padding-left: 1.4rem;
  margin: 0 0 1rem;
}

li {
  margin: 0.25rem 0;
}

ul.tight li,
ol.tight li {
  margin: 0.1rem 0;
}

strong {
  font-weight: 700;
  color: var(--ink);
}

/* --- inline code + keys ------------------------------------------------- */

code {
  font-family: var(--mono);
  font-size: 0.92em;
  background: var(--bg2);
  border: 1px solid var(--rule);
  border-radius: 2px;
  padding: 0.05em 0.32em;
  color: var(--ink);
  overflow-wrap: break-word;
}

a code {
  color: inherit;
  border-color: currentColor;
  background: none;
}

kbd {
  font-family: var(--mono);
  font-size: 0.78em;
  background: var(--panel);
  border: 1px solid var(--rule2);
  border-bottom-width: 2px;
  border-radius: 3px;
  padding: 0.1em 0.4em;
  color: var(--ink2);
  white-space: nowrap;
}

/* --- definition lists (man-page OPTIONS style) -------------------------- */

.dl {
  margin: 0 0 1.4rem;
  max-width: 92ch;
}

.dl dt {
  font-weight: 700;
  color: var(--accent);
  margin-top: 1rem;
  overflow-wrap: break-word;
}

.dl dt:first-child {
  margin-top: 0;
}

.dl dt .arg {
  color: var(--dim);
  font-weight: 400;
  font-style: italic;
}

.dl dd {
  margin: 0.2rem 0 0 clamp(1rem, 3vw, 2.6rem);
  color: var(--ink2);
}

.dl dd code {
  font-size: 0.88em;
}

.dl--split dt {
  color: var(--ink);
}

.dl--split dt em {
  color: var(--dim);
  font-style: normal;
  font-weight: 400;
}

/* --- callout ------------------------------------------------------------ */

.note {
  border: 1px solid var(--rule);
  border-left: 3px solid var(--accent);
  background: var(--panel);
  padding: 0.85rem 1rem;
  margin: 1.4rem 0;
  max-width: var(--measure);
}

.note > :last-child {
  margin-bottom: 0;
}

.note__tag {
  display: block;
  font-size: 0.68rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 0.35rem;
  font-weight: 700;
}

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

.note--warn .note__tag {
  color: var(--accent2);
}

/* --- tables ------------------------------------------------------------- */

.tablewrap {
  overflow-x: auto;
  margin: 1.2rem 0 1.6rem;
  border: 1px solid var(--rule);
  background: var(--panel);
}

table {
  border-collapse: collapse;
  width: 100%;
  font-size: 0.82rem;
  min-width: 32rem;
}

caption {
  caption-side: bottom;
  text-align: left;
  color: var(--dim);
  font-size: 0.76rem;
  padding: 0.6rem 0.8rem;
  border-top: 1px solid var(--rule);
}

th,
td {
  text-align: left;
  padding: 0.42rem 0.8rem;
  border-bottom: 1px solid var(--rule);
  vertical-align: top;
}

thead th {
  font-size: 0.7rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--dim);
  background: var(--bg2);
  border-bottom: 1px solid var(--rule2);
  white-space: nowrap;
}

tbody tr:last-child td {
  border-bottom: 0;
}

td code {
  white-space: nowrap;
  background: none;
  border: 0;
  padding: 0;
  color: var(--accent);
}

td.wrap code {
  white-space: normal;
}

/* ==========================================================================
   TERMINAL SURFACES
   ========================================================================== */

.term {
  position: relative;
  background: var(--t-bg);
  border: 1px solid #000;
  border-radius: 7px;
  margin: 1.4rem 0 1.8rem;
  overflow: hidden;
  box-shadow: 0 20px 46px -26px rgba(0, 0, 0, 0.85),
    inset 0 0 0 1px rgba(255, 255, 255, 0.04);
  color: var(--t-ink);
}

/* the phosphor plate — a photographed CRT, screen-blended, kept quiet */
.term::before {
  content: "";
  position: absolute;
  inset: 0;
  background: url("phosphor.png") center / cover no-repeat;
  opacity: 0.2;
  mix-blend-mode: screen;
  pointer-events: none;
  z-index: 0;
}

.term__bar {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--t-chrome);
  border-bottom: 1px solid #000;
  padding: 0.45rem 0.7rem;
  font-size: 0.72rem;
  color: var(--t-dim);
}

.term__dots {
  display: flex;
  gap: 0.35rem;
  flex: none;
}

.term__dots i {
  width: 0.6rem;
  height: 0.6rem;
  border-radius: 50%;
  background: #3a4642;
  display: block;
}

.term__dots i:first-child {
  background: #7a3f3a;
}

.term__dots i:nth-child(2) {
  background: #7a6a35;
}

.term__dots i:nth-child(3) {
  background: #3a6a4a;
}

.term__title {
  flex: 1;
  text-align: center;
  letter-spacing: 0.06em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.term__tag {
  flex: none;
  font-size: 0.66rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--t-dim);
}

.term__body {
  position: relative;
  z-index: 1;
  margin: 0;
  padding: 0.9rem 1rem 1.1rem;
  overflow-x: auto;
  font-family: var(--mono);
  font-size: 0.8rem;
  line-height: 1.62;
  white-space: pre;
  tab-size: 2;
}

.term--lg .term__body {
  font-size: clamp(0.72rem, 0.62rem + 0.36vw, 0.86rem);
  padding: 1.1rem 1.2rem 1.4rem;
}

.term__cap {
  position: relative;
  z-index: 1;
  border-top: 1px solid var(--t-rule);
  padding: 0.5rem 1rem;
  font-size: 0.72rem;
  color: var(--t-dim);
  white-space: normal;
  line-height: 1.55;
}

.term__cap code {
  background: none;
  border: 0;
  padding: 0;
  color: var(--t-ink);
}

/* terminal text colours — mirror rich's markup in the real CLI */
.p {
  color: var(--t-green);
  font-weight: 700;
}
/* prompt */
.c {
  color: var(--t-ink);
  font-weight: 700;
}
/* typed command */
.o {
  color: var(--t-dim);
}
/* dim/comment */
.g {
  color: var(--t-green);
}
.y {
  color: var(--t-yellow);
}
.cy {
  color: var(--t-cyan);
}
.b {
  color: var(--t-blue);
}
.m {
  color: var(--t-magenta);
}
.r {
  color: var(--t-red);
}
.bd {
  font-weight: 700;
}

.cursor {
  display: inline-block;
  width: 0.6em;
  height: 1.05em;
  background: var(--t-green);
  vertical-align: text-bottom;
  opacity: 0.85;
}

@media (prefers-reduced-motion: no-preference) {
  .cursor {
    animation: blink 1.15s steps(1) infinite;
  }
}

@keyframes blink {
  50% {
    opacity: 0;
  }
}

/* ==========================================================================
   MASTHEAD (index) — the command deck itself
   ========================================================================== */

.masthead {
  margin-bottom: 2rem;
}

.masthead h1 {
  font-size: clamp(1.35rem, 1rem + 2.2vw, 2.3rem);
  letter-spacing: -0.01em;
  margin-bottom: 0.5rem;
}

.masthead h1 .dimtxt {
  color: var(--dim);
  font-weight: 400;
}

.masthead .lede {
  max-width: 68ch;
  color: var(--ink2);
}

.factbar {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(9.5rem, 1fr));
  border: 1px solid var(--rule);
  background: var(--panel);
  margin: 1.6rem 0 0;
}

.factbar div {
  padding: 0.7rem 0.9rem;
  border-right: 1px solid var(--rule);
}

.factbar div:last-child {
  border-right: 0;
}

@media (max-width: 46rem) {
  .factbar div {
    border-right: 0;
    border-bottom: 1px solid var(--rule);
  }
  .factbar div:last-child {
    border-bottom: 0;
  }
}

.factbar dt {
  font-size: 0.66rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--dim);
  margin-bottom: 0.2rem;
}

.factbar dd {
  margin: 0;
  font-weight: 700;
  color: var(--ink);
  font-size: 0.9rem;
}

/* --- command index cards (used sparingly, never as primary content) ----- */

.jump {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(15rem, 1fr));
  gap: 0;
  border: 1px solid var(--rule);
  margin: 1.2rem 0 0;
}

.jump a {
  display: block;
  padding: 0.8rem 1rem;
  border-right: 1px solid var(--rule);
  border-bottom: 1px solid var(--rule);
  text-decoration: none;
  color: var(--ink2);
  background: var(--panel);
}

.jump a:hover {
  background: var(--bg2);
  color: var(--ink);
}

.jump b {
  display: block;
  color: var(--accent);
  font-size: 0.86rem;
  margin-bottom: 0.15rem;
}

.jump span {
  font-size: 0.78rem;
  color: var(--dim);
  display: block;
  line-height: 1.5;
}

/* ==========================================================================
   FIGURES / DIAGRAMS
   ========================================================================== */

figure {
  margin: 1.8rem 0 2rem;
  border: 1px solid var(--rule);
  background: var(--panel);
  box-shadow: var(--shadow);
}

.fig__frame {
  padding: clamp(0.6rem, 1.6vw, 1.2rem);
  overflow-x: auto;
}

figcaption {
  border-top: 1px solid var(--rule);
  padding: 0.65rem 0.9rem;
  font-size: 0.76rem;
  color: var(--dim);
  line-height: 1.6;
}

figcaption b {
  color: var(--ink2);
  font-weight: 700;
}

figcaption code {
  font-size: 0.9em;
}

/* diagram primitives, driven by the --d-* tokens so both themes work */
.dg {
  font-family: var(--mono);
}

.dg .box {
  fill: var(--d-fill);
  stroke: var(--d-line);
  stroke-width: 1.2;
}

.dg .box2 {
  fill: var(--d-fill2);
  stroke: var(--d-line);
  stroke-width: 1.2;
}

.dg .box-a {
  fill: var(--d-a-fill);
  stroke: var(--d-a);
  stroke-width: 1.4;
}

.dg .box-b {
  fill: var(--d-b-fill);
  stroke: var(--d-b);
  stroke-width: 1.4;
}

.dg .box-c {
  fill: var(--d-c-fill);
  stroke: var(--d-c);
  stroke-width: 1.4;
}

.dg .box-d {
  fill: var(--d-d-fill);
  stroke: var(--d-d);
  stroke-width: 1.4;
}

.dg .dash {
  stroke-dasharray: 4 3;
}

.dg .ln {
  stroke: var(--d-line);
  stroke-width: 1.2;
  fill: none;
}

.dg .ln-a {
  stroke: var(--d-a);
  stroke-width: 1.4;
  fill: none;
}

.dg .ln-b {
  stroke: var(--d-b);
  stroke-width: 1.4;
  fill: none;
}

.dg .ln-c {
  stroke: var(--d-c);
  stroke-width: 1.4;
  fill: none;
}

.dg .ln-d {
  stroke: var(--d-d);
  stroke-width: 1.4;
  fill: none;
}

.dg text {
  fill: var(--d-ink);
  font-family: var(--mono);
  font-size: 11px;
}

.dg .t-sm {
  font-size: 9.5px;
  fill: var(--d-dim);
}

.dg .t-xs {
  font-size: 8.5px;
  fill: var(--d-dim);
}

.dg .t-bd {
  font-weight: 700;
}

.dg .t-a {
  fill: var(--d-a);
}
.dg .t-b {
  fill: var(--d-b);
}
.dg .t-c {
  fill: var(--d-c);
}
.dg .t-d {
  fill: var(--d-d);
}
.dg .t-dim {
  fill: var(--d-dim);
}

.dg .lbl {
  font-size: 9px;
  fill: var(--d-dim);
  letter-spacing: 0.08em;
}

.dg .hd {
  font-size: 9px;
  letter-spacing: 0.16em;
  fill: var(--d-dim);
}

/* ==========================================================================
   ANNOTATED SOURCE
   ========================================================================== */

.src {
  border: 1px solid var(--rule);
  background: var(--panel);
  margin: 1.3rem 0 1.7rem;
  overflow: hidden;
}

.src__hd {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: baseline;
  background: var(--bg2);
  border-bottom: 1px solid var(--rule);
  padding: 0.45rem 0.8rem;
  font-size: 0.74rem;
  color: var(--dim);
  flex-wrap: wrap;
}

.src__hd b {
  color: var(--ink2);
  font-weight: 700;
  overflow-wrap: anywhere;
}

.src__code {
  margin: 0;
  padding: 0.8rem 0.9rem;
  overflow-x: auto;
  font-size: 0.78rem;
  line-height: 1.65;
  white-space: pre;
  color: var(--ink2);
  tab-size: 4;
}

.src__code .ln {
  color: var(--dim);
  opacity: 0.65;
  user-select: none;
}

.src__code .kw {
  color: var(--accent2);
}

.src__code .st {
  color: var(--accent);
}

.src__code .cm {
  color: var(--dim);
  font-style: italic;
}

.src__note {
  border-top: 1px solid var(--rule);
  padding: 0.6rem 0.9rem;
  font-size: 0.76rem;
  color: var(--dim);
  line-height: 1.6;
}

.src__note code {
  font-size: 0.9em;
}

/* ==========================================================================
   MISC
   ========================================================================== */

.fineprint {
  font-size: 0.78rem;
  color: var(--dim);
  line-height: 1.6;
}

.seealso {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1.2rem;
  padding: 0;
  margin: 0;
  list-style: none;
  max-width: none;
}

.seealso li {
  margin: 0;
}

.status {
  display: inline-block;
  font-size: 0.68rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  border: 1px solid var(--rule2);
  border-radius: 2px;
  padding: 0.05em 0.45em;
  color: var(--dim);
  white-space: nowrap;
  font-weight: 700;
}

.status--ok {
  color: var(--accent);
  border-color: var(--accent);
}

.status--part {
  color: var(--accent2);
  border-color: var(--accent2);
}

.tree {
  font-size: 0.8rem;
  line-height: 1.7;
  white-space: pre;
  overflow-x: auto;
  border: 1px solid var(--rule);
  background: var(--panel);
  padding: 0.9rem 1rem;
  margin: 1.2rem 0 1.6rem;
  color: var(--ink2);
}

.tree b {
  color: var(--accent);
}

.tree i {
  color: var(--dim);
  font-style: normal;
}
