:root {
  --bg: #0d0907;
  --ink: #efe6d6;
  --ink-dim: #a8957d;
  --parchment: #e9dcbf;
  --parchment-dark: #b9a37d;
  --parchment-ink: #2b1d14;
  --gold: #f2c230;
  --blood: #c0281e;
  --font-hand: "Patrick Hand", "Comic Sans MS", cursive;
  --font-px: "Pixelify Sans", ui-monospace, monospace;
}

* { box-sizing: border-box; }

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

body {
  background: radial-gradient(ellipse at center, #1c130e 0%, var(--bg) 70%) fixed, var(--bg);
  color: var(--ink);
  font-family: var(--font-hand);
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
}

.px { image-rendering: pixelated; image-rendering: crisp-edges; display: block; }

/* ---------- Layout ---------- */

.stage {
  min-height: 100dvh;
  max-width: 1200px;
  margin: 0 auto;
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.hud {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: start;
  gap: 12px;
  min-height: 64px;
}

.hud-left { display: flex; flex-direction: column; gap: 4px; }

.hearts { display: flex; gap: 3px; }
.hearts img { width: 22px; height: auto; }

.pickups { list-style: none; margin: 0; padding: 0; display: flex; gap: 12px; font-family: var(--font-px); font-size: 15px; }
.pickups li { display: flex; align-items: center; gap: 4px; }
.pickups .bump { animation: bump .35s ease-out; }

.ico { display: inline-block; }
.ico img { width: 16px; height: auto; }

.hud-center { text-align: center; }
.hud-center h1 { margin: 0; font-size: clamp(22px, 4vw, 34px); font-weight: 400; letter-spacing: .5px; text-shadow: 0 2px 0 #000; }
.floor-name { margin: 0; color: var(--ink-dim); font-size: 16px; }

.minimap {
  justify-self: end;
  display: grid;
  grid-template-columns: repeat(var(--mm-cols, 3), 22px);
  grid-template-rows: repeat(var(--mm-rows, 3), 15px);
  gap: 3px;
  padding: 6px;
  background: rgba(0, 0, 0, .45);
  border: 2px solid #2a1d15;
}
.minimap button {
  all: unset;
  cursor: pointer;
  background: #3a3a3a;
  border: 2px solid #111;
  display: grid;
  place-items: center;
  font-size: 10px;
  line-height: 1;
  color: #111;
}
.minimap button.unknown { background: #1d1d1d; border-color: #3a3a3a; color: #777; }
.minimap button.visited { background: #8d8d8d; }
.minimap button.current { background: #f4f4f4; }
.minimap button:focus-visible { outline: 2px solid var(--gold); }

.room-wrap { flex: 1; display: grid; place-items: center; }

.room {
  --tile: calc(100cqw / var(--cols));
  position: relative;
  container-type: inline-size;
  width: min(100%, calc((100dvh - 170px) * var(--cols) / var(--rows)));
  aspect-ratio: var(--cols) / var(--rows);
  min-width: 260px;
  box-shadow: 0 0 0 4px #000, 0 20px 60px rgba(0, 0, 0, .8);
  overflow: hidden;
  user-select: none;
  cursor: crosshair;
}

.room-bg, .layer, .vignette { position: absolute; inset: 0; width: 100%; height: 100%; }
.room-bg { image-rendering: pixelated; }
.vignette { pointer-events: none; background: radial-gradient(ellipse at center, transparent 45%, rgba(0, 0, 0, .55) 100%); }

.room.exit-left   { animation: exit-left .18s ease-in forwards; }
.room.exit-right  { animation: exit-right .18s ease-in forwards; }
.room.exit-top    { animation: exit-top .18s ease-in forwards; }
.room.exit-bottom { animation: exit-bottom .18s ease-in forwards; }
.room.enter       { animation: enter .22s ease-out; }
.room.shake       { animation: shake .35s; }

.foot {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  color: var(--ink-dim);
  font-family: var(--font-px);
  font-size: 13px;
}

.pill-switch {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  color: var(--ink);
  text-decoration: none;
  font-family: var(--font-hand);
  font-size: 18px;
  background: rgba(0, 0, 0, .5);
  border: 2px solid #3a2a1e;
  border-radius: 999px;
}
.pill-switch:hover, .pill-switch:focus-visible { border-color: var(--gold); outline: none; }
.pill-switch:hover .ico { animation: wobble .4s; }
.pill-switch .ico img { width: 26px; }

/* ---------- Entidades ---------- */

.ent {
  position: absolute;
  display: block;
  padding: 0;
  margin: 0;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  cursor: pointer;
}
.ent:focus-visible { outline: 2px dashed var(--gold); outline-offset: 2px; }
.ent > img { width: 100%; height: 100%; object-fit: contain; }

.shadow::before {
  content: "";
  position: absolute;
  left: 18%; right: 18%; bottom: 2%;
  height: 14%;
  background: rgba(0, 0, 0, .35);
  border-radius: 50%;
}

.player { pointer-events: none; }
.player > img { animation: idle 1.6s ease-in-out infinite; position: relative; }

.item .pedestal { position: absolute; left: 0; right: 0; bottom: 0; width: 100%; height: auto; }
.item .floating {
  position: absolute;
  left: 20%; width: 60%;
  top: 4%;
  height: auto;
  animation: bob 2s ease-in-out infinite;
  filter: drop-shadow(0 calc(var(--tile) * .18) 0 rgba(0, 0, 0, .35));
}
.item:hover .floating, .item:focus-visible .floating, .item.active .floating { animation-duration: .9s; filter: drop-shadow(0 0 calc(var(--tile) * .12) rgba(255, 240, 180, .9)); }
.item .label {
  position: absolute;
  left: 50%; top: 100%;
  transform: translateX(-50%);
  white-space: nowrap;
  font-size: calc(var(--tile) * .32);
  color: rgba(255, 255, 255, .7);
  text-shadow: 0 1px 0 #000;
  pointer-events: none;
}

.hittable.hit > img { animation: hit .2s; }
.poop > img { transform-origin: 50% 85%; transition: transform .15s; }
.rubble { pointer-events: none; opacity: .55; filter: grayscale(.3) brightness(.7); }
.rubble > img { transform: scale(.7, .35) translateY(70%); }

.pickup > img { animation: bob 1.4s ease-in-out infinite; }

.crack { cursor: pointer; }
.crack > img { filter: drop-shadow(1px 1px 0 rgba(255, 220, 180, .45)) drop-shadow(-1px 0 0 rgba(255, 220, 180, .25)); }
.crack:hover > img { filter: drop-shadow(1px 1px 0 rgba(255, 230, 160, .9)); }

.chalk {
  position: absolute;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
  color: rgba(255, 255, 255, .5);
  font-size: calc(var(--tile) * .42);
  line-height: 1.15;
  text-shadow: 0 0 1px rgba(255, 255, 255, .4);
  transform: rotate(-1.5deg);
}
.chalk strong { font-weight: 400; font-size: 1.7em; color: rgba(255, 255, 255, .7); }
.chalk p { margin: .2em 0; }

/* Puertas: el arte está dibujado para la pared de arriba y se rota para las demás */
.door { cursor: pointer; }
.door .door-art {
  position: absolute;
  inset: 0;
  background: linear-gradient(#6b4a2c, #3d2817);
  border-radius: 50% 50% 0 0 / 80% 80% 0 0;
  box-shadow: inset 0 0 0 3px #1a1110;
}
.door .door-art::after {
  content: "";
  position: absolute;
  left: 24%; right: 24%; top: 26%; bottom: 0;
  background: radial-gradient(ellipse at 50% 100%, #2a1e17 0%, #000 70%);
  border-radius: 50% 50% 0 0 / 70% 70% 0 0;
}
.door.left .door-art, .door.right .door-art { inset: auto; width: 200%; height: 50%; left: -50%; top: 25%; }
.door.right .door-art  { transform: rotate(90deg); }
.door.bottom .door-art { transform: rotate(180deg); }
.door.left .door-art   { transform: rotate(-90deg); }
.door:hover .door-art::after, .door:focus-visible .door-art::after { background: radial-gradient(ellipse at 50% 100%, #5a4030 0%, #000 75%); }

.door.treasure .door-art { background: linear-gradient(#ffe27a, #b68a12); }
.door.boss .door-art {
  background:
    repeating-linear-gradient(90deg, transparent 0 10%, #1a1110 10% 13%),
    linear-gradient(#a3241a, #4a0d08);
}
.door.secret .door-art { background: none; box-shadow: none; }
.door.secret .door-art::after { left: 18%; right: 18%; top: 10%; border-radius: 40% 55% 10% 20% / 60% 70% 10% 10%; background: #000; }

.trapdoor {
  cursor: pointer;
  background: #000;
  box-shadow: inset 0 0 0 calc(var(--tile) * .12) #4f2f1a, inset 0 0 0 calc(var(--tile) * .18) #1a1110;
}
.trapdoor:hover { box-shadow: inset 0 0 0 calc(var(--tile) * .12) var(--gold), inset 0 0 0 calc(var(--tile) * .18) #1a1110; }

.boss > img { animation: idle 1.1s ease-in-out infinite; filter: hue-rotate(150deg) saturate(1.4) brightness(.9); }
.boss.hit > img { animation: hit-boss .15s; }
.boss.dying > img { animation: die .8s forwards; }

.bossbar {
  position: absolute;
  left: 25%; right: 25%;
  bottom: calc(var(--tile) * .3);
  height: calc(var(--tile) * .35);
  background: #2a0605;
  border: 2px solid #000;
  pointer-events: none;
}
.bossbar span { display: block; height: 100%; background: linear-gradient(#ff5a4a, var(--blood)); transition: width .2s; }

/* ---------- Proyectiles y efectos ---------- */

.tear {
  position: absolute;
  width: calc(var(--tile) * .36);
  height: calc(var(--tile) * .36);
  margin: calc(var(--tile) * -.18) 0 0 calc(var(--tile) * -.18);
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fff 0 18%, #9fd8ff 30%, #3d8fd6 80%);
  box-shadow: 0 0 0 2px rgba(0, 0, 0, .35);
  pointer-events: none;
  z-index: 5;
}
.splash {
  position: absolute;
  width: calc(var(--tile) * .6);
  height: calc(var(--tile) * .6);
  margin: calc(var(--tile) * -.3) 0 0 calc(var(--tile) * -.3);
  border-radius: 50%;
  border: 3px solid #9fd8ff;
  pointer-events: none;
  animation: splash .3s ease-out forwards;
  z-index: 5;
}
.boom {
  position: absolute;
  width: calc(var(--tile) * 3);
  height: calc(var(--tile) * 3);
  margin: calc(var(--tile) * -1.5) 0 0 calc(var(--tile) * -1.5);
  border-radius: 50%;
  background: radial-gradient(circle, #fff6c2 0 15%, #ffb03a 35%, #e0461c 60%, transparent 70%);
  pointer-events: none;
  animation: boom .5s ease-out forwards;
  z-index: 6;
}

/* ---------- Banner tipo "recogiste un item" ---------- */

.banner {
  position: fixed;
  left: 50%;
  top: 14%;
  z-index: 20;
  min-width: min(420px, 86vw);
  max-width: 92vw;
  padding: 14px 34px 16px;
  text-align: center;
  color: var(--parchment-ink);
  background: radial-gradient(ellipse at center, var(--parchment) 55%, var(--parchment-dark) 100%);
  clip-path: polygon(2% 8%, 10% 0, 30% 5%, 52% 0, 75% 4%, 92% 0, 100% 10%, 97% 50%, 100% 90%, 88% 100%, 65% 95%, 45% 100%, 22% 96%, 6% 100%, 0 88%, 3% 50%);
  pointer-events: none;
  opacity: 0;
  transform: translate(-50%, -12px) scale(.96);
  transition: opacity .15s, transform .15s;
}
.banner.show { opacity: 1; transform: translate(-50%, 0) scale(1); }
.banner-title { font-size: clamp(26px, 5vw, 40px); line-height: 1; }
.banner-sub { margin-top: 4px; font-size: clamp(16px, 2.6vw, 21px); opacity: .85; }

/* ---------- Overlay (cambio de piso / VS) ---------- */

.overlay {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  background: #000;
  color: var(--ink);
  opacity: 0;
  pointer-events: none;
  transition: opacity .3s;
  font-size: clamp(32px, 8vw, 72px);
  text-align: center;
}
.overlay.show { opacity: 1; pointer-events: auto; }
.overlay small { display: block; font-size: .4em; color: var(--ink-dim); }
.vs { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 4vw; width: 100%; padding: 0 6vw; }
.vs .vs-word { color: var(--blood); font-size: 1.4em; animation: bump .5s; }
.vs img { width: min(28vw, 220px); margin: 0 auto; }
.vs .boss-portrait { filter: hue-rotate(150deg) saturate(1.4) brightness(.9); }

/* ---------- Animaciones ---------- */

@keyframes bob { 50% { transform: translateY(-12%); } }
@keyframes idle { 50% { transform: scale(1.04, .96) translateY(3%); } }
@keyframes hit { 50% { filter: brightness(2.2); transform: scale(1.08, .92); } }
@keyframes hit-boss { 50% { filter: hue-rotate(150deg) brightness(3); transform: scale(1.06); } }
@keyframes die { 30% { transform: scale(1.2, .8); filter: brightness(3); } 100% { transform: scale(0); opacity: 0; } }
@keyframes splash { from { transform: scale(.3); opacity: 1; } to { transform: scale(1.2); opacity: 0; } }
@keyframes boom { from { transform: scale(.2); opacity: 1; } to { transform: scale(1.3); opacity: 0; } }
@keyframes bump { 50% { transform: scale(1.4); } }
@keyframes wobble { 25% { transform: rotate(-12deg); } 75% { transform: rotate(12deg); } }
@keyframes shake { 20% { translate: -6px 3px; } 40% { translate: 5px -4px; } 60% { translate: -4px -2px; } 80% { translate: 3px 3px; } }
@keyframes exit-left   { to { transform: translateX(8%);  opacity: 0; } }
@keyframes exit-right  { to { transform: translateX(-8%); opacity: 0; } }
@keyframes exit-top    { to { transform: translateY(8%);  opacity: 0; } }
@keyframes exit-bottom { to { transform: translateY(-8%); opacity: 0; } }
@keyframes enter { from { opacity: 0; } }

@media (max-width: 600px) {
  .hud { grid-template-columns: 1fr auto; }
  .hud-center { grid-column: 1 / -1; grid-row: 2; }
  .room { min-width: 0; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
