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

body,
html {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  display: flex;
  justify-content: center;
  align-items: center;
  background-color: #1a1a2e;
  /* iOS 안전 영역 변수 추가 */
  --sat: env(safe-area-inset-top, 0px);
  --sar: env(safe-area-inset-right, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
  /* 모바일 브라우저 UI 고려 */
  position: fixed;
  overscroll-behavior: none;
}

#game-container {
  position: relative;
  width: 100%;
  height: 100%;
  max-width: min(100vw, calc(100vh * (9 / 16)));
  max-height: min(100vh, calc(100vw * (16 / 9)));
  aspect-ratio: 9 / 16;
  background-color: #16213e;
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 0 20px rgba(0, 0, 0, 0.5);
  /* iOS 안전 영역 적용 */
  padding: var(--sat) var(--sar) var(--sab) var(--sal);
  box-sizing: border-box;
}

/* Start Screen */
#start-screen {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  background-color: rgba(0, 0, 0, 0.8);
  z-index: 10;
}

#start-screen h1 {
  font-size: 2.2rem;
  margin-bottom: 2rem;
  color: #e94560;
  text-align: center;
}

#game-title {
  width: 80%;
  max-width: 400px;
  height: auto;
  margin-bottom: 2rem;
  user-select: none;
}

#game-title img {
  width: 100%;
  height: auto;
  object-fit: contain;
}

#start-button,
#restart-button {
  padding: 0.8rem 1.5rem;
  font-size: 1.2rem;
  background-color: #e94560;
  color: #ffffff;
  border: none;
  border-radius: 5px;
  cursor: pointer;
  transition: all 0.3s ease;
}

#start-button:hover,
#restart-button:hover {
  background-color: #ff6b81;
  transform: scale(1.05);
}

/* Battle Area */
#battle-area {
  height: 30%;
  min-height: 30%;
  background-color: #0f3460;
  background-image: url("Dungeondoku_2/images/backgrounds/battle_bg.png");
  background-size: cover;
  background-position: center;
  padding: 0.5rem 0; /* 상하 패딩만 유지하고 좌우 패딩 제거 */
  position: relative;
  display: flex;
  flex-direction: column;
  width: 100%; /* 너비 100% 명시 */
  box-sizing: border-box;
}

#floor-info {
  position: absolute;
  top: 10px;
  left: 10px;
  font-size: 1rem;
  font-weight: bold;
  color: #e94560;
}

#damage-score {
  position: absolute;
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 1rem;
  font-weight: bold;
  color: #e94560;
  background-color: rgba(0, 0, 0, 0.5);
  padding: 5px 10px;
  border-radius: 5px;
}

/* 몬스터 컨테이너 레이아웃 수정 */
#monsters-container {
  display: flex;
  justify-content: space-evenly;
  align-items: flex-end; /* 몬스터를 하단에 정렬 */
  height: 100%;
  width: 100%;
  padding: 0 0.5rem 10px 0.5rem; /* 하단 패딩을 20px에서 30px로 증가 */
}

.monster {
  display: flex;
  flex-direction: column;
  align-items: center;
  position: relative;
  background-color: rgba(0, 0, 0, 0);
  padding: 5px;
  border-radius: 8px;
  margin: 0; /* 마진 제거 */
  flex: 1; /* 균등하게 공간 차지 */
  max-width: 33%; /* 최대 너비 제한 */
  transform: translateY(30px); /* -30px에서 30px로 변경하여 아래로 이동 */
}

.monster-info {
  display: none; /* 몬스터 이름과 HP 정보 숨김 */
}

.monster-image {
  width: 125px;
  height: 125px;
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
  margin-bottom: 10px;
  position: relative;
  z-index: 1;
}

.monster-image img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.monster-image .emoji {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 2rem;
  display: none; /* 기본적으로 이모지는 숨김 */
}

.monster-hp-bar {
  width: 60px;
  height: 8px;
  background-color: #33333300;
  border-radius: 5px;
  overflow: hidden;
}

.monster-hp-fill {
  height: 100%;
  background-color: #e94560;
  transition: width 0.3s ease;
}

/* Puzzle Area */
#puzzle-area {
  height: 70%;
  min-height: 70%;
  background-color: #222222;
  padding: 0.5rem;
  display: flex;
  flex-direction: column;
}

#player-info {
  margin-bottom: 10px;
  padding: 8px 10px;
  background-color: rgba(0, 0, 0, 0.5);
  border-radius: 5px;
  color: white;
  position: relative;
}

.player-info-container {
  display: flex;
  align-items: center;
  width: 100%;
}

.player-stats-summary {
  display: flex;
  flex-direction: column;
}

#hp-container,
#level-container {
  font-weight: bold;
}

#grid-container {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  grid-template-rows: repeat(9, 1fr);
  gap: 1px;
  aspect-ratio: 1 / 1;
  width: 100%;
  max-width: 100%;
  margin: 0 auto 0.5rem auto;
}

.grid-cell {
  background-color: #1d1d1d;
  border-radius: 2px;
  position: relative;
  transition: background-color 0.2s ease;
  width: 100%;
  aspect-ratio: 1 / 1;
  border: 1px solid rgba(255, 255, 255, 0.137);
}

/* 3x3 블록별 체스판 패턴 */
.grid-cell.block-even {
  background-color: #242222;
  opacity: 0.9;
}

.grid-cell.block-odd {
  background-color: #1d1c1c;
  opacity: 0.9;
}

/* 3x3 블록 경계선 강조 */
/* 세로 경계선: 3번째, 6번째 열 */
.grid-cell:nth-child(9n+3),
.grid-cell:nth-child(9n+6) {
  border-right: 2px solid rgba(255, 255, 255, 0.137);
}

/* 가로 경계선: 3번째, 6번째 행 */
.grid-cell:nth-child(n+19):nth-child(-n+27),
.grid-cell:nth-child(n+46):nth-child(-n+54) {
  border-bottom: 2px solid rgba(255, 255, 255, 0.137);
}

/* 채워진 셀 스타일 */
.grid-cell.filled {
  background-color: #45e9ce !important;
  opacity: 1 !important;
}

.grid-cell.highlight {
  background-color: rgba(69, 233, 233, 0.4) !important;
  box-shadow: inset 0 0 3px rgba(233, 69, 96, 0.8);
}

/* 잘못된 배치 위치 */
.grid-cell.invalid {
  background-color: rgba(255, 17, 0, 0.829) !important;
  box-shadow: inset 0 0 3px rgba(244, 67, 54, 0.8);
}

/* 완성 가능한 줄/블록 하이라이트 스타일 추가 */
.grid-cell.would-complete {
  background-color: rgba(76, 175, 80, 0.4) !important;
  box-shadow: inset 0 0 5px rgba(255, 255, 255, 0.3);
}

/* 하이라이트와 완성 가능 표시가 동시에 적용될 때의 스타일 */
.grid-cell.highlight.would-complete {
  background-color: rgba(76, 175, 80, 0.7) !important;
  box-shadow: inset 0 0 8px rgba(255, 255, 255, 0.5);
  animation: completePulse 1.5s infinite;
}

@keyframes completePulse {
  0% {
    box-shadow: 0 0 0 0 rgba(76, 175, 80, 0.6);
  }
  70% {
    box-shadow: 0 0 0 5px rgba(76, 175, 80, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(76, 175, 80, 0);
  }
}

/* 원소 구슬 관련 CSS 스타일 제거 */
/*
.orb {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 70%;
  height: 70%;
  border-radius: 50%;
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 0.8rem;
  box-shadow: 0 0 5px rgba(255, 255, 255, 0.5);
  transition: all 0.2s ease;
}

.orb:hover {
  transform: translate(-50%, -50%) scale(1.1);
  box-shadow: 0 0 10px rgba(255, 255, 255, 0.8);
}

.orb.fire {
  background-color: #ff5722;
  box-shadow: 0 0 8px rgba(255, 87, 34, 0.8);
}
.orb.water {
  background-color: #2196f3;
  box-shadow: 0 0 8px rgba(33, 150, 243, 0.8);
}
.orb.wood {
  background-color: #4caf50;
  box-shadow: 0 0 8px rgba(76, 175, 80, 0.8);
}
.orb.lightning {
  background-color: #ffeb3b;
  box-shadow: 0 0 8px rgba(255, 235, 59, 0.8);
}
.orb.poison {
  background-color: #9c27b0;
  box-shadow: 0 0 8px rgba(156, 39, 176, 0.8);
}
.orb.darkness {
  background-color: #424242;
  box-shadow: 0 0 8px rgba(66, 66, 66, 0.8);
}

@keyframes orbCollect {
  0% {
    transform: translate(-50%, -50%) scale(1);
    opacity: 1;
  }
  50% {
    transform: translate(-50%, -50%) scale(1.5);
    opacity: 0.8;
  }
  100% {
    transform: translate(-50%, -50%) scale(0);
    opacity: 0;
  }
}

.orb-collecting {
  animation: orbCollect 0.5s forwards;
  pointer-events: none;
}

.element-effect {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 1.2rem;
  font-weight: bold;
  color: white;
  text-shadow: 0 0 5px rgba(0, 0, 0, 0.8);
  pointer-events: none;
  z-index: 100;
  animation: elementEffect 1.5s forwards;
}

@keyframes elementEffect {
  0% {
    opacity: 0;
    transform: scale(0.5);
  }
  20% {
    opacity: 1;
    transform: scale(1.2);
  }
  80% {
    opacity: 1;
    transform: scale(1);
  }
  100% {
    opacity: 0;
    transform: scale(1.5);
  }
}

.element-effect.fire {
  background: radial-gradient(circle, rgba(255, 87, 34, 0.6) 0%, rgba(255, 87, 34, 0) 70%);
}

.element-effect.water {
  background: radial-gradient(circle, rgba(33, 150, 243, 0.6) 0%, rgba(33, 150, 243, 0) 70%);
}

.element-effect.wood {
  background: radial-gradient(circle, rgba(76, 175, 80, 0.6) 0%, rgba(76, 175, 80, 0) 70%);
}

.element-effect.lightning {
  background: radial-gradient(circle, rgba(255, 235, 59, 0.6) 0%, rgba(255, 235, 59, 0) 70%);
}

.element-effect.poison {
  background: radial-gradient(circle, rgba(156, 39, 176, 0.6) 0%, rgba(156, 39, 176, 0) 70%);
}

.element-effect.darkness {
  background: radial-gradient(circle, rgba(66, 66, 66, 0.6) 0%, rgba(66, 66, 66, 0) 70%);
}

.status-effects {
  display: flex;
  justify-content: center;
  margin-top: 5px;
  gap: 5px;
}

.status-icon {
  font-size: 1.2rem;
  filter: drop-shadow(0 0 3px rgba(0, 0, 0, 0.5));
  animation: statusPulse 2s infinite;
}

@keyframes statusPulse {
  0%,
  100% {
    transform: scale(1);
    opacity: 1;
  }
  50% {
    transform: scale(1.2);
    opacity: 0.8;
  }
}

.element-text {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background-color: rgba(0, 0, 0, 0.7);
  color: white;
  padding: 10px 20px;
  border-radius: 10px;
  font-size: 1.2rem;
  font-weight: bold;
  z-index: 1000;
  pointer-events: none;
  animation: fadeInOut 1.5s forwards;
  text-align: center;
}

@keyframes fadeInOut {
  0% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.8);
  }
  20% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
  }
  80% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(1.2);
  }
}
*/

#pieces-container {
  display: flex;
  justify-content: space-around;
  align-items: center;
  margin-top: auto;
  padding: 0.5rem;
  height: 60px; /* 70px에서 90px로 증가 */
}

.piece-container {
  display: flex;
  justify-content: center;
  align-items: center;
  cursor: pointer;
  user-select: none;
  touch-action: none;
  background-color: rgba(255, 255, 255, 0.1);
  border-radius: 5px;
  padding: 8px; /* 패딩 추가 */
  width: 30%; /* 너비 지정 */
  height: 70px; /* 높이 지정 */
}

.piece-container.selected {
  box-shadow: 0 0 10px #45e976;
  background-color: rgba(69, 233, 170, 0.308);
  border-radius: 5px;
}

/* 놓을 수 없는 퍼즐 조각 스타일 */
.piece-container.disabled {
  opacity: 0.4;
  filter: grayscale(50%);
  cursor: not-allowed;
}

.piece-container.disabled:hover {
  opacity: 0.4;
}

.piece-preview {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  grid-template-rows: repeat(5, 1fr);
  gap: 1px;
  aspect-ratio: 1 / 1;
  width: 65px; /* 50px에서 65px로 증가 */
  height: 65px; /* 높이 지정 */
}

.piece-cell {
  background-color: transparent;
}

.piece-cell.filled {
  background-color: #45e9ce;
  border-radius: 2px;
}

/* 드래그 중인 조각 스타일 */
.dragging-piece {
  position: absolute !important;
  pointer-events: none !important;
  z-index: 1000 !important;
  opacity: 0.85 !important;
  transform-origin: center center !important;
  transition: transform 0.05s ease-out, left 0.05s linear, top 0.05s linear;
  will-change: transform, left, top;
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
  /* 추가적인 시각적 효과 */
  filter: brightness(1.1);
}

/* Game Over Screen */
#game-over-screen {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  background-color: rgba(0, 0, 0, 0.9);
  z-index: 10;
}

#game-over-screen h2 {
  font-size: 2rem;
  margin-bottom: 1rem;
  color: #e94560;
}

#game-over-reason {
  font-size: 1.2rem;
  color: #ffffff;
  margin-bottom: 1.5rem;
  text-align: center;
  padding: 0.5rem 1rem;
  background-color: rgba(233, 69, 96, 0.2);
  border-radius: 5px;
}

#game-over-screen p {
  font-size: 1.2rem;
  margin-bottom: 2rem;
}

/* Helper classes */
.hidden {
  display: none !important;
}

/* Animations */
@keyframes shake {
  0%,
  100% {
    transform: translateX(0);
  }
  25% {
    transform: translateX(-5px);
  }
  75% {
    transform: translateX(5px);
  }
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

.shake {
  animation: shake 0.5s;
}

.damage-text {
  position: absolute;
  color: #ff0000;
  font-weight: bold;
  font-size: 1.2rem;
  animation: damageFloat 1s ease-out forwards;
  z-index: 5;
}

@keyframes damageFloat {
  0% {
    opacity: 1;
    transform: translateY(0);
  }
  100% {
    opacity: 0;
    transform: translateY(-30px);
  }
}

.attack-flash {
  animation: attackFlash 0.3s;
}

@keyframes attackFlash {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.5;
  }
}

/* 몬스터 피격 애니메이션 */
@keyframes monsterHit {
  0%,
  100% {
    transform: translateX(0);
  }
  25% {
    transform: translateX(-5px) rotate(-5deg);
  }
  75% {
    transform: translateX(5px) rotate(5deg);
  }
}

.monster-hit {
  animation: monsterHit 0.3s ease-in-out !important;
  will-change: transform;
}

/* 데미지 텍스트 스타일 */
.monster-damage {
  position: absolute;
  top: -30px;
  left: 50%;
  transform: translateX(-50%);
  color: #ff4444;
  font-size: 1.2rem;
  font-weight: bold;
  text-shadow: 2px 2px 2px rgba(0, 0, 0, 0.5);
  animation: damageFloat 1s ease-out forwards;
  pointer-events: none;
  z-index: 10;
  white-space: nowrap;
  user-select: none;
  will-change: transform, opacity;
}

@keyframes damageFloat {
  0% {
    opacity: 1;
    transform: translate(-50%, 0);
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -30px);
  }
}

/* 플레이어 피격 효과 */
@keyframes screenShake {
  0%,
  100% {
    transform: translate(0, 0);
  }
  25% {
    transform: translate(-5px, -5px);
  }
  50% {
    transform: translate(5px, 5px);
  }
  75% {
    transform: translate(-5px, 5px);
  }
}

@keyframes damageFlash {
  0%,
  100% {
    background-color: transparent;
  }
  50% {
    background-color: rgba(255, 0, 0, 0.2);
  }
}

.player-damage {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 1000;
  animation: damageFlash 0.3s ease-out;
}

.screen-shake {
  animation: screenShake 0.3s ease-in-out;
}

/* Responsive design */

/* iOS 기기 최적화 */
@supports (-webkit-touch-callout: none) {
  #game-container {
    /* 노치 및 홈 인디케이터 영역 고려 */
    height: calc(100% - var(--sat) - var(--sab));
    /* 아이패드에서 너무 넓어지지 않도록 제한 */
    max-width: min(100vw, calc((100vh - var(--sat) - var(--sab)) * (9 / 16)));
  }
}

/* 아이패드 최적화 */
@media only screen and (min-device-width: 768px) and (max-device-width: 1024px) {
  #game-container {
    max-width: min(90vw, calc(90vh * (9 / 16)));
    max-height: 90vh;
    border-radius: 16px;
  }
}

/* 아이폰 최적화 */
@media only screen and (max-device-width: 767px) {
  #game-container {
    max-width: 100vw;
    max-height: 100vh;
    border-radius: 0;
  }

  #battle-area {
    height: 30%;
    padding-top: calc(0.5rem + var(--sat));
  }

  #puzzle-area {
    height: 70%;
    padding-bottom: calc(0.5rem + var(--sab));
  }
}

/* 가로 모드 최적화 */
@media (orientation: landscape) and (max-height: 500px) {
  #game-container {
    max-width: calc(100vh * (9 / 16));
    height: 100vh;
  }

  #battle-area {
    height: 25%;
  }

  #puzzle-area {
    height: 75%;
  }

  .monster-image {
    width: 60px;
    height: 60px;
  }
}

/* 짧은 화면 대응 */
@media (max-height: 700px) {
  #battle-area {
    height: 25%;
    min-height: 25%;
  }

  #puzzle-area {
    height: 75%;
    min-height: 75%;
  }

  .monster-image {
    width: 50px;
    height: 50px;
  }

  .monster-hp-bar {
    width: 40px;
    height: 6px;
  }
}

/* 몬스터 사망 시 블링크 효과 및 숨김 처리 */
.monster.dead {
  animation: monsterDeath 1.2s forwards;
}

@keyframes monsterDeath {
  0% {
    opacity: 1;
    filter: brightness(1);
  }
  10% {
    opacity: 1;
    filter: brightness(2) saturate(2);
  }
  20% {
    opacity: 0.8;
    filter: brightness(1);
  }
  30% {
    opacity: 1;
    filter: brightness(2) saturate(2);
  }
  40% {
    opacity: 0.8;
    filter: brightness(1);
  }
  50% {
    opacity: 1;
    filter: brightness(2) saturate(2);
  }
  60% {
    opacity: 0.8;
    filter: brightness(1);
  }
  70% {
    opacity: 1;
    filter: brightness(2) saturate(2);
  }
  80% {
    opacity: 0.6;
    filter: brightness(1.5) saturate(1.5);
  }
  100% {
    opacity: 0;
    filter: brightness(3) saturate(0);
    transform: scale(1.2);
  }
}

/* 설정 버튼 스타일 */
.settings-button {
  position: absolute;
  top: 10px;
  right: 10px;
  background-color: rgba(0, 0, 0, 0.5);
  color: white;
  border: none;
  border-radius: 50%;
  width: 32px;
  height: 32px;
  font-size: 1.2rem;
  cursor: pointer;
  z-index: 10;
  display: flex;
  justify-content: center;
  align-items: center;
  transition: background-color 0.3s;
}

.settings-button:hover {
  background-color: rgba(0, 0, 0, 0.7);
}

/* 모바일 터치 최적화 스타일 */
@media (max-width: 768px) {
  .piece-container {
    touch-action: none;
    -webkit-tap-highlight-color: transparent;
    min-height: 70px;
    padding: 6px;
    cursor: grab;
    height: 70px; /* 모바일에서는 약간 작게 */
  }

  .piece-preview {
    width: 55px; /* 모바일에서는 약간 작게 */
    height: 55px;
  }

  .grid-cell {
    touch-action: none;
    -webkit-tap-highlight-color: transparent;
  }

  .dragging-piece {
    z-index: 2000 !important;
    transform-origin: center center;
    filter: drop-shadow(0 5px 15px rgba(0, 0, 0, 0.4));
  }

  /* 하이라이트 효과 강화 */
  .grid-cell.highlight {
    background-color: rgba(76, 175, 80, 0.7);
    box-shadow: inset 0 0 5px rgba(255, 255, 255, 0.5);
    animation: pulse 1.5s infinite;
  }

  .grid-cell.invalid {
    background-color: rgba(244, 67, 54, 0.7);
    box-shadow: inset 0 0 5px rgba(255, 255, 255, 0.5);
  }

  /* 게임 컨트롤 버튼 크기 증가 */
  .settings-button {
    width: 40px;
    height: 40px;
    font-size: 1.5rem;
  }

  /* 모바일에서 스크롤 방지 */
  body,
  html {
    overscroll-behavior: none;
    overflow: hidden;
    position: fixed;
    width: 100%;
    height: 100%;
  }
}

/* 하이라이트 펄스 애니메이션 */
@keyframes pulse {
  0% {
    box-shadow: 0 0 0 0 rgba(76, 175, 80, 0.4);
  }
  70% {
    box-shadow: 0 0 0 5px rgba(76, 175, 80, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(76, 175, 80, 0);
  }
}

/* 이벤트 로그 스타일 */
#event-log-container {
  position: absolute;
  bottom: 10px;
  left: 10px;
  width: 60%;
  max-width: 300px;
  display: flex;
  flex-direction: column;
  z-index: 10;
  pointer-events: none;
}

.event-log-item {
  background-color: rgba(0, 0, 0, 0.6);
  color: white;
  padding: 5px 8px;
  margin-bottom: 5px;
  border-radius: 5px;
  font-size: 0.8rem;
  animation: fadeInOut 4s forwards;
  text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.8);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

@keyframes fadeInOut {
  0% {
    opacity: 0;
    transform: translateY(10px);
  }
  10% {
    opacity: 1;
    transform: translateY(0);
  }
  80% {
    opacity: 1;
  }
  100% {
    opacity: 0;
  }
}

@media (max-width: 500px) {
  #event-log-container {
    width: 70%;
    max-width: 250px;
    bottom: 5px;
    left: 5px;
  }

  .event-log-item {
    font-size: 0.7rem;
    padding: 3px 6px;
    margin-bottom: 3px;
  }
}

/* 미믹 몬스터 스타일 */
.monster.mimic .monster-image {
  animation: mimicPulse 2s infinite;
}

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

/* 장비 획득 팝업 스타일 */
#equipment-popup {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.8);
  z-index: 100;
  display: flex;
  justify-content: center;
  align-items: center;
}

.equipment-popup-content {
  background-color: #16213e;
  border: 2px solid #e94560;
  border-radius: 10px;
  width: 90%;
  max-width: 400px;
  padding: 20px;
  color: white;
  text-align: center;
}

.equipment-popup-content h2 {
  color: #e94560;
  margin-top: 0;
  margin-bottom: 15px;
}

.equipment-image {
  width: 80px;
  height: 80px;
  background-color: rgba(255, 255, 255, 0.1);
  border-radius: 50%;
  margin: 0 auto 15px;
  display: flex;
  justify-content: center;
  align-items: center;
}

.equipment-emoji {
  font-size: 2.5rem;
}

.equipment-info {
  margin-bottom: 20px;
}

.equipment-name {
  font-size: 1.2rem;
  font-weight: bold;
  margin-bottom: 5px;
}

.equipment-description {
  font-size: 0.9rem;
  color: #ccc;
  margin-bottom: 10px;
}

.equipment-stats {
  font-size: 0.9rem;
  color: #4caf50;
}

.equipment-comparison {
  display: flex;
  justify-content: space-between;
  margin-bottom: 20px;
  padding: 10px;
  background-color: rgba(0, 0, 0, 0.2);
  border-radius: 5px;
}

.current-equipment,
.new-equipment {
  width: 48%;
}

.current-equipment h3,
.new-equipment h3 {
  font-size: 0.9rem;
  margin-top: 0;
  margin-bottom: 5px;
  color: #aaa;
}

.current-equipment-name,
.new-equipment-name {
  font-weight: bold;
  margin-bottom: 5px;
}

.current-equipment-stats,
.new-equipment-stats {
  font-size: 0.8rem;
  color: #aaa;
}

.equipment-buttons {
  display: flex;
  justify-content: space-between;
}

.equip-button,
.discard-button {
  padding: 10px 20px;
  border: none;
  border-radius: 5px;
  font-size: 1rem;
  cursor: pointer;
  width: 48%;
}

.equip-button {
  background-color: #4caf50;
  color: white;
}

.discard-button {
  background-color: #f44336;
  color: white;
}

/* 희귀도별 색상 적용 */
.rarity-common {
  color: #aaaaaa;
}

.rarity-uncommon {
  color: #1a9c1a;
}

.rarity-rare {
  color: #0070dd;
}

.rarity-epic {
  color: #a335ee;
}

.rarity-legendary {
  color: #ff8000;
}

/* 모바일 브라우저 최적화 */
@media screen and (max-height: 800px) {
  #battle-area {
    height: 25% !important;
    min-height: 25% !important;
  }

  #puzzle-area {
    height: 75% !important;
    min-height: 75% !important;
  }

  .monster-image {
    width: 80px;
    height: 80px;
  }

  #grid-container {
    margin-bottom: 0.3rem;
  }

  .piece-preview {
    width: 45px;
  }
}

/* 매우 작은 화면 최적화 */
@media screen and (max-height: 600px) {
  #battle-area {
    height: 20% !important;
    min-height: 20% !important;
  }

  #puzzle-area {
    height: 80% !important;
    min-height: 80% !important;
  }

  .monster-image {
    width: 60px;
    height: 60px;
  }

  #player-info {
    margin-bottom: 5px;
    padding: 3px 8px;
  }

  #grid-container {
    margin-bottom: 0.2rem;
  }

  .piece-preview {
    width: 40px;
  }
}

/* 모바일 브라우저 주소창 고려 */
@supports (-webkit-touch-callout: none) {
  #game-container {
    height: -webkit-fill-available;
    max-height: -webkit-fill-available;
  }

  #pieces-container {
    padding-bottom: calc(10px + env(safe-area-inset-bottom, 10px));
  }
}

/* 퍼즐 클리어 연출 효과 */
@keyframes lineCompleteWave {
  0% {
    transform: scale(1);
    background-color: rgba(255, 215, 0, 0.4);
    box-shadow: 0 0 10px rgba(255, 215, 0, 0.3);
  }
  50% {
    transform: scale(1.1);
    background-color: rgba(255, 215, 0, 0.8);
    box-shadow: 0 0 20px rgba(255, 215, 0, 0.6);
  }
  100% {
    transform: scale(1);
    background-color: rgba(255, 215, 0, 0.2);
    box-shadow: 0 0 5px rgba(255, 215, 0, 0.2);
  }
}

@keyframes lineVanish {
  0% {
    opacity: 1;
    transform: scale(1);
  }
  50% {
    opacity: 0.5;
    transform: scale(1.05);
  }
  100% {
    opacity: 0;
    transform: scale(0.9);
  }
}

@keyframes comboText {
  0% {
    opacity: 0;
    transform: translateY(20px) scale(0.5);
  }
  20% {
    opacity: 1;
    transform: translateY(0px) scale(1.2);
  }
  80% {
    opacity: 1;
    transform: translateY(-10px) scale(1);
  }
  100% {
    opacity: 0;
    transform: translateY(-30px) scale(0.8);
  }
}

.line-complete-highlight {
  animation: lineCompleteWave 0.6s ease-in-out;
  z-index: 10;
}

.line-vanish {
  animation: lineVanish 0.4s ease-out forwards;
}

.combo-text {
  position: absolute;
  font-size: 1.5rem;
  font-weight: bold;
  color: #ffd700;
  text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.8);
  pointer-events: none;
  animation: comboText 2s ease-out forwards;
  z-index: 20;
}

.multi-line-clear {
  position: relative;
}

.grid-cell.line-highlight-row {
  background-color: rgba(255, 215, 0, 0.6) !important;
  box-shadow: inset 0 0 10px rgba(255, 215, 0, 0.4);
  animation: lineCompleteWave 0.8s ease-in-out;
}

.grid-cell.line-highlight-col {
  background-color: rgba(0, 255, 255, 0.6) !important;
  box-shadow: inset 0 0 10px rgba(0, 255, 255, 0.4);
  animation: lineCompleteWave 0.8s ease-in-out;
}

.grid-cell.line-highlight-block {
  background-color: rgba(255, 105, 180, 0.6) !important;
  box-shadow: inset 0 0 10px rgba(255, 105, 180, 0.4);
  animation: lineCompleteWave 0.8s ease-in-out;
}

.grid-complete-pulse {
  animation: gridPulse 0.5s ease-in-out 2;
}

@keyframes gridPulse {
  0% {
    box-shadow: 0 0 0 rgba(255, 215, 0, 0.7);
  }
  50% {
    box-shadow: 0 0 20px rgba(255, 215, 0, 0.9);
  }
  100% {
    box-shadow: 0 0 0 rgba(255, 215, 0, 0.7);
  }
}

.line-complete-highlight {
  animation: lineCompleteWave 0.6s ease-in-out;
  z-index: 10;
}
