/* Global Styles and 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-x: hidden;
    touch-action: pan-y;
}

/* Container - Responsive height based on context */
.container {
    width: 100%;
    height: 450px;
    background: white;
    position: relative;
    overflow-y: auto;
    overflow-x: hidden;
}

/* If opened in new tab, use 90vh */
@media (min-height: 600px) {
    body.standalone .container {
        height: 90vh;
    }
}

/* Header Tooltip - Shows on hover */
/* MODIFIED: Added display flex for layout with close button, and hidden class */
.header-tooltip {
    position: fixed;
    top: 10px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.85);
    color: white;
    padding: 8px 16px;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 600;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s;
    z-index: 1000;
    text-align: center;
    display: flex;
    align-items: center;
    gap: 12px;
}

.container:hover .header-tooltip {
    opacity: 1;
    pointer-events: auto; /* MODIFIED: Allow interaction when visible */
}

/* MODIFIED: Add hidden state for tooltip */
.header-tooltip.hidden {
    display: none !important;
}

/* NEW: Close button for tooltip */
.tooltip-close-btn {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    line-height: 1;
    transition: background 0.2s;
    flex-shrink: 0;
}

.tooltip-close-btn:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* Main Content Area */
.main-content {
    padding: 15px;
    max-width: 1200px;
    margin: 0 auto;
}

/* Drop Zones Container */
.drop-zones {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 15px;
    margin-bottom: 15px;
}

@media (max-width: 768px) {
    .drop-zones {
        grid-template-columns: 1fr;
    }
}

/* Individual Drop Zone */
.drop-zone {
    background: #f8f9fa;
    border: 3px dashed #cbd5e0;
    border-radius: 12px;
    padding: 12px;
    min-height: 140px;
    transition: all 0.3s ease;
}

.drop-zone.drag-over {
    background: #e6f7ff;
    border-color: #1890ff;
    box-shadow: 0 4px 12px rgba(24, 144, 255, 0.3);
    transform: scale(1.02);
}

/* NEW: Highlight drop zone when a word card is selected via click */
.drop-zone.click-target {
    background: #fff4e6;
    border-color: #f59e0b;
    box-shadow: 0 4px 12px rgba(245, 158, 11, 0.3);
    animation: pulse 1s infinite;
}

@keyframes pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.02); }
}

.zone-header {
    font-size: 18px;
    font-weight: 700;
    color: #2d3748;
    margin-bottom: 5px;
    text-align: center;
}

.zone-description {
    font-size: 12px;
    color: #718096;
    text-align: center;
    margin-bottom: 10px;
    font-style: italic;
}

.drop-area {
    min-height: 80px;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: flex-start;
    align-content: flex-start;
}

/* Word Bank */
.word-bank-container {
    background: #ffffff;
    border: 2px solid #e2e8f0;
    border-radius: 12px;
    padding: 12px;
    margin-bottom: 15px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.word-bank-header {
    font-size: 15px;
    font-weight: 600;
    color: #2d3748;
    margin-bottom: 10px;
    text-align: center;
}

.word-bank {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    justify-content: center;
    min-height: 60px;
}

/* Draggable Word Card */
.word-card {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 8px 12px;
    border-radius: 8px;
    cursor: move;
    user-select: none;
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    font-weight: 600;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
    transition: all 0.2s ease;
    min-height: 44px;
    min-width: 44px;
    touch-action: none;
    position: relative;
}

.word-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
}

.word-card.dragging {
    opacity: 0.5;
    cursor: grabbing;
}

/* NEW: Selected state for click interaction */
.word-card.selected {
    background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
    transform: scale(1.1);
    box-shadow: 0 6px 16px rgba(245, 158, 11, 0.5);
    animation: selectedBounce 0.3s ease;
}

@keyframes selectedBounce {
    0%, 100% { transform: scale(1.1); }
    50% { transform: scale(1.15); }
}

.word-card.correct {
    background: linear-gradient(135deg, #48bb78 0%, #38a169 100%);
    animation: correctPulse 0.5s ease;
}

.word-card.incorrect {
    background: linear-gradient(135deg, #f56565 0%, #e53e3e 100%);
    animation: shake 0.5s ease;
}

@keyframes correctPulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.1); }
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-5px); }
    75% { transform: translateX(5px); }
}

/* Word Card Image */
.word-image {
    width: 32px;
    height: 32px;
    object-fit: contain;
    background: white;
    border-radius: 4px;
    padding: 2px;
}

/* NEW: Educational tooltip for word cards in drop zones */
.word-tooltip {
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.9);
    color: white;
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 500;
    white-space: normal;
    max-width: 250px;
    text-align: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s;
    z-index: 1000;
    margin-bottom: 5px;
    line-height: 1.4;
}

.word-tooltip::after {
    content: '';
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    border: 5px solid transparent;
    border-top-color: rgba(0, 0, 0, 0.9);
}

.word-card:hover .word-tooltip {
    opacity: 1;
}

/* Controls */
.controls {
    display: flex;
    gap: 10px;
    justify-content: center;
    margin-bottom: 15px;
    flex-wrap: wrap;
}

.btn {
    padding: 10px 20px;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    min-height: 44px;
    white-space: nowrap;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
}

.btn-check {
    background: #48bb78;
    color: white;
}

.btn-check:hover {
    background: #38a169;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(72, 187, 120, 0.4);
}

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

.btn-reset:hover {
    background: #dd6b20;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(237, 137, 54, 0.4);
}

.btn-analytics {
    background: #4299e1;
    color: white;
}

.btn-analytics:hover {
    background: #3182ce;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(66, 153, 225, 0.4);
}

.btn-small {
    padding: 5px 10px;
    background: #718096;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
    min-height: 30px;
}

.btn-small:hover {
    background: #4a5568;
}

/* Feedback */
.feedback {
    text-align: center;
    padding: 12px;
    border-radius: 8px;
    font-weight: 600;
    font-size: 16px;
    margin-bottom: 15px;
    min-height: 20px;
}

.feedback.success {
    background: #c6f6d5;
    color: #22543d;
    border: 2px solid #48bb78;
}

.feedback.error {
    background: #fed7d7;
    color: #742a2a;
    border: 2px solid #f56565;
}

.feedback.info {
    background: #bee3f8;
    color: #2c5282;
    border: 2px solid #4299e1;
}

/* Analytics Panel */
.analytics-panel {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: white;
    border-top: 3px solid #4299e1;
    box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.15);
    max-height: 50%;
    transition: transform 0.3s ease;
    z-index: 100;
    overflow: hidden;
}

.analytics-panel.collapsed {
    transform: translateY(100%);
}

.analytics-header {
    background: #4299e1;
    color: white;
    padding: 10px 15px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: 600;
}

.analytics-header > div {
    display: flex;
    gap: 8px;
}

.analytics-content {
    padding: 15px;
    overflow-y: auto;
    max-height: calc(50vh - 50px);
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 15px;
}

@media (max-width: 768px) {
    .analytics-content {
        grid-template-columns: 1fr;
    }
}

.analytics-section h4 {
    color: #2d3748;
    margin-bottom: 8px;
    font-size: 14px;
}

.log-container {
    background: #f7fafc;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    padding: 10px;
    max-height: 200px;
    overflow-y: auto;
    font-size: 12px;
}

.log-entry {
    padding: 6px;
    margin-bottom: 6px;
    background: white;
    border-left: 3px solid #cbd5e0;
    border-radius: 4px;
}

.log-entry.action {
    border-left-color: #4299e1;
}

.log-entry.correct {
    border-left-color: #48bb78;
    background: #f0fff4;
}

.log-entry.incorrect {
    border-left-color: #f56565;
    background: #fff5f5;
}

.log-timestamp {
    color: #718096;
    font-size: 10px;
    font-weight: 600;
}

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

/* Mobile Optimizations */
@media (max-width: 480px) {
    .main-content {
        padding: 10px;
    }
    
    .word-card {
        font-size: 12px;
        padding: 6px 10px;
    }
    
    .word-image {
        width: 28px;
        height: 28px;
    }
    
    .zone-header {
        font-size: 16px;
    }
    
    .btn {
        padding: 8px 16px;
        font-size: 13px;
    }
    
    .word-tooltip {
        max-width: 200px;
        font-size: 11px;
    }
}