/* ===== CSS Variables ===== */
:root {
    --bg-dark: #0a0a1a;
    --bg-card: rgba(20, 20, 40, 0.85);
    --bg-card-hover: rgba(30, 30, 60, 0.9);
    --primary: #c9a227;
    --primary-glow: rgba(201, 162, 39, 0.4);
    --secondary: #8b5cf6;
    --secondary-glow: rgba(139, 92, 246, 0.3);
    --text-primary: #f5f5f5;
    --text-secondary: #a0a0b0;
    --text-gold: #e8d48b;
    --border-mystical: rgba(201, 162, 39, 0.3);
    --gradient-mystical: linear-gradient(135deg, #1a1a2e 0%, #16213e 50%, #0f0f23 100%);
    --gradient-gold: linear-gradient(135deg, #c9a227 0%, #e8d48b 50%, #c9a227 100%);
    --shadow-mystical: 0 10px 40px rgba(0, 0, 0, 0.5), 0 0 20px var(--primary-glow);
    --font-chinese: 'Noto Serif TC', 'Ma Shan Zheng', serif;
    --font-body: 'Noto Serif TC', serif;
}

/* ===== Reset & Base ===== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
}

body {
    font-family: var(--font-body);
    background: var(--gradient-mystical);
    color: var(--text-primary);
    min-height: 100vh;
    line-height: 1.6;
    overflow-x: hidden;
}

/* ===== Mystical Background ===== */
.mystical-bg {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 0;
    overflow: hidden;
}

.stars {
    position: absolute;
    width: 100%;
    height: 100%;
    background-image: 
        radial-gradient(2px 2px at 20px 30px, rgba(255,255,255,0.3), transparent),
        radial-gradient(2px 2px at 40px 70px, rgba(255,255,255,0.2), transparent),
        radial-gradient(1px 1px at 90px 40px, rgba(255,255,255,0.4), transparent),
        radial-gradient(2px 2px at 130px 80px, rgba(255,255,255,0.2), transparent),
        radial-gradient(1px 1px at 160px 120px, rgba(255,255,255,0.3), transparent);
    background-size: 200px 200px;
    animation: twinkle 4s infinite;
}

@keyframes twinkle {
    0%, 100% { opacity: 0.5; }
    50% { opacity: 1; }
}

.talisman {
    position: absolute;
    font-size: 3rem;
    color: var(--primary);
    opacity: 0.1;
    animation: float 6s ease-in-out infinite;
}

.talisman-1 { top: 10%; left: 5%; animation-delay: 0s; }
.talisman-2 { top: 20%; right: 10%; animation-delay: 1.5s; }
.talisman-3 { bottom: 30%; left: 8%; animation-delay: 3s; }
.talisman-4 { bottom: 15%; right: 5%; animation-delay: 4.5s; font-family: var(--font-chinese); }

@keyframes float {
    0%, 100% { transform: translateY(0) rotate(0deg); }
    50% { transform: translateY(-20px) rotate(10deg); }
}

/* ===== Container ===== */
.container {
    position: relative;
    z-index: 1;
    max-width: 600px;
    margin: 0 auto;
    padding: 20px;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* ===== Header ===== */
.header {
    text-align: center;
    padding: 30px 0;
}

.logo {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    margin-bottom: 10px;
}

.logo-icon {
    font-size: 2.5rem;
    animation: pulse-glow 2s ease-in-out infinite;
}

@keyframes pulse-glow {
    0%, 100% { 
        filter: drop-shadow(0 0 10px var(--primary-glow));
        transform: scale(1);
    }
    50% { 
        filter: drop-shadow(0 0 20px var(--primary));
        transform: scale(1.1);
    }
}

.header h1 {
    font-family: var(--font-chinese);
    font-size: 2.2rem;
    background: var(--gradient-gold);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    text-shadow: 0 0 30px var(--primary-glow);
}

.tagline {
    color: var(--text-secondary);
    font-size: 1rem;
    letter-spacing: 4px;
}

/* ===== Main Content ===== */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

/* ===== Upload Section ===== */
.upload-section {
    background: var(--bg-card);
    border-radius: 20px;
    padding: 30px;
    border: 1px solid var(--border-mystical);
    box-shadow: var(--shadow-mystical);
    backdrop-filter: blur(10px);
}

.upload-box {
    text-align: center;
}

.upload-icon {
    font-size: 4rem;
    margin-bottom: 15px;
    animation: bounce 2s ease-in-out infinite;
}

@keyframes bounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-10px); }
}

.upload-box h2 {
    font-size: 1.5rem;
    color: var(--text-gold);
    margin-bottom: 10px;
}

.upload-box p {
    color: var(--text-secondary);
    margin-bottom: 5px;
}

.upload-box .hint {
    font-size: 0.85rem;
    opacity: 0.7;
    margin-bottom: 25px;
}

.upload-buttons {
    display: flex;
    gap: 15px;
    justify-content: center;
    flex-wrap: wrap;
}

/* ===== Buttons ===== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 14px 28px;
    border: none;
    border-radius: 12px;
    font-family: var(--font-body);
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
}

.btn-icon {
    font-size: 1.2rem;
}

.btn-primary {
    background: var(--gradient-gold);
    color: #1a1a2e;
    box-shadow: 0 4px 15px var(--primary-glow);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 25px var(--primary-glow);
}

.btn-primary:active {
    transform: translateY(0);
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-primary);
    border: 1px solid var(--border-mystical);
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.15);
    border-color: var(--primary);
}

.btn-analyze {
    padding: 16px 40px;
    font-size: 1.1rem;
}

.btn-capture {
    width: 70px;
    height: 70px;
    border-radius: 50%;
    background: var(--gradient-gold);
    font-size: 1.8rem;
    box-shadow: 0 0 30px var(--primary-glow);
}

.btn-capture:hover {
    transform: scale(1.1);
}

.btn-cancel {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-primary);
    padding: 10px 20px;
}

/* ===== Camera Container ===== */
.camera-container {
    position: relative;
    border-radius: 16px;
    overflow: hidden;
}

#cameraPreview {
    width: 100%;
    border-radius: 16px;
    transform: scaleX(-1);
}

.camera-controls {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 20px;
    align-items: center;
}

/* ===== Preview Container ===== */
.preview-container {
    text-align: center;
}

#previewImage {
    max-width: 100%;
    max-height: 400px;
    border-radius: 16px;
    border: 2px solid var(--border-mystical);
    box-shadow: 0 0 30px var(--primary-glow);
    margin-bottom: 20px;
}

.preview-controls {
    display: flex;
    gap: 15px;
    justify-content: center;
    flex-wrap: wrap;
}

/* ===== Loading Section ===== */
.loading-section {
    text-align: center;
    padding: 60px 20px;
    background: var(--bg-card);
    border-radius: 20px;
    border: 1px solid var(--border-mystical);
    box-shadow: var(--shadow-mystical);
}

.loading-animation {
    position: relative;
    width: 150px;
    height: 150px;
    margin: 0 auto 30px;
}

.crystal-ball {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 4rem;
    animation: pulse-glow 1.5s ease-in-out infinite;
    z-index: 2;
}

.loading-rings {
    position: absolute;
    width: 100%;
    height: 100%;
}

.ring {
    position: absolute;
    border: 2px solid var(--primary);
    border-radius: 50%;
    opacity: 0;
    animation: ring-expand 2s ease-out infinite;
}

.ring-1 {
    width: 60px;
    height: 60px;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    animation-delay: 0s;
}

.ring-2 {
    width: 60px;
    height: 60px;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    animation-delay: 0.6s;
}

.ring-3 {
    width: 60px;
    height: 60px;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    animation-delay: 1.2s;
}

@keyframes ring-expand {
    0% {
        width: 60px;
        height: 60px;
        opacity: 1;
    }
    100% {
        width: 150px;
        height: 150px;
        opacity: 0;
    }
}

.loading-text {
    font-size: 1.3rem;
    color: var(--text-gold);
    margin-bottom: 10px;
}

.loading-hint {
    color: var(--text-secondary);
    font-style: italic;
    animation: fade-text 2s ease-in-out infinite;
}

@keyframes fade-text {
    0%, 100% { opacity: 0.5; }
    50% { opacity: 1; }
}

/* ===== Result Section ===== */
.result-section {
    background: var(--bg-card);
    border-radius: 20px;
    padding: 30px;
    border: 1px solid var(--border-mystical);
    box-shadow: var(--shadow-mystical);
    animation: fade-in 0.8s ease-out;
}

@keyframes fade-in {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.result-header {
    text-align: center;
    margin-bottom: 25px;
    padding-bottom: 20px;
    border-bottom: 1px solid var(--border-mystical);
}

.result-header h2 {
    font-size: 1.5rem;
    color: var(--text-gold);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
}

.result-content {
    font-size: 1rem;
    line-height: 1.9;
    color: var(--text-primary);
}

.result-content h3 {
    color: var(--text-gold);
    font-size: 1.2rem;
    margin: 25px 0 15px;
    padding-left: 15px;
    border-left: 3px solid var(--primary);
}

.result-content p {
    margin-bottom: 12px;
    text-align: justify;
}

.result-content strong {
    color: var(--primary);
}

.result-content ul {
    list-style: none;
    padding-left: 20px;
}

.result-content li {
    position: relative;
    margin-bottom: 8px;
    padding-left: 20px;
}

.result-content li::before {
    content: '✦';
    position: absolute;
    left: 0;
    color: var(--primary);
}

.result-actions {
    display: flex;
    gap: 15px;
    justify-content: center;
    margin-top: 30px;
    padding-top: 20px;
    border-top: 1px solid var(--border-mystical);
    flex-wrap: wrap;
}

.disclaimer {
    text-align: center;
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-top: 20px;
    opacity: 0.7;
}

/* ===== Footer ===== */
.footer {
    text-align: center;
    padding: 20px;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

/* ===== Modal ===== */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    backdrop-filter: blur(5px);
}

.modal-content {
    background: var(--bg-card);
    padding: 35px;
    border-radius: 20px;
    max-width: 400px;
    width: 90%;
    text-align: center;
    border: 1px solid var(--border-mystical);
    box-shadow: var(--shadow-mystical);
}

.modal-content h3 {
    color: var(--text-gold);
    margin-bottom: 15px;
    font-size: 1.4rem;
}

.modal-content p {
    color: var(--text-secondary);
    margin-bottom: 20px;
}

.modal-content input {
    width: 100%;
    padding: 14px 18px;
    border-radius: 10px;
    border: 1px solid var(--border-mystical);
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-primary);
    font-size: 1rem;
    margin-bottom: 20px;
    transition: border-color 0.3s;
}

.modal-content input:focus {
    outline: none;
    border-color: var(--primary);
}

.modal-buttons {
    margin-bottom: 15px;
}

.api-hint {
    font-size: 0.85rem;
}

.api-hint a {
    color: var(--primary);
    text-decoration: none;
}

.api-hint a:hover {
    text-decoration: underline;
}

/* ===== Responsive ===== */
@media (max-width: 480px) {
    .header h1 {
        font-size: 1.8rem;
    }
    
    .upload-section {
        padding: 20px;
    }
    
    .upload-buttons {
        flex-direction: column;
    }
    
    .btn {
        width: 100%;
    }
    
    .preview-controls {
        flex-direction: column;
    }
    
    .result-actions {
        flex-direction: column;
    }
}
