:root {
    --bg-color: #020617;
    --text-color: #f8fafc;
    --accent: #3b82f6;
    --accent-glow: rgba(59, 130, 246, 0.5);
    --glass-bg: rgba(255, 255, 255, 0.03);
    --glass-border: rgba(255, 255, 255, 0.08);
    --glass-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
    --scan-laser: #10b981;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Outfit', sans-serif;
}

body {
    background-color: var(--bg-color);
    color: var(--text-color);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow-x: hidden;
    padding: 20px;
}

/* Background animated orbs */
.background {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: -1;
    overflow: hidden;
}

.orb {
    position: absolute;
    border-radius: 50%;
    filter: blur(80px);
    opacity: 0.4;
    animation: float 20s infinite alternate;
}

.orb-1 {
    width: 300px;
    height: 300px;
    background: #3b82f6;
    top: -50px;
    left: -50px;
}

.orb-2 {
    width: 400px;
    height: 400px;
    background: #8b5cf6;
    bottom: -100px;
    right: -100px;
    animation-delay: -5s;
}

@keyframes float {
    0% { transform: translate(0, 0); }
    100% { transform: translate(50px, 50px); }
}

/* Settings Button & Modal */
.settings-btn {
    position: absolute;
    top: 24px;
    right: 24px;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid var(--glass-border);
    border-radius: 50%;
    width: 40px;
    height: 40px;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    color: #cbd5e1;
    transition: all 0.3s ease;
    z-index: 10;
}

.settings-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: rotate(45deg);
}

.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(8px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.modal-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

.modal-content {
    background: #0f172a;
    border: 1px solid var(--glass-border);
    border-radius: 20px;
    padding: 32px;
    width: 90%;
    max-width: 400px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.5);
    transform: translateY(20px);
    transition: transform 0.3s ease;
}

.modal-overlay.active .modal-content {
    transform: translateY(0);
}

.modal-content h2 {
    margin-bottom: 16px;
    font-size: 1.5rem;
}

.form-group {
    margin-bottom: 24px;
}

.form-group label {
    display: block;
    font-size: 0.875rem;
    color: #94a3b8;
    margin-bottom: 8px;
}

.form-group input, .form-group textarea {
    width: 100%;
    padding: 12px 16px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 10px;
    color: white;
    font-size: 1rem;
    outline: none;
    transition: border-color 0.3s;
    resize: none;
}

.form-group input:focus, .form-group textarea:focus {
    border-color: var(--accent);
}

/* Main Container */
.glass-container {
    background: var(--glass-bg);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--glass-border);
    border-radius: 24px;
    box-shadow: var(--glass-shadow);
    width: 100%;
    max-width: 500px;
    min-height: 600px;
    padding: 24px;
    position: relative;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

/* APP NAVIGATION */
.app-nav {
    display: flex;
    position: relative;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 12px;
    margin-bottom: 24px;
    padding: 4px;
}

.nav-tab {
    flex: 1;
    background: none;
    border: none;
    color: #94a3b8;
    padding: 12px 0;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    position: relative;
    z-index: 2;
    transition: color 0.3s ease;
}

.nav-tab.active {
    color: #fff;
}

.nav-slider {
    position: absolute;
    top: 4px;
    left: 4px;
    height: calc(100% - 8px);
    width: calc(33.333% - 8px);
    background: rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    transition: transform 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
    z-index: 1;
}

.app-mode {
    display: none;
    flex-direction: column;
    flex-grow: 1;
    animation: fadeIn 0.4s ease;
}

.app-mode.active {
    display: flex;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Layout views */
.view {
    display: flex;
    flex-direction: column;
    flex-grow: 1;
    width: 100%;
}

.view.hidden {
    display: none;
}

.view.active {
    display: flex;
}

header {
    text-align: center;
    margin-bottom: 24px;
}

h1 {
    font-weight: 800;
    font-size: 1.8rem;
    margin-bottom: 8px;
    background: linear-gradient(90deg, #60a5fa, #c084fc);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.subtitle {
    color: #94a3b8;
    font-size: 0.95rem;
    line-height: 1.4;
}

/* Upload Area */
.upload-area {
    flex-grow: 1;
    border: 2px dashed rgba(255, 255, 255, 0.2);
    border-radius: 16px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 32px 24px;
    cursor: pointer;
    transition: all 0.3s ease;
    text-align: center;
    background: rgba(0, 0, 0, 0.2);
    margin-bottom: 16px;
}

.upload-area:hover, .upload-area.drag-over {
    border-color: var(--accent);
    background: rgba(59, 130, 246, 0.1);
}

.upload-icon {
    margin-bottom: 16px;
    color: #60a5fa;
    transition: transform 0.3s ease;
}

.upload-area:hover .upload-icon {
    transform: translateY(-5px);
}

.upload-area h3 {
    font-size: 1.25rem;
    font-weight: 600;
    margin-bottom: 8px;
}

.upload-area p {
    color: #64748b;
    font-size: 0.875rem;
    margin-bottom: 8px;
}

/* Buttons */
.btn {
    border: none;
    border-radius: 12px;
    padding: 14px 28px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    width: 100%;
    margin-top: auto;
}

.btn.primary {
    background: linear-gradient(90deg, #3b82f6, #8b5cf6);
    color: white;
    box-shadow: 0 4px 15px rgba(59, 130, 246, 0.4);
}

.btn.primary:hover {
    box-shadow: 0 6px 20px rgba(59, 130, 246, 0.6);
    transform: translateY(-2px);
}

.btn.secondary {
    background: rgba(255, 255, 255, 0.1);
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.1);
    margin-top: 12px;
}

.btn.secondary:hover {
    background: rgba(255, 255, 255, 0.15);
}

.error-message {
    color: #ef4444;
    font-size: 0.9rem;
    margin-top: 4px;
    margin-bottom: 12px;
    text-align: center;
    display: none;
}

/* Scan View */
.scan-container {
    position: relative;
    width: 100%;
    aspect-ratio: 3/4;
    border-radius: 16px;
    overflow: hidden;
    margin-bottom: 24px;
    background: #000;
    border: 1px solid var(--glass-border);
}

#scan-image {
    width: 100%;
    height: 100%;
    object-fit: contain;
    background: #111;
    opacity: 0.7;
    filter: contrast(1.1) brightness(0.9);
}

.scan-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(rgba(16, 185, 129, 0.1) 0%, transparent 5%, transparent 95%, rgba(16, 185, 129, 0.1) 100%);
    pointer-events: none;
}

.scan-laser {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 2px;
    background: var(--scan-laser);
    box-shadow: 0 0 10px 2px rgba(16, 185, 129, 0.8), 0 0 20px 5px rgba(16, 185, 129, 0.4);
    animation: scan 2s cubic-bezier(0.4, 0, 0.2, 1) infinite alternate;
}

@keyframes scan {
    0% { top: 0%; opacity: 0; }
    10% { opacity: 1; }
    90% { opacity: 1; }
    100% { top: 100%; opacity: 0; }
}

.scan-corner {
    position: absolute;
    width: 30px;
    height: 30px;
    border-color: var(--scan-laser);
    border-style: solid;
    border-width: 0;
}

.top-left { top: 10px; left: 10px; border-top-width: 2px; border-left-width: 2px; }
.top-right { top: 10px; right: 10px; border-top-width: 2px; border-right-width: 2px; }
.bottom-left { bottom: 10px; left: 10px; border-bottom-width: 2px; border-left-width: 2px; }
.bottom-right { bottom: 10px; right: 10px; border-bottom-width: 2px; border-right-width: 2px; }

.loading-stats {
    text-align: center;
    font-family: monospace;
    color: var(--scan-laser);
    letter-spacing: 1px;
}

.glitch-text {
    animation: glitch 1s linear infinite;
}

@keyframes glitch {
    2%, 64% { transform: translate(2px, 0) skew(0deg); }
    4%, 60% { transform: translate(-2px, 0) skew(0deg); }
    62% { transform: translate(0, 0) skew(5deg); }
}

/* Result View */
#result-view {
    gap: 16px;
}

.score-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    position: relative;
    margin-bottom: 8px;
}

.score-circle {
    position: relative;
    width: 140px;
    height: 140px;
}

.circular-chart {
    display: block;
    margin: 0 auto;
    max-width: 100%;
    max-height: 250px;
}

.circle-bg {
    fill: none;
    stroke: rgba(255, 255, 255, 0.1);
    stroke-width: 2.5;
}

.circle {
    fill: none;
    stroke-width: 2.5;
    stroke-linecap: round;
    transition: stroke-dasharray 1.5s ease-out, stroke 0.5s;
}

.color-excellent { stroke: #10b981; }
.color-good { stroke: #3b82f6; }
.color-average { stroke: #f59e0b; }

.score-content {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    display: flex;
    flex-direction: column;
    margin-top: 5px;
}

#final-score {
    font-size: 2.8rem;
    font-weight: 800;
    line-height: 1;
}

.score-label {
    font-size: 0.8rem;
    color: #94a3b8;
}

.score-badge {
    margin-top: -10px;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 600;
    letter-spacing: 1px;
    text-transform: uppercase;
    opacity: 0;
    transform: translateY(10px);
    transition: all 0.5s ease 1s;
}

.bg-excellent { background: linear-gradient(90deg, #10b981, #059669); box-shadow: 0 4px 10px rgba(16, 185, 129, 0.3); }
.bg-good { background: linear-gradient(90deg, #3b82f6, #2563eb); box-shadow: 0 4px 10px rgba(59, 130, 246, 0.3); }
.bg-average { background: linear-gradient(90deg, #f59e0b, #d97706); box-shadow: 0 4px 10px rgba(245, 158, 11, 0.3); }

.score-badge.show {
    opacity: 1;
    transform: translateY(0);
}

.details-grid {
    display: flex;
    flex-direction: column;
    gap: 16px;
    margin-bottom: auto;
}

.glass-panel {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: 16px;
    padding: 16px;
}

.glass-panel h3 {
    font-size: 1rem;
    color: #cbd5e1;
    margin-bottom: 12px;
    font-weight: 600;
}

.metric {
    margin-bottom: 12px;
}
.metric:last-child { margin-bottom: 0; }

.metric-header {
    display: flex;
    justify-content: space-between;
    font-size: 0.875rem;
    margin-bottom: 6px;
}

.metric-header span:last-child {
    font-weight: 600;
    color: #60a5fa;
}

.progress-bar {
    height: 6px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 3px;
    overflow: hidden;
}

.progress {
    height: 100%;
    background: linear-gradient(90deg, #3b82f6, #8b5cf6);
    border-radius: 3px;
    transition: width 1.5s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Match Card */
.match-info {
    display: flex;
    align-items: center;
    gap: 16px;
    opacity: 0;
    transform: translateX(-20px);
    transition: all 0.5s ease 1.5s;
}

.match-info.show {
    opacity: 1;
    transform: translateX(0);
}

.match-img-wrapper {
    width: 60px;
    height: 60px;
    min-width: 60px;
    border-radius: 50%;
    padding: 2px;
    background: linear-gradient(45deg, #f59e0b, #ec4899);
}

#match-img {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid var(--glass-bg);
}

.match-text h4 {
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 4px;
}

.match-text p {
    font-size: 0.875rem;
    color: #f59e0b;
    font-weight: 600;
}


/* =========================== */
/*       TAROT STYLES          */
/* =========================== */

.tarot-form {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
}

.tarot-deck-preview {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 24px 0;
    margin-bottom: 16px;
}

.deck-stack {
    position: relative;
    width: 80px;
    height: 120px;
}

.card-back-fake {
    position: absolute;
    width: 100%;
    height: 100%;
    border-radius: 6px;
    background-image: url('https://images.unsplash.com/photo-1462331940025-496dfbfc7564?w=400&q=80');
    background-size: cover;
    background-position: center;
    border: 2px solid rgba(255, 255, 255, 0.7);
    box-shadow: 0 4px 8px rgba(0,0,0,0.5);
    transition: transform 0.3s ease;
}

.deck-stack .c1 { transform: rotate(-5deg); z-index: 1; }
.deck-stack .c2 { transform: rotate(0deg); top: -2px; z-index: 2; }
.deck-stack .c3 { transform: rotate(5deg); top: -4px; z-index: 3; }
.deck-stack:hover .c1 { transform: rotate(-15deg) translate(-10px, 5px); }
.deck-stack:hover .c3 { transform: rotate(15deg) translate(10px, 5px); }

/* Gacha Slot Machine Styles */
.gacha-container { 
    display: flex; 
    gap: 16px; 
    justify-content: center; 
    margin-bottom: 24px; 
}
.gacha-col { 
    display: flex; 
    flex-direction: column; 
    align-items: center; 
    width: 100px; 
    gap: 8px;
}
.gacha-col label { 
    font-size: 0.8rem; 
    color: #94a3b8; 
    font-weight: 600;
}
.gacha-window {
    width: 100%; 
    height: 160px;
    background: #000; 
    border-radius: 8px; 
    border: 2px solid var(--glass-border);
    position: relative; 
    overflow: hidden;
    box-shadow: inset 0 0 10px rgba(0,0,0,1);
    /* For sparkles relative anchor */
}
.gacha-strip {
    display: flex; 
    flex-direction: row; /* Roll horizontal */
    height: 100%; 
    width: max-content;
    /* CSS transition for scrolling logic */
    /* Transition speed handled in JS dynamically */
}
.gacha-strip img { 
    width: 100px; 
    height: 160px; 
    object-fit: cover; 
    border-right: 2px solid #222; /* Tách biệt nhẹ các lá lúc xoay */
}
.gacha-overlay {
    position: absolute; 
    top:0; left:0; right:0; bottom:0;
    /* Bóng đổ shadow 2 bên mờ ảo */
    box-shadow: inset 20px 0 20px -20px #000, inset -20px 0 20px -20px #000;
    pointer-events: none;
    z-index: 5;
}
.spin-btn { 
    padding: 8px; 
    font-size: 0.85rem; 
    width: 100%;
}
.spin-btn:disabled { 
    opacity: 0.5; 
    background: #475569; 
    box-shadow: none; 
    cursor: not-allowed; 
}

/* Winner Glow state */
.gacha-window.winner {
    border-color: #fcd34d;
    box-shadow: 0 0 15px #fcd34d, inset 0 0 10px #fcd34d;
    animation: pulseGlow 1.5s infinite alternate;
}

.gacha-window.winner .gacha-strip img {
    border-right: none; /* Khử cấn viền khi dừng lại trúng tâm */
}

@keyframes pulseGlow {
    from { box-shadow: 0 0 15px #fcd34d, inset 0 0 10px rgba(252, 211, 77, 0.4); }
    to { box-shadow: 0 0 25px rgba(252, 211, 77, 0.8), inset 0 0 15px #fcd34d; }
}

/* Sparkle element class */
.sparkle {
    position: absolute; 
    width: 4px; 
    height: 4px; 
    background: white; 
    border-radius: 50%;
    box-shadow: 0 0 10px 2px #fff, 0 0 20px 5px #fcd34d;
    animation: floatSparkle 1.2s ease-in-out forwards;
    z-index: 10;
    pointer-events: none;
}
@keyframes floatSparkle {
    0% { opacity: 1; transform: translateY(0) scale(1); }
    100% { opacity: 0; transform: translateY(-40px) scale(0); }
}

/* Tarot Reading Output */
.tarot-reading {
    max-height: 250px;
    overflow-y: auto;
    margin-bottom: 24px;
}
.tarot-reading::-webkit-scrollbar { width: 4px; }
.tarot-reading::-webkit-scrollbar-thumb { background: #8b5cf6; border-radius: 4px; }

#tarot-reading-text {
    font-size: 0.95rem;
    line-height: 1.6;
    color: #e2e8f0;
    white-space: pre-wrap;
}

#tarot-question-echo {
    font-style: italic;
    color: #cbd5e1;
    margin-bottom: 12px;
}
/* Footer Links */
.app-footer {
    display: flex;
    justify-content: center;
    align-items: center;
    margin-top: auto;
    padding-top: 24px;
    font-size: 0.85rem;
    gap: 8px;
}
.app-footer a {
    color: #cbd5e1;
    text-decoration: none;
    transition: color 0.2s;
}
.app-footer a:hover {
    color: #60a5fa;
    text-decoration: underline;
}
.app-footer span {
    color: #475569;
}

/* Responsive constraints */
@media (max-width: 480px) {
    .glass-container {
        border-radius: 0;
        border: none;
        min-height: 100vh;
        width: 100vw;
        justify-content: flex-start;
    }
    
    .tarot-card-wrapper {
        width: 90px;
        height: 153px;
    }
}
