/* 
 * 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 (screen only - print uses worksheet-base.css)
   ============================================ */
@media screen {
    .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__number {
    position: absolute;
    top: 0;
    left: 0;
    font-size: 0.45em;
    font-weight: 600;
    color: #9ca3af;
    font-family: var(--font-ui, 'Nunito', sans-serif);
    line-height: 1;
}

.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, #16a34a);
}

/* ============================================
   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, #16a34a);
    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, #16a34a);
    border-color: var(--c-answer, #16a34a);
}

/* ============================================
   EXPONENT MODE
   ============================================ */
.problem--exponent {
    align-items: center;
    justify-content: center;
    padding: 0.5em 0.3em;
}

.problem--exponent .problem__row {
    display: flex;
    align-items: flex-start;
    justify-content: center;
    gap: 0;
}

.exponent-base {
    font-size: 1em;
    line-height: 1.2;
}

.exponent-power {
    font-size: 0.5em;
    font-weight: 700;
    line-height: 1;
    margin-top: -0.2em;
    margin-left: 0.05em;
}

.problem--exponent .problem__operator {
    align-self: center;
    margin-left: 0.3em;
}

.problem--exponent .problem__answer {
    margin-top: 0.2em;
    padding-top: 0.2em;
    border-top: 2px solid #000;
    width: 100%;
    text-align: center;
}

/* ============================================
   MODULO (REMAINDER) MODE
   ============================================ */
.problem__answer--remainder {
    font-size: 0.85em;
    text-align: right;
}

/* ============================================
   SQUARE ROOT MODE
   ============================================ */
.problem--sqrt {
    align-items: center;
    padding: 0.4em 0.3em;
}

.problem--sqrt .problem__row {
    display: flex;
    align-items: baseline;
    justify-content: center;
}

.sqrt-symbol {
    font-size: 1.2em;
    font-weight: 400;
    margin-right: 0.1em;
}

.sqrt-radicand {
    border-top: 2px solid #000;
    padding: 0 0.3em;
    display: inline-block;
}

.problem--sqrt .problem__answer {
    margin-top: 0.3em;
    width: 100%;
    text-align: center;
}

/* ============================================
   GCF / LCM MODE
   ============================================ */
.problem--function {
    align-items: center;
    padding: 0.4em 0.2em;
}

.problem--function .problem__row {
    display: flex;
    align-items: baseline;
    justify-content: center;
    gap: 0.15em;
    white-space: nowrap;
}

.fn-name {
    font-size: 0.65em;
    font-weight: 700;
    letter-spacing: 0.5px;
}

/* ============================================
   INLINE PROBLEM MODE (doubles, halves, percent, rounding, order-ops, negatives)
   ============================================ */
.problem--inline {
    align-items: center;
    padding: 0.4em 0.2em;
}

.problem--inline .problem__row {
    text-align: center;
    width: 100%;
    white-space: nowrap;
}

.problem__row--center {
    text-align: center !important;
    justify-content: center !important;
}

.problem__instruction {
    font-size: 0.4em;
    font-weight: 600;
    color: #6b7280;
    text-align: center;
    margin-bottom: 0.3em;
    font-family: var(--font-ui, 'Nunito', sans-serif);
    text-transform: none;
    letter-spacing: 0;
}

/* ============================================
   COMPARISON MODE & GRID PAPER (screen only)
   ============================================ */
@media screen {
    .sheet--comparison .sheet__grid {
        column-gap: 3em;
    }

    /* Grid paper background 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 {
    /* Math-specific print overrides (base print styles in worksheet-base.css) */

    /* Match screen grid gap so spacing is identical to preview */
    .sheet__grid {
        gap: 0.5em 0.3em !important;
    }

    .problem__row,
    .problem__answer {
        min-width: 0 !important;
        max-width: 100% !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 !important;
    }

    .problem--solved .problem__answer {
        color: #16a34a !important;
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }

    .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-box {
        border: 2px solid #000 !important;
        color: transparent !important;
    }

    .problem--solved .comparison-box {
        color: #000 !important;
        border-color: #000 !important;
    }

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

    /* New operation print rules */
    .problem__instruction {
        color: #374151 !important;
    }

    .exponent-power {
        color: #000 !important;
    }

    .sqrt-radicand {
        border-top-color: #000 !important;
    }

    .fn-name {
        color: #000 !important;
    }

    .problem--inline .problem__row {
        color: #000 !important;
    }
}

/* ============================================
   RESPONSIVE OVERRIDES FOR MATH (screen only)
   ============================================ */
@media screen and (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 screen and (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;
    }
}