/* ==========================================================================
   Building Real-World Agentic AI Systems with LangGraph - portal stylesheet
   Palette sampled from images/Kindle-Cover.jpg. One theme, matching the
   printed object: the cover is dark, so the page is dark.
   Order: tokens -> reset -> layout -> components.
   ========================================================================== */

:root {
  /* --- Extracted from the cover art ------------------------------------ */
  --ground:     #071228;   /* deepest navy field (cover ground #040F23-#0B1B3B) */
  --ground-2:   #0B1B3B;   /* section bands */
  --ground-3:   #102952;   /* the lighter diagonal in the cover gradient */
  --panel:      #0C1F40;   /* the cover's code-panel fill */
  --panel-2:    #0E254E;
  --ink:        #F4F8FF;   /* cover author name */
  --ink-soft:   #9FB0CE;   /* cover subtitle */
  --ink-dim:    #7B93B9;   /* cover code-comment grey, lightened for contrast */
  --rule:       #1C3663;
  --rule-soft:  #16294B;
  --accent:     #35D4C0;   /* cover teal: "WITH LANGGRAPH", the mark, the rule */
  --accent-2:   #F5A93B;   /* cover amber: the agent/plan nodes */

  /* Seven parts, seven steps between the cover's two accents. The cover
     keys nothing to a sequence, so the sequence is a straight blend of the
     only two accents it has, rather than hues the book never uses. */
  --s1: #35D4C0; --s2: #55CDAA; --s3: #75C694; --s4: #95BE7E;
  --s5: #B5B767; --s6: #D5B051; --s7: #F5A93B;

  --measure: 68ch;
  --page:    1120px;
  --gap:     clamp(1rem, 4vw, 2.5rem);

  --font-sans: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
}

/* --- reset ------------------------------------------------------------- */

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

html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--ground);
  background-image:
    radial-gradient(120ch 80ch at 78% -10%, var(--ground-3) 0%, transparent 62%),
    radial-gradient(90ch 60ch at 0% 8%, var(--ground-2) 0%, transparent 55%);
  background-attachment: fixed;
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 1.0625rem;
  line-height: 1.6;
  font-feature-settings: "kern" 1, "liga" 1;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

img { max-width: 100%; height: auto; display: block; }

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

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

code, kbd, pre { font-family: var(--font-mono); }

/* --- layout ------------------------------------------------------------ */

.wrap { max-width: var(--page); margin-inline: auto; padding-inline: var(--gap); }

.section { padding-block: clamp(3rem, 8vw, 5.5rem); border-top: 1px solid var(--rule-soft); }
.section--flush { border-top: 0; }
.section--band { background: rgba(12, 31, 64, 0.55); }

.prose { max-width: var(--measure); }
.prose p { margin-block: 0 1.1em; }
.prose p:last-child { margin-bottom: 0; }

/* --- type -------------------------------------------------------------- */

h1, h2, h3 { margin: 0; line-height: 1.1; letter-spacing: -0.02em; font-weight: 700; }

.eyebrow {
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  color: var(--ink-dim);
  margin: 0 0 1.1rem;
}
.eyebrow--accent { color: var(--accent); }

.h-section {
  font-size: clamp(1.6rem, 3.5vw, 2.4rem);
  margin-bottom: 0.7em;
}
.h-section span { color: var(--ink-soft); font-weight: 400; }

.lede { font-size: clamp(1.05rem, 2vw, 1.25rem); color: var(--ink-soft); max-width: var(--measure); }

.mono { font-family: var(--font-mono); }

/* --- masthead ---------------------------------------------------------- */

.masthead__bar { display: flex; height: 8px; }
.masthead__bar span { flex: 1; }

.masthead__meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1.5rem;
  justify-content: space-between;
  align-items: center;
  padding-block: 0.85rem;
  border-bottom: 1px solid var(--rule-soft);
  font-family: var(--font-mono);
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  color: var(--ink-dim);
}
.masthead__meta strong { color: var(--ink-soft); font-weight: 600; }

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

.hero { padding-block: clamp(2.5rem, 7vw, 4.5rem) clamp(2.5rem, 6vw, 4rem); }

.hero__grid { display: grid; gap: clamp(2rem, 5vw, 3.5rem); align-items: start; }
@media (min-width: 900px) {
  .hero__grid { grid-template-columns: minmax(0, 1fr) 380px; }
  .hero__art { order: 2; position: sticky; top: 2rem; }
}

.hero__art img {
  width: 100%;
  border: 1px solid var(--rule);
  border-radius: 4px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.55);
}

.hero__code {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--ink-dim);
  margin: 0 0 0.9rem;
  letter-spacing: 0.02em;
}
.hero__code b { color: var(--accent); font-weight: 500; }

h1 {
  font-size: clamp(2.4rem, 6.4vw, 4rem);
  line-height: 0.99;
  letter-spacing: -0.03em;
  margin-bottom: 0.5rem;
}
h1 .h1-line { display: block; }
h1 .h1-line--accent { color: var(--accent); }

.hero__sub {
  font-size: clamp(1.02rem, 1.9vw, 1.2rem);
  color: var(--ink-soft);
  max-width: 46ch;
  margin: 0 0 1.75rem;
}

.thesis {
  border-left: 4px solid var(--accent);
  padding: 0.1rem 0 0.1rem 1.15rem;
  margin: 0 0 1.9rem;
  max-width: 56ch;
}
.thesis b { display: block; font-size: 1.12rem; margin-bottom: 0.35rem; }
.thesis p { margin: 0; color: var(--ink-soft); font-size: 0.98rem; }

/* --- buy row ----------------------------------------------------------- */

.buy { display: flex; flex-wrap: wrap; gap: 0.75rem; }

.btn {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  padding: 0.7rem 1.25rem;
  border: 1px solid var(--rule);
  border-radius: 4px;
  text-decoration: none;
  color: var(--ink);
  background: transparent;
  transition: border-color 0.15s, background-color 0.15s, transform 0.15s;
}
.btn:hover { border-color: var(--accent); background: rgba(53, 212, 192, 0.08); color: var(--ink); }
.btn__label { font-weight: 600; font-size: 0.98rem; letter-spacing: -0.01em; }
.btn__store {
  font-family: var(--font-mono);
  font-size: 0.66rem;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  color: var(--ink-dim);
}
.btn--primary { background: var(--accent); border-color: var(--accent); color: var(--ground); }
.btn--primary:hover { background: var(--ink); border-color: var(--ink); color: var(--ground); }
.btn--primary .btn__store { color: rgba(7, 18, 40, 0.7); }
.btn--primary:hover .btn__store { color: rgba(7, 18, 40, 0.7); }

.buy-aside {
  margin: 1.05rem 0 0;
  font-size: 0.9rem;
  color: var(--ink-dim);
}

/* --- stat strip -------------------------------------------------------- */

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 1px;
  margin-top: 2.75rem;
  background: var(--rule-soft);
  border: 1px solid var(--rule-soft);
  border-radius: 4px;
  overflow: hidden;
}
.stat { background: var(--ground); padding: 0.9rem 1rem; }
.stat__n {
  font-size: 1.55rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
  display: block;
}
.stat__l {
  font-family: var(--font-mono);
  font-size: 0.63rem;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--ink-dim);
}

/* --- the ladder (centerpiece) ------------------------------------------ */

.ladder { margin-top: 2.5rem; }

.ladder__tools {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem 1rem;
  align-items: center;
  margin-bottom: 1.5rem;
}
.tool-btn {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--ink-soft);
  background: transparent;
  border: 1px solid var(--rule);
  border-radius: 3px;
  padding: 0.45rem 0.85rem;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
}
.tool-btn:hover { border-color: var(--accent); color: var(--accent); }

/* A staircase: each part steps in one notch, capped so Part VII does not crush.
   Dropped entirely on narrow viewports, where the indent costs more than it says. */
.part { margin-bottom: 2.4rem; }
@media (min-width: 780px) {
  .part { margin-left: calc(var(--step, 0) * 14px); }
}

.part__head {
  display: flex;
  align-items: baseline;
  gap: 0.75rem;
  padding-bottom: 0.6rem;
  margin-bottom: 0.85rem;
  border-bottom: 1px solid var(--rule-soft);
}
.part__num {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.16em;
  color: var(--c);
}
.part__title { font-size: 1.05rem; font-weight: 600; letter-spacing: -0.01em; }
.part__range {
  margin-left: auto;
  font-family: var(--font-mono);
  font-size: 0.68rem;
  letter-spacing: 0.12em;
  color: var(--ink-dim);
  white-space: nowrap;
}

.rung {
  border: 1px solid var(--rule-soft);
  border-left: 6px solid var(--c);
  border-radius: 3px;
  background: rgba(12, 31, 64, 0.4);
  margin-bottom: 0.5rem;
}
.rung[open] { background: var(--panel); border-color: var(--rule); border-left-color: var(--c); }

.rung > summary {
  display: flex;
  align-items: baseline;
  gap: 0.85rem;
  flex-wrap: wrap;
  padding: 0.8rem 1rem;
  cursor: pointer;
  list-style: none;
}
.rung > summary::-webkit-details-marker { display: none; }
.rung > summary::marker { content: ""; }

.rung__n {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  color: var(--c);
  min-width: 3.2em;
}
.rung__name { font-weight: 600; letter-spacing: -0.01em; flex: 1 1 14rem; }
.rung__hint {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  color: var(--ink-dim);
  letter-spacing: 0.02em;
  flex: 1 1 100%;
}
@media (min-width: 720px) {
  .rung__hint { flex: 0 1 auto; text-align: right; }
}
.rung__sign {
  font-family: var(--font-mono);
  font-size: 1rem;
  color: var(--ink-dim);
  width: 1em;
  text-align: center;
}
.rung[open] .rung__sign { color: var(--c); }
.rung__sign::after { content: "+"; }
.rung[open] .rung__sign::after { content: "\2212"; }

.rung__body { padding: 0.2rem 1rem 1.1rem 1rem; border-top: 1px solid var(--rule-soft); margin-top: 0.1rem; }

.field { padding-top: 0.95rem; }
.field__k {
  font-family: var(--font-mono);
  font-size: 0.64rem;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  color: var(--ink-dim);
  margin: 0 0 0.3rem;
}
.field__v { margin: 0; max-width: var(--measure); }
.field--break .field__v { color: var(--ink); font-weight: 500; }
.field--mech .field__v { color: var(--ink-soft); }
.field--term .field__v { color: var(--ink-soft); font-size: 0.95rem; }
.field--term .term {
  color: var(--accent);
  font-family: var(--font-mono);
  font-size: 0.92em;
  font-weight: 500;
}
.field--none .field__v { color: var(--ink-dim); font-size: 0.92rem; font-style: italic; }

/* --- concept grid ------------------------------------------------------ */

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(255px, 1fr));
  gap: 1px;
  background: var(--rule-soft);
  border: 1px solid var(--rule-soft);
  border-radius: 4px;
  overflow: hidden;
}
.card { background: var(--ground); padding: 1.15rem 1.25rem; }
.card__k {
  font-family: var(--font-mono);
  font-size: 0.63rem;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--ink-dim);
  margin: 0 0 0.5rem;
}
.card__t {
  font-family: var(--font-mono);
  font-size: 0.95rem;
  font-weight: 500;
  color: var(--accent);
  margin: 0 0 0.45rem;
}
.card__d { margin: 0; font-size: 0.93rem; color: var(--ink-soft); }

/* --- tables ------------------------------------------------------------ */

/* A grid/flex item defaults to min-width:auto, which lets a wide table push the
   whole track past the viewport and defeat the scroller. Reset it explicitly. */
.split > *, .hero__grid > *, .prose { min-width: 0; }

.scroll-x { overflow-x: auto; max-width: 100%; -webkit-overflow-scrolling: touch; }

/* 30rem keeps a table inside a half-width desktop column without clipping, while
   still forcing its .scroll-x wrapper to scroll on a phone. Tables with more
   columns opt into a wider floor. */
table { border-collapse: collapse; width: 100%; min-width: 30rem; font-size: 0.93rem; }
table.table--wide { min-width: 42rem; }
th, td { text-align: left; padding: 0.65rem 0.9rem; border-bottom: 1px solid var(--rule-soft); vertical-align: top; }
thead th {
  font-family: var(--font-mono);
  font-size: 0.63rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--ink-dim);
  border-bottom-color: var(--rule);
}
tbody td { color: var(--ink-soft); }
tbody td:first-child { color: var(--ink); font-weight: 500; white-space: nowrap; }
tbody tr:last-child td { border-bottom: 0; }

/* --- contents ---------------------------------------------------------- */

.toc { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 1.75rem 1.5rem; }
.toc__part { border-top: 2px solid var(--c); padding-top: 0.8rem; }
.toc__label {
  font-family: var(--font-mono);
  font-size: 0.66rem;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  color: var(--c);
  margin: 0 0 0.15rem;
}
.toc__title { font-size: 0.95rem; font-weight: 600; margin: 0 0 0.65rem; }
.toc__list { list-style: none; margin: 0; padding: 0; font-size: 0.9rem; color: var(--ink-soft); }
.toc__list li { display: flex; gap: 0.6rem; padding-block: 0.18rem; }
.toc__list b { font-family: var(--font-mono); font-size: 0.78rem; color: var(--ink-dim); font-weight: 500; min-width: 1.6em; }

.appendix-strip {
  margin-top: 2rem;
  padding-top: 1.2rem;
  border-top: 1px solid var(--rule-soft);
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 0.75rem;
}
.chip {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  letter-spacing: 0.04em;
  color: var(--ink-soft);
  border: 1px solid var(--rule-soft);
  border-radius: 3px;
  padding: 0.3rem 0.65rem;
  background: rgba(12, 31, 64, 0.4);
}

/* --- code block -------------------------------------------------------- */

pre.code {
  background: var(--panel);
  border: 1px solid var(--rule-soft);
  border-left: 3px solid var(--accent);
  border-radius: 3px;
  padding: 1rem 1.1rem;
  overflow-x: auto;
  font-size: 0.82rem;
  line-height: 1.65;
  color: var(--ink-soft);
  margin: 1.4rem 0 0;
}
pre.code .c { color: var(--ink-dim); }
pre.code .k { color: var(--accent); }

/* --- two-column split -------------------------------------------------- */

.split { display: grid; gap: clamp(1.75rem, 4vw, 3rem); }
@media (min-width: 860px) { .split { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); } }
@media (min-width: 860px) { .split--wide-left { grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr); } }

/* --- author ------------------------------------------------------------ */

.author__links { list-style: none; margin: 1.2rem 0 0; padding: 0; font-size: 0.93rem; }
.author__links li { padding-block: 0.2rem; }
.author__links span {
  font-family: var(--font-mono);
  font-size: 0.66rem;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--ink-dim);
  margin-right: 0.7rem;
}

/* --- sticky buy bar ---------------------------------------------------- */

.stickybar {
  position: fixed;
  inset-inline: 0;
  bottom: 0;
  z-index: 50;
  background: rgba(7, 18, 40, 0.94);
  backdrop-filter: blur(8px);
  border-top: 1px solid var(--rule);
  transform: translateY(101%);
  transition: transform 0.25s ease;
}
body.show-bar .stickybar { transform: translateY(0); }
.stickybar__in {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding-block: 0.6rem;
  flex-wrap: wrap;
}
.stickybar__t {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--ink-dim);
  margin-right: auto;
}
.stickybar .btn { padding: 0.45rem 0.9rem; }
.stickybar .btn__store { display: none; }
@media (max-width: 560px) { .stickybar__t { display: none; } }

/* --- footer ------------------------------------------------------------ */

.footer { border-top: 1px solid var(--rule-soft); padding-block: clamp(2.5rem, 6vw, 4rem) 6rem; }
.footer__meta {
  margin-top: 2rem;
  padding-top: 1.2rem;
  border-top: 1px solid var(--rule-soft);
  font-family: var(--font-mono);
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--ink-dim);
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem 1.5rem;
}

/* --- reveal on scroll (JS adds .is-in; content is visible by default) --- */

@media (prefers-reduced-motion: no-preference) {
  .js .reveal { opacity: 0; transform: translateY(14px); transition: opacity 0.5s ease, transform 0.5s ease; }
  .js .reveal.is-in { opacity: 1; transform: none; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; }
}
