/* Addition-specific styles - Optimized for All Screen */

.addition-container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0.5rem;
    overflow-x: hidden; /* Prevent horizontal scroll */
}

/* Title Container */
.container.title-container {
    text-align: center;
    margin-bottom: 1.5rem;
    padding: 1rem;
    background: white;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.page-title {
    color: #2c3e50;
    font-size: 1.8rem;
    margin-bottom: 0.5rem;
}

.page-description {
    color: #666;
    font-size: 1.1rem;
    line-height: 1.4;
}

/* Dual Container Layout - Better for small screens */
.dual-container {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    margin: 1rem auto;
    max-width: 1200px;
}

@media (min-width: 1024px) {
    .dual-container {
        flex-direction: row;
        gap: 2rem;
    }
}

/* Make both containers take full width on mobile, equal width on desktop */
.main-problem-container,
.sub-problem-container {
    flex: 1;
    min-width: 0; /* Prevents flex items from overflowing */
    display: flex;
    flex-direction: column;
    min-height: 400px; /* Minimum height for consistency */
    max-height: 650px; /* Maximum height to prevent getting too tall */
    overflow-y: auto; /* Allow scrolling if content exceeds */
}

@media (min-width: 1024px) {
    .main-problem-container,
    .sub-problem-container {
        flex: 1;
        max-width: 50%;
    }
}

/* Main Problem Container */
.main-problem-container {
    background: white;
    padding: 1rem;
    border-radius: 12px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    border: 2px solid #e0e0e0;
}

.main-problem-container h3 {
    color: #2c3e50;
    margin-bottom: 1rem;
    text-align: center;
    font-size: 1.3rem;
    border-bottom: 2px solid #2196f3;
    padding-bottom: 0.5rem;
    position: sticky;
    top: 0;
    background: white;
    z-index: 10;
}

/* Responsive Main Problem Grid */
.problem-grid {
    display: grid;
    grid-template-columns: 40px repeat(3, minmax(50px, 1fr));
    grid-template-rows: repeat(5, 45px);
    gap: 2px;
    margin: 0 auto;
    max-width: 400px;
}

@media (min-width: 480px) {
    .problem-grid {
        grid-template-columns: 50px repeat(3, minmax(60px, 1fr));
        grid-template-rows: repeat(5, 50px);
    }
}

@media (min-width: 768px) {
    .problem-grid {
        grid-template-columns: 60px repeat(3, minmax(70px, 1fr));
        grid-template-rows: repeat(5, 60px);
    }
}

@media (min-width: 1024px) {
    .problem-grid {
        grid-template-columns: 60px repeat(3, 80px);
        grid-template-rows: repeat(5, 60px);
    }
}

.grid-cell {
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    border: 1px solid #ddd;
    position: relative;
    background: #f9f9f9;
    font-size: 1.4rem;
}

@media (min-width: 480px) {
    .grid-cell {
        font-size: 1.6rem;
    }
}

@media (min-width: 768px) {
    .grid-cell {
        font-size: 1.8rem;
    }
}

/* Plus Column */
.grid-cell.plus-column {
    background: #f8f9fa;
    font-size: 1.8rem;
    color: #2196f3;
    font-weight: bold;
    border-right: 2px solid #ccc;
}

/* Carry Cells */
.grid-cell.carry-cell {
    background: transparent;
    border: none;
    font-size: 0.9rem;
    color: #666;
    font-weight: normal;
    min-height: 25px;
    padding-top: 5px;
}

.grid-cell.active-carry {
    background: #fff3e0;
    border: 2px solid #ff9800;
    color: #ef6c00;
    font-weight: bold;
    border-radius: 4px;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% { opacity: 0.8; transform: scale(0.98); }
    50% { opacity: 1; transform: scale(1.02); }
    100% { opacity: 0.8; transform: scale(0.98); }
}

/* Number Cells */
.grid-cell.number-cell {
    background: #f8f9fa;
    font-size: 1.8rem;
    color: #333;
    border: 1px solid #ccc;
}

/* Horizontal Line */
.grid-cell.line {
    background: #333;
    border: none;
    height: 1px;
    margin: 2px -3px 2px -1px;
    min-height: 20px !important; /* Force max height */
    max-height: 20px !important;
    align-self: center; /* Center vertically in the row */
}

/* Answer Cells */
.grid-cell.answer-cell {
    background: #f5f5f5;
    font-size: 1.8rem;
    color: #555;
    border: 1px dashed #bbb;
}

.grid-cell.answer-cell.correct {
    background: #e8f5e9;
    border: 2px solid #4caf50;
    color: #2e7d32;
    font-weight: bold;
    animation: correctPop 0.5s;
}

@keyframes correctPop {
    0% { transform: scale(1); }
    50% { transform: scale(1.1); }
    100% { transform: scale(1); }
}

.grid-cell.answer-cell.incorrect {
    background: #ffebee;
    border: 2px solid #f44336;
    color: #c62828;
    font-weight: bold;
}

/* Active Column Highlighting */
.grid-cell.active-column {
    background: #e3f2fd;
    border: 2px solid #2196f3;
    box-shadow: 0 0 0 3px rgba(33, 150, 243, 0.2);
    z-index: 1;
}

/* Sub-Problem Container */
.sub-problem-container {
    background: white;
    padding: 1rem;
    border-radius: 12px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    border: 2px solid #e0e0e0;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.sub-problem-container h3 {
    color: #2c3e50;
    margin-bottom: 1rem;
    text-align: center;
    font-size: 1.3rem;
    border-bottom: 2px solid #ff9800;
    padding-bottom: 0.5rem;
    position: sticky;
    top: 0;
    background: white;
    z-index: 10;
}

/* Sub-Problem Display */
.sub-problem-display {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    width: 100%;
    max-width: 280px;
    margin-top: 1rem;
}

/* Side-by-side numbers row */
.sub-numbers-row {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    flex-wrap: wrap;
    margin-bottom: 0.5rem;
}

.sub-carry-value {
    font-size: 1.5rem;
    font-weight: bold;
    color: #ef6c00;
    background: #fff3e0;
    padding: 0.3rem 0.8rem;
    border-radius: 6px;
    border: 2px solid #ff9800;
    animation: pulse 2s infinite;
}

.sub-number {
    font-size: 2rem;
    font-weight: bold;
    color: #1565c0;
    background: #e3f2fd;
    padding: 0.3rem 0.8rem;
    border-radius: 6px;
    border: 2px solid #2196f3;
    min-width: 50px;
    text-align: center;
}

.sub-plus {
    font-size: 1.8rem;
    font-weight: bold;
    color: #666;
    margin: 0 0.3rem;
}

.sub-line {
    width: 80%;
    height: 2px;
    background: #333;
    margin: 0.5rem 0;
}

.sub-answer, .sub-answer-placeholder {
    font-size: 2rem;
    font-weight: bold;
    padding: 0.3rem 0.8rem;
    border-radius: 6px;
    min-width: 50px;
    text-align: center;
    margin-top: 0.5rem;
}

.sub-answer-placeholder {
    background: #f5f5f5;
    color: #999;
    border: 2px dashed #bbb;
}

.sub-answer.correct {
    background: #e8f5e9;
    color: #2e7d32;
    border: 2px solid #4caf50;
    animation: correctPop 0.5s;
}

.sub-answer.incorrect {
    background: #ffebee;
    color: #c62828;
    border: 2px solid #f44336;
}

/* Sub-Problem Complete Message */
.sub-complete {
    text-align: center;
    padding: 1.5rem;
    background: #e8f5e9;
    border-radius: 10px;
    border: 2px solid #4caf50;
    margin: 1rem 0;
}

.sub-complete h4 {
    color: #2e7d32;
    margin-bottom: 1rem;
    font-size: 1.5rem;
}

.sub-complete p {
    color: #2e7d32;
    font-size: 1.1rem;
    margin: 0.5rem 0;
}

/* ===== SIMPLE NUMBER CONTROLS FOR ALL SCREENS ===== */
.sub-input-container {
    margin-top: 1rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    align-items: center;
    width: 100%;
    padding: 0 0.5rem;
}

/* Hide regular input field (we use our own display) */
#subAnswer {
    display: none !important;
}

/* Simple number controls container */
.simple-number-controls {
    width: 100%;
    max-width: 500px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
    padding: 0.5rem;
}

/* Number display */
.number-display {
    width: 100%;
    text-align: center;
    margin-bottom: 0.5rem;
}

#currentNumber {
    display: inline-block;
    font-size: 3rem;
    font-weight: bold;
    color: #1565c0;
    background: #e3f2fd;
    padding: 0.5rem 2rem;
    border-radius: 12px;
    border: 3px solid #2196f3;
    min-width: 120px;
    min-height: 70px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 12px rgba(33, 150, 243, 0.2);
}

/* Number buttons container */
.number-buttons {
    display: flex;
    gap: 0.8rem;
    width: 100%;
    justify-content: center;
    flex-wrap: nowrap;
}

/* Base button style */
.number-btn {
    padding: 0.8rem 0.5rem; /* Reduce padding, especially horizontal */
    font-size: 1.2rem;
    font-weight: bold;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.2s;
    flex: 1; /* Make buttons grow/shrink equally */
    min-width: 0; /* Allow shrinking below content size */
    display: flex;
    align-items: center;
    justify-content: center;
    user-select: none;
    color: white;
    white-space: nowrap; /* Prevent text wrapping inside button */
}

.number-btn:active {
    transform: scale(0.95);
}

/* Specific button colors */
.number-btn.decrement {
    background: linear-gradient(135deg, #f44336 0%, #d32f2f 100%);
}

.number-btn.decrement:hover:not(:disabled) {
    background: linear-gradient(135deg, #d32f2f 0%, #c62828 100%);
    box-shadow: 0 4px 8px rgba(244, 67, 54, 0.3);
}

.number-btn.increment {
    background: linear-gradient(135deg, #4caf50 0%, #388e3c 100%);
}

.number-btn.increment:hover:not(:disabled) {
    background: linear-gradient(135deg, #388e3c 0%, #2e7d32 100%);
    box-shadow: 0 4px 8px rgba(76, 175, 80, 0.3);
}

.number-btn.clear {
    background: linear-gradient(135deg, #ff9800 0%, #f57c00 100%);
}

.number-btn.clear:hover:not(:disabled) {
    background: linear-gradient(135deg, #f57c00 0%, #ef6c00 100%);
    box-shadow: 0 4px 8px rgba(255, 152, 0, 0.3);
}

.number-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none !important;
}

/* Combined Action Button */
.combined-action-btn {
    padding: 1rem 1.5rem;
    font-size: 1.1rem;
    font-weight: 600;
    border-radius: 8px;
    border: none;
    cursor: pointer;
    transition: all 0.3s;
    width: 100%;
    max-width: 300px;
    margin: 0 auto;
    display: block;
    background: linear-gradient(135deg, #2196f3 0%, #1976d2 100%);
    color: white;
}

.combined-action-btn:hover:not(:disabled) {
    transform: translateY(-3px);
    box-shadow: 0 6px 12px rgba(0, 0, 0, 0.2);
}

.combined-action-btn:active:not(:disabled) {
    transform: translateY(-1px);
}

.combined-action-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none !important;
}

/* Sub-Feedback */
.sub-feedback {
    margin-top: 1rem;
    padding: 0.8rem;
    border-radius: 8px;
    text-align: center;
    font-size: 1rem;
    font-weight: bold;
    min-height: 60px;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1.5;
    width: 100%;
    max-width: 300px;
}

.sub-feedback.correct {
    background: linear-gradient(135deg, #e8f5e9 0%, #c8e6c9 100%);
    color: #2e7d32;
    border: 2px solid #81c784;
}

.sub-feedback.incorrect {
    background: linear-gradient(135deg, #ffebee 0%, #ffcdd2 100%);
    color: #c62828;
    border: 2px solid #e57373;
}

/* Main Feedback */
.feedback {
    margin: 1rem auto;
    padding: 0.8rem;
    border-radius: 8px;
    text-align: center;
    font-size: 1.1rem;
    font-weight: bold;
    min-height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    max-width: 500px;
}

.feedback.correct {
    background: linear-gradient(135deg, #e8f5e9 0%, #c8e6c9 100%);
    color: #2e7d32;
    border: 2px solid #81c784;
}

.feedback.incorrect {
    background: linear-gradient(135deg, #ffebee 0%, #ffcdd2 100%);
    color: #c62828;
    border: 2px solid #e57373;
}

/* Simple Controls - Hide the old New Problem button */
.simple-controls {
    display: none;
}

/* Ratio Container */
.container.ratio-container {
    margin-top: 2rem;
    padding: 1.5rem;
    background: white;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.score-display {
    text-align: center;
}

.score-display h3 {
    color: #2c3e50;
    font-size: 1.5rem;
    margin-bottom: 1.5rem;
    border-bottom: 2px solid #9c27b0;
    padding-bottom: 0.5rem;
    display: inline-block;
}

/* Score Stats */
.score-stats {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.stat {
    background: #f8f9fa;
    padding: 1rem;
    border-radius: 10px;
    border: 2px solid #dee2e6;
    min-width: 140px;
    flex: 1;
    max-width: 200px;
    transition: transform 0.3s, box-shadow 0.3s;
}

.stat:hover {
    transform: translateY(-3px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.stat.correct {
    border-color: #4caf50;
    background: linear-gradient(135deg, #e8f5e9 0%, #c8e6c9 100%);
}

.stat.incorrect {
    border-color: #f44336;
    background: linear-gradient(135deg, #ffebee 0%, #ffcdd2 100%);
}

.stat.total {
    border-color: #2196f3;
    background: linear-gradient(135deg, #e3f2fd 0%, #bbdefb 100%);
}

.stat.accuracy {
    border-color: #9c27b0;
    background: linear-gradient(135deg, #f3e5f5 0%, #e1bee7 100%);
}

.stat-label {
    display: block;
    font-size: 0.9rem;
    color: #6c757d;
    margin-bottom: 0.5rem;
    font-weight: 600;
}

.stat-value {
    display: block;
    font-size: 1.8rem;
    font-weight: bold;
    color: #2c3e50;
}

.stat.correct .stat-value {
    color: #2e7d32;
}

.stat.incorrect .stat-value {
    color: #c62828;
}

.stat.total .stat-value {
    color: #1565c0;
}

.stat.accuracy .stat-value {
    color: #6a1b9a;
}

/* Reset Scores Button */
#resetScores {
    padding: 0.8rem 1.5rem;
    font-size: 1rem;
    font-weight: 600;
    border-radius: 8px;
    border: none;
    cursor: pointer;
    transition: all 0.3s;
    background: linear-gradient(135deg, #9e9e9e 0%, #757575 100%);
    color: white;
    margin: 0.5rem auto;
    display: block;
    max-width: 200px;
}

#resetScores:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}

/* ==================== MOBILE OPTIMIZATIONS ==================== */
/* Tablet and Below (≤1023px) */
@media (max-width: 1023px) {
    .addition-container {
        padding: 0.25rem;
    }
    
    .container.title-container {
        margin-bottom: 1rem;
        padding: 0.75rem;
    }
    
    .page-title {
        font-size: 1.5rem;
        margin-bottom: 0.3rem;
    }
    
    .page-description {
        font-size: 0.95rem;
        line-height: 1.3;
    }
    
    .dual-container {
        gap: 1rem;
        margin: 0.5rem auto;
    }
    
    /* Make containers compact */
    .main-problem-container,
    .sub-problem-container {
        height: auto;
        min-height: 320px;
        padding: 0.75rem;
    }
    
    /* Reduce grid size */
    .problem-grid {
        grid-template-columns: 35px repeat(3, minmax(45px, 1fr));
        grid-template-rows: repeat(5, 40px);
        gap: 1px;
        max-width: 320px;
    }
    
    .grid-cell {
        font-size: 1.3rem;
    }
    
    /* Sub-problem adjustments */
    .sub-number, .sub-answer, .sub-answer-placeholder {
        font-size: 1.6rem;
        min-width: 40px;
        padding: 0.2rem 0.6rem;
    }
    
    .sub-carry-value {
        font-size: 1.3rem;
        padding: 0.2rem 0.6rem;
    }
    
    /* Number display adjustments */
    #currentNumber {
        font-size: 2.5rem;
        padding: 0.4rem 1.5rem;
        min-height: 60px;
    }
    
    .number-btn {
        padding: 0.9rem 1.2rem;
        font-size: 1rem;
        min-width: 70px;
    }
    
    .combined-action-btn {
        padding: 0.9rem;
        font-size: 1rem;
        max-width: 250px;
    }
    
    /* Score display adjustments */
    .container.ratio-container {
        margin-top: 1.5rem;
        padding: 1rem;
    }
    
    .score-stats {
        gap: 0.75rem;
    }
    
    .stat {
        min-width: 110px;
        padding: 0.75rem;
    }
    
    .stat-value {
        font-size: 1.5rem;
    }
}

/* Mobile (≤768px) */
@media (max-width: 768px) {
    .main-problem-container h3,
    .sub-problem-container h3 {
        font-size: 1.1rem;
        padding-bottom: 0.3rem;
        margin-bottom: 0.75rem;
        position: static; /* Remove sticky on mobile */
    }
    
    /* Score stats - stack vertically */
    .score-stats {
        flex-direction: column;
        align-items: center;
    }
    
    .stat {
        width: 100%;
        max-width: 280px;
    }
}

/* Small Mobile (≤480px) */
@media (max-width: 480px) {
    .main-problem-container,
    .sub-problem-container {
        min-height: 280px;
        padding: 0.5rem;
    }
    
    .problem-grid {
        grid-template-columns: 30px repeat(3, minmax(40px, 1fr));
        grid-template-rows: repeat(5, 35px);
        max-width: 280px;
    }
    
    .grid-cell {
        font-size: 1.2rem;
    }
    
    /* Adjust sub-problem elements */
    .sub-number, .sub-answer, .sub-answer-placeholder {
        font-size: 1.5rem;
        min-width: 35px;
        padding: 0.2rem 0.5rem;
    }
    
    .sub-carry-value {
        font-size: 1.2rem;
        padding: 0.2rem 0.5rem;
    }
    
    /* Smaller controls */
    #currentNumber {
        font-size: 2.2rem;
        padding: 0.4rem 1.2rem;
        min-height: 55px;
    }
    
    .number-buttons {
        gap: 0.5rem;
    }
    
    .number-btn {
        padding: 0.8rem 1rem;
        font-size: 0.9rem;
        min-width: 60px;
    }
    
    .combined-action-btn {
        padding: 0.8rem;
        font-size: 0.9rem;
        max-width: 250px;
    }
}

/* Extra Small Mobile (≤360px) */
@media (max-width: 360px) {
    .problem-grid {
        grid-template-columns: 28px repeat(3, minmax(35px, 1fr));
        grid-template-rows: repeat(5, 32px);
        max-width: 240px;
    }
    
    .grid-cell {
        font-size: 1.1rem;
    }
    
    /* Even smaller controls */
    #currentNumber {
        font-size: 2rem;
        padding: 0.3rem 1rem;
        min-height: 50px;
    }
    
    .number-buttons {
        gap: 0.3rem;
    }
    
    .number-btn {
        padding: 0.7rem 0.8rem;
        font-size: 0.85rem;
        min-width: 55px;
    }
    
    .combined-action-btn {
        padding: 0.7rem;
        font-size: 0.85rem;
        max-width: 220px;
    }
    
    .sub-problem-display {
        max-width: 220px;
    }
}

/* Remove old mobile number pad styles */
.mobile-number-pad {
    display: none !important;
}

/* Animation classes */
@keyframes dropIn {
    0% {
        transform: translateY(-20px);
        opacity: 0;
    }
    100% {
        transform: translateY(0);
        opacity: 1;
    }
}

@keyframes sourcePulse {
    0% { box-shadow: 0 0 0 0 rgba(33, 150, 243, 0.7); }
    70% { box-shadow: 0 0 0 10px rgba(33, 150, 243, 0); }
    100% { box-shadow: 0 0 0 0 rgba(33, 150, 243, 0); }
}

.animate-source {
    animation: sourcePulse 1s ease;
    z-index: 10;
}

.animate-drop-in {
    animation: dropIn 0.5s ease forwards;
}

/* Scrollbar styling */
.main-problem-container::-webkit-scrollbar,
.sub-problem-container::-webkit-scrollbar {
    width: 6px;
}

.main-problem-container::-webkit-scrollbar-track,
.sub-problem-container::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 10px;
}

.main-problem-container::-webkit-scrollbar-thumb,
.sub-problem-container::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 10px;
}

.main-problem-container::-webkit-scrollbar-thumb:hover,
.sub-problem-container::-webkit-scrollbar-thumb:hover {
    background: #a8a8a8;
}
