:root {
  --ink: #15252b;
  --muted: #526871;
  --line: #d5e1e5;
  --tint: #eef6f8;
  --teal: #0b6f8a;
  --teal-dark: #084f63;
  --red: #b3261e;
  --green: #1b7a43;
  --code-bg: #10222a;
  --code-ink: #e4f0f3;
  --ad-navy: #14162e;
  --ad-yellow: #ffd60a;
  --ad-red: #d8262c;
  --ad-purple: #4b2a8f;
  --ad-green: #39ff6a;
  --pixel: "Pixelify Sans", "Courier New", monospace;
  --top-ad-height: 92px;
  --ticker-height: 34px;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; scroll-padding-top: calc(var(--top-ad-height) + 16px); }
body {
  margin: 0;
  color: var(--ink);
  background: #fff;
  font: 17px/1.65 "IBM Plex Sans", "Segoe UI", Arial, sans-serif;
  padding-bottom: var(--ticker-height);
}
img { display: block; max-width: 100%; height: auto; }
button { font: inherit; cursor: pointer; }
:focus-visible { outline: 3px solid var(--teal); outline-offset: 2px; }

/* The textbook */
.hero {
  color: #fff;
  background: #0b6f8a url("assets/deck-bg.png") center / cover;
  padding: 56px 24px 40px;
}
.hero-inner { max-width: 880px; margin: 0 auto; }
.eyebrow { margin: 0 0 8px; font-weight: 600; opacity: .9; }
h1, h2, h3 { font-family: "IBM Plex Serif", Georgia, serif; font-weight: 600; line-height: 1.2; }
h1 { margin: 0 0 16px; font-size: clamp(32px, 6vw, 54px); text-wrap: balance; }
.byline, .sponsor-line { margin: 0; }
.sponsor-line a { color: var(--ad-yellow); font-weight: 600; }
.hero nav { display: flex; flex-wrap: wrap; gap: 8px; margin: 24px 0 16px; }
.hero nav a {
  color: #fff;
  text-decoration: none;
  padding: 6px 14px;
  background: rgba(0, 0, 0, .25);
  border-radius: 6px;
}
.hero nav a:hover { background: rgba(0, 0, 0, .45); }

.layout {
  display: grid;
  grid-template-columns: 180px minmax(0, 760px) 180px;
  justify-content: center;
  gap: 32px;
  padding: 32px 24px;
}
main { min-width: 0; }
section { margin: 48px 0; }
.chapter { margin: 0 0 4px; color: var(--muted); font-size: 14px; }
h2 { margin: 0 0 16px; font-size: 32px; }
h3 { margin: 32px 0 10px; font-size: 22px; }
h4 { margin: 0 0 6px; font-size: 15px; }
blockquote {
  margin: 16px 0;
  padding: 20px 24px;
  background: var(--tint);
  border-radius: 8px;
  font: 600 23px/1.35 "IBM Plex Serif", Georgia, serif;
  color: var(--teal-dark);
}
.goals { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; padding: 0; list-style: none; }
.goals li { padding: 14px; background: var(--tint); border-radius: 8px; }
.goals strong { display: block; }

code, pre { font-family: "IBM Plex Mono", Consolas, monospace; }
:not(pre) > code { padding: 1px 5px; background: var(--tint); border-radius: 4px; font-size: .92em; overflow-wrap: anywhere; }
.code {
  margin: 12px 0;
  padding: 14px 16px;
  overflow-x: auto;
  color: var(--code-ink);
  background: var(--code-bg);
  border-radius: 8px;
  font-size: 14px;
  line-height: 1.55;
}
.tok-comment { color: #8fb7a8; font-style: italic; }
.tok-keyword { color: #7fd4ec; }
.tok-string { color: #f3c98b; }
.tok-number { color: #f2a7a0; }

.compare { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; margin: 16px 0; }
.compare .code { margin: 0; }
.bad h4 { color: var(--red); }
.good h4 { color: var(--green); }

.tabs { display: flex; gap: 8px; margin-top: 12px; }
.tab { padding: 6px 18px; background: #fff; border: 1px solid var(--line); border-radius: 6px; color: var(--ink); }
.tab[aria-pressed="true"] { color: #fff; background: var(--teal); border-color: var(--teal); }
.primary { padding: 8px 16px; color: #fff; background: var(--teal); border: 0; border-radius: 6px; font-weight: 600; }
.primary:hover { background: var(--teal-dark); }
.run-row { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; }
#rsi-output { font-family: "IBM Plex Mono", Consolas, monospace; font-size: 14px; }

.quiz { padding: 20px; background: var(--tint); border-radius: 8px; }
.quiz p { margin: 0; }
.quiz-count, .quiz-context { color: var(--muted); font-size: 14px; }
.quiz-name { margin: 6px 0 !important; font-size: 26px; }
.quiz-name code { background: #fff; overflow-wrap: anywhere; }
.quiz-buttons { display: flex; flex-wrap: wrap; gap: 8px; margin: 14px 0 10px; }
.quiz-buttons button { padding: 8px 20px; color: #fff; background: var(--teal); border: 0; border-radius: 6px; font-weight: 600; }
.quiz-buttons button:hover { background: var(--teal-dark); }
.quiz-feedback { min-height: 1.65em; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 8px 10px; text-align: left; border-bottom: 1px solid var(--line); }
th { color: var(--muted); font-size: 14px; }
td code { white-space: nowrap; overflow-wrap: normal; }

.converter-label { display: block; margin-bottom: 4px; font-weight: 600; }
#case-input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid #8ea4ac;
  border-radius: 6px;
  font: 16px "IBM Plex Mono", Consolas, monospace;
}
.converter { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 4px 16px; margin: 12px 0; }
.converter dt { color: var(--muted); font-size: 14px; align-self: center; }
.converter dd { margin: 0; font-family: "IBM Plex Mono", Consolas, monospace; overflow-wrap: anywhere; }

.thanks { text-align: center; }
.thanks p { margin: 0 0 16px; color: var(--muted); }
.final-ad {
  display: inline-block;
  max-width: 508px;
  overflow: hidden;
  color: var(--ad-navy);
  background: var(--ad-yellow);
  border-radius: 8px;
  font: 700 24px var(--pixel);
  text-decoration: none;
}
.final-ad span { display: block; padding: 10px; }
.final-ad:hover { filter: brightness(1.08); }

footer { padding: 16px 24px 32px; color: var(--muted); font-size: 14px; text-align: center; }
footer p { margin: 0; }

/* The ads: deliberately nothing like the textbook */
.ad {
  position: relative;
  display: flex;
  overflow: hidden;
  color: var(--ad-yellow);
  background: var(--ad-navy);
  font-family: var(--pixel);
  line-height: 1.15;
}
.ad > a { display: flex; flex: 1; min-width: 0; color: inherit; text-decoration: none; }
.ad img { image-rendering: pixelated; object-fit: cover; }
.ad-kicker { display: block; margin-bottom: 4px; font-size: 12px; font-weight: 500; letter-spacing: .06em; opacity: .85; }
.ad-title { display: block; font-size: 25px; font-weight: 700; text-wrap: balance; }
.ad-text { display: block; margin-top: 4px; color: #fff; font-size: 16px; font-weight: 500; line-height: 1.25; }
.ad-cta {
  display: inline-block;
  margin-top: 8px;
  padding: 5px 12px;
  color: #fff;
  background: var(--ad-red);
  font-size: 16px;
  font-weight: 700;
  box-shadow: 3px 3px 0 #000;
  animation: ad-pulse .9s steps(2) infinite;
}
.ad-close {
  position: absolute;
  top: 2px;
  right: 2px;
  z-index: 1;
  width: 24px;
  height: 24px;
  padding: 0;
  color: #fff;
  background: rgba(0, 0, 0, .55);
  border: 0;
  font-size: 13px;
  line-height: 1;
}
.ad-theme-red { color: #fff; background: var(--ad-red); }
.ad-theme-red .ad-cta { color: var(--ad-navy); background: var(--ad-yellow); }
.ad-theme-purple { color: var(--ad-green); background: var(--ad-purple); }
.ad-theme-yellow { color: var(--ad-navy); background: var(--ad-yellow); }
.ad-theme-yellow .ad-text { color: var(--ad-navy); }

.top-ad {
  position: sticky;
  top: 0;
  z-index: 20;
  height: var(--top-ad-height);
  background: var(--ad-navy);
  box-shadow: 0 2px 8px rgba(0, 0, 0, .35);
}
.top-ad .ad { height: 100%; justify-content: center; }
.top-ad .ad > a { flex: 0 1 960px; align-items: center; gap: 16px; padding-right: 28px; }
.top-ad img { height: var(--top-ad-height); width: auto; aspect-ratio: 2 / 1; flex: none; }
.top-ad .ad-copy { flex: 1; min-width: 0; }
.top-ad .ad-kicker, .top-ad .ad-text { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top-ad .ad-title { font-size: 24px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top-ad .ad-cta { flex: none; margin: 0; }

.sky { position: sticky; top: calc(var(--top-ad-height) + 16px); align-self: start; }
.sky .ad > a { flex-direction: column; }
.sky img { width: 100%; aspect-ratio: 397 / 315; }
.sky .ad-copy { padding: 12px; min-height: 340px; }
.sky .ad-title { font-size: 24px; overflow-wrap: break-word; }

[data-ad-slot="card"] { margin: 32px 0; }
.ad-card > a { align-items: stretch; }
.ad-card img { width: 42%; flex: none; aspect-ratio: 397 / 315; }
.ad-card .ad-copy { flex: 1; min-width: 0; padding: 16px 32px 16px 16px; align-self: center; }
.ad-card .ad-title { font-size: 31px; }

/* Search-result style text ad */
[data-ad-slot="text"] { margin: 32px 0; }
.ad-search {
  display: block;
  padding: 14px 16px;
  color: #1a1a1a;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-family: Arial, sans-serif;
  line-height: 1.4;
}
.ad-search > a { display: block; }
.ad-search small { color: #333; font-size: 13px; }
.ad-search b { display: block; color: #1a0dab; font-size: 20px; font-weight: 400; }
.ad-search > a:hover b { text-decoration: underline; }
.ad-search span { font-size: 14px; }

/* "Around the web" clickbait grid */
[data-ad-slot="chum"] { margin: 32px 0; }
.chum-title { margin: 0 0 8px; color: var(--muted); font-size: 13px; }
.chum-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.chum-grid a { color: var(--ink); font: 700 15px/1.25 Arial, sans-serif; text-decoration: none; }
.chum-grid a:hover { text-decoration: underline; }
.chum-grid img { width: 100%; aspect-ratio: 16 / 10; margin-bottom: 6px; object-fit: cover; image-rendering: pixelated; }

.ticker {
  position: fixed;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 20;
  height: var(--ticker-height);
  overflow: hidden;
  color: var(--ad-navy);
  background: var(--ad-yellow);
  font: 700 18px/34px var(--pixel);
  white-space: nowrap;
}
.ticker-track { display: inline-block; animation: ticker 70s linear infinite; }

.corner-ad {
  position: fixed;
  right: 16px;
  bottom: calc(var(--ticker-height) + 16px);
  z-index: 25;
  width: 260px;
  color: var(--ad-yellow);
  background: var(--ad-navy);
  box-shadow: 0 6px 24px rgba(0, 0, 0, .5);
  font-family: var(--pixel);
}
.corner-ad[hidden] { display: none; }
.corner-bar { display: flex; justify-content: space-between; align-items: center; padding: 4px 4px 4px 8px; font-size: 13px; }
.corner-bar button { padding: 2px 8px; color: #fff; background: #000; border: 1px solid #fff; font-size: 13px; }
.corner-bar button:disabled { cursor: default; opacity: .7; }
.corner-ad a { display: block; color: inherit; text-decoration: none; }
.corner-ad img { width: 100%; image-rendering: pixelated; }
.corner-ad strong { display: block; padding: 8px; font-size: 19px; line-height: 1.1; }

.interstitial {
  width: min(520px, calc(100vw - 32px));
  max-height: calc(100dvh - 32px);
  padding: 24px;
  color: #fff;
  background: var(--ad-purple);
  border: 6px solid var(--ad-yellow);
  font-family: var(--pixel);
  text-align: center;
  overflow-y: auto;
}
.interstitial::backdrop { background: rgba(0, 0, 0, .7); }
.interstitial h2 { margin: 8px 0; color: var(--ad-yellow); font: 700 30px/1.1 var(--pixel); }
.interstitial p { margin: 8px 0; font-size: 18px; line-height: 1.25; }
.interstitial img { width: 70%; margin: 10px auto; image-rendering: pixelated; }
.interstitial .cta {
  display: inline-block;
  padding: 10px 20px;
  color: #fff;
  background: var(--ad-red);
  box-shadow: 4px 4px 0 #000;
  font-size: 22px;
  font-weight: 700;
  text-decoration: none;
  animation: ad-pulse .9s steps(2) infinite;
}
.interstitial .fine-print { margin-top: 14px; font-size: 13px; opacity: .85; }
.burst {
  display: inline-block;
  margin: 0 !important;
  padding: 26px 22px;
  color: var(--ad-red);
  background: var(--ad-yellow);
  font-size: 18px !important;
  font-weight: 700;
  transform: rotate(-8deg);
  clip-path: polygon(50% 0, 61% 18%, 82% 7%, 82% 29%, 100% 35%, 87% 50%, 100% 65%, 82% 71%, 82% 93%, 61% 82%, 50% 100%, 39% 82%, 18% 93%, 18% 71%, 0 65%, 13% 50%, 0 35%, 18% 29%, 18% 7%, 39% 18%);
}
.runaway {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 36px;
  height: 36px;
  padding: 0;
  color: #fff;
  background: #000;
  border: 1px solid #fff;
}

.toast {
  position: fixed;
  left: 16px;
  bottom: calc(var(--ticker-height) + 16px);
  z-index: 30;
  max-width: 320px;
  margin: 0;
  padding: 10px 14px;
  color: #fff;
  background: var(--ink);
  border-radius: 6px;
  font-size: 15px;
}
.toast[hidden] { display: none; }

@keyframes ad-pulse { 50% { filter: brightness(1.35); transform: translateY(-1px); } }
@keyframes ticker { to { transform: translateX(-50%); } }

@media (max-width: 1240px) {
  .layout { grid-template-columns: minmax(0, 760px); padding: 16px 20px; }
  .sky { display: none; }
}
@media (max-width: 680px) {
  :root { --top-ad-height: 72px; }
  body { font-size: 16px; }
  h2 { font-size: 27px; }
  .hero { padding: 32px 20px 28px; }
  .goals, .compare { grid-template-columns: minmax(0, 1fr); }
  .chum-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .chum-grid a:nth-child(3) { display: none; }
  .top-ad img, .top-ad .ad-text, .top-ad .ad-cta { display: none; }
  .top-ad .ad > a { padding: 0 32px 0 12px; }
  .top-ad .ad-title { font-size: 20px; white-space: normal; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
  .ad-card > a { flex-direction: column; }
  .ad-card img { width: 100%; }
  .ad-card .ad-copy { align-self: stretch; padding: 14px; }
  .corner-ad { width: 190px; right: 8px; }
  .corner-ad strong { font-size: 16px; }
}
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .ad-cta, .interstitial .cta, .ticker-track { animation: none; }
}

@media (max-width: 680px), (max-height: 600px) {
  #challenge { padding: 14px; }
  #challenge h2 { font-size: 24px; }
  #challenge p { font-size: 16px; }
  #challenge .burst { padding: 18px 16px; font-size: 15px !important; }
  #challenge .cta { font-size: 19px; padding: 8px 14px; }
}
