/* ── Tarot demo — full-screen stage, floating cards ───────────────────── */

:root {
  --bg: #0b1710;
  --panel: rgba(14, 30, 20, 0.74);
  --border: #2c4a34;
  --text: #e8f0e2;
  --text-muted: #9dbba3;
  --gold: #7fd24a;
  --gold-soft: #c4f39a;
  --error: #e08c8c;
  --radius: 12px;
}

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

/* Author display rules (e.g. .phase { display: flex }) would otherwise beat
   the UA stylesheet's [hidden] { display: none } — keep hidden authoritative. */
[hidden] {
  display: none !important;
}

html,
body {
  height: 100%;
  overflow: hidden;
}

body {
  font-family: "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", sans-serif;
  background: var(--bg);
  color: var(--text);
}

.layout {
  position: fixed;
  inset: 0;
}

/* ── Full-bleed stage ─────────────────────────────────────────────────── */

.stage-panel {
  position: absolute;
  inset: 0;
  background: #08120c;
}

sv-presenter {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

/*
 * Before she is Ready the stage is covered, not removed. `hidden` (display:
 * none) leaves the element with no box, and the presenter engine will not
 * finish booting inside a box it cannot measure — initialize() hangs at
 * "launching" forever. Veiling it keeps the layout the engine needs and still
 * shows the placeholder underneath: opacity, not display.
 */
sv-presenter.veiled {
  opacity: 0;
  pointer-events: none;
}

.stage-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  background:
    radial-gradient(ellipse 60% 40% at 20% 0%, #1c3d26 0%, transparent 60%),
    radial-gradient(ellipse 50% 35% at 85% 100%, #173420 0%, transparent 60%),
    var(--bg);
}

.stage-glyph {
  font-size: 44px;
  color: var(--gold);
  margin-bottom: 12px;
  text-shadow: 0 0 24px rgba(127, 210, 74, 0.6);
}

.speaking-indicator {
  position: absolute;
  top: 18px;
  right: 18px;
  padding: 6px 16px;
  border-radius: 999px;
  background: rgba(10, 22, 14, 0.8);
  border: 1px solid var(--gold);
  color: var(--gold-soft);
  font-size: 13px;
  letter-spacing: 0.08em;
  z-index: 3;
}

/* ── Overlay: everything floats above the stage ───────────────────────── */

.table-panel {
  position: absolute;
  inset: 0;
  pointer-events: none; /* individual widgets re-enable below */
  z-index: 2;
}

.table-header {
  position: absolute;
  top: 18px;
  left: 0;
  right: 0;
  text-align: center;
}

.table-header h1 {
  font-family: "Noto Serif TC", "Songti TC", serif;
  font-size: 22px;
  font-weight: 600;
  color: var(--gold);
  letter-spacing: 0.14em;
  text-shadow: 0 2px 12px rgba(0, 0, 0, 0.7);
}

.subtitle {
  margin-top: 4px;
  color: var(--text-muted);
  font-size: 13px;
  letter-spacing: 0.1em;
  text-shadow: 0 1px 8px rgba(0, 0, 0, 0.7);
}

.status {
  position: absolute;
  top: 84px;
  left: 0;
  right: 0;
  text-align: center;
  font-size: 13px;
  color: var(--gold-soft);
  text-shadow: 0 1px 8px rgba(0, 0, 0, 0.8);
}

.status.is-error {
  color: var(--error);
}

/* ── Floating interaction card (launch / question / shuffle) ──────────── */

.phase {
  display: flex;
  flex-direction: column;
  gap: 14px;
  align-items: center;
  pointer-events: auto;
}

#phase-launch,
#phase-question,
#phase-shuffle {
  position: absolute;
  left: 50%;
  bottom: 4%;
  transform: translateX(-50%);
  width: min(460px, 92vw);
  padding: 22px 26px;
  border-radius: var(--radius);
  border: 1px solid rgba(127, 210, 74, 0.35);
  background: var(--panel);
  backdrop-filter: blur(10px);
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
}

.phase-copy {
  color: var(--text-muted);
  font-size: 14px;
  line-height: 1.7;
  text-align: center;
  max-width: 40ch;
}

.field-label {
  align-self: flex-start;
  font-size: 13px;
  color: var(--gold-soft);
  letter-spacing: 0.08em;
}

input[type="text"] {
  width: 100%;
  padding: 10px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: rgba(10, 24, 15, 0.85);
  color: var(--text);
  font-size: 14px;
  outline: none;
}

input[type="text"]:focus {
  border-color: var(--gold);
}

.btn {
  padding: 10px 26px;
  border-radius: 999px;
  border: 1px solid var(--gold);
  font-size: 14px;
  letter-spacing: 0.12em;
  cursor: pointer;
  transition:
    background 0.2s,
    color 0.2s,
    box-shadow 0.2s;
}

.btn-primary {
  background: linear-gradient(180deg, #a5e36f 0%, var(--gold) 100%);
  color: #0d2412;
  font-weight: 600;
}

.btn-primary:hover:not(:disabled) {
  box-shadow: 0 0 18px rgba(127, 210, 74, 0.45);
}

.btn-primary:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-ghost {
  background: rgba(10, 22, 14, 0.6);
  color: var(--gold-soft);
}

.btn-ghost:hover {
  background: rgba(127, 210, 74, 0.15);
}

/* ── Card back (pure CSS — the source site has no back image) ─────────── */

.card-back-skin {
  background:
    radial-gradient(circle at 50% 42%, rgba(127, 210, 74, 0.5) 0%, transparent 26%),
    radial-gradient(circle at 50% 42%, rgba(127, 210, 74, 0.28) 0%, transparent 42%),
    repeating-linear-gradient(45deg, #14301c 0 6px, #183a22 6px 12px);
  border: 1px solid var(--gold);
  border-radius: 8px;
  position: relative;
}

.card-back-skin::after {
  content: "🐍";
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--gold-soft);
  font-size: 18px;
  text-shadow: 0 0 10px rgba(196, 243, 154, 0.8);
}

/* ── Shuffle animation ────────────────────────────────────────────────── */

.shuffle-stage {
  position: relative;
  width: 220px;
  height: 150px;
}

.shuffle-card {
  position: absolute;
  left: 74px;
  top: 15px;
  width: 72px;
  height: 120px;
  background:
    radial-gradient(circle at 50% 42%, rgba(127, 210, 74, 0.5) 0%, transparent 26%),
    repeating-linear-gradient(45deg, #14301c 0 6px, #183a22 6px 12px);
  border: 1px solid var(--gold);
  border-radius: 8px;
}

.is-shuffling .shuffle-card {
  animation: shuffle-swirl 0.9s ease-in-out infinite;
  animation-delay: calc(var(--n) * 0.12s);
}

@keyframes shuffle-swirl {
  0% {
    transform: translate(0, 0) rotate(0deg);
  }
  25% {
    transform: translate(-58px, -12px) rotate(-14deg);
  }
  50% {
    transform: translate(0, -22px) rotate(0deg);
  }
  75% {
    transform: translate(58px, -12px) rotate(14deg);
  }
  100% {
    transform: translate(0, 0) rotate(0deg);
  }
}

.is-cutting .shuffle-card {
  animation: cut-split 0.8s ease-in-out 1 forwards;
}

.is-cutting .shuffle-card:nth-child(-n + 2) {
  animation-name: cut-split-left;
}

@keyframes cut-split {
  0% {
    transform: translate(0, 0);
  }
  45% {
    transform: translate(56px, 0);
  }
  100% {
    transform: translate(0, 0);
  }
}

@keyframes cut-split-left {
  0% {
    transform: translate(0, 0);
  }
  45% {
    transform: translate(-56px, 0);
  }
  100% {
    transform: translate(0, 0);
  }
}

/* ── The 78-card spread — floats along the bottom of the screen ───────── */

#spread-area {
  position: absolute;
  left: 50%;
  bottom: 2%;
  transform: translateX(-50%);
  width: min(1100px, 94vw);
  pointer-events: auto;
}

#spread-hint {
  text-shadow: 0 1px 8px rgba(0, 0, 0, 0.8);
}

.spread {
  display: flex;
  width: 100%;
  overflow-x: auto;
  padding: 26px 12px 14px;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.spread-card {
  flex: 0 0 auto;
  width: 58px;
  height: 96px;
  margin-left: var(--spread-overlap, -38px);
  cursor: pointer;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.55);
  transition:
    transform 0.18s ease,
    box-shadow 0.18s ease;
}

.spread-card:first-child {
  margin-left: 0;
}

.spread-card:hover,
.spread-card.is-previewing {
  transform: translateY(-16px);
  box-shadow: 0 0 18px rgba(127, 210, 74, 0.55);
  z-index: 1;
}

.spread-card.is-taken {
  visibility: hidden; /* keeps the gap where the card was drawn from */
  pointer-events: none;
}

.spread.is-locked .spread-card {
  pointer-events: none;
  opacity: 0.55;
}

/* ── Slots (past / present / future) — floating over the scene ────────── */

.slots {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.card-slot {
  position: absolute;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  animation: float-bob 4.5s ease-in-out infinite alternate;
}

/* Freeze the bob while the pointer is on a card so it's easy to click. */
.card-slot:hover {
  animation-play-state: paused;
}

.card-slot[data-slot="0"] {
  left: 24%;
  top: 50%;
  animation-delay: 0s;
}

.card-slot[data-slot="1"] {
  left: 50%;
  top: 46%;
  transform: translateX(-50%);
  animation-name: float-bob-centered;
  animation-delay: 1.4s;
}

.card-slot[data-slot="2"] {
  right: 24%;
  top: 50%;
  animation-delay: 2.8s;
}

@keyframes float-bob {
  from {
    translate: 0 0;
  }
  to {
    translate: 0 -14px;
  }
}

@keyframes float-bob-centered {
  from {
    translate: 0 0;
  }
  to {
    translate: 0 -14px;
  }
}

.slot-label {
  font-size: 13px;
  color: var(--gold-soft);
  letter-spacing: 0.3em;
  text-indent: 0.3em; /* visually recenters the letter-spaced label */
  text-shadow: 0 1px 8px rgba(0, 0, 0, 0.8);
}

.card-slot .flip {
  width: 120px;
  height: 200px;
  perspective: 700px;
  border-radius: 10px;
  border: 1px dashed rgba(127, 210, 74, 0.4); /* empty-slot placeholder */
  pointer-events: auto;
}

.card-slot .flip-inner {
  visibility: hidden; /* shown once a card lands in the slot */
}

.card-slot.has-card .flip {
  border-color: transparent;
}

.card-slot.has-card .flip-inner {
  visibility: visible;
  animation: card-land 0.4s ease-out;
}

@keyframes card-land {
  from {
    transform: translateY(-26px) scale(0.85);
    opacity: 0;
  }
  to {
    transform: translateY(0) scale(1);
    opacity: 1;
  }
}

.card-slot.has-card.is-unflipped .flip {
  cursor: pointer;
}

.card-slot.has-card.is-unflipped .flip:hover {
  filter: drop-shadow(0 0 12px rgba(127, 210, 74, 0.6));
}

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

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

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

.face.front {
  transform: rotateY(180deg);
  border: 1px solid var(--gold);
  background: #08120c;
}

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

.card-slot.is-reversed .face.front img {
  transform: rotate(180deg);
}

/* Text is hidden for now (voice-only) — remove display:none to bring the
   card-name captions back. */
.slot-name {
  display: none;
  min-height: 2.6em;
  font-size: 12px;
  color: var(--text-muted);
  text-align: center;
  line-height: 1.3;
  max-width: 128px;
}

.slot-name .reversed-tag {
  color: var(--error);
}

/* ── Chat — floating bottom bar, log hidden (voice-only) ──────────────── */

.chat-area {
  position: absolute;
  left: 50%;
  bottom: 3%;
  transform: translateX(-50%);
  width: min(560px, 92vw);
  gap: 10px;
  pointer-events: auto;
}

.chat-log {
  display: flex;
  width: 100%;
  max-height: 12vh; /* keep the floating cards visible above the log */
  overflow-y: auto;
  flex-direction: column;
  gap: 8px;
  padding: 4px 2px;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.chat-log:empty {
  display: none;
}

.chat-msg {
  max-width: 88%;
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 14px;
  line-height: 1.7;
  white-space: pre-wrap;
  backdrop-filter: blur(8px);
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.35);
}

.chat-msg.user {
  align-self: flex-end;
  background: rgba(127, 210, 74, 0.16);
  border: 1px solid rgba(127, 210, 74, 0.4);
}

.chat-msg.assistant {
  align-self: flex-start;
  background: rgba(14, 30, 19, 0.9);
  border: 1px solid var(--border);
}

.chat-msg.error {
  align-self: center;
  color: var(--error);
  background: rgba(224, 140, 140, 0.08);
  border: 1px solid rgba(224, 140, 140, 0.35);
  font-size: 13px;
}

.chat-msg.thinking {
  align-self: flex-start;
  color: var(--text-muted);
  font-style: italic;
}

.chat-form {
  display: flex;
  gap: 8px;
  width: 100%;
}

.chat-form input {
  flex: 1;
}

/* Lives in the top-right corner, below the speaking indicator. */
#reset-btn {
  position: absolute;
  top: 62px;
  right: 18px;
  font-size: 13px;
  padding: 8px 18px;
  pointer-events: auto;
  z-index: 3;
}
