/* ============================================================
   塔罗牌占卜 - 手势互动抽卡 样式
   纯 CSS 3D 实现，无第三方库依赖
   ============================================================ */

/* ====== 重置 ====== */
*, *::before, *::after {
    margin: 0; padding: 0; box-sizing: border-box;
}

:root {
    --bg: #0a0a14;
    --gold: #d4a853;
    --gold-light: #f0d68a;
    --purple: #6b3fa0;
    --purple-dark: #2d1b4e;
    --text: #e0d8f0;
    --text-muted: #9a8bb8;
    --card-w: 60px;
    --card-h: 96px;
    --card-fan-w: 75px;
    --card-fan-h: 120px;
    --cylinder-radius: 280px;
    --perspective: 1000px;
    --entry-stagger: 50ms;
    --total-cards: 78;
}

html, body {
    width: 100%; height: 100%;
    overflow: hidden;
    background: var(--bg);
    color: var(--text);
    font-family: 'Georgia', 'Noto Serif SC', 'STSong', 'SimSun', serif;
    user-select: none;
    -webkit-user-select: none;
}

#app {
    width: 100%; height: 100%;
    position: relative;
    overflow: hidden;
}

/* ====== 场景 ====== */
#scene {
    position: fixed;
    inset: 0;
    z-index: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    perspective: var(--perspective);
    perspective-origin: 50% 55%;
}

#floor-glow {
    position: absolute;
    bottom: 10%;
    left: 50%;
    transform: translateX(-50%);
    width: 80vmin; height: 80vmin;
    border-radius: 50%;
    background: radial-gradient(ellipse, rgba(107,63,160,0.2) 0%, transparent 70%);
    pointer-events: none;
    animation: floorPulse 4s ease-in-out infinite;
}
@keyframes floorPulse {
    0%, 100% { opacity: 0.5; transform: translateX(-50%) scale(1); }
    50% { opacity: 0.8; transform: translateX(-50%) scale(1.08); }
}

/* ====== 粒子背景 ====== */
#particles-bg {
    position: fixed;
    inset: 0;
    z-index: 0;
    pointer-events: none;
    opacity: 0.5;
}

/* ====== 卡牌容器 ====== */
#card-container {
    position: relative;
    width: 0; height: 0;
    transform-style: preserve-3d;
    /* 旋转由JS控制 */
}

/* ====== 卡牌 ====== */
.card {
    position: absolute;
    width: var(--card-fan-w);
    height: var(--card-fan-h);
    left: calc(var(--card-fan-w) / -2);
    top: calc(var(--card-fan-h) / -2);
    transform-style: preserve-3d;
    cursor: pointer;
    will-change: transform;
    /* 默认透明，入场后显示 */
    opacity: 0;
}

.card.entered {
    opacity: 1;
}

.card-inner {
    width: 100%;
    height: 100%;
    position: relative;
    transform-style: preserve-3d;
    border-radius: 4px;
}

.card-face {
    position: absolute;
    inset: 0;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
    border-radius: 4px;
    overflow: hidden;
    /* 内容由JS生成的canvas填充 */
    background-size: 100% 100%;
    background-repeat: no-repeat;
}

.card-back {
    z-index: 2;
    background: linear-gradient(135deg, #1a0a3e, #2d1048, #1a0a3e);
    border: 2px solid var(--gold);
    box-shadow: inset 0 0 20px rgba(212,168,83,0.1);
}

.card-face.card-back canvas {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
}

.card-front {
    transform: rotateY(180deg);
    background: linear-gradient(180deg, #faf3e6, #f5e6c8, #efe0c0);
    border: 2px solid #8b6914;
    box-shadow: inset 0 0 10px rgba(139,105,20,0.1);
}

.card-front canvas {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
}

/* ====== 卡牌入场动画 ====== */
.card.entry-phase {
    transition: opacity 0s, transform 0.7s cubic-bezier(0.34, 1.56, 0.64, 1);
    opacity: 0;
}

.card.entered {
    opacity: 1;
}

/* ====== 卡牌选中高亮（旋转阶段） ====== */
.card.highlighted .card-back {
    box-shadow: 0 0 25px var(--gold), 0 0 50px rgba(212,168,83,0.4);
    border-color: var(--gold-light);
}

/* ====== 卡牌选中后浮出 ====== */
.card.selected {
    z-index: 100 !important;
    pointer-events: none;
}
.card.selected .card-back {
    border-color: var(--gold-light);
    box-shadow: 0 0 30px rgba(212,168,83,0.6);
}

/* ====== 洗牌动画 ====== */
.card.shuffle-split-left {
    transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}
.card.shuffle-split-right {
    transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

.card.shuffle-riffle {
    transition: transform 0.18s cubic-bezier(0.4, 0, 0.2, 1);
}

.card.shuffle-return {
    transition: transform 0.55s cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* ====== 3D圆柱旋转阶段 ====== */
.card.cylinder-mode {
    position: absolute;
    transform-style: preserve-3d;
}

/* ====== 翻牌动画 ====== */
.card.flipped .card-inner {
    transform: rotateY(180deg);
}
.card .card-inner {
    transition: transform 0.6s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ====== 弹出展示动画 ====== */
.card.popup-mode {
    z-index: 200 !important;
    pointer-events: none;
}
.card.popup-mode .card-inner {
    transform: rotateY(180deg);
}

/* ====== 返回按钮 ====== */
#back-btn {
    position: fixed;
    top: 24px;
    left: 24px;
    z-index: 60;
    font-family: inherit;
    font-size: 0.95rem;
    padding: 8px 18px;
    border-radius: 50px;
    border: 1px solid rgba(212,168,83,0.3);
    background: rgba(10,10,20,0.6);
    backdrop-filter: blur(10px);
    color: var(--gold-light);
    cursor: pointer;
    text-decoration: none;
    letter-spacing: 0.06em;
    transition: all 0.3s ease;
}
#back-btn:hover {
    background: rgba(107,63,160,0.4);
    border-color: var(--gold);
    box-shadow: 0 0 20px rgba(212,168,83,0.2);
    transform: translateX(-2px);
}

/* ====== UI ====== */
#ui-layer {
    position: fixed;
    inset: 0;
    z-index: 10;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    pointer-events: none;
}
#ui-layer > * {
    pointer-events: auto;
}

#title {
    font-size: 3rem;
    font-weight: normal;
    color: var(--gold-light);
    text-shadow: 0 0 30px rgba(212,168,83,0.4), 0 0 60px rgba(212,168,83,0.2);
    letter-spacing: 0.15em;
    margin-bottom: 0.3em;
    transition: all 0.8s ease;
}
#subtitle {
    font-size: 1.1rem;
    color: var(--text-muted);
    margin-bottom: 2.5em;
    letter-spacing: 0.1em;
    transition: all 0.8s ease;
}
#start-btn {
    font-family: inherit;
    font-size: 1.4rem;
    padding: 0.8em 2.5em;
    border: 2px solid var(--gold);
    border-radius: 50px;
    background: rgba(107,63,160,0.3);
    color: var(--gold-light);
    cursor: pointer;
    letter-spacing: 0.1em;
    transition: all 0.3s ease;
    backdrop-filter: blur(10px);
    position: relative;
    overflow: hidden;
}
#start-btn::before {
    content: '';
    position: absolute;
    top: 0; left: -100%;
    width: 100%; height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.1), transparent);
    transition: left 0.5s ease;
}
#start-btn:hover {
    background: rgba(107,63,160,0.5);
    border-color: var(--gold-light);
    box-shadow: 0 0 30px rgba(212,168,83,0.4), 0 0 60px rgba(107,63,160,0.3);
    transform: translateY(-2px);
}
#start-btn:hover::before { left: 100%; }
#start-btn:active { transform: scale(0.96); }
#start-btn:disabled {
    opacity: 0.5; cursor: not-allowed; pointer-events: none;
}

/* 手势提示 */
#gesture-hint {
    text-align: center;
    animation: fadeInUp 0.6s ease;
}
#gesture-hint .hint-icon {
    font-size: 3rem;
    animation: bounce 1.5s ease-in-out infinite;
}
#gesture-hint .hint-main {
    font-size: 1.6rem; color: var(--gold-light);
    margin: 0.5em 0 0.2em; letter-spacing: 0.08em;
}
#gesture-hint .hint-sub {
    font-size: 1rem; color: var(--text-muted); letter-spacing: 0.05em;
}
#gesture-hint .hint-fallback {
    font-size: 0.8rem; color: rgba(154,139,184,0.6); margin-top: 0.8em; letter-spacing: 0.03em;
}
#gesture-hint .hint-fallback kbd {
    padding: 1px 6px; border-radius: 3px; background: rgba(212,168,83,0.15);
    border: 1px solid rgba(212,168,83,0.3); font-family: inherit; color: var(--gold-light);
}

/* 选择进度 */
#selected-count { color: var(--gold-light); font-size: 1.3rem; }

/* 摄像头 */
#webcam-container {
    position: fixed; bottom: 20px; right: 20px; z-index: 20;
    border-radius: 16px; overflow: hidden;
    border: 2px solid rgba(212,168,83,0.5);
    box-shadow: 0 0 20px rgba(0,0,0,0.5);
    transition: all 0.4s ease;
}
#webcam-container.hidden { opacity: 0; transform: scale(0.8); pointer-events: none; }
#webcam { width: 200px; height: 150px; object-fit: cover; display: block; transform: scaleX(-1); }
#webcam-canvas { display: none; }

/* 摄像头开关 */
#camera-toggle {
    position: fixed; top: 20px; right: 20px; z-index: 30;
    padding: 8px 18px; border-radius: 10px; cursor: pointer;
    font-size: 13px; letter-spacing: 1px; font-family: inherit;
    background: rgba(255,255,255,0.04);
    border: 1px solid rgba(255,255,255,0.06);
    color: rgba(255,255,255,0.35);
    transition: all 0.3s ease;
}
#camera-toggle:hover {
    background: rgba(255,255,255,0.08);
    border-color: rgba(255,255,255,0.1);
    color: rgba(255,255,255,0.6);
}
#camera-toggle.active {
    background: rgba(244,67,54,0.08);
    border-color: rgba(244,67,54,0.12);
    color: rgba(244,67,54,0.4);
}
#camera-toggle.active:hover {
    background: rgba(244,67,54,0.12);
    color: rgba(244,67,54,0.6);
}

/* 选牌栏 */
#selected-cards-bar {
    position: fixed; bottom: 30px; left: 50%; z-index: 15;
    transform: translateX(-50%); display: flex; gap: 1.5em;
    transition: all 0.5s ease;
}
#selected-cards-bar.hidden { opacity: 0; transform: translateX(-50%) translateY(30px); pointer-events: none; }
.selected-card-slot {
    width: 100px; height: 160px; border-radius: 8px;
    border: 2px dashed rgba(212,168,83,0.4);
    display: flex; align-items: center; justify-content: center;
    background: rgba(107,63,160,0.15); transition: all 0.4s ease;
    position: relative; overflow: hidden;
}
.selected-card-slot.filled { border: 2px solid var(--gold); background: rgba(107,63,160,0.3); box-shadow: 0 0 20px rgba(212,168,83,0.3); }
.selected-card-slot.filled .slot-placeholder { display: none; }
.slot-placeholder { font-size: 2rem; color: rgba(212,168,83,0.4); }
.slot-card { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 12px; }
.slot-card .card-name { font-size: 0.85rem; color: var(--gold-light); text-align: center; }
.slot-card .card-position { font-size: 0.7rem; color: var(--text-muted); margin-top: 4px; }

/* 卡牌展示 */
#reading-showcase { text-align: center; padding: 1em; }
#reading-showcase h2 { font-size: 1.6rem; color: var(--gold-light); font-weight: normal; letter-spacing: 0.1em; margin-bottom: 1.2em; }
#showcase-cards { display: flex; gap: 2em; justify-content: center; flex-wrap: wrap; margin-bottom: 1.5em; }
.showcase-card { width: 160px; }
.showcase-front { width: 160px; height: 240px; border-radius: 8px; overflow: hidden; border: 2px solid var(--gold); box-shadow: 0 0 30px rgba(212,168,83,0.3); }
.showcase-front canvas { width: 100%; height: 100%; display: block; }
.showcase-name { font-size: 1rem; color: var(--gold-light); margin-top: 0.6em; letter-spacing: 0.05em; }
.showcase-pos { font-size: 0.8rem; color: var(--text-muted); margin-top: 0.2em; }
#view-report-btn {
    font-family: inherit; font-size: 1.2rem; padding: 0.7em 2.5em;
    border: 2px solid var(--gold); border-radius: 50px;
    background: rgba(107,63,160,0.3); color: var(--gold-light);
    cursor: pointer; letter-spacing: 0.1em; transition: all 0.3s ease;
    margin-top: 0.5em;
}
#view-report-btn:hover { background: rgba(107,63,160,0.5); box-shadow: 0 0 25px rgba(212,168,83,0.3); }

/* 报告页卡牌 */
#report-cards { display: flex; gap: 1.5em; justify-content: center; flex-wrap: wrap; margin-bottom: 1.5em; }
.report-card { width: 100px; }
.report-front { width: 100px; height: 150px; border-radius: 6px; overflow: hidden; border: 2px solid var(--gold); box-shadow: 0 0 15px rgba(212,168,83,0.2); margin: 0 auto; }
.report-front canvas { width: 100%; height: 100%; display: block; }
.report-name { font-size: 0.9rem; color: var(--gold-light); margin-top: 0.4em; text-align: center; }
.report-pos { font-size: 0.75rem; color: var(--text-muted); margin-top: 0.15em; text-align: center; }

@media (max-width: 768px) {
    .showcase-card { width: 100px; }
    .showcase-front { width: 100px; height: 150px; }
    .report-card { width: 80px; }
    .report-front { width: 80px; height: 120px; }
}

/* 解读弹窗 */
#reading-overlay {
    position: fixed; inset: 0; z-index: 50;
    background: rgba(10,10,20,0.92); display: flex;
    align-items: center; justify-content: center;
    backdrop-filter: blur(10px); transition: all 0.6s ease;
}
#reading-overlay.hidden { opacity: 0; pointer-events: none; }
#reading-content {
    background: linear-gradient(135deg, rgba(45,27,78,0.95), rgba(20,10,40,0.95));
    border: 2px solid var(--gold); border-radius: 24px; padding: 3em 2.5em;
    max-width: 900px; width: 90%; max-height: 85vh; overflow-y: auto;
    box-shadow: 0 0 60px rgba(107,63,160,0.4), 0 0 120px rgba(212,168,83,0.2);
    animation: modalIn 0.5s ease; text-align: center;
}
#reading-content h2 { font-size: 2rem; color: var(--gold-light); font-weight: normal; letter-spacing: 0.12em; margin-bottom: 1.5em; }
#reading-cards-row { display: flex; gap: 1.5em; justify-content: center; flex-wrap: wrap; margin-bottom: 2em; }
.reading-card {
    background: rgba(107,63,160,0.2); border: 1px solid rgba(212,168,83,0.4);
    border-radius: 16px; padding: 1.5em; width: 240px; text-align: center;
    transition: transform 0.3s ease;
}
.reading-card:hover { transform: translateY(-4px); box-shadow: 0 8px 30px rgba(107,63,160,0.4); }
.reading-card .card-position-label { font-size: 0.85rem; color: var(--text-muted); letter-spacing: 0.08em; margin-bottom: 0.5em; }
.reading-card .card-display-name { font-size: 1.3rem; color: var(--gold-light); letter-spacing: 0.06em; margin-bottom: 0.8em; }
.reading-card .card-meaning { font-size: 0.9rem; color: var(--text); line-height: 1.7; }
#reading-summary { margin: 1.5em 0; padding: 1.5em; background: rgba(212,168,83,0.08); border-radius: 12px; border: 1px solid rgba(212,168,83,0.2); }
#reading-summary p { color: var(--text); line-height: 1.8; font-size: 1.05rem; white-space: pre-line; }
#restart-btn {
    font-family: inherit; font-size: 1.1rem; padding: 0.7em 2em;
    border: 2px solid var(--gold); border-radius: 50px;
    background: rgba(107,63,160,0.3); color: var(--gold-light);
    cursor: pointer; letter-spacing: 0.08em; transition: all 0.3s ease; margin-top: 1em;
}
#restart-btn:hover { background: rgba(107,63,160,0.5); box-shadow: 0 0 25px rgba(212,168,83,0.3); }

/* ====== 通用 ====== */
.hidden { display: none !important; }

/* ====== 动画 ====== */
@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}
@keyframes bounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-15px); }
}
@keyframes dotPulse {
    0%, 100% { box-shadow: 0 0 8px var(--gold); transform: scale(1); }
    50% { box-shadow: 0 0 20px var(--gold-light); transform: scale(1.3); }
}
@keyframes modalIn {
    from { opacity: 0; transform: scale(0.9) translateY(20px); }
    to { opacity: 1; transform: scale(1) translateY(0); }
}

/* ====== 滚动条 ====== */
#reading-content::-webkit-scrollbar { width: 6px; }
#reading-content::-webkit-scrollbar-track { background: transparent; }
#reading-content::-webkit-scrollbar-thumb { background: rgba(212,168,83,0.3); border-radius: 3px; }

/* ====== 响应式 ====== */
@media (max-width: 768px) {
    :root {
        --card-fan-w: 52px;
        --card-fan-h: 83px;
        --cylinder-radius: 180px;
        --perspective: 800px;
    }
    #title { font-size: 2rem; }
    #subtitle { font-size: 0.9rem; }
    #start-btn { font-size: 1.1rem; padding: 0.6em 1.8em; }
    #gesture-hint .hint-main { font-size: 1.2rem; }
    #selected-cards-bar { gap: 0.8em; bottom: 20px; }
    .selected-card-slot { width: 70px; height: 112px; }
    #reading-content { padding: 2em 1em; }
    .reading-card { width: 180px; padding: 1em; }
    #webcam { width: 140px; height: 105px; }
}
