.lesson-preview {
  margin-top: 20px;
  border-top: 1px solid #d8e1dc;
  padding-top: 14px;
}

.lesson-preview summary {
  padding: 10px 12px;
  border: 1px solid #bdcfc8;
  border-radius: 8px;
  background: #eff6f2;
}

.lesson-preview summary:focus-visible {
  outline: 3px solid #2787c4;
  outline-offset: 3px;
}

dialog:has(.lesson-preview[open]) {
  width: min(756px, 94vw);
}

.lesson-figure {
  --figure-accent: #66d4b9;
  --figure-edge: #639b97;
  container-type: inline-size;
  margin: 18px 0 22px;
  padding: clamp(14px, 3vw, 26px);
  border-radius: 15px;
  background: #18343e;
  color: #f5fbf8;
}

.lesson-figure[data-figure="compare"] {
  --figure-accent: #9cdcf5;
  --figure-edge: #749aa9;
}

.lesson-figure[data-figure="cycle"] {
  --figure-accent: #e4ecac;
  --figure-edge: #9cae75;
}

.lesson-figure__heading {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
}

.lesson-figure__heading h3 {
  font-size: clamp(1rem, 2.8cqi, 1.3rem);
  line-height: 1.5;
  overflow-wrap: anywhere;
}

.lesson-figure__kind {
  padding: 2px 8px;
  border: 1px solid var(--figure-edge);
  border-radius: 5px;
  color: var(--figure-accent);
  font-size: .75rem;
  font-weight: 700;
}

.lesson-figure__diagram {
  margin: 16px 0;
  padding: clamp(12px, 3cqi, 20px);
  border: 1px solid #46636a;
  border-radius: 11px;
  background-color: #102b36;
  background-image: radial-gradient(#375661 1px, transparent 1px);
  background-size: 14px 14px;
}

.lesson-figure__nodes {
  --node-gap: 24px;
  display: flex;
  gap: var(--node-gap);
  list-style: none;
  padding: 0;
  margin: 0;
}

.lesson-figure__node {
  flex: 1;
  min-width: 0;
  position: relative;
  display: grid;
}

.lesson-figure__node:not(:last-child)::after,
.lesson-figure__node:not(:last-child)::before {
  position: absolute;
  pointer-events: none;
  content: "";
  color: var(--figure-edge);
}

.lesson-figure__node:not(:last-child)::after {
  left: 100%;
  top: 50%;
  width: var(--node-gap);
  border-top: 2px solid;
}

.lesson-figure__node:not(:last-child)::before {
  z-index: 1;
  left: calc(100% + var(--node-gap) / 2 - 4px);
  top: calc(50% - 3px);
  width: 6px;
  height: 6px;
  border: solid;
  border-width: 2px 2px 0 0;
  transform: rotate(45deg);
}

[data-figure="compare"] .lesson-figure__node:not(:last-child)::after {
  border-top-style: dashed;
}

[data-figure="compare"] .lesson-figure__node:not(:last-child)::before {
  display: none;
}

.lesson-figure__step {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  gap: 4px;
  padding: 9px;
  min-height: 62px;
  border: 1px solid var(--figure-edge);
  border-radius: 8px;
  color: #eaf5f2;
  background: #234551;
  text-align: left;
  overflow-wrap: anywhere;
  font-size: clamp(.86rem, 2.35cqi, 1rem);
  line-height: 1.45;
}

.lesson-figure__step:hover {
  border-color: var(--figure-accent);
  background: #2f5561;
}

.lesson-figure__step[aria-pressed="true"] {
  border-color: var(--figure-accent);
  box-shadow: inset 0 -3px var(--figure-accent);
  color: white;
  background: #31535a;
}

.lesson-figure__step:focus-visible {
  outline-color: #f5fcfb;
}

.lesson-figure__number {
  display: grid;
  place-items: center;
  min-width: 21px;
  height: 21px;
  border-radius: 50%;
  background: var(--figure-accent);
  color: #17343a;
  font-size: .73rem;
  font-weight: 800;
}

.lesson-figure__return {
  position: relative;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  margin: 0 16px;
  height: 23px;
  border: 2px solid var(--figure-edge);
  border-top: 0;
  border-radius: 0 0 9px 9px;
  color: var(--figure-accent);
  font-size: .72rem;
  line-height: 1;
}

.lesson-figure__return::before {
  content: "";
  position: absolute;
  top: 2px;
  left: -5px;
  width: 6px;
  height: 6px;
  border: solid var(--figure-edge);
  border-width: 2px 2px 0 0;
  transform: rotate(-45deg);
}

.lesson-figure__return span {
  padding: 0 7px;
  background: #102b36;
  transform: translateY(50%);
}

.lesson-figure__note {
  border-left: 3px solid var(--figure-accent);
  border-radius: 0 7px 7px 0;
  padding: 9px 12px;
  background: #284650;
  overflow-wrap: anywhere;
}

.lesson-figure__note strong {
  color: var(--figure-accent);
}

.lesson-figure__note p {
  margin: 3px 0 0;
  font-size: .94rem;
  white-space: pre-line;
}

.lesson-figure figcaption {
  margin-top: 12px;
  color: #d9eae9;
  font-size: .87rem;
  overflow-wrap: anywhere;
}

.schematic {
  margin-top: 16px;
  padding: clamp(10px, 2.7cqi, 18px);
  border: 1px solid #46636a;
  border-radius: 11px;
  background: #102b36;
}

.schematic h4,
.schematic h5 {
  margin: 0;
  line-height: 1.45;
}

.schematic h4 {
  font-size: .97rem;
}

.schematic h5 {
  color: var(--route-accent);
  font-size: .87rem;
}

.schematic h5 span {
  margin-left: .45rem;
  color: #c8dbde;
  font-weight: 400;
}

.schematic__lane {
  --route-accent: #9cdcf5;
  margin-top: 10px;
}

.schematic__lane--secondary {
  --route-accent: #a8e3b6;
  margin-top: 13px;
  padding-top: 12px;
  border-top: 1px solid #46636a;
}

.schematic__route {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(56px, .62fr) minmax(0, 1fr);
  align-items: stretch;
  gap: 5px;
  margin-top: 6px;
}

.schematic__route--network {
  grid-template-columns: minmax(0, 1fr) minmax(54px, .60fr) minmax(0, 1fr) minmax(62px, .60fr) minmax(0, 1fr);
}

.schematic__actor {
  display: grid;
  align-content: center;
  gap: 2px;
  padding: 6px 7px;
  border: 1px solid #6a919a;
  border-radius: 6px;
  background: #234551;
  text-align: center;
  overflow-wrap: anywhere;
  font-size: .83rem;
  line-height: 1.35;
}

.schematic__actor > span {
  color: #d8e9ec;
  font-size: .78rem;
}

.schematic__actor .schematic__key {
  justify-self: center;
  margin-top: 2px;
  padding: 2px 4px;
  border-radius: 4px;
  background: #102b36;
  color: var(--route-accent);
  font-weight: 700;
  word-break: keep-all;
}

.schematic__link {
  display: grid;
  align-content: center;
  gap: 4px;
  min-width: 0;
  color: var(--route-accent);
  text-align: center;
  font-size: .75rem;
  font-weight: 700;
  line-height: 1.25;
}

.schematic__arrow {
  position: relative;
  display: block;
  height: 2px;
  margin: 0 3px;
  background: currentColor;
}

.schematic__arrow::after,
.schematic__arrow--both::before {
  content: "";
  position: absolute;
  top: -3px;
  width: 6px;
  height: 6px;
  border: solid currentColor;
  border-width: 2px 2px 0 0;
}

.schematic__arrow::after {
  right: 0;
  transform: rotate(45deg);
}

.schematic__arrow--both::before {
  left: 0;
  transform: rotate(-135deg);
}

@container (max-width: 435px) {
  .schematic__route--network {
    grid-template-columns: minmax(0, 1fr);
  }

  .schematic__route--network .schematic__actor {
    grid-template-columns: 1fr 1fr;
    gap: 5px;
  }

  .schematic__route--network .schematic__link {
    grid-template-columns: 1fr 1fr;
    align-items: center;
    min-height: 20px;
  }

  .schematic__route--network .schematic__link > span:first-child {
    justify-self: end;
    padding-right: 10px;
  }

  .schematic__route--network .schematic__arrow {
    width: 15px;
    margin-left: -10px;
    transform: rotate(90deg);
  }
}

@container (max-width: 490px) {
  .lesson-figure__nodes {
    --node-gap: 18px;
    flex-direction: column;
  }

  .lesson-figure__step {
    flex-direction: row;
    align-items: center;
    justify-content: flex-start;
    gap: 9px;
    min-height: 44px;
  }

  .lesson-figure__node:not(:last-child)::after {
    left: 20px;
    top: 100%;
    width: 0;
    height: var(--node-gap);
    border-top: 0;
    border-left: 2px solid;
  }

  .lesson-figure__node:not(:last-child)::before {
    left: 17px;
    top: calc(100% + 4px);
    transform: rotate(135deg);
  }

  [data-figure="compare"] .lesson-figure__node:not(:last-child)::after {
    border-left-style: dashed;
  }

  .lesson-figure__diagram:has(.lesson-figure__return) {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 32px;
  }

  .lesson-figure__return {
    height: auto;
    margin: 22px 9px 22px 0;
    border: 2px solid var(--figure-edge);
    border-left: 0;
    border-radius: 0 9px 9px 0;
    align-items: center;
    justify-content: flex-end;
  }

  .lesson-figure__return::before {
    top: -5px;
    left: 2px;
    transform: rotate(-135deg);
  }

  .lesson-figure__return span {
    padding: 7px 0;
    writing-mode: vertical-rl;
    transform: translateX(50%);
  }
}

@media (max-width: 470px) {
  dialog:has(.lesson-preview) {
    padding: 18px;
  }
}
