* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #10121a;
  font-family: "Trebuchet MS", "Segoe UI", Verdana, sans-serif;
  color: #e8e6df;
  overscroll-behavior: none;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

#app {
  position: fixed;
  inset: 0;
  overflow: hidden;
}

#game {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

.hidden { display: none !important; }

#hud {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  padding: calc(10px + env(safe-area-inset-top)) calc(12px + env(safe-area-inset-right)) 0 calc(12px + env(safe-area-inset-left));
  pointer-events: none;
  z-index: 30;
}

#stamWrap {
  display: flex;
  align-items: center;
  gap: 7px;
  background: rgba(10, 12, 20, 0.55);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 12px;
  padding: 7px 10px;
  backdrop-filter: blur(2px);
}

.hudIcon { width: 20px; height: 20px; color: #ffd35c; flex: 0 0 auto; }

#stamBarOuter {
  width: clamp(90px, 22vw, 190px);
  height: 14px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.10);
  border: 1px solid rgba(0, 0, 0, 0.45);
  overflow: hidden;
}

#stamBarFill {
  width: 100%;
  height: 100%;
  border-radius: 7px;
  background: linear-gradient(90deg, #58d97a, #9fe870);
  transform-origin: left center;
  transition: background 0.3s;
}

#stamWrap.warn #stamBarFill { background: linear-gradient(90deg, #e8a33d, #ffd35c); }
#stamWrap.low #stamBarFill { background: linear-gradient(90deg, #d84343, #ff7a5c); }
#stamWrap.low { animation: lowPulse 0.7s infinite; }

@keyframes lowPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(216, 67, 67, 0.0); }
  50% { box-shadow: 0 0 14px 3px rgba(216, 67, 67, 0.55); }
}

#scoreWrap {
  text-align: center;
  background: rgba(10, 12, 20, 0.55);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 12px;
  padding: 5px 14px;
  backdrop-filter: blur(2px);
  min-width: 92px;
}

#scoreVal {
  font-size: clamp(20px, 4.5vw, 30px);
  font-weight: bold;
  letter-spacing: 1px;
  color: #fff;
  text-shadow: 0 2px 6px rgba(0, 0, 0, 0.7);
  line-height: 1.15;
}

#bestVal {
  font-size: 11px;
  color: #b9c4d8;
  letter-spacing: 0.5px;
}

#hudButtons {
  display: flex;
  gap: 8px;
  pointer-events: auto;
}

.iconBtn {
  width: 46px;
  height: 46px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(10, 12, 20, 0.6);
  color: #e8e6df;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  backdrop-filter: blur(2px);
}

.iconBtn svg { width: 22px; height: 22px; }
.iconBtn:active { transform: scale(0.93); }
.iconBtn:focus { outline: none; }
.iconBtn:focus-visible { outline: 2px solid #ffd35c; outline-offset: 2px; }
.bigBtn:focus { outline: none; }
.bigBtn:focus-visible { outline: 3px solid #fff; outline-offset: 2px; }
#muteBtn .iconOff { display: none; }
#muteBtn.muted .iconOn { display: none; }
#muteBtn.muted .iconOff { display: block; }
#muteBtn.muted { color: #8a90a2; }

#banner {
  position: absolute;
  top: calc(74px + env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  z-index: 12;
  padding: 9px 22px;
  border-radius: 14px;
  font-size: clamp(17px, 4vw, 26px);
  font-weight: bold;
  letter-spacing: 1.5px;
  text-align: center;
  pointer-events: none;
  animation: bannerDrop 0.35s ease-out;
  white-space: nowrap;
}

@keyframes bannerDrop {
  0% { transform: translateX(-50%) translateY(-24px) scale(0.8); opacity: 0; }
  70% { transform: translateX(-50%) translateY(3px) scale(1.04); opacity: 1; }
  100% { transform: translateX(-50%) translateY(0) scale(1); }
}

#banner.warn {
  background: rgba(40, 26, 6, 0.82);
  border: 2px solid #ffb03a;
  color: #ffd98c;
  text-shadow: 0 0 12px rgba(255, 176, 58, 0.8);
  animation: bannerDrop 0.35s ease-out, bannerBlink 0.55s 0.35s infinite;
}

@keyframes bannerBlink {
  0%, 100% { box-shadow: 0 0 6px 1px rgba(255, 176, 58, 0.35); }
  50% { box-shadow: 0 0 22px 6px rgba(255, 176, 58, 0.85); }
}

#banner.safe {
  background: rgba(10, 40, 20, 0.8);
  border: 2px solid #58d97a;
  color: #c8f5c0;
}

#toast {
  position: absolute;
  bottom: calc(96px + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  z-index: 12;
  background: rgba(10, 12, 20, 0.78);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: #e8e6df;
  padding: 8px 18px;
  border-radius: 12px;
  font-size: clamp(13px, 3.2vw, 17px);
  pointer-events: none;
  transition: opacity 0.5s;
  text-align: center;
  max-width: 86vw;
}

#firstHint {
  position: absolute;
  bottom: calc(40px + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  z-index: 11;
  color: rgba(232, 230, 223, 0.85);
  background: rgba(10, 12, 20, 0.55);
  padding: 7px 16px;
  border-radius: 12px;
  font-size: clamp(12px, 3vw, 15px);
  pointer-events: none;
  transition: opacity 1s;
  text-align: center;
  max-width: 90vw;
}

#touchLayer {
  position: absolute;
  inset: 0;
  z-index: 5;
  touch-action: none;
}

#joystick {
  position: absolute;
  z-index: 15;
  pointer-events: none;
}

#stickBase {
  position: absolute;
  width: 132px;
  height: 132px;
  margin: -66px 0 0 -66px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.4);
  background: rgba(20, 24, 36, 0.35);
  box-shadow: 0 0 18px rgba(0, 0, 0, 0.35) inset;
}

#stickKnob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 58px;
  height: 58px;
  margin: -29px 0 0 -29px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, rgba(255, 255, 255, 0.55), rgba(255, 255, 255, 0.12) 60%);
  border: 2px solid rgba(255, 255, 255, 0.65);
}

#joystickHint {
  position: absolute;
  z-index: 9;
  left: calc(26px + env(safe-area-inset-left));
  bottom: calc(26px + env(safe-area-inset-bottom));
  width: 108px;
  height: 108px;
  border-radius: 50%;
  border: 2px dashed rgba(255, 255, 255, 0.28);
  pointer-events: none;
  opacity: 0.9;
}

#joystickHint::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 44px;
  height: 44px;
  margin: -22px 0 0 -22px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.10);
  border: 2px solid rgba(255, 255, 255, 0.3);
}

.overlay {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(8, 10, 16, 0.72);
  backdrop-filter: blur(3px);
  padding: calc(16px + env(safe-area-inset-top)) 16px calc(16px + env(safe-area-inset-bottom));
}

.panel {
  width: min(560px, 94vw);
  max-height: 96vh;
  overflow-y: auto;
  background: linear-gradient(160deg, #232838, #191d29);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 20px;
  padding: 26px 26px 22px;
  text-align: center;
  box-shadow: 0 18px 60px rgba(0, 0, 0, 0.55);
}

.panel.small { width: min(420px, 92vw); padding: 24px 24px 20px; }

#titleSpider { margin-bottom: 4px; animation: spiderBob 2.6s ease-in-out infinite; }

@keyframes spiderBob {
  0%, 100% { transform: translateY(0) rotate(-2deg); }
  50% { transform: translateY(-9px) rotate(2deg); }
}

h1 {
  font-size: clamp(30px, 7.5vw, 46px);
  letter-spacing: 1px;
  color: #ffe9b0;
  text-shadow: 0 3px 0 rgba(0, 0, 0, 0.4), 0 0 26px rgba(255, 200, 90, 0.25);
  margin-bottom: 4px;
}

.tagline {
  color: #b9c4d8;
  font-size: clamp(13px, 3.2vw, 16px);
  margin-bottom: 18px;
}

#legend {
  display: flex;
  flex-direction: column;
  gap: 9px;
  text-align: left;
  margin: 0 auto 20px;
  max-width: 430px;
}

.legRow {
  display: flex;
  align-items: center;
  gap: 12px;
  background: rgba(255, 255, 255, 0.05);
  border-radius: 12px;
  padding: 8px 12px;
  font-size: clamp(12.5px, 3vw, 14.5px);
  line-height: 1.3;
}

.legRow svg { width: 26px; height: 26px; flex: 0 0 auto; }
.legRow b { color: #ffd98c; }

.bigBtn {
  font-family: inherit;
  font-size: clamp(19px, 4.6vw, 24px);
  font-weight: bold;
  letter-spacing: 1px;
  color: #20242f;
  background: linear-gradient(180deg, #ffd35c, #f5a623);
  border: none;
  border-radius: 16px;
  padding: 15px 44px;
  min-height: 56px;
  cursor: pointer;
  box-shadow: 0 5px 0 #b06f10, 0 10px 22px rgba(0, 0, 0, 0.4);
  transition: transform 0.06s;
}

.bigBtn:active {
  transform: translateY(4px);
  box-shadow: 0 1px 0 #b06f10, 0 4px 12px rgba(0, 0, 0, 0.4);
}

.hint {
  margin-top: 14px;
  color: #9aa5bb;
  font-size: clamp(11.5px, 2.8vw, 13.5px);
  line-height: 1.45;
}

h2 {
  font-size: clamp(22px, 5.5vw, 30px);
  margin-bottom: 14px;
  color: #ffe9b0;
  line-height: 1.25;
}

#goScore {
  font-size: clamp(40px, 10vw, 58px);
  font-weight: bold;
  color: #fff;
  text-shadow: 0 3px 10px rgba(0, 0, 0, 0.5);
}

#goBest { color: #b9c4d8; font-size: 15px; margin-bottom: 6px; }

#goNewBest {
  display: block;
  width: max-content;
  margin: 0 auto 12px;
  background: linear-gradient(90deg, #ffd35c, #f5a623);
  color: #20242f;
  font-weight: bold;
  font-size: 14px;
  letter-spacing: 1.5px;
  padding: 5px 14px;
  border-radius: 999px;
  animation: bestPop 0.5s ease-out;
}

@keyframes bestPop {
  0% { transform: scale(0); }
  70% { transform: scale(1.25); }
  100% { transform: scale(1); }
}

#gameoverScreen .bigBtn { margin-top: 10px; }

@media (max-height: 480px) {
  #legend { display: none; }
  .panel { padding: 14px 18px; }
  #titleSpider svg { width: 52px; height: 52px; }
}
