/* === CSS Variables === */
:root {
  --bg:         #f5efe2;
  --bg-deep:    #e8dcc6;
  --text:       #1e1a2e;
  --text-muted: #7a6e9a;
  --gold:       #8b6314;
  --gold-dim:   rgba(139, 99, 20, 0.2);
  --gold-glow:  rgba(139, 99, 20, 0.1);
  --border:     rgba(139, 99, 20, 0.28);
  --font-title: 'Cinzel', 'Noto Serif TC', Georgia, serif;
  --font-body:  'EB Garamond', 'Noto Serif TC', Georgia, 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 120% 55% at 50% -5%, rgba(255, 248, 225, 0.65) 0%, transparent 65%),
    radial-gradient(ellipse 80% 50% at 10% 80%, rgba(230, 218, 192, 0.4) 0%, transparent 60%),
    radial-gradient(ellipse 60% 40% at 90% 20%, rgba(245, 235, 210, 0.35) 0%, transparent 55%),
    radial-gradient(2px 2px at 12% 18%, rgba(139,99,20,0.2)  0%, transparent 100%),
    radial-gradient(1px 1px at 38% 8%,  rgba(30,26,46,0.12)  0%, transparent 100%),
    radial-gradient(2px 2px at 65% 22%, rgba(139,99,20,0.15) 0%, transparent 100%),
    radial-gradient(1px 1px at 82% 12%, rgba(30,26,46,0.1)   0%, transparent 100%),
    radial-gradient(1px 1px at 5%  55%, rgba(139,99,20,0.15) 0%, transparent 100%),
    radial-gradient(2px 2px at 91% 62%, rgba(30,26,46,0.08)  0%, transparent 100%),
    radial-gradient(1px 1px at 28% 78%, rgba(139,99,20,0.12) 0%, transparent 100%),
    radial-gradient(1px 1px at 55% 88%, rgba(30,26,46,0.1)   0%, transparent 100%),
    radial-gradient(2px 2px at 75% 83%, rgba(139,99,20,0.1)  0%, transparent 100%),
    radial-gradient(1px 1px at 18% 93%, rgba(30,26,46,0.08)  0%, transparent 100%),
    radial-gradient(1px 1px at 48% 45%, rgba(139,99,20,0.08) 0%, transparent 100%),
    radial-gradient(1px 1px at 88% 38%, rgba(30,26,46,0.07)  0%, transparent 100%);
  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: center;
}

.screen-inner {
  width: 100%;
  max-width: 430px;
  padding: 64px 28px 52px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 22px;
  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(139, 99, 20, 0.38);
  white-space: nowrap;
  pointer-events: none;
}

/* === 畫面 1：問題輸入 === */
#screen-question {
  overflow: hidden;
}

/* 大字水印（已移除） */

.screen-inner > * {
  position: relative;
  z-index: 1;
}

.prompt-label {
  font-family: var(--font-title);
  font-size: 14px;
  color: var(--text);
  text-align: center;
  line-height: 1.9;
  letter-spacing: 0.1em;
}

#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);
  padding: 10px 4px;
  resize: none;
  outline: none;
  transition: border-color 0.3s;
  line-height: 1.75;
  caret-color: var(--gold);
}
#question-input:focus {
  border-bottom-color: var(--gold);
}
#question-input::placeholder {
  color: rgba(107, 110, 154, 0.45);
  font-style: italic;
  font-size: 14px;
}

/* === 按鈕 === */
.btn-primary {
  width: 100%;
  max-width: 280px;
  padding: 14px 0;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 100px;
  color: var(--gold);
  font-size: 11.5px;
  font-family: var(--font-title);
  letter-spacing: 0.3em;
  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(139,99,20,0.1) 0%, transparent 70%);
  opacity: 0;
  transition: opacity 0.35s;
}
.btn-primary:hover {
  border-color: rgba(139, 99, 20, 0.65);
  box-shadow:
    0 0 18px rgba(139,99,20,0.12),
    inset 0 0 14px rgba(139,99,20,0.05);
}
.btn-primary:hover::before {
  opacity: 1;
}
.btn-primary:active {
  box-shadow: 0 0 26px rgba(139,99,20,0.2);
}

/* === 畫面 2：抽牌 === */
.draw-hint {
  font-family: var(--font-title);
  font-size: 10px;
  color: var(--text-muted);
  letter-spacing: 0.35em;
  text-align: center;
  text-transform: uppercase;
  opacity: 0;
  transition: opacity 0.5s;
}
.draw-hint.visible {
  opacity: 1;
}

.cards-container {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 18px;
  width: 100%;
  padding: 20px 0;
}

/* 每張牌的槽位（3D perspective 容器） */
.card-slot {
  perspective: 900px;
  width: 110px;
  height: 180px;
  cursor: pointer;
  flex-shrink: 0;
}
.card-inner {
  width: 100%;
  height: 100%;
  position: relative;
  transform-style: preserve-3d;
  transition: transform 0.7s cubic-bezier(0.4, 0, 0.2, 1);
}

/* 洗牌入場動畫 */
.card-slot:nth-child(1) .card-inner { animation: shuffle-1 0.9s ease both; }
.card-slot:nth-child(2) .card-inner { animation: shuffle-2 0.9s ease 0.12s both; }
.card-slot:nth-child(3) .card-inner { animation: shuffle-3 0.9s ease 0.24s both; }

@keyframes shuffle-1 {
  0%   { transform: translateX(-55px) rotate(-9deg); opacity: 0; filter: blur(4px); }
  100% { transform: translateX(0) rotate(0deg);      opacity: 1; filter: blur(0); }
}
@keyframes shuffle-2 {
  0%   { transform: translateY(-45px); opacity: 0; filter: blur(4px); }
  100% { transform: translateY(0);     opacity: 1; filter: blur(0); }
}
@keyframes shuffle-3 {
  0%   { transform: translateX(55px) rotate(9deg); opacity: 0; filter: blur(4px); }
  100% { transform: translateX(0) rotate(0deg);    opacity: 1; filter: blur(0); }
}

/* 翻牌：翻轉 card-inner */
.card-slot.flipped .card-inner {
  transform: rotateY(180deg);
}
/* 未選牌淡出 */
.card-slot.dimmed {
  opacity: 0.15;
  pointer-events: none;
  transition: opacity 0.4s;
}
/* 選中牌放大 */
.card-slot.selected .card-inner {
  transform: scale(1.06);
  transition: transform 0.3s;
}
.card-slot.selected.flipped .card-inner {
  transform: rotateY(180deg) scale(1.06);
}

/* 牌背 — 羊皮紙幾何風格 */
.card-back {
  position: absolute;
  width: 100%;
  height: 100%;
  backface-visibility: hidden;
  border-radius: 12px;
  overflow: hidden;
  background:
    radial-gradient(circle at 50% 50%, rgba(139,99,20,0.08) 0%, transparent 62%),
    var(--bg-deep);
  border: 1px solid rgba(139, 99, 20, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 12px rgba(0,0,0,0.08), 0 1px 4px rgba(0,0,0,0.05);
}

/* 斜線格紋底紋 */
.card-back::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 12px;
  background-image:
    repeating-linear-gradient(
      45deg,
      transparent 0px, transparent 9px,
      rgba(139,99,20,0.07) 9px, rgba(139,99,20,0.07) 10px
    ),
    repeating-linear-gradient(
      -45deg,
      transparent 0px, transparent 9px,
      rgba(139,99,20,0.07) 9px, rgba(139,99,20,0.07) 10px
    );
}

/* 內框 + 中心星符號 */
.card-back::after {
  content: '✦';
  position: relative;
  z-index: 1;
  color: rgba(139, 99, 20, 0.6);
  font-size: 24px;
  text-shadow: 0 1px 6px rgba(139,99,20,0.2);
  outline: 1px solid rgba(139, 99, 20, 0.18);
  outline-offset: 18px;
  border-radius: 50%;
}

/* 牌面（翻牌後顯示） */
.card-front {
  position: absolute;
  width: 100%;
  height: 100%;
  backface-visibility: hidden;
  transform: rotateY(180deg);
  border-radius: 12px;
  background:
    radial-gradient(circle at 50% 35%, rgba(139,99,20,0.1) 0%, transparent 60%),
    #ede4cf;
  border: 1px solid rgba(139, 99, 20, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 10px;
  box-shadow: 0 2px 12px rgba(0,0,0,0.08);
}
.card-front .card-name-mini {
  font-family: var(--font-title);
  font-size: 10px;
  color: rgba(139, 99, 20, 0.8);
  text-align: center;
  letter-spacing: 0.12em;
}

/* 發光效果（翻牌完成後） */
.card-slot.glowing .card-inner {
  filter:
    drop-shadow(0 0 14px rgba(139,99,20,0.22))
    drop-shadow(0 6px 20px rgba(0,0,0,0.12));
  transition: filter 0.6s ease-out;
}

/* === 畫面 4：結果頁 === */
.result-question {
  font-size: 13px;
  color: var(--text-muted);
  text-align: center;
  font-style: italic;
  line-height: 1.75;
  letter-spacing: 0.04em;
}

.result-card-image {
  width: 160px;
  height: 268px;
  border-radius: 14px;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid rgba(139, 99, 20, 0.35);
  box-shadow:
    0 0 30px rgba(139,99,20,0.1),
    0 8px 30px rgba(0,0,0,0.1);
}
.result-card-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* CSS placeholder 卡面 */
.card-placeholder {
  width: 100%;
  height: 100%;
  background:
    radial-gradient(circle at 50% 42%, rgba(139,99,20,0.09) 0%, transparent 60%),
    var(--bg-deep);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 16px;
  position: relative;
  overflow: hidden;
}
.card-placeholder::before {
  content: '';
  position: absolute;
  inset: 0;
  background-image:
    repeating-linear-gradient(
      45deg,
      transparent 0px, transparent 9px,
      rgba(139,99,20,0.055) 9px, rgba(139,99,20,0.055) 10px
    ),
    repeating-linear-gradient(
      -45deg,
      transparent 0px, transparent 9px,
      rgba(139,99,20,0.055) 9px, rgba(139,99,20,0.055) 10px
    );
}
.card-placeholder .placeholder-symbol {
  font-size: 36px;
  color: rgba(139, 99, 20, 0.58);
  text-shadow: 0 1px 8px rgba(139,99,20,0.18);
  position: relative;
  z-index: 1;
}
.card-placeholder .placeholder-name {
  font-family: var(--font-title);
  font-size: 11px;
  color: rgba(139, 99, 20, 0.7);
  text-align: center;
  letter-spacing: 0.14em;
  position: relative;
  z-index: 1;
}

.result-card-name {
  font-family: var(--font-title);
  font-size: 22px;
  font-weight: 400;
  letter-spacing: 0.28em;
  color: var(--gold);
  text-align: center;
}

.result-keywords {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
}
.keyword-tag {
  font-family: var(--font-title);
  font-size: 10.5px;
  color: rgba(139, 99, 20, 0.85);
  border: 1px solid rgba(139, 99, 20, 0.3);
  border-radius: 100px;
  padding: 4px 14px;
  letter-spacing: 0.12em;
  background: rgba(139, 99, 20, 0.06);
}

.divider {
  width: 80px;
  height: 1px;
  border: none;
  background: linear-gradient(to right, transparent, rgba(139,99,20,0.35), transparent);
  position: relative;
}
.divider::after {
  content: '✦';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 9px;
  color: rgba(139, 99, 20, 0.55);
  background: var(--bg);
  padding: 0 8px;
}

.result-reading {
  font-size: 15.5px;
  line-height: 1.95;
  color: var(--text);
  max-width: 360px;
  padding-left: 16px;
  border-left: 2px solid rgba(139, 99, 20, 0.28);
  text-align: left;
  align-self: flex-start;
  margin-left: auto;
  margin-right: auto;
}

.result-companion {
  font-size: 13.5px;
  color: var(--text-muted);
  text-align: center;
  font-style: italic;
  letter-spacing: 0.05em;
  line-height: 1.85;
}

/* === 結果頁入場動畫 === */
#screen-result.active .screen-inner {
  animation: result-fadein 0.6s ease both;
}
@keyframes result-fadein {
  from { opacity: 0; transform: translateY(18px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* === 桌面版置中 === */
@media (min-width: 480px) {
  body {
    display: flex;
    justify-content: center;
  }
  .screen {
    max-width: 430px;
    width: 430px;
  }
}
