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

/* ========================================
   CODE PLAYGROUND
   ======================================== */
.code-playground {
    background: #f8fafc;
    border: 1px solid #dbe2ea;
    border-radius: 12px;
    margin: 1.25rem 0;
    overflow: hidden;
    box-shadow: 0 1px 3px rgba(15, 23, 42, 0.08);
}

.playground-header {
    background: #e8edf5;
    color: #374151;
    padding: 10px 14px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: 600;
    font-size: 0.875rem;
    border-bottom: 1px solid #d6dee8;
}

.playground-header i {
    margin-right: 8px;
    color: #22c55e;
}

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

.playground-btn {
    background: transparent;
    border: none;
    color: #6b7280;
    padding: 4px 6px;
    border-radius: 6px;
    font-size: 0.8rem;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 6px;
    font-weight: 500;
}

.playground-btn:hover {
    color: #4b5563;
    background: rgba(255, 255, 255, 0.55);
    transform: none;
}

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

.playground-btn.run-btn {
    background: #14b8a6;
    border: 1px solid #14b8a6;
    color: white;
    padding: 6px 14px;
    border-radius: 8px;
    margin-left: 10px;
    font-weight: 600;
}

.playground-btn.run-btn:hover {
    background: #0ea5a4;
    border-color: #0ea5a4;
    color: #ffffff;
}

.playground-btn.copy-btn {
    background: transparent;
    color: #6b7280;
}

.playground-btn.copy-btn:hover {
    background: rgba(255, 255, 255, 0.55);
    color: #4b5563;
}

.playground-editor {
    position: relative;
}

.playground-code {
    font-family: 'SF Mono', Monaco, 'Cascadia Code', 'Roboto Mono', monospace;
    font-size: 14px;
    line-height: 1.6;
    padding: 14px 14px 12px;
    margin: 0;
    background: #f3f4f6 !important;
    color: #1f2937 !important;
    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-editor::after {
    content: '⚡ Runs instantly in your browser';
    display: block;
    text-align: right;
    color: #6b7280;
    font-size: 0.78rem;
    padding: 8px 12px 10px;
    background: #f8fafc;
    border-top: 1px solid #e5e7eb;
}

.playground-output {
    background: #f8fafc;
    color: #1f2937;
    padding: 28px 12px 12px;
    font-family: 'SF Mono', Monaco, monospace;
    font-size: 13px;
    line-height: 1.6;
    border-top: 1px solid #e5e7eb;
    border-bottom: 1px solid #e5e7eb;
    max-height: 300px;
    overflow-y: auto;
    white-space: pre-wrap;
    word-wrap: break-word;
    overflow-wrap: break-word;
    position: relative;
}

.playground-output::before {
    content: 'OUTPUT';
    position: absolute;
    top: 8px;
    left: 12px;
    font-family: 'Poppins', sans-serif;
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    color: #0d9488;
}

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

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

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

/* Force light background for code editor in dark mode */
[data-theme="dark"] .playground-code {
    background: #1f2937 !important;
    color: #f1f5f9 !important;
}

[data-theme="dark"] .code-playground {
    background: #243347;
    border-color: #334155;
}

[data-theme="dark"] .playground-header {
    background: #2f4158;
    border-bottom-color: #3f556d;
    color: #e5e7eb;
}

[data-theme="dark"] .playground-btn,
[data-theme="dark"] .playground-btn.copy-btn,
[data-theme="dark"] .playground-btn.reset-btn {
    color: #c6d2db;
}

[data-theme="dark"] .playground-btn:hover,
[data-theme="dark"] .playground-btn.copy-btn:hover,
[data-theme="dark"] .playground-btn.reset-btn:hover {
    background: rgba(82, 109, 130, 0.35);
    color: #dde6ed;
}

[data-theme="dark"] .playground-btn.run-btn {
    background: #14b8a6;
    border-color: #14b8a6;
    color: #ffffff;
}

[data-theme="dark"] .playground-editor::after {
    background: #243347;
    border-top-color: #3f556d;
    color: #9ca3af;
}

[data-theme="dark"] .playground-output {
    background: #243347;
    color: #f1f5f9;
    border-top-color: #3f556d;
    border-bottom-color: #3f556d;
}

[data-theme="dark"] .playground-output::before {
    color: #2dd4bf;
}

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

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

/* Mobile responsive code playground */
@media (max-width: 768px) {
    .code-playground {
        margin: 1rem 0;
        border-radius: 8px;
    }
    
    .playground-header {
        padding: 8px 10px;
        font-size: 0.8rem;
        flex-wrap: wrap;
    }
    
    .playground-header span {
        font-size: 0.8rem;
    }
    
    .playground-actions {
        gap: 6px;
    }
    
    .playground-btn {
        padding: 3px 5px;
        font-size: 0.75rem;
        gap: 4px;
    }
    
    .playground-btn.run-btn {
        padding: 5px 10px;
        font-size: 0.8rem;
        margin-left: 6px;
    }
    
    .playground-code {
        font-size: 13px;
        padding: 10px;
        line-height: 1.5;
    }
    
    .playground-editor::after {
        font-size: 0.7rem;
        padding: 6px 10px 8px;
    }
    
    .playground-output {
        font-size: 12px;
        padding: 24px 10px 10px;
        max-height: 250px;
    }
    
    .playground-output::before {
        font-size: 0.7rem;
        top: 6px;
        left: 10px;
    }
}

.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);
}

/* ========================================
   FORCE LIGHT CODE BLOCKS (HIGHEST PRIORITY)
   ======================================== */
.playground-code,
textarea.playground-code,
.code-playground .playground-code,
[data-theme="dark"] .playground-code,
[data-theme="dark"] textarea.playground-code,
[data-theme="dark"] .code-playground .playground-code {
    background: #f6f8fa !important;
    color: #24292e !important;
}

.markdown-content pre,
.markdown-body pre,
[data-theme="dark"] .markdown-content pre,
[data-theme="dark"] .markdown-body pre {
    background: #f6f8fa !important;
    border: 1px solid #e1e4e8 !important;
}

.markdown-content pre code,
.markdown-body pre code,
[data-theme="dark"] .markdown-content pre code,
[data-theme="dark"] .markdown-body pre code {
    color: #24292e !important;
    background: transparent !important;
}
