:root {
    --primary-color: #2c3e50;
    --secondary-color: #3498db;
    --accent-color: #e74c3c;
    --bg-color: #f5f6fa;
    --text-color: #2c3e50;
    --card-bg: #ffffff;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    margin: 0;
    padding: 0;
}

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

/* Welcome Page */
.welcome-container {
    text-align: center;
    padding-top: 50px;
}

.rules-box {
    background: var(--card-bg);
    padding: 30px;
    border-radius: 10px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    text-align: left;
    margin: 30px 0;
}

.start-form {
    background: var(--card-bg);
    padding: 30px;
    border-radius: 10px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    max-width: 400px;
    margin: 0 auto;
}

.form-group {
    margin-bottom: 20px;
    text-align: left;
}

.form-group label {
    display: block;
    margin-bottom: 5px;
    font-weight: bold;
}

.form-group input {
    width: 100%;
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: 5px;
    font-size: 16px;
}

.btn-start,
.btn-submit,
.btn-home {
    background-color: var(--secondary-color);
    color: white;
    border: none;
    padding: 12px 24px;
    border-radius: 5px;
    font-size: 18px;
    cursor: pointer;
    transition: background 0.3s;
    text-decoration: none;
    display: inline-block;
}

.btn-start:hover,
.btn-submit:hover,
.btn-home:hover {
    background-color: #2980b9;
}

/* Exam Page */
.header-bar {
    background: var(--primary-color);
    color: white;
    padding: 15px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
}

.timer-box {
    font-size: 1.2em;
    font-weight: bold;
    background: rgba(255, 255, 255, 0.1);
    padding: 5px 15px;
    border-radius: 5px;
}

.question-card {
    background: var(--card-bg);
    padding: 20px;
    margin-bottom: 20px;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.question-header {
    font-size: 1.1em;
    margin-bottom: 15px;
    line-height: 1.5;
}

.q-num {
    font-weight: bold;
    color: var(--secondary-color);
    margin-right: 10px;
}

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

.option-item {
    display: flex;
    align-items: flex-start;
    padding: 10px;
    border: 1px solid #eee;
    border-radius: 5px;
    cursor: pointer;
    transition: background 0.2s;
}

.option-item:hover {
    background-color: #f8f9fa;
}

.option-item input[type="radio"] {
    margin-top: 4px;
    margin-right: 10px;
}

.opt-label {
    font-weight: bold;
    margin-right: 5px;
}

.submit-section {
    text-align: center;
    margin-top: 30px;
    margin-bottom: 50px;
}

/* Result Page */
.result-container {
    text-align: center;
    padding-top: 100px;
}

.btn-review {
    background-color: var(--primary-color);
    color: white;
    border: none;
    padding: 12px 24px;
    border-radius: 5px;
    font-size: 18px;
    cursor: pointer;
    transition: background 0.3s;
    text-decoration: none;
    display: inline-block;
}

.btn-review:hover {
    background-color: #34495e;
}

/* Review Page Details */
.correct-answer-box {
    margin-top: 15px;
    padding-top: 10px;
    border-top: 1px solid #eee;
}

.explanation-box {
    margin-top: 10px;
    border-top: 1px solid #eee;
    background-color: #fafafa;
    padding: 10px;
    border-radius: 4px;
}

.explanation-text {
    margin-top: 5px;
    color: #555;
    line-height: 1.4;
}

/* AI Chat Styling */
.btn-ask-ai {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    padding: 6px 14px;
    border-radius: 20px;
    cursor: pointer;
    font-size: 0.85em;
    margin-left: 15px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    transition: transform 0.2s;
    vertical-align: middle;
}

.btn-ask-ai:hover {
    transform: translateY(-2px);
    opacity: 0.9;
}

.ai-chat-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 400px;
    height: 600px;
    background-color: white;
    box-shadow: 0 5px 25px rgba(0, 0, 0, 0.25);
    border-radius: 15px;
    display: none;
    /* hidden by default */
    flex-direction: column;
    z-index: 2000;
    overflow: hidden;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    border: 1px solid #eee;
    animation: slideUp 0.3s ease-out;
}

@keyframes slideUp {
    from {
        transform: translateY(20px);
        opacity: 0;
    }

    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.ai-chat-header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 15px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}

.ai-header-title {
    font-weight: bold;
    font-size: 1.1em;
    display: flex;
    align-items: center;
    gap: 8px;
}

.ai-close-btn {
    background: none;
    border: none;
    color: white;
    font-size: 1.5em;
    cursor: pointer;
    line-height: 1;
    padding: 0 5px;
}

.ai-chat-messages {
    flex: 1;
    padding: 15px;
    overflow-y: auto;
    background-color: #f8f9fa;
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.ai-message {
    padding: 12px 16px;
    border-radius: 12px;
    font-size: 0.95em;
    line-height: 1.5;
    max-width: 85%;
    position: relative;
    word-wrap: break-word;
}

.ai-message.user-message {
    background-color: #764ba2;
    color: white;
    align-self: flex-end;
    border-bottom-right-radius: 2px;
}

.ai-message.ai-message {
    background-color: #ffffff;
    color: #2d3436;
    align-self: flex-start;
    border-bottom-left-radius: 2px;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.05);
}

.ai-message.loading-msg {
    align-self: flex-start;
    color: #888;
    background: none;
    padding: 5px;
    font-style: italic;
    box-shadow: none;
}

/* Markdown styling inside AI messages */
.ai-message p {
    margin-top: 0;
    margin-bottom: 0.8em;
}

.ai-message p:last-child {
    margin-bottom: 0;
}

.ai-message ul,
.ai-message ol {
    margin-left: 10px;
    padding-left: 10px;
    margin-bottom: 0.8em;
}

.ai-message code {
    background-color: rgba(0, 0, 0, 0.1);
    padding: 2px 4px;
    border-radius: 3px;
    font-family: monospace;
}

.ai-message pre {
    background-color: #2d3436;
    color: #fff;
    padding: 10px;
    border-radius: 5px;
    overflow-x: auto;
    margin-bottom: 0.8em;
}

.ai-message pre code {
    background-color: transparent;
    color: inherit;
}

.ai-message strong {
    font-weight: 700;
}

.ai-chat-input {
    padding: 15px;
    border-top: 1px solid #eee;
    display: flex;
    background-color: white;
    gap: 10px;
}

.ai-chat-input input {
    flex: 1;
    padding: 12px;
    border: 1px solid #ddd;
    border-radius: 25px;
    outline: none;
    font-size: 0.95em;
    transition: border-color 0.2s;
}

.ai-chat-input input:focus {
    border-color: #764ba2;
}

.ai-chat-input button {
    background: #764ba2;
    border: none;
    color: white;
    width: 45px;
    height: 45px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: background 0.2s, transform 0.1s;
}

.ai-chat-input button:hover {
    background: #667eea;
}


/* Exam Page - Two Column Layout */
.exam-layout {
    display: flex;
    gap: 30px;
    align-items: flex-start;
}

.exam-sidebar {
    position: sticky;
    top: 80px;
    /* Adjust based on header height, header bar is ~60px */
    width: 250px;
    max-height: calc(100vh - 100px);
    overflow-y: auto;
    background: white;
    padding: 15px;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
    flex-shrink: 0;
}

.exam-content {
    flex-grow: 1;
    min-width: 0;
    /* Prevents flex items from overflowing */
}

.question-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    margin-bottom: 20px;
}

.grid-item {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 35px;
    background-color: #e0e0e0;
    /* Gray for unanswered */
    color: #333;
    border-radius: 4px;
    font-size: 0.9em;
    font-weight: bold;
    text-decoration: none;
    cursor: pointer;
    transition: background-color 0.2s, color 0.2s;
}

.grid-item:hover {
    background-color: #d0d0d0;
}

.grid-item.answered {
    background-color: #2ecc71;
    /* Green for answered */
    color: white;
}

.grid-item.current {
    border: 2px solid var(--primary-color);
}

.sidebar-submit-section {
    position: sticky;
    bottom: 0;
    background: white;
    padding-top: 10px;
    border-top: 1px solid #eee;
    text-align: center;
}

/* Adjust main container for exam page to take full width if needed */
.exam-page-container {
    max-width: 1200px;
}

/* Speaker button for text-to-speech */
.speaker-btn {
    background: #3498db;
    color: white;
    border: none;
    border-radius: 50%;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s ease;
    flex-shrink: 0;
    font-size: 14px;
    margin-top: 4px;
}

.speaker-btn:hover {
    background: #2980b9;
    transform: scale(1.1);
}

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