* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  display: grid;
  place-items: center;
  background: #f5f4ef;
}

.game-shell {
  position: relative;
  width: min(320px, 100vw, calc((100svh - 142px) * 2 / 3));
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
}

.game-header {
  display: grid;
  grid-template-columns: max-content max-content max-content minmax(64px, 1fr);
  align-items: center;
  gap: 8px;
  height: 46px;
  padding: 0 10px;
  background: #142b2a;
  color: #a8c0b1;
  font-size: 11px;
  white-space: nowrap;
}

.game-header strong { color: #f5f4ef; font-size: 16px; }
.health { display: flex; align-items: center; gap: 4px; }
.health progress {
  width: 34px;
  height: 7px;
  --health-color: #b7cf9f;
  accent-color: var(--health-color);
}
.health progress[data-level="warning"] { --health-color: #e5b46f; }
.health progress[data-level="critical"] { --health-color: #e9856c; }
.health progress::-webkit-progress-value { background-color: var(--health-color); }
.health progress::-moz-progress-bar { background-color: var(--health-color); }
#mode { justify-self: end; width: 64px; color: #c5dac4; text-align: right; }
#mode.manual { color: #f2bf8e; }

.shaft-background {
  position: relative;
  overflow: hidden;
  width: 100%;
  aspect-ratio: 2 / 3;
  background-color: #0c1a22;
  background-image: url("./background/tile.svg");
  background-repeat: repeat;
  background-position: 0 0;
  image-rendering: pixelated;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.shaft-background.shaking { animation: damage-shake 0.22s steps(1, end); }

.shaft-background::after {
  content: "";
  position: absolute;
  z-index: 4;
  inset: 0;
  background: rgb(235 120 92 / 22%);
  opacity: 0;
  pointer-events: none;
}

.shaft-background.flashing::after { animation: damage-flash 0.28s ease-out; }

@keyframes damage-shake {
  0%, 100% { transform: translate(0, 0); }
  12% { transform: translate(-2px, 0); }
  25% { transform: translate(2px, 1px); }
  38% { transform: translate(-2px, -1px); }
  50% { transform: translate(1px, 2px); }
  62% { transform: translate(-1px, 1px); }
  75% { transform: translate(2px, -1px); }
  88% { transform: translate(-1px, 0); }
}

@keyframes damage-flash {
  from { opacity: 1; }
  to { opacity: 0; }
}

.platform {
  position: absolute;
  top: 0;
  left: 0;
  width: 30.625%;
  height: auto;
  pointer-events: none;
}

.conveyor-markers {
  position: absolute;
  top: 0;
  left: 0;
  background-image: url("./platforms/belt-markers.svg");
  background-size: var(--marker-repeat) 100%;
  background-repeat: repeat-x;
  image-rendering: pixelated;
  animation: conveyor-scroll 0.55s linear infinite;
  pointer-events: none;
}

@keyframes conveyor-scroll {
  from { background-position: 0 0; }
  to { background-position: var(--marker-repeat) 0; }
}

.platform-number {
  position: absolute;
  top: 0;
  left: 0;
  color: #a3bcac;
  font-weight: 700;
  line-height: 1;
  white-space: nowrap;
  pointer-events: none;
  user-select: none;
}

.particles {
  position: absolute;
  z-index: 1;
  inset: 0;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  pointer-events: none;
}

.character {
  position: absolute;
  z-index: 2;
  top: 0;
  left: 0;
  width: 11.25%;
  height: auto;
  image-rendering: auto;
  pointer-events: none;
}

.character.invulnerable { animation: hurt-blink 0.16s steps(1, end) infinite; }

@keyframes hurt-blink {
  50% { opacity: 0.2; }
}

@media (prefers-reduced-motion: reduce) {
  .character.invulnerable { animation: none; opacity: 0.55; }
  .conveyor-markers { animation: none; }
  .shaft-background.shaking,
  .shaft-background.flashing::after { animation: none; }
}

.ceiling {
  position: absolute;
  z-index: 3;
  top: 0;
  left: 0;
  width: 100%;
  height: auto;
  pointer-events: none;
}

.game-over {
  position: absolute;
  z-index: 5;
  inset: 0;
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 10px;
  background: rgb(7 19 24 / 86%);
  color: #f5f4ef;
  text-align: center;
}

.game-over[hidden] { display: none; }
.game-over strong { font-size: 26px; }
.game-over > span { color: #b7cf9f; font-size: 13px; }
.game-over small { color: #a8c0b1; font-size: 10px; }

.controls {
  margin: 0;
  padding: 10px 6px;
  color: #45635b;
  font-size: 10px;
  text-align: center;
}

.touch-only { display: none; }
@media (any-pointer: coarse) {
  .keyboard-only { display: none; }
  .touch-only { display: inline; }
}
