:root {
  --bg: #0b0d10;
  --ink: #e6e8eb;
  --muted: #8b929c;
  --axis: #6b737e;
  --flash: #ffd29a;
  --panel: rgb(20 23 28 / .86);
  --panel-border: rgb(230 232 235 / .12);
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0; 
  height: 100%;
}

body {
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 ui-sans-serif, system-ui, -apple-system, "Helvetica Neue", sans-serif;
  display: grid;
  place-items: center;
}

.viewer {
  width: 100%;
  padding: 16px;
  display: grid;
  justify-items: center;
  gap: 12px;
  /* Orbiting can swing a note past the edge on small screens */
  overflow-x: clip;
}

.stage {
  position: relative;
  width: min(100%, 62vh, 640px);
  aspect-ratio: 5 / 6;
}

canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  cursor: grab;
  touch-action: none;
  border-radius: 12px;
}

canvas:active {
  cursor: grabbing;
}

canvas:focus-visible {
  outline: 2px solid var(--axis);
  outline-offset: -2px;
}

/* Notes are anchored to points in the flow, JS moves them every frame */
.note {
  position: absolute;
  left: 0;
  top: 0;
  pointer-events: none;
  font-size: clamp(12px, 2.2vmin, 15px);
  color: var(--ink);
  white-space: nowrap;
  text-shadow: 0 0 3px var(--bg), 0 0 6px var(--bg), 0 0 10px var(--bg);
  transition: opacity .4s ease;
}

.note::before {
  content: "";
  position: absolute;
  left: -3px;
  top: -3px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--ink);
}

.note-below {
  translate: -50% 10px;
}

.note-below::before { 
  left: calc(50% - 3px);
  top: -13px;
}

.note-right {
  translate: 10px -50%;
}

.note-right::before {
  left: -13px;
  top: calc(50% - 3px);
}

.tooltip {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 1;
  width: min(220px, 55%);
  padding: 8px 10px;
  display: grid;
  gap: 2px;
  pointer-events: none;
  font-size: 13px;
  line-height: 1.35;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  backdrop-filter: blur(6px);
  opacity: 0;
  visibility: hidden;
  transition: opacity .2s ease, visibility .2s;
}

@media (min-width: 1200px) {
  .tooltip {
    top: 50%;
    right: auto;
    left: calc(100% + 24px);
    width: 240px;
    translate: 0 -50%;
  }
}

.tooltip.is-visible {
  opacity: 1;
  visibility: visible;
}

.tooltip-title {
  font-size: 14px;
}

.tooltip-stats {
  color: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.hint {
  margin: 0;
  font-size: 13px;
  color: var(--muted);
  text-align: center;
  transition: opacity .6s ease;
}

.hint.is-done {
  opacity: 0;
}

.controls {
  width: min(100%, 700px);
  display: grid;
  grid-template-columns: 1fr 150px 180px;
  column-gap: 28px;
}

@media (max-width: 640px) {
  .controls { grid-template-columns: 1fr; row-gap: 14px; }
}

.legend,
.speed,
.singularity {
  display: grid;
  grid-template-rows: auto 30px auto;
  align-items: center;
  gap: 4px;
  font-size: 13px;
  color: var(--muted);
}

.legend {
  outline: none;
}

.control-title {
  display: flex;
  align-items: baseline;
  gap: 6px;
}

.control-note {
  font-size: 11px;
  opacity: .8;
}

.control-scale {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
}

.speed-value {
  margin-left: auto;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

.legend-bar {
  position: relative;
  height: 10px;
  border-radius: 999px;
  background: var(--ramp, linear-gradient(to right, #43d0dc, #f6ac54));
  cursor: crosshair;
  touch-action: none;
}

.legend:focus-visible .legend-bar {
  outline: 2px solid var(--axis);
  outline-offset: 3px;
}

.legend-band {
  position: absolute;
  top: -4px;
  bottom: -4px;
  border: 2px solid var(--ink);
  border-radius: 6px;
  pointer-events: none;
  opacity: 0;
  transition: opacity .15s ease;
}

.legend.is-active .legend-band {
  opacity: 1;
}

.speed input {
  width: 100%;
  margin: 0;
  accent-color: var(--ink);
  cursor: pointer;
}

.speed input:focus-visible {
  outline: 2px solid var(--axis);
  outline-offset: 3px;
}

.blowup {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  height: 30px;
  padding: 0 12px;
  overflow: hidden;
  font: inherit;
  font-size: 13px;
  color: var(--ink);
  background:
    linear-gradient(var(--bg), var(--bg)) padding-box,
    var(--ramp, linear-gradient(to right, #43d0dc, #f6ac54)) border-box;
  border: 1px solid transparent;
  border-radius: 999px;
  cursor: pointer;
  transition: box-shadow .2s ease;
}

.blowup:hover {
  box-shadow: 0 0 0 3px var(--panel-border);
}

.blowup:focus-visible {
  outline: 2px solid var(--axis);
  outline-offset: 3px;
}

.blowup[aria-busy="true"] {
  cursor: progress;
}

.blowup-fill {
  position: absolute;
  inset: 0;
  background: var(--ramp, linear-gradient(to right, #43d0dc, #f6ac54));
  opacity: .22;
  transform-origin: left;
  transform: scaleX(0);
}

.blowup-icon {
  position: relative;
  width: 15px;
  height: 15px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
}

.blowup > span:last-child {
  position: relative;
  white-space: nowrap;
}

.blowup-status {
  justify-content: center;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}