/* division.css - UPDATED FOR NEW 12x9 GRID STRUCTURE */
/* ============================================
   RESET & BASE STYLES
   ============================================ */
:root {
    /* Colors */
    --primary: #007bff;
    --success: #28a745;
    --danger: #dc3545;
    --warning: #ffc107;
    --info: #17a2b8;
    --light: #f8f9fa;
    --dark: #212529;
    --white: #ffffff;
    --gray: #6c757d;
    
    /* Grid Colors - Updated to match your HTML classes */
    --blue: #00a6e6;
    --green: #2db84d;
    --orange: #ff8c2a;
    --brown: #8B4513; /* Added for brown answer cells */
    --yellow: #ffee00;
    --pink: #ffb6c1;
    
    /* Spacing */
    --space-xs: 4px;
    --space-sm: 8px;
    --space-md: 16px;
    --space-lg: 24px;
    --space-xl: 32px;
    
    /* Fonts */
    --font-math: "Latin Modern Math", "STIX Two Math", serif;
    --font-ui: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    --font-mono: 'Courier New', monospace;
    
    /* Grid dimensions */
    --cell-size: 50px;
    --cell-gap: 2px;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* ============================================
   ANIMATIONS
   ============================================ */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(-10px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes pulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.05); }
    100% { transform: scale(1); }
}

@keyframes highlightCell {
    0% { background-color: inherit; }
    50% { background-color: rgba(255, 255, 0, 0.3); }
    100% { background-color: inherit; }
}

/* ============================================
   LAYOUT CONTAINERS
   ============================================ */
.division-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: var(--space-md);
}

.dual-container {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-lg);
    margin: var(--space-lg) 0;
}

@media (max-width: 768px) {
    .dual-container {
        grid-template-columns: 1fr;
    }
}

/* ============================================
   PROBLEM DISPLAY (LEFT SIDE)
   ============================================ */
.left-container {
    background: var(--white);
    border-radius: 10px;
    padding: var(--space-lg);
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    border: 1px solid #dee2e6;
}

.main-problem {
    min-height: 300px;
}

.equation-display {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 200px;
    transition: all 3s ease;

}

.large-equation {
    font-family: var(--font-math);
    font-size: 3em;
    color: #1a237e;
    padding: var(--space-lg);
    background: var(--white);
    border-radius: 10px;
    border: 2px solid #e8eaf6;
    text-align: center;
    transition: all 3s ease;

}

.current-step-container {
    margin-top: var(--space-lg);
    padding: var(--space-md);
    background: #e3f2fd;
    border-radius: 8px;
    border: 2px solid #2196f3;
}

.current-step-title {
    font-weight: bold;
    color: #0d47a1;
    margin-bottom: var(--space-sm);
}

.current-step-equation {
    font-family: var(--font-math);
    font-size: 1.3em;
    color: #1a237e;
    margin: var(--space-sm) 0;
    padding: var(--space-sm);
    background: var(--white);
    border-radius: 6px;
}

.current-instruction {
    color: #455a64;
    font-style: italic;
    margin-top: var(--space-sm);
}

/* Style for placeholder/question marks */
.quotient-digit,
.remainder-digit {
    color: #6c757d; /* Gray color for placeholders */
    font-weight: normal;
    opacity: 0.7;
}

/* When answered, these styles will be overridden */
.quotient-digit.answered,
.remainder-digit.answered {
    color: var(--green);
    font-weight: bold;
    opacity: 1;
}

/* ============================================
   WORK AREA (RIGHT SIDE)
   ============================================ */
.right-container {
    background: var(--white);
    border-radius: 10px;
    padding: var(--space-lg);
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    border: 1px solid #dee2e6;
}

.right-container {
    min-height: 400px;
    padding: var(--space-md);
    background: var(--light);
    border-radius: 8px;
    border: 1px solid #dee2e6;
    overflow: auto;
}

/* ============================================
   12x9 GRID STRUCTURE
   ============================================ */
.division-work-layout {
    position: relative;
    width: fit-content;
    margin: 0 auto;
}

.large-grid {
    display: grid;
    grid-template-columns: repeat(9, var(--cell-size));
    grid-auto-rows: var(--cell-size);
    gap: var(--cell-gap);
    background: transparent;
    position: relative;
}

.work-row {
    display: contents; /* This allows grid items to participate in grid layout */
}

/* ============================================
   DIVISION TABLE CELL BASE STYLES
   ============================================ */
.division-table {
    width: var(--cell-size);
    height: var(--cell-size);
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: var(--font-mono);
    font-size: 1.5em;
    font-weight: bold;
    position: relative;
    user-select: none;
}

/* ============================================
   CELL TYPES & COLORS
   ============================================ */

/* TRANSPARENT CELLS */
.division-table.transparent {
    background: transparent !important;
    border: none !important;
    color: transparent !important;
}

/* COLORED CELLS WITH BORDERS */
.division-table.blue {
    background-color: var(--blue);
    color: var(--white);
    border: 2px solid darken(var(--blue), 15%);
    border-radius: 4px;
}

.division-table.green {
    background-color: var(--green);
    color: var(--white);
    border: 2px solid darken(var(--green), 15%);
    border-radius: 4px;
}

.division-table.orange {
    background-color: var(--orange);
    color: var(--white);
    border: 2px solid darken(var(--orange), 15%);
    border-radius: 4px;
}

.division-table.yellow {
    background-color: var(--yellow);
    color: var(--dark);
    border: 2px solid darken(var(--yellow), 15%);
    border-radius: 4px;
}

.division-table.brown {
    background-color: var(--brown);
    color: var(--white);
    border: 2px solid darken(var(--brown), 15%);
    border-radius: 4px;
}

.division-table.pink {
    background-color: var(--pink);
    color: var(--dark);
    border: 2px solid darken(var(--pink), 15%);
    border-radius: 4px;
}


/* ============================================
   LINES AND SYMBOLS
   ============================================ */

.division-table.vertical-line {
    position: relative;
}

.division-table.vertical-line::before {
    content: '';
    position: absolute;
    top: 0;
    left: 50%;
    width: 2px;
    height: 100%;
    background: #333;
    transform: translateX(-50%);
}


.division-table.horizontal-line {
    position: relative;
}

.division-table.horizontal-line::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 0;
    width: calc(100% + 2px);
    height: 2px;
    background: #333;
    transform: translateY(-50%);
}


/* CORNER LINE (L-shaped from bottom-center to center to right-middle) */
.division-table.corner-line {
    position: relative;
    background: transparent !important;
    border: none !important;
    overflow: visible; /* Allow lines to extend beyond cell boundaries */
}

.division-table.corner-line::before {
    content: '';
    position: absolute;
    bottom: -4px; /* Extend 4px below the bottom edge */
    left: 50%;
    width: 2px;
    height: calc(50% + 4px); /* Add 4px to extend past the center */
    background: #333;
    transform: translateX(-50%);
}

.division-table.corner-line::after {
    content: '';
    position: absolute;
    top: 50%;
    right: -4px; /* Extend 4px beyond the right edge */
    width: calc(50% + 4px); /* Add 4px to extend past the center */
    height: 2px;
    background: #333;
    transform: translateY(-50%);
}

.division-table.minus::before {
    content: '−';
    position: absolute;
    left: 4;
    top: 0;
    height: 100%;
    display: flex;
    align-items: center;
    font-size: 28px;
    font-weight: bold;
    color: #333;
    z-index: 2;
}


/* ============================================
   STEP-SPECIFIC STYLES
   ============================================ */

/* STEP 1 cells */
.division-table.step1 {
    animation-delay: 1s;
}

/* STEP 2 cells */
.division-table.step2 {
    animation-delay: 1s;
}


/* STEP 3 cells */
.division-table.step3 {
    animation-delay: 1s;
}


/* ============================================
   CONTROLS & INTERACTIVE
   ============================================ */
.work-feedback {
    margin-top: var(--space-lg);
}

.control-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: var(--space-sm);
    margin: var(--space-md) 0;
}

.grid-btn {
    padding: var(--space-sm);
    border: none;
    border-radius: 6px;
    font-size: 1.2em;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.2s;
}

.grid-btn.decrement { 
    background: var(--danger); 
    color: var(--white); 
}

.grid-btn.increment { 
    background: var(--success); 
    color: var(--white); 
}

.grid-btn.clear { 
    background: var(--warning); 
    color: var(--dark); 
}

.grid-btn:hover {
    opacity: 0.9;
    transform: translateY(-2px);
}

.number-display {
    text-align: center;
    font-size: 1.3em;
    margin: var(--space-md) 0;
    padding: var(--space-sm);
    background: var(--light);
    border-radius: 6px;
    border: 2px solid #dee2e6;
}

.commit-btn {
    width: 100%;
    padding: var(--space-md);
    background: var(--primary);
    color: var(--white);
    border: none;
    border-radius: 8px;
    font-size: 1.2em;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s;
}

.commit-btn:hover {
    background: #0056b3;
    transform: translateY(-2px);
}

.commit-btn:active {
    transform: translateY(0);
}

/* ============================================
   MAIN CONTROLS
   ============================================ */
.division-controls {
    margin: var(--space-lg) 0;
    text-align: center;
}

.control-buttons {
    display: flex;
    gap: var(--space-md);
    justify-content: center;
    flex-wrap: wrap;
}

.primary-btn, .secondary-btn {
    padding: var(--space-md) var(--space-xl);
    border: none;
    border-radius: 8px;
    font-size: 1.1em;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s;
}

.primary-btn {
    background: var(--primary);
    color: var(--white);
}

.secondary-btn {
    background: var(--light);
    color: var(--dark);
    border: 2px solid var(--gray);
}

.primary-btn:hover {
    background: #0056b3;
    transform: translateY(-2px);
}

.secondary-btn:hover {
    background: #e2e6ea;
    transform: translateY(-2px);
}

/* ============================================
   FEEDBACK & ANIMATIONS
   ============================================ */
.digit-animation {
    position: fixed;
    font-size: 24px;
    font-weight: bold;
    color: var(--blue);
    background: var(--white);
    border: 2px solid var(--blue);
    border-radius: 5px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 10px;
    z-index: 10000;
    pointer-events: none;
    transition: all 0.5s ease-in-out;
}

.digit-highlight {
    animation: pulse 0.5s ease-in-out;
    background-color: #e3f2fd !important;
    border: 2px solid var(--blue) !important;
}

.cell-highlight {
    animation: highlightCell 1s ease-in-out;
}

.feedback-success {
    padding: var(--space-sm);
    background: #d4edda;
    color: #155724;
    border: 2px solid var(--success);
    border-radius: 6px;
    animation: fadeIn 0.3s ease-in;
    margin-top: var(--space-md);
}

.feedback-error {
    padding: var(--space-sm);
    background: #f8d7da;
    color: #721c24;
    border: 2px solid var(--danger);
    border-radius: 6px;
    animation: fadeIn 0.3s ease-in;
    margin-top: var(--space-md);
}

/* ============================================
   LAYOUT ADJUSTMENTS FOR HIDDEN CONTAINERS
   ============================================ */

/* When current-step-container is hidden, expand the equation display */
.main-problem:has(.current-step-container.hidden) .equation-display {
    height: 100%;
    min-height: 350px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* When work-feedback is hidden, adjust left-container spacing */
.left-container:has(.work-feedback.hidden) {
    padding-bottom: var(--space-lg);
}

/* When both are hidden, center the equation */
.main-problem:has(.current-step-container.hidden):has(.work-feedback.hidden) .equation-display {
    min-height: 450px;
    height: calc(100vh - 300px);
}

/* Base styles with transitions */
.current-step-container,
.work-feedback {
    transition: all 3s ease;
    overflow: hidden;
}

/* VISIBLE STATE (when NOT hidden) */
.current-step-container:not(.hidden),
.work-feedback:not(.hidden) {
    opacity: 1;
    visibility: visible;
    max-height: 500px; /* Adjust based on your content */
    transform: translateY(0);
}

/* HIDDEN STATE (when hidden class is applied) */
.current-step-container.hidden,
.work-feedback.hidden {
    opacity: 0;
    visibility: hidden;
    max-height: 0;
    transform: translateY(-20px);
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(-20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}


/* ============================================
   SCORE DISPLAY
   ============================================ */
.enhanced-score-container {
    background: var(--light);
    border-radius: 10px;
    padding: var(--space-lg);
    margin-top: var(--space-lg);
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.score-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: var(--space-md);
    margin: var(--space-md) 0;
}

.stat {
    background: var(--white);
    padding: var(--space-md);
    border-radius: 8px;
    text-align: center;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.stat.correct { border-left: 4px solid var(--success); }
.stat.incorrect { border-left: 4px solid var(--danger); }
.stat.accuracy { border-left: 4px solid var(--warning); }
.stat.streak { border-left: 4px solid var(--info); }

.stat-label {
    display: block;
    font-size: 0.9em;
    color: var(--gray);
    margin-bottom: var(--space-xs);
}

.stat-value {
    display: block;
    font-size: 1.5em;
    font-weight: bold;
    color: var(--dark);
}

/* Reset Scores Button */
#resetDivisionScores {
    padding: var(--space-sm) var(--space-md);
    background: var(--danger);
    color: var(--white);
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.9em;
    margin-top: var(--space-md);
    transition: all 0.3s;
}

#resetDivisionScores:hover {
    background: #c82333;
}

/* ============================================
   RESPONSIVE ADJUSTMENTS
   ============================================ */
@media (max-width: 768px) {
    .division-container {
        padding: var(--space-sm);
    }
    
    .large-equation {
        font-size: 2.5em;
        padding: var(--space-md);
    }
    
    :root {
        --cell-size: 40px;
    }
    
    .division-table {
        font-size: 1.3em;
    }
    
    .division-table.answer {
        font-size: 1.4em;
    }
    
    .right-container {
        min-height: 350px;
    }
}

@media (max-width: 480px) {
    :root {
        --cell-size: 35px;
    }
    
    .division-table {
        font-size: 1.1em;
    }
    
    .division-table.answer {
        font-size: 1.2em;
    }
    
    .right-container {
        min-height: 300px;
    }
    
    .control-buttons {
        flex-direction: column;
        align-items: center;
    }
    
    .primary-btn, .secondary-btn {
        width: 100%;
        max-width: 300px;
    }
}

/* ============================================
   UTILITY CLASSES
   ============================================ */
.unused {
    /* Explicitly empty for unused cells */
}

.hidden {
    opacity: 0;
    visibility: hidden;
    max-height: 0;
    overflow: hidden;
    transform: translateY(-20px);
}

.visible {
    display: block !important;
}

/* Debugging helper */
.debug-outline {
    outline: 1px solid red !important;
}

/* For JavaScript toggling */
.active-step {
    background-color: rgba(255, 255, 0, 0.2) !important;
    border: 2px dashed var(--warning) !important;
}

.completed-step {
    opacity: 0.7;
}
