:root {
  color-scheme: light;
  --background: #faf9f5;
  --surface: #f2f0e9;
  --text: #3d3929;
  --border: #e1ded5;
  --accent: #c96442;
  --accent-text: #af5033;
  --muted: #716d62;
  font-family: "Iowan Old Style", "Palatino Linotype", "Book Antiqua", Georgia, serif;
  color: var(--text);
  background: var(--background);
  font-synthesis: none;
  -webkit-font-smoothing: antialiased;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100svh;
}

a {
  color: inherit;
  text-decoration: none;
  -webkit-tap-highlight-color: transparent;
}

a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 6px;
}

.modules {
  width: min(1120px, 100%);
  min-height: 100vh;
  min-height: 100svh;
  margin: 0 auto;
  padding: 64px 40px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-content: center;
  gap: 24px;
}

.module {
  min-height: 420px;
  padding: 36px 40px 42px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: space-between;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  transition: background-color 180ms ease, border-color 180ms ease, transform 180ms ease;
}

.module-arrow {
  align-self: flex-end;
  flex-shrink: 0;
  color: var(--accent);
  stroke: currentColor;
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: transform 180ms ease;
}

.module-title {
  font-size: clamp(40px, 5.2vw, 64px);
  font-weight: 400;
  line-height: 1.06;
  letter-spacing: -0.045em;
}

.module:first-child .module-title {
  font-size: clamp(64px, 7vw, 88px);
}

.module-body {
  width: 100%;
}

.module-body .module-title {
  margin: 0 0 28px;
}

.chapter-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.chapter-list > li + li {
  border-top: 1px solid var(--border);
}

.chapter-list a {
  display: grid;
  grid-template-columns: 24px minmax(0, 1fr);
  gap: 16px;
  padding: 16px 0;
  font-size: 21px;
  line-height: 1.4;
  transition: color 180ms ease;
}

.chapter-number {
  padding-top: 3px;
  color: var(--accent-text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}

.subchapter-list {
  list-style: none;
  margin: 0 0 8px 40px;
  padding: 0;
}

.subchapter-list a {
  grid-template-columns: 28px minmax(0, 1fr);
  padding: 10px 0;
  font-size: 18px;
}

.chapter-description {
  margin: 28px 0 0;
  font-size: 22px;
  line-height: 1.5;
}

.chapter-sections {
  max-width: 720px;
  margin-top: 48px;
}

.chapter-sections a {
  grid-template-columns: 36px minmax(0, 1fr);
  padding: 24px 0;
  font-size: 27px;
}

.chapter-sections .chapter-number {
  padding-top: 8px;
  font-size: 16px;
}

@media (hover: hover) {
  .module:hover {
    background: #edeae1;
    border-color: #cec7b9;
    transform: translateY(-3px);
  }

  .module:hover .module-arrow {
    transform: translate(2px, -2px);
  }

  .back:hover {
    color: var(--accent);
  }

  .reference-link:hover,
  .chapter-list a:hover,
  .game-link:hover figcaption {
    color: var(--accent);
    text-decoration-color: currentColor;
  }
}

.topic {
  width: min(1040px, 100%);
  margin: 0 auto;
  padding: 48px 40px 80px;
}

.back {
  width: 44px;
  height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  border-radius: 50%;
  transition: color 180ms ease;
}

.back svg {
  stroke: currentColor;
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.topic-title {
  margin: 88px 0 0;
  font-size: clamp(44px, 7vw, 80px);
  font-weight: 400;
  line-height: 1.08;
  letter-spacing: -0.045em;
  overflow-wrap: break-word;
}

.timeline-page {
  width: min(1280px, 100%);
  padding-bottom: 96px;
}

.timeline-page .topic-title {
  margin-top: 64px;
  font-size: clamp(44px, 5.5vw, 68px);
}

.timeline {
  list-style: none;
  margin: 64px 0 0;
  padding: 0;
}

.timeline-entry {
  display: grid;
  grid-template-columns: 88px minmax(0, 1fr);
  gap: 28px;
}

.timeline-year {
  padding-top: 5px;
  font-size: 23px;
  line-height: 1.3;
  text-align: right;
  font-variant-numeric: lining-nums tabular-nums;
}

.timeline-content {
  position: relative;
  min-width: 0;
  padding: 0 0 48px 36px;
  border-left: 1px solid var(--border);
}

.timeline-content::before {
  content: "";
  position: absolute;
  top: 13px;
  left: -4px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
}

.timeline-entry:not(:last-child) .timeline-content {
  padding-bottom: 64px;
}

.timeline-media {
  display: block;
  width: min(100%, 720px);
  margin-top: 36px;
  border-radius: 6px;
}

.timeline-media--wide {
  width: 100%;
}

.timeline-media img {
  display: block;
  width: 100%;
  height: auto;
  background: var(--surface);
  border-radius: inherit;
}

.timeline-heading h2 {
  margin: 0;
  font-size: 30px;
  font-weight: 400;
  line-height: 1.3;
  letter-spacing: -0.025em;
}

.timeline-heading p {
  margin: 6px 0 0;
  color: var(--muted);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 15px;
  line-height: 1.5;
}

.reference-link,
.game-link figcaption {
  text-decoration: underline;
  text-decoration-color: var(--border);
  text-decoration-thickness: 1px;
  text-underline-offset: 5px;
  transition: color 180ms ease, text-decoration-color 180ms ease;
}

.game-link {
  display: block;
  min-width: 0;
  border-radius: 5px;
}

.game-gallery {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 24px;
  margin-top: 36px;
}

.game {
  min-width: 0;
  margin: 0;
}

.game img {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 160 / 210;
  object-fit: contain;
  image-rendering: pixelated;
  background: #000;
  border-radius: 5px;
}

.game figcaption {
  margin-top: 14px;
  font-size: 21px;
  line-height: 1.3;
  text-align: center;
}

.chapter-page .topic-title {
  font-size: clamp(40px, 5.5vw, 64px);
}

.mdp-interaction {
  margin: 56px 0 0;
}

.mdp-interaction > a {
  display: block;
}

.mdp-interaction img {
  display: block;
  width: 100%;
  height: auto;
}

.mdp-assumption,
.mdp-explanation {
  font-size: 22px;
  line-height: 1.5;
}

.mdp-assumption {
  margin: 28px 0 14px;
}

.mdp-interaction figcaption {
  color: var(--muted);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 14px;
  line-height: 1.6;
}

.mdp-definition {
  margin-top: 64px;
  padding: 32px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
}

.mdp-definition h2,
.mdp-goal h2,
.mdp-example h2 {
  margin: 0;
  font-size: 32px;
  font-weight: 400;
  line-height: 1.25;
  letter-spacing: -0.025em;
}

.definition-list {
  list-style: none;
  margin: 28px 0 0;
  padding: 0;
}

.definition-list li {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(200px, 0.8fr);
  align-items: baseline;
  gap: 24px;
  padding: 16px 0;
  font-size: 25px;
  line-height: 1.4;
}

.definition-list li + li {
  border-top: 1px solid var(--border);
}

.definition-list .transition-definition {
  row-gap: 12px;
}

.definition-note {
  grid-column: 1 / -1;
  margin: 0;
  font-size: 18px;
  line-height: 1.6;
}

.mdp-goal {
  margin-top: 64px;
}

.mdp-tuple {
  margin: 0 0 32px;
  font-size: clamp(24px, 3vw, 32px);
}

.mdp-equation {
  margin-top: 28px;
  padding: 12px 0;
  overflow-x: auto;
  font-size: clamp(20px, 3vw, 32px);
}

.mdp-equation math {
  width: max-content;
  margin: 0;
}

.mdp-equation:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 6px;
}

.mdp-explanation {
  margin: 28px 0 0;
}

.mdp-example {
  margin-top: 64px;
  padding-top: 48px;
  border-top: 1px solid var(--border);
}

.gridworld-figure {
  width: min(100%, 720px);
  margin: 32px 0 0;
}

.gridworld-figure a,
.gridworld-figure img {
  display: block;
}

.gridworld-figure img {
  width: 100%;
  height: auto;
  border-radius: 6px;
}

.mdp-example h3 {
  margin: 48px 0 0;
  font-size: 28px;
  font-weight: 400;
  line-height: 1.3;
}

.value-intro {
  margin-top: 56px;
}

.value-intro h2,
.value-case h2 {
  margin: 0;
  font-size: 32px;
  font-weight: 400;
  line-height: 1.25;
  letter-spacing: -0.025em;
}

.value-example-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  align-items: start;
  gap: 40px;
  margin-top: 48px;
}

.value-example-grid .gridworld-figure {
  width: 100%;
  margin: 0;
}

.value-assumptions h3 {
  margin: 0;
  font-size: 28px;
  font-weight: 400;
  line-height: 1.3;
}

.value-assumptions p {
  margin: 16px 0 0;
  font-size: 22px;
  line-height: 1.6;
}

.value-examples {
  list-style: none;
  margin: 24px 0 0;
  padding: 0;
  font-size: 27px;
}

.value-examples li + li {
  margin-top: 22px;
}

.value-exit-note {
  margin-top: 48px;
  padding-top: 28px;
  border-top: 1px solid var(--border);
}

.value-exit-note .mdp-explanation {
  margin-top: 0;
}

.value-case {
  margin-top: 64px;
  padding-top: 40px;
  border-top: 1px solid var(--border);
}

.value-case .value-examples {
  margin-top: 32px;
}

.value-expression {
  padding: 2px 0;
  overflow-x: auto;
}

.value-expression--wrap {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 8px;
}

.value-stochastic-equation {
  font-size: 27px;
}

.value-horizon + .value-horizon {
  margin-top: 40px;
}

.value-horizon-definition {
  margin: 0;
  font-size: 24px;
  line-height: 1.6;
}

.value-recursion .mdp-equation,
.value-bellman .mdp-equation,
.value-convergence .mdp-equation,
.value-q-values .mdp-equation,
.policy-evaluation .mdp-equation {
  margin-top: 24px;
  font-size: clamp(20px, 2.6vw, 28px);
}

.value-theorem {
  margin-top: 32px;
  padding: 28px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
}

.value-theorem .mdp-explanation {
  margin-top: 0;
}

.value-algorithm {
  margin-top: 32px;
  padding: 28px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
}

.value-algorithm h3 {
  margin: 0;
  font-size: 28px;
  font-weight: 400;
  line-height: 1.3;
}

.value-q-values h3,
.policy-evaluation h3 {
  margin: 32px 0 0;
  font-size: 26px;
  font-weight: 400;
  line-height: 1.3;
}

.policy-explanation {
  margin: 28px 0 0;
  padding-left: 28px;
  font-size: 22px;
  line-height: 1.6;
}

.policy-explanation li + li {
  margin-top: 12px;
}

.entropy-examples h3,
.maximum-entropy-mdp h3,
.entropy-one-step-policy h3,
.entropy-value-iteration h3 {
  margin: 32px 0 0;
  font-size: 26px;
  font-weight: 400;
  line-height: 1.3;
}

.entropy-definition .mdp-equation,
.entropy-examples .mdp-equation,
.maximum-entropy-mdp .mdp-equation,
.entropy-one-step-policy .mdp-equation,
.entropy-one-step-value .mdp-equation,
.entropy-value-iteration .mdp-equation {
  font-size: clamp(20px, 2.6vw, 28px);
}

.entropy-one-step-policy .entropy-long-equation,
.entropy-one-step-value .entropy-long-equation,
.entropy-value-iteration .entropy-long-equation {
  font-size: 20px;
}

.entropy-binary-plot {
  width: min(100%, 640px);
  margin: 32px auto 0;
}

.entropy-binary-plot img,
.entropy-distributions img {
  display: block;
  width: 100%;
  height: auto;
}

.entropy-distributions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 32px;
  margin-top: 32px;
}

.entropy-distributions figure {
  min-width: 0;
  margin: 0;
}

.entropy-distributions figcaption {
  margin-top: 16px;
  font-size: 21px;
  line-height: 1.4;
  text-align: center;
}

.q-gridworld {
  width: min(100%, 640px);
  margin: 32px auto 0;
}

.q-gridworld figcaption {
  margin-bottom: 16px;
  font-size: 26px;
  text-align: center;
}

.q-gridworld img {
  display: block;
  width: 100%;
  height: auto;
}

.value-algorithm p {
  margin: 24px 0 0;
  font-size: 22px;
  line-height: 1.6;
}

.value-algorithm-loop {
  margin-left: 24px;
}

.value-gridworld,
.value-intuition,
.value-contractions {
  margin-top: 48px;
}

.value-gridworld h3,
.value-intuition h3,
.value-contractions h3 {
  margin: 0;
  font-size: 28px;
  font-weight: 400;
  line-height: 1.3;
  letter-spacing: -0.025em;
}

.value-intuition .proof-equation {
  margin-top: 32px;
  padding: 16px 0;
  font-size: 26px;
}

.value-intuition .proof-series {
  font-size: 22px;
}

.proof-label {
  color: var(--accent-text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 15px;
}

.proof-arrow {
  font-size: 22px;
}

.contraction-list {
  margin: 28px 0 0;
  padding-left: 28px;
}

.contraction-list > li + li {
  margin-top: 32px;
}

.contraction-list > li::marker {
  color: var(--accent-text);
}

.contraction-list h4 {
  margin: 0;
  font-size: 22px;
  font-weight: 400;
  line-height: 1.5;
}

.contraction-list .mdp-equation {
  margin-top: 16px;
}

.contraction-list .mdp-explanation {
  margin-top: 16px;
}

.exercise-gridworld {
  width: min(100%, 520px);
  margin: 32px auto 0;
}

.exercise-gridworld img {
  display: block;
  width: 100%;
  height: auto;
}

.exercise-matches {
  margin-top: 32px;
  overflow-x: auto;
}

.exercise-matches:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 6px;
}

.exercise-matches table {
  width: 100%;
  min-width: 600px;
  border-collapse: collapse;
  text-align: left;
  font-size: 20px;
  line-height: 1.5;
}

.exercise-matches th,
.exercise-matches td {
  padding: 16px;
  border-bottom: 1px solid var(--border);
  font-weight: 400;
}

.exercise-matches thead th {
  color: var(--muted);
  font-size: 18px;
}

.exercise-matches th:first-child {
  padding-left: 0;
}

.exercise-matches td {
  white-space: nowrap;
}

.iteration-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  align-items: start;
  gap: 40px;
  margin-top: 32px;
}

.iteration-context {
  padding-top: 56px;
}

.iteration-context .gridworld-figure {
  width: 100%;
  margin: 0;
}

.iteration-settings {
  margin: 24px 0 0;
  font-size: 22px;
  line-height: 1.6;
}

.iteration-player {
  min-width: 0;
}

.iteration-step {
  margin: 0 0 16px;
  font-size: 32px;
  line-height: 1.25;
}

.iteration-grid {
  width: 100%;
  table-layout: fixed;
  border-collapse: collapse;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: clamp(17px, 2vw, 24px);
  font-variant-numeric: tabular-nums;
}

.iteration-grid td {
  position: relative;
  width: 25%;
  padding: 0;
  border: 1px solid var(--border);
  background: var(--surface);
  text-align: center;
  transition: background-color 280ms ease;
}

.iteration-grid td > span {
  display: grid;
  place-items: center;
  aspect-ratio: 1;
}

.iteration-grid .is-positive {
  background: color-mix(in srgb, #aeb99d calc(var(--value) * 100%), var(--surface));
}

.iteration-grid .is-negative {
  background: #efd5c7;
}

.iteration-grid .iteration-wall {
  background: var(--border);
}

.iteration-exit::after {
  position: absolute;
  inset: 8%;
  border: 1px solid currentColor;
  opacity: 0.3;
  content: "";
  pointer-events: none;
}

.iteration-controls {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-top: 16px;
}

.iteration-controls[hidden] {
  display: none;
}

.iteration-toggle {
  display: grid;
  flex: 0 0 40px;
  width: 40px;
  height: 40px;
  padding: 0;
  place-items: center;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--surface);
  color: var(--accent-text);
  cursor: pointer;
}

.iteration-player[data-playing="true"] .iteration-icon--play,
.iteration-player[data-playing="false"] .iteration-icon--pause {
  display: none;
}

.iteration-range {
  flex: 1;
  min-width: 0;
  margin: 0;
  accent-color: var(--accent-text);
  cursor: pointer;
}

.iteration-toggle:focus-visible,
.iteration-range:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 4px;
}

@media (max-width: 960px) {
  .game-gallery {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 28px 20px;
  }
}

@media (max-width: 680px) {
  .modules {
    grid-template-columns: 1fr;
    gap: 16px;
    padding: 32px 24px;
  }

  .module {
    min-height: 280px;
    padding: 28px 30px 32px;
  }

  .module-title {
    font-size: clamp(40px, 8.8vw, 56px);
  }

  .module:first-child .module-title {
    font-size: 64px;
  }

  .chapter-list a {
    gap: 12px;
    font-size: 19px;
  }

  .subchapter-list {
    margin-left: 36px;
  }

  .subchapter-list a {
    font-size: 18px;
  }

  .chapter-sections a {
    font-size: 25px;
  }

  .chapter-description {
    font-size: 20px;
  }

  .topic {
    padding: 32px 24px 64px;
  }

  .topic-title {
    margin-top: 64px;
  }

  .timeline-page .topic-title {
    margin-top: 48px;
    font-size: clamp(38px, 8vw, 52px);
  }

  .timeline {
    margin-top: 44px;
  }

  .timeline-entry {
    grid-template-columns: minmax(0, 1fr);
    gap: 16px;
  }

  .timeline-year {
    padding: 0 0 0 24px;
    color: var(--accent-text);
    font-size: 20px;
    text-align: left;
  }

  .timeline-content {
    padding: 0 0 28px 24px;
  }

  .timeline-heading h2 {
    font-size: 27px;
  }

  .game-gallery {
    margin-top: 28px;
  }

  .timeline-media {
    margin-top: 28px;
  }

  .timeline-entry:not(:last-child) .timeline-content {
    padding-bottom: 44px;
  }

  .game figcaption {
    margin-top: 10px;
    font-size: 18px;
  }

  .mdp-interaction {
    margin-top: 36px;
  }

  .mdp-assumption,
  .mdp-explanation {
    font-size: 20px;
  }

  .mdp-definition {
    margin-top: 44px;
    padding: 24px;
  }

  .mdp-definition h2,
  .mdp-goal h2,
  .mdp-example h2 {
    font-size: 28px;
  }

  .definition-list li {
    grid-template-columns: minmax(0, 1fr);
    gap: 8px;
    font-size: 23px;
  }

  .mdp-goal {
    margin-top: 44px;
  }

  .mdp-example {
    margin-top: 44px;
    padding-top: 36px;
  }

  .mdp-example h3 {
    margin-top: 36px;
    font-size: 26px;
  }

  .value-intro {
    margin-top: 36px;
  }

  .entropy-distributions {
    grid-template-columns: minmax(0, 1fr);
  }

  .value-intro h2,
  .value-case h2 {
    font-size: 28px;
  }

  .value-example-grid {
    grid-template-columns: minmax(0, 1fr);
    gap: 32px;
    margin-top: 36px;
  }

  .value-assumptions h3 {
    font-size: 26px;
  }

  .value-assumptions p {
    font-size: 20px;
  }

  .value-exit-note {
    margin-top: 36px;
  }

  .value-case {
    margin-top: 44px;
    padding-top: 32px;
  }

  .value-case .value-examples {
    font-size: 22px;
  }

  .value-stochastic-equation {
    font-size: 20px;
  }

  .value-horizon-definition {
    font-size: 22px;
  }

  .value-algorithm {
    padding: 20px;
  }

  .value-theorem {
    padding: 20px;
  }

  .value-algorithm p {
    font-size: 20px;
  }

  .value-algorithm-loop {
    margin-left: 12px;
  }

  .iteration-layout {
    grid-template-columns: minmax(0, 1fr);
    gap: 32px;
  }

  .value-gridworld,
  .value-intuition,
  .value-contractions {
    margin-top: 36px;
  }

  .value-gridworld h3,
  .value-intuition h3,
  .value-contractions h3 {
    font-size: 26px;
  }

  .value-intuition .proof-equation {
    font-size: 20px;
  }

  .iteration-context {
    padding-top: 0;
  }

  .iteration-settings {
    font-size: 20px;
  }
}

@media (max-width: 360px) {
  .game-gallery {
    grid-template-columns: minmax(0, 1fr);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition: none !important;
  }
}
