/* 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 */
}

/* 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: flex-end;
}

/* Large (1-col) */
.single-col .pictorial-group {
    width: 110px;
    height: 130px;
}

/* Background SVG Layer */
.group-bg {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 0;
    pointer-events: none;
}

.container-svg {
    width: 100%;
    height: 100%;
    display: block;
}

/* Items Layer (Cookies, Apples) */
.group-items {
    position: relative;
    z-index: 1;
    /* Default dimensions, overridden by JS for specific themes */
    width: 80%;
    height: 70%; 
    display: flex;
    flex-wrap: wrap;
    align-content: center;
    justify-content: center;
    /* Padding for number bubble */
    padding-bottom: 15px; 
}

.single-col .group-items {
    padding-bottom: 20px;
}

/* Individual Item */
.pictorial-item {
    /* Size is set dynamically by JS */
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.item-svg {
    width: 100%;
    height: 100%;
    filter: drop-shadow(1px 1px 1px rgba(0,0,0,0.2));
}

/* 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;
}

.single-col .pictorial-operator {
    font-size: 32px;
    margin: 0 0.5rem;
}

/* 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: #d93025; /* Answer key color */
}

/* Theme Specific Adjustments */
.container-jar .group-items {
    width: 75%;
    height: 65%;
    margin-bottom: 8px;
}
.single-col .container-jar .group-items { margin-bottom: 10px; }

.container-tree .group-items {
    width: 90%;
    height: 55%;
    margin-bottom: 35px; 
}
.single-col .container-tree .group-items { margin-bottom: 35px; }

.container-bowl .group-items {
    width: 75%;
    height: 60%;
    margin-bottom: 10px;
}
.single-col .container-bowl .group-items { margin-bottom: 14px; }

/* Print Optimizations */
@media print {
    .sheet__grid {
        gap: 0.5rem;
    }
    
    .pictorial-group {
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }
}

/* ============================================
   RESPONSIVE STYLES
   ============================================ */
@media (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);
    }
}

@media (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);
    }
}

