/* ===================================
   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 - Adaptive Height
   =================================== */
#mainContainer {
    width: 100%;
    height: 450px; /* Default for iframe */
    display: flex;
    flex-direction: column;
    background: #ffffff;
    position: relative;
}

/* Full window mode detection */
@media (min-height: 500px) {
    body:not(.iframe-mode) #mainContainer {
        height: 90vh;
    }
}

/* ===================================
   TOOLTIP (Header Information)
   =================================== */
.tooltip {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(0, 0, 0, 0.9);
    color: white;
    padding: 12px 20px;
    border-radius: 8px;
    font-size: 14px;
    z-index: 1000;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.3s ease;
    max-width: 80%;
    text-align: center;
    line-height: 1.4;
}

#interactiveArea:hover ~ #headerTooltip {
    opacity: 1;
}

/* ===================================
   INTERACTIVE AREA
   =================================== */
#interactiveArea {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 8px;
    gap: 8px;
    overflow: hidden;
}

/* ===================================
   CONTROL PANEL
   =================================== */
#controlPanel {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 8px;
    background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.control-group {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
}

.control-group label {
    font-size: 13px;
    font-weight: 600;
    color: #2d3748;
    white-space: nowrap;
}

/* ===================================
   BUTTONS - Optimized for Space
   =================================== */
.texture-btn,
.action-btn {
    padding: 8px 12px;
    font-size: 13px;
    font-weight: 600;
    border: 2px solid transparent;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.3s ease;
    white-space: nowrap;
    min-height: 44px; /* Touch-friendly */
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.texture-btn {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    box-shadow: 0 2px 6px rgba(102, 126, 234, 0.3);
}

.texture-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.5);
}

.texture-btn.active {
    background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
    border-color: #f5576c;
    box-shadow: 0 4px 12px rgba(245, 87, 108, 0.5);
}

.action-btn {
    background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
    color: white;
    box-shadow: 0 2px 6px rgba(79, 172, 254, 0.3);
}

.action-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(79, 172, 254, 0.5);
}

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

/* ===================================
   SLIDERS
   =================================== */
input[type="range"] {
    flex: 1;
    min-width: 100px;
    height: 8px;
    border-radius: 4px;
    background: linear-gradient(to right, #667eea 0%, #764ba2 100%);
    outline: none;
    -webkit-appearance: none;
}

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

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

input[type="range"]::-moz-range-thumb {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #f5576c;
    cursor: pointer;
    border: none;
    box-shadow: 0 2px 6px rgba(0,0,0,0.3);
}

/* ===================================
   VISUALIZATION AREA
   =================================== */
#visualizationArea {
    flex: 1;
    position: relative;
    background: #ffffff;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
    overflow: hidden;
    min-height: 200px;
}

#textureCanvas {
    width: 100%;
    height: 100%;
    display: block;
}

/* ===================================
   DESCRIPTION BOX
   =================================== */
.info-box {
    position: absolute;
    bottom: 10px;
    left: 10px;
    right: 10px;
    background: rgba(255, 255, 255, 0.95);
    padding: 10px;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
    backdrop-filter: blur(10px);
}

.info-box h3 {
    font-size: 16px;
    color: #2d3748;
    margin-bottom: 4px;
}

.info-box p {
    font-size: 12px;
    color: #4a5568;
    line-height: 1.4;
    margin-bottom: 4px;
}

#textureExample {
    font-size: 11px;
    color: #718096;
    font-style: italic;
}

/* ===================================
   ANALYTICS PANEL
   =================================== */
#analyticsPanel {
    background: #f7fafc;
    border-top: 2px solid #e2e8f0;
    max-height: 180px;
    display: flex;
    flex-direction: column;
    transition: max-height 0.3s ease;
}

#analyticsPanel.collapsed {
    max-height: 40px;
}

#analyticsHeader {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 12px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    font-weight: 600;
    font-size: 13px;
    cursor: pointer;
}

#toggleAnalytics {
    background: transparent;
    border: none;
    color: white;
    font-size: 16px;
    cursor: pointer;
    padding: 4px 8px;
    transition: transform 0.3s ease;
}

#analyticsPanel.collapsed #toggleAnalytics {
    transform: rotate(-90deg);
}

#analyticsContent {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

#analyticsControls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 12px;
    background: #edf2f7;
    border-bottom: 1px solid #e2e8f0;
}

.analytics-btn {
    padding: 4px 12px;
    font-size: 11px;
    background: #4299e1;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    min-height: 32px;
}

.analytics-btn:hover {
    background: #3182ce;
}

#sessionTime {
    font-size: 11px;
    color: #4a5568;
    font-weight: 600;
}

#actionLog {
    flex: 1;
    overflow-y: auto;
    padding: 8px 12px;
    font-size: 11px;
    line-height: 1.6;
    color: #2d3748;
}

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

.log-entry:last-child {
    border-bottom: none;
}

.log-time {
    color: #4299e1;
    font-weight: 600;
}

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

.log-state {
    color: #718096;
    font-size: 10px;
}

/* ===================================
   RESPONSIVE DESIGN
   =================================== */
@media (max-width: 600px) {
    #controlPanel {
        padding: 6px;
        gap: 6px;
    }
    
    .texture-btn,
    .action-btn {
        font-size: 12px;
        padding: 6px 10px;
    }
    
    .control-group label {
        font-size: 12px;
    }
    
    .info-box h3 {
        font-size: 14px;
    }
    
    .info-box p {
        font-size: 11px;
    }
}

/* ===================================
   ACCESSIBILITY & TOUCH OPTIMIZATION
   =================================== */
button:focus,
input:focus {
    outline: 3px solid #4299e1;
    outline-offset: 2px;
}

@media (hover: none) and (pointer: coarse) {
    /* Touch device optimizations */
    .texture-btn,
    .action-btn {
        min-height: 48px;
        padding: 10px 14px;
    }
}