/* Lecture 03: iterative binary digits */
.binary-layout {
  width: min(100%, 780px);
}

.binary-ladder {
  display: grid;
  gap: 5px;
  max-width: 640px;
  margin: 0 auto;
}

.ladder-row {
  display: grid;
  grid-template-columns: 42px minmax(95px, 1fr) minmax(90px, 0.75fr) minmax(120px, 1fr);
  align-items: center;
  gap: 8px;
  min-height: 38px;
  padding: 4px 9px;
  color: var(--muted);
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-family: var(--mono);
  font-size: 0.77rem;
}

.ladder-row.is-active {
  color: #6d430f;
  background: var(--accent-soft);
  border-color: var(--accent);
}

.ladder-row.is-false {
  color: #8c2a34;
  background: var(--danger-soft);
  border-color: #edc2c7;
}

.ladder-step {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  color: #fff;
  background: var(--brand);
  border-radius: 50%;
  font-size: 0.75rem;
  font-weight: 850;
}

.ladder-condition {
  font-weight: 760;
}

.binary-summary {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin-top: 18px;
}

/* Lecture 03: Tower of Hanoi */
.hanoi-layout {
  width: min(100%, 900px);
}

.hanoi-trace-layout {
  display: grid;
  grid-template-columns: minmax(330px, 1fr) minmax(170px, 0.42fr);
  align-items: stretch;
  gap: 12px;
}

.hanoi-board-column {
  min-width: 0;
}

.hanoi-trace-layout .hanoi-board {
  grid-template-columns: repeat(3, minmax(90px, 1fr));
  gap: 10px;
}

.hanoi-board {
  position: relative;
  display: grid;
  grid-template-columns: repeat(3, minmax(120px, 1fr));
  gap: 18px;
  min-height: 245px;
  padding: 10px 8px 42px;
}

.hanoi-board::after {
  content: "";
  position: absolute;
  right: 0;
  bottom: 38px;
  left: 0;
  height: 7px;
  background: #81949d;
  border: 0;
  border-radius: 999px;
  box-shadow: none;
}

.peg-zone {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  min-width: 0;
  min-height: 200px;
  padding-bottom: 18px;
  border: 2px solid transparent;
  border-radius: 12px;
  cursor: default;
}

.hanoi-board.is-practice .peg-zone {
  cursor: pointer;
}

.hanoi-board.is-practice .peg-zone:hover {
  background: rgba(63, 94, 168, 0.045);
  border-color: rgba(63, 94, 168, 0.14);
}

.peg-zone.is-selected {
  background: var(--accent-soft) !important;
  border-color: var(--accent) !important;
}

.peg {
  position: absolute;
  bottom: 18px;
  width: 8px;
  height: 165px;
  background: #81949d;
  border: 0;
  border-radius: 999px 999px 2px 2px;
  box-shadow: none;
}

.disk-stack {
  position: relative;
  z-index: 2;
  display: flex;
  flex-direction: column-reverse;
  align-items: center;
  justify-content: flex-start;
  width: 100%;
}

.hanoi-disk {
  display: grid;
  place-items: center;
  width: var(--disk-width);
  height: 27px;
  margin-top: 2px;
  color: #fff;
  background: var(--brand);
  border: 1px solid var(--brand-deep);
  border-radius: 6px;
  box-shadow: none;
  font-family: var(--mono);
  font-size: 0.75rem;
  font-weight: 900;
}

.hanoi-disk.is-top {
  outline: 2px solid #bfcbea;
  outline-offset: 2px;
}

.hanoi-disk.is-current {
  color: #17333e;
  background: var(--accent);
  border-color: #a46d1f;
  box-shadow: 0 0 0 3px rgba(231, 143, 47, 0.18);
}

.hanoi-board.is-complete .hanoi-disk {
  color: #fff;
  background: var(--success);
  border-color: #226346;
}

.peg-label {
  position: absolute;
  bottom: -31px;
  z-index: 3;
  color: var(--brand);
  font-size: 1.04rem;
  font-weight: 850;
}

.hanoi-call-panel {
  display: flex;
  flex-direction: column;
  min-width: 0;
  padding: 10px;
  background: rgba(237, 244, 246, 0.82);
  border: 1px solid var(--border);
  border-radius: 10px;
}

.hanoi-call-panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 24px;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 820;
  letter-spacing: 0.07em;
  text-transform: uppercase;
}

.hanoi-phase {
  padding: 3px 6px;
  color: var(--muted);
  background: #fff;
  border-radius: 5px;
  font-size: 0.75rem;
  letter-spacing: 0.04em;
}

.hanoi-phase.is-call {
  color: #7a4710;
  background: var(--accent-soft);
}

.hanoi-phase.is-move {
  color: #176762;
  background: var(--teal-soft);
}

.hanoi-phase.is-return {
  color: var(--brand-deep);
  background: var(--brand-soft);
}

.hanoi-phase.is-complete {
  color: #205f44;
  background: var(--success-soft);
}

.hanoi-call-list {
  display: flex;
  flex-direction: column;
  gap: 5px;
  min-width: 0;
  margin: 0;
  padding: 0;
  list-style: none;
}

.hanoi-call-frame {
  display: grid;
  grid-template-columns: 18px minmax(0, 1fr) auto;
  align-items: center;
  gap: 5px;
  min-height: 27px;
  padding: 4px 6px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.72);
  border: 1px solid transparent;
  border-radius: 7px;
}

.hanoi-call-frame.is-active {
  color: var(--ink);
  background: var(--accent-soft);
  border-color: rgba(231, 143, 47, 0.58);
}

.hanoi-call-depth {
  color: var(--faint);
  font-family: var(--mono);
  font-size: 0.75rem;
  font-weight: 800;
}

.hanoi-call-frame code {
  overflow: hidden;
  color: inherit;
  font-size: 0.75rem;
  font-weight: 760;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.hanoi-call-frame small {
  color: var(--faint);
  font-size: 0.75rem;
  white-space: nowrap;
}

.hanoi-call-empty {
  padding: 8px 6px;
  color: var(--faint);
  font-size: 0.75rem;
}

.recursion-stack,
.recurrence-ladder {
  min-height: 0;
  padding: 10px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 10px;
}

.mini-panel-title {
  margin: 0 0 5px;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 820;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.practice-message {
  margin: 11px 0 0;
  padding: 9px 11px;
  color: var(--muted);
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 9px;
  text-align: center;
  font-size: 0.78rem;
  font-weight: 690;
}

.practice-message.is-error {
  color: #8c2a34;
  background: var(--danger-soft);
  border-color: #edc2c7;
}

.practice-message.is-success {
  color: #176654;
  background: var(--success-soft);
  border-color: #b8dfd5;
}

/* Lecture 03: recursive binary digits */
.recursive-layout {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) minmax(220px, 0.9fr);
  align-items: stretch;
  gap: 22px;
  width: min(100%, 840px);
}

.recursion-frames {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-height: 0;
  justify-content: flex-start;
}

.recursion-frame {
  position: relative;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 7px;
  padding: 5px 8px;
  color: var(--brand-deep);
  background: var(--brand-soft);
  border: 1px solid #c5d0e9;
  border-radius: 9px;
  font-family: var(--mono);
  font-size: 0.78rem;
}

.recursion-frame.is-active {
  background: var(--accent-soft);
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(216, 138, 36, 0.12);
}

.frame-status {
  margin-left: auto;
  color: var(--muted);
  font-family: var(--sans);
  font-size: 0.75rem;
  font-weight: 690;
}

.recurrence-steps {
  display: grid;
  gap: 4px;
}

.recurrence-step {
  padding: 5px 8px;
  color: var(--muted);
  background: #f5f8f9;
  border: 1px solid #e0e9ec;
  border-radius: 8px;
  font-family: var(--mono);
  font-size: 0.76rem;
}

.recurrence-step.is-active {
  color: #6d430f;
  background: var(--accent-soft);
  border-color: var(--accent);
}

.recurrence-step.is-pending {
  opacity: 0.38;
}

/* Master Theorem work profile */
.master-layout {
  --master-level-columns: 58px minmax(160px, 1fr) minmax(122px, 0.52fr);
  --master-level-gap: 7px;
  display: grid;
  gap: 3px;
  width: min(100%, 880px);
  line-height: 1.15;
}

.master-mechanism {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 5px;
}

.master-force {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-rows: auto auto;
  align-items: center;
  min-height: 38px;
  padding: 5px 9px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.9);
  border: 1px solid var(--border);
  border-radius: 8px;
}

.master-force small {
  overflow: hidden;
  font-size: 0.66rem;
  font-weight: 760;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.master-force strong {
  grid-row: 1 / 3;
  grid-column: 2;
  color: var(--ink);
  font-family: var(--mono);
  font-size: 0.98rem;
}

.master-force em {
  font-size: 0.62rem;
  font-style: normal;
}

.master-force-structure {
  color: var(--brand-deep);
  background: var(--brand-soft);
  border-color: #c7d3ed;
}

.master-force-total {
  color: var(--faint);
  background: var(--surface-strong);
}

.master-force-total strong {
  color: inherit;
}

.master-force-total.is-revealed {
  color: #176c67;
  background: var(--teal-soft);
  border-color: #a9d9d5;
}

.master-reading {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 24px;
  padding: 3px 8px;
  color: var(--muted);
  font-size: 0.7rem;
  text-align: center;
}

.master-reading.is-outcome {
  color: #6d430f;
  background: var(--accent-soft);
  border: 1px solid #f2d39e;
  border-radius: 7px;
}

.master-reading strong {
  color: inherit;
  letter-spacing: 0.035em;
  text-transform: uppercase;
}

.master-profile-key {
  display: grid;
  grid-template-columns: var(--master-level-columns);
  gap: var(--master-level-gap);
  min-height: 12px;
  padding: 0 5px;
  color: var(--faint);
  font-size: 0.6rem;
  font-weight: 700;
}

.master-profile-key span:first-child {
  grid-column: 2;
  text-align: center;
}

.master-profile-key span:last-child {
  grid-column: 3;
  text-align: center;
}

.master-profile {
  display: grid;
  gap: 1px;
}

.master-level {
  display: grid;
  grid-template-columns: var(--master-level-columns);
  align-items: center;
  gap: var(--master-level-gap);
  min-height: 24px;
  padding: 1px 5px;
  color: var(--muted);
  border: 1px solid transparent;
  border-radius: 7px;
  font-size: 0.68rem;
}

.master-level.is-active {
  color: var(--ink);
  background: var(--accent-soft);
  border-color: var(--accent);
}

.master-level.is-unrevealed {
  color: var(--faint);
  opacity: 0.5;
}

.master-level-index {
  display: flex;
  align-items: baseline;
  gap: 5px;
  color: var(--brand-deep);
  font-family: var(--mono);
  font-weight: 850;
  white-space: nowrap;
}

.master-level-index small {
  overflow: hidden;
  color: var(--faint);
  font-family: var(--sans);
  font-size: 0.58rem;
  font-weight: 700;
  text-overflow: ellipsis;
}

.master-work-band {
  justify-self: center;
  width: max(2px, var(--band-width));
  height: 18px;
  overflow: hidden;
  background-color: var(--teal);
  background-image: linear-gradient(to right, transparent calc(100% - 1px), rgba(255, 255, 255, 0.82) 0);
  background-size: var(--segment-width) 100%;
  border: 1px solid #17756f;
  border-radius: 4px;
}

.master-level.is-active .master-work-band {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.master-level.is-dominant .master-work-band {
  background-color: #167c76;
}

.master-band-placeholder {
  justify-self: stretch;
  width: 100%;
  border-top: 1px dashed var(--border-strong);
}

.master-level-equation {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 5px;
  min-width: 0;
  font-family: var(--mono);
  white-space: nowrap;
}

.master-level-equation span {
  overflow: hidden;
  text-overflow: ellipsis;
}

.master-level-equation strong,
.master-level-equation b {
  color: #176c67;
  font-weight: 850;
}

@media (max-width: 620px) {
  .recursive-layout {
    grid-template-columns: 1fr;
  }

  .hanoi-trace-layout {
    grid-template-columns: 1fr;
    gap: 7px;
  }

  .hanoi-trace-layout .hanoi-board {
    min-height: 188px;
    padding-block: 0 30px;
  }

  .hanoi-trace-layout .hanoi-board::after {
    bottom: 25px;
  }

  .hanoi-trace-layout .peg-zone {
    min-height: 154px;
    padding-bottom: 12px;
  }

  .hanoi-trace-layout .peg {
    bottom: 12px;
    height: 126px;
  }

  .hanoi-trace-layout .peg-label {
    bottom: -24px;
  }

  .hanoi-call-panel {
    padding: 6px;
  }

  .hanoi-call-panel-heading {
    min-height: 20px;
    margin-bottom: 5px;
  }

  .hanoi-call-list {
    flex-direction: row;
    padding-bottom: 2px;
    overflow-x: auto;
  }

  .hanoi-call-frame {
    grid-template-columns: 14px minmax(70px, 1fr);
    flex: 0 0 auto;
    min-height: 25px;
  }

  .hanoi-call-frame small {
    display: none;
  }
}

@media (max-width: 680px) {
  .ladder-row {
    grid-template-columns: 34px 1fr 1fr;
    font-size: 0.75rem;
  }

  .ladder-condition {
    grid-column: 2 / -1;
  }

  .hanoi-board {
    grid-template-columns: repeat(3, minmax(80px, 1fr));
    gap: 4px;
    min-height: 245px;
  }

  .peg-zone {
    min-height: 205px;
  }

  .peg {
    height: 166px;
  }

  .hanoi-disk {
    height: 24px;
    font-size: 0.75rem;
  }

  .master-layout {
    --master-level-columns: 42px minmax(96px, 1fr) minmax(96px, 0.85fr);
    --master-level-gap: 4px;
  }

  .master-force {
    padding-inline: 5px;
  }

  .master-force em,
  .master-level-index small {
    display: none;
  }

  .master-profile-key {
    padding-inline: 3px;
  }

  .master-level {
    padding-inline: 3px;
  }

  .master-level-equation {
    font-size: 0.63rem;
  }
}

@media (min-width: 761px) and (max-height: 820px) {
  .hanoi-board {
    min-height: 205px;
    padding-block: 2px 34px;
  }

  .hanoi-board::after {
    bottom: 28px;
  }

  .peg-zone {
    min-height: 170px;
    padding-bottom: 14px;
  }

  .peg {
    bottom: 14px;
    height: 140px;
  }

  .peg-label {
    bottom: -27px;
  }
}
