/* 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, #f5f7fa 0%, #c3cfe2 100%);
    height: 100vh;
    overflow: hidden;
}

/* Container setup for iframe compatibility */
.container {
    width: 100%;
    height: 450px; /* Default iframe height */
    display: flex;
    flex-direction: column;
    padding: 8px;
    gap: 8px;
    position: relative;
}

/* Adjust height when not in iframe */
@media (min-height: 500px) {
    .container {
        height: 90vh;
    }
}

/* Lab bench area - main workspace */
.lab-bench {
    display: flex;
    gap: 12px;
    height: 45%;
    background: linear-gradient(145deg, #ffffff, #e6e6e6);
    border-radius: 12px;
    padding: 12px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.1);
}

/* Test tube rack styling */
.test-tube-rack {
    flex: 1;
    position: relative;
    background: #8B4513;
    border-radius: 8px;
    padding: 10px;
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.2);
}

.rack-base {
    height: 20px;
    background: linear-gradient(145deg, #A0522D, #8B4513);
    border-radius: 4px;
    margin-bottom: 8px;
}

.test-tubes-container {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(40px, 1fr));
    gap: 8px;
    height: calc(100% - 28px);
}

/* Test tube styling */
.test-tube {
    width: 35px;
    height: 120px;
    background: linear-gradient(to bottom, transparent 0%, #e8f4f8 100%);
    border: 2px solid #b0c4de;
    border-radius: 0 0 15px 15px;
    position: relative;
    cursor: pointer;
    transition: all 0.3s ease;
    margin: 0 auto;
}

.test-tube:hover {
    transform: translateY(-3px);
    box-shadow: 0 6px 12px rgba(0,0,0,0.2);
}

.test-tube.selected {
    border-color: #4CAF50;
    box-shadow: 0 0 10px rgba(76, 175, 80, 0.5);
}

.test-tube.has-substance {
    background: linear-gradient(to bottom, transparent 60%, #current-color 100%);
}

.test-tube.tested {
    animation: colorChange 0.8s ease-in-out;
}

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

/* Apparatus shelf styling */
.apparatus-shelf {
    flex: 1.5;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.shelf-section {
    flex: 1;
    background: #f8f9fa;
    border-radius: 8px;
    padding: 8px;
    border: 2px solid #dee2e6;
}

.shelf-section h3 {
    font-size: 14px;
    margin-bottom: 8px;
    color: #495057;
    text-align: center;
}

.indicator-bottles, .substance-bottles {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(60px, 1fr));
    gap: 6px;
    height: calc(100% - 30px);
}

/* Bottle styling */
.bottle {
    background: linear-gradient(145deg, #ffffff, #f1f3f4);
    border: 2px solid #dadce0;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    min-height: 50px;
}

.bottle:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0,0,0,0.15);
    border-color: #4285f4;
}

.bottle.selected {
    border-color: #34a853;
    background: linear-gradient(145deg, #e8f5e8, #d4edda);
}

.bottle-label {
    font-size: 11px;
    font-weight: 600;
    text-align: center;
    color: #333;
    line-height: 1.2;
}

/* Specific indicator colors */
.universal-indicator { background: linear-gradient(90deg, #ff0000, #ffff00, #00ff00, #0000ff); }
.litmus-indicator { background: linear-gradient(90deg, #ff6b6b, #4ecdc4); }
.phenol-indicator { background: linear-gradient(90deg, transparent, #ff69b4); }
.methyl-indicator { background: linear-gradient(90deg, #ff4757, #ffa502); }

.mystery {
    background: linear-gradient(145deg, #6c5ce7, #a29bfe) !important;
    color: white;
}

.mystery .bottle-label {
    color: white;
}

/* Control panel styling */
.control-panel {
    height: 25%;
    display: flex;
    gap: 12px;
    background: #ffffff;
    border-radius: 12px;
    padding: 12px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}

/* pH Chart */
.ph-chart {
    flex: 2;
}

.ph-chart h3 {
    font-size: 14px;
    margin-bottom: 8px;
    color: #333;
}

.ph-scale {
    position: relative;
    height: 60px;
}

.ph-values {
    display: flex;
    justify-content: space-between;
    font-size: 10px;
    font-weight: bold;
    margin-bottom: 4px;
}

.ph-colors {
    height: 20px;
    background: linear-gradient(to right, 
        #ff0000 0%, #ff4500 7%, #ffa500 14%, #ffff00 21%, 
        #9acd32 28%, #32cd32 35%, #00ff00 42%, #00ff7f 50%, 
        #00ffff 57%, #0080ff 64%, #0000ff 71%, #4b0082 78%, 
        #8b00ff 85%, #ff00ff 92%, #ff1493 100%);
    border-radius: 10px;
    margin-bottom: 4px;
}

.ph-labels {
    display: flex;
    justify-content: space-between;
    font-size: 9px;
    color: #666;
}

/* pH Display */
.ph-display {
    flex: 1;
    text-align: center;
}

.ph-display h3 {
    font-size: 14px;
    margin-bottom: 8px;
    color: #333;
}

.digital-ph {
    font-size: 24px;
    font-weight: bold;
    color: #2196F3;
    background: #000;
    border-radius: 8px;
    padding: 8px;
    margin-bottom: 4px;
    font-family: 'Courier New', monospace;
}

.ph-nature {
    font-size: 12px;
    color: #666;
    font-weight: 500;
}

/* Control buttons */
.controls {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.btn {
    padding: 8px 12px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 12px;
    font-weight: 600;
    transition: all 0.3s ease;
    height: fit-content;
    white-space: nowrap;
}

.hint-btn {
    background: #ffc107;
    color: #333;
}

.zoom-btn {
    background: #17a2b8;
    color: white;
}

.reset-btn {
    background: #dc3545;
    color: white;
}

.btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 2px 6px rgba(0,0,0,0.2);
}

/* Results table */
.results-table {
    height: 30%;
    background: #ffffff;
    border-radius: 12px;
    padding: 12px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}

.results-table h3 {
    font-size: 14px;
    margin-bottom: 8px;
    color: #333;
}

.table-container {
    height: calc(100% - 30px);
    overflow-y: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 11px;
}

th, td {
    padding: 4px 6px;
    text-align: center;
    border: 1px solid #dee2e6;
}

th {
    background: #f8f9fa;
    font-weight: 600;
    color: #495057;
}

tr:nth-child(even) {
    background: #f8f9fa;
}

/* Modal styles */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0,0,0,0.5);
}

.modal-content {
    background-color: #fefefe;
    margin: 15% auto;
    padding: 20px;
    border-radius: 12px;
    width: 80%;
    max-width: 500px;
    position: relative;
    box-shadow: 0 4px 20px rgba(0,0,0,0.3);
}

.close {
    color: #aaa;
    float: right;
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
    line-height: 1;
}

.close:hover {
    color: #000;
}

.zoom-content .magnified-tube {
    width: 200px;
    height: 300px;
    margin: 20px auto;
    border: 4px solid #b0c4de;
    border-radius: 0 0 30px 30px;
    background: linear-gradient(to bottom, transparent 60%, #current-color 100%);
}

/* Instructions */
.instructions {
    position: absolute;
    top: 10px;
    right: 10px;
    background: rgba(255,255,255,0.95);
    padding: 8px;
    border-radius: 6px;
    font-size: 10px;
    box-shadow: 0 2px 6px rgba(0,0,0,0.1);
    max-width: 200px;
}

.instructions p {
    margin-bottom: 2px;
    line-height: 1.3;
}

/* Mobile optimizations */
@media (max-width: 768px) {
    .container {
        padding: 4px;
        gap: 4px;
    }
    
    .lab-bench {
        flex-direction: column;
        height: 50%;
    }
    
    .control-panel {
        height: 20%;
        flex-wrap: wrap;
    }
    
    .results-table {
        height: 30%;
    }
    
    .bottle {
        min-height: 40px;
    }
    
    .bottle-label {
        font-size: 10px;
    }
    
    .test-tube {
        width: 30px;
        height: 100px;
    }
}

/* Touch-friendly sizing for mobile */
@media (pointer: coarse) {
    .bottle, .test-tube, .btn {
        min-height: 44px;
        min-width: 44px;
    }
}