/* 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%);
    color: #333;
    overflow-x: hidden;
}

/* Container setup for iframe/standalone */
.container {
    width: 100%;
    height: 100vh;
    max-height: 450px;
    display: flex;
    flex-direction: column;
    background: white;
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.1);
    overflow: hidden;
}

/* Detect if in iframe and adjust height */
@media (max-height: 500px) {
    .container {
        height: 450px;
    }
}

@media (min-height: 501px) {
    .container {
        height: 90vh;
    }
}

/* Tooltip */
.tooltip {
    position: absolute;
    background: rgba(0,0,0,0.9);
    color: white;
    padding: 8px 12px;
    border-radius: 4px;
    font-size: 12px;
    pointer-events: none;
    z-index: 1000;
    opacity: 0;
    transition: opacity 0.3s;
    max-width: 200px;
    word-wrap: break-word;
}

.tooltip.show {
    opacity: 1;
}

/* Control Panel */
.control-panel {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 15px;
    background: #f8f9fa;
    border-bottom: 2px solid #e9ecef;
    flex-shrink: 0;
}

.controls-left, .controls-center, .controls-right {
    display: flex;
    align-items: center;
    gap: 10px;
}

.controls-center {
    flex: 1;
    justify-content: center;
}

/* Buttons */
.btn {
    padding: 8px 16px;
    border: none;
    border-radius: 6px;
    background: #007bff;
    color: white;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.3s;
    min-height: 44px;
    min-width: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn:hover {
    background: #0056b3;
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0,123,255,0.3);
}

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

.btn-small {
    padding: 4px 8px;
    font-size: 12px;
    min-height: 32px;
    min-width: auto;
}

/* Select dropdown */
select {
    padding: 6px 10px;
    border: 2px solid #ddd;
    border-radius: 4px;
    font-size: 14px;
    background: white;
    cursor: pointer;
    min-height: 44px;
}

select:focus {
    outline: none;
    border-color: #007bff;
}

/* Lab Container */
.lab-container {
    flex: 1;
    padding: 10px;
    background: #fafafa;
    position: relative;
    overflow: hidden;
}

#labSvg {
    width: 100%;
    height: 100%;
    background: white;
    border: 2px solid #ddd;
    border-radius: 8px;
    cursor: default;
}

/* SVG Elements */
.light-source {
    fill: url(#lightGradient);
    stroke: #ff6600;
    stroke-width: 2;
    cursor: grab;
    filter: drop-shadow(0 0 10px rgba(255,255,0,0.5));
}

.light-source:active {
    cursor: grabbing;
}

.light-ray {
    stroke: #ffff00;
    stroke-width: 3;
    stroke-dasharray: 5,5;
    opacity: 0.8;
    filter: drop-shadow(0 0 3px rgba(255,255,0,0.3));
}

.opaque-object {
    fill: #8B4513;
    stroke: #654321;
    stroke-width: 2;
    cursor: grab;
    filter: drop-shadow(2px 2px 4px rgba(0,0,0,0.3));
}

.opaque-object:active {
    cursor: grabbing;
}

.screen {
    fill: #e0e0e0;
    stroke: #999;
    stroke-width: 2;
    cursor: grab;
}

.screen:active {
    cursor: grabbing;
}

.shadow {
    fill: url(#shadowGradient);
    opacity: 0.7;
}

.label {
    font-size: 12px;
    fill: #333;
    text-anchor: middle;
    font-weight: 500;
}

.draggable:hover {
    filter: brightness(1.1);
}

/* Measurements */
.measurements {
    opacity: 0.6;
}

.dist-line {
    stroke: #666;
    stroke-width: 1;
    stroke-dasharray: 2,2;
}

.dist-text {
    font-size: 10px;
    fill: #666;
    text-anchor: middle;
}

/* Info Panel */
.info-panel {
    display: flex;
    justify-content: space-around;
    padding: 10px;
    background: #f8f9fa;
    border-top: 1px solid #e9ecef;
    flex-shrink: 0;
}

.info-item {
    text-align: center;
}

.info-label {
    font-size: 12px;
    color: #666;
    display: block;
}

.info-value {
    font-size: 14px;
    font-weight: bold;
    color: #007bff;
}

/* Analytics Panel */
.analytics-panel {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 150px;
    background: white;
    border-top: 2px solid #007bff;
    transform: translateY(100%);
    transition: transform 0.3s ease;
    z-index: 100;
}

.analytics-panel.show {
    transform: translateY(0);
}

.analytics-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 15px;
    background: #f8f9fa;
    border-bottom: 1px solid #e9ecef;
}

.analytics-header h3 {
    font-size: 14px;
    margin: 0;
}

.action-log {
    height: calc(150px - 45px);
    overflow-y: auto;
    padding: 10px;
    font-size: 12px;
    line-height: 1.4;
}

.log-entry {
    padding: 4px 0;
    border-bottom: 1px solid #f0f0f0;
}

.log-time {
    color: #666;
    font-weight: bold;
}

.log-action {
    color: #333;
    margin-left: 10px;
}

/* Mobile Responsiveness */
@media (max-width: 768px) {
    .control-panel {
        flex-direction: column;
        gap: 10px;
        padding: 8px;
    }
    
    .controls-left, .controls-center, .controls-right {
        width: 100%;
        justify-content: center;
    }
    
    .btn {
        font-size: 12px;
        padding: 6px 12px;
    }
    
    .info-panel {
        flex-direction: column;
        gap: 5px;
    }
    
    .info-item {
        display: flex;
        justify-content: space-between;
        align-items: center;
    }
    
    .info-label {
        display: inline;
    }
}

/* Touch-friendly adjustments */
@media (pointer: coarse) {
    .btn {
        min-height: 48px;
        min-width: 48px;
    }
    
    select {
        min-height: 48px;
    }
    
    .light-source, .opaque-object, .screen {
        stroke-width: 3;
    }
}

/* Animation classes */
.animate-light {
    transition: cx 0.1s ease-out;
}

/* Accessibility */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}