/* 심야 카페 - 모카 스타일시트 */

/* ===== Reset & Base ===== */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
  overflow: hidden;
}

body {
  font-family: 'Pretendard', -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
  background: #1a1a2e;
  color: #e5e7eb;
  -webkit-font-smoothing: antialiased;
}

/* ===== App Container ===== */
.app {
  position: relative;
  width: 100%;
  height: 100%;
  max-width: 520px;
  margin: 0 auto;
  background: linear-gradient(180deg, #1a1a2e 0%, #16213e 50%, #0f0f23 100%);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ===== Header ===== */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  padding-top: calc(12px + env(safe-area-inset-top, 0px));
  background: rgba(0, 0, 0, 0.3);
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.cafe-name {
  font-size: 16px;
  font-weight: 600;
  color: #d4a574;
}

.cafe-time {
  font-size: 12px;
  color: #6b7280;
}

.back-link {
  padding: 6px 12px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 999px;
  color: #9ca3af;
  font-size: 11px;
  text-decoration: none;
  transition: all 0.2s;
}

.back-link:hover {
  background: rgba(255, 255, 255, 0.1);
  color: #d4a574;
}

.btn-collection {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px 12px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 999px;
  color: #9ca3af;
  font-size: 12px;
  cursor: pointer;
  position: relative;
  transition: all 0.2s;
}

.btn-collection:hover {
  background: rgba(255, 255, 255, 0.1);
}

.new-badge {
  position: absolute;
  top: -2px;
  right: -2px;
  width: 8px;
  height: 8px;
  background: #ef4444;
  border-radius: 50%;
  animation: pulse-badge 1.5s ease-in-out infinite;
}

.new-badge.hidden {
  display: none;
}

@keyframes pulse-badge {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.3); opacity: 0.8; }
}

/* ===== Chat Container ===== */
.chat-container {
  flex: 1;
  overflow-y: auto;
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* ===== Message Styles ===== */
.message {
  display: flex;
  gap: 10px;
  animation: fadeInUp 0.4s ease-out;
}

@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.message.moka {
  align-items: flex-start;
}

.message.user {
  flex-direction: row-reverse;
}

.message.system {
  justify-content: center;
}

/* 모카 아바타 */
.moka-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: linear-gradient(135deg, #d4a574, #a67c52);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  flex-shrink: 0;
  box-shadow: 0 2px 10px rgba(212, 165, 116, 0.3);
}

/* 말풍선 */
.bubble {
  max-width: 75%;
  padding: 12px 16px;
  border-radius: 18px;
  font-size: 14px;
  line-height: 1.5;
  word-break: keep-all;
}

.message.moka .bubble {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.05);
  border-radius: 18px 18px 18px 4px;
  color: #e5e7eb;
}

.message.user .bubble {
  background: linear-gradient(135deg, #d4a574, #a67c52);
  border-radius: 18px 18px 4px 18px;
  color: #1a1a2e;
}

.message.system .bubble {
  background: transparent;
  color: #6b7280;
  font-size: 12px;
  padding: 8px;
}

/* 타이핑 인디케이터 */
.typing-indicator {
  display: flex;
  gap: 4px;
  padding: 12px 16px;
}

.typing-indicator span {
  width: 6px;
  height: 6px;
  background: #6b7280;
  border-radius: 50%;
  animation: typing 1.4s ease-in-out infinite;
}

.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typing {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-4px); opacity: 1; }
}

/* ===== Card in Chat ===== */
.card-message {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 20px;
  animation: fadeInUp 0.4s ease-out;
}

.chat-card {
  width: 160px;
  height: 224px;
  perspective: 1000px;
  cursor: pointer;
}

.chat-card-inner {
  width: 100%;
  height: 100%;
  position: relative;
  transform-style: preserve-3d;
  transition: transform 0.6s cubic-bezier(0.4, 0, 0.2, 1);
}

.chat-card.flipped .chat-card-inner {
  transform: rotateY(180deg);
}

.chat-card-face {
  position: absolute;
  width: 100%;
  height: 100%;
  backface-visibility: hidden;
  border-radius: 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.4);
}

/* 카드 뒷면 */
.chat-card-back {
  background: linear-gradient(145deg, #2d2d5a, #1a1a3e);
  border: 2px solid rgba(212, 165, 116, 0.3);
}

.chat-card-back::before {
  content: "☕";
  font-size: 48px;
  opacity: 0.5;
}

.chat-card-back::after {
  content: "탭하여 뒤집기";
  position: absolute;
  bottom: 20px;
  font-size: 11px;
  color: rgba(255, 255, 255, 0.4);
}

/* 카드 앞면 */
.chat-card-front {
  transform: rotateY(180deg);
  padding: 16px;
  text-align: center;
}

.chat-card-front.common {
  background: linear-gradient(145deg, #f8fafc, #e2e8f0);
  border: 2px solid rgba(148, 163, 184, 0.4);
}

.chat-card-front.rare {
  background: linear-gradient(145deg, #fef9c3, #fde047);
  border: 2px solid rgba(202, 138, 4, 0.5);
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.4), 0 0 30px rgba(250, 204, 21, 0.2);
}

.chat-card-front.epic {
  background: linear-gradient(145deg, #f3e8ff, #d8b4fe);
  border: 2px solid rgba(147, 51, 234, 0.5);
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.4), 0 0 30px rgba(192, 132, 252, 0.25);
}

.chat-card-front.legendary {
  background: linear-gradient(145deg, #fef3c7, #fbbf24, #f59e0b);
  border: 2px solid rgba(245, 158, 11, 0.8);
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.4), 0 0 40px rgba(245, 158, 11, 0.4);
  animation: legendary-glow 2s ease-in-out infinite;
}

@keyframes legendary-glow {
  0%, 100% { box-shadow: 0 10px 40px rgba(0,0,0,0.4), 0 0 40px rgba(245,158,11,0.4); }
  50% { box-shadow: 0 10px 40px rgba(0,0,0,0.4), 0 0 60px rgba(245,158,11,0.6); }
}

.chat-card-emoji {
  font-size: 48px;
  margin-bottom: 8px;
}

.chat-card-text {
  font-size: 12px;
  line-height: 1.4;
  color: #1e293b;
  font-weight: 500;
  word-break: keep-all;
}

.chat-card-rarity {
  position: absolute;
  bottom: 12px;
  font-size: 10px;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 999px;
}

.chat-card-rarity.common {
  background: rgba(100, 116, 139, 0.2);
  color: #64748b;
}

.chat-card-rarity.rare {
  background: rgba(202, 138, 4, 0.2);
  color: #a16207;
}

.chat-card-rarity.epic {
  background: rgba(147, 51, 234, 0.2);
  color: #7e22ce;
}

.chat-card-rarity.legendary {
  background: rgba(180, 83, 9, 0.25);
  color: #92400e;
}

/* ===== Action Buttons in Chat ===== */
.card-actions {
  display: flex;
  gap: 10px;
  margin-top: 8px;
  animation: fadeInUp 0.4s ease-out 0.3s both;
}

.btn-card-action {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px 16px;
  border: none;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

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

.btn-card-action.kakao {
  background: #FEE500;
  color: #191919;
}

.btn-card-action.kakao img {
  width: 18px;
  height: 18px;
  border-radius: 4px;
}

.btn-card-action.save {
  background: rgba(255, 255, 255, 0.1);
  color: #e5e7eb;
  border: 1px solid rgba(255, 255, 255, 0.1);
}

/* ===== Input Area ===== */
.input-area {
  padding: 16px;
  padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  background: rgba(0, 0, 0, 0.3);
  border-top: 1px solid rgba(255, 255, 255, 0.05);
  display: flex;
  justify-content: center;
  gap: 10px;
}

.btn-action {
  flex: 1;
  max-width: 200px;
  padding: 14px 24px;
  border: none;
  border-radius: 999px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

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

.btn-action:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-draw {
  background: linear-gradient(135deg, #d4a574, #a67c52);
  color: #1a1a2e;
  box-shadow: 0 4px 15px rgba(212, 165, 116, 0.3);
}

.btn-draw:hover:not(:disabled) {
  box-shadow: 0 6px 20px rgba(212, 165, 116, 0.4);
}

.btn-again {
  background: rgba(255, 255, 255, 0.1);
  color: #e5e7eb;
  border: 1px solid rgba(255, 255, 255, 0.1);
}

/* 남은 횟수 표시 */
.draw-count {
  font-size: 12px;
  color: #9ca3af;
  text-align: center;
  margin-top: 8px;
}

.draw-count.exhausted {
  color: #ef4444;
}

/* ===== Toast ===== */
.toast {
  position: fixed;
  bottom: 100px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: rgba(26, 26, 46, 0.95);
  color: white;
  padding: 14px 24px;
  border-radius: 12px;
  font-size: 14px;
  font-weight: 500;
  opacity: 0;
  pointer-events: none;
  transition: all 0.3s;
  z-index: 1000;
  backdrop-filter: blur(10px);
  border: 1px solid rgba(212, 165, 116, 0.2);
  min-width: fit-content;
  max-width: 360px;
  text-align: center;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  word-break: break-all;
  white-space: pre-wrap;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

@media (max-width: 400px) {
  .toast {
    font-size: 13px;
    padding: 12px 20px;
  }
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ===== 컬렉션 모달 (기존 스타일 재사용) ===== */
.collection-modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.8);
  backdrop-filter: blur(8px);
  z-index: 200;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.3s;
}

.collection-modal.open {
  opacity: 1;
}

.collection-modal.closing {
  opacity: 0;
}

.collection-content {
  width: 100%;
  max-width: 520px;
  max-height: 85vh;
  background: linear-gradient(180deg, #1a1a2e 0%, #0f0f23 100%);
  border-radius: 24px 24px 0 0;
  padding: 20px;
  overflow-y: auto;
  transform: translateY(100%);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.collection-modal.open .collection-content {
  transform: translateY(0);
}

.collection-modal.closing .collection-content {
  transform: translateY(100%);
}

.collection-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.collection-header h2 {
  font-size: 20px;
  font-weight: 700;
  color: #d4a574;
}

.collection-close {
  width: 32px;
  height: 32px;
  border: none;
  background: rgba(255, 255, 255, 0.1);
  color: #9ca3af;
  border-radius: 50%;
  font-size: 16px;
  cursor: pointer;
  transition: all 0.2s;
}

.collection-close:hover {
  background: rgba(255, 255, 255, 0.2);
  color: white;
}

.collection-stats {
  text-align: center;
  margin-bottom: 20px;
}

.stat-main {
  font-size: 14px;
  margin-bottom: 4px;
}

.stat-number {
  font-size: 36px;
  font-weight: 700;
  color: #d4a574;
}

.stat-total {
  color: #6b7280;
}

.stat-percent {
  color: #9ca3af;
  font-size: 14px;
}

.stat-draws {
  font-size: 12px;
  color: #6b7280;
}

.collection-progress {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 20px;
  padding: 12px;
  background: rgba(0, 0, 0, 0.2);
  border-radius: 12px;
}

.progress-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
}

.progress-label {
  width: 70px;
  font-weight: 600;
}

.progress-bar {
  flex: 1;
  height: 6px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 3px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.5s ease-out;
}

.progress-count {
  width: 40px;
  text-align: right;
  color: #9ca3af;
}

.collection-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  overflow-x: auto;
  padding-bottom: 4px;
}

.tab-btn {
  padding: 8px 16px;
  border: none;
  background: rgba(255, 255, 255, 0.05);
  color: #9ca3af;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}

.tab-btn:hover {
  background: rgba(255, 255, 255, 0.1);
}

.tab-btn.active {
  background: rgba(212, 165, 116, 0.3);
  color: #d4a574;
}

.collection-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
}

.rarity-section {
  grid-column: 1 / -1;
  margin-top: 12px;
  margin-bottom: 4px;
}

.rarity-section:first-child {
  margin-top: 0;
}

.rarity-title {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.collection-card {
  aspect-ratio: 5/7;
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  position: relative;
  transition: all 0.2s;
}

.collection-card.owned {
  background: linear-gradient(145deg, rgba(255,255,255,0.1), rgba(255,255,255,0.05));
  border: 1px solid rgba(255, 255, 255, 0.2);
  cursor: pointer;
}

.collection-card.owned:active {
  transform: scale(0.95);
}

.collection-card.owned.rare {
  border-color: rgba(250, 204, 21, 0.5);
  box-shadow: 0 0 10px rgba(250, 204, 21, 0.2);
}

.collection-card.owned.epic {
  border-color: rgba(192, 132, 252, 0.5);
  box-shadow: 0 0 10px rgba(192, 132, 252, 0.2);
}

.collection-card.owned.legendary {
  border-color: rgba(245, 158, 11, 0.6);
  box-shadow: 0 0 15px rgba(245, 158, 11, 0.3);
}

.collection-card.locked {
  background: rgba(0, 0, 0, 0.3);
  border: 1px dashed rgba(255, 255, 255, 0.1);
}

.collection-card .card-emoji {
  font-size: 24px;
  margin: 0;
}

.collection-card.locked .card-emoji {
  opacity: 0.3;
  filter: grayscale(1);
}

.collection-card .card-count {
  position: absolute;
  bottom: 4px;
  right: 4px;
  font-size: 9px;
  color: #9ca3af;
  background: rgba(0, 0, 0, 0.5);
  padding: 1px 4px;
  border-radius: 4px;
}

/* ===== 카드 상세 모달 ===== */
.card-detail-modal {
  position: fixed;
  inset: 0;
  z-index: 300;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.2s;
}

.card-detail-modal.open {
  opacity: 1;
}

.card-detail-modal.closing {
  opacity: 0;
}

.card-detail-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
}

.card-detail-content {
  position: relative;
  width: 280px;
  padding: 32px 24px;
  border-radius: 20px;
  text-align: center;
  transform: scale(0.9);
  transition: transform 0.2s;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

.card-detail-modal.open .card-detail-content {
  transform: scale(1);
}

.card-detail-modal.closing .card-detail-content {
  transform: scale(0.9);
}

.card-detail-content.common {
  background: linear-gradient(145deg, #f8fafc, #e2e8f0);
  color: #1e293b;
}

.card-detail-content.rare {
  background: linear-gradient(145deg, #fef9c3, #fde047);
  color: #1e293b;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5), 0 0 40px rgba(250, 204, 21, 0.3);
}

.card-detail-content.epic {
  background: linear-gradient(145deg, #f3e8ff, #d8b4fe);
  color: #1e293b;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5), 0 0 40px rgba(192, 132, 252, 0.3);
}

.card-detail-content.legendary {
  background: linear-gradient(145deg, #fef3c7, #fbbf24, #f59e0b);
  color: #1e293b;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5), 0 0 50px rgba(245, 158, 11, 0.5);
}

.card-detail-emoji {
  font-size: 72px;
  margin-bottom: 16px;
}

.card-detail-text {
  font-size: 18px;
  font-weight: 600;
  line-height: 1.5;
  margin-bottom: 16px;
  word-break: keep-all;
}

.card-detail-rarity {
  display: inline-block;
  padding: 6px 16px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  margin-bottom: 16px;
}

.card-detail-stats {
  display: flex;
  justify-content: center;
  gap: 16px;
  font-size: 12px;
  color: #64748b;
  margin-bottom: 20px;
}

.card-detail-buttons {
  display: flex;
  gap: 10px;
  justify-content: center;
}

.card-detail-kakao {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px 20px;
  border: none;
  border-radius: 999px;
  background: #FEE500;
  color: #191919;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.card-detail-kakao:hover {
  background: #F5DC00;
}

.card-detail-kakao:active {
  transform: scale(0.96);
}

.card-detail-kakao img {
  border-radius: 4px;
}

.card-detail-close {
  padding: 10px 24px;
  border: none;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.1);
  color: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}

.card-detail-close:hover {
  background: rgba(0, 0, 0, 0.2);
}

/* ===== Responsive ===== */
@media (max-width: 400px) {
  .chat-card {
    width: 140px;
    height: 196px;
  }
  
  .chat-card-emoji {
    font-size: 40px;
  }
  
  .chat-card-text {
    font-size: 11px;
  }
  
  .collection-grid {
    grid-template-columns: repeat(4, 1fr);
  }
}