/* ============================================================
   Multi-Agent Reinforcement Learning — marl-book.com
   Palette derived from the book cover (MIT Press, 2024)
   ============================================================ */

:root{
  /* Surfaces */
  --bg:            #0d1418;
  --bg-alt:        #111c22;
  --surface:       #16242b;
  --surface-2:     #1a2b32;   /* cover background */
  --border:        rgba(144, 199, 229, .14);
  --border-strong: rgba(144, 199, 229, .28);

  /* Type */
  --text:          #e8f0f4;
  --text-muted:    #a3b8c3;
  --text-dim:      #7e949f;

  /* Accent */
  --accent:        #90c7e5;   /* cover blue */
  --accent-soft:   #b9dcf0;
  --accent-deep:   #4e93bb;
  --accent-glow:   rgba(144, 199, 229, .20);

  /* Type scale */
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Helvetica, Arial, "Noto Sans", sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;

  /* Layout */
  --wrap: 1120px;
  --radius: 6px;        /* cards */
  --radius-sm: 6px;     /* buttons, mobile nav links */
  --header-h: 64px;
}

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

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

body{
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 17px;
  line-height: 1.68;
  letter-spacing: .005em;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;
}

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

h1, h2, h3{
  line-height: 1.18;
  letter-spacing: -.02em;
  margin: 0 0 .6em;
  font-weight: 650;
}

p{ margin: 0 0 1.1em; }
p:last-child{ margin-bottom: 0; }

a{
  color: var(--accent);
  text-decoration: none;
  transition: color .18s ease, border-color .18s ease;
}
a:hover{ color: var(--accent-soft); }

/* Links inside running prose get a subtle underline */
.section p a, .news-item a, .site-footer a, .byline a, .section-lede a{
  border-bottom: 1px solid rgba(144, 199, 229, .3);
  padding-bottom: 1px;
}
.section p a:hover, .news-item a:hover, .site-footer a:hover, .byline a:hover, .section-lede a:hover{
  border-bottom-color: var(--accent-soft);
}

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

.wrap{
  width: 100%;
  max-width: var(--wrap);
  margin: 0 auto;
  padding: 0 24px;
}

.muted{ color: var(--text-muted); }
.small{ font-size: .89rem; }

.skip-link{
  position: absolute;
  left: -9999px;
  top: 0;
  z-index: 200;
  background: var(--accent);
  color: #06131a;
  padding: 10px 18px;
  border-radius: 0 0 var(--radius-sm) 0;
  font-weight: 600;
}
.skip-link:focus{ left: 0; }

/* ============================================================
   Header / navigation
   ============================================================ */
.site-header{
  position: fixed;
  inset: 0 0 auto 0;
  height: var(--header-h);
  z-index: 100;
  background: rgba(13, 20, 24, .55);
  backdrop-filter: blur(14px) saturate(140%);
  -webkit-backdrop-filter: blur(14px) saturate(140%);
  border-bottom: 1px solid transparent;
  transition: background .25s ease, border-color .25s ease;
}
.site-header.is-scrolled{
  background: rgba(13, 20, 24, .88);
  border-bottom-color: var(--border);
}

.header-inner{
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
}

.brand{
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
  font-weight: 650;
  letter-spacing: .01em;
  font-size: .98rem;
  white-space: nowrap;
}
.brand:hover{ color: var(--text); }
.brand-dim{ color: var(--text-dim); font-weight: 500; }

.brand-mark{
  width: 22px;
  height: 22px;
  flex: none;
  display: block;
  fill: var(--accent);
}

.nav ul{
  display: flex;
  align-items: center;
  gap: 4px;
  list-style: none;
  margin: 0;
  padding: 0;
}
.nav a{
  display: block;
  padding: 8px 12px;
  border-radius: 999px;
  color: var(--text-muted);
  font-size: .93rem;
  font-weight: 500;
}
.nav a:hover{ color: var(--text); background: rgba(144, 199, 229, .08); }
.nav a.is-active{ color: var(--accent); background: rgba(144, 199, 229, .12); }

.nav-toggle{
  display: none;
  width: 42px; height: 42px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: transparent;
  cursor: pointer;
  padding: 0;
  place-items: center;
}
.nav-toggle span{
  display: block;
  width: 18px; height: 1.6px;
  background: var(--text);
  margin: 3.4px auto;
  transition: transform .25s ease, opacity .2s ease;
}
.nav-toggle[aria-expanded="true"] span:nth-child(1){ transform: translateY(5px) rotate(45deg); }
.nav-toggle[aria-expanded="true"] span:nth-child(2){ opacity: 0; }
.nav-toggle[aria-expanded="true"] span:nth-child(3){ transform: translateY(-5px) rotate(-45deg); }

/* ============================================================
   Hero
   ============================================================ */
.hero{
  position: relative;
  padding: calc(var(--header-h) + 76px) 0 92px;
  overflow: hidden;
  background:
    radial-gradient(120% 90% at 78% 8%, rgba(144, 199, 229, .13), transparent 58%),
    radial-gradient(80% 70% at 8% 0%, rgba(78, 147, 187, .10), transparent 60%),
    linear-gradient(180deg, var(--surface-2) 0%, #14212700 100%),
    var(--bg);
}
.hero::after{
  content: "";
  position: absolute;
  inset: auto 0 0 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--border-strong), transparent);
}

.hero-inner{
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1.32fr) minmax(0, .68fr);
  gap: 64px;
  align-items: center;
}

.eyebrow{
  display: inline-block;
  margin: 0 0 18px;
  padding: 5px 13px;
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  background: rgba(144, 199, 229, .07);
  color: var(--accent);
  font-size: .76rem;
  font-weight: 600;
  letter-spacing: .13em;
  text-transform: uppercase;
}

.hero h1{
  margin: 0 0 .26em;
  font-size: clamp(2.3rem, 6vw, 4rem);
  font-weight: 700;
  letter-spacing: -.032em;
  background: linear-gradient(180deg, #ffffff 0%, #c7dfec 92%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.subtitle{
  margin: 0 0 1.1em;
  font-size: clamp(1.05rem, 2.3vw, 1.42rem);
  font-weight: 500;
  color: var(--accent);
  letter-spacing: .005em;
}

.byline{
  margin: 0 0 1.5em;
  font-size: .98rem;
  color: var(--text-muted);
}
.byline .sep{ color: var(--text-dim); margin: 0 .55em; }

.lede{
  max-width: 46ch;
  font-size: 1.06rem;
  color: var(--text-muted);
  margin-bottom: 2em;
}

.cta-row{
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
}

.btn{
  display: inline-flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 1px;
  padding: 13px 24px;
  border-radius: var(--radius-sm);
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: .005em;
  border: 1px solid transparent;
  transition: transform .18s ease, box-shadow .22s ease, background .2s ease, border-color .2s ease, color .2s ease;
}
.btn:hover{ transform: translateY(-2px); }
.btn-meta{
  font-size: .74rem;
  font-weight: 500;
  letter-spacing: .04em;
  opacity: .72;
}

.btn-primary{
  background: linear-gradient(180deg, var(--accent-soft), var(--accent));
  color: #07161e;
  box-shadow: 0 6px 22px -8px var(--accent-glow), inset 0 1px 0 rgba(255,255,255,.35);
}
.btn-primary:hover{
  color: #07161e;
  box-shadow: 0 12px 30px -10px rgba(144, 199, 229, .5), inset 0 1px 0 rgba(255,255,255,.45);
}

.btn-ghost{
  background: rgba(144, 199, 229, .05);
  border-color: var(--border-strong);
  color: var(--text);
}
.btn-ghost:hover{
  color: var(--text);
  background: rgba(144, 199, 229, .11);
  border-color: var(--accent-deep);
}

.hero-errata{
  margin: 20px 0 0;
  font-size: .88rem;
  color: var(--text-dim);
}
.hero-errata a{
  color: var(--text-muted);
  border-bottom: 1px solid rgba(144, 199, 229, .28);
  padding-bottom: 1px;
}
.hero-errata a:hover{ color: var(--accent); }

.hero-cover{
  position: relative;
  justify-self: center;
}
.hero-cover::before{
  content: "";
  position: absolute;
  inset: -14% -10% -22%;
  background: radial-gradient(closest-side, var(--accent-glow), transparent 72%);
  filter: blur(10px);
  z-index: 0;
}
.hero-cover img{
  position: relative;
  z-index: 1;
  width: min(320px, 100%);
  border-radius: 0;
  box-shadow:
    0 2px 0 rgba(255,255,255,.06) inset,
    0 30px 60px -22px rgba(0,0,0,.85),
    0 0 0 1px rgba(144, 199, 229, .16);
  transform: perspective(1400px) rotateY(-8deg) rotateX(1.5deg);
  transition: transform .5s cubic-bezier(.22,.9,.3,1);
}
.hero-cover img:hover{
  transform: perspective(1400px) rotateY(-3deg) rotateX(0deg) translateY(-4px);
}

/* ============================================================
   Sections
   ============================================================ */
.section{ padding: 88px 0; }
.section-alt{ background: var(--bg-alt); border-block: 1px solid var(--border); }

.section-title{
  position: relative;
  font-size: clamp(1.5rem, 3.2vw, 2.05rem);
  margin-bottom: .8em;
  padding-top: 18px;
}
.section-title::before{
  content: "";
  position: absolute;
  top: 0; left: 0;
  width: 46px; height: 3px;
  border-radius: 3px;
  background: linear-gradient(90deg, var(--accent), transparent);
}

.section-lede{
  color: var(--text-muted);
  margin-top: -.4em;
  margin-bottom: 2em;
}

/* ---------- About ---------- */
.about-grid{
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(0, .85fr);
  gap: 48px;
  align-items: start;
}
.about-grid p{ color: var(--text-muted); }

.note-card{
  background: linear-gradient(160deg, var(--surface), var(--bg-alt));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 26px 28px;
}
/* Drop the card so its label sits level with the first line of body text
   on the left. Two-column layout only. */
@media (min-width: 981px){
  .note-card{ margin-top: 56px; }
}

.note-card h3{
  font-size: .78rem;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 1em;
}
.note-card p{ font-size: .95rem; margin: 0; }

.fact-row{
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1px;
  list-style: none;
  margin: 56px 0 0;
  padding: 0;
  background: var(--border);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.fact-row li{
  background: var(--bg);
  padding: 22px 24px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.fact-key{
  font-size: .72rem;
  letter-spacing: .13em;
  text-transform: uppercase;
  color: var(--text-dim);
}
.fact-val{ font-weight: 600; color: var(--text); }

/* ---------- Cards ---------- */
.card-grid{ display: grid; gap: 24px; }
.card-grid.two{ grid-template-columns: repeat(2, minmax(0, 1fr)); }

.card{
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 30px 32px;
  transition: border-color .22s ease, transform .22s ease, box-shadow .22s ease;
}
.card:hover{
  border-color: var(--border-strong);
  transform: translateY(-3px);
  box-shadow: 0 18px 40px -28px rgba(0,0,0,.9);
}
.card h3{ font-size: 1.16rem; margin-bottom: .7em; }
.card p{ color: var(--text-muted); font-size: .97rem; }

.card-feature{
  background:
    radial-gradient(120% 120% at 100% 0%, rgba(144, 199, 229, .12), transparent 55%),
    var(--surface-2);
  display: flex;
  flex-direction: column;
  align-items: flex-start;
}
.card-feature .btn{ margin-top: auto; }

.link-arrow{ font-weight: 550; }
.link-arrow::after{
  content: "\2192";
  display: inline-block;
  margin-left: .45em;
  transition: transform .18s ease;
}
.link-arrow:hover::after{ transform: translateX(3px); }

.mail{
  font-family: var(--font-mono);
  font-size: .86em;
  color: var(--text);
  word-break: break-word;
}

/* ---------- News ---------- */
.news-list{
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 16px;
}
.news-item{
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent-deep);
  border-radius: var(--radius);
  padding: 22px 26px;
  color: var(--text-muted);
  transition: border-left-color .22s ease, background .22s ease;
}
.news-item:first-child{ border-left-color: var(--accent); }
.news-item:hover{ background: var(--surface-2); border-left-color: var(--accent); }
.news-item p{ margin: 0; }

/* ---------- Citation ---------- */
.citation-plain{
  color: var(--text-muted);
  max-width: 72ch;
  margin-bottom: 1.8em;
}

.code-block{
  margin: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: #0a1216;
}
.code-block figcaption{
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 11px 18px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  font-size: .76rem;
  letter-spacing: .13em;
  text-transform: uppercase;
  color: var(--text-dim);
}
.code-block pre{
  margin: 0;
  padding: 22px 24px;
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: .86rem;
  line-height: 1.65;
  color: #cfe4ef;
}

.copy-btn{
  font: inherit;
  font-size: .72rem;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--accent);
  background: rgba(144, 199, 229, .09);
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  padding: 5px 12px;
  cursor: pointer;
  transition: background .18s ease, color .18s ease;
}
.copy-btn:hover{ background: rgba(144, 199, 229, .18); }
.copy-btn.is-copied{ color: #8fe3b0; border-color: rgba(143, 227, 176, .4); background: rgba(143, 227, 176, .12); }

/* ---------- Table of contents ---------- */
.toc-grid{
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 40px 48px;
}
.toc-intro{ grid-column: 1 / -1; }

.part-title{
  font-size: .95rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 1.2em;
  padding-bottom: .9em;
  border-bottom: 1px solid var(--border);
}
.part-label{
  display: block;
  font-size: .72rem;
  letter-spacing: .15em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: .45em;
}

.toc-list{
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 10px;
}
.toc-list li{
  display: grid;
  grid-template-columns: 2.4rem 1fr;
  align-items: baseline;
  color: var(--text-muted);
  font-size: .98rem;
}
.ch-num{
  font-family: var(--font-mono);
  font-size: .82rem;
  color: var(--accent-deep);
}
.toc-intro .toc-list li{ font-size: 1.05rem; color: var(--text); }

.appendix{
  margin-top: 44px;
  padding-top: 22px;
  border-top: 1px solid var(--border);
  color: var(--text-dim);
  font-size: .95rem;
}

/* ---------- Endorsements ---------- */
.quote-grid{
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 24px;
}
.quote{
  position: relative;
  margin: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 30px 32px 26px;
  display: flex;
  flex-direction: column;
  transition: border-color .22s ease, transform .22s ease;
}
.quote:hover{ border-color: var(--border-strong); transform: translateY(-3px); }
.quote::before{
  content: "\201C";
  position: absolute;
  top: 6px; right: 22px;
  font-size: 4.6rem;
  line-height: 1;
  color: var(--accent);
  opacity: .16;
}
.quote blockquote{
  margin: 0 0 22px;
  color: var(--text);
  font-size: 1rem;
  line-height: 1.62;
}
.quote blockquote::before{ content: "\201C"; }
.quote blockquote::after{ content: "\201D"; }
.quote figcaption{
  margin-top: auto;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.q-name{ font-weight: 650; color: var(--accent); font-size: .95rem; }
.q-aff{ color: var(--text-dim); font-size: .84rem; line-height: 1.45; }

/* ---------- Closing ---------- */
.closing{
  padding: 92px 0;
  background:
    radial-gradient(90% 140% at 50% 0%, rgba(144, 199, 229, .13), transparent 62%),
    var(--surface-2);
  border-top: 1px solid var(--border);
  text-align: center;
}
.closing-inner h2{ font-size: clamp(1.6rem, 3.4vw, 2.2rem); }
.closing-inner p{ color: var(--text-muted); margin-bottom: 2em; }
.closing .cta-row{ justify-content: center; }
.closing .btn{ align-items: center; }

/* ---------- Footer ---------- */
.site-footer{
  background: var(--bg);
  border-top: 1px solid var(--border);
  padding: 34px 0;
  color: var(--text-dim);
  font-size: .88rem;
}
.footer-inner{
  display: flex;
  flex-wrap: wrap;
  gap: 8px 28px;
  justify-content: space-between;
}
.site-footer p{ margin: 0; }
.site-footer a{ color: var(--text-muted); }
.site-footer a:hover{ color: var(--accent); }

/* ============================================================
   Responsive
   ============================================================ */
@media (max-width: 980px){
  .hero-inner{ grid-template-columns: 1fr; gap: 48px; text-align: left; }
  .hero-cover{ order: -1; justify-self: start; }
  .hero-cover img{ width: min(196px, 50vw); transform: none; }
  .hero-cover img:hover{ transform: translateY(-4px); }
  .about-grid{ grid-template-columns: 1fr; gap: 32px; }
  .fact-row{ grid-template-columns: repeat(2, 1fr); }
  .toc-grid{ grid-template-columns: 1fr; }
}

@media (max-width: 760px){
  body{ font-size: 16px; }
  .wrap{ padding: 0 20px; }
  .section{ padding: 64px 0; }
  .hero{ padding: calc(var(--header-h) + 48px) 0 68px; }

  .nav-toggle{ display: grid; }
  .nav{
    position: fixed;
    inset: var(--header-h) 0 auto 0;
    background: rgba(13, 20, 24, .97);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    border-bottom: 1px solid var(--border);
    transform: translateY(-8px);
    opacity: 0;
    visibility: hidden;
    transition: opacity .2s ease, transform .2s ease, visibility .2s;
  }
  .nav.is-open{ opacity: 1; visibility: visible; transform: translateY(0); }
  .nav ul{
    flex-direction: column;
    align-items: stretch;
    gap: 0;
    padding: 10px 12px 18px;
  }
  .nav a{
    padding: 13px 14px;
    border-radius: var(--radius-sm);
    font-size: 1rem;
  }

  .card-grid.two{ grid-template-columns: 1fr; }
  .card, .quote{ padding: 24px 22px; }
  .quote-grid{ grid-template-columns: 1fr; }
  .btn{ width: 100%; align-items: center; }
  .cta-row{ gap: 12px; }
  .footer-inner{ flex-direction: column; }
}

@media (max-width: 420px){
  .fact-row{ grid-template-columns: 1fr; }
  .byline .sep{ margin: 0 .35em; }
}

/* ---------- Motion & print ---------- */
@media (prefers-reduced-motion: reduce){
  html{ scroll-behavior: auto; }
  *, *::before, *::after{
    animation-duration: .001ms !important;
    transition-duration: .001ms !important;
  }
  .btn:hover, .card:hover, .quote:hover, .hero-cover img:hover{ transform: none; }
}

@media print{
  .site-header, .closing, .nav-toggle, .copy-btn{ display: none !important; }
  body{ background: #fff; color: #000; }
  a{ color: #000; }
}
