* {
    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;
    padding: 10px;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    background: white;
    border-radius: 20px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    overflow: hidden;
}

.ai-disclaimer {
    background: #fff4e5;
    color: #664d03;
    padding: 12px 20px;
    margin: 10px 0;
    border-left: 5px solid #ffc107;
    border-radius: 8px;
    font-size: 0.9em;
    line-height: 1.4;
    display: flex;
    align-items: center;
    gap: 10px;
}

header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 10px 15px;
    text-align: center;
}

header h1 {
    font-size: 1.8em;
    margin-bottom: 5px;
}

header p {
    font-size: 1em;
    opacity: 0.9;
}

main {
    padding: 15px;
}

/* Subject Selection */
.subject-selection h2 {
    text-align: center;
    margin-bottom: 20px;
    color: #333;
}

/* Mode Toggle */
.mode-toggle {
    display: flex;
    justify-content: center;
    align-items: center;
    margin-bottom: 30px;
    flex-wrap: wrap;
    gap: 10px;
}

.mode-btn {
    padding: 10px 20px;
    border: 2px solid #667eea;
    background: white;
    color: #667eea;
    border-radius: 25px;
    cursor: pointer;
    font-size: 0.95em;
    font-weight: 600;
    transition: all 0.3s;
    display: flex;
    align-items: center;
    gap: 8px;
    min-height: 44px;
    -webkit-tap-highlight-color: transparent;
}

.mode-btn:hover {
    background: #f0f2ff;
    transform: translateY(-2px);
}

.mode-btn.active {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border-color: #667eea;
}

.mode-icon-small {
    font-size: 1.2em;
}

.subject-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 20px;
    margin-bottom: 40px;
}

.subject-card {
    background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
    padding: 30px;
    border-radius: 15px;
    text-align: center;
    cursor: pointer;
    transition: transform 0.3s, box-shadow 0.3s;
    -webkit-tap-highlight-color: transparent;
}

.subject-card:hover {
    transform: translateY(-10px);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
}

.subject-icon {
    font-size: 4em;
    margin-bottom: 15px;
}

.subject-card h3 {
    font-size: 1.5em;
    margin-bottom: 10px;
    color: #333;
}

.subject-card p {
    color: #666;
}

/* Buttons */
.btn {
    padding: 10px 25px;
    border: none;
    border-radius: 25px;
    font-size: 0.95em;
    cursor: pointer;
    transition: all 0.3s;
    font-weight: 600;
}

.btn-primary {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.btn-primary:hover {
    transform: scale(1.05);
    box-shadow: 0 5px 15px rgba(102, 126, 234, 0.4);
}

.btn-secondary {
    background: #f5f7fa;
    color: #333;
    border: 2px solid #667eea;
}

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

.btn-success {
    background: linear-gradient(135deg, #11998e 0%, #27ae60 100%);
    color: white;
}

.btn-success:hover {
    transform: scale(1.05);
    box-shadow: 0 5px 15px rgba(17, 153, 142, 0.4);
}

.btn-small {
    padding: 8px 15px;
    font-size: 0.9em;
}

.spinner-small {
    width: 16px;
    height: 16px;
    border: 2px solid rgba(108, 92, 231, 0.3);
    border-radius: 50%;
    border-top-color: #6c5ce7;
    animation: spin 1s linear infinite;
    display: inline-block;
}

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

.ai-feedback {
    border-left: 4px solid #6c5ce7;
    background: #fdf2ff;
    animation: fadeIn 0.3s ease;
    padding: 15px;
    margin-top: 15px;
    border-radius: 8px;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(-5px); }
    to { opacity: 1; transform: translateY(0); }
}

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

/* Actions */
.actions {
    text-align: center;
    margin-top: 20px;
}

.actions button {
    margin: 0 8px;
}

.progress-container {
    display: flex;
    align-items: center;
    gap: 15px;
    margin-top: 0;
    margin-bottom: 20px;
}

/* Progress Bar */
.progress-bar {
    flex: 1;
    height: 8px;
    background: #eef2f7;
    border-radius: 4px;
    margin-bottom: 0;
    overflow: hidden;
}

.progress {
    height: 100%;
    background: #27ae60;
    transition: width 0.3s;
    border-radius: 4px;
}

#question-counter {
    font-size: 0.9em;
    color: #666;
    font-weight: 600;
    white-space: nowrap;
}

/* Test Container */
.test-container {
    max-width: 1100px;
    margin: 0 auto;
}

.question-card {
    background: #f5f7fa;
    padding: 12px 18px;
    border-radius: 12px;
    margin-bottom: 15px;
    border-left: 5px solid #667eea;
    box-shadow: 0 4px 15px rgba(0,0,0,0.05);
}

.question-number {
    color: #667eea;
    font-weight: bold;
    font-size: 0.95em;
    margin-bottom: 0;
    display: inline;
    margin-right: 5px;
}

.question-card h2 {
    color: #333;
    font-size: 1.15em;
    margin-bottom: 4px;
    line-height: 1.5;
    margin-top: 0;
    display: block;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.options-container {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    margin-top: 4px;
}

.radio-option {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: 8px;
    border: 1.5px solid #ddd;
    background: white;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 1.0em;
    height: 100%;
    min-height: 44px;
    -webkit-tap-highlight-color: transparent;
}

.radio-option.selected {
    border-color: #667eea;
    background: #f0f2ff;
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.1);
}

.radio-option input[type="radio"] {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

.radio-option .option-text {
    font-size: 1.0em;
}

.radio-option.selected .option-text {
    font-weight: normal;
    color: #667eea;
}

.option {
    background: white;
    padding: 12px 15px;
    border-radius: 8px;
    border: 2px solid #ddd;
    cursor: pointer;
    transition: all 0.3s;
    font-size: 1.05em;
    display: block;
    width: 100%;
    margin-bottom: 8px;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

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

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

/* Navigation */
.navigation-buttons {
    display: flex;
    justify-content: center;
    gap: 15px;
    margin-top: 30px;
}

.navigation-buttons button {
    min-width: 150px;
}

/* Results */
.score-summary {
    text-align: center;
    margin-bottom: 15px;
}

.score-summary h2 {
    font-size: 1.2em;
    margin-bottom: 10px;
}

.score-circle {
    width: 120px;
    height: 120px;
    margin: 15px auto;
    border-radius: 50%;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 5px 15px rgba(102, 126, 234, 0.3);
}

.score-text {
    text-align: center;
    color: white;
}

#score-percentage {
    font-size: 1.8em;
    font-weight: bold;
    display: block;
}

#score-details {
    font-size: 0.85em;
    margin-top: 5px;
}

#score-message {
    font-size: 0.95em;
    color: #666;
    margin-top: 10px;
}

/* Answer Review */
.answers-review {
    margin-bottom: 15px;
}

.answers-review h2 {
    margin-bottom: 10px;
    color: #333;
    font-size: 1.1em;
}

.answer-item {
    background: #f5f7fa;
    padding: 10px 12px;
    border-radius: 8px;
    margin-bottom: 8px;
    border-left: 3px solid #ddd;
}

.answer-item.correct {
    border-left-color: #03b346;
}

.answer-item.incorrect {
    border-left-color: #ff6b6b;
}

.answer-item h3 {
    color: #333;
    margin-bottom: 6px;
    font-size: 0.85em;
}

.answer-detail {
    display: flex;
    justify-content: space-between;
    margin: 3px 0;
    font-size: 0.8em;
}

.answer-detail strong {
    color: #666;
}

.correct-answer {
    color: #03b346;
    font-weight: bold;
}

.incorrect-answer {
    color: #ff6b6b;
    font-weight: bold;
}

/* History Table */
.history-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 30px;
    border: 2px solid #667eea;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

.history-table th,
.history-table td {
    padding: 12px 15px;
    text-align: center;
    border: 1px solid #ddd;
}

.history-table th {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    font-weight: 600;
    text-align: center;
}

.history-table tbody tr {
    background: white;
}

.history-table tr:hover {
    background: #f5f7fa;
}

.score-good {
    color: #03b346;
    font-weight: bold;
}

.score-bad {
    color: #ff6b6b;
    font-weight: bold;
}

/* Loading */
.loading {
    text-align: center;
    padding: 60px;
    font-size: 1.3em;
    color: #666;
}

/* Footer */
footer {
    background: #f5f7fa;
    padding: 20px;
    text-align: center;
    color: #666;
}

/* Scrollable table wrapper for mobile */
.table-scroll {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: 8px;
}

/* Responsive — phones & tablets (≤768px) */
@media (max-width: 768px) {
    body {
        padding: 0;
    }
    .container {
        border-radius: 0;
        box-shadow: none;
        min-height: 100vh;
    }
    header h1 {
        font-size: 1.4em;
    }
    main {
        padding: 12px;
    }
    .subject-cards {
        grid-template-columns: 1fr;
        gap: 12px;
    }
    .subject-card {
        padding: 20px;
    }
    .subject-icon {
        font-size: 3em;
    }
    .mode-toggle {
        margin-bottom: 20px;
    }
    .options-container {
        grid-template-columns: 1fr;
    }
    .navigation-buttons {
        flex-direction: column;
        align-items: stretch;
        gap: 10px;
    }
    .navigation-buttons button {
        min-width: unset;
        width: 100%;
    }
    .actions {
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 10px;
    }
    .actions button {
        margin: 0;
        width: 100%;
        max-width: 320px;
    }
    .score-details {
        flex-wrap: wrap;
        gap: 8px;
        justify-content: center;
    }
    .score-item {
        min-width: 70px;
    }
    .section-header {
        flex-direction: column;
        gap: 8px;
        align-items: flex-start;
    }
    .answer-card {
        padding: 12px 14px;
    }
    .answer-row {
        flex-direction: column;
        align-items: flex-start;
        gap: 4px;
    }
    .answer-label {
        min-width: unset;
    }
    .answer-display {
        width: 100%;
    }
    .answer-letter {
        min-width: auto;
    }
    .history-table {
        font-size: 0.82em;
        min-width: 480px;
    }
    .history-table th,
    .history-table td {
        padding: 8px 6px;
    }
}
/* Results Page Styling */
.results-summary {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 20px;
    border-radius: 15px;
    margin-bottom: 25px;
    box-shadow: 0 8px 25px rgba(102, 126, 234, 0.2);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 15px;
}

.score-main {
    text-align: center;
}

.results-summary h2 {
    font-size: 1.1em;
    margin-bottom: 5px;
    opacity: 0.9;
    font-weight: 500;
}

.score-display {
    font-size: 3em;
    font-weight: 800;
    margin: 0;
    text-shadow: 0 2px 10px rgba(0,0,0,0.1);
}

.score-details {
    display: flex;
    gap: 12px;
    flex-wrap: nowrap;
}

.score-item {
    background: rgba(255, 255, 255, 0.15);
    padding: 8px 15px;
    border-radius: 10px;
    text-align: center;
    min-width: 90px;
    transition: background 0.2s;
}

.score-item .label {
    font-size: 0.8em;
    opacity: 0.8;
    margin-bottom: 2px;
}

.score-item .value {
    font-size: 1.4em;
    font-weight: bold;
    margin-top: 0;
}

#correct-count {
    color: #27ae60;
}

#incorrect-count {
    color: #ff6b6b;
}

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

.section-header h2 {
    margin-bottom: 0;
}

.header-actions {
    display: flex;
    gap: 15px;
}

.header-link {
    text-decoration: none;
    color: #667eea;
    font-weight: 600;
    font-size: 0.95em;
    padding: 5px 10px;
    border-radius: 5px;
    transition: background 0.2s;
}

.header-link:hover {
    background: #f0f2ff;
    color: #764ba2;
}

/* Answer Cards */
.answer-card {
    background: white;
    border-radius: 12px;
    padding: 15px 20px;
    margin-bottom: 12px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.08);
    transition: transform 0.2s;
}

.answer-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.12);
}

.answer-card.correct {
    border-left: 5px solid #28a745;
}

.answer-card.incorrect {
    border-left: 5px solid #dc3545;
}

.answer-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
    padding-bottom: 8px;
    border-bottom: 1px solid #f0f0f0;
}

.question-number {
    font-weight: 600;
    color: #667eea;
    font-size: 1.05em;
}

.answer-status {
    padding: 4px 12px;
    border-radius: 20px;
    font-weight: 600;
    font-size: 0.85em;
}

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

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

.question-text {
    font-size: 1.05em;
    color: #333;
    line-height: 1.5;
    margin-bottom: 12px;
    padding: 10px 12px;
    background: #f8f9fa;
    border-radius: 8px;
    display: block;
    width: 100%;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

/* Inline data tables inside question text */
.q-table {
    border-collapse: collapse;
    margin: 10px 0;
    font-size: 0.92em;
    width: auto;
}
.q-table th,
.q-table td {
    border: 1px solid #bbb;
    padding: 5px 12px;
    text-align: center;
}
.q-table thead tr {
    background: #e8eaf6;
    font-weight: 600;
}
.q-table tbody tr:nth-child(even) {
    background: #f5f5f5;
}

/* Answer Section */
.answer-section {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.answer-row {
    display: flex;
    align-items: center;
    gap: 15px;
}

.answer-label {
    color: #555;
    font-size: 0.9em;
    min-width: 100px;
    font-weight: 600;
}

.answer-display {
    display: flex;
    align-items: center;
    padding: 8px 15px;
    border-radius: 8px;
    gap: 8px;
    background: #f8f9fa;
    flex: 1;
}

.answer-letter {
    font-weight: normal;
    font-size: 1.1em;
    color: #667eea;
    min-width: 25px;
    flex-shrink: 0;
}

.answer-text {
    flex: 1;
    line-height: 1.4;
    color: #333;
    font-size: 0.95em;
}

/* User Answer Styling */
.user-answer-row .answer-display {
    background: #fff3cd;
    border: 2px solid #ffc107;
}

.answer-card.correct .user-answer-row .answer-display {
    background: #d4edda;
    border: 2px solid #28a745;
}

.answer-card.incorrect .user-answer-row .answer-display {
    background: #f8d7da;
    border: 2px solid #dc3545;
}

/* Correct Answer Styling */
.correct-answer-row .answer-display {
    background: #d4edda;
    border: 2px solid #28a745;
}

.correct-answer-row .answer-letter {
    color: #28a745;
}

/* Action Buttons */
.results-actions {
    display: flex;
    gap: 15px;
    justify-content: center;
    margin-top: 30px;
    flex-wrap: wrap;
}

.btn {
    padding: 12px 30px;
    border: none;
    border-radius: 8px;
    font-size: 1em;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
}

.btn-primary {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

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

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

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

/* Small phones (≤480px) */
@media (max-width: 480px) {
    header h1 {
        font-size: 1.2em;
    }
    .score-display {
        font-size: 2.2em;
    }
    .subject-card h3 {
        font-size: 1.2em;
    }
    .score-item {
        min-width: 60px;
        padding: 6px 10px;
    }
    .btn {
        padding: 10px 20px;
        font-size: 0.9em;
    }
    .answer-display {
        flex-direction: column;
        align-items: flex-start;
    }
}