:root {
  color-scheme: dark;
  --bg: #000;
  --bg-page: #070708;
  --bg-col: #0b0b0d;
  --ink: #ece7dc;
  --ink-soft: rgba(236, 231, 220, 0.9);
  --ink-muted: rgba(236, 231, 220, 0.55);
  --ink-dim: rgba(236, 231, 220, 0.45);
  --line: rgba(236, 231, 220, 0.12);
  --code-bg: #101214;
  --code-ink: #d8ffe6;
  --accent: #d8ffe6;
  --hud-bg: rgba(5, 5, 6, 0.55);
  --hud-ink: rgba(236, 231, 220, 0.8);
  --catalog-bg: rgba(7, 7, 8, 0.96);
  --copy-bg: rgba(16, 18, 20, 0.9);
}

html.light,
html.light body {
  color-scheme: light;
  --bg: #f3efe6;
  --bg-page: #f6f2ea;
  --bg-col: #efe9dc;
  --ink: #1c1914;
  --ink-soft: rgba(28, 25, 20, 0.92);
  --ink-muted: rgba(28, 25, 20, 0.58);
  --ink-dim: rgba(28, 25, 20, 0.42);
  --line: rgba(28, 25, 20, 0.12);
  --code-bg: #1c1f22;
  --code-ink: #d8ffe6;
  --accent: #0b6b4a;
  --hud-bg: rgba(255, 252, 246, 0.78);
  --hud-ink: #1c1914;
  --catalog-bg: rgba(246, 242, 234, 0.97);
  --copy-bg: rgba(28, 31, 34, 0.92);
}

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

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

html,
body {
  margin: 0;
  min-width: 0;
  max-width: 100%;
  height: 100%;
  background: var(--bg);
  overflow-x: hidden;
}

body.fan {
  overflow: hidden;
  width: 100%;
  height: 100%;
  height: 100dvh;
  height: 100svh;
  overscroll-behavior: none;
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: crosshair;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

body.strategy {
  min-height: 100%;
  min-height: 100dvh;
  height: auto;
  overflow-x: hidden;
  overflow-y: auto;
  background: var(--bg-page);
  color: var(--ink);
  font-family: "Iowan Old Style", Palatino, "Palatino Linotype", "Times New Roman", serif;
}

.wrap {
  display: grid;
  grid-template-columns: 1fr 1fr;
  min-height: 100vh;
  min-height: 100dvh;
  align-items: stretch;
  width: 100%;
  max-width: 100%;
  min-width: 0;
}

.col {
  padding: 48px 56px 64px;
  min-width: 0;
}

.col-strategy,
.col-build {
  display: flex;
  flex-direction: column;
}

.col-strategy {
  border-right: 1px solid var(--line);
}

.col-build {
  background: var(--bg-col);
}

.col-build h1 {
  font-size: 32px;
  margin-bottom: 18px;
  line-height: 1.12;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 36px;
}

.topbar-actions {
  display: flex;
  gap: 8px;
}

.back {
  display: inline-block;
  margin: 0;
  font-family: "SF Mono", Menlo, ui-monospace, monospace;
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-dim);
  text-decoration: none;
}

.back:hover {
  color: var(--ink);
}

.kicker {
  margin: 0 0 12px;
  font-family: "SF Mono", Menlo, ui-monospace, monospace;
  font-size: 11px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ink-dim);
}

h1 {
  margin: 0 0 14px;
  font-size: 42px;
  line-height: 1.05;
  font-weight: 600;
  letter-spacing: -0.03em;
  text-wrap: balance;
  overflow-wrap: anywhere;
}

.meta,
.horizon,
.prompt {
  font-family: "SF Mono", Menlo, ui-monospace, monospace;
  font-size: 12px;
  line-height: 1.55;
  color: var(--ink-muted);
}

.meta {
  margin: 0 0 28px;
}

.col-strategy .prose,
.col-build p {
  margin: 0 0 16px;
  font-size: 17px;
  line-height: 1.5;
  color: var(--ink-soft);
  overflow-wrap: break-word;
}

.col-build .step {
  font-size: 14px;
  line-height: 1.5;
  color: var(--ink-muted);
  margin: 0 0 10px;
}

.eq {
  margin: 0 0 18px;
  padding: 12px 8px;
  max-width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  color: var(--ink);
}

.eq .katex-display,
.eq .katex-html {
  margin: 0;
  max-width: 100%;
}

.katex-mathml {
  position: absolute !important;
  clip: rect(0, 0, 0, 0) !important;
  width: 1px !important;
  height: 1px !important;
  overflow: hidden !important;
}

.eq .katex,
.eq .katex *,
.prose .katex,
.prose .katex * {
  color: var(--ink) !important;
}

.empty {
  font-size: 15px;
  color: var(--ink-dim);
}

a.ext {
  color: var(--accent);
  text-underline-offset: 3px;
}

a.cta {
  display: inline-block;
  margin: 4px 0 10px;
  padding: 11px 16px;
  font-family: "SF Mono", Menlo, ui-monospace, monospace;
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--bg-page);
  background: var(--accent);
  text-decoration: none;
}

html.light a.cta {
  color: #f6f2ea;
}

.roles {
  width: 100%;
  max-width: 100%;
  border-collapse: collapse;
  margin: 4px 0 28px;
}

.roles th {
  text-align: left;
  font-family: "SF Mono", Menlo, ui-monospace, monospace;
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  font-weight: 500;
  color: var(--ink-dim);
  padding: 0 16px 10px 0;
  border-bottom: 1px solid var(--line);
}

.roles td {
  padding: 11px 16px 11px 0;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
  font-size: 14px;
  line-height: 1.45;
}

.roles td:first-child {
  font-family: "SF Mono", Menlo, ui-monospace, monospace;
  font-size: 12px;
  letter-spacing: 0.02em;
  white-space: nowrap;
  width: 34%;
  color: var(--ink);
}

.roles td:last-child {
  color: var(--ink-muted);
}

.cmd {
  position: relative;
  margin: 0 0 22px;
}

.cmd pre {
  margin: 0;
  padding: 16px 52px 16px 16px;
  white-space: pre-wrap;
  word-break: break-word;
}

.cmd .copy {
  position: absolute;
  top: 8px;
  right: 8px;
  min-height: 32px;
  padding: 4px 8px;
  font-family: "SF Mono", Menlo, ui-monospace, monospace;
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--code-ink);
  background: var(--copy-bg);
  border: 1px solid rgba(216, 255, 230, 0.18);
  cursor: pointer;
}

.cmd .copy:hover {
  color: #fff;
}

#masthead {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 4;
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: 8px;
  padding: max(18px, env(safe-area-inset-top, 0px)) max(18px, env(safe-area-inset-right, 0px)) 16px
    max(18px, env(safe-area-inset-left, 0px));
  pointer-events: none;
}

/* Title styled as a box to match the HUD buttons; links to AgenKit. */
#fan-title {
  margin: 0;
  display: inline-flex;
  max-width: min(520px, 100%);
  min-height: 40px;
  background: var(--hud-bg);
  border: 1px solid var(--line);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  pointer-events: auto;
}

#fan-title a {
  display: inline-flex;
  align-items: center;
  width: 100%;
  padding: 8px 12px;
  font-family: "SF Mono", Menlo, ui-monospace, monospace;
  font-size: 11px;
  line-height: 1.4;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  font-weight: 600;
  color: var(--ink);
  text-decoration: none;
  transition: color 150ms ease-out;
}

#fan-title:hover {
  border-color: var(--ink-muted);
}

#hud {
  flex-shrink: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.5s ease;
}

body.fan.settled #hud {
  opacity: 1;
}

body.fan.settled #hud .hud-btn {
  pointer-events: auto;
}

.hud-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 12px;
  min-height: 40px;
  font-family: "SF Mono", Menlo, ui-monospace, monospace;
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  text-decoration: none;
  color: var(--hud-ink);
  background: var(--hud-bg);
  border: 1px solid var(--line);
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  transition-property: color, background-color, border-color, filter;
  transition-duration: 150ms;
  transition-timing-function: ease-out;
}

.btn-ico {
  flex-shrink: 0;
  opacity: 0.85;
}

/* Hover preview card for the chart: shows which strategy a line is. */
#fan-tip {
  position: fixed;
  z-index: 6;
  left: 0;
  top: 0;
  max-width: min(300px, 82vw);
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 10px 13px 11px;
  background: var(--catalog-bg);
  border: 1px solid var(--line);
  border-left: 2px solid var(--tip-accent, var(--accent));
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  pointer-events: none;
}

#fan-tip[hidden] {
  display: none;
}

.tip-kicker {
  font-family: "SF Mono", Menlo, ui-monospace, monospace;
  font-size: 10px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-dim);
}

.tip-title {
  font-family: "Iowan Old Style", Palatino, "Palatino Linotype", "Times New Roman", serif;
  font-size: 16px;
  line-height: 1.15;
  color: var(--ink);
}

.tip-meta {
  font-family: "SF Mono", Menlo, ui-monospace, monospace;
  font-size: 11px;
  letter-spacing: 0.02em;
  color: var(--ink-muted);
}

.tip-meta:empty {
  display: none;
}

.hud-short {
  display: none;
}

a.hud-btn,
a.hud-btn:link,
a.hud-btn:visited,
a.hud-btn:hover,
a.hud-btn:active {
  display: inline-flex;
  text-decoration: none;
}

.hud-btn:hover {
  color: var(--ink);
  border-color: var(--ink-muted);
}

body.strategy .hud-btn {
  opacity: 1;
  pointer-events: auto;
}

#catalog {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: min(380px, 100vw);
  z-index: 5;
  overflow: auto;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  background: var(--catalog-bg);
  border-right: 1px solid var(--line);
  -webkit-overflow-scrolling: touch;
}

#catalog[hidden] {
  display: none;
}

.catalog-head {
  position: sticky;
  top: 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 16px 12px;
  background: var(--catalog-bg);
}

.catalog-head p {
  margin: 0;
  font-family: "SF Mono", Menlo, ui-monospace, monospace;
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-muted);
}

#catalog-close {
  min-height: 44px;
  padding: 8px 4px;
  font-family: "SF Mono", Menlo, ui-monospace, monospace;
  font-size: 11px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-muted);
  background: transparent;
  border: 0;
  cursor: pointer;
  touch-action: manipulation;
}

#catalog-list {
  margin: 0;
  padding: 0 0 24px;
  list-style: none;
}

#catalog-list a {
  display: block;
  padding: 12px 16px;
  min-height: 44px;
  font-family: "SF Mono", Menlo, ui-monospace, monospace;
  font-size: 12px;
  letter-spacing: 0.02em;
  color: var(--ink-soft);
  text-decoration: none;
  border-top: 1px solid var(--line);
  overflow-wrap: anywhere;
}

#catalog-list a:hover {
  color: var(--ink);
  background: rgba(128, 128, 128, 0.06);
}

.horizon {
  margin: 0 0 32px;
}

h2 {
  margin: 32px 0 12px;
  font-family: "SF Mono", Menlo, ui-monospace, monospace;
  font-size: 11px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  font-weight: 500;
  color: var(--ink-dim);
}

code {
  font-family: "SF Mono", Menlo, ui-monospace, monospace;
  font-size: 0.92em;
}

pre {
  margin: 0;
  padding: 18px 20px;
  overflow: auto;
  max-width: 100%;
  font-family: "SF Mono", Menlo, ui-monospace, monospace;
  font-size: 13px;
  line-height: 1.6;
  color: var(--code-ink);
  background: var(--code-bg);
  border: 1px solid rgba(216, 255, 230, 0.1);
}

.col-strategy .step {
  font-size: 15px;
  line-height: 1.5;
  color: var(--ink-muted);
  margin: 0 0 14px;
}

#math-notes .prose {
  margin-bottom: 12px;
}

@media (max-width: 900px) {
  .wrap {
    grid-template-columns: 1fr;
  }

  .col-strategy {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .col {
    padding: 28px 20px 40px;
    padding-left: max(20px, env(safe-area-inset-left, 0px));
    padding-right: max(20px, env(safe-area-inset-right, 0px));
  }

  h1 {
    font-size: 32px;
  }

  .col-build h1 {
    max-width: none;
    font-size: 28px;
  }

  .topbar {
    flex-wrap: wrap;
    align-items: flex-start;
  }

  .topbar-actions {
    flex-wrap: wrap;
  }
}

@media (max-width: 640px) {
  /* Title stacks above the controls at the top of the page. */
  #masthead {
    gap: 8px;
    padding: max(14px, env(safe-area-inset-top, 0px)) max(14px, env(safe-area-inset-right, 0px)) 12px
      max(14px, env(safe-area-inset-left, 0px));
  }

  #fan-title {
    max-width: 100%;
    min-height: 44px;
    background: rgba(7, 7, 8, 0.82);
    border-color: rgba(236, 231, 220, 0.24);
  }

  html.light #fan-title {
    background: rgba(246, 242, 234, 0.9);
    border-color: rgba(28, 25, 20, 0.18);
  }

  .hud-btn {
    min-height: 44px;
    padding: 10px 14px;
    font-size: 11px;
    letter-spacing: 0.1em;
    background: rgba(7, 7, 8, 0.82);
    border-color: rgba(236, 231, 220, 0.24);
  }

  html.light .hud-btn {
    background: rgba(246, 242, 234, 0.9);
    border-color: rgba(28, 25, 20, 0.18);
  }

  .hud-full {
    display: none;
  }

  .hud-short {
    display: inline;
  }

  #catalog {
    width: 100%;
    border-right: 0;
  }

  .col {
    padding: 20px 16px calc(36px + env(safe-area-inset-bottom, 0px));
    padding-left: max(16px, env(safe-area-inset-left, 0px));
    padding-right: max(16px, env(safe-area-inset-right, 0px));
  }

  .topbar {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
    margin-bottom: 24px;
  }

  .topbar-actions {
    width: 100%;
  }

  .topbar-actions .hud-btn {
    flex: 1 1 auto;
    text-align: center;
  }

  h1 {
    font-size: clamp(1.5rem, 7vw, 1.85rem);
  }

  .col-build h1 {
    font-size: clamp(1.35rem, 6.5vw, 1.7rem);
  }

  .col-strategy .prose,
  .col-build p {
    font-size: 16px;
  }

  .meta,
  .horizon,
  .prompt {
    overflow-wrap: anywhere;
  }

  a.cta {
    display: block;
    width: 100%;
    text-align: center;
  }

  .roles thead {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
  }

  .roles,
  .roles tbody,
  .roles tr,
  .roles td {
    display: block;
    width: 100%;
  }

  .roles td:first-child {
    width: auto;
    white-space: normal;
    padding: 14px 0 2px;
    border-bottom: 0;
  }

  .roles td:last-child {
    padding: 0 0 14px;
  }

  .cmd pre,
  pre {
    padding: 14px 16px 42px 14px;
    font-size: 12px;
  }

  .cmd .copy {
    min-height: 36px;
    min-width: 44px;
  }

  .eq .katex {
    font-size: 1.05em;
  }
}

@media (max-width: 400px) {
  .hud-btn {
    letter-spacing: 0.04em;
    padding: 10px 10px;
  }

  .col {
    padding-left: max(14px, env(safe-area-inset-left, 0px));
    padding-right: max(14px, env(safe-area-inset-right, 0px));
  }
}

@media (max-height: 500px) and (orientation: landscape) {
  #masthead {
    padding-top: max(10px, env(safe-area-inset-top, 0px));
    padding-bottom: 10px;
  }

  #hud {
    gap: 6px;
  }

  .hud-btn {
    min-height: 36px;
    padding: 6px 10px;
  }
}
