/* ==========================================================================
   The Chat Templates Handbook - portal stylesheet
   Palette, type character, and series sequence extracted from the book's own
   cover art: images/cover-3200x5120.png
   Order: tokens -> reset -> layout -> components
   ========================================================================== */

:root {
  /* --- Ground and ink, sampled from the cover ------------------------- */
  --ground:     #05080F;   /* cover's lower field */
  --ground-2:   #0B1533;   /* cover's upper field, section bands */
  --surface:    #0B1430;   /* the cover's code panel */
  --surface-2:  #0D1838;   /* its title bar */
  --ink:        #FFFFFF;   /* cover title */
  --ink-2:      #C3D2EE;   /* cover subtitle, body prose */
  --ink-soft:   #8FA4CD;   /* cover kicker line, mono labels */
  --rule:       #182243;   /* hairlines */
  --accent:     #38F0C8;   /* the cover's one emphasis colour */

  /* --- The cover's seven-segment series bar, in the cover's own order -- */
  --s1: #EF4444; --s2: #FB923C; --s3: #FACC15; --s4: #22C55E;
  --s5: #2563EB; --s6: #4F46E5; --s7: #7C3AED;

  /* --- The cover's three part-card keys ------------------------------- */
  --p1: #38F0C8;   /* Part I   - Foundations */
  --p2: #FACC15;   /* Part II  - The Hard Parts */
  --p3: #C084FC;   /* Part III - Production and Operations */

  --measure: 68ch;
  --page:    1120px;
  --gap:     clamp(1rem, 4vw, 2.5rem);

  --font-sans: "Manrope", system-ui, -apple-system, "Segoe UI", Roboto,
               "Helvetica Neue", Arial, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo,
               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);
  color: var(--ink-2);
  font-family: var(--font-sans);
  font-size: 1.0625rem;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

img, svg { display: block; max-width: 100%; height: auto; }

a { color: var(--accent); text-decoration-thickness: 1px; text-underline-offset: 3px; }
a:hover { color: var(--ink); }

h1, h2, h3 { color: var(--ink); font-weight: 800; letter-spacing: -0.02em; margin: 0 0 0.5em; }
p { margin: 0 0 1em; max-width: var(--measure); }
ul { max-width: var(--measure); }

code, kbd, samp, pre { font-family: var(--font-mono); font-size: 0.9em; }

code {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: 4px;
  padding: 0.1em 0.36em;
  color: var(--accent);
  overflow-wrap: anywhere;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
  border-radius: 3px;
}

.skip {
  position: absolute; left: -9999px; top: 0;
  background: var(--accent); color: var(--ground);
  padding: 0.6rem 1rem; font-weight: 700; z-index: 100;
}
.skip:focus { left: 0; }

/* ==========================================================================
   Layout
   ========================================================================== */

.wrap { max-width: var(--page); margin-inline: auto; padding-inline: var(--gap); }

section { padding-block: clamp(3rem, 8vw, 5.5rem); }
section + section { border-top: 1px solid var(--rule); }

.band { background: var(--ground-2); }

.split {
  display: grid;
  gap: clamp(1.5rem, 4vw, 3rem);
  grid-template-columns: 1fr;
}
@media (min-width: 900px) { .split { grid-template-columns: 1.15fr 1fr; } }

/* A grid/flex item defaults to min-width:auto and will stretch its own track
   around any wide child, which presents exactly as an overflow wrapper not
   working. Reset it here, with the layout, rather than after measuring. */
.split > *, .hero__grid > *, .contents__grid > *, .prose { min-width: 0; }

.prose { max-width: var(--measure); }

/* ==========================================================================
   Type components
   ========================================================================== */

.eyebrow {
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  color: var(--ink-soft);
  margin: 0 0 0.9rem;
  display: block;
}

.h-display {
  font-size: clamp(2.5rem, 7vw, 4.5rem);
  line-height: 0.98;
  letter-spacing: -0.03em;
  margin: 0 0 0.6rem;
}
/* A <br> inside a heading leaves no word separator in the extracted text,
   so the line break is a block span instead. Renders identically. */
.h-display span { display: block; }
.h-display .tint { color: var(--accent); }

h2 { font-size: clamp(1.6rem, 3.5vw, 2.4rem); line-height: 1.1; }
h3 { font-size: 1.15rem; line-height: 1.3; letter-spacing: -0.01em; }

.deck {
  font-size: clamp(1.05rem, 2vw, 1.35rem);
  font-weight: 400;
  color: var(--ink-soft);
  line-height: 1.4;
  max-width: 34ch;
}
/* A heading or the subtitle is one typographic line; an inline code box
   would break it into a block. Keep the mono face, drop the chrome. */
.deck code {
  background: none; border: 0; padding: 0;
  color: var(--ink-2); font-size: 0.92em;
}
h1 code, h2 code, h3 code {
  background: none; border: 0; padding: 0;
  color: var(--accent); font-size: 0.88em; font-weight: 700;
}

.lede { font-size: 1.15rem; color: var(--ink-2); }

.pull {
  border-left: 4px solid var(--accent);
  padding: 0.1rem 0 0.1rem 1.15rem;
  margin: 1.75rem 0;
  color: var(--ink);
  font-size: 1.05rem;
  max-width: var(--measure);
}
.pull p { margin: 0; }
.pull cite {
  display: block; margin-top: 0.6rem;
  font-family: var(--font-mono); font-size: 0.72rem;
  letter-spacing: 0.14em; text-transform: uppercase;
  color: var(--ink-soft); font-style: normal;
}

/* ==========================================================================
   Masthead
   ========================================================================== */

.series-bar { display: flex; height: 8px; }
.series-bar span { flex: 1; }

.masthead .wrap {
  display: flex; flex-wrap: wrap; gap: 0.5rem 1.5rem;
  justify-content: space-between; align-items: baseline;
  padding-block: 0.85rem;
  border-bottom: 1px solid var(--rule);
}
.masthead .eyebrow { margin: 0; }
.masthead .eyebrow strong { color: var(--ink-2); font-weight: 600; }

/* ==========================================================================
   Hero
   ========================================================================== */

.hero { padding-block: clamp(2.5rem, 7vw, 4.5rem) clamp(3rem, 8vw, 5rem); }

.hero__grid {
  display: grid;
  gap: clamp(2rem, 5vw, 3.5rem);
  grid-template-columns: 1fr;
  align-items: start;
}
@media (min-width: 900px) {
  .hero__grid { grid-template-columns: minmax(0, 1fr) 420px; }
}

.hero__cover { order: -1; max-width: 420px; margin-inline: auto; width: 100%; }
@media (min-width: 900px) { .hero__cover { order: 0; margin-inline: 0; } }
/* The cover art carries its own spectrum border, so it gets depth, not a frame. */
.hero__cover img {
  width: 100%;
  border-radius: 6px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.65);
}

.hero__kicker {
  font-family: var(--font-mono);
  color: var(--accent);
  font-size: clamp(0.8rem, 2vw, 1rem);
  letter-spacing: 0.02em;
  margin: 0 0 0.75rem;
  overflow-wrap: anywhere;
}

.hero__meta {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  color: var(--ink-soft);
  margin-top: 1.5rem;
}
.hero__meta span { white-space: nowrap; }

/* ==========================================================================
   Buy row
   ========================================================================== */

.buy {
  display: flex; flex-wrap: wrap; gap: 0.75rem;
  margin: 1.75rem 0 0;
}

.btn {
  display: flex; flex-direction: column; gap: 0.15rem;
  padding: 0.7rem 1.15rem;
  border-radius: 6px;
  border: 1px solid var(--rule);
  background: transparent;
  color: var(--ink);
  text-decoration: none;
  font-weight: 700;
  font-size: 0.95rem;
  line-height: 1.2;
  transition: border-color 0.15s ease, background-color 0.15s ease,
              transform 0.15s ease;
}
.btn small {
  font-family: var(--font-mono);
  font-weight: 500;
  font-size: 0.66rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-soft);
}
.btn:hover { border-color: var(--accent); transform: translateY(-1px); color: var(--ink); }

.btn--primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--ground);
}
.btn--primary small { color: rgba(5, 8, 15, 0.72); }
.btn--primary:hover { background: var(--ink); border-color: var(--ink); color: var(--ground); }

/* Running prose, so it is sans - the mono eyebrow is for labels only. */
.buy__note {
  font-size: 0.88rem;
  color: var(--ink-soft);
  margin: 0.9rem 0 0;
  max-width: 52ch;
}

/* ==========================================================================
   Stats
   ========================================================================== */

.stats {
  display: grid; gap: 1.25rem;
  max-width: none;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  margin-top: 2rem;
  padding: 0; list-style: none;
}
.stat {
  border-left: 3px solid var(--accent);
  padding-left: 1rem;
}
.stat b {
  display: block;
  font-size: clamp(2.25rem, 5vw, 3.25rem);
  line-height: 1;
  font-weight: 800;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.03em;
}
.stat span { display: block; font-size: 0.95rem; color: var(--ink-soft); margin-top: 0.4rem; }
.stat:nth-child(2) { border-color: var(--p2); }
.stat:nth-child(3) { border-color: var(--p3); }

/* ==========================================================================
   Centerpiece - the twelve chapters
   ========================================================================== */

.spine { margin-top: 2.5rem; }

.spine__part { margin-bottom: 2.5rem; }
.spine__part:last-child { margin-bottom: 0; }

.spine__parthead {
  display: flex; flex-wrap: wrap; align-items: baseline; gap: 0.5rem 1rem;
  border-bottom: 1px solid var(--rule);
  padding-bottom: 0.6rem;
  margin-bottom: 1rem;
}
.spine__partno {
  font-family: var(--font-mono); font-weight: 700; font-size: 0.75rem;
  letter-spacing: 0.18em; text-transform: uppercase; color: var(--c);
}
.spine__parttitle { font-size: 1.15rem; font-weight: 800; color: var(--ink); }
.spine__partpurpose { font-size: 0.9rem; color: var(--ink-soft); flex-basis: 100%; margin: 0; max-width: none; }

/* Indent steps per PART, not per chapter - a twelve-step staircase crushes. */
.spine__part--2 { padding-left: 3%; }
.spine__part--3 { padding-left: 6%; }
@media (max-width: 640px) {
  .spine__part--2, .spine__part--3 { padding-left: 0; }
}

.rung {
  border: 1px solid var(--rule);
  border-left: 6px solid var(--c);
  border-radius: 6px;
  background: var(--surface);
  margin-bottom: 0.6rem;
}
.rung[open] { background: var(--surface-2); }

.rung summary {
  display: flex; flex-wrap: wrap; align-items: baseline; gap: 0.35rem 0.9rem;
  padding: 0.85rem 1.1rem 0.85rem 1rem;
  cursor: pointer;
  list-style: none;
  position: relative;
  padding-right: 3rem;
}
.rung summary::-webkit-details-marker { display: none; }
.rung summary::after {
  content: "+";
  position: absolute; right: 1.1rem; top: 50%; transform: translateY(-50%);
  font-family: var(--font-mono); font-size: 1.1rem; font-weight: 700;
  color: var(--c); line-height: 1;
}
.rung[open] summary::after { content: "\2212"; }
.rung summary:hover .rung__name { color: var(--accent); }

.rung__no {
  font-family: var(--font-mono); font-size: 0.7rem; font-weight: 700;
  letter-spacing: 0.14em; text-transform: uppercase; color: var(--c);
  white-space: nowrap;
}
.rung__name { font-weight: 700; color: var(--ink); font-size: 1.02rem; }
.rung__concept {
  font-family: var(--font-mono); font-size: 0.68rem; letter-spacing: 0.1em;
  text-transform: uppercase; color: var(--ink-soft);
  flex-basis: 100%;
}

.rung__body {
  padding: 0.2rem 1.1rem 1.15rem 1rem;
  border-top: 1px solid var(--rule);
  margin-top: -1px;
  padding-top: 1rem;
}
.rung__field + .rung__field { margin-top: 1rem; }
.rung__field .eyebrow { margin-bottom: 0.35rem; font-size: 0.68rem; }
.rung__field p { margin: 0; font-size: 0.98rem; max-width: 78ch; }
.rung__field--cost { border-left: 2px solid var(--c); padding-left: 0.85rem; }
.rung__field--cost p { color: var(--ink); }

.spine__controls { display: flex; gap: 0.75rem; margin-top: 1.5rem; }
.ghost {
  font-family: var(--font-mono); font-size: 0.72rem; font-weight: 600;
  letter-spacing: 0.14em; text-transform: uppercase;
  background: transparent; color: var(--ink-soft);
  border: 1px solid var(--rule); border-radius: 5px;
  padding: 0.55rem 0.95rem; cursor: pointer;
}
.ghost:hover { color: var(--accent); border-color: var(--accent); }

/* ==========================================================================
   Tables
   ========================================================================== */

.tablewrap { overflow-x: auto; margin: 1.5rem 0; }

table {
  border-collapse: collapse;
  width: 100%;
  min-width: 34rem;
  font-size: 0.92rem;
}
table.table--wide { min-width: 44rem; }

th, td {
  text-align: left;
  padding: 0.6rem 1rem 0.6rem 0;
  border-bottom: 1px solid var(--rule);
  vertical-align: top;
}
th {
  font-family: var(--font-mono); font-size: 0.68rem; font-weight: 600;
  letter-spacing: 0.16em; text-transform: uppercase; color: var(--ink-soft);
  white-space: nowrap;
}
td:first-child { color: var(--ink); font-weight: 600; }
td code { white-space: nowrap; }

.tablenote {
  font-size: 0.85rem; color: var(--ink-soft); margin-top: 0.75rem;
}

/* ==========================================================================
   Cards and lists
   ========================================================================== */

.cards {
  display: grid; gap: 1rem;
  max-width: none;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  margin: 2rem 0 0; padding: 0; list-style: none;
}
.card {
  border: 1px solid var(--rule);
  border-top: 3px solid var(--c, var(--accent));
  border-radius: 6px;
  background: var(--surface);
  padding: 1.2rem;
}
.card h3 { margin-bottom: 0.4rem; }
.card p { font-size: 0.95rem; color: var(--ink-soft); margin: 0; max-width: none; }

.contents__grid {
  display: grid; gap: 1.5rem;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  margin-top: 2rem;
}
.contents__col h3 {
  font-family: var(--font-mono); font-size: 0.72rem; font-weight: 700;
  letter-spacing: 0.18em; text-transform: uppercase; color: var(--c);
  border-bottom: 1px solid var(--rule); padding-bottom: 0.5rem;
}
.contents__col ol { list-style: none; margin: 0; padding: 0; }
.contents__col li { display: flex; gap: 0.7rem; padding: 0.35rem 0; font-size: 0.93rem; }
.contents__col li b {
  font-family: var(--font-mono); font-weight: 500; color: var(--ink-soft);
  font-size: 0.8rem; padding-top: 0.15rem; min-width: 1.4rem;
}

.backmatter {
  margin-top: 2rem; padding-top: 1.5rem; border-top: 1px solid var(--rule);
  display: flex; flex-wrap: wrap; gap: 0.5rem 1.25rem;
  list-style: none; padding-left: 0;
  font-size: 0.88rem; color: var(--ink-soft);
  max-width: none;
}
.backmatter li { display: flex; gap: 0.5rem; }
.backmatter b { font-family: var(--font-mono); font-size: 0.78rem; color: var(--accent); font-weight: 500; }

.checklist { list-style: none; padding: 0; margin: 1.5rem 0 0; }
.checklist li {
  position: relative; padding-left: 1.6rem; margin-bottom: 0.6rem;
  font-size: 0.98rem;
}
.checklist li::before {
  content: "\203A"; position: absolute; left: 0; top: -0.05em;
  color: var(--accent); font-weight: 700; font-size: 1.2rem; line-height: 1.35;
}

/* ==========================================================================
   Code block
   ========================================================================== */

.codeblock {
  border: 1px solid var(--rule);
  border-radius: 6px;
  background: var(--surface);
  overflow: hidden;
  margin: 1.5rem 0 0;
}
.codeblock__bar {
  background: var(--surface-2);
  border-bottom: 1px solid var(--rule);
  padding: 0.5rem 0.9rem;
  font-family: var(--font-mono); font-size: 0.7rem;
  letter-spacing: 0.14em; text-transform: uppercase; color: var(--ink-soft);
}
.codeblock pre {
  margin: 0; padding: 1rem 0.9rem; overflow-x: auto;
  font-size: 0.83rem; line-height: 1.65; color: var(--ink-2);
}
.codeblock pre b { color: var(--accent); font-weight: 400; }
.codeblock pre i { color: var(--ink-soft); font-style: normal; }

/* ==========================================================================
   Sticky buy bar
   ========================================================================== */

.stickybar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 50;
  background: rgba(5, 8, 15, 0.94);
  border-top: 1px solid var(--rule);
  backdrop-filter: blur(8px);
  transform: translateY(110%);
  transition: transform 0.25s ease;
}
body.show-sticky .stickybar { transform: translateY(0); }
.stickybar .wrap {
  display: flex; flex-wrap: wrap; align-items: center;
  justify-content: space-between; gap: 0.75rem;
  padding-block: 0.7rem;
}
.stickybar__title {
  font-weight: 800; color: var(--ink); font-size: 0.95rem;
}
.stickybar__title small {
  display: block; font-family: var(--font-mono); font-weight: 500;
  font-size: 0.66rem; letter-spacing: 0.14em; text-transform: uppercase;
  color: var(--ink-soft);
}
.stickybar .buy { margin: 0; }
.stickybar .btn { padding: 0.5rem 0.9rem; font-size: 0.85rem; }
@media (max-width: 560px) { .stickybar__title { display: none; } }

/* ==========================================================================
   Footer
   ========================================================================== */

footer { background: var(--ground-2); border-top: 1px solid var(--rule); }
footer .wrap { padding-block: clamp(2.5rem, 6vw, 4rem) 6rem; }
footer .eyebrow { color: var(--ink-soft); }
.footer__legal {
  margin-top: 2rem; padding-top: 1.5rem; border-top: 1px solid var(--rule);
  font-size: 0.82rem; color: var(--ink-soft); max-width: none;
}

/* ==========================================================================
   Reveal on scroll - content is visible by default; JS adds the animation
   ========================================================================== */

@media (prefers-reduced-motion: no-preference) {
  .js-reveal.will-reveal { opacity: 0; transform: translateY(14px); }
  .js-reveal.is-in {
    opacity: 1; transform: none;
    transition: opacity 0.5s ease, transform 0.5s ease;
  }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
