/* --- 기본 설정 --- */
* { box-sizing: border-box; }
body {
  font-family: "Pretendard", system-ui, -apple-system, sans-serif;
  margin: 0;
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  background: radial-gradient(circle at top, #2b3250 0, #0c0f1f 45%, #050612 100%);
  color: #f7f5ff;
}

/* --- 알림 토스트 --- */
#notification {
  position: fixed; top: 30px; left: 50%;
  transform: translateX(-50%) translateY(-100px);
  background: rgba(255, 255, 255, 0.95);
  color: #0c0f1f; padding: 12px 30px; border-radius: 4px;
  font-weight: 700; font-size: 0.9rem;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  z-index: 2000; opacity: 0; pointer-events: none;
  transition: transform 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275), opacity 0.4s;
}
#notification.show { transform: translateX(-50%) translateY(0); opacity: 1; }

/* --- 메인 컨테이너 (PC 기본) --- */
.app-shell {
  width: 100%; max-width: 1400px;
  height: auto; 
  min-height: 85vh;
  background: rgba(10, 12, 28, 0.95); border-radius: 20px;
  box-shadow: 0 22px 50px rgba(0, 0, 0, 0.7);
  padding: 30px; display: flex; flex-direction: column;
  gap: 20px; border: 1px solid rgba(255, 255, 255, 0.08);
  backdrop-filter: blur(10px);
}

/* --- 헤더 --- */
header { display: flex; justify-content: space-between; align-items: center; }
.header-content h1 { 
  margin: 0; font-size: 1.6rem; letter-spacing: -0.02em; 
  color: #fff; font-weight: 700;
  display: flex; align-items: center;
}
.title-icon { height: 1em; width: auto; margin: 0 8px; vertical-align: middle; }
.subtitle { font-size: 0.95rem; opacity: 0.7; margin-top: 8px; font-weight: 400; letter-spacing: -0.01em; }

.lang-selector {
  padding: 6px 12px; border-radius: 6px; font-size: 0.8rem;
  background: rgba(255, 255, 255, 0.05); color: rgba(255,255,255,0.7);
  border: 1px solid rgba(255, 255, 255, 0.1); cursor: pointer; outline: none;
}
.lang-selector option { background: #0c0f1f; }

.header-button { text-decoration: none; align-items: center; justify-content: center; }
.header-controls { display: flex; align-items: center; gap: 15px; }
.header-right { display: flex; align-items: center; }
.side-nav { display: flex; gap: 20px; margin-right: 15px; }
.nav-link { color: rgba(255, 255, 255, 0.7); text-decoration: none; font-size: 0.9rem; transition: color 0.2s; }
.nav-link:hover { color: #fff; }

/* --- 그리드 레이아웃 (PC 기본) --- */
.layout {
  display: grid;
  grid-template-columns: 380px 1fr; 
  grid-template-rows: auto 1fr;     
  gap: 24px;
  height: auto; 
  grid-template-areas: "question cards" "answer cards"; 
}

/* 설명 페이지 레이아웃 (PC 기본) */
.explanation-layout {
  grid-template-columns: 1fr;
  grid-template-rows: auto;
  grid-template-areas: "main-content";
}

#panel-question { grid-area: question; }
#panel-answer   { grid-area: answer; }
#panel-cards    { grid-area: cards; }

/* --- 패널 공통 --- */
.panel {
  background: rgba(255, 255, 255, 0.03);
  border-radius: 16px; padding: 24px;
  border: 1px solid rgba(255, 255, 255, 0.05);
  display: flex; flex-direction: column;
}

.panel-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 16px; flex-shrink: 0;
}
.panel-title { font-size: 1.1rem; font-weight: 700; color: #fff; margin: 0; letter-spacing: -0.01em; }
.panel-desc { font-size: 0.85rem; color: rgba(255, 255, 255, 0.6); margin-top: 6px; display: block; }

/* --- 1. 질문 패널 --- */
.topic-buttons {
  display: grid; grid-template-columns: repeat(3, 1fr); 
  gap: 10px; margin-bottom: 20px;
}
.btn-topic {
  padding: 14px; border-radius: 10px; border: 1px solid rgba(255,255,255,0.1);
  background: rgba(255,255,255,0.03); color: #ccc;
  font-size: 0.9rem; font-weight: 500; cursor: pointer; transition: all 0.2s;
  display: flex; align-items: center; justify-content: center; gap: 6px;
  text-align: center; line-height: 1.4; height: 100%;
}
.btn-topic:hover, .btn-topic.active {
  background: rgba(255, 255, 255, 0.15); color: #fff; border-color: rgba(255, 255, 255, 0.4);
}

.input-label {
  display: flex; margin-bottom: 10px; margin-top: 10px;
  font-size: 0.9rem; color: #f9c851; font-weight: 600; align-items: center; gap: 6px;
}

textarea {
  width: 100%; height: 90px; padding: 14px; font-size: 0.9rem;
  border-radius: 10px; border: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(0, 0, 0, 0.3); color: #fff; resize: none; line-height: 1.5;
  transition: border-color 0.2s, background 0.2s;
}
textarea:focus { outline: none; border-color: #f9c851; background: rgba(0, 0, 0, 0.5); }
textarea::placeholder { color: rgba(255,255,255,0.4); }

/* --- 2. 카드 패널 --- */
.card-panel { position: relative; height: auto; min-height: 600px; }
.control-group { display: flex; gap: 8px; }
.btn-ghost {
  background: transparent; border: 1px solid rgba(255,255,255,0.2);
  color: rgba(255,255,255,0.8); padding: 8px 14px; border-radius: 8px;
  font-size: 0.85rem; cursor: pointer; transition: all 0.2s; font-weight: 500;
}
.btn-ghost:hover { background: rgba(255,255,255,0.1); color: #fff; border-color: rgba(255,255,255,0.6); }

.card-grid-container {
  flex-grow: 1; overflow: visible; padding: 20px 0;
  display: flex; justify-content: center; align-items: flex-start;
}
.card-grid {
  display: flex; flex-wrap: wrap; justify-content: center; gap: 0;
  width: 100%; perspective: 1000px; 
}

.card {
  width: clamp(40px, 5vw, 70px); aspect-ratio: 5/8; 
  border-radius: 5px; cursor: pointer;
  background-color: transparent; 
  box-shadow: -3px 3px 10px rgba(0,0,0,0.4); margin: -0.7vw; position: relative;
  image-rendering: -webkit-optimize-contrast;
  transition: transform 0.6s cubic-bezier(0.23, 1, 0.32, 1);
  transform-style: preserve-3d;
}
.card:not(.picked):hover {
  transform: scale(1.3) translateY(-20px) !important;
  z-index: 100 !important;
  box-shadow: 0 15px 30px rgba(0,0,0,0.8); border: 1px solid rgba(255,255,255,0.9);
}
.card.flipping { transform: rotateY(90deg) scale(1.1) !important; pointer-events: none; }
.card.picked { 
  z-index: 50; box-shadow: 0 0 20px rgba(255, 215, 0, 0.5);
  border: 1px solid rgba(255, 215, 0, 0.7); cursor: default;
  transform: scale(1.15) !important;
}
.card.picked.reversed { transform: scale(1.2) rotate(180deg) !important; }

/* --- 3. 결과 패널 --- */
.answer-panel { min-height: 250px; }
#btn-share { display: flex; align-items: center; gap: 6px; }
#selected-cards-display { display: flex; justify-content: center; gap: 15px; margin-bottom: 20px; flex-wrap: wrap; }
#aiAnswer { font-size: 0.95rem; line-height: 1.7; white-space: pre-wrap; color: rgba(255,255,255,0.95); height: auto; }
.typing-cursor::after {
  content: '▋'; display: inline-block; vertical-align: bottom;
  animation: blink 1s infinite; color: #f9c851; margin-left: 2px; font-size: 0.9em;
}
@keyframes blink { 0%, 100% { opacity: 1; } 50% { opacity: 0; } }
.loading-text { color: #e0e0e0; font-style: italic; animation: pulse 1.5s infinite; font-weight: 300; }
@keyframes pulse { 0% { opacity: 0.5; } 50% { opacity: 1; } 100% { opacity: 0.5; } }
.error-message { color: #ff7e5f; }
.error-details { opacity: 0.8; }

/* 푸터 스타일 (기본) */
.footer {
  margin-top: 40px; padding-top: 20px;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  text-align: center; color: rgba(255, 255, 255, 0.4);
  font-size: 0.75rem; line-height: 1.6;
}
.hidden { display: none !important; }
#aiAnswer .answer-placeholder { opacity: 0.6; }
.copyright { margin-top: 8px; font-weight: 500; opacity: 0.8; }

/* 공유하기 캡처 영역 */
#share-capture-area {
  position: fixed; left: -9999px; top: 0; width: 540px; 
  background: radial-gradient(circle at top, #2b3250 0, #0c0f1f 100%);
  color: #fff; padding: 50px 40px; 
  display: flex; flex-direction: column; gap: 15px;
  font-family: "Pretendard", sans-serif; visibility: visible; z-index: 1000;
}
#share-header { text-align: center; }
#share-title { font-size: 2.2rem; font-weight: 700; color: #f9c851; margin: 0; letter-spacing: -0.02em; }
#share-date { font-size: 1rem; opacity: 0.6; margin-top: 8px; }
#share-cards { display: flex; justify-content: center; gap: 20px; padding: 15px 0; min-height: 120px; align-items: center; }
#share-cards img { width: 100px; height: 140px; border-radius: 8px; box-shadow: 0 8px 20px rgba(0,0,0,0.6); object-fit: contain; }
#share-cards img.reversed { transform: rotate(180deg); }
#share-topic { text-align: center; font-size: 1.3rem; font-weight: bold; color: #e0e0e0; }
#share-answer { 
  background: rgba(255,255,255,0.05); padding: 30px; border-radius: 20px; 
  font-size: 1.1rem; line-height: 1.7; white-space: pre-wrap; 
  border: 1px solid rgba(255,255,255,0.1);
}

/* 카드 모달 스타일 (공통) */
.card-modal {
  display: none; position: fixed; z-index: 1000; left: 0; top: 0;
  width: 100%; height: 100%; background-color: rgba(0, 0, 0, 0.8);
  backdrop-filter: blur(5px);
}
.card-modal.show { display: flex; align-items: center; justify-content: center; }
.modal-content {
  background: linear-gradient(135deg, #2b3250 0%, #0c0f1f 100%);
  border-radius: 20px; padding: 30px; text-align: center;
  border: 2px solid rgba(255, 255, 255, 0.1);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.8);
  max-width: 90%; max-height: 90%; position: relative;
}
.modal-card-img {
  width: 200px; height: 280px; border-radius: 10px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5); object-fit: contain;
  margin-bottom: 20px;
}
.modal-card-img.reversed { transform: rotate(180deg); }
.modal-card-name { color: #f9c851; font-size: 1.2rem; font-weight: 600; margin-bottom: 20px; text-transform: capitalize; }
.modal-close {
  background: rgba(255, 255, 255, 0.1); border: 1px solid rgba(255, 255, 255, 0.2);
  color: #fff; padding: 10px 20px; border-radius: 8px; cursor: pointer;
  font-size: 0.9rem; transition: all 0.2s;
}
.modal-close:hover { background: rgba(255, 255, 255, 0.2); border-color: rgba(255, 255, 255, 0.4); }

/* 선택된 카드 표시 스타일 */
.selected-card {
  display: flex; flex-direction: column; align-items: center;
  margin: 0 10px; cursor: pointer; transition: transform 0.2s;
}
.selected-card:hover { transform: scale(1.05); }
.selected-card img {
  width: 70px; height: 105px; border-radius: 6px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4); object-fit: contain;
}
.selected-card img.reversed { transform: rotate(180deg); }
.selected-card-name { font-size: 0.7rem; color: #f9c851; margin-top: 4px; text-align: center; font-weight: 500; line-height: 1.2; }

/* --- 카드 설명 목록 스타일 (cards_explanation.html) --- */
.card-category-nav {
  display: flex; flex-wrap: wrap; justify-content: center; gap: 10px;
  margin-bottom: 20px; margin-top: 10px;
}
.card-category-nav button {
  padding: 10px 18px; border-radius: 8px; border: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(255, 255, 255, 0.03); color: #ccc; font-size: 0.9rem; font-weight: 500;
  cursor: pointer; transition: all 0.2s; flex-shrink: 0;
}
.card-category-nav button:hover, .card-category-nav button.active {
  background: rgba(255, 255, 255, 0.15); color: #fff; border-color: rgba(255, 255, 255, 0.4);
}

#card-list-container {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 20px; padding: 10px; max-height: 70vh; overflow-y: auto; 
  scrollbar-width: thin; scrollbar-color: #f9c851 rgba(255, 255, 255, 0.1);
}
#card-list-container::-webkit-scrollbar { width: 8px; }
#card-list-container::-webkit-scrollbar-track { background: rgba(255, 255, 255, 0.1); border-radius: 10px; }
#card-list-container::-webkit-scrollbar-thumb { background-color: #f9c851; border-radius: 10px; border: 2px solid rgba(255, 255, 255, 0.1); }

.tarot-card-item {
  background: rgba(255, 255, 255, 0.05); border-radius: 12px; padding: 15px;
  display: flex; flex-direction: column; align-items: center; text-align: center;
  cursor: pointer; transition: all 0.2s; border: 1px solid rgba(255, 255, 255, 0.08);
}
.tarot-card-item:hover {
  background: rgba(255, 255, 255, 0.1); border-color: rgba(255, 255, 255, 0.2);
  transform: translateY(-5px); box-shadow: 0 8px 16px rgba(0, 0, 0, 0.4);
}
.tarot-card-item .card-image {
  width: 90px; height: 140px; object-fit: contain; border-radius: 8px;
  margin-bottom: 10px; box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
}
.tarot-card-item .card-info { flex-grow: 1; display: flex; flex-direction: column; justify-content: center; }
.tarot-card-item .card-korean-name { font-size: 1rem; font-weight: 700; color: #f9c851; margin: 0; margin-bottom: 2px; }
.tarot-card-item .card-english-name { font-size: 0.8rem; opacity: 0.7; margin: 0; margin-bottom: 8px; text-transform: capitalize; }
.tarot-card-item .card-summary { font-size: 0.85rem; opacity: 0.9; line-height: 1.4; margin: 0; }

/* 카드 설명 모달 스타일 */
#cardDetailModal .modal-content {
  max-width: 600px; max-height: 90%; overflow-y: auto; padding: 30px; text-align: left;
  scrollbar-width: thin; scrollbar-color: #f9c851 rgba(255, 255, 255, 0.1);
}
#cardDetailModal .modal-content::-webkit-scrollbar { width: 8px; }
#cardDetailModal .modal-content::-webkit-scrollbar-track { background: rgba(255, 255, 255, 0.1); border-radius: 10px; }
#cardDetailModal .modal-content::-webkit-scrollbar-thumb { background-color: #f9c851; border-radius: 10px; border: 2px solid rgba(255, 255, 255, 0.1); }

#modalDetailCardImg { display: block; margin: 0 auto 20px auto; width: 150px; height: auto; }
#modalDetailCardName { text-align: center; font-size: 1.5rem; margin-bottom: 15px; }
#modalDetailCardSummary {
  font-size: 1rem; line-height: 1.5; margin-bottom: 15px;
  background: rgba(255, 255, 255, 0.05); padding: 10px 15px;
  border-radius: 8px; border: 1px solid rgba(255, 255, 255, 0.1);
}
#modalDetailCardSummary strong { color: #f9c851; }
#modalDetailCardDescription {
  font-size: 0.95rem; line-height: 1.7; white-space: pre-line; word-break: keep-all;
  margin-bottom: 20px; opacity: 0.9;
}
#modalDetailCardKeywords {
  font-size: 0.85rem; opacity: 0.8;
  background: rgba(255, 255, 255, 0.05); padding: 10px 15px;
  border-radius: 8px; border: 1px solid rgba(255, 255, 255, 0.1);
}
#modalDetailCardKeywords strong { color: #f9c851; }

.footer-links { margin-top: 20px; padding-top: 15px; border-top: 1px solid rgba(255, 255, 255, 0.08); }
.footer-links .btn-ghost { display: inline-flex; align-items: center; gap: 5px; padding: 8px 16px; font-size: 0.9rem; }
.footer-links .btn-ghost::before { content: '←'; font-size: 1.2em; }


/* ==========================================================================
   [모바일 반응형 스타일]
   1. 일반 페이지 (메인): 자연스러운 스크롤 유지
   2. 설명 페이지 (.page-explanation): 화면 고정 및 내부 스크롤
   ========================================================================== */

@media (max-width: 900px) {
  /* --- 공통 모바일 설정 --- */
  body { padding: 0; align-items: flex-start; background: #0c0f1f; }
  
  /* 헤더 공통: 세로 정렬 */
  header { flex-direction: column; align-items: center; gap: 15px; }
  .header-content { text-align: center; margin-bottom: 10px; }
  .title-icon { height: 0.9em; margin: 0 6px; }
  .header-content h1 { font-size: 1.4rem; }
  .subtitle { font-size: 0.9rem; }

  /* -----------------------------------------------------
     [1] 메인 페이지 (index.html) - 일반 스크롤 모드
     ----------------------------------------------------- */
  .app-shell {
    min-height: 100vh;
    border-radius: 0; border: none; padding: 20px; box-shadow: none;
    /* 메인 페이지는 여기서 overflow: hidden을 주지 않음으로써 스크롤 허용 */
  }
  
  .layout {
    display: grid; grid-template-columns: 1fr;
    grid-template-rows: auto auto auto; gap: 24px; height: auto;
    grid-template-areas: "question" "cards" "answer";
  }
  
  /* 메인 페이지 패널 스타일 */
  .panel-header { flex-direction: column; align-items: flex-start; gap: 16px; }
  .control-group { width: 100%; display: flex; gap: 10px; }
  .control-group .btn-ghost { flex: 1; display: flex; justify-content: center; align-items: center; padding: 12px; }
  .card-panel { min-height: auto; padding: 24px 16px; }
  .card { width: clamp(45px, 11vw, 65px); margin: -1.5vw; }
  
  /* 메인 페이지 모달 */
  .modal-card-img { width: 150px; height: 210px; }


  /* -----------------------------------------------------
     [2] 설명 페이지 (cards-explanation.html) - 화면 고정 모드
     ----------------------------------------------------- */
  
  /* 전체 앱 틀: 화면 고정 */
  .page-explanation .app-shell {
    display: flex; flex-direction: column;
    height: 100vh; height: 100dvh; /* 화면 높이 고정 */
    padding: 10px 10px 0 10px !important;
    overflow: hidden; /* 전체 스크롤 막기 */
    box-sizing: border-box; border: none; border-radius: 0;
  }

  /* 헤더: 고정 */
  .page-explanation header { flex-shrink: 0; margin-bottom: 10px; }

  /* 중간 레이아웃 & 패널: 남은 공간 채우기 및 자름 */
  .page-explanation .explanation-layout, 
  .page-explanation .layout {
    flex: 1; display: flex !important; flex-direction: column;
    min-height: 0; margin: 0 !important; width: 100%; overflow: hidden;
  }
  .page-explanation .panel {
    flex: 1; display: flex !important; flex-direction: column;
    min-height: 0; padding: 0 !important;
    background: transparent !important; border: none !important; box-shadow: none !important;
    overflow: hidden; /* 자식 요소(리스트)가 넘치면 자름 */
  }
  
  /* 설명 페이지 패널 헤더 정렬 */
  .page-explanation .panel-header {
    align-items: center !important; text-align: center !important;
    justify-content: center; margin-top: 10px; flex-shrink: 0;
  }
  
  /* 카테고리 버튼 */
  .page-explanation .card-category-nav {
    flex-shrink: 0; padding: 0 10px 10px 10px; justify-content: center;
  }

  /* 카드 리스트: ★여기만 스크롤★ */
  .page-explanation #card-list-container {
    flex: 1; height: 100%; overflow-y: auto;
    display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
    gap: 12px; padding: 0 5px 20px 5px !important; margin: 0 !important;
    max-height: none !important;
  }

  /* 설명 페이지 푸터: 바닥 고정 */
  .page-explanation .footer {
    flex-shrink: 0; margin-top: 0; padding-top: 15px; padding-bottom: 15px;
    background: #0c0f1f; z-index: 50; border-top: 1px solid rgba(255, 255, 255, 0.1); width: 100%;
  }

  /* --- 설명 페이지 모달창 (팝업) 스타일 --- */
  #cardDetailModal .modal-content {
    width: 90% !important; max-width: 450px !important; max-height: 85%;
    padding: 25px 20px !important;
    overflow-y: auto; scrollbar-width: none; -ms-overflow-style: none;
  }
  #cardDetailModal .modal-content::-webkit-scrollbar { display: none; }

  #modalDetailCardKeywords {
    padding: 6px 10px !important; line-height: 1.3 !important;
    margin-bottom: 40px !important; font-size: 0.8rem !important;
  }
  .modal-close { margin-top: 10px !important; }

  /* 설명 페이지 카드 아이템 */
  .tarot-card-item { padding: 10px; }
  .tarot-card-item .card-image {
    width: 100%; height: auto; aspect-ratio: 5/8; max-width: 90px;
  }
  .tarot-card-item .card-korean-name { font-size: 0.9rem; }
  .tarot-card-item .card-english-name,
  .tarot-card-item .card-summary { font-size: 0.75rem; }
}