/* ============================================================
   AI Study Platform — Stylesheet v1.0.0
   Design: Deep Indigo + Warm Amber, clean educational aesthetic
   Font: Poppins (loaded via @import)
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@400;500;600;700&family=DM+Mono:wght@400;500&display=swap');

/* ---------- CSS Variables ---------- */
:root {
    --asp-primary:      #3B2F9E;
    --asp-primary-dark: #2A206E;
    --asp-primary-light:#EEF0FF;
    --asp-accent:       #F59E0B;
    --asp-accent-dark:  #D97706;
    --asp-success:      #10B981;
    --asp-error:        #EF4444;
    --asp-warning:      #F59E0B;
    --asp-bg:           #F7F8FC;
    --asp-card:         #FFFFFF;
    --asp-border:       #E5E7EB;
    --asp-text:         #1F2937;
    --asp-text-muted:   #6B7280;
    --asp-radius:       12px;
    --asp-radius-sm:    8px;
    --asp-shadow:       0 2px 16px rgba(59,47,158,0.08);
    --asp-shadow-lg:    0 8px 32px rgba(59,47,158,0.14);
    --asp-font:         'Poppins', sans-serif;
    --asp-font-mono:    'DM Mono', monospace;
    --asp-transition:   all 0.22s ease;
}

/* ---------- Base ---------- */
#asp-auth-wrap,
#asp-dashboard {
    font-family: var(--asp-font);
    color: var(--asp-text);
    font-size: 15px;
    line-height: 1.6;
    box-sizing: border-box;
}

#asp-auth-wrap *,
#asp-dashboard * {
    box-sizing: border-box;
}

/* ============================================================
   AUTH — Login / Register
   ============================================================ */
#asp-auth-wrap {
    display: flex;
    justify-content: center;
    align-items: flex-start;
    padding: 40px 16px 60px;
    min-height: 500px;
    background: linear-gradient(135deg, #F0F2FF 0%, #FFF7ED 100%);
}

.asp-auth-card {
    background: var(--asp-card);
    border-radius: 20px;
    padding: 40px 36px;
    width: 100%;
    max-width: 440px;
    box-shadow: var(--asp-shadow-lg);
    border: 1px solid var(--asp-border);
}

/* Brand */
.asp-brand {
    text-align: center;
    margin-bottom: 28px;
}
.asp-brand-icon {
    font-size: 48px;
    line-height: 1;
    margin-bottom: 10px;
    display: block;
}
.asp-brand-name {
    font-size: 22px;
    font-weight: 700;
    color: var(--asp-primary);
    margin: 0 0 6px;
}
.asp-brand-tagline {
    font-size: 13px;
    color: var(--asp-text-muted);
    margin: 0;
}

/* Auth Tabs */
.asp-auth-tabs {
    display: flex;
    background: var(--asp-bg);
    border-radius: var(--asp-radius-sm);
    padding: 4px;
    margin-bottom: 24px;
    gap: 4px;
}
.asp-auth-tab {
    flex: 1;
    padding: 9px 0;
    border: none;
    background: transparent;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 600;
    color: var(--asp-text-muted);
    cursor: pointer;
    font-family: var(--asp-font);
    transition: var(--asp-transition);
}
.asp-auth-tab.active {
    background: var(--asp-card);
    color: var(--asp-primary);
    box-shadow: 0 1px 6px rgba(59,47,158,0.12);
}

/* Forms */
.asp-form .asp-field {
    margin-bottom: 18px;
}
.asp-form label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--asp-text);
    margin-bottom: 6px;
}
.asp-form label small {
    font-weight: 400;
    color: var(--asp-text-muted);
}
.asp-form input[type="text"],
.asp-form input[type="email"],
.asp-form input[type="password"],
.asp-form input[type="number"],
.asp-form select,
.asp-form textarea {
    width: 100%;
    padding: 11px 14px;
    border: 1.5px solid var(--asp-border);
    border-radius: var(--asp-radius-sm);
    font-size: 14px;
    font-family: var(--asp-font);
    color: var(--asp-text);
    background: #FAFAFA;
    transition: var(--asp-transition);
    outline: none;
}
.asp-form input:focus,
.asp-form select:focus,
.asp-form textarea:focus {
    border-color: var(--asp-primary);
    background: #fff;
    box-shadow: 0 0 0 3px rgba(59,47,158,0.08);
}
.asp-form textarea {
    resize: vertical;
    min-height: 90px;
}

/* Alert */
.asp-alert {
    padding: 12px 16px;
    border-radius: var(--asp-radius-sm);
    font-size: 13.5px;
    margin-bottom: 18px;
    font-weight: 500;
}
.asp-alert.success {
    background: #D1FAE5;
    color: #065F46;
    border: 1px solid #6EE7B7;
}
.asp-alert.error {
    background: #FEE2E2;
    color: #991B1B;
    border: 1px solid #FCA5A5;
}

/* Auth Footer */
.asp-auth-footer {
    text-align: center;
    font-size: 12px;
    color: var(--asp-text-muted);
    margin-top: 20px;
    margin-bottom: 0;
}

/* ============================================================
   BUTTONS
   ============================================================ */
.asp-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 11px 24px;
    border: none;
    border-radius: var(--asp-radius-sm);
    font-size: 14px;
    font-weight: 600;
    font-family: var(--asp-font);
    cursor: pointer;
    transition: var(--asp-transition);
    text-decoration: none;
}
.asp-btn:disabled {
    opacity: 0.65;
    cursor: not-allowed;
}
.asp-btn-primary {
    background: var(--asp-primary);
    color: #fff;
}
.asp-btn-primary:hover:not(:disabled) {
    background: var(--asp-primary-dark);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(59,47,158,0.25);
}
.asp-btn-full {
    width: 100%;
}
.asp-btn-outline {
    background: transparent;
    color: var(--asp-primary);
    border: 1.5px solid var(--asp-primary);
}
.asp-btn-outline:hover:not(:disabled) {
    background: var(--asp-primary-light);
}

/* ============================================================
   DASHBOARD — Header
   ============================================================ */
#asp-dashboard {
    background: var(--asp-bg);
    min-height: 600px;
    border-radius: 16px;
    overflow: hidden;
    box-shadow: var(--asp-shadow-lg);
}

.asp-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--asp-primary);
    padding: 14px 24px;
    flex-wrap: wrap;
    gap: 12px;
}
.asp-header-left {
    display: flex;
    align-items: center;
    gap: 10px;
}
.asp-logo-icon { font-size: 24px; }
.asp-logo-text {
    font-size: 17px;
    font-weight: 700;
    color: #fff;
    letter-spacing: -0.3px;
}
.asp-header-right {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

/* Usage pill */
.asp-usage-pill {
    background: rgba(255,255,255,0.15);
    border: 1px solid rgba(255,255,255,0.25);
    border-radius: 20px;
    padding: 5px 14px;
    font-size: 13px;
    color: #fff;
    font-weight: 600;
}
.asp-usage-pill #asp-usage-remaining { color: #FCD34D; }
.asp-usage-label { font-weight: 400; font-size: 12px; margin-left: 4px; opacity: 0.85; }

/* User chip */
.asp-user-chip {
    display: flex;
    align-items: center;
    gap: 8px;
}
.asp-user-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--asp-accent);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 14px;
}
.asp-user-name {
    font-size: 14px;
    color: rgba(255,255,255,0.9);
    font-weight: 500;
    max-width: 120px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.asp-logout-btn {
    background: rgba(255,255,255,0.15);
    border: 1px solid rgba(255,255,255,0.25);
    color: #fff;
    border-radius: 8px;
    width: 34px;
    height: 34px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 16px;
    transition: var(--asp-transition);
}
.asp-logout-btn:hover { background: rgba(255,255,255,0.25); }

/* ============================================================
   LANGUAGE BAR
   ============================================================ */
.asp-lang-bar {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 24px;
    background: var(--asp-primary-light);
    border-bottom: 1px solid #DDE0F5;
    flex-wrap: wrap;
}
.asp-lang-label {
    font-size: 13px;
    font-weight: 600;
    color: var(--asp-primary);
}
.asp-lang-pills {
    display: flex;
    gap: 8px;
}
.asp-lang-btn {
    padding: 5px 16px;
    border-radius: 20px;
    border: 1.5px solid var(--asp-primary);
    background: transparent;
    color: var(--asp-primary);
    font-size: 13px;
    font-weight: 600;
    font-family: var(--asp-font);
    cursor: pointer;
    transition: var(--asp-transition);
}
.asp-lang-btn.active {
    background: var(--asp-primary);
    color: #fff;
}
.asp-lang-btn:hover:not(.active) {
    background: var(--asp-primary-light);
}

/* ============================================================
   FEATURE TABS NAV
   ============================================================ */
.asp-tabs-nav {
    display: flex;
    gap: 0;
    background: #fff;
    border-bottom: 2px solid var(--asp-border);
    padding: 0 24px;
    overflow-x: auto;
}
.asp-tab-btn {
    display: flex;
    align-items: center;
    gap: 7px;
    padding: 14px 20px 12px;
    border: none;
    border-bottom: 3px solid transparent;
    background: transparent;
    color: var(--asp-text-muted);
    font-size: 14px;
    font-weight: 600;
    font-family: var(--asp-font);
    cursor: pointer;
    transition: var(--asp-transition);
    white-space: nowrap;
    margin-bottom: -2px;
}
.asp-tab-btn:hover { color: var(--asp-primary); }
.asp-tab-btn.active {
    color: var(--asp-primary);
    border-bottom-color: var(--asp-primary);
}
.asp-tab-icon { font-size: 16px; }

/* ============================================================
   PANELS
   ============================================================ */
.asp-panels { padding: 24px; }

.asp-panel-header {
    margin-bottom: 20px;
}
.asp-panel-header h2 {
    font-size: 19px;
    font-weight: 700;
    color: var(--asp-primary);
    margin: 0 0 4px;
}
.asp-panel-header p {
    font-size: 14px;
    color: var(--asp-text-muted);
    margin: 0;
}

/* Feature forms inside panels */
.asp-feature-form .asp-form-row {
    display: flex;
    gap: 16px;
    flex-wrap: wrap;
}
.asp-feature-form .asp-form-row .asp-field { flex: 1; min-width: 160px; }

.asp-feature-form .asp-field { margin-bottom: 16px; }
.asp-feature-form label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    margin-bottom: 6px;
    color: var(--asp-text);
}

/* ============================================================
   RESULT BOX
   ============================================================ */
.asp-result-box {
    margin-top: 20px;
    background: #FAFBFF;
    border: 1.5px solid #DDE0F5;
    border-radius: var(--asp-radius);
    padding: 22px 24px;
    font-size: 14.5px;
    line-height: 1.75;
    color: var(--asp-text);
    white-space: pre-wrap;
    word-break: break-word;
    position: relative;
    animation: asp-fadeUp 0.3s ease;
}
.asp-result-box strong { font-weight: 700; }

/* Copy button inside result */
.asp-copy-btn {
    position: absolute;
    top: 12px;
    right: 12px;
    background: var(--asp-primary-light);
    border: none;
    border-radius: 6px;
    padding: 5px 12px;
    font-size: 12px;
    color: var(--asp-primary);
    font-weight: 600;
    cursor: pointer;
    font-family: var(--asp-font);
    transition: var(--asp-transition);
}
.asp-copy-btn:hover { background: var(--asp-primary); color: #fff; }

/* ============================================================
   QUIZ AREA
   ============================================================ */
.asp-quiz-area {
    margin-top: 20px;
    animation: asp-fadeUp 0.3s ease;
}

.asp-quiz-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
    flex-wrap: wrap;
    gap: 8px;
}
.asp-quiz-header h3 {
    font-size: 16px;
    font-weight: 700;
    color: var(--asp-primary);
    margin: 0;
}
.asp-quiz-score-badge {
    background: var(--asp-primary-light);
    color: var(--asp-primary);
    font-size: 13px;
    font-weight: 700;
    padding: 5px 14px;
    border-radius: 20px;
    display: none;
}

.asp-quiz-question {
    background: #fff;
    border: 1.5px solid var(--asp-border);
    border-radius: var(--asp-radius);
    padding: 18px 20px;
    margin-bottom: 12px;
    transition: var(--asp-transition);
}
.asp-quiz-question.correct { border-color: var(--asp-success); background: #F0FDF4; }
.asp-quiz-question.wrong   { border-color: var(--asp-error);   background: #FFF5F5; }

.asp-q-num {
    font-size: 12px;
    font-weight: 700;
    color: var(--asp-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 8px;
}
.asp-q-text {
    font-size: 15px;
    font-weight: 600;
    color: var(--asp-text);
    margin-bottom: 14px;
}
.asp-q-options {
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.asp-q-option {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    border: 1.5px solid var(--asp-border);
    border-radius: var(--asp-radius-sm);
    cursor: pointer;
    font-size: 14px;
    font-family: var(--asp-font);
    background: #FAFAFA;
    transition: var(--asp-transition);
    text-align: left;
    color: var(--asp-text);
}
.asp-q-option:hover:not(:disabled) {
    border-color: var(--asp-primary);
    background: var(--asp-primary-light);
    color: var(--asp-primary);
}
.asp-q-option.selected { border-color: var(--asp-primary); background: var(--asp-primary-light); }
.asp-q-option.correct-ans { border-color: var(--asp-success) !important; background: #D1FAE5 !important; color: #065F46 !important; font-weight: 600; }
.asp-q-option.wrong-ans   { border-color: var(--asp-error)   !important; background: #FEE2E2 !important; color: #991B1B !important; }
.asp-q-option:disabled { cursor: default; }

.asp-option-letter {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: var(--asp-border);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 700;
    flex-shrink: 0;
    color: var(--asp-text-muted);
}
.asp-q-option.correct-ans .asp-option-letter { background: var(--asp-success); color: #fff; }
.asp-q-option.wrong-ans   .asp-option-letter { background: var(--asp-error);   color: #fff; }

.asp-quiz-footer {
    display: flex;
    justify-content: flex-end;
    margin-top: 16px;
    gap: 12px;
    flex-wrap: wrap;
}

/* Score result card */
.asp-score-card {
    background: linear-gradient(135deg, var(--asp-primary) 0%, #5B4DD1 100%);
    border-radius: var(--asp-radius);
    padding: 28px 24px;
    text-align: center;
    color: #fff;
    margin-top: 16px;
}
.asp-score-card .asp-score-num {
    font-size: 52px;
    font-weight: 700;
    line-height: 1;
    margin-bottom: 6px;
}
.asp-score-card .asp-score-label {
    font-size: 16px;
    opacity: 0.85;
    margin-bottom: 16px;
}
.asp-score-card .asp-score-emoji { font-size: 36px; }

/* ============================================================
   GLOBAL ALERT / TOAST
   ============================================================ */
.asp-global-alert {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 9999;
    background: var(--asp-text);
    color: #fff;
    padding: 13px 22px;
    border-radius: var(--asp-radius-sm);
    font-size: 14px;
    font-weight: 500;
    font-family: var(--asp-font);
    box-shadow: var(--asp-shadow-lg);
    max-width: 320px;
    animation: asp-slideIn 0.25s ease;
}
.asp-global-alert.error { background: var(--asp-error); }
.asp-global-alert.success { background: var(--asp-success); }

/* ============================================================
   LOADING SPINNER
   ============================================================ */
.asp-spinner {
    display: inline-block;
    width: 18px;
    height: 18px;
    border: 2px solid rgba(255,255,255,0.4);
    border-top-color: #fff;
    border-radius: 50%;
    animation: asp-spin 0.7s linear infinite;
    vertical-align: middle;
    margin-right: 6px;
}

/* ============================================================
   ANIMATIONS
   ============================================================ */
@keyframes asp-spin {
    to { transform: rotate(360deg); }
}
@keyframes asp-fadeUp {
    from { opacity: 0; transform: translateY(12px); }
    to   { opacity: 1; transform: translateY(0); }
}
@keyframes asp-slideIn {
    from { opacity: 0; transform: translateX(20px); }
    to   { opacity: 1; transform: translateX(0); }
}

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 600px) {
    .asp-auth-card { padding: 28px 20px; }
    .asp-panels { padding: 16px; }
    .asp-header { padding: 12px 16px; }
    .asp-logo-text { font-size: 15px; }
    .asp-tab-btn { padding: 12px 14px; font-size: 13px; }
    .asp-tab-label { display: none; }
    .asp-tab-icon { font-size: 20px; }
    .asp-lang-bar { padding: 10px 16px; }
    .asp-user-name { display: none; }
    .asp-result-box { padding: 16px; }
}

/* ============================================================
   PHASE 2 — Difficulty Pills
   ============================================================ */
.asp-difficulty-pills {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}
.asp-diff-btn {
    padding: 7px 18px;
    border-radius: 20px;
    border: 1.5px solid var(--asp-border);
    background: #FAFAFA;
    color: var(--asp-text-muted);
    font-size: 13px;
    font-weight: 600;
    font-family: var(--asp-font);
    cursor: pointer;
    transition: var(--asp-transition);
}
.asp-diff-btn:hover { border-color: var(--asp-primary); color: var(--asp-primary); }
.asp-diff-btn.active {
    background: var(--asp-primary);
    border-color: var(--asp-primary);
    color: #fff;
}
.asp-diff-btn[data-diff="Easy"].active   { background: #059669; border-color: #059669; }
.asp-diff-btn[data-diff="Medium"].active { background: #D97706; border-color: #D97706; }
.asp-diff-btn[data-diff="Hard"].active   { background: #DC2626; border-color: #DC2626; }

/* Difficulty badge in quiz header */
.asp-diff-badge {
    display: inline-block;
    padding: 3px 12px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 700;
    margin-left: 10px;
}
.asp-diff-badge.Easy   { background: #D1FAE5; color: #065F46; }
.asp-diff-badge.Medium { background: #FEF3C7; color: #92400E; }
.asp-diff-badge.Hard   { background: #FEE2E2; color: #991B1B; }

/* Cache hit indicator */
.asp-cache-badge {
    display: inline-block;
    background: #F0FDF4;
    color: #065F46;
    border: 1px solid #6EE7B7;
    border-radius: 12px;
    padding: 2px 10px;
    font-size: 11px;
    font-weight: 600;
    margin-left: 8px;
    vertical-align: middle;
}

/* ============================================================
   PHASE 2 — Mistake Analyzer
   ============================================================ */
.asp-result-mistake {
    border-left: 4px solid var(--asp-primary);
}

/* ============================================================
   PHASE 2 — History
   ============================================================ */
.asp-history-filters {
    display: flex;
    align-items: flex-end;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 20px;
    padding: 16px;
    background: var(--asp-primary-light);
    border-radius: var(--asp-radius);
}
.asp-field-inline {
    display: flex;
    flex-direction: column;
    gap: 5px;
    margin-bottom: 0;
}
.asp-field-inline label { font-size: 12px; font-weight: 600; color: var(--asp-primary); }
.asp-field-inline select { padding: 8px 12px; font-size: 13px; min-width: 140px; }
.asp-btn-sm { padding: 8px 16px; font-size: 13px; }

.asp-history-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.asp-history-empty {
    text-align: center;
    padding: 40px 20px;
    color: var(--asp-text-muted);
    font-size: 14px;
}

.asp-history-item {
    background: #fff;
    border: 1.5px solid var(--asp-border);
    border-radius: var(--asp-radius);
    overflow: hidden;
    transition: var(--asp-transition);
}
.asp-history-item:hover { border-color: #C7CDF5; }

.asp-hist-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    cursor: pointer;
    gap: 10px;
    flex-wrap: wrap;
}
.asp-hist-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    flex: 1;
    min-width: 0;
}
.asp-hist-feature-badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 10px;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    flex-shrink: 0;
}
.asp-hist-feature-badge.doubt_solver    { background: #EEF0FF; color: var(--asp-primary); }
.asp-hist-feature-badge.quiz_generator  { background: #FEF3C7; color: #92400E; }
.asp-hist-feature-badge.short_notes     { background: #D1FAE5; color: #065F46; }
.asp-hist-feature-badge.mistake_analyzer{ background: #FEE2E2; color: #991B1B; }

.asp-hist-topic {
    font-size: 14px;
    font-weight: 600;
    color: var(--asp-text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 280px;
}
.asp-hist-sub-info {
    font-size: 12px;
    color: var(--asp-text-muted);
    flex-shrink: 0;
}
.asp-hist-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}
.asp-hist-toggle {
    background: none;
    border: none;
    font-size: 18px;
    cursor: pointer;
    color: var(--asp-text-muted);
    padding: 2px 6px;
    transition: var(--asp-transition);
}
.asp-hist-toggle:hover { color: var(--asp-primary); }
.asp-hist-delete {
    background: none;
    border: 1px solid var(--asp-border);
    border-radius: 6px;
    padding: 4px 10px;
    font-size: 12px;
    color: var(--asp-error);
    cursor: pointer;
    font-family: var(--asp-font);
    transition: var(--asp-transition);
}
.asp-hist-delete:hover { background: #FEE2E2; border-color: var(--asp-error); }

.asp-hist-body {
    padding: 0 16px 16px;
    font-size: 13.5px;
    line-height: 1.7;
    color: var(--asp-text);
    border-top: 1px solid var(--asp-border);
    display: none;
    white-space: pre-wrap;
    word-break: break-word;
    background: #FAFBFF;
}
.asp-hist-body.open { display: block; }

/* Pagination */
.asp-history-pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 16px;
    margin-top: 20px;
    padding-top: 16px;
    border-top: 1px solid var(--asp-border);
}
#asp-hist-page-info {
    font-size: 13px;
    color: var(--asp-text-muted);
    font-weight: 500;
}

/* ── Text-to-Speech Button ─────────────────────────── */
.asp-tts-btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    background: none;
    border: 1px solid var(--asp-border);
    color: var(--asp-text-muted);
    border-radius: 6px;
    padding: 4px 12px;
    font-size: 13px;
    cursor: pointer;
    margin: 0 6px 10px 0;
    transition: all .18s;
}
.asp-tts-btn:hover { background: #f0f0ff; border-color: var(--asp-primary); color: var(--asp-primary); }

/* ── Print Button ──────────────────────────────────── */
.asp-print-btn {
    margin-top: 4px;
}

/* ── Image Upload ──────────────────────────────────── */
#image-upload {
    display: block;
    width: 100%;
    padding: 10px;
    border: 2px dashed var(--asp-border);
    border-radius: 10px;
    background: #fafbff;
    font-size: 14px;
    cursor: pointer;
    transition: border-color .2s;
}
#image-upload:hover { border-color: var(--asp-primary); }
#asp-image-submit:disabled { opacity: .5; cursor: not-allowed; }

/* ── Scores Panel ──────────────────────────────────── */
.asp-score-stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
    gap: 14px;
    margin-bottom: 6px;
}
.asp-stat-card {
    background: linear-gradient(135deg, #f5f3ff 0%, #ede9fe 100%);
    border: 1px solid #ddd6fe;
    border-radius: 12px;
    padding: 18px 12px;
    text-align: center;
}
.asp-stat-num {
    font-size: 26px;
    font-weight: 700;
    color: var(--asp-primary);
    line-height: 1.1;
}
.asp-stat-label {
    font-size: 12px;
    color: var(--asp-text-muted);
    margin-top: 4px;
    font-weight: 500;
}
.asp-subject-bars { display: flex; flex-direction: column; gap: 10px; }
.asp-subj-bar-row { display: flex; align-items: center; gap: 10px; }
.asp-subj-label   { min-width: 120px; font-size: 13px; font-weight: 600; color: var(--asp-text); }
.asp-subj-bar-wrap {
    flex: 1;
    background: #e5e7eb;
    border-radius: 6px;
    height: 12px;
    overflow: hidden;
}
.asp-subj-bar {
    height: 12px;
    border-radius: 6px;
    transition: width .5s ease;
}
.asp-subj-pct { font-size: 13px; font-weight: 600; min-width: 160px; color: var(--asp-text); }
.asp-subj-pct small { font-weight: 400; color: var(--asp-text-muted); }

.asp-scores-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13.5px;
    margin-top: 4px;
}
.asp-scores-table th {
    background: #f5f3ff;
    padding: 8px 12px;
    text-align: left;
    font-size: 12px;
    font-weight: 600;
    color: var(--asp-text-muted);
    border-bottom: 2px solid #ddd6fe;
}
.asp-scores-table td {
    padding: 9px 12px;
    border-bottom: 1px solid var(--asp-border);
    color: var(--asp-text);
}
.asp-scores-table tr:last-child td { border-bottom: none; }
.asp-scores-table tr:hover td { background: #fafbff; }

@media (max-width: 540px) {
    .asp-subj-label  { min-width: 80px; font-size: 12px; }
    .asp-subj-pct    { min-width: auto; font-size: 12px; }
    .asp-scores-table th, .asp-scores-table td { padding: 7px 8px; font-size: 12px; }
    .asp-score-stats-grid { grid-template-columns: 1fr 1fr; }
}

/* ── Image Attach Widget (all tools) ──────────────────── */
.asp-img-widget {
    margin: 10px 0 14px;
    border: 1px dashed var(--asp-border);
    border-radius: 10px;
    padding: 12px 14px;
    background: #fafbff;
}
.asp-img-widget-btns {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}
.asp-imgw-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 16px;
    border: 1.5px solid var(--asp-border);
    border-radius: 8px;
    background: #fff;
    color: var(--asp-text);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all .18s;
    position: relative;
    overflow: hidden;
}
.asp-imgw-btn:hover {
    border-color: var(--asp-primary);
    color: var(--asp-primary);
    background: #f5f3ff;
}
/* hide the actual file input but keep it clickable via label */
.asp-file-input {
    position: absolute;
    inset: 0;
    opacity: 0;
    cursor: pointer;
    width: 100%;
}
.asp-cam-btn { cursor: pointer; }

/* Preview strip */
.asp-imgw-preview {
    margin-top: 10px;
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}
.asp-imgw-preview img {
    max-height: 80px;
    max-width: 120px;
    border-radius: 6px;
    border: 1px solid var(--asp-border);
    object-fit: cover;
}
.asp-imgw-remove {
    background: none;
    border: 1px solid #fca5a5;
    color: #dc2626;
    border-radius: 6px;
    padding: 3px 10px;
    font-size: 12px;
    cursor: pointer;
    transition: background .15s;
}
.asp-imgw-remove:hover { background: #fee2e2; }
.asp-imgw-label {
    font-size: 12px;
    color: #065f46;
    background: rgba(16,185,129,.1);
    border-radius: 6px;
    padding: 3px 9px;
}

/* Camera modal — fixed overlay so it's never clipped on mobile */
.asp-cam-modal {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 99999;
    background: rgba(0,0,0,.92);
    display: -webkit-box;
    display: -ms-flexbox;
    display: flex;
    -webkit-box-align: center;
        -ms-flex-align: center;
            align-items: center;
    -webkit-box-pack: center;
        -ms-flex-pack: center;
            justify-content: center;
    padding: 16px;
    -webkit-box-sizing: border-box;
            box-sizing: border-box;
}
.asp-cam-inner {
    position: relative;
    width: 100%;
    max-width: 520px;
    border-radius: 14px;
    overflow: hidden;
    background: #000;
    box-shadow: 0 8px 40px rgba(0,0,0,.6);
}
.asp-cam-inner video {
    display: block;
    width: 100%;
    max-height: 60vh;
    object-fit: cover;
    background: #111;
}
.asp-cam-controls {
    display: flex;
    gap: 12px;
    justify-content: center;
    padding: 14px 16px;
    background: rgba(0,0,0,.75);
}
.asp-cam-controls .asp-btn {
    min-width: 140px;
    font-size: 15px;
    padding: 10px 18px;
}
.asp-snap-btn {
    background: var(--asp-primary) !important;
    color: #fff !important;
}
.asp-snap-btn:hover {
    background: var(--asp-primary-dark, #4338ca) !important;
}

@media (max-width: 480px) {
    .asp-img-widget-btns { flex-direction: column; }
    .asp-imgw-btn { width: 100%; justify-content: center; }
}

/* ============================================================
   DARK MODE
   ============================================================ */
html.asp-dark {
    --asp-bg:           #0f1117;
    --asp-card:         #1a1d27;
    --asp-border:       #2d3148;
    --asp-text:         #e8eaf6;
    --asp-text-muted:   #9096b8;
    --asp-primary-light:#1e2044;
    --asp-shadow:       0 2px 16px rgba(0,0,0,0.4);
    --asp-shadow-lg:    0 8px 32px rgba(0,0,0,0.5);
}
html.asp-dark body,
html.asp-dark #asp-dashboard { background: var(--asp-bg); color: var(--asp-text); }
html.asp-dark .asp-header    { background: #12152a; border-color: var(--asp-border); }
html.asp-dark .asp-lang-bar  { background: #12152a; border-color: var(--asp-border); }
html.asp-dark .asp-tabs-nav  { background: #12152a; border-color: var(--asp-border); }
html.asp-dark .asp-tab-btn   { color: var(--asp-text-muted); }
html.asp-dark .asp-tab-btn.active { background: var(--asp-card); color: var(--asp-text); }
html.asp-dark .asp-panel,
html.asp-dark .asp-panels    { background: var(--asp-bg); }
html.asp-dark .asp-feature-form,
html.asp-dark .asp-result-box,
html.asp-dark .asp-history-item,
html.asp-dark .asp-score-stats-grid .asp-stat-card { background: var(--asp-card); border-color: var(--asp-border); }
html.asp-dark input,
html.asp-dark textarea,
html.asp-dark select          { background: #1e2236; color: var(--asp-text); border-color: var(--asp-border); }
html.asp-dark input::placeholder,
html.asp-dark textarea::placeholder { color: var(--asp-text-muted); }
html.asp-dark .asp-img-widget { background: #1a1d27; border-color: var(--asp-border); }
html.asp-dark .asp-imgw-btn   { background: #1e2236; border-color: var(--asp-border); color: var(--asp-text); }
html.asp-dark .asp-result-box { background: var(--asp-card); color: var(--asp-text); }
html.asp-dark .asp-hist-body  { background: #12152a; color: var(--asp-text); }
html.asp-dark .asp-scores-table th { background: #1a1d27; color: var(--asp-text-muted); }
html.asp-dark .asp-scores-table td { color: var(--asp-text); }
html.asp-dark .asp-fc-card    { background: var(--asp-card); border-color: var(--asp-border); }
html.asp-dark .asp-fc-front,
html.asp-dark .asp-fc-back    { background: var(--asp-card); color: var(--asp-text); }

/* Dark mode toggle button */
.asp-darkmode-btn {
    background: none;
    border: 1px solid var(--asp-border);
    border-radius: 8px;
    padding: 5px 10px;
    font-size: 16px;
    cursor: pointer;
    color: var(--asp-text);
    transition: var(--asp-transition);
    margin-left: 6px;
}
.asp-darkmode-btn:hover { background: var(--asp-primary-light); }

/* ============================================================
   FLASHCARD COMPONENT
   ============================================================ */
.asp-fc-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 12px;
    margin-bottom: 20px;
}
.asp-fc-header h3 { margin: 0; font-size: 17px; color: var(--asp-text); }
.asp-fc-count     { font-size: 13px; font-weight: 400; color: var(--asp-text-muted); }
.asp-fc-nav       { display: flex; align-items: center; gap: 12px; }
#asp-fc-indicator { font-size: 14px; font-weight: 600; color: var(--asp-text-muted); min-width: 60px; text-align: center; }

.asp-fc-stage {
    display: flex;
    justify-content: center;
    margin-bottom: 16px;
    min-height: 220px;
}

.asp-fc-card {
    width: 100%;
    max-width: 560px;
    min-height: 200px;
    perspective: 1000px;
    cursor: pointer;
    display: none;
}
.asp-fc-card.active { display: block; }

.asp-fc-inner {
    position: relative;
    width: 100%;
    min-height: 200px;
    transition: transform 0.5s ease;
    transform-style: preserve-3d;
}
.asp-fc-card.flipped .asp-fc-inner { transform: rotateY(180deg); }

.asp-fc-front,
.asp-fc-back {
    position: absolute;
    inset: 0;
    border-radius: var(--asp-radius);
    border: 2px solid var(--asp-border);
    background: var(--asp-card);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 28px 24px;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
    text-align: center;
    box-shadow: var(--asp-shadow);
}
.asp-fc-back {
    transform: rotateY(180deg);
    background: var(--asp-primary-light);
    border-color: var(--asp-primary);
}
.asp-fc-label {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .7px;
    color: var(--asp-text-muted);
    margin-bottom: 12px;
}
.asp-fc-text {
    font-size: 16px;
    font-weight: 500;
    color: var(--asp-text);
    line-height: 1.6;
}
.asp-fc-back .asp-fc-text { color: var(--asp-primary); font-weight: 600; }
.asp-fc-hint {
    font-size: 11px;
    color: var(--asp-text-muted);
    margin-top: 16px;
    opacity: 0.7;
}

.asp-fc-footer {
    display: flex;
    justify-content: center;
    gap: 12px;
    margin-top: 4px;
}

@media (max-width: 480px) {
    .asp-fc-header { flex-direction: column; align-items: flex-start; }
    .asp-fc-card { min-height: 180px; }
    .asp-fc-text { font-size: 14px; }
}

/* ============================================================
   INPUT MODE TABS (Type / Image switcher per tool)
   ============================================================ */
.asp-input-mode-tabs {
    display: flex;
    gap: 0;
    margin-bottom: 18px;
    border-radius: var(--asp-radius-sm);
    overflow: hidden;
    border: 1.5px solid var(--asp-border);
    width: fit-content;
}
.asp-imt-btn {
    padding: 8px 22px;
    background: #f9fafb;
    border: none;
    border-right: 1.5px solid var(--asp-border);
    font-size: 13px;
    font-weight: 600;
    color: var(--asp-text-muted);
    cursor: pointer;
    font-family: var(--asp-font);
    transition: var(--asp-transition);
}
.asp-imt-btn:last-child { border-right: none; }
.asp-imt-btn.active {
    background: var(--asp-primary);
    color: #fff;
}
.asp-imt-btn:hover:not(.active) {
    background: var(--asp-primary-light);
    color: var(--asp-primary);
}
html.asp-dark .asp-imt-btn         { background: #1e2236; color: var(--asp-text-muted); border-color: var(--asp-border); }
html.asp-dark .asp-imt-btn.active  { background: var(--asp-primary); color: #fff; }

/* ── History: Quiz rendering ──────────────────────── */
.asp-hist-quiz { padding: 4px 0; }
.asp-hq-item   { margin-bottom: 14px; padding-bottom: 10px; border-bottom: 1px solid var(--asp-border); }
.asp-hq-item:last-child { border-bottom: none; }
.asp-hq-q      { margin: 0 0 6px; font-size: 13.5px; color: var(--asp-text); }
.asp-hq-opts   { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 4px; }
.asp-hq-opts li { font-size: 13px; padding: 4px 8px; border-radius: 5px; color: var(--asp-text); }
.asp-hq-correct { background: rgba(16,185,129,.12); color: #065f46 !important; font-weight: 600; }
.asp-hq-letter  { font-weight: 700; margin-right: 4px; }
.asp-hq-tick    { margin-left: 6px; color: #16a34a; }

/* ── History: Flashcard rendering ─────────────────── */
.asp-hist-flashcards { display: flex; flex-direction: column; gap: 8px; }
.asp-hfc-row { border: 1px solid var(--asp-border); border-radius: 8px; overflow: hidden; }
.asp-hfc-q   { padding: 7px 12px; background: var(--asp-primary-light); font-size: 13px; font-weight: 600; color: var(--asp-primary); }
.asp-hfc-a   { padding: 7px 12px; font-size: 13px; color: var(--asp-text); }

/* ── KaTeX display math centering ─────────────────── */
.katex-display { overflow-x: auto; padding: 4px 0; }
.katex { font-size: 1.05em; }
