/* ==========================================================================
   Sabiá — Design System · "O canto que ensina"
   Temas: sépia (leitura), claro, escuro. Variáveis consumidas por index.html/app.js.
   ========================================================================== */

:root {
    --primary: #6366f1;
    --primary-hover: #4f46e5;
    --secondary: #0ea5e9;
    --danger: #dc2626;
    --success: #16a34a;
    --radius: 12px;
    --radius-lg: 18px;
    --transition: all 0.18s ease;
    --font-size-base: 16px;
    --font-ui: 'Segoe UI Variable', 'Segoe UI', system-ui, -apple-system, 'Inter', Roboto, 'Helvetica Neue', sans-serif;
    --font-serif: Georgia, 'Iowan Old Style', 'Palatino Linotype', 'Times New Roman', serif;
    --font-mono: ui-monospace, 'Cascadia Code', 'JetBrains Mono', monospace;
    --shadow: 0 10px 30px rgba(20, 16, 60, 0.14);
    --shadow-sm: 0 2px 10px rgba(20, 16, 60, 0.08);
    --shadow-btn: 0 4px 14px rgba(99, 102, 241, 0.28);
    --ring: 0 0 0 3px rgba(99, 102, 241, 0.35);
}

/* ---- Temas ---- */
body.theme-sepia {
    --bg-main: #f3ead6;
    --bg-surface: #efe4cd;
    --bg-surface-elevated: #e7d9bd;
    --text-primary: #3a3128;
    --text-secondary: #5b4f3f;
    --text-muted: #8b7c65;
    --border-color: #dccdae;
    --primary: #9a6a3a;
    --primary-hover: #7f5528;
}
body.theme-light {
    --bg-main: #f5f7fb;
    --bg-surface: #ffffff;
    --bg-surface-elevated: #eef2f9;
    --text-primary: #0f172a;
    --text-secondary: #334155;
    --text-muted: #64748b;
    --border-color: #e2e8f0;
}
body.theme-dark {
    --bg-main: #0b0f19;
    --bg-surface: #131a2a;
    --bg-surface-elevated: #1c2536;
    --text-primary: #e6ecf5;
    --text-secondary: #aeb9cc;
    --text-muted: #7c89a1;
    --border-color: #263044;
    --primary: #818cf8;
    --primary-hover: #6366f1;
    --shadow: 0 6px 24px rgba(0, 0, 0, 0.45);
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    height: 100%;
}

body {
    font-family: var(--font-ui);
    background: var(--bg-main);
    color: var(--text-primary);
    font-size: 14px;
    line-height: 1.55;
    letter-spacing: -0.006em;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
    font-feature-settings: 'kern' 1, 'liga' 1, 'calt' 1;
    transition: background 0.25s ease, color 0.25s ease;
}

h1, h2, h3, h4 { margin: 0; font-weight: 800; color: var(--text-primary); line-height: 1.2; }
h1 { letter-spacing: -0.02em; }
h2 { letter-spacing: -0.018em; }
h3 { letter-spacing: -0.012em; }
p { margin: 0 0 8px; }
a { color: inherit; text-decoration: none; }
small { letter-spacing: 0; }

/* ---- Layout ---- */
.app-layout { display: flex; height: 100vh; overflow: hidden; }

.sidebar {
    width: 300px;
    flex-shrink: 0;
    background: var(--bg-surface);
    border-right: 1px solid var(--border-color);
    padding: 18px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    overflow-y: auto;
}

.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* ---- Brand ---- */
.brand { display: flex; align-items: center; gap: 12px; }
.brand-icon {
    width: 46px; height: 46px;
    display: grid; place-items: center;
    font-size: 24px;
    background: linear-gradient(135deg, #818cf8, #6366f1 55%, #7c3aed);
    border-radius: 13px;
    box-shadow: 0 6px 16px rgba(99, 102, 241, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.3);
}
.brand-text h2 { font-size: 19px; line-height: 1; letter-spacing: -0.02em; }
.brand-text h2 span { color: var(--primary); }
.badge-byok {
    display: inline-block;
    margin-top: 4px;
    font-size: 10px;
    font-weight: 700;
    color: var(--text-muted);
}

/* ---- Cards da sidebar ---- */
.reader-controls-card,
.license-status-card,
.active-material-card {
    background: var(--bg-main);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.widget-title {
    font-size: 11px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--text-muted);
}

.theme-selector-buttons { display: flex; gap: 6px; }
.btn-theme-opt {
    flex: 1;
    padding: 7px 4px;
    font-size: 11px;
    font-weight: 700;
    border: 1px solid var(--border-color);
    background: var(--bg-surface);
    color: var(--text-secondary);
    border-radius: 8px;
    cursor: pointer;
    transition: var(--transition);
}
.btn-theme-opt:hover { border-color: var(--primary); }
.btn-theme-opt.active {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}

.font-size-controls {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}
.btn-font-size {
    width: 34px; height: 30px;
    border: 1px solid var(--border-color);
    background: var(--bg-surface);
    color: var(--text-primary);
    border-radius: 8px;
    font-weight: 800;
    cursor: pointer;
    transition: var(--transition);
}
.btn-font-size:hover { border-color: var(--primary); color: var(--primary); }
.font-size-label { font-size: 11px; color: var(--text-muted); font-weight: 700; }

.license-status-card { border-color: var(--primary); }
.license-status-header { font-size: 13px; font-weight: 800; color: var(--primary); }
.license-status-card p { font-size: 12px; color: var(--text-muted); margin: 0; }

.select-material-dropdown,
.select-material-dropdown:focus {
    width: 100%;
    padding: 9px;
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 13px;
    font-weight: 600;
    outline: none;
}

.material-progress-box { display: flex; flex-direction: column; gap: 6px; }
.progress-info { display: flex; justify-content: space-between; font-size: 11px; color: var(--text-muted); font-weight: 700; }
.progress-bar-bg { height: 8px; background: var(--bg-surface-elevated); border-radius: 999px; overflow: hidden; }
.progress-bar-fill { height: 100%; background: linear-gradient(90deg, var(--primary), var(--secondary)); border-radius: 999px; transition: width 0.4s ease; }

/* ---- Navegação ---- */
.nav-menu { display: flex; flex-direction: column; gap: 4px; }
.nav-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 11px 12px;
    border-radius: 10px;
    font-size: 13px;
    font-weight: 700;
    color: var(--text-secondary);
    cursor: pointer;
    transition: var(--transition);
}
.nav-item:hover { background: var(--bg-surface-elevated); color: var(--text-primary); }
.nav-item.active { background: linear-gradient(135deg, var(--primary), var(--primary-hover)); color: #fff; box-shadow: 0 4px 14px rgba(0, 0, 0, 0.16); }
.count-badge {
    background: var(--bg-surface-elevated);
    color: var(--text-muted);
    font-size: 11px;
    font-weight: 800;
    padding: 1px 8px;
    border-radius: 999px;
}
.nav-item.active .count-badge { background: rgba(255,255,255,0.25); color: #fff; }

.sidebar-footer { margin-top: auto; }

/* ---- Botões base ---- */
.btn-primary, .btn-secondary {
    position: relative;
    border: none;
    border-radius: 11px;
    padding: 11px 18px;
    font-size: 13px;
    font-weight: 700;
    letter-spacing: -0.005em;
    font-family: inherit;
    cursor: pointer;
    transition: transform 0.12s ease, box-shadow 0.18s ease, background 0.18s ease, border-color 0.18s ease, color 0.18s ease, opacity 0.18s ease;
    -webkit-tap-highlight-color: transparent;
}
.btn-primary {
    background: linear-gradient(135deg, var(--primary), var(--primary-hover));
    color: #fff;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.14), inset 0 1px 0 rgba(255, 255, 255, 0.18);
}
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 8px 22px rgba(0, 0, 0, 0.20), inset 0 1px 0 rgba(255, 255, 255, 0.22); }
.btn-primary:active { transform: translateY(0); box-shadow: 0 2px 8px rgba(0, 0, 0, 0.18); }
.btn-secondary {
    background: var(--bg-surface-elevated);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-sm);
}
.btn-secondary:hover { transform: translateY(-1px); border-color: var(--primary); color: var(--primary); box-shadow: var(--shadow); }
.btn-secondary:active { transform: translateY(0); }
.btn-primary:focus-visible, .btn-secondary:focus-visible { outline: none; box-shadow: var(--ring); }
.btn-full { width: 100%; }
button:disabled { opacity: 0.45; cursor: not-allowed; transform: none !important; box-shadow: none; }
input:focus-visible, select:focus-visible, textarea:focus-visible { outline: none; box-shadow: var(--ring); border-color: var(--primary) !important; }

/* ---- Header ---- */
.top-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 16px 26px;
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-surface);
    flex-shrink: 0;
}
.header-left { display: flex; align-items: center; gap: 12px; }
.top-header h1 { font-size: 19px; }
.top-header p { font-size: 12px; color: var(--text-muted); margin: 2px 0 0; }
.header-actions { display: flex; align-items: center; gap: 12px; }

.user-chip-editable {
    background: var(--bg-surface-elevated);
    border: 1px solid var(--border-color);
    border-radius: 999px;
    padding: 7px 14px;
    font-size: 13px;
    cursor: pointer;
    transition: var(--transition);
}
.user-chip-editable:hover { border-color: var(--primary); }
.user-chip-editable small { color: var(--text-muted); font-size: 11px; }

/* ---- Abas ---- */
.tab-pane { display: none; padding: 26px; overflow-y: auto; flex: 1; }
.tab-pane.active { display: block; }
#tab-tutor.active { display: flex; padding: 0; }

/* ---- Modo Livro ---- */
.book-reader-container {
    max-width: 760px;
    margin: 0 auto;
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 40px 46px;
    box-shadow: var(--shadow-sm);
}
.book-chapter-tag { font-size: 12px; font-weight: 800; color: var(--primary); text-transform: uppercase; letter-spacing: 0.05em; }
.book-title { font-family: var(--font-serif); font-size: 28px; line-height: 1.25; margin: 12px 0 24px; }
.book-paragraph p {
    font-family: var(--font-serif);
    font-size: var(--font-size-base);
    line-height: 1.85;
    color: var(--text-secondary);
    margin-bottom: 18px;
}
.book-paragraph strong { color: var(--text-primary); }

/* Figuras ilustrativas do manual (dentro do Modo Livro) */
.reader-figuras { display: flex; flex-direction: column; gap: 18px; margin: 4px 0 26px; }
.reader-figura { margin: 0; }
.reader-figura svg { display: block; width: 100%; max-width: 560px; height: auto; border-radius: 12px; box-shadow: 0 4px 14px rgba(0,0,0,0.10); }
.reader-figura .cap { font-family: var(--font-serif); font-size: 13px; color: var(--text-muted); margin-top: 8px; font-style: italic; }

/* ---- Trilha / módulos ---- */
.modules-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; }
.module-card {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 18px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    transition: var(--transition);
}
.module-card:hover { border-color: var(--primary); box-shadow: var(--shadow-sm); transform: translateY(-2px); }
.module-num { font-size: 11px; font-weight: 800; color: var(--primary); text-transform: uppercase; }
.module-title { font-size: 15px; line-height: 1.35; }
.module-summary { font-size: 13px; color: var(--text-muted); flex: 1; }
.module-card-actions { margin-top: 6px; }

/* ---- Tutor / chat ---- */
.tutor-container { display: flex; width: 100%; height: 100%; }
.tutor-sidebar {
    width: 280px;
    flex-shrink: 0;
    border-right: 1px solid var(--border-color);
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    overflow-y: auto;
    background: var(--bg-surface);
}
.quick-prompts { display: flex; flex-direction: column; gap: 8px; }
.btn-quick-action {
    text-align: left;
    padding: 9px 12px;
    font-size: 12px;
    font-weight: 700;
    background: var(--bg-surface-elevated);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    border-radius: 9px;
    cursor: pointer;
    transition: var(--transition);
}
.btn-quick-action:hover { border-color: var(--primary); color: var(--primary); }

.chat-viewport { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.chat-messages { flex: 1; overflow-y: auto; padding: 24px; display: flex; flex-direction: column; gap: 14px; }

.message { max-width: 78%; }
.message.system-msg { align-self: flex-start; }
.message.user-msg { align-self: flex-end; }
.msg-body {
    padding: 12px 16px;
    border-radius: 14px;
    font-size: 14px;
    line-height: 1.55;
    box-shadow: var(--shadow-sm);
}
.system-msg .msg-body { background: var(--bg-surface); border: 1px solid var(--border-color); border-bottom-left-radius: 4px; }
.user-msg .msg-body { background: linear-gradient(135deg, var(--primary), var(--primary-hover)); color: #fff; border-bottom-right-radius: 4px; box-shadow: 0 4px 14px rgba(0,0,0,0.14); }
.msg-body strong { display: block; font-size: 11px; opacity: 0.7; margin-bottom: 4px; text-transform: uppercase; letter-spacing: 0.03em; }
.user-msg .msg-body strong { opacity: 0.85; }
.msg-body p { margin: 0; }

.chat-input-area {
    display: flex;
    align-items: flex-end;
    gap: 10px;
    padding: 16px 24px;
    border-top: 1px solid var(--border-color);
    background: var(--bg-surface);
}
.chat-input-area textarea {
    flex: 1;
    resize: none;
    padding: 11px 14px;
    background: var(--bg-main);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    color: var(--text-primary);
    font-family: inherit;
    font-size: 14px;
    outline: none;
}
.chat-input-area textarea:focus { border-color: var(--primary); }
#btnMicInput { padding: 10px 14px; }

/* ---- Flashcards ---- */
.btn-rate {
    border: none;
    border-radius: 10px;
    padding: 10px 16px;
    font-size: 13px;
    font-weight: 700;
    color: #fff;
    cursor: pointer;
    transition: var(--transition);
}
.rate-1 { background: var(--danger); }
.rate-3 { background: #d97706; }
.rate-5 { background: var(--success); }
.btn-rate:hover { filter: brightness(1.08); }

/* ---- Perfil / config ---- */
.profile-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 18px; }
.config-card {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 22px;
}
.config-card h3 { font-size: 16px; margin-bottom: 6px; }
.config-card > p { font-size: 13px; color: var(--text-muted); margin-bottom: 16px; }

.form-group { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.form-group label { font-size: 12px; font-weight: 700; color: var(--text-secondary); }
.form-group input,
.form-group select,
.config-card input,
.config-card select {
    padding: 11px 13px;
    background: var(--bg-main);
    border: 1px solid var(--border-color);
    border-radius: 9px;
    color: var(--text-primary);
    font-family: inherit;
    font-size: 14px;
    outline: none;
}
.form-group input:focus, .form-group select:focus { border-color: var(--primary); }

.license-info-box {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 14px;
    background: var(--bg-main);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    font-size: 13px;
}
.license-info-box strong { color: var(--primary); }

/* ---- Modais ---- */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 12, 40, 0.5);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 20px;
}
.modal-overlay.active { display: flex; animation: fadeIn 0.18s ease; }
.modal-overlay.active .modal-content { animation: popIn 0.22s cubic-bezier(0.2, 0.9, 0.3, 1.2); }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes popIn { from { opacity: 0; transform: translateY(10px) scale(0.98); } to { opacity: 1; transform: none; } }
.modal-content {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 26px;
    width: 100%;
    max-width: 460px;
    box-shadow: var(--shadow);
    /* Cards altos (ex.: Adicionar matéria) não podem estourar a tela e esconder
       os botões — rolam por dentro, sempre deixando a ação alcançável. */
    max-height: calc(100dvh - 32px);
    overflow-y: auto;
    overscroll-behavior: contain;
}
.modal-content h3 { font-size: 18px; margin-bottom: 18px; }

/* Barra de ações do modal de ingestão: fica colada no rodapé do card mesmo
   com o conteúdo rolando, então o "Gerar com IA" está sempre à mão. */
.modal-content .modal-actions {
    position: sticky;
    bottom: -26px;
    margin: 8px -26px -26px;
    padding: 14px 26px;
    background: var(--bg-surface);
    border-top: 1px solid var(--border-color);
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    flex-wrap: wrap;
    z-index: 2;
}

/* ---- Audio Player Controls ---- */
.audio-player-controls {
    display: flex;
    align-items: center;
    gap: 6px;
    background: var(--bg-surface-elevated);
    padding: 4px 10px;
    border-radius: 20px;
    border: 1px solid var(--border-color);
}
.btn-audio-ctrl {
    background: var(--primary);
    color: white;
    border: none;
    padding: 6px 12px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 700;
    cursor: pointer;
    transition: var(--transition);
}
.btn-audio-ctrl:hover { background: var(--primary-hover); }
.btn-audio-stop { background: var(--danger); }
.btn-audio-stop:hover { background: #b91c1c; }

/* ---- Responsivo ---- */
/* Painel Gemas → desconto (aba Conquistas) */
.desconto-panel { background: var(--bg-surface); border: 1px solid var(--border-color); border-left: 3px solid var(--primary); border-radius: 14px; padding: 16px 18px; margin: 20px 0; }
.dp-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 14px; flex-wrap: wrap; }
.dp-title { font-weight: 800; font-size: 15px; }
.dp-sub { font-size: 12.5px; color: var(--text-muted); margin-top: 3px; max-width: 440px; line-height: 1.5; }
.dp-now { text-align: center; flex: 0 0 auto; }
.dp-now b { display: block; font-size: 26px; color: var(--primary); line-height: 1; }
.dp-now span { font-size: 11px; color: var(--text-muted); font-weight: 700; }
.dp-tiers { display: flex; gap: 8px; flex-wrap: wrap; margin: 12px 0 8px; }
.dp-tier { font-size: 12px; font-weight: 700; color: var(--text-muted); background: var(--bg-main); border: 1px solid var(--border-color); border-radius: 999px; padding: 4px 10px; }
.dp-tier.on { color: #fff; background: var(--primary); border-color: var(--primary); }
.dp-hint { font-size: 12px; color: var(--text-muted); line-height: 1.55; }

/* Quebra de palavras longas (nomes de arquivo, URLs) para não estourar as caixas */
h1, h2, h3, h4,
#pageTitle, #pageSubtitle,
.book-title, .book-chapter-tag, .module-title, .module-summary,
#activeTutorModuleName, #activeTutorModuleDesc,
.bib-card-top h4, .bib-sub, .fc-face,
.book-paragraph, .msg-content, .msg-body { overflow-wrap: anywhere; word-break: break-word; }

/* Flashcards (repetição espaçada SM-2) */
.fc-deck-head h2 { margin-bottom: 4px; }
.fc-deck-head p { color: var(--text-muted); font-size: 14px; margin-bottom: 18px; }
.fc-stats { display: flex; gap: 14px; margin-bottom: 18px; flex-wrap: wrap; }
.fc-stat { background: var(--bg-surface); border: 1px solid var(--border-color); border-radius: 14px; padding: 14px 20px; text-align: center; min-width: 96px; }
.fc-stat b { display: block; font-size: 28px; color: var(--primary); line-height: 1.1; }
.fc-stat span { font-size: 12px; color: var(--text-muted); font-weight: 700; }
.fc-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.fc-hint { color: var(--text-muted); font-size: 13px; line-height: 1.55; max-width: 580px; }
.fc-session { max-width: 640px; margin: 0 auto; }
.fc-progress { text-align: center; font-size: 12px; font-weight: 800; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; margin-bottom: 12px; }
.fc-card { min-height: 220px; background: var(--bg-surface); border: 1px solid var(--border-color); border-radius: 18px; padding: 28px; display: flex; flex-direction: column; justify-content: center; gap: 16px; box-shadow: var(--shadow-sm); }
.fc-face { font-size: 18px; line-height: 1.6; }
.fc-front { font-weight: 700; text-align: center; }
.fc-back { border-top: 1px dashed var(--border-color); padding-top: 16px; }
.fc-controls { margin-top: 16px; }
.fc-rate { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.fc-rate-btn { padding: 12px 6px; font-size: 13px; }
#btnFcSair { display: block; margin: 16px auto 0; }

/* Biblioteca — matérias organizadas em abas (pastas) */
.bib-toolbar { display: flex; gap: 10px; margin-bottom: 16px; flex-wrap: wrap; }
.bib-search { flex: 1; min-width: 180px; padding: 12px 14px; background: var(--bg-surface); border: 1px solid var(--border-color); border-radius: 10px; color: var(--text-primary); font-family: inherit; font-size: 14px; }
.bib-folders { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 8px; margin-bottom: 16px; }
.bib-folder { flex: 0 0 auto; display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; background: var(--bg-surface); border: 1px solid var(--border-color); border-radius: 999px; color: var(--text-primary); font-weight: 700; font-size: 13px; cursor: pointer; white-space: nowrap; transition: var(--transition); }
.bib-folder:hover { border-color: var(--primary); }
.bib-folder.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.bib-folder-n { font-size: 11px; opacity: 0.8; background: rgba(0, 0, 0, 0.12); border-radius: 999px; padding: 1px 7px; }
.bib-folder.active .bib-folder-n { background: rgba(255, 255, 255, 0.25); }
.bib-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 14px; }
.bib-card { background: var(--bg-surface); border: 1px solid var(--border-color); border-radius: var(--radius); padding: 16px; display: flex; flex-direction: column; }
.bib-card.ativa { border-color: var(--primary); box-shadow: var(--ring); }
.bib-card-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.bib-card-top h4 { font-size: 15px; line-height: 1.3; }
.bib-badge-ativa { flex: 0 0 auto; font-size: 10px; font-weight: 800; text-transform: uppercase; letter-spacing: 0.03em; color: #fff; background: var(--primary); border-radius: 999px; padding: 3px 8px; }
.bib-sub { font-size: 12px; color: var(--text-muted); margin: 4px 0 10px; }
.bib-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.bib-chip { font-size: 11px; font-weight: 700; color: var(--text-muted); background: var(--bg-main); border: 1px solid var(--border-color); border-radius: 999px; padding: 3px 9px; }
.bib-card-actions { display: flex; gap: 8px; margin-top: 14px; flex-wrap: wrap; }
.bib-card-actions .btn-sm { flex: 1 1 auto; }
.bib-card-actions .bib-del { flex: 0 0 auto; }
.notas-input-wrap { display: flex; gap: 8px; align-items: flex-start; }
.notas-input-wrap textarea { flex: 1; padding: 11px; background: var(--bg-main); border: 1px solid var(--border-color); border-radius: 9px; color: var(--text-primary); font-family: inherit; resize: vertical; }

@media (max-width: 860px) {
    .sidebar { position: fixed; z-index: 900; height: 100%; transform: translateX(-100%); transition: transform 0.25s ease; }
    .sidebar.open { transform: translateX(0); }
    .btn-mobile-menu { display: inline-block !important; }
    .tutor-container { flex-direction: column; }
    .tutor-sidebar { width: 100%; border-right: none; border-bottom: 1px solid var(--border-color); }
    .btn-sidebar-close { display: inline-flex !important; }
    .btn-tutor-collapse { display: inline-flex !important; }
    .tutor-sidebar.collapsed > *:not(.btn-tutor-collapse) { display: none !important; }
}

/* Menu drawer (mobile): fundo escuro + botão fechar + recolher painel do tutor */
.sidebar-backdrop { display: none; position: fixed; inset: 0; background: rgba(0, 0, 0, 0.45); z-index: 899; }
.sidebar-backdrop.show { display: block; }
.btn-sidebar-close {
    display: none; position: absolute; top: 12px; right: 12px;
    width: 34px; height: 34px; align-items: center; justify-content: center;
    background: var(--bg-surface); border: 1px solid var(--border-color);
    border-radius: 9px; color: var(--text-muted); font-size: 16px; cursor: pointer; z-index: 2;
}
.btn-sidebar-close:hover { color: var(--primary); border-color: var(--primary); }
.btn-tutor-collapse {
    display: none; width: 100%; align-items: center; justify-content: center; gap: 6px;
    padding: 10px; margin-bottom: 4px; background: var(--bg-surface-elevated);
    border: 1px solid var(--border-color); border-radius: 10px;
    color: var(--text-primary); font-weight: 700; font-size: 13px; cursor: pointer;
}

/* Scrollbars discretas */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--border-color); border-radius: 999px; }
::-webkit-scrollbar-track { background: transparent; }

/* Toast */
#toast {
    position: fixed;
    left: 50%;
    bottom: 26px;
    transform: translateX(-50%) translateY(20px);
    background: var(--text-primary);
    color: var(--bg-main);
    padding: 12px 20px;
    border-radius: 12px;
    font-size: 13px;
    font-weight: 700;
    box-shadow: var(--shadow);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease, transform 0.25s ease;
    z-index: 2000;
    max-width: 90vw;
    text-align: center;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* Mensagem "em itálico" da didática no chat */
.msg-body em { font-style: italic; opacity: 0.8; }

/* ===================== MASCOTE SABIÁ ===================== */
.sabia-mascot { display: block; width: 100%; height: auto; animation: sabiaBob 3.2s ease-in-out infinite; transform-origin: center bottom; }
@keyframes sabiaBob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-6px); } }
.sabia-mascot .lid { transform-box: fill-box; transform-origin: center; animation: sabiaBlink 5.5s infinite; }
@keyframes sabiaBlink { 0%, 93%, 100% { transform: scaleY(0); } 95%, 97% { transform: scaleY(1); } }
.tutor-mascot { width: 92px; margin: 0 auto 10px; }
.sp-mascot { position: absolute; right: 16px; bottom: 12px; width: 88px; pointer-events: none; }
@media (max-width: 640px) { .sp-mascot { display: none; } }

/* ===================== GAMIFICAÇÃO ===================== */
.header-avatar {
    width: 42px; height: 42px;
    display: grid; place-items: center;
    font-size: 23px;
    border-radius: 50%;
    background: radial-gradient(circle at 30% 25%, color-mix(in srgb, var(--primary) 30%, var(--bg-surface-elevated)), var(--bg-surface-elevated));
    border: 2px solid var(--primary);
    box-shadow: 0 2px 8px rgba(0,0,0,0.14), inset 0 1px 2px rgba(255,255,255,0.35);
    cursor: pointer;
    transition: var(--transition);
    position: relative;
}
.header-avatar:hover { transform: scale(1.1) rotate(-3deg); box-shadow: 0 4px 14px color-mix(in srgb, var(--primary) 45%, transparent); }
/* Emoji do avatar com um leve relevo, pra não parecer "chapado" */
.ava-base { line-height: 1; display: inline-block; filter: drop-shadow(0 1px 1px rgba(0,0,0,0.22)); }
.ava-acc { font-size: 0.5em; position: absolute; bottom: -2px; right: -2px; }

.gami-hero { display: grid; grid-template-columns: 1.4fr 1fr; gap: 18px; }
@media (max-width: 820px) { .gami-hero { grid-template-columns: 1fr; } }

.superpower-card {
    --sp-cor: var(--primary);
    position: relative;
    display: flex; align-items: center; gap: 20px;
    padding: 26px;
    border-radius: var(--radius-lg);
    color: #fff;
    overflow: hidden;
    background: linear-gradient(135deg, var(--primary), var(--sp-cor));
    box-shadow: var(--shadow);
}
.superpower-card .sp-avatar {
    width: 96px; height: 96px; flex-shrink: 0;
    display: grid; place-items: center;
    background: rgba(255,255,255,0.18);
    border-radius: 22px;
    position: relative;
}
.superpower-card .sp-avatar .ava-acc { font-size: 0.45em; }
.superpower-card .sp-emoji { position: absolute; top: 18px; right: 22px; font-size: 44px; opacity: 0.9; }
.superpower-card .sp-tag { font-size: 11px; font-weight: 800; letter-spacing: 0.08em; opacity: 0.85; }
.superpower-card h2 { color: #fff; font-size: 26px; margin: 4px 0 6px; }
.superpower-card p { font-size: 14px; opacity: 0.92; margin: 0; max-width: 42ch; }
.superpower-card .btn-secondary { background: rgba(255,255,255,0.2); border-color: rgba(255,255,255,0.35); color: #fff; }

.gami-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.stat-tile {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 14px 16px;
    display: flex; flex-direction: column; gap: 4px; justify-content: center;
}
.stat-tile .stat-num { font-size: 20px; font-weight: 800; letter-spacing: -0.01em; }
.stat-tile .stat-lbl { font-size: 11px; color: var(--text-muted); font-weight: 700; text-transform: uppercase; letter-spacing: 0.02em; }
.xp-bar { height: 7px; background: var(--bg-surface-elevated); border-radius: 999px; overflow: hidden; margin: 4px 0; }
.xp-bar > div { height: 100%; background: linear-gradient(90deg, var(--primary), var(--secondary)); border-radius: 999px; transition: width 0.5s ease; }

.medals-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 14px; }
.medal {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 18px 16px;
    text-align: center;
    opacity: 0.6;
    filter: grayscale(0.6);
    transition: var(--transition);
}
.medal.earned { opacity: 1; filter: none; border-color: var(--primary); box-shadow: var(--shadow-sm); }
.medal.earned:hover { transform: translateY(-3px); box-shadow: var(--shadow); }
.medal-emoji { font-size: 40px; }
.medal-name { font-weight: 800; font-size: 14px; margin: 6px 0 4px; }
.medal-desc { font-size: 12px; color: var(--text-muted); min-height: 32px; }
.medal-reward { font-size: 11px; font-weight: 800; color: var(--primary); margin-top: 8px; }

.avatar-editor { display: flex; align-items: flex-start; gap: 20px; flex-wrap: wrap; background: var(--bg-surface); border: 1px solid var(--border-color); border-radius: var(--radius); padding: 18px; }
.ava-preview {
    width: 100px; height: 100px; flex-shrink: 0; display: grid; place-items: center;
    border-radius: 50%; overflow: hidden; position: relative;
    box-shadow: 0 6px 16px rgba(0,0,0,0.14);
}
.ava-svg { display: block; width: 100%; height: 100%; }
/* Avatar SVG dentro do chip redondo do cabeçalho e do card de superpoder */
.header-avatar { overflow: hidden; }
.header-avatar .ava-svg, .sp-avatar .ava-svg { border-radius: 50%; }

/* Editor de peças do avatar (camadas) */
.ava-parts { display: flex; flex-direction: column; gap: 12px; flex: 1; min-width: 220px; }
.ava-part-row { display: flex; flex-direction: column; gap: 6px; }
.ava-part-lbl { font-size: 11px; font-weight: 800; text-transform: uppercase; color: var(--text-muted); }
.ava-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.ava-sw { width: 34px; height: 34px; border-radius: 9px; border: 2px solid var(--border-color); cursor: pointer; transition: var(--transition); }
.ava-sw:hover { transform: scale(1.08); }
.ava-sw.sel { border-color: var(--primary); box-shadow: var(--ring); transform: scale(1.08); }
.ava-opt {
    display: inline-flex; align-items: center; gap: 5px;
    background: var(--bg-main); border: 2px solid var(--border-color);
    border-radius: 10px; padding: 7px 11px; font-size: 12px; cursor: pointer;
    color: var(--text-primary); transition: var(--transition);
}
.ava-opt:hover { border-color: var(--primary); }
.ava-opt.sel { border-color: var(--primary); background: var(--bg-surface-elevated); box-shadow: var(--ring); }
.ava-opt.locked { border-style: dashed; color: var(--text-muted); }
.ava-cost { color: var(--primary); font-weight: 800; }
.shop-empty { grid-column: 1 / -1; color: var(--text-muted); text-align: center; padding: 20px; }
.ava-preview .ava-acc { font-size: 0.5em; }
.ava-bases { display: flex; flex-wrap: wrap; gap: 10px; flex: 1; }
.ava-base-opt {
    width: 50px; height: 50px; font-size: 26px;
    display: grid; place-items: center;
    border: 2px solid var(--border-color);
    background: radial-gradient(circle at 32% 24%, color-mix(in srgb, var(--primary) 12%, var(--bg-main)), var(--bg-main));
    border-radius: 14px; cursor: pointer;
    transition: var(--transition);
}
.ava-base-opt:hover { border-color: var(--primary); transform: translateY(-2px) scale(1.08); }
.ava-base-opt.sel {
    border-color: var(--primary);
    background: radial-gradient(circle at 32% 24%, color-mix(in srgb, var(--primary) 32%, var(--bg-surface-elevated)), var(--bg-surface-elevated));
    box-shadow: var(--ring), 0 4px 12px color-mix(in srgb, var(--primary) 35%, transparent);
    transform: scale(1.06);
}

.shop-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 14px; }
.shop-item { background: var(--bg-surface); border: 1px solid var(--border-color); border-radius: var(--radius); padding: 16px; text-align: center; }
.shop-item.owned { border-color: var(--success); }
.shop-emoji { font-size: 36px; }
.shop-name { font-size: 13px; font-weight: 700; margin: 6px 0 10px; }
.shop-btn { width: 100%; }

/* Quiz */
.quiz-count { font-size: 12px; font-weight: 800; color: var(--primary); text-transform: uppercase; }
.quiz-ops { display: flex; flex-direction: column; gap: 10px; }
.quiz-op {
    text-align: left; padding: 14px 16px;
    border: 1px solid var(--border-color);
    background: var(--bg-main); color: var(--text-primary);
    border-radius: 12px; font-size: 14px; font-weight: 600; cursor: pointer;
    transition: var(--transition); font-family: inherit;
}
.quiz-op:hover { border-color: var(--primary); background: var(--bg-surface-elevated); transform: translateX(3px); }
.quiz-op:disabled { cursor: default; transform: none; opacity: 1; }
.quiz-op-ok { border-color: var(--success) !important; background: rgba(34, 197, 94, 0.14) !important; font-weight: 800; }
.quiz-op-no { border-color: #e05252 !important; background: rgba(224, 82, 82, 0.14) !important; }
.quiz-feedback { margin-top: 14px; padding: 12px 14px; background: var(--bg-main); border: 1px solid var(--border-color); border-radius: 12px; font-size: 13px; line-height: 1.55; }

/* Balão de aviso do celular no ingest */
.ingest-nota-celular {
    margin-top: 10px; padding: 11px 13px; font-size: 12px; line-height: 1.5;
    color: var(--text-primary); background: rgba(99, 102, 241, 0.10);
    border: 1px solid var(--border-color); border-left: 3px solid var(--primary);
    border-radius: 10px;
}
.ingest-figuras-opt {
    margin: 10px 0 0; padding: 10px 12px;
    background: color-mix(in srgb, var(--primary) 8%, transparent);
    border: 1px solid var(--border-color); border-radius: 10px;
}

/* Ajuda */
.help-steps { padding-left: 20px; margin: 10px 0; }
.help-steps li { margin-bottom: 9px; font-size: 14px; line-height: 1.5; }
.help-key { background: var(--bg-main); border: 1px solid var(--border-color); border-radius: 12px; padding: 16px 18px; margin-top: 14px; }
.help-key h4 { font-size: 14px; margin-bottom: 8px; }
.help-key ol { padding-left: 20px; margin: 0; }
.help-key li { font-size: 13px; margin-bottom: 5px; }
.help-note { font-size: 12px; color: var(--text-muted); margin-top: 10px; line-height: 1.5; }

/* ---- Ajustes de chat: fonte escalável + ouvir + didática ---- */
.msg-body p { font-size: var(--font-size-base); line-height: 1.6; }
.msg-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.msg-body p strong { display: inline; font-size: inherit; opacity: 1; text-transform: none; font-weight: 800; letter-spacing: 0; }

/* Conteúdo do balão renderizado como markdown (títulos, listas, negrito, código) */
.msg-content { font-size: var(--font-size-base); line-height: 1.6; }
.msg-content.typing::after {
  content: '▍';
  display: inline-block;
  margin-left: 1px;
  color: var(--primary);
  animation: sabiaCaret 1s steps(1) infinite;
}
@keyframes sabiaCaret { 50% { opacity: 0; } }
.msg-content p { margin: 0 0 8px; }
.msg-content p:last-child { margin-bottom: 0; }
.msg-content strong { display: inline; font-size: inherit; opacity: 1; text-transform: none; font-weight: 800; letter-spacing: 0; }
.msg-content em { font-style: italic; opacity: 0.9; }
.msg-content h3, .msg-content h4, .msg-content h5, .msg-content h6 {
  margin: 10px 0 6px; line-height: 1.3; font-weight: 800; opacity: 1;
  text-transform: none; letter-spacing: 0;
}
.msg-content h3 { font-size: calc(var(--font-size-base) + 3px); }
.msg-content h4 { font-size: calc(var(--font-size-base) + 1px); }
.msg-content h5, .msg-content h6 { font-size: var(--font-size-base); }
.msg-content > :first-child { margin-top: 0; }
.msg-content ul, .msg-content ol { margin: 6px 0 8px; padding-left: 1.4em; }
.msg-content li { margin: 3px 0; }
.msg-content li::marker { color: var(--primary); }
.user-msg .msg-content li::marker { color: rgba(255,255,255,0.85); }
.msg-content code {
  font-family: ui-monospace, "Cascadia Code", Consolas, monospace;
  font-size: 0.9em; padding: 1px 5px; border-radius: 5px;
  background: rgba(127,127,127,0.16);
}
.user-msg .msg-content code { background: rgba(255,255,255,0.2); }

/* ---- Solicitar licença + pontos→desconto (modal de licença) ---- */
.lic-request { margin-top: 18px; }
.lic-sep { display: flex; align-items: center; gap: 10px; color: var(--text-muted); font-size: 12px; margin: 6px 0 12px; }
.lic-sep::before, .lic-sep::after { content: ""; flex: 1; height: 1px; background: var(--border-color); }
.lic-hint { font-size: 13px; color: var(--text-secondary); margin: 0 0 10px; }
.desconto-info {
  margin-top: 12px; padding: 12px 14px; border-radius: var(--radius);
  background: var(--bg-main); border: 1px solid var(--border-color);
  font-size: 13px; color: var(--text-secondary); line-height: 1.5;
}
.desconto-info strong { color: var(--primary); font-weight: 800; }
.desconto-hint { font-size: 12px; color: var(--text-muted); margin-top: 4px; }
.cod-row { display: flex; align-items: center; gap: 8px; margin-top: 10px; }
.cod-row code {
  flex: 1; font-family: var(--font-mono); font-size: 13px; letter-spacing: 0.02em;
  background: var(--bg-surface-elevated); color: var(--text-primary);
  padding: 8px 10px; border-radius: 8px; border: 1px dashed var(--primary);
  text-align: center; user-select: all;
}
.btn-sm { padding: 8px 12px !important; font-size: 12px !important; width: auto !important; white-space: nowrap; }
.btn-listen { background: transparent; border: none; cursor: pointer; font-size: 17px; opacity: 0.65; padding: 0 2px; transition: var(--transition); }
.btn-listen:hover { opacity: 1; transform: scale(1.18); }
.user-msg .btn-listen { display: none; }
.estr { font-size: 11px; font-style: italic; opacity: 0.7; margin: 2px 0 6px; }

/* ---- Microfone (responder por voz) ---- */
.btn-mic { padding: 10px 14px; font-size: 16px; }
.btn-mic.rec { background: var(--danger); color: #fff; border-color: var(--danger); animation: micpulse 1s infinite; }
@keyframes micpulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.55; } }

/* ---- Toggles de acessibilidade ---- */
.switch-row { display: flex; align-items: flex-start; gap: 10px; margin: 12px 0; cursor: pointer; font-size: 13px; }
.switch-row input { width: 20px; height: 20px; margin-top: 2px; accent-color: var(--primary); flex-shrink: 0; cursor: pointer; }
.switch-row small { color: var(--text-muted); line-height: 1.4; }

/* ---- Anexos (ingestão de arquivos) ---- */
.ingest-dropzone { display:flex; align-items:center; gap:12px; padding:16px; border:2px dashed var(--border-color);
  border-radius:12px; background:var(--bg-main); cursor:pointer; transition:border-color .15s, background .15s; }
.ingest-dropzone:hover, .ingest-dropzone.dragover { border-color:var(--primary); background:var(--bg-surface-elevated); }
.ingest-dz-icon { font-size:26px; line-height:1; }
.ingest-dz-text { font-size:13px; color:var(--text-secondary); line-height:1.4; }
.ingest-dz-text small { color:var(--text-muted); }
.ingest-file-list { display:flex; flex-direction:column; gap:6px; margin-top:10px; }
.ingest-file-chip { display:flex; align-items:center; gap:8px; font-size:12px; padding:7px 10px; border-radius:8px;
  background:var(--bg-surface-elevated); border:1px solid var(--border-color); }
.ingest-file-chip .fc-name { flex:1; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.ingest-file-chip .fc-status { color:var(--text-muted); font-weight:700; }
.ingest-file-chip.ok .fc-status { color:#22c55e; }
.ingest-file-chip.err .fc-status { color:#ef4444; }
.ingest-file-chip.busy .fc-status { color:var(--primary); }

/* ---- Modo Livro: busca no material + navegar frente/trás (Fase 1) ---- */
.reader-topbar { display:flex; gap:12px; align-items:flex-start; margin-bottom:18px; flex-wrap:wrap; }
.reader-search-wrap { position:relative; flex:1; min-width:200px; }
.reader-search { width:100%; padding:11px 14px; background:var(--bg-surface); border:1px solid var(--border-color);
  border-radius:10px; color:var(--text-primary); font-family:inherit; font-size:14px; }
.reader-search:focus { outline:none; border-color:var(--primary); }
.reader-search-results { position:absolute; top:calc(100% + 6px); left:0; right:0; z-index:30;
  background:var(--bg-surface-elevated); border:1px solid var(--border-color); border-radius:12px;
  box-shadow:0 12px 30px rgba(0,0,0,.22); max-height:340px; overflow-y:auto; padding:6px; }
.reader-search-results .rd-result { display:flex; flex-direction:column; gap:3px; width:100%; text-align:left;
  background:transparent; border:none; border-radius:8px; padding:9px 11px; cursor:pointer; color:var(--text-primary); }
.reader-search-results .rd-result:hover { background:var(--bg-main); }
.reader-search-results .rd-result b { font-size:13px; color:var(--primary); }
.reader-search-results .rd-result span { font-size:12px; color:var(--text-muted); line-height:1.4; }
.reader-search-results .rd-noresult { font-size:13px; color:var(--text-muted); padding:10px 12px; }
.reader-nav { display:flex; align-items:center; gap:8px; }
.reader-indicator { font-size:12px; color:var(--text-muted); font-weight:700; min-width:96px; text-align:center; }
.btn-sm { padding:8px 12px; font-size:13px; }
.reader-nav .btn-sm:disabled { opacity:.4; cursor:not-allowed; }
mark.rd-hit { background:#ffe08a; color:#3a2a00; border-radius:3px; padding:0 2px; }

/* ---- Aviso de trava de anexo no modal de licença ---- */
.lic-anexo-aviso { background:var(--bg-surface-elevated); border:1px solid var(--primary);
  border-radius:12px; padding:14px 16px; margin-bottom:16px; font-size:13.5px; line-height:1.5; color:var(--text-primary); }

/* ---- Ícones SVG próprios de gamificação (medalhas/superpoderes/acessórios) ---- */
.medal-emoji { font-size: 0; line-height: 0; }
.medal-emoji .ic-medal { width: 72px; height: 75px; display: block; margin: 0 auto; }
.superpower-card .sp-emoji .ic-power { width: 60px; height: 68px; display: block; }
.quiz-power-ic { margin: 4px 0 2px; }
.quiz-power-ic .ic-power { width: 86px; height: 96px; display: block; margin: 0 auto; }
.shop-emoji { font-size: 0; }
.shop-emoji .ic-acc { width: 44px; height: 44px; display: block; margin: 0 auto; }
.shop-emoji .ava-svg { width: 56px; height: 56px; margin: 0 auto; }
/* acessórios equipados = faixinha discreta na BASE do avatar (não cobre o personagem) */
.ava-acc { position: absolute; bottom: -7px; left: 50%; transform: translateX(-50%);
  display: inline-flex; gap: 2px; padding: 2px 4px; border-radius: 20px;
  background: var(--bg-surface); border: 1px solid var(--border-color); box-shadow: var(--shadow-sm);
  font-size: initial; right: auto; }
.ava-acc:empty { display: none; }
.ava-acc .ic-acc { width: 15px; height: 15px; display: block; }
.ava-preview .ava-acc .ic-acc { width: 17px; height: 17px; }
.superpower-card .sp-avatar .ava-acc .ic-acc { width: 15px; height: 15px; }
/* no avatar pequeno do cabeçalho, mostra só o personagem (sem poluir) */
#headerAvatar .ava-acc { display: none; }
