* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  background: #000;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  font-family: "Courier New", Courier, monospace;
}

#app {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #000;
  touch-action: none;
}

#canvasWrap {
  position: relative;
  touch-action: none;
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  background: #5c94fc;
  touch-action: none;
}

/* ---------- Rotate overlay ---------- */
#rotateOverlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: #000;
  color: #fff;
  align-items: center;
  justify-content: center;
  text-align: center;
  font-size: 18px;
  line-height: 1.6;
  padding: 20px;
}
.rotateIcon { font-size: 42px; margin-bottom: 10px; }
.rotateMsg span { font-size: 13px; opacity: 0.7; }

@media (orientation: portrait) {
  #rotateOverlay { display: flex; }
}

/* ---------- HUD ---------- */
#hud {
  position: absolute;
  top: 3%;
  left: 3%;
  right: 3%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: #fff;
  font-size: 4.2vmin;
  text-shadow: 2px 2px 0 #000, -1px -1px 0 #000;
  pointer-events: none;
  z-index: 20;
  letter-spacing: 1px;
}
.livesCounter { color: #ff5577; }

.castleToast {
  position: absolute;
  top: 13%;
  left: 50%;
  max-width: 84%;
  transform: translate(-50%, -6px);
  background: #241238;
  border: 3px solid #ffd166;
  box-shadow: 0 0 0 3px #000;
  color: #fff2cc;
  font-size: clamp(10px, 2.4vw, 14px);
  line-height: 1.4;
  padding: 8px 14px;
  text-align: center;
  z-index: 25;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.35s ease, transform 0.35s ease;
}
.castleToast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* ---------- Overlays ---------- */
.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(8, 8, 20, 0.88);
  color: #fff;
  text-align: center;
  z-index: 30;
  padding: 4% 6%;
}

#startScreen {
  justify-content: flex-end;
  background: linear-gradient(to top, rgba(11, 5, 25, 0.92) 0%, rgba(19, 8, 38, 0.6) 32%, rgba(19, 8, 38, 0) 60%);
  padding-bottom: 10%;
}
#startTitle {
  font-size: clamp(20px, 6vw, 42px);
  margin: 0 0 6px 0;
  color: #ffd166;
  text-shadow: 0 0 12px rgba(255, 209, 102, 0.5), 3px 3px 0 #5c1f4d;
  letter-spacing: 2px;
}
.subtitle {
  margin: 0 0 24px 0;
  font-size: clamp(11px, 2.2vw, 16px);
  color: #ffb3c6;
  text-shadow: 2px 2px 0 #3a0f2e;
}
.blink { animation: blink 1s steps(1) infinite; font-size: clamp(11px, 2.4vw, 16px); color: #ffe9c7; text-shadow: 2px 2px 0 #3a0f2e; }
@keyframes blink { 50% { opacity: 0; } }

.sign {
  background: #241238;
  border: 4px solid #ffd166;
  box-shadow: 0 0 0 4px #000;
  padding: 20px 24px;
  max-width: min(90vw, 520px);
}
.sign p#memoryText {
  font-size: clamp(12px, 2.6vw, 17px);
  line-height: 1.6;
  margin: 0 0 14px 0;
  color: #fff2cc;
  white-space: pre-wrap;
}
.sign .hint { margin: 0; font-size: 12px; color: #9ad; }

#lifeLostOverlay { background: rgba(35, 4, 10, 0.88); }
.lifeLostBox p {
  margin: 0 0 8px 0;
  font-size: clamp(18px, 5vw, 32px);
  color: #ff6b6b;
  text-shadow: 3px 3px 0 #3a0000;
  letter-spacing: 2px;
}
.lifeLostBox p.small {
  font-size: clamp(11px, 2.5vw, 15px);
  color: #ffdede;
  text-shadow: 2px 2px 0 #3a0000;
}

.finalBox {
  background: #2b1b2e;
  border: 4px solid #ffd166;
  box-shadow: 0 0 0 4px #000;
  padding: 20px 26px;
  max-width: min(90vw, 560px);
  max-height: 88vh;
  overflow-y: auto;
}
.finalBox h2 { font-size: 28px; margin: 0 0 8px 0; }
#finalPhoto {
  display: none;
  max-width: 100%;
  max-height: 34vh;
  border: 3px solid #fff;
  margin-bottom: 12px;
  image-rendering: auto;
}
#finalPhoto.show { display: inline-block; }
#finalMessage {
  font-size: clamp(12px, 2.4vw, 16px);
  line-height: 1.6;
  color: #ffe8f0;
  white-space: pre-wrap;
  margin: 0 0 18px 0;
}

.pixelBtn {
  font-family: inherit;
  font-size: 14px;
  padding: 10px 22px;
  background: #ff6b9d;
  color: #fff;
  border: 3px solid #fff;
  box-shadow: 0 0 0 3px #000;
  cursor: pointer;
  letter-spacing: 1px;
  touch-action: none;
}
.pixelBtn:active { background: #e8467f; }

.hidden { display: none !important; }

/* ---------- Touch controls ---------- */
#controls {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 15;
}
#dpad {
  position: absolute;
  left: 3%;
  bottom: 6%;
  display: flex;
  gap: 3vmin;
  pointer-events: auto;
}
.ctrlBtn {
  width: 15vmin;
  height: 15vmin;
  min-width: 48px;
  min-height: 48px;
  max-width: 84px;
  max-height: 84px;
  border-radius: 14px;
  border: 2px solid rgba(255,255,255,0.85);
  background: rgba(255,255,255,0.16);
  color: #fff;
  font-size: 5vmin;
  font-family: inherit;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  pointer-events: auto;
}
.ctrlBtn:active { background: rgba(255,255,255,0.42); }

.jumpBtn {
  position: absolute;
  right: 4%;
  bottom: 7%;
  width: 20vmin;
  height: 20vmin;
  min-width: 64px;
  min-height: 64px;
  max-width: 108px;
  max-height: 108px;
  border-radius: 50%;
  font-size: 2.8vmin;
  pointer-events: auto;
}
