* { box-sizing: border-box; }

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

body {
  font-family: "Jua", "Malgun Gothic", "Apple SD Gothic Neo", system-ui, sans-serif;
  background:
    repeating-linear-gradient(0deg, rgba(255, 255, 255, .04) 0 2px, rgba(0, 0, 0, 0) 2px 4px),
    radial-gradient(circle at 50% -10%, #4b2a86, #221447 46%, #0b0620);
  color: #eef7ff;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  display: flex;
  align-items: center;
  justify-content: center;
}

#game {
  position: relative;
  width: 100%;
  height: 100dvh;
  max-width: 400px;
  max-height: 500px;
  margin: 0 auto;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: linear-gradient(180deg, rgba(64, 20, 120, .5), rgba(11, 6, 32, .3));
  box-shadow: inset 0 0 0 3px rgba(0, 229, 255, .3), inset 0 0 34px rgba(255, 0, 170, .2);
}

/* ---------- HUD ---------- */
#hud {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  flex: 0 0 auto;
}

.hud-item {
  background: linear-gradient(#2b1a5a, #150c33);
  border: 2px solid #00e5ff;
  border-radius: 10px;
  padding: 4px 6px;
  text-align: center;
  box-shadow: 0 0 12px rgba(0, 229, 255, .55), inset 0 0 14px rgba(0, 229, 255, .22);
  line-height: 1.1;
}

.hud-label {
  display: block;
  font-size: 11px;
  letter-spacing: 2px;
  color: #ffd83d;
  text-shadow: 0 0 8px rgba(255, 170, 0, .9);
}

.hud-item > span:last-child {
  font-family: "Black Han Sans", "Jua", system-ui, sans-serif;
  font-size: 21px;
  font-weight: 400;
  color: #fff;
  text-shadow: 0 0 6px #00e5ff, 0 0 14px #0aa7ff;
}

/* ---------- 왕 체력바 ---------- */
#kingBar {
  display: flex;
  align-items: center;
  gap: 8px;
  background: linear-gradient(#3a0f3f, #1d0730);
  border: 2px solid #ff2fb9;
  border-radius: 10px;
  padding: 6px 10px;
  color: #ffe6fb;
  font-size: 12px;
  flex: 0 0 auto;
  box-shadow: 0 0 12px rgba(255, 47, 185, .55);
}

#kingBar.hidden { display: none; }

.king-label { white-space: nowrap; font-weight: 700; }

#kingBar .bar {
  flex: 1;
  height: 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, .2);
  overflow: hidden;
}

#kingFill {
  height: 100%;
  width: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, #ffd83d, #ff2fb9);
  transition: width .15s ease-out;
}

#kingHpText { font-weight: 700; white-space: nowrap; }

/* ---------- 밭 ---------- */
#board {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  gap: 8px;
  padding: 10px;
  background:
    linear-gradient(rgba(0, 229, 255, .13) 1px, rgba(0, 0, 0, 0) 1px) 0 0 / 100% 34px,
    linear-gradient(90deg, rgba(255, 47, 185, .13) 1px, rgba(0, 0, 0, 0) 1px) 0 0 / 34px 100%,
    radial-gradient(circle at 50% 0%, #3b1668, #1d0c40 60%, #120629);
  border: 3px solid #00e5ff;
  border-radius: 20px;
  box-shadow: 0 0 18px rgba(0, 229, 255, .5), inset 0 0 26px rgba(120, 0, 255, .5);
}

/* ---------- 구멍 ---------- */
.hole {
  position: relative;
  min-height: 0;
  min-width: 0;
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
  touch-action: manipulation;
  font: inherit;
}

.hole .ground {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: radial-gradient(circle at 50% 34%, #5a2ea6, #341a63 62%, #241046);
  box-shadow: inset 0 -8px 14px rgba(0, 0, 0, .5), 0 0 0 2px rgba(255, 216, 61, .55), 0 0 14px rgba(255, 216, 61, .3);
}

.hole .pit {
  position: absolute;
  left: 50%;
  bottom: 13%;
  transform: translateX(-50%);
  width: 76%;
  height: 36%;
  border-radius: 50%;
  background: radial-gradient(circle at 50% 28%, #1b0d33, #04010c);
  box-shadow: inset 0 6px 12px rgba(0, 0, 0, .85), 0 0 12px rgba(120, 0, 255, .6);
}

.hole .clip {
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  bottom: 20%;
  overflow: hidden;
  border-radius: 50%;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

/* ---------- 두더지 (그림) ---------- */
.mole {
  position: relative;
  width: 92%;
  aspect-ratio: 200 / 172;
  transform: translateY(112%);
  transition: transform .46s cubic-bezier(.3, 0, .6, 1);
}

.hole.up .mole {
  transform: translateY(6%);
  transition: transform .13s cubic-bezier(.2, .9, .3, 1.2);
}

/* 그림에서 캐릭터 부분만 보이도록 잘라 쓴다 */
.mole .body {
  position: absolute;
  inset: 0;
  overflow: hidden;
}

.mole .body svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  pointer-events: none;
}

/* 균열 표시 */
.mole .crack { position: absolute; inset: 0; opacity: 0; transition: opacity .15s; }
.mole .crack::before,
.mole .crack::after {
  content: '';
  position: absolute;
  width: 3px;
  border-radius: 2px;
  background: rgba(58, 34, 16, .8);
}
.mole .crack::before { top: 40%; left: 50%; height: 22%; transform: rotate(16deg); }
.mole .crack::after { top: 52%; left: 40%; height: 18%; transform: rotate(-24deg); }

.hole.cracked .mole .body { filter: saturate(.6) brightness(.86); }
.hole.cracked .mole .crack { opacity: 1; }

/* 튼튼한 두더지: 공사장 헬멧(안전모)을 쓴다 */
.hole.tough .mole .body { filter: saturate(.55) contrast(1.05) brightness(.98); }

/* 헬멧 몸통 */
.hole.tough .mole::after {
  content: '';
  position: absolute;
  top: 9%;
  left: 31%;
  right: 31%;
  height: 27%;
  border-radius: 52% 52% 12% 12% / 66% 66% 26% 26%;
  background: linear-gradient(#fff08a, #ffc72e 52%, #d98c00);
  box-shadow:
    inset -5px -4px 0 rgba(150, 84, 0, .3),
    inset 5px 3px 0 rgba(255, 255, 255, .55),
    0 2px 0 rgba(90, 60, 20, .35);
  z-index: 2;
}

/* 헬멧 챙 */
.hole.tough .mole::before {
  content: '';
  position: absolute;
  top: 30%;
  left: 22%;
  right: 22%;
  height: 9%;
  border-radius: 999px;
  background: linear-gradient(#ffe066, #e09b00);
  box-shadow: 0 3px 0 rgba(90, 60, 20, .3);
  z-index: 3;
}

/* 두더지 대왕: 붉은 기운 + 왕관 */
.hole.king .mole::before {
  content: '';
  position: absolute;
  top: -4%;
  left: 33%;
  right: 33%;
  height: 22%;
  background: linear-gradient(#f7d98a, #d9a63f);
  clip-path: polygon(0 100%, 0 32%, 22% 68%, 40% 0, 60% 68%, 78% 0, 100% 32%, 100% 100%);
  filter: drop-shadow(0 2px 0 rgba(117, 82, 63, .45));
}
.hole.king .mole .body { filter: hue-rotate(-22deg) saturate(1.2) brightness(.98); }

/* 때리는 순간 */
.hole.hit .mole { transform: translateY(6%) scale(.9) rotate(-4deg); }
.hole.hit .ground { box-shadow: inset 0 -8px 14px rgba(0, 0, 0, .5), 0 0 0 2px rgba(255, 216, 61, .6), 0 0 8px rgba(255, 216, 61, .25); }

/* ---------- 화면 ---------- */
.screen {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: radial-gradient(circle at 50% 40%, rgba(90, 20, 160, .78), rgba(5, 2, 18, .93));
  backdrop-filter: blur(2px);
  z-index: 10;
}

.screen.hidden { display: none; }

.panel {
  width: 100%;
  max-width: 500px;
  max-height: 100%;
  overflow: auto;
  background:
    repeating-linear-gradient(0deg, rgba(255, 255, 255, .05) 0 2px, rgba(0, 0, 0, 0) 2px 4px),
    linear-gradient(#2a1157, #150a33);
  border: 3px solid #ffd83d;
  border-radius: 16px;
  padding: 22px;
  box-shadow: 0 0 24px rgba(255, 47, 185, .6), inset 0 0 22px rgba(0, 229, 255, .3);
  text-align: center;
}

.panel h1 {
  margin: 0 0 10px;
  font-family: "Black Han Sans", "Jua", system-ui, sans-serif;
  font-size: 30px;
  font-weight: 400;
  color: #fff;
  text-shadow: 0 0 8px #ff2fb9, 0 0 18px #7a2bff, 2px 2px 0 #0a0320;
}
.panel h2 {
  margin: 0 0 10px;
  font-family: "Black Han Sans", "Jua", system-ui, sans-serif;
  font-size: 26px;
  font-weight: 400;
  color: #fff;
  text-shadow: 0 0 8px #00e5ff, 0 0 18px #0aa7ff, 2px 2px 0 #0a0320;
}
.panel p { margin: 8px 0; font-size: 16px; line-height: 1.55; color: #d9d2ff; }

.panel .story {
  margin: 10px 0;
  padding: 12px;
  border-radius: 10px;
  background: rgba(0, 229, 255, .1);
  border: 1px solid rgba(0, 229, 255, .45);
  text-align: left;
}
.panel .story p { margin: 6px 0; color: #eaf6ff; font-size: 16px; }

.panel .story .type-line { min-height: 1.45em; }

.panel .story .type-line.typing::after {
  content: '▮';
  margin-left: 2px;
  color: #00ffe0;
  animation: careBlink .7s steps(1) infinite;
}

@keyframes careBlink {
  0%, 50% { opacity: 1; }
  50.01%, 100% { opacity: 0; }
}

.panel .ranking-status {
  margin: 10px 0 0;
  min-height: 1.3em;
  font-size: 15px;
  color: #9fe9ff;
}

.panel .rules {
  margin: 10px 0;
  font-size: 15px;
  color: #ffe9a8;
  text-align: left;
  background: rgba(255, 47, 185, .14);
  border-left: 4px solid #ff2fb9;
  border-radius: 8px;
  padding: 8px 10px;
}

.panel .big {
  font-family: "Black Han Sans", "Jua", system-ui, sans-serif;
  font-size: 28px;
  font-weight: 400;
  color: #00ffe0;
  text-shadow: 0 0 10px #00b3ff;
}

.panel button {
  margin-top: 14px;
  width: 100%;
  padding: 14px 18px;
  font-family: inherit;
  font-size: 19px;
  font-weight: 700;
  letter-spacing: 1px;
  color: #1a0530;
  background: linear-gradient(#ffe66b, #ffb300);
  border: 0;
  border-bottom: 4px solid #b06f00;
  border-radius: 999px;
  cursor: pointer;
  box-shadow: 0 0 16px rgba(255, 200, 0, .7);
}

.panel button:active { transform: translateY(2px); border-bottom-width: 2px; }

@media (max-height: 520px) {
  #hud { grid-template-columns: repeat(2, 1fr); gap: 5px; }
  .hud-item { padding: 2px 4px; }
  .hud-label { font-size: 10px; letter-spacing: 1px; }
  .hud-item > span:last-child { font-size: 16px; }
  .panel { padding: 14px; }
  .panel h1 { font-size: 22px; margin-bottom: 6px; }
  .panel h2 { font-size: 20px; margin-bottom: 6px; }
  .panel p { font-size: 14px; }
  .panel .story p { font-size: 14px; }
  .panel .rules { font-size: 13.5px; }
  .panel .big { font-size: 21px; }
  .panel button { padding: 10px; margin-top: 10px; }
}

/* ---------- 망치 커서 ---------- */
#board,
#board * { cursor: none; }

#hammer {
  position: fixed;
  left: 0;
  top: 0;
  width: 60px;
  height: 60px;
  z-index: 60;
  pointer-events: none;
  opacity: 0;
  transform: translate(-50%, -50%);
  transition: opacity .12s linear;
  will-change: transform;
}

#hammer.visible { opacity: 1; }

.hammer-tool {
  position: absolute;
  inset: 0;
  transform-origin: 74% 82%;
  transform: rotate(-40deg);
  transition: transform .07s ease-out;
}

#hammer.swing .hammer-tool { transform: rotate(16deg); }

.hammer-head {
  position: absolute;
  top: 2px;
  left: 4px;
  width: 48px;
  height: 20px;
  border-radius: 7px;
  background: linear-gradient(#f4f7fa, #b3bfc9 52%, #76838f);
  box-shadow: inset 0 -3px 0 rgba(74, 53, 32, .22), 0 2px 5px rgba(74, 53, 32, .26);
}

.hammer-head::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 7px;
  width: 12px;
  height: 6px;
  border-radius: 4px;
  background: rgba(255, 255, 255, .7);
}

.hammer-grip {
  position: absolute;
  top: 16px;
  left: 22px;
  width: 13px;
  height: 42px;
  border-radius: 7px;
  background: linear-gradient(90deg, #7a2bff, #d98cff 42%, #4b1a9e);
  box-shadow: 0 2px 5px rgba(0, 0, 0, .32);
}

/* ---------- 타격 이펙트 ---------- */
#fx {
  position: absolute;
  inset: 0;
  z-index: 20;
  pointer-events: none;
  overflow: hidden;
}

.fx-pop {
  position: absolute;
  transform: translate(-50%, -50%);
  font-size: 25px;
  font-weight: 800;
  color: #fff8d6;
  text-shadow: 0 2px 0 #8a4b12, 0 0 10px rgba(0, 0, 0, .5);
  white-space: nowrap;
  animation: fxUp .72s cubic-bezier(.2, .8, .4, 1) forwards;
}

.fx-star {
  position: absolute;
  font-size: 21px;
  color: #ffe45c;
  text-shadow: 0 0 8px rgba(255, 150, 0, .9);
  animation: fxStar .52s ease-out forwards;
}

@keyframes fxUp {
  0% { opacity: 0; transform: translate(-50%, -20%) scale(.6); }
  25% { opacity: 1; transform: translate(-50%, -70%) scale(1.12); }
  100% { opacity: 0; transform: translate(-50%, -170%) scale(1); }
}

@keyframes fxStar {
  0% { opacity: 1; transform: translate(-50%, -50%) scale(.5) rotate(0deg); }
  100% { opacity: 0; transform: translate(calc(-50% + var(--dx, 0px)), calc(-50% + var(--dy, -30px))) scale(1.3) rotate(110deg); }
}

/* ---------- 맞은 표정 ---------- */
.mole .bump {
  position: absolute;
  top: 17%;
  left: 33%;
  width: 19%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: radial-gradient(circle at 38% 32%, #ffc2cd, #d9536f 72%);
  box-shadow: 0 0 0 2px rgba(120, 26, 46, .3);
  opacity: 0;
  transform: scale(.2);
  transition: opacity .1s linear, transform .18s cubic-bezier(.3, 1.6, .5, 1);
}

.mole .xeye {
  position: absolute;
  top: 46%;
  width: 9%;
  aspect-ratio: 1;
  opacity: 0;
  transition: opacity .08s linear;
}
.mole .xeye.left { left: 31%; }
.mole .xeye.right { left: 60%; }

.mole .xeye::before,
.mole .xeye::after {
  content: '';
  position: absolute;
  top: 50%;
  left: -8%;
  width: 116%;
  height: 17%;
  border-radius: 2px;
  background: #3b2a1c;
}

/* X자 눈이 뜨면 원래 눈은 숨겨 X만 보이게 한다 */
.hole.hurt .mole .eye,
.hole.hurt .mole .eye-glint { opacity: 0; }

.mole .xeye::before { transform: translateY(-50%) rotate(44deg); }
.mole .xeye::after { transform: translateY(-50%) rotate(-44deg); }

.hole.hurt .mole .bump,
.hole.cracked .mole .bump { opacity: 1; transform: scale(1); }

.hole.hurt .mole .xeye { opacity: 1; }

/* ---------- 두더지 대왕 (가운데 고정) ---------- */
.hole.king { z-index: 6; }

.hole.king .pit {
  width: 84%;
  height: 40%;
  bottom: 10%;
}

.hole.king .clip {
  bottom: 16%;
  border-radius: 0;
  overflow: visible;
}

.hole.king .mole {
  width: 190%;
  transform: translateY(6%);
  transition: transform .46s ease-out;
  filter: drop-shadow(0 6px 12px rgba(120, 0, 255, .55));
}

.hole.king.hit .mole { transform: translateY(6%) scale(.95) rotate(-3deg); }

.hole.king.defeated .mole {
  transform: translateY(22%) rotate(-12deg) scale(.94);
  filter: drop-shadow(0 4px 8px rgba(90, 66, 45, .28));
}
