/* === CSS Variables === */
:root {
  --bg:          #FDF6EE;
  --bg-deep:     #F2E4D0;
  --text:        #3D2B1F;
  --text-muted:  #A07860;
  --accent:      #C17B5C;
  --accent-dim:  rgba(193,123,92,0.18);
  --accent-glow: rgba(193,123,92,0.28);
  --border:      rgba(193,123,92,0.25);
  --font-title:  'Cormorant Garamond', 'Noto Serif TC', Georgia, serif;
  --font-body:   'DM Sans', 'Noto Serif TC', sans-serif;
}

/* === Reset & Base === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
}

/* 柔和日光背景 */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  background:
    radial-gradient(ellipse 130% 60% at 50% -10%, rgba(255,235,210,0.7) 0%, transparent 60%),
    radial-gradient(ellipse 80% 60% at 5%  90%,  rgba(240,210,185,0.4) 0%, transparent 55%),
    radial-gradient(ellipse 60% 50% at 95% 15%,  rgba(255,245,225,0.4) 0%, transparent 50%);
  pointer-events: none;
  z-index: 0;
}

/* === 畫面容器 === */
.screen {
  display: none;
  min-height: 100vh;
  width: 100%;
  position: relative;
  z-index: 1;
}
.screen.active {
  display: flex;
  justify-content: center;
  align-items: flex-start;
}

.screen-inner {
  width: 100%;
  max-width: 480px;
  padding: 64px 28px 52px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  position: relative;
}

/* 頂部小標題 */
.screen-inner::before {
  content: '✦  TAROT  ✦';
  position: absolute;
  top: 22px;
  left: 50%;
  transform: translateX(-50%);
  font-family: var(--font-title);
  font-size: 9px;
  letter-spacing: 0.55em;
  color: rgba(193,123,92,0.38);
  white-space: nowrap;
  pointer-events: none;
}

.screen-inner > * { position: relative; z-index: 1; }

/* === 畫面 1：問題輸入 === */
.prompt-label {
  font-family: var(--font-title);
  font-size: 16px;
  font-style: italic;
  color: var(--text);
  text-align: center;
  line-height: 1.85;
  letter-spacing: 0.04em;
}

#question-input {
  width: 100%;
  background: transparent;
  border: none;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  font-size: 15px;
  font-family: var(--font-body);
  font-weight: 300;
  padding: 10px 4px;
  resize: none;
  outline: none;
  transition: border-color 0.3s;
  line-height: 1.75;
  caret-color: var(--accent);
}
#question-input:focus { border-bottom-color: var(--accent); }
#question-input::placeholder {
  color: rgba(160,120,96,0.45);
  font-style: italic;
  font-size: 14px;
}

/* === 按鈕 === */
.btn-primary {
  width: 100%;
  max-width: 260px;
  padding: 13px 0;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 100px;
  color: var(--accent);
  font-size: 11px;
  font-family: var(--font-title);
  letter-spacing: 0.35em;
  cursor: pointer;
  transition: border-color 0.3s, box-shadow 0.3s;
  position: relative;
  overflow: hidden;
}
.btn-primary::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 100px;
  background: radial-gradient(ellipse at center, rgba(193,123,92,0.1) 0%, transparent 70%);
  opacity: 0;
  transition: opacity 0.35s;
}
.btn-primary:hover {
  border-color: rgba(193,123,92,0.6);
  box-shadow: 0 0 18px rgba(193,123,92,0.12), inset 0 0 12px rgba(193,123,92,0.05);
}
.btn-primary:hover::before { opacity: 1; }
.btn-primary:active { box-shadow: 0 0 24px rgba(193,123,92,0.2); }
.btn-primary:disabled { opacity: 0.45; cursor: not-allowed; }

/* === 畫面 2：抽牌 === */
.draw-hint {
  font-family: var(--font-title);
  font-size: 11px;
  font-style: italic;
  color: var(--text-muted);
  letter-spacing: 0.15em;
  text-align: center;
  opacity: 0;
  transition: opacity 0.5s;
  position: absolute;
  top: 52px;
  left: 50%;
  transform: translateX(-50%);
  white-space: nowrap;
}
.draw-hint.visible { opacity: 1; }

.draw-counter {
  font-family: var(--font-body);
  font-size: 11px;
  font-weight: 300;
  color: var(--text-muted);
  letter-spacing: 0.15em;
  position: absolute;
  top: 76px;
  left: 50%;
  transform: translateX(-50%);
  white-space: nowrap;
}

/* 滑動容器（用於遮罩定位） */
#draw-scroll-wrapper {
  position: relative;
  width: calc(100vw - 0px);
  max-width: 100vw;
  margin-left: calc(-28px);
  margin-right: calc(-28px);
}

/* 左右漸層遮罩 */
#draw-scroll-wrapper::before,
#draw-scroll-wrapper::after {
  content: '';
  position: absolute;
  top: 0; bottom: 0;
  width: 48px;
  pointer-events: none;
  z-index: 2;
}
#draw-scroll-wrapper::before {
  left: 0;
  background: linear-gradient(to right, var(--bg) 30%, transparent);
}
#draw-scroll-wrapper::after {
  right: 0;
  background: linear-gradient(to left, var(--bg) 30%, transparent);
}

/* 可滑動牌列 */
.cards-container {
  display: flex;
  align-items: center;
  gap: 12px;
  overflow-x: auto;
  overflow-y: visible;
  padding: 48px 48px;
  -webkit-overflow-scrolling: touch;
  scroll-behavior: smooth;
  /* 隱藏 scrollbar */
  scrollbar-width: none;
  -ms-overflow-style: none;
}
.cards-container::-webkit-scrollbar { display: none; }

/* 每張牌的槽位 */
.card-slot {
  flex-shrink: 0;
  perspective: 700px;
  cursor: pointer;
  position: relative;
  animation: card-slide-in 0.45s cubic-bezier(0.25, 0.46, 0.45, 0.94) both;
}

@keyframes card-slide-in {
  0%   { transform: translateX(80px); opacity: 0; }
  60%  { opacity: 1; }
  100% { transform: translateX(0); opacity: 1; }
}

.card-inner {
  width: 88px;
  height: 144px;
  position: relative;
  transform-style: preserve-3d;
  transition: transform 0.7s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Hover 上浮 */
.card-slot:not(.chosen):hover .card-inner {
  transform: translateY(-12px) scale(1.06);
  filter: drop-shadow(0 10px 18px rgba(193,123,92,0.32));
  transition: transform 0.18s cubic-bezier(0.34,1.56,0.64,1), filter 0.18s ease;
}

/* 翻牌 */
.card-slot.flipped .card-inner  { transform: rotateY(180deg); }
.card-slot.chosen.flipped:hover .card-inner { transform: rotateY(180deg); }

/* 未選中（選完 3 張後） */
.card-slot.unchosen {
  opacity: 0.1;
  pointer-events: none;
  transition: opacity 0.5s ease;
}

/* 牌背 — 陶土暖色 */
.card-back {
  position: absolute;
  width: 100%;
  height: 100%;
  backface-visibility: hidden;
  border-radius: 14px;
  overflow: hidden;
  background:
    radial-gradient(circle at 50% 45%, rgba(193,123,92,0.12) 0%, transparent 65%),
    var(--bg-deep);
  border: 1px solid rgba(193,123,92,0.38);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 10px rgba(0,0,0,0.07);
}
.card-back::before {
  content: '';
  position: absolute;
  inset: 0;
  background-image:
    radial-gradient(circle, rgba(193,123,92,0.1) 1px, transparent 1px);
  background-size: 13px 13px;
}
.card-back::after {
  content: '✦';
  position: relative;
  z-index: 1;
  color: rgba(193,123,92,0.55);
  font-size: 18px;
  outline: 1px solid rgba(193,123,92,0.2);
  outline-offset: 14px;
}

/* 牌面 */
.card-front {
  position: absolute;
  width: 100%;
  height: 100%;
  backface-visibility: hidden;
  transform: rotateY(180deg);
  border-radius: 14px;
  overflow: visible;
  border: 1px solid rgba(193,123,92,0.38);
}
.card-front img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  border-radius: 14px;
}

/* 選取標籤（翻開後顯示） */
.pick-badge {
  position: absolute;
  bottom: -30px;
  left: 50%;
  transform: translateX(-50%);
  font-family: var(--font-title);
  font-size: 11px;
  font-style: italic;
  letter-spacing: 0.08em;
  color: var(--accent);
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  animation: badge-in 0.3s 0.5s ease both;
  background: rgba(193,123,92,0.10);
  border: 1px solid var(--border);
  border-radius: 100px;
  padding: 3px 10px;
}
@keyframes badge-in {
  to { opacity: 1; }
}

/* 發光效果 */
.card-slot.glowing .card-inner {
  filter: drop-shadow(0 0 8px rgba(193,123,92,0.55))
          drop-shadow(0 0 18px rgba(193,123,92,0.35))
          drop-shadow(0 8px 20px rgba(0,0,0,0.15));
  transition: filter 0.6s ease-out, transform 0.7s cubic-bezier(0.4, 0, 0.2, 1);
}

/* 粒子 */
.particle {
  position: absolute;
  top: 35%;
  left: 50%;
  font-size: 10px;
  color: var(--accent);
  pointer-events: none;
  z-index: 10;
  animation: particle-float 0.8s ease-out both;
}
@keyframes particle-float {
  0%   { transform: translate(-50%, 0) scale(1); opacity: 1; }
  100% { transform: translate(calc(-50% + var(--dx)), var(--dy)) scale(0.3); opacity: 0; }
}

/* === 畫面 3：結果頁 === */
#screen-result.active { align-items: flex-start; }

.result-question {
  font-size: 13px;
  color: var(--text-muted);
  text-align: center;
  font-family: var(--font-title);
  font-style: italic;
  line-height: 1.75;
  letter-spacing: 0.04em;
}

.result-cards {
  display: flex;
  flex-direction: column;
  gap: 36px;
  width: 100%;
}

.result-card-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  opacity: 0;
  transform: translateY(20px);
  animation: section-enter 0.5s ease both;
}
.result-card-section:nth-child(1) { animation-delay: 0.1s; }
.result-card-section:nth-child(2) { animation-delay: 0.3s; }
.result-card-section:nth-child(3) { animation-delay: 0.5s; }

@keyframes section-enter {
  to { opacity: 1; transform: translateY(0); }
}

.result-position {
  font-family: var(--font-title);
  font-size: 10px;
  font-style: italic;
  letter-spacing: 0.3em;
  color: var(--text-muted);
}

.result-card-image {
  width: 130px;
  height: 216px;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--border);
  box-shadow: 0 0 24px rgba(193,123,92,0.1), 0 8px 24px rgba(0,0,0,0.08);
}
.result-card-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.result-card-name {
  font-family: var(--font-title);
  font-size: 20px;
  font-weight: 400;
  letter-spacing: 0.18em;
  color: var(--accent);
  text-align: center;
  display: flex;
  align-items: center;
  gap: 8px;
}

.orientation-badge {
  font-family: var(--font-body);
  font-size: 11px;
  font-weight: 300;
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: 100px;
  padding: 2px 10px;
  letter-spacing: 0.05em;
}

.result-reading {
  font-size: 15px;
  line-height: 2;
  color: var(--text);
  font-weight: 300;
  max-width: 340px;
  padding-left: 14px;
  border-left: 2px solid var(--border);
  text-align: left;
  align-self: flex-start;
  margin: 0 auto;
}

/* 分隔線 */
.divider {
  width: 60px;
  height: 1px;
  border: none;
  background: linear-gradient(to right, transparent, var(--border), transparent);
  position: relative;
}
.divider::after {
  content: '✦';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 8px;
  color: var(--text-muted);
  background: var(--bg);
  padding: 0 8px;
}

.result-summary {
  font-family: var(--font-title);
  font-size: 14.5px;
  font-style: italic;
  line-height: 2.1;
  color: var(--text-muted);
  text-align: center;
  max-width: 290px;
}

/* === 抽牌畫面：垂直置中 === */
#screen-draw.active {
  align-items: center;
}

#screen-draw .screen-inner {
  min-height: 100dvh;
  justify-content: center;
  padding: 0;
  gap: 0;
}

/* === 桌面版置中 === */
@media (min-width: 520px) {
  body { display: flex; justify-content: center; }
  .screen { max-width: 480px; width: 480px; }
  #draw-scroll-wrapper {
    width: calc(480px + 56px);
    margin-left: -28px;
    margin-right: -28px;
  }
}
