:root {
  --bg-1: #0a0820;
  --bg-2: #1a1238;
  --accent: #a78bfa;
  --gold: #f7d774;
  --text: #f4f1ff;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: "Noto Sans TC", system-ui, sans-serif;
  color: var(--text);
  background: radial-gradient(circle at 20% 20%, #2a1b50 0%, var(--bg-1) 50%),
              linear-gradient(140deg, var(--bg-1), var(--bg-2));
  min-height: 100vh;
}

.bg-glow {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(circle at 70% 30%, rgba(167, 139, 250, 0.25), transparent 40%),
              radial-gradient(circle at 30% 70%, rgba(247, 215, 116, 0.15), transparent 45%);
}

.app { max-width: 1100px; margin: 0 auto; padding: 28px 18px 42px; position: relative; z-index: 1; }
header h1 { margin: 0; letter-spacing: .06em; }
header p { margin-top: 6px; opacity: .85; }

.controls {
  margin: 14px 0 18px;
  display: flex;
  gap: 12px;
  align-items: center;
}
button {
  border: 1px solid rgba(247, 215, 116, .5);
  background: rgba(247, 215, 116, .1);
  color: var(--gold);
  padding: 8px 14px;
  border-radius: 999px;
  cursor: pointer;
}
button:disabled {
  opacity: .55;
  cursor: not-allowed;
}

.deck {
  position: relative;
  height: 260px;
  border-radius: 14px;
  background: rgba(255,255,255,.04);
  border: 1px solid rgba(255,255,255,.12);
  overflow-x: auto;
  overflow-y: hidden;
  box-shadow: 0 10px 30px rgba(0,0,0,.35) inset;
}

.card {
  position: absolute;
  top: 30px;
  width: 120px;
  height: 190px;
  border-radius: 10px;
  border: 1px solid rgba(255,255,255,.2);
  background: linear-gradient(180deg, #231645, #160f2f);
  box-shadow: 0 10px 20px rgba(0,0,0,.4);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  color: rgba(255,255,255,.15);
  user-select: none;
  transition: transform .22s ease, top .22s ease, filter .22s ease, box-shadow .22s ease;
  will-change: transform, left, opacity;
  cursor: pointer;
  overflow: hidden;
}
.card-back {
  width: calc(100% - 8px);
  height: calc(100% - 8px);
  border-radius: 8px;
  background-image: url('./tarot.jpg');
  background-size: cover;
  background-position: center;
  border: 1px solid rgba(255,255,255,.35);
}
@media (hover: hover) and (pointer: fine) {
  .card:hover {
    top: 12px;
    transform: translateY(-8px) scale(1.03);
    filter: brightness(1.15);
    z-index: 120;
  }
}
.card.drawn {
  opacity: 0;
  pointer-events: none;
}
.card.selected {
  transform: translateY(-16px) scale(1.02);
  filter: brightness(1.16);
  /* 保持原本每張卡自己的 z-index，維持左邊壓右邊規則 */
  box-shadow: 0 0 0 2px rgba(247, 215, 116, .5), 0 10px 22px rgba(0,0,0,.4);
}

.drawn-area { margin-top: 18px; }
.drawn {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
}
.drawn-card {
  border: 1px solid rgba(247, 215, 116, .35);
  background: rgba(25,18,56,.75);
  border-radius: 12px;
  padding: 12px;
}
.drawn-card h4 { margin: 0 0 8px; color: var(--gold); }
.drawn-card-image-wrap {
  display: flex;
  justify-content: center;
  margin-bottom: 10px;
}
.drawn-card-image {
  width: min(100%, 180px);
  border-radius: 8px;
  border: 1px solid rgba(255,255,255,.22);
  box-shadow: 0 6px 14px rgba(0,0,0,.35);
  transition: transform .25s ease;
}
.drawn-card-image.reversed {
  transform: rotate(180deg);
}
.drawn-card p { margin: 0; opacity: .9; font-size: 14px; }
.drawn-card .orientation {
  margin-top: 8px;
  font-size: 12px;
  color: #d5c9ff;
  opacity: .9;
}

.ai-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
}
select {
  background: rgba(255,255,255,.08);
  border: 1px solid rgba(255,255,255,.2);
  color: var(--text);
  border-radius: 8px;
  padding: 6px 10px;
}
.question-box {
  margin: 8px 0 12px;
}
.question-box label {
  display: block;
  margin-bottom: 6px;
  opacity: .9;
  font-size: 13px;
}
.question-box textarea {
  width: 100%;
  min-height: 84px;
  resize: vertical;
  border-radius: 10px;
  border: 1px solid rgba(255,255,255,.2);
  background: rgba(255,255,255,.04);
  color: var(--text);
  padding: 10px;
  line-height: 1.5;
}
.question-count {
  margin-top: 4px;
  font-size: 12px;
  opacity: .75;
  text-align: right;
}

.ai-result { margin-top: 18px; }
.ai-box {
  border: 1px solid rgba(167, 139, 250, .5);
  background: rgba(14, 11, 33, .75);
  border-radius: 12px;
  padding: 14px;
  line-height: 1.75;
}
.ai-heading {
  color: var(--gold);
  font-weight: 700;
  margin: 10px 0 4px;
}
.disclaimer {
  opacity: .75;
  font-size: 12px;
  margin-top: 8px;
}
.flow-hint { opacity: .8; margin: 6px 0 10px; font-size: 14px; }

.reveal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(5, 4, 14, .97);
  z-index: 5000;
  display: grid;
  place-items: center;
  padding: 14px;
  overscroll-behavior: none;
}
.reveal-panel {
  width: min(1100px, 96vw);
  max-height: min(88vh, 900px);
  border: 1px solid rgba(255,255,255,.18);
  border-radius: 14px;
  background: rgba(18, 13, 42, .92);
  padding: 14px;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}
.reveal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.close-btn {
  width: 34px;
  height: 34px;
  border-radius: 999px;
  border: 1px solid rgba(255,255,255,.35);
  background: rgba(255,255,255,.08);
  color: #fff;
  font-size: 18px;
  line-height: 1;
  padding: 0;
}
.reveal-row {
  margin-top: 10px;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}
.reveal-card {
  border: 1px solid rgba(255,255,255,.15);
  border-radius: 12px;
  background: rgba(255,255,255,.03);
  padding: 10px;
  transition: transform .2s ease;
}
.reveal-card.active { transform: scale(1.06); z-index: 2; }
.reveal-card-inner {
  position: relative;
  width: 100%;
  aspect-ratio: 2 / 3;
  transform-style: preserve-3d;
  transition: transform .55s ease;
  cursor: pointer;
}
.reveal-card-inner[data-open="1"] { transform: rotateY(180deg); }
.reveal-face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid rgba(255,255,255,.2);
}
.reveal-face img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.reveal-front { transform: rotateY(180deg); }
.reveal-front img.reversed { transform: rotate(180deg); }
.reveal-meta { margin-top: 8px; }
.reveal-meta h4 { margin: 0; color: var(--gold); }
.reveal-meta .muted { margin: 3px 0 0; opacity: .75; font-size: 12px; }
.reveal-desc { margin-top: 8px; font-size: 13px; line-height: 1.55; }

body.overlay-open .reveal-overlay {
  pointer-events: auto;
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.6);
  display: grid;
  place-items: center;
  z-index: 20;
}
.hidden { display: none; }
.modal-card {
  width: min(90vw, 460px);
  background: #120d2a;
  border: 1px solid rgba(247, 215, 116, .35);
  border-radius: 14px;
  padding: 16px;
}
.modal-card h3 { margin: 0 0 10px; color: var(--gold); }
.modal-card p { margin: 0 0 14px; line-height: 1.6; }
