/* ============================================================
   ANAC PLA Simulado - Light/Dark Theme
   ============================================================ */

/* ---- Light theme (default) ---- */
:root {
    --bg: #f5f5f7;
    --bg-card: #ffffff;
    --bg-hover: #f0f0f2;
    --text: #1a1a1a;
    --text-muted: #6b7280;
    --text-dim: #9ca3af;
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --success: #16a34a;
    --success-bg: rgba(22, 163, 74, 0.1);
    --error: #dc2626;
    --error-bg: rgba(220, 38, 38, 0.08);
    --warning: #d97706;
    --warning-bg: rgba(217, 119, 6, 0.08);
    --border: #e5e7eb;
    --border-light: #d1d5db;
    --radius: 8px;
    --radius-lg: 12px;
    --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.04);
    --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.08), 0 2px 4px -2px rgba(0,0,0,0.04);
    --transition: 150ms ease;
    --toggle-bg: #e5e7eb;
}

/* ---- Dark theme ---- */
[data-theme="dark"] {
    --bg: #111118;
    --bg-card: #1a1a24;
    --bg-hover: #22222e;
    --text: #e8e8ec;
    --text-muted: #9ca3af;
    --text-dim: #6b7280;
    --primary: #3b82f6;
    --primary-hover: #2563eb;
    --success: #22c55e;
    --success-bg: rgba(34, 197, 94, 0.12);
    --error: #ef4444;
    --error-bg: rgba(239, 68, 68, 0.1);
    --warning: #f59e0b;
    --warning-bg: rgba(245, 158, 11, 0.1);
    --border: #2a2a36;
    --border-light: #3a3a48;
    --shadow: 0 1px 3px rgba(0,0,0,0.3), 0 1px 2px rgba(0,0,0,0.2);
    --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.3), 0 2px 4px -2px rgba(0,0,0,0.2);
    --toggle-bg: #2a2a36;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
}

#app {
    max-width: 800px;
    margin: 0 auto;
    padding: 16px;
}

/* ---- Typography ---- */
h1 { font-size: 1.75rem; font-weight: 700; margin-bottom: 4px; }
h2 { font-size: 1.25rem; font-weight: 600; margin-bottom: 12px; color: var(--text); }
h3 { font-size: 1rem; font-weight: 600; margin-bottom: 8px; }
.subtitle { color: var(--text-muted); font-size: 0.9rem; margin-bottom: 24px; }

/* ---- Buttons ---- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 20px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-card);
    color: var(--text);
    font-size: 0.95rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition);
    text-decoration: none;
    box-shadow: var(--shadow);
}
.btn:hover { background: var(--bg-hover); border-color: var(--border-light); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-success { background: var(--success); border-color: var(--success); color: #fff; }
.btn-error { background: var(--error); border-color: var(--error); color: #fff; }
.btn-sm { padding: 6px 12px; font-size: 0.85rem; }
.btn-block { display: flex; width: 100%; }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* ---- Cards ---- */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 20px;
    margin-bottom: 16px;
    box-shadow: var(--shadow);
}

/* ---- Header ---- */
.header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 0;
    margin-bottom: 20px;
    border-bottom: 1px solid var(--border);
}
.header h1 { font-size: 1.2rem; margin: 0; }

/* ---- Top Bar (theme + bank toggles) ---- */
.top-bar {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 16px;
    padding: 8px 0;
    margin-bottom: 4px;
}

.toggle-group {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.8rem;
    color: var(--text-muted);
}

.bank-selector {
    display: flex;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}
.bank-btn {
    padding: 5px 12px;
    font-size: 0.75rem;
    font-weight: 600;
    border: none;
    background: var(--bg-card);
    color: var(--text-muted);
    cursor: pointer;
    transition: all var(--transition);
}
.bank-btn:not(:last-child) { border-right: 1px solid var(--border); }
.bank-btn:hover { background: var(--bg-hover); }
.bank-btn.active { background: var(--primary); color: #fff; }

.toggle-switch {
    position: relative;
    width: 40px;
    height: 22px;
    background: var(--toggle-bg);
    border-radius: 11px;
    cursor: pointer;
    transition: background var(--transition);
    border: 1px solid var(--border);
}
.toggle-switch::after {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 16px;
    height: 16px;
    background: #fff;
    border-radius: 50%;
    transition: transform var(--transition);
    box-shadow: 0 1px 2px rgba(0,0,0,0.2);
}
.toggle-switch.active {
    background: var(--primary);
    border-color: var(--primary);
}
.toggle-switch.active::after {
    transform: translateX(18px);
}

/* ---- Verification badge ---- */
.verified-badge {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    font-size: 0.65rem;
    font-weight: 600;
    padding: 2px 6px;
    border-radius: 10px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}
.verified-badge.verified {
    background: var(--success-bg);
    color: var(--success);
    border: 1px solid rgba(22, 163, 74, 0.2);
}
.verified-badge.ai {
    background: var(--warning-bg);
    color: var(--warning);
    border: 1px solid rgba(217, 119, 6, 0.2);
}
.verified-badge.unverified {
    background: var(--error-bg);
    color: var(--error);
    border: 1px solid rgba(220, 38, 38, 0.2);
}

/* ---- Home Screen ---- */
.home-title {
    text-align: center;
    padding: 32px 0 8px;
}
.home-title h1 { font-size: 2rem; color: var(--primary); }
.home-title .subtitle { margin-top: 4px; }

.stats-bar {
    display: flex;
    gap: 12px;
    margin-bottom: 24px;
    flex-wrap: wrap;
}
.stat-item {
    flex: 1;
    min-width: 100px;
    text-align: center;
    padding: 14px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}
.stat-value { font-size: 1.5rem; font-weight: 700; color: var(--primary); }
.stat-label { font-size: 0.75rem; color: var(--text-muted); margin-top: 2px; }

/* ---- Subject Grid ---- */
.subject-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 8px;
    margin-bottom: 20px;
}
.subject-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    transition: all var(--transition);
    user-select: none;
    box-shadow: var(--shadow);
}
.subject-item:hover { border-color: var(--primary); }
.subject-item.selected { border-color: var(--primary); background: rgba(37,99,235,0.04); }
.subject-item.empty { opacity: 0.4; cursor: not-allowed; }
.subject-item.empty:hover { border-color: var(--border); }
[data-theme="dark"] .subject-item.selected { background: rgba(59,130,246,0.08); }
.subject-item input[type="checkbox"] {
    width: 18px; height: 18px; accent-color: var(--primary);
}
.subject-name { font-size: 0.9rem; font-weight: 600; flex: 1; }
.subject-count { font-size: 0.8rem; color: var(--text-muted); font-weight: 500; }

/* ---- Mode Buttons ---- */
.mode-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-bottom: 24px;
}
.mode-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 20px 16px;
    background: var(--bg-card);
    border: 2px solid var(--border);
    border-radius: var(--radius-lg);
    cursor: pointer;
    transition: all var(--transition);
    text-align: center;
    box-shadow: var(--shadow);
}
.mode-btn:hover { border-color: var(--primary); transform: translateY(-1px); box-shadow: var(--shadow-md); }
.mode-btn.active { border-color: var(--primary); background: rgba(37,99,235,0.04); }
[data-theme="dark"] .mode-btn.active { background: rgba(59,130,246,0.08); }
.mode-icon { font-size: 1.5rem; }
.mode-title { font-weight: 600; font-size: 0.95rem; }
.mode-desc { font-size: 0.75rem; color: var(--text-muted); }

/* ---- Exam Screen ---- */
.exam-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
    flex-wrap: wrap;
    gap: 8px;
}
.exam-progress {
    font-size: 0.85rem;
    color: var(--text-muted);
}
.progress-bar {
    width: 100%;
    height: 4px;
    background: var(--border);
    border-radius: 2px;
    margin-bottom: 20px;
    overflow: hidden;
}
.progress-fill {
    height: 100%;
    background: var(--primary);
    border-radius: 2px;
    transition: width 300ms ease;
}

.subject-badge {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.question-stem {
    font-size: 1.05rem;
    line-height: 1.7;
    margin: 16px 0 20px;
    padding: 16px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

/* ---- Option Buttons ---- */
.options-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 20px; }
.option-btn {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 14px 16px;
    background: var(--bg-card);
    border: 2px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    transition: all var(--transition);
    text-align: left;
    font-size: 0.95rem;
    line-height: 1.5;
    width: 100%;
    box-shadow: var(--shadow);
}
.option-btn:hover { border-color: var(--primary); background: rgba(37,99,235,0.03); }
.option-btn.selected { border-color: var(--primary); background: rgba(37,99,235,0.06); }
.option-btn.correct { border-color: var(--success); background: var(--success-bg); }
.option-btn.wrong { border-color: var(--error); background: var(--error-bg); }
.option-btn.disabled { pointer-events: none; }
.option-letter {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--bg);
    border: 2px solid var(--border);
    font-weight: 700;
    font-size: 0.85rem;
    flex-shrink: 0;
    color: var(--text-muted);
}
.option-btn.selected .option-letter { background: var(--primary); border-color: var(--primary); color: #fff; }
.option-btn.correct .option-letter { background: var(--success); border-color: var(--success); color: #fff; }
.option-btn.wrong .option-letter { background: var(--error); border-color: var(--error); color: #fff; }
.option-text { flex: 1; padding-top: 2px; }

/* ---- Flash Mode (Pratica Rapida) ---- */
.flash-score-bar {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 10px 16px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.9rem;
    box-shadow: var(--shadow);
}

.flash-feedback {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px;
    border-radius: var(--radius);
    margin-bottom: 12px;
    animation: flashSlideIn 200ms ease;
}
.flash-feedback.correct {
    background: var(--success-bg);
    border: 2px solid var(--success);
    color: var(--success);
}
.flash-feedback.wrong {
    background: var(--error-bg);
    border: 2px solid var(--error);
    color: var(--error);
}
.flash-feedback-icon {
    font-size: 1.8rem;
    font-weight: 700;
    flex-shrink: 0;
}
.flash-feedback-text {
    font-size: 1rem;
    font-weight: 600;
}

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

.flash-options .btn.active {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
}

.flash-source-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 8px;
}

.flash-source {
    font-size: 0.85rem;
}

/* ---- Bank Selector (ANAC vs Todas) ---- */
.bank-selector {
    display: inline-flex;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    background: var(--bg-card);
}
.bank-btn {
    padding: 6px 14px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition);
}
.bank-btn:not(:last-child) { border-right: 1px solid var(--border); }
.bank-btn:hover { background: var(--bg-hover); }
.bank-btn.active { background: var(--primary); color: #fff; }

.warning-banner {
    background: var(--warning-bg);
    border: 1px solid var(--warning);
    color: var(--warning);
    padding: 10px 14px;
    border-radius: var(--radius);
    font-size: 0.85rem;
    font-weight: 500;
    margin-bottom: 16px;
    text-align: center;
}

.prev-mistake-badge {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    font-size: 0.65rem;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 10px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    background: var(--error-bg);
    color: var(--error);
    border: 1px solid rgba(220, 38, 38, 0.2);
}

.comment-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: var(--primary);
    color: #fff;
    border: none;
    font-weight: 700;
    font-size: 0.8rem;
    cursor: pointer;
    transition: all var(--transition);
}
.comment-icon:hover { background: var(--primary-hover); }

/* ---- Flag Button ---- */
.flag-btn {
    background: none;
    border: none;
    font-size: 1.3rem;
    cursor: pointer;
    padding: 4px 8px;
    opacity: 0.3;
    transition: all var(--transition);
}
.flag-btn:hover { opacity: 0.6; }
.flag-btn.flagged { opacity: 1; }

/* ---- Question Nav Grid ---- */
.nav-grid {
    display: grid;
    grid-template-columns: repeat(10, 1fr);
    gap: 4px;
    margin-bottom: 16px;
}
.nav-cell {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 32px;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 600;
    cursor: pointer;
    background: var(--bg-card);
    border: 1px solid var(--border);
    transition: all var(--transition);
    position: relative;
    color: var(--text-muted);
}
.nav-cell:hover { border-color: var(--primary); }
.nav-cell.current { border-color: var(--primary); background: rgba(37,99,235,0.1); color: var(--primary); font-weight: 700; }
.nav-cell.answered { background: var(--bg-hover); color: var(--text); }
.nav-cell.flagged-cell::after { content: ''; position: absolute; top: 2px; right: 2px; width: 5px; height: 5px; background: var(--warning); border-radius: 50%; }

/* ---- Exam Footer ---- */
.exam-nav {
    display: flex;
    gap: 8px;
    justify-content: space-between;
    align-items: center;
    margin-top: 16px;
}

/* ---- Results Screen ---- */
.result-summary {
    text-align: center;
    padding: 24px;
    margin-bottom: 20px;
}
.result-score {
    font-size: 3rem;
    font-weight: 800;
}
.result-score.pass { color: var(--success); }
.result-score.fail { color: var(--error); }
.result-detail { color: var(--text-muted); margin-top: 4px; }

.subject-breakdown {
    margin-bottom: 24px;
}
.breakdown-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 0;
    border-bottom: 1px solid var(--border);
}
.breakdown-name { flex: 1; font-size: 0.85rem; font-weight: 600; min-width: 120px; }
.breakdown-bar-wrap {
    flex: 2;
    height: 8px;
    background: var(--border);
    border-radius: 4px;
    overflow: hidden;
}
.breakdown-bar {
    height: 100%;
    border-radius: 4px;
    transition: width 500ms ease;
}
.breakdown-score { font-size: 0.85rem; font-weight: 600; min-width: 60px; text-align: right; }

/* ---- Review List ---- */
.review-filters {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}
.filter-btn {
    padding: 6px 14px;
    border-radius: 20px;
    font-size: 0.8rem;
    border: 1px solid var(--border);
    background: var(--bg-card);
    color: var(--text-muted);
    cursor: pointer;
    transition: all var(--transition);
}
.filter-btn:hover { border-color: var(--text-muted); }
.filter-btn.active { background: var(--primary); border-color: var(--primary); color: #fff; }

.review-item {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 12px;
    background: var(--bg-card);
    box-shadow: var(--shadow);
}
.review-item.wrong { border-left: 3px solid var(--error); }
.review-item.right { border-left: 3px solid var(--success); }

.review-stem {
    font-size: 0.9rem;
    margin-bottom: 12px;
    line-height: 1.6;
    font-weight: 500;
}
.review-options { margin-bottom: 12px; }
.review-option {
    padding: 6px 10px;
    font-size: 0.85rem;
    border-radius: 4px;
    margin-bottom: 4px;
}
.review-option.correct-opt { background: var(--success-bg); color: var(--success); font-weight: 600; }
.review-option.wrong-opt { background: var(--error-bg); color: var(--error); text-decoration: line-through; }

.comment-box {
    margin-top: 12px;
    padding: 12px;
    background: rgba(37,99,235,0.04);
    border: 1px solid rgba(37,99,235,0.15);
    border-radius: var(--radius);
    font-size: 0.85rem;
    line-height: 1.6;
    color: var(--text-muted);
}
.comment-box strong { color: var(--primary); }

.history-chips {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    margin-top: 8px;
}
.history-chip {
    display: inline-block;
    padding: 2px 8px;
    font-size: 0.7rem;
    border-radius: 10px;
    border: 1px solid var(--border);
    font-weight: 500;
}
.history-chip.was-right { border-color: var(--success); color: var(--success); }
.history-chip.was-wrong { border-color: var(--error); color: var(--error); }

/* ---- Responsive (iPhone 15 Pro: 393px viewport) ---- */
@media (max-width: 600px) {
    #app {
        padding: 12px;
        padding-top: env(safe-area-inset-top, 12px);
        padding-bottom: calc(env(safe-area-inset-bottom, 0px) + 12px);
    }

    h1 { font-size: 1.5rem; }
    h2 { font-size: 1.1rem; margin-bottom: 10px; }
    h3 { font-size: 0.95rem; }

    .home-title { padding: 20px 0 4px; }
    .home-title h1 { font-size: 1.75rem; }
    .subtitle { font-size: 0.82rem; margin-bottom: 16px; }

    .top-bar { gap: 10px; }
    .toggle-group { font-size: 0.7rem; }

    .stats-bar {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 8px;
        margin-bottom: 20px;
    }
    .stat-item { padding: 10px; min-width: 0; }
    .stat-value { font-size: 1.3rem; }
    .stat-label { font-size: 0.7rem; }

    .subject-grid { grid-template-columns: 1fr; gap: 6px; margin-bottom: 14px; }
    .subject-item { padding: 12px 14px; min-height: 44px; }
    .subject-name { font-size: 0.85rem; }

    .mode-grid { grid-template-columns: 1fr; gap: 8px; margin-bottom: 16px; }
    .mode-btn { padding: 16px 14px; flex-direction: row; gap: 12px; text-align: left; min-height: 44px; }
    .mode-icon { font-size: 1.3rem; flex-shrink: 0; }
    .mode-title { font-size: 0.9rem; }
    .mode-desc { font-size: 0.72rem; }

    .flash-options { padding: 14px; }
    .flash-source-grid { gap: 6px; }
    .flash-source { padding: 8px 12px; font-size: 0.8rem; min-height: 38px; }
    .flash-options .flash-qty { min-height: 38px; }

    .question-stem { font-size: 0.95rem; padding: 14px; margin: 12px 0 16px; line-height: 1.65; }

    .option-btn { padding: 12px 14px; font-size: 0.9rem; min-height: 48px; gap: 10px; }
    .option-letter { width: 26px; height: 26px; font-size: 0.8rem; }

    .nav-grid { grid-template-columns: repeat(8, 1fr); gap: 3px; }
    .nav-cell { height: 36px; font-size: 0.7rem; }

    .exam-nav { margin-top: 12px; }
    .exam-nav .btn { padding: 12px 16px; font-size: 0.9rem; min-height: 44px; }

    .flash-score-bar { padding: 8px 12px; font-size: 0.85rem; gap: 10px; }
    .flash-feedback { padding: 12px; gap: 10px; }
    .flash-feedback-icon { font-size: 1.5rem; }
    .flash-feedback-text { font-size: 0.9rem; }

    .result-score { font-size: 2.5rem; }
    .result-summary { padding: 20px 16px; }
    .result-detail { font-size: 0.82rem; }

    .breakdown-row { gap: 8px; padding: 6px 0; }
    .breakdown-name { font-size: 0.78rem; min-width: 90px; }
    .breakdown-score { font-size: 0.78rem; min-width: 45px; }

    .review-filters { gap: 6px; }
    .filter-btn { padding: 8px 12px; font-size: 0.78rem; min-height: 36px; }

    .review-item { padding: 14px; margin-bottom: 10px; }
    .review-stem { font-size: 0.85rem; }
    .review-option { font-size: 0.8rem; padding: 5px 8px; }

    .comment-box { padding: 10px; font-size: 0.8rem; }

    .btn { font-size: 0.9rem; min-height: 44px; }
    .btn-sm { min-height: 36px; font-size: 0.82rem; }
    .btn-block { padding: 14px; font-size: 1rem; }

    #start-btn { font-size: 1rem !important; padding: 14px !important; }

    /* Prevent iOS zoom on input focus */
    input[type="number"] { font-size: 16px; }
}

/* iOS standalone / PWA safe areas */
@supports (padding: env(safe-area-inset-top)) {
    body {
        padding-left: env(safe-area-inset-left);
        padding-right: env(safe-area-inset-right);
    }
}

/* Disable tap highlight and text select on interactive elements */
.mode-btn, .option-btn, .subject-item, .nav-cell, .flash-source, .flash-qty, .filter-btn {
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
}

/* Smooth scrolling for iOS */
html {
    -webkit-overflow-scrolling: touch;
    scroll-behavior: smooth;
}
