* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: #180507;
  color: #f2e9dc;
  font-family: 'Outfit', system-ui, sans-serif;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

#app {
  position: fixed;
  inset: 0;
  overflow: hidden;
  touch-action: none;
}

#stage, #stage canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

#stage canvas { outline: none; }

.hidden { display: none !important; }

/* ---------- atmosphere screens ---------- */

#depthHaze {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 5;
  background:
    radial-gradient(ellipse 78% 72% at 54% 56%, rgba(18, 3, 4, 0) 42%, rgba(18, 3, 4, 0.28) 74%, rgba(10, 2, 3, 0.62) 100%);
}

#vignette {
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0;
  background:
    radial-gradient(ellipse at center, rgba(255, 40, 20, 0) 45%, rgba(255, 42, 18, 0.62) 100%);
  transition: opacity 120ms linear;
  z-index: 6;
}
#vignette.on { opacity: 1; transition: opacity 40ms linear; }

#whiteFlash {
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0;
  background: #ffd2a0;
  z-index: 7;
}

/* ---------- HUD ---------- */

#hud {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 8;
}

.slab {
  background:
    linear-gradient(180deg, rgba(46, 11, 12, 0.86), rgba(19, 4, 6, 0.9));
  border-radius: 12px;
  box-shadow:
    inset 0 0 0 2px rgba(255, 126, 54, 0.42),
    inset 0 0 18px rgba(255, 80, 24, 0.18),
    0 4px 12px rgba(0, 0, 0, 0.55);
}

#livesSlab {
  position: absolute;
  top: calc(env(safe-area-inset-top, 0px) + 10px);
  left: calc(env(safe-area-inset-left, 0px) + 10px);
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 4px 8px 3px 6px;
}

#levelChip {
  position: absolute;
  top: calc(env(safe-area-inset-top, 0px) + 66px);
  left: calc(env(safe-area-inset-left, 0px) + 10px);
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 5px 10px 6px;
  pointer-events: none;
}
.levelChipNum {
  font-family: 'Luckiest Guy', 'Outfit', system-ui, sans-serif;
  font-size: clamp(13px, 3.6vw, 18px);
  line-height: 1;
  letter-spacing: 0.05em;
  color: #ffb066;
  text-shadow: 0 1px 0 rgba(0, 0, 0, 0.6);
}
.levelChipName {
  font-size: clamp(8px, 2.4vw, 11px);
  line-height: 1;
  letter-spacing: 0.13em;
  color: #f7ead8;
  opacity: 0.82;
}

.carrot {
  width: clamp(30px, 9vw, 46px);
  height: clamp(30px, 9vw, 46px);
  display: block;
  position: relative;
}
.carrot img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
  filter: drop-shadow(0 2px 2px rgba(0, 0, 0, 0.5));
  transition: transform 120ms ease, opacity 220ms ease;
}
.carrot.gone img {
  transform: scale(0.82) rotate(-8deg);
  opacity: 0.42;
}
.carrot.crumble img { animation: crumble 360ms ease-out; }
@keyframes crumble {
  0% { transform: scale(1.15) rotate(0deg); opacity: 1; }
  40% { transform: scale(0.9) rotate(9deg); opacity: 0.9; }
  100% { transform: scale(0.82) rotate(-8deg); opacity: 0.42; }
}

#pips {
  position: absolute;
  top: calc(env(safe-area-inset-top, 0px) + 6px);
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 1px;
  padding: 4px 8px;
  border-radius: 12px;
  background: rgba(22, 5, 6, 0.55);
  box-shadow: 0 0 18px rgba(255, 120, 40, 0.18);
}
.pip {
  width: clamp(24px, 7vw, 36px);
  height: clamp(24px, 7vw, 36px);
  display: block;
  transition: opacity 200ms ease;
}
.pip img { width: 100%; height: 100%; object-fit: contain; display: block; }
.pip.broken img { animation: pipBreak 420ms ease-out; }
.pip.gone { opacity: 0; }
@keyframes pipBreak {
  0% { transform: scale(1.2); filter: brightness(2); }
  60% { transform: scale(1.25) rotate(6deg); opacity: 0.9; }
  100% { transform: scale(0.7) rotate(-6deg); opacity: 0; }
}

.iconBtn {
  pointer-events: auto;
  position: absolute;
  top: calc(env(safe-area-inset-top, 0px) + 8px);
  right: calc(env(safe-area-inset-right, 0px) + 10px);
  width: clamp(40px, 11vw, 54px);
  height: clamp(38px, 10.5vw, 52px);
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
  filter: drop-shadow(0 3px 6px rgba(0, 0, 0, 0.55));
}
.iconBtn img { width: 100%; height: 100%; object-fit: contain; display: block; }
.iconBtn:active { transform: scale(0.93); filter: brightness(1.25); }

/* ---------- banner and toast ---------- */

#banner {
  position: absolute;
  z-index: 9;
  left: 0;
  right: 0;
  top: 22%;
  text-align: center;
  pointer-events: none;
  text-shadow: 0 3px 0 rgba(40, 6, 6, 0.9), 0 0 26px rgba(255, 96, 30, 0.55);
  animation: bannerIn 400ms ease-out;
}
.bannerKicker {
  font-weight: 700;
  letter-spacing: 0.32em;
  font-size: clamp(11px, 3vw, 15px);
  color: #ffb070;
  opacity: 0.9;
}
.bannerTitle {
  font-family: 'Luckiest Guy', system-ui, sans-serif;
  font-size: clamp(54px, 17vw, 110px);
  line-height: 0.95;
  color: #ff8c3a;
  -webkit-text-stroke: 2px #4a0e12;
  text-shadow: 0 5px 0 #3d0a0c, 0 8px 22px rgba(0, 0, 0, 0.6);
}
.bannerSub {
  font-family: 'Luckiest Guy', system-ui, sans-serif;
  font-size: clamp(20px, 6vw, 34px);
  color: #f3e6d4;
  letter-spacing: 0.04em;
}
#banner.out { animation: bannerOut 420ms ease-in forwards; }
@keyframes bannerIn {
  from { opacity: 0; transform: translateY(14px) scale(0.94); }
  to { opacity: 1; transform: none; }
}
@keyframes bannerOut {
  to { opacity: 0; transform: translateY(-10px); }
}

#toast {
  position: absolute;
  z-index: 9;
  left: 50%;
  top: calc(env(safe-area-inset-top, 0px) + 62px);
  transform: translateX(-50%);
  max-width: 84vw;
  padding: 8px 14px;
  border-radius: 10px;
  background: rgba(24, 6, 7, 0.86);
  box-shadow: inset 0 0 0 1.5px rgba(255, 130, 56, 0.34);
  color: #f4e8d9;
  font-size: clamp(12px, 3.4vw, 16px);
  font-weight: 600;
  text-align: center;
  pointer-events: none;
  opacity: 0;
  transition: opacity 260ms ease;
}
#toast.on { opacity: 1; }

/* ---------- touch controls ---------- */

#controls {
  position: absolute;
  left: 0;
  right: 0;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 10px);
  z-index: 10;
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  padding: 0 calc(env(safe-area-inset-left, 0px) + 8px) 0 calc(env(safe-area-inset-right, 0px) + 8px);
  pointer-events: none;
}
.pad {
  display: flex;
  gap: clamp(6px, 2vw, 14px);
  pointer-events: none;
}
.ctrl {
  pointer-events: auto;
  width: clamp(58px, 18vw, 92px);
  height: clamp(56px, 17vw, 88px);
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
  filter: drop-shadow(0 5px 8px rgba(0, 0, 0, 0.55));
  transition: transform 70ms ease, filter 90ms ease;
  touch-action: none;
}
.ctrl img { width: 100%; height: 100%; object-fit: contain; display: block; }
.ctrl.down {
  transform: scale(0.93) translateY(2px);
  filter: brightness(1.35) drop-shadow(0 0 14px rgba(255, 122, 42, 0.9));
}
.ctrl.wide { width: clamp(64px, 19vw, 98px); }

/* ---------- screens ---------- */

.screen {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: none;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  padding: calc(env(safe-area-inset-top, 0px) + 8px) 14px calc(env(safe-area-inset-bottom, 0px) + 8px);
}
.screen.on { display: flex; }

#titleScreen {
  justify-content: flex-start;
  background:
    radial-gradient(ellipse at 50% 40%, rgba(20, 3, 5, 0.06) 30%, rgba(12, 2, 4, 0.55) 100%);
  z-index: 22;
}

.titleWrap {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding-top: 1.4vh;
}

#titleArt {
  width: min(84vw, 620px);
  max-height: 30vh;
  object-fit: contain;
  filter: drop-shadow(0 8px 18px rgba(0, 0, 0, 0.7));
  animation: titleFloat 5.5s ease-in-out infinite;
}
@keyframes titleFloat {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-5px); }
}

#levelCards {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: clamp(6px, 1.5vh, 16px);
  margin-top: clamp(4px, 1.6vh, 18px);
}

.levelCard {
  position: relative;
  width: min(39vw, 250px, 22vh);
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
  filter: drop-shadow(0 8px 14px rgba(0, 0, 0, 0.6));
  transition: transform 120ms ease, filter 120ms ease;
}
.levelCard img {
  width: 100%;
  display: block;
  border-radius: 12px;
}
.levelCard:hover { transform: translateY(-2px) scale(1.02); }
.levelCard:active { transform: scale(0.96); filter: brightness(1.2) drop-shadow(0 0 16px rgba(255, 120, 40, 0.75)); }
.levelCard::after {
  content: '';
  position: absolute;
  inset: 4% 5%;
  border-radius: 10px;
  box-shadow: inset 0 0 12px rgba(255, 110, 40, 0.0);
  pointer-events: none;
  transition: box-shadow 120ms ease;
}
.levelCard:active::after { box-shadow: inset 0 0 18px rgba(255, 130, 50, 0.5); }

.cardMeta {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  margin-top: 1px;
  font-size: clamp(9px, 2.5vw, 12px);
  letter-spacing: 0.16em;
  font-weight: 700;
  color: #ffc08a;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.8);
}
.cardBest {
  font-size: clamp(9px, 2.4vw, 11px);
  letter-spacing: 0.06em;
  font-weight: 600;
  color: #d8c7b5;
  opacity: 0.85;
  min-height: 1em;
}
.cardBest:empty { display: none; }

.titleHint {
  margin-top: auto;
  padding: 7px 16px;
  border-radius: 9px;
  background: rgba(22, 5, 6, 0.7);
  box-shadow: inset 0 0 0 1.5px rgba(255, 130, 56, 0.28);
  font-size: clamp(11px, 3vw, 14px);
  font-weight: 600;
  letter-spacing: 0.08em;
  color: #f5e7d6;
}
.titleKeys {
  margin: 8px 4px 0;
  text-align: center;
  font-size: clamp(10px, 2.8vw, 13px);
  color: #cbb6a4;
  line-height: 1.35;
  max-width: 88vw;
  padding: 5px 10px;
  border-radius: 8px;
  background: rgba(18, 4, 5, 0.48);
}

.soundBtn {
  position: absolute;
  top: calc(env(safe-area-inset-top, 0px) + 10px);
  right: calc(env(safe-area-inset-right, 0px) + 10px);
  width: 46px;
  height: 42px;
  border: 0;
  border-radius: 10px;
  background: rgba(28, 7, 9, 0.78);
  box-shadow: inset 0 0 0 1.5px rgba(255, 130, 56, 0.4);
  cursor: pointer;
  padding: 8px;
  z-index: 24;
}
.soundBtn svg { width: 100%; height: 100%; fill: #ffb070; stroke: #ffb070; stroke-width: 1.6; stroke-linecap: round; fill-rule: evenodd; }
.soundBtn .slash { opacity: 0; stroke: #ff6a40; stroke-width: 2.4; }
.soundBtn.off .wave, .soundBtn.off .wave2 { opacity: 0; }
.soundBtn.off .slash { opacity: 1; }
.soundBtn.off svg { opacity: 0.65; }
.soundBtn:active { transform: scale(0.94); }

.whoami {
  position: absolute;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 8px);
  right: calc(env(safe-area-inset-right, 0px) + 12px);
  font-size: 10px;
  color: #8e7568;
  letter-spacing: 0.06em;
  pointer-events: none;
}
.whoami:empty { display: none; }

/* ---------- panels ---------- */

.panel {
  width: min(88vw, 430px);
  max-height: 90vh;
  overflow: auto;
  padding: clamp(16px, 4vw, 26px);
  border-radius: 18px;
  background:
    linear-gradient(180deg, rgba(40, 10, 12, 0.94), rgba(17, 4, 6, 0.95)),
    url('elements/cave_block_textures_02_dark_crimson_rock.webp') center / 190px repeat;
  box-shadow:
    inset 0 0 0 2px rgba(255, 128, 54, 0.4),
    inset 0 0 40px rgba(255, 78, 22, 0.12),
    0 20px 60px rgba(0, 0, 0, 0.7);
  text-align: center;
}
.panel.loading { width: min(70vw, 320px); }
.panelKicker {
  font-size: clamp(10px, 2.9vw, 13px);
  font-weight: 700;
  letter-spacing: 0.22em;
  color: #ffae6a;
  margin-bottom: 4px;
}
.panelTitle {
  font-family: 'Luckiest Guy', system-ui, sans-serif;
  font-size: clamp(34px, 10vw, 56px);
  line-height: 1;
  color: #ff8a3a;
  -webkit-text-stroke: 1.5px #400d10;
  text-shadow: 0 4px 0 #35080a, 0 8px 24px rgba(0, 0, 0, 0.6);
  margin-bottom: clamp(10px, 2.4vh, 20px);
}
.panelRow {
  display: flex;
  gap: 10px;
  justify-content: center;
  margin-bottom: 10px;
  flex-wrap: wrap;
}
.stoneBtn {
  flex: 1 1 0;
  min-width: 110px;
  padding: 12px 14px 11px;
  border: 0;
  border-radius: 12px;
  font-family: 'Outfit', system-ui, sans-serif;
  font-weight: 700;
  font-size: clamp(12px, 3.3vw, 15px);
  letter-spacing: 0.08em;
  color: #ffe1c2;
  cursor: pointer;
  background:
    linear-gradient(180deg, #8e2618 0%, #5c130f 55%, #380b0b 100%);
  box-shadow:
    inset 0 2px 0 rgba(255, 170, 100, 0.4),
    inset 0 -3px 0 rgba(0, 0, 0, 0.45),
    0 4px 10px rgba(0, 0, 0, 0.45);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.6);
}
.stoneBtn:hover { filter: brightness(1.12); }
.stoneBtn:active { transform: translateY(2px); filter: brightness(1.25); }
.stoneBtn.wide { flex: 0 0 auto; width: 100%; margin-top: 2px; }
.stoneBtn:disabled { opacity: 0.45; cursor: default; transform: none; }

.statRow {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: 9px 12px;
  margin-bottom: 12px;
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.28);
  box-shadow: inset 0 0 0 1px rgba(255, 130, 60, 0.2);
  font-size: clamp(12px, 3.2vw, 15px);
  color: #d9c5b3;
}
.statRow b {
  font-family: 'Luckiest Guy', system-ui, sans-serif;
  font-weight: 400;
  font-size: clamp(19px, 5.4vw, 26px);
  color: #ffd08a;
  letter-spacing: 0.04em;
}

.controlList {
  margin: 14px 0 10px;
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.24);
  text-align: left;
  font-size: clamp(11px, 2.9vw, 14px);
  line-height: 1.55;
  color: #d6c2b0;
}
.controlList b { color: #ffc08a; font-weight: 700; }
.panelKeys {
  font-size: clamp(10px, 2.7vw, 12px);
  line-height: 1.45;
  color: #a88f7e;
  margin-top: 6px;
}

/* ---------- narrow / landscape adjustments ---------- */

@media (min-aspect-ratio: 1/1) {
  #titleArt { width: min(46vw, 560px); max-height: 40vh; }
  #levelCards { flex-direction: row; gap: clamp(10px, 3vw, 28px); }
  .levelCard { width: min(22vw, 220px, 34vh); }
  .titleWrap { justify-content: center; padding-top: 0; }
  .titleHint { margin-top: 2vh; }
}

@media (max-height: 800px) {
  .titleKeys { display: none; }
}

@media (max-height: 620px) {
  #titleArt { max-height: 26vh; }
  .levelCard { width: min(34vw, 200px, 20vh); }
}

@media (max-height: 520px) {
  #titleArt { width: min(40vw, 380px); max-height: 34vh; }
  .levelCard { width: min(20vw, 160px, 34vh); }
  #levelCards { flex-direction: row; gap: 12px; margin-top: 2px; }
  .titleKeys { display: none; }
  .titleHint { margin-top: 6px; }
}

@media (max-width: 330px) {
  .ctrl { width: 54px; height: 52px; }
  .carrot { width: 27px; height: 27px; }
}
