/* =============================================
   🐱 고양이 만지기 - Mobile Touch Game
   v2.0 — 다크모드 + 파티클 + 게이지 + 모던 팝업
   ============================================= */

/* --- Reset & Base --- */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

:root {
  --bg-deep: #0a0e1a;
  --bg-card: #111827;
  --bg-card-hover: #1a2332;
  --text: #e8edf5;
  --text-dim: #8892a8;
  --text-muted: #555d70;
  --border: rgba(255,255,255,0.06);

  --blue: #0096FF;
  --blue-dim: rgba(0,150,255,0.15);
  --blue-glow: rgba(0,150,255,0.4);
  --blue-mid: #0070cc;

  --gold: #FFB800;
  --gold-glow: rgba(255,184,0,0.5);
  --green: #10B981;
  --red: #EF4444;
  --pink: #EC4899;

  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: 'Pretendard', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg-deep);
  touch-action: none;
  overscroll-behavior: none;
  -webkit-overflow-scrolling: none;
}

#app {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  position: relative;
  max-width: 480px;
  margin: 0 auto;
  overflow: hidden;
}

/* =============================================
   TAB SYSTEM — 홈/포털 ↔ 게임 전환
   ============================================= */
.tab-bar {
  display: flex;
  padding: 8px 16px;
  padding-top: calc(8px + var(--safe-top));
  gap: 8px;
  background: rgba(10,14,26,0.9);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border);
  position: relative;
  z-index: 30;
}

.tab-btn {
  flex: 1;
  padding: 10px 16px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: transparent;
  color: var(--text-dim);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.25s ease;
  touch-action: manipulation;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.tab-btn.active {
  background: var(--blue-dim);
  border-color: var(--blue);
  color: var(--blue);
  box-shadow: 0 0 20px rgba(0,150,255,0.1);
}

.tab-btn:active {
  transform: scale(0.96);
}

.tab-content {
  display: none;
  width: 100%;
  height: 100%;
  flex-direction: column;
}

.tab-content.active {
  display: flex;
}

/* =============================================
   PORTAL TAB — spacedaily 포털 미리보기
   ============================================= */
#portal-tab {
  overflow-y: auto;
  padding: 24px 20px;
  padding-bottom: calc(24px + var(--safe-bottom));
  flex: 1;
}

.portal-header {
  text-align: center;
  margin-bottom: 28px;
}

.portal-header .brand {
  font-size: 22px;
  font-weight: 700;
  color: #fff;
  letter-spacing: -0.5px;
  margin-bottom: 4px;
}

.portal-header .brand span { color: var(--blue); }

.portal-header .tagline {
  font-size: 13px;
  color: var(--text-dim);
}

.portal-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.portal-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 16px;
  cursor: pointer;
  transition: all 0.25s ease;
  text-decoration: none;
  color: inherit;
}

.portal-card:hover {
  border-color: rgba(0,150,255,0.2);
  transform: translateY(-2px);
}

.portal-card .card-icon {
  font-size: 28px;
  margin-bottom: 8px;
}

.portal-card h4 {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 2px;
}

.portal-card p {
  font-size: 11px;
  color: var(--text-dim);
}

.portal-card.full {
  grid-column: 1 / -1;
}

/* =============================================
   GAME TAB — 게임 영역
   ============================================= */

/* --- HUD --- */
#hud {
  display: flex;
  justify-content: space-around;
  align-items: center;
  padding: 10px 8px;
  background: rgba(10,14,26,0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  position: relative;
  z-index: 10;
}

.hud-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
}

.hud-icon {
  font-size: 18px;
}

/* --- LEVEL PROGRESS BAR --- */
#progress-section {
  padding: 6px 16px;
  background: rgba(10,14,26,0.6);
  border-bottom: 1px solid var(--border);
}

.progress-label {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--text-dim);
  margin-bottom: 4px;
}

.progress-label span:last-child {
  color: var(--blue);
  font-weight: 600;
}

.progress-track {
  width: 100%;
  height: 6px;
  background: var(--bg-card);
  border-radius: 100px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--blue-mid), var(--blue), #80d4ff);
  border-radius: 100px;
  transition: width 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
  position: relative;
}

.progress-fill::after {
  content: '';
  position: absolute;
  right: 0;
  top: 0;
  width: 12px;
  height: 100%;
  background: rgba(255,255,255,0.4);
  border-radius: 100px;
  animation: progressShimmer 2s ease-in-out infinite;
}

@keyframes progressShimmer {
  0%, 100% { opacity: 0.3; }
  50% { opacity: 0.8; }
}

/* --- 게임 영역: 고양이 터치 --- */
#game-area {
  flex: 1;
  display: flex;
  justify-content: center;
  align-items: center;
  position: relative;
  overflow: hidden;
}

#cat-container {
  position: relative;
  width: 200px;
  height: 200px;
}

/* --- 고양이 얼굴 CSS 아트 --- */
#cat {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background: radial-gradient(circle at 40% 35%, #1a1a3a, #0d0d2a);
  box-shadow:
    0 8px 32px rgba(0, 150, 255, 0.15),
    inset 0 -4px 12px rgba(0, 0, 0, 0.3),
    0 0 60px rgba(0, 150, 255, 0.05);
  display: flex;
  justify-content: center;
  align-items: center;
  position: relative;
  cursor: pointer;
  transition: transform 0.1s ease;
  -webkit-tap-highlight-color: transparent;
  border: 2px solid rgba(0,150,255,0.1);
}

.cat-idle {
  animation: catBreathe 3s ease-in-out infinite;
}

.cat-pressed {
  transform: scale(0.92) !important;
  animation: none !important;
}

.cat-happy {
  animation: catHappy 0.6s ease-out !important;
}

@keyframes catBreathe {
  0%, 100% { transform: scale(1); box-shadow: 0 8px 32px rgba(0,150,255,0.15); }
  50% { transform: scale(1.03); box-shadow: 0 12px 48px rgba(0,150,255,0.25); }
}

@keyframes catHappy {
  0% { transform: scale(1) rotate(0deg); }
  25% { transform: scale(1.08) rotate(-3deg); box-shadow: 0 0 40px var(--blue-glow); }
  50% { transform: scale(0.95) rotate(2deg); }
  75% { transform: scale(1.04) rotate(-1deg); }
  100% { transform: scale(1) rotate(0deg); }
}

/* 귀 */
.cat-ears {
  position: absolute;
  top: -22px;
  left: 0;
  right: 0;
  display: flex;
  justify-content: space-between;
  padding: 0 12px;
}

.ear {
  width: 36px;
  height: 44px;
  background: #0d0d2a;
  border-radius: 50% 50% 0 0;
  position: relative;
  border: 1px solid rgba(0,150,255,0.1);
}

.ear::after {
  content: '';
  position: absolute;
  top: 6px;
  left: 7px;
  right: 7px;
  bottom: 8px;
  background: var(--blue-dim);
  border-radius: 50% 50% 0 0;
}

.ear.left { transform: rotate(-10deg); }
.ear.right { transform: rotate(10deg); }

.cat-face {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}

.cat-eyes {
  display: flex;
  gap: 32px;
  margin-bottom: 10px;
}

.eye {
  width: 18px;
  height: 20px;
  background: #e8edf5;
  border-radius: 50%;
  position: relative;
  animation: blink 4s ease-in-out infinite;
  box-shadow: 0 0 8px rgba(232,237,245,0.2);
}

.eye::after {
  content: '';
  position: absolute;
  top: 4px;
  left: 4px;
  width: 6px;
  height: 6px;
  background: var(--blue);
  border-radius: 50%;
  box-shadow: 0 0 6px var(--blue-glow);
}

@keyframes blink {
  0%, 95%, 100% { transform: scaleY(1); }
  97% { transform: scaleY(0.1); }
}

.cat-nose {
  width: 12px;
  height: 8px;
  background: var(--pink);
  border-radius: 50%;
  margin-bottom: 4px;
  opacity: 0.8;
}

.cat-mouth {
  position: relative;
  width: 52px;
  height: 16px;
}

.cat-mouth::before,
.cat-mouth::after {
  content: '';
  position: absolute;
  top: 0;
  width: 14px;
  height: 8px;
  border: 1.5px solid rgba(232,237,245,0.3);
  border-top: none;
  border-right: none;
}

.cat-mouth::before {
  left: 10px;
  transform: rotate(20deg);
}

.cat-mouth::after {
  right: 10px;
  transform: rotate(-20deg);
  border-right: 1.5px solid rgba(232,237,245,0.3);
  border-left: none;
}

/* 수염 */
.whisker {
  position: absolute;
  width: 36px;
  height: 1.5px;
  background: rgba(232,237,245,0.2);
  top: 6px;
}

.whisker.left-top { right: 58px; top: -2px; transform: rotate(-10deg); }
.whisker.left-bottom { right: 58px; top: 8px; transform: rotate(8deg); }
.whisker.right-top { left: 58px; top: -2px; transform: rotate(10deg); }
.whisker.right-bottom { left: 58px; top: 8px; transform: rotate(-8deg); }

/* --- 파티클 컨테이너 --- */
#particle-container {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  pointer-events: none;
  z-index: 15;
}

.particle {
  position: absolute;
  font-size: 16px;
  pointer-events: none;
  animation: particleBurst 0.8s ease-out forwards;
}

@keyframes particleBurst {
  0% {
    opacity: 1;
    transform: translate(0, 0) scale(1) rotate(0deg);
  }
  100% {
    opacity: 0;
    transform: translate(var(--dx), var(--dy)) scale(0.3) rotate(var(--rot));
  }
}

/* --- 플로팅 텍스트 --- */
#floating-text-container {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  pointer-events: none;
  z-index: 20;
}

.floating-text {
  position: absolute;
  font-size: 26px;
  font-weight: 800;
  color: var(--gold);
  text-shadow: 0 2px 12px var(--gold-glow);
  animation: floatUp 0.9s ease-out forwards;
  pointer-events: none;
}

.floating-text.critical {
  font-size: 40px;
  color: var(--pink);
  text-shadow: 0 0 24px rgba(236,72,153,0.6);
}

@keyframes floatUp {
  0% { opacity: 1; transform: translateY(0) scale(1); }
  50% { opacity: 1; transform: translateY(-50px) scale(1.2); }
  100% { opacity: 0; transform: translateY(-90px) scale(0.8); }
}

/* --- 자동 수입 미니 피드백 --- */
.auto-particle {
  position: absolute;
  font-size: 12px;
  pointer-events: none;
  animation: autoFloat 1.5s ease-out forwards;
  opacity: 0.6;
}

@keyframes autoFloat {
  0% { opacity: 0.6; transform: translateY(0) scale(0.8); }
  50% { opacity: 0.8; transform: translateY(-30px) scale(1); }
  100% { opacity: 0; transform: translateY(-60px) scale(0.5); }
}

/* =============================================
   하단 업그레이드 숍 (다크 모드)
   ============================================= */
#shop {
  padding: 10px 8px;
  padding-bottom: calc(10px + var(--safe-bottom));
  background: rgba(10,14,26,0.9);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
}

.shop-row {
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
}

.shop-row:last-child {
  margin-bottom: 0;
}

.shop-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 10px 6px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--bg-card);
  cursor: pointer;
  transition: all 0.2s ease;
  touch-action: manipulation;
}

.shop-item:active {
  transform: scale(0.95);
  background: var(--bg-card-hover);
}

.shop-item.disabled {
  opacity: 0.3;
  pointer-events: none;
  filter: grayscale(0.6);
}

.shop-item.can-afford {
  border-color: rgba(0,150,255,0.3);
  box-shadow: 0 0 12px rgba(0,150,255,0.05);
}

.shop-icon {
  font-size: 20px;
}

.shop-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
}

.shop-level {
  font-size: 10px;
  font-weight: 500;
  color: var(--text-dim);
}

.shop-cost {
  font-size: 12px;
  font-weight: 700;
  color: var(--gold);
}

/* =============================================
   알림 팝업 (다크 모드)
   ============================================= */
.notification {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.8);
  background: rgba(17,24,39,0.92);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  color: var(--text);
  padding: 18px 28px;
  border-radius: 16px;
  font-size: 16px;
  font-weight: 700;
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: all 0.3s ease;
  text-align: center;
  border: 1px solid var(--border);
}

.notification.show {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
}

/* =============================================
   오프라인 수입 팝업 (모던화)
   ============================================= */
.offline-popup-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.5);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 200;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.4s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}

.offline-popup-overlay.show {
  opacity: 1;
  pointer-events: auto;
}

.offline-popup {
  background: linear-gradient(135deg, #111827, #1a2332);
  border: 1px solid var(--border);
  border-radius: 24px;
  padding: 32px 28px;
  max-width: 340px;
  width: 90%;
  text-align: center;
  transform: scale(0.9) translateY(20px);
  transition: transform 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
  box-shadow: 0 24px 80px rgba(0,0,0,0.5);
}

.offline-popup-overlay.show .offline-popup {
  transform: scale(1) translateY(0);
}

.offline-popup .popup-emoji {
  font-size: 48px;
  margin-bottom: 12px;
  display: block;
}

.offline-popup h2 {
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 6px;
}

.offline-popup p {
  font-size: 14px;
  color: var(--text-dim);
  margin-bottom: 16px;
  line-height: 1.5;
}

.offline-popup .earnings {
  font-size: 32px;
  font-weight: 800;
  color: var(--gold);
  margin: 8px 0 20px;
  text-shadow: 0 0 30px var(--gold-glow);
}

.offline-popup .claim-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 14px 36px;
  border: none;
  border-radius: 100px;
  background: linear-gradient(135deg, #FFB800, #FF9500);
  color: #000;
  font-size: 17px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: 0 4px 24px var(--gold-glow);
  touch-action: manipulation;
}

.offline-popup .claim-btn:active {
  transform: scale(0.95);
}

/* =============================================
   모바일 대응
   ============================================= */
@media (max-width: 380px) {
  .shop-item { padding: 8px 4px; }
  .shop-icon { font-size: 18px; }
  .shop-label { font-size: 11px; }
  .portal-grid { gap: 8px; }
  .portal-card { padding: 12px; }
}
