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

html, body {
  height: 100%;
}

@font-face {
  font-family: "ComicSansBold";
  src: url("fonts/Comic Sans MS Bold.ttf") format("truetype");
  font-weight: bold;
  font-style: normal;
  font-display: swap;
}

body {
  font-family: "ComicSansBold", "Comic Sans MS", "Comic Sans", cursive;
  background: #FFFFFF;
  overflow: hidden;
  overscroll-behavior: none;
  user-select: none;
  -webkit-user-select: none;
}

#counter {
  position: fixed;
  top: 14px;
  right: 18px;
  font-size: 28px;
  font-weight: bold;
  color: #222;
  background: rgba(255, 255, 255, 0.75);
  border: 3px solid #222;
  border-radius: 12px;
  padding: 4px 14px;
  z-index: 10;
}

#voiceline {
  position: fixed;
  bottom: 110px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 26px;
  font-weight: bold;
  color: #fff;
  background: rgba(0, 0, 0, 0.65);
  border-radius: 12px;
  padding: 8px 20px;
  z-index: 30;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s;
  white-space: nowrap;
}

#voiceline.show {
  opacity: 1;
}

#mood {
  font-size: 20px;
  font-weight: bold;
  color: #222;
  background: rgba(255, 255, 255, 0.85);
  border: 3px solid #222;
  border-radius: 10px;
  padding: 4px 12px;
}

#badges {
  position: fixed;
  top: 60px;
  left: 18px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
  z-index: 10;
}

#mood.hidden {
  display: none;
}

#moodtooltip {
  position: fixed;
  top: 88px;
  left: 18px;
  font-size: 14px;
  font-weight: bold;
  color: #222;
  background: rgba(255, 255, 255, 0.95);
  border: 2px solid #222;
  border-radius: 8px;
  padding: 6px 10px;
  z-index: 11;
  pointer-events: none;
  white-space: nowrap;
}

#moodtooltip.hidden {
  display: none;
}

#effecttooltip {
  position: fixed;
  top: 60px;
  left: 260px;
  font-size: 14px;
  font-weight: bold;
  color: #222;
  background: rgba(255, 255, 255, 0.95);
  border: 2px solid #222;
  border-radius: 8px;
  padding: 6px 10px;
  z-index: 11;
  pointer-events: none;
  white-space: nowrap;
}

#effecttooltip.hidden {
  display: none;
}

#pinwheel {
  position: fixed;
  inset: -50%;
  z-index: 1;
  pointer-events: none;
  background:
    repeating-conic-gradient(
      from 0deg,
      rgba(60, 179, 113, 0.5) 0deg 60deg,
      rgba(255, 255, 255, 0.5) 60deg 120deg
    );
  animation: spin 3s linear infinite;
}

#pinwheel.hidden {
  display: none;
}

@keyframes spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

#feverbadge {
  font-size: 18px;
  font-weight: bold;
  color: #fff;
  background: #ff8c42;
  border: 3px solid #222;
  border-radius: 10px;
  padding: 4px 12px;
}

#feverbadge.hidden {
  display: none;
}

#freezebadge {
  font-size: 18px;
  font-weight: bold;
  color: #fff;
  background: #b7410e;
  border: 3px solid #222;
  border-radius: 10px;
  padding: 4px 12px;
}

#freezebadge.hidden {
  display: none;
}

#studiobadge {
  font-size: 18px;
  font-weight: bold;
  color: #fff;
  background: #9b59b6;
  border: 3px solid #222;
  border-radius: 10px;
  padding: 4px 12px;
  animation: studiopulse 1.5s ease-in-out infinite;
}

#studiobadge.hidden {
  display: none;
}

@keyframes studiopulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.08); }
}

#studiodialog {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 320px;
  background: #fff;
  border: 3px solid #222;
  border-radius: 12px;
  padding: 20px;
  text-align: center;
  z-index: 80;
  box-shadow: 0 8px 30px rgba(0,0,0,0.4);
}

#studiodialog.hidden {
  display: none;
}

#studioearned {
  font-size: 18px;
  font-weight: bold;
  color: #222;
  margin: 12px 0 18px;
}

#studioclaim {
  font-family: inherit;
  font-size: 20px;
  font-weight: bold;
  color: #fff;
  background: #9b59b6;
  border: 3px solid #222;
  border-radius: 10px;
  padding: 10px 28px;
  cursor: pointer;
}

#hungerbar {
  position: fixed;
  top: 14px;
  left: 18px;
  width: 220px;
  height: 34px;
  background: #fff;
  border: 3px solid #222;
  border-radius: 12px;
  overflow: hidden;
  z-index: 10;
}

#hungerfill {
  height: 100%;
  width: 100%;
  background: #86cecb;
  transition: width 0.2s;
}

#hungerlabel {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  font-weight: bold;
  color: #222;
  text-shadow: 1px 1px 0 #fff, -1px -1px 0 #fff, 1px -1px 0 #fff, -1px 1px 0 #fff;
}

#shopbtn {
  position: fixed;
  bottom: 18px;
  right: 18px;
  font-family: inherit;
  font-size: 20px;
  font-weight: bold;
  color: #222;
  background: #fff;
  border: 3px solid #222;
  border-radius: 12px;
  padding: 8px 18px;
  cursor: pointer;
  z-index: 10;
}

#shop {
  position: fixed;
  bottom: 70px;
  right: 18px;
  width: min(720px, calc(100vw - 28px));
  max-height: min(78vh, 720px);
  overflow-y: auto;
  background: #fff;
  border: 4px solid #222;
  border-radius: 12px;
  padding: 18px;
  z-index: 20;
}

#shop.hidden {
  display: none;
}

.shop-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.shop-title {
  font-size: 28px;
  font-weight: bold;
}

.shop-subtitle {
  color: #777;
  font-size: 14px;
}

.shop-tabs {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 7px;
  margin-bottom: 14px;
}

.shop-tab {
  font-family: inherit;
  font-size: 14px;
  font-weight: bold;
  color: #222;
  background: #eee;
  border: 2px solid #222;
  border-radius: 8px;
  padding: 8px 5px;
  cursor: pointer;
}

.shop-tab.active {
  background: #86cecb;
}

.shop-category.hidden {
  display: none;
}

.shop-category-title {
  color: #555;
  font-size: 14px;
  letter-spacing: 0.08em;
  margin: 2px 0 7px;
}

.shop-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.shop-item {
  display: flex;
  align-items: center;
  gap: 10px;
  border: 2px solid #222;
  border-radius: 10px;
  min-height: 96px;
  padding: 10px;
  background: #fff;
}

.shop-item.owned {
  background: #e9f8f6;
}

.shop-item.hidden {
  display: none;
}

.shop-item img {
  width: 64px;
  height: 64px;
  object-fit: contain;
  flex: 0 0 64px;
}

.shop-info {
  flex: 1;
}

.shop-name {
  font-size: 17px;
  font-weight: bold;
}

.shop-desc {
  font-size: 13px;
  color: #555;
  margin: 2px 0;
}

.shop-cost {
  font-size: 14px;
  color: #555;
}

.buybtn {
  font-family: inherit;
  font-size: 14px;
  font-weight: bold;
  color: #222;
  background: #86cecb;
  border: 2px solid #222;
  border-radius: 8px;
  padding: 4px 10px;
  cursor: pointer;
}

.buybtn:disabled {
  background: #cfe8e6;
  color: #666;
  cursor: default;
}

#shopclose {
  width: 100%;
  font-family: inherit;
  font-size: 16px;
  font-weight: bold;
  color: #222;
  background: #eee;
  border: 2px solid #222;
  border-radius: 8px;
  padding: 6px;
  cursor: pointer;
  margin-top: 14px;
}

#hotbar {
  position: fixed;
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 10px;
  background: rgba(255, 255, 255, 0.85);
  border: 3px solid #222;
  border-radius: 12px;
  padding: 8px;
  min-height: 60px;
  z-index: 10;
}

.hotbar-item {
  width: 48px;
  height: 48px;
  border: 2px solid #222;
  border-radius: 8px;
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: grab;
  position: relative;
}

.hotbar-item img {
  width: 40px;
  height: 40px;
  object-fit: contain;
  pointer-events: none;
}

.hotbar-item .count {
  position: absolute;
  bottom: -2px;
  right: -2px;
  background: #222;
  color: #fff;
  font-size: 12px;
  border-radius: 6px;
  padding: 0 4px;
}

.hotbar-item.dragging {
  opacity: 0.5;
}

.drag-ghost {
  position: fixed;
  width: 48px;
  height: 48px;
  pointer-events: none;
  z-index: 100;
  transform: translate(-50%, -50%);
}

.drag-ghost img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.drag-ghost.reject {
  animation: reject-bounce 0.45s ease-out forwards;
}

@keyframes reject-bounce {
  0% {
    transform: translate(-50%, -50%) scale(1);
    opacity: 1;
  }
  25% {
    transform: translate(-50%, -50%) scale(1.25);
  }
  60% {
    transform: translate(-50%, 40%) scale(1.05);
  }
  100% {
    transform: translate(-50%, -10%) scale(0.8);
    opacity: 0;
  }
}

#hotbar.empty::after {
  content: "HOTBAR";
  color: #999;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
}

#stage {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  touch-action: manipulation;
  z-index: 2;
}

#target {
  max-width: 40vmin;
  max-height: 55vmin;
  width: auto;
  height: auto;
  pointer-events: none;
  transition: transform 0.08s;
  position: relative;
  z-index: 2;
  filter: drop-shadow(2px 3px 0 rgba(34, 34, 34, 0.2));
}

#teto-assist {
  position: absolute;
  left: 50%;
  bottom: calc(50% + 15vmin);
  width: clamp(86px, 18vmin, 170px);
  height: auto;
  pointer-events: none;
  transform: translateX(-50%);
  transform-origin: 50% 100%;
  z-index: 3;
  filter: drop-shadow(2px 3px 0 rgba(34, 34, 34, 0.2));
}

#teto-assist.hidden {
  display: none;
}

#teto-assist.bouncing {
  animation: teto-bounce-flip 0.92s cubic-bezier(0.22, 0.72, 0.3, 1) both;
}

@keyframes teto-bounce-flip {
  0% {
    transform: translateX(-50%) translateY(0) rotate(0deg) rotateY(0deg);
  }
  24% {
    transform: translateX(-50%) translateY(-5vmin) rotate(-7deg) rotateY(80deg);
  }
  52% {
    transform: translateX(-50%) translateY(-7vmin) rotate(5deg) rotateY(190deg);
  }
  78% {
    transform: translateX(-50%) translateY(-2vmin) rotate(-3deg) rotateY(290deg);
  }
  100% {
    transform: translateX(-50%) translateY(0) rotate(0deg) rotateY(360deg);
  }
}

#target.held {
  transform: scaleX(1.65) scaleY(0.7);
}

.hitmarker {
  position: fixed;
  font-size: 40px;
  font-weight: bold;
  color: #86cecb;
  text-shadow: 2px 2px 0 #fff, -2px -2px 0 #fff, 2px -2px 0 #fff, -2px 2px 0 #fff;
  pointer-events: none;
  transform: translate(-50%, -50%);
  animation: pop 0.5s ease-out forwards;
  z-index: 5;
}

@keyframes pop {
  0% { opacity: 1; transform: translate(-50%, -50%) scale(0.6); }
  100% { opacity: 0; transform: translate(-50%, -120%) scale(1.3); }
}

@media (max-width: 560px) {
  #shop {
    right: 10px;
    bottom: 68px;
    width: calc(100vw - 20px);
    padding: 13px;
  }

  .shop-header {
    align-items: center;
  }

  .shop-title {
    font-size: 24px;
  }

  .shop-subtitle {
    font-size: 12px;
  }

  .shop-grid {
    grid-template-columns: 1fr;
  }

  .shop-item {
    min-height: 86px;
  }

  .shop-item img {
    width: 56px;
    height: 56px;
    flex-basis: 56px;
  }

  .shop-desc {
    font-size: 12px;
  }
}

#fadeblack {
  position: fixed;
  inset: 0;
  background: #000;
  opacity: 0;
  pointer-events: none;
  z-index: 59;
}

#fadeblack.fade {
  animation: fadeblack-anim 1.3s ease-in forwards;
}

@keyframes fadeblack-anim {
  0% { opacity: 0; }
  100% { opacity: 0.85; }
}

#target.dead {
  filter: grayscale(1) brightness(0.75) contrast(1.1);
}

#gameover {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  background: rgba(0, 0, 0, 0.85);
  color: #fff;
  z-index: 70;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.4s;
}

#gameover.show {
  opacity: 1;
  pointer-events: auto;
}

#deathtext {
  font-size: 52px;
  font-weight: bold;
  color: #fff;
}

#deathhits,
#deathspent {
  font-size: 26px;
  font-weight: bold;
  color: #fff;
  text-shadow: 1px 1px 0 #000, -1px -1px 0 #000;
}

#restartbtn {
  font-family: inherit;
  font-size: 24px;
  font-weight: bold;
  color: #fff;
  background: #86cecb;
  border: 3px solid #fff;
  border-radius: 12px;
  padding: 12px 34px;
  cursor: pointer;
}

/* Keep the play area clear on phones with small screens and/or a home indicator. */
@media (max-width: 600px) {
  #counter {
    top: max(10px, env(safe-area-inset-top));
    right: 12px;
    font-size: 20px;
    padding: 5px 9px;
    border-width: 2px;
    border-radius: 10px;
  }

  #hungerbar {
    top: max(10px, env(safe-area-inset-top));
    left: 12px;
    width: min(160px, calc(100vw - 142px));
    height: 30px;
    border-width: 2px;
    border-radius: 10px;
  }

  #hungerlabel {
    font-size: 13px;
  }

  #badges {
    top: calc(max(10px, env(safe-area-inset-top)) + 46px);
    left: 12px;
    right: 12px;
    gap: 5px;
  }

  #mood,
  #feverbadge,
  #freezebadge,
  #studiobadge {
    font-size: 14px;
    border-width: 2px;
    border-radius: 8px;
    padding: 3px 8px;
    max-width: min(100%, 250px);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  #moodtooltip,
  #effecttooltip {
    top: calc(max(10px, env(safe-area-inset-top)) + 82px);
    left: 12px;
    right: 12px;
    max-width: none;
    white-space: normal;
    text-align: center;
    font-size: 12px;
    padding: 6px 8px;
  }

  #effecttooltip {
    top: calc(max(10px, env(safe-area-inset-top)) + 46px);
  }

  #voiceline {
    bottom: calc(env(safe-area-inset-bottom) + 86px);
    left: 12px;
    right: 12px;
    transform: none;
    width: auto;
    white-space: normal;
    text-align: center;
    font-size: 18px;
    line-height: 1.15;
    padding: 8px 12px;
  }

  #target {
    max-width: min(68vw, 42vh);
    max-height: 46vh;
  }

  #teto-assist {
    width: clamp(74px, 24vw, 120px);
    bottom: calc(50% + min(30vw, 140px));
  }

  #shopbtn {
    right: 12px;
    bottom: calc(env(safe-area-inset-bottom) + 12px);
    min-width: 72px;
    min-height: 44px;
    font-size: 16px;
    padding: 7px 10px;
    border-width: 2px;
    border-radius: 10px;
  }

  #hotbar {
    left: 12px;
    right: 94px;
    bottom: calc(env(safe-area-inset-bottom) + 12px);
    transform: none;
    min-width: 0;
    min-height: 58px;
    padding: 5px;
    gap: 7px;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    touch-action: none;
    -webkit-overflow-scrolling: touch;
  }

  .hotbar-item {
    width: 46px;
    height: 46px;
    flex: 0 0 46px;
  }

  .hotbar-item img {
    width: 38px;
    height: 38px;
  }

  #shop {
    left: 0;
    right: 0;
    bottom: 0;
    width: auto;
    max-height: 85dvh;
    padding: 14px 12px calc(14px + env(safe-area-inset-bottom));
    border-width: 3px;
    border-bottom: 0;
    border-radius: 18px 18px 0 0;
    box-shadow: 0 -8px 24px rgba(0, 0, 0, 0.18);
    overscroll-behavior: contain;
  }

  .shop-header {
    margin-bottom: 10px;
  }

  .shop-title {
    font-size: 22px;
  }

  .shop-subtitle {
    font-size: 11px;
  }

  .shop-tabs {
    gap: 5px;
    margin-bottom: 12px;
  }

  .shop-tab {
    min-height: 44px;
    font-size: 12px;
    padding: 7px 3px;
  }

  .shop-grid {
    gap: 8px;
  }

  .shop-item {
    display: grid;
    grid-template-columns: 52px minmax(0, 1fr) auto;
    gap: 8px;
    min-height: 82px;
    padding: 8px;
  }

  .shop-item img {
    width: 52px;
    height: 52px;
    flex-basis: auto;
  }

  .shop-name {
    font-size: 15px;
  }

  .shop-desc {
    line-height: 1.15;
  }

  .buybtn {
    min-width: 58px;
    min-height: 44px;
    padding: 4px 7px;
  }

  #shopclose {
    min-height: 44px;
    margin-top: 12px;
  }

  #studiodialog {
    width: calc(100vw - 24px);
    max-width: 320px;
    padding: 16px 14px;
  }

  #studioclaim {
    min-height: 46px;
    width: 100%;
    padding: 9px 12px;
  }

  #gameover {
    padding: 20px 16px;
    gap: 14px;
    text-align: center;
  }

  #deathtext {
    font-size: clamp(34px, 12vw, 52px);
  }

  #deathhits,
  #deathspent {
    font-size: clamp(18px, 5.5vw, 26px);
  }

  #restartbtn {
    min-height: 48px;
    font-size: 20px;
    padding: 10px 28px;
  }
}

#loader {
  position: fixed;
  inset: 0;
  background: #ffffff;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  z-index: 999;
  transition: opacity 0.45s ease;
}

#loader.done {
  opacity: 0;
  pointer-events: none;
}

#loader.gone {
  display: none;
}

#loader img {
  width: 170px;
  image-rendering: auto;
  animation: loaderbounce 1s ease-in-out infinite;
}

.loader-title {
  font-size: 44px;
  font-weight: bold;
  color: #222;
  letter-spacing: 3px;
}

.loader-bar {
  width: min(420px, 72vw);
  height: 26px;
  border: 3px solid #222;
  border-radius: 12px;
  background: #ffffff;
  overflow: hidden;
}

#loaderfill {
  width: 0%;
  height: 100%;
  background: #86cecb;
  border-right: 3px solid #222;
  box-sizing: border-box;
  transition: width 0.15s linear;
}

#loadertext {
  font-size: 16px;
  font-weight: bold;
  color: #222;
}

@keyframes loaderbounce {
  0%, 100% { transform: translateY(0) scale(1, 1); }
  50% { transform: translateY(-14px) scale(0.96, 1.05); }
}
