:root {
  /* 달빛 점집 — 딥 인디고 + 크림 + 촛불빛 앰버 */
  --bg-0: #070a1c;
  --bg-1: #0f1430;
  --bg-2: #1a2148;
  --gold: #edcb8b;        /* 촛불빛 (액센트/골드테마) */
  --gold-soft: #d8ac5f;
  --purple: #33417e;      /* 인디고 (탭/포인트) */
  --purple-light: #8b98db;/* 은은한 남보라 */
  --ink: #f5efe0;         /* 따뜻한 크림 텍스트 */
  --ink-dim: #b1accb;
  --card-face: linear-gradient(160deg, #232a55, #131836);
  --card-back: repeating-linear-gradient(45deg, #262e5c 0 8px, #1b2146 8px 16px);
  --shadow: 0 12px 42px rgba(3,5,20,.6);
  --radius: 16px;
  --font-hand: "Nanum Pen Script", "Gaegu", cursive;
  --font-serif: "Nanum Myeongjo", serif;
}

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

body {
  font-family: "Pretendard", "Apple SD Gothic Neo", "Malgun Gothic", -apple-system, sans-serif;
  background: radial-gradient(1100px 800px at 50% -20%, #202a5e 0%, #10152f 55%, #070a1c 100%);
  color: var(--ink);
  min-height: 100vh;
  overflow-x: hidden;
  position: relative;
}

/* 밤하늘의 달 */
body::before {
  content: "";
  position: fixed;
  top: 34px;
  right: 8%;
  width: 150px;
  height: 150px;
  border-radius: 50%;
  background: radial-gradient(circle at 38% 36%, #fdf7e6 0%, #f2e6c4 55%, #e7d5a6 72%, rgba(231,213,166,0) 78%);
  box-shadow: 0 0 70px 24px rgba(244,236,214,.22), 0 0 150px 60px rgba(237,203,139,.12);
  opacity: .92;
  z-index: 0;
  pointer-events: none;
}
/* 한지(종이) 질감 오버레이 */
body::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  opacity: .05;
  mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

/* 반짝이는 별 배경 (은은하게) */
.stars {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image:
    radial-gradient(1.5px 1.5px at 20% 30%, #fdf6e0cc, transparent),
    radial-gradient(1.5px 1.5px at 70% 20%, #fdf6e099, transparent),
    radial-gradient(2px 2px at 40% 70%, #f2dca588, transparent),
    radial-gradient(1px 1px at 85% 60%, #fdf6e0aa, transparent),
    radial-gradient(1.5px 1.5px at 10% 80%, #fdf6e077, transparent),
    radial-gradient(1px 1px at 55% 45%, #fdf6e099, transparent),
    radial-gradient(2px 2px at 90% 90%, #f2dca566, transparent);
  animation: twinkle 6s ease-in-out infinite alternate;
  z-index: 0;
}
@keyframes twinkle { from { opacity: .45; } to { opacity: .9; } }

.app-header, .tabs, main, .app-footer { position: relative; z-index: 1; }

.app-header {
  text-align: center;
  padding: 32px 16px 12px;
}
.logo {
  font-family: var(--font-hand);
  font-size: 52px;
  font-weight: 400;
  letter-spacing: 2px;
  color: var(--gold);
  text-shadow: 0 0 22px rgba(237,203,139,.5), 0 2px 6px rgba(0,0,0,.4);
  line-height: 1.1;
}
.tagline {
  font-family: var(--font-serif);
  color: #e6dcc4;
  margin-top: 4px;
  font-size: 15px;
  letter-spacing: .5px;
}

/* 탭 */
.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  padding: 16px;
  max-width: 720px;
  margin: 0 auto;
}
.tab {
  background: rgba(255,255,255,.04);
  border: 1px solid rgba(232,200,116,.25);
  color: var(--ink-dim);
  padding: 10px 16px;
  border-radius: 999px;
  cursor: pointer;
  font-size: 14px;
  transition: all .2s ease;
}
.tab:hover { color: var(--ink); border-color: var(--gold-soft); }
.tab.active {
  background: linear-gradient(135deg, var(--purple), var(--purple-light));
  color: #fff;
  border-color: transparent;
  box-shadow: 0 6px 20px rgba(109,63,184,.5);
}

main {
  max-width: 860px;
  margin: 0 auto;
  padding: 16px 16px 60px;
  min-height: 50vh;
}

/* 뷰 공통 */
.view-title { font-family: var(--font-serif); font-weight: 800; text-align: center; font-size: 23px; margin-bottom: 6px; color: var(--gold); }
.view-sub { text-align: center; color: var(--ink-dim); font-size: 14px; margin-bottom: 22px; }

.btn {
  display: inline-block;
  background: linear-gradient(135deg, var(--gold-soft), var(--gold));
  color: #2a1a52;
  border: none;
  padding: 13px 28px;
  border-radius: 999px;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  transition: transform .15s ease, box-shadow .2s ease;
  box-shadow: 0 6px 18px rgba(232,200,116,.35);
}
.btn:hover { transform: translateY(-2px); box-shadow: 0 10px 26px rgba(232,200,116,.5); }
.btn:active { transform: translateY(0); }
.btn.ghost {
  background: transparent;
  border: 1px solid rgba(232,200,116,.4);
  color: var(--gold);
  box-shadow: none;
}
.center { text-align: center; }
.mt { margin-top: 22px; }

/* 카드 */
.card {
  width: 160px;
  height: 268px;
  border-radius: var(--radius);
  position: relative;
  perspective: 1000px;
  cursor: pointer;
  flex: 0 0 auto;
}
.card-inner {
  position: relative;
  width: 100%;
  height: 100%;
  transition: transform .7s cubic-bezier(.2,.8,.2,1);
  transform-style: preserve-3d;
}
.card.flipped .card-inner { transform: rotateY(180deg); }

.card-face, .card-back-face {
  position: absolute;
  inset: 0;
  border-radius: var(--radius);
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  box-shadow: var(--shadow);
}
.card-back-face {
  background: var(--card-back);
  border: 2px solid var(--gold-soft);
  display: flex;
  align-items: center;
  justify-content: center;
}
.card-back-face::after {
  content: "✦";
  font-size: 42px;
  color: var(--gold);
  text-shadow: 0 0 12px rgba(232,200,116,.6);
}
.card-face {
  transform: rotateY(180deg);
  background: var(--card-face);
  border: 2px solid var(--gold-soft);
  overflow: hidden;
}
/* 실제 카드 이미지 */
.card-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  z-index: 0;
  transition: filter .3s ease;
}
.card-face.reversed .card-img { transform: rotate(180deg); }

/* 하단 이름 캡션 (이미지 위에 오버레이) */
.card-caption {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  z-index: 2;
  padding: 16px 8px 8px;
  font-size: 13px;
  font-weight: 700;
  color: #fff;
  text-align: center;
  background: linear-gradient(to top, rgba(10,5,25,.92), rgba(10,5,25,0));
  text-shadow: 0 1px 3px #000;
}
.card-caption .rev-tag {
  display: inline-block;
  margin-left: 4px;
  font-size: 10px;
  color: #ffb3c4;
}

/* 이미지 로드 실패 시 이모지 폴백 */
.card-fallback {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 12px;
  text-align: center;
}
.card-face.no-img .card-fallback { display: flex; }
.card-face.no-img.reversed .card-fallback { transform: rotate(180deg); }
.card-fallback .card-symbol { font-size: 58px; line-height: 1; filter: drop-shadow(0 0 10px rgba(232,200,116,.4)); }
.card-fallback .card-name { font-size: 15px; font-weight: 700; color: var(--ink); }
.card-fallback .card-en { font-size: 10px; color: var(--ink-dim); }

.cards-row {
  display: flex;
  gap: 18px;
  justify-content: center;
  flex-wrap: wrap;
  margin: 18px 0;
}

/* 결과 해석 박스 */
.reading {
  background: rgba(255,255,255,.035);
  border: 1px solid rgba(232,200,116,.2);
  border-radius: var(--radius);
  padding: 18px 20px;
  margin: 14px auto;
  max-width: 640px;
  animation: fadeUp .5s ease both;
}
.reading h3 { color: var(--gold); font-size: 17px; margin-bottom: 4px; }
.reading .pos { color: var(--purple-light); font-size: 13px; margin-bottom: 8px; }
.reading .orient { font-size: 13px; margin-bottom: 8px; }
.reading .orient.up { color: #9be6a0; }
.reading .orient.down { color: #ff9bb0; }
.reading p { color: var(--ink-dim); line-height: 1.65; font-size: 14px; }
.reading .kw { color: var(--ink); }
@keyframes fadeUp { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }

/* 질문하고 뽑기 — 쉬운 해석 박스 */
.q-reading-box { text-align: left; }
.q-reading-box h3 { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.q-quote {
  color: var(--ink);
  font-style: italic;
  background: rgba(255,255,255,.05);
  border-left: 3px solid var(--gold-soft);
  padding: 8px 12px;
  border-radius: 8px;
  margin: 10px 0 4px;
  font-size: 14px;
}
.q-section { margin-top: 14px; }
.q-label { font-size: 13px; font-weight: 700; color: var(--purple-light); margin-bottom: 5px; }
.q-label.light { color: var(--gold); }
.q-plain { color: var(--ink-dim); line-height: 1.6; font-size: 14px; }
.q-answer {
  margin-top: 14px;
  background: linear-gradient(160deg, rgba(109,63,184,.22), rgba(232,200,116,.08));
  border: 1px solid rgba(232,200,116,.35);
  border-radius: 12px;
  padding: 14px 16px;
}
.q-answer p { color: var(--ink); line-height: 1.75; font-size: 15px; }
.q-note { margin-top: 12px; font-size: 12px; color: var(--ink-dim); opacity: .8; }

/* 질문 입력 */
.q-input {
  width: 100%;
  max-width: 480px;
  padding: 14px 18px;
  border-radius: 14px;
  border: 1px solid rgba(232,200,116,.3);
  background: rgba(255,255,255,.05);
  color: var(--ink);
  font-size: 15px;
  margin: 0 auto 18px;
  display: block;
}
.q-input::placeholder { color: var(--ink-dim); }
.q-input:focus { outline: none; border-color: var(--gold); }
.q-echo {
  text-align: center;
  color: var(--ink);
  font-style: italic;
  margin-bottom: 6px;
}

/* 도감 그리드 */
.lib-filters {
  display: flex;
  gap: 8px;
  justify-content: center;
  flex-wrap: wrap;
  margin-bottom: 18px;
}
.chip {
  background: rgba(255,255,255,.04);
  border: 1px solid rgba(232,200,116,.25);
  color: var(--ink-dim);
  padding: 7px 14px;
  border-radius: 999px;
  cursor: pointer;
  font-size: 13px;
}
.chip.active { background: var(--purple); color: #fff; border-color: transparent; }

.lib-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
  gap: 12px;
}
.lib-card {
  background: var(--card-face);
  border: 1px solid rgba(232,200,116,.3);
  border-radius: 12px;
  padding: 12px 6px;
  text-align: center;
  cursor: pointer;
  transition: transform .15s ease, box-shadow .2s ease;
}
.lib-card:hover { transform: translateY(-4px); box-shadow: 0 8px 22px rgba(0,0,0,.5); border-color: var(--gold); }
.lib-thumb {
  position: relative;
  width: 100%;
  aspect-ratio: 3 / 5;
  border-radius: 8px;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}
.lib-thumb img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.lib-thumb .s { font-size: 32px; display: none; }
.lib-thumb.no-img .s { display: block; }
.lib-card .n { font-size: 11px; margin-top: 6px; color: var(--ink); }

/* 모달 */
.modal { position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center; padding: 20px; }
.modal.hidden { display: none; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(6,3,18,.7); backdrop-filter: blur(4px); }
.modal-body {
  position: relative;
  background: linear-gradient(160deg, #202750, #10152f);
  border: 1px solid var(--gold-soft);
  border-radius: 20px;
  padding: 28px 24px;
  max-width: 420px;
  width: 100%;
  text-align: center;
  box-shadow: var(--shadow);
  animation: fadeUp .35s ease both;
}
.modal-img-wrap {
  width: 180px;
  aspect-ratio: 3 / 5;
  margin: 0 auto 6px;
  border-radius: 12px;
  overflow: hidden;
  border: 2px solid var(--gold-soft);
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--card-face);
}
.modal-img-wrap img { width: 100%; height: 100%; object-fit: cover; }
.modal-body .big-symbol { font-size: 72px; filter: drop-shadow(0 0 14px rgba(232,200,116,.4)); display: none; }
.modal-img-wrap.no-img .big-symbol { display: block; }
.modal-body h2 { color: var(--gold); margin: 8px 0 2px; }
.modal-body .en { color: var(--ink-dim); font-size: 13px; margin-bottom: 16px; }
.modal-body .row { text-align: left; margin: 10px 0; }
.modal-body .row .label { color: var(--purple-light); font-size: 13px; font-weight: 700; }
.modal-body .row .val { color: var(--ink-dim); font-size: 14px; line-height: 1.6; }
.modal-close {
  margin-top: 18px;
}

.app-footer {
  text-align: center;
  color: var(--ink-dim);
  font-size: 12px;
  padding: 20px 16px 40px;
  opacity: .8;
}

/* 디자인 전환 버튼 */
.theme-switch {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 14px;
  padding: 6px 8px;
  background: rgba(255,255,255,.04);
  border: 1px solid rgba(232,200,116,.2);
  border-radius: 999px;
}
.theme-label { font-size: 12px; color: var(--ink-dim); margin-right: 2px; }
.theme-btn {
  background: transparent;
  border: 1px solid rgba(232,200,116,.3);
  color: var(--ink-dim);
  padding: 5px 12px;
  border-radius: 999px;
  cursor: pointer;
  font-size: 12px;
  transition: all .2s ease;
}
.theme-btn:hover { color: var(--ink); border-color: var(--gold-soft); }
.theme-btn.active {
  background: linear-gradient(135deg, var(--purple), var(--purple-light));
  color: #fff;
  border-color: transparent;
}

/* ============ 카드 디자인 테마 ============ */
/* 공통: 이미지 위 색감 오버레이 (캡션은 z-index 2로 위에 유지) */
.card-face::after,
.lib-thumb::after,
.modal-img-wrap::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
}
.lib-thumb { position: relative; }
.lib-thumb img { z-index: 0; }
.lib-thumb .s { position: relative; z-index: 2; }
.modal-img-wrap { position: relative; }
.modal-img-wrap img { position: relative; z-index: 0; }
.modal-img-wrap .big-symbol { position: relative; z-index: 2; }

/* ── 1. 골드 프리미엄 (기본) ── */
body.theme-premium .card-img,
body.theme-premium .lib-thumb img,
body.theme-premium .modal-img-wrap img {
  filter: saturate(1.22) contrast(1.08) brightness(1.03);
}
body.theme-premium .card-face {
  border: 3px solid var(--gold);
  box-shadow: inset 0 0 0 1px rgba(232,200,116,.4), 0 12px 36px rgba(0,0,0,.55), 0 0 22px rgba(232,200,116,.3);
}
/* 은은한 비네팅으로 그림에 깊이감 부여 */
body.theme-premium .card-face::after {
  background: radial-gradient(135% 100% at 50% 22%, transparent 50%, rgba(16,7,36,.42) 100%);
}
body.theme-premium .lib-thumb { border-radius: 8px; box-shadow: inset 0 0 0 1px rgba(232,200,116,.4); }
body.theme-premium .modal-img-wrap { border: 3px solid var(--gold); box-shadow: 0 0 22px rgba(232,200,116,.3); }

/* ── 2. 파스텔 드림 ── */
body.theme-pastel .card-img,
body.theme-pastel .lib-thumb img,
body.theme-pastel .modal-img-wrap img {
  filter: brightness(1.12) saturate(.82) contrast(.92);
}
body.theme-pastel .card-face::after,
body.theme-pastel .lib-thumb::after,
body.theme-pastel .modal-img-wrap::after {
  background: linear-gradient(150deg, rgba(255,182,214,.28), rgba(190,170,255,.28));
  mix-blend-mode: soft-light;
}
body.theme-pastel .card-face {
  border: 3px solid #f3c6dd;
  box-shadow: 0 10px 30px rgba(180,140,220,.35), 0 0 20px rgba(243,198,221,.5);
}
body.theme-pastel .lib-thumb { border-radius: 10px; box-shadow: inset 0 0 0 2px #f3c6dd; }
body.theme-pastel .modal-img-wrap { border: 3px solid #f3c6dd; box-shadow: 0 0 24px rgba(243,198,221,.55); }
body.theme-pastel .card-back-face { border-color: #f3c6dd; }

/* ── 3. 다크 네온 미스틱 ── */
body.theme-neon .card-img,
body.theme-neon .lib-thumb img,
body.theme-neon .modal-img-wrap img {
  filter: saturate(1.35) contrast(1.12) brightness(.94);
}
body.theme-neon .card-face::after,
body.theme-neon .lib-thumb::after,
body.theme-neon .modal-img-wrap::after {
  background:
    radial-gradient(120% 100% at 50% 0%, rgba(166,120,232,.18), transparent 55%),
    radial-gradient(120% 100% at 50% 110%, rgba(20,8,40,.55), transparent 60%);
}
body.theme-neon .card-face {
  border: 2px solid var(--purple-light);
  box-shadow: 0 0 20px rgba(166,120,232,.65), 0 0 42px rgba(166,120,232,.35), inset 0 0 12px rgba(166,120,232,.25);
}
body.theme-neon .lib-thumb { border-radius: 8px; box-shadow: 0 0 14px rgba(166,120,232,.5), inset 0 0 0 1px var(--purple-light); }
body.theme-neon .modal-img-wrap { border: 2px solid var(--purple-light); box-shadow: 0 0 26px rgba(166,120,232,.7); }
body.theme-neon .card-back-face { border-color: var(--purple-light); box-shadow: 0 0 18px rgba(166,120,232,.5); }
body.theme-neon .card-caption { background: linear-gradient(to top, rgba(20,6,45,.95), transparent); }

/* ============ 프리미엄 마감 (모든 테마 공통) ============ */
/* 카드 표면 유리 광택 — 좌상단에서 떨어지는 부드러운 하이라이트 */
.card-face::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  border-radius: var(--radius);
  background: linear-gradient(125deg, rgba(255,255,255,.24) 0%, rgba(255,255,255,.06) 18%, transparent 42%);
  mix-blend-mode: screen;
}
/* 카드에 입체 그림자 + 부유감, 호버 시 살짝 밝아짐 */
.card { filter: drop-shadow(0 16px 30px rgba(0,0,0,.5)); }
.card-inner { transition: transform .7s cubic-bezier(.2,.8,.2,1), filter .25s ease; }
.card:hover .card-inner { filter: brightness(1.05) saturate(1.05); }

/* 도감 썸네일 & 모달에도 동일한 유리 광택 */
.lib-thumb::before, .modal-img-wrap::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  background: linear-gradient(125deg, rgba(255,255,255,.18), transparent 42%);
}
.lib-card { transition: transform .18s ease, box-shadow .2s ease; }
.lib-card:hover { transform: translateY(-5px) scale(1.03); }

/* 모달 상세 이미지 조금 더 크게 */
.modal-img-wrap { width: 210px; }

/* 고급스러운 카드 뒷면 — 이중 금테 + 중앙 광채 */
.card-back-face {
  background:
    radial-gradient(circle at 50% 50%, rgba(232,200,116,.14), transparent 62%),
    var(--card-back);
  box-shadow: var(--shadow), inset 0 0 0 4px rgba(11,6,26,.6), inset 0 0 0 5px rgba(232,200,116,.35);
}
.card-back-face::after {
  text-shadow: 0 0 16px rgba(232,200,116,.75);
}

/* 반응형 */
@media (max-width: 480px) {
  .logo { font-size: 24px; }
  .card { width: 128px; height: 214px; }
  .card-symbol { font-size: 46px; }
  .cards-row { gap: 10px; }
  .theme-switch { flex-wrap: wrap; justify-content: center; }
  .modal-img-wrap { width: 170px; }
}
