/* 
 * Math Worksheet Generator - Math-Specific Styles
 * Version: 2.0 (December 2025)
 * Methodology: BEM (Block Element Modifier)
 * NOTE: Base styles are inherited from worksheet-base.css
 */

/* ============================================
   MATH GRID LAYOUT
   ============================================ */
.sheet__grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 0.5em 0.3em;
    flex: 1;
    align-content: space-between;
}

/* ============================================
   PROBLEM BASE STYLES
   ============================================ */
.problem {
    font-family: var(--font-sheet, 'Roboto Mono', 'Courier New', monospace);
    font-size: 24px;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    padding: 0.1em 0.2em;
    position: relative;
    color: #000;
}

.problem__row {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    width: 100%;
    line-height: 1.1;
}

.problem__operator {
    margin-right: 0.5em;
}

.problem__line {
    width: 100%;
    height: 2px;
    background-color: #000;
    border: none;
    margin: 0.2em 0;
}

.problem__answer {
    height: 1.2em;
    min-height: 1.2em;
    color: transparent;
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    width: 100%;
    font-family: var(--font-sheet, 'Roboto Mono', 'Courier New', monospace);
    line-height: 1;
}

.problem--solved .problem__answer {
    color: var(--c-answer, #d93025);
}

/* ============================================
   MISSING NUMBER MODE
   ============================================ */
.missing-box {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 3.5em;
    height: 1.4em;
    padding: 0 4px;
    border: 1px solid #000;
    background: #fff;
    vertical-align: middle;
    margin: 0 2px;
    border-radius: 2px;
    color: var(--c-answer, #d93025);
    font-weight: bold;
    line-height: 1;
}

.problem--missing-term .problem__answer {
    color: #000 !important;
}

/* ============================================
   HORIZONTAL LAYOUT
   ============================================ */
.problem--horizontal {
    flex-direction: row;
    align-items: center;
    justify-content: center;
    gap: 0.2em;
    padding: 0.5em 0;
    white-space: nowrap;
}

.problem--horizontal .problem__operator {
    margin: 0 0.1em;
    font-weight: bold;
}

.problem--horizontal .problem__answer {
    width: auto;
    min-width: 1.5em;
    border-bottom: 1px solid #000;
    text-align: center;
    padding: 0 4px;
    height: auto;
    display: inline-block;
    margin-left: 0.1em;
}

.problem--horizontal.problem--solved .problem__answer {
    border-bottom: 1px solid #ccc;
}

/* ============================================
   COMPARISON MODE
   ============================================ */
.problem--comparison {
    flex-direction: row;
    align-items: center;
    justify-content: center;
    gap: 1em;
    padding: 0.8em 0;
}

.comparison-box {
    width: 2.5em;
    height: 2.5em;
    border: 2px solid #000;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    font-size: 1.2em;
    color: transparent;
    flex-shrink: 0;
}

.problem--solved .comparison-box {
    color: var(--c-answer, #d93025);
    border-color: var(--c-answer, #d93025);
}

.sheet--comparison .sheet__grid {
    column-gap: 3em;
}

/* ============================================
   GRID PAPER EFFECT
   ============================================ */
.sheet--grid .problem {
    background-image: 
        linear-gradient(#e5e7eb 1px, transparent 1px),
        linear-gradient(90deg, #e5e7eb 1px, transparent 1px);
    background-size: 20px 20px;
    background-position: center bottom;
    border: 1px solid #e5e7eb;
    padding: 10px !important;
}

.sheet--grid .problem__row,
.sheet--grid .problem__answer {
    position: relative;
    z-index: 1;
}

/* ============================================
   MATH-SPECIFIC PRINT OVERRIDES
   ============================================ */
@media print {
    /* Grid spreads content evenly across page */
    .sheet__grid {
        align-content: space-between !important;
        height: 100% !important;
    }

    /* Problems */
    .problem {
        color: #000 !important;
        break-inside: avoid !important;
        page-break-inside: avoid !important;
    }

    .problem__row {
        color: #000 !important;
    }

    .problem__line {
        background-color: #000 !important;
        height: 2px !important;
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }

    .problem__answer {
        color: transparent;
    }
    
    .problem--solved .problem__answer {
        color: #d93025 !important;
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }

    /* Missing Box */
    .missing-box {
        border: 1px solid #000 !important;
        background: #fff !important;
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }
    
    .problem--missing-term .problem__answer {
        color: #000 !important;
    }

    /* Comparison Mode */
    .comparison-box {
        border: 2px solid #000 !important;
        color: transparent;
    }

    .problem--solved .comparison-box {
        color: #000 !important;
        border-color: #000 !important;
    }

    /* Grid Paper Effect */
    .sheet--grid .problem {
        background-image: 
            linear-gradient(#ccc 1px, transparent 1px),
            linear-gradient(90deg, #ccc 1px, transparent 1px) !important;
        border: 1px solid #ccc !important;
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }
}

/* ============================================
   RESPONSIVE OVERRIDES FOR MATH
   ============================================ */
@media (max-width: 1024px) {
    .sheet__grid {
        grid-template-columns: repeat(4, 1fr);
        gap: 0.3em 0.2em;
    }

    .problem {
        font-size: clamp(10px, 2.5vw, 18px);
    }

    .comparison-box {
        width: clamp(1.5em, 4vw, 2.5em);
        height: clamp(1.5em, 4vw, 2.5em);
        font-size: clamp(0.8em, 2vw, 1.2em);
    }

    .missing-box {
        min-width: clamp(2em, 6vw, 3.5em);
        height: clamp(1em, 3vw, 1.4em);
    }
}

@media (max-width: 600px) {
    .sheet__grid {
        grid-template-columns: repeat(3, 1fr);
        gap: 0.2em 0.15em;
    }

    .problem {
        font-size: clamp(8px, 2vw, 14px);
        padding: 0.05em 0.1em;
    }

    .problem__line {
        height: 1px;
        margin: 0.1em 0;
    }

    .problem--horizontal {
        gap: 0.1em;
        padding: 0.3em 0;
    }

    .comparison-box {
        width: clamp(1.2em, 3.5vw, 2em);
        height: clamp(1.2em, 3.5vw, 2em);
        border-width: 1px;
        font-size: clamp(0.7em, 1.8vw, 1em);
    }

    .missing-box {
        min-width: clamp(1.5em, 5vw, 2.5em);
        height: clamp(0.8em, 2.5vw, 1.2em);
        padding: 0 2px;
        font-size: 0.9em;
    }

    .sheet--comparison .sheet__grid {
        column-gap: 1em;
    }

    /* Grid paper effect - smaller for mobile */
    .sheet--grid .problem {
        background-size: 12px 12px;
        padding: 6px !important;
    }
}
