/* Live OpenCV demos */

.cv-demo {
  margin: 1.5rem 0;
  padding: 1rem;
  border: 1px solid rgba(138, 109, 29, 0.35);
  border-radius: 14px;
}

.cv-demo__views {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

.cv-demo__views figure {
  margin: 0;
}

.cv-demo__views figcaption {
  font-size: 0.85rem;
  opacity: 0.75;
  text-align: center;
  margin-top: 0.25rem;
}

.cv-demo video,
.cv-demo canvas {
  display: block;
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  background: #000;
  border-radius: 10px;
}

.cv-demo__controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem 1.5rem;
  margin-top: 0.9rem;
}

.cv-demo__controls label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.9rem;
}

.cv-demo__controls input[type="range"] {
  accent-color: #cfb97d;
}

.cv-demo__controls output {
  min-width: 2.5em;
  font-variant-numeric: tabular-nums;
}

.cv-demo__status {
  margin: 0.6rem 0 0;
  font-size: 0.85rem;
  opacity: 0.75;
}

@media (max-width: 600px) {
  .cv-demo__views {
    grid-template-columns: 1fr;
  }
}

/* Figures drawn as inline SVG */

.loop-figure {
  display: block;
  width: 100%;
  max-width: 640px;
  margin: 0.5rem auto;
}

.loop-figure__box rect {
  fill: rgba(207, 185, 125, 0.08);
  stroke: rgba(207, 185, 125, 0.55);
  stroke-width: 1.5;
}

.loop-figure__box rect.loop-figure__accent {
  fill: rgba(207, 185, 125, 0.22);
  stroke: #cfb97d;
}

.loop-figure__label text {
  fill: currentColor;
  font-family: "Nunito Sans", sans-serif;
  font-size: 17px;
  font-weight: 700;
}

.loop-figure__note text {
  fill: currentColor;
  opacity: 0.65;
  font-family: "Open Sans", sans-serif;
  font-size: 12px;
}

/* Timeline: alternating cards on a gold line, one column on phones */

.timeline {
  position: relative;
  margin: 2rem 0 2.2rem;
  padding: 0;
  list-style: none;
}

.timeline::before {
  position: absolute;
  top: 0.5rem;
  bottom: 0.5rem;
  left: 50%;
  width: 2px;
  background: linear-gradient(to bottom, rgba(207, 185, 125, 0.15), #cfb97d 12%, #cfb97d 88%, rgba(207, 185, 125, 0.15));
  content: "";
  transform: translateX(-50%);
}

.timeline__item {
  position: relative;
  width: calc(50% - 1.75rem);
  margin: 0 0 1.1rem;
  padding: 0.85rem 1.05rem 0.95rem;
  border: 1px solid rgba(207, 185, 125, 0.3);
  border-radius: 14px;
  background: rgba(207, 185, 125, 0.06);
  transition: transform 160ms ease, border-color 160ms ease, box-shadow 160ms ease;
}

.timeline__item:nth-child(odd) {
  margin-right: auto;
  text-align: right;
}

.timeline__item:nth-child(even) {
  margin-left: auto;
}

/* Dot on the center line */
.timeline__item::after {
  position: absolute;
  top: 1.15rem;
  width: 14px;
  height: 14px;
  border: 3px solid #cfb97d;
  border-radius: 50%;
  background: var(--bs-body-bg, #fff);
  content: "";
}

.timeline__item:nth-child(odd)::after {
  right: calc(-1.75rem - 7px);
}

.timeline__item:nth-child(even)::after {
  left: calc(-1.75rem - 7px);
}

.timeline__item:hover {
  border-color: #cfb97d;
  transform: translateY(-2px);
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.1);
}

.timeline__year {
  display: inline-block;
  padding: 0.1rem 0.65rem;
  border-radius: 999px;
  background: #343607;
  color: #f7df91;
  font-family: "Nunito Sans", sans-serif;
  font-size: 0.85rem;
  font-weight: 800;
  letter-spacing: 0.04em;
}

.timeline__title {
  display: block;
  margin: 0.4rem 0 0.25rem;
  font-family: "Nunito Sans", sans-serif;
  font-size: 1.12rem;
  font-weight: 800;
  line-height: 1.3;
}

.timeline__text {
  display: block;
  font-size: 0.93rem;
  line-height: 1.6;
  opacity: 0.85;
}

.timeline__item--now {
  border-style: dashed;
  border-color: #cfb97d;
}

.timeline__item--now::after {
  background: #cfb97d;
  box-shadow: 0 0 0 6px rgba(207, 185, 125, 0.25);
}

/* On wide screens the alternating cards interleave */
@media (min-width: 701px) {
  .timeline__item + .timeline__item {
    margin-top: -3.4rem;
  }
}

@media (max-width: 700px) {
  .timeline::before {
    left: 9px;
  }

  .timeline__item,
  .timeline__item:nth-child(odd),
  .timeline__item:nth-child(even) {
    width: auto;
    margin-left: 2rem;
    margin-right: 0;
    text-align: left;
  }

  .timeline__item:nth-child(odd)::after,
  .timeline__item:nth-child(even)::after {
    left: calc(-2rem + 2px);
    right: auto;
  }
}

/* Video clips: autoplay, muted, looping */

.clip,
.clip-grid,
.camo {
  margin: 1.5rem 0;
}

.clip video {
  display: block;
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
  border-radius: 14px;
}

main figure.clip-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.6rem;
}

.clip-grid video {
  width: 100%;
  aspect-ratio: 16 / 10;
  object-fit: cover;
  border-radius: 12px;
  background: #000;
}

.clip-grid figcaption {
  grid-column: 1 / -1;
}

.clip figcaption,
.clip-grid figcaption,
.camo figcaption {
  margin-top: 0.6rem;
  font-size: 0.9rem;
  opacity: 0.75;
  text-align: center;
}

@media (max-width: 600px) {
  main figure.clip-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* Camouflage demo */

.camo__stage {
  position: relative;
  overflow: hidden;
  border-radius: 14px;
  aspect-ratio: 16 / 9;
  background: #000;
}

.camo__stage img,
.camo__stage video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.camo__mask {
  mix-blend-mode: screen;
  opacity: 0.85;
}

.camo__controls {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.5rem;
  margin-top: 0.75rem;
}

/* Small line drawings on the timeline cards */

.timeline__icon {
  float: left;
  width: 64px;
  height: 64px;
  margin: 0.15rem 0.85rem 0.3rem 0;
  padding: 6px;
  border-radius: 12px;
  background: rgba(207, 185, 125, 0.12);
  fill: none;
  stroke: #b39a52;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.timeline__icon .f {
  fill: rgba(207, 185, 125, 0.45);
}

.timeline__item:nth-child(odd) .timeline__icon {
  float: right;
  margin: 0.15rem 0 0.3rem 0.85rem;
}

.timeline__item::before {
  display: table;
  content: "";
}

.timeline__text::after {
  display: block;
  clear: both;
  content: "";
}

html[data-theme="dark"] .timeline__icon {
  stroke: #d6bd72;
}

@media (max-width: 700px) {
  .timeline__item:nth-child(odd) .timeline__icon {
    float: left;
    margin: 0.15rem 0.85rem 0.3rem 0;
  }
}

/* Bird versus insect comparison */

.versus {
  position: relative;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.1rem;
  margin: 1.6rem 0;
}

main figure.versus__card {
  overflow: hidden;
  margin: 0;
  border: 1px solid rgba(207, 185, 125, 0.3);
  border-radius: 18px;
  background: rgba(207, 185, 125, 0.06);
  transition: transform 180ms ease, box-shadow 180ms ease, border-color 180ms ease;
}

main figure.versus__card:hover {
  border-color: #cfb97d;
  transform: translateY(-3px);
  box-shadow: 0 14px 32px rgba(0, 0, 0, 0.14);
}

.versus__media {
  position: relative;
  aspect-ratio: 4 / 3;
  overflow: hidden;
}

.versus__media img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 400ms ease;
}

main figure.versus__card:hover .versus__media img {
  transform: scale(1.04);
}

.versus__media::after {
  position: absolute;
  inset: auto 0 0 0;
  height: 45%;
  background: linear-gradient(to top, rgba(0, 0, 0, 0.55), transparent);
  content: "";
}

.versus__tag {
  position: absolute;
  z-index: 1;
  left: 0.9rem;
  bottom: 0.8rem;
  padding: 0.2rem 0.75rem;
  border-radius: 999px;
  background: rgba(5, 6, 0, 0.7);
  color: #f7df91;
  font-family: "Nunito Sans", sans-serif;
  font-size: 0.8rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  backdrop-filter: blur(6px);
}

.versus__card figcaption {
  padding: 0.9rem 1.1rem 1.1rem;
  text-align: left;
}

.versus__card figcaption strong {
  display: block;
  margin-bottom: 0.55rem;
  font-family: "Nunito Sans", sans-serif;
  font-size: 1.2rem;
  font-weight: 800;
}

.versus__facts {
  display: grid;
  gap: 0.35rem;
  font-size: 0.92rem;
}

.versus__facts b {
  display: inline-block;
  min-width: 5.2rem;
  color: #b39a52;
  font-family: "Nunito Sans", sans-serif;
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

html[data-theme="dark"] .versus__facts b {
  color: #d6bd72;
}

.versus__vs {
  position: absolute;
  z-index: 2;
  top: calc((100% - 0px) * 0.36);
  left: 50%;
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  border: 3px solid var(--bs-body-bg, #fff);
  border-radius: 50%;
  background: #cfb97d;
  color: #1d1e00;
  font-family: "Nunito Sans", sans-serif;
  font-size: 0.9rem;
  font-weight: 900;
  text-transform: uppercase;
  transform: translate(-50%, -50%);
}

@media (max-width: 600px) {
  .versus {
    grid-template-columns: 1fr;
  }

  .versus__vs {
    display: none;
  }
}

.versus__credit {
  grid-column: 1 / -1;
  margin: -0.4rem 0 0;
  font-size: 0.78rem;
  opacity: 0.6;
  text-align: right;
}


/* Interactive figures (Chapter 2 and later) */

.sim {
  margin: 1.5rem 0;
  padding: 1rem;
  border: 1px solid rgba(207, 185, 125, 0.32);
  border-radius: 16px;
  background: rgba(207, 185, 125, 0.05);
}

.sim__svg,
.sim__canvas,
.sim__image {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 12px;
}

.sim__svg {
  background: rgba(207, 185, 125, 0.06);
}

.sim__canvas--chart {
  max-width: 480px;
  margin: 0 auto;
  background: #000;
}

.sim__canvas--pixels {
  image-rendering: pixelated;
}

.sim__controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.6rem 1.4rem;
  margin-top: 0.9rem;
}

.sim__controls label,
.sim__group {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.9rem;
}

.sim__controls input[type="range"] {
  accent-color: #cfb97d;
}

.sim__controls output {
  min-width: 4.5em;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}

.sim .btn.is-on {
  background: #343607;
  color: #f7df91;
  border-color: #a79047;
}

.sim__readout {
  margin: 0.7rem 0 0;
  font-size: 0.9rem;
}

.sim__pair,
.sim__trio {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.8rem;
}

.sim__trio {
  grid-template-columns: repeat(3, 1fr);
}

.sim__pair figure,
.sim__trio figure {
  margin: 0;
}

.sim__pair canvas,
.sim__trio canvas {
  display: block;
  width: 100%;
  border-radius: 12px;
  background: #111;
}

.sim__trio canvas {
  aspect-ratio: 4 / 3;
}

.sim__pair figcaption,
.sim__trio figcaption {
  margin-top: 0.3rem;
  font-size: 0.85rem;
  opacity: 0.7;
  text-align: center;
}

/* Pinhole drawing */
.sim__axis { stroke: currentColor; stroke-opacity: 0.25; stroke-dasharray: 4 5; }
.sim__object { stroke: #2f8f5b; stroke-width: 5; stroke-linecap: round; }
.sim__projected { stroke: #cfb97d; stroke-width: 5; stroke-linecap: round; }
.sim__ray { stroke: #cfb97d; stroke-width: 1.6; stroke-opacity: 0.85; }
.sim__ray--faint { stroke-opacity: 0.35; }
.sim__plane { stroke: currentColor; stroke-opacity: 0.45; stroke-width: 2; }
.sim__barrier { stroke: currentColor; stroke-width: 6; stroke-opacity: 0.75; }

@media (max-width: 600px) {
  .sim__trio {
    grid-template-columns: 1fr;
  }
}
.sim__label { fill: currentColor; font-family: 'Nunito Sans', sans-serif; font-size: 14px; font-weight: 700; text-anchor: middle; opacity: 0.75; }

