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

body {
    font-family: 'Microsoft YaHei', 'SimHei', sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: #333;
    overflow: hidden;
    user-select: none;
}

/* Main container with responsive height */
#main-container {
    width: 100%;
    height: 450px; /* Default iframe height */
    display: flex;
    flex-direction: column;
    position: relative;
}

/* Responsive height for full browser view */
@media (min-height: 600px) {
    body:not(.iframe-mode) #main-container {
        height: 90vh;
    }
}

/* Control panel styling */
#control-panel {
    background: rgba(255, 255, 255, 0.95);
    padding: 8px;
    display: flex;
    gap: 8px;
    justify-content: center;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    flex-shrink: 0;
}

.control-btn {
    background: linear-gradient(145deg, #f0f0f0, #cacaca);
    border: none;
    border-radius: 8px;
    padding: 8px 12px;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 2px 2px 5px rgba(0, 0, 0, 0.1);
    min-height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.control-btn:hover {
    background: linear-gradient(145deg, #e0e0e0, #bababa);
    transform: translateY(-2px);
    box-shadow: 3px 3px 8px rgba(0, 0, 0, 0.2);
}

.control-btn:active {
    transform: translateY(0);
    box-shadow: 1px 1px 3px rgba(0, 0, 0, 0.2);
}

/* Sentence construction area */
#sentence-area {
    background: rgba(255, 255, 255, 0.9);
    margin: 10px;
    padding: 15px;
    border-radius: 15px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
    flex-shrink: 0;
}

.sentence-template {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    justify-content: center;
    margin-bottom: 10px;
}

.sentence-slot {
    position: relative;
    min-width: 80px;
    height: 40px;
    border: 2px dashed #ccc;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(248, 249, 250, 0.8);
    transition: all 0.3s ease;
}

.sentence-slot.drag-over {
    border-color: #4CAF50;
    background: rgba(76, 175, 80, 0.1);
    transform: scale(1.05);
}

.sentence-slot.filled {
    border-color: #2196F3;
    background: rgba(33, 150, 243, 0.1);
}

.placeholder {
    color: #999;
    font-size: 12px;
    pointer-events: none;
}

.drop-zone {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: bold;
    color: #333;
}

#constructed-sentence {
    text-align: center;
    font-size: 16px;
    font-weight: bold;
    color: #2c3e50;
    min-height: 25px;
    padding: 5px;
    background: rgba(255, 255, 255, 0.7);
    border-radius: 8px;
    margin-top: 10px;
}

/* Elements container */
#elements-container {
    flex: 1;
    overflow-y: auto;
    padding: 10px;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 15px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 15px;
    margin: 0 10px 10px 10px;
}

.category-section {
    background: rgba(255, 255, 255, 0.9);
    border-radius: 12px;
    padding: 12px;
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.1);
}

.category-title {
    text-align: center;
    font-size: 16px;
    font-weight: bold;
    margin-bottom: 10px;
    color: #2c3e50;
    border-bottom: 2px solid #ecf0f1;
    padding-bottom: 5px;
}

/* Draggable items with color coding */
.draggable-item {
    background: linear-gradient(145deg, #f8f9fa, #e9ecef);
    border: 2px solid transparent;
    border-radius: 8px;
    padding: 8px 12px;
    margin: 5px 0;
    cursor: grab;
    transition: all 0.3s ease;
    font-size: 14px;
    font-weight: 500;
    text-align: center;
    box-shadow: 2px 2px 5px rgba(0, 0, 0, 0.1);
    min-height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.draggable-item:hover {
    transform: translateY(-2px);
    box-shadow: 3px 3px 10px rgba(0, 0, 0, 0.2);
}

.draggable-item:active {
    cursor: grabbing;
    transform: scale(0.95);
}

/* Color coding for different categories */
.time-item {
    background: linear-gradient(145deg, #fff3e0, #ffcc02);
    border-color: #ff9800;
}

.who-item {
    background: linear-gradient(145deg, #e8f5e8, #4caf50);
    border-color: #2e7d32;
}

.where-item {
    background: linear-gradient(145deg, #e3f2fd, #2196f3);
    border-color: #1565c0;
}

.how-item {
    background: linear-gradient(145deg, #fce4ec, #e91e63);
    border-color: #c2185b;
}

.what-item {
    background: linear-gradient(145deg, #f3e5f5, #9c27b0);
    border-color: #7b1fa2;
}

/* Example overlay */
#example-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.example-content {
    background: white;
    padding: 20px;
    border-radius: 15px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
    max-width: 400px;
    text-align: center;
    position: relative;
}

.close-btn {
    position: absolute;
    top: 10px;
    right: 15px;
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: #666;
}

.example-sentence {
    display: flex;
    gap: 8px;
    justify-content: center;
    margin: 15px 0;
    flex-wrap: wrap;
}

.example-sentence span {
    padding: 5px 10px;
    border-radius: 5px;
    font-size: 14px;
    font-weight: bold;
}

.example-time { background: #fff3e0; color: #ff9800; }
.example-who { background: #e8f5e8; color: #4caf50; }
.example-where { background: #e3f2fd; color: #2196f3; }
.example-how { background: #fce4ec; color: #e91e63; }
.example-what { background: #f3e5f5; color: #9c27b0; }

.example-text {
    font-size: 16px;
    font-weight: bold;
    color: #2c3e50;
    margin-top: 10px;
    padding: 10px;
    background: #f8f9fa;
    border-radius: 8px;
}

/* Tooltip styling */
.tooltip {
    position: absolute;
    background: rgba(0, 0, 0, 0.8);
    color: white;
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 12px;
    pointer-events: none;
    z-index: 1001;
    white-space: nowrap;
}

/* Utility classes */
.hidden {
    display: none !important;
}

.dragging {
    opacity: 0.5;
    transform: rotate(5deg);
}

/* Mobile responsiveness */
@media (max-width: 768px) {
    .sentence-template {
        gap: 5px;
    }
    
    .sentence-slot {
        min-width: 70px;
        height: 35px;
        font-size: 12px;
    }
    
    .draggable-item {
        font-size: 13px;
        padding: 6px 10px;
        min-height: 32px;
    }
    
    #elements-container {
        grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
        gap: 10px;
    }
    
    .control-btn {
        padding: 6px 10px;
        font-size: 12px;
        min-height: 32px;
    }
}

/* Touch device optimizations */
@media (hover: none) and (pointer: coarse) {
    .draggable-item {
        min-height: 44px; /* Minimum touch target size */
    }
    
    .control-btn {
        min-height: 44px;
        min-width: 44px;
    }
    
    .sentence-slot {
        min-height: 44px;
    }
}

/* Print styles */
@media print {
    #control-panel {
        display: none;
    }
    
    #main-container {
        height: auto;
    }
    
    body {
        background: white;
    }
}