/* Reset and base styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    overflow: hidden;
}

/* Main container - adapts to iframe or standalone */
/* MODIFIED: Increased height to accommodate all content without overlap */
#mainContainer {
    width: 100%;
    height: 550px; /* Increased from 450px to prevent overlap */
    background: white;
    display: flex;
    flex-direction: column;
    position: relative;
    overflow-y: auto;
    padding: 15px;
}

/* If opened in new tab, use 90vh */
body.standalone #mainContainer {
    height: 90vh;
    padding: 20px;
}

/* Info icon for header tooltip */
#infoIcon {
    position: absolute;
    top: 10px;
    right: 10px;
    font-size: 20px;
    cursor: pointer;
    z-index: 100;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #4a90e2;
    color: white;
    border-radius: 50%;
    transition: transform 0.2s, box-shadow 0.2s;
}

#infoIcon:hover {
    transform: scale(1.1);
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
}

/* Tooltip styling */
.tooltip {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(0, 0, 0, 0.9);
    color: white;
    padding: 15px 25px;
    border-radius: 8px;
    font-size: 16px;
    font-weight: bold;
    z-index: 1000;
    display: none;
    text-align: center;
    max-width: 80%;
    box-shadow: 0 8px 20px rgba(0,0,0,0.3);
}

.tooltip.show {
    display: block;
}

/* Interactive area - main content */
/* MODIFIED: Added flex-shrink: 0 to prevent compression */
#interactiveArea {
    display: flex;
    gap: 15px;
    flex: 0 0 auto; /* Changed from flex: 1 to prevent shrinking */
    min-height: 250px; /* Added minimum height to ensure visibility */
    margin-bottom: 15px;
}

/* Control panel - left side */
#controlPanel {
    flex: 0 0 280px;
    background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
    padding: 15px;
    border-radius: 12px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.control-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.control-group label {
    font-weight: bold;
    color: #333;
    font-size: 16px;
}

.slider-container {
    display: flex;
    gap: 10px;
    align-items: center;
}

/* Slider styling */
input[type="range"] {
    flex: 1;
    height: 8px;
    border-radius: 5px;
    background: #ddd;
    outline: none;
    -webkit-appearance: none;
    cursor: pointer;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: #4a90e2;
    cursor: pointer;
    box-shadow: 0 2px 6px rgba(0,0,0,0.2);
    transition: transform 0.2s, box-shadow 0.2s;
}

input[type="range"]::-webkit-slider-thumb:hover {
    transform: scale(1.2);
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}

input[type="range"]::-moz-range-thumb {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: #4a90e2;
    cursor: pointer;
    border: none;
    box-shadow: 0 2px 6px rgba(0,0,0,0.2);
    transition: transform 0.2s, box-shadow 0.2s;
}

input[type="range"]::-moz-range-thumb:hover {
    transform: scale(1.2);
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}

/* Number input styling */
input[type="number"] {
    width: 60px;
    padding: 8px;
    border: 2px solid #4a90e2;
    border-radius: 6px;
    font-size: 16px;
    text-align: center;
    font-weight: bold;
}

input[type="number"]:focus {
    outline: none;
    border-color: #357abd;
    box-shadow: 0 0 8px rgba(74, 144, 226, 0.3);
}

/* Notation display */
#notationDisplay {
    background: white;
    padding: 20px;
    border-radius: 10px;
    text-align: center;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    margin: 10px 0;
}

#notationText {
    font-size: 36px;
    font-weight: bold;
    color: #4a90e2;
}

/* Calculate button */
#calculateBtn {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    padding: 12px;
    border-radius: 8px;
    font-size: 16px;
    font-weight: bold;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
}

#calculateBtn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(0,0,0,0.3);
}

#calculateBtn:active {
    transform: translateY(0);
}

/* Result display */
#resultDisplay {
    background: white;
    padding: 12px;
    border-radius: 8px;
    text-align: center;
    font-size: 18px;
    font-weight: bold;
    color: #667eea;
    min-height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

/* Visual panel - right side */
/* MODIFIED: Added min-height to ensure proper display */
#visualPanel {
    flex: 1;
    background: linear-gradient(135deg, #ffecd2 0%, #fcb69f 100%);
    padding: 15px;
    border-radius: 12px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
    overflow-y: auto;
    min-height: 200px; /* Added to ensure visibility */
}

#multiplicationDisplay {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    font-weight: bold;
    color: #333;
    min-height: 100px;
}

.base-box {
    background: white;
    padding: 12px 18px;
    border-radius: 8px;
    box-shadow: 0 3px 10px rgba(0,0,0,0.15);
    animation: fadeIn 0.3s ease-in;
    transition: transform 0.2s;
}

.base-box:hover {
    transform: scale(1.05);
}

.multiply-sign {
    color: #764ba2;
    font-size: 28px;
    animation: fadeIn 0.3s ease-in;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: scale(0.8);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

/* Question section */
/* MODIFIED: Added flex-shrink: 0 to prevent compression and ensure proper spacing */
#questionSection {
    background: linear-gradient(135deg, #a8edea 0%, #fed6e3 100%);
    padding: 15px;
    border-radius: 12px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
    margin-bottom: 15px;
    flex-shrink: 0; /* Prevents compression */
}

#questionText {
    font-size: 16px;
    font-weight: bold;
    color: #333;
    margin-bottom: 12px;
}

#answerOptions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.answer-btn {
    background: white;
    border: 2px solid #4a90e2;
    padding: 10px 20px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.2s;
    color: #333;
    white-space: nowrap;
}

.answer-btn:hover {
    background: #4a90e2;
    color: white;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
}

.answer-btn.correct {
    background: #4caf50;
    color: white;
    border-color: #4caf50;
}

.answer-btn.incorrect {
    background: #f44336;
    color: white;
    border-color: #f44336;
}

.answer-btn:disabled {
    cursor: not-allowed;
    opacity: 0.6;
}

/* Feedback message */
#feedbackMessage {
    margin-top: 12px;
    padding: 12px;
    border-radius: 8px;
    font-weight: bold;
    text-align: center;
    display: none;
}

#feedbackMessage.show {
    display: block;
}

#feedbackMessage.correct {
    background: #c8e6c9;
    color: #2e7d32;
}

#feedbackMessage.incorrect {
    background: #ffcdd2;
    color: #c62828;
}

/* Progress section */
/* MODIFIED: Added flex-shrink: 0 to prevent compression */
#progressSection {
    background: linear-gradient(135deg, #e0c3fc 0%, #8ec5fc 100%);
    padding: 12px;
    border-radius: 12px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
    flex-shrink: 0; /* Prevents compression */
}

#progressText {
    font-weight: bold;
    color: #333;
    margin-bottom: 8px;
    font-size: 14px;
}

#progressBar {
    width: 100%;
    height: 20px;
    background: white;
    border-radius: 10px;
    overflow: hidden;
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.1);
}

#progressFill {
    height: 100%;
    background: linear-gradient(90deg, #667eea 0%, #764ba2 100%);
    width: 0%;
    transition: width 0.5s ease;
    border-radius: 10px;
}

/* Responsive adjustments for smaller screens */
@media (max-width: 768px) {
    #interactiveArea {
        flex-direction: column;
    }
    
    #controlPanel {
        flex: 0 0 auto;
    }
    
    #visualPanel {
        min-height: 120px;
    }
}

/* Touch-friendly sizing */
@media (hover: none) and (pointer: coarse) {
    .answer-btn {
        min-height: 44px;
        min-width: 44px;
    }
    
    input[type="range"]::-webkit-slider-thumb {
        width: 32px;
        height: 32px;
    }
    
    input[type="range"]::-moz-range-thumb {
        width: 32px;
        height: 32px;
    }
}