/* Magnesium product page (Views/Home/Magnesium.cshtml).
   Wears the Magnesium brand, not QNSET's: the cobalt angular wordmark with a
   navy bevel from the header artwork, Flow the mascot, and the Magnesium Dark
   editor theme for every code sample. Display type is Chakra Petch, whose cut
   corners echo the wordmark. The QNSET header and footer stay.
   Everything renders complete without JavaScript; motion is only added under
   html.mg-js, and prefers-reduced-motion shows final states. */

body:has(.mg) {
  background: #04061a;
  background-image: none;
}

.mg {
  --mg-0: #04061a;
  --mg-1: #070b26;
  --mg-2: #0b1136;
  --mg-3: #111a4d;
  --mg-navy: #1a215a;
  --mg-cobalt: #2f5bff;
  --mg-cobalt-hi: #5d84ff;
  --mg-ice: #a9c1ff;
  --mg-text: #eef2ff;
  --mg-text-2: rgba(226, 233, 255, 0.7);
  --mg-text-3: rgba(226, 233, 255, 0.46);
  --mg-line: rgba(150, 175, 255, 0.14);
  --mg-line-2: rgba(150, 175, 255, 0.26);
  --mg-spark: #ffc83d;
  --mg-bad: #ff5d6c;
  --mg-ok: #4ee09a;
  --mg-display: 'Chakra Petch', 'Geist', ui-sans-serif, system-ui, sans-serif;
  --mg-sans: 'Geist', ui-sans-serif, system-ui, sans-serif;
  --mg-mono: 'Geist Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --mg-ease: cubic-bezier(0.16, 1, 0.3, 1);
  --mg-gutter: clamp(16px, 4vw, 48px);
  /* chamfered corners, the wordmark's signature */
  --mg-cut: polygon(14px 0, 100% 0, 100% calc(100% - 14px), calc(100% - 14px) 100%, 0 100%, 0 14px);

  position: relative;
  overflow-x: clip;
  margin-bottom: -3rem;
  font-family: var(--mg-sans);
  color: var(--mg-text);
  background:
    radial-gradient(60rem 40rem at 50% -10%, rgba(47, 91, 255, 0.16), transparent 70%),
    var(--mg-0);
}

.mg *,
.mg *::before,
.mg *::after {
  box-sizing: border-box;
}

.mg-wrap {
  width: min(1240px, 100% - 2 * var(--mg-gutter));
  margin-inline: auto;
}

.mg-sr {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.mg code {
  font-family: var(--mg-mono);
  font-size: 0.9em;
}

.mg :not(pre) > code {
  padding: 0.1em 0.38em;
  border-radius: 0.3rem;
  background: rgba(93, 132, 255, 0.14);
  color: var(--mg-ice);
}

/* ---------- Type ---------- */

.mg-kicker {
  margin: 0 0 1rem;
  font-family: var(--mg-mono);
  font-size: 0.72rem;
  font-weight: 500;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--mg-cobalt-hi);
}

.mg-h2 {
  margin: 0;
  font-family: var(--mg-display);
  font-size: clamp(2.1rem, 4.6vw, 3.9rem);
  font-weight: 700;
  line-height: 1;
  letter-spacing: -0.01em;
  text-wrap: balance;
}

.mg-sub {
  max-width: 50ch;
  margin: 1.25rem 0 0;
  font-size: clamp(1.02rem, 1.2vw, 1.15rem);
  line-height: 1.6;
  color: var(--mg-text-2);
}

.mg-note {
  margin: 1rem 0 0;
  font-size: 0.88rem;
  line-height: 1.55;
  color: var(--mg-text-3);
}

.mg-cap {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem 1.5rem;
  margin-top: 0.9rem;
  font-size: 0.82rem;
  color: var(--mg-text-3);
}

/* ---------- Buttons ---------- */

.mg-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.75rem;
}

.mg-btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  height: 3.2rem;
  padding: 0 1.6rem;
  border: 0;
  clip-path: var(--mg-cut);
  font-family: var(--mg-display);
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
  transition: background-color 0.25s ease, color 0.25s ease, transform 0.4s var(--mg-ease);
}

.mg-btn--primary {
  background: linear-gradient(180deg, #5d84ff, #2f5bff 55%, #2246e0);
  color: #fff;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.35);
}

.mg-btn--primary:hover {
  background: linear-gradient(180deg, #7b9bff, #4069ff 55%, #2b50f0);
  transform: translateY(-2px);
}

.mg-btn--ghost {
  background: rgba(93, 132, 255, 0.1);
  color: var(--mg-text);
}

.mg-btn--ghost:hover {
  background: rgba(93, 132, 255, 0.2);
}

.mg-btn--small {
  height: 2.5rem;
  padding: 0 1.1rem;
  font-size: 0.9rem;
}

.mg-btn:focus-visible,
.mg button:focus-visible,
.mg a:focus-visible {
  outline: 2px solid var(--mg-ice);
  outline-offset: 3px;
}

/* ---------- Windows and code (Magnesium Dark token colours) ---------- */

.mg-window {
  position: relative;
  overflow: hidden;
  border: 1px solid var(--mg-line-2);
  border-radius: 0.9rem;
  background: linear-gradient(180deg, #0d1335, #090d28);
  box-shadow: 0 30px 80px -40px rgba(0, 0, 0, 0.9), 0 0 0 1px rgba(0, 0, 0, 0.3);
}

.mg-window-bar {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  height: 2.4rem;
  padding: 0 0.9rem;
  border-bottom: 1px solid var(--mg-line);
  background: rgba(255, 255, 255, 0.02);
  font-family: var(--mg-mono);
  font-size: 0.75rem;
  color: var(--mg-text-3);
}

.mg-window-bar > i {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: rgba(226, 233, 255, 0.16);
}

.mg-window-bar > span {
  margin-left: 0.6rem;
}

.mg-code {
  margin: 0;
  padding: 1.1rem 1.25rem;
  overflow-x: auto;
  font-family: var(--mg-mono);
  font-size: 0.86rem;
  line-height: 1.7;
  color: #d4d4d4;
  tab-size: 4;
}

.mg-code code {
  font-size: inherit;
}

.mg-code .c { color: #6a9955; font-style: italic; }
.mg-code .k { color: #c586c0; }
.mg-code .d { color: #569cd6; }
.mg-code .f { color: #dcdcaa; }
.mg-code .t { color: #4ec9b0; }
.mg-code .v { color: #9cdcfe; }
.mg-code .s { color: #ce9178; }
.mg-code .n { color: #b5cea8; }
.mg-code .e { color: #569cd6; }

/* ---------- Hero ---------- */

.mg-hero {
  position: relative;
  isolation: isolate;
  padding-block: clamp(3rem, 9vh, 6rem) clamp(4rem, 10vh, 7rem);
  text-align: center;
}

.mg-hero-glow {
  position: absolute;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background:
    radial-gradient(42rem 18rem at 52% 22%, rgba(47, 91, 255, 0.28), transparent 70%),
    linear-gradient(rgba(150, 175, 255, 0.05) 1px, transparent 1px) 0 0 / 100% 32px;
  -webkit-mask-image: radial-gradient(70% 60% at 50% 30%, #000, transparent);
  mask-image: radial-gradient(70% 60% at 50% 30%, #000, transparent);
}

.mg-h1 {
  margin: 0;
}

.mg-wm {
  position: relative;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  width: min(980px, 100%);
  margin-inline: auto;
}

.mg-wm-flow {
  position: relative;
  z-index: 0;
  flex: none;
  width: clamp(70px, 14vw, 160px);
  height: auto;
  margin-right: -2.5%;
  margin-bottom: -2%;
  filter: drop-shadow(0 18px 30px rgba(0, 0, 0, 0.5));
  transform-origin: 50% 100%;
}

.mg-wm-svg {
  position: relative;
  z-index: 1;
  flex: 1;
  min-width: 0;
  height: auto;
  overflow: visible;
  filter: drop-shadow(0 0 28px rgba(47, 91, 255, 0.35));
}

.mg-wm-bevel {
  transform: translate(4px, 5px);
}

.mg-wm-lines {
  opacity: 0;
}

.mg-wm-burn {
  opacity: 0;
}

.mg-tagline {
  margin: clamp(1.75rem, 4vh, 2.5rem) 0 0;
  font-family: var(--mg-display);
  font-size: clamp(2rem, 5vw, 3.6rem);
  font-weight: 700;
  line-height: 1;
  letter-spacing: -0.01em;
}

.mg-lede {
  max-width: 58ch;
  margin: 1.25rem auto 2rem;
  font-size: clamp(1.05rem, 1.3vw, 1.2rem);
  line-height: 1.6;
  color: var(--mg-text-2);
}

.mg-facts {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.5rem 1.4rem;
  margin: 1.75rem 0 0;
  padding: 0;
  list-style: none;
  font-family: var(--mg-mono);
  font-size: 0.76rem;
  color: var(--mg-text-3);
}

.mg-facts li + li::before {
  content: '/';
  margin-right: 1.4rem;
  color: var(--mg-line-2);
}

/* the hello.mg demo */
.mg-run {
  max-width: 56rem;
  margin: clamp(3rem, 7vh, 4.5rem) auto 0;
  text-align: left;
}

.mg-run-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
}

.mg-run-grid .mg-code {
  border-right: 1px solid var(--mg-line);
}

.mg-term {
  padding: 1.1rem 1.25rem;
  background: rgba(0, 0, 0, 0.25);
  font-family: var(--mg-mono);
  font-size: 0.86rem;
  line-height: 1.7;
  color: #d4d4d4;
}

.mg-term-line {
  margin: 0;
  min-height: 1.7em;
}

.mg-prompt {
  color: var(--mg-cobalt-hi);
}

.mg-term-in {
  color: var(--mg-spark);
}

.mg-caret {
  display: inline-block;
  width: 0.55em;
  height: 1.1em;
  vertical-align: -0.18em;
  background: var(--mg-ice);
  animation: mg-blink 1.1s steps(1) infinite;
}

.mg-replay {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  height: 2rem;
  padding: 0 0.8rem;
  border: 1px solid var(--mg-line-2);
  border-radius: 999px;
  background: none;
  font: inherit;
  color: var(--mg-text-2);
  cursor: pointer;
}

.mg-replay:hover {
  color: var(--mg-text);
  border-color: var(--mg-ice);
}

/* ---------- Sections ---------- */

.mg-sec {
  position: relative;
  padding-block: clamp(5rem, 12vh, 8.5rem);
  border-top: 1px solid var(--mg-line);
}

.mg-head {
  max-width: 46rem;
  margin-bottom: clamp(2.5rem, 5vw, 4rem);
}

.mg-head--split {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 2rem 4rem;
  max-width: none;
}

.mg-split {
  display: grid;
  grid-template-columns: minmax(0, 0.9fr) minmax(0, 1.1fr);
  gap: clamp(2.5rem, 6vw, 6rem);
  align-items: center;
}

.mg-split > .mg-head {
  margin-bottom: 0;
}

.mg-split--flip {
  grid-template-columns: minmax(0, 1.1fr) minmax(0, 0.9fr);
}

/* ---------- Pipeline ---------- */

.mg-pipe {
  position: relative;
}

.mg-steps {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 0.5rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.mg-steps button {
  display: flex;
  align-items: baseline;
  gap: 0.6rem;
  width: 100%;
  padding: 0.9rem 0.25rem;
  border: 0;
  background: none;
  font-family: var(--mg-display);
  font-size: clamp(0.95rem, 1.4vw, 1.2rem);
  font-weight: 600;
  text-align: left;
  color: var(--mg-text-3);
  cursor: pointer;
  transition: color 0.3s ease;
}

.mg-steps button:hover,
.mg-steps button[aria-selected="true"] {
  color: var(--mg-text);
}

.mg-step-n {
  font-family: var(--mg-mono);
  font-size: 0.7rem;
  font-weight: 500;
  color: var(--mg-cobalt-hi);
}

.mg-steps-rail {
  position: relative;
  display: block;
  height: 2px;
  background: var(--mg-line);
}

.mg-steps-rail i {
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, var(--mg-cobalt), var(--mg-ice));
  transform: scaleX(var(--p, 1));
  transform-origin: left;
  transition: transform 0.6s var(--mg-ease);
  box-shadow: 0 0 12px rgba(93, 132, 255, 0.8);
}

.mg-pipe-body {
  display: grid;
  grid-template-columns: minmax(0, 0.8fr) minmax(0, 1.2fr);
  gap: clamp(1.5rem, 4vw, 3.5rem);
  align-items: start;
  margin-top: clamp(1.75rem, 4vw, 3rem);
}

.mg-pipe-src {
  border: 1px solid var(--mg-line-2);
  border-radius: 0.9rem;
  background: linear-gradient(180deg, #0d1335, #090d28);
  font-size: 0.95rem;
}

.mg-panels {
  display: grid;
  gap: 2.5rem;
}

.mg-panel-lead {
  margin: 0 0 1.25rem;
  font-size: 1.05rem;
  line-height: 1.55;
  color: var(--mg-text-2);
}

.mg-tokens {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.mg-tokens li {
  padding: 0.35rem 0.6rem;
  border: 1px solid currentColor;
  border-radius: 0.4rem;
  font-family: var(--mg-mono);
  font-size: 0.85rem;
  background: rgba(255, 255, 255, 0.03);
}

.mg .t-kw { color: #569cd6; }
.mg .t-id { color: #9cdcfe; }
.mg .t-op { color: var(--mg-spark); }
.mg .t-p { color: rgba(212, 212, 212, 0.6); }

.mg-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem 1.25rem;
  margin: 1.25rem 0 0;
  font-family: var(--mg-mono);
  font-size: 0.72rem;
}

.mg-legend span::before {
  content: '';
  display: inline-block;
  width: 0.55rem;
  height: 0.55rem;
  margin-right: 0.45rem;
  border-radius: 2px;
  background: currentColor;
}

.mg-ast {
  display: block;
  width: 100%;
  max-width: 26rem;
  height: auto;
}

.mg-ast-edges path {
  fill: none;
  stroke: var(--mg-line-2);
  stroke-width: 1.5;
}

.mg-ast-node rect {
  fill: #0d1335;
  stroke: var(--mg-line-2);
}

.mg-ast-node text {
  font-family: var(--mg-mono);
  font-size: 13px;
  text-anchor: middle;
  fill: #9cdcfe;
}

.mg-ast-node.is-fn rect { stroke: #569cd6; }
.mg-ast-node.is-fn text { fill: #dcdcaa; }
.mg-ast-node.is-op rect { stroke: var(--mg-spark); }
.mg-ast-node.is-op text { fill: var(--mg-spark); font-size: 15px; }

.mg-bc {
  display: grid;
  gap: 0.35rem;
  margin: 0;
  padding: 0;
  list-style: none;
  font-family: var(--mg-mono);
  font-size: 0.92rem;
}

.mg-bc li {
  display: grid;
  grid-template-columns: 5.5rem minmax(0, 1fr) auto;
  align-items: center;
  gap: 1rem;
  padding: 0.6rem 0.9rem;
  border: 1px solid var(--mg-line);
  border-radius: 0.5rem;
  background: rgba(255, 255, 255, 0.02);
  color: #9cdcfe;
}

.mg-op {
  font-weight: 600;
  color: #c586c0;
}

.mg-bc--dis li {
  grid-template-columns: 2.75rem 5rem minmax(0, 1fr) auto;
}

.mg-bc--dis li.is-dim {
  opacity: 0.5;
}

.mg-bc-at {
  font-size: 0.75rem;
  color: var(--mg-text-3);
}

.mg-bc-note {
  font-size: 0.78rem;
  color: var(--mg-text-3);
}

.mg-checks {
  display: grid;
  gap: 0.6rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.mg-checks li {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 1rem;
  color: var(--mg-text);
}

.mg-checks li::before {
  content: '';
  flex: none;
  width: 1.25rem;
  height: 1.25rem;
  border-radius: 50%;
  background:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2304061a' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M5 12.5l4.5 4.5L19 7.5'/%3E%3C/svg%3E") center / 70% no-repeat,
    var(--mg-ok);
}

.mg-verdict {
  display: inline-flex;
  align-items: center;
  gap: 0.75rem;
  margin: 1.5rem 0 0;
  font-family: var(--mg-mono);
  font-size: 0.9rem;
  color: var(--mg-text-2);
}

.mg-verdict span {
  padding: 0.3rem 0.7rem;
  border-radius: 0.35rem;
  background: rgba(78, 224, 154, 0.14);
  font-weight: 600;
  color: var(--mg-ok);
}

.mg-vm {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 1.25rem;
  align-items: start;
}

.mg-bc--run li {
  grid-template-columns: 5.5rem minmax(0, 1fr);
  transition: border-color 0.25s ease, background-color 0.25s ease, box-shadow 0.25s ease;
}

.mg-regs {
  display: grid;
  gap: 0.35rem;
  margin: 0;
  font-family: var(--mg-mono);
}

.mg-regs > div {
  display: grid;
  grid-template-columns: 2.25rem 3.5rem;
  align-items: center;
  border: 1px solid var(--mg-line);
  border-radius: 0.5rem;
  overflow: hidden;
}

.mg-regs dt {
  padding: 0.45rem 0;
  background: rgba(255, 255, 255, 0.04);
  font-size: 0.75rem;
  text-align: center;
  color: var(--mg-text-3);
}

.mg-regs dd {
  position: relative;
  margin: 0;
  padding: 0.45rem 0.7rem;
  font-size: 0.95rem;
  color: #b5cea8;
}



.mg-result {
  margin: 1.25rem 0 0;
  font-family: var(--mg-display);
  font-size: 1.5rem;
  color: var(--mg-text-2);
}

.mg-result strong {
  color: var(--mg-spark);
}

.mg-pipe-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  margin-top: 2rem;
  height: 2rem;
  padding: 0 0.85rem;
  border: 1px solid var(--mg-line-2);
  border-radius: 999px;
  background: none;
  font: inherit;
  font-size: 0.82rem;
  color: var(--mg-text-2);
  cursor: pointer;
}

.mg-pipe-toggle:hover {
  color: var(--mg-text);
}

.mg-ic-play,
.mg-pipe-toggle.is-paused .mg-ic-pause {
  display: none;
}

.mg-pipe-toggle.is-paused .mg-ic-play {
  display: block;
}

/* ---------- Benchmarks ---------- */

.mg-score-box {
  display: grid;
  justify-items: end;
  gap: 1.25rem;
}

.mg-mode {
  display: inline-flex;
  padding: 3px;
  border: 1px solid var(--mg-line-2);
  border-radius: 999px;
}

.mg-mode[hidden] {
  display: none;
}

.mg-mode button {
  height: 2.1rem;
  padding: 0 1rem;
  border: 0;
  border-radius: 999px;
  background: none;
  font-family: var(--mg-mono);
  font-size: 0.78rem;
  color: var(--mg-text-2);
  cursor: pointer;
  transition: background-color 0.25s ease, color 0.25s ease;
}

.mg-mode button[aria-pressed="true"] {
  background: var(--mg-cobalt);
  color: #fff;
}

.mg-score {
  display: flex;
  gap: clamp(1.5rem, 4vw, 3rem);
  margin: 0;
}

.mg-score dt {
  font-family: var(--mg-mono);
  font-size: 0.72rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--mg-text-3);
}

.mg-score dd {
  margin: 0.25rem 0 0;
  font-family: var(--mg-display);
  font-size: clamp(2.6rem, 5.5vw, 4.25rem);
  font-weight: 700;
  line-height: 1;
  color: var(--mg-text);
  text-shadow: 0 0 30px rgba(93, 132, 255, 0.55);
}

.mg-score dd::after {
  content: ' faster';
  font-size: 0.32em;
  font-weight: 600;
  color: var(--mg-text-3);
  text-shadow: none;
}

.mg-race-key {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1.5rem;
  margin: 0 0 1rem;
  font-family: var(--mg-mono);
  font-size: 0.75rem;
  color: var(--mg-text-2);
}

.mg-race-key span::before {
  content: '';
  display: inline-block;
  width: 1.4rem;
  height: 4px;
  margin-right: 0.5rem;
  vertical-align: middle;
  border-radius: 2px;
}

.mg-race-key .k-mg::before { background: linear-gradient(90deg, var(--mg-cobalt), var(--mg-ice)); }
.mg-race-key .k-lua::before { background: #7f87b8; }
.mg-race-key .k-py::before { background: #474f7e; }

.mg-rows {
  margin: 0;
  padding: 0;
  list-style: none;
  border-top: 1px solid var(--mg-line);
}

.mg-row {
  display: grid;
  grid-template-columns: minmax(0, 12rem) minmax(0, 1fr) minmax(0, 15.5rem);
  align-items: center;
  gap: 0.5rem 1.5rem;
  padding: 0.8rem 0;
  border-bottom: 1px solid var(--mg-line);
}

.mg-row-name {
  display: grid;
  margin: 0;
}

.mg-row-name span {
  font-family: var(--mg-mono);
  font-size: 0.88rem;
  color: var(--mg-text);
}

.mg-row-name small {
  font-size: 0.76rem;
  color: var(--mg-text-3);
}

.mg-bars {
  display: grid;
  gap: 3px;
}

.mg-bar {
  display: block;
  width: 100%;
  height: 5px;
  transform-origin: left;
}

.mg-bar.b-mg {
  height: 7px;
  filter: drop-shadow(0 0 6px rgba(93, 132, 255, 0.7));
}

.mg-bar.b-mg rect { fill: var(--mg-cobalt-hi); }
.mg-bar.b-lua rect { fill: #7f87b8; }
.mg-bar.b-py rect { fill: #474f7e; }

.mg-row-nums {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.75rem;
  margin: 0;
  font-family: var(--mg-mono);
  text-align: right;
}

.mg-row-nums dt {
  font-size: 0.62rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--mg-text-3);
}

.mg-row-nums dd {
  margin: 0.1rem 0 0;
  font-size: 0.86rem;
  color: var(--mg-text-2);
}

.mg-row-nums .n-mg dd {
  font-weight: 600;
  color: var(--mg-ice);
}

.mg-row-x {
  grid-column: 3;
  margin: -0.35rem 0 0;
  font-family: var(--mg-mono);
  font-size: 0.7rem;
  text-align: right;
  color: var(--mg-text-3);
}

.mg-race-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem 1.5rem;
  margin-bottom: 1rem;
}

.mg-race-head .mg-race-key {
  margin: 0;
}

.mg-race-unit {
  margin: 0;
  font-family: var(--mg-mono);
  font-size: 0.72rem;
  color: var(--mg-text-3);
}

/* every timed run, for anyone who wants the raw numbers */
.mg-runs-box {
  margin-top: 1.5rem;
  border: 1px solid var(--mg-line);
  border-radius: 0.9rem;
  background: var(--mg-1);
}

.mg-runs-box summary {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 1rem 1.25rem;
  font-family: var(--mg-mono);
  font-size: 0.82rem;
  color: var(--mg-text-2);
  cursor: pointer;
  list-style: none;
}

.mg-runs-box summary::-webkit-details-marker {
  display: none;
}

.mg-runs-box summary::before {
  content: '+';
  display: grid;
  place-items: center;
  width: 1.4rem;
  height: 1.4rem;
  border: 1px solid var(--mg-line-2);
  border-radius: 0.3rem;
  color: var(--mg-ice);
}

.mg-runs-box[open] summary::before {
  content: '\2212';
}

.mg-runs-box summary:hover {
  color: var(--mg-text);
}

.mg-runs-scroll {
  display: grid;
  gap: 2rem;
  padding: 0.5rem 1.25rem 1.5rem;
  overflow-x: auto;
}

.mg-runs {
  width: 100%;
  min-width: 44rem;
  border-collapse: collapse;
  font-family: var(--mg-mono);
  font-size: 0.8rem;
}

.mg-runs caption {
  padding-bottom: 0.75rem;
  font-family: var(--mg-display);
  font-size: 1.1rem;
  font-weight: 700;
  text-align: left;
  color: var(--mg-text);
}

.mg-runs th,
.mg-runs td {
  padding: 0.45rem 0.75rem;
  border-bottom: 1px solid var(--mg-line);
  text-align: right;
  color: var(--mg-text-2);
  white-space: nowrap;
}

.mg-runs thead th {
  font-size: 0.66rem;
  font-weight: 500;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--mg-text-3);
}

.mg-runs th[scope="row"],
.mg-runs td:nth-last-child(5),
.mg-runs thead th:nth-child(-n + 2) {
  text-align: left;
}

.mg-runs th[scope="row"] {
  vertical-align: top;
  font-weight: 500;
  color: var(--mg-text);
}

.mg-runs tr.is-mg td {
  color: var(--mg-ice);
}

.mg-runs td:last-child {
  color: var(--mg-text-3);
}

.mg-gate {
  display: grid;
  grid-template-columns: minmax(0, 14rem) minmax(0, 1fr);
  gap: 0.75rem 2.5rem;
  margin-top: clamp(2.5rem, 5vw, 3.5rem);
  padding: clamp(1.5rem, 3vw, 2.25rem);
  clip-path: var(--mg-cut);
  background: linear-gradient(135deg, rgba(47, 91, 255, 0.14), rgba(47, 91, 255, 0.03));
}

.mg-gate p {
  margin: 0;
  line-height: 1.6;
  color: var(--mg-text-2);
}

.mg-gate .mg-gate-title {
  grid-row: span 2;
  font-family: var(--mg-display);
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--mg-text);
}

.mg-gate .mg-gate-foot {
  font-size: 0.84rem;
  color: var(--mg-text-3);
}

/* ---------- Verifier ---------- */

.mg-guards {
  display: grid;
  gap: 0.75rem;
  margin: 2rem 0 0;
  padding: 1.5rem 0 0;
  list-style: none;
  border-top: 1px solid var(--mg-line);
}

.mg-guards li {
  display: grid;
  grid-template-columns: minmax(0, 12rem) minmax(0, 1fr);
  gap: 1rem;
  align-items: baseline;
  font-size: 0.92rem;
  color: var(--mg-text-2);
}

.mg-hex {
  display: grid;
  gap: 0.25rem;
  padding: 1.1rem 1.25rem;
  font-family: var(--mg-mono);
}

.mg-hex-region {
  display: grid;
  grid-template-columns: 6.5rem minmax(0, 1fr);
  align-items: center;
  gap: 0.75rem;
}

.mg-hex-label {
  font-size: 0.7rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--mg-text-3);
}

.mg-hex-bytes {
  display: flex;
  flex-wrap: wrap;
  gap: 0.15rem 0.5rem;
  font-size: 0.88rem;
  color: #9cdcfe;
  word-spacing: 0.4em;
}

.mg-hex-bytes b {
  font-weight: 400;
  transition: color 0.3s ease, background-color 0.3s ease;
  border-radius: 3px;
}

.mg-hex-bytes b.is-bad {
  background: rgba(255, 93, 108, 0.22);
  color: var(--mg-bad);
  animation: mg-glitch 0.45s steps(2) 2;
}

.mg-hex-bytes b.is-cut {
  opacity: 0.15;
  text-decoration: line-through;
}

.mg-hex-bytes b.is-extra {
  color: var(--mg-bad);
}

.mg-term--short {
  border-top: 1px solid var(--mg-line);
}

.mg-verify.is-bad [data-mg-verify-out] {
  color: var(--mg-bad);
}

.mg-verify.is-ok [data-mg-verify-out] {
  color: var(--mg-ok);
}

/* Flow is not impressed by damaged bytecode */
.mg-flow-mad {
  position: absolute;
  right: 1rem;
  bottom: -0.5rem;
  width: 4.75rem;
  height: auto;
  opacity: 0;
  transform: translateY(40%) rotate(8deg);
  transition: opacity 0.25s ease, transform 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
  pointer-events: none;
}

.mg-verify.is-bad .mg-flow-mad {
  opacity: 1;
  transform: none;
}

.mg-verify-ctl {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem 1rem;
  margin-top: 1rem;
}

.mg-verify-why {
  margin: 0;
  font-size: 0.9rem;
  color: var(--mg-text-2);
}

.mg-verify-why:empty {
  display: none;
}

/* ---------- Inside ---------- */

.mg-stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 1rem;
  margin: 0 0 clamp(2rem, 4vw, 3rem);
  padding: 0;
  list-style: none;
}

.mg-stats li {
  display: grid;
  gap: 0.35rem;
  padding-top: 1rem;
  border-top: 2px solid var(--mg-cobalt);
}

.mg-stats strong {
  font-family: var(--mg-display);
  font-size: clamp(2.4rem, 5vw, 3.75rem);
  font-weight: 700;
  line-height: 1;
}

.mg-stats span {
  font-size: 0.9rem;
  color: var(--mg-text-2);
}

.mg-die {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  grid-auto-flow: dense;
  gap: 0.75rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.mg-chip {
  position: relative;
  display: grid;
  align-content: start;
  gap: 0.4rem;
  min-height: 9.5rem;
  padding: 1.25rem 1.3rem;
  clip-path: var(--mg-cut);
  background:
    linear-gradient(180deg, rgba(93, 132, 255, 0.08), rgba(93, 132, 255, 0.02)),
    var(--mg-1);
  transition: background-color 0.3s ease;
}

/* the chamfered border, drawn inside the clipped shape */
.mg-chip::before {
  content: '';
  position: absolute;
  inset: 0;
  clip-path: var(--mg-cut);
  background: var(--mg-line-2);
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor;
  mask: linear-gradient(#000 0 0) content-box exclude, linear-gradient(#000 0 0);
  padding: 1px;
  pointer-events: none;
  transition: background-color 0.3s ease;
}

/* a pointer-follow light (magnesium.js sets --mx / --my) */
.mg-chip::after {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(16rem circle at var(--mx, 50%) var(--my, 0%), rgba(93, 132, 255, 0.18), transparent 60%);
  opacity: 0;
  transition: opacity 0.4s ease;
  pointer-events: none;
}

.mg-chip:hover::after {
  opacity: 1;
}

.mg-chip:hover::before {
  background: var(--mg-cobalt-hi);
}

.mg-chip--xl {
  grid-column: span 2;
  grid-row: span 2;
  min-height: 19.75rem;
}

.mg-chip--lg {
  grid-column: span 2;
}

.mg-chip > code {
  justify-self: start;
  padding: 0;
  background: none;
  font-size: 0.78rem;
  color: var(--mg-cobalt-hi);
}

.mg-chip h3 {
  margin: 0;
  font-family: var(--mg-display);
  font-size: 1.3rem;
  font-weight: 700;
}

.mg-chip--xl h3 {
  font-size: clamp(2rem, 4vw, 3rem);
}

.mg-chip p {
  margin: 0;
  font-size: 0.9rem;
  line-height: 1.5;
  color: var(--mg-text-2);
}

.mg-chip--xl p {
  max-width: 30ch;
  font-size: 1.05rem;
}

/* ---------- Embedding ---------- */

.mg-bindings {
  display: grid;
  gap: 0.75rem;
  margin: 2rem 0 0;
  padding: 1.5rem 0 0;
  list-style: none;
  border-top: 1px solid var(--mg-line);
}

.mg-bindings li {
  display: grid;
  grid-template-columns: 5rem minmax(0, 1fr);
  gap: 1rem;
  align-items: baseline;
  font-size: 0.92rem;
  color: var(--mg-text-2);
}

.mg-bindings strong {
  font-family: var(--mg-display);
  font-size: 1.05rem;
  color: var(--mg-text);
}

.mg-tabbar {
  display: flex;
  gap: 0.25rem;
  padding: 0.5rem 0.6rem 0;
  border-bottom: 1px solid var(--mg-line);
  background: rgba(255, 255, 255, 0.02);
}

.mg-tabbar button {
  position: relative;
  padding: 0.55rem 0.9rem;
  border: 0;
  background: none;
  font-family: var(--mg-mono);
  font-size: 0.78rem;
  color: var(--mg-text-3);
  cursor: pointer;
}

.mg-tabbar button[aria-selected="true"] {
  color: var(--mg-text);
}

.mg-tabbar button[aria-selected="true"]::after {
  content: '';
  position: absolute;
  left: 0.6rem;
  right: 0.6rem;
  bottom: -1px;
  height: 2px;
  background: var(--mg-cobalt-hi);
  box-shadow: 0 0 10px var(--mg-cobalt);
}

/* without JavaScript every panel shows, one after another */
.mg-tabbar {
  display: none;
}

.mg-tabpanel + .mg-tabpanel {
  border-top: 1px solid var(--mg-line);
}

/* ---------- Tooling ---------- */

.mg-editor .mg-window {
  padding-bottom: 1.8rem;
}

.mg-squiggle {
  text-decoration: underline wavy var(--mg-bad);
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}

.mg-hover {
  position: absolute;
  top: 9.6rem;
  left: 52%;
  max-width: 15rem;
  padding: 0.6rem 0.8rem;
  border: 1px solid var(--mg-line-2);
  border-radius: 0.5rem;
  background: #10163f;
  box-shadow: 0 16px 40px -10px rgba(0, 0, 0, 0.8);
  font-size: 0.82rem;
}

.mg-hover p {
  margin: 0;
  color: var(--mg-text-2);
}

.mg-hover-title {
  margin-bottom: 0.25rem !important;
  font-family: var(--mg-mono);
  font-size: 0.7rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--mg-bad) !important;
}

.mg-statusbar {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  justify-content: space-between;
  height: 1.8rem;
  padding: 0 0.9rem;
  align-items: center;
  background: var(--mg-cobalt);
  font-family: var(--mg-mono);
  font-size: 0.72rem;
  color: #fff;
}

.mg-status-err::before {
  content: '\2297  ';
}

.mg-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin: 1.75rem 0 0;
  padding: 0;
  list-style: none;
}

.mg-pills li {
  padding: 0.3rem 0.7rem;
  border: 1px solid var(--mg-line-2);
  border-radius: 999px;
  font-family: var(--mg-mono);
  font-size: 0.76rem;
  color: var(--mg-text-2);
}

/* ---------- Close ---------- */

.mg-close {
  background: radial-gradient(50rem 30rem at 80% 60%, rgba(47, 91, 255, 0.16), transparent 70%);
}

.mg-close-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.3fr) minmax(0, 0.7fr);
  gap: clamp(2rem, 5vw, 5rem);
  align-items: center;
}

.mg-close .mg-actions {
  justify-content: flex-start;
  margin-top: 2rem;
}

.mg-install {
  display: grid;
  gap: 1rem;
  margin-top: 2rem;
}

.mg-copy {
  margin-left: auto;
  padding: 0.25rem 0.7rem;
  border: 1px solid var(--mg-line-2);
  border-radius: 999px;
  background: none;
  font: inherit;
  color: var(--mg-text-2);
  cursor: pointer;
}

.mg-copy:hover,
.mg-copy.is-done {
  color: var(--mg-text);
  border-color: var(--mg-ice);
}

.mg-flow {
  display: grid;
  justify-items: center;
  gap: 1rem;
}

.mg-flow-img {
  width: min(100%, 15rem);
  height: auto;
  filter: drop-shadow(0 30px 40px rgba(0, 0, 0, 0.6));
  transform-origin: 50% 100%;
  transition: transform 0.6s var(--mg-ease);
}

.mg-flow:hover .mg-flow-img {
  transform: rotate(-4deg) translateY(-6px);
}

.mg-flow-name {
  margin: 0;
  font-family: var(--mg-display);
  font-size: 1.4rem;
  font-weight: 700;
}

.mg-credits {
  margin: clamp(3rem, 7vh, 5rem) 0 0;
  padding-top: 1.5rem;
  border-top: 1px solid var(--mg-line);
  font-size: 0.85rem;
  color: var(--mg-text-3);
}

/* =====================================================================
   Motion. Everything below only applies once magnesium.js is running.
   ===================================================================== */

/* wordmark: skeleton draws, the body burns in left to right, the bevel
   drops in behind it, then Flow pops up and leans on the M */
.mg-js .mg-wm-lines {
  opacity: 1;
  animation: mg-fade-out 0.6s ease 1.9s forwards;
}

.mg-js .mg-wm-lines path {
  stroke-dasharray: 1;
  stroke-dashoffset: 1;
  animation: mg-draw 0.8s cubic-bezier(0.5, 0, 0.2, 1) forwards;
}

.mg-js .mg-wm-lines path:nth-child(1) { animation-delay: 0.05s; }
.mg-js .mg-wm-lines path:nth-child(2) { animation-delay: 0.12s; }
.mg-js .mg-wm-lines path:nth-child(3) { animation-delay: 0.19s; }
.mg-js .mg-wm-lines path:nth-child(4) { animation-delay: 0.26s; }
.mg-js .mg-wm-lines path:nth-child(5) { animation-delay: 0.33s; }
.mg-js .mg-wm-lines path:nth-child(6) { animation-delay: 0.4s; }
.mg-js .mg-wm-lines path:nth-child(7) { animation-delay: 0.47s; }
.mg-js .mg-wm-lines path:nth-child(8) { animation-delay: 0.54s; }
.mg-js .mg-wm-lines path:nth-child(9) { animation-delay: 0.61s; }

.mg-js .mg-wm-wipe {
  transform-box: fill-box;
  transform-origin: left center;
  transform: scaleX(0);
  animation: mg-wipe 1.1s cubic-bezier(0.65, 0, 0.35, 1) 0.85s forwards;
}

.mg-js .mg-wm-burn {
  animation: mg-burn 1.1s cubic-bezier(0.65, 0, 0.35, 1) 0.85s forwards;
}

.mg-js .mg-wm.is-relit .mg-wm-burn {
  animation: mg-burn 1s cubic-bezier(0.65, 0, 0.35, 1) forwards;
}

.mg-js .mg-wm-bevel {
  opacity: 0;
  animation: mg-bevel 0.7s var(--mg-ease) 1.55s forwards;
}

.mg-js .mg-wm-flow {
  opacity: 0;
  transform: translateY(35%) rotate(-12deg) scale(0.9);
  animation: mg-flow-in 0.9s cubic-bezier(0.34, 1.56, 0.64, 1) 1.85s forwards;
}

.mg-js .mg-tagline,
.mg-js .mg-lede,
.mg-js .mg-hero .mg-actions,
.mg-js .mg-facts,
.mg-js .mg-run {
  opacity: 0;
  animation: mg-rise 0.9s var(--mg-ease) forwards;
}

.mg-js .mg-tagline { animation-delay: 1.5s; }
.mg-js .mg-lede { animation-delay: 1.65s; }
.mg-js .mg-hero .mg-actions { animation-delay: 1.8s; }
.mg-js .mg-facts { animation-delay: 1.95s; }
.mg-js .mg-run { animation-delay: 2.1s; }

/* hello.mg: lines appear as magnesium.js steps through the run */
.mg-js .mg-run [data-mg-step] {
  visibility: hidden;
}

.mg-js .mg-run[data-step="1"] [data-mg-step="1"],
.mg-js .mg-run[data-step="2"] [data-mg-step="1"],
.mg-js .mg-run[data-step="2"] [data-mg-step="2"],
.mg-js .mg-run[data-step="3"] [data-mg-step] {
  visibility: visible;
}

/* reveals */
.mg-js [data-mg-reveal] {
  opacity: 0;
  transform: translateY(28px);
  transition: opacity 0.8s ease, transform 1s var(--mg-ease);
}

.mg-js [data-mg-reveal].is-in {
  opacity: 1;
  transform: none;
}

.mg-js .mg-die [data-mg-reveal]:nth-child(2) { transition-delay: 0.06s; }
.mg-js .mg-die [data-mg-reveal]:nth-child(3) { transition-delay: 0.12s; }
.mg-js .mg-die [data-mg-reveal]:nth-child(4) { transition-delay: 0.18s; }
.mg-js .mg-die [data-mg-reveal]:nth-child(5) { transition-delay: 0.22s; }
.mg-js .mg-die [data-mg-reveal]:nth-child(6) { transition-delay: 0.26s; }
.mg-js .mg-die [data-mg-reveal]:nth-child(7) { transition-delay: 0.3s; }
.mg-js .mg-die [data-mg-reveal]:nth-child(8) { transition-delay: 0.34s; }
.mg-js .mg-die [data-mg-reveal]:nth-child(9) { transition-delay: 0.38s; }
.mg-js .mg-die [data-mg-reveal]:nth-child(10) { transition-delay: 0.42s; }

/* pipeline: one stage at a time, each with its own entrance */
.mg-js .mg-panels {
  display: grid;
  min-height: 21rem;
}

.mg-js .mg-panel {
  grid-area: 1 / 1;
  visibility: hidden;
  opacity: 0;
  transition: opacity 0.35s ease, visibility 0s linear 0.35s;
}

.mg-js .mg-panel.is-active {
  visibility: visible;
  opacity: 1;
  transition: opacity 0.35s ease 0.1s, visibility 0s;
}

.mg-js .mg-panel.is-active .mg-tokens li {
  animation: mg-pop 0.45s var(--mg-ease) both;
}

.mg-js .mg-panel.is-active .mg-tokens li:nth-child(n) { animation-delay: calc(var(--i, 0) * 45ms); }

.mg-js .mg-panel.is-active .mg-ast-node,
.mg-js .mg-panel.is-active .mg-ast-edges path {
  animation: mg-fade-in 0.5s ease both;
}

.mg-js .mg-panel.is-active .mg-ast-node:nth-of-type(2) { animation-delay: 0.12s; }
.mg-js .mg-panel.is-active .mg-ast-node:nth-of-type(3) { animation-delay: 0.24s; }
.mg-js .mg-panel.is-active .mg-ast-node:nth-of-type(4) { animation-delay: 0.36s; }
.mg-js .mg-panel.is-active .mg-ast-node:nth-of-type(5) { animation-delay: 0.42s; }
.mg-js .mg-panel.is-active .mg-ast-node:nth-of-type(6) { animation-delay: 0.54s; }
.mg-js .mg-panel.is-active .mg-ast-node:nth-of-type(7) { animation-delay: 0.6s; }
.mg-js .mg-panel.is-active .mg-ast-edges path { animation-delay: 0.3s; }

.mg-js .mg-panel.is-active .mg-bc li,
.mg-js .mg-panel.is-active .mg-checks li {
  animation: mg-slide 0.5s var(--mg-ease) both;
}

.mg-js .mg-panel.is-active .mg-bc li:nth-child(2),
.mg-js .mg-panel.is-active .mg-checks li:nth-child(2) { animation-delay: 0.25s; }
.mg-js .mg-panel.is-active .mg-bc li:nth-child(3),
.mg-js .mg-panel.is-active .mg-checks li:nth-child(3) { animation-delay: 0.5s; }
.mg-js .mg-panel.is-active .mg-checks li:nth-child(4) { animation-delay: 0.75s; }

.mg-js .mg-panel.is-active .mg-verdict {
  animation: mg-pop 0.5s var(--mg-ease) 1.1s both;
}

/* the VM steps through its three instructions */
.mg-js .mg-panel.is-active .mg-bc--run li {
  animation: mg-ip 2.4s steps(1) both;
}

.mg-js .mg-panel.is-active .mg-bc--run li:nth-child(1) { animation-name: mg-ip-1; }
.mg-js .mg-panel.is-active .mg-bc--run li:nth-child(2) { animation-name: mg-ip-2; }
.mg-js .mg-panel.is-active .mg-bc--run li:nth-child(3) { animation-name: mg-ip-3; }

.mg-js .mg-panel.is-active .mg-reg-late dd span {
  display: inline-block;
  animation: mg-r4 2.4s steps(1) both;
}

.mg-js .mg-panel.is-active .mg-reg-late.is-r5 dd span {
  animation-name: mg-r5;
}

.mg-js .mg-panel.is-active .mg-result {
  animation: mg-pop 0.5s var(--mg-ease) 2s both;
}

/* benchmarks: every bar runs at the same speed, so the fastest runtime
   finishes first (magnesium.js sets --t from each bar's length) */
.mg-js .mg-bar {
  transform: scaleX(0);
}

.mg-js .mg-race.is-in .mg-bar {
  animation: mg-grow calc(var(--t, 1) * 1.6s) linear forwards;
  animation-delay: calc(var(--row, 0) * 40ms);
}

.mg-js .mg-race .mg-row-nums,
.mg-js .mg-race .mg-row-x {
  opacity: 0;
}

.mg-js .mg-race.is-in .mg-row-nums,
.mg-js .mg-race.is-in .mg-row-x {
  animation: mg-fade-in 0.4s ease forwards;
  animation-delay: calc(var(--row, 0) * 40ms + var(--tmg, 0.3) * 1.6s);
}

/* tabs */
.mg-js .mg-tabbar {
  display: flex;
}

.mg-js .mg-tabpanel {
  display: none;
  border-top: 0;
}

.mg-js .mg-tabpanel.is-active {
  display: block;
  animation: mg-fade-in 0.35s ease;
}

/* ---------- Keyframes ---------- */

@keyframes mg-draw { to { stroke-dashoffset: 0; } }
@keyframes mg-wipe { to { transform: scaleX(1); } }
@keyframes mg-burn {
  0% { opacity: 1; transform: translateX(0); }
  85% { opacity: 1; }
  100% { opacity: 0; transform: translateX(700px); }
}
@keyframes mg-bevel {
  from { opacity: 0; transform: translate(0, 0); }
  to { opacity: 1; transform: translate(4px, 5px); }
}
@keyframes mg-flow-in {
  to { opacity: 1; transform: none; }
}
@keyframes mg-rise {
  from { opacity: 0; transform: translateY(18px); }
  to { opacity: 1; transform: none; }
}
@keyframes mg-fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes mg-fade-out { to { opacity: 0; } }
@keyframes mg-pop {
  from { opacity: 0; transform: translateY(8px) scale(0.92); }
  to { opacity: 1; transform: none; }
}
@keyframes mg-slide {
  from { opacity: 0; transform: translateX(-14px); }
  to { opacity: 1; transform: none; }
}
@keyframes mg-grow { to { transform: scaleX(1); } }
@keyframes mg-blink { 50% { opacity: 0; } }
@keyframes mg-glitch {
  0% { transform: translate(1px, -1px); }
  50% { transform: translate(-1px, 1px); }
  100% { transform: none; }
}
@keyframes mg-ip-1 {
  0% { border-color: var(--mg-line); }
  15%, 45% { border-color: var(--mg-cobalt-hi); background: rgba(93, 132, 255, 0.16); box-shadow: 0 0 18px -4px rgba(93, 132, 255, 0.8); }
  46%, 100% { border-color: var(--mg-line); background: rgba(255, 255, 255, 0.02); box-shadow: none; }
}
@keyframes mg-ip-2 {
  0%, 45% { border-color: var(--mg-line); }
  46%, 75% { border-color: var(--mg-cobalt-hi); background: rgba(93, 132, 255, 0.16); box-shadow: 0 0 18px -4px rgba(93, 132, 255, 0.8); }
  76%, 100% { border-color: var(--mg-line); background: rgba(255, 255, 255, 0.02); box-shadow: none; }
}
@keyframes mg-ip-3 {
  0%, 75% { border-color: var(--mg-line); }
  76%, 100% { border-color: var(--mg-spark); background: rgba(255, 200, 61, 0.1); }
}
@keyframes mg-r4 {
  0%, 29% { opacity: 0; }
  30%, 100% { opacity: 1; }
}
@keyframes mg-r5 {
  0%, 59% { opacity: 0; }
  60%, 100% { opacity: 1; }
}

/* ---------- Responsive ---------- */

@media (max-width: 960px) {
  .mg-split,
  .mg-split--flip,
  .mg-pipe-body,
  .mg-close-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .mg-split--flip > .mg-head {
    order: -1;
  }

  .mg-die {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .mg-stats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .mg-flow-img {
    width: 10rem;
  }
}

@media (max-width: 720px) {
  .mg-run-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .mg-run-grid .mg-code {
    border-right: 0;
    border-bottom: 1px solid var(--mg-line);
  }

  .mg-steps {
    grid-template-columns: repeat(5, minmax(4.5rem, 1fr));
    overflow-x: auto;
  }

  .mg-steps button {
    flex-direction: column;
    gap: 0.15rem;
    font-size: 0.9rem;
  }

  .mg-row {
    grid-template-columns: minmax(0, 1fr);
  }

  .mg-row-nums {
    text-align: left;
  }

  .mg-row-x {
    grid-column: auto;
    margin: 0;
    text-align: left;
  }

  .mg-gate {
    grid-template-columns: minmax(0, 1fr);
  }

  .mg-gate .mg-gate-title {
    grid-row: auto;
  }

  .mg-score-box {
    justify-items: start;
  }

  .mg-guards li,
  .mg-bindings li {
    grid-template-columns: minmax(0, 1fr);
    gap: 0.15rem;
  }

  .mg-die {
    grid-template-columns: minmax(0, 1fr);
  }

  .mg-chip--xl,
  .mg-chip--lg {
    grid-column: auto;
    grid-row: auto;
    min-height: 0;
  }

  .mg-facts li + li::before {
    display: none;
  }

  .mg-hover {
    top: auto;
    bottom: 2.4rem;
    left: auto;
    right: 0.75rem;
  }

  .mg-vm {
    grid-template-columns: minmax(0, 1fr);
  }

  .mg-regs {
    grid-template-columns: repeat(5, minmax(0, 1fr));
  }

  .mg-regs > div {
    grid-template-columns: minmax(0, 1fr);
  }
}

/* ---------- Reduced motion: final states, no movement ---------- */

@media (prefers-reduced-motion: reduce) {
  .mg *,
  .mg *::before,
  .mg *::after {
    animation-duration: 0.001ms !important;
    animation-delay: 0s !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    transition-delay: 0s !important;
  }

  .mg-caret {
    animation: none !important;
  }
}
