/* Pictorial Math Worksheet Styles */

/* Grid Layout */
.sheet__grid.pictorial-grid {
    display: grid;
    gap: 0;
    /* Gap handled by borders/padding for lines */
    padding: 0;
    grid-template-columns: 1fr 1fr;
    /* Default 2 columns */
    grid-template-rows: repeat(6, 1fr);
    /* Distribute 6 rows evenly */
    height: 100%;
    /* Fill the sheet height */
    align-content: stretch;
    border: 2px solid #333;
    /* Outer border */
    position: relative;
    /* For pseudo-element line */
    min-height: 0;
    flex: 1 1 auto;
}

/* Continuous Vertical Line for 2-col layout */
.sheet__grid.pictorial-grid:not(.single-col)::after {
    content: '';
    position: absolute;
    top: 0;
    bottom: 0;
    left: 50%;
    width: 2px;
    background-color: #333;
    transform: translateX(-50%);
    z-index: 1;
}

.sheet__grid.pictorial-grid.single-col {
    grid-template-columns: 1fr;
    grid-template-rows: repeat(5, 1fr);
    /* Distribute 5 rows evenly */
    border: 2px solid #333;
}

/* Equation Row */
.pictorial-equation {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    /* Reduced padding, let flex/grid handle spacing */
    width: 100%;
    height: 100%;
    /* Fill the grid cell */
    border-bottom: 2px solid #333;
    /* Horizontal separation */
    box-sizing: border-box;
}

/* Remove individual cell borders since we use the pseudo-element */
.pictorial-grid:not(.single-col) .pictorial-equation:nth-child(odd) {
    border-right: none;
}

/* Remove bottom border for last row items */
/* Assuming we fill the grid, we might need JS to handle exact last row, 
   but CSS :last-child and :nth-last-child(2) can work if we know the count is even */
.pictorial-grid:not(.single-col) .pictorial-equation:nth-last-child(1),
.pictorial-grid:not(.single-col) .pictorial-equation:nth-last-child(2) {
    border-bottom: none;
}

.single-col .pictorial-equation:last-child {
    border-bottom: none;
}

.single-col .pictorial-equation {
    gap: 2rem;
    padding: 2rem 1rem;
}

/* Group Container (Jar, Tree, etc.) */
/* Default (Compact/2-col) */
.pictorial-group {
    position: relative;
    width: 70px;
    height: 90px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    border: 2px dashed #d1d5db;
    border-radius: 12px;
    background: #fafafa;
}

/* Large (1-col) */
.single-col .pictorial-group {
    width: 110px;
    height: 130px;
    border-width: 2.5px;
    border-radius: 16px;
}

/* Items Layer */
.group-items {
    position: relative;
    z-index: 1;
    width: 90%;
    height: 80%;
    display: flex;
    flex-wrap: wrap;
    align-content: center;
    justify-content: center;
    gap: 1px;
    padding-bottom: 10px;
}

.single-col .group-items {
    padding-bottom: 14px;
}

/* Individual Item */
.pictorial-item {
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Emoji item — text-based, no SVG */
.pictorial-item.emoji-item {
    text-align: center;
    line-height: 1;
    -webkit-user-select: none;
    user-select: none;
}

/* Number Bubble */
.group-number {
    position: absolute;
    bottom: -6px;
    background: white;
    border: 1.5px solid #333;
    border-radius: 50%;
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    font-size: 12px;
    color: #333;
    z-index: 2;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.single-col .group-number {
    bottom: -10px;
    width: 30px;
    height: 30px;
    font-size: 16px;
    border-width: 2px;
}

/* Operators (+, -, =) */
.pictorial-operator {
    font-size: 20px;
    font-weight: 900;
    color: #555;
    margin: 0 0.15rem;
}

/* Comparison Operator (special styling for <, >, =) */
.pictorial-operator.comparison-op {
    font-size: 32px;
    font-weight: 900;
    color: #6366f1;
    min-width: 40px;
    text-align: center;
    white-space: nowrap;
}

.single-col .pictorial-operator.comparison-op {
    font-size: 48px;
    min-width: 60px;
}

.single-col .pictorial-operator {
    font-size: 32px;
    margin: 0 0.5rem;
}

/* Multiplier Number (for multiplication: 3 × [group] = answer) */
.pictorial-multiplier {
    font-size: 28px;
    font-weight: 900;
    color: #333;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2.5px solid #6366f1;
    border-radius: 50%;
    background: #eef2ff;
    flex-shrink: 0;
}

.single-col .pictorial-multiplier {
    font-size: 40px;
    width: 60px;
    height: 60px;
    border-width: 3px;
}

/* Comparison Target Highlight */
.pictorial-group.compare-target::after {
    content: '';
    position: absolute;
    inset: -4px;
    border: 3px solid #f59e0b;
    border-radius: 12px;
    pointer-events: none;
}

/* Answer Box */
.pictorial-answer-box {
    width: 50px;
    height: 50px;
    border: 2px solid #333;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #fff;
    font-size: 24px;
    font-weight: bold;
    color: #333;
}

.single-col .pictorial-answer-box {
    width: 80px;
    height: 80px;
    border-width: 3px;
    border-radius: 12px;
    font-size: 36px;
}

.pictorial-answer-box.has-answer {
    color: #16a34a;
}

/* Compact Answer Key */
.answer-key-list {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px 20px;
    padding: 12px 20px 16px;
    font-size: 14px;
}

.answer-key-item {
    display: flex;
    justify-content: space-between;
    border-bottom: 1px dashed #ccc;
    padding: 2px 0;
}

.answer-key-num {
    color: #555;
    font-weight: 600;
}

.answer-key-val {
    color: #111;
    font-weight: 700;
}

/* Control Utilities */
.control-checkbox-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 16px;
    margin-top: 6px;
}

.control-checkbox {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: #555;
}

.footer-select {
    margin-top: 10px;
}

/* Instruction Text */
.instruction-text {
    font-size: 13px;
    font-weight: 600;
    color: #555;
    text-align: center;
    padding: 6px 16px;
    border-bottom: 1px dashed #ccc;
    font-style: italic;
}

/* Mystery Box (Missing Number) */
.pictorial-answer-box.mystery-box {
    border-style: dashed;
    border-color: #6366f1;
    color: #6366f1;
    background: #f5f3ff;
    font-size: 28px;
}

.single-col .pictorial-answer-box.mystery-box {
    font-size: 40px;
}

.pictorial-answer-box.mystery-box.has-answer {
    border-style: solid;
    color: #16a34a;
    border-color: #16a34a;
    background: #f0fdf4;
}

/* Work Space */
.pictorial-equation.has-work-space {
    flex-wrap: wrap;
}

/* True/False Mode */
.tf-shown-answer {
    font-weight: 900;
    border-style: solid;
    border-color: #6366f1;
    color: #333;
    background: #eef2ff;
}

.tf-choice {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-left: 6px;
}

.tf-option {
    width: 32px;
    height: 32px;
    border: 2px solid #ccc;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    font-weight: 900;
    cursor: default;
    background: #fff;
}

.tf-option.tf-true {
    color: #16a34a;
    border-color: #bbf7d0;
}

.tf-option.tf-false {
    color: #dc2626;
    border-color: #fecaca;
}

.tf-option.tf-correct {
    background: #16a34a;
    color: #fff;
    border-color: #16a34a;
}

.tf-option.tf-false.tf-correct {
    background: #dc2626;
    border-color: #dc2626;
}

.single-col .tf-option {
    width: 44px;
    height: 44px;
    font-size: 22px;
}

.single-col .tf-shown-answer {
    font-size: 36px;
}

.work-space {
    width: 100%;
    min-height: 32px;
    border-top: 1px dashed #ccc;
    margin-top: 4px;
    position: relative;
}

.work-space::after {
    content: 'Show your work';
    position: absolute;
    top: 2px;
    right: 8px;
    font-size: 8px;
    color: #bbb;
    font-style: italic;
}

.single-col .work-space {
    min-height: 48px;
}

.single-col .work-space::after {
    font-size: 10px;
}

/* Print Optimizations */
@media print {
    .sheet__grid.pictorial-grid {
        height: auto !important;
        min-height: 0 !important;
        align-content: stretch !important;
    }

    .sheet__grid.pictorial-grid.single-col {
        grid-template-rows: auto !important;
    }

    .single-col .pictorial-equation {
        gap: 6mm !important;
        padding: 4mm 2mm !important;
    }

    .single-col .pictorial-group {
        width: 82px !important;
        height: 98px !important;
    }

    .single-col .group-items {
        padding-bottom: 12px !important;
    }

    .single-col .pictorial-answer-box {
        width: 62px !important;
        height: 62px !important;
        font-size: 28px !important;
    }

    .single-col .pictorial-operator {
        font-size: 28px !important;
        margin: 0 0.25rem !important;
    }

    .single-col .pictorial-operator.comparison-op {
        font-size: 32px !important;
        min-width: 44px !important;
    }

    /* Print: multiplier circle */
    .pictorial-multiplier {
        border-color: #333 !important;
        background: #fff !important;
        color: #333 !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }

    .sheet__grid {
        gap: 0.5rem;
    }

    .pictorial-group {
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
        border-color: #ccc !important;
        background: #fff !important;
    }

    .pictorial-equation {
        border-bottom-color: #333 !important;
    }

    .sheet__grid.pictorial-grid {
        border-color: #333 !important;
    }

    .pictorial-operator {
        color: #333 !important;
    }

    .answer-key-list {
        break-inside: avoid;
        page-break-inside: avoid;
    }

    .instruction-text {
        color: #333 !important;
        border-bottom-color: #999 !important;
    }

    .pictorial-answer-box.mystery-box {
        border-color: #333 !important;
        color: #333 !important;
        background: #fff !important;
    }

    .pictorial-answer-box.mystery-box.has-answer {
        color: #16a34a !important;
        border-color: #16a34a !important;
    }

    .work-space {
        border-top-color: #999 !important;
    }

    .work-space::after {
        color: #999 !important;
    }

    .tf-shown-answer {
        border-color: #333 !important;
        background: #fff !important;
    }

    .tf-option {
        border-color: #999 !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }

    .tf-option.tf-correct {
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }

    .group-number {
        color: #333 !important;
        border-color: #333 !important;
        background: #fff !important;
    }
}

/* ============================================
   RESPONSIVE STYLES
   ============================================ */
@media screen and (max-width: 1024px) {
    .pictorial-group {
        width: clamp(40px, 12vw, 70px);
        height: clamp(55px, 15vw, 90px);
    }

    .pictorial-equation {
        gap: clamp(4px, 1vw, 0.5rem);
        padding: clamp(4px, 1vw, 0.5rem) clamp(8px, 2vw, 1rem);
    }

    .group-number {
        width: clamp(14px, 4vw, 20px);
        height: clamp(14px, 4vw, 20px);
        font-size: clamp(8px, 2vw, 12px);
    }

    .pictorial-operator {
        font-size: clamp(12px, 4vw, 20px);
    }

    .pictorial-answer-box {
        width: clamp(30px, 10vw, 50px);
        height: clamp(30px, 10vw, 50px);
        font-size: clamp(14px, 5vw, 24px);
    }

    /* Single column adjustments */
    .single-col .pictorial-group {
        width: clamp(60px, 18vw, 110px);
        height: clamp(75px, 22vw, 130px);
    }

    .single-col .pictorial-operator {
        font-size: clamp(18px, 6vw, 32px);
    }

    .single-col .pictorial-answer-box {
        width: clamp(45px, 14vw, 80px);
        height: clamp(45px, 14vw, 80px);
        font-size: clamp(20px, 7vw, 36px);
    }

    .single-col .group-number {
        width: clamp(18px, 5vw, 30px);
        height: clamp(18px, 5vw, 30px);
        font-size: clamp(10px, 3vw, 16px);
    }

    /* Multiplier circle responsive: 1024px */
    .pictorial-multiplier {
        width: clamp(28px, 8vw, 40px);
        height: clamp(28px, 8vw, 40px);
        font-size: clamp(16px, 5vw, 28px);
    }

    .single-col .pictorial-multiplier {
        width: clamp(40px, 12vw, 60px);
        height: clamp(40px, 12vw, 60px);
        font-size: clamp(24px, 7vw, 40px);
    }
}

@media screen and (max-width: 600px) {
    .sheet__grid.pictorial-grid {
        border-width: 1px;
    }

    .sheet__grid.pictorial-grid:not(.single-col)::after {
        width: 1px;
    }

    .pictorial-equation {
        border-bottom-width: 1px;
    }

    .pictorial-group {
        width: clamp(30px, 10vw, 50px);
        height: clamp(42px, 13vw, 65px);
    }

    .pictorial-equation {
        gap: clamp(2px, 0.8vw, 0.3rem);
        padding: clamp(2px, 0.8vw, 0.3rem) clamp(4px, 1.5vw, 0.5rem);
    }

    .group-number {
        width: clamp(12px, 3.5vw, 16px);
        height: clamp(12px, 3.5vw, 16px);
        font-size: clamp(7px, 1.8vw, 9px);
        bottom: -3px;
        border-width: 1px;
    }

    .pictorial-operator {
        font-size: clamp(10px, 3vw, 14px);
        margin: 0 1px;
    }

    .pictorial-answer-box {
        width: clamp(24px, 8vw, 32px);
        height: clamp(24px, 8vw, 32px);
        font-size: clamp(11px, 3.5vw, 14px);
        border-width: 1.5px;
        border-radius: 4px;
    }

    /* Single column adjustments for mobile */
    .single-col .pictorial-group {
        width: clamp(50px, 15vw, 80px);
        height: clamp(65px, 18vw, 100px);
    }

    .single-col .pictorial-equation {
        gap: clamp(8px, 3vw, 2rem);
        padding: clamp(8px, 3vw, 2rem) clamp(8px, 2vw, 1rem);
    }

    .single-col .pictorial-operator {
        font-size: clamp(16px, 5vw, 24px);
    }

    .single-col .pictorial-answer-box {
        width: clamp(36px, 12vw, 50px);
        height: clamp(36px, 12vw, 50px);
        font-size: clamp(16px, 5vw, 24px);
    }

    .single-col .group-number {
        width: clamp(16px, 4.5vw, 22px);
        height: clamp(16px, 4.5vw, 22px);
        font-size: clamp(9px, 2.5vw, 12px);
    }

    /* Multiplier circle responsive: 600px */
    .pictorial-multiplier {
        width: clamp(22px, 7vw, 32px);
        height: clamp(22px, 7vw, 32px);
        font-size: clamp(13px, 4vw, 20px);
        border-width: 2px;
    }

    .single-col .pictorial-multiplier {
        width: clamp(30px, 10vw, 44px);
        height: clamp(30px, 10vw, 44px);
        font-size: clamp(18px, 6vw, 28px);
    }
}