/* Theme Variables & Root */
.theme-light {
    --primary-color: #FF4757;
    --secondary-color: #2F3542;
    --accent-color: #FFA502;
    --bg-color: #FFF9F0;
    --card-bg: #FFFFFF;
    --text-color: #2F3542;
    --floating-bg: rgba(255, 255, 255, 0.8);
    --card-back-color: #FF4757;
}

.theme-dark {
    --primary-color: #FF6B81;
    --secondary-color: #F1F2F6;
    --accent-color: #ECCC68;
    --bg-color: #1E272E;
    --card-bg: #2F3542;
    --text-color: #F1F2F6;
    --floating-bg: rgba(47, 53, 66, 0.8);
    --card-back-color: #FF6B81;
}

.theme-trad {
    --primary-color: #7B241C;
    --secondary-color: #4D5656;
    --accent-color: #B7950B;
    --bg-color: #F5F5DC;
    --card-bg: #EAECEE;
    --text-color: #1B2631;
    --floating-bg: rgba(234, 236, 238, 0.8);
    --card-back-color: #7B241C;
}

:root {
    --transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
    --shadow: 0 10px 30px rgba(0,0,0,0.1);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    background-color: var(--bg-color);
    color: var(--text-color);
    font-family: 'Nanum Gothic', sans-serif;
    transition: background-color 0.5s ease, color 0.5s ease;
    overflow-x: hidden;
}

/* Settings Panel */
.settings-panel {
    position: fixed;
    top: 80px;
    right: 20px;
    background: var(--card-bg);
    padding: 15px;
    border-radius: 20px;
    box-shadow: var(--shadow);
    z-index: 99;
    width: 220px;
    animation: slideIn 0.3s ease;
}

.setting-item {
    width: 100%;
    padding: 12px;
    margin-bottom: 8px;
    border: none;
    background: var(--bg-color);
    border-radius: 12px;
    cursor: pointer;
    font-family: inherit;
    font-weight: 600;
    color: var(--text-color);
    transition: var(--transition);
    text-align: left;
}

.setting-item:hover {
    background: var(--primary-color);
    color: white;
}

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

.icon-btn {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    border: none;
    background: var(--floating-bg);
    backdrop-filter: blur(5px);
    box-shadow: 0 4px 15px rgba(0,0,0,0.1);
    cursor: pointer;
    font-size: 1.2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
}

.icon-btn:hover {
    transform: scale(1.1);
    background: white;
}

.streak-badge {
    background: #ff4757;
    color: white;
    padding: 10px;
    border-radius: 20px;
    font-weight: 800;
    font-size: 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 15px rgba(255, 71, 87, 0.3);
}

/* Hero Section */
.hero {
    height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    background: radial-gradient(circle at center, #FFFFFF 0%, #FFF9F0 100%);
}

.title {
    font-family: 'Outfit', sans-serif;
    font-size: 3.5rem;
    font-weight: 800;
    margin-bottom: 1rem;
    line-height: 1.2;
}

.highlight {
    color: var(--primary-color);
    position: relative;
    display: inline-block;
}

.highlight::after {
    content: '';
    position: absolute;
    bottom: 5px;
    left: 0;
    width: 100%;
    height: 15px;
    background: rgba(255, 71, 87, 0.2);
    z-index: -1;
}

.subtitle {
    font-size: 1.2rem;
    color: #747d8c;
    margin-bottom: 2rem;
}

.mascot-svg-container {
    width: 250px;
    height: 250px;
    margin: 0 auto;
    filter: drop-shadow(0 10px 20px rgba(0,0,0,0.1));
    cursor: pointer;
    transition: transform 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.mascot-svg-container:hover {
    transform: scale(1.1);
}

.eye { transition: transform 0.1s ease-out; }
.pupil { fill: #2f3542; }

.wing {
    animation-duration: 2s;
    animation-iteration-count: infinite;
    animation-timing-function: ease-in-out;
}

.wing-l {
    animation-name: flapL;
    transform-origin: 40px 110px;
}

.wing-r {
    animation-name: flapR;
    transform-origin: 160px 110px;
}

/* Daily Worry Input */
.worry-input-container {
    margin: 20px auto;
    max-width: 400px;
}

#user-worry {
    width: 100%;
    padding: 15px 25px;
    border-radius: 30px;
    border: 2px solid #f1f2f6;
    background: white;
    font-size: 1rem;
    font-family: inherit;
    text-align: center;
    transition: var(--transition);
    box-shadow: 0 5px 15px rgba(0,0,0,0.05);
}

#user-worry:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 10px 20px rgba(255, 71, 87, 0.15);
}

@keyframes flapL {
    0%, 100% { transform: rotate(0deg); }
    50% { transform: rotate(15deg); }
}

@keyframes flapR {
    0%, 100% { transform: rotate(0deg); }
    50% { transform: rotate(-15deg); }
}

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

.cta-btn {
    background-color: var(--primary-color);
    color: white;
    border: none;
    padding: 1.2rem 3rem;
    font-size: 1.2rem;
    font-weight: 800;
    border-radius: 50px;
    cursor: pointer;
    box-shadow: 0 10px 20px rgba(255, 71, 87, 0.3);
    transition: var(--transition);
}

.mode-selector {
    display: flex;
    gap: 20px;
    justify-content: center;
    flex-wrap: wrap;
}

.cta-btn.secondary {
    background-color: var(--secondary-color);
    box-shadow: 0 10px 20px rgba(47, 53, 66, 0.3);
}

.cta-btn.secondary:hover {
    box-shadow: 0 15px 25px rgba(47, 53, 66, 0.4);
}

/* Fortune Section */
#fortune-section {
    padding: 100px 0;
    background-color: var(--bg-color);
    min-height: 100vh;
}

.section-title {
    text-align: center;
    font-size: 2rem;
    margin-bottom: 3rem;
}

.deck {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
    gap: 15px;
    perspective: 1000px;
}

.card {
    aspect-ratio: 5/8;
    background-color: var(--primary-color);
    border: 4px solid white;
    border-radius: 12px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
    color: rgba(255,255,255,0.3);
    box-shadow: 0 5px 15px rgba(0,0,0,0.1);
    transition: var(--transition);
    position: relative;
    transform-style: preserve-3d;
}

.card.shuffling {
    animation: realistic-shuffle 0.6s infinite ease-in-out;
    pointer-events: none;
}

@keyframes realistic-shuffle {
    0%, 100% { transform: translate(0, 0) rotate(0deg); }
    25% { transform: translate(var(--tx, 30px), var(--ty, -20px)) rotate(var(--tr, 15deg)); }
    50% { transform: translate(var(--tx-mid, -25px), var(--ty-mid, 25px)) rotate(var(--tr-mid, -10deg)); }
    75% { transform: translate(var(--tx-alt, 20px), var(--ty-alt, -10px)) rotate(var(--tr-alt, 10deg)); }
}

.card:hover {
    transform: translateY(-10px) rotateY(10deg) scale(1.05);
    box-shadow: 0 15px 30px rgba(255, 71, 87, 0.3);
    z-index: 10;
}

.card.selected {
    transform: scale(0.9);
    filter: grayscale(0.5) brightness(0.7);
    cursor: default;
}

.card::before {
    content: '🧧';
    font-size: 2.5rem;
}

/* 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(8px);
}

.modal.hidden {
    display: none;
}

/* Modal Result Layout */
.result-container {
    display: flex;
    flex-direction: column;
    gap: 30px;
    max-height: 70vh;
    overflow-y: auto;
    padding-right: 10px;
}

.modal-content {
    background: var(--card-bg);
    color: var(--text-color);
    padding: 3rem;
    border-radius: 40px;
    max-width: 600px;
    width: 95%;
    text-align: center;
    position: relative;
    animation: zoomIn 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes zoomIn {
    from { opacity: 0; transform: scale(0.5); }
    to { opacity: 1; transform: scale(1); }
}

.close-btn {
    position: absolute;
    top: 20px;
    right: 30px;
    font-size: 2rem;
    cursor: pointer;
    color: #a4b0be;
    z-index: 10;
}

/* Skins Grid */
.skin-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
    gap: 15px;
    padding: 20px;
}

.skin-item {
    aspect-ratio: 1;
    background: var(--bg-color);
    border-radius: 15px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    border: 3px solid transparent;
    transition: var(--transition);
}

.skin-item.active {
    border-color: var(--primary-color);
}

.skin-item.locked {
    opacity: 0.5;
    filter: grayscale(1);
    cursor: not-allowed;
}

/* Mini Game Grid */
.game-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
    padding: 20px;
    max-width: 400px;
    margin: 0 auto;
}

.game-card {
    aspect-ratio: 0.7;
    background: var(--primary-color);
    border-radius: 10px;
    cursor: pointer;
    transform-style: preserve-3d;
    transition: transform 0.6s cubic-bezier(0.4, 0, 0.2, 1);
}

.game-card.flipped {
    transform: rotateY(180deg);
}

/* Mascot Skin Display */
.mascot-skin.hidden { display: none !important; }

/* Stats & Dictionary */
.stats-container, .dict-container {
    padding: 20px;
    max-height: 400px;
    overflow-y: auto;
}

.stats-item, .dict-item {
    padding: 15px;
    margin-bottom: 10px;
    background: var(--bg-color);
    border-radius: 15px;
}

.dict-item h4 { color: var(--primary-color); margin-bottom: 5px; }

@media (max-width: 768px) {
    .game-grid { grid-template-columns: repeat(3, 1fr); }
}

.result-container {
    display: flex;
    flex-direction: column;
    gap: 25px;
    align-items: center;
    width: 100%;
    margin-top: 20px;
}

.result-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
    padding: 25px;
    width: 100%;
    max-width: 500px;
    background: var(--bg-color);
    border-radius: 30px;
    box-shadow: var(--shadow);
    opacity: 0;
    animation: slideUp 0.6s ease-out forwards;
}

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

@media (min-width: 768px) {
    /* Multi-card layout for deep dive */
    .result-container:has(> :nth-child(2)) .result-item {
        flex-direction: row;
        align-items: center;
        max-width: 100%;
        text-align: left !important;
    }
}

.result-tag {
    background: var(--primary-color);
    color: white;
    padding: 5px 12px;
    border-radius: 10px;
    font-weight: 800;
    font-size: 0.8rem;
    margin-bottom: 5px;
    display: inline-block;
}

.card-display {
    flex-shrink: 0;
    width: 100px;
    aspect-ratio: 5/8;
    perspective: 1000px;
}

.card-inner {
    width: 100%;
    height: 100%;
    position: relative;
    transition: transform 0.8s;
    transform-style: preserve-3d;
}

.card-inner.flipped {
    transform: rotateY(180deg);
}

.card-front, .card-back {
    position: absolute;
    width: 100%;
    height: 100%;
    backface-visibility: hidden;
    border-radius: 15px;
    border: 8px solid white;
    box-shadow: var(--shadow);
    display: flex;
    align-items: center;
    justify-content: center;
}

.card-front {
    background-color: var(--primary-color);
    font-size: 3rem;
    color: white;
}

.card-back {
    background-color: white;
    transform: rotateY(180deg);
    background-size: 300% 200%;
    background-repeat: no-repeat;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

/* Sprite Utility Classes */
.sprite-0-0 { background-position: 0% 0%; }
.sprite-1-0 { background-position: 50% 0%; }
.sprite-2-0 { background-position: 100% 0%; }
.sprite-0-1 { background-position: 0% 100%; }
.sprite-1-1 { background-position: 50% 100%; }
.sprite-2-1 { background-position: 100% 100%; }

.fortune-text h4 {
    font-size: 1.8rem;
    margin-bottom: 0.5rem;
    color: var(--primary-color);
}

.fortune-text p {
    font-size: 1.1rem;
    color: #57606f;
}

.retry-btn {
    margin-top: 2rem;
    background: #f1f2f6;
    border: none;
    padding: 1rem 2rem;
    border-radius: 30px;
    font-weight: 700;
    cursor: pointer;
    transition: var(--transition);
}

.retry-btn:hover {
    background: #dfe4ea;
}

.footer {
    padding: 3rem 0;
    text-align: center;
    font-size: 0.9rem;
    color: #a4b0be;
}

.hidden {
    display: none !important;
}

/* Secondary Buttons */
.secondary-btns {
    display: flex;
    gap: 10px;
    justify-content: center;
    margin-top: 15px;
}

.collection-link {
    background: var(--card-bg);
    color: var(--text-color);
    padding: 10px 20px;
    border: none;
    text-decoration: underline;
    font-weight: 700;
    margin-top: 1.5rem;
    cursor: pointer;
    font-size: 1rem;
}

.mascot-mini-container {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    margin-bottom: 20px;
}

.mascot-bubble {
    background: #f1f2f6;
    padding: 10px 20px;
    border-radius: 20px;
    font-size: 0.9rem;
    position: relative;
    display: inline-block;
    color: #2f3542;
    border: 2px solid var(--primary-color);
}

.mascot-bubble::after {
    content: '';
    position: absolute;
    left: -10px;
    top: 50%;
    transform: translateY(-50%);
    border-top: 10px solid transparent;
    border-bottom: 10px solid transparent;
    border-right: 10px solid var(--primary-color);
}

/* Collection Grid */
.collection-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
    margin-top: 20px;
}

.collection-item {
    aspect-ratio: 5/8;
    background: #f1f2f6;
    border-radius: 10px;
    position: relative;
    overflow: hidden;
    filter: grayscale(1);
    opacity: 0.3;
}

.collection-item.unlocked {
    filter: none;
    opacity: 1;
    border: 2px solid var(--primary-color);
    box-shadow: 0 4px 10px rgba(0,0,0,0.1);
}

/* Premium Story Box 3.0 */
.fortune-story-container {
    margin-top: 40px;
    padding: 30px;
    background: linear-gradient(135deg, var(--card-bg) 0%, var(--bg-color) 100%);
    border-radius: 30px;
    border: 2px solid rgba(255, 165, 2, 0.3);
    box-shadow: 0 15px 35px rgba(0,0,0,0.05);
    position: relative;
    overflow: hidden;
    opacity: 0;
    transform: translateY(20px);
    transition: all 1s cubic-bezier(0.23, 1, 0.32, 1);
}

.fortune-story-container::before {
    content: '"';
    position: absolute;
    top: 10px;
    left: 20px;
    font-size: 5rem;
    color: var(--accent-color);
    opacity: 0.1;
    font-family: serif;
}

.story-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 20px;
    border-bottom: 1px solid rgba(255, 165, 2, 0.2);
    padding-bottom: 15px;
}

.story-header span {
    font-size: 1.2rem;
    font-weight: 800;
    color: var(--accent-color);
    letter-spacing: -0.5px;
}

.story-content {
    font-size: 1.1rem;
    line-height: 1.9;
    color: var(--text-color);
    word-break: keep-all;
    font-style: italic;
    position: relative;
    z-index: 1;
}

.story-content b {
    color: var(--primary-color);
    font-weight: 800;
    border-bottom: 2px solid rgba(255, 71, 87, 0.2);
}

/* Seasonal Themes Continued */
body.spring { --bg-color: #fff0f6; }
body.summer { --bg-color: #e3f2fd; }
body.autumn { --bg-color: #fff3e0; }
body.winter { --bg-color: #f5f5f5; }
