/* ===================================
   GLOBAL STYLES & RESET
   =================================== */
* {
    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;
    touch-action: manipulation;
}

/* ===================================
   MAIN CONTAINER LAYOUT
   =================================== */
#main-container {
    width: 100%;
    height: 450px; /* Default for iframe */
    display: flex;
    flex-direction: column;
    background: white;
    position: relative;
    overflow-x: auto;
}

/* If opened in new tab, use 90vh */
body.fullscreen #main-container {
    height: 90vh;
}

/* ===================================
   CONTROL PANEL STYLES
   =================================== */
#control-panel {
    background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
    padding: 6px 14px;
    border-bottom: 3px solid #667eea;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    display: inline-flex;
    flex-wrap: nowrap;
    flex-shrink: 0;
    min-width: 100%;
    width: max-content;
    gap: 8px;
    align-items: center;
    overflow-x: auto;
}

.control-group {
    flex: 0 0 auto;
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 6px;
    min-width: 0;
}

.control-group label {
    display: flex;
    align-items: center;
    gap: 4px;
    font-weight: 600;
    font-size: 12px;
    color: #2d3748;
    white-space: nowrap;
    margin-bottom: 0;
}

.label-icon {
    font-size: 13px;
}

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

input[type="range"] {
    width: 100px;
    flex: none;
    height: 6px;
    border-radius: 5px;
    background: #ddd;
    outline: none;
    -webkit-appearance: none;
    cursor: pointer;
}

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

input[type="range"]::-webkit-slider-thumb:hover {
    background: #5568d3;
    transform: scale(1.1);
}

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

.value-display {
    min-width: 38px;
    font-weight: bold;
    color: #667eea;
    font-size: 12px;
    text-align: right;
}

/* ===================================
   BUTTON STYLES
   =================================== */
.button-group {
    display: flex;
    gap: 6px;
    flex-wrap: nowrap;
    flex: 0 0 auto;
    border-left: 2px solid #667eea;
    padding-left: 10px;
}

.action-btn {
    padding: 6px 10px;
    background: #667eea;
    color: white;
    border: none;
    border-radius: 6px;
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
    white-space: nowrap;
    min-height: 34px;
}

.action-btn:hover {
    background: #5568d3;
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0,0,0,0.3);
}

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

/* ===================================
   PRESET SCENARIOS
   =================================== */
.preset-group {
    flex: 0 0 auto;
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 6px;
    margin-top: 0;
    margin-left: 4px;
}

.preset-title {
    font-size: 11px;
    font-weight: 600;
    color: #2d3748;
    white-space: nowrap;
    margin-bottom: 0;
}

.preset-btn {
    padding: 6px 10px;
    background: #48bb78;
    color: white;
    border: none;
    border-radius: 6px;
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
    margin: 0;
    transition: all 0.3s;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
    white-space: nowrap;
    min-height: 34px;
}

.preset-btn:hover {
    background: #38a169;
    transform: translateY(-2px);
}

/* ===================================
   SIMULATION AREA
   =================================== */
#simulation-area {
    flex: 1;
    position: relative;
    overflow: hidden;
    background: linear-gradient(180deg, #e0f2fe 0%, #f0f9ff 100%);
    display: flex;
    justify-content: center;
    align-items: center;
}

#beaker-canvas {
    max-width: 100%;
    max-height: 100%;
    display: block;
}

/* ===================================
   TOOLTIP STYLES
   =================================== */
.tooltip {
    position: absolute;
    background: rgba(0, 0, 0, 0.85);
    color: white;
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 12px;
    pointer-events: none;
    z-index: 1000;
    max-width: 250px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
    transition: opacity 0.2s;
}

.tooltip.hidden {
    opacity: 0;
    visibility: hidden;
}

/* ===================================
   EXPLANATION PANEL - MODIFIED
   Moved to left side, no longer blocking beaker
   =================================== */
#explanation-panel {
    /* Changed from absolute bottom positioning to left side positioning */
    position: absolute;
    left: 10px;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(255, 255, 255, 0.95);
    padding: 12px 16px;
    border-radius: 10px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
    max-width: 220px; /* Reduced width to fit on side */
    text-align: left; /* Changed from center to left */
    border: 2px solid #667eea;
    z-index: 10; /* Ensure it's above canvas */
}

#state-indicator {
    font-size: 14px; /* Slightly reduced */
    font-weight: bold;
    color: #667eea;
    margin-bottom: 6px;
}

#explanation-text {
    font-size: 11px; /* Slightly reduced */
    color: #2d3748;
    line-height: 1.4;
}

/* ===================================
   REFLECTION PANEL
   =================================== */
#reflection-panel {
    position: absolute;
    top: 85px;
    right: 10px;
    background: rgba(255, 255, 255, 0.95);
    padding: 12px;
    border-radius: 10px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
    max-width: 280px;
    border: 2px solid #48bb78;
}

#reflection-panel h3 {
    font-size: 14px;
    color: #2d3748;
    margin-bottom: 8px;
}

#reflection-questions {
    list-style: none;
    font-size: 11px;
    color: #4a5568;
    line-height: 1.6;
}

#reflection-questions li {
    margin-bottom: 6px;
    padding-left: 16px;
    position: relative;
}

#reflection-questions li:before {
    content: "💡";
    position: absolute;
    left: 0;
}

/* ===================================
   ANALYTICS PANEL
   =================================== */
#analytics-panel {
    background: #f7fafc;
    border-top: 3px solid #667eea;
    transition: all 0.3s ease;
    overflow: hidden;
    max-height: 200px;
}

#analytics-panel.collapsed {
    display: none;
}

#analytics-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 15px;
    background: #edf2f7;
    border-bottom: 1px solid #cbd5e0;
}

#analytics-header h3 {
    font-size: 14px;
    color: #2d3748;
}

.small-btn {
    padding: 6px 12px;
    background: #e53e3e;
    color: white;
    border: none;
    border-radius: 4px;
    font-size: 11px;
    cursor: pointer;
    transition: all 0.2s;
    min-height: 44px;
}

.small-btn:hover {
    background: #c53030;
}

#analytics-content {
    padding: 10px 15px;
    max-height: 150px;
    overflow-y: auto;
}

#action-log {
    font-size: 11px;
    color: #4a5568;
    line-height: 1.6;
}

.log-entry {
    padding: 6px 10px;
    margin-bottom: 6px;
    background: white;
    border-left: 3px solid #667eea;
    border-radius: 4px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.log-timestamp {
    font-weight: bold;
    color: #667eea;
    margin-right: 8px;
}

.log-action {
    color: #2d3748;
}

.log-state {
    color: #718096;
    font-style: italic;
    margin-left: 8px;
}

/* ===================================
   RESPONSIVE DESIGN
   =================================== */
@media (max-width: 768px) {
    /* Control panel stays as a single horizontal scrollable line on all screen sizes */

    /* MODIFIED: Adjust explanation panel for mobile */
    #explanation-panel {
        left: 5px;
        max-width: 180px;
        padding: 8px 12px;
        font-size: 10px;
    }
    
    #state-indicator {
        font-size: 12px;
    }
    
    #explanation-text {
        font-size: 10px;
    }

    #reflection-panel {
        top: 5px;
        right: 5px;
        max-width: 200px;
    }
}

/* ===================================
   QUESTIONS PANEL (Task Tracker)
   =================================== */
#questions-panel {
    background: #f0fff4;
    border-top: 3px solid #48bb78;
    overflow: hidden;
    transition: max-height 0.3s ease;
    max-height: 0;
    flex-shrink: 0;  /* prevent simulation-area from squeezing this panel */
}

#questions-panel.expanded {
    max-height: 260px;
}

#questions-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 5px 15px;
    background: #c6f6d5;
    border-bottom: 1px solid #9ae6b4;
    position: sticky;
    top: 0;
    z-index: 5;
}

#questions-header h3 {
    font-size: 12px;
    color: #22543d;
    font-weight: 600;
}

#questions-score {
    font-size: 12px;
    font-weight: bold;
    color: #276749;
    background: white;
    padding: 2px 8px;
    border-radius: 10px;
    border: 1px solid #9ae6b4;
    white-space: nowrap;
}

#questions-content {
    padding: 5px 10px;
    display: flex;
    flex-direction: column;
    gap: 3px;
    max-height: 220px;
    overflow-y: auto;
}

.question-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 8px;
    background: white;
    border-left: 3px solid #cbd5e0;
    border-radius: 5px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.07);
    transition: border-color 0.3s, background 0.3s;
    flex-shrink: 0;
    min-height: 28px;
}

.question-item.achieved {
    border-left-color: #48bb78;
    background: #f0fff4;
}

.q-num {
    font-weight: bold;
    font-size: 11px;
    color: #667eea;
    min-width: 22px;
    flex-shrink: 0;
}

.q-text {
    flex: 1;
    font-size: 10px;
    color: #4a5568;
    line-height: 1.4;
}

.q-text em {
    color: #718096;
}

.q-status {
    font-size: 11px;
    font-weight: bold;
    color: #718096;
    min-width: 52px;
    text-align: right;
    flex-shrink: 0;
}

.question-item.achieved .q-status {
    color: #38a169;
}

.q6-options {
    display: flex;
    gap: 8px;
    flex-shrink: 0;
}

.q6-options label {
    font-size: 10px;
    color: #2d3748;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 2px;
    white-space: nowrap;
}

/* ===================================
   UTILITY CLASSES
   =================================== */
.hidden {
    display: none !important;
}

/* Scrollbar styling for analytics */
#analytics-content::-webkit-scrollbar {
    width: 6px;
}

#analytics-content::-webkit-scrollbar-track {
    background: #edf2f7;
}

#analytics-content::-webkit-scrollbar-thumb {
    background: #cbd5e0;
    border-radius: 3px;
}

#analytics-content::-webkit-scrollbar-thumb:hover {
    background: #a0aec0;
}