/*
 * The FM-1 as FM-SWITCH draws it: the real panel's layout and proportions (372 x 200), plain dot
 * knobs and readable button labels. Everything is placed as a share of the panel, so it scales
 * with its width.
 *
 * Its screen can play through an install in the app's stages: .fm1--loop repeats it (the index's
 * hover plays it once, in flair.css), taking --fm1-time (9 s unless set on a parent). Otherwise,
 * and with reduced motion, it shows Ready.
 */

.fm1 {
  --fm1-body: #4a4e52;
  --fm1-key: #33363a;
  --fm1-bed: #26292c;
  --fm1-knob: #6e7276;
  --fm1-label: #c9ccd0;
  --fm1-screen: #12171a;
  --fm1-ready: #9be7b4;
  --fm1-ready-soft: #7cb791;
  --fm1-busy: #f2b483;
  --fm1-busy-soft: #e0a074;

  position: relative;
  container-type: inline-size;
  aspect-ratio: 372 / 200;
  border-radius: 5.6% / 10.4%;
  background: var(--fm1-body);
  box-shadow: 0 8px 12px rgb(0 0 0 / 22%);
}

.fm1 > * {
  position: absolute;
}

/* Two pairs of knobs on the left, four in a row on the right. */
.fm1-knobs {
  display: flex;
  flex-wrap: wrap;
  place-content: space-between;
}

.fm1-knobs--left {
  top: 13.1%;
  left: 4%;
  width: 11.3%;
  height: 21.1%;
}

.fm1-knobs--right {
  top: 10.7%;
  left: 52.1%;
  width: 42.1%;
  height: 8.93%;
}

.fm1-knobs span {
  width: 4.8cqw;
  aspect-ratio: 1;
  border-radius: 50%;
  background: var(--fm1-knob);
}

.fm1-oct,
.fm1-buttons span {
  display: grid;
  place-items: center;
  border-radius: 0.9cqw;
  background: var(--fm1-key);
  color: var(--fm1-label);
  font: 700 2.2cqw/1 system-ui, sans-serif;
}

.fm1-oct {
  top: 39.7%;
  width: 7.2%;
  height: 10.3%;
}

.fm1-oct--down {
  left: 1.9%;
}

.fm1-oct--up {
  left: 10.2%;
}

.fm1-screen {
  top: 3.8%;
  left: 19.8%;
  width: 26.1%;
  height: 55.9%;
  box-sizing: border-box;
  border: 0.75cqw solid #2b2f33;
  border-radius: 1.6cqw;
  background: var(--fm1-screen);
  font-family: ui-rounded, "SF Pro Rounded", system-ui, sans-serif;
}

/* Each stage of an install fills the screen in turn. */
.fm1-stage {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 0 2.6cqw;
  color: var(--fm1-busy);
  opacity: 0;
}

.fm1-stage b {
  font-size: 3.4cqw;
  font-weight: 700;
  line-height: 1.3;
}

.fm1-stage small {
  color: var(--fm1-busy-soft);
  font-size: 2.8cqw;
  line-height: 1.3;
}

.fm1-stage--ready,
.fm1-stage--done {
  color: var(--fm1-ready);
}

.fm1-stage--ready small,
.fm1-stage--done small {
  color: var(--fm1-ready-soft);
}

.fm1-stage--ready {
  opacity: 1;
}

.fm1-bar {
  height: 0.9cqw;
  margin-top: 1.2cqw;
  border-radius: 1cqw;
  background: rgb(255 255 255 / 12%);
  overflow: hidden;
}

.fm1-bar::before {
  content: "";
  display: block;
  width: var(--fm1-done, 0%);
  height: 100%;
  border-radius: inherit;
  background: currentcolor;
}

.fm1-bar--8 {
  --fm1-done: 8%;
}

.fm1-bar--50 {
  --fm1-done: 50%;
}

.fm1-bar--90 {
  --fm1-done: 90%;
}

.fm1-bar--98 {
  --fm1-done: 98%;
}

.fm1-buttons {
  top: 23.8%;
  left: 48.3%;
  width: 49.6%;
  height: 29.1%;
  box-sizing: border-box;
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 0.6cqw;
  padding: 0.7cqw;
  border-radius: 1.6cqw;
  background: var(--fm1-bed);
}

.fm1-buttons .fm1-home {
  color: #fff;
}

.fm1-buttons .fm1-play {
  color: #9be36b;
}

.fm1-buttons .fm1-rec {
  color: #ff7a6e;
}

.fm1-keys {
  top: 64.1%;
  left: 1.9%;
  width: 96.1%;
  height: 32.1%;
  box-sizing: border-box;
  display: grid;
  grid-template-columns: repeat(16, 1fr);
  gap: 1cqw;
  padding: 1.6cqw;
  border-radius: 2.4cqw;
  background: var(--fm1-bed);
}

.fm1-keys span {
  border-radius: 1cqw;
  background: var(--fm1-key);
}

/* Playing through an install: six stages, a sixth of the time each, in order (--fm1-at). */
.fm1-stage:nth-child(2) {
  --fm1-at: 1;
}

.fm1-stage:nth-child(3) {
  --fm1-at: 2;
}

.fm1-stage:nth-child(4) {
  --fm1-at: 3;
}

.fm1-stage:nth-child(5) {
  --fm1-at: 4;
}

.fm1-stage:nth-child(6) {
  --fm1-at: 5;
}

.fm1--loop .fm1-stage {
  animation: fm1-stage var(--fm1-time, 9s) linear calc(var(--fm1-time, 9s) * var(--fm1-at, 0) / 6) infinite;
}

/* Ready gives way to the stages after it, rather than showing again under them. */
.fm1--loop .fm1-stage--ready {
  opacity: 0;
}

@keyframes fm1-stage {
  0%,
  16.6% {
    opacity: 1;
  }

  16.7%,
  100% {
    opacity: 0;
  }
}

@keyframes fm1-show {
  to {
    opacity: 1;
  }
}

@media (prefers-reduced-motion: reduce) {
  .fm1 .fm1-stage {
    animation: none !important;
  }

  .fm1 .fm1-stage--ready {
    opacity: 1 !important;
  }
}
