/* ==========================================================================
   ECS master stylesheet.
   Concept: the page is a ruled source file. A left "gutter" column holds
   section labels (like an editor gutter); content sits to the right.
   Code is the visual metaphor only: everything scrolls and clicks normally.
   Mobile-first; 48em = tablet, 64em = desktop (gutter appears).
   ========================================================================== */

/* ---------- Tokens ---------- */
:root {
  --bg: #0b0c0b;
  --bg-raise: #121412;
  --line: #1f2320;
  --line-strong: #30352f;
  --text: #ecebe5;
  --dim: #9c9e97;
  --faint: #5c605a;
  --accent: #50c878; /* emerald */
  --accent-hover: #6dd690;
  --on-accent: #04130a;

  --sans: "Geist", ui-sans-serif, system-ui, sans-serif;
  --mono: "Geist Mono", ui-monospace, SFMono-Regular, Menlo, monospace;

  --text-sm: 0.8125rem;
  --text-h1: clamp(2.6rem, 1.3rem + 5.2vw, 5.75rem);
  --text-h2: clamp(1.75rem, 1.1rem + 2.6vw, 3.25rem);

  --frame: 84rem;
  --gutter: 16.5rem;
  --pad-x: 1rem;
  --body-pad-x: clamp(2.5rem, 7vw, 7rem); /* wide enough for the hanging > and // marks */
  --sec-pad: clamp(4.5rem, 3rem + 6vw, 9rem);
  --header-h: 3.5rem;
}

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

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
  scroll-padding-top: calc(var(--header-h) + 1rem);
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--sans);
  font-size: 1.0625rem;
  line-height: 1.6;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

h1, h2, h3, p, ul, ol {
  margin: 0;
}

ul, ol {
  padding: 0;
  list-style: none;
}

a {
  color: inherit;
  text-decoration: none;
}

::selection {
  background: var(--accent);
  color: var(--on-accent);
}

:focus-visible {
  outline: 1px solid var(--accent);
  outline-offset: 3px;
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  * { transition: none !important; }
}

.dim {
  color: var(--dim);
}

/* ---------- Frame: the outer ruled box ---------- */
.frame {
  max-width: var(--frame);
  margin-inline: auto;
}

/* ---------- Header ---------- */
.site-header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: rgb(11 12 11 / 0.85);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}

.site-header__inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--header-h);
  padding-inline: var(--pad-x);
}

.logo {
  font-family: var(--mono);
  font-weight: 500;
  font-size: 1.0625rem;
  letter-spacing: 0.02em;
}
.logo span {
  color: var(--accent);
}

/* Mobile: two-line toggle + dropdown panel */
.nav-toggle {
  display: grid;
  place-items: center;
  width: 2.75rem;
  height: 2.75rem;
  margin-right: -0.75rem;
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  cursor: pointer;
}

.nav-toggle__bar,
.nav-toggle__bar::after {
  display: block;
  width: 1.25rem;
  height: 1px;
  background: currentColor;
  transition: transform 0.2s;
}
.nav-toggle__bar {
  position: relative;
  transform: translateY(-3px);
}
.nav-toggle__bar::after {
  content: "";
  position: absolute;
  top: 6px;
  left: 0;
}
.nav-toggle[aria-expanded="true"] .nav-toggle__bar {
  transform: translateY(0) rotate(45deg);
}
.nav-toggle[aria-expanded="true"] .nav-toggle__bar::after {
  transform: translateY(-6px) rotate(-90deg);
}

.site-nav {
  display: none;
  position: absolute;
  top: var(--header-h);
  left: 0;
  right: 0;
  padding: 0.5rem var(--pad-x) 1.25rem;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.site-nav.is-open {
  display: block;
}

.site-nav__list a {
  display: block;
  padding: 0.85rem 0;
  border-bottom: 1px solid var(--line);
  font-family: var(--mono);
  font-size: 0.9375rem;
  color: var(--dim);
}
.site-nav__list a:hover,
.site-nav__list a[aria-current="page"] {
  color: var(--text);
}

.site-nav__cta {
  margin-top: 1.25rem;
  width: 100%;
}

/* ---------- Sections: gutter label + body ---------- */
.sec {
  display: grid;
  gap: 2rem;
  padding: var(--sec-pad) var(--pad-x);
  border-bottom: 1px solid var(--line);
}

.sec__label {
  font-family: var(--mono);
  font-size: var(--text-sm);
  color: var(--dim);
  white-space: nowrap;
}
.sec__label b {
  font-weight: 400;
  color: var(--accent);
}

.sec__body {
  display: grid;
  gap: 2.5rem;
  justify-items: start;
  min-width: 0;
}

.headline {
  max-width: 22ch;
  font-size: var(--text-h2);
  font-weight: 500;
  line-height: 1.08;
  letter-spacing: -0.032em;
  text-wrap: balance;
}

.eyebrow {
  font-family: var(--mono);
  font-size: var(--text-sm);
  color: var(--dim);
}

.actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 1rem 2rem;
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  min-height: 2.75rem; /* touch target */
  padding: 0 1.125rem;
  border: 0;
  border-radius: 3px;
  font-family: var(--mono);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: background-color 0.15s, color 0.15s;
}

.btn--lg {
  min-height: 3.25rem;
  padding-inline: 1.5rem;
  font-size: 0.9375rem;
}

.btn--sm {
  min-height: 2.25rem;
  padding-inline: 0.9rem;
  font-size: var(--text-sm);
}

.btn--primary {
  background: var(--accent);
  color: var(--on-accent);
}
.btn--primary:hover {
  background: var(--accent-hover);
}

/* Secondary links are drawn as [ bracketed ] text, as in the client sketch */
.btn--bracket {
  padding: 0;
  color: var(--text);
  font-weight: 400;
}
.btn--bracket::before,
.btn--bracket::after {
  color: var(--faint);
  transition: color 0.15s;
}
.btn--bracket::before { content: "["; }
.btn--bracket::after  { content: "]"; }
.btn--bracket:hover::before,
.btn--bracket:hover::after {
  color: var(--accent);
}

.arr {
  transition: transform 0.15s;
}
.btn:hover .arr,
.module:hover .arr {
  transform: translateX(3px);
}

/* ---------- Hero ---------- */
.sec--hero {
  border-bottom-color: var(--line);
}

.hero__title {
  max-width: 15ch;
  font-size: var(--text-h1);
  font-weight: 500;
  line-height: 1;
  letter-spacing: -0.045em;
}

.prompt {
  margin-right: 0.3em;
  font-family: var(--mono);
  font-weight: 400;
  color: var(--accent);
}

.hero__out {
  font-family: var(--mono);
  font-size: clamp(0.9375rem, 0.85rem + 0.35vw, 1.125rem);
  line-height: 1.75;
  color: var(--dim);
}
.hero__out span {
  color: var(--text);
}

/* ---------- 01: the problem, as a numbered code listing ---------- */
.code {
  counter-reset: ln;
  width: 100%;
  max-width: 100%;
  font-family: var(--mono);
  font-size: clamp(0.875rem, 0.7rem + 0.7vw, 1.3125rem);
  line-height: 2;
  overflow-x: auto; /* scroll the listing, never the page */
}

.code li {
  display: flex;
  white-space: pre;
}
.code li::before {
  counter-increment: ln;
  content: counter(ln);
  flex: none;
  width: 2ch;
  margin-right: 2.5ch;
  text-align: right;
  color: var(--faint);
  user-select: none;
}

.code__in > :first-child {
  margin-left: 2ch; /* indent the code, not the line number */
}
.code__k {
  display: inline-block;
  min-width: 12ch;
}
.code__arrow {
  display: inline-block;
  width: 3ch;
  color: var(--accent);
}
.code__v {
  color: var(--dim);
}
.code__p {
  color: var(--faint);
}

/* ---------- 02: many inputs -> ECS -> useful action ---------- */
.flow {
  display: grid;
  justify-items: center;
  gap: 0;
  width: 100%;
  font-family: var(--mono);
}

.flow__in {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.25rem 1.25rem;
  color: var(--dim);
  font-size: 0.9375rem;
}

/* wires are vertical on phones, horizontal from tablet up */
.flow__wire {
  position: relative;
  width: 1px;
  height: 2.75rem;
  margin-block: 0.75rem;
  background: var(--accent);
}
.flow__wire::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: 0;
  width: 7px;
  height: 7px;
  border-right: 1px solid var(--accent);
  border-bottom: 1px solid var(--accent);
  transform: translate(-50%, 0) rotate(45deg);
}

.flow__core {
  padding: 0.9rem 1.75rem;
  border: 1px solid var(--accent);
  border-radius: 3px;
  color: var(--accent);
  font-size: 1.5rem;
  font-weight: 500;
  letter-spacing: 0.04em;
}

.flow__out {
  padding: 0.7rem 1.1rem;
  border-radius: 3px;
  background: var(--accent);
  color: var(--on-accent);
  font-weight: 500;
}

.feed {
  width: 100%;
  max-width: 44rem;
  padding-top: 1.75rem;
  border-top: 1px solid var(--line);
  font-family: var(--mono);
  font-size: 0.9375rem;
}
.feed__head {
  margin-bottom: 1rem;
  color: var(--faint);
}
.feed li {
  display: flex;
  gap: 1ch;
  padding-block: 0.4rem;
  color: var(--dim);
}
.feed li::before {
  content: "\2192";
  flex: none;
  color: var(--accent);
}

/* ---------- 03: platform modules ---------- */
.modules {
  display: grid;
  gap: 1px;
  width: 100%;
  background: var(--line);
  border: 1px solid var(--line);
}

.module {
  display: grid;
  grid-template-columns: 1fr auto;
  align-content: start;
  gap: 0.6rem 1rem;
  height: 100%;
  padding: 1.5rem 1.5rem 1.75rem;
  background: var(--bg);
  transition: background-color 0.15s;
}
.module:hover {
  background: var(--bg-raise);
}

.module__name {
  font-size: 1.3125rem;
  font-weight: 500;
  letter-spacing: -0.02em;
}
.module .arr {
  font-family: var(--mono);
  color: var(--faint);
}
.module:hover .arr {
  color: var(--accent);
}
.module__desc {
  grid-column: 1 / -1;
  max-width: 32ch;
  font-size: 0.9375rem;
  line-height: 1.5;
  color: var(--dim);
}

.sec__body > .actions--end {
  justify-self: end;
}

/* ---------- 04: statement with a hanging comment mark ---------- */
.statement {
  max-width: 26ch;
}
.comment-mark {
  margin-right: 0.35em;
  font-family: var(--mono);
  font-weight: 400;
  color: var(--faint);
}

/* ---------- Placeholder pages ---------- */
.outline {
  width: 100%;
  max-width: 40rem;
  border-top: 1px solid var(--line);
  font-family: var(--mono);
  font-size: 0.9375rem;
}
.outline li {
  display: flex;
  gap: 2ch;
  padding-block: 0.85rem;
  border-bottom: 1px solid var(--line);
}
.outline__n {
  color: var(--faint);
}
.outline__todo {
  margin-left: auto;
  color: var(--faint);
}

/* ---------- Footer ---------- */
.site-footer__inner {
  display: grid;
  gap: 1.5rem;
  padding: 2.5rem var(--pad-x);
  font-family: var(--mono);
  font-size: var(--text-sm);
}

.site-footer__links {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem 0;
}
.site-footer__links li:not(:last-child)::after {
  content: "/";
  margin-inline: 0.9ch;
  color: var(--faint);
}
.site-footer__links a {
  color: var(--dim);
}
.site-footer__links a:hover {
  color: var(--text);
}

.site-footer__meta {
  color: var(--faint);
}

/* ==========================================================================
   Tablet and up
   ========================================================================== */
@media (min-width: 48em) {
  :root {
    --pad-x: 2rem;
  }

  /* nav becomes inline */
  .nav-toggle {
    display: none;
  }
  .site-nav,
  .site-nav.is-open {
    display: flex;
    align-items: center;
    gap: 2.25rem;
    position: static;
    padding: 0;
    background: none;
    border: 0;
  }
  .site-nav__list {
    display: flex;
    gap: 2rem;
  }
  .site-nav__list a {
    padding: 0;
    border: 0;
    font-size: var(--text-sm);
  }
  .site-nav__cta {
    margin-top: 0;
    width: auto;
  }

  /* diagram runs left to right; input wires merge into one bracket */
  .flow {
    grid-template-columns: max-content minmax(2.5rem, 1fr) max-content minmax(2.5rem, 1fr) max-content;
    align-items: center;
  }
  .flow__in {
    position: relative;
    display: grid;
    justify-content: stretch;
    gap: 0;
    width: 15rem;
  }
  .flow__in li {
    display: flex;
    align-items: center;
    gap: 1rem;
    line-height: 2.4rem;
  }
  .flow__in li::after {
    content: "";
    flex: 1;
    height: 1px;
    background: var(--line-strong);
  }
  .flow__in::after {
    content: "";
    position: absolute;
    right: 0;
    top: 1.2rem;
    bottom: 1.2rem;
    width: 1px;
    background: var(--accent);
  }
  .flow__wire {
    justify-self: stretch;
    width: auto;
    height: 1px;
    margin: 0;
  }
  .flow__wire::after {
    left: auto;
    right: 0;
    bottom: auto;
    top: 0;
    border-bottom: 0;
    border-top: 1px solid var(--accent);
    transform: translate(0, -50%) rotate(45deg);
  }

  .modules {
    grid-template-columns: repeat(2, 1fr);
  }
  .module {
    min-height: 11rem;
  }

  .site-footer__inner {
    grid-template-columns: auto 1fr auto;
    align-items: center;
    gap: 2.5rem;
  }
}

/* ==========================================================================
   Desktop: the gutter column appears and the frame gets side rules
   ========================================================================== */
@media (min-width: 64em) {
  .frame {
    border-inline: 1px solid var(--line);
  }
  .site-header {
    border-bottom: 0;
  }
  .site-header .frame {
    border-bottom: 1px solid var(--line);
  }

  .site-header__inner {
    display: grid;
    grid-template-columns: var(--gutter) 1fr;
    padding: 0;
  }
  .logo {
    display: flex;
    align-items: center;
    height: 100%;
    padding-left: 2rem;
    border-right: 1px solid var(--line);
  }
  .site-nav,
  .site-nav.is-open {
    justify-content: flex-end;
    padding-right: 1.25rem;
  }

  .sec {
    grid-template-columns: var(--gutter) minmax(0, 1fr);
    gap: 0;
    padding: 0;
  }
  .sec__label {
    padding: var(--sec-pad) 2rem;
    border-right: 1px solid var(--line);
  }
  /* label stays in view while its section scrolls past */
  .sec__label > span {
    position: sticky;
    top: calc(var(--header-h) + 2rem);
  }
  .sec__body {
    padding: var(--sec-pad) var(--body-pad-x);
  }
  .sec--hero .sec__body {
    align-content: center;
    min-height: min(72svh, 46rem);
  }
  .sec--cta .sec__body {
    align-content: center;
    min-height: min(48svh, 30rem);
  }

  /* hang the > and // marks into the left padding so text aligns */
  .hero__title,
  .statement {
    position: relative;
  }
  .prompt,
  .comment-mark {
    position: absolute;
    margin-right: 0;
    transform: translateX(calc(-100% - 0.3em));
  }

  .modules {
    grid-template-columns: repeat(3, 1fr);
  }

  .site-footer__inner {
    grid-template-columns: var(--gutter) 1fr auto;
    gap: 0;
    padding: 0;
  }
  .site-footer__inner > * {
    padding: 2.5rem 2rem;
  }
  .site-footer__inner .logo {
    height: auto;
  }
  .site-footer__links {
    padding-left: var(--body-pad-x);
  }
}
