:root {
    --bg-color: #F5F5F7;
    --card-bg: rgba(255, 255, 255, 0.95);
    --text-primary: #1D1D1F;
    --text-secondary: #86868B;
    --accent: #000000;
    --accent-hover: #333333;
    --danger: #FF3B30;
    --success: #34C759;
    --radius: 20px;
    --shadow: 0 4px 20px rgba(0,0,0,0.06);
    --border: 1px solid rgba(0,0,0,0.08);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-font-smoothing: antialiased;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-primary);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    padding: 40px 20px;
    line-height: 1.5;
}

.container {
    width: 100%;
    max-width: 850px;
    margin: 0 auto;
}

/* Header */
.header {
    text-align: center;
    margin-bottom: 40px;
    animation: fadeIn 0.8s ease-out;
}

.header h1 {
    font-size: 2.5rem;
    font-weight: 800;
    letter-spacing: -0.03em;
    margin-bottom: 8px;
    color: var(--accent);
    background: linear-gradient(135deg, var(--accent) 0%, var(--accent-hover) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.header .subtitle {
    font-size: 1.05rem;
    color: var(--text-secondary);
    font-weight: 500;
    letter-spacing: 0.01em;
}

/* Card Style */
.card {
    background: var(--card-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-radius: var(--radius);
    padding: 40px;
    box-shadow: var(--shadow);
    border: var(--border);
    margin-bottom: 30px;
    transition: transform 0.3s cubic-bezier(0.2, 0.8, 0.2, 1);
}

/* History / Saved Sets Tabs */
.sets-nav {
    display: flex;
    gap: 20px;
    margin-bottom: 20px;
    border-bottom: 1px solid #e5e5ea;
    padding-bottom: 10px;
}

.set-tab {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-secondary);
    cursor: pointer;
    padding-bottom: 10px;
    margin-bottom: -11px;
    transition: color 0.2s;
}

.set-tab.active {
    color: var(--accent);
    border-bottom: 2px solid var(--accent);
}

.saved-sets-scroll {
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-height: 200px;
    overflow-y: auto;
    padding-right: 5px;
    margin-bottom: 25px;
}

.saved-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    background: #fbfbfd;
    border: 1px solid rgba(0,0,0,0.05);
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.2s;
}

.saved-item:hover {
    background: #f2f2f7;
    transform: translateX(2px);
}

.saved-info {
    display: flex;
    flex-direction: column;
}

.saved-name {
    font-weight: 600;
    font-size: 0.95rem;
}

.saved-date {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.delete-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 1.2rem;
    padding: 5px;
    cursor: pointer;
    opacity: 0.5;
}

.delete-btn:hover {
    opacity: 1;
    color: var(--danger);
}

/* Inputs */
.input-group {
    margin-bottom: 25px;
}

label {
    display: block;
    font-size: 0.85rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
    margin-bottom: 10px;
}

textarea {
    width: 100%;
    min-height: 160px;
    padding: 18px;
    border-radius: 16px;
    border: 1px solid #d2d2d7;
    background: #fbfbfd;
    font-family: inherit;
    font-size: 1rem;
    resize: vertical;
    transition: all 0.2s ease;
}

textarea:focus {
    outline: none;
    border-color: var(--accent);
    background: white;
    box-shadow: 0 0 0 4px rgba(0,0,0,0.03);
}

/* Segmented Controls */
.segmented-control {
    display: flex;
    background: rgba(118, 118, 128, 0.12);
    padding: 3px;
    border-radius: 12px;
    margin-bottom: 25px;
}

.segment-option {
    flex: 1;
    text-align: center;
    padding: 8px;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    border-radius: 9px;
    color: var(--text-primary);
    transition: all 0.2s;
}

.segment-option.selected {
    background: white;
    box-shadow: 0 2px 6px rgba(0,0,0,0.08);
    font-weight: 600;
}

/* Settings */
.settings-row {
    display: flex;
    gap: 15px;
    margin-bottom: 25px;
}

select {
    appearance: none;
    width: 100%;
    padding: 12px 16px;
    border-radius: 12px;
    border: 1px solid #d2d2d7;
    background: white url("data:image/svg+xml;charset=US-ASCII,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%22292.4%22%20height%3D%22292.4%22%3E%3Cpath%20fill%3D%22%231D1D1F%22%20d%3D%22M287%2069.4a17.6%2017.6%200%200%200-13-5.4H18.4c-5%200-9.3%201.8-12.9%205.4A17.6%2017.6%200%200%200%200%2082.2c0%205%201.8%209.3%205.4%2012.9l128%20127.9c3.6%203.6%207.8%205.4%2012.8%205.4s9.2-1.8%2012.8-5.4L287%2095c3.5-3.5%205.4-7.8%205.4-12.8%200-5-1.9-9.2-5.5-12.8z%22%2F%3E%3C%2Fsvg%3E") no-repeat right 15px center;
    background-size: 10px;
    font-size: 0.95rem;
    cursor: pointer;
}

/* Action Button */
.btn {
    width: 100%;
    padding: 17px;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: 14px;
    font-size: 1.05rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 2px 8px rgba(0,0,0,0.12);
    position: relative;
    overflow: hidden;
}

.btn::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    border-radius: 50%;
    background: rgba(255,255,255,0.15);
    transform: translate(-50%, -50%);
    transition: width 0.4s, height 0.4s;
}

.btn:hover::before {
    width: 300px;
    height: 300px;
}

.btn:hover {
    background: var(--accent-hover);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.18);
}

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

.btn:disabled {
    background: #d2d2d7;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

/* Loading State */
.loading {
    display: none;
    text-align: center;
    margin-top: 30px;
}

.loading.active {
    display: block;
    animation: fadeIn 0.4s ease;
}

.loading-spinner {
    width: 50px;
    height: 50px;
    border: 4px solid rgba(0,0,0,0.08);
    border-left-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 0 auto 20px;
}

.loading-text {
    color: var(--text-secondary);
    font-size: 0.95rem;
    font-weight: 500;
    margin-bottom: 12px;
}

.loading-progress {
    margin-top: 20px;
    text-align: center;
}

.progress-bar {
    width: 100%;
    height: 6px;
    background: rgba(0,0,0,0.06);
    border-radius: 10px;
    overflow: hidden;
    margin-top: 10px;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--accent), var(--accent-hover));
    border-radius: 10px;
    transition: width 0.3s ease;
    animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}

/* Flashcard Mode */
.flashcard-container {
    display: none;
}

.flashcard-container.active {
    display: block;
}

.flashcard-wrapper {
    position: relative;
    width: 100%;
    min-height: 350px;
    cursor: pointer;
    transform-style: preserve-3d;
    transition: transform 0.6s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.flashcard-wrapper.flipped {
    transform: rotateY(180deg);
}

.flashcard-face {
    position: absolute;
    width: 100%;
    height: 100%;
    backface-visibility: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 30px;
    background: white;
    border-radius: 20px;
    box-shadow: 0 10px 30px -10px rgba(0,0,0,0.1);
    border: 1px solid rgba(0,0,0,0.05);
    text-align: center;
    font-size: 1.3rem;
    font-weight: 500;
    color: var(--text-primary);
}

.flashcard-back {
    transform: rotateY(180deg);
    background: #f5f5f7;
    text-align: left;
    padding: 40px;
    font-size: 1.1rem;
    line-height: 1.6;
}

.nav-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 30px;
}

.nav-btn {
    background: white;
    border: 1px solid #e5e5ea;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    font-size: 1.5rem;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 8px rgba(0,0,0,0.05);
}

.nav-btn:hover {
    background: #f5f5f7;
    border-color: #d2d2d7;
}

/* Quiz Mode */
.quiz-container {
    display: none;
}

.quiz-container.active {
    display: block;
}

.quiz-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 25px;
    padding-bottom: 15px;
    border-bottom: 2px solid #e5e5ea;
}

.quiz-progress-text {
    font-weight: 600;
    color: var(--text-secondary);
    font-size: 0.95rem;
}

.quiz-page {
    display: none;
}

.quiz-page.active {
    display: block;
    animation: fadeIn 0.4s ease;
}

.question-card {
    background: white;
    border-radius: 16px;
    padding: 28px;
    margin-bottom: 20px;
    box-shadow: 0 2px 12px rgba(0,0,0,0.04);
    border: 1px solid rgba(0,0,0,0.06);
    transition: all 0.3s ease;
    animation: slideUp 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}

.question-card:hover {
    box-shadow: 0 4px 16px rgba(0,0,0,0.08);
    transform: translateY(-2px);
}

.question-text {
    font-weight: 600;
    font-size: 1.05rem;
    margin-bottom: 15px;
    color: var(--text-primary);
}

.option {
    padding: 14px 16px;
    margin-top: 10px;
    border-radius: 10px;
    border: 2px solid #e5e5ea;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 0.95rem;
    font-weight: 500;
}

.option:hover {
    background: #f8f8fa;
    border-color: #d2d2d7;
}

.option.selected {
    background: #e8e8ed;
    border-color: var(--accent);
    font-weight: 600;
}

.option.correct {
    background: #d4edda !important;
    border-color: var(--success) !important;
    font-weight: 700;
}

.option.incorrect {
    background: #f8d7da !important;
    border-color: var(--danger) !important;
}

.quiz-nav {
    display: flex;
    gap: 12px;
    margin-top: 30px;
}

.quiz-nav .btn {
    flex: 1;
}

.quiz-nav .btn-secondary {
    background: #f2f2f7;
    color: var(--text-primary);
    border: 2px solid #e5e5ea;
}

.quiz-nav .btn-secondary:hover {
    background: #e5e5ea;
}

/* Short Answer Specifics */
.sa-controls {
    display: flex;
    gap: 10px;
    margin-top: 15px;
}

.sa-controls .btn {
    width: auto;
    flex-grow: 1;
}

.sa-controls .btn-secondary {
    background: #f2f2f7;
    color: var(--text-primary);
    border: 1px solid #e5e5ea;
}

.sa-controls .btn-secondary:hover {
    background: #e5e5ea;
}

.sa-correct-answer {
    margin-top: 20px;
    padding: 15px;
    border-radius: 10px;
    border: 1px solid #ddd;
    background: #fff8e6;
    text-align: left;
}

.sa-correct-answer strong {
    display: block;
    margin-bottom: 5px;
    color: #cc8400;
}

.sa-correct-answer p {
    font-size: 0.95rem;
    line-height: 1.4;
}

/* Results & Summary */
.results {
    display: none;
    text-align: center;
    margin-top: 10px;
}

.results.active {
    display: block;
}

.score-circle {
    width: 120px;
    height: 120px;
    border-radius: 50%;
    border: 4px solid var(--text-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2.5rem;
    font-weight: 700;
    margin: 0 auto 20px;
}

.ai-summary {
    text-align: left;
    background: #f5f5f7;
    padding: 25px;
    border-radius: 16px;
    margin: 30px 0;
    border: 1px solid rgba(0,0,0,0.05);
}

.ai-tag {
    display: inline-block;
    background: white;
    padding: 4px 10px;
    border-radius: 6px;
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 10px;
}

.weak-area-item {
    background: white;
    padding: 15px;
    border-radius: 10px;
    margin-top: 10px;
    border-left: 3px solid var(--danger);
}

/* Timer */
.timer-float {
    position: fixed;
    top: 20px;
    right: 20px;
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(10px);
    color: var(--text-primary);
    padding: 8px 16px;
    border-radius: 20px;
    font-weight: 700;
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
    z-index: 100;
    display: none;
    font-feature-settings: "tnum";
}

.timer-float.active {
    display: block;
}

/* Background Generation Indicator */
.background-gen-indicator {
    position: fixed;
    bottom: 20px;
    right: 20px;
    background: rgba(52, 199, 89, 0.95);
    backdrop-filter: blur(10px);
    color: white;
    padding: 12px 20px;
    border-radius: 20px;
    font-weight: 600;
    font-size: 0.9rem;
    box-shadow: 0 4px 16px rgba(52, 199, 89, 0.3);
    z-index: 100;
    display: none;
    align-items: center;
    gap: 10px;
    animation: slideInRight 0.3s ease;
}

.background-gen-indicator:not(.hidden) {
    display: flex;
}

.spinner-small {
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes slideInRight {
    from {
        opacity: 0;
        transform: translateX(100px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

/* Animations */
@keyframes spin {
    0% {
        transform: rotate(0deg);
    }
    100% {
        transform: rotate(360deg);
    }
}

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

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

/* Staggered animation for quiz questions */
.quiz-page .question-card:nth-child(1) { animation-delay: 0.1s; }
.quiz-page .question-card:nth-child(2) { animation-delay: 0.2s; }
.quiz-page .question-card:nth-child(3) { animation-delay: 0.3s; }
.quiz-page .question-card:nth-child(4) { animation-delay: 0.4s; }
.quiz-page .question-card:nth-child(5) { animation-delay: 0.5s; }
.quiz-page .question-card:nth-child(6) { animation-delay: 0.6s; }

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

/* Utility Classes */
.hidden {
    display: none !important;
}
