/* General Body & Font Styling */
body { 
    font-family: 'Poppins', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: #343a40; 
    margin: 0; 
    padding: 20px; 
    display: flex; 
    flex-direction: column; 
    align-items: center; 
}
header { width: 100%; max-width: 1200px; text-align: center; margin-bottom: 30px; }
header h1 { color: #fff; font-weight: 600; text-shadow: 1px 1px 3px rgba(0,0,0,0.2); }
header p.subtitle { font-size: 16px; color: #f0f0f0; max-width: 600px; margin: 5px auto 0 auto; line-height: 1.5; }

/* Main Layout */
.main-container { display: flex; width: 100%; max-width: 1300px; gap: 0; background: #ffffff; border-radius: 12px; box-shadow: 0 8px 30px rgba(0,0,0,0.12); overflow: hidden; }
.pane { flex: 1; padding: 30px; display: flex; flex-direction: column; align-items: center; min-height: 600px; }
#input-pane { border-right: 1px solid #dee2e6; }
#output-pane { background-color: #f8f9fa; }

h2 { color: #343a40; font-weight: 600; margin-top: 0; margin-bottom: 20px; border-bottom: 1px solid #dee2e6; padding-bottom: 10px; width: 100%; text-align: center; }

/* Controls */
.controls { display: flex; flex-direction: column; align-items: center; gap: 20px; margin-bottom: 25px; width: 100%; }
.config-area { display: flex; flex-wrap: wrap; justify-content: center; gap: 20px; }
.block-config { display: flex; flex-direction: column; gap: 10px; padding: 15px; border: 1px solid #ced4da; border-radius: 8px; background-color: #f8f9fa; }
.block-config.hidden { display: none; }
input[type="number"] { width: 60px; padding: 8px; border: 1px solid #ced4da; border-radius: 6px; font-size: 14px; text-align: center; }
.input-group { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.input-group label { font-size: 14px; color: #495057; font-weight: 500; }

/* New Operation Selector */
.operation-selector-modern { width: 100%; max-width: 400px; }
.operation-selector-modern label { font-weight: 600; font-size: 14px; color: #495057; margin-bottom: 8px; display: block; text-align: center;}
#operation-select {
    width: 100%;
    padding: 10px;
    font-size: 16px;
    font-family: 'Poppins', sans-serif;
    border: 1px solid #ced4da;
    border-radius: 8px;
    background-color: #fff;
    cursor: pointer;
}
#operation-select:focus { outline: 2px solid #007bff; }

/* Description Box */
.tool-description { 
    font-size: 14px; color: #495057; background-color: #e9ecef; 
    padding: 15px; border-radius: 8px; text-align: center; line-height: 1.6;
    width: 100%; max-width: 400px; box-sizing: border-box; 
    border-left: 5px solid #007bff;
    transition: background-color 0.3s;
}
.tool-description b { color: #343a40; }

/* Buttons */
.button-row { display: flex; justify-content: center; gap: 10px; width: 100%; }
button { padding: 10px 20px; font-size: 16px; font-weight: 500; font-family: 'Poppins', sans-serif; color: #fff; border: none; border-radius: 6px; cursor: pointer; transition: all 0.2s ease; }
button:hover { transform: translateY(-1px); }
#generate-btn { background-color: #007bff; }
#generate-btn:hover { background-color: #0069d9; box-shadow: 0 4px 12px rgba(0, 123, 255, 0.2); }
.util-btn { background-color: #6c757d; }
.util-btn:hover { background-color: #5a6268; box-shadow: 0 4px 12px rgba(0,0,0,0.1); }
.util-btn.save { background-color: #28a745; }
.util-btn.save:hover { background-color: #218838; }
.util-btn.load { background-color: #fd7e14; }
.util-btn.load:hover { background-color: #e36f0c; }
#op-btn { background-color: #28a745; margin-top: 20px; }
#op-btn:hover { background-color: #218838; box-shadow: 0 4px 12px rgba(40, 167, 69, 0.2); }

/* Block Display & Input Styling */
.blocks-display-area { display: flex; flex-wrap: wrap; gap: 20px; justify-content: center; align-items: flex-start; width: 100%; position: relative; }
.block-wrapper { display: flex; flex-direction: column; justify-content: center; align-items: center; gap: 5px; }
.matrix-label { font-size: 24px; font-weight: bold; font-family: 'Times New Roman', serif; }
.placeholder { color: #6c757d; text-align: center; padding: 20px; }
.grid-block { display: grid; border-radius: 4px; overflow: hidden; border: 3px solid; box-shadow: 0 4px 15px rgba(0,0,0,0.1); }
.grid-cell { width: 60px; height: 45px; display: flex; justify-content: center; align-items: center; font-size: 14px; font-weight: 500; color: #343a40; background-color: #f0f0f0; border: none; border-right: 1px solid; border-bottom: 1px solid; border-color: #ccc; box-sizing: border-box; }
.grid-cell-input { width: 60px; height: 45px; padding: 0; margin: 0; border: none; border-right: 1px solid #888; border-bottom: 1px solid #888; text-align: center; font-size: 16px; font-family: 'Roboto Mono', monospace; box-sizing: border-box; background-color: rgba(255,255,255,0.7); box-shadow: inset 0 1px 3px rgba(0,0,0,0.1); }
.grid-cell-input:focus { outline: 2px solid #007bff; z-index: 1; }

/* Color Themes */
.grid-block.theme-blue { border-color: #17a2b8; }
.grid-block.theme-red { border-color: #fd7e14; }
.grid-block.theme-purple { border-color: #6610f2; }
.grid-block.theme-green { border-color: #28a745; }
.grid-block.theme-orange { border-color: #fd7e14; }

/* Result Formatting */
#result-container {
    width: 100%;
    animation: fadeInResult 0.5s forwards;
}
@keyframes fadeInResult { from { opacity: 0; } to { opacity: 1; } }

#result-container .latex-result { 
    text-align: left; padding: 20px; font-size: 1.1em; line-height: 1.8;
    background-color: #fff; border-radius: 8px; border: 1px solid #dee2e6;
    width: 100%; box-sizing: border-box;
}
#result-container .latex-result p, #result-container .latex-result li { margin: 15px 0; }
#result-container .latex-result h3 { 
    margin-top: 20px; margin-bottom: 10px;
    border-bottom: 2px solid #007bff; 
    padding-bottom: 5px; color: #343a40;
}
#result-container .latex-result code { 
    background-color: #e9ecef; padding: 2px 5px; border-radius: 4px; 
    font-family: 'Roboto Mono', monospace;
}
#result-container .final-result-grid {
    margin-top: 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px;
}

/* Utility Class */
.hidden { display: none !important; }