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

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    margin: 0;
    padding: 0;
    display: flex;
}

/* Sidebar Styles */
.sidebar {
    width: 250px;
    background: white;
    height: 100vh;
    display: flex;
    flex-direction: column;
    box-shadow: 2px 0 10px rgba(0, 0, 0, 0.1);
    transition: all 0.3s ease;
    z-index: 1000;
    position: fixed;
    left: 0;
    top: 0;
}

.sidebar.collapsed {
    width: 70px;
}

.sidebar.collapsed .nav-text,
.sidebar.collapsed .sidebar-footer p,
.sidebar.collapsed .sidebar-header h2 {
    display: none;
}

.sidebar.collapsed .nav-item {
    justify-content: center;
    padding: 15px;
}

.sidebar.collapsed .toggle-icon {
    transform: rotate(180deg);
}

.sidebar-header {
    padding: 20px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.sidebar-header h2 {
    font-size: 1.5em;
    margin: 0;
    transition: opacity 0.3s;
}

.sidebar-toggle {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    font-size: 1.2em;
    cursor: pointer;
    padding: 5px 10px;
    border-radius: 4px;
    transition: all 0.3s;
}

.sidebar-toggle:hover {
    background: rgba(255, 255, 255, 0.3);
}

.toggle-icon {
    display: inline-block;
    transition: transform 0.3s;
}

.sidebar-nav {
    flex: 1;
    padding: 20px 0;
    overflow-y: auto;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 15px;
    padding: 15px 20px;
    color: #333;
    text-decoration: none;
    transition: all 0.3s;
    border-left: 4px solid transparent;
}

.nav-item:hover:not(.disabled) {
    background: #f0f4ff;
    border-left-color: #667eea;
}

.nav-item.active {
    background: #e7f3ff;
    border-left-color: #667eea;
    color: #667eea;
    font-weight: 600;
}

.nav-item.disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.nav-icon {
    font-size: 1.5em;
    min-width: 30px;
    text-align: center;
}

.nav-text {
    font-size: 1em;
    white-space: nowrap;
    transition: opacity 0.3s;
}

.sidebar-footer {
    padding: 20px;
    border-top: 1px solid #e0e0e0;
    text-align: center;
    color: #666;
    font-size: 0.85em;
    transition: opacity 0.3s;
}

/* Mobile Menu Button */
.mobile-menu-btn {
    display: none;
    position: fixed;
    top: 15px;
    left: 15px;
    font-size: 1.5em;
    color: white;
    background: #667eea;
    width: 45px;
    height: 45px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    z-index: 999;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
    transition: all 0.3s;
}

.mobile-menu-btn:hover {
    background: #5568d3;
    transform: scale(1.05);
}

/* Main Content */
.main-content {
    margin-left: 250px;
    flex: 1;
    height: 100vh;
    overflow-y: auto;
    transition: margin-left 0.3s ease;
}

.main-content.sidebar-collapsed {
    margin-left: 70px;
}

.container {
    height: 100vh;
    display: flex;
    flex-direction: column;
    animation: fadeIn 0.5s ease;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

header {
    text-align: center;
    padding: 4px;
    flex-shrink: 0;
    background: white;
    border-bottom: 2px solid #f0f0f0;
    height: 50px;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.passage-info-compact {
    padding: 4px 15px;
    background: #d4edda;
    text-align: center;
    font-size: 0.75em;
    color: #155724;
    border-bottom: 1px solid #c3e6cb;
    animation: slideDown 0.3s ease;
}

@keyframes slideDown {
    from { 
        opacity: 0;
        max-height: 0;
        padding: 0 15px;
    }
    to { 
        opacity: 1;
        max-height: 30px;
        padding: 4px 15px;
    }
}

h1 {
    color: #333;
    font-size: 1em;
    margin: 0;
    line-height: 1.2;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.subtitle {
    color: #666;
    font-size: 0.7em;
    margin: 0;
    line-height: 1.2;
}

.stats-bar {
    display: flex;
    justify-content: space-around;
    background: #f8f9fa;
    padding: 3px 10px;
    flex-wrap: wrap;
    gap: 6px;
    flex-shrink: 0;
    border-bottom: 2px solid #e0e0e0;
    min-height: 30px;
}

.stat {
    text-align: center;
    font-size: 0.85em;
}

.label {
    display: block;
    color: #666;
    font-size: 0.7em;
    margin-bottom: 1px;
}

.value {
    font-size: 1em;
    font-weight: bold;
    color: #667eea;
    transition: all 0.3s ease;
}

.value.warning {
    color: #dc3545;
    animation: pulse 1s ease infinite;
}

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

.limit {
    color: #999;
    font-size: 0.95em;
}

.test-area {
    display: flex;
    flex-direction: column;
    gap: 8px;
    flex: 1;
    overflow: hidden;
    padding: 8px;
}

.passage-section {
    background: #f8f9fa;
    padding: 8px;
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-height: 0;
    flex: 0 0 auto;
    max-height: 25%;
}

.typing-section {
    background: #f8f9fa;
    padding: 8px;
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    flex: 1;
    min-height: 250px;
}

h3 {
    color: #333;
    margin: 0 0 5px 0;
    font-size: 0.8em;
    flex-shrink: 0;
}

.passage {
    font-size: 14pt;
    line-height: 1.3;
    color: #333;
    font-family: 'Times New Roman', Times, serif;
    white-space: pre-wrap;
    word-break: normal;
    overflow-wrap: break-word;
    hyphens: manual;
    overflow-y: auto;
    flex: 1;
    padding-right: 10px;
    tab-size: 5;
}

.passage .correct {
    background-color: #d4edda;
    color: #155724;
}

.passage .incorrect {
    background-color: #f8d7da;
    color: #721c24;
    text-decoration: underline wavy red;
}

.passage .current {
    background-color: #fff3cd;
}

#typingArea {
    width: 100%;
    flex: 1;
    height: 100%;
    font-size: 14pt;
    line-height: 1.3;
    padding: 15px;
    border: 2px solid #ddd;
    border-radius: 6px;
    font-family: 'Times New Roman', Times, serif;
    resize: none;
    overflow-y: auto;
    word-break: normal;
    overflow-wrap: break-word;
    hyphens: manual;
}

#typingArea:focus {
    outline: none;
    border-color: #667eea;
}

#typingArea:disabled {
    background-color: #e9ecef;
    cursor: not-allowed;
}

.controls {
    display: flex;
    justify-content: center;
    gap: 10px;
    padding: 6px;
    background: white;
    border-top: 2px solid #f0f0f0;
    flex-shrink: 0;
}

.btn {
    padding: 6px 14px;
    font-size: 0.9em;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.3s;
    font-weight: 600;
}

.btn-primary {
    background: #667eea;
    color: white;
}

.btn-primary:hover {
    background: #5568d3;
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(102, 126, 234, 0.4);
}

.btn-secondary {
    background: #6c757d;
    color: white;
}

.btn-secondary:hover {
    background: #5a6268;
}

.btn-success {
    background: #28a745;
    color: white;
}

.btn-success:hover {
    background: #218838;
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(40, 167, 69, 0.4);
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none !important;
}

.results {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 20px;
}

.results-content {
    background: white;
    padding: 30px;
    border-radius: 12px;
    max-width: 600px;
    max-height: 90vh;
    overflow-y: auto;
    text-align: center;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
    position: relative;
}

.close-modal-btn {
    position: absolute;
    top: 15px;
    right: 15px;
    background: transparent;
    border: none;
    font-size: 2em;
    color: #999;
    cursor: pointer;
    line-height: 1;
    padding: 0;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s;
    border-radius: 4px;
}

.close-modal-btn:hover {
    color: #333;
    background: #f0f0f0;
}

.results-content h2 {
    color: #333;
    margin: 0 0 20px 0;
}

.result-status {
    font-size: 2em;
    font-weight: bold;
    margin-bottom: 20px;
    padding: 20px;
    border-radius: 8px;
}

.result-status.pass {
    background: #d4edda;
    color: #155724;
}

.result-status.fail {
    background: #f8d7da;
    color: #721c24;
}

.result-details {
    text-align: left;
    background: white;
    padding: 20px;
    border-radius: 6px;
    line-height: 2;
}

.result-details p {
    margin-bottom: 10px;
    font-size: 1.1em;
}

.result-details strong {
    color: #667eea;
}

.hidden {
    display: none;
}

/* Toggle Switch Styles */
.mode-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
}

.toggle-label {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    user-select: none;
}

.toggle-label input[type="checkbox"] {
    display: none;
}

.toggle-slider {
    position: relative;
    width: 50px;
    height: 26px;
    background: #ccc;
    border-radius: 13px;
    transition: background 0.3s;
}

.toggle-slider::before {
    content: '';
    position: absolute;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: white;
    top: 3px;
    left: 3px;
    transition: transform 0.3s;
}

.toggle-label input[type="checkbox"]:checked + .toggle-slider {
    background: #667eea;
}

.toggle-label input[type="checkbox"]:checked + .toggle-slider::before {
    transform: translateX(24px);
}

.toggle-text {
    font-size: 0.75em;
    color: #333;
    font-weight: 500;
}

/* Typing area in exam mode */
.typing-section.exam-mode #typingArea {
    border-color: #28a745;
    background: #f0fff4;
}

/* Error highlighting in typing area after submission */
.typing-area-highlight {
    font-size: 14pt;
    line-height: 1.3;
    padding: 15px;
    font-family: 'Times New Roman', Times, serif;
    white-space: pre-wrap;
    word-break: normal;
    overflow-wrap: break-word;
    hyphens: manual;
    overflow-y: auto;
    flex: 1;
}

.typing-area-highlight .error-char {
    background-color: #f8d7da;
    color: #721c24;
    text-decoration: underline wavy red;
}

.typing-area-highlight .correct-char {
    color: #333;
}

/* Mobile Responsive */
@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
        width: 250px;
    }
    
    .sidebar.open {
        transform: translateX(0);
    }
    
    .sidebar.collapsed {
        width: 250px;
    }
    
    .sidebar-toggle {
        display: none;
    }
    
    .mobile-menu-btn {
        display: block;
    }
    
    .main-content {
        margin-left: 0;
    }
    
    .main-content.sidebar-collapsed {
        margin-left: 0;
    }
}
