:root {
    --primary-color: #d4af37; /* 金色主题 */
    --bg-color: #1a1a1a;
    --text-light: #e0e0e0;
}

body {
    background: var(--bg-color) url('bg-pattern.png'); /* 可添加古典纹理背景 */
    color: var(--text-light);
    font-family: 'Noto Serif SC', serif; /* 推荐使用思源宋体 */
    min-height: 100vh;
    margin: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.controls {
    display: flex;
    gap: 1rem;
    margin: 2rem 0;  /* 增加垂直外边距 */
    position: relative; /* 新增定位基准 */
    z-index: 100;      /* 确保按钮在卡片上方 */
    align-items: center;
    justify-content: center;  /* 新增居中 */
    width: 100%;             /* 新增宽度控制 */
}

input {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid var(--primary-color);
    color: var(--text-light);
    padding: 0.8rem;
    border-radius: 6px;
    width: 100px;
    text-align: center;
    font-size: 1.2rem;
}

button {
    background: linear-gradient(to right, #d4af37, #a67c00);
    color: #2a2a2a;
    border: none;
    padding: 0.8rem 2rem;
    border-radius: 6px;
    font-weight: bold;
    cursor: pointer;
    transition: transform 0.2s;
    position: relative;
    overflow: hidden;
}

button::after {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: linear-gradient(45deg, 
        transparent, 
        rgba(255, 255, 255, 0.2), 
        transparent);
    transform: rotate(45deg);
    /* 只在悬停时触发动画，减少常驻动画 */
    left: -150%;
    transition: left 0.5s ease;
}

button:hover::after {
    left: 150%;
}

.container {
    position: absolute;
    background: rgba(0, 0, 0, 0.8);
    border: 2px solid var(--primary-color);
    border-radius: 12px;
    padding: 0.5rem;
    box-shadow: 0 0 30px rgba(212, 175, 55, 0.2);
    max-width: 1400px;
    min-height: 600px;  /* 设置最小高度 */
    width: 100%;
    height: auto; 
    top: 50%;
    transform: translateY(-50%); /* 垂直居中 */
    overflow: hidden; /* 防止动画越界 */
}

#cardDisplay {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    position: relative;
    gap: 10px;
    padding: 20px 0;
    min-height: 400px;  /* 增大最小高度保证可见性 */
    max-height: 600px;  /* 减小最大高度避免溢出容器 */
    overflow-y: auto;   /* 明确垂直滚动 */
    overflow-x: hidden; /* 隐藏水平溢出 */
    align-content: flex-end; /* 新增：顶部对齐 */
}

.card {
    position: absolute;
    transform-origin: bottom center;
    width: 180px !important;     
    height: auto !important;
    min-height: 270px;           /* 设置最小高度 */
    bottom: 20px;  /* 新增底部基准线 */
    margin: 10px 0;  /* 增加垂直间距 */
    padding: 1rem;
    z-index: 1;      
    transition: all 0.6s cubic-bezier(0.4, 0, 0.2, 1), transform 0.3s ease; /* 新增平移过渡 */
    display: flex;               /* 新增flex布局 */
    flex-direction: column;      /* 垂直排列 */
    align-items: center;         /* 水平居中 */
    justify-content: center;     /* 垂直居中 */
    text-align: center;           /* 文本居中 */
    overflow: hidden;          /* 防止内容溢出 */
}

.card.init-animation {
    animation: fanSpread 1s ease-in-out forwards;
}

.card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(120deg,
        transparent 20%,
        rgba(212, 175, 55, 0.1) 50%,
        transparent 80%);
    /* 减少不必要的动画，只在悬停时显示 */
    opacity: 0.3;
    transition: opacity 0.3s ease;
}

/* 结果卡片横向排列 */
#cardDisplay.results {
    flex-wrap: nowrap !important;  /* 禁止换行 */
    justify-content: space-around; /* 均匀分布 */
    gap: 30px;        /* 增大间距 */
    padding: 20px;    /* 增加内边距 */
    justify-content: space-around;  /* 新增间距分布 */
}

#cardDisplay.results .card {
    position: static !important;
    transform: none !important;  /* 移除所有变形 */
    margin: 0 !important;        /* 清除外边距 */
    animation: none !important;  /* 禁用动画 */
    border-radius: 16px;      /* 卡片整体圆角增强 */
    box-shadow: 0 0 20px rgba(212, 175, 55, 0.2); /* 卡片阴影增强 */
}

/* 下方默认卦牌区域 */
#defaultDeck {
    margin-top: 260px;
    text-align: center;
}

/* 图片尺寸限制 */
.card img {
    width: 100% !important;     /* 强制充满容器 */
    height: auto !important;
    max-height: 240px;         /* 增大最大高度 */
    min-height: 200px;         /* 设置最小高度 */
    object-fit: contain;
    margin: 0 auto;
    flex-shrink: 0;            /* 禁止图片收缩 */
    border-radius: 12px;       /* 新增圆角效果 */
    overflow: hidden;         /* 确保圆角不溢出 */      
}

.card h3 {
    color: var(--primary-color);
    margin: 0 0 0.5rem;
    font-size: 1.5rem; /* 缩小标题字号 */
}

.card p {
    font-size: 1rem;
    line-height: 1.2;
    opacity: 0.8;
}

/* 初始化动画只播放一次 */
.card.init-animation {
    animation: fanSpread 1s ease-in-out 1;
    animation-fill-mode: forwards;
}

@keyframes fanSpread {
    0% { transform: rotate(0deg) translateY(0); }
    50% { transform: rotate(var(--rot)) translateY(-18px); } /* 展开到目标位置 */
    100% { transform: rotate(var(--rot)) translateY(-10px); } /* 稍微回弹 */
}

/* 洗牌动画 */
.shuffling {
    animation: shuffleMove 2s ease-in-out;
}

@keyframes shine {
    0% { left: -50%; }
    100% { left: 150%; }
}

@keyframes glow {
    0%, 100% { opacity: 0.3; }
    50% { opacity: 0.6; }
}

@keyframes shuffleMove {
    0% { transform: rotate(0) translateY(0); }
    25% { transform: rotate(-5deg) translateY(-20px); }
    50% { transform: rotate(5deg) translateY(20px); }
    75% { transform: rotate(-3deg) translateY(-10px); }
    100% { transform: rotate(0) translateY(0); }
}

/* 需要合并的洗牌动画定义 */
/* 优化洗牌动画，使用CSS变量 */
@keyframes fanShuffle {
    0% { transform: rotate(calc(-5deg * (var(--card-index, 0) * 0.2 + 1))) translateY(-20px); }
    50% { transform: rotate(calc(5deg * (var(--card-index, 0) * 0.2 + 1))) translateY(20px); }
    100% { transform: rotate(calc(-3deg * (var(--card-index, 0) * 0.2 + 1))) translateY(-10px); }
}

/* 优化提升卡片动画 */
@keyframes liftCard {
    0% { transform: translateY(0); }
    100% { transform: translateY(-40px); }
}

.card.highlight {
    animation: liftCard 0.5s ease-out forwards;
    z-index: 999 !important;
}

/* 优化洗牌动画，减少动画时间，避免无限循环 */
.shuffling .card {
    animation: fanShuffle 1.5s ease-in-out;
}

/* 初始化扇形排列 */
.card:nth-child(n) {
    transform: rotate(var(--rot)) translateY(-50px);
}

.title {
font-family: 'ZCOOL XiaoWei', serif;
color: var(--primary-color);
font-size: 2.5rem;
text-align: center;
margin: 1rem 0 2rem;
text-shadow: 0 0 10px rgba(212, 175, 55, 0.5);
}

/* 关于按钮样式 */
.about-btn {
    position: fixed;
    left: 20px;
    top: 50%;
    transform: translateY(-50%);
    z-index: 1000;
    padding: 12px 24px;
}

/* 关于页面蒙层 */
.about-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.9);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}

.about-content {
    background: var(--bg-color);
    padding: 2rem;
    border-radius: 12px;
    max-width: 600px;
    position: relative;
}

.qr-container {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 2rem;
    margin-top: 1.5rem;
}

.qr-item img {
    width: 200px;
    height: auto;
    border: 2px solid var(--primary-color);
    border-radius: 8px;
}

.close-btn {
    position: absolute;
    top: 10px;
    right: 10px;
    font-size: 2rem;
    background: none;
    border: none;
    color: var(--primary-color);
}

/* 优化3D变换支持 */
#cardDisplay {
    transform-style: preserve-3d;
    /* 添加硬件加速，但仅在必要时 */
    will-change: transform;
}

.card {
    transition-timing-function: cubic-bezier(0.17, 0.67, 0.35, 1.1);
    /* 移除单个卡片的硬件加速，避免过多内存消耗 */
    /* 只在动画时添加硬件加速 */
}

.card.init-animation, .card.highlight, .shuffling .card {
    will-change: transform;
}

.footer {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    text-align: center;
    padding: 10px 0;
    background-color: rgba(0, 0, 0, 0.7);
    z-index: 1000;
    font-size: 12px;
}
.footer a {
    color: #666;
    text-decoration: none;
}
.footer a:hover {
    text-decoration: underline;
}