html, body {
  margin: 0;
  height: 100%;
  background: #140c08;
  overflow: hidden;
  color: #fff4dd;
}

body {
  display: flex;
  align-items: center;
  justify-content: center;
}

#frame {
  position: relative;
  width: min(100vw, calc(100vh * 512 / 448));
  aspect-ratio: 512 / 448;
  background: #07080c;
  box-shadow: 0 0 0 8px #3a2414, 0 18px 50px rgba(0, 0, 0, 0.55);
  overflow: hidden;
  container-type: inline-size;
  font-family: "Segoe UI", Tahoma, sans-serif;
  font-size: clamp(12px, 2.35cqi, 20px);
  user-select: none;
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

#hud {
  position: absolute;
  inset: 0;
  pointer-events: none;
  font-weight: 800;
  text-shadow: 0 2px 0 #000, 0 0 4px #000;
  z-index: 2;
}

.hud-top {
  display: flex;
  justify-content: space-between;
  gap: 0.35em;
  padding: 0.4em 0.55em 0;
}

#hud-level {
  text-align: center;
  opacity: 0.92;
  margin-top: 0.1em;
}

#hud-time.low { color: #ffb4a8; }

#bossbar, #air {
  position: absolute;
  left: 0.7em;
  right: 0.7em;
  height: 0.9em;
  background: rgba(0, 0, 0, 0.55);
  border: 2px solid #f0d090;
  box-sizing: border-box;
}

#bossbar { top: 2.7em; }
#air { bottom: 0.5em; border-color: #9ad; }

#bossbar > span, #air > span {
  display: block;
  height: 100%;
  width: 0;
  background: #e14b3c;
}

#air > span { background: #6ad4ff; }

#bossbar em, #air em {
  position: absolute;
  inset: 0;
  font-style: normal;
  font-size: 0.72em;
  text-align: center;
  line-height: 1.2em;
}

#powers {
  position: absolute;
  left: 0.55em;
  bottom: 1.6em;
  display: flex;
  gap: 0.35em;
}

#powers span {
  background: rgba(20, 12, 8, 0.82);
  border: 2px solid #f0c14a;
  padding: 0.08em 0.35em;
}

#mute {
  pointer-events: auto;
  position: absolute;
  right: 0.4em;
  bottom: 0.35em;
  padding: 0.12em 0.4em;
}

#toast {
  position: absolute;
  left: 50%;
  bottom: 16%;
  transform: translateX(-50%);
  max-width: 88%;
  background: rgba(32, 18, 8, 0.92);
  color: #fff6df;
  border: 3px solid #e7b14a;
  padding: 0.35em 0.7em;
  text-align: center;
  opacity: 0;
  z-index: 4;
  pointer-events: none;
}

#toast.on { opacity: 1; }

#screens { position: absolute; inset: 0; z-index: 3; pointer-events: none; }

.screen {
  display: none;
  position: absolute;
  inset: 0;
  align-items: flex-end;
  justify-content: center;
  padding: 4% 3% 4%;
  box-sizing: border-box;
  background: linear-gradient(to top, rgba(8, 4, 2, 0.78), rgba(8, 4, 2, 0.18) 50%, rgba(8, 4, 2, 0.05));
  pointer-events: auto;
}

.screen.on { display: flex; }

.panel {
  width: min(96%, 36em);
  max-height: 92%;
  overflow: auto;
  background: linear-gradient(#643818, #3a2010);
  border: 4px solid #f0c14a;
  box-shadow: inset 0 0 0 3px #2a1408, 0 10px 24px rgba(0, 0, 0, 0.35);
  padding: 0.7em 0.85em 0.9em;
  text-align: center;
}

h1, h2 { margin: 0 0 0.25em; font-family: Georgia, "Times New Roman", serif; color: #ffe7a8; }
h1 { font-size: 1.5em; }
h2 { font-size: 1.2em; }
.eyebrow { margin: 0; letter-spacing: 0.12em; text-transform: uppercase; font-size: 0.72em; color: #f0c14a; }
.lead, .panel p { margin: 0.3em 0 0.65em; line-height: 1.35; }
.best { color: #ffe7a8; }

.row { display: flex; flex-wrap: wrap; gap: 0.4em; justify-content: center; }

button {
  font: inherit;
  font-weight: 800;
  background: #f0c14a;
  color: #3a2208;
  border: 3px solid #6a3c12;
  padding: 0.35em 0.7em;
  cursor: pointer;
}

button.secondary { background: #d5e2cf; }
button:hover { filter: brightness(1.08); }
button:disabled { filter: grayscale(0.4); opacity: 0.55; cursor: default; }

.help { text-align: left; margin: 0 0 0.7em; padding-left: 1.1em; }
.help li { margin: 0.25em 0; }

.levels { display: grid; grid-template-columns: 1fr 1fr; gap: 0.35em; margin-bottom: 0.65em; }
.levels button { width: 100%; }
.levels small { display: block; font-weight: 650; opacity: 0.85; }

.stats { list-style: none; margin: 0 0 0.7em; padding: 0; text-align: left; }
.stats li {
  display: flex;
  justify-content: space-between;
  gap: 1em;
  border-bottom: 1px solid rgba(255, 228, 170, 0.2);
  padding: 0.18em 0;
}

#touch {
  display: none;
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0.3em;
  z-index: 5;
  justify-content: space-between;
  padding: 0 0.35em;
  pointer-events: none;
}

.pad { display: flex; gap: 0.25em; pointer-events: auto; }
#touch button {
  width: 2.5em;
  height: 2.5em;
  font-size: 1.05em;
  background: rgba(240, 193, 74, 0.88);
}
#touch .jump { width: 3.1em; height: 3.1em; }

@media (pointer: coarse) {
  #touch { display: flex; }
}

#boot-error {
  position: absolute;
  inset: 8%;
  z-index: 7;
  background: #2a0c0c;
  color: #ffd0d0;
  border: 3px solid #f66;
  padding: 0.8em;
  overflow: auto;
  white-space: pre-wrap;
}
