/* 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 */
}

.mixed-op-problem {
    text-align: left; /* Override arith-problem right align */
    display: flex;
    align-items: center;
    padding-left: 10px;
}

/* --- 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 */
/* Print-specific page chrome. Everything inside #problems-container is laid
   out on the squared grid by styles/print-grid.css (see ui/print-grid.js). */
@media print {

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

    body {
        position: relative;
        background-color: #fff;
        font-size: 12pt;
        display: flex;
        flex-direction: column;
    }

    /* === Hide non-printable elements === */
    header,
    .topic-sidebar,
    #topic-selection-section,
    .controls,
    #actions-panel,
    footer,
    nav,
    body::before {
        display: none !important;
    }

    .app-container {
        display: block !important;
        max-width: 100% !important;
        margin: 0 !important;
        padding: 0 !important;
    }

    /* === Main content area === */
    main {
        max-width: 100%;
        margin: 0;
        padding: 0;
        border: none;
        box-shadow: none;
        display: flex;
        flex-direction: column;
        flex-grow: 1;
        min-height: 100vh;
    }

    #output-area {
        border: none;
        margin: 0;
        padding: 0;
        background-color: #fff;
        flex-grow: 1;
        display: flex;
        flex-direction: column;
    }
}

.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;
}

/* --- Operator puzzles & comparisons (screen) --- */
.operator-puzzle-item .puzzle,
.compare-expression-item .puzzle {
    font-family: 'Courier New', Courier, monospace;
    font-size: 1.2em;
}

.operator-puzzle-item .op-blank,
.compare-expression-item .cmp-blank {
    display: inline-block;
    width: 1.4em;
    border-bottom: 2px solid #333;
    margin: 0 0.15em;
    vertical-align: baseline;
}

.find-the-number-letters-item .puzzle,
.unit-conversion-item .puzzle {
    font-family: 'Courier New', Courier, monospace;
    font-size: 1.1em;
}

.find-the-number-letters-item .answer-space,
.unit-conversion-item .answer-space {
    display: inline-block;
    width: 4em;
    border-bottom: 2px solid #333;
    vertical-align: baseline;
}

/* --- 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;
}


/* --- 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;
}

.mixed-op-problem .answer-space {
    flex-grow: 1;
    border-bottom: 1px solid #333;
    min-width: 60px;
    margin-left: 10px;
    height: 1.5em;
    min-height: auto;
}

/* --- Boolean logic (screen) --- */
.boolean-logic-item .puzzle {
    font-family: 'Courier New', Courier, monospace;
    font-size: 1.2em;
}

.boolean-logic-item .bl-assignment,
.boolean-logic-item .bl-answer {
    display: block;
    margin-top: 0.3em;
}

.boolean-logic-item .bl-blank {
    display: inline-block;
    width: 3em;
    border-bottom: 2px solid #333;
    vertical-align: baseline;
}

.gf-figures {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    align-items: flex-start;
    margin: 0.5em 0;
}

.gf-svg {
    display: block;
    max-width: 100%;
    height: auto;
    overflow: visible;
}

/* Cube buildings: plan of digits, one bordered square per column of cubes. */
.cube-plan {
    display: inline-block;
    margin: 8px 0;
    font-family: 'Courier New', Courier, monospace;
}

.cube-plan-row {
    display: flex;
}

.cube-cell {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.6em;
    height: 1.6em;
    border: 1px solid #333;
    margin: -1px 0 0 -1px;
}

.cube-plan-front {
    font-size: 0.85em;
    text-align: center;
}

.cube-stairs svg,
.dice-svg svg,
.cs-svg {
    display: block;
    margin: 8px 0;
}

.magic-square {
    border-collapse: collapse;
    margin: 0.5em 0;
    font: bold 1.1em monospace;
}

.magic-square td {
    position: relative;
    width: 3em;
    height: 2.2em;
    border: 1px solid #333;
    text-align: center;
}

.magic-square td.ms-sum {
    background: #f0f0f0;
}

.magic-square td.ms-none {
    border: 0;
}

.ms-star {
    position: absolute;
    top: 1px;
    left: 3px;
    font-size: 0.85em;
    font-weight: normal;
}
