:root {
  --bg: #0a0907;
  --ink: #f4eee4;
  --muted: #9a8f7e;
  --gold: #d4b37a;
  --gold-soft: #e8d4ad;
  --gold-dim: rgba(212, 179, 122, 0.35);
  --line: rgba(244, 238, 228, 0.12);
  --panel: rgba(16, 13, 10, 0.78);
  --card-w: min(118px, 24vw);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --font-display: "Noto Serif SC", "Cormorant Garamond", "Songti SC", serif;
  --font-en: "Cormorant Garamond", "Noto Serif SC", serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  color: var(--ink);
  background: var(--bg);
  font-family: "PingFang SC", "Microsoft YaHei", sans-serif;
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  touch-action: manipulation;
}

body {
  min-height: 100dvh;
  overscroll-behavior: none;
}

button,
a,
input,
label,
.mode-btn,
.qa-chip,
.spread,
.deck-pile,
.card,
.icon-btn,
.ghost,
.cta,
.field-link {
  touch-action: manipulation;
}

.sky {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background:
    radial-gradient(110% 65% at 50% -12%, #2c2418 0%, transparent 52%),
    radial-gradient(70% 45% at 90% 95%, #17120c 0%, transparent 50%),
    radial-gradient(1.4px 1.4px at 14% 16%, rgba(244, 238, 228, 0.4), transparent),
    radial-gradient(1px 1px at 72% 24%, rgba(244, 238, 228, 0.32), transparent),
    radial-gradient(1.2px 1.2px at 38% 68%, rgba(212, 179, 122, 0.38), transparent),
    radial-gradient(1px 1px at 86% 52%, rgba(244, 238, 228, 0.22), transparent),
    radial-gradient(1px 1px at 22% 86%, rgba(244, 238, 228, 0.18), transparent),
    var(--bg);
  animation: skyDrift 20s ease-in-out infinite alternate;
}

.vignette {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background: radial-gradient(ellipse at center, transparent 45%, rgba(0, 0, 0, 0.45) 100%);
}

@keyframes skyDrift {
  from {
    filter: brightness(1);
  }
  to {
    filter: brightness(1.07);
  }
}

.app {
  position: relative;
  z-index: 1;
  width: min(1120px, 100%);
  margin: 0 auto;
  min-height: 100dvh;
  padding: max(14px, env(safe-area-inset-top)) 20px calc(28px + var(--safe-b));
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 0 6px;
  animation: fadeUp 0.55s ease both;
}

.brand-lockup {
  min-width: 0;
}

.kicker {
  margin: 0 0 2px;
  font-family: var(--font-en);
  letter-spacing: 0.38em;
  font-size: 11px;
  color: var(--gold);
}

.brand {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: clamp(34px, 9vw, 48px);
  letter-spacing: 0.16em;
  line-height: 1.05;
  text-indent: 0.12em;
  background: linear-gradient(180deg, #fff8ec 8%, var(--gold) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.icon-btn {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.03);
  color: var(--muted);
  border-radius: 999px;
  padding: 8px 12px;
  font: inherit;
  font-size: 12px;
  letter-spacing: 0.08em;
  cursor: pointer;
  transition: 0.15s ease;
}

.icon-btn[aria-pressed="true"] {
  color: var(--gold-soft);
  border-color: rgba(212, 179, 122, 0.45);
  background: rgba(212, 179, 122, 0.1);
}

.main {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.mode-switch {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin: 8px 0 4px;
  padding: 4px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.28);
}

.mode-btn {
  border: 0;
  border-radius: 999px;
  padding: 10px 12px;
  font: inherit;
  font-size: 13px;
  letter-spacing: 0.06em;
  cursor: pointer;
  color: var(--muted);
  background: transparent;
}

.mode-btn.active {
  color: #1a140c;
  background: linear-gradient(180deg, #f0d9a4, #c9a56a);
  font-weight: 600;
}

.qa-panel {
  margin-top: 10px;
  animation: fadeUp 0.45s ease both;
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.qa-shell {
  flex: 1;
  min-height: min(70vh, 640px);
  display: flex;
  flex-direction: column;
  border: 1px solid rgba(212, 179, 122, 0.22);
  border-radius: 18px;
  overflow: hidden;
  background:
    linear-gradient(180deg, rgba(28, 22, 16, 0.92), rgba(10, 9, 8, 0.96));
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.35);
}

.qa-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px 12px;
  border-bottom: 1px solid var(--line);
}

.qa-title {
  margin: 0;
  font-family: var(--font-display);
  font-size: 18px;
  letter-spacing: 0.12em;
  color: var(--gold-soft);
}

.qa-sub {
  margin: 4px 0 0;
  font-size: 12px;
  color: var(--muted);
}

.qa-chat {
  flex: 1;
  overflow: auto;
  padding: 16px 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background:
    radial-gradient(1px 1px at 20% 30%, rgba(255, 255, 255, 0.06), transparent),
    radial-gradient(1px 1px at 70% 60%, rgba(255, 255, 255, 0.04), transparent);
}

.qa-row {
  display: flex;
  flex-direction: column;
  max-width: 88%;
  gap: 6px;
}

.qa-row.bot {
  align-self: flex-start;
  align-items: flex-start;
}

.qa-row.user {
  align-self: flex-end;
  align-items: flex-end;
}

.qa-quote {
  font-size: 11px;
  color: var(--muted);
  padding: 6px 10px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.05);
  border-left: 2px solid rgba(212, 179, 122, 0.45);
  max-width: 100%;
}

.qa-bubble {
  padding: 10px 12px;
  border-radius: 14px;
  font-size: 14px;
  line-height: 1.65;
  white-space: pre-wrap;
  word-break: break-word;
}

.qa-bubble.bot {
  background: rgba(255, 255, 255, 0.08);
  color: #efe6d8;
  border-top-left-radius: 4px;
  border: 1px solid rgba(255, 255, 255, 0.06);
}

.qa-bubble.user {
  background: linear-gradient(180deg, #e8c98a, #c9a56a);
  color: #1a140c;
  border-top-right-radius: 4px;
}

.qa-choices {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 12px 14px 14px;
  border-top: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.22);
  min-height: 56px;
}

.qa-chip {
  border: 1px solid rgba(212, 179, 122, 0.35);
  background: rgba(255, 255, 255, 0.04);
  color: var(--gold-soft);
  border-radius: 999px;
  padding: 8px 14px;
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  transition: 0.15s ease;
}

.qa-chip:active {
  transform: scale(0.98);
}

.qa-chip-primary {
  color: #1a140c;
  border-color: transparent;
  background: linear-gradient(180deg, #f0d9a4, #c9a56a);
  font-weight: 600;
}

.qa-chip-ghost {
  border-style: dashed;
  color: var(--muted);
  border-color: rgba(212, 179, 122, 0.28);
}

.qa-input-row {
  display: flex;
  gap: 8px;
  width: 100%;
  align-items: center;
}

.qa-input {
  flex: 1;
  min-width: 0;
  border: 1px solid rgba(212, 179, 122, 0.35);
  background: rgba(255, 255, 255, 0.06);
  color: #efe6d8;
  border-radius: 999px;
  padding: 9px 14px;
  font: inherit;
  font-size: 13px;
  outline: none;
}

.qa-input::placeholder {
  color: rgba(239, 230, 216, 0.4);
}

.qa-input:focus {
  border-color: rgba(212, 179, 122, 0.65);
  background: rgba(255, 255, 255, 0.09);
}

.toast {
  position: fixed;
  left: 50%;
  top: 14%;
  transform: translateX(-50%);
  z-index: 80;
  padding: 10px 16px;
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.82);
  color: #fff;
  font-size: 13px;
  pointer-events: none;
  animation: fadeUp 0.25s ease;
}

.setup {
  margin-top: 10px;
  animation: fadeUp 0.65s 0.05s ease both;
}

.setup-stage {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.setup-aside {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.system-switch {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  padding: 4px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.25);
}

.system-btn {
  border: 0;
  border-radius: 999px;
  padding: 10px 12px;
  font: inherit;
  font-family: var(--font-display);
  font-size: 14px;
  letter-spacing: 0.08em;
  cursor: pointer;
  color: var(--muted);
  background: transparent;
  transition: 0.15s ease;
}

.system-btn.active {
  color: #1a140c;
  background: linear-gradient(180deg, #f0d9a4, #c9a56a);
  font-weight: 600;
}

.face-lorman {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 8px;
  background:
    radial-gradient(80% 60% at 50% 30%, rgba(212, 179, 122, 0.16), transparent 70%),
    linear-gradient(180deg, #2a2318, #14110d);
  color: var(--ink);
  text-align: center;
}

.face-lorman .sym {
  font-size: clamp(28px, 6vw, 36px);
  line-height: 1;
  filter: drop-shadow(0 4px 10px rgba(0, 0, 0, 0.35));
}

.face-lorman .num {
  font-size: 11px;
  letter-spacing: 0.16em;
  color: var(--gold);
}

.face-lorman .cn {
  font-family: var(--font-display);
  font-size: clamp(15px, 3.2vw, 18px);
  font-weight: 700;
  letter-spacing: 0.12em;
}

.face-lorman .en {
  font-family: var(--font-en);
  font-size: 11px;
  color: var(--muted);
  letter-spacing: 0.04em;
}

.table.layout-grid9 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  justify-items: center;
  max-width: 420px;
  margin: 0 auto;
}

.setup-board {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 14px;
  border-radius: 18px;
  border: 1px solid var(--line);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.03), rgba(255, 255, 255, 0.015)),
    rgba(12, 10, 8, 0.55);
}

.lead {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  letter-spacing: 0.08em;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 12px;
  color: var(--muted);
  letter-spacing: 0.1em;
}

.field-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.field-link {
  border: 0;
  background: none;
  padding: 0;
  font: inherit;
  font-size: 12px;
  letter-spacing: 0.06em;
  color: var(--gold-soft);
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}

.setup-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 4px;
}

.setup-actions .cta {
  margin-top: 0;
}

.setup-qa-btn {
  width: 100%;
  padding: 12px 16px;
  border-radius: 999px;
  letter-spacing: 0.14em;
}

.field input {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.03);
  color: var(--ink);
  border-radius: 14px;
  padding: 14px 16px;
  font: inherit;
  font-size: 16px; /* ≥16px 避免 iOS 聚焦放大 */
  outline: none;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.field input:focus {
  border-color: var(--gold-dim);
  box-shadow: 0 0 0 3px rgba(212, 179, 122, 0.12);
}

.field input::placeholder {
  color: rgba(154, 143, 126, 0.6);
}

.opts {
  display: flex;
  gap: 12px;
}

.check {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
  cursor: pointer;
}

.check input {
  accent-color: var(--gold);
}

.spread-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-top: 2px;
  font-size: 12px;
  letter-spacing: 0.14em;
  color: var(--muted);
}

.spread-hint {
  color: var(--gold);
  letter-spacing: 0.06em;
}

.spreads {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

.spread {
  position: relative;
  border: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.035), rgba(255, 255, 255, 0.015));
  color: var(--muted);
  border-radius: 14px;
  padding: 12px 12px 11px;
  cursor: pointer;
  text-align: left;
  transition: 0.18s ease;
}

.spread:hover {
  border-color: rgba(212, 179, 122, 0.28);
}

.spread .count {
  position: absolute;
  top: 10px;
  right: 10px;
  min-width: 22px;
  height: 22px;
  padding: 0 6px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  font-size: 11px;
  color: var(--gold);
  background: rgba(212, 179, 122, 0.12);
  border: 1px solid rgba(212, 179, 122, 0.22);
}

.spread strong {
  display: block;
  color: var(--ink);
  font-family: var(--font-display);
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 4px;
  padding-right: 28px;
}

.spread span {
  display: block;
  font-size: 11px;
  line-height: 1.4;
}

.spread.active {
  border-color: rgba(212, 179, 122, 0.55);
  background: rgba(212, 179, 122, 0.1);
  color: #e8d4ad;
  box-shadow: inset 0 0 0 1px rgba(212, 179, 122, 0.1), 0 10px 28px rgba(0, 0, 0, 0.22);
}

.cta {
  border: 0;
  border-radius: 999px;
  padding: 15px 20px;
  margin-top: 4px;
  font: inherit;
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 600;
  letter-spacing: 0.2em;
  text-indent: 0.16em;
  cursor: pointer;
  color: #1a140c;
  background: linear-gradient(180deg, #f0d9a4 0%, #c9a56a 100%);
  box-shadow: 0 12px 32px rgba(201, 165, 106, 0.22);
  transition: transform 0.15s ease;
}

.cta:active {
  transform: scale(0.98);
}

.cta:disabled {
  opacity: 0.55;
  cursor: wait;
}

.fine {
  margin: 0;
  text-align: center;
  color: rgba(154, 143, 126, 0.72);
  font-size: 11px;
  letter-spacing: 0.04em;
}

.hidden {
  display: none !important;
}

.reading {
  margin-top: 8px;
  animation: fadeUp 0.4s ease both;
}

.reading-layout {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.reading-main {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-width: 0;
}

.reading-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.spread-name {
  margin: 0 0 4px;
  font-family: var(--font-display);
  font-size: 18px;
  letter-spacing: 0.12em;
  color: var(--gold-soft);
}

.ask {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.overall {
  margin-top: 2px;
  padding: 14px 16px;
  border-radius: 14px;
  border: 1px solid rgba(212, 179, 122, 0.35);
  background:
    linear-gradient(145deg, rgba(232, 201, 138, 0.12), rgba(0, 0, 0, 0.28)),
    rgba(20, 16, 12, 0.75);
  animation: fadeUp 0.35s ease both;
}

.overall-label {
  margin: 0 0 8px;
  font-size: 11px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--gold-soft);
}

.overall-body {
  margin: 0;
  font-size: 14px;
  line-height: 1.75;
  color: #efe6d8;
  white-space: pre-wrap;
  word-break: break-word;
}

.reading-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: flex-end;
}

.ghost {
  border: 1px solid var(--line);
  background: transparent;
  color: var(--gold);
  border-radius: 999px;
  padding: 8px 12px;
  font: inherit;
  font-size: 12px;
  letter-spacing: 0.04em;
  cursor: pointer;
  white-space: nowrap;
}

.draw-tip {
  margin: 6px 0 0;
  color: var(--gold);
  font-size: 12px;
  letter-spacing: 0.06em;
}

.table-wrap {
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 16px 10px 18px;
  background:
    radial-gradient(80% 70% at 50% 40%, rgba(212, 179, 122, 0.07), transparent 70%),
    linear-gradient(180deg, rgba(28, 22, 16, 0.9), rgba(12, 10, 8, 0.95));
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04), 0 18px 48px rgba(0, 0, 0, 0.35);
}

.draw-row {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.deck-pile {
  border: 0;
  background: transparent;
  color: var(--gold-soft);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 0;
  transition: transform 0.15s ease, opacity 0.2s ease;
}

.deck-pile:not(:disabled):active {
  transform: scale(0.96);
}

.deck-pile:disabled {
  opacity: 0.35;
  cursor: default;
}

.deck-pile.pulse .deck-visual {
  animation: deckPulse 1.4s ease-in-out infinite;
}

.deck-pile.dealing .deck-visual {
  animation: deckDealKick 0.42s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.deck-visual {
  width: min(96px, 22vw);
  aspect-ratio: 350 / 600;
  border-radius: 9px;
  border: 2px solid rgba(212, 179, 122, 0.6);
  background:
    linear-gradient(145deg, rgba(212, 179, 122, 0.3), transparent 42%),
    repeating-linear-gradient(45deg, #1a1510 0, #1a1510 7px, #241c14 7px, #241c14 14px);
  box-shadow:
    4px 4px 0 rgba(20, 16, 12, 0.9),
    8px 8px 0 rgba(20, 16, 12, 0.55),
    0 14px 28px rgba(0, 0, 0, 0.4);
  position: relative;
}

.deck-visual::after {
  content: "✦";
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--gold);
  font-size: 22px;
}

.deck-label {
  font-family: var(--font-display);
  font-size: 14px;
  letter-spacing: 0.16em;
}

@keyframes deckPulse {
  0%,
  100% {
    box-shadow:
      4px 4px 0 rgba(20, 16, 12, 0.9),
      8px 8px 0 rgba(20, 16, 12, 0.55),
      0 0 0 0 rgba(212, 179, 122, 0.35);
  }
  50% {
    box-shadow:
      4px 4px 0 rgba(20, 16, 12, 0.9),
      8px 8px 0 rgba(20, 16, 12, 0.55),
      0 0 0 10px rgba(212, 179, 122, 0);
  }
}

@keyframes deckDealKick {
  0% {
    transform: translateY(0) scale(1);
  }
  35% {
    transform: translateY(-10px) scale(0.94) rotate(-4deg);
  }
  100% {
    transform: translateY(0) scale(1) rotate(0);
  }
}

/* 从牌堆飞向空位的发牌影子 */
.deal-flyer {
  position: fixed;
  z-index: 80;
  width: var(--card-w);
  aspect-ratio: 350 / 600;
  border-radius: 9px;
  border: 2px solid rgba(212, 179, 122, 0.55);
  background:
    linear-gradient(145deg, rgba(212, 179, 122, 0.28), transparent 42%),
    repeating-linear-gradient(45deg, #1a1510 0, #1a1510 7px, #241c14 7px, #241c14 14px);
  box-shadow: 0 18px 36px rgba(0, 0, 0, 0.45), 0 0 24px rgba(212, 179, 122, 0.18);
  pointer-events: none;
  display: grid;
  place-items: center;
  will-change: transform, left, top, opacity;
  transition:
    left 0.55s cubic-bezier(0.22, 0.9, 0.28, 1),
    top 0.55s cubic-bezier(0.35, 0.1, 0.2, 1.05),
    transform 0.55s cubic-bezier(0.22, 0.9, 0.28, 1),
    opacity 0.2s ease;
}

.deal-flyer::after {
  content: "✦";
  color: var(--gold);
  font-size: 22px;
  opacity: 0.9;
}

.deal-flyer.arc {
  transform: translate(-50%, -50%) rotate(18deg) scale(0.92);
}

.deal-flyer.land {
  transform: translate(-50%, -50%) rotate(0deg) scale(1);
  opacity: 0.15;
}

.card.deal-land {
  animation: cardLand 0.48s cubic-bezier(0.2, 0.85, 0.25, 1.15) both;
}

@keyframes cardLand {
  0% {
    opacity: 0;
    transform: translateY(-18px) scale(0.88) rotate(-6deg);
    filter: drop-shadow(0 0 0 rgba(212, 179, 122, 0));
  }
  55% {
    opacity: 1;
    transform: translateY(3px) scale(1.03) rotate(1deg);
    filter: drop-shadow(0 0 14px rgba(212, 179, 122, 0.35));
  }
  100% {
    opacity: 1;
    transform: translateY(0) scale(1) rotate(0);
    filter: drop-shadow(0 0 0 rgba(212, 179, 122, 0));
  }
}

.slot.next-target .slot-hole {
  animation: holeBreathe 1.2s ease-in-out infinite;
}

@keyframes holeBreathe {
  0%,
  100% {
    border-color: rgba(212, 179, 122, 0.55);
    box-shadow: 0 0 0 1px rgba(212, 179, 122, 0.15), 0 0 12px rgba(212, 179, 122, 0.1);
  }
  50% {
    border-color: rgba(240, 217, 164, 0.9);
    box-shadow: 0 0 0 2px rgba(212, 179, 122, 0.28), 0 0 22px rgba(212, 179, 122, 0.28);
  }
}

.slot.empty .slot-hole {
  width: var(--card-w);
  aspect-ratio: 350 / 600;
  border-radius: 9px;
  border: 1px dashed rgba(212, 179, 122, 0.28);
  background: rgba(0, 0, 0, 0.18);
}

.table {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 12px 10px;
  min-height: 200px;
  perspective: 1000px;
  width: 100%;
}

.table.layout-celtic {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  grid-template-rows: repeat(4, auto);
  gap: 8px 6px;
  align-items: end;
  justify-items: center;
  min-height: 420px;
}

.table.layout-celtic .slot[data-i="0"] {
  grid-column: 2;
  grid-row: 2;
}
.table.layout-celtic .slot[data-i="1"] {
  grid-column: 2;
  grid-row: 2;
  z-index: 2;
  transform: rotate(90deg);
  margin-top: 8px;
}
.table.layout-celtic .slot[data-i="2"] {
  grid-column: 2;
  grid-row: 3;
}
.table.layout-celtic .slot[data-i="3"] {
  grid-column: 1;
  grid-row: 2;
}
.table.layout-celtic .slot[data-i="4"] {
  grid-column: 3;
  grid-row: 2;
}
.table.layout-celtic .slot[data-i="5"] {
  grid-column: 2;
  grid-row: 1;
}
.table.layout-celtic .slot[data-i="6"] {
  grid-column: 5;
  grid-row: 4;
}
.table.layout-celtic .slot[data-i="7"] {
  grid-column: 5;
  grid-row: 3;
}
.table.layout-celtic .slot[data-i="8"] {
  grid-column: 5;
  grid-row: 2;
}
.table.layout-celtic .slot[data-i="9"] {
  grid-column: 5;
  grid-row: 1;
}

.table.layout-celtic .slot[data-i="1"] .slot-label {
  transform: rotate(-90deg);
  white-space: nowrap;
}

.table.layout-cross {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: auto auto auto;
  gap: 10px;
  justify-items: center;
  align-items: center;
}

.table.layout-cross .slot[data-i="0"] {
  grid-column: 2;
  grid-row: 2;
}
.table.layout-cross .slot[data-i="1"] {
  grid-column: 2;
  grid-row: 1;
}
.table.layout-cross .slot[data-i="2"] {
  grid-column: 1;
  grid-row: 2;
}
.table.layout-cross .slot[data-i="3"] {
  grid-column: 3;
  grid-row: 2;
}
.table.layout-cross .slot[data-i="4"] {
  grid-column: 2;
  grid-row: 3;
}

.table.layout-row5,
.table.layout-row4,
.table.layout-row7 {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
}

.table.compact .card {
  width: min(92px, 18vw);
}

.table.layout-celtic .card {
  width: min(78px, 15vw);
}

.slot {
  width: var(--card-w);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.slot-label {
  font-size: 11px;
  letter-spacing: 0.1em;
  color: var(--gold);
  font-family: var(--font-display);
  text-align: center;
  min-height: 1.2em;
}

.card {
  width: var(--card-w);
  aspect-ratio: 350 / 600;
  border: 0;
  padding: 0;
  background: transparent;
  cursor: pointer;
  perspective: 800px;
}

.card-inner {
  position: relative;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  transition: transform 0.72s cubic-bezier(0.4, 0.15, 0.2, 1);
}

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

.face {
  position: absolute;
  inset: 0;
  border-radius: 9px;
  backface-visibility: hidden;
  overflow: hidden;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.45);
}

.face-back {
  background:
    linear-gradient(145deg, rgba(212, 179, 122, 0.28), transparent 42%),
    repeating-linear-gradient(45deg, #1a1510 0, #1a1510 7px, #241c14 7px, #241c14 14px);
  border: 2px solid rgba(212, 179, 122, 0.55);
  display: grid;
  place-items: center;
}

.face-back::after {
  content: "✦";
  color: var(--gold);
  font-size: 22px;
  opacity: 0.85;
}

.face-front {
  position: relative;
  transform: rotateY(180deg);
  background: #111;
  border: 2px solid rgba(212, 179, 122, 0.4);
}

.face-front img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.card.selected {
  filter: drop-shadow(0 0 12px rgba(212, 179, 122, 0.5));
}

/* 逆位不再把图倒过来，避免看起来像显示错误；用角标标明 */
.card-badge {
  position: absolute;
  top: 6px;
  right: 6px;
  z-index: 2;
  padding: 3px 7px;
  border-radius: 999px;
  font-size: 10px;
  letter-spacing: 0.12em;
  color: #1a140c;
  background: linear-gradient(180deg, #f0d9a4, #c9a56a);
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.35);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.card.flipped.reversed .card-badge {
  opacity: 1;
}

.detail {
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 16px;
  padding: 16px 16px 18px;
  backdrop-filter: blur(10px);
  animation: fadeUp 0.3s ease both;
}

.detail-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

.detail .pos {
  margin: 0;
  color: var(--gold);
  font-size: 12px;
  letter-spacing: 0.16em;
}

.detail .orient {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0.12em;
}

.detail h2 {
  margin: 8px 0 10px;
  font-family: var(--font-display);
  font-size: clamp(22px, 5vw, 28px);
  font-weight: 700;
  letter-spacing: 0.06em;
}

.detail .mean-label,
.detail .ref-label {
  margin: 0 0 6px;
  font-size: 11px;
  letter-spacing: 0.18em;
  color: var(--gold);
}

.detail .mean {
  margin: 0 0 14px;
  font-size: 15px;
  line-height: 1.7;
  color: #ebe2d4;
}

.detail .ref-block {
  margin: 0;
  padding: 12px 12px 14px;
  border-radius: 12px;
  border: 1px solid rgba(212, 179, 122, 0.18);
  background: rgba(0, 0, 0, 0.22);
}

.detail .ref-body {
  margin: 0;
  min-height: 3.5em;
  font-size: 14px;
  line-height: 1.8;
  color: #f0e6d6;
  white-space: pre-wrap;
  word-break: break-word;
}

.detail .ref-note {
  margin: 12px 0 0;
  font-size: 11px;
  color: rgba(154, 143, 126, 0.85);
  letter-spacing: 0.04em;
}

.detail .yesno {
  margin: 14px 0 0;
  padding-top: 12px;
  border-top: 1px solid var(--line);
  font-family: var(--font-display);
  font-size: 18px;
  letter-spacing: 0.1em;
  color: var(--gold);
}

.welcome {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  place-items: center;
  padding: 24px 16px;
  background: rgba(6, 5, 4, 0.78);
  backdrop-filter: blur(7px);
  animation: fadeUp 0.28s ease;
}

.welcome[hidden] {
  display: none !important;
}

.welcome-card {
  width: min(360px, 100%);
  padding: 24px 20px 20px;
  border-radius: 18px;
  border: 1px solid rgba(212, 179, 122, 0.28);
  background: linear-gradient(180deg, #1c1711 0%, #12100d 100%);
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.5);
  text-align: left;
}

.welcome-kicker {
  margin: 0 0 4px;
  color: var(--gold);
  font-size: 12px;
  letter-spacing: 0.2em;
}

.welcome-card h2 {
  margin: 0 0 12px;
  font-family: var(--font-display);
  font-size: 28px;
  letter-spacing: 0.12em;
}

.welcome-body {
  margin: 0 0 18px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.7;
}

.welcome-card .cta {
  width: 100%;
  letter-spacing: 0.12em;
  text-indent: 0;
}

.shuffle[hidden] {
  display: none !important;
}

.shuffle {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 16px;
  background: rgba(6, 5, 4, 0.78);
  backdrop-filter: blur(6px);
  color: var(--gold);
  font-family: var(--font-display);
  letter-spacing: 0.22em;
}

.shuffle-stack {
  position: relative;
  width: 88px;
  height: 150px;
}

.shuffle-stack span {
  position: absolute;
  inset: 0;
  border-radius: 10px;
  border: 2px solid rgba(212, 179, 122, 0.55);
  background:
    repeating-linear-gradient(45deg, #1a1510 0, #1a1510 8px, #241c14 8px, #241c14 16px);
  box-shadow: 0 14px 36px rgba(0, 0, 0, 0.5);
}

.shuffle-stack span:nth-child(1) {
  animation: shuffleA 0.55s ease-in-out infinite;
}
.shuffle-stack span:nth-child(2) {
  animation: shuffleB 0.55s ease-in-out infinite;
}
.shuffle-stack span:nth-child(3) {
  animation: shuffleC 0.55s ease-in-out infinite;
}

@keyframes shuffleA {
  0%,
  100% {
    transform: translate(-6px, 2px) rotate(-8deg);
  }
  50% {
    transform: translate(8px, -8px) rotate(6deg);
  }
}
@keyframes shuffleB {
  0%,
  100% {
    transform: translate(4px, -2px) rotate(5deg);
  }
  50% {
    transform: translate(-8px, 6px) rotate(-7deg);
  }
}
@keyframes shuffleC {
  0%,
  100% {
    transform: translate(0, 0) rotate(0);
  }
  50% {
    transform: translate(0, -10px) rotate(2deg);
  }
}

@keyframes fadeUp {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 520px) {
  .app {
    padding-left: 14px;
    padding-right: 14px;
  }

  .table.layout-celtic {
    min-height: 360px;
    gap: 6px 4px;
  }

  .reading-head {
    flex-direction: column;
  }

  .reading-actions {
    width: 100%;
  }

  .setup-board {
    padding: 12px;
  }
}

@media (min-width: 720px) {
  .spreads {
    grid-template-columns: repeat(3, 1fr);
  }

  .spread {
    min-height: 78px;
  }
}

@media (min-width: 960px) {
  :root {
    --card-w: min(128px, 12vw);
  }

  .mode-switch {
    max-width: 360px;
  }

  .qa-shell {
    min-height: min(72vh, 680px);
  }

  .qa-bubble {
    font-size: 15px;
  }

  body {
    overflow-y: auto;
  }

  .sky {
    background:
      radial-gradient(70% 55% at 18% 10%, #322818 0%, transparent 50%),
      radial-gradient(55% 45% at 82% 80%, #1a140e 0%, transparent 48%),
      radial-gradient(1.4px 1.4px at 10% 20%, rgba(244, 238, 228, 0.35), transparent),
      radial-gradient(1px 1px at 70% 30%, rgba(244, 238, 228, 0.28), transparent),
      radial-gradient(1.2px 1.2px at 40% 70%, rgba(212, 179, 122, 0.35), transparent),
      radial-gradient(1px 1px at 88% 18%, rgba(244, 238, 228, 0.2), transparent),
      var(--bg);
  }

  .app {
    width: min(1180px, calc(100% - 48px));
    padding-top: 28px;
    padding-bottom: 40px;
  }

  .topbar {
    align-items: center;
    padding-bottom: 18px;
    border-bottom: 1px solid rgba(244, 238, 228, 0.08);
    margin-bottom: 8px;
  }

  .brand {
    font-size: 56px;
    letter-spacing: 0.2em;
  }

  .kicker {
    font-size: 12px;
    letter-spacing: 0.45em;
  }

  .setup {
    margin-top: 22px;
  }

  .setup-stage {
    display: grid;
    grid-template-columns: minmax(280px, 360px) minmax(0, 1fr);
    gap: 28px;
    align-items: stretch;
    min-height: min(640px, calc(100dvh - 160px));
  }

  .setup-aside {
    position: sticky;
    top: 24px;
    align-self: start;
    gap: 18px;
    padding: 28px 24px;
    border-radius: 22px;
    border: 1px solid rgba(212, 179, 122, 0.22);
    background:
      linear-gradient(165deg, rgba(42, 34, 24, 0.55) 0%, rgba(14, 12, 10, 0.75) 100%);
    box-shadow: 0 24px 60px rgba(0, 0, 0, 0.35);
  }

  .setup-aside .lead {
    font-family: var(--font-display);
    font-size: 18px;
    color: var(--gold-soft);
    letter-spacing: 0.12em;
    line-height: 1.5;
  }

  .setup-aside .cta {
    margin-top: 8px;
    padding: 16px 20px;
    font-size: 19px;
  }

  .setup-board {
    padding: 22px 22px 20px;
    border-radius: 22px;
    border-color: rgba(212, 179, 122, 0.18);
    background:
      radial-gradient(90% 70% at 50% 0%, rgba(212, 179, 122, 0.08), transparent 55%),
      linear-gradient(180deg, rgba(24, 20, 16, 0.92), rgba(10, 9, 8, 0.95));
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04), 0 28px 70px rgba(0, 0, 0, 0.32);
  }

  .spread-head {
    margin-bottom: 4px;
    font-size: 13px;
  }

  .spreads {
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
  }

  .spread {
    min-height: 96px;
    padding: 14px 12px 12px;
    border-radius: 16px;
  }

  .spread strong {
    font-size: 17px;
  }

  .spread span {
    font-size: 12px;
  }

  .spread:hover {
    transform: translateY(-1px);
    background: rgba(212, 179, 122, 0.07);
  }

  .reading-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(280px, 340px);
    gap: 22px;
    align-items: start;
  }

  .reading-layout:has(.detail[hidden]) {
    grid-template-columns: 1fr;
  }

  .table-wrap {
    padding: 28px 24px;
    border-radius: 22px;
    min-height: 420px;
  }

  .draw-row {
    flex-direction: row;
    align-items: flex-start;
    justify-content: center;
    gap: 28px;
  }

  .deck-pile {
    position: sticky;
    top: 28px;
    flex: 0 0 auto;
    padding-top: 28px;
  }

  .deck-visual {
    width: 110px;
  }

  .detail {
    position: sticky;
    top: 24px;
    min-height: 280px;
    padding: 22px;
    border-radius: 20px;
  }

  .detail h2 {
    font-size: 30px;
  }

  .detail .mean {
    font-size: 16px;
  }

  .detail .ref-body {
    font-size: 15px;
  }

  .welcome-card {
    width: min(420px, 100%);
    padding: 32px 28px 26px;
  }

  .table.layout-celtic {
    min-height: 520px;
    max-width: 640px;
    margin: 0 auto;
  }

  .table.layout-celtic .card {
    width: min(96px, 9vw);
  }
}

@media (min-width: 1280px) {
  .app {
    width: min(1240px, calc(100% - 64px));
  }

  .setup-stage {
    grid-template-columns: 380px minmax(0, 1fr);
    gap: 36px;
  }

  .spreads {
    gap: 12px;
  }
}
