/* ==========================================================
   POWER CARD｜N°112 關係樂園 RELATOPIA
   版面概念：一張紙、一張牌。所有東西沿中軸排列，牌是唯一主角。
   ========================================================== */
:root {
  color-scheme: light;
  --paper: #F4F1EA;      /* 奶油白 */
  --paper-deep: #ECE6DA; /* 暖象牙（陰影、分隔） */
  --wine: #7A1B1D;       /* 暗酒紅 */
  --ink: #2A2524;        /* 深咖黑 */
  --ink-soft: #6B605B;   /* 次要文字 */
  --gold: #C8A66A;       /* 霧金 */
  --gold-faint: rgba(200, 166, 106, .28);

  --f-latin: "Cormorant Garamond", "Noto Serif TC", Georgia, serif;
  --f-zh: "Noto Serif TC", "Songti TC", "PMingLiU", serif;

  --card-w: min(86vw, 360px);
  --ease: cubic-bezier(.22, .61, .36, 1);
  --ease-flip: cubic-bezier(.45, .05, .25, 1);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
html { -webkit-text-size-adjust: 100%; }

body {
  background: var(--paper);
  color: var(--ink);
  font-family: var(--f-zh);
  font-size: 16px;
  line-height: 1.8;
  overflow-x: hidden;
  min-height: 100%;
  -webkit-font-smoothing: antialiased;
}

/* 紙張纖維＋極淡底片顆粒 */
body::before {
  content: "";
  position: fixed; inset: 0;
  pointer-events: none;
  z-index: 0;
  opacity: .5;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='220' height='220'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 .42  0 0 0 0 .34  0 0 0 0 .26  0 0 0 .10 0'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
}

.page {
  position: relative; z-index: 1;
  max-width: 640px;
  margin: 0 auto;
  padding-inline: 20px;
  padding-block: 28px 0;
  display: flex; flex-direction: column; align-items: center;
}

img { max-width: 100%; display: block; }
button { font: inherit; color: inherit; }

.logo { width: 92px; height: auto; }

/* ---------- 細線裝飾 ---------- */
.rule {
  display: flex; align-items: center; gap: 10px;
  width: 140px; color: var(--gold);
}
.rule::before, .rule::after { content: ""; flex: 1; height: 1px; background: currentColor; opacity: .7; }
.rule span { font-size: 9px; line-height: 1; }

/* =========================================================
   STEP 1｜進入畫面
   ========================================================= */
.intro {
  width: 100%;
  min-height: calc(100svh - 28px);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 18px;
  text-align: center;
  padding-block: 8px 40px;
}
.intro[hidden] { display: none !important; }

.deck-peek {
  position: relative;
  width: 104px; aspect-ratio: 2 / 3;
  margin-block: 6px 4px;
}
.deck-peek img {
  position: absolute; inset: 0; width: 100%; height: 100%;
  object-fit: cover; border-radius: 6px;
  box-shadow: 0 10px 24px -14px rgba(42, 37, 36, .55);
}
.deck-peek img:nth-child(1) { transform: rotate(-9deg) translate(-14px, 4px); opacity: .55; }
.deck-peek img:nth-child(2) { transform: rotate(7deg) translate(12px, 2px); opacity: .75; }
.deck-peek img:nth-child(3) { transform: rotate(-1deg); }

.eyebrow {
  font-family: var(--f-latin);
  font-size: 15px; letter-spacing: .42em; text-indent: .42em;
  color: var(--wine);
  margin: 0;
}
.intro h1 {
  margin: 0;
  font-weight: 500;
  font-size: clamp(26px, 7.4vw, 34px);
  line-height: 1.4;
  letter-spacing: .08em;
  color: var(--wine);
  text-wrap: balance;
}
.lede {
  margin: 0;
  font-size: 16px; line-height: 1.95;
  color: var(--ink);
  letter-spacing: .04em;
}
.prompt {
  margin: 0;
  font-size: 13.5px; line-height: 1.9;
  color: var(--ink-soft);
  letter-spacing: .06em;
}

/* ---------- 按鈕 ---------- */
.btn {
  appearance: none; border: 0; cursor: pointer;
  min-height: 52px;
  padding: 0 34px;
  border-radius: 999px;
  font-size: 16px; letter-spacing: .12em;
  transition: transform .3s var(--ease), box-shadow .3s var(--ease), background-color .3s var(--ease);
  -webkit-tap-highlight-color: transparent;
}
.btn:focus-visible { outline: 2px solid var(--gold); outline-offset: 4px; }
.btn-primary {
  background: var(--wine); color: var(--paper);
  box-shadow: 0 10px 24px -14px rgba(122, 27, 29, .9), inset 0 0 0 1px rgba(200, 166, 106, .45);
}
.btn-primary:hover { transform: translateY(-2px); }
.btn-ghost {
  background: transparent; color: var(--wine);
  box-shadow: inset 0 0 0 1px var(--gold);
  min-height: 46px; font-size: 15px; padding: 0 22px;
}
.btn-ghost:hover { background: rgba(200, 166, 106, .1); }
.btn-text {
  background: none; border: 0; cursor: pointer;
  min-height: 44px; padding: 0 12px;
  color: var(--ink-soft); font-size: 14px; letter-spacing: .1em;
  text-decoration: underline; text-decoration-color: var(--gold-faint); text-underline-offset: 6px;
}
.btn-text:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; border-radius: 4px; }

/* =========================================================
   抽牌舞台
   ========================================================= */
.draw {
  width: 100%;
  overflow-x: clip;
  display: flex; flex-direction: column; align-items: center;
  padding-block: 4px 0;
}
.draw[hidden] { display: none !important; }

.draw-head { display: flex; flex-direction: column; align-items: center; gap: 8px; margin-bottom: 18px; }
.draw-head .logo { width: 62px; }

.stage {
  position: relative;
  width: var(--card-w);
  aspect-ratio: 2 / 3;
  max-width: 100%;
  /* 桌機／矮螢幕時避免牌卡超出畫面 */
  max-height: calc((100svh - 150px));
  perspective: 1600px;
}
@supports (height: 100svh) {
  .stage { width: min(var(--card-w), calc((100svh - 150px) * 2 / 3)); }
}

/* 金色光暈 */
.glow {
  position: absolute; inset: -18% -22%;
  background: radial-gradient(closest-side, rgba(200, 166, 106, .32), rgba(200, 166, 106, .10) 55%, transparent 75%);
  opacity: 0; transform: scale(.9);
  transition: opacity 1.6s var(--ease), transform 1.6s var(--ease);
  pointer-events: none;
}
.stage.is-revealed .glow { opacity: 1; transform: scale(1); }

/* 洗牌用的 20 張牌背（洗完後攤開，讓使用者自己選一張） */
.fan { position: absolute; inset: 0; pointer-events: none; z-index: 2; }
.fan.is-spread { pointer-events: auto; }
.fan-card {
  position: absolute; left: 50%; top: 50%;
  width: 44%; aspect-ratio: 2 / 3;
  margin-left: -22%; margin-top: -33%;
  padding: 0; border: 0; cursor: pointer;
  border-radius: 5px;
  background: var(--wine) center / cover no-repeat;
  box-shadow: 0 8px 18px -12px rgba(42, 37, 36, .7), 0 0 0 1px rgba(200, 166, 106, .25);
  transform: translate(var(--x, 0px), calc(var(--y, 0px) + var(--lift, 0px))) rotate(var(--r, 0deg)) scale(var(--s, 1));
  will-change: transform, opacity;
  -webkit-tap-highlight-color: transparent;
}
.fan.is-spread .fan-card {
  transition: transform .75s var(--ease), opacity .45s var(--ease), box-shadow .3s var(--ease);
  transition-delay: var(--d, 0ms), 0ms, 0ms;
}
.fan.is-picking .fan-card { transition-delay: 0ms; }
.fan-card:focus-visible { outline: 2px solid var(--gold); outline-offset: 3px; }
@media (hover: hover) {
  .fan.is-spread:not(.is-picking) .fan-card:hover { --lift: -6px; box-shadow: 0 14px 22px -12px rgba(42, 37, 36, .75), 0 0 0 1px rgba(200, 166, 106, .6); }
}
.fan-card.is-out { opacity: 0; pointer-events: none; }

/* 被選中的那張（飛到中央後翻面） */
.chosen {
  position: absolute; inset: 0; z-index: 3;
  opacity: 0; pointer-events: none;
  transform-style: preserve-3d;
}
.chosen.is-ready { opacity: 1; }

.flipper {
  position: absolute; inset: 0;
  transform-style: preserve-3d;
  transition: transform .82s var(--ease-flip);
}
.chosen.is-flipped .flipper { transform: rotateY(180deg); }

.face {
  position: absolute; inset: 0;
  backface-visibility: hidden; -webkit-backface-visibility: hidden;
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 22px 40px -26px rgba(42, 37, 36, .65), 0 2px 6px -2px rgba(42, 37, 36, .18);
}
.face img { width: 100%; height: 100%; object-fit: contain; background: var(--paper); }
.face-back img { object-fit: cover; }
.face-front { transform: rotateY(180deg); }

.tap-hint {
  margin: 20px 0 0;
  min-height: 1.8em;
  font-size: 14px; letter-spacing: .14em;
  color: var(--ink-soft);
  text-align: center;
  opacity: 0;
  transition: opacity .8s var(--ease);
}
.tap-hint.is-on { opacity: 1; }

/* =========================================================
   抽牌結果
   ========================================================= */
.result {
  width: 100%; max-width: 30em;
  display: flex; flex-direction: column; align-items: center;
  text-align: center;
  gap: 0;
  opacity: 0; transform: translateY(10px);
  transition: opacity 1s var(--ease), transform 1s var(--ease);
}
.result[hidden] { display: none !important; }
.result.is-on { opacity: 1; transform: none; }

.drawn-label {
  margin: 4px 0 6px;
  font-size: 13px; letter-spacing: .2em; color: var(--ink-soft);
}
.drawn-cat {
  margin: 0;
  font-family: var(--f-latin);
  font-size: 19px; letter-spacing: .22em;
  color: var(--wine);
}
.drawn-cat .zh { font-family: var(--f-zh); font-size: 16px; letter-spacing: .14em; }
.drawn-cat .bar { color: var(--gold); margin-inline: .35em; }
.drawn-num {
  margin: 2px 0 0;
  font-family: var(--f-latin);
  font-size: 15px; letter-spacing: .3em;
  color: var(--gold);
  font-variant-numeric: lining-nums tabular-nums;
}

.note { margin-top: 30px; display: flex; flex-direction: column; align-items: center; gap: 14px; }
.note h2 {
  margin: 0;
  font-weight: 500; font-size: 19px; letter-spacing: .24em; text-indent: .24em;
  color: var(--wine);
}
.message { display: flex; flex-direction: column; gap: 1em; max-width: 21em; }
.message p {
  margin: 0;
  font-size: 16.5px; line-height: 2.05; letter-spacing: .04em;
  color: var(--ink);
  text-wrap: balance;
  word-break: keep-all; overflow-wrap: anywhere;
}

.leave {
  margin: 30px 0 0;
  display: flex; flex-direction: column; gap: 2px;
  color: var(--ink-soft); opacity: .72;
}
.leave .zh { font-size: 13.5px; letter-spacing: .12em; }
.leave .en { font-family: var(--f-latin); font-style: italic; font-size: 14px; letter-spacing: .08em; }

.actions {
  margin-top: 34px;
  width: 100%;
  display: flex; flex-direction: column; align-items: center; gap: 12px;
}
.actions .btn-primary { min-width: 220px; }
.actions-row { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; }
.calm-note {
  margin: 4px 0 0;
  font-size: 13px; line-height: 1.8; color: var(--ink-soft); letter-spacing: .06em;
}

.tag-note { margin: 2px 0 0; font-size: 13.5px; letter-spacing: .06em; color: var(--ink-soft); }
.tag-note .handle { font-family: var(--f-latin); font-size: 16px; font-weight: 600; color: var(--wine); letter-spacing: .04em; }
.inapp-note {
  margin: 10px 0 0; max-width: 24em; padding: 14px 18px;
  border: 1px solid var(--gold-faint); border-radius: 12px;
  font-size: 13px; line-height: 1.85; letter-spacing: .04em; color: var(--ink-soft);
}
.inapp-note a { display: inline-flex; align-items: center; min-height: 44px; color: var(--wine); text-underline-offset: 5px; }

/* toast */
.toast {
  position: fixed; left: 50%; z-index: 20;
  bottom: calc(24px + env(safe-area-inset-bottom, 0px));
  transform: translate(-50%, 12px);
  max-width: calc(100vw - 32px);
  padding: 12px 20px;
  border-radius: 999px;
  background: var(--ink); color: var(--paper);
  font-size: 14px; letter-spacing: .06em; text-align: center;
  opacity: 0; pointer-events: none;
  transition: opacity .4s var(--ease), transform .4s var(--ease);
}
.toast.is-on { opacity: .94; transform: translate(-50%, 0); }

/* =========================================================
   頁尾
   ========================================================= */
.footer {
  width: 100%;
  margin-top: 72px;
  padding-block: 36px calc(40px + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--gold-faint);
  display: flex; flex-direction: column; align-items: center; gap: 14px;
  text-align: center;
}
.footer .logo { width: 76px; }
.footer-quote {
  margin: 0; max-width: 22em;
  font-size: 14px; line-height: 2; letter-spacing: .06em; color: var(--ink-soft);
}
.footer-links { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.footer-links a {
  display: inline-flex; align-items: center; min-height: 44px; padding: 0 14px;
  font-family: var(--f-latin); font-size: 15px; letter-spacing: .2em;
  color: var(--wine); text-decoration: none;
}
.footer-links a:hover { text-decoration: underline; text-decoration-color: var(--gold); text-underline-offset: 6px; }
.footer-links a:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; border-radius: 4px; }
.copyright { margin: 4px 0 0; font-family: var(--f-latin); font-size: 12px; letter-spacing: .24em; color: var(--ink-soft); opacity: .7; }

/* 桌機：只增加留白 */
@media (min-width: 760px) {
  .page { padding-block: 44px 0; }
  .intro h1 { font-size: 36px; }
  .deck-peek { width: 120px; }
  .actions { flex-direction: column; }
}

/* 減少動態 */
@media (prefers-reduced-motion: reduce) {
  .flipper { transition: none; }
  .btn, .glow, .result, .tap-hint, .fan-card { transition-duration: .01ms !important; transition-delay: 0ms !important; }
}

/* 翻牌完成後攤平 3D，讓手機可以長按圖片儲存 */
.chosen.is-settled .flipper { transition: none; transform: none; }
.chosen.is-settled .face-back { display: none; }
.chosen.is-settled .face-front { transform: none; }
.chosen.is-settled img { -webkit-touch-callout: default; user-select: auto; }
html { overflow-x: clip; }
