/* ============================================================
   쉿!탐험대 — Design System (야간 감성 토큰)
   ============================================================ */
:root {
  /* Brand */
  --bg: #0F1733;
  --surface: #1E2642;
  --surface-hl: #2C3558;
  --primary: #8FA8FF;
  --secondary: #8DE0D1;
  --gold: #FFD166;

  /* Quiet State */
  --safe: #8DE0D1;
  --caution: #FFD166;
  --danger: #FF9F7C;
  --fail: #E57CD8;

  /* Text */
  --text-1: #FFFFFF;
  --text-2: #B4C2F0;
  --text-3: #5E6B9B;

  /* Layout */
  --radius-sm: 8px;
  --radius-md: 16px;
  --radius-lg: 24px;
  --radius-xl: 32px;
  --radius-pill: 999px;

  --font: 'Noto Sans KR', sans-serif;
}

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

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text-1);
  min-height: 100dvh;
  overflow: hidden;
  -webkit-user-select: none;
  user-select: none;
}

#app {
  width: 100vw;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
}

/* ============================================================
   Stars Background Animation
   ============================================================ */
.stars-bg {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  overflow: hidden;
}
.star {
  position: absolute;
  width: 3px; height: 3px;
  background: rgba(255,255,255,0.6);
  border-radius: 50%;
  animation: twinkle var(--dur, 3s) ease-in-out infinite alternate;
}
@keyframes twinkle {
  0% { opacity: 0.2; transform: scale(0.8); }
  100% { opacity: 1; transform: scale(1.2); }
}

/* ============================================================
   Screens (공통)
   ============================================================ */
.screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 1;
  opacity: 0;
  transition: opacity 0.32s ease;
  pointer-events: none;
  padding: 24px;
}
.screen.active {
  opacity: 1;
  pointer-events: auto;
}

/* ============================================================
   Splash
   ============================================================ */
.splash-title {
  font-size: 42px;
  font-weight: 800;
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  animation: fadeInUp 0.6s ease;
}
.splash-sub {
  font-size: 18px;
  color: var(--text-2);
  margin-top: 12px;
  animation: fadeInUp 0.6s ease 0.2s both;
}
@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(20px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ============================================================
   Buttons
   ============================================================ */
.btn {
  min-height: 72px;
  min-width: 200px;
  padding: 16px 40px;
  border: none;
  border-radius: var(--radius-xl);
  font-family: var(--font);
  font-size: 20px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.12s, box-shadow 0.12s;
  position: relative;
}
.btn:active { transform: translateY(3px); box-shadow: none !important; }

.btn-primary {
  background: linear-gradient(135deg, var(--primary), #7B96F0);
  color: var(--text-1);
  box-shadow: 0 6px 0 #6B83CC, 0 8px 20px rgba(0,0,0,0.3);
}
.btn-secondary {
  background: var(--surface-hl);
  color: var(--text-1);
  box-shadow: 0 4px 0 #1a2040, 0 6px 16px rgba(0,0,0,0.2);
  min-height: 56px;
  min-width: 120px;
  font-size: 17px;
}

/* ============================================================
   Home
   ============================================================ */
.cat-avatar {
  width: 160px; height: 160px;
  border-radius: 50%;
  border: 4px solid var(--primary);
  background: var(--surface);
  display: flex; align-items: center; justify-content: center;
  font-size: 72px;
  margin-bottom: 24px;
  animation: breathe 3s ease-in-out infinite;
  box-shadow: 0 0 40px rgba(143,168,255,0.2);
}
@keyframes breathe {
  0%, 100% { transform: scale(1); box-shadow: 0 0 40px rgba(143,168,255,0.2); }
  50% { transform: scale(1.04); box-shadow: 0 0 60px rgba(143,168,255,0.35); }
}
.home-greeting {
  font-size: 28px;
  font-weight: 700;
  margin-bottom: 40px;
  text-align: center;
}
.home-nav {
  display: flex;
  gap: 16px;
  margin-top: 24px;
}

/* ============================================================
   Calibration
   ============================================================ */
.calibration-ring {
  width: 200px; height: 200px;
  border-radius: 50%;
  border: 6px solid var(--secondary);
  display: flex; align-items: center; justify-content: center;
  flex-direction: column;
  position: relative;
  margin-bottom: 32px;
}
.calibration-ring::after {
  content: '';
  position: absolute;
  inset: -6px;
  border-radius: 50%;
  border: 6px solid transparent;
  border-top-color: var(--primary);
  animation: spin 1.5s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.calibration-text {
  font-size: 16px;
  color: var(--text-2);
  text-align: center;
  margin-top: 16px;
  line-height: 1.6;
}

/* ============================================================
   Gameplay
   ============================================================ */
.gameplay-header {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  position: absolute;
  top: 0;
  z-index: 5;
}
.stage-label {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-2);
}
.quiet-gauge {
  display: flex;
  align-items: center;
  gap: 8px;
}
.gauge-bar {
  width: 120px;
  height: 12px;
  background: var(--surface-hl);
  border-radius: var(--radius-pill);
  overflow: hidden;
  position: relative;
}
.gauge-fill {
  height: 100%;
  border-radius: var(--radius-pill);
  transition: width 0.3s ease, background 0.3s ease;
}
.cat-mini {
  font-size: 28px;
  transition: transform 0.3s ease;
}

/* Puzzle Area */
.puzzle-area {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  padding: 80px 16px 100px;
}

/* Memory Cards */
.memory-grid {
  display: grid;
  gap: 10px;
  max-width: 400px;
}
.memory-card {
  aspect-ratio: 1;
  border-radius: var(--radius-md);
  cursor: pointer;
  perspective: 800px;
  min-width: 72px;
  min-height: 72px;
}
.memory-card-inner {
  width: 100%;
  height: 100%;
  position: relative;
  transform-style: preserve-3d;
  transition: transform 0.4s ease;
  border-radius: var(--radius-md);
}
.memory-card.flipped .memory-card-inner,
.memory-card.matched .memory-card-inner {
  transform: rotateY(180deg);
}
.memory-card-front, .memory-card-back {
  position: absolute;
  inset: 0;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  backface-visibility: hidden;
  font-size: 32px;
}
.memory-card-front {
  background: linear-gradient(135deg, var(--surface-hl), var(--surface));
  border: 2px solid var(--text-3);
}
.memory-card-front::after {
  content: '?';
  font-size: 28px;
  color: var(--text-3);
}
.memory-card-back {
  background: var(--surface);
  border: 2px solid var(--secondary);
  transform: rotateY(180deg);
}
.memory-card.matched .memory-card-back {
  border-color: var(--safe);
  box-shadow: 0 0 16px rgba(141,224,209,0.35);
}

/* Counting */
.counting-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 32px;
}
.counting-items {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  justify-content: center;
  max-width: 320px;
}
.counting-item {
  font-size: 36px;
  animation: popIn 0.3s ease both;
}
@keyframes popIn {
  from { opacity: 0; transform: scale(0.5); }
  to   { opacity: 1; transform: scale(1); }
}
.counting-options {
  display: flex;
  gap: 16px;
}
.counting-option {
  width: 80px; height: 80px;
  border-radius: var(--radius-xl);
  background: var(--surface-hl);
  border: 3px solid var(--text-3);
  font-size: 28px;
  font-weight: 700;
  color: var(--text-1);
  cursor: pointer;
  font-family: var(--font);
  transition: border-color 0.2s, transform 0.15s;
}
.counting-option:active { transform: scale(0.92); }
.counting-option.correct {
  border-color: var(--safe);
  background: rgba(141,224,209,0.15);
}
.counting-option.wrong {
  border-color: var(--danger);
  animation: shake 0.4s ease;
}
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-8px); }
  75% { transform: translateX(8px); }
}

/* Sorting */
.sorting-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 32px;
  width: 100%;
  max-width: 400px;
}
.sorting-objects {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  justify-content: center;
}
.sorting-obj {
  width: 64px; height: 64px;
  border-radius: var(--radius-md);
  display: flex; align-items: center; justify-content: center;
  font-size: 32px;
  cursor: grab;
  transition: transform 0.2s;
  border: 3px solid transparent;
}
.sorting-obj:active { transform: scale(1.1); cursor: grabbing; }
.sorting-obj.placed { opacity: 0.3; pointer-events: none; }
.sorting-obj.selected { border-color: var(--primary); transform: scale(1.1); }

.sorting-baskets {
  display: flex;
  gap: 16px;
}
.sorting-basket {
  width: 100px; height: 100px;
  border-radius: var(--radius-lg);
  background: var(--surface-hl);
  border: 3px dashed var(--text-3);
  display: flex; align-items: center; justify-content: center;
  flex-direction: column;
  gap: 4px;
  font-size: 14px;
  color: var(--text-2);
  cursor: pointer;
  transition: border-color 0.2s;
}
.sorting-basket:hover { border-color: var(--primary); }
.sorting-basket-icon { font-size: 28px; }

/* ============================================================
   Gameplay Footer (Progress)
   ============================================================ */
.gameplay-footer {
  width: 100%;
  padding: 16px 24px;
  position: absolute;
  bottom: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  z-index: 5;
}
.progress-dots {
  display: flex;
  gap: 8px;
}
.progress-dot {
  width: 12px; height: 12px;
  border-radius: 50%;
  background: var(--text-3);
  transition: background 0.3s;
}
.progress-dot.done { background: var(--safe); }
.progress-dot.current { background: var(--primary); transform: scale(1.3); }

/* ============================================================
   Result Screen
   ============================================================ */
.result-stars {
  display: flex;
  gap: 12px;
  margin: 24px 0;
}
.result-star {
  font-size: 48px;
  opacity: 0.2;
  transition: opacity 0.4s, transform 0.4s;
}
.result-star.earned {
  opacity: 1;
  animation: starPop 0.5s ease both;
}
@keyframes starPop {
  0% { transform: scale(0) rotate(-30deg); opacity: 0; }
  60% { transform: scale(1.3) rotate(5deg); }
  100% { transform: scale(1) rotate(0); opacity: 1; }
}
.result-msg {
  font-size: 22px;
  font-weight: 600;
  margin-bottom: 12px;
  text-align: center;
}
.result-sub {
  font-size: 16px;
  color: var(--text-2);
  margin-bottom: 32px;
  text-align: center;
}
.reward-card {
  background: var(--surface);
  border: 2px solid var(--gold);
  border-radius: var(--radius-lg);
  padding: 16px 28px;
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 32px;
  animation: fadeInUp 0.5s ease 0.6s both;
}
.reward-card-icon { font-size: 36px; }
.reward-card-text {
  font-size: 15px;
  color: var(--gold);
  font-weight: 600;
}
.result-actions {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  justify-content: center;
}

/* ============================================================
   World Map
   ============================================================ */
.world-title {
  font-size: 24px;
  font-weight: 700;
  margin-bottom: 24px;
}
.chapter-section {
  margin-bottom: 20px;
  width: 100%;
  max-width: 380px;
}
.chapter-name {
  font-size: 15px;
  color: var(--text-2);
  margin-bottom: 10px;
  font-weight: 600;
}
.stage-list {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}
.stage-node {
  width: 56px; height: 56px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700;
  font-size: 18px;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
  border: 3px solid transparent;
}
.stage-node:hover { transform: scale(1.1); }
.stage-node.locked {
  background: var(--surface);
  color: var(--text-3);
  border-color: var(--text-3);
  cursor: not-allowed;
  opacity: 0.5;
}
.stage-node.unlocked {
  background: var(--surface-hl);
  color: var(--text-1);
  border-color: var(--primary);
}
.stage-node.cleared {
  background: rgba(141,224,209,0.15);
  color: var(--safe);
  border-color: var(--safe);
}
.stage-stars-mini {
  display: flex;
  gap: 1px;
  position: absolute;
  bottom: -14px;
  font-size: 10px;
}
.world-map-scroll {
  overflow-y: auto;
  max-height: 70dvh;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding-bottom: 24px;
}
.world-back {
  position: absolute;
  top: 16px;
  left: 16px;
  z-index: 5;
}
