:root {
    /* Light theme colors */
    --bg-primary: #f5f5f5;
    --bg-secondary: white;
    --bg-tertiary: #f8f9fa;
    --text-primary: #333;
    --text-secondary: #2c3e50;
    --border-color: #ddd;
    --border-light: #e1e5e9;
    --shadow-light: rgba(0,0,0,0.1);
    --shadow-medium: rgba(0,0,0,0.15);
    --accent-blue: #3498db;
    --accent-blue-hover: #2980b9;
    --accent-green: #27ae60;
    --accent-green-hover: #229954;
    --accent-gray: #95a5a6;
    --accent-gray-hover: #7f8c8d;
    --accent-purple: #9b59b6;
    --accent-purple-hover: #8e44ad;
}

[data-theme="dark"] {
    /* Dark theme colors */
    --bg-primary: #1a1a1a;
    --bg-secondary: #2d2d2d;
    --bg-tertiary: #333333;
    --text-primary: #e0e0e0;
    --text-secondary: #ffffff;
    --border-color: #444;
    --border-light: #555;
    --shadow-light: rgba(0,0,0,0.3);
    --shadow-medium: rgba(0,0,0,0.5);
    --accent-blue: #4a9eff;
    --accent-blue-hover: #357abd;
    --accent-green: #2ecc71;
    --accent-green-hover: #27ae60;
    --accent-gray: #95a5a6;
    --accent-gray-hover: #7f8c8d;
    --accent-purple: #a569bd;
    --accent-purple-hover: #9b59b6;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    transition: background-color 0.3s ease, color 0.3s ease;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 20px;
}

header {
    background: var(--bg-secondary);
    padding: 20px;
    border-radius: 8px;
    margin-bottom: 20px;
    box-shadow: 0 2px 4px var(--shadow-light);
    transition: all 0.3s ease;
}

header h1 {
    color: var(--text-secondary);
    margin-bottom: 15px;
}

.logo {
    height: 100px;
    margin-bottom: 15px;
}

.header-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 20px;
}

.search-container {
    display: flex;
    gap: 10px;
    flex: 1;
}

.theme-toggle {
    flex-shrink: 0;
}

.theme-toggle-btn {
    width: 50px;
    height: 50px;
    border: none;
    border-radius: 12px;
    background: var(--bg-tertiary);
    color: var(--text-primary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    box-shadow: 0 2px 8px var(--shadow-light);
}

.theme-toggle-btn:hover {
    background: var(--accent-blue);
    color: white;
    transform: scale(1.05);
}

.theme-icon {
    width: 20px;
    height: 20px;
}

#searchInput {
    flex: 1;
    padding: 12px 16px;
    border: 1px solid var(--border-light);
    border-radius: 12px;
    font-size: 14px;
    box-shadow: 0 2px 8px var(--shadow-light);
    transition: all 0.2s ease;
    background: var(--bg-secondary);
    color: var(--text-primary);
}

#searchInput:focus {
    outline: none;
    border-color: var(--accent-blue);
    box-shadow: 0 4px 12px rgba(52, 152, 219, 0.15);
}

#searchBtn {
    padding: 12px 16px;
    background: var(--accent-blue);
    color: white;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    font-size: 14px;
    box-shadow: 0 2px 8px rgba(52, 152, 219, 0.25);
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

#searchBtn:hover {
    background: var(--accent-blue-hover);
    box-shadow: 0 4px 12px rgba(52, 152, 219, 0.35);
    transform: translateY(-1px);
}

.search-icon {
    width: 18px;
    height: 18px;
}

.main-content {
    display: flex;
    gap: 20px;
    min-height: calc(100vh - 200px);
}

.sidebar {
    width: 300px;
    background: var(--bg-secondary);
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 2px 4px var(--shadow-light);
    max-height: calc(100vh - 200px);
    overflow-y: auto;
    position: sticky;
    top: 20px;
    transition: all 0.3s ease;
}

.sidebar h3 {
    margin-bottom: 15px;
    color: var(--text-secondary);
}

.question-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.question-item {
    padding: 12px;
    background: var(--bg-tertiary);
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s;
    color: var(--text-primary);
}

.question-item:hover {
    background: var(--border-color);
}

.question-item.active {
    background: var(--accent-blue);
    color: white;
}

.question-item h4 {
    font-size: 14px;
    margin-bottom: 5px;
}

.question-meta {
    display: flex;
    gap: 10px;
    font-size: 12px;
    opacity: 0.8;
}

.difficulty {
    padding: 2px 6px;
    border-radius: 3px;
    font-size: 11px;
}

.difficulty.Easy {
    background: #27ae60;
    color: white;
}

.difficulty.Medium {
    background: #f39c12;
    color: white;
}

.difficulty.Hard {
    background: #e74c3c;
    color: white;
}

.workspace {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.question-display {
    background: var(--bg-secondary);
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 2px 4px var(--shadow-light);
    min-height: 200px;
    resize: vertical; /* Allow vertical resizing */
    overflow: auto;
    position: relative;
    transition: all 0.3s ease;
    color: var(--text-primary);
}

.question-display h2 {
    color: var(--text-secondary);
    margin-bottom: 15px;
}

.question-display .placeholder {
    color: var(--text-primary);
    opacity: 0.6;
    text-align: center;
    padding: 40px;
}

.question-description {
    line-height: 1.6;
    margin-bottom: 15px;
}

.question-description pre {
    background: var(--bg-tertiary);
    padding: 10px;
    border-radius: 4px;
    overflow-x: auto;
    margin: 10px 0;
    color: var(--text-primary);
}

.editor-container {
    background: var(--bg-secondary);
    border-radius: 8px;
    box-shadow: 0 2px 4px var(--shadow-light);
    display: flex;
    flex-direction: column;
    min-height: 400px; /* Reasonable minimum */
    height: 500px; /* Set initial height */
    resize: vertical; /* Allow vertical resizing */
    position: relative;
    overflow: hidden; /* Prevent content from spilling out */
    transition: all 0.3s ease;
}

.editor-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 20px;
    background: var(--bg-tertiary);
    border-bottom: 1px solid var(--border-color);
    flex: 0 0 auto; /* Never grow or shrink */
    height: 60px; /* Fixed height */
}

.editor-header h3 {
    color: var(--text-secondary);
}

.editor-actions {
    display: flex;
    gap: 10px;
    flex-shrink: 0; /* Prevent buttons from shrinking */
}

.btn-run, .btn-run-app, .btn-solution {
    padding: 8px 16px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    white-space: nowrap; /* Prevent text wrapping */
    min-width: auto; /* Allow natural button width */
}

.btn-run {
    background: var(--accent-green);
    color: white;
}

.btn-run:hover {
    background: var(--accent-green-hover);
}

.btn-run-app {
    background: var(--accent-blue);
    color: white;
}

.btn-run-app:hover {
    background: var(--accent-blue-hover);
}

.btn-solution {
    background: var(--accent-purple);
    color: white;
}

.btn-solution:hover {
    background: var(--accent-purple-hover);
}

/* CodeMirror wrapper to fill remaining space */
.editor-wrapper {
    flex: 1;
    overflow: hidden;
    position: relative;
}

.CodeMirror {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    height: 100%;
    font-size: 14px;
}

/* Ensure CodeMirror's scroll container works properly */
.CodeMirror-scroll {
    height: 100%;
    overflow: auto !important;
}

.results-container {
    background: var(--bg-secondary);
    border-radius: 8px;
    box-shadow: 0 2px 4px var(--shadow-light);
    min-height: 200px;
    overflow: hidden;
    transition: all 0.3s ease;
}

.results-container h3 {
    background: var(--bg-tertiary);
    border-bottom: 1px solid var(--border-color);
    padding: 15px 20px;
    margin: 0 0 0 0;
    color: var(--text-secondary);
}

.results-content {
    background: var(--bg-secondary);
    padding: 20px;
    font-family: 'Courier New', 'Monaco', monospace;
}

.test-result {
    padding: 12px;
    margin-bottom: 12px;
    border-radius: 4px;
    border: 2px solid;
    background: #f8f9fa;
    font-family: 'Courier New', 'Monaco', monospace;
    font-size: 13px;
    position: relative;
}

.test-result.passed {
    border-color: #a8e6a3;
    box-shadow: 0 0 8px rgba(0, 255, 65, 0.1);
}

.test-result.passed::before {
    content: "✓ PASS";
    position: absolute;
    top: 8px;
    right: 12px;
    color: #ffffff;
    font-size: 11px;
    font-weight: bold;
    background: #00aa33;
    padding: 2px 6px;
    border-radius: 3px;
}

.test-result.failed {
    border-color: #f5a3a3;
    box-shadow: 0 0 8px rgba(255, 68, 68, 0.1);
}

.test-result.failed::before {
    content: "✗ FAIL";
    position: absolute;
    top: 8px;
    right: 12px;
    color: #ffffff;
    font-size: 11px;
    font-weight: bold;
    background: #cc3333;
    padding: 2px 6px;
    border-radius: 3px;
}

.test-result h4 {
    margin-bottom: 8px;
    color: #2c3e50;
    font-family: 'Courier New', 'Monaco', monospace;
    font-size: 13px;
    margin-right: 60px;
    font-weight: bold;
}

.test-detail {
    font-size: 12px;
    margin-top: 8px;
    color: #666666;
    font-family: 'Courier New', 'Monaco', monospace;
}

.test-detail pre {
    background: #f1f3f4;
    padding: 10px;
    border-radius: 3px;
    margin-top: 5px;
    word-wrap: break-word;
    white-space: pre-wrap;
    border: 1px solid #d1d5db;
    color: #374151;
    font-family: 'Courier New', 'Monaco', monospace;
    font-size: 11px;
    line-height: 1.4;
}

.summary {
    padding: 15px;
    background: #f8f9fa;
    border-radius: 4px;
    margin-bottom: 15px;
    text-align: center;
    border: 2px solid #d1d5db;
    font-family: 'Courier New', 'Monaco', monospace;
    text-transform: uppercase;
    letter-spacing: 1px;
    font-size: 13px;
    font-weight: bold;
}

.summary.success {
    background: #f0f9f0;
    color: #00aa33;
    border-color: #a8e6a3;
    box-shadow: 0 0 10px rgba(0, 255, 65, 0.1);
}

.summary.failure {
    background: #fef2f2;
    color: #cc3333;
    border-color: #f5a3a3;
    box-shadow: 0 0 10px rgba(255, 68, 68, 0.1);
}

/* Responsive design for smaller screens */
@media (max-width: 1200px) {
    .sidebar {
        width: 250px;
    }
}

@media (max-width: 768px) {
    .container {
        padding: 10px;
    }
    
    .main-content {
        flex-direction: column;
    }
    
    .sidebar {
        width: 100%;
        max-height: 200px;
        position: static;
    }
    
    .workspace {
        width: 100%;
    }
    
    /* Mobile-specific CodeMirror adjustments */
    .CodeMirror {
        font-size: 12px !important;
    }
    
    .CodeMirror-lines {
        padding: 8px !important;
    }
    
    /* Ensure code content wraps and doesn't overflow */
    .CodeMirror pre.CodeMirror-line,
    .CodeMirror pre.CodeMirror-line-like {
        word-wrap: break-word !important;
        white-space: pre-wrap !important;
        word-break: break-word !important;
    }
    
    /* Question description improvements */
    .question-description {
        font-size: 14px;
        overflow-x: auto;
    }
    
    .question-description pre {
        font-size: 12px;
        overflow-x: auto;
        white-space: pre-wrap;
        word-wrap: break-word;
    }
    
    /* Editor container adjustments */
    .editor-container {
        min-height: 300px;
        height: 400px;
    }
    
    /* Editor header - stack buttons on mobile */
    .editor-header {
        padding: 10px 15px;
        height: auto;
        min-height: 50px;
    }
    
    .editor-actions {
        flex-wrap: wrap;
        gap: 5px;
    }
    
    .btn-run, .btn-run-app, .btn-solution {
        padding: 6px 10px;
        font-size: 12px;
    }
    
    /* Results container improvements */
    .test-result pre {
        font-size: 11px;
        overflow-x: auto;
        white-space: pre-wrap;
        word-wrap: break-word;
    }
    
    /* Solution dialog mobile adjustments */
    .solution-dialog {
        width: 95vw !important;
        max-width: 95vw !important;
        height: 70vh !important;
        max-height: 70vh !important;
        left: 2.5vw !important;
        top: 15vh !important;
        transform: none !important;
    }
    
    .solution-code pre {
        font-size: 12px;
        white-space: pre-wrap;
        word-wrap: break-word;
    }
    
    /* Header controls - stack on mobile */
    .header-controls {
        flex-direction: column;
        gap: 10px;
    }
    
    .search-container {
        width: 100%;
    }
    
    /* Hide resize indicators on mobile */
    .question-display::after,
    .editor-container::after {
        display: none;
    }
}

/* Add visual resize handle indicator */
.question-display::after,
.editor-container::after {
    content: '⋮⋮⋮';
    position: absolute;
    bottom: 2px;
    right: 50%;
    transform: translateX(50%);
    color: #ccc;
    font-size: 12px;
    letter-spacing: 2px;
    cursor: ns-resize;
    user-select: none;
}

/* Smooth scrolling for the entire page */
html {
    scroll-behavior: smooth;
}

/* Add some padding at bottom for better visibility */
body {
    padding-bottom: 50px;
}

/* Floating Navigation Arrows */
.floating-nav {
    position: fixed;
    right: 20px;
    top: 50%;
    transform: translateY(-50%);
    display: flex;
    flex-direction: column;
    gap: 8px;
    z-index: 1000;
}

.nav-arrow {
    width: 50px;
    height: 50px;
    border: none;
    border-radius: 16px;
    background: var(--accent-blue);
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    font-weight: bold;
    box-shadow: 0 4px 12px var(--shadow-medium);
    transition: all 0.3s ease;
    backdrop-filter: blur(10px);
    border: 2px solid rgba(255, 255, 255, 0.2);
}

.nav-arrow:hover {
    background: var(--accent-blue-hover);
    transform: scale(1.1);
    box-shadow: 0 6px 20px var(--shadow-medium);
}

.nav-arrow:active {
    transform: scale(0.95);
}

.nav-icon {
    width: 18px;
    height: 18px;
    color: white;
}

/* Hide navigation on mobile devices */
@media (max-width: 768px) {
    .floating-nav {
        display: none;
    }
}

/* Adjust navigation position for smaller screens */
@media (max-width: 1200px) {
    .floating-nav {
        right: 15px;
    }
    
    .nav-arrow {
        width: 45px;
        height: 45px;
        border-radius: 14px;
    }
    
    .nav-icon {
        width: 16px;
        height: 16px;
    }
}

/* Countdown Timer */
.countdown-timer {
    position: fixed;
    top: 20px;
    right: 20px;
    background: var(--bg-secondary);
    border: 2px solid #66d480;
    border-radius: 12px;
    padding: 15px;
    box-shadow: 0 6px 20px var(--shadow-medium);
    z-index: 1001;
    backdrop-filter: blur(10px);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    min-width: 140px;
    transition: all 0.3s ease;
}

.timer-display {
    text-align: center;
}

#timerText {
    font-size: 24px;
    font-weight: bold;
    font-family: 'Orbitron', 'DS-Digital', 'Segment7Standard', 'Courier New', monospace;
    color: #00cc44;
    display: block;
    line-height: 1;
    letter-spacing: 2px;
    width: 80px;
    text-align: center;
    text-shadow: 0 0 6px rgba(0, 204, 68, 0.3);
}

.countdown-timer.warning #timerText {
    color: #cc7700;
    text-shadow: 0 0 6px rgba(204, 119, 0, 0.4);
}

.countdown-timer.danger #timerText {
    color: #cc3333;
    text-shadow: 0 0 8px rgba(204, 51, 51, 0.5);
    animation: pulse 1s infinite;
}

.countdown-timer.expired #timerText {
    color: #cc3333;
    text-shadow: 0 0 10px rgba(204, 51, 51, 0.6);
    animation: blink 0.5s infinite;
}

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

@keyframes blink {
    0%, 50% { opacity: 1; }
    51%, 100% { opacity: 0.3; }
}

.timer-controls {
    display: flex;
    gap: 8px;
}

.timer-btn {
    background: none;
    border: none;
    font-size: 16px;
    cursor: pointer;
    padding: 5px;
    border-radius: 6px;
    transition: background-color 0.2s;
    min-width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-primary);
}

.timer-btn:hover {
    background: var(--bg-tertiary);
}

.timer-btn:active {
    transform: scale(0.95);
}

.timer-control-icon {
    width: 24px;
    height: 24px;
}

/* Hide timer on mobile devices */
@media (max-width: 768px) {
    .countdown-timer {
        top: 10px;
        right: 10px;
        padding: 10px;
        min-width: 115px;
    }
    
    #timerText {
        font-size: 20px;
        letter-spacing: 1px;
        width: 65px;
    }
    
    .timer-btn {
        min-width: 25px;
        height: 25px;
    }
    
    .timer-control-icon {
        width: 20px;
        height: 20px;
    }
}

/* Adjust position when floating nav is present */
@media (min-width: 769px) {
    .countdown-timer {
        right: 90px; /* Leave space for floating navigation */
    }
}

/* App Output Styles */
.app-output-container {
    background: #ffffff;
    border-radius: 8px;
    overflow: hidden;
    font-family: 'Courier New', 'Monaco', monospace;
}

.app-output-header {
    background: #f0f9f0;
    padding: 12px 16px;
    font-size: 14px;
    font-weight: bold;
    color: #00aa33;
    border-bottom: 2px solid #a8e6a3;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.app-output-header.error {
    background: #fef2f2;
    color: #cc3333;
    border-bottom: 2px solid #f5a3a3;
}

.app-output {
    background: #1a1a1a;
    color: #00ff00;
    padding: 16px;
    margin: 0;
    font-size: 13px;
    line-height: 1.6;
    white-space: pre-wrap;
    word-wrap: break-word;
    border: none;
    font-family: 'Courier New', 'Monaco', monospace;
    text-shadow: 0 0 3px rgba(0, 255, 0, 0.3);
}

.app-return {
    background: #262626;
    color: #87CEEB;
    padding: 12px 16px;
    margin: 0;
    border-top: 1px solid #444;
    font-size: 13px;
    font-family: 'Courier New', 'Monaco', monospace;
}

.app-error {
    background: #1a1a1a;
    color: #ff4444;
    padding: 16px;
    margin: 0;
    font-size: 13px;
    line-height: 1.6;
    white-space: pre-wrap;
    word-wrap: break-word;
    font-family: 'Courier New', 'Monaco', monospace;
    text-shadow: 0 0 3px rgba(255, 68, 68, 0.3);
}

/* CodeMirror Autocomplete Styling */
.CodeMirror-hints {
    position: absolute;
    z-index: 10000;
    overflow: hidden;
    list-style: none;
    margin: 0;
    padding: 2px;
    background: #2d2d2d;
    border: 1px solid #444;
    border-radius: 4px;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
    font-size: 13px;
    font-family: 'Courier New', monospace;
    max-height: 200px;
    overflow-y: auto;
}

.CodeMirror-hint {
    margin: 0;
    padding: 4px 8px;
    color: #f8f8f2;
    cursor: pointer;
    white-space: pre;
    border-radius: 2px;
}

.CodeMirror-hint-active {
    background: #3498db;
    color: white;
}

/* Custom scrollbar for autocomplete dropdown */
.CodeMirror-hints::-webkit-scrollbar {
    width: 8px;
}

.CodeMirror-hints::-webkit-scrollbar-track {
    background: #1a1a1a;
}

.CodeMirror-hints::-webkit-scrollbar-thumb {
    background: #555;
    border-radius: 4px;
}

.CodeMirror-hints::-webkit-scrollbar-thumb:hover {
    background: #777;
}

/* Solution Dialog */
.solution-dialog {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 700px;
    height: 500px;
    min-width: 400px;
    min-height: 300px;
    max-width: 90vw;
    max-height: 80vh;
    background: var(--bg-secondary);
    border-radius: 12px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
    z-index: 1000;
    display: flex;
    flex-direction: column;
    resize: both;
    overflow: auto;
}

.dialog-header {
    padding: 15px 20px;
    background: var(--bg-tertiary);
    border-radius: 12px 12px 0 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: grab;
    user-select: none;
    border-bottom: 1px solid var(--border-color);
}

.dialog-header:active {
    cursor: grabbing;
}

.dialog-title {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-secondary);
}

.dialog-close {
    background: none;
    border: none;
    color: var(--text-primary);
    cursor: pointer;
    padding: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: background 0.2s;
}

.dialog-close:hover {
    background: var(--border-color);
}

.dialog-content {
    padding: 20px;
    overflow-y: auto;
    flex: 1;
    display: flex;
    flex-direction: column;
}

.solution-code {
    flex: 1;
    overflow: auto;
}

.solution-code pre {
    background: #1e1e1e;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 15px;
    overflow-x: auto;
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
    font-size: 14px;
    line-height: 1.6;
    white-space: pre;
    color: #d4d4d4;
    margin: 0;
}

.solution-code h4,
.solution-notes h4 {
    margin-bottom: 10px;
    color: var(--text-secondary);
    font-size: 16px;
}

.solution-notes {
    margin-top: 20px;
}

.solution-notes .notes-content {
    background: var(--bg-tertiary);
    border-left: 3px solid var(--accent-purple);
    padding: 15px;
    border-radius: 4px;
    line-height: 1.6;
}

/* Question Header with Copy Link Button */
.question-header-wrapper {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 10px;
}

.question-header-wrapper h2 {
    margin: 0;
}

.copy-link-btn {
    background: none;
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 8px;
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.copy-link-btn:hover {
    background: var(--bg-tertiary);
    border-color: var(--accent-purple);
    color: var(--accent-purple);
}

.copy-link-btn.copied {
    background: var(--accent-green);
    border-color: var(--accent-green);
    color: white;
}

.copy-link-btn svg {
    width: 20px;
    height: 20px;
}