/* ENEE350 recursion visualizer. Uses the site's theme variables so it follows dark/light mode. */

/* This page runs without the site's top navigation bar (this stylesheet only loads here). */
body > header {
  display: none;
}
body.fixed-top-nav {
  padding-top: 0 !important;
}
body > .container.mt-5 {
  margin-top: 1.5rem !important;
}

.rv {
  --rv-w: min(1400px, calc(100vw - 32px));
  --rv-fs: 1;
  --rv-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  --rv-border: var(--global-divider-color);
  --rv-muted: var(--global-text-color-light);
  --rv-accent: var(--global-theme-color);
  --rv-panel: color-mix(in srgb, var(--global-bg-color) 92%, var(--global-text-color) 8%);
  --rv-panel-2: color-mix(in srgb, var(--global-bg-color) 85%, var(--global-text-color) 15%);
  --rv-hl: color-mix(in srgb, var(--global-theme-color) 22%, transparent);
  --rv-ok: #3fb67a;
  --rv-warn: #e0a43a;
  --rv-dur: 600ms;
  width: var(--rv-w);
  position: relative;
  left: 50%;
  margin-left: calc(var(--rv-w) / -2);
  font-size: calc(15px * var(--rv-fs));
  color: var(--global-text-color);
  padding-bottom: 2rem;
}
.rv.rv-large {
  --rv-fs: 1.28;
}
.rv *,
.rv *::before,
.rv *::after {
  box-sizing: border-box;
}
.rv [hidden] {
  display: none !important;
}

/* Header */
.rv-head {
  margin: 0.5rem 0 1rem;
}
.rv-kicker {
  margin: 0;
  color: var(--rv-muted);
  font-size: 0.85em;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.rv-head h1 {
  font-size: calc(1.9rem * var(--rv-fs));
  font-weight: 300;
  margin: 0.15rem 0 0.4rem;
}
/* Toolbar */
.rv-toolbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.6rem 1.2rem;
  padding: 0.6rem 0.75rem;
  margin-bottom: 1rem;
  background: var(--global-bg-color);
  border: 1px solid var(--rv-border);
  border-radius: 10px;
}
.rv-group {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  flex-wrap: wrap;
}
.rv-group label {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  margin: 0;
  font-size: 0.9em;
  color: var(--rv-muted);
}
.rv select,
.rv input[type="number"] {
  font: inherit;
  font-size: 0.95em;
  color: var(--global-text-color);
  background: var(--rv-panel);
  border: 1px solid var(--rv-border);
  border-radius: 6px;
  padding: 0.25rem 0.4rem;
}
.rv input[type="number"] {
  width: 3.4em;
  text-align: center;
}
.rv-btn {
  font: inherit;
  font-size: 0.95em;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  min-width: 2.5em;
  height: 2.3em;
  padding: 0 0.7em;
  color: var(--global-text-color);
  background: var(--rv-panel);
  border: 1px solid var(--rv-border);
  border-radius: 7px;
  cursor: pointer;
  transition:
    background 150ms,
    border-color 150ms,
    transform 100ms;
}
.rv-btn:hover:not(:disabled) {
  border-color: var(--rv-accent);
}
.rv-btn:active:not(:disabled) {
  transform: translateY(1px);
}
.rv-btn:disabled {
  opacity: 0.4;
  cursor: default;
}
.rv-btn:focus-visible,
.rv select:focus-visible,
.rv input:focus-visible {
  outline: 2px solid var(--rv-accent);
  outline-offset: 2px;
}
.rv-btn.rv-primary {
  min-width: 6.2em;
  background: var(--rv-accent);
  border-color: var(--rv-accent);
  color: var(--global-bg-color);
  font-weight: 600;
}
.rv-btn.rv-on {
  border-color: var(--rv-accent);
  color: var(--rv-accent);
}
.rv-btn svg {
  width: 1em;
  height: 1em;
  fill: currentColor;
}
.rv-progress {
  flex: 1 1 16rem;
  display: flex;
  align-items: center;
  gap: 0.6rem;
}
.rv-progress input[type="range"] {
  flex: 1;
  accent-color: var(--rv-accent);
  min-width: 6rem;
}
.rv-count {
  font-family: var(--rv-mono);
  font-size: 0.85em;
  color: var(--rv-muted);
  white-space: nowrap;
}

/* Grid */
.rv-grid {
  display: grid;
  gap: 1rem;
  grid-template-columns: minmax(0, 1.68fr) minmax(0, 1fr) minmax(0, 1fr);
  grid-template-areas:
    "asm state frames"
    "explain explain explain"
    "c c c";
}
.rv-asm {
  grid-area: asm;
}
.rv-state {
  grid-area: state;
}
.rv-frames-panel {
  grid-area: frames;
}
.rv-explain {
  grid-area: explain;
}
.rv-c {
  grid-area: c;
}
@media (min-width: 1200px) {
  .rv-grid {
    grid-template-areas:
      "asm state frames"
      "c explain explain";
  }
}
@media (max-width: 999px) {
  .rv-grid {
    grid-template-columns: minmax(0, 1.45fr) minmax(0, 1fr);
    grid-template-areas:
      "asm state"
      "explain explain"
      "frames c";
  }
}
@media (max-width: 680px) {
  .rv-grid {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas:
      "explain"
      "asm"
      "state"
      "frames"
      "c";
  }
  .rv-toolbar {
    top: auto;
    bottom: 0;
    border-radius: 10px 10px 0 0;
    gap: 0.5rem;
  }
  .rv-head h1 {
    font-size: calc(1.5rem * var(--rv-fs));
  }
}

.rv-panel {
  min-width: 0;
  background: var(--rv-panel);
  border: 1px solid var(--rv-border);
  border-radius: 12px;
  padding: 0.85rem 0.95rem 1rem;
}
.rv-panel h2 {
  font-size: 0.8em;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--rv-muted);
  margin: 0 0 0.6rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}
.rv-panel h2 + .rv-sub {
  margin-top: -0.35rem;
}
.rv-sub {
  font-size: 0.85em;
  color: var(--rv-muted);
  margin: 0 0 0.6rem;
}
.rv-h2-gap {
  margin-top: 1.1rem !important;
}

/* Code listings */
.rv-code {
  position: relative;
  font-family: var(--rv-mono);
  font-size: 0.92em;
  line-height: 1.75;
  padding-left: 30px; /* jump-arrow gutter */
}
.rv-code-c {
  padding-left: 0;
  overflow-x: auto;
}
.rv-line {
  position: relative;
  z-index: 1;
  display: flex;
  gap: 0.55rem;
  padding: 0 0.5rem;
  white-space: pre;
  border-radius: 5px;
  transition: color var(--rv-dur);
}
.rv-line.rv-blank {
  height: 0.9em;
}
.rv-addr {
  flex: 0 0 1.6em;
  text-align: right;
  color: var(--rv-muted);
  opacity: 0.75;
  user-select: none;
}
.rv-label {
  color: var(--rv-accent);
}
.rv-src {
  flex: 0 0 auto;
  min-width: 19ch;
}
/* Comments sit to the right of the instruction, aligned in one column. */
.rv-comment {
  flex: 0 0 auto;
  white-space: pre;
  color: var(--rv-muted);
  font-style: italic;
  font-size: 0.82em;
  opacity: 0.85;
}
/* Phones and small tablets: no room for a comment column. */
@media (max-width: 759px) {
  .rv-comment {
    display: none;
  }
}
/* If the panel is narrower than the code, scroll sideways instead of wrapping. */
.rv-asm .rv-code {
  overflow-x: auto;
  overflow-y: hidden;
}
.rv-op {
  font-weight: 600;
}
.rv-line.rv-dim {
  opacity: 0.55;
}
.rv-hl {
  position: absolute;
  left: 30px;
  right: 0;
  z-index: 0;
  border-radius: 5px;
  background: var(--rv-hl);
  box-shadow: inset 3px 0 0 var(--rv-accent);
  transition:
    top var(--rv-dur) cubic-bezier(0.3, 0.7, 0.2, 1),
    height var(--rv-dur) cubic-bezier(0.3, 0.7, 0.2, 1),
    opacity 200ms;
  pointer-events: none;
}
.rv-code-c .rv-hl {
  left: 0;
}
.rv-next {
  position: absolute;
  left: 12px;
  z-index: 2;
  width: 0;
  height: 0;
  border-top: 5px solid transparent;
  border-bottom: 5px solid transparent;
  border-left: 7px solid var(--rv-muted);
  transition: top var(--rv-dur) cubic-bezier(0.3, 0.7, 0.2, 1);
  pointer-events: none;
}
.rv-arrows {
  position: absolute;
  left: 0;
  top: 0;
  width: 30px;
  height: 100%;
  overflow: visible;
  pointer-events: none;
  z-index: 3;
}
.rv-arrows path {
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
}
.rv-arrows .rv-a-call {
  stroke: var(--rv-accent);
}
.rv-arrows .rv-a-ret {
  stroke: var(--rv-ok);
}
.rv-arrows .rv-a-jump {
  stroke: var(--rv-warn);
}
.rv-arrows .rv-draw {
  animation: rv-draw var(--rv-dur) ease-out both;
}
@keyframes rv-draw {
  from {
    stroke-dashoffset: var(--rv-len);
  }
  to {
    stroke-dashoffset: 0;
  }
}
.rv-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 0.9rem;
  margin-top: 0.7rem;
  font-size: 0.8em;
  color: var(--rv-muted);
}
.rv-legend span::before {
  content: "";
  display: inline-block;
  width: 1.1em;
  height: 2px;
  margin-right: 0.35em;
  vertical-align: middle;
  background: currentColor;
}
.rv-legend .rv-l-call {
  color: var(--rv-accent);
}
.rv-legend .rv-l-ret {
  color: var(--rv-ok);
}
.rv-legend .rv-l-jump {
  color: var(--rv-warn);
}

/* Registers */
.rv-regs {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(5.2em, 1fr));
  gap: 0.5rem;
}
.rv-reg {
  position: relative;
  border: 1px solid var(--rv-border);
  border-radius: 9px;
  padding: 0.35rem 0.5rem 0.4rem;
  background: var(--rv-panel-2);
  text-align: center;
  transition:
    border-color 300ms,
    box-shadow 300ms;
}
.rv-reg-name {
  font-family: var(--rv-mono);
  font-size: 0.78em;
  color: var(--rv-muted);
}
.rv-reg-val {
  display: block;
  font-family: var(--rv-mono);
  font-size: 1.6em;
  font-weight: 600;
  line-height: 1.2;
}
.rv-reg-was {
  display: block;
  min-height: 1.2em;
  font-size: 0.72em;
  color: var(--rv-muted);
}
.rv-reg.rv-special .rv-reg-val {
  font-size: 1.25em;
}
.rv-reg.rv-changed {
  border-color: var(--rv-accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--rv-accent) 25%, transparent);
}
.rv-reg.rv-changed .rv-reg-val {
  animation: rv-pop calc(var(--rv-dur) * 0.9) ease-out;
}
@keyframes rv-pop {
  0% {
    transform: scale(1);
  }
  35% {
    transform: scale(1.28);
    color: var(--rv-accent);
  }
  100% {
    transform: scale(1);
  }
}

/* Stack */
.rv-stack {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  min-height: 3rem;
}
.rv-slot {
  --h: 210;
  display: grid;
  grid-template-columns: 2.6em minmax(0, 1fr);
  align-items: center;
  gap: 0.5rem;
  font-size: 0.92em;
}
.rv-slot-idx {
  font-family: var(--rv-mono);
  font-size: 0.8em;
  color: var(--rv-muted);
  text-align: right;
}
.rv-slot-box {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.6rem;
  min-width: 0;
  padding: 0.35rem 0.6rem;
  border-radius: 8px;
  border: 1px solid hsl(var(--h) 60% 55% / 0.75);
  background: hsl(var(--h) 70% 50% / 0.14);
  border-left: 4px solid hsl(var(--h) 65% 55%);
}
.rv-slot-main {
  font-family: var(--rv-mono);
  font-weight: 600;
  white-space: nowrap;
}
.rv-slot-desc {
  font-size: 0.82em;
  color: var(--rv-muted);
  text-align: right;
  min-width: 0;
  overflow-wrap: anywhere;
}
.rv-slot.rv-ret .rv-slot-box {
  border-style: dashed;
  border-left-style: solid;
}
.rv-slot.rv-in .rv-slot-box {
  animation: rv-drop var(--rv-dur) cubic-bezier(0.2, 0.8, 0.2, 1.1) both;
}
@keyframes rv-drop {
  from {
    transform: translateY(-14px) scale(0.97);
    opacity: 0;
  }
  to {
    transform: none;
    opacity: 1;
  }
}
.rv-slot.rv-waiting .rv-slot-box {
  visibility: hidden;
}
.rv-sp {
  display: grid;
  grid-template-columns: 2.6em minmax(0, 1fr);
  gap: 0.5rem;
  align-items: center;
  font-family: var(--rv-mono);
  font-size: 0.82em;
  color: var(--rv-accent);
}
.rv-sp-line {
  border-top: 2px dashed color-mix(in srgb, var(--rv-accent) 60%, transparent);
  position: relative;
}
.rv-sp-line span {
  position: absolute;
  right: 0;
  top: -0.85em;
  background: var(--rv-panel);
  padding-left: 0.4em;
}
.rv-empty {
  font-size: 0.85em;
  color: var(--rv-muted);
  font-style: italic;
  padding: 0.3rem 0 0.2rem 3.1em;
}
.rv-stack-base {
  margin-left: 3.1em;
  border-top: 3px solid var(--rv-border);
  font-size: 0.75em;
  color: var(--rv-muted);
  padding-top: 0.15rem;
}

/* Call frames */
.rv-frames {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}
.rv-frame {
  --h: 0;
  --d: 0;
  padding: 0.45rem 0.65rem;
  border-radius: 9px;
  border: 1px solid hsl(var(--h) 55% 55% / 0.6);
  border-left: 4px solid hsl(var(--h) 65% 55%);
  background: hsl(var(--h) 70% 50% / 0.1);
  transition:
    box-shadow 300ms,
    opacity 300ms;
}
.rv-frame.rv-main {
  border-color: var(--rv-border);
  border-left-color: var(--rv-muted);
  background: var(--rv-panel-2);
}
.rv-frame-title {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  font-family: var(--rv-mono);
  font-weight: 600;
}
.rv-frame-depth {
  font-family: inherit;
  font-weight: 400;
  font-size: 0.78em;
  color: var(--rv-muted);
}
.rv-frame-ret {
  font-size: 0.82em;
  color: var(--rv-muted);
}
.rv-frame.rv-active {
  box-shadow: 0 0 0 2px var(--rv-accent);
}
.rv-frame.rv-waiting-call {
  opacity: 0.72;
}
.rv-frame.rv-in {
  animation: rv-enter var(--rv-dur) cubic-bezier(0.2, 0.8, 0.2, 1.1) both;
}
@keyframes rv-enter {
  from {
    transform: translateY(-12px) scale(0.97);
    opacity: 0;
  }
  to {
    transform: none;
    opacity: 1;
  }
}
.rv-frame.rv-got {
  animation: rv-glow calc(var(--rv-dur) * 1.2) ease-out;
}
@keyframes rv-glow {
  0% {
    box-shadow: 0 0 0 2px var(--rv-ok);
  }
  100% {
    box-shadow: 0 0 0 2px var(--rv-accent);
  }
}
.rv-returns {
  margin-top: 0.9rem;
  font-size: 0.85em;
  color: var(--rv-muted);
}
.rv-returns-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-top: 0.35rem;
}
.rv-chip {
  font-family: var(--rv-mono);
  font-size: 0.92em;
  padding: 0.1rem 0.45rem;
  border-radius: 999px;
  border: 1px solid var(--rv-border);
  color: var(--global-text-color);
  white-space: nowrap;
}
.rv-chip.rv-new {
  border-color: var(--rv-ok);
  animation: rv-drop var(--rv-dur) ease-out both;
}

/* Explanation */
.rv-explain-step {
  font-size: 0.82em;
  color: var(--rv-muted);
  margin-bottom: 0.25rem;
}
.rv-explain-ins {
  font-family: var(--rv-mono);
  font-size: 1.15em;
  font-weight: 600;
  margin-bottom: 0.3rem;
}
.rv-explain-body {
  font-size: 1.08em;
  line-height: 1.55;
  margin: 0;
}
.rv-explain-body code,
.rv-notes code {
  font-family: var(--rv-mono);
  font-size: 0.92em;
  padding: 0.05em 0.3em;
  border-radius: 4px;
  background: var(--rv-panel-2);
  color: inherit;
}
.rv-explain-note {
  margin: 0.55rem 0 0;
  font-size: 0.92em;
  color: var(--rv-muted);
}
.rv-explain-anim {
  animation: rv-fade 260ms ease-out;
}
@keyframes rv-fade {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}
.rv-done {
  color: var(--rv-ok);
}

/* Flying values (absolutely positioned on <body>) */
.rv-fly {
  position: fixed;
  z-index: 1000;
  pointer-events: none;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-weight: 700;
  font-size: 15px;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  color: #fff;
  background: var(--global-theme-color);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.35);
  white-space: nowrap;
}
.rv-fly.rv-fly-ret {
  background: #2f9e67;
}

/* Notes */
.rv-notes {
  margin-top: 1.5rem;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(18rem, 1fr));
  gap: 1rem;
  font-size: 0.95em;
}
.rv-notes h3 {
  font-size: 1em;
  font-weight: 600;
  margin: 0 0 0.35rem;
}
.rv-notes p,
.rv-notes ul {
  margin: 0;
  color: var(--global-text-color);
  opacity: 0.9;
}
.rv-notes ul {
  padding-left: 1.1rem;
}
.rv kbd {
  font-family: var(--rv-mono);
  font-size: 0.85em;
  padding: 0.05em 0.35em;
  border: 1px solid var(--rv-border);
  border-bottom-width: 2px;
  border-radius: 4px;
}
.rv-error {
  border: 1px solid #d9534f;
  color: #d9534f;
  padding: 0.6rem 0.8rem;
  border-radius: 8px;
  margin-bottom: 1rem;
}

/* Reduced motion: keep state changes, drop movement. */
@media (prefers-reduced-motion: reduce) {
  .rv {
    --rv-dur: 1ms;
  }
  .rv *,
  .rv *::before,
  .rv *::after {
    animation-duration: 1ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 1ms !important;
  }
}
.rv.rv-still {
  --rv-dur: 1ms;
}
