/* 6174: the Kaprekar machine, its paper tape, and the map of all 10,000 numbers. */

/* The machine */

.machine {
  --tile-w: 64px;
  --tile-h: 84px;
  --gap: 10px;
  --sort-ms: 520ms;
}

@media (max-width: 420px) {
  .machine {
    --tile-w: 54px;
    --tile-h: 70px;
    --gap: 8px;
  }

  .row--minus::before {
    width: 14px;
    margin-right: 8px;
  }
}

.works {
  display: grid;
  justify-content: center;
  gap: 10px;
  margin: 28px 0 18px;
}

.row {
  position: relative;
  width: calc(4 * var(--tile-w) + 3 * var(--gap));
  height: var(--tile-h);
}

.row--minus::before {
  content: '';
  position: absolute;
  right: 100%;
  top: 50%;
  width: 18px;
  height: 4px;
  margin: -2px 12px 0 0;
  border-radius: 2px;
  background: var(--ink);
}

.rule {
  height: 3px;
  border-radius: 2px;
  background: var(--ink);
}

.tile {
  position: absolute;
  top: 0;
  left: 0;
  transform: translateX(calc(var(--slot) * (var(--tile-w) + var(--gap))));
  transition: transform var(--sort-ms) cubic-bezier(0.65, 0, 0.35, 1);
}

.row[data-row='small'] .tile {
  background: var(--paper);
  color: var(--ink);
  box-shadow: inset 0 0 0 2px var(--ink), inset 0 -5px 0 color-mix(in srgb, var(--ink) 22%, transparent);
}

.works.is-still .tile {
  transition: none;
}

/* The map of all 10,000 numbers */

.map-frame {
  position: relative;
  max-width: 560px;
  padding: 22px 0;
}

.map-frame canvas {
  display: block;
  width: 100%;
  aspect-ratio: 1;
  border-radius: 6px;
  background: var(--paper);
  touch-action: manipulation;
  cursor: crosshair;
}

.corner {
  position: absolute;
  color: var(--ink-soft);
  font: 400 0.8rem/1 var(--print);
}

.corner--tl,
.corner--tr {
  top: 4px;
}

.corner--bl,
.corner--br {
  bottom: 4px;
}

.corner--tl,
.corner--bl {
  left: 0;
}

.corner--tr,
.corner--br {
  right: 0;
}

.map-tip {
  position: absolute;
  z-index: 1;
  max-width: min(18rem, 80%);
  padding: 8px 12px;
  border-radius: 10px;
  background: var(--key);
  color: var(--on-key);
  font-size: 0.92rem;
  line-height: 1.4;
  pointer-events: none;
  box-shadow: 0 2px 0 color-mix(in srgb, #000 25%, transparent);
}

.map-tip strong {
  font: 700 1.05rem/1.2 var(--print);
}

.map-tip .route {
  display: block;
  font: 400 0.85rem/1.4 var(--print);
  opacity: 0.85;
}

.collapse {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px 16px;
  max-width: 560px;
  margin-top: 6px;
}

.collapse-status {
  flex: 1 1 16rem;
  font-weight: 600;
  min-height: 3em;
  display: flex;
  align-items: center;
}

/* Histogram: columns double as the map's legend. */

.bars,
.bars-axis {
  grid-template-columns: repeat(8, 1fr);
}

.bars .value {
  margin-bottom: 4px;
  font-size: 0.85rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.rep-note {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 14px;
  color: var(--ink-soft);
  font-size: 0.95rem;
}

.swatch {
  background: var(--rep);
}

/* Notes */

.formula {
  overflow-x: auto;
  padding: 8px 0;
  font-family: var(--print);
  font-size: 0.98rem;
  line-height: 1.8;
  white-space: pre;
}

.formula span {
  display: block;
}

.notes var {
  font-style: italic;
}

.formula var {
  font-style: normal;
  font-weight: 700;
}

@media (prefers-reduced-motion: reduce) {
  .tile {
    transition: none;
  }
}
