* { box-sizing: border-box; }
body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background: #2563eb;
    min-height: 100vh;
    color: #1e293b;
    line-height: 1.55;
    padding-top: 80px;
}
@media (max-width: 768px) { body { padding-top: 120px; } }

.app-container { max-width: 1280px; margin: 0 auto; padding: 20px 16px 48px; }

/* Login reminder (guests) — same pattern as AMC 10 Trainer */
.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;
}

.app-header {
    text-align: center;
    margin-bottom: 24px;
    padding: 22px;
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
}
.app-header h1 {
    margin: 0;
    font-size: 1.85rem;
    color: #667eea;
    font-weight: 700;
}
.app-header .subtitle { margin: 10px 0 0; color: #64748b; font-size: 0.98rem; }

.main-content {
    display: grid;
    grid-template-columns: 300px minmax(0, 1fr);
    gap: 22px;
    align-items: start;
}
.main-content.guided-mode-active {
    grid-template-columns: 300px minmax(0, 1fr) minmax(260px, 360px);
}
@media (max-width: 960px) {
    .main-content { grid-template-columns: 1fr; }
    .main-content.guided-mode-active {
        grid-template-columns: 1fr;
    }
}

.panel-section {
    background: #fff;
    border-radius: 12px;
    padding: 18px;
    margin-bottom: 16px;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.06);
}
.panel-section h3 {
    margin: 0 0 14px;
    font-size: 1rem;
    color: #667eea;
}

.filter-group { margin-bottom: 14px; }
.filter-group label:not(.checkbox-label) {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: #475569;
    margin-bottom: 6px;
}
.field-hint { font-size: 12px; color: #94a3b8; margin: 6px 0 0; }
.filter-select {
    width: 100%;
    padding: 9px 10px;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    font-size: 14px;
    margin-bottom: 10px;
}
.checkbox-label {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    color: #334155;
}
.action-buttons { display: flex; flex-direction: column; gap: 10px; margin-top: 8px; }

.btn {
    border: none;
    border-radius: 8px;
    padding: 10px 16px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.05s, box-shadow 0.15s;
}
.btn:active { transform: scale(0.98); }
.btn-primary { background: #667eea; color: #fff; }
.btn-primary:hover { background: #5a6fd6; box-shadow: 0 4px 14px rgba(102, 126, 234, 0.35); }
.btn-primary:disabled { opacity: 0.55; cursor: not-allowed; box-shadow: none; }
.btn-secondary { background: #64748b; color: #fff; }
.btn-secondary:hover { background: #475569; }
.btn-outline {
    background: #fff;
    color: #667eea;
    border: 2px solid #667eea;
}
.btn-outline:hover { background: #eef2ff; }
.btn-success { background: #22c55e; color: #fff; }
.btn-success:hover { background: #16a34a; box-shadow: 0 4px 14px rgba(34, 197, 94, 0.35); }
.btn-info { background: #0ea5e9; color: #fff; }
.btn-info:hover { background: #0284c7; box-shadow: 0 4px 14px rgba(14, 165, 233, 0.35); }

.stats-panel .stats-row {
    display: flex;
    justify-content: space-between;
    padding: 8px 0;
    border-bottom: 1px solid #f1f5f9;
    font-size: 14px;
}
.stats-panel .stats-row:last-child { border-bottom: none; }
.stats-panel strong { color: #667eea; }

.right-panel {
    background: #fff;
    border-radius: 12px;
    padding: 22px;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.06);
    min-height: 400px;
}

.loading-banner, .error-banner {
    padding: 12px 16px;
    border-radius: 8px;
    margin-bottom: 16px;
    font-size: 14px;
}
.loading-banner { background: #e0e7ff; color: #3730a3; }
.error-banner { background: #fee2e2; color: #991b1b; }
.ok-banner { background: #dcfce7; color: #166534; }
.report-passage-textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    font-family: inherit;
    font-size: 14px;
    resize: vertical;
    margin-bottom: 4px;
}

.meta-strip {
    font-size: 13px;
    color: #64748b;
    margin-bottom: 16px;
    padding: 10px 12px;
    background: #f8fafc;
    border-radius: 8px;
    border-left: 4px solid #667eea;
}

.section-title {
    margin: 0 0 12px;
    font-size: 1.05rem;
    color: #334155;
}

.passage-card { margin-bottom: 28px; }
.passage-card-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 12px;
}
.passage-card-head .passage-card-title {
    margin: 0;
    flex: 1;
    min-width: 0;
}
.passage-card-head .btn {
    flex-shrink: 0;
}
.passage-text {
    max-height: min(55vh, 480px);
    overflow-y: auto;
    padding: 16px;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    font-size: 15px;
    line-height: 1.65;
    white-space: normal;
}
.passage-text .placeholder { color: #94a3b8; margin: 0; }

/* Markdown-rendered passage: preserve intentional line breaks & indentation */
.passage-text.passage-markdown p,
.passage-text.passage-markdown li,
.passage-text.passage-markdown td,
.passage-text.passage-markdown th {
    white-space: pre-wrap;
    word-break: break-word;
}
.passage-text.passage-markdown p { margin: 0.55em 0; }
.passage-text.passage-markdown p:first-child { margin-top: 0; }
.passage-text.passage-markdown p:last-child { margin-bottom: 0; }
.passage-text.passage-markdown h1,
.passage-text.passage-markdown h2,
.passage-text.passage-markdown h3,
.passage-text.passage-markdown h4 {
    margin: 0.75em 0 0.4em;
    color: #1e293b;
    font-weight: 700;
    line-height: 1.3;
}
.passage-text.passage-markdown h1 { font-size: 1.25rem; }
.passage-text.passage-markdown h2 { font-size: 1.12rem; }
.passage-text.passage-markdown h3,
.passage-text.passage-markdown h4 { font-size: 1.02rem; }
.passage-text.passage-markdown ul,
.passage-text.passage-markdown ol {
    margin: 0.5em 0;
    padding-left: 1.5em;
}
.passage-text.passage-markdown li { margin: 0.25em 0; }
.passage-text.passage-markdown blockquote {
    margin: 0.6em 0;
    padding: 0.35em 0 0.35em 12px;
    border-left: 3px solid #cbd5e1;
    color: #475569;
}
.passage-text.passage-markdown pre {
    margin: 0.6em 0;
    padding: 10px 12px;
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    overflow-x: auto;
    font-size: 14px;
    white-space: pre-wrap;
    word-break: break-word;
}
.passage-text.passage-markdown code {
    font-family: ui-monospace, Consolas, monospace;
    font-size: 0.92em;
    background: #fff;
    padding: 0.12em 0.35em;
    border-radius: 4px;
    border: 1px solid #e2e8f0;
}
.passage-text.passage-markdown pre code {
    border: none;
    padding: 0;
    background: none;
}
.passage-text.passage-markdown hr {
    border: none;
    border-top: 1px solid #e2e8f0;
    margin: 1em 0;
}
.passage-text.passage-markdown strong,
.passage-text.passage-markdown b { font-weight: 700; color: #0f172a; }
.passage-text.passage-markdown a { color: #4338ca; word-break: break-all; }
.passage-text.passage-markdown table {
    border-collapse: collapse;
    width: 100%;
    margin: 0.6em 0;
    font-size: 14px;
}
.passage-text.passage-markdown th,
.passage-text.passage-markdown td {
    border: 1px solid #e2e8f0;
    padding: 6px 10px;
    text-align: left;
    vertical-align: top;
}
.passage-text.passage-markdown th { background: #f1f5f9; font-weight: 600; }

.question-stem { font-size: 16px; font-weight: 600; color: #1e293b; margin: 0 0 16px; }

.answer-options { display: flex; flex-direction: column; gap: 10px; }
.option-row {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 12px 14px;
    border: 2px solid #e2e8f0;
    border-radius: 10px;
    cursor: pointer;
    transition: border-color 0.15s, background 0.15s;
}
.option-row:hover { border-color: #c7d2fe; background: #fafbff; }
.option-row input { margin-top: 3px; }
.option-row.selected { border-color: #667eea; background: #eef2ff; }
.option-row.correct { border-color: #22c55e; background: #f0fdf4; }
.option-row.incorrect { border-color: #ef4444; background: #fef2f2; }
.option-label { font-weight: 600; color: #667eea; min-width: 22px; }
.option-text { flex: 1; font-size: 14px; }

.question-actions { margin-top: 18px; display: flex; gap: 12px; flex-wrap: wrap; }

.feedback {
    margin-top: 18px;
    padding: 14px 16px;
    border-radius: 10px;
    font-size: 14px;
}
.feedback.correct { background: #dcfce7; color: #166534; }
.feedback.incorrect { background: #fee2e2; color: #991b1b; }
.feedback .explanation { margin-top: 10px; padding-top: 10px; border-top: 1px solid rgba(0,0,0,0.08); color: #334155; }

.has-navbar .app-container { padding-top: 8px; }

/* Modal */
.modal {
    display: none;
    position: fixed;
    z-index: 2000;
    inset: 0;
    background: rgba(15, 23, 42, 0.45);
    overflow-y: auto;
    padding: 40px 16px;
}
.modal-content {
    position: relative;
    max-width: 640px;
    margin: 0 auto;
    background: #fff;
    border-radius: 12px;
    padding: 28px 28px 24px;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.2);
}
.modal-content h2 { margin: 0 0 16px; color: #667eea; font-size: 1.2rem; padding-right: 36px; }
.modal-close {
    position: absolute;
    top: 16px;
    right: 16px;
    border: none;
    background: none;
    font-size: 28px;
    line-height: 1;
    color: #94a3b8;
    cursor: pointer;
}
.modal-close:hover { color: #1e293b; }
.help-body p { margin: 0 0 12px; font-size: 14px; color: #475569; }
.help-body .help-section-title {
    margin: 20px 0 8px;
    font-size: 0.95rem;
    font-weight: 600;
    color: #334155;
}
.help-body .help-section-title:first-child { margin-top: 0; }

/* General Math–style large modals & tables */
.gm-style-modal .modal-content-large {
    max-width: 1100px;
    width: 92%;
    max-height: 85vh;
    overflow-y: auto;
    margin: 3vh auto;
    padding: 28px 32px 32px;
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.25);
    position: relative;
}
.gm-style-modal h2 {
    color: #667eea;
    margin: 0 0 12px;
    font-size: 1.35rem;
}
.modal-lead { color: #64748b; font-size: 14px; margin: 0 0 16px; line-height: 1.5; }
.modal-subheading {
    font-size: 15px;
    font-weight: 600;
    color: #334155;
    margin: 20px 0 8px;
}
.modal-shared-hint {
    font-size: 13px;
    color: #64748b;
    margin: 0 0 10px;
    line-height: 1.45;
}
.shared-pool-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 12px 20px;
    align-items: flex-end;
    margin-bottom: 14px;
    padding: 12px 14px;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
}
.shared-pool-field {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 0;
}
.shared-pool-toolbar .shared-pool-field:first-child {
    flex: 1 1 220px;
}
.shared-pool-toolbar .shared-pool-field:last-child {
    flex: 0 1 200px;
}
.shared-pool-label {
    font-size: 12px;
    font-weight: 600;
    color: #64748b;
}
.shared-pool-search {
    width: 100%;
    padding: 9px 12px;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    font-size: 14px;
    box-sizing: border-box;
}
.shared-pool-sort {
    width: 100%;
    padding: 9px 10px;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    font-size: 14px;
    background: #fff;
    box-sizing: border-box;
}
.review-passages-toolbar {
    margin-bottom: 12px;
}
.passage-modal-actions { margin-bottom: 20px; }
.review-passage-modal-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
    margin-bottom: 16px;
}
.close-modal {
    position: absolute;
    top: 16px;
    right: 20px;
    font-size: 28px;
    font-weight: bold;
    color: #94a3b8;
    cursor: pointer;
    line-height: 1;
    user-select: none;
}
.close-modal:hover { color: #1e293b; }

.mistakes-table-wrapper, .passage-table-wrapper {
    overflow-x: auto;
    margin-top: 8px;
}
.mistakes-table, .passage-select-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 8px;
    font-size: 14px;
}
.mistakes-table th,
.mistakes-table td,
.passage-select-table th,
.passage-select-table td {
    padding: 10px 12px;
    text-align: left;
    border-bottom: 1px solid #e2e8f0;
}
.mistakes-table th,
.passage-select-table th {
    background: #f8fafc;
    font-weight: 600;
    color: #334155;
    cursor: pointer;
    user-select: none;
}
.mistakes-table th:hover,
.passage-select-table th:hover { background: #f1f5f9; }
.mistakes-table tr:hover td,
.passage-select-table tr:hover td { background: #fafbff; }

.passage-row-actions {
    white-space: normal;
    vertical-align: middle;
}
.passage-row-actions .btn-small {
    margin-right: 6px;
    margin-bottom: 4px;
}

.btn-small {
    padding: 8px 14px;
    font-size: 13px;
    min-width: 72px;
    border-radius: 6px;
    border: none;
    font-weight: 600;
    cursor: pointer;
    background: #667eea;
    color: #fff;
}
.btn-small:hover { background: #5a6fd6; }
.btn-small.secondary { background: #64748b; }
.btn-small.secondary:hover { background: #475569; }

.question-nav-wrap {
    margin-bottom: 16px;
}
.question-nav-wrap .question-nav-title {
    margin-bottom: 8px;
    font-size: 1.1rem;
}
.question-nav-wrap .question-progress {
    margin-bottom: 0;
}
.question-progress {
    font-size: 14px;
    font-weight: 600;
    color: #4338ca;
    margin-bottom: 10px;
    padding: 8px 12px;
    background: #eef2ff;
    border-radius: 8px;
}
.batch-question-progress {
    display: flex;
    flex-direction: column;
    gap: 10px;
    align-items: flex-start;
}
.batch-mode-hint {
    margin: 0;
    font-size: 13px;
    font-weight: 500;
    color: #475569;
    line-height: 1.45;
    max-width: 720px;
}
.batch-mode-hint.batch-mode-done { color: #15803d; }
.batch-q-pills {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
}
.batch-q-pill {
    min-width: 38px;
    padding: 8px 12px;
    border: 2px solid #c7d2fe;
    border-radius: 8px;
    background: #fff;
    font-weight: 700;
    font-size: 14px;
    color: #4338ca;
    cursor: pointer;
}
.batch-q-pill:hover { background: #f5f7ff; }
.batch-q-pill.active {
    border-color: #667eea;
    background: #667eea;
    color: #fff;
}
.batch-q-pill.active.pill-unanswered {
    border-style: solid;
    border-color: #667eea;
    background: #667eea;
    color: #fff;
}
.batch-q-pill.pill-unanswered {
    border-style: dashed;
    border-color: #cbd5e1;
    background: #f8fafc;
    color: #64748b;
}
.batch-q-pill.pill-answered {
    border-style: solid;
    border-color: #60a5fa;
    background: #dbeafe;
}
.batch-q-pill.pill-correct {
    border-color: #22c55e;
    background: #dcfce7;
    color: #166534;
}
.batch-q-pill.pill-incorrect {
    border-color: #f87171;
    background: #fee2e2;
    color: #991b1b;
}
.batch-q-pill.pill-skipped {
    border-color: #f59e0b;
    background: #fffbeb;
    color: #92400e;
}
.batch-q-pill.pill-has-guided {
    box-shadow: 0 0 0 2px rgba(13, 148, 136, 0.5);
}
.batch-q-pill.active.pill-has-guided {
    box-shadow: 0 0 0 2px rgba(204, 251, 241, 0.95);
}
.batch-q-label {
    font-size: 13px;
    color: #64748b;
    font-weight: 600;
}

.guided-md {
    font-size: 14px;
    line-height: 1.5;
}
.guided-md p {
    margin: 0 0 0.65em;
}
.guided-md p:last-child {
    margin-bottom: 0;
}
.guided-md ul,
.guided-md ol {
    margin: 0.4em 0 0.65em 1.25em;
    padding: 0;
}
.guided-md li {
    margin: 0.25em 0;
}
.guided-md strong {
    font-weight: 700;
}
.guided-md em {
    font-style: italic;
}

/* Guided AI Mode — third column; narrows passage area (General Math–style) */
.guided-mode-panel {
    display: none;
    position: sticky;
    top: 100px;
    height: calc(100vh - 120px);
    max-height: calc(100vh - 120px);
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
    flex-direction: column;
    overflow: hidden;
    min-width: 0;
}
.guided-mode-panel.active {
    display: flex;
}
.guided-mode-header {
    padding: 14px 18px;
    border-bottom: 2px solid #e2e8f0;
    background: #f8fafc;
}
.guided-mode-header h3 {
    color: #667eea;
    font-size: 1rem;
}
.guided-mode-content {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    padding: 14px;
}
.guided-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 14px;
    background: #f8fafc;
    border-radius: 10px;
    margin-bottom: 12px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    min-height: 0;
}
.guided-chat-input-container {
    display: flex;
    gap: 10px;
    align-items: center;
}
.guided-chat-input {
    flex: 1;
    padding: 10px 12px;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    font-size: 14px;
}
.guided-chat-input:focus {
    outline: none;
    border-color: #667eea;
}
.guided-chat-input:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}
.guided-message {
    padding: 10px 14px;
    border-radius: 10px;
    max-width: 92%;
    word-wrap: break-word;
    font-size: 14px;
    line-height: 1.5;
}
.guided-message-user {
    background: #667eea;
    color: #fff;
    align-self: flex-end;
    margin-left: auto;
}
.guided-message-assistant {
    background: #fff;
    border: 1px solid #e2e8f0;
    align-self: flex-start;
}
.guided-message-system {
    background: #fef3c7;
    border: 1px solid #fcd34d;
    align-self: center;
    text-align: center;
    font-size: 13px;
    color: #92400e;
}
.typing-indicator .guided-message-content {
    color: #64748b;
    font-style: italic;
}
@media (max-width: 1100px) {
    .main-content.guided-mode-active {
        grid-template-columns: minmax(240px, 280px) minmax(0, 1fr);
    }
    .guided-mode-panel.active {
        position: fixed;
        right: 12px;
        top: 88px;
        width: min(340px, calc(100vw - 24px));
        z-index: 1500;
        max-height: calc(100vh - 100px);
        box-shadow: -4px 0 24px rgba(0, 0, 0, 0.12);
    }
}
@media (max-width: 768px) {
    .guided-mode-panel.active {
        left: 12px;
        right: 12px;
        width: auto;
        top: auto;
        bottom: 12px;
        max-height: 45vh;
        height: auto;
    }
}
