/* ===== 기본 리셋 & 폰트 ===== */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-user-select: none;
  user-select: none;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: 'Jua', 'Gaegu', 'Comic Sans MS', sans-serif;
  background: linear-gradient(180deg, #87ceeb 0%, #ffd1dc 60%, #fff5b8 100%);
  cursor: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='32' height='32' viewBox='0 0 32 32'><text x='0' y='26' font-size='28'>👆</text></svg>") 6 6, auto;
  /* 모바일: 더블탭 확대 방지, 길게 누르기 콜아웃 방지 */
  touch-action: manipulation;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  outline: none;
}

/* ===== 화면 공통 ===== */
.screen {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 1;
}

.screen.active {
  display: flex;
}

/* ===== 메인 카드 ===== */
.home-card,
.select-card {
  background: rgba(255, 255, 255, 0.92);
  border-radius: 32px;
  padding: 40px 50px;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.18);
  border: 6px solid #ffd166;
  max-width: 720px;
  width: 100%;
  max-height: 92vh;
  overflow-y: auto;
}

.title {
  font-size: 56px;
  color: #ff6b9d;
  text-shadow: 3px 3px 0 #fff, 6px 6px 0 rgba(255, 107, 157, 0.3);
  line-height: 1.2;
  margin-bottom: 12px;
}

.title-sm {
  font-size: 38px;
  color: #ff6b9d;
  text-shadow: 2px 2px 0 #fff;
  margin-bottom: 22px;
}

.subtitle {
  font-size: 22px;
  color: #555;
  margin-bottom: 26px;
}

.hero-emoji {
  font-size: 70px;
  margin: 14px 0 28px;
  display: flex;
  justify-content: center;
  gap: 12px;
}

.hero-emoji span {
  display: inline-block;
}

.hidden {
  display: none !important;
}

.mode-panel {
  background: #fff8d8;
  border: 4px solid #ffd166;
  border-radius: 24px;
  margin: 8px auto 18px;
  max-width: 520px;
  padding: 16px;
}

.mode-title {
  color: #6a4c00;
  font-size: 22px;
  margin-bottom: 10px;
}

.mode-buttons {
  display: flex;
  justify-content: center;
  gap: 10px;
}

.mode-btn {
  background: #fff;
  border: 3px solid #ffd166;
  border-radius: 999px;
  color: #555;
  font-size: 22px;
  min-width: 110px;
  padding: 10px 20px;
  transition: transform 0.12s ease, background 0.12s ease, color 0.12s ease;
}

.mode-btn.active {
  background: linear-gradient(180deg, #ff8fb3, #ff5f8d);
  border-color: #ff5f8d;
  color: white;
  box-shadow: 0 4px 0 rgba(0,0,0,0.15);
}

.mode-btn:hover {
  transform: translateY(-2px);
}

.text-settings {
  margin-top: 14px;
  text-align: left;
}

.text-settings label {
  color: #444;
  display: block;
  font-size: 20px;
  margin-bottom: 8px;
  text-align: center;
}

.text-settings textarea {
  border: 3px solid #ffd166;
  border-radius: 18px;
  color: #333;
  font-family: inherit;
  font-size: 22px;
  line-height: 1.35;
  outline: none;
  padding: 12px 14px;
  resize: vertical;
  width: 100%;
  /* 입력창은 길게 눌러서 복사/붙여넣기, 텍스트 선택을 허용해야 함 */
  -webkit-touch-callout: default;
  -webkit-user-select: text;
  user-select: text;
}

.text-settings textarea:focus {
  border-color: #ff6b9d;
  box-shadow: 0 0 0 4px rgba(255, 107, 157, 0.18);
}

.input-help,
.save-message {
  color: #666;
  font-size: 16px;
  margin-top: 6px;
  text-align: center;
}

.save-message {
  color: #ff6b9d;
  min-height: 22px;
}

.small-action-btn {
  background: linear-gradient(180deg, #8ed7ff, #4cb8f0);
  border-radius: 999px;
  box-shadow: 0 4px 0 rgba(0,0,0,0.15);
  color: white;
  display: block;
  font-size: 20px;
  margin: 10px auto 0;
  padding: 10px 24px;
}

.bounce {
  animation: bounce 1.4s ease-in-out infinite;
}

.delay1 { animation-delay: 0.15s; }
.delay2 { animation-delay: 0.30s; }
.delay3 { animation-delay: 0.45s; }

@keyframes bounce {
  0%, 100% { transform: translateY(0); }
  50%      { transform: translateY(-22px); }
}

/* ===== 큰 버튼 ===== */
.big-btn {
  display: inline-block;
  font-size: 28px;
  padding: 18px 40px;
  border-radius: 999px;
  margin: 8px;
  transition: transform 0.12s ease, box-shadow 0.12s ease, filter 0.12s ease;
  box-shadow: 0 6px 0 rgba(0,0,0,0.18), 0 8px 16px rgba(0,0,0,0.12);
}

.big-btn:hover {
  transform: translateY(-3px);
  filter: brightness(1.05);
}

.big-btn:active {
  transform: translateY(2px);
  box-shadow: 0 2px 0 rgba(0,0,0,0.18), 0 4px 8px rgba(0,0,0,0.12);
}

.big-btn.primary {
  background: linear-gradient(180deg, #ff8fb3, #ff5f8d);
  color: white;
}

.big-btn.secondary {
  background: linear-gradient(180deg, #8ed7ff, #4cb8f0);
  color: white;
}

.big-btn.ghost {
  background: linear-gradient(180deg, #f0f0f0, #d4d4d4);
  color: #444;
}

.back-btn {
  background: linear-gradient(180deg, #fff1a8, #ffd166);
  color: #6a4c00;
  font-size: 22px;
  padding: 10px 22px;
  border-radius: 999px;
  box-shadow: 0 4px 0 rgba(0,0,0,0.15);
  transition: transform 0.1s ease;
}

.back-btn.small {
  font-size: 18px;
  padding: 8px 16px;
}

.back-btn:hover { transform: translateY(-2px); }
.back-btn:active { transform: translateY(1px); }

/* ===== 뱃지 ===== */
.badges {
  margin-top: 18px;
  font-size: 22px;
  color: #555;
}

/* ===== 스테이지 선택 ===== */
.stage-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, 170px);
  gap: 16px;
  margin-top: 20px;
  justify-content: center;
}

.stage-list > .level-header {
  grid-column: 1 / -1;
  font-size: 24px;
  margin-top: 10px;
  font-weight: bold;
  text-align: center;
}

.stage-card {
  background: linear-gradient(180deg, #fff, #ffe9b3);
  border: 4px solid #ffd166;
  border-radius: 22px;
  padding: 18px 10px;
  text-align: center;
  cursor: pointer;
  transition: transform 0.12s ease;
  box-shadow: 0 4px 0 rgba(0,0,0,0.12);
}

.stage-card:hover {
  transform: translateY(-3px) scale(1.03);
}

.stage-card .stage-num {
  font-size: 26px;
  color: #ff6b9d;
  font-weight: bold;
}

.stage-card .stage-name {
  font-size: 18px;
  color: #444;
  margin: 6px 0;
}

.stage-card .stage-stars {
  font-size: 22px;
}

.stage-card.locked {
  background: #ddd;
  border-color: #aaa;
  cursor: not-allowed;
  opacity: 0.7;
}

.stage-card.locked .stage-num,
.stage-card.locked .stage-name {
  color: #888;
}

/* ===== HUD ===== */
.hud {
  position: fixed;
  top: 0; left: 0; right: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  gap: 14px;
  background: rgba(255,255,255,0.85);
  backdrop-filter: blur(6px);
  border-bottom: 4px solid #ffd166;
  z-index: 5;
}

.hud-left, .hud-right {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 0 0 auto;
}

.hud-center {
  flex: 1;
  max-width: 600px;
}

.stage-label {
  font-size: 24px;
  color: #ff6b9d;
  font-weight: bold;
}

.score-bar {
  position: relative;
  width: 100%;
  height: 36px;
  background: #ffe9e9;
  border-radius: 999px;
  border: 3px solid #ff6b9d;
  overflow: hidden;
}

.score-bar-fill {
  position: absolute;
  inset: 0;
  width: 0%;
  background: linear-gradient(90deg, #ffd166, #ff6b9d);
  transition: width 0.3s ease;
}

.score-text {
  position: relative;
  z-index: 2;
  text-align: center;
  font-size: 22px;
  color: #fff;
  text-shadow: 1px 1px 0 #ff6b9d, -1px -1px 0 #ff6b9d, 1px -1px 0 #ff6b9d, -1px 1px 0 #ff6b9d;
  line-height: 30px;
}

.lives {
  font-size: 26px;
  letter-spacing: 1px;
  white-space: nowrap;
}

/* ===== 게임 영역 ===== */
.game-area {
  position: fixed;
  /* HUD 높이는 game.js의 syncHudHeight()가 측정해서 주입한다.
     초기/측정 실패 시 64px(데스크톱 기본 HUD 높이)을 사용한다. */
  top: var(--hud-height, 64px);
  left: 0;
  right: 0;
  bottom: 0;
  overflow: hidden;
  /* 손가락 터치 시 브라우저의 더블탭 줌, 스크롤 등을 차단 */
  touch-action: manipulation;
}

/* ===== 타겟 ===== */
.target {
  position: absolute;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 2;
  will-change: transform;
  transition: transform 0.1s ease;
  filter: drop-shadow(2px 4px 4px rgba(0,0,0,0.2));
}

.target.text-target {
  background: radial-gradient(circle at 30% 25%, #fff 0%, #fff5c8 45%, #ffd166 100%);
  border: 5px solid #ff8fb3;
  border-radius: 28%;
  color: #333;
  font-weight: bold;
  line-height: 1.05;
  overflow: hidden;
  padding: 6px;
  text-align: center;
  text-shadow: 2px 2px 0 rgba(255,255,255,0.9);
  word-break: break-all;
  overflow-wrap: anywhere;
}

.target.text-target.bomb-target {
  background: radial-gradient(circle at 30% 25%, #fff 0%, #ffd6d6 45%, #ff8fa3 100%);
  border-color: #ff3b3b;
  color: #8b0000;
}

.target:hover {
  transform: scale(1.1) rotate(5deg);
}

.target.popping {
  animation: pop 0.30s ease-out forwards;
  pointer-events: none;
}

@keyframes pop {
  0%   { transform: scale(1); opacity: 1; }
  60%  { transform: scale(1.6) rotate(15deg); opacity: 0.8; }
  100% { transform: scale(0) rotate(40deg); opacity: 0; }
}

/* 시간 초과(놓침) - 슬그머니 사라짐 */
.target.fading {
  animation: fadeOut 0.25s ease-in forwards;
  pointer-events: none;
}

@keyframes fadeOut {
  0%   { transform: scale(1); opacity: 1; filter: grayscale(0%); }
  100% { transform: scale(0.6); opacity: 0; filter: grayscale(100%); }
}

.target.spawning {
  animation: spawnIn 0.3s ease-out;
}

@keyframes spawnIn {
  0%   { transform: scale(0); opacity: 0; }
  60%  { transform: scale(1.15); opacity: 1; }
  100% { transform: scale(1); }
}

/* 점수 팝업 */
.score-pop {
  position: absolute;
  font-size: 32px;
  color: #ff6b9d;
  font-weight: bold;
  text-shadow: 2px 2px 0 #fff;
  pointer-events: none;
  animation: scorePop 0.9s ease-out forwards;
  z-index: 6;
}

.score-pop.minus {
  color: #ff3b3b;
}

@keyframes scorePop {
  0%   { transform: translateY(0) scale(0.6); opacity: 0; }
  20%  { transform: translateY(-10px) scale(1.2); opacity: 1; }
  100% { transform: translateY(-80px) scale(1.0); opacity: 0; }
}

/* ===== 힌트 ===== */
.hint {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(255,255,255,0.9);
  border: 3px solid #ffd166;
  border-radius: 999px;
  padding: 10px 24px;
  font-size: 20px;
  color: #555;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  z-index: 4;
  max-width: 90%;
  text-align: center;
  pointer-events: none;
  transition: opacity 0.5s ease;
}

.hint.fade {
  opacity: 0;
}

/* ===== 모달 ===== */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
  animation: fadeIn 0.3s ease;
}

.modal.hidden {
  display: none;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.modal-card {
  background: white;
  border-radius: 28px;
  padding: 36px 40px;
  text-align: center;
  max-width: 500px;
  width: 100%;
  border: 6px solid #ffd166;
  animation: popIn 0.4s ease-out;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}

.modal-card.fail {
  border-color: #ff8fa3;
}

@keyframes popIn {
  0%   { transform: scale(0.5); opacity: 0; }
  70%  { transform: scale(1.05); }
  100% { transform: scale(1); opacity: 1; }
}

.modal-card h2 {
  font-size: 42px;
  color: #ff6b9d;
  margin-bottom: 8px;
}

.modal-card p {
  font-size: 22px;
  color: #444;
  margin-bottom: 18px;
}

.big-emoji {
  font-size: 90px;
  display: inline-block;
  margin-bottom: 8px;
}

.shake {
  animation: shake 0.6s ease-in-out infinite;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25%      { transform: translateX(-8px) rotate(-5deg); }
  75%      { transform: translateX(8px) rotate(5deg); }
}

.stars {
  font-size: 44px;
  margin: 12px 0;
  letter-spacing: 4px;
}

.modal-buttons {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin-top: 14px;
}

.modal-buttons .big-btn {
  font-size: 22px;
  padding: 14px 28px;
}

/* ===== 클릭 파티클 ===== */
.particle {
  position: absolute;
  font-size: 24px;
  pointer-events: none;
  animation: particleFly 0.7s ease-out forwards;
  z-index: 5;
}

@keyframes particleFly {
  0%   { transform: translate(0,0) scale(1); opacity: 1; }
  100% { transform: translate(var(--dx), var(--dy)) scale(0.4); opacity: 0; }
}

/* ===== 화면 흔들림 (실패 시) ===== */
.shake-screen {
  animation: screenShake 0.4s;
}

@keyframes screenShake {
  0%, 100% { transform: translate(0,0); }
  20% { transform: translate(-6px, 4px); }
  40% { transform: translate(6px, -4px); }
  60% { transform: translate(-4px, 4px); }
  80% { transform: translate(4px, -2px); }
}

/* ===== 반응형 ===== */
@media (max-width: 600px) {
  .title { font-size: 40px; }
  .title-sm { font-size: 28px; }
  .subtitle { font-size: 18px; }
  .big-btn { font-size: 22px; padding: 14px 28px; }
  .home-card, .select-card { padding: 26px 24px; }
  .hero-emoji { font-size: 50px; }
  .hud { padding: 8px 10px; gap: 6px; flex-wrap: wrap; }
  .hud-left, .hud-right { gap: 6px; }
  .back-btn.small { font-size: 15px; padding: 6px 12px; }
  .stage-label { font-size: 16px; }
  .score-bar { height: 28px; }
  .score-text { font-size: 16px; line-height: 22px; }
  .lives { font-size: 18px; letter-spacing: 0; }
  .hud-center { flex-basis: 100%; order: 3; }
  .modal-card h2 { font-size: 32px; }
  .big-emoji { font-size: 70px; }
  .stage-list { grid-template-columns: repeat(auto-fit, 140px); gap: 12px; }
  .stage-list > .level-header { font-size: 20px; }
  .mode-title { font-size: 19px; }
  .mode-btn { font-size: 19px; min-width: 92px; padding: 9px 16px; }
  .text-settings textarea { font-size: 19px; }
  .hint { font-size: 16px; padding: 8px 18px; bottom: 12px; }
}

/* 태블릿 사이즈 - HUD 가독성 미세 조정 */
@media (min-width: 601px) and (max-width: 1024px) {
  .stage-label { font-size: 20px; }
  .score-text { font-size: 20px; }
}
