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

body {
    font-family: Arial, sans-serif;
    line-height: 1.6;
    padding: 0;
    background-color: #f4f4f4;
    color: #333;
}

header {
    background: #333;
    color: #fff;
    padding: 1rem 20px;
    text-align: center;
    margin-bottom: 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

header h1 {
    margin: 0;
    font-size: 1.5em;
    flex-grow: 0;
}

#language-switcher {
    display: flex;
    gap: 10px;
    z-index: 100;
    font-size: 24px; /* This will control the size of the flags */
}

#language-switcher .language-flag {
    cursor: pointer;
    font-size: 28px;
    transition: transform 0.2s, filter 0.2s;
    filter: drop-shadow(0 0 2px rgba(0,0,0,0.3));
    border-radius: 4px;
    padding: 2px;
}

#language-switcher .language-flag:hover {
    transform: scale(1.1);
    filter: drop-shadow(0 0 4px rgba(0,0,0,0.5));
}

/* App Container - Sidebar Layout */
.app-container {
    display: flex;
    align-items: flex-start;
    max-width: 1400px;
    margin: 0 auto;
    gap: 0;
    min-height: calc(100vh - 120px);
    background: #fff;
}

/* Topic Sidebar */
.topic-sidebar {
    width: 280px;
    background: #f8f9fa;
    border-right: 2px solid #dee2e6;
    padding: 20px 15px;
    overflow-y: auto;
    flex-shrink: 0;
    height: 100%;
}

.topic-sidebar h2 {
    margin: 0 0 20px 0;
    font-size: 1.2em;
    color: #333;
    padding-bottom: 10px;
    border-bottom: 2px solid #dee2e6;
}

/* Topic Tree Navigation */
.topic-tree {
    list-style: none;
    margin: 0;
    padding: 0;
}

.topic-category {
    margin-bottom: 10px;
}

.category-header {
    display: flex;
    align-items: center;
    padding: 8px 10px;
    cursor: pointer;
    background: #e9ecef;
    border-radius: 4px;
    transition: background 0.2s;
    user-select: none;
}

.category-header:hover {
    background: #dee2e6;
}

.category-toggle {
    display: inline-block;
    width: 20px;
    font-size: 12px;
    transition: transform 0.2s;
    color: #495057;
}

.topic-category.expanded .category-toggle {
    transform: rotate(90deg);
}

.category-name {
    font-weight: 600;
    color: #495057;
    font-size: 0.95em;
}

.topic-list {
    list-style: none;
    margin: 0;
    padding: 0;
    max-height: 0;
    overflow: hidden;
    opacity: 0;
    transition: max-height 0.3s ease-out, opacity 0.2s ease-out;
}

.topic-category.expanded .topic-list {
    max-height: 1000px;
    opacity: 1;
    transition: max-height 0.3s ease-in, opacity 0.2s ease-in;
}

.topic-item {
    padding: 8px 10px 8px 35px;
    cursor: pointer;
    transition: all 0.2s;
    border-left: 3px solid transparent;
    font-size: 0.9em;
    color: #495057;
}

.topic-item:hover {
    background: #e3f2fd;
    border-left-color: #2196f3;
}

.topic-item.selected {
    background: #e8f5e8;
    border-left-color: #4caf50;
    font-weight: 600;
    color: #2e7d32;
}

main {
    flex: 1;
    background: #fff;
    padding: 20px;
    overflow-y: auto;
}

section {
    margin-bottom: 20px;
    padding: 15px;
    border: 1px solid #ddd;
    border-radius: 4px;
}

h2 {
    margin-bottom: 10px;
    color: #333;
}

/* Old Topic Grid Styles - Deprecated, kept for compatibility */
.topic-grid {
    display: none;
}

.topic-card {
    display: none;
}

/* Responsive Design */
@media (max-width: 768px) {
    .app-container {
        flex-direction: column;
    }

    .topic-sidebar {
        width: 100%;
        border-right: none;
        border-bottom: 2px solid #dee2e6;
        max-height: 400px;
    }

    main {
        padding: 15px;
    }
}

@media (max-width: 480px) {
    .topic-sidebar {
        padding: 15px 10px;
    }

    .topic-item {
        padding: 6px 8px 6px 25px;
        font-size: 0.85em;
    }

    .category-name {
        font-size: 0.9em;
    }
}

/* Controls Panel */
.controls label {
    display: block;
    margin-bottom: 5px;
}

.controls input[type="number"],
.controls input[type="text"],
.controls select {
    width: 100%;
    padding: 8px;
    margin-bottom: 10px;
    border-radius: 4px;
    border: 1px solid #ccc;
}

.controls input[type="checkbox"] {
    margin-right: 5px;
}

/* Buttons */
.button {
    display: inline-block;
    background: #5cb85c;
    color: #fff;
    padding: 10px 15px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    margin-right: 10px;
    font-size: 1em;
}

.button:hover {
    background: #4cae4c;
}

#print-button {
    background: #f0ad4e;
}

#print-button:hover {
    background: #eea236;
}

/* Problems Output Area */
.problems {
    background-color: #e9e9e9;
}

#problems-container {
    min-height: 100px; /* Placeholder height */
    padding: 10px;
    border: 1px dashed #ccc;
    background-color: #fff; /* White background for the content area */
}

#problems-container h3 {
    margin-bottom: 10px;
    font-size: 1.2em;
    color: #333;
}

#problems-container .problem-subtitle {
    font-size: 0.9em;
    color: #555;
    margin-bottom: 15px;
}

.problem {
    padding: 8px 0;
    border-bottom: 1px solid #eee;
    font-size: 1.1em; /* Slightly larger font for problems */
    display: flex; /* For better alignment of problem parts if needed */
    align-items: center;
}

.problem:last-child {
    border-bottom: none;
}

.problem .blank {
    display: inline-block;
    width: 70px; /* Adjust width as needed */
    border-bottom: 1px solid #333;
    margin-left: 5px;
    margin-right: 5px;
    text-align: center;
    font-weight: bold;
}

.error-message {
    color: red;
    font-weight: bold;
}

/* Multiplication Chart Specific Styles */
.multiplication-chart {
    width: 100%;
    border-collapse: collapse;
    margin-top: 15px;
    font-size: 0.9em; /* Adjust as needed */
}

.multiplication-chart th,
.multiplication-chart td {
    border: 1px solid #ccc;
    padding: 8px;
    text-align: center;
    min-width: 30px; /* Ensure cells are not too small */
    height: 30px;
}

.multiplication-chart th {
    background-color: #f0f0f0;
    font-weight: bold;
}

.multiplication-chart td {
    background-color: #fff;
}

.multiplication-chart td.prefilled {
    background-color: #e0ffe0; /* A light green background */
    font-weight: bold;
    color: #228B22; /* Forest green text color */
}


/* --- Styles for Columnar Addition/Subtraction & Multiplication Problems --- */
#problems-container .arithmetic-grid { /* Applied to a div inside #problems-container */
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); /* Adjust minmax for desired problem width */
    gap: 30px 25px; /* Row gap, Column gap */
    align-items: start; /* Align items to the start of their grid cell */
    padding-top: 15px; /* Space from the "Addition & Subtraction Problems" header */
}

.arith-problem {
    font-family: 'Courier New', Courier, monospace; /* Monospaced font for alignment */
    font-size: 1.6em; /* Larger font for clarity */
    line-height: 1.3;
    /* display: inline-block; */ /* Not needed if parent is grid */
    text-align: right;
    /* padding: 10px; */ /* Let grid gap handle spacing */
    /* border: 1px solid #f0f0f0; */ /* Optional border around each problem */
    /* border-radius: 3px; */
    /* background-color: #fdfdfd; */
    min-width: 100px; /* Ensure a minimum width based on font and digits */
    margin: 0 auto; /* Center in grid cell if cell is wider */
}

.arith-problem .operand-1 {
    padding-right: 5px; /* Align with operand-2 numbers */
    margin-bottom: 2px; /* Small space before operator line */
}

.arith-problem .operator-operand2 {
    display: flex;
    /* justify-content: space-between; */ /* Operator will be on left of operand2 */
    align-items: flex-end; /* Align along the bottom of the numbers */
    width: 100%;
}

.arith-problem .operator {
    padding-right: 10px; /* Space between operator and operand2's start */
    min-width: 1em; /* Ensure operator takes some space */
    text-align: left;
    color: #333;
}
.arith-problem .operand-2 {
    flex-grow: 1; /* Operand 2 takes remaining space to ensure right alignment */
    padding-right: 5px; /* Consistent with operand-1 */
}


.arith-problem .problem-line {
    border-bottom: 2.5px solid #000;
    margin-top: 5px;
    margin-bottom: 8px;
    min-height: 2px;
}

.arith-problem .answer-space {
    min-height: 3.5em; /* Generous space for writing the answer and carry/borrow marks */
    /* background-color: #f0f8ff; /* Light blue for answer space, optional */
}

/* Style for linear division problems when they are grid items */
.arithmetic-grid .division-problem {
    font-size: 1.2em; /* Or adjust to match .problem style */
    padding: 10px 8px;
    text-align: left;
    border: 1px solid #f0f0f0;
    background-color: #fdfdfd;
    border-radius: 3px;
    min-height: 3em; /* Try to match height of columnar problems */
    display: flex;
    align-items: center;
    justify-content: flex-start; /* Align content (numbering + problem) to the left */
}

.arithmetic-grid .division-problem .blank {
    /* Ensure .blank styles from general .problem apply or redefine here if needed */
}

.arithmetic-grid .multiplication-problem {
    /* Inherits .arith-problem styles. Add specific overrides if necessary. */
    /* e.g., if multiplication needs more answer space than addition */
}

/* --- Styles for User-Requested Division Problems --- */
.arith-problem.division-problem-user {
    display: flex;
    align-items: flex-start;
    text-align: center;
}

.division-problem-user .dividend {
    padding: 0 10px;
}

.division-problem-user .divisor-container {
    position: relative;
    padding-left: 12px; /* Space for the separator */
}

.division-problem-user .divisor-container::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    height: 1.5em; /* approximate height of a line of text */
    width: 2.5px;
    background-color: #000;
}

.division-problem-user .divisor {
    padding-bottom: 5px;
}

.division-problem-user .answer-line {
    border-top: 2.5px solid #000; /* Horizontal line for the answer */
}

.division-problem-user .answer-space {
    min-height: 3.5em; /* Space for the answer */
}

.warning-message {
    color: #8a6d3b; /* Bootstrap warning color */
    background-color: #fcf8e3;
    border: 1px solid #faebcc;
    padding: 10px;
    border-radius: 4px;
    margin-bottom: 15px;
}

/* --- Styles for Digital Root Self-Check Grid --- */
.digital-root-check-grid-container {
    margin-top: 30px;
    padding: 15px;
    border: 1px solid #e0e0e0;
    background-color: #f9f9f9;
    border-radius: 5px;
}

.digital-root-check-grid-container h4 {
    margin-top: 0;
    margin-bottom: 5px; /* Reduced margin */
    font-size: 1.1em;
    color: #333;
    text-align: center;
}
.digital-root-check-grid-container p { /* For the Mult/Div explanation text */
    text-align: center;
    font-size: 0.85em;
    color: #555;
    margin-bottom: 10px;
}

.digital-root-check-grid {
    display: grid;
    /* Dynamically set column count via JS or try to match problem grid: */
    grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); /* Match problem grid */
    gap: 10px 25px; /* Smaller gap for DR grid cells; Row gap, Column gap */
    justify-items: center; /* Center cells horizontally */
}

.dr-cell {
    font-family: 'Courier New', Courier, monospace;
    font-size: 1.4em; /* Prominent display */
    font-weight: bold;
    color: #0056b3;
    background-color: #fff;
    border: 1px solid #d4d4d4;
    border-radius: 4px;
    padding: 8px 5px; /* Adjust padding */
    min-width: 40px; /* Ensure a decent width */
    height: 40px; /* Ensure a decent height */
    display: flex;
    justify-content: center;
    align-items: center;
    text-align: center;
}

/* Grid for Fraction Simplification Problems */
.fraction-problem-grid {
    /* Uses .arithmetic-grid styles by sharing the class */
    /* We can add specific overrides here if needed */
    gap: 20px 15px; /* Potentially different gap */
}

.fraction-problem-item {
    font-size: 1.2em;
    padding: 10px;
    border: 1px solid #e0e0e0;
    border-radius: 4px;
    background-color: #fdfdfd;
    display: flex;
    flex-direction: column; /* Stack problem content and calculation space */
    align-items: center;    /* Center the problem content horizontally */
    justify-content: flex-start; /* Align content to the top, allowing calculation-space to fill below */
    min-height: 7em; /* Significantly increased height for calculation space */
}

.fraction-problem-item .problem-content {
    display: flex;
    align-items: center; /* Vertically align fraction and equals sign */
    /* font-size: 1.2em; /* Already inherited or can be set on fraction-problem-item */
    margin-bottom: 5px; /* Small space before calculation area */
    width: 100%; /* Ensure it takes width for justify-content if needed */
    justify-content: center; /* Center the fraction and equals sign group */
}

.fraction-problem-item .calculation-space {
    flex-grow: 1; /* Takes up remaining vertical space */
    width: 100%;  /* Full width for scribbling */
    /* border-top: 1px dashed #ccc; /* Optional: visual separator for the calculation area */
    min-height: 2em; /* Ensure some minimum space even if flex-grow doesn't give much */
}

/* Styling for the fraction itself */
.fraction {
    display: inline-block;
    text-align: center;
    vertical-align: middle; /* Align with surrounding text */
    margin: 0 8px; /* Space around the fraction */
    font-family: 'Courier New', Courier, monospace; /* Good for consistent width */
    position: relative; /* For absolute positioning of the vinculum (line) if chosen */
}

.fraction .numerator,
.fraction .denominator {
    display: block;
    padding: 0 5px; /* Padding around number */
    line-height: 1.1; /* Snug line height */
    font-size: 1.1em; /* Slightly larger numbers */
}

.fraction .numerator {
    border-bottom: 2px solid #333; /* Vinculum (fraction line) */
    padding-bottom: 2px;
}

.fraction .denominator {
    padding-top: 2px;
}


/* Footer */
footer {
    text-align: center;
    margin-top: 30px;
    padding-top: 15px;
    border-top: 1px solid #eee;
    font-size: 0.9em;
    color: #777;
}

/* Print-specific styles */
@media print {
    html, body { /* Ensure html and body can expand */
        height: 100%;
    }
    body {
        position: relative; /* Needed for absolute positioning of children */
        padding: 0;
        background-color: #fff; /* Ensure white background for printing */
        font-size: 12pt; /* Adjust base font size for print */
        display: flex; /* Make body a flex container to manage main's height */
        flex-direction: column;
    }

    header,
    .topic-sidebar,
    #topic-selection-section,
    .controls,
    #actions-panel,
    footer,
    nav /* if you add a nav */ {
        display: none !important;
    }

    .app-container {
        display: block;
    }

    main {
        max-width: 100%;
        margin: 0; /* Standard browser print margins will apply outside <html> */
        padding: 10mm 10mm 0 10mm; /* Add some padding, but bottom padding handled by #problems-container or fixed key */
        border: none;
        box-shadow: none;
        display: flex; /* Use flexbox on main */
        flex-direction: column;
        flex-grow: 1; /* Allow main to grow if body is flex */
        /* Attempt to make main fill the page height minus space for fixed key */
        /* 100vh in print context is one page. Subtract estimated fixed key height + bottom margin */
        min-height: calc(100vh - 60mm); /* 50mm was padding, key itself is ~10-15mm high. Adjust as needed. */
    }

    #output-area { /* This contains #problems-container */
        border: none;
        padding: 0;
        background-color: #fff;
        flex-grow: 1; /* Allow output area to take space in main */
        display: flex;
        flex-direction: column;
    }
    
    #problems-container {
        min-height: auto;
        border: none;
        padding-bottom: 10mm; /* Reduced padding since we're no longer using fixed positioning */
        flex-grow: 1; /* Allow problems container to take available space in #output-area */
        display: flex; 
        flex-direction: column;
    }

    #problems-container .arithmetic-grid,
    #problems-container .fraction-problem-grid { 
        /* display: grid !important; -- Already ensured above or inherited */
        grid-template-columns: repeat(4, 1fr); /* Example: 4 columns for print, adjust as needed */
        /* gap: 15mm 8mm; /* More generous spacing for print */
        /* padding-top: 5mm; */ /* Let align-content handle spacing */
        flex-grow: 1; /* Make the grid itself take available vertical space in #problems-container */
        align-content: space-around; /* Distribute space between rows */
        gap: 10mm 8mm !important; /* Adjust gap for row and column, row gap increased */
    }

    .problem { /* This is for the old linear problem style, might not be needed if all are grid */
        page-break-inside: avoid; /* Try to keep problems from splitting across pages */
        padding: 5px 0; /* Adjust padding for print */
    }

    .arith-problem {
        font-size: 14pt; /* Ensure good print size */
        border: none; /* Remove borders for cleaner print */
        padding: 5px 0; /* Adjust padding for print */
        page-break-inside: avoid;
    }
    .arith-problem .answer-space {
        min-height: 1.8cm; /* Specific height for print answer */
    }
    .arith-problem .problem-line {
        border-bottom-width: 2px;
    }

    /* Print-specific adjustments for Digital Root Grid */
    .digital-root-check-grid-container {
        margin-top: 8mm;
        padding: 3mm;
        border: 1px solid #ccc;
        background-color: #fff;
        page-break-before: avoid;
        page-break-after: avoid;
    }
    .digital-root-check-grid-container h4 {
        font-size: 12pt;
    }
    .digital-root-check-grid-container p {
        font-size: 9pt;
    }
    .digital-root-check-grid {
        /* Match column count of problem grid in print, e.g., repeat(4, 1fr) */
        grid-template-columns: repeat(6, 1fr); /* More columns to fit more items per row */
        gap: 3mm 3mm; /* Reduced gap */
    }
    .dr-cell {
        font-size: 10pt;
        border: 1px solid #bbb;
        min-width: 8mm;
        height: 8mm;
        padding: 1mm;
        page-break-inside: avoid;
    }

    /* --- Styles for Rational Operations Problems --- */
    /* .fraction-problem-grid (from canonical) can be reused if styling is similar */

    .fraction-operation-item {
        font-size: 1.2em; /* Base font size for the item */
        padding: 10px;
        border: 1px solid #e0e0e0;
        border-radius: 4px;
        background-color: #fdfdfd;
        display: flex;
        flex-direction: column; 
        align-items: center;    
        justify-content: flex-start; 
        min-height: 7em; /* Consistent with simplification problems for vertical space */
    }

    .fraction-operation-item .problem-content {
        display: flex;
        align-items: center; 
        justify-content: center;
        margin-bottom: 5px; 
        width: 100%;
        /* font-size for fractions within is handled by .fraction class */
    }

    .fraction-operation-item .operation-symbol {
        font-size: 1.5em; /* Make operator stand out from fraction numbers */
        font-weight: bold;
        margin: 0 10px; 
        color: #333;
        line-height: 1; /* Ensure it aligns well vertically with fractions */
    }

    /* .fraction styles are reused */
    /* .calculation-space style (if added to HTML structure) is reused from .fraction-problem-item .calculation-space */


     /* Print specific for fractions */
             .fraction-problem-grid { /* This assumes .fraction-problem-grid is a class on the same element as .arithmetic-grid or a child */
                 display: grid !important; /* Ensure grid display */
                 /* Assuming grid-template-columns is set similar to .arithmetic-grid if it's a top-level problem grid */
                 /* If it's just a class on .arithmetic-grid, this display:grid might be redundant but harmless */
                 gap: 15mm 10mm; 
             }

        /* Styles for Control Sum Key Grid (Fractions) */
        .control-sum-key-container {
        margin-top: 30px;
        padding: 15px;
        border: 1px solid #e0e0e0;
        background-color: #f9f9f9;
        border-radius: 5px;
    }

    .control-sum-key-container h4 {
        margin-top: 0;
        margin-bottom: 5px; 
        font-size: 1.1em;
        color: #333;
        text-align: center;
    }
    .control-sum-key-container p { /* For the explanation text */
        text-align: center;
        font-size: 0.85em;
        color: #555;
        margin-bottom: 10px;
    }

    .control-sum-grid {
        display: grid;
        grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); /* Match problem grid */
        gap: 10px 15px; /* Row gap, Column gap */
        justify-items: center;
    }

    .control-sum-cell {
        font-family: 'Courier New', Courier, monospace;
        font-size: 1.4em; 
        font-weight: bold;
        color: #0056b3; /* Consistent with DR cell color */
        background-color: #fff;
        border: 1px solid #d4d4d4;
        border-radius: 4px;
        padding: 8px 5px; 
        min-width: 40px; 
        height: 40px; 
        display: flex;
        justify-content: center;
        align-items: center;
        text-align: center;
    }
    .fraction-problem-item {
        font-size: 12pt;
        border: none;
        page-break-inside: avoid;
        min-height: 2.5cm; /* Adjusted min-height for print */
    }
    .fraction .numerator, .fraction .denominator {
        font-size: 13pt;
    }
    .fraction .numerator {
        border-bottom-width: 1.5px; /* Slightly thinner for print */
    }

    /* Print specific for fraction operations */
    .fraction-operation-item {
        font-size: 12pt;
        border: none;
        min-height: 2.5cm; 
        page-break-inside: avoid;
    }
    .fraction-operation-item .operation-symbol {
        font-size: 1.3em; 
        margin: 0 6px; /* Adjusted margin for print */
    }
    /* .fraction print styles are inherited */
    /* .calculation-space print styles are inherited */

    /* Print specific for proportion problems */
    .proportion-problem-grid {
        display: grid !important;
        grid-template-columns: repeat(2, 1fr) !important; /* 2 columns for print */
        gap: 20mm 15mm !important;
    }
    
    .proportion-problem-item {
        font-size: 11pt;
        border: 1px solid #ccc;
        min-height: 2.5cm; /* Reduced from 6cm since we removed sections */
        page-break-inside: avoid;
        padding: 6mm; /* Reduced padding */
    }
    
    .proportion-problem-item .problem-header {
        font-size: 11pt;
        margin-bottom: 5mm;
    }
    
    .proportion {
        font-size: 1.2em;
    }
    
    .answer-section .answer-line {
        border-bottom-width: 1.5px;
        min-width: 60px;
    }
    
    .control-check-section {
        border-top: 1px dashed #999;
        padding-top: 5mm;
    }
    
    .cross-check-line .check-answer-line {
        border-bottom-width: 1px;
        min-width: 40px;
    }

    /* Print specific for decimal/rational problems */
    .decimal-rational-problem-grid {
        display: grid !important;
        grid-template-columns: repeat(2, 1fr) !important; /* 2 columns for print */
        gap: 15mm 10mm !important;
    }
    
    .decimal-rational-problem-item {
        font-size: 11pt;
        border: 1px solid #ccc;
        min-height: 2.5cm;
        page-break-inside: avoid;
        padding: 6mm;
    }
    
    .fraction-display,
    .decimal-display {
        font-size: 1.1em;
        margin-bottom: 4mm;
    }
    
    .fraction-display .answer-space,
    .decimal-display .answer-space {
        border-bottom-width: 1.5px;
        min-width: 60px;
        max-width: 120px;
    }

    /* Print-specific adjustments for Control Sum containers only */
    .control-sum-key-container {
        position: relative;
        margin-top: 8mm;
        margin-bottom: 10mm;
        width: auto;
        background-color: #fdfdfd;
        border: 1px solid #ccc;
        padding: 3mm;
        page-break-inside: avoid !important;
        page-break-before: avoid;
        clear: both; 
    }
    .digital-root-check-grid-container h4, /* Shared style for h4 in key containers */
    .control-sum-key-container h4 {
        font-size: 12pt;
    }
    .digital-root-check-grid-container p, /* Shared style for p in key containers */
    .control-sum-key-container p {
        font-size: 9pt;
    }

    .digital-root-check-grid,
    .control-sum-grid {
        display: grid !important; 
        grid-template-columns: repeat(auto-fill, minmax(30px, 1fr)) !important; /* Use auto-fill to adapt */
        gap: 3mm !important; 
        list-style-type: none !important; 
        padding: 0 !important; 
        margin: 0 auto !important; /* Center grid if its container is wider */
        max-width: 100%;
    }

    .dr-cell,
    .control-sum-cell {
        display: flex; 
        align-items: center;
        justify-content: center;
        border: 1px solid #ccc; 
        font-size: 8pt; /* Even smaller if needed */
        height: 0.7cm;       
        padding: 1mm; 
        page-break-inside: avoid;
        overflow: hidden; 
        text-overflow: ellipsis;
        margin: 0; 
    }

    /* New style for the comma-separated line of sums in rational sections' keys */
    /* This targets the <p class="control-sum-line"> inside the key container */
    .control-sum-key-container .control-sum-line {
        font-size: 8pt;          /* Small font for the compact list */
        text-align: center;      /* Center the text block */
        word-wrap: break-word;   /* Allow long line of numbers to wrap */
        line-height: 1.3;        /* Adjust line height for wrapped text */
        padding: 1mm 3mm;      /* Give it a little horizontal padding within the fixed footer */
        margin: 0 auto;          /* Center the paragraph block if its container is wider */
        max-width: 90%;          /* Prevent it from touching edges of the footer container */
    }


    h1, h2 {
        /* Optionally style headers differently for print or hide them if part of .controls */
    }
}

.range-inputs > div {
    display: flex;
    align-items: center;
}

.range-inputs label {
    display: block;
    margin-bottom: 5px;
}

.range-inputs div > label {
    margin-bottom: 0;
    margin-right: 5px;
}

.range-inputs input {
    width: 80px !important;
    margin-right: 10px;
    text-align: center;
}

/* --- Styles for Proportion Problems --- */
.proportion-problem-grid {
    /* Uses .arithmetic-grid styles by sharing the class */
    gap: 25px 20px; /* Potentially different gap for proportion problems */
}

.proportion-problem-item {
    font-size: 1.1em;
    padding: 15px;
    border: 1px solid #e0e0e0;
    border-radius: 4px;
    background-color: #fdfdfd;
    display: flex;
    flex-direction: column;
    min-height: 4em; /* Reduced since we removed answer and control check sections */
}

.proportion-problem-item .problem-header {
    font-weight: bold;
    font-size: 1.1em;
    margin-bottom: 10px;
    text-align: center;
    color: #333;
}

.proportion-problem-item .problem-content {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
}

.proportion-equation {
    margin-bottom: 15px;
    text-align: center;
}

.proportion-equation .solve-text {
    display: block;
    margin-bottom: 8px;
    font-weight: bold;
    color: #333;
}

.proportion {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.3em;
}

.proportion .equals {
    margin: 0 15px;
    font-size: 1.2em;
    font-weight: bold;
}

.answer-section {
    margin-bottom: 15px;
    display: flex;
    align-items: center;
    justify-content: flex-start;
}

.answer-section .answer-label {
    font-weight: bold;
    margin-right: 10px;
}

.answer-section .answer-line {
    flex-grow: 1;
    height: 2px;
    border-bottom: 2px solid #333;
    min-width: 80px;
    max-width: 120px;
}

.control-check-section {
    border-top: 1px dashed #ccc;
    padding-top: 10px;
    flex-grow: 1;
}

.control-check-header {
    font-weight: bold;
    margin-bottom: 8px;
    color: #555;
}

.cross-multiplication {
    font-size: 0.95em;
}

.cross-check-line {
    display: flex;
    align-items: center;
    margin-bottom: 5px;
}

.cross-check-line .cross-product {
    margin-right: 10px;
    min-width: 80px;
    text-align: left;
}

.cross-check-line .check-answer-line {
    flex-grow: 1;
    height: 1px;
    border-bottom: 1px solid #666;
    min-width: 50px;
    max-width: 80px;
}

.verification-note {
    font-size: 0.85em;
    color: #666;
    font-style: italic;
    margin-top: 5px;
    text-align: center;
}

/* --- Styles for Decimal/Rational Conversion Problems --- */
.decimal-rational-problem-grid {
    /* Uses .arithmetic-grid styles by sharing the class */
    gap: 20px 15px; /* Adjust gap for decimal/rational problems */
}

.decimal-rational-problem-item {
    font-size: 1.1em;
    padding: 15px;
    border: 1px solid #e0e0e0;
    border-radius: 4px;
    background-color: #fdfdfd;
    display: flex;
    flex-direction: column;
    min-height: 4em; /* Further reduced height since no conversion prompt */
}

.decimal-rational-problem-item .problem-content {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
}

.fraction-display,
.decimal-display {
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 15px;
    font-size: 1.3em;
}

.decimal-number {
    font-family: 'Courier New', Courier, monospace;
    font-size: 1.2em;
    font-weight: bold;
}

.fraction-display .equals,
.decimal-display .equals {
    margin-right: 10px;
    font-weight: bold;
}

.fraction-display .answer-space,
.decimal-display .answer-space {
    flex-grow: 1;
    height: 2px;
    border-bottom: 2px solid #333;
    min-width: 100px;
    max-width: 200px;
}

/* --- House Problems Styles --- */
.house-problems-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 20px;
    margin-top: 20px;
    align-items: start;
}

.house-problem {
    display: flex;
    flex-direction: column;
    align-items: center;
    background: white;
    padding: 15px;
    border-radius: 8px;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
    border: 1px solid #ddd;
}

/* Print styles for house problems */
@media print {
    .house-problems-grid {
        grid-template-columns: repeat(3, 1fr) !important;
        gap: 15px !important;
        page-break-inside: avoid;
    }

    .house-problem {
        break-inside: avoid;
        margin-bottom: 15px;
        box-shadow: none;
        border: 1px solid #333;
    }

    .house-problem svg {
        width: 180px !important;
        height: 155px !important;
    }
}

/* --- Pyramid Problems Styles --- */
.pyramid-problems-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 20px;
    margin-top: 20px;
    align-items: start;
}

.pyramid-problem {
    display: flex;
    flex-direction: column;
    align-items: center;
    background: white;
    padding: 15px;
    border-radius: 8px;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
    border: 1px solid #ddd;
}

/* Print styles for pyramid problems */
@media print {
    .pyramid-problems-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 15px !important;
        page-break-inside: avoid;
    }

    .pyramid-problem {
        break-inside: avoid;
        margin-bottom: 20px;
        box-shadow: none;
        border: 1px solid #333;
    }

    .pyramid-problem svg {
        width: 280px !important;
        height: 180px !important;
    }
}

