/* AMC 12 Trainer - Styles */

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: #2563eb;
    color: #333;
    line-height: 1.6;
    padding-top: 80px; /* Space for fixed navbar */
    position: relative;
    overflow-x: hidden;
}

@media (max-width: 768px) {
    body {
        padding-top: 120px; /* More space for wrapped navbar on mobile */
    }
}

@media (max-width: 480px) {
    body {
        padding-top: 140px; /* Even more space for very small screens */
    }
}

/* Background learning objects for app */
.bg-objects {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 0;
    overflow: hidden;
}

.bg-object {
    position: absolute;
    font-size: 28px;
    opacity: 0.7;
    will-change: transform;
    touch-action: none;
    cursor: grab;
    filter: drop-shadow(0 4px 6px rgba(0, 0, 0, 0.35));
}

.bg-object.math::before { content: '📐'; }
.bg-object.lightbulb::before { content: '💡'; }
.bg-object.atom::before { content: '⚛️'; }
.bg-object.rocket::before { content: '🚀'; }
.bg-object.star::before { content: '⭐'; }

.app-container {
    max-width: 1600px;
    margin: 0 auto;
    padding: 20px;
    position: relative;
    z-index: 1;
}

/* Navbar Styles */
.navbar {
    background: #f5f5f5;
    padding: 15px 30px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 1000;
}

.navbar-left {
    display: flex;
    align-items: center;
    gap: 30px;
}

.navbar-brand a {
    font-size: 24px;
    font-weight: 700;
    color: #667eea;
    text-decoration: none;
    color: #667eea;
    position: relative;
    overflow: hidden;
}

.navbar-brand a::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    border-radius: 50%;
    background: rgba(102, 126, 234, 0.2);
    transform: translate(-50%, -50%);
    transition: width 0.6s, height 0.6s;
}

.navbar-brand a:active::before {
    width: 300px;
    height: 300px;
}

.navbar-brand a:hover {
    opacity: 0.8;
}

.navbar-links {
    display: flex;
    align-items: center;
    gap: 20px;
}

.navbar-links a {
    color: #555;
    text-decoration: none;
    font-weight: 500;
    padding: 8px 16px;
    border-radius: 5px;
    transition: all 0.3s;
    position: relative;
    overflow: hidden;
    background: rgba(102, 126, 234, 0.1);
}

.navbar-links a::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    border-radius: 50%;
    background: rgba(102, 126, 234, 0.3);
    transform: translate(-50%, -50%);
    transition: width 0.6s, height 0.6s;
}

.navbar-links a:active::before {
    width: 300px;
    height: 300px;
}

.navbar-links a:hover {
    background: rgba(102, 126, 234, 0.2);
    color: #667eea;
}

.navbar-links a:active {
    background: rgba(102, 126, 234, 0.3);
}

.navbar-right {
    display: flex;
    align-items: center;
    gap: 20px;
}

.navbar-right a {
    color: #555;
    text-decoration: none;
    font-weight: 500;
    padding: 8px 16px;
    border-radius: 5px;
    transition: all 0.3s;
    position: relative;
    overflow: hidden;
    background: rgba(102, 126, 234, 0.1);
}

.navbar-right a::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    border-radius: 50%;
    background: rgba(102, 126, 234, 0.3);
    transform: translate(-50%, -50%);
    transition: width 0.6s, height 0.6s;
}

.navbar-right a:active::before {
    width: 300px;
    height: 300px;
}

.navbar-right a:hover {
    background: rgba(102, 126, 234, 0.2);
    color: #667eea;
}

.navbar-right a:active {
    background: rgba(102, 126, 234, 0.3);
}

.navbar-user {
    color: #667eea;
    font-weight: 500;
    padding: 8px 16px;
    background: rgba(102, 126, 234, 0.1);
    border-radius: 5px;
}

/* Login Reminder */
.login-reminder {
    background: #fff3cd;
    border: 1px solid #ffc107;
    border-radius: 8px;
    padding: 15px;
    margin-bottom: 20px;
    text-align: center;
}

.login-reminder p {
    color: #856404;
    margin: 0;
}

.login-reminder a {
    color: #667eea;
    font-weight: 600;
    text-decoration: none;
}

.login-reminder a:hover {
    text-decoration: underline;
}

/* Header */
.app-header {
    text-align: center;
    margin-bottom: 30px;
    padding: 20px;
    background: white;
    border-radius: 10px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

.app-header h1 {
    color: #667eea;
    font-size: 36px;
    margin-bottom: 10px;
    font-weight: 700;
}

.subtitle {
    color: #666;
    font-size: 18px;
}

/* Main Content Layout */
.main-content {
    display: grid;
    grid-template-columns: 300px 1fr;
    gap: 20px;
    position: relative;
}

/* When guided mode is active, adjust layout */
.main-content.guided-mode-active {
    grid-template-columns: 300px 1fr 400px;
}

/* Left Panel */
.left-panel {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.panel-section {
    background: white;
    border-radius: 10px;
    padding: 20px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

.panel-section h3 {
    color: #333;
    font-size: 18px;
    margin-bottom: 15px;
    padding-bottom: 10px;
    border-bottom: 2px solid #e0e0e0;
}

/* Filters */
.filter-group {
    margin-bottom: 20px;
}

.filter-group label {
    display: block;
    margin-bottom: 8px;
    color: #555;
    font-weight: 500;
    font-size: 14px;
}

.filter-select {
    width: 100%;
    padding: 8px 12px;
    border: 2px solid #e0e0e0;
    border-radius: 5px;
    font-size: 14px;
    background: white;
    cursor: pointer;
}

.filter-select:focus {
    outline: none;
    border-color: #667eea;
}

.difficulty-checkboxes {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-bottom: 10px;
}

.difficulty-checkboxes label {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-weight: normal;
}

.difficulty-checkboxes input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
}

.difficulty-buttons {
    display: flex;
    gap: 10px;
}

.year-range {
    display: flex;
    align-items: center;
    gap: 10px;
}

.year-range input {
    flex: 1;
    padding: 8px 12px;
    border: 2px solid #e0e0e0;
    border-radius: 5px;
    font-size: 14px;
}

.year-range input:focus {
    outline: none;
    border-color: #667eea;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 10px;
    cursor: pointer;
    font-weight: normal;
}

.checkbox-label input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
}

/* Buttons */
.btn {
    padding: 12px 24px;
    border: none;
    border-radius: 8px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
    width: 100%;
    margin-bottom: 10px;
}

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

.btn-primary:hover {
    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: #10B981;
    color: white;
}

.btn-success:hover {
    background: #059669;
}

.btn-warning {
    background: #F59E0B;
    color: white;
}

.btn-warning:hover {
    background: #D97706;
}

.btn-outline {
    background: white;
    color: #667eea;
    border: 2px solid #667eea;
}

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

.btn-small {
    padding: 8px 16px;
    font-size: 14px;
    border-radius: 4px;
    cursor: pointer;
    margin-right: 5px;
    flex-shrink: 0;
    width: auto;
    min-width: auto;
}

.btn-small.btn-outline {
    border: 1px solid #667eea;
    background: transparent;
    color: #667eea;
}

.btn-small.btn-outline:hover {
    background: #667eea;
    color: white;
}

.btn-small:not(.btn-outline) {
    background: #667eea;
    color: white;
    border: none;
}

.btn-small:not(.btn-outline):hover {
    background: #5568d3;
}

.action-buttons {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

/* Session Stats */
.session-stats {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.stat-item {
    display: flex;
    justify-content: space-between;
    padding: 8px;
    background: #f8f9fa;
    border-radius: 5px;
}

.stat-label {
    font-weight: 500;
    color: #666;
}

/* Overall stats labels - white color */
.overall-stats .stat-label {
    color: white;
}

/* Right Panel */
.right-panel {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

/* Problem Info */
.problem-info {
    background: white;
    border-radius: 10px;
    padding: 20px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

.problem-header {
    margin-bottom: 10px;
    padding-bottom: 15px;
    border-bottom: 2px solid #e0e0e0;
}

.problem-meta {
    font-size: 18px;
    font-weight: 600;
    color: #333;
}

.problem-difficulty {
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
}

.difficulty-easy {
    background: #d4edda;
    color: #155724;
}

.difficulty-medium {
    background: #fff3cd;
    color: #856404;
}

.difficulty-hard {
    background: #f8d7da;
    color: #721c24;
}

.difficulty-very-hard {
    background: #e2d9f3;
    color: #6f42c1;
}

.problem-type-info {
    color: #666;
    font-size: 14px;
    margin-bottom: 10px;
}

.problem-link a {
    color: #667eea;
    text-decoration: none;
    font-size: 14px;
}

.problem-link a:hover {
    text-decoration: underline;
}

/* Problem Content */
.problem-content {
    background: white;
    border-radius: 10px;
    padding: 25px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    min-height: 200px;
    overflow: visible !important;
    overflow-x: auto;
    overflow-y: visible !important;
}

.problem-text {
    font-size: 18px;
    line-height: 1.8;
    color: #333;
}

/* LaTeX/MathJax styling */
.problem-text {
    text-align: left;
    line-height: 1.8;
    overflow: visible !important;
    overflow-x: auto;
    overflow-y: visible !important;
}

.problem-text .MathJax {
    font-size: 1.1em;
}

/* Force ALL MathJax in problem text to be inline - override display math */
.problem-text mjx-container {
    display: inline !important;
    margin: 0 !important;
    padding: 0 !important;
    width: auto !important;
    max-width: none !important;
    vertical-align: baseline !important;
}

/* Override display math in problem text to be inline */
.problem-text mjx-container[jax="CHTML"][display="true"],
.problem-text mjx-container[display="true"] {
    display: inline !important;
    text-align: left !important;
    margin: 0 !important;
    padding: 0 !important;
    width: auto !important;
    max-width: none !important;
    vertical-align: baseline !important;
}

/* Legacy MathJax 2.x support - force inline */
.problem-text .MathJax[display="true"],
.problem-text .MathJax-Display {
    display: inline !important;
    text-align: left !important;
    margin: 0 !important;
    padding: 0 !important;
    width: auto !important;
    max-width: none !important;
    vertical-align: baseline !important;
}

/* Inline math ($...$) - MUST stay inline */
.problem-text mjx-container[jax="CHTML"]:not([display="true"]) {
    display: inline !important;
    margin: 0 !important;
    padding: 0 2px !important;
    vertical-align: baseline !important;
    width: auto !important;
}

.problem-text .MathJax:not([display="true"]):not(.MathJax-Display) {
    display: inline !important;
    margin: 0 !important;
    padding: 0 !important;
    vertical-align: baseline !important;
}

/* Answer choice math blocks - rules moved to end to override general problem-text rules */

/* Multiple choice options - allow display math ($$...$$) for answer choices */
.answer-options mjx-container[display="true"],
.answer-options .MathJax-Display {
    display: block !important;
    text-align: center !important;
    margin: 0.5em auto !important;
    width: fit-content !important;
    max-width: 100% !important;
}

/* Inline math in answer options stays inline */
.answer-options mjx-container:not([display="true"]),
.answer-options .MathJax:not(.MathJax-Display) {
    display: inline !important;
    text-align: left !important;
    margin: 0 !important;
    padding: 0 !important;
    width: auto !important;
    max-width: none !important;
    vertical-align: baseline !important;
}

/* Prevent any MathJax from taking full width unless display math */
.problem-text mjx-container:not([display="true"]) {
    max-width: none !important;
    width: auto !important;
    display: inline !important;
}

/* Force ALL MathJax containers to be inline - override everything including display math */
.problem-text mjx-container,
.problem-text mjx-container[display="true"],
.problem-text > mjx-container,
.problem-text > mjx-container[display="true"],
.problem-text mjx-container[jax="CHTML"],
.problem-text mjx-container[jax="CHTML"][display="true"] {
    display: inline !important;
    margin: 0 !important;
    padding: 0 !important;
    width: auto !important;
    max-width: none !important;
    vertical-align: baseline !important;
    box-sizing: border-box;
    overflow: visible !important;
    text-align: left !important;
}

/* Answer choice math blocks (containing \text{(A)}, \text{(B)}, etc.) - allow display math */
/* These rules MUST come AFTER .problem-text rules to override inline forcing */
.problem-text .answer-choice-math mjx-container[display="true"],
.problem-text .answer-choice-math .MathJax-Display,
.problem-text .answer-choice-math mjx-container[jax="CHTML"][display="true"],
.answer-choice-math mjx-container[display="true"],
.answer-choice-math .MathJax-Display {
    display: block !important;
    text-align: center !important;
    margin: 0.5em auto !important;
    width: fit-content !important;
    max-width: 100% !important;
    vertical-align: baseline !important;
}

/* Override ALL inline rules for answer choice math - must be very specific and come last */
/* This rule MUST override all previous .problem-text mjx-container rules */
/* Using maximum specificity to ensure it wins */
.problem-text .answer-choice-math mjx-container,
.problem-text .answer-choice-math mjx-container[display="true"],
.problem-text .answer-choice-math mjx-container[jax="CHTML"],
.problem-text .answer-choice-math mjx-container[jax="CHTML"][display="true"],
.problem-text span.answer-choice-math mjx-container,
.problem-text span.answer-choice-math mjx-container[display="true"],
div.problem-text span.answer-choice-math mjx-container,
div.problem-text span.answer-choice-math mjx-container[display="true"] {
    display: block !important;
    text-align: center !important;
    margin: 0.5em auto !important;
    width: fit-content !important;
    max-width: 100% !important;
    vertical-align: baseline !important;
}

/* Also target the span itself to ensure proper centering */
.problem-text .answer-choice-math,
.problem-text span.answer-choice-math {
    display: block !important;
    text-align: center !important;
    margin: 0.5em auto !important;
    width: 100% !important;
}

/* FINAL OVERRIDE - These rules must be at the very end to ensure they win */
/* Maximum specificity for answer choice math blocks */
.problem-text .answer-choice-math mjx-container[display="true"],
.problem-text span.answer-choice-math mjx-container[display="true"],
div.problem-text .answer-choice-math mjx-container[display="true"],
div.problem-text span.answer-choice-math mjx-container[display="true"] {
    display: block !important;
    text-align: center !important;
    margin: 0.5em auto !important;
    width: fit-content !important;
    max-width: 100% !important;
}

/* Ensure MathJax SVG/CHTML elements are inline (but not in answer-choice-math) */
.problem-text mjx-container svg:not(.answer-choice-math svg),
.problem-text mjx-container mjx-math:not(.answer-choice-math mjx-math),
.problem-text mjx-container[display="true"] svg:not(.answer-choice-math mjx-container[display="true"] svg),
.problem-text mjx-container[display="true"] mjx-math:not(.answer-choice-math mjx-container[display="true"] mjx-math) {
    overflow: visible !important;
    display: inline !important;
    width: auto !important;
    max-width: none !important;
}

/* Answer choice math SVG/math elements should allow block display */
.problem-text .answer-choice-math mjx-container svg,
.problem-text .answer-choice-math mjx-container mjx-math {
    display: block !important;
    margin: 0 auto !important;
}

/* Make MathJax boxes (menclose) bigger */
.problem-text mjx-menclose mjx-box {
    padding: 0.4em 0.5em !important;
    border-width: 0.1em !important;
}

.problem-text mjx-menclose {
    margin: 0.2em 0.1em !important;
}

/* Asymptote image styling */
.asymptote-container {
    margin: 20px 0;
    text-align: center;
    padding: 10px;
    background: #f8f9fa;
    border-radius: 5px;
}

.asymptote-image {
    max-width: 100%;
    height: auto;
    display: block;
    margin: 0 auto;
    border: 1px solid #e0e0e0;
    border-radius: 4px;
    background: white;
}

/* Ensure LaTeX and Asymptote don't break layout */
.problem-text {
    overflow-x: auto;
    word-wrap: break-word;
}

.problem-text img {
    max-width: 100%;
    height: auto;
}

/* Styles for scraped AoPS wiki content */
.problem-text p {
    margin: 1em 0;
    text-align: center;
}

.problem-text img.latex {
    vertical-align: middle;
    display: inline-block;
}

.problem-text img.latexcenter {
    display: block;
    margin: 10px auto;
}

.problem-text a {
    color: #667eea;
    text-decoration: none;
}

.problem-text a:hover {
    text-decoration: underline;
}

/* Preserve AoPS wiki table styles */
.problem-text table {
    margin: 1em auto;
    border-collapse: collapse;
}

.problem-text table.wikitable {
    border: 1px solid #aaa;
    background: #f9f9f9;
}

.problem-text table.wikitable td,
.problem-text table.wikitable th {
    border: 1px solid #aaa;
    padding: 0.2em 0.4em;
}

/* Preserve any inline styles from scraped content - they are automatically preserved in HTML */

.loading-text {
    text-align: center;
    color: #666;
    padding: 20px;
    font-style: italic;
}

/* Answer Section */
.answer-section {
    background: white;
    border-radius: 10px;
    padding: 20px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

.answer-options {
    display: grid;
    gap: 12px;
    margin-bottom: 20px;
}

.answer-option {
    padding: 15px 20px;
    background: #f8f9fa;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s;
    font-size: 18px;
    font-weight: 600;
    text-align: center;
}

.answer-option:hover {
    border-color: #667eea;
    background: #f0f4ff;
}

.answer-option.selected {
    border-color: #667eea;
    background: #e6f2ff;
    color: #667eea;
}

.answer-option.correct {
    border-color: #28a745;
    background: #d4edda;
    color: #155724;
}

.answer-option.incorrect {
    border-color: #dc3545;
    background: #f8d7da;
    color: #721c24;
}

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

.answer-actions .btn {
    width: auto;
    flex: 1;
    min-width: 120px;
}

/* Feedback */
.feedback {
    padding: 15px;
    border-radius: 8px;
    margin-top: 15px;
    font-weight: 500;
}

.feedback.correct {
    background: #d4edda;
    color: #155724;
    border: 1px solid #c3e6cb;
}

.feedback.incorrect {
    background: #f8d7da;
    color: #721c24;
    border: 1px solid #f5c6cb;
}

/* Overall Stats */
.overall-stats {
    background: white;
    border-radius: 10px;
    padding: 20px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

.overall-stats h3 {
    color: #333;
    font-size: 18px;
    margin-bottom: 15px;
    padding-bottom: 10px;
    border-bottom: 2px solid #e0e0e0;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
    gap: 8px;
}

.stat-card {
    background: #667eea;
    color: white;
    padding: 16px 6px;
    border-radius: 6px;
    text-align: center;
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.3);
    white-space: nowrap;
    min-width: 0;
    overflow: hidden;
    min-height: 70px;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.stat-value {
    font-size: 20px;
    font-weight: 700;
    margin-bottom: 3px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.2;
}

.stat-label {
    font-size: 11px;
    opacity: 0.9;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.2;
}

/* Overall stats labels - explicitly white */
.overall-stats .stat-label {
    color: white !important;
}

/* Modals */
/* Info icon tooltip */
.info-icon {
    display: inline-block;
    width: 18px;
    height: 18px;
    line-height: 18px;
    text-align: center;
    border-radius: 50%;
    background-color: #667eea;
    color: white;
    font-size: 12px;
    font-weight: bold;
    cursor: help;
    position: relative;
    vertical-align: middle;
    font-style: normal;
}

.info-icon:hover {
    background-color: #5568d3;
}

.info-icon[title]:hover::after {
    content: attr(title);
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    padding: 8px 12px;
    background-color: #333;
    color: white;
    border-radius: 4px;
    font-size: 12px;
    white-space: normal;
    width: 250px;
    z-index: 1000;
    margin-bottom: 5px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
    pointer-events: none;
}

.info-icon[title]:hover::before {
    content: '';
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    border: 5px solid transparent;
    border-top-color: #333;
    margin-bottom: -5px;
    z-index: 1001;
}

.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgba(0, 0, 0, 0.5);
}

.modal-content {
    background-color: white;
    margin: 5% auto;
    padding: 30px;
    border-radius: 10px;
    width: 80%;
    max-width: 800px;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
}

.modal-content.large {
    max-width: 1200px;
}

.close {
    color: #aaa;
    float: right;
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
}

.close:hover {
    color: #000;
}

.modal h2 {
    color: #667eea;
    margin-bottom: 20px;
}

/* Statistics Tables */
.stats-overview {
    margin-bottom: 30px;
    padding: 20px;
    background: #f8f9fa;
    border-radius: 8px;
}

.stats-overview h3 {
    color: #333;
    margin-bottom: 15px;
}

.stats-overview p {
    margin: 8px 0;
    font-size: 16px;
}

.stats-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 15px;
}

.stats-table th,
.stats-table td {
    padding: 12px;
    text-align: left;
    border-bottom: 1px solid #e0e0e0;
}

.stats-table th {
    background: #f8f9fa;
    font-weight: 600;
    color: #333;
}

.stats-table th.sortable {
    cursor: pointer;
    user-select: none;
    position: relative;
    padding-right: 25px;
}

.stats-table th.sortable:hover {
    background: #e9ecef;
}

.stats-table .sort-indicator {
    position: absolute;
    right: 8px;
    color: #667eea;
    font-weight: bold;
}

.stats-table tr:hover {
    background: #f8f9fa;
}

.stats-table .clickable-category {
    color: #667eea;
    text-decoration: underline;
    cursor: pointer;
}

.stats-table .clickable-category:hover {
    color: #5568d3;
    background: #f0f2ff;
}

.mistakes-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 15px;
}

.mistakes-table th,
.mistakes-table td {
    padding: 12px;
    text-align: left;
    border-bottom: 1px solid #e0e0e0;
}

.mistakes-table th {
    background: #f8f9fa;
    font-weight: 600;
    color: #333;
}

.mistakes-table th.sortable {
    cursor: pointer;
    user-select: none;
    position: relative;
    padding-right: 25px;
}

.mistakes-table th.sortable:hover {
    background: #e9ecef;
}

.mistakes-table .sort-indicator {
    position: absolute;
    right: 8px;
    color: #667eea;
    font-weight: bold;
}

.mistakes-table tr:hover {
    background: #f8f9fa;
}

/* Mobile responsive wrapper for mistakes table */
.mistakes-table-wrapper {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

/* Responsive Design */
@media (max-width: 1200px) {
    .main-content {
        grid-template-columns: 250px 1fr;
    }
    
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 768px) {
    .main-content {
        grid-template-columns: 1fr;
    }
    
    .left-panel {
        order: 2;
    }
    
    .right-panel {
        order: 1;
    }
    
    .stats-grid {
        grid-template-columns: 1fr;
    }
    
    .answer-actions {
        flex-direction: column;
    }
    
    .answer-actions .btn {
        width: 100%;
    }
    
    .modal-content {
        width: 95%;
        margin: 10% auto;
        padding: 20px;
    }
    
    /* Make mistakes table scroll horizontally on mobile */
    .mistakes-table-wrapper {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        width: 100%;
    }
    
    .mistakes-table {
        min-width: 600px; /* Ensure table doesn't get too compressed */
    }
    
    .mistakes-table th,
    .mistakes-table td {
        padding: 8px;
        font-size: 14px;
    }
    
    /* Stack charts vertically on mobile */
    .charts-container {
        grid-template-columns: 1fr !important;
        gap: 30px !important;
    }
    
    .charts-container canvas {
        max-height: 250px !important;
    }
}

/* ============================================================================
   FINAL OVERRIDE RULES FOR ANSWER CHOICE MATH - MUST BE AT END OF FILE
   ============================================================================ */
/* Target mjx-container with display="true" that contains answer choices (A), (B), etc. */
/* MathJax might create containers outside the span, so we need to detect by content */
.problem-text mjx-container[display="true"]:has(mjx-mtext:has-text("(A)")),
.problem-text mjx-container[display="true"]:has(mjx-mtext:has-text("(B)")),
.problem-text mjx-container[display="true"]:has(mjx-mtext:has-text("(C)")),
.problem-text mjx-container[display="true"]:has(mjx-mtext:has-text("(D)")),
.problem-text mjx-container[display="true"]:has(mjx-mtext:has-text("(E)")),
.problem-text .answer-choice-math mjx-container[display="true"],
.problem-text span.answer-choice-math mjx-container[display="true"],
div.problem-text .answer-choice-math mjx-container[display="true"],
div.problem-text span.answer-choice-math mjx-container[display="true"],
.problem-text .answer-choice-math mjx-container,
.problem-text span.answer-choice-math mjx-container {
    display: block !important;
    text-align: center !important;
    margin: 0.5em auto !important;
    width: fit-content !important;
    max-width: 100% !important;
}

.problem-text .answer-choice-math,
.problem-text span.answer-choice-math {
    display: block !important;
    text-align: center !important;
    margin: 0.5em auto !important;
    width: 100% !important;
}

/* Problem Selector Modal Styles */
.problem-selector-form {
    padding: 20px 0;
}

.problem-selector-form .form-group {
    margin-bottom: 20px;
}

.problem-selector-form label {
    display: block;
    margin-bottom: 8px;
    font-weight: 600;
    color: #333;
}

.problem-selector-form input[type="number"],
.problem-selector-form select {
    width: 100%;
    padding: 10px;
    border: 2px solid #ddd;
    border-radius: 5px;
    font-size: 16px;
    transition: border-color 0.3s;
}

.problem-selector-form input[type="number"]:focus,
.problem-selector-form select:focus {
    outline: none;
    border-color: #4CAF50;
}

.problem-selector-form .form-group:last-of-type {
    display: flex;
    gap: 10px;
    margin-top: 30px;
}

.problem-selector-form .form-group:last-of-type button {
    flex: 1;
}

.error-message {
    background-color: #ffebee;
    color: #c62828;
    padding: 12px;
    border-radius: 5px;
    margin-top: 15px;
    border-left: 4px solid #c62828;
}

.success-message {
    background-color: #e8f5e9;
    color: #2e7d32;
    padding: 12px;
    border-radius: 5px;
    margin-top: 15px;
    border-left: 4px solid #2e7d32;
}

/* Report Issue Modal Styles */
#reportIssueModal .form-group {
    margin-bottom: 20px;
}

#reportIssueModal label {
    display: block;
    margin-bottom: 8px;
    font-weight: 600;
    color: #333;
}

#reportIssueModal .form-control {
    width: 100%;
    padding: 10px;
    border: 2px solid #ddd;
    border-radius: 5px;
    font-size: 16px;
    transition: border-color 0.3s;
    box-sizing: border-box;
}

#reportIssueModal .form-control:focus {
    outline: none;
    border-color: #667eea;
}

#reportIssueModal textarea.form-control {
    resize: vertical;
    min-height: 100px;
}

#reportIssueModal .checkbox-label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: normal;
    cursor: pointer;
}

#reportIssueModal .checkbox-label input[type="checkbox"] {
    width: auto;
    cursor: pointer;
}

#reportIssueModal .form-group:last-of-type {
    display: flex;
    gap: 10px;
    margin-top: 30px;
}

#reportIssueModal .form-group:last-of-type button {
    flex: 1;
}

/* Solution Modal Styles */
#solutionModal .modal-content {
    max-width: 90%;
    max-height: 90vh;
    overflow-y: auto;
}

#solutionContent {
    text-align: center;
    padding: 20px;
}

#solutionContent h2 {
    color: #333;
    padding-bottom: 10px;
    margin-top: 30px;
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    justify-content: center;
    border-bottom: none;
}

#solutionContent h2:first-child {
    margin-top: 0;
}

/* Solution container wrapper */
.solution-section {
    margin-bottom: 30px;
    padding-bottom: 20px;
    text-align: center;
}

.solution-section * {
    text-align: center;
}

.solution-section img.latex {
    text-align: center;
}

.solution-section:last-child {
    margin-bottom: 0;
}

/* Solution header with tags and report button */
.solution-header {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    margin-bottom: 15px;
    flex-wrap: wrap;
    padding-bottom: 10px;
    border-bottom: 2px solid #4CAF50;
    flex-direction: row;
}

.solution-header h2 {
    margin: 0 !important;
    border-bottom: none;
    padding: 0 !important;
    text-align: center;
    flex: 0 0 auto;
    line-height: 1.2;
    display: block;
}

.solution-tag {
    background: #4CAF50;
    color: white;
    padding: 4px 12px;
    border-radius: 12px;
    font-size: 0.75em;
    font-weight: 600;
    white-space: nowrap;
}

.solution-report-btn {
    background: #dc3545;
    color: white;
    border: none;
    padding: 6px 12px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.85em;
    white-space: nowrap;
    transition: background 0.3s;
    margin: 0 !important;
    line-height: 1.2;
    display: block;
    height: auto;
}

.solution-report-btn:hover {
    background: #c82333;
}

#solutionContent .solution-meta {
    font-size: 0.7em;
    font-weight: normal;
    color: #666;
    font-style: italic;
}

#solutionContent p {
    text-align: center !important;
    margin-bottom: 1em;
    line-height: 1.6;
}

#solutionContent img {
    /* Constrain width but preserve aspect ratio */
    max-width: 100% !important;
    /* CRITICAL: height: auto ensures aspect ratio is preserved when width is constrained */
    /* When max-width scales down the width, height: auto scales height proportionally */
    /* This prevents images from being stretched/dilated vertically */
    height: auto !important;
    display: block;
    margin: 10px auto;
}

/* LaTeX images should be inline-block with vertical-align: middle (same as problem-text) */
#solutionContent img.latex {
    display: inline-block !important;
    max-width: 100% !important;
    /* Preserve aspect ratio */
    height: auto !important;
    vertical-align: middle !important;
    /* Remove auto margins - they cause positioning issues with inline-block */
    margin: 0 !important;
}

#solutionContent img.latexcenter {
    display: block !important;
    margin: 10px auto !important;
    max-width: 100% !important;
    /* Preserve aspect ratio */
    height: auto !important;
}

/* Constrain figure elements containing images */
#solutionContent figure {
    max-width: 100%;
    margin: 1em auto;
    text-align: center;
}

#solutionContent figure img {
    max-width: 100% !important;
    /* Preserve aspect ratio */
    height: auto !important;
}

#solutionContent a {
    color: #007bff;
    text-decoration: none;
    cursor: default;
    pointer-events: none;
}

#solutionContent a:hover {
    text-decoration: none;
}

#solutionContent table.wikitable {
    border-collapse: collapse;
    margin: 1em auto;
    border: 1px solid #ddd;
}

#solutionContent table.wikitable td,
#solutionContent table.wikitable th {
    padding: 8px;
    border: 1px solid #ddd;
}

#solutionContent table.wikitable th {
    background-color: #f5f5f5;
    font-weight: bold;
}

/* Alternative: Target by assistive-mml content if :has() doesn't work */
/* Note: This selector may not work in all browsers, kept for future reference */

/* Exam - Center all text */
#examProblemText,
#examProblemText * {
    text-align: center !important;
}

/* Exam Review - Center all text */
#examReviewProblemText,
#examReviewProblemText * {
    text-align: center !important;
}

#examReviewSolution,
#examReviewSolution * {
    text-align: center !important;
}

#examReviewSolution .solution-section,
#examReviewSolution .solution-section * {
    text-align: center !important;
}

/* Mobile Responsive Navbar Styles */
@media (max-width: 768px) {
    .navbar {
        flex-wrap: wrap;
        padding: 15px 20px;
        height: auto;
        min-height: 80px;
    }
    
    .navbar-left {
        flex-wrap: wrap;
        gap: 15px;
        width: 100%;
        justify-content: space-between;
    }
    
    .navbar-brand a {
        font-size: 20px;
    }
    
    .navbar-links {
        flex-wrap: wrap;
        gap: 10px;
        width: 100%;
        justify-content: center;
    }
    
    .navbar-links a {
        padding: 6px 12px;
        font-size: 14px;
    }
    
    .navbar-right {
        flex-wrap: wrap;
        gap: 10px;
        width: 100%;
        justify-content: center;
    }
    
    .navbar-right a {
        padding: 6px 12px;
        font-size: 14px;
    }
    
    .navbar-user {
        padding: 6px 12px;
        font-size: 14px;
        width: 100%;
        text-align: center;
    }
}

@media (max-width: 480px) {
    .navbar {
        padding: 10px 15px;
        min-height: 100px;
    }
    
    .navbar-brand a {
        font-size: 18px;
    }
    
    .navbar-links {
        gap: 8px;
    }
    
    .navbar-links a {
        padding: 5px 10px;
        font-size: 13px;
    }
    
    .navbar-right {
        gap: 8px;
    }
    
    .navbar-right a {
        padding: 5px 10px;
        font-size: 13px;
    }
}

/* Guided Mode Chat Styles */
#guidedChatMessages {
    min-height: 300px;
    max-height: 500px;
}

#guidedChatMessages::-webkit-scrollbar {
    width: 8px;
}

#guidedChatMessages::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 4px;
}

#guidedChatMessages::-webkit-scrollbar-thumb {
    background: #888;
    border-radius: 4px;
}

#guidedChatMessages::-webkit-scrollbar-thumb:hover {
    background: #555;
}

#guidedChatInput:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

#guidedSendBtn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.btn-info {
    background: #17a2b8;
    color: white;
    border: none;
}

.btn-info:hover {
    background: #138496;
}

/* Guided Mode Side Panel */
.guided-mode-panel {
    display: none;
    position: sticky;
    top: 100px;
    height: calc(100vh - 120px);
    max-height: calc(100vh - 120px);
    background: white;
    border-radius: 10px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    flex-direction: column;
    overflow: hidden;
}

.guided-mode-panel.active {
    display: flex;
}

.guided-mode-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 20px;
    border-bottom: 2px solid #e0e0e0;
    background: #f8f9fa;
}

.guided-mode-header h3 {
    margin: 0;
    color: #667eea;
    font-size: 18px;
}

.guided-mode-close {
    background: none;
    border: none;
    font-size: 28px;
    color: #aaa;
    cursor: pointer;
    padding: 0;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: all 0.3s;
}

.guided-mode-close:hover {
    color: #000;
    background: rgba(0, 0, 0, 0.05);
}

.guided-mode-content {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    padding: 15px;
}

.guided-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 15px;
    background: #f8f9fa;
    border-radius: 8px;
    margin-bottom: 15px;
    display: flex;
    flex-direction: column;
    gap: 15px;
    min-height: 0;
}

.guided-chat-input-container {
    display: flex;
    gap: 10px;
    align-items: center;
}

.guided-chat-input {
    flex: 1;
    padding: 12px;
    border: 1px solid #ddd;
    border-radius: 5px;
    font-size: 14px;
}

.guided-chat-input:focus {
    outline: none;
    border-color: #667eea;
}

.guided-chat-input:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* Responsive: Hide guided mode panel on smaller screens or stack it */
@media (max-width: 1400px) {
    .main-content.guided-mode-active {
        grid-template-columns: 300px 1fr;
    }
    
    .guided-mode-panel {
        position: fixed;
        right: 0;
        top: 80px;
        width: 400px;
        z-index: 999;
        box-shadow: -2px 0 10px rgba(0, 0, 0, 0.2);
    }
    
    .main-content.guided-mode-active .right-panel {
        margin-right: 420px;
    }
}

@media (max-width: 768px) {
    .guided-mode-panel {
        width: 100%;
        right: 0;
        left: 0;
        height: 50vh;
        top: auto;
        bottom: 0;
        border-radius: 10px 10px 0 0;
    }
    
    .main-content.guided-mode-active .right-panel {
        margin-right: 0;
        margin-bottom: 50vh;
    }
}