/* ================================
   CSS Variables & Reset
================================ */
:root {
    --primary-red: #D32F2F;
    --deep-red: #B71C1C;
    --light-red: #EF5350;
    --gold: #FFD700;
    --gold-dark: #FFC107;
    --gold-light: #FFECB3;
    --bg-dark: #1A0A0A;
    --text-light: #FFFFFF;
    --text-cream: #FFF8E1;
    --shadow-color: rgba(0, 0, 0, 0.3);
    --card-bg: linear-gradient(135deg, #FFF8E1 0%, #FFECB3 100%);
    --btn-gradient: linear-gradient(135deg, var(--gold) 0%, var(--gold-dark) 100%);
    --red-gradient: linear-gradient(180deg, var(--light-red) 0%, var(--deep-red) 100%);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    height: 100%;
    overflow-x: hidden;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
    background: var(--red-gradient);
    background-attachment: fixed;
    color: var(--text-light);
    min-height: 100vh;
    position: relative;
}

/* 喜庆背景装饰 */
body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-image: 
        radial-gradient(circle at 10% 20%, rgba(255, 215, 0, 0.1) 0%, transparent 20%),
        radial-gradient(circle at 90% 80%, rgba(255, 215, 0, 0.1) 0%, transparent 20%),
        radial-gradient(circle at 50% 50%, rgba(255, 255, 255, 0.05) 0%, transparent 50%);
    pointer-events: none;
    z-index: 0;
}

/* ================================
   Layout
================================ */
#app-container {
    position: relative;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    z-index: 1;
    padding: 20px;
    padding-bottom: 140px;
}

/* ================================
   Header & Menu Button
================================ */
#header {
    position: fixed;
    top: 15px;
    right: 15px;
    z-index: 100;
}

#menu-btn {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    overflow: hidden;
    cursor: pointer;
    box-shadow: 
        0 4px 15px var(--shadow-color),
        0 0 20px rgba(255, 215, 0, 0.3);
    border: 2px solid var(--gold);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    background: var(--primary-red);
}

#menu-btn:hover {
    transform: scale(1.1);
    box-shadow: 
        0 6px 20px var(--shadow-color),
        0 0 30px rgba(255, 215, 0, 0.5);
}

#menu-btn img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* ================================
   Main Content
================================ */
#main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 0 20px;
}

/* Title Area */
#title-area {
    text-align: center;
    margin-bottom: 30px;
}

#title-area h1 {
    font-size: 4rem;
    font-weight: 900;
    color: var(--gold);
    text-shadow: 
        0 0 20px rgba(255, 215, 0, 0.5),
        2px 2px 4px var(--shadow-color);
    letter-spacing: 0.1em;
    animation: glow 2s ease-in-out infinite alternate;
}

#title-area h2 {
    font-size: 1.8rem;
    font-weight: 600;
    color: var(--text-cream);
    margin-top: 5px;
    letter-spacing: 0.3em;
}

#title-area .subtitle {
    font-size: 1rem;
    color: rgba(255, 255, 255, 0.8);
    margin-top: 10px;
}

/* ================================
   Fortune Card
================================ */
#fortune-card {
    width: 280px;
    height: 360px;
    perspective: 1000px;
    margin-bottom: 30px;
}

.card-front, .card-back {
    width: 100%;
    height: 100%;
    position: absolute;
    backface-visibility: hidden;
    transition: transform 0.6s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.card-front {
    transform: rotateY(0deg);
}

.card-back {
    transform: rotateY(180deg);
}

#fortune-card.flipped .card-front {
    transform: rotateY(-180deg);
}

#fortune-card.flipped .card-back {
    transform: rotateY(0deg);
}

/* 签筒样式 */
.fortune-tube {
    position: relative;
    width: 120px;
    text-align: center;
}

.tube-body {
    width: 100%;
    height: 200px;
    background: linear-gradient(90deg, #8B4513 0%, #D2691E 30%, #CD853F 50%, #D2691E 70%, #8B4513 100%);
    border-radius: 10px 10px 20px 20px;
    position: relative;
    box-shadow: 
        inset 0 -20px 30px rgba(0, 0, 0, 0.3),
        0 10px 30px var(--shadow-color);
    overflow: hidden;
}

.tube-body::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 20px;
    background: linear-gradient(90deg, #654321 0%, #8B4513 50%, #654321 100%);
    border-radius: 10px 10px 0 0;
}

.sticks {
    position: absolute;
    top: -30px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 8px;
}

.sticks span {
    width: 8px;
    height: 80px;
    background: linear-gradient(180deg, var(--gold) 0%, #DAA520 100%);
    border-radius: 4px 4px 2px 2px;
    box-shadow: 0 2px 5px var(--shadow-color);
}

.sticks span:nth-child(1) { transform: rotate(-15deg); height: 70px; }
.sticks span:nth-child(2) { transform: rotate(-8deg); height: 85px; }
.sticks span:nth-child(3) { transform: rotate(0deg); height: 90px; }
.sticks span:nth-child(4) { transform: rotate(8deg); height: 85px; }
.sticks span:nth-child(5) { transform: rotate(15deg); height: 70px; }

.tube-label {
    position: absolute;
    bottom: -50px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 3rem;
    color: var(--gold);
    font-weight: bold;
    text-shadow: 0 0 10px rgba(255, 215, 0, 0.5);
}

/* 结果卡片样式 */
.result-card {
    width: 260px;
    min-height: 320px;
    background: var(--card-bg);
    border-radius: 15px;
    padding: 30px 25px;
    position: relative;
    box-shadow: 
        0 10px 40px var(--shadow-color),
        0 0 30px rgba(255, 215, 0, 0.2);
    border: 3px solid var(--gold);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.result-decoration {
    position: absolute;
    width: 30px;
    height: 30px;
    border: 3px solid var(--primary-red);
}

.result-decoration.top-left {
    top: 10px;
    left: 10px;
    border-right: none;
    border-bottom: none;
}

.result-decoration.top-right {
    top: 10px;
    right: 10px;
    border-left: none;
    border-bottom: none;
}

.result-decoration.bottom-left {
    bottom: 10px;
    left: 10px;
    border-right: none;
    border-top: none;
}

.result-decoration.bottom-right {
    bottom: 10px;
    right: 10px;
    border-left: none;
    border-top: none;
}

.result-number {
    font-size: 1rem;
    color: var(--primary-red);
    margin-bottom: 15px;
    opacity: 0.8;
}

.result-text {
    font-size: 1.4rem;
    color: var(--deep-red);
    text-align: center;
    line-height: 2;
    font-weight: 500;
    padding: 0 10px;
}

/* ================================
   Buttons
================================ */
#action-btns {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px;
}

#result-btns {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
}

.btn-primary, .btn-secondary {
    padding: 15px 40px;
    border: none;
    border-radius: 50px;
    font-size: 1.1rem;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: all 0.3s ease;
    min-width: 180px;
    justify-content: center;
}

.btn-primary {
    background: var(--btn-gradient);
    color: var(--deep-red);
    box-shadow: 
        0 4px 15px rgba(255, 215, 0, 0.4),
        0 0 20px rgba(255, 215, 0, 0.2);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 
        0 6px 20px rgba(255, 215, 0, 0.5),
        0 0 30px rgba(255, 215, 0, 0.3);
}

.btn-primary:active {
    transform: translateY(0);
}

.btn-secondary {
    background: transparent;
    color: var(--gold);
    border: 2px solid var(--gold);
}

.btn-secondary:hover {
    background: rgba(255, 215, 0, 0.1);
}

.btn-icon {
    font-size: 1.2rem;
}

/* 抽签动画 */
#fortune-card.shaking .fortune-tube {
    animation: shake 0.5s ease-in-out infinite;
}

#fortune-card.shaking .sticks span {
    animation: stickJump 0.3s ease-in-out infinite alternate;
}

#fortune-card.shaking .sticks span:nth-child(1) { animation-delay: 0s; }
#fortune-card.shaking .sticks span:nth-child(2) { animation-delay: 0.05s; }
#fortune-card.shaking .sticks span:nth-child(3) { animation-delay: 0.1s; }
#fortune-card.shaking .sticks span:nth-child(4) { animation-delay: 0.15s; }
#fortune-card.shaking .sticks span:nth-child(5) { animation-delay: 0.2s; }

/* ================================
   Footer
================================ */
#footer {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: linear-gradient(180deg, transparent 0%, rgba(0, 0, 0, 0.5) 100%);
    padding: 15px 20px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    z-index: 50;
}

.footer-btn {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 20px;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 215, 0, 0.3);
    border-radius: 10px;
    color: var(--text-cream);
    text-decoration: none;
    font-size: 0.95rem;
    transition: all 0.3s ease;
}

.footer-btn:hover {
    background: rgba(255, 215, 0, 0.2);
    border-color: var(--gold);
}

.footer-btn small {
    width: 100%;
    text-align: center;
    font-size: 0.75rem;
    color: rgba(255, 255, 255, 0.7);
    margin-top: 3px;
}

/* ================================
   Menu Popup
================================ */
.popup {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
}

.popup.hidden {
    display: none;
}

.popup-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(3px);
}

.popup-content {
    position: relative;
    z-index: 1;
    background: linear-gradient(135deg, var(--deep-red) 0%, #2D0A0A 100%);
    border-radius: 20px;
    padding: 25px;
    border: 2px solid var(--gold);
    box-shadow: 0 10px 50px rgba(0, 0, 0, 0.5);
    max-width: 90%;
    max-height: 90vh;
    overflow-y: auto;
}

.menu-content {
    display: flex;
    flex-direction: column;
    gap: 12px;
    min-width: 200px;
}

.menu-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 15px 20px;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 215, 0, 0.3);
    border-radius: 12px;
    color: var(--text-cream);
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.3s ease;
}

.menu-item:hover {
    background: rgba(255, 215, 0, 0.2);
    border-color: var(--gold);
    transform: translateX(5px);
}

.menu-icon {
    font-size: 1.3rem;
}

/* ================================
   Poster Modal
================================ */
.poster-content {
    width: 340px;
    max-width: 95%;
    padding: 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.poster-loading {
    text-align: center;
    padding: 40px 20px;
}

.loading-spinner {
    width: 50px;
    height: 50px;
    border: 4px solid rgba(255, 215, 0, 0.3);
    border-top-color: var(--gold);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 15px;
}

#poster-canvas {
    width: 300px;
    background: linear-gradient(180deg, var(--primary-red) 0%, var(--deep-red) 100%);
    border-radius: 15px;
    padding: 25px 20px;
    border: 3px solid var(--gold);
    text-align: center;
}

.poster-header {
    margin-bottom: 20px;
}

.poster-year {
    font-size: 2.5rem;
    font-weight: 900;
    color: var(--gold);
    text-shadow: 0 0 10px rgba(255, 215, 0, 0.5);
}

.poster-title {
    font-size: 1.2rem;
    color: var(--text-cream);
    letter-spacing: 0.2em;
}

.poster-body {
    background: var(--card-bg);
    border-radius: 10px;
    padding: 25px 15px;
    margin-bottom: 20px;
    border: 2px solid var(--gold-dark);
}

.poster-result {
    font-size: 1.2rem;
    color: var(--deep-red);
    line-height: 1.8;
    font-weight: 500;
}

.poster-footer {
    display: flex;
    align-items: center;
    gap: 15px;
    justify-content: center;
}

#qrcode-container {
    width: 80px;
    height: 80px;
    background: white;
    border-radius: 8px;
    padding: 5px;
    display: flex;
    align-items: center;
    justify-content: center;
}

#qrcode-container canvas,
#qrcode-container img {
    max-width: 100%;
    max-height: 100%;
}

.poster-info {
    text-align: left;
    font-size: 0.8rem;
    color: var(--text-cream);
}

.poster-info p {
    margin-bottom: 5px;
}

.poster-channel {
    color: var(--gold);
    font-weight: 600;
}

#poster-image-container {
    text-align: center;
}

#poster-image {
    max-width: 100%;
    border-radius: 15px;
    box-shadow: 0 5px 20px rgba(0, 0, 0, 0.3);
}

.save-tip {
    margin-top: 10px;
    font-size: 0.85rem;
    color: var(--gold);
}

#poster-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 20px;
    justify-content: center;
}

.action-btn {
    padding: 10px 18px;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid var(--gold);
    border-radius: 25px;
    color: var(--gold);
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.3s ease;
}

.action-btn:hover {
    background: var(--gold);
    color: var(--deep-red);
}

.close-btn {
    position: absolute;
    top: 10px;
    right: 10px;
    width: 30px;
    height: 30px;
    border: none;
    background: rgba(255, 255, 255, 0.2);
    color: var(--text-light);
    font-size: 1.5rem;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

.close-btn:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* ================================
   Toast
================================ */
.toast {
    position: fixed;
    bottom: 160px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.8);
    color: white;
    padding: 12px 25px;
    border-radius: 25px;
    font-size: 0.9rem;
    z-index: 300;
    animation: fadeInUp 0.3s ease;
}

.toast.hidden {
    display: none;
}

/* ================================
   Utility Classes
================================ */
.hidden {
    display: none !important;
}

/* ================================
   Animations
================================ */
@keyframes glow {
    from {
        text-shadow: 
            0 0 20px rgba(255, 215, 0, 0.5),
            2px 2px 4px var(--shadow-color);
    }
    to {
        text-shadow: 
            0 0 40px rgba(255, 215, 0, 0.8),
            0 0 60px rgba(255, 215, 0, 0.4),
            2px 2px 4px var(--shadow-color);
    }
}

@keyframes shake {
    0%, 100% { transform: rotate(-3deg); }
    50% { transform: rotate(3deg); }
}

@keyframes stickJump {
    0% { transform: translateY(0) rotate(var(--rotation, 0deg)); }
    100% { transform: translateY(-15px) rotate(var(--rotation, 0deg)); }
}

@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translate(-50%, 20px);
    }
    to {
        opacity: 1;
        transform: translate(-50%, 0);
    }
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(30px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes bounce {
    0%, 20%, 53%, 80%, 100% {
        transform: translateY(0);
    }
    40%, 43% {
        transform: translateY(-20px);
    }
    70% {
        transform: translateY(-10px);
    }
    90% {
        transform: translateY(-5px);
    }
}

/* Result card animation */
.card-back .result-card {
    animation: slideUp 0.5s ease-out;
}

/* ================================
   Responsive Design
================================ */
@media (max-width: 480px) {
    #title-area h1 {
        font-size: 3rem;
    }
    
    #title-area h2 {
        font-size: 1.4rem;
        letter-spacing: 0.2em;
    }
    
    #fortune-card {
        width: 250px;
        height: 320px;
    }
    
    .result-card {
        width: 230px;
        min-height: 280px;
        padding: 25px 20px;
    }
    
    .result-text {
        font-size: 1.2rem;
    }
    
    .btn-primary, .btn-secondary {
        padding: 12px 30px;
        font-size: 1rem;
        min-width: 160px;
    }
    
    #footer {
        padding: 10px 15px;
    }
    
    .footer-btn {
        padding: 10px 15px;
        font-size: 0.85rem;
    }
    
    #poster-canvas {
        width: 280px;
        padding: 20px 15px;
    }
    
    .poster-year {
        font-size: 2rem;
    }
    
    .poster-result {
        font-size: 1.1rem;
    }
}

@media (max-width: 360px) {
    #app-container {
        padding: 15px;
        padding-bottom: 130px;
    }
    
    #title-area h1 {
        font-size: 2.5rem;
    }
    
    #fortune-card {
        width: 220px;
        height: 290px;
    }
    
    .result-card {
        width: 200px;
        min-height: 250px;
    }
    
    .result-text {
        font-size: 1.1rem;
        line-height: 1.8;
    }
}

/* 横屏适配 */
@media (max-height: 600px) and (orientation: landscape) {
    #main-content {
        padding: 40px 0 10px;
    }
    
    #title-area {
        margin-bottom: 15px;
    }
    
    #title-area h1 {
        font-size: 2rem;
    }
    
    #title-area h2 {
        font-size: 1rem;
    }
    
    #fortune-card {
        width: 200px;
        height: 250px;
    }
    
    .result-card {
        width: 180px;
        min-height: 220px;
        padding: 20px 15px;
    }
    
    .result-text {
        font-size: 1rem;
    }
    
    #footer {
        flex-direction: row;
        flex-wrap: wrap;
        justify-content: center;
    }
    
    .footer-btn {
        flex: 0 0 auto;
    }
    
    .footer-btn small {
        display: none;
    }
}

/* ================================
   Decorative Elements
================================ */
/* 烟花效果（可选） */
.firework {
    position: fixed;
    pointer-events: none;
    z-index: 0;
}

/* 飘落的金色粒子效果 */
@keyframes float {
    0%, 100% {
        transform: translateY(0) rotate(0deg);
        opacity: 1;
    }
    50% {
        transform: translateY(-20px) rotate(180deg);
        opacity: 0.5;
    }
}

/* 选中状态样式 */
::selection {
    background: var(--gold);
    color: var(--deep-red);
}

/* 滚动条样式 */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.1);
}

::-webkit-scrollbar-thumb {
    background: var(--gold);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--gold-dark);
}
/* ================================
   Poster Modal - 修复渲染问题
================================ */
.poster-content {
    width: 340px;
    max-width: 95%;
    padding: 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
    position: relative;
}

.poster-loading {
    text-align: center;
    padding: 40px 20px;
    min-height: 200px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

#poster-canvas {
    width: 300px;
    min-height: 380px;
    background: linear-gradient(180deg, var(--primary-red) 0%, var(--deep-red) 100%);
    border-radius: 15px;
    padding: 25px 20px;
    border: 3px solid var(--gold);
    text-align: center;
    box-sizing: border-box;
}

/* 确保海报内容正确显示 */
.poster-header {
    margin-bottom: 20px;
}

.poster-body {
    background: linear-gradient(135deg, #FFF8E1 0%, #FFECB3 100%);
    border-radius: 10px;
    padding: 25px 15px;
    margin-bottom: 20px;
    border: 2px solid var(--gold-dark);
    min-height: 80px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.poster-result {
    font-size: 1.2rem;
    color: var(--deep-red);
    line-height: 1.8;
    font-weight: 500;
    word-break: break-all;
}

.poster-footer {
    display: flex;
    align-items: center;
    gap: 15px;
    justify-content: center;
}

#qrcode-container {
    width: 80px;
    height: 80px;
    min-width: 80px;
    min-height: 80px;
    background: white;
    border-radius: 8px;
    padding: 5px;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

#qrcode-container canvas,
#qrcode-container img {
    max-width: 100%;
    max-height: 100%;
    display: block;
}

#poster-image-container {
    text-align: center;
    width: 100%;
}

#poster-image {
    max-width: 100%;
    border-radius: 15px;
    box-shadow: 0 5px 20px rgba(0, 0, 0, 0.3);
    display: block;
    margin: 0 auto;
}

.save-tip {
    margin-top: 10px;
    font-size: 0.85rem;
    color: var(--gold);
    text-align: center;
}

/* 确保隐藏类正确工作 */
#poster-wrapper.hidden {
    display: none !important;
}

#poster-loading.hidden {
    display: none !important;
}

#poster-image-container.hidden {
    display: none !important;
}
