:root {
    --bg-color: #0d0221;
    --card-bg: #1a0b3b;
    --primary-color: #c29ffd;
    --secondary-color: #ff9e7d;
    --text-color: #e0e0e0;
    --gold: #ffd700;
    --shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
    --transition: all 0.3s ease;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    background-color: var(--bg-color);
    color: var(--text-color);
    font-family: 'PingFang SC', 'Microsoft YaHei', sans-serif;
    line-height: 1.6;
    overflow-x: hidden;
    min-height: 100vh;
}

#app {
    max-width: 1200px;
    margin: 0 auto;
    padding: 2rem 1rem;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

header {
    text-align: center;
    margin-bottom: 3rem;
}

h1 {
    font-size: 2.5rem;
    color: var(--primary-color);
    text-shadow: 0 0 10px rgba(194, 159, 253, 0.5);
    margin-bottom: 0.5rem;
}

.subtitle {
    color: var(--secondary-color);
    letter-spacing: 2px;
}

.view {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    animation: fadeIn 0.5s ease-out;
}

.hidden {
    display: none !important;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Setup View */
.card-container {
    background: var(--card-bg);
    padding: 2.5rem;
    border-radius: 20px;
    box-shadow: var(--shadow);
    width: 100%;
    max-width: 600px;
    border: 1px solid rgba(194, 159, 253, 0.2);
}

.input-group {
    margin-bottom: 2rem;
}

label {
    display: block;
    margin-bottom: 0.8rem;
    color: var(--primary-color);
    font-weight: bold;
}

input[type="text"] {
    width: 100%;
    padding: 1rem;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(194, 159, 253, 0.3);
    border-radius: 10px;
    color: white;
    font-size: 1rem;
    outline: none;
    transition: var(--transition);
}

input[type="text"]:focus {
    border-color: var(--primary-color);
    background: rgba(255, 255, 255, 0.1);
}

.grid-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 1rem;
    margin-bottom: 2rem;
}

.spread-item {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(194, 159, 253, 0.2);
    padding: 1rem;
    border-radius: 10px;
    text-align: center;
    cursor: pointer;
    transition: var(--transition);
    font-size: 0.9rem;
}

.spread-item:hover {
    background: rgba(194, 159, 253, 0.1);
}

.spread-item.active {
    background: var(--primary-color);
    color: var(--bg-color);
    border-color: var(--primary-color);
    font-weight: bold;
}

.primary-btn {
    width: 100%;
    padding: 1rem;
    background: linear-gradient(135deg, var(--primary-color), #8e44ad);
    color: white;
    border: none;
    border-radius: 10px;
    font-size: 1.1rem;
    font-weight: bold;
    cursor: pointer;
    transition: var(--transition);
    box-shadow: 0 4px 15px rgba(142, 68, 173, 0.4);
}

.primary-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(142, 68, 173, 0.6);
}

/* Draw View */
.deck-area {
    margin-bottom: 3rem;
    text-align: center;
}

.deck {
    position: relative;
    width: 120px;
    height: 180px;
    margin: 0 auto 1.5rem;
    cursor: pointer;
}

.card-back {
    position: absolute;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, #2c1e4a, #1a0b3b);
    border: 2px solid var(--gold);
    border-radius: 10px;
    box-shadow: 2px 2px 10px rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s ease;
}

.card-back::after {
    content: '🔮';
    font-size: 2rem;
}

.deck .card-back:nth-child(1) { transform: translate(0, 0); z-index: 5; }
.deck .card-back:nth-child(2) { transform: translate(2px, 2px); z-index: 4; }
.deck .card-back:nth-child(3) { transform: translate(4px, 4px); z-index: 3; }
.deck .card-back:nth-child(4) { transform: translate(6px, 6px); z-index: 2; }
.deck .card-back:nth-child(5) { transform: translate(8px, 8px); z-index: 1; }

.deck:hover .card-back:nth-child(1) { transform: translate(-5px, -5px); }

.layout-area {
    width: 100%;
    min-height: 400px;
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 2rem;
    padding: 2rem;
}

.position-slot {
    width: 140px;
    text-align: center;
}

.slot-label {
    font-size: 0.85rem;
    color: var(--secondary-color);
    margin-bottom: 0.5rem;
}

.drawn-card {
    width: 120px;
    height: 180px;
    background: var(--card-bg);
    border: 2px solid var(--primary-color);
    border-radius: 10px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 0;
    cursor: pointer;
    overflow: hidden;
    position: relative;
    animation: flipIn 0.6s perspective(1000px) rotateY(-180deg) forwards;
    transform-style: preserve-3d;
}

.card-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.card-info-overlay {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: rgba(0, 0, 0, 0.7);
    padding: 0.3rem;
    display: none;
}

.drawn-card:hover .card-info-overlay {
    display: block;
}

.drawn-card.reversed .card-img {
    transform: rotate(180deg);
}

@keyframes flipIn {
    0% { transform: perspective(1000px) rotateY(-180deg); opacity: 0; }
    100% { transform: perspective(1000px) rotateY(0deg); opacity: 1; }
}

@keyframes mysteriousPulse {
    0%, 100% {
        transform: scale(1);
        filter: brightness(1);
    }
    50% {
        transform: scale(1.05);
        filter: brightness(1.3);
    }
}

.card-name {
    font-size: 0.9rem;
    font-weight: bold;
    text-align: center;
}

.card-orientation {
    font-size: 0.7rem;
    margin-top: 0.3rem;
    color: var(--secondary-color);
}

/* Result Layout */
.result-layout {
    display: flex;
    flex-direction: column;
    width: 100%;
    gap: 2rem;
    margin-bottom: 2rem;
}

@media (min-width: 900px) {
    .result-layout {
        flex-direction: row;
        align-items: flex-start;
    }
    #result-cards {
        flex: 0 0 45%;
        position: sticky;
        top: 2rem;
        height: fit-content;
    }
    .reading-report {
        flex: 1;
        max-height: 85vh;
        overflow-y: auto;
    }
}

.reading-report {
    background: var(--card-bg);
    padding: 2rem;
    border-radius: 20px;
    border: 1px solid rgba(194, 159, 253, 0.2);
    box-shadow: var(--shadow);
}

.report-title {
    color: var(--primary-color);
    text-align: center;
    margin-bottom: 2rem;
    border-bottom: 1px solid rgba(194, 159, 253, 0.3);
    padding-bottom: 1rem;
}

.reading-item {
    margin-bottom: 2.5rem;
    padding-bottom: 2rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.reading-item:last-child {
    border-bottom: none;
}

.reading-pos {
    color: var(--secondary-color);
    font-size: 0.9rem;
    font-weight: bold;
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 0.5rem;
}

.reading-card-header {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1rem;
}

.reading-card-name {
    color: var(--gold);
    font-size: 1.3rem;
    margin: 0;
}

.reading-orientation-tag {
    font-size: 0.75rem;
    padding: 2px 8px;
    border-radius: 4px;
    background: rgba(255, 255, 255, 0.1);
}

.reading-keywords {
    font-style: italic;
    font-size: 0.9rem;
    color: #aaa;
    margin-bottom: 1rem;
}

.reading-content {
    line-height: 1.8;
    color: #eee;
}

.result-grid {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 1rem;
}

.actions {
    text-align: center;
    padding: 2rem 0;
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal-content {
    background: var(--card-bg);
    padding: 2rem;
    border-radius: 20px;
    max-width: 800px;
    width: 95%;
    max-height: 90vh;
    overflow-y: auto;
    position: relative;
    border: 1px solid var(--primary-color);
}

.modal-flex {
    display: flex;
    gap: 2rem;
}

.modal-img-container {
    flex: 0 0 200px;
}

.modal-card-img {
    width: 100%;
    border-radius: 10px;
    border: 2px solid var(--gold);
}

.modal-card-img.reversed {
    transform: rotate(180deg);
}

.modal-text-content {
    flex: 1;
}

@media (max-width: 600px) {
    .modal-flex {
        flex-direction: column;
        align-items: center;
    }
    .modal-img-container {
        flex: 0 0 auto;
        width: 150px;
    }
}

.modal-close {
    position: absolute;
    top: 1rem;
    right: 1.5rem;
    font-size: 2rem;
    cursor: pointer;
    color: var(--primary-color);
}

.detail-title {
    color: var(--primary-color);
    font-size: 1.8rem;
    margin-bottom: 1rem;
    text-align: center;
}

.detail-keywords {
    color: var(--secondary-color);
    text-align: center;
    font-style: italic;
    margin-bottom: 1.5rem;
    border-bottom: 1px solid rgba(255,255,255,0.1);
    padding-bottom: 1rem;
}

.detail-section h4 {
    color: var(--gold);
    margin: 1.2rem 0 0.5rem;
}

.secondary-btn {
    padding: 0.8rem 2rem;
    background: transparent;
    border: 2px solid var(--primary-color);
    color: var(--primary-color);
    border-radius: 10px;
    cursor: pointer;
    font-weight: bold;
    transition: var(--transition);
}

.secondary-btn:hover {
    background: var(--primary-color);
    color: var(--bg-color);
}

.text-btn {
    background: none;
    border: none;
    color: var(--secondary-color);
    text-decoration: underline;
    cursor: pointer;
    margin-top: 1rem;
}

footer {
    margin-top: auto;
    text-align: center;
    padding: 2rem;
    font-size: 0.8rem;
    color: rgba(255,255,255,0.3);
}

/* Responsive */
@media (max-width: 600px) {
    h1 { font-size: 1.8rem; }
    .card-container { padding: 1.5rem; }
    .grid-list { grid-template-columns: repeat(2, 1fr); }
}
