/**
 * Interactive Reader Features
 * Inspired by educative.io for enhanced learning experience
 */

/* ========================================
   CODE PLAYGROUND
   ======================================== */
.code-playground {
    background: var(--color-surface, #ffffff);
    border: 2px solid var(--color-border, #e5e7eb);
    border-radius: 12px;
    margin: 2rem 0;
    overflow: hidden;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
}

.playground-header {
    background: linear-gradient(135deg, #4F46E5 0%, #7C3AED 100%);
    color: white;
    padding: 12px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: 600;
    font-size: 0.9rem;
}

.playground-header i {
    margin-right: 8px;
}

.playground-actions {
    display: flex;
    gap: 10px;
}

.playground-btn {
    background: rgba(255, 255, 255, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.3);
    color: white;
    padding: 6px 14px;
    border-radius: 6px;
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 6px;
}

.playground-btn:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: translateY(-1px);
}

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

.playground-btn.run-btn {
    background: #10B981;
    border-color: #059669;
}

.playground-btn.run-btn:hover {
    background: #059669;
}

.playground-btn.copy-btn {
    background: #3B82F6;
    border-color: #2563EB;
}

.playground-btn.copy-btn:hover {
    background: #2563EB;
}

.playground-editor {
    position: relative;
}

.playground-code {
    font-family: 'SF Mono', Monaco, 'Cascadia Code', 'Roboto Mono', monospace;
    font-size: 14px;
    line-height: 1.6;
    padding: 20px;
    margin: 0;
    background: #1E293B;
    color: #E2E8F0;
    border: none;
    resize: none;
    min-height: 100px;
    width: 100%;
    outline: none;
    overflow-y: auto;
    overflow-x: hidden;
    white-space: pre-wrap;
    word-wrap: break-word;
    overflow-wrap: break-word;
    box-sizing: border-box;
}

.playground-output {
    background: #0F172A;
    color: #CBD5E1;
    padding: 12px 20px;
    font-family: 'SF Mono', Monaco, monospace;
    font-size: 13px;
    line-height: 1.6;
    border-top: 2px solid var(--color-border, #334155);
    max-height: 300px;
    overflow-y: auto;
    white-space: pre-wrap;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.playground-output.hidden {
    display: none;
}

/* Ensure consistent spacing in both light and dark modes */
[data-theme="light"] .playground-output {
    padding: 12px 20px;
    line-height: 1.6;
}

[data-theme="dark"] .playground-output {
    padding: 12px 20px;
    line-height: 1.6;
}

.playground-output.success {
    border-left: 4px solid #10B981;
}

.playground-output.error {
    border-left: 4px solid #EF4444;
    color: #FCA5A5;
}

.playground-status {
    padding: 10px 20px;
    background: #F3F4F6;
    font-size: 0.85rem;
    color: #6B7280;
    display: flex;
    align-items: center;
    gap: 8px;
}

.playground-status.loading {
    background: #FEF3C7;
    color: #92400E;
}

.playground-status i {
    animation: spin 1s linear infinite;
}

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

/* ========================================
   INTERACTIVE EXERCISES
   ======================================== */
.interactive-exercise {
    background: linear-gradient(135deg, #F0F9FF 0%, #E0F2FE 100%);
    border: 2px solid #BAE6FD;
    border-radius: 12px;
    padding: 24px;
    margin: 2rem 0;
}

[data-theme="dark"] .interactive-exercise {
    background: linear-gradient(135deg, #1E293B 0%, #334155 100%);
    border-color: #475569;
}

.exercise-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 16px;
}

.exercise-icon {
    width: 40px;
    height: 40px;
    background: linear-gradient(135deg, #3B82F6 0%, #2563EB 100%);
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 1.2rem;
}

.exercise-title {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--color-text, #111827);
    margin: 0;
}

.exercise-question {
    font-size: 1rem;
    line-height: 1.7;
    color: var(--color-text-secondary, #374151);
    margin-bottom: 20px;
}

.exercise-options {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.exercise-option {
    background: white;
    border: 2px solid #E5E7EB;
    border-radius: 10px;
    padding: 16px 20px;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 0.95rem;
}

[data-theme="dark"] .exercise-option {
    background: #1E293B;
    border-color: #475569;
}

.exercise-option:hover {
    border-color: #3B82F6;
    background: #F0F9FF;
    transform: translateX(4px);
}

[data-theme="dark"] .exercise-option:hover {
    background: #334155;
}

.exercise-option.selected {
    border-color: #3B82F6;
    background: #DBEAFE;
}

[data-theme="dark"] .exercise-option.selected {
    background: #1E40AF;
}

.exercise-option.correct {
    border-color: #10B981;
    background: #D1FAE5;
}

[data-theme="dark"] .exercise-option.correct {
    background: #064E3B;
}

.exercise-option.incorrect {
    border-color: #EF4444;
    background: #FEE2E2;
}

[data-theme="dark"] .exercise-option.incorrect {
    background: #7F1D1D;
}

.option-indicator {
    width: 24px;
    height: 24px;
    border: 2px solid #D1D5DB;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
    flex-shrink: 0;
}

.exercise-option.correct .option-indicator {
    background: #10B981;
    border-color: #10B981;
    color: white;
}

.exercise-option.incorrect .option-indicator {
    background: #EF4444;
    border-color: #EF4444;
    color: white;
}

.exercise-feedback {
    margin-top: 16px;
    padding: 16px;
    border-radius: 8px;
    font-size: 0.9rem;
    line-height: 1.6;
    display: none;
}

.exercise-feedback.show {
    display: block;
}

.exercise-feedback.correct {
    background: #D1FAE5;
    color: #065F46;
    border-left: 4px solid #10B981;
}

[data-theme="dark"] .exercise-feedback.correct {
    background: #064E3B;
    color: #D1FAE5;
}

.exercise-feedback.incorrect {
    background: #FEE2E2;
    color: #991B1B;
    border-left: 4px solid #EF4444;
}

[data-theme="dark"] .exercise-feedback.incorrect {
    background: #7F1D1D;
    color: #FEE2E2;
}

/* ========================================
   COLLAPSIBLE SECTIONS
   ======================================== */
.collapsible-section {
    margin: 1.5rem 0;
    border: 1px solid var(--color-border, #e5e7eb);
    border-radius: 10px;
    overflow: hidden;
    background: var(--color-surface, #ffffff);
}

.collapsible-header {
    background: var(--color-bg-secondary, #F9FAFB);
    padding: 16px 20px;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: all 0.2s ease;
    user-select: none;
}

.collapsible-header:hover {
    background: var(--color-bg-tertiary, #F3F4F6);
}

.collapsible-title {
    font-weight: 600;
    font-size: 1rem;
    color: var(--color-text, #111827);
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 0;
}

.collapsible-icon {
    transition: transform 0.3s ease;
    color: var(--color-text-tertiary, #6B7280);
}

.collapsible-section.expanded .collapsible-icon {
    transform: rotate(90deg);
}

.collapsible-content {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease, padding 0.3s ease;
    padding: 0 20px;
}

.collapsible-section.expanded .collapsible-content {
    max-height: 2000px;
    padding: 20px;
}

/* ========================================
   PROGRESS TRACKING
   ======================================== */
.chapter-progress {
    position: sticky;
    top: 70px;
    background: var(--color-surface, #ffffff);
    border: 1px solid var(--color-border, #e5e7eb);
    border-radius: 10px;
    padding: 16px;
    margin-bottom: 20px;
    z-index: 10;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.progress-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}

.progress-title {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--color-text, #111827);
}

.progress-percentage {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--color-primary, #4F46E5);
}

.progress-bar-container {
    height: 8px;
    background: var(--color-bg-tertiary, #E5E7EB);
    border-radius: 4px;
    overflow: hidden;
}

.progress-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, #4F46E5 0%, #7C3AED 100%);
    border-radius: 4px;
    transition: width 0.5s ease;
}

/* ========================================
   FLIP CARDS (Quiz/Learning Cards)
   ======================================== */
.flip-card {
    perspective: 1000px;
    min-height: 200px;
    margin: 2rem 0;
}

.flip-card-inner {
    position: relative;
    width: 100%;
    height: 100%;
    min-height: 200px;
    transition: transform 0.6s;
    transform-style: preserve-3d;
}

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

.flip-card-front,
.flip-card-back {
    position: absolute;
    width: 100%;
    height: 100%;
    min-height: 200px;
    backface-visibility: hidden;
    border-radius: 12px;
    padding: 30px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.flip-card-front {
    background: linear-gradient(135deg, #667EEA 0%, #764BA2 100%);
    color: white;
}

.flip-card-back {
    background: linear-gradient(135deg, #F093FB 0%, #F5576C 100%);
    color: white;
    transform: rotateY(180deg);
}

.flip-card-content {
    font-size: 1.1rem;
    line-height: 1.6;
}

.flip-card-hint {
    margin-top: 20px;
    font-size: 0.85rem;
    opacity: 0.9;
}

/* ========================================
   HIGHLIGHT & NOTES
   ======================================== */
.highlighted-text {
    background: linear-gradient(120deg, #84FAB0 0%, #8FD3F4 100%);
    background: rgba(255, 235, 59, 0.3);
    padding: 2px 0;
    border-radius: 3px;
    cursor: pointer;
    position: relative;
}

[data-theme="dark"] .highlighted-text {
    background: rgba(255, 235, 59, 0.2);
}

.note-marker {
    position: absolute;
    top: -8px;
    right: -8px;
    width: 20px;
    height: 20px;
    background: #F59E0B;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.7rem;
    color: white;
    cursor: pointer;
}

.note-popup {
    position: absolute;
    background: white;
    border: 1px solid #E5E7EB;
    border-radius: 8px;
    padding: 12px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    z-index: 1000;
    max-width: 300px;
    font-size: 0.9rem;
}

[data-theme="dark"] .note-popup {
    background: #1E293B;
    border-color: #475569;
    color: #E2E8F0;
}

/* ========================================
   NAVIGATION CONTROLS
   ======================================== */
.chapter-navigation {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 20px;
    margin: 3rem 0 2rem;
    padding: 20px;
    background: var(--color-bg-secondary, #F9FAFB);
    border-radius: 12px;
}

.nav-chapter-btn {
    flex: 1;
    padding: 16px 24px;
    background: var(--color-primary, #4F46E5);
    color: white;
    border: none;
    border-radius: 10px;
    font-weight: 600;
    font-size: 0.95rem;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
}

.nav-chapter-btn:hover {
    background: var(--color-primary-dark, #4338CA);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(79, 70, 229, 0.3);
}

.nav-chapter-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.nav-chapter-btn.prev {
    flex-direction: row;
}

.nav-chapter-btn.next {
    flex-direction: row-reverse;
}

/* ========================================
   CODE ANNOTATIONS
   ======================================== */
.code-annotation {
    position: relative;
    display: inline-block;
}

.annotation-trigger {
    border-bottom: 2px dotted var(--color-primary, #4F46E5);
    cursor: help;
}

.annotation-tooltip {
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    background: #1F2937;
    color: white;
    padding: 10px 14px;
    border-radius: 8px;
    font-size: 0.85rem;
    white-space: nowrap;
    opacity: 0;
    visibility: hidden;
    transition: all 0.2s ease;
    margin-bottom: 8px;
    z-index: 100;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.annotation-tooltip::after {
    content: '';
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    border: 6px solid transparent;
    border-top-color: #1F2937;
}

.code-annotation:hover .annotation-tooltip {
    opacity: 1;
    visibility: visible;
}

/* ========================================
   RESPONSIVE DESIGN
   ======================================== */
@media (max-width: 768px) {
    .playground-code {
        font-size: 12px;
        padding: 15px;
    }
    
    .playground-output {
        padding: 15px;
        font-size: 12px;
    }
    
    .interactive-exercise {
        padding: 16px;
    }
    
    .chapter-navigation {
        flex-direction: column;
    }
    
    .nav-chapter-btn {
        width: 100%;
    }
    
    .flip-card-front,
    .flip-card-back {
        padding: 20px;
        font-size: 0.95rem;
    }
}

/* ========================================
   ANIMATIONS
   ======================================== */
@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.fade-in-up {
    animation: fadeInUp 0.5s ease forwards;
}

@keyframes pulse {
    0%, 100% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.05);
    }
}

.pulse {
    animation: pulse 2s ease-in-out infinite;
}

/* ========================================
   KEYBOARD SHORTCUTS INDICATOR
   ======================================== */
.keyboard-shortcuts {
    position: fixed;
    bottom: 20px;
    right: 20px;
    background: var(--color-surface, white);
    border: 1px solid var(--color-border, #e5e7eb);
    border-radius: 10px;
    padding: 12px 16px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    font-size: 0.85rem;
    z-index: 100;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
}

.keyboard-shortcuts.show {
    opacity: 1;
    visibility: visible;
}

.kbd {
    background: var(--color-bg-tertiary, #F3F4F6);
    border: 1px solid var(--color-border, #D1D5DB);
    border-radius: 4px;
    padding: 2px 8px;
    font-family: monospace;
    font-size: 0.8rem;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}
