/* Basic Reset & Glassy Theme */
:root {
    --bg-color: #0f0e17;
    --card-bg: rgba(18, 18, 24, 0.4);
    --sidebar-bg: rgba(15, 14, 23, 0.6);
    --text-color: #fffffe;
    --accent-color: #7f5af0;
    --accent-color-2: #2cb67d;
    --accent-color-3: #ff8906;
    --border-color: rgba(255, 255, 255, 0.08);
    --shadow-color: rgba(127, 90, 240, 0.2);
    --glass-blur: 15px;
    --card-border-radius: 18px;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', 'SF Pro Display', 'Segoe UI', Arial, sans-serif;
    background: radial-gradient(ellipse at bottom right, #2d2b55 0%, #0f0e17 70%);
    color: var(--text-color);
    min-height: 100vh;
    overflow: hidden;
}

/* Custom Scrollbar */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.05);
    border-radius: 10px;
}

::-webkit-scrollbar-thumb {
    background: var(--accent-color);
    border-radius: 10px;
    transition: background 0.3s ease;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--accent-color-2);
}

/* Header */
header {
    background: rgba(15, 14, 23, 0.7);
    backdrop-filter: blur(var(--glass-blur));
    -webkit-backdrop-filter: blur(var(--glass-blur));
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
    border-bottom: 1px solid var(--border-color);
    padding: 1.5rem 2rem;
    text-align: center;
    position: relative;
    z-index: 10;
}

header h1 {
    font-size: 2.4rem;
    font-weight: 700;
    letter-spacing: 1px;
    background: linear-gradient(45deg, var(--accent-color), var(--accent-color-2));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    text-shadow: 0px 2px 10px rgba(127, 90, 240, 0.3);
    transition: transform 0.3s ease;
}

header h1:hover {
    transform: scale(1.02);
}

.container {
    display: flex;
    height: calc(100vh - 85px);
    overflow: hidden;
}

/* Sidebar Styling */
.sidebar {
    width: 320px;
    background: var(--sidebar-bg);
    backdrop-filter: blur(10px); /* Reduced from 15px */
    -webkit-backdrop-filter: blur(10px); /* Reduced from 15px */
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.08); /* Reduced shadow intensity */
    border-right: 1px solid var(--border-color);
    padding: 2rem;
    display: flex;
    flex-direction: column;
    z-index: 2;
    transition: all 0.5s cubic-bezier(0.16, 1, 0.3, 1);
}

.sidebar h2 {
    color: var(--accent-color);
    font-weight: 600;
    margin-bottom: 1.5rem;
    letter-spacing: 0.5px;
    font-size: 1.5rem;
    position: relative;
    display: inline-block;
}

.sidebar h2::after {
    content: '';
    position: absolute;
    bottom: -8px;
    left: 0;
    width: 40px;
    height: 3px;
    background: var(--accent-color);
    border-radius: 3px;
}

#topic-list {
    list-style: none;
    flex-grow: 1;
    overflow-y: auto;
    padding-right: 0.5rem;
}

.topic-item {
    margin-bottom: 1.2rem;
    transition: transform 0.2s;
}

.topic-name {
    font-weight: 500;
    cursor: pointer;
    display: block;
    padding: 0.9rem 1.2rem;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.03);
    transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    color: var(--text-color);
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.05);
}

.topic-name:hover {
    background: rgba(127, 90, 240, 0.1);
    box-shadow: 0 4px 10px rgba(127, 90, 240, 0.1); /* Reduced shadow */
    transform: translateY(-2px);
}

.topic-item.expanded > .topic-name {
    background: rgba(127, 90, 240, 0.15);
    box-shadow: 0 4px 10px rgba(127, 90, 240, 0.1); /* Reduced shadow */
    font-weight: 600;
}

.topic-name::before {
    content: '›';
    display: inline-block;
    margin-right: 8px;
    transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    font-size: 1.2rem;
    color: var(--accent-color);
}

.topic-item.expanded > .topic-name::before {
    transform: rotate(90deg);
}

.subtopic-list {
    list-style: none;
    margin-left: 1.5rem;
    margin-top: 0.8rem;
    padding: 0.3rem 0;
    opacity: 0;
    max-height: 0;
    overflow: hidden;
    transition: all 0.5s cubic-bezier(0.16, 1, 0.3, 1);
}

.topic-item.expanded .subtopic-list {
    opacity: 1;
    max-height: 500px;
}

.subtopic-item {
    margin-bottom: 0.5rem;
    transition: transform 0.2s;
}

.subtopic-item label {
    display: flex;
    align-items: center;
    cursor: pointer;
    font-size: 0.95rem;
    padding: 0.7rem 1rem;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.02);
    transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.03);
}

.subtopic-item label:hover {
    background: rgba(44, 182, 125, 0.1);
    transform: translateX(5px);
}

.subtopic-item input[type="checkbox"] {
    margin-right: 0.8rem;
    appearance: none;
    -webkit-appearance: none;
    width: 18px;
    height: 18px;
    border: 1.5px solid var(--accent-color-2);
    border-radius: 4px;
    background: transparent;
    position: relative;
    cursor: pointer;
    transition: all 0.2s ease;
}

.subtopic-item input[type="checkbox"]:checked {
    background: var(--accent-color-2);
    border-color: var(--accent-color-2);
}

.subtopic-item input[type="checkbox"]:checked::after {
    content: "✓";
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: white;
    font-size: 0.8rem;
}

.card-count-label {
    margin-top: 1.5rem;
    font-size: 1rem;
    color: var(--text-color);
    text-align: center;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 12px;
    padding: 0.9rem 1rem;
    font-weight: 500;
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.05);
    position: relative;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.card-count-label::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(120deg, rgba(127, 90, 240, 0.1), rgba(44, 182, 125, 0.1));
    opacity: 0.5;
    z-index: -1;
}

#card-count {
    color: var(--accent-color-2);
    font-weight: 700;
    font-size: 1.1rem;
    text-shadow: 0 0 10px rgba(44, 182, 125, 0.5);
}

/* Sound control button */
.sound-control {
    margin-top: 1rem;
    background: rgba(255, 255, 255, 0.05);
    border: none;
    border-radius: 12px;
    padding: 0.8rem;
    color: var(--text-color);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    width: 100%;
    transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.05);
}

.sound-control:hover {
    background: rgba(127, 90, 240, 0.15);
}

.sound-control .sound-icon {
    margin-right: 8px;
    font-size: 1.2rem;
}

.sound-control.muted .sound-icon {
    opacity: 0.6;
}

/* Main Content & Flashcard Area */
.main-content {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    background: linear-gradient(135deg, rgba(127, 90, 240, 0.05) 0%, rgba(44, 182, 125, 0.05) 100%);
    position: relative;
    overflow: hidden;
}

.main-content::before {
    content: '';
    position: absolute;
    width: 500px;
    height: 500px;
    background: radial-gradient(circle, rgba(127, 90, 240, 0.2) 0%, rgba(127, 90, 240, 0) 70%);
    top: -250px;
    right: -150px;
    border-radius: 50%;
    filter: blur(50px);
}

.main-content::after {
    content: '';
    position: absolute;
    width: 300px;
    height: 300px;
    background: radial-gradient(circle, rgba(44, 182, 125, 0.15) 0%, rgba(44, 182, 125, 0) 70%);
    bottom: -100px;
    left: -50px;
    border-radius: 50%;
    filter: blur(40px);
}

.flashcard-area {
    position: relative;
    width: 100%;
    max-width: 800px; /* Increased from 650px */
    height: 500px; /* Increased from 450px */
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1;
    margin: 0 auto; /* Center horizontally */
    padding: 0 20px; /* Add some padding on the sides */
}

.flashcard-area:hover .flip-hint {
    opacity: 1;
    transform: translateY(0);
}

/* === Enhanced 3D Flip Animation === */
.card-container {
    perspective: 2000px !important;
    transform-style: preserve-3d !important;
    width: 100%; /* Ensure full width usage */
    height: 100%; /* Ensure full height usage */
}

.card {
    width: 100%;
    height: 100%;
    transform-style: preserve-3d !important;
    transition: transform 0.7s cubic-bezier(0.175, 0.885, 0.32, 1.275), box-shadow 0.4s ease !important;
    position: relative;
    will-change: transform;
    border-radius: var(--card-border-radius);
    box-shadow: 0 15px 35px rgba(0, 0, 0, 0.2), 0 0 0 1px var(--border-color);
}

/* Add hover effect for the entire card */
.card-container:hover .card {
    box-shadow: 0 15px 45px rgba(127, 90, 240, 0.4), 0 0 0 1px var(--accent-color);
}

.card-face {
    /* full overlay stack */
    position: absolute;
    width: 100%;
    height: 100%;
    top: 0;
    left: 0;
    /* Enhanced transition with multiple properties */
    transition: opacity 0.5s ease, transform 0.7s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    /* Better 3D support */
    backface-visibility: hidden !important;
    -webkit-backface-visibility: hidden !important;
    transform: translateZ(0);
    will-change: transform, opacity;
    padding: 2rem; /* Increased padding */
    display: flex;
    flex-direction: column;
}

.card-front {
    opacity: 1;
    z-index: 2;
    transform: rotateY(0deg) translateZ(1px);
}

.card-back {
    opacity: 0;
    z-index: 1;
    transform: rotateY(-180deg) translateZ(1px);
}

.card.flipped {
    transform: rotateY(180deg) !important;
}

.card.flipped .card-front {
    opacity: 0;
    z-index: 1;
    pointer-events: none;
    transform: rotateY(0deg) translateZ(1px);
}

.card.flipped .card-back {
    opacity: 1;
    z-index: 2;
    pointer-events: auto;
    transform: rotateY(-180deg) translateZ(1px);
}

/* Card background subtle geometric patterns */
.card-front::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    opacity: 0.05;
    background-image: 
        radial-gradient(circle at 20% 30%, rgba(127, 90, 240, 0.7) 0%, transparent 20%),
        radial-gradient(circle at 80% 70%, rgba(44, 182, 125, 0.7) 0%, transparent 20%);
    z-index: -1;
}

.card-back::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    opacity: 0.07;
    background-image: 
        radial-gradient(circle at 70% 20%, rgba(255, 137, 6, 0.7) 0%, transparent 20%),
        radial-gradient(circle at 30% 80%, rgba(127, 90, 240, 0.7) 0%, transparent 20%);
    z-index: -1;
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 1rem;
    margin-bottom: 1.5rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid var(--border-color);
}

.series-info {
    color: var(--accent-color);
    font-weight: 600;
    letter-spacing: 0.5px;
}

.question-number {
    color: var(--accent-color-3);
    font-weight: 600;
    background: rgba(255, 137, 6, 0.1);
    padding: 0.3rem 0.8rem;
    border-radius: 8px;
}

.card-body {
    flex-grow: 1;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    overflow-y: auto;
    padding: 2rem; /* Increased padding */
    font-size: 1.25rem; /* Increased from 1.15rem */
    line-height: 1.7; /* Increased from 1.6 */
    background: rgba(255, 255, 255, 0.05); /* Slightly more contrast */
    border-radius: 14px;
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.07);
    opacity: 1; /* Ensure content is visible by default when face is shown */
    max-height: calc(100% - 120px); /* Ensure it doesn't overflow */
    margin-top: 0.5rem;
    text-align: left; /* Ensure text alignment is consistent */
    width: 100%; /* Ensure full width */
}

.marks-info {
    align-self: flex-start;
    margin-top: 1.2rem;
    font-size: 0.9rem;
    background: rgba(127, 90, 240, 0.15);
    color: var(--accent-color);
    padding: 0.3rem 0.8rem;
    border-radius: 8px;
    font-weight: 600;
    letter-spacing: 0.5px;
    transition: all 0.3s ease;
}

/* Navigation Arrows - Enhanced with playful effects */
.nav-arrow {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(15, 14, 23, 0.7);
    color: var(--text-color);
    border: none;
    border-radius: 50%;
    width: 55px;
    height: 55px;
    font-size: 1.5rem;
    cursor: pointer;
    z-index: 10;
    display: flex;
    justify-content: center;
    align-items: center;
    backdrop-filter: blur(var(--glass-blur));
    -webkit-backdrop-filter: blur(var(--glass-blur));
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.15), 0 0 0 1px var(--border-color);
    transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    overflow: hidden;
}

.nav-arrow::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--accent-color);
    border-radius: 50%;
    transform: scale(0);
    transition: transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
    z-index: -1;
}

.nav-arrow:hover {
    transform: translateY(-50%) scale(1.12);
    box-shadow: 0 12px 30px rgba(127, 90, 240, 0.4), 0 0 0 1px var(--accent-color);
    color: white;
}

.nav-arrow:hover::before {
    transform: scale(1);
}

.nav-arrow:active {
    transform: translateY(-50%) scale(0.9);
}

.prev-arrow { left: -27px; }
.next-arrow { right: -27px; }
.nav-arrow.hidden { opacity: 0; pointer-events: none; }

/* Progress indicators */
.progress-dots {
    position: absolute;
    bottom: -40px;
    left: 0;
    right: 0;
    display: none;
    justify-content: center;
    gap: 8px;
}

.progress-dot {
    width: 10px;
    height: 10px;
    background: rgba(255, 255, 255, 0.15);
    border-radius: 50%;
    transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    display : none;
}

.progress-dot.active {
    background: var(--accent-color);
    box-shadow: 0 0 10px rgba(127, 90, 240, 0.5);
    transform: scale(1.3);
    display: none;
}

/* Flip hint */
.flip-hint {
    position: absolute;
    bottom: -30px;
    left: 0;
    right: 0;
    text-align: center;
    color: rgba(255, 255, 255, 0.5);
    font-size: 0.9rem;
    opacity: 0;
    transform: translateY(10px);
    transition: all 0.5s cubic-bezier(0.16, 1, 0.3, 1);
}

/* Keyboard shortcuts guide */
.keyboard-shortcuts {
    position: absolute;
    bottom: 20px;
    left: 0;
    right: 0;
    display: flex;
    justify-content: center;
    gap: 15px;
    font-size: 0.85rem;
    color: rgba(255, 255, 255, 0.6);
}

.shortcut {
    display: flex;
    align-items: center;
    gap: 5px;
}

.key {
    display: inline-block;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 4px;
    padding: 2px 6px;
    font-family: 'SF Mono', 'Courier New', monospace;
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.1);
}

/* Background gradient effects */
.background-gradient {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: -1;
    background: radial-gradient(ellipse at bottom right, #2d2b55 0%, #0f0e17 70%);
}

/* Card Animations */
@keyframes float {
    0%, 100% { transform: translateY(0) rotate(0deg); }
    50% { transform: translateY(-10px) rotate(-1deg); }
}

/* Sliding animations - slide then fade (refined) */
@keyframes slideOutLeftFade {
    0% { transform: translateX(0) scale(1); opacity: 1; }
    70% { transform: translateX(-110%) scale(0.9); opacity: 0.5; } /* Start fading earlier, move slightly further */
    100% { transform: translateX(-120%) scale(0.85); opacity: 0; } /* Complete fade and move further */
}

@keyframes slideOutRightFade {
    0% { transform: translateX(0) scale(1); opacity: 1; }
    70% { transform: translateX(110%) scale(0.9); opacity: 0.5; } /* Start fading earlier, move slightly further */
    100% { transform: translateX(120%) scale(0.85); opacity: 0; } /* Complete fade and move further */
}

.slide-out-left {
    animation: slideOutLeftFade 0.6s ease-in-out forwards;
    /* Let animation handle final state */
}

.slide-in-right {
    /* Restore transition */
    transition: transform 0.6s ease-in-out, opacity 0.6s ease-in-out;
    /* Remove animation */
    /* animation: slideInRightFade 0.6s ease-in-out forwards; */
    /* Set initial state explicitly */
    transform: translateX(100%) scale(1.1);
    opacity: 0;
}

.slide-out-right {
    animation: slideOutRightFade 0.6s ease-in-out forwards;
    /* Let animation handle final state */
}

.slide-in-left {
    /* Restore transition */
    transition: transform 0.6s ease-in-out, opacity 0.6s ease-in-out;
    /* Remove animation */
    /* animation: slideInLeftFade 0.6s ease-in-out forwards; */
    /* Set initial state explicitly */
    transform: translateX(-100%) scale(1.1);
    opacity: 0;
}

/* Celebration animations */
@keyframes pulse {
    0% { transform: scale(1); box-shadow: 0 15px 35px rgba(0, 0, 0, 0.2), 0 0 0 1px var(--border-color); }
    50% { transform: scale(1.05); box-shadow: 0 25px 50px rgba(127, 90, 240, 0.4), 0 0 0 2px var(--accent-color); }
    100% { transform: scale(1); box-shadow: 0 15px 35px rgba(0, 0, 0, 0.2), 0 0 0 1px var(--border-color); }
}

.confetti {
    position: absolute;
    width: 12px;
    height: 12px;
    top: -30px;
    z-index: 100;
    pointer-events: none;
    opacity: 0.8;
    animation: confetti-fall 3s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

@keyframes confetti-fall {
    0% { transform: translateY(0) rotate(0deg); opacity: 0.8; }
    20% { opacity: 0.9; }
    100% { transform: translateY(calc(100vh - 100px)) rotate(720deg); opacity: 0; }
}

/* Responsive Adjustments */
@media (max-width: 1024px) {
    .sidebar { width: 280px; }
    .flashcard-area { max-width: 550px; height: 400px; }
}

@media (max-width: 900px) {
    .container { flex-direction: column; }
    .sidebar { 
        width: 100%; 
        max-height: 40vh; 
        border-right: none;
        border-bottom: 1px solid var(--border-color);
    }
    .main-content { height: 60vh; }
    .flashcard-area { max-width: 90vw; height: 40vh; }
    .prev-arrow, .next-arrow { top: 50%; }
}

@media (max-width: 600px) {
    header h1 { font-size: 1.8rem; }
    .card-face { padding: 1.5rem; }
    .card-body { font-size: 1rem; padding: 1rem; }
    .nav-arrow { width: 45px; height: 45px; font-size: 1.2rem; }
    .prev-arrow { left: -15px; }
    .next-arrow { right: -15px; }
}
