/* =========================================
   CSS3: VARIÁVEIS E RESET
========================================= */
:root {
    --primary: #4F46E5;
    --primary-hover: #4338CA;
    --bg-color: #F3F4F6;
    --toolbar-bg: #FFFFFF;
    --text-color: #1F2937;
    --border: #E5E7EB;
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --pencil-color: #000000; 
    
    --tool-bg: rgba(255, 255, 255, 0.85);
    --tool-border: #9CA3AF;
    --tool-text: #374151;
    --tool-blue-bg: rgba(173, 216, 230, 0.35);
}

* { box-sizing: border-box; margin: 0; padding: 0; font-family: 'Poppins', sans-serif; user-select: none; }
body { background-color: var(--bg-color); display: flex; flex-direction: column; height: 100vh; overflow: hidden; }

/* =========================================
   TOOLBAR (BARRA DE FERRAMENTAS)
========================================= */
.toolbar { background-color: var(--toolbar-bg); padding: 10px 20px; display: flex; align-items: center; gap: 15px; box-shadow: var(--shadow); z-index: 5000; flex-wrap: wrap; position: relative; }
.toolbar-group { display: flex; align-items: center; gap: 8px; padding-right: 15px; border-right: 2px solid var(--border); }
.toolbar-group:last-child { border-right: none; }
.toolbar-label { font-size: 14px; color: var(--text-color); opacity: 0.8; font-weight: 500; }

button { background: transparent; border: none; color: var(--text-color); font-size: 16px; padding: 8px 12px; border-radius: 6px; cursor: pointer; transition: all 0.2s; display: flex; align-items: center; gap: 6px; }
button:hover { background-color: var(--border); }
button.active { background-color: var(--primary); color: white; }
.btn-clear { color: #EF4444; }

.btn-primary { background-color: var(--primary) !important; color: white !important; font-weight: 600; padding: 8px 16px; border-radius: 8px; border: none; box-shadow: 0 2px 4px rgba(79, 70, 229, 0.3); }
.btn-primary:hover { background-color: var(--primary-hover) !important; transform: translateY(-1px); }

input[type="color"] { border: none; width: 30px; height: 30px; border-radius: 50%; cursor: pointer; overflow: hidden; }
input[type="range"] { cursor: pointer; width: 80px; }

.bg-selector { background: var(--toolbar-bg); border: 1px solid var(--border); color: var(--text-color); font-size: 13px; padding: 6px 10px; border-radius: 6px; cursor: pointer; outline: none; margin-left: 5px; transition: background 0.3s, color 0.3s; }
.bg-selector:hover { background: var(--border); }

/* =========================================
   LAYOUT PRINCIPAL E BARRA LATERAL
========================================= */
#main-layout { 
    display: flex; 
    flex: 1; 
    height: calc(100vh - 65px); 
    overflow: hidden; 
    position: relative; /* Essencial para a barra absoluta não sair do ecrã */
}

#sidebar { 
    width: 320px; 
    background-color: var(--toolbar-bg); 
    border-right: 1px solid var(--border); 
    display: flex; 
    flex-direction: column; 
    padding: 20px; 
    overflow-y: auto; 
    z-index: 6000; 
    box-shadow: 2px 0 5px rgba(0,0,0,0.02);
    
    /* NOVO: A barra agora flutua POR CIMA do quadro */
    position: absolute; 
    top: 0; 
    bottom: 0; 
    left: 0;
    
    /* Animação suave de deslize */
    transition: transform 0.3s facil; 
}

/* NOVO: Estado da barra lateral recolhida */
#sidebar.collapsed { 
    transform: translateX(-100%); /* Desliza a barra totalmente para a esquerda, fora do ecrã */
}

.sidebar-category { margin-bottom: 25px; border-bottom: 1px solid var(--border); padding-bottom: 20px; }
.sidebar-category:last-child { border-bottom: none; }

.sidebar-title { font-size: 15px; font-weight: 600; color: var(--text-color); margin-bottom: 15px; }

.horizontal-scroll-container { display: flex; align-items: stretch; gap: 12px; overflow-x: auto; padding: 6px 2px 10px 2px; scroll-behavior: smooth; -ms-overflow-style: none; scrollbar-width: none; }
.horizontal-scroll-container::-webkit-scrollbar { display: none; }

.card-button { min-width: 100px; height: 120px; border: 2px dashed #9CA3AF; border-radius: 8px; display: flex; justify-content: center; align-items: center; cursor: pointer; transition: all 0.3s; background-color: #F9FAFB; flex-shrink: 0; }
.card-button i { font-size: 28px; color: #9CA3AF; transition: all 0.3s; }
.card-button:hover { border-color: var(--primary); background-color: #EEF2FF; transform: translateY(-2px); box-shadow: 0 4px 6px rgba(79, 70, 229, 0.1); }
.card-button:hover i { color: var(--primary); transform: scale(1.1); }

.lesson-card { width: 125px; min-width: 125px; max-width: 125px; min-height: 120px; background-color: #F9FAFB; border: 1px solid var(--border); border-radius: 8px; padding: 10px 8px; display: flex; flex-direction: column; justify-content: center; align-items: center; text-align: center; cursor: pointer; transition: all 0.2s; flex-shrink: 0; box-sizing: border-box; }
.lesson-card:hover { border-color: var(--primary); background-color: #EEF2FF; transform: translateY(-2px); box-shadow: 0 4px 6px rgba(79, 70, 229, 0.1); }
.lesson-icon { color: var(--primary); font-size: 22px; margin-bottom: 6px; flex-shrink: 0; }
.lesson-name { font-size: 12px; font-weight: 600; color: var(--text-color); margin-bottom: 4px; line-height: 1.25; width: 100%; word-wrap: break-word; overflow-wrap: break-word; }
.lesson-folder { font-size: 10px; color: #6B7280; margin-bottom: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; display: flex; align-items: center; gap: 4px; }
.lesson-meta { font-size: 10px; color: #9CA3AF; font-weight: 500; }

.folder-card { background-color: #FFFBEB; border-color: #FDE68A; }
.folder-card:hover { background-color: #FEF3C7; border-color: #F59E0B; }
.folder-card .lesson-icon { color: #F59E0B; }

.back-card { background-color: #F3F4F6; border-color: #D1D5DB; }
.back-card:hover { background-color: #E5E7EB; border-color: #9CA3AF; }
.back-card .lesson-icon { color: #6B7280; }

#sidebar-recording { margin-bottom: 15px; }
.recording-indicator { display: flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 600; color: #EF4444; margin-bottom: 5px; justify-content: center; }
.red-dot { width: 10px; height: 10px; background-color: #EF4444; border-radius: 50%; animation: pulse-red 1.5s infinite; }
@keyframes pulse-red { 0% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.7); } 70% { box-shadow: 0 0 0 6px rgba(239, 68, 68, 0); } 100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0); } }
.scene-counter { text-align: center; font-size: 12px; color: #6B7280; margin-bottom: 15px; }
.btn-full { width: 100%; justify-content: center; margin-bottom: 8px; padding: 10px; font-size: 14px; }
.btn-success { background-color: #10B981 !important; color: white !important; font-weight: 600; border-radius: 8px; }
.btn-success:hover { background-color: #059669 !important; }
.btn-danger { background-color: transparent !important; color: #EF4444 !important; border: 1px solid #EF4444; border-radius: 8px; }
.btn-danger:hover { background-color: #FEF2F2 !important; }

/* =========================================
   MODAL DE SALVAR E APRESENTAÇÃO
========================================= */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 9999; display: flex; align-items: center; justify-content: center; backdrop-filter: blur(2px); }
.modal-content { background: white; padding: 25px; border-radius: 12px; width: 350px; box-shadow: 0 20px 25px -5px rgba(0,0,0,0.1); }
.modal-content h3 { margin-bottom: 20px; color: var(--text-color); font-size: 18px; }
.input-group { margin-bottom: 15px; display: flex; flex-direction: column; gap: 5px; }
.input-group label { font-size: 13px; color: #4B5563; font-weight: 500; }
.input-group input { padding: 10px; border: 1px solid var(--border); border-radius: 6px; font-size: 14px; outline: none; font-family: 'Poppins', sans-serif; }
.input-group input:focus { border-color: var(--primary); }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 25px; }
.btn-outline { border: 1px solid var(--border); color: #4B5563 !important; background: transparent; padding: 8px 16px; border-radius: 8px; cursor: pointer; }
.btn-outline:hover { background: #F3F4F6; }

#presentation-mode { position: fixed; inset: 0; background: rgba(17, 24, 39, 0.95); z-index: 10000; display: flex; align-items: center; justify-content: center; flex-direction: column; }
#presentation-image { max-width: 85vw; max-height: 85vh; object-fit: contain; border-radius: 8px; box-shadow: 0 10px 30px rgba(0,0,0,0.5); background-color: white; }
#btn-close-presentation { position: absolute; top: 20px; right: 30px; font-size: 30px; color: white; background: transparent; cursor: pointer; opacity: 0.7; transition: opacity 0.2s; padding: 10px; border: none; }
#btn-close-presentation:hover { opacity: 1; background: transparent; }
.nav-arrow { position: absolute; top: 50%; transform: translateY(-50%); font-size: 40px; color: white; opacity: 0.5; background: transparent; padding: 20px; border-radius: 50%; transition: all 0.2s; border: none; cursor: pointer; }
.nav-arrow:hover { opacity: 1; background: rgba(255,255,255,0.1); }
.nav-arrow.left { left: 2vw; }
.nav-arrow.right { right: 2vw; }
#presentation-counter { position: absolute; bottom: 20px; left: 50%; transform: translateX(-50%); color: white; font-size: 16px; font-weight: 500; background: rgba(0,0,0,0.5); padding: 6px 16px; border-radius: 20px; }

#workspace-viewport {
    position: relative;
    flex: 1;
    width: 100%;
    height: 100%;
    overflow: hidden;
    box-sizing: border-box;
}

#workspace-viewport.paper-mode,
#workspace-viewport.zoomed-mode {
    overflow: auto;
    background-color: #E5E7EB;
    padding: 24px;
}

#workspace-zoom-wrapper {
    position: relative;
    width: 100%;
    height: 100%;
    margin: 0 auto;
}

#workspace { 
    position: relative; 
    width: 100%; /* O quadro ocupa 100% da largura sempre */
    height: 100%; 
    overflow: hidden;
    transform-origin: top left;
    transition: transform 0.12s ease-out;
}

#workspace-viewport.paper-mode #workspace,
#workspace-viewport.zoomed-mode #workspace {
    box-shadow: 0 10px 28px rgba(15, 23, 42, 0.16);
    border: 1px solid #CBD5E1;
    overflow: visible;
}

/* Controle de Zoom Exclusivo (Pílula Segmentada no Cabeçalho) */
.zoom-control-pill {
    display: inline-flex;
    align-items: center;
    background-color: #F3F4F6;
    border: 1px solid #D1D5DB;
    border-radius: 999px;
    padding: 2px;
    gap: 2px;
}

.zoom-pill-btn {
    width: 28px;
    height: 28px;
    border: none;
    background: transparent;
    color: #374151;
    border-radius: 999px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 12px;
    transition: background-color 0.15s, color 0.15s;
}

.zoom-pill-btn:hover {
    background-color: var(--primary);
    color: #FFFFFF;
}

.zoom-pill-value {
    border: none;
    background: #FFFFFF;
    color: #111827;
    font-size: 12px;
    font-weight: 600;
    min-width: 48px;
    height: 26px;
    padding: 0 8px;
    border-radius: 999px;
    cursor: pointer;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
    transition: background-color 0.15s, color 0.15s;
}

.zoom-pill-value:hover {
    background-color: #EEF2FF;
    color: var(--primary);
}
/* Menu Dropdown de Formatos de Folha (Estilo Word) */
.page-size-dropdown {
    position: relative;
    display: inline-flex;
    align-items: center;
}

.page-size-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    white-space: nowrap;
}

.page-size-menu {
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    width: 285px;
    max-height: 430px;
    overflow-y: auto;
    background: #FFFFFF;
    border: 1px solid #D1D5DB;
    border-radius: 8px;
    box-shadow: 0 12px 28px rgba(15, 23, 42, 0.18);
    z-index: 9999;
    padding: 6px;
}

.page-size-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 10px;
    border-radius: 6px;
    cursor: pointer;
    border: 1px solid transparent;
    transition: background-color 0.15s, border-color 0.15s;
    text-align: left;
}

.page-size-item:hover {
    background-color: #F3F4F6;
}

.page-size-item.active {
    background-color: #FEF3C7;
    border-color: #F59E0B;
}

.page-size-icon {
    width: 24px;
    height: 30px;
    border: 1px solid #64748B;
    background: linear-gradient(135deg, #FFFFFF 0%, #F1F5F9 100%);
    box-shadow: 1px 1px 2px rgba(0, 0, 0, 0.12);
    flex-shrink: 0;
    border-radius: 2px;
}

.page-size-icon.free-icon {
    width: 28px;
    height: 20px;
    border-style: dashed;
}

.page-size-info {
    display: flex;
    flex-direction: column;
    line-height: 1.3;
}

.page-size-title {
    font-size: 12.5px;
    font-weight: 600;
    color: #111827;
}

.page-size-sub {
    font-size: 11px;
    color: #4B5563;
}

/* Menu Dropdown Agrupado do Cabeçalho (Formas, Texto e Imagem) */
.toolbar-dropdown {
    position: relative;
    display: inline-flex;
    align-items: center;
}

.toolbar-dropdown-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 14px;
    font-weight: 500;
    white-space: nowrap;
}

.toolbar-dropdown:has(.toolbar-dropdown-menu button.active) .toolbar-dropdown-btn {
    background-color: var(--primary);
    color: #FFFFFF;
}

.toolbar-dropdown-menu {
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    min-width: 195px;
    background: #FFFFFF;
    border: 1px solid #D1D5DB;
    border-radius: 8px;
    box-shadow: 0 12px 28px rgba(15, 23, 42, 0.18);
    z-index: 9999;
    padding: 6px;
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.toolbar-dropdown-menu button {
    width: 100%;
    justify-content: flex-start;
    font-size: 13.5px;
    padding: 8px 10px;
    border-radius: 6px;
}

.toolbar-dropdown-menu button i {
    width: 18px;
    text-align: center;
}

.toolbar-dropdown-divider {
    height: 1px;
    background-color: var(--border);
    margin: 4px 2px;
}

canvas { position: relative; z-index: 200; display: block; width: 100%; height: 100%; touch-action: none; } /* Camada de desenho acima dos objetos carimbados */
.workspace-hand canvas { pointer-events: none; }
#overlays { position: absolute; top: 0; left: 0; width: 100%; height: 100%; pointer-events: none; }

.bg-white { background-color: #FFFFFF !important; }
.bg-grid { background-color: #FFFFFF !important; background-image: linear-gradient(#D1D5DB 1px, transparent 1px), linear-gradient(90deg, #D1D5DB 1px, transparent 1px) !important; background-size: 40px 40px !important; }
.bg-lined { background-color: #FFFFFF !important; background-image: linear-gradient(#9CA3AF 1px, transparent 1px) !important; background-size: 100% 40px !important; }
.bg-cartesian { background-color: #FFFFFF !important; background-image: linear-gradient(to right, transparent calc(50% - 1px), #111827 calc(50% - 1px), #111827 calc(50% + 1px), transparent calc(50% + 1px)), linear-gradient(to bottom, transparent calc(50% - 1px), #111827 calc(50% - 1px), #111827 calc(50% + 1px), transparent calc(50% + 1px)), linear-gradient(#E5E7EB 1px, transparent 1px), linear-gradient(90deg, #E5E7EB 1px, transparent 1px) !important; background-size: 100% 100%, 100% 100%, 40px 40px, 40px 40px !important; background-position: center center, center center, calc(50% + 20px) calc(50% + 20px), calc(50% + 20px) calc(50% + 20px) !important; }
/* =========================================
   NOVO: CURSOR DINÂMICO DA BORRACHA
========================================= */
#eraser-cursor {
    position: absolute;
    pointer-events: none; /* Garante que os cliques passam através dele para o canvas */
    border: 2px solid rgba(156, 163, 175, 0.8);
    background-color: rgba(255, 255, 255, 0.4);
    border-radius: 50%;
    transform: translate(-50%, -50%); /* Centraliza exato no ponteiro do rato */
    display: none;
    z-index: 1000;
    box-shadow: 0 0 4px rgba(0,0,0,0.1);
}

.cursor-none {
    cursor: none !important;
}

/* =========================================
   FERRAMENTAS MATEMÁTICAS E UI FLUTUANTE
========================================= */
.math-tool { position: absolute; pointer-events: auto; box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.3); touch-action: none; z-index: 300; }
.rotate-handle { position: absolute; width: 30px; height: 30px; background: var(--primary); color: white; border-radius: 50%; display: flex; justify-content: center; align-items: center; cursor: grab; font-size: 12px; box-shadow: 0 2px 4px rgba(0,0,0,0.3); z-index: 10; }
.rotate-handle:active { cursor: grabbing; }
.close-handle { position: absolute; top: -15px; right: -15px; width: 24px; height: 24px; background: #EF4444; color: white; border-radius: 50%; display: flex; justify-content: center; align-items: center; cursor: pointer; font-size: 10px; z-index: 10; }

.tool-ruler { width: 1230px; height: 100px; background-color: var(--tool-bg); border: 2px solid var(--tool-border); border-radius: 4px; backdrop-filter: blur(4px); cursor: move; position: relative; }
.tool-ruler .rotate-handle { top: 15px; right: -40px; }
.tool-protractor { width: 400px; height: 200px; background-color: var(--tool-blue-bg); border: 2px solid var(--tool-border); border-bottom: 2px solid var(--tool-border); border-radius: 200px 200px 0 0; backdrop-filter: blur(4px); cursor: move; position: relative; }
.tool-protractor .rotate-handle { top: -20px; left: 50%; transform: translateX(-50%); }
.tool-protractor .close-handle { top: 12px; right: 24px; }
.tool-setsquare { width: 600px; height: 600px; cursor: move; position: relative; clip-path: polygon(0 0, 0 100%, 100% 100%); }
.tool-setsquare .rotate-handle { top: 250px; left: 100px; }
.tool-setsquare .close-handle { top: 24px; left: 10px; right: auto; }

.tool-compass { position: absolute; width: 0; height: 0; transform-origin: 0 0; z-index: 300; box-shadow: none; }
.compass-pin { position: absolute; top: 0; left: 0; transform: translate(-50%, -50%); width: 32px; height: 32px; background: radial-gradient(circle at 30% 30%, #ffffff, #9ca3af 50%, #374151); border: 2px solid #1f2937; border-radius: 50%; box-shadow: 0 6px 10px rgba(0,0,0,0.4); cursor: move; z-index: 10; }
.compass-pin::before { content: ''; position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); width: 14px; height: 14px; background: radial-gradient(circle, #111827, #374151); border-radius: 50%; border: 1px solid #6b7280; }
.compass-pin::after { content: ''; position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); width: 4px; height: 4px; background: #ef4444; border-radius: 50%; box-shadow: 0 0 2px #000; }
.compass-arm { position: absolute; top: -6px; left: 0; height: 12px; background: linear-gradient(to bottom, #e5e7eb 0%, #ffffff 30%, #9ca3af 70%, #4b5563 100%); border-top: 1px solid #fff; border-bottom: 1px solid #1f2937; box-shadow: 0 4px 6px rgba(0,0,0,0.3); z-index: 1; transform-origin: 0 50%; }
.compass-arm::after { content: ''; position: absolute; top: 0; left: 20px; right: 20px; bottom: 0; background-image: repeating-linear-gradient(to right, transparent, transparent 4px, rgba(0,0,0,0.2) 4px, rgba(0,0,0,0.2) 5px); }
.compass-pencil-container { position: absolute; top: 0; transform: translate(-50%, -100%); display: flex; flex-direction: column; align-items: center; cursor: pointer; z-index: 5; padding-bottom: 0px; filter: drop-shadow(0 6px 6px rgba(0,0,0,0.4)); }
.compass-draw-handle { width: 36px; height: 36px; background: linear-gradient(135deg, #10B981, #059669); border-radius: 50%; display: flex; justify-content: center; align-items: center; color: white; font-size: 16px; box-shadow: inset 0 2px 4px rgba(255,255,255,0.4), 0 2px 4px rgba(0,0,0,0.5); border: 2px solid #064e3b; cursor: grab; pointer-events: auto; z-index: 2; }
.compass-draw-handle:active { cursor: grabbing; }
.compass-pencil-body { width: 14px; height: 45px; background: linear-gradient(to right, #6b7280 0%, #d1d5db 40%, #9ca3af 60%, #374151 100%); border-left: 1px solid #1f2937; border-right: 1px solid #1f2937; margin-top: -8px; z-index: 1; pointer-events: auto; cursor: ew-resize; }
.compass-pencil-tip { width: 0; height: 0; border-left: 7px solid transparent; border-right: 7px solid transparent; border-top: 14px solid #d1d5db; position: relative; pointer-events: auto; }
.compass-pencil-graphite { width: 4px; height: 8px; background-color: var(--pencil-color); border-radius: 0 0 2px 2px; margin-top: -2px; pointer-events: auto; }
.compass-close { top: -25px; left: -25px; }

.compass-tooltip { position: absolute; bottom: 110%; left: 50%; transform: translateX(-50%); background-color: var(--toolbar-bg); color: #10B981; padding: 4px 8px; border-radius: 6px; font-size: 13px; font-weight: 600; pointer-events: none; opacity: 0; transition: opacity 0.2s; border: 1px solid var(--border); box-shadow: var(--shadow); z-index: 10; }
.compass-tooltip.show { opacity: 1; }
.compass-tooltip::after { content: ''; position: absolute; top: 100%; left: 50%; transform: translateX(-50%); border-width: 5px; border-style: solid; border-color: var(--toolbar-bg) transparent transparent transparent; }

.text-input-overlay { 
    position: absolute; 
    background: transparent; 
    border: 2px dashed var(--tool-border); 
    outline: none; 
    font-family: 'Poppins', sans-serif; 
    padding: 0px 4px; /* Zerado o padding vertical (Top/Bottom) */
    line-height: 1.2; /* Altura de linha estrita para sincronizar com o Canvas */
    z-index: 350;
    min-width: 50px; 
    min-height: 20px; 
    white-space: pre-wrap; 
    pointer-events: auto; 
    border-radius: 4px; 
    color: var(--pencil-color); 
}
.text-input-overlay:focus { border-color: var(--primary); background: var(--tool-bg); }

#measure-tooltip { position: absolute; background: rgba(31, 41, 55, 0.9); color: #10B981; padding: 6px 12px; border-radius: 6px; font-size: 13px; font-family: 'Poppins', sans-serif; font-weight: 600; pointer-events: none; display: none; z-index: 1000; white-space: nowrap; box-shadow: 0 4px 6px rgba(0,0,0,0.3); border: 1px solid #4B5563; }

/* =========================================
   ASSISTENTE MATEMÁTICO INTELIGENTE
========================================= */
/* Adaptação dos cards para a área de cálculos */
.calc-card { min-width: 100px; height: 100px; justify-content: center; }
.calc-card .lesson-icon { font-size: 28px; margin-bottom: 10px; }

.math-calc-overlay {
    position: absolute;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    font-family: 'Poppins', sans-serif;
    font-size: 35px; 
    color: var(--pencil-color);
    pointer-events: auto;
    z-index: 100;
    background: var(--tool-bg);
    padding: 30px 20px 15px 30px; /* Padding top maior para anotações */
    border-radius: 8px;
    border: 2px dashed var(--tool-border);
    transform: translate(-50%, -50%);
    box-shadow: 0 10px 25px rgba(0,0,0,0.1);
    outline: none; /* Para não ficar com borda azul do navegador quando focado */
}

.math-calc-overlay:not(.floating-obj),
.math-calc-overlay:focus {
    z-index: 250;
}

.math-calc-overlay:focus {
    border-color: var(--primary);
}

.math-grid { display: grid; grid-template-rows: auto auto auto auto; row-gap: 5px; }
.math-row { display: flex; justify-content: flex-end; gap: 8px; position: relative; min-height: 40px; }

/* Coluna de sinais (+ ou -) */
.math-sign { position: absolute; left: -30px; bottom: 0; color: #60A5FA; font-weight: 600; }

/* Linha separadora do resultado */
.math-grid-line { width: 100%; height: 4px; background-color: #60A5FA; border-radius: 2px; margin: 5px 0; }

/* Dígitos individuais */
.math-digit { width: 25px; text-align: center; position: relative; cursor: pointer; font-weight: 500; line-height: 1; }

/* Linha superior interativa da parcela 1 */
.math-row.top-row .math-digit:hover { background-color: rgba(0, 0, 0, 0.05); border-radius: 4px; }

/* Números pequenos (Vai 1 / Empréstimo) */
.math-small-note { position: absolute; top: -25px; left: 50%; transform: translateX(-50%); font-size: 18px; color: #EF4444; font-weight: 600; }

/* Traço riscando o número (Emprestou) */
.math-crossed { position: relative; color: #9CA3AF; }
.math-crossed::after { content: ''; position: absolute; top: 50%; left: -2px; right: -2px; height: 2px; background-color: #EF4444; transform: translateY(-50%) rotate(-25deg); }

/* =========================================
   LAYOUT DA DIVISÃO (MÉTODO DA CHAVE)
========================================= */
.math-div-container {
    display: flex;
    flex-direction: row;
    align-items: flex-start;
    gap: 0px;
}
.math-div-left {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    padding-right: 5px;
}
.math-div-right {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
}
.math-chave {
    border-left: 3px solid #60A5FA;
    border-bottom: 3px solid #60A5FA;
    padding: 0 5px 2px 10px;
    min-width: 60px;
    min-height: 40px;
    display: flex;
}
.math-quotient {
    padding: 5px 5px 0 10px;
    min-width: 60px;
    display: flex;
}
/* Alinhamento de etapas */
.math-div-step {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    width: 100%;
}
.math-div-subline {
    width: 100%;
    height: 3px;
    background-color: #60A5FA;
    margin: 2px 0;
}
.math-div-active {
    background-color: rgba(0, 0, 0, 0.05);
    border-radius: 4px;
}

/* =========================================
   OBJETOS FLUTUANTES E MÃOZINHA
========================================= */
.floating-obj {
    position: absolute;
    cursor: default;
}

/* Quando a Mãozinha está ativa, o cursor muda */
.workspace-hand .floating-obj {
    cursor: grab;
}
.workspace-hand .floating-obj:active {
    cursor: grabbing;
}

/* Remove os traços, sombra e fundo da caixa quando carimbado no quadro */
.math-calc-overlay.floating-obj:not(.selected):not(:focus) {
    border-color: transparent;
    background: transparent;
    box-shadow: none;
}

/* O aspeto do objeto quando está selecionado */
.floating-obj.selected {
    outline: 2px dashed var(--primary);
    background-color: rgba(79, 70, 229, 0.05);
}

/* O cantinho inferior direito para redimensionar */
.resize-handle {
    position: absolute;
    bottom: -6px;
    right: -6px;
    width: 15px;
    height: 15px;
    background-color: var(--primary);
    border: 2px solid #fff;
    border-radius: 50%;
    cursor: nwse-resize;
    display: none;
    z-index: 110;
}

.floating-obj.selected .resize-handle {
    display: block;
}

/* =========================================
   GRÁFICO DE COLUNAS
========================================= */
.math-chart-container { display: flex; flex-direction: column; gap: 10px; font-family: 'Poppins', sans-serif; padding: 10px; min-width: 300px; }
.math-chart-area { display: flex; height: 200px; margin-top: 10px; position: relative; padding-left: 10px; padding-bottom: 10px; }
.math-chart-x-axis { display: flex; border-top: 3px solid #111827; width: 100%; height: 100%; position: absolute; left: 50px; bottom: 0; align-items: flex-end; justify-content: space-around; padding-bottom: -30px; }
.math-chart-grid { position: absolute; left: 50px; bottom: 10px; top: 0; right: 0; display: flex; flex-direction: column-reverse; justify-content: space-between; z-index: -1; }
.math-chart-grid-line { width: 100%; height: 1px; background-color: #E5E7EB; border-top: 1px dashed #9CA3AF; }
.math-chart-y-axis { display: flex; flex-direction: column; justify-content: space-between; border-right: 3px solid #111827; padding-right: 8px; align-items: flex-end; height: 100%; }
.math-chart-bar { width: 30px; background: linear-gradient(to top, #4F46E5, #818CF8); border-radius: 4px 4px 0 0; transition: height 0.5s ease-out; border: 1px solid #312E81; }
.math-chart-col-wrapper { display: flex; flex-direction: column; justify-content: flex-end; align-items: center; height: 100%; min-width: 80px; position: relative; }
.math-chart-label { font-size: 14px; font-weight: 500; color: #374151; padding-top: 8px; white-space: nowrap; position: absolute; top: 100%; }
.math-chart-input-row { display: flex; align-items: baseline; gap: 10px; font-size: 20px; }
.math-chart-input { display: flex; border-bottom: 2px solid transparent; min-width: 50px; justify-content: center; padding: 2px 5px; color: var(--pencil-color); }
.math-chart-input.active { border-color: #D1D5DB; }

/* =========================================
   ARREDONDAMENTO
========================================= */
.math-arred-container { display: flex; flex-direction: column; gap: 15px; font-family: 'Poppins', sans-serif; padding: 10px; align-items: center; min-width: 300px; }
.math-arred-number-row { display: flex; align-items: flex-end; position: relative; margin-top: 30px; }
.math-arred-digit-box { display: flex; flex-direction: column; align-items: center; justify-content: flex-end; width: 35px; }
.math-arred-digit { font-size: 40px; font-weight: 500; color: var(--pencil-color); line-height: 1; text-align: center; }
.math-arred-target { border-bottom: 4px solid #4F46E5; }
.math-arred-neighbor { color: #F59E0B; }
.math-arred-rule-input { display: flex; justify-content: center; min-width: 40px; border-bottom: 2px solid transparent; font-size: 20px; font-weight: 600; color: var(--pencil-color); padding: 2px 5px; margin-bottom: 5px; }
.math-arred-rule-input.active { border-color: #D1D5DB; }
.math-arred-final-input { display: flex; border-bottom: 2px solid transparent; min-width: 100px; justify-content: center; font-size: 40px; font-weight: 600; padding: 5px; }
.math-arred-final-input.active { border-color: #D1D5DB; }




