:root {
  color-scheme: dark;
  font-family: "Courier New", ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  background: #030406;
  color: #f3f7ef;
}

* {
  box-sizing: border-box;
}

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

body {
  display: grid;
  place-items: center;
  min-height: 100vh;
  overflow-x: hidden;
  background:
    linear-gradient(90deg, transparent 0 31px, rgba(152, 171, 194, 0.08) 32px),
    linear-gradient(transparent 0 31px, rgba(152, 171, 194, 0.08) 32px),
    #030406;
  background-size: 32px 32px;
}

button {
  font: inherit;
}

.machine {
  display: grid;
  grid-template-columns: auto minmax(214px, 320px);
  align-items: stretch;
  gap: 18px;
  width: min(96vw, 1040px);
  min-height: min(94vh, 780px);
  padding: 16px;
}

.well-frame {
  display: grid;
  grid-template-columns: 48px minmax(280px, 420px) 48px;
  justify-content: center;
  gap: 8px;
  min-width: 0;
}

#game {
  width: min(58vw, 420px);
  max-height: calc(100vh - 40px);
  aspect-ratio: 7 / 12;
  border: 4px solid #1b2028;
  box-shadow:
    0 0 0 4px #96a8bc,
    0 0 0 8px #3e4c60,
    0 18px 0 #10131d;
  background: #020304;
  image-rendering: pixelated;
}

.rail {
  position: relative;
  min-width: 34px;
  border: 4px solid #344153;
  background:
    linear-gradient(90deg, #607186 0 14%, #d7dce1 17% 34%, #f8faf9 38% 46%, #9ca8b4 54% 66%, #3e4b5f 72% 100%);
  box-shadow: inset 0 0 0 4px #1f2836;
}

.rail::before,
.rail::after {
  position: absolute;
  left: -8px;
  right: -8px;
  height: 14px;
  border: 3px solid #2b333d;
  background: #b8c4cf;
  content: "";
}

.rail::before {
  top: 12%;
}

.rail::after {
  bottom: 12%;
}

.console {
  position: relative;
  display: grid;
  grid-template-rows: 136px auto 76px auto auto;
  gap: 12px;
  min-width: 0;
  padding: 18px;
  border: 4px solid #364354;
  background:
    linear-gradient(45deg, rgba(107, 126, 150, 0.38) 25%, transparent 25% 75%, rgba(107, 126, 150, 0.38) 75%),
    linear-gradient(45deg, rgba(107, 126, 150, 0.38) 25%, transparent 25% 75%, rgba(107, 126, 150, 0.38) 75%),
    #9badc1;
  background-position:
    0 0,
    24px 24px;
  background-size: 48px 48px;
  box-shadow: inset 0 0 0 4px #7f92aa;
}

.pipe-cluster {
  position: absolute;
  inset: 8px auto auto 14px;
  display: flex;
  gap: 10px;
  height: 138px;
  pointer-events: none;
}

.pipe-cluster span {
  width: 18px;
  border: 3px solid #293241;
  background: linear-gradient(90deg, #5f6d7e, #eef1f4 45%, #8794a2 72%, #465364);
}

.preview-box {
  align-self: end;
  justify-self: center;
  width: 152px;
  height: 118px;
  margin-top: 6px;
  padding: 10px;
  border: 4px solid #d8dee4;
  background: #111316;
  box-shadow:
    0 0 0 4px #222b36,
    inset 0 0 0 3px #060708;
  image-rendering: pixelated;
}

#next {
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
}

.meters {
  display: grid;
  gap: 8px;
  margin: 0;
}

.meters div,
.status {
  border: 4px solid #2d3744;
  background: #eef4ec;
  color: #020304;
  box-shadow: inset 0 -4px 0 #c4d0c0;
}

.meters div {
  display: grid;
  gap: 2px;
  min-height: 72px;
  padding: 7px 9px;
}

.meters dt {
  overflow: hidden;
  font-size: 15px;
  font-weight: 900;
  line-height: 1;
}

.meters dd {
  margin: 0;
  overflow: hidden;
  font-size: clamp(30px, 4vw, 44px);
  font-weight: 900;
  line-height: 1;
}

.status {
  display: grid;
  gap: 8px;
  align-content: center;
  padding: 10px;
  font-weight: 900;
}

meter {
  width: 100%;
  height: 16px;
}

.actions,
.pad {
  display: grid;
  gap: 8px;
}

.actions {
  grid-template-columns: repeat(2, 1fr);
}

.pad {
  grid-template-columns: repeat(3, minmax(54px, 1fr));
}

.pad [data-action="drop"] {
  grid-column: 1 / -1;
}

.actions button,
.pad button {
  min-height: 48px;
  border: 4px solid #202833;
  background: #dfe9df;
  color: #0b1015;
  font-size: 26px;
  font-weight: 900;
  line-height: 1;
  box-shadow:
    inset -4px -4px 0 #8c9c94,
    inset 4px 4px 0 #ffffff;
  touch-action: none;
}

.actions button:active,
.pad button:active {
  transform: translateY(2px);
  box-shadow:
    inset 4px 4px 0 #8c9c94,
    inset -2px -2px 0 #ffffff;
}

@media (max-width: 780px) {
  body {
    place-items: start center;
  }

  .machine {
    grid-template-columns: 1fr;
    gap: 14px;
    width: 100%;
    min-height: 100vh;
    padding: 10px;
  }

  .well-frame {
    grid-template-columns: 28px minmax(0, 1fr) 28px;
    gap: 5px;
  }

  #game {
    width: 100%;
    max-height: 64vh;
  }

  .console {
    grid-template-columns: 132px 1fr;
    grid-template-rows: auto auto auto;
    gap: 10px;
    padding: 12px;
  }

  .pipe-cluster {
    display: none;
  }

  .preview-box {
    grid-row: 1 / 3;
    width: 126px;
    height: 102px;
    padding: 8px;
  }

  .meters {
    grid-template-columns: repeat(3, 1fr);
  }

  .meters div {
    min-height: 58px;
    padding: 6px;
  }

  .meters dt {
    font-size: 12px;
  }

  .meters dd {
    font-size: clamp(22px, 8vw, 32px);
  }

  .status {
    grid-column: 2;
  }

  .actions {
    grid-column: 1;
  }

  .pad {
    grid-column: 1 / -1;
  }
}
