/* ========== 基本設定 ========== */
:root {
  --bg: #0b0c18;
  --surface: #1b1e38;
  --gold: #c9a86a;
  --gold-bright: #e8cf9b;
  --text: #e9e7f2;
  --text-dim: #9a97b3;
  --card-ratio: 420 / 250;
}

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

html { -webkit-text-size-adjust: 100%; }

body {
  font-family: "Noto Sans JP", sans-serif;
  font-weight: 300;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}

button { font-family: inherit; }

.hidden { display: none !important; }

/* ========== シーン ========== */
.scene {
  position: fixed;
  inset: 0;
  overflow: hidden;
}

/* 部屋 */
.room {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse 90% 60% at 50% 18%, #262a52 0%, #14152c 55%, #0b0c18 100%);
}

.bg-stars {
  position: absolute;
  inset: 0;
  background-image:
    radial-gradient(1px 1px at 20% 20%, rgba(255,255,255,.55) 0, transparent 100%),
    radial-gradient(1px 1px at 68% 10%, rgba(255,255,255,.4) 0, transparent 100%),
    radial-gradient(1.5px 1.5px at 84% 30%, rgba(255,255,255,.35) 0, transparent 100%),
    radial-gradient(1px 1px at 38% 34%, rgba(255,255,255,.3) 0, transparent 100%),
    radial-gradient(1px 1px at 10% 42%, rgba(255,255,255,.4) 0, transparent 100%),
    radial-gradient(1.5px 1.5px at 54% 6%, rgba(255,255,255,.35) 0, transparent 100%),
    radial-gradient(1px 1px at 92% 14%, rgba(255,255,255,.45) 0, transparent 100%);
  animation: twinkle 6s ease-in-out infinite alternate;
}

@keyframes twinkle {
  from { opacity: .45; }
  to   { opacity: 1; }
}

.moon-glow {
  position: absolute;
  left: 50%;
  top: 8%;
  width: 60vmin;
  height: 60vmin;
  transform: translateX(-50%);
  background: radial-gradient(circle, rgba(160,150,230,.14) 0%, transparent 65%);
  pointer-events: none;
}

.curtain {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 18vw;
  pointer-events: none;
}

.curtain-left {
  left: 0;
  background: linear-gradient(90deg, rgba(8,8,18,.92) 0%, rgba(16,14,36,.5) 55%, transparent 100%);
}

.curtain-right {
  right: 0;
  background: linear-gradient(-90deg, rgba(8,8,18,.92) 0%, rgba(16,14,36,.5) 55%, transparent 100%);
}

/* ロゴ */
.site-header {
  position: absolute;
  top: 18px;
  left: 0;
  right: 0;
  text-align: center;
  z-index: 5;
  pointer-events: none;
}

.logo {
  font-family: "Cormorant Garamond", serif;
  font-weight: 600;
  font-size: 1.15rem;
  letter-spacing: .55em;
  text-indent: .55em;
  color: var(--gold);
  opacity: .85;
}

/* ========== 占い師 ========== */
.teller {
  position: absolute;
  left: 50%;
  bottom: 24vh;
  width: min(64vh, 88vw);
  transform: translateX(-50%);
  z-index: 1;
  animation: breathe 5.5s ease-in-out infinite;
  transform-origin: 50% 100%;
}

.teller svg { display: block; width: 100%; }

@keyframes breathe {
  0%, 100% { transform: translateX(-50%) scale(1); }
  50%      { transform: translateX(-50%) scale(1.012, 1.02); }
}

/* 水晶玉 */
.crystal {
  position: absolute;
  left: 50%;
  bottom: 27vh;
  width: 9vmin;
  height: 9vmin;
  transform: translateX(-50%);
  border-radius: 50%;
  background:
    radial-gradient(circle at 34% 30%, rgba(255,255,255,.75) 0%, rgba(210,200,255,.28) 22%, rgba(120,110,220,.22) 55%, rgba(50,45,120,.4) 100%);
  box-shadow:
    0 0 24px rgba(150,140,255,.45),
    0 0 60px rgba(120,110,230,.25),
    inset 0 -6px 14px rgba(20,15,60,.6);
  z-index: 2;
  animation: crystalPulse 4s ease-in-out infinite;
}

@keyframes crystalPulse {
  0%, 100% { box-shadow: 0 0 24px rgba(150,140,255,.45), 0 0 60px rgba(120,110,230,.25), inset 0 -6px 14px rgba(20,15,60,.6); }
  50%      { box-shadow: 0 0 36px rgba(170,160,255,.65), 0 0 90px rgba(130,120,240,.35), inset 0 -6px 14px rgba(20,15,60,.6); }
}

/* キャンドル */
.candle {
  position: absolute;
  bottom: 26vh;
  width: 2.2vmin;
  z-index: 2;
}

.candle-left  { left: calc(50% - min(30vh, 40vw)); }
.candle-right { right: calc(50% - min(30vh, 40vw)); }

.wax {
  width: 100%;
  height: 9vmin;
  background: linear-gradient(180deg, #e8ddc4, #c9bb98 60%, #a8996f);
  border-radius: 3px 3px 2px 2px;
}

.flame {
  width: 1.4vmin;
  height: 2.6vmin;
  margin: 0 auto -0.4vmin;
  background: radial-gradient(ellipse at 50% 75%, #fff5d0 0%, #ffc95e 45%, #ff8c2e 80%, transparent 100%);
  border-radius: 50% 50% 45% 45% / 65% 65% 35% 35%;
  filter: blur(.4px);
  animation: flicker 2.2s ease-in-out infinite;
  box-shadow: 0 0 18px rgba(255,180,80,.55), 0 0 46px rgba(255,150,50,.22);
}

.candle-right .flame { animation-delay: -1.1s; }

@keyframes flicker {
  0%, 100% { transform: scale(1) rotate(-2deg); opacity: .95; }
  25%      { transform: scale(1.08, .94) rotate(2deg); }
  50%      { transform: scale(.94, 1.06) rotate(-1deg); opacity: .85; }
  75%      { transform: scale(1.04, .97) rotate(1.5deg); }
}

/* ========== テーブル(3D) ========== */
.table3d {
  position: absolute;
  left: 50%;
  bottom: 0;
  width: min(150vh, 100vw);
  height: 30vh;
  transform: translateX(-50%);
  perspective: 780px;
  perspective-origin: 50% -60%;
  z-index: 3;
}

.table-top {
  position: absolute;
  inset: 0;
  transform: rotateX(48deg);
  transform-origin: 50% 100%;
  transform-style: preserve-3d;
  background:
    radial-gradient(ellipse 75% 90% at 50% 30%, rgba(120,90,200,.14) 0%, transparent 70%),
    linear-gradient(180deg, #221f48 0%, #191635 55%, #131028 100%);
  border-radius: 46% 46% 0 0 / 16% 16% 0 0;
  border-top: 2px solid rgba(201,168,106,.5);
  box-shadow: 0 -8px 40px rgba(0,0,0,.5), inset 0 10px 60px rgba(0,0,0,.35);
}

/* テーブル上のカード */
.card-slot {
  position: absolute;
  bottom: 34%;
  transform-style: preserve-3d;
}

.table-card {
  display: block;
  width: var(--tcard-w, 62px);
  aspect-ratio: 250 / 420;
  border: none;
  background: transparent;
  padding: 0;
  cursor: pointer;
  border-radius: 6px;
  box-shadow: 2px 4px 10px rgba(0,0,0,.55);
  transition: transform .22s ease, opacity .45s ease, box-shadow .22s ease;
  animation: dealIn .5s cubic-bezier(.2,.7,.3,1) backwards;
}

.table-card svg { display: block; width: 100%; height: 100%; border-radius: 6px; }

.card-slot:hover .table-card:not(.picked),
.table-card:focus-visible:not(.picked) {
  transform: translateY(-26px);
  box-shadow: 2px 14px 22px rgba(0,0,0,.6), 0 0 18px rgba(201,168,106,.28);
  outline: none;
}

.table-card.picked {
  opacity: 0;
  pointer-events: none;
  transform: translateY(-90px) scale(1.05);
}

@keyframes dealIn {
  from { opacity: 0; transform: translateY(-140px); }
  to   { opacity: 1; transform: none; }
}

/* ========== セリフ ========== */
.dialog {
  position: absolute;
  top: 9vh;
  left: 50%;
  transform: translateX(-50%);
  width: min(680px, 92vw);
  text-align: center;
  z-index: 6;
  pointer-events: none;
}

.teller-line {
  font-size: clamp(.95rem, 2.4vmin, 1.25rem);
  letter-spacing: .22em;
  line-height: 2;
  color: var(--text);
  text-shadow: 0 2px 12px rgba(0,0,0,.8);
  min-height: 2.4em;
}

.teller-line::after {
  content: "";
  display: inline-block;
  width: .5em;
}

.draw-counter {
  margin-top: 10px;
  font-size: .8rem;
  letter-spacing: .3em;
  color: var(--gold-bright);
  min-height: 1.4em;
}

/* ========== スプレッド選択 ========== */
.choices {
  position: absolute;
  left: 50%;
  bottom: 8vh;
  transform: translateX(-50%);
  display: flex;
  gap: 22px;
  z-index: 7;
  animation: fadeUp .6s ease both;
}

@keyframes fadeUp {
  from { opacity: 0; transform: translateX(-50%) translateY(16px); }
  to   { opacity: 1; transform: translateX(-50%); }
}

.plaque {
  min-width: 190px;
  padding: 18px 26px;
  background: linear-gradient(165deg, rgba(35,38,74,.92), rgba(20,21,44,.92));
  border: 1px solid rgba(201,168,106,.45);
  border-radius: 10px;
  color: var(--text);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: center;
  backdrop-filter: blur(4px);
  transition: transform .22s ease, border-color .22s ease, box-shadow .22s ease;
}

.plaque:hover,
.plaque:focus-visible {
  transform: translateY(-3px);
  border-color: var(--gold);
  box-shadow: 0 10px 28px rgba(0,0,0,.5), 0 0 22px rgba(201,168,106,.15);
  outline: none;
}

.plaque-title {
  font-size: 1rem;
  font-weight: 500;
  letter-spacing: .35em;
  text-indent: .35em;
  color: var(--gold-bright);
}

.plaque-sub {
  font-size: .72rem;
  letter-spacing: .1em;
  color: var(--text-dim);
}

/* ========== 悩みジャンル選択 ========== */
.genre-box {
  position: absolute;
  left: 50%;
  bottom: 8vh;
  transform: translateX(-50%);
  width: min(640px, 94vw);
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  justify-content: center;
  z-index: 7;
  animation: fadeUp .6s ease both;
}

.genre-btn {
  min-width: 108px;
  padding: 14px 20px;
  font-family: inherit;
  font-size: .88rem;
  font-weight: 500;
  letter-spacing: .2em;
  text-indent: .2em;
  color: var(--text);
  background: linear-gradient(165deg, rgba(35,38,74,.92), rgba(20,21,44,.92));
  border: 1px solid rgba(201,168,106,.45);
  border-radius: 10px;
  cursor: pointer;
  backdrop-filter: blur(4px);
  transition: transform .22s ease, border-color .22s ease, box-shadow .22s ease;
}

.genre-btn:hover,
.genre-btn:focus-visible {
  transform: translateY(-3px);
  border-color: var(--gold);
  box-shadow: 0 10px 28px rgba(0,0,0,.5), 0 0 22px rgba(201,168,106,.15);
  outline: none;
}

.genre-icon {
  display: block;
  font-size: 1.05rem;
  color: var(--gold-bright);
  margin-bottom: 6px;
  text-indent: 0;
  letter-spacing: 0;
}

/* ========== 占い師の見立て(AI鑑定) ========== */
.oracle-box {
  max-width: 640px;
  margin: 0 auto 4vh;
  padding: 24px 28px;
  background: linear-gradient(160deg, rgba(32,35,68,.9), rgba(18,19,40,.9));
  border: 1px solid rgba(201,168,106,.35);
  border-radius: 14px;
  animation: fadeInUp .6s ease both;
}

@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(14px); }
  to   { opacity: 1; transform: none; }
}

.oracle-label {
  text-align: center;
  font-size: .8rem;
  letter-spacing: .35em;
  text-indent: .35em;
  color: var(--gold-bright);
  margin-bottom: 14px;
}

.oracle-text {
  font-size: .9rem;
  line-height: 2.1;
  color: var(--text);
  letter-spacing: .04em;
  white-space: pre-wrap;
}

.oracle-text.loading {
  text-align: center;
  color: var(--text-dim);
  animation: oraclePulse 1.8s ease-in-out infinite;
}

@keyframes oraclePulse {
  0%, 100% { opacity: .45; }
  50%      { opacity: 1; }
}

/* ========== 結果オーバーレイ ========== */
.reveal-layer {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: rgba(6,7,16,.88);
  backdrop-filter: blur(6px);
  overflow-y: auto;
  padding: 6vh 16px 8vh;
  animation: fadeIn .6s ease both;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.reveal-title {
  text-align: center;
  font-weight: 400;
  font-size: 1.2rem;
  letter-spacing: .5em;
  text-indent: .5em;
  color: var(--gold-bright);
  margin-bottom: 4vh;
}

.result-area {
  display: flex;
  justify-content: center;
  gap: 30px;
  flex-wrap: wrap;
  max-width: 1000px;
  margin: 0 auto 4vh;
}

.result-slot {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  width: min(290px, 100%);
}

.slot-label {
  font-size: .8rem;
  letter-spacing: .4em;
  text-indent: .4em;
  color: var(--gold-bright);
}

.slot-note {
  font-size: .68rem;
  letter-spacing: .12em;
  color: var(--text-dim);
  margin-top: -6px;
  min-height: 1em;
}

/* フリップ */
.flip-card {
  width: min(158px, 40vw);
  aspect-ratio: 250 / 420;
  perspective: 1000px;
  cursor: pointer;
  background: none;
  border: none;
  padding: 0;
}

.flip-inner {
  position: relative;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  transition: transform .9s cubic-bezier(.4, .1, .2, 1);
}

.flip-card.flipped .flip-inner { transform: rotateY(180deg); }

.flip-face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 10px 30px rgba(0,0,0,.55);
}

.flip-face svg { display: block; width: 100%; height: 100%; }

.flip-front { transform: rotateY(180deg); }

.flip-front .card-rot { width: 100%; height: 100%; }
.flip-front .card-rot.reversed { transform: rotate(180deg); }

.flip-card.flipped:hover .flip-inner { transform: rotateY(180deg) translateY(-4px); }

.tap-hint {
  font-size: .72rem;
  color: var(--text-dim);
  letter-spacing: .18em;
  min-height: 1.2em;
}

/* 解説 */
.card-reading {
  opacity: 0;
  transform: translateY(8px);
  transition: opacity .5s ease .15s, transform .5s ease .15s;
  background: linear-gradient(160deg, rgba(32,35,68,.9), rgba(18,19,40,.9));
  border: 1px solid rgba(201,168,106,.28);
  border-radius: 12px;
  padding: 18px 20px;
  width: 100%;
}

.result-slot.revealed .card-reading { opacity: 1; transform: none; }

.reading-position {
  display: inline-block;
  font-size: .7rem;
  letter-spacing: .15em;
  padding: 3px 10px;
  border-radius: 999px;
  margin-bottom: 10px;
}

.reading-position.upright {
  color: var(--gold-bright);
  border: 1px solid rgba(201,168,106,.5);
}

.reading-position.reversed {
  color: #b9a6e8;
  border: 1px solid rgba(150,120,220,.5);
}

.reading-keywords {
  font-size: .8rem;
  color: var(--gold-bright);
  letter-spacing: .06em;
  margin-bottom: 8px;
}

.reading-text {
  font-size: .85rem;
  line-height: 1.9;
  color: var(--text);
}

.result-summary {
  text-align: center;
  color: var(--text-dim);
  font-size: .88rem;
  letter-spacing: .12em;
  line-height: 2.1;
  max-width: 560px;
  margin: 0 auto 4vh;
  min-height: 1.8em;
}

.btn-primary {
  display: block;
  margin: 0 auto;
  padding: 14px 48px;
  font-size: .9rem;
  letter-spacing: .25em;
  text-indent: .25em;
  color: #1a1508;
  font-weight: 500;
  background: linear-gradient(180deg, var(--gold-bright), var(--gold));
  border: none;
  border-radius: 999px;
  cursor: pointer;
  transition: all .25s ease;
}

.btn-primary:hover,
.btn-primary:focus-visible {
  box-shadow: 0 0 28px rgba(201,168,106,.4);
  transform: translateY(-2px);
  outline: none;
}

/* ========== レスポンシブ ========== */
@media (max-width: 640px) {
  .teller { bottom: 30vh; width: min(56vh, 96vw); }
  .crystal { bottom: 32vh; }
  .candle { bottom: 31vh; }
  .candle-left { left: 6vw; }
  .candle-right { right: 6vw; }
  .table3d { height: 36vh; }
  .choices { flex-direction: column; gap: 12px; bottom: 6vh; }
  .plaque { min-width: 220px; padding: 14px 22px; }
  .result-area { gap: 20px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    transition-duration: .01ms !important;
  }
}
