:root {
    --bg-color: #0f172a;
    --glass-bg: rgba(30, 41, 59, 0.7);
    --glass-border: rgba(255, 255, 255, 0.1);
    --primary: #8b5cf6;
    --primary-hover: #7c3aed;
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --glow-color: rgba(139, 92, 246, 0.5);
}

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

body {
    background-color: var(--bg-color);
    color: var(--text-main);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow-x: hidden;
    overflow-y: auto;
    position: relative;
}

/* Animated Background */
.background-animation {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: 
        radial-gradient(circle at 15% 50%, rgba(139, 92, 246, 0.15) 0%, transparent 50%),
        radial-gradient(circle at 85% 30%, rgba(56, 189, 248, 0.15) 0%, transparent 50%);
    z-index: -1;
    animation: pulse 15s infinite alternate;
}

@keyframes pulse {
    0% { transform: scale(1); }
    100% { transform: scale(1.1); }
}

.app-container {
    width: 100%;
    max-width: 500px;
    padding: 2rem;
    position: relative;
    z-index: 1;
    margin: 2rem 0;
}

.glass-panel {
    background: var(--glass-bg);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--glass-border);
    border-radius: 24px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
}

.screen {
    display: none;
    opacity: 0;
    transition: opacity 0.4s ease, transform 0.4s ease;
    transform: translateY(10px);
}

.screen.active {
    display: block;
    opacity: 1;
    transform: translateY(0);
    animation: fadeIn 0.4s ease forwards;
}

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

/* Typography */
.title {
    font-size: 3rem;
    font-weight: 800;
    text-align: center;
    margin-bottom: 0.5rem;
    background: linear-gradient(to right, #f8fafc, #cbd5e1);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.title span {
    color: var(--primary);
    -webkit-background-clip: unset;
    -webkit-text-fill-color: var(--primary);
}

.subtitle {
    text-align: center;
    color: var(--text-muted);
    margin-bottom: 1.5rem;
    font-size: 1.1rem;
}

/* Form Styles */
.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

.settings-section {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

.hidden {
    display: none !important;
}

.input-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.full-width {
    grid-column: span 2;
}

label {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-muted);
}

input {
    width: 100%;
    background: rgba(15, 23, 42, 0.6);
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    padding: 0.8rem;
    color: var(--text-main);
    font-size: 1.2rem;
    font-weight: 600;
    outline: none;
    transition: all 0.3s ease;
    text-align: center;
}

input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 15px var(--glow-color);
}

/* Segmented Control */
.segmented-control {
    display: flex;
    background: rgba(15, 23, 42, 0.6);
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    overflow: hidden;
    width: 100%;
}

.segmented-control input[type="radio"] {
    display: none;
}

.segmented-control label {
    flex: 1;
    text-align: center;
    padding: 0.8rem;
    cursor: pointer;
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-muted);
    transition: all 0.3s ease;
    border-right: 1px solid var(--glass-border);
}

.segmented-control label:last-of-type {
    border-right: none;
}

.segmented-control input[type="radio"]:checked + label {
    background: rgba(139, 92, 246, 0.3);
    color: var(--text-main);
    box-shadow: inset 0 0 10px rgba(139, 92, 246, 0.2);
}

/* Buttons */
.btn-primary {
    background: var(--primary);
    color: white;
    border: none;
    padding: 1rem;
    border-radius: 12px;
    font-size: 1.1rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.3s ease;
    margin-top: 0.5rem;
}

.btn-primary:hover {
    background: var(--primary-hover);
    transform: translateY(-2px);
    box-shadow: 0 10px 25px -5px var(--glow-color);
}

.btn-primary:active {
    transform: translateY(0);
}

.btn-secondary {
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    border-radius: 8px;
    transition: all 0.2s ease;
    margin-bottom: 2rem;
}

.btn-secondary:hover {
    color: var(--text-main);
    background: rgba(255, 255, 255, 0.05);
}

/* Flashcard */
.flashcard-container {
    perspective: 1000px;
    width: 100%;
    height: 250px;
    margin-bottom: 2rem;
}

.flashcard-inner {
    position: relative;
    width: 100%;
    height: 100%;
    text-align: center;
    transition: transform 0.6s cubic-bezier(0.4, 0, 0.2, 1);
    transform-style: preserve-3d;
    cursor: pointer;
}

.flashcard-inner.is-flipped {
    transform: rotateX(180deg);
}

.flashcard-front, .flashcard-back {
    position: absolute;
    width: 100%;
    height: 100%;
    backface-visibility: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 20px;
    background: linear-gradient(145deg, rgba(255,255,255,0.05) 0%, rgba(255,255,255,0.01) 100%);
    border: 1px solid var(--glass-border);
    box-shadow: 0 10px 30px -10px rgba(0,0,0,0.3);
}

.flashcard-back {
    transform: rotateX(180deg);
    background: linear-gradient(145deg, rgba(139, 92, 246, 0.15) 0%, rgba(56, 189, 248, 0.05) 100%);
    border-color: rgba(139, 92, 246, 0.3);
}

.question-text, .answer-text {
    font-size: 3.5rem;
    font-weight: 800;
    letter-spacing: 2px;
}

.answer-text {
    color: #a78bfa;
    text-shadow: 0 0 20px rgba(167, 139, 250, 0.4);
    width: 100%;
}

/* Factors Grid for Reverse Mode */
.factors-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 0.8rem;
    justify-content: center;
    align-items: center;
    padding: 1.5rem;
    max-height: 100%;
    overflow-y: auto;
    width: 100%;
}

.factor-badge {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    padding: 0.6rem 1.2rem;
    border-radius: 12px;
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--text-main);
    transition: all 0.2s ease;
    cursor: pointer;
    user-select: none;
}

.factor-badge:hover {
    transform: scale(1.05);
    background: rgba(255, 255, 255, 0.1);
}

/* Color variations for factors */
.factor-badge.color-0 { border-color: rgba(139, 92, 246, 0.5); background: rgba(139, 92, 246, 0.15); color: #c4b5fd; }
.factor-badge.color-1 { border-color: rgba(56, 189, 248, 0.5); background: rgba(56, 189, 248, 0.15); color: #bae6fd; }
.factor-badge.color-2 { border-color: rgba(244, 63, 94, 0.5); background: rgba(244, 63, 94, 0.15); color: #fecdd3; }
.factor-badge.color-3 { border-color: rgba(16, 185, 129, 0.5); background: rgba(16, 185, 129, 0.15); color: #a7f3d0; }
.factor-badge.color-4 { border-color: rgba(245, 158, 11, 0.5); background: rgba(245, 158, 11, 0.15); color: #fde68a; }

.factor-badge.missed {
    background: rgba(239, 68, 68, 0.2) !important;
    border-color: #ef4444 !important;
    color: #fca5a5 !important;
    box-shadow: 0 0 15px rgba(239, 68, 68, 0.3);
    animation: shake 0.4s ease-in-out;
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-5px); }
    75% { transform: translateX(5px); }
}

/* Timer and Status */
.timer-bar-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 6px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 20px 20px 0 0;
    overflow: hidden;
    z-index: 10;
    transform: translateZ(1px); /* Keep it above the card face */
}

.timer-bar {
    height: 100%;
    width: 100%;
    background: #34d399; /* Green */
    transition: width 0.1s linear, background-color 0.3s ease;
}

.timer-bar.slow {
    background: #ef4444; /* Red */
}

.status-badge {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(239, 68, 68, 0.15);
    color: #ef4444;
    border: 1px solid rgba(239, 68, 68, 0.4);
    padding: 0.4rem 1rem;
    border-radius: 12px;
    font-size: 0.95rem;
    font-weight: 700;
    opacity: 0;
    transition: opacity 0.3s ease, transform 0.3s ease;
}

.status-badge.visible {
    opacity: 1;
    transform: translateX(-50%) translateY(-5px);
}

.performance-stats {
    position: absolute;
    top: 20px;
    left: 0;
    width: 100%;
    text-align: center;
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.performance-stats.visible {
    opacity: 1;
}

.time-taken {
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--text-main);
}

.motivation-message {
    font-size: 0.95rem;
    font-weight: 600;
    text-shadow: 0 0 10px rgba(0,0,0,0.5);
}

.flashcard-inner.wrong-marked .flashcard-back {
    border-color: rgba(239, 68, 68, 0.5);
    box-shadow: 0 10px 30px -10px rgba(239, 68, 68, 0.3);
}

/* Hints */
.controls-hint {
    text-align: center;
    color: var(--text-muted);
    font-size: 1rem;
    animation: bob 2s infinite ease-in-out;
}

.controls-hint strong {
    color: var(--primary);
    background: rgba(139, 92, 246, 0.1);
    padding: 0.2rem 0.6rem;
    border-radius: 4px;
    border: 1px solid rgba(139, 92, 246, 0.2);
}

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

@media (max-width: 480px) {
    .app-container {
        padding: 1.5rem;
        margin: 1rem;
        width: calc(100% - 2rem);
    }
    
    .question-text, .answer-text {
        font-size: 2.5rem;
    }
    
    .title {
        font-size: 2.5rem;
    }
}
