:root {
  --bg: #f5f4ef;
  --panel: #fbfaf6;
  --ink: #15181d;
  --muted: #69707b;
  --line: rgba(21, 24, 29, 0.14);
  --line-strong: rgba(21, 24, 29, 0.28);
  --accent: #0e84a5;
  --accent-soft: #dff2f6;
  --amber: #a8681a;
  --term-bg: #10191b;
  --term-panel: #142226;
  --term-header: #1a2a2f;
  --term-text: #edf3ef;
  --term-muted: #91a4a6;
  --term-green: #a8d8bd;
  --term-cyan: #88d8e4;
  --term-red: #e98b82;
  --term-line: rgba(237, 243, 239, 0.11);
  --radius: 8px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--bg);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
}

body {
  min-height: 100vh;
  margin: 0;
  overflow-x: hidden;
  background:
    linear-gradient(rgba(21, 24, 29, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(21, 24, 29, 0.035) 1px, transparent 1px),
    radial-gradient(circle at 80% 8%, rgba(14, 132, 165, 0.12), transparent 32%),
    var(--bg);
  background-size: 42px 42px, 42px 42px, auto, auto;
}

button,
input {
  font: inherit;
}

button {
  border: 1px solid var(--line);
  background: rgba(251, 250, 246, 0.82);
  color: var(--ink);
  cursor: pointer;
}

button:hover {
  border-color: var(--line-strong);
  transform: translateY(-1px);
}

button:focus-visible,
a:focus-visible,
input:focus-visible {
  outline: 2px solid rgba(14, 132, 165, 0.65);
  outline-offset: 3px;
}

a {
  color: inherit;
}

.shell {
  width: min(1440px, 100%);
  min-height: 100vh;
  margin: 0 auto;
  padding: 24px;
}

.topbar {
  display: flex;
  width: 100%;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding-bottom: 20px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
}

.brand__mark {
  display: grid;
  width: 44px;
  height: 44px;
  place-items: center;
  border: 1px solid var(--ink);
  border-radius: var(--radius);
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 13px;
  letter-spacing: 0;
}

.brand strong,
.brand small {
  display: block;
}

.brand strong {
  font-size: 15px;
}

.brand small {
  color: var(--muted);
  font-size: 12px;
}

.nav-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.nav-actions button {
  min-height: 40px;
  padding: 0 14px;
  border-radius: 999px;
  transition: transform 160ms ease, border-color 160ms ease, background 160ms ease;
}

.agent-button {
  border-color: rgba(14, 132, 165, 0.42);
  background: var(--accent);
  color: white;
}

.hero-grid {
  display: grid;
  grid-template-columns: minmax(360px, 0.95fr) minmax(420px, 1.35fr);
  align-items: start;
  min-height: calc(100vh - 230px);
  border: 1px solid var(--line);
  background: rgba(251, 250, 246, 0.72);
  backdrop-filter: blur(18px);
}

.terminal-panel,
.stage-panel {
  min-width: 0;
}

.terminal-panel {
  display: grid;
  grid-template-rows: 44px minmax(0, 1fr) auto 54px;
  height: min(720px, calc(100vh - 136px));
  min-height: 520px;
  overflow: hidden;
  border-right: 1px solid rgba(21, 24, 29, 0.3);
  background:
    linear-gradient(180deg, rgba(223, 242, 246, 0.055), transparent 24%),
    var(--term-bg);
  color: var(--term-text);
}

.terminal-panel__header,
.stage-panel__meta {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 48px;
  padding: 0 16px;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 12px;
}

.terminal-panel__header {
  min-height: 44px;
  border-bottom-color: var(--term-line);
  background: var(--term-header);
  color: var(--term-muted);
  box-shadow: inset 0 -1px rgba(251, 250, 246, 0.055);
}

.terminal-panel__header::before {
  content: "";
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: rgba(251, 250, 246, 0.34);
  box-shadow: 17px 0 rgba(136, 216, 228, 0.52), 34px 0 rgba(14, 132, 165, 0.84);
}

.terminal-dot {
  width: 7px;
  height: 7px;
  margin-left: 42px;
  border-radius: 50%;
  background: var(--term-cyan);
  box-shadow: 0 0 18px rgba(136, 216, 228, 0.34);
}

.terminal-panel__status,
#stage-index {
  margin-left: auto;
}

.terminal-output {
  overflow-x: hidden;
  overflow-y: scroll;
  min-height: 0;
  padding: 18px 16px 28px;
  background:
    linear-gradient(rgba(237, 243, 239, 0.018) 1px, transparent 1px),
    var(--term-bg);
  background-size: 100% 28px;
  color: var(--term-text);
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 13px;
  line-height: 1.55;
  scrollbar-color: rgba(136, 216, 228, 0.34) rgba(237, 243, 239, 0.045);
  scrollbar-width: thin;
}

.terminal-output::-webkit-scrollbar {
  width: 10px;
}

.terminal-output::-webkit-scrollbar-track {
  background: rgba(237, 243, 239, 0.045);
}

.terminal-output::-webkit-scrollbar-thumb {
  border: 2px solid var(--term-bg);
  border-radius: 999px;
  background: rgba(136, 216, 228, 0.36);
}

.terminal-output::-webkit-scrollbar-thumb:hover {
  background: rgba(136, 216, 228, 0.56);
}

.terminal-line {
  margin: 0 0 10px;
  white-space: pre-wrap;
}

.terminal-line[data-kind="command"] {
  color: var(--term-cyan);
}

.terminal-line[data-kind="error"] {
  color: var(--term-red);
}

.terminal-line a {
  color: var(--term-cyan);
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}

.command-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--term-line);
  background: linear-gradient(180deg, rgba(237, 243, 239, 0.025), transparent), var(--term-panel);
}

.command-suggestions button {
  min-height: 32px;
  padding: 0 10px;
  border-color: rgba(237, 243, 239, 0.16);
  border-radius: 6px;
  background: rgba(237, 243, 239, 0.045);
  color: var(--term-text);
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 12px;
  transition: transform 160ms ease, border-color 160ms ease, background 160ms ease;
}

.command-suggestions button:hover {
  border-color: rgba(98, 214, 232, 0.52);
  background: rgba(98, 214, 232, 0.12);
}

.terminal-input-row {
  display: grid;
  grid-template-columns: auto auto 1fr;
  align-items: center;
  gap: 10px;
  min-height: 54px;
  padding: 0 16px;
  border-top: 1px solid var(--term-line);
  background: #0d1517;
  color: var(--term-text);
  font-family: "SFMono-Regular", Consolas, monospace;
}

.terminal-input-row label {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
}

.terminal-input-row span {
  color: var(--term-green);
}

.terminal-input-row input {
  width: 100%;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--term-text);
  font-family: inherit;
  caret-color: var(--term-green);
}

.stage-panel {
  display: grid;
  grid-template-rows: auto 1fr;
}

.stage-panel__meta {
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.stage-content {
  display: grid;
  align-content: center;
  min-height: 100%;
  padding: clamp(28px, 5vw, 72px);
}

.stage-card {
  max-width: 760px;
  animation: contentIn 260ms ease both;
}

.stage-card__label {
  margin: 0 0 18px;
  color: var(--accent);
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
}

.stage-card h1,
.stage-card h2 {
  margin: 0;
  font-size: clamp(40px, 7vw, 108px);
  line-height: 0.92;
  letter-spacing: 0;
  text-wrap: balance;
}

.stage-card h2 {
  font-size: clamp(34px, 5vw, 78px);
}

.stage-card p {
  max-width: 680px;
  margin: 22px 0 0;
  color: #30343b;
  font-size: clamp(16px, 1.4vw, 20px);
  line-height: 1.6;
}

.stage-card__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 28px;
}

.stage-card__actions a,
.stage-card__actions button {
  display: inline-flex;
  align-items: center;
  min-height: 42px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  text-decoration: none;
  background: white;
  color: var(--ink);
}

.stage-card__actions a.primary,
.stage-card__actions button.primary {
  border-color: var(--accent);
  background: var(--accent);
  color: white;
}

.facts {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-top: 28px;
}

.fact {
  min-height: 92px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.62);
}

.fact strong,
.fact small {
  display: block;
}

.fact strong {
  font-size: 18px;
}

.fact small {
  margin-top: 6px;
  color: var(--muted);
  line-height: 1.35;
}

.project-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  padding-top: 10px;
}

.project-strip button {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 4px 12px;
  min-height: 86px;
  padding: 14px;
  border-radius: var(--radius);
  text-align: left;
  transition: transform 160ms ease, border-color 160ms ease, background 160ms ease;
}

.project-strip span {
  grid-row: span 2;
  color: var(--accent);
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 12px;
}

.project-strip strong,
.project-strip small {
  display: block;
}

.project-strip small {
  color: var(--muted);
  line-height: 1.35;
}

.pill-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 24px;
}

.pill-list span {
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.64);
  color: #333942;
  font-size: 13px;
}

.system-diagram {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 26px;
}

.system-diagram span {
  position: relative;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.68);
  color: #2c333a;
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 12px;
}

.system-diagram span:not(:last-child)::after {
  content: "->";
  margin-left: 8px;
  color: var(--accent);
}

.project-ledger,
.metric-stack,
.agent-flow,
.proof-grid,
.score-grid,
.reference-grid,
.article-grid,
.rule-list {
  display: grid;
  gap: 8px;
  margin-top: 28px;
}

.project-ledger button,
.metric-stack div,
.agent-flow div,
.proof-grid div,
.score-grid div,
.reference-grid a,
.article-grid a,
.rule-list div {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 12px;
  min-height: 58px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.66);
  text-align: left;
}

.project-ledger span,
.agent-flow span {
  color: var(--accent);
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 12px;
}

.project-ledger small,
.metric-stack span,
.agent-flow small,
.proof-grid span {
  color: var(--muted);
  line-height: 1.35;
}

.metric-stack div {
  grid-template-columns: minmax(140px, 0.45fr) 1fr;
}

.agent-flow {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.score-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.reference-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.article-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.proof-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.agent-flow div,
.score-grid div {
  grid-template-columns: 1fr;
  align-content: start;
  min-height: 122px;
}

.score-grid strong {
  color: var(--accent);
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 22px;
}

.score-grid span,
.score-grid small {
  display: block;
}

.score-grid span {
  font-weight: 700;
}

.score-grid small {
  color: var(--muted);
  line-height: 1.35;
}

.reference-grid a {
  grid-template-columns: 1fr;
  min-height: 116px;
  color: inherit;
  text-decoration: none;
}

.article-grid a {
  grid-template-columns: 1fr;
  align-content: start;
  min-height: 172px;
  color: inherit;
  text-decoration: none;
}

.reference-grid a:hover {
  border-color: var(--accent);
  background: rgba(255, 255, 255, 0.86);
}

.article-grid a:hover {
  border-color: var(--accent);
  background: rgba(255, 255, 255, 0.86);
}

.reference-grid strong,
.reference-grid span,
.article-grid strong,
.article-grid span,
.article-grid small {
  display: block;
}

.article-grid span {
  color: var(--accent);
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 12px;
  text-transform: uppercase;
}

.article-grid strong {
  margin-top: 10px;
  font-size: 19px;
  line-height: 1.16;
}

.reference-grid span {
  color: var(--muted);
  line-height: 1.4;
}

.article-grid small {
  margin-top: 12px;
  color: var(--muted);
  line-height: 1.4;
}

.rule-list div {
  grid-template-columns: minmax(180px, 0.5fr) 1fr;
}

.rule-list span {
  color: var(--muted);
  line-height: 1.4;
}

.check-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 28px;
}

.check-grid span {
  padding: 9px 11px;
  border: 1px solid rgba(14, 132, 165, 0.32);
  border-radius: 999px;
  background: rgba(223, 242, 246, 0.52);
  color: #15576a;
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 12px;
}

.proof-grid div {
  grid-template-columns: 1fr;
  align-content: start;
  min-height: 96px;
}

.proof-grid strong,
.proof-grid span {
  display: block;
}

.proof-grid span {
  margin-top: 8px;
}

.evidence-frame {
  margin: 28px 0 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.68);
  overflow: hidden;
}

.evidence-frame img {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 7;
  object-fit: cover;
  object-position: center;
  border-bottom: 1px solid var(--line);
}

.evidence-frame figcaption {
  padding: 12px 14px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.evidence-frame--compact img {
  aspect-ratio: 16 / 6;
}

.evidence-frame--diagram {
  background: #fbfaf6;
}

.evidence-frame--diagram img {
  padding: 10px;
  background: #fbfaf6;
  object-fit: contain;
}

@keyframes contentIn {
  from {
    transform: translateY(8px);
  }
  to {
    transform: translateY(0);
  }
}

@media (max-width: 980px) {
  .shell {
    padding: 14px;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .nav-actions {
    width: 100%;
    justify-content: flex-start;
  }

  .hero-grid {
    grid-template-columns: 1fr;
  }

  .terminal-panel {
    height: 520px;
    min-height: 0;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .stage-content {
    min-height: 520px;
  }

  .project-strip,
  .facts,
  .agent-flow,
  .proof-grid,
  .score-grid,
  .reference-grid,
  .article-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 560px) {
  .shell {
    width: 100%;
    max-width: 100%;
    padding: 14px;
    overflow: hidden;
  }

  .topbar {
    width: 100%;
    max-width: calc(100vw - 28px);
  }

  .nav-actions {
    display: grid;
    grid-template-columns: 1fr;
    width: calc(100vw - 28px);
    max-width: calc(100vw - 28px);
    padding-right: 0;
  }

  .nav-actions button {
    min-width: 0;
    width: 100%;
    padding: 0 10px;
  }

  .nav-actions .agent-button {
    grid-column: auto;
  }

  .terminal-panel {
    width: 100%;
    max-width: 100%;
    height: 462px;
    min-height: 0;
  }

  .terminal-panel__status {
    display: none;
  }

  .terminal-output {
    overflow-wrap: anywhere;
  }

  .hero-grid,
  .stage-panel,
  .project-strip {
    width: 100%;
    max-width: 100%;
  }

  .stage-content {
    width: 100%;
    max-width: 100%;
    min-height: 390px;
    padding: 30px 16px;
    overflow: hidden;
  }

  .stage-card {
    width: 100%;
    max-width: 100%;
    min-width: 0;
  }

  .facts {
    margin-top: 22px;
  }

  .metric-stack div,
  .project-ledger button,
  .rule-list div {
    grid-template-columns: 1fr;
  }

  .system-diagram {
    display: grid;
  }

  .system-diagram span:not(:last-child)::after {
    content: "";
  }

  .evidence-frame img,
  .evidence-frame--compact img {
    aspect-ratio: 4 / 3;
  }

  .evidence-frame--diagram img {
    aspect-ratio: 16 / 9;
  }

  .stage-card h1,
  .stage-card h2 {
    max-width: 12ch;
    font-size: clamp(26px, 7vw, 30px);
    line-height: 1.04;
    overflow-wrap: break-word;
    word-break: normal;
    text-wrap: wrap;
  }

  .stage-card p:not(.stage-card__label) {
    max-width: min(100%, 31ch);
    font-size: 15px;
    overflow-wrap: anywhere;
  }

  .stage-card__label {
    max-width: 100%;
    font-size: 11px;
    overflow-wrap: anywhere;
  }

  .stage-card__actions a,
  .stage-card__actions button {
    max-width: 100%;
    justify-content: center;
    text-align: center;
    overflow-wrap: anywhere;
  }
}
