* { 
    margin: 0; 
    padding: 0; 
    box-sizing: border-box; 
}

body.form-page-bg {
    line-height: 1.6;
    color: var(--color-text-primary, #1a202c);
}

.container { 
    max-width: 1200px; 
    margin: 0 auto; 
    padding: 2rem 1rem; 
}

.lesson-generator.lesson-generator-panel {
    margin-bottom: 2rem;
}

.form-group { 
    margin-bottom: 2rem; 
    transition: all 0.2s ease;
}

.form-group:focus-within {
    transform: translateY(-1px);
}

.form-collapsed {
    max-height: 80px;
    overflow: hidden;
    position: relative;
    transition: max-height 0.3s ease;
    cursor: pointer;
}

.form-collapsed::after {
    content: '▼ Click to edit parameters and regenerate';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: linear-gradient(to bottom, rgba(255,255,255,0), rgba(255,255,255,0.95) 20%, white 100%);
    padding: 1.5rem 1rem 1rem;
    text-align: center;
    color: #2563eb;
    font-weight: 700;
    font-size: 1rem;
    pointer-events: none;
}

.form-collapsed:hover {
    box-shadow: 0 8px 30px rgba(37, 99, 235, 0.25);
}

.form-group label { 
    display: block; 
    margin-bottom: 0.75rem; 
    font-weight: 700; 
    color: #2d3748; 
    font-size: 1.1rem;
}

.required::after { 
    content: ' *'; 
    color: #dc2626; 
}

select { 
    width: 100%; 
    padding: 1rem; 
    border: 2px solid #e2e8f0; 
    border-radius: 12px; 
    font-size: 1rem; 
    transition: all 0.3s ease; 
    background: white; 
    cursor: pointer;
    font-weight: 500;
}

select:focus { 
    outline: none; 
    border-color: #2563eb; 
    box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.15); 
    transform: scale(1.02);
}

select:disabled { 
    background: #f7fafc; 
    cursor: not-allowed; 
    opacity: 0.6;
}

.radio-group, .checkbox-group { 
    display: grid; 
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); 
    gap: 0.75rem; 
}

.radio-item, .checkbox-item { 
    display: flex; 
    align-items: center; 
    gap: 0.75rem; 
    padding: 1rem; 
    border: 2px solid #e2e8f0; 
    border-radius: 12px; 
    cursor: pointer; 
    transition: all 0.3s ease; 
    background: white;
    position: relative;
    overflow: hidden;
    will-change: transform;
    transform: translateZ(0);
}

.radio-item:hover, .checkbox-item:hover { 
    border-color: #2563eb; 
    background: #f0f9ff; 
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(37, 99, 235, 0.15);
}

.radio-item input, .checkbox-item input { 
    margin: 0; 
    cursor: pointer; 
    width: 18px;
    height: 18px;
    accent-color: #2563eb;
}

.radio-item label, .checkbox-item label { 
    cursor: pointer; 
    margin: 0; 
    font-weight: 600;
    color: #2d3748;
    flex: 1;
}

.radio-item input:checked + label,
.checkbox-item input:checked + label {
    color: #2563eb;
}

.radio-item:has(input:checked),
.checkbox-item:has(input:checked) {
    border-color: #2563eb;
    background: linear-gradient(135deg, #f0f9ff 0%, #e0f2fe 100%);
    box-shadow: 0 4px 15px rgba(37, 99, 235, 0.2);
}

.generate-btn { 
    background: linear-gradient(135deg, #2563eb 0%, #1d4ed8 100%); 
    color: white; 
    padding: 1.25rem 2rem; 
    border: none; 
    border-radius: 50px; 
    font-size: 1.2rem; 
    font-weight: 700; 
    cursor: pointer; 
    width: 100%; 
    transition: all 0.3s ease; 
    margin-top: 1rem;
    position: relative;
    overflow: hidden;
    will-change: transform;
}

.generate-btn::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.2), transparent);
    transition: left 0.5s;
}

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

.generate-btn:hover:not(:disabled) { 
    transform: translateY(-3px); 
    box-shadow: 0 20px 40px rgba(37, 99, 235, 0.4);
}

.generate-btn:hover:not(:disabled)::before {
    left: 100%;
}

.generate-btn:active::after {
    width: 300px;
    height: 300px;
}

.generate-btn:disabled { 
    opacity: 0.6; 
    cursor: not-allowed;
    transform: none;
}

/* Enhanced accessibility */
*:focus-visible {
    outline: 2px solid #2563eb;
    outline-offset: 2px;
}

.loading { 
    display: none; 
    text-align: center; 
    padding: 3rem; 
    background: white; 
    border-radius: 24px; 
    box-shadow: 0 20px 60px rgba(0,0,0,0.1);
    margin: 2rem 0;
}

.loading h3 { 
    color: #2563eb; 
    margin-bottom: 1rem; 
    font-size: 1.5rem;
}

.loading-spinner { 
    width: 60px; 
    height: 60px; 
    background: conic-gradient(from 0deg, #e2e8f0, #2563eb, #e2e8f0);
    border-radius: 50%; 
    animation: spin 1s linear infinite; 
    margin: 0 auto 1rem;
    position: relative;
}

.loading-spinner::before {
    content: '';
    position: absolute;
    top: 4px;
    left: 4px;
    right: 4px;
    bottom: 4px;
    background: white;
    border-radius: 50%;
}

@keyframes spin { 
    to { transform: rotate(360deg); } 
}

@keyframes progress {
    0% { background-position: -200% 0; }
    100% { background-position: 200% 0; }
}

#lesson-result { 
    display: none; 
    background: white; 
    border-radius: 24px; 
    padding: 3rem; 
    box-shadow: 0 20px 60px rgba(0,0,0,0.1);
    margin: 2rem 0;
    border: 1px solid rgba(37, 99, 235, 0.1);
}

.lesson-header { 
    border-bottom: 3px solid #2563eb; 
    padding-bottom: 1.5rem; 
    margin-bottom: 2rem; 
}

.lesson-header h2 { 
    font-size: clamp(1.5rem, 4vw, 2.5rem); 
    color: #2d3748; 
    margin-bottom: 1rem; 
    font-weight: 800;
}

.lesson-meta { 
    display: flex; 
    flex-wrap: wrap; 
    gap: 0.75rem; 
    font-size: 0.95rem; 
    color: #718096; 
}

.lesson-meta span { 
    background: #f8fafc; 
    padding: 0.5rem 1rem; 
    border-radius: 20px; 
    font-weight: 600;
    border: 1px solid #e2e8f0;
    color: #4a5568;
}

.lesson-section { 
    margin-bottom: 3rem; 
}

.lesson-section h3 { 
    font-size: 1.4rem; 
    color: #2563eb; 
    margin-bottom: 1rem; 
    border-left: 4px solid #2563eb; 
    padding-left: 1rem; 
    font-weight: 700;
    letter-spacing: -0.025em;
    line-height: 1.3;
}

.lesson-section ul { 
    margin-left: 2rem; 
}

.lesson-section li { 
    margin-bottom: 0.75rem; 
    line-height: 1.7;
}

.activity-card { 
    background: #f7fafc; 
    border-left: 4px solid #2563eb; 
    padding: 1.5rem; 
    margin-bottom: 1.5rem; 
    border-radius: 12px; 
    border: 1px solid rgba(37, 99, 235, 0.1);
}

.activity-card h4 { 
    color: #2d3748; 
    margin-bottom: 0.75rem; 
    font-size: 1.2rem; 
    font-weight: 700;
}

.activity-meta { 
    display: flex; 
    gap: 1rem; 
    margin-bottom: 1rem; 
    font-size: 0.9rem; 
    color: #718096; 
    flex-wrap: wrap;
}

.activity-meta span {
    background: white;
    padding: 0.25rem 0.75rem;
    border-radius: 12px;
    font-weight: 600;
}

.lesson-actions { 
    display: flex; 
    gap: 1rem; 
    flex-wrap: wrap; 
    margin-top: 2rem; 
    padding-top: 2rem; 
    border-top: 2px solid #e2e8f0; 
}

.action-btn { 
    flex: 1; 
    min-width: 150px; 
    padding: 1rem 1.5rem; 
    background: white; 
    border: 2px solid #2563eb; 
    color: #2563eb; 
    border-radius: 12px; 
    font-weight: 600; 
    cursor: pointer; 
    transition: all 0.3s ease; 
    text-decoration: none;
    text-align: center;
    display: inline-block;
}

.action-btn:hover { 
    background: #2563eb; 
    color: white; 
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(37, 99, 235, 0.3);
}

.back-link { 
    display: inline-block; 
    margin: 2rem 1rem; 
    color: #2563eb; 
    text-decoration: none; 
    font-weight: 600; 
    padding: 0.75rem 1.5rem;
    border-radius: 12px;
    background: white;
    box-shadow: 0 4px 15px rgba(0,0,0,0.1);
    transition: all 0.3s ease;
}

.back-link:hover { 
    text-decoration: none;
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(37, 99, 235, 0.2);
}

@media print { 
    .header, .back-link, .lesson-actions, .generate-btn { 
        display: none; 
    }
    .lesson-generator {
        box-shadow: none;
        border: none;
    }
}

/* Mobile Optimizations */
@media (max-width: 768px) {
    .container {
        padding: 1rem 0.5rem;
    }
    
    .lesson-generator {
        padding: 1.5rem;
        margin: 0 0.5rem 2rem;
    }
    
    .page-subhero h1 {
        font-size: 2.5rem;
        line-height: 1.2;
    }
    
    .lesson-section h3 {
        font-size: 1.25rem;
    }
    
    .radio-group, .checkbox-group { 
        grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); 
        gap: 0.5rem;
    }
    
    .radio-item, .checkbox-item {
        padding: 0.75rem;
        flex-direction: column;
        text-align: center;
        gap: 0.5rem;
    }
    
    .radio-item label, .checkbox-item label {
        font-size: 0.9rem;
    }
    
    .lesson-actions {
        flex-direction: column;
    }
    
    .action-btn {
        min-width: auto;
    }
}

@media (max-width: 480px) {
    .page-subhero {
        padding: 1.5rem 1rem;
    }
    
    .lesson-generator {
        padding: 1rem;
        margin: 0 0.25rem 1rem;
    }
    
    .radio-group, .checkbox-group { 
        grid-template-columns: 1fr 1fr; 
    }
    
    .lesson-meta {
        flex-direction: column;
        align-items: flex-start;
    }
    
    .activity-meta {
        flex-direction: column;
        gap: 0.5rem;
    }
    
    /* Mobile UX Improvements */
    .form-group input, 
    .form-group select, 
    .form-group textarea {
        font-size: 16px; /* Prevents zoom on iOS */
        min-height: 48px; /* Better touch targets */
    }
    
    .radio-item, 
    .checkbox-item {
        min-height: 56px;
        padding: 1rem;
    }
    
    .generate-btn {
        width: 100%;
        padding: 1.5rem;
        font-size: 1.1rem;
        min-height: 56px;
    }
    
    /* Better touch targets for form elements */
    input[type="radio"], 
    input[type="checkbox"] {
        width: 20px;
        height: 20px;
    }
    
    /* Improve lesson result display on mobile */
    .lesson-section {
        margin-bottom: 2rem;
        padding: 1.5rem;
    }
    
    .lesson-section h3 {
        font-size: 1.3rem;
        margin-bottom: 1rem;
    }
    
    .activity-card {
        margin-bottom: 1.5rem;
        padding: 1.5rem;
    }
    
    .lesson-actions {
        display: flex;
        flex-direction: column;
        gap: 1rem;
    }
    
    .action-btn {
        width: 100%;
        padding: 1rem;
        font-size: 1rem;
    }
}

/* Tablet: single breakpoint for container + form shell */
@media (min-width: 769px) and (max-width: 1024px) {
    .container {
        padding: 2rem 1.5rem;
    }
    .lesson-generator {
        padding: 2.25rem;
    }
}

/* Focus states for accessibility */
.radio-item:focus-within,
.checkbox-item:focus-within {
    outline: 2px solid #2563eb;
    outline-offset: 2px;
}

/* Loading animation improvements */
.loading p {
    color: #718096;
    font-size: 1.1rem;
}

/* Error states */
.error {
    background: #fef2f2;
    border: 1px solid #fecaca;
    color: #dc2626;
    padding: 1rem;
    border-radius: 12px;
    margin: 1rem 0;
}

/* Success states */
.success {
    background: var(--success-50);
    border: 1px solid var(--success-500);
    color: var(--success-700);
    padding: 1rem;
    border-radius: 12px;
    margin: 1rem 0;
    animation: slideInUp 0.5s ease;
}

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

/* Assessment and Differentiation Styling */
.assessment-content, .differentiation-content {
    margin-top: 1rem;
}

.assessment-item, .differentiation-item {
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    padding: 1.5rem;
    margin: 1rem 0;
    border-left: 4px solid #2563eb;
}

.assessment-item h4, .differentiation-item h4 {
    color: #1e40af;
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 0.75rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.rubric {
    background: white;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    padding: 1rem;
    margin-top: 0.75rem;
}

.rubric-item {
    padding: 0.5rem 0;
    border-bottom: 1px solid #f3f4f6;
}

.rubric-item:last-child {
    border-bottom: none;
}

.rubric-item strong {
    color: #1e40af;
    font-weight: 600;
    margin-right: 0.5rem;
}

/* PDF Modal Styles */
.pdf-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.8);
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.pdf-modal-content {
    background: white;
    border-radius: 12px;
    max-width: 90%;
    max-height: 90%;
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}

.pdf-modal-header {
    padding: 1rem 1.5rem;
    border-bottom: 1px solid #e2e8f0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #f8fafc;
    border-radius: 12px 12px 0 0;
}

.pdf-modal-header h3 {
    margin: 0;
    color: #1e293b;
    font-size: 1.25rem;
}

.pdf-modal-body {
    flex: 1;
    overflow: auto;
    padding: 1rem;
    background: #f8fafc;
}

.pdf-modal-footer {
    padding: 1rem 1.5rem;
    border-top: 1px solid #e2e8f0;
    display: flex;
    gap: 1rem;
    justify-content: flex-end;
    background: white;
    border-radius: 0 0 12px 12px;
}

.pdf-preview {
    max-width: 8.5in;
    margin: 0 auto;
    padding: 1in;
    background: white;
    box-shadow: 0 0 20px rgba(0,0,0,0.1);
    font-family: 'Times New Roman', serif;
    line-height: 1.6;
    color: #333;
    border-radius: 8px;
}

.pdf-preview .lesson-header {
    text-align: center;
    border-bottom: 2px solid #2563eb;
    padding-bottom: 1rem;
    margin-bottom: 2rem;
}

.pdf-preview .lesson-header h2 {
    color: #1e293b;
    margin-bottom: 0.5rem;
}

.pdf-preview .lesson-meta {
    display: flex;
    justify-content: center;
    gap: 1rem;
    flex-wrap: wrap;
    font-size: 0.9rem;
    color: #64748b;
}

.pdf-preview .lesson-section {
    page-break-inside: avoid;
    margin-bottom: 1.5rem;
}

.pdf-preview .lesson-section h3 {
    color: #1e293b;
    border-bottom: 1px solid #e2e8f0;
    padding-bottom: 0.5rem;
    margin-bottom: 1rem;
}

.pdf-preview .activity-card {
    page-break-inside: avoid;
    margin-bottom: 1rem;
    padding: 1rem;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    background: #f8fafc;
}

.pdf-preview .activity-card h4 {
    color: #1e293b;
    margin-bottom: 0.5rem;
}

.pdf-preview .activity-meta {
    display: flex;
    gap: 1rem;
    margin-bottom: 0.5rem;
    font-size: 0.9rem;
    color: #64748b;
}

.pdf-preview ul, .pdf-preview ol {
    margin: 0.5rem 0;
    padding-left: 1.5rem;
}

.pdf-preview li {
    margin-bottom: 0.25rem;
}

.close-pdf-modal {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: #666;
    padding: 0.25rem;
    border-radius: 4px;
    transition: all 0.2s ease;
}

.close-pdf-modal:hover {
    background: #f1f5f9;
    color: #1e293b;
}

.btn-secondary {
    background: #f1f5f9;
    border: 1px solid #cbd5e1;
    color: #475569;
    padding: 0.5rem 1rem;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 500;
    transition: all 0.2s ease;
}

.btn-secondary:hover {
    background: #e2e8f0;
    border-color: #94a3b8;
}

/* Page break controls */
.pdf-preview .page-break {
    page-break-before: always;
}

.pdf-preview .no-break {
    page-break-inside: avoid;
}

/* Mobile responsive */
@media (max-width: 768px) {
    .pdf-modal-content {
        max-width: 95%;
        max-height: 95%;
    }
    
    .pdf-preview {
        padding: 0.5in;
        font-size: 0.9rem;
    }
    
    .pdf-modal-footer {
        flex-direction: column;
        gap: 0.5rem;
    }
    
    .pdf-modal-footer button {
        width: 100%;
    }
}

/* Loading panel (enhanced generation state) */
.loading-panel {
    text-align: center;
    padding: var(--space-8);
}

.loading-panel__spinner {
    width: 3.75rem;
    height: 3.75rem;
    border: 4px solid var(--gray-200);
    border-top-color: var(--primary-600);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto var(--space-4);
}

.loading-panel h3 {
    color: var(--color-text-primary);
    margin-bottom: var(--space-2);
    font-family: var(--font-display);
}

.loading-panel__elapsed {
    color: var(--color-text-tertiary);
    margin-bottom: var(--space-6);
}

.loading-panel__steps-wrap {
    background: var(--gray-50);
    border-radius: var(--radius-lg);
    padding: var(--space-4);
    margin: var(--space-4) 0;
    border-left: 4px solid var(--primary-600);
    text-align: left;
}

.loading-panel__steps-title {
    font-weight: var(--font-semibold);
    color: var(--color-text-primary);
    margin-bottom: var(--space-2);
}

.loading-panel__steps {
    color: var(--color-text-secondary);
    font-size: var(--text-sm);
}

.loading-panel__bar {
    background: linear-gradient(90deg, var(--gray-200) 0%, var(--primary-600) 50%, var(--gray-200) 100%);
    background-size: 200% 100%;
    height: 4px;
    border-radius: var(--radius-sm);
    margin: var(--space-4) 0;
    animation: progress 2s linear infinite;
}

.loading-panel__cancel {
    margin-top: var(--space-4);
    padding: var(--space-3) var(--space-6);
    background: var(--error-50);
    border: 2px solid var(--error-200);
    color: var(--error-700);
    border-radius: var(--radius-lg);
    font-weight: var(--font-semibold);
    cursor: pointer;
    font-size: var(--text-base);
    font-family: var(--font-body);
    transition: background var(--transition-fast);
}

.loading-panel__cancel:hover {
    background: var(--error-100);
}

.field-invalid {
    border-color: var(--error-500) !important;
}

.field-focused {
    border-color: var(--primary-600);
}
