/* 雷諾曼抽牌 /lenormand 樣式。色票/動效 token 取自 css/tools-shared.css（--lf-*）。
   牌面插畫尚未到位：牌面一律以 CSS 卡面（牌號＋牌名）打底，圖檔載入成功才蓋上（見 js/lenormand.js makeCard）。 */

html, body { overflow-x: clip; }

.lm-bg {
  position: fixed; inset: 0; z-index: -2; pointer-events: none;
  background:
    radial-gradient(ellipse at 20% 10%, rgba(198, 183, 218, 0.35), transparent 55%),
    radial-gradient(ellipse at 85% 85%, rgba(216, 166, 174, 0.28), transparent 55%),
    linear-gradient(180deg, #F7F0E4 0%, #F1E8EE 100%);
}

.lm-main {
  position: relative;
  max-width: 720px;
  margin: 0 auto;
  /* 站台 navbar 為 absolute（<992px 高約 101px、≥992px 約 121px），頂端留白蓋過它 */
  padding: 10rem 1.25rem 4rem;
  color: var(--lf-deep-lavender);
}
.lm-header { text-align: center; margin-bottom: 2rem; }
.lm-title { font-size: clamp(1.8rem, 5vw, 2.4rem); letter-spacing: 0.12em; color: var(--lf-deep-lavender); margin: 0 0 0.6rem; }
.lm-sub { margin: 0; line-height: 1.8; opacity: 0.85; }
.lm-error { text-align: center; color: #8a3b3b; }
.lm-screen[hidden], [hidden] { display: none !important; }

.lm-h2 { font-size: 1.35rem; text-align: center; margin: 0 0 0.6rem; letter-spacing: 0.08em; }
.lm-h3 { font-size: 1.05rem; text-align: center; margin: 1.5rem 0 0.4rem; }
.lm-hint { font-size: 0.9rem; line-height: 1.7; opacity: 0.75; margin: 0.3rem 0 0.8rem; }

/* ---- 按鈕 ---- */
.lm-btn {
  display: inline-block;
  min-height: 44px;
  padding: 0.7rem 1.8rem;
  border: 1px solid var(--lf-champagne-gold);
  border-radius: 999px;
  background: linear-gradient(180deg, #E6C98B, var(--lf-champagne-gold));
  color: #3b2d52;
  font-size: 1rem;
  letter-spacing: 0.08em;
  text-decoration: none;
  cursor: pointer;
  transition: opacity var(--lf-dur-med) var(--lf-ease-breath), box-shadow var(--lf-dur-med) var(--lf-ease-breath);
}
.lm-btn:hover { box-shadow: 0 4px 18px rgba(216, 179, 106, 0.45); color: #3b2d52; text-decoration: none; }
.lm-btn:disabled { opacity: 0.45; cursor: not-allowed; box-shadow: none; }
.lm-btn--ghost { background: transparent; }
.lm-btn--line { background: linear-gradient(180deg, #8fd0a0, #6fbf86); border-color: #6fbf86; }
.lm-actions { display: flex; gap: 0.8rem; justify-content: center; flex-wrap: wrap; margin: 1.4rem 0; }

/* ---- 首頁入口 ---- */
.lm-entry-grid { display: grid; gap: 1.2rem; grid-template-columns: 1fr; }
@media (min-width: 640px) { .lm-entry-grid { grid-template-columns: 1fr 1fr; } }
.lm-entry {
  padding: 1.6rem 1.4rem;
  border: 1px solid rgba(216, 179, 106, 0.55);
  border-radius: 18px;
  background: rgba(255, 252, 246, 0.72);
  text-align: center;
  display: flex; flex-direction: column; gap: 0.8rem; align-items: center; justify-content: space-between;
}
.lm-entry h2 { font-size: 1.25rem; margin: 0; letter-spacing: 0.1em; }
.lm-entry p { margin: 0; line-height: 1.8; font-size: 0.95rem; }

/* ---- 設定表單 ---- */
.lm-fieldset { border: 0; padding: 0; margin: 0 0 1.4rem; min-width: 0; }
.lm-fieldset legend { font-size: 1.05rem; font-weight: 600; margin-bottom: 0.5rem; padding: 0; }
.lm-choices { display: grid; gap: 0.6rem; }
.lm-choice {
  display: flex; gap: 0.7rem; align-items: flex-start;
  padding: 0.8rem 1rem; border-radius: 14px;
  border: 1px solid rgba(74, 58, 99, 0.18); background: rgba(255, 252, 246, 0.7);
  cursor: pointer;
}
.lm-choice:has(input:checked) { border-color: var(--lf-champagne-gold); background: rgba(244, 235, 221, 0.95); }
.lm-choice input { margin-top: 0.3rem; flex: 0 0 auto; accent-color: var(--lf-champagne-gold); }
.lm-choice-body { display: flex; flex-direction: column; gap: 0.2rem; }
.lm-choice-title { font-weight: 600; }
.lm-choice-desc { font-size: 0.88rem; line-height: 1.6; opacity: 0.8; }
.lm-field { margin-bottom: 1.4rem; }
.lm-field label { font-weight: 600; display: block; margin-bottom: 0.4rem; }
.lm-field textarea {
  width: 100%; border-radius: 12px; border: 1px solid rgba(74, 58, 99, 0.25);
  padding: 0.7rem 0.9rem; background: rgba(255, 252, 246, 0.85); font: inherit; color: inherit; resize: vertical;
}

/* ---- 洗牌動畫 ---- */
.lm-shuffle { text-align: center; padding: 3rem 0; }
.lm-shuffle-stack { position: relative; width: 96px; height: 144px; margin: 0 auto 1.5rem; }
.lm-shuffle-stack span {
  position: absolute; inset: 0; border-radius: 10px;
  border: 1px solid var(--lf-champagne-gold);
  background: url(../images/tools/lenormand/lenormand-back.webp) center / cover, linear-gradient(160deg, #5b4a78, var(--lf-deep-lavender));
  animation: lm-shuffle 1.1s var(--lf-ease-breath) infinite;
}
.lm-shuffle-stack span:nth-child(2) { animation-delay: 0.1s; }
.lm-shuffle-stack span:nth-child(3) { animation-delay: 0.2s; }
.lm-shuffle-stack span:nth-child(4) { animation-delay: 0.3s; }
.lm-shuffle-stack span:nth-child(5) { animation-delay: 0.4s; }
@keyframes lm-shuffle {
  0%, 100% { transform: translateX(0) rotate(0); }
  25% { transform: translateX(-34px) rotate(-6deg); }
  75% { transform: translateX(34px) rotate(6deg); }
}

/* ---- 挑牌格 ---- */
.lm-pick-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; margin: 1rem 0; }
@media (min-width: 640px) { .lm-pick-grid { grid-template-columns: repeat(9, 1fr); } }
.lm-pick {
  position: relative; aspect-ratio: 2 / 3; min-height: 44px; padding: 0;
  border-radius: 8px; border: 1px solid var(--lf-champagne-gold);
  background: url(../images/tools/lenormand/lenormand-back.webp) center / cover, linear-gradient(160deg, #5b4a78, var(--lf-deep-lavender));
  color: var(--lf-champagne-gold); cursor: pointer;
  transition: transform var(--lf-dur-med) var(--lf-ease-breath), box-shadow var(--lf-dur-med) var(--lf-ease-breath);
}
.lm-pick:hover:not(:disabled) { transform: translateY(-3px); }
.lm-pick.is-picked { transform: translateY(-6px); box-shadow: 0 0 0 2px var(--lf-champagne-gold), 0 6px 16px rgba(216, 179, 106, 0.5); }
.lm-pick:disabled { opacity: 0.4; cursor: not-allowed; }
.lm-pick-mark { font-size: 1rem; opacity: 0.7; }
.lm-pick-order {
  position: absolute; top: -8px; right: -8px; min-width: 20px; height: 20px; line-height: 20px;
  border-radius: 50%; background: var(--lf-champagne-gold); color: #3b2d52; font-size: 0.75rem; font-weight: 700;
}
.lm-pick-order:empty { display: none; }
.lm-counter { text-align: center; margin: 0.4rem 0 0; }

/* ---- 牌（翻牌） ---- */
.lm-card { width: 100%; max-width: 150px; aspect-ratio: 2 / 3; perspective: 900px; margin: 0 auto; }
.lm-daily-card .lm-card { max-width: 200px; }
.lm-card-inner { position: relative; width: 100%; height: 100%; transform-style: preserve-3d; transition: transform 0.9s var(--lf-ease-breath); }
.lm-card.is-flipped .lm-card-inner { transform: rotateY(180deg); }
.lm-card-face {
  position: absolute; inset: 0; border-radius: 12px; overflow: hidden;
  backface-visibility: hidden; -webkit-backface-visibility: hidden;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 0.2rem;
  border: 1px solid var(--lf-champagne-gold);
  box-shadow: 0 6px 20px rgba(74, 58, 99, 0.2);
}
.lm-card-back { background: url(../images/tools/lenormand/lenormand-back.webp) center / cover, linear-gradient(160deg, #5b4a78, var(--lf-deep-lavender)); color: var(--lf-champagne-gold); font-size: 1.6rem; }
.lm-card-front { transform: rotateY(180deg); background: linear-gradient(170deg, #FBF5E8, #EFE2EE); color: var(--lf-deep-lavender); text-align: center; }
.lm-card-num { font-family: 'Cormorant Garamond', serif; font-size: 1.8rem; color: var(--lf-champagne-gold); line-height: 1; }
.lm-card-name { font-size: 1.15rem; font-weight: 600; letter-spacing: 0.1em; }
.lm-card-en { font-size: 0.7rem; letter-spacing: 0.08em; opacity: 0.7; }
.lm-card-front.has-img > span { display: none; }
.lm-card-img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }

.lm-slots { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.8rem; margin: 1.2rem 0; }
.lm-slot-label { text-align: center; font-size: 0.9rem; margin-bottom: 0.4rem; letter-spacing: 0.1em; }

/* ---- 解讀文字 ---- */
.lm-text { margin-top: 1rem; }
.lm-text-block { padding: 1rem 1.1rem; margin-bottom: 0.9rem; border-radius: 14px; background: rgba(255, 252, 246, 0.8); border: 1px solid rgba(216, 179, 106, 0.4); }
.lm-text-label { font-size: 1rem; margin: 0 0 0.4rem; color: var(--lf-earth-clay); letter-spacing: 0.1em; }
.lm-text-body, .lm-lead { line-height: 1.9; margin: 0 0 0.6rem; }
.lm-lead { font-weight: 600; }
#daily-text { padding: 1rem 1.1rem; border-radius: 14px; background: rgba(255, 252, 246, 0.8); border: 1px solid rgba(216, 179, 106, 0.4); }
.lm-expand summary { cursor: pointer; color: var(--lf-earth-clay); min-height: 32px; }
.lm-expand p { line-height: 1.8; margin: 0.5rem 0 0; font-size: 0.95rem; }
.lm-question { text-align: center; font-size: 0.95rem; margin: 0 0 0.6rem; }
.lm-both { text-align: center; line-height: 1.8; padding: 0.8rem 1rem; border-radius: 12px; background: rgba(198, 183, 218, 0.28); }
.lm-outro { text-align: center; margin-top: 1.6rem; display: flex; flex-direction: column; align-items: center; gap: 0.8rem; }
.lm-links a { color: var(--lf-earth-clay); }
.lm-disclaimer { text-align: center; font-size: 0.82rem; opacity: 0.7; margin-top: 3rem; line-height: 1.7; }

/* reduced-motion：不翻轉、不搖晃，直接切換正反面（tools-shared.css 的規則只管 .lf-motion 內） */
@media (prefers-reduced-motion: reduce) {
  .lm-card-inner { transition: none; transform: none !important; }
  .lm-card-front { transform: none; opacity: 0; }
  .lm-card.is-flipped .lm-card-back { opacity: 0; }
  .lm-card.is-flipped .lm-card-front { opacity: 1; }
  .lm-shuffle-stack span, .lm-pick { animation: none; transition: none; }
}

/* ---- Phase 2：兩張組合／九宮格／大牌陣 ---- */
@media (min-width: 960px) { .lm-entry-grid { grid-template-columns: repeat(3, 1fr); } }
@media (min-width: 640px) and (max-width: 959.98px) { .lm-entry-grid > .lm-entry:last-child { grid-column: 1 / -1; } }
.lm-ai-layout { display: grid; gap: 0.8rem; margin: 1.2rem 0; }
.lm-ai-layout--pair { grid-template-columns: repeat(2, minmax(0, 150px)); justify-content: center; }
.lm-ai-layout--grid9 { grid-template-columns: repeat(3, minmax(0, 120px)); justify-content: center; gap: 0.6rem; }
/* 大牌陣：8 欄，第五列 4 張置中（欄位由 js grandCell 寫入 inline grid-row/column） */
.lm-ai-layout--grand { grid-template-columns: repeat(8, minmax(0, 1fr)); gap: 4px; }
.lm-ai-slot { min-width: 0; cursor: default; border-radius: 8px; }
.lm-ai-layout--grid9 .lm-ai-slot, .lm-ai-layout--grand .lm-ai-slot { cursor: pointer; }
.lm-ai-layout--grand .lm-card { max-width: none; perspective: 500px; }
.lm-ai-layout--grand .lm-card-face { border-radius: 5px; box-shadow: 0 2px 6px rgba(74, 58, 99, 0.18); }
.lm-ai-layout--grand .lm-card-num { font-size: 0.75rem; }
.lm-ai-layout--grand .lm-card-name { font-size: clamp(0.5rem, 2.4vw, 0.85rem); letter-spacing: 0; line-height: 1.1; }
.lm-ai-layout--grand .lm-card-en, .lm-ai-layout--grand .lm-card-back-mark { display: none; }
.lm-ai-layout--grid9 .lm-card-name { font-size: 0.95rem; }
.lm-ai-slot.is-near .lm-card-face { outline: 2px solid rgba(216, 166, 174, 0.95); outline-offset: 1px; }
.lm-ai-slot.is-focus .lm-card-face { outline: 3px solid var(--lf-champagne-gold); outline-offset: 1px; }
.lm-ai-slot:focus-visible { outline: 2px solid var(--lf-deep-lavender); outline-offset: 2px; }
.lm-waiting { text-align: center; line-height: 1.8; animation: lm-breath 3.2s var(--lf-ease-breath) infinite; }
@keyframes lm-breath { 0%, 100% { opacity: 0.55; } 50% { opacity: 1; } }
.lm-ai-text .lm-text-body { margin-bottom: 0.9rem; }
.lm-ai-notice { text-align: center; font-size: 0.8rem; opacity: 0.7; margin: 0.4rem 0 0; }
.lm-ai-outro-note { text-align: center; }
.lm-zoom {
  position: fixed; inset: 0; z-index: 1050; display: flex; align-items: center; justify-content: center;
  background: rgba(59, 45, 82, 0.55); padding: 1rem;
}
.lm-zoom-panel { background: #FBF5E8; border-radius: 18px; padding: 1.4rem 1.2rem 1rem; text-align: center; width: min(320px, 100%); }
.lm-zoom-card .lm-card { max-width: 200px; }
.lm-zoom-name { margin: 0.8rem 0 0.4rem; font-size: 1.1rem; letter-spacing: 0.1em; }
@media (prefers-reduced-motion: reduce) { .lm-waiting { animation: none; } }

/* ---- Phase 3 ---- */
.lm-center { text-align: center; }

/* P3-3 每日一牌：攤開背面朝上的牌（手機 12 張兩排、寬螢幕 18 張） */
.lm-daily-fan { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 8px; margin: 1rem 0 0.5rem; }
@media (min-width: 640px) { .lm-daily-fan { grid-template-columns: repeat(9, minmax(0, 1fr)); } }
.lm-daily-pick {
  position: relative; aspect-ratio: 2 / 3; min-height: 44px; padding: 0;
  border-radius: 8px; border: 1px solid var(--lf-champagne-gold);
  background: url(../images/tools/lenormand/lenormand-back.webp) center / cover, linear-gradient(160deg, #5b4a78, var(--lf-deep-lavender));
  color: var(--lf-champagne-gold); cursor: pointer;
  animation: lm-fan-in 0.5s var(--lf-ease-breath) both;
  transition: transform var(--lf-dur-med) var(--lf-ease-breath), box-shadow var(--lf-dur-med) var(--lf-ease-breath);
}
.lm-daily-pick:nth-child(odd) { animation-delay: 0.05s; }
.lm-daily-pick:hover, .lm-daily-pick:focus-visible { transform: translateY(-5px); box-shadow: 0 0 0 2px var(--lf-champagne-gold), 0 6px 16px rgba(216, 179, 106, 0.5); outline: none; }
@keyframes lm-fan-in { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }
.lm-card--tap { cursor: pointer; }

/* P3-2 九宮格：欄名在上、列名在左（直書省寬度，390px 不溢出） */
.lm-ai-layout--grid9 { grid-template-columns: 1.6rem repeat(3, minmax(0, 110px)); align-items: center; }
.lm-grid9-col { text-align: center; font-size: 0.85rem; letter-spacing: 0.08em; color: var(--lf-earth-clay); }
.lm-grid9-row { writing-mode: vertical-rl; text-orientation: upright; justify-self: center; font-size: 0.85rem; letter-spacing: 0.15em; color: var(--lf-earth-clay); }
.lm-ai-slot.is-core { position: relative; }
.lm-ai-slot.is-core .lm-card-face { outline: 3px solid var(--lf-champagne-gold); outline-offset: 1px; }
.lm-grid9-core {
  position: absolute; top: -0.55rem; left: 50%; transform: translateX(-50%); z-index: 2;
  padding: 0 0.5rem; border-radius: 999px; background: var(--lf-champagne-gold); color: #3b2d52;
  font-size: 0.72rem; line-height: 1.4; letter-spacing: 0.1em; white-space: nowrap;
}

/* P3-1／P3-4 AI 區塊與逐張牌義收合 */
.lm-ai-text .lm-ai-notice { margin: 0.2rem 0 0; }
.lm-cards-detail { margin: 0.4rem 0 0.9rem; }
.lm-cards-detail > summary { padding: 0.6rem 0.2rem; font-weight: 600; }
.lm-cards-detail-body { margin-top: 0.6rem; }

/* P3-5 LINE 確認框 */
.lm-consult {
  width: min(420px, calc(100vw - 32px)); max-height: calc(100vh - 32px); overflow-y: auto;
  padding: 0; border: 1px solid var(--lf-champagne-gold); border-radius: 18px;
  background: #FBF5E8; color: var(--lf-deep-lavender); box-shadow: 0 12px 40px rgba(59, 45, 82, 0.3);
}
.lm-consult::backdrop { background: rgba(59, 45, 82, 0.55); }
.lm-consult-panel { padding: 1.5rem 1.25rem 1.1rem; text-align: center; }
.lm-consult-text { line-height: 1.8; margin: 0 0 0.8rem; text-align: left; }
.lm-consult-note { font-size: 0.9rem; opacity: 0.85; }
.lm-consult-price { font-size: 1.35rem; font-weight: 700; letter-spacing: 0.08em; color: var(--lf-earth-clay); margin: 0.2rem 0 0.9rem; }
.lm-consult-actions { display: flex; flex-direction: column; gap: 0.7rem; align-items: stretch; margin: 1rem 0 0.4rem; }
.lm-consult-actions .lm-btn { text-align: center; }
.lm-consult-status { min-height: 1.4em; font-size: 0.88rem; margin: 0.3rem 0; }
.lm-consult-copytext { width: 100%; border-radius: 10px; border: 1px solid rgba(74, 58, 99, 0.25); padding: 0.5rem; font: inherit; font-size: 0.85rem; background: #fff; color: inherit; }
.lm-consult-friend { margin: 0.5rem 0; font-size: 0.9rem; }
.lm-consult-friend a { color: var(--lf-earth-clay); }
.lm-consult-close { min-height: 44px; padding: 0.4rem 1.2rem; border: 0; background: transparent; color: var(--lf-deep-lavender); text-decoration: underline; cursor: pointer; font: inherit; }

/* P3-6 切牌：三疊並排（390px 不溢出：每疊 minmax(0,1fr)＋max-width），以疊影表現厚度 */
.lm-cut-piles { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; max-width: 420px; margin: 1.6rem auto 1rem; padding: 0 8px 8px 0; }
.lm-cut-pile {
  position: relative; aspect-ratio: 2 / 3; min-height: 44px; padding: 0;
  border-radius: 10px; border: 1px solid var(--lf-champagne-gold);
  background: url(../images/tools/lenormand/lenormand-back.webp) center / cover, linear-gradient(160deg, #5b4a78, var(--lf-deep-lavender));
  color: var(--lf-champagne-gold); cursor: pointer;
  box-shadow: 3px 3px 0 -1px #5b4a78, 3px 3px 0 0 var(--lf-champagne-gold), 6px 6px 0 -1px #5b4a78, 6px 6px 0 0 var(--lf-champagne-gold);
  animation: lm-fan-in 0.5s var(--lf-ease-breath) both;
  transition: transform var(--lf-dur-med) var(--lf-ease-breath), opacity var(--lf-dur-med) var(--lf-ease-breath);
}
.lm-cut-pile:nth-child(2) { animation-delay: 0.08s; }
.lm-cut-pile:nth-child(3) { animation-delay: 0.16s; }
.lm-cut-pile:hover:not(:disabled), .lm-cut-pile:focus-visible { transform: translateY(-5px); outline: 3px solid var(--lf-champagne-gold); outline-offset: 3px; }
.lm-cut-pile:disabled { cursor: default; }
.lm-cut-pile:disabled:not(.is-chosen) { opacity: 0.35; }
.lm-cut-pile.is-chosen { transform: translateY(-22px) scale(1.06); }

@media (prefers-reduced-motion: reduce) {
  .lm-cut-pile { animation: none; transition: opacity 0.3s; }
  .lm-cut-pile.is-chosen, .lm-cut-pile:hover:not(:disabled) { transform: none; }
  .lm-daily-pick { animation: none; transition: none; }
}
