/* The Bounded Observer */

:root {
  --bg: #fbfaf8;
  --bg-sunk: #f3f1ec;
  --panel: #ffffff;
  --ink: #1b1a18;
  --ink-2: #4d4a45;
  --ink-3: #6f6a62;
  --rule: #e2ddd4;
  --accent: #b4552b;
  --accent-soft: rgba(180, 85, 43, 0.12);
  --cool: #2b6b8f;
  --good: #3f7d54;
  --warn: #a8791f;
  --bad: #9b3232;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, "Times New Roman", serif;
  --sans: ui-sans-serif, -apple-system, "Segoe UI", Inter, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;
  --measure: 34rem;
  --wide: 76rem;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #14130f;
    --bg-sunk: #1b1915;
    --panel: #1e1c18;
    --ink: #efece5;
    --ink-2: #c3beb4;
    --ink-3: #8b857a;
    --rule: #33302a;
    --accent: #e08a5c;
    --accent-soft: rgba(224, 138, 92, 0.16);
    --cool: #6fb4d8;
    --good: #74b98a;
    --warn: #d6ab52;
    --bad: #de7a7a;
  }
}
:root[data-theme="dark"] {
  --bg: #14130f; --bg-sunk: #1b1915; --panel: #1e1c18;
  --ink: #efece5; --ink-2: #c3beb4; --ink-3: #8b857a; --rule: #33302a;
  --accent: #e08a5c; --accent-soft: rgba(224, 138, 92, 0.16);
  --cool: #6fb4d8; --good: #74b98a; --warn: #d6ab52; --bad: #de7a7a;
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--serif);
  font-size: 1.0625rem;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
}

.wrap { max-width: var(--wide); margin: 0 auto; padding: 0 16px; }
.prose { max-width: var(--measure); margin-inline: auto; }

h1, h2, h3, .ui { font-family: var(--sans); }
h1 { font-size: clamp(2rem, 6vw, 3.4rem); line-height: 1.08; letter-spacing: -0.022em; font-weight: 650; margin: 0; }
.prose > h1 { margin-bottom: .65rem; }
h2 { font-size: clamp(1.45rem, 3.4vw, 2.05rem); line-height: 1.15; letter-spacing: -0.016em; font-weight: 640; margin: 0 0 .5rem; }
h3 { font-size: 1.06rem; letter-spacing: -0.004em; font-weight: 640; margin: 2rem 0 .4rem; }
p { margin: 0 0 1.05rem; }
a { color: var(--accent); text-underline-offset: 2px; text-decoration-thickness: 1px; }
a:hover { color: var(--ink); }
code, .mono { font-family: var(--mono); font-size: .89em; }
em.term { font-style: normal; font-weight: 600; }

/* ---------------------------------------------------------------- masthead */
.top {
  position: sticky; top: 0; z-index: 30;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--rule);
}
.top-in { display: flex; align-items: center; gap: 1rem; height: 52px; }
.brand { font-family: var(--sans); font-weight: 650; letter-spacing: -0.012em; text-decoration: none; color: var(--ink); font-size: .95rem; white-space: nowrap; }
.brand span { color: var(--ink-3); font-weight: 400; }
.top nav { margin-left: auto; display: flex; gap: 1.1rem; overflow-x: auto; scrollbar-width: none; }
.top nav::-webkit-scrollbar { display: none; }
.top nav a { font-family: var(--sans); font-size: .82rem; color: var(--ink-2); text-decoration: none; white-space: nowrap; }
.top nav a:hover, .top nav a[aria-current] { color: var(--accent); }

@media (max-width: 900px) {
  .top-in { display: block; height: auto; padding-top: .55rem; padding-bottom: .55rem; }
  .brand { display: block; }
  .top nav { margin: .4rem 0 0; flex-wrap: wrap; gap: .2rem .8rem; overflow: visible; }
}

/* ---------------------------------------------------------------- hero */
.hero { padding: clamp(2.2rem, 5vw, 4rem) 0 clamp(2.5rem, 7vw, 5rem); position: relative; }
.hero canvas { position: absolute; inset: 0; width: 100%; height: 100%; opacity: .5; pointer-events: none; }
.hero .prose { position: relative; }
.hero h1 { margin-bottom: 1.2rem; }
.hero-art { max-width: 68rem; margin: clamp(1.6rem, 4vw, 2.8rem) auto; position: relative; }
.hero-art img { display: block; width: 100%; height: auto; border: 1px solid var(--rule); border-radius: 12px; }
.hero-art figcaption { margin-top: .4rem; font: .75rem/1.4 var(--sans); color: var(--ink-3); text-align: right; }
@media (max-width: 640px) {
  .hero-art img { aspect-ratio: 4 / 3; object-fit: cover; }
}
.lede { font-size: clamp(1.1rem, 2.4vw, 1.3rem); color: var(--ink-2); line-height: 1.5; }
.hero-entry { display: flex; align-items: center; flex-wrap: wrap; gap: .5rem 1rem; margin: 1.4rem 0 0; }
.hero-entry span { flex: 1 1 12rem; font: .83rem/1.45 var(--sans); color: var(--ink-2); }
.sig { font-family: var(--sans); font-size: .82rem; color: var(--ink-3); margin-top: 2rem; }

.gate-index {
  display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: .7rem;
  padding-bottom: clamp(2rem, 5vw, 3.2rem);
}
.gate-index a {
  display: flex; flex-direction: column; gap: .12rem;
  border: 1px solid var(--rule); border-radius: 9px; padding: .65rem .8rem;
  text-decoration: none; font-family: var(--sans); background: var(--panel);
}
.gate-index a:hover, .gate-index a:focus-visible { border-color: var(--accent); }
.gate-index a[aria-current] { border-color: var(--accent); background: var(--accent-soft); }
.gate-index b { color: var(--ink); font-size: .82rem; }
.gate-index span { color: var(--ink-3); font-size: .74rem; line-height: 1.35; }
@media (max-width: 640px) { .gate-index { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.gate { scroll-margin-top: 90px; }

/* ---------------------------------------------------------------- sections */
.gate { border-top: 1px solid var(--rule); padding: clamp(2.5rem, 6vw, 4.5rem) 0; }
.gate-tag {
  font-family: var(--sans); font-size: .72rem; font-weight: 640; letter-spacing: .1em;
  text-transform: uppercase; color: var(--accent); margin-bottom: .55rem;
}
.gate-q { font-size: 1.12rem; color: var(--ink-2); font-style: italic; margin: -.1rem 0 1.4rem; }

/* ---------------------------------------------------------------- sim card */
.sim {
  background: var(--panel);
  border: 1px solid var(--rule);
  border-radius: 14px;
  overflow: hidden;
  margin: 1.8rem auto;
  max-width: 54rem;
  box-shadow: 0 1px 2px rgba(0,0,0,.04), 0 8px 24px -16px rgba(0,0,0,.18);
}
.sim-head { padding: 1rem 1.15rem .35rem; }
.sim-name { font-family: var(--sans); font-weight: 640; font-size: 1rem; letter-spacing: -.008em; }
.sim-do { font-family: var(--sans); font-size: .84rem; color: var(--ink-3); margin-top: .12rem; }
.stage { position: relative; background: var(--bg-sunk); border-block: 1px solid var(--rule); }
.stage canvas { display: block; width: 100%; height: 340px; touch-action: none; }
@media (max-width: 640px) { .stage canvas { height: 280px; } }
.readout {
  position: absolute; top: 10px; right: 12px;
  font-family: var(--mono); font-size: .74rem; line-height: 1.5;
  color: var(--ink-2); text-align: right; pointer-events: none;
  background: color-mix(in srgb, var(--panel) 72%, transparent);
  padding: .3rem .45rem; border-radius: 6px;
}
.readout b { color: var(--ink); font-weight: 600; }
.ctls { padding: .85rem 1.15rem; display: flex; flex-wrap: wrap; gap: .5rem 1.4rem; }
.ctl { display: flex; align-items: center; gap: .5rem; font-family: var(--sans); font-size: .8rem; color: var(--ink-2); }
.ctl-name { white-space: nowrap; }
.ctl input[type=range] { width: 122px; accent-color: var(--accent); }
.ctl output { font-family: var(--mono); font-size: .76rem; color: var(--ink); min-width: 3.2em; }
.seg { display: inline-flex; border: 1px solid var(--rule); border-radius: 8px; overflow: hidden; }
.seg button {
  font-family: var(--sans); font-size: .78rem; padding: .3rem .62rem; border: 0;
  background: transparent; color: var(--ink-2); cursor: pointer;
}
.seg button[aria-pressed=true] { background: var(--accent); color: #fff; }
.sim-note {
  padding: .8rem 1.15rem 1.05rem; border-top: 1px solid var(--rule);
  font-size: .93rem; color: var(--ink-2);
}
.sim-note b { color: var(--ink); font-weight: 600; }
.sim-src {
  font-family: var(--sans); font-size: .74rem; color: var(--ink-3);
  padding: 0 1.15rem 1rem; display: flex; flex-wrap: wrap; gap: .4rem .9rem;
}

/* ---------------------------------------------------------------- tags */
.tag {
  font-family: var(--sans); font-size: .68rem; font-weight: 650; letter-spacing: .04em;
  padding: .1rem .38rem; border-radius: 4px; vertical-align: .08em; white-space: nowrap;
}
.tag-P { background: color-mix(in srgb, var(--good) 16%, transparent); color: var(--good); }
.tag-D { background: color-mix(in srgb, var(--cool) 16%, transparent); color: var(--cool); }
.tag-H { background: color-mix(in srgb, var(--warn) 18%, transparent); color: var(--warn); }
.tag-X { background: color-mix(in srgb, var(--bad) 15%, transparent); color: var(--bad); }
.tag-M { background: color-mix(in srgb, var(--cool) 12%, transparent); color: var(--cool); }
.tag-U { background: color-mix(in srgb, var(--ink-3) 14%, transparent); color: var(--ink-2); }

/* ---------------------------------------------------------------- tables */
table { border-collapse: collapse; width: 100%; font-family: var(--sans); font-size: .86rem; }
th, td { text-align: left; padding: .5rem .6rem; border-bottom: 1px solid var(--rule); vertical-align: top; }
th { color: var(--ink-3); font-weight: 600; font-size: .76rem; text-transform: uppercase; letter-spacing: .05em; }
.scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* ---------------------------------------------------------------- misc */
.pull {
  border-left: 3px solid var(--accent); padding-left: 1rem; margin: 1.6rem 0;
  font-size: 1.12rem; color: var(--ink); line-height: 1.45;
}
.foot { border-top: 1px solid var(--rule); padding: 2.5rem 0 3.5rem; color: var(--ink-3); font-family: var(--sans); font-size: .84rem; }
.foot a { color: var(--ink-2); }
.cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 1.6rem; }
.btn {
  display: inline-block; font-family: var(--sans); font-size: .85rem; font-weight: 600;
  padding: .5rem .95rem; border-radius: 8px; text-decoration: none;
  background: var(--accent); color: #fff;
}
.btn.ghost { background: transparent; color: var(--ink); border: 1px solid var(--rule); }
.skip { position: absolute; left: -9999px; }
.skip:focus { left: 8px; top: 8px; background: var(--panel); padding: .5rem .8rem; border-radius: 6px; z-index: 100; }
