* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  background: #0a0a0c;
  overflow: hidden;
  font-family: 'Courier New', monospace;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}

#app {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: #0a0a0c;
}

#game-root {
  position: relative;
  /* Fill most of the viewport while keeping the 3:2 aspect ratio —
     bounded by width (78vw) or by height (78vh worth of width, at the
     3:2 ratio), whichever is tighter, so a short/wide window doesn't
     push the bottom off-screen. 640px was a fixed cap that left most of
     a laptop screen as unused black letterboxing; 92vw/138vh (the first
     fix) went too far the other way and felt oversized. */
  width: min(78vw, 117vh);
  max-width: 1100px;
  aspect-ratio: 3 / 2;
  background: #000;
  box-shadow: 0 0 40px rgba(0,0,0,0.6);
}

#game-root canvas {
  width: 100% !important;
  height: 100% !important;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

/* ---------- HUD ---------- */
#hud {
  position: absolute;
  top: max(8px, env(safe-area-inset-top));
  left: 0;
  right: 0;
  display: flex;
  justify-content: center;
  pointer-events: none;
  z-index: 20;
  visibility: hidden;
}

#hearts {
  position: absolute;
  left: 10px;
  top: 0;
  display: flex;
  gap: 2px;
  pointer-events: auto;
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 8px;
}

#prana-label {
  color: #ffd84d;
  font-weight: bold;
  font-size: 11px;
  letter-spacing: 0.06em;
  text-shadow: 0 0 4px rgba(0,0,0,0.8);
  align-self: center;
  margin-right: 2px;
}

.heart {
  font-size: 18px;
  color: #ff4d6d;
  text-shadow: 0 0 4px rgba(0,0,0,0.6);
  transition: color 0.2s, opacity 0.2s;
}
.heart.empty {
  color: #555;
  opacity: 0.6;
}

/* Diya resource meter — same shape as #hearts, shown only by scenes that
   emit hud-diya (the DOM bridge un-hides it on first event) */
#diya {
  position: absolute;
  left: 10px;
  top: 30px;
  display: flex;
  gap: 2px;
  padding: 4px 6px;
}
#diya.hidden { display: none; }

#diya-label {
  color: #ffb74d;
  font-weight: bold;
  font-size: 11px;
  letter-spacing: 0.06em;
  text-shadow: 0 0 4px rgba(0,0,0,0.8);
  align-self: center;
  margin-right: 2px;
}

.diya-pip {
  font-size: 14px;
  color: #ffb74d;
  text-shadow: 0 0 4px rgba(255,183,77,0.6);
  transition: color 0.2s, opacity 0.2s;
}
.diya-pip.empty {
  color: #555;
  opacity: 0.6;
  text-shadow: none;
}

#coin-counter {
  position: absolute;
  right: 10px;
  top: 2px;
  color: #ffd84d;
  font-weight: bold;
  font-size: 13px;
  text-shadow: 0 0 4px rgba(0,0,0,0.8);
}

#message-bar {
  margin-top: 2px;
  color: #f2f2f2;
  font-size: 16px;
  font-weight: bold;
  line-height: 1.35;
  text-align: center;
  white-space: pre-line;
  background: rgba(0,0,0,0.6);
  padding: 5px 14px;
  border-radius: 6px;
  max-width: 85%;
  opacity: 0;
  transition: opacity 0.4s;
  pointer-events: none;
}
#message-bar.show { opacity: 1; }

#longpress-ring {
  position: absolute;
  left: 14px;
  top: 34px;
  width: 26px;
  height: 26px;
  opacity: 0;
  pointer-events: none;
}
#longpress-ring.show { opacity: 1; }
#longpress-ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
#longpress-ring circle {
  fill: none;
  stroke: #ffe28a;
  stroke-width: 3;
  stroke-dasharray: 100;
  stroke-dashoffset: 100;
  transition: stroke-dashoffset linear;
}

/* ---------- Controls ---------- */
#controls {
  position: absolute;
  bottom: max(16px, env(safe-area-inset-bottom));
  left: 0;
  right: 0;
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  padding: 0 16px;
  z-index: 20;
  pointer-events: none;
  visibility: hidden;
}

#dpad {
  display: flex;
  gap: 10px;
  pointer-events: none;
}

.ctrl-btn {
  touch-action: none;
  pointer-events: auto;
  width: 54px;
  height: 54px;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.35);
  background: rgba(255,255,255,0.12);
  color: #fff;
  font-size: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-user-select: none;
  user-select: none;
  backdrop-filter: blur(2px);
}
.ctrl-btn:active,
.ctrl-btn.pressed {
  background: rgba(255,255,255,0.3);
  transform: scale(0.95);
}

#btn-jump {
  width: 64px;
  height: 64px;
  font-size: 24px;
  background: rgba(255,216,77,0.18);
  border-color: rgba(255,216,77,0.5);
}

/* ---------- Panels ---------- */
.panel {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,0.75);
  z-index: 40;
  transition: opacity 0.4s;
}
.panel.hidden { display: none; }

.panel-inner {
  text-align: center;
  color: #fff;
  padding: 24px 20px;
  max-width: 80%;
}
.panel-inner h2 {
  margin: 0 0 10px;
  font-size: 20px;
  color: #ffe28a;
}
.panel-inner p {
  margin: 0 0 18px;
  font-size: 13px;
  color: #ddd;
  line-height: 1.5;
}

.panel-btn {
  font-family: inherit;
  font-size: 13px;
  background: #ffd84d;
  color: #222;
  border: none;
  padding: 10px 22px;
  border-radius: 20px;
  font-weight: bold;
  pointer-events: auto;
  display: block;
  margin: 0 auto 10px;
}
.panel-btn:last-child { margin-bottom: 0; }
.panel-btn:active { transform: scale(0.96); }
.panel-btn-secondary {
  background: transparent;
  color: #cfd2e0;
  border: 1px solid rgba(255,255,255,0.3);
}
.panel-btn.hidden { display: none; }

#panel-need-gold.hidden { display: none; }
