:root {
  --ea-background: hsl(40 26% 97%);
  --ea-foreground: hsl(34 11% 11%);
  --ea-card: hsl(40 20% 98%);
  --ea-border: hsl(34 15% 82%);
  --ea-border-soft: hsl(34 15% 88%);
  --ea-primary: hsl(219 42% 29%);
  --ea-muted: hsl(40 18% 93%);
  --ea-muted-foreground: hsl(31 8% 36%);
  --ea-grid: hsl(214 24% 55% / 0.07);
  --ea-display: "EB Garamond", Georgia, "Times New Roman", serif;
  --ea-sans: "DM Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --ea-reader: 44rem;
  --ea-sidebar: 18rem;
}

html {
  scroll-behavior: smooth;
  background: var(--ea-background);
}

* {
  box-sizing: border-box;
}

*::selection {
  background: hsl(219 42% 29% / 0.16);
  color: inherit;
}

body {
  margin: 0;
  padding: 0;
  overflow-x: hidden;
  background: var(--ea-background);
  color: var(--ea-foreground);
  font-family: var(--ea-sans);
  font-size: 17px;
  font-feature-settings: "liga", "kern", "tnum";
  font-kerning: normal;
  font-weight: 400;
  letter-spacing: -0.008em;
  line-height: 1.82;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}

body::before {
  display: none !important;
  content: none !important;
}

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

a:hover {
  text-decoration: none;
}

.page-layout {
  width: 100%;
  max-width: none;
  min-height: 100vh;
  margin: 0;
  padding: 0;
}

.layout {
  display: flex;
  align-items: flex-start;
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  align-self: flex-start;
  width: var(--ea-sidebar);
  height: 100vh;
  flex: 0 0 var(--ea-sidebar);
  overflow-x: hidden;
  overflow-y: auto;
  padding: 2rem 1.65rem 3.5rem;
  border-right: 1px solid var(--ea-border);
  border-bottom: 0;
  background: var(--ea-background);
  scrollbar-color: var(--ea-border) transparent;
  scrollbar-width: thin;
}

.sidebar-header {
  margin-bottom: 2rem;
}

.sidebar-title {
  margin: 0;
  color: var(--ea-foreground);
  font-family: var(--ea-display);
  font-size: 1.85rem;
  font-weight: 500;
  letter-spacing: -0.035em;
  line-height: 1;
}

.chapter-list {
  margin: 0;
  padding: 0;
  border: 0;
  list-style: none;
  font-family: var(--ea-sans);
  font-size: 0.75rem;
}

.chapter-list > li {
  margin: 0;
  padding: 0;
  border: 0;
}

.sidebar .chapter-link {
  display: grid;
  grid-template-columns: 1.8rem minmax(0, 1fr);
  align-items: baseline;
  gap: 0.4rem;
  width: 100%;
  margin: 0;
  padding: 0.58rem 0.55rem 0.58rem 0.7rem;
  border: 0 !important;
  border-left: 2px solid transparent !important;
  background: transparent;
  color: var(--ea-muted-foreground);
  font-family: var(--ea-sans);
  font-size: 0.73rem;
  font-weight: 500;
  letter-spacing: 0;
  line-height: 1.43;
  text-decoration: none;
  transition:
    color 180ms ease,
    border-color 180ms ease,
    background-color 180ms ease;
}

.sidebar .chapter-link:hover {
  border-left-color: var(--ea-border) !important;
  color: var(--ea-foreground);
  text-decoration: none;
}

.sidebar .chapter-link.active {
  border-left-color: var(--ea-primary) !important;
  background: hsl(219 42% 29% / 0.045);
  color: var(--ea-primary);
  font-weight: 600;
}

.chapter-roman {
  color: var(--ea-muted-foreground);
  font-size: 0.62rem;
  font-weight: 600;
  letter-spacing: 0.11em;
}

.chapter-link.active .chapter-roman {
  color: var(--ea-primary);
}

.chapter-label {
  min-width: 0;
}

.subtopic-list {
  display: none;
  margin: 0.18rem 0 0.7rem 2.35rem;
  padding: 0 0 0.15rem 0.75rem;
  border-left: 1px solid var(--ea-border-soft);
  list-style: none;
}

.chapter-link.active + .subtopic-list {
  display: block;
}

.subtopic-list li {
  position: relative;
  margin: 0;
  padding: 0;
  border: 0;
}

.sidebar .subtopic-link {
  position: relative;
  display: block;
  margin: 0;
  padding: 0.31rem 0.35rem;
  border: 0;
  background: transparent;
  color: var(--ea-muted-foreground);
  font-family: var(--ea-sans);
  font-size: 0.69rem;
  font-weight: 400;
  letter-spacing: 0;
  line-height: 1.48;
  text-decoration: none;
  transition: color 180ms ease;
}

.sidebar .subtopic-link::before {
  position: absolute;
  top: 0.48rem;
  bottom: 0.48rem;
  left: -0.79rem;
  width: 2px;
  background: transparent;
  content: "";
}

.sidebar .subtopic-link:hover {
  color: var(--ea-foreground);
  text-decoration: none;
}

.sidebar .subtopic-link.active {
  color: var(--ea-primary);
  font-weight: 500;
}

.sidebar .subtopic-link.active::before {
  background: var(--ea-primary);
}

.mobile-subtopics {
  display: none;
}

.content {
  min-width: 0;
  flex: 1 1 auto;
  padding: 0 clamp(2rem, 7vw, 8.5rem);
  background-color: var(--ea-background);
  background-image:
    linear-gradient(to right, var(--ea-grid) 1px, transparent 1px),
    linear-gradient(to bottom, var(--ea-grid) 1px, transparent 1px);
  background-position: top left;
  background-size: 30px 30px;
  font-size: 15.5px;
}

.chapter {
  width: 100%;
  max-width: var(--ea-reader);
  margin: 0 auto;
  padding: 5.6rem 0 7.5rem;
  border: 0;
  background: transparent;
}

.chapter.hidden {
  display: none;
}

.chapter > h1:first-of-type {
  margin: 0 0 0.9rem;
  color: var(--ea-muted-foreground);
  font-family: var(--ea-sans);
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.18em;
  line-height: 1.4;
  text-align: left;
  text-transform: uppercase;
}

.chapter h2 {
  display: block;
  margin: 4.8rem 0 1.15rem;
  color: var(--ea-foreground);
  font-family: var(--ea-display);
  font-size: clamp(1.55rem, 2.2vw, 1.95rem);
  font-weight: 500;
  letter-spacing: -0.025em;
  line-height: 1.12;
  text-wrap: balance;
}

.chapter h2[id] {
  scroll-margin-top: 2rem;
}

.chapter h2::after {
  display: none;
  content: none;
}

.chapter > h2:first-of-type {
  max-width: 18ch;
  margin: 0 0 3.4rem;
  padding: 0 0 2.2rem;
  border-bottom: 1px solid var(--ea-border);
  color: var(--ea-foreground);
  font-family: var(--ea-display);
  font-size: clamp(2.5rem, 4.4vw, 3.75rem);
  font-weight: 500;
  letter-spacing: -0.04em;
  line-height: 1;
  text-align: left;
  text-wrap: balance;
}

.chapter h3 {
  margin: 2.35rem 0 0.65rem;
  color: var(--ea-foreground);
  font-family: var(--ea-display);
  font-size: clamp(1.2rem, 1.55vw, 1.4rem);
  font-weight: 500;
  letter-spacing: -0.025em;
  line-height: 1.2;
  text-wrap: balance;
}

.chapter p,
.chapter li {
  font-family: var(--ea-sans);
  font-size: inherit;
  line-height: 1.78;
}

.chapter p {
  margin: 0 0 1.28rem;
}

.chapter p.after-keynes-gap {
  margin-bottom: 2rem;
}

.chapter strong {
  color: var(--ea-foreground);
  font-weight: 600;
}

.chapter em {
  color: var(--ea-muted-foreground);
}

.chapter ul,
.chapter ol {
  margin: 0.35rem 0 1.5rem;
  padding: 0;
  list-style: none;
}

.chapter ul > li,
.chapter ol > li {
  position: relative;
  margin: 0 0 0.72rem;
  padding: 0 0 0 1.45rem;
}

.chapter ul > li::before {
  position: absolute;
  top: 0.76em;
  left: 0.18rem;
  width: 4px;
  height: 4px;
  border: 0;
  border-radius: 50%;
  background: var(--ea-primary);
  content: "";
  transform: none;
}

.chapter ol {
  counter-reset: macro-list;
}

.chapter ol > li {
  counter-increment: macro-list;
}

.chapter ol > li::before {
  position: absolute;
  top: 0.13rem;
  left: 0;
  color: var(--ea-primary);
  content: counter(macro-list) ".";
  font-family: var(--ea-sans);
  font-size: 0.72rem;
  font-weight: 600;
  line-height: 1.82;
}

.math-block {
  margin: 1.7rem 0;
  padding: 0;
  overflow-x: auto;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  text-align: center;
}

.math-block mjx-container {
  color: var(--ea-foreground);
}

.math-block mjx-container[display="true"] {
  margin: 0.35rem 0 !important;
}

.katex {
  font-size: 1.08em !important;
}

.graph-block,
.graph-two-up,
.graph-carousel {
  margin: 2.35rem 0;
  gap: 1.15rem;
}

.graph-block {
  display: grid;
}

.graph-block-pair,
.graph-two-up {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-items: start;
}

.graph-figure,
.graph-figure-plain {
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
}

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

.graph-figure figcaption {
  margin-top: 0.9rem;
  color: var(--ea-muted-foreground);
  font-family: var(--ea-sans);
  font-size: 0.76rem;
  font-style: normal;
  letter-spacing: 0;
  line-height: 1.55;
  text-align: left;
}

.graph-carousel {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  padding-right: 3.25rem;
}

.graph-carousel-compact {
  margin-top: 0.4rem;
}

.graph-carousel-viewport {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 18rem;
}

.graph-carousel-slide {
  display: none;
  width: 100%;
}

.graph-carousel-slide.is-active {
  display: block;
}

.graph-carousel-next {
  position: absolute;
  top: 50%;
  right: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.5rem;
  height: 2.5rem;
  padding: 0;
  border: 1px solid var(--ea-border);
  border-radius: 0.6rem;
  background: hsl(40 20% 98% / 0.92);
  box-shadow: none;
  color: var(--ea-primary);
  cursor: pointer;
  font-family: var(--ea-sans);
  font-size: 1.2rem;
  line-height: 1;
  transform: translateY(-50%);
  transition:
    border-color 180ms ease,
    background-color 180ms ease,
    transform 180ms ease;
}

.graph-carousel-next:hover {
  border-color: hsl(219 42% 29% / 0.45);
  background: var(--ea-muted);
  transform: translateY(-50%) translateX(2px);
}

.graph-image-small {
  width: 60% !important;
  margin: 0 auto;
}

.graph-image-half {
  width: 68% !important;
  margin: 0 auto;
}

.graph-image-medium {
  width: 78% !important;
  margin: 0 auto;
}

.graph-image-crisis-large {
  width: 88% !important;
  margin: 0 auto;
}

.graph-image-carousel-main {
  width: 48% !important;
  margin: 0 auto;
}

.graph-image-carousel-slide {
  width: 72% !important;
  margin: 0 auto;
}

.graph-image-mid-small {
  width: 40% !important;
  margin: 0 auto;
}

.graph-image-ch10 {
  width: 46% !important;
  margin: 0 auto;
}

.graph-image-ch10-small {
  width: 38% !important;
  margin: 0 auto;
}

.graph-image-ch10-large {
  width: 58% !important;
  margin: 0 auto;
}

.graph-image-islm-small,
.graph-image-is-main {
  width: 34% !important;
  margin: 0 auto;
}

.graph-image-tiny {
  width: 29% !important;
  margin: 0 auto;
}

.graph-image-pair-small {
  width: 62% !important;
  margin: 0 auto;
}

#chapter-12 .graph-image-medium {
  width: 42% !important;
}

#chapter-12 .graph-image-pair-small {
  width: 68% !important;
}

#chapter-12 img[alt="page-41-image-12.png"] {
  width: 36% !important;
  margin-right: auto;
  margin-left: auto;
}

.eq-summary {
  display: grid;
  grid-template-columns: 3rem minmax(0, 1fr) 3rem minmax(0, 1.18fr);
  align-items: center;
  column-gap: 0.75rem;
  row-gap: 0.85rem;
  margin: 2rem 0;
  padding: 0.25rem 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
}

.eq-summary-head {
  margin: 0 0 0.2rem;
  color: var(--ea-foreground);
  font-family: var(--ea-display);
  font-size: 1.12rem;
  font-weight: 500;
  letter-spacing: -0.02em;
  text-align: left;
}

.eq-summary-head-left {
  grid-column: 1 / 3;
}

.eq-summary-head-right {
  grid-column: 3 / 5;
}

.eq-summary-tag {
  color: var(--ea-primary);
  font-family: var(--ea-sans);
  font-size: 0.7rem;
  font-weight: 600;
  text-align: right;
}

.eq-summary-formula {
  overflow-x: auto;
}

.shock-explain {
  margin: 2rem 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
}

.shock-inline-formula {
  margin-top: 0;
  text-align: left;
}

.shock-notes {
  color: var(--ea-muted-foreground);
  font-size: 0.96rem;
  line-height: 1.7;
}

.shock-notes p {
  margin-bottom: 0.8rem;
}

.chapter-nav {
  display: flex;
  justify-content: space-between;
  gap: 2rem;
  margin-top: 5.5rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--ea-border);
  color: var(--ea-muted-foreground);
  font-family: var(--ea-sans);
  font-size: 0.66rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  line-height: 1.55;
  text-transform: uppercase;
}

.chapter-nav a {
  max-width: 46%;
  padding: 0;
  border: 0;
  color: var(--ea-primary);
  text-decoration: none;
}

.chapter-nav a:hover {
  color: var(--ea-foreground);
}

.chapter-nav .next {
  margin-left: auto;
  text-align: right;
}

.back-button {
  position: fixed;
  top: calc(env(safe-area-inset-top, 0px) + 1.5rem);
  right: calc(env(safe-area-inset-right, 0px) + 2rem);
  z-index: 50;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.5rem;
  height: 2.5rem;
  padding: 0;
  border: 1px solid var(--ea-border);
  border-radius: 0.6rem;
  background: hsl(40 20% 98% / 0.88);
  box-shadow: none;
  color: var(--ea-foreground);
  font-family: var(--ea-sans);
  font-size: 1rem;
  line-height: 1;
  text-decoration: none;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  transition:
    border-color 180ms ease,
    background-color 180ms ease,
    color 180ms ease,
    transform 180ms ease;
}

.back-button:hover {
  border-color: hsl(219 42% 29% / 0.45);
  background: var(--ea-card);
  color: var(--ea-primary);
  text-decoration: none;
  transform: translateX(-2px);
}

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

@media (max-width: 980px) {
  .layout {
    display: block;
    min-height: 0;
  }

  .sidebar {
    position: sticky;
    top: 0;
    z-index: 40;
    width: 100%;
    height: auto;
    max-height: none;
    overflow: hidden;
    padding: 1rem 4.8rem 0.7rem 1.25rem;
    border-right: 0;
    border-bottom: 1px solid var(--ea-border);
    background: hsl(40 26% 97% / 0.92);
    backdrop-filter: blur(18px);
    -webkit-backdrop-filter: blur(18px);
  }

  .sidebar-header {
    max-width: var(--ea-reader);
    margin: 0 auto 0.7rem;
  }

  .sidebar-title {
    font-size: 1.55rem;
  }

  .sidebar nav {
    max-width: var(--ea-reader);
    margin: 0 auto;
    overflow: hidden;
  }

  .chapter-list {
    display: flex;
    gap: 0.25rem;
    overflow-x: auto;
    margin: 0;
    padding: 0;
    scrollbar-color: var(--ea-border) transparent;
    scrollbar-width: thin;
  }

  .chapter-list > li {
    flex: 0 0 auto;
  }

  .sidebar .chapter-link {
    display: inline-flex;
    align-items: baseline;
    gap: 0.38rem;
    width: auto;
    padding: 0.55rem 0.65rem 0.48rem;
    border: 0 !important;
    border-bottom: 2px solid transparent !important;
    background: transparent;
    font-size: 0.69rem;
    white-space: nowrap;
  }

  .sidebar .chapter-link:hover {
    border-bottom-color: var(--ea-border) !important;
  }

  .sidebar .chapter-link.active {
    border-bottom-color: var(--ea-primary) !important;
    background: transparent;
  }

  .subtopic-list {
    display: none !important;
  }

  .mobile-subtopics {
    display: flex;
    gap: 1.1rem;
    overflow-x: auto;
    margin: 0.35rem 0 0;
    padding: 0.58rem 0 0.2rem;
    border-top: 1px solid var(--ea-border-soft);
    scrollbar-color: var(--ea-border) transparent;
    scrollbar-width: thin;
  }

  .sidebar .mobile-subtopic-link {
    flex: 0 0 auto;
    margin: 0;
    padding: 0 0 0.26rem;
    border: 0;
    border-bottom: 1px solid transparent;
    border-radius: 0;
    background: transparent;
    color: var(--ea-muted-foreground);
    font-family: var(--ea-sans);
    font-size: 0.67rem;
    font-weight: 400;
    letter-spacing: 0;
    line-height: 1.5;
    text-decoration: none;
    white-space: nowrap;
  }

  .sidebar .mobile-subtopic-link:hover,
  .sidebar .mobile-subtopic-link.active {
    border-bottom-color: var(--ea-primary);
    background: transparent;
    color: var(--ea-primary);
    font-weight: 500;
    text-decoration: none;
  }

  .content {
    padding: 0 1.5rem;
  }

  .chapter {
    padding: 4.5rem 0 6rem;
  }

  .chapter h2[id] {
    scroll-margin-top: 10.5rem;
  }

  .back-button {
    top: calc(env(safe-area-inset-top, 0px) + 0.9rem);
    right: calc(env(safe-area-inset-right, 0px) + 1.1rem);
  }
}

@media (max-width: 640px) {
  body {
    font-size: 16px;
    line-height: 1.78;
  }

  .sidebar {
    padding-right: 4.4rem;
    padding-left: 1rem;
  }

  .sidebar-header {
    display: block;
  }

  .sidebar-title {
    color: var(--ea-foreground);
    font-size: 1.35rem;
  }

  .content {
    --ea-grid: hsl(214 24% 55% / 0.045);
    padding: 0 1.1rem;
    background-size: 28px 28px;
    font-size: 15px;
  }

  .chapter {
    padding-top: 3.5rem;
  }

  .chapter > h2:first-of-type {
    margin-bottom: 2.7rem;
    padding-bottom: 1.7rem;
    font-size: clamp(2.15rem, 10vw, 2.8rem);
  }

  .chapter h2 {
    margin-top: 4rem;
    font-size: clamp(1.5rem, 6vw, 1.8rem);
  }

  .chapter h3 {
    font-size: 1.28rem;
  }

  .graph-two-up,
  .graph-block-pair {
    grid-template-columns: 1fr;
  }

  .graph-figure,
  .graph-figure-plain {
    padding: 0;
  }

  .math-block {
    margin-right: 0;
    margin-left: 0;
    padding: 0;
  }

  .graph-carousel {
    padding-right: 2.8rem;
  }

  .eq-summary {
    grid-template-columns: 2.7rem minmax(0, 1fr);
    padding: 0.25rem 0;
  }

  .eq-summary-head-left,
  .eq-summary-head-right {
    grid-column: 1 / -1;
  }

  .eq-summary-tag-right,
  .eq-summary-formula-right {
    grid-column: auto;
  }

  .chapter-nav {
    gap: 1rem;
    margin-top: 4.5rem;
    font-size: 0.6rem;
  }

  .chapter-nav a {
    max-width: 48%;
  }

  img[class*="graph-image-"] {
    width: 100% !important;
    max-width: 33.75rem;
    margin-right: auto;
    margin-left: auto;
  }

  .graph-image-tiny,
  .graph-image-islm-small,
  .graph-image-is-main,
  .graph-image-mid-small,
  .graph-image-ch10-small {
    width: 84% !important;
    max-width: 26rem;
  }

  #chapter-12 .graph-image-medium,
  #chapter-12 .graph-image-pair-small,
  #chapter-12 img[alt="page-41-image-12.png"] {
    width: 100% !important;
    max-width: 33.75rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}

@media print {
  body {
    background: #fff;
    color: #000;
    font-size: 11pt;
  }

  .sidebar,
  .back-button,
  .chapter-nav {
    display: none !important;
  }

  .layout,
  .content {
    display: block;
  }

  .content {
    padding: 0;
    background: #fff;
  }

  .chapter,
  .chapter.hidden {
    display: block !important;
    max-width: none;
    padding: 0;
  }

  .chapter + .chapter {
    break-before: page;
  }

  .graph-figure,
  .math-block,
  .eq-summary,
  .shock-explain {
    background: #fff;
    box-shadow: none;
    break-inside: avoid;
  }
}
