* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html, body {
    width: 100%;
    height: 100%;
    overflow-x: hidden;
    position: relative;
}

body {
    background: linear-gradient(135deg, #2c003e, #1a0026);
    color: #ffffff;
    font-family: 'Arial', sans-serif;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    align-items: center;
    padding: 10px;
    position: relative;
    perspective: 1000px;
}

/* Interactive Cursor */
.interactive-cursor {
    position: fixed;
    width: 20px;
    height: 20px;
    background: radial-gradient(circle, rgba(255, 215, 0, 0.8) 0%, transparent 70%);
    border-radius: 50%;
    pointer-events: none;
    z-index: 9999;
    transform: translate(-50%, -50%);
    transition: transform 0.1s ease-out;
    mix-blend-mode: screen;
}

/* Cosmic Background Layer */
body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: 
        radial-gradient(circle at 20% 20%, rgba(255, 215, 0, 0.2) 0%, transparent 30%),
        radial-gradient(circle at 80% 80%, rgba(255, 107, 107, 0.2) 0%, transparent 30%),
        radial-gradient(circle at 50% 50%, rgba(44, 0, 62, 0.4) 0%, transparent 40%),
        radial-gradient(circle at 30% 70%, rgba(255, 215, 0, 0.15) 0%, transparent 35%),
        radial-gradient(circle at 70% 30%, rgba(255, 107, 107, 0.15) 0%, transparent 35%);
    animation: cosmicPulse 20s ease-in-out infinite;
    z-index: -3;
    pointer-events: none;
    transform-style: preserve-3d;
    will-change: transform;
}

/* Mystical Grid Layer */
body::after {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: 
        repeating-linear-gradient(
            45deg,
            transparent 0px,
            transparent 2px,
            rgba(255, 215, 0, 0.08) 2px,
            rgba(255, 215, 0, 0.08) 4px
        ),
        repeating-linear-gradient(
            -45deg,
            transparent 0px,
            transparent 2px,
            rgba(255, 107, 107, 0.08) 2px,
            rgba(255, 107, 107, 0.08) 4px
        );
    animation: gridMove 30s linear infinite;
    z-index: -2;
    pointer-events: none;
    opacity: 0.7;
    transform-style: preserve-3d;
    will-change: transform;
}

/* Ethereal Overlay */
.ethereal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: 
        radial-gradient(circle at 50% 50%, rgba(255, 215, 0, 0.15) 0%, transparent 60%),
        radial-gradient(circle at 0% 0%, rgba(255, 107, 107, 0.15) 0%, transparent 60%),
        radial-gradient(circle at 100% 100%, rgba(255, 215, 0, 0.15) 0%, transparent 60%);
    animation: etherealPulse 15s ease-in-out infinite;
    z-index: -1;
    pointer-events: none;
    mix-blend-mode: overlay;
    transform-style: preserve-3d;
    will-change: transform;
}

/* Enhanced Floating Particles */
.floating-particles {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: -1;
    pointer-events: none;
    transform-style: preserve-3d;
    will-change: transform;
}

.particle {
    position: absolute;
    width: 2px;
    height: 2px;
    background: rgba(255, 215, 0, 0.6);
    border-radius: 50%;
    animation: float 15s infinite linear;
    box-shadow: 0 0 10px 2px rgba(255, 215, 0, 0.3);
    will-change: transform;
}

.particle::before {
    content: '';
    position: absolute;
    width: 100%;
    height: 100%;
    background: inherit;
    border-radius: inherit;
    animation: particlePulse 2s infinite ease-in-out;
}

.particle:nth-child(1) { left: 10%; top: 10%; animation-delay: 0s; }
.particle:nth-child(2) { left: 20%; top: 20%; animation-delay: 2s; }
.particle:nth-child(3) { left: 30%; top: 30%; animation-delay: 4s; }
.particle:nth-child(4) { left: 40%; top: 40%; animation-delay: 6s; }
.particle:nth-child(5) { left: 50%; top: 50%; animation-delay: 8s; }
.particle:nth-child(6) { left: 60%; top: 60%; animation-delay: 10s; }
.particle:nth-child(7) { left: 70%; top: 70%; animation-delay: 12s; }
.particle:nth-child(8) { left: 80%; top: 80%; animation-delay: 14s; }

/* Enhanced Animations */
@keyframes cosmicPulse {
    0%, 100% {
        transform: scale(1) rotate(0deg) translateZ(0);
        opacity: 0.8;
    }
    25% {
        transform: scale(1.05) rotate(2deg) translateZ(10px);
        opacity: 0.9;
    }
    50% {
        transform: scale(1.1) rotate(0deg) translateZ(20px);
        opacity: 1;
    }
    75% {
        transform: scale(1.05) rotate(-2deg) translateZ(10px);
        opacity: 0.9;
    }
}

@keyframes gridMove {
    0% {
        background-position: 0 0, 0 0;
        transform: translateZ(0);
    }
    50% {
        background-position: 100px 100px, -100px -100px;
        transform: translateZ(10px);
    }
    100% {
        background-position: 0 0, 0 0;
        transform: translateZ(0);
    }
}

@keyframes etherealPulse {
    0%, 100% {
        transform: scale(1) translateZ(0);
        opacity: 0.3;
    }
    50% {
        transform: scale(1.2) translateZ(20px);
        opacity: 0.5;
    }
}

@keyframes float {
    0% {
        transform: translateY(0) translateX(0) translateZ(0);
        opacity: 0;
    }
    10% {
        opacity: 1;
    }
    90% {
        opacity: 1;
    }
    100% {
        transform: translateY(-100vh) translateX(100px) translateZ(30px);
        opacity: 0;
    }
}

@keyframes particlePulse {
    0%, 100% {
        transform: scale(1);
        opacity: 0.5;
    }
    50% {
        transform: scale(2);
        opacity: 0.8;
    }
}

/* Container and Layout */
.container {
    position: relative;
    z-index: 1;
    background: rgba(26, 0, 38, 0.7);
    backdrop-filter: blur(5px);
    border-radius: 20px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    max-width: 900px;
    width: 100%;
    text-align: center;
    padding: 10px;
    transform-style: preserve-3d;
    margin: 0 auto;
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
}

h1 {
    font-family: 'Cinzel', serif;
    font-size: clamp(32px, 5vw, 48px);
    font-weight: 700;
    margin-bottom: 20px;
    text-shadow: 0 0 10px rgba(255, 215, 0, 0.5);
    color: #ffd700;
}

.controls {
    background: rgba(255, 255, 255, 0.1);
    padding: clamp(15px, 3vw, 20px);
    border-radius: 15px;
    margin-bottom: 30px;
    backdrop-filter: blur(5px);
    width: 100%;
    max-width: 500px;
    margin-left: auto;
    margin-right: auto;
}

label {
    font-size: clamp(16px, 3vw, 20px);
    margin-bottom: 10px;
    display: block;
    font-family: 'Cinzel', serif;
}

#spread-select, #draw-button {
    padding: clamp(8px, 2vw, 12px) clamp(15px, 3vw, 20px);
    font-size: clamp(14px, 2vw, 16px);
    font-weight: 600;
    border: 2px solid #ffd700;
    border-radius: 25px;
    background-color: #f0e6d2;
    color: #2c003e;
    cursor: pointer;
    transition: all 0.3s ease;
    margin: 8px;
    width: auto;
    min-width: 120px;
}

#spread-select:hover, #draw-button:hover {
    background-color: #ffd700;
    color: #2c003e;
}

#draw-button:active {
    transform: scale(0.95);
}

.cards-grid {
    display: flex;
    padding-bottom: 55px;
    flex-wrap: wrap;
    justify-content: center;
    gap: clamp(15px, 3vw, 25px);
    width: 100%;
    max-width: 900px;
    margin: 0 auto;
}

.card-wrapper {
    position: relative;
    width: clamp(110px, 20vw, 150px);
    height: clamp(165px, 30vw, 225px);
    margin: 5px;
    transform-style: preserve-3d;
    transform: translateX(-100%);
    opacity: 0;
    transition: transform 0.5s ease, opacity 0.5s ease;
}

.card-container {
    position: absolute;
    width: 100%;
    height: 100%;
    transition: all 0.6s cubic-bezier(0.4, 0, 0.2, 1);
    transform-style: preserve-3d;
}

.card-container.expanded {
    transform: scale(2) rotateY(180deg);
    z-index: 100;
}

.card-front, .card-back {
    position: absolute;
    width: 100%;
    height: 100%;
    backface-visibility: hidden;
    border-radius: 15px;
    padding: 15px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.2);
}

.card-front {
    background: linear-gradient(135deg, #f5f5f5, #e0e0e0);
    transform: rotateY(0deg);
    border: 3px solid #ffd700;
    overflow: hidden;
    padding: 0;
}

.card-front img {
    width: calc(100% + 10px);
    height: calc(100% + 10px);
    object-fit: cover;
    border-radius: 12px;
    margin: -5px;
    display: block;
}

.card-back {
    background: linear-gradient(135deg, #ffd700, #ff6b6b);
    transform: rotateY(180deg);
    border: 3px solid #ff0000;
    padding: 15px;
    overflow: auto;
}

.cards-grid.dimmed .card-wrapper:not(.expanded) {
    opacity: 0.3;
    filter: blur(0px);
}

.card-name {
    font-size: 16px;
    font-weight: bold;
    text-align: center;
    color: #1a0026;
}

.card-label {
    position: absolute;
    bottom: 10px;
    left: 10px;
    background: rgba(255, 0, 0, 0.8);
    color: #fff;
    padding: 2px 5px;
    border-radius: 5px;
    font-size: 12px;
    z-index: 2;
}

.back-content {
    text-align: center;
    padding: 10px;
    overflow: hidden;
}

.back-content strong {
    font-size: 14px;
    display: block;
    margin-bottom: 5px;
}

.back-content p {
    font-size: 10px;
    margin: 5px 0;
    overflow-wrap: break-word;
}

.back-content em {
    font-size: 10px;
    display: block;
    margin-top: 5px;
}

/* Responsive adjustments */
@media (max-width: 600px) {
    .card-wrapper {
        width: 120px;
        height: 180px;
    }
    .card-container.expanded {
        transform: scale(1.8) rotateY(180deg);
    }
    .back-content strong {
        font-size: 12px;
    }
    .back-content p {
        font-size: 8px;
    }
    .back-content em {
        font-size: 6px;
    }
}

@media (max-width: 375px) {
    .card-wrapper {
        width: 110px;
        height: 160px;
    }
    .card-container.expanded {
        transform: scale(1.6) rotateY(180deg);
    }
    .back-content strong {
        font-size: 10px;
    }
    .back-content p {
        font-size: 6px;
    }
    .back-content em {
        font-size: 4px;
    }
}

/* Footer */
footer {
    width: 100%;
    position: relative;
    z-index: 1;
    margin-top: auto;
}

.footer-content {
    background-color: rgba(51, 51, 51, 0.9);
    color: white;
    text-align: center;
    padding: 15px 10px;
    width: 100%;
    position: relative;
    z-index: 1;
}

.support-link {
    color: whitesmoke;
    text-decoration: none;
    font-weight: 600;
    font-size: 12px;
}

.support-bitcoin {
    color: #FFD700;
    text-decoration: none;
    font-weight: 600;
    font-size: 12px;
}

iframe {
    width: 100%;
    height: 100%;
    border: none;
    display: block;
    padding-bottom: 20px;
}

.reference-button {
    padding: clamp(8px, 2vw, 12px) clamp(15px, 3vw, 20px);
    font-size: clamp(14px, 2vw, 16px);
    font-weight: 600;
    border: 2px solid #ffd700;
    border-radius: 25px;
    background-color: #f0e6d2;
    color: #2c003e;
    cursor: pointer;
    transition: all 0.3s ease;
    margin: 15px 0;
    width: auto;
    min-width: 200px;
}

.reference-button:hover {
    background-color: #ffd700;
    color: #2c003e;
}

.reference-section {
    background: rgba(255, 255, 255, 0.1);
    padding: clamp(15px, 3vw, 20px);
    border-radius: 15px;
    margin: 15px 0;
    backdrop-filter: blur(5px);
    opacity: 0;
    transition: opacity 0.3s ease;
    width: 100%;
    max-width: 900px;
    margin-left: auto;
    margin-right: auto;
}

.reference-section:not(.hidden) {
    opacity: 1;
}

.reference-section.hidden {
    display: none;
}

.reference-section h2 {
    font-family: 'Cinzel', serif;
    color: #ffd700;
    margin-bottom: 20px;
    text-shadow: 0 0 10px rgba(255, 215, 0, 0.5);
    display: none;
}

.reference-section:not(.hidden) h2 {
    display: block;
}

.reference-card {
    position: relative;
    width: clamp(100px, 20vw, 150px);
    height: clamp(150px, 30vw, 225px);
    margin: 5px;
    transform-style: preserve-3d;
    transition: transform 0.6s cubic-bezier(0.4, 0, 0.2, 1);
    cursor: pointer;
}

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

.reference-card-front, .reference-card-back {
    position: absolute;
    width: 100%;
    height: 100%;
    backface-visibility: hidden;
    border-radius: 15px;
    overflow: hidden;
}

.reference-card-front {
    background: linear-gradient(135deg, #f5f5f5, #e0e0e0);
    border: 3px solid #ffd700;
    transform: rotateY(0deg);
}

.reference-card-front img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.reference-card-back {
    background: linear-gradient(135deg, #ffd700, #ff6b6b);
    border: 3px solid #ff0000;
    transform: rotateY(180deg);
    padding: 10px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.2);
    overflow: hidden;
}

.reference-card-meaning {
    color: #fff;
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.5);
    font-size: clamp(9px, 1.5vw, 11px);
    line-height: 1.3;
    max-height: 100%;
    overflow-y: auto;
    padding: clamp(3px, 1vw, 5px);
    width: 100%;
}

.reference-card-meaning strong {
    display: block;
    color: #ffd700;
    margin: clamp(2px, 1vw, 3px) 0;
    font-size: clamp(10px, 1.8vw, 12px);
    text-shadow: 0 0 5px rgba(255, 215, 0, 0.5);
}

.reference-card-meaning p {
    margin: clamp(2px, 1vw, 3px) 0;
    font-size: clamp(8px, 1.3vw, 10px);
}

.reference-card-meaning em {
    display: block;
    margin-top: clamp(5px, 1.5vw, 8px);
    font-style: italic;
    color: #ffd700;
    text-shadow: 0 0 5px rgba(255, 215, 0, 0.5);
    font-size: clamp(8px, 1.3vw, 10px);
}

/* Custom scrollbar for the card back */
.reference-card-meaning::-webkit-scrollbar {
    width: 4px;
}

.reference-card-meaning::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.1);
}

.reference-card-meaning::-webkit-scrollbar-thumb {
    background: rgba(255, 215, 0, 0.5);
    border-radius: 2px;
}

.reference-card-meaning::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 215, 0, 0.8);
}

.reference-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(clamp(100px, 20vw, 150px), 1fr));
    gap: clamp(10px, 2vw, 20px);
    padding: clamp(10px, 2vw, 20px);
    perspective: 1000px;
    width: 100%;
}

@media (max-width: 600px) {
    .reference-card {
        width: 120px;
        height: 180px;
    }
}

@media (max-width: 375px) {
    .reference-card {
        width: 100px;
        height: 150px;
    }
}

/* Landscape mode adjustments */
@media (max-height: 500px) and (orientation: landscape) {
    body {
        padding: 2px;
    }
    
    .container {
        padding: 5px;
        margin: 2px;
    }
    
    .footer-content {
        padding: 5px 2px;
        font-size: 12px;
    }
    
    .card-wrapper, .reference-card {
        width: clamp(80px, 15vh, 120px);
        height: clamp(120px, 22vh, 180px);
    }
    
    .reference-grid {
        grid-template-columns: repeat(auto-fill, minmax(clamp(80px, 15vh, 120px), 1fr));
    }
}

/* High DPI screens optimization */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    .card-front img, .reference-card-front img {
        image-rendering: -webkit-optimize-contrast;
        image-rendering: crisp-edges;
    }
}

/* Touch device optimizations */
@media (hover: none) {
    body {
        cursor: default;
    }
    
    .interactive-cursor,
    .mouse-interaction {
        display: none;
    }
    
    /* Optimize animations for touch devices */
    body::before,
    body::after,
    .ethereal-overlay {
        animation-duration: 40s;
    }
    
    .particle {
        animation-duration: 20s;
    }
    
    #spread-select, #draw-button, .reference-button {
        padding: 12px 20px;
    }
}

/* Mouse Interaction Effects */
.mouse-interaction {
    position: fixed;
    width: 100px;
    height: 100px;
    background: radial-gradient(circle, rgba(255, 215, 0, 0.2) 0%, transparent 70%);
    border-radius: 50%;
    pointer-events: none;
    z-index: -1;
    transform: translate(-50%, -50%);
    transition: transform 0.3s ease-out;
    mix-blend-mode: screen;
}

/* Scroll Interaction Effects */
.scroll-interaction {
    position: fixed;
    width: 100%;
    height: 100%;
    background: radial-gradient(circle at center, rgba(255, 107, 107, 0.1) 0%, transparent 50%);
    pointer-events: none;
    z-index: -1;
    transition: transform 0.3s ease-out;
    mix-blend-mode: overlay;
}

/* Mobile Optimizations */
@media (max-width: 768px) {
    body {
        padding: 5px;
    }
    
    .container {
        padding: 8px;
        margin: 5px;
        width: calc(100% - 10px);
    }
    
    .footer-content {
        padding: 10px 5px;
    }
    
    /* Adjust animations for mobile */
    body::before {
        animation: cosmicPulse 30s ease-in-out infinite;
    }
    
    body::after {
        animation: gridMove 45s linear infinite;
    }
    
    .particle {
        width: 1.5px;
        height: 1.5px;
    }
    
    .ethereal-overlay {
        animation: etherealPulse 25s ease-in-out infinite;
    }
    
    /* Optimize interactive elements for touch */
    .interactive-cursor {
        display: none;
    }
    
    .mouse-interaction {
        display: none;
    }
    
    .scroll-interaction {
        opacity: 0.3;
    }
}

/* Small Screens */
@media (max-width: 480px) {
    body {
        padding: 2px;
    }
    
    .container {
        padding: 5px;
        margin: 2px;
        width: calc(100% - 4px);
    }
    
    .footer-content {
        padding: 8px 2px;
        font-size: 11px;
    }
    
    /* Reduce animation intensity */
    body::before,
    body::after {
        opacity: 0.4;
    }
    
    .particle {
        display: none;
    }
    
    .ethereal-overlay {
        opacity: 0.3;
    }
}

/* Fix for iOS Safari */
@supports (-webkit-touch-callout: none) {
    body {
        min-height: -webkit-fill-available;
    }
    
    .container {
        min-height: -webkit-fill-available;
    }
}

/* Ensure no horizontal scroll */
@media (max-width: 100%) {
    html, body {
        overflow-x: hidden;
        width: 100%;
        position: relative;
    }
    
    .container {
        max-width: 100%;
        width: 100%;
    }
}
