/* ==========================================================================
   How Software Is Built — page styles

   The page is two layers: a full-viewport canvas ("The Works") pinned behind
   everything, and the article floating on top of it in translucent panels.
   The article layer is pointer-transparent except for the panels themselves,
   so dragging the margins still moves the map underneath.
   ========================================================================== */

:root {
  --grass:      #6fae52;
  --grass-dk:   #4f8a3a;
  --sky:        #bfe6f5;
  --moat:       #3a86a8;
  --slab:       #b9c1b8;
  --ink:        #16232c;
  --ink-soft:   #46606f;
  --paper:      #fbf7ec;
  --paper-2:    #f2ebd9;
  --panel-bg:   rgba(251, 247, 236, .93);
  --panel-bg-2: rgba(242, 235, 217, .86);
  --line:       #ddd2b6;
  --accent:     #e8663c;   /* attention */
  --accent-2:   #f2a93b;   /* requests */
  --violet:     #7a5cc4;   /* static assets */
  --cyan:       #2fb3c9;   /* identity */
  --blue:       #2f7fd0;   /* data */
  --magenta:    #d05fb8;   /* model calls */
  --green:      #5bbd4f;   /* success */
  --red:        #e0384a;   /* refused, failed */
  --shadow:     0 2px 0 rgba(22, 35, 44, .18), 0 14px 30px rgba(22, 35, 44, .16);
  --radius:     14px;
  --maxw:       880px;
  --mono: ui-monospace, "SF Mono", "SFMono-Regular", Menlo, Consolas, monospace;
  --sans: "Trebuchet MS", "Segoe UI", system-ui, -apple-system, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --sky:        #16323f;
    --ink:        #ecf3f6;
    --ink-soft:   #a8c0cc;
    --paper:      #12222b;
    --paper-2:    #172c37;
    --panel-bg:   rgba(15, 30, 38, .90);
    --panel-bg-2: rgba(23, 44, 55, .84);
    --line:       #2b4553;
    --shadow:     0 2px 0 rgba(0, 0, 0, .35), 0 14px 30px rgba(0, 0, 0, .45);
  }
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; scroll-padding-top: 112px; }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }

body {
  margin: 0;
  font-family: var(--sans);
  font-size: 17px;
  line-height: 1.65;
  color: var(--ink);
  background: var(--sky);
  -webkit-text-size-adjust: 100%;
}

.wrap { max-width: var(--maxw); margin: 0 auto; padding: 0 20px; }

a { color: var(--accent); text-decoration-thickness: 2px; text-underline-offset: 2px; }
a:hover { color: var(--accent-2); }

code, kbd {
  font-family: var(--mono);
  font-size: .88em;
  background: var(--paper-2);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: .08em .38em;
}

:focus-visible { outline: 3px solid var(--violet); outline-offset: 2px; }

/* ------------------------------------------------------- the world layer  */

.world {
  position: fixed;
  inset: 0;
  z-index: 0;
  background: linear-gradient(180deg, #d6eefa 0%, #bfe6f5 46%, #a9dcef 100%);
}
@media (prefers-color-scheme: dark) {
  .world { background: linear-gradient(180deg, #16394a 0%, #123040 50%, #0d2632 100%); }
}

.world canvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: grab;
  touch-action: pan-y;         /* let the page scroll vertically over the map */
}
.world canvas.dragging { cursor: grabbing; }
body.article-hidden .world canvas { touch-action: none; }

/* A scrim that keeps text readable over a busy, animated map. It lifts
   almost entirely when the map is being explored. */
.veil {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(120% 80% at 50% 0%, rgba(255, 255, 255, .34), transparent 60%),
    linear-gradient(180deg, rgba(255, 255, 255, .10), rgba(255, 255, 255, .34));
  transition: opacity .45s ease;
}
@media (prefers-color-scheme: dark) {
  .veil {
    background:
      radial-gradient(120% 80% at 50% 0%, rgba(4, 14, 20, .38), transparent 60%),
      linear-gradient(180deg, rgba(4, 14, 20, .22), rgba(4, 14, 20, .48));
  }
}
body.article-hidden .veil { opacity: 0; }

/* --------------------------------------------------------- article layer  */

.page {
  position: relative;
  z-index: 2;
  pointer-events: none;        /* the gutters belong to the map */
  transition: opacity .35s ease, transform .35s ease;
}
body.article-hidden .page {
  opacity: 0;
  transform: translateY(14px);
  pointer-events: none;
}
body.article-hidden { overflow: hidden; }

/* everything a reader actually touches opts back in */
.panel, .hero-card, .toc, .dock, .inspector { pointer-events: auto; }

/* ---------------------------------------------- show / hide the article  */

.text-toggle {
  position: fixed;
  top: 12px;
  right: 14px;
  z-index: 26;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-family: var(--sans);
  font-size: 13.5px;
  font-weight: 700;
  color: var(--ink);
  background: var(--panel-bg);
  border: 2px solid var(--line);
  border-bottom-width: 3px;
  border-radius: 999px;
  padding: 6px 14px;
  cursor: pointer;
  box-shadow: var(--shadow);
  backdrop-filter: blur(9px);
  -webkit-backdrop-filter: blur(9px);
  transition: transform .08s ease, background .15s ease;
}
.text-toggle:hover { border-color: var(--ink-soft); }
.text-toggle:active { transform: translateY(2px); border-bottom-width: 2px; }
.text-toggle .tt-icon { font-size: 15px; line-height: 1; }
body.article-hidden .text-toggle {
  background: var(--accent);
  border-color: #b44e2c;
  color: #fff;
}

/* …and opts back out while the map has the screen, so a faded-out panel
   cannot quietly swallow a click meant for a building behind it */
body.article-hidden .page .panel,
body.article-hidden .page .hero-card,
body.article-hidden .page .toc { pointer-events: none; }

.panel, .hero-card {
  background: var(--panel-bg);
  border: 2px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  backdrop-filter: blur(7px);
  -webkit-backdrop-filter: blur(7px);
}

/* ----------------------------------------------------------------- hero  */

.hero { padding: min(16vh, 120px) 0 26px; }

.hero-card { padding: 26px 28px 22px; }

.hero h1 {
  margin: 0 0 10px;
  font-size: clamp(32px, 6vw, 54px);
  line-height: 1.05;
  letter-spacing: -.02em;
}

.hero p.lede {
  margin: 0;
  max-width: 62ch;
  font-size: clamp(17px, 2.3vw, 21px);
  color: var(--ink-soft);
}

.hero-hint {
  margin: 16px 0 0;
  font-size: 14.5px;
  line-height: 2;
  color: var(--ink-soft);
}

.eyebrow {
  display: inline-block;
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: .16em;
  text-transform: uppercase;
  color: var(--ink-soft);
  border: 1px solid var(--line);
  background: var(--paper-2);
  border-radius: 999px;
  padding: 4px 12px;
  margin-bottom: 16px;
}

/* ------------------------------------------------------------------ toc  */

.toc {
  position: sticky;
  top: 56px;                 /* below the show/hide toggle, at every width */
  z-index: 5;
  max-width: calc(var(--maxw) - 8px);
  margin: 0 auto 4px;
  background: var(--panel-bg-2);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 2px solid var(--line);
  border-radius: 999px;
  box-shadow: var(--shadow);
}
.toc ul {
  display: flex;
  gap: 4px;
  overflow-x: auto;
  list-style: none;
  margin: 0;
  padding: 7px 12px;
  scrollbar-width: thin;
}
.toc a {
  white-space: nowrap;
  font-size: 13px;
  font-weight: 700;
  text-decoration: none;
  color: var(--ink-soft);
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 4px 10px;
}
.toc a:hover { background: var(--paper-2); border-color: var(--line); color: var(--ink); }
.toc a.current { background: var(--accent); border-color: var(--accent); color: #fff; }

/* ------------------------------------------------------------- sections  */

main { padding-top: 14px; }

main section.panel {
  padding: 4px 26px 22px;
  margin: 22px 0;
}

h2 {
  font-size: clamp(24px, 3.6vw, 32px);
  line-height: 1.15;
  margin: 24px 0 6px;
  letter-spacing: -.01em;
}
h2 .num {
  font-family: var(--mono);
  font-size: .6em;
  color: var(--accent);
  margin-right: .5em;
}
h3 { font-size: 20px; margin: 24px 0 4px; }

p { margin: 12px 0; }
p.sub { color: var(--ink-soft); }

ul, ol { padding-left: 22px; }
li { margin: 7px 0; }

.card {
  background: var(--panel-bg-2);
  border: 2px solid var(--line);
  border-left-width: 6px;
  border-left-color: var(--cyan);
  border-radius: 12px;
  padding: 14px 16px;
  margin: 18px 0;
}
.card h4 { margin: 0 0 6px; font-size: 15px; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-soft); }
.card p:last-child { margin-bottom: 0; }
.card.warn { border-left-color: var(--accent-2); }
.card.green { border-left-color: var(--grass-dk); }

.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 14px; margin: 18px 0; }

.tile {
  background: var(--panel-bg-2);
  border: 2px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
}
.tile h4 { margin: 0 0 4px; font-size: 16px; }
.tile p { margin: 0; font-size: 15px; color: var(--ink-soft); }

table { width: 100%; border-collapse: collapse; margin: 18px 0; font-size: 15px; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { background: var(--panel-bg-2); font-size: 13px; text-transform: uppercase; letter-spacing: .05em; color: var(--ink-soft); }
.table-scroll { overflow-x: auto; }

.trace {
  font-family: var(--mono);
  font-size: 13.5px;
  line-height: 1.6;
  background: #12222b;
  color: #d7e8ef;
  border-radius: 12px;
  padding: 14px 16px;
  overflow-x: auto;
  border: 2px solid #0b171e;
  white-space: pre;
}
.trace .c { color: #7fa7b6; }
.trace .k { color: #8fd06a; }
.trace .g { color: #f2a93b; }

footer {
  margin-top: 34px;
  padding: 0 0 140px;
  color: var(--ink-soft);
  font-size: 15px;
}
footer .panel { padding: 18px 24px; }
footer a { color: var(--ink); }

/* ------------------------------------------------------------------ hud  */

/* The counters are the map's own instrumentation, so they appear when the map
   is what you are looking at — while reading, they would just collide with the
   sticky table of contents. */
.hud {
  position: fixed;
  top: 10px; left: 10px;
  z-index: 8;
  display: none;
  gap: 8px;
  flex-wrap: wrap;
  max-width: 60vw;
  pointer-events: none;
}
body.article-hidden .hud { display: flex; }

.chip {
  font-family: var(--mono);
  font-size: 11.5px;
  background: rgba(18, 34, 43, .78);
  color: #eaf6fb;
  border-radius: 8px;
  padding: 3px 9px;
  white-space: nowrap;
}
.chip b { color: var(--accent-2); font-weight: 700; }

/* ----------------------------------------------------------------- dock  */

.dock {
  position: fixed;
  left: 50%;
  bottom: 12px;
  transform: translateX(-50%);
  z-index: 20;
  width: min(1000px, calc(100vw - 20px));
  background: var(--panel-bg);
  border: 2px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  backdrop-filter: blur(9px);
  -webkit-backdrop-filter: blur(9px);
}

.dock-handle {
  position: absolute;
  top: -16px;
  left: 14px;
  font-family: var(--sans);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--ink-soft);
  background: var(--paper-2);
  border: 2px solid var(--line);
  border-radius: 999px;
  padding: 2px 12px;
  cursor: pointer;
}
.dock-handle:hover { color: var(--ink); }
.dock[data-open="false"] .dock-body { display: none; }
.dock[data-open="false"] { width: auto; left: 12px; transform: none; }
.dock[data-open="false"] .dock-handle { position: static; display: block; }

.dock-body { padding: 12px 14px 11px; }

.narrator {
  display: flex;
  gap: 11px;
  align-items: flex-start;
  margin-bottom: 10px;
}
.narrator .step-no {
  flex: none;
  width: 28px; height: 28px;
  border-radius: 8px;
  display: grid; place-items: center;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  font-family: var(--mono);
  font-size: 13px;
}
.narrator .step-text { margin: 0; font-size: 15px; line-height: 1.45; }
.narrator .step-text strong { display: block; }
.narrator .step-text span { color: var(--ink-soft); font-size: 14.5px; }

.controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
  font-size: 13px;
}
.controls label { display: inline-flex; align-items: center; gap: 7px; color: var(--ink-soft); font-weight: 700; }
.controls label.check { font-weight: 400; }
input[type="range"] { accent-color: var(--accent); width: 104px; }
input[type="checkbox"] { accent-color: var(--accent); }

button.btn, select.btn {
  font-family: var(--sans);
  font-size: 14px;
  font-weight: 700;
  color: var(--ink);
  background: var(--paper);
  border: 2px solid var(--line);
  border-bottom-width: 3px;
  border-radius: 10px;
  padding: 5px 11px;
  cursor: pointer;
  transition: transform .08s ease, background .15s ease;
}
button.btn:hover, select.btn:hover { border-color: var(--ink-soft); }
button.btn:active { transform: translateY(2px); border-bottom-width: 2px; }
button.btn.primary, button.btn[aria-pressed="true"] {
  background: var(--accent);
  border-color: #b44e2c;
  color: #fff;
}
.icon-btn { min-width: 36px; text-align: center; }

.legend { display: flex; flex-wrap: wrap; gap: 5px 13px; margin-top: 9px; font-size: 12.5px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; color: var(--ink-soft); }
.legend i {
  width: 11px; height: 11px;
  border-radius: 3px;
  display: inline-block;
  transform: rotate(45deg);
  border: 1px solid rgba(0, 0, 0, .25);
}

/* ------------------------------------------------------------ inspector  */

.inspector {
  position: fixed;
  top: 62px;                 /* clear of the show/hide toggle */
  right: 14px;
  z-index: 22;
  width: min(310px, calc(100vw - 28px));
  padding: 14px 16px 15px;
  background: var(--panel-bg);
  border: 2px solid var(--line);
  border-left: 6px solid var(--cyan);
  border-radius: 12px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(9px);
  -webkit-backdrop-filter: blur(9px);
}
.inspector h3 { margin: 0; font-size: 18px; }
.inspector .insp-sub {
  margin: 2px 0 8px;
  font-family: var(--mono);
  font-size: 11.5px;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--ink-soft);
}
.inspector p { margin: 0 0 10px; font-size: 14.5px; color: var(--ink-soft); }
.inspector .insp-link { font-size: 13.5px; font-weight: 700; text-decoration: none; }
.inspector-close {
  position: absolute;
  top: 8px; right: 8px;
  border: none;
  background: transparent;
  color: var(--ink-soft);
  font-size: 15px;
  cursor: pointer;
  line-height: 1;
  padding: 4px;
}
.inspector-close:hover { color: var(--ink); }

/* ----------------------------------------------------------- focus hint  */

.hint-bar {
  position: fixed;
  top: 44px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 18;
  font-size: 12.5px;
  color: #eaf6fb;
  background: rgba(18, 34, 43, .8);
  border-radius: 999px;
  padding: 6px 16px;
  pointer-events: none;
  text-align: center;
  max-width: calc(100vw - 24px);
}
.hint-bar kbd {
  background: rgba(255, 255, 255, .12);
  border-color: rgba(255, 255, 255, .25);
  color: #fff;
  margin: 0 1px;
}

/* --------------------------------------------------------------- mobile  */

@media (max-width: 760px) {
  body { font-size: 16px; }
  .hero { padding-top: 54px; }
  .hero-card { padding: 20px 18px 18px; }
  main section.panel { padding: 2px 18px 18px; margin: 16px 0; }
  .toc { border-radius: 14px; }
  .dock { bottom: 8px; }
  .dock-body { padding: 9px 10px 8px; }
  .legend, .hint-bar { display: none; }
  footer { padding-bottom: 130px; }

  /* the dock has to stay a strip, not a panel: narration plus the two
     controls that matter, with the rest revealed once the map has the screen */
  .narrator { margin-bottom: 8px; gap: 9px; }
  .narrator .step-no { width: 24px; height: 24px; font-size: 12px; }
  .narrator .step-text { font-size: 14px; }
  .narrator .step-text span { display: none; }
  .controls { gap: 6px 8px; }
  button.btn, select.btn { font-size: 13px; padding: 4px 9px; border-bottom-width: 2px; }
  .icon-btn { min-width: 32px; }
  .controls label[for="scenario"] { flex: 1 1 100%; min-width: 0; gap: 6px; }
  .controls select.btn { flex: 1 1 auto; min-width: 0; }
  .controls label[for="speed"], .controls label.check { display: none; }
  body:not(.article-hidden) .controls .icon-btn,
  body:not(.article-hidden) .controls #restartBtn { display: none; }
  body.article-hidden .controls label.check { display: inline-flex; }

  .inspector { top: auto; bottom: 106px; right: 8px; left: 8px; width: auto; }
  #hitChip, #errChip { display: none; }   /* one row of counters, not three */

  .text-toggle { top: 8px; right: 8px; font-size: 12.5px; padding: 5px 11px; gap: 5px; }
  .toc { top: 48px; }
  .hud { top: 50px; }        /* the toggle owns the top-right corner */
}

@media (prefers-reduced-motion: reduce) {
  .page, .veil { transition: none; }
}
