/* ===== GLOBAL STYLES ===== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

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

/* Main Container - Responsive Height */
#mainContainer {
    width: 100%;
    height: 450px; /* Default for iframe */
    display: flex;
    flex-direction: column;
    background: white;
    position: relative;
    overflow: hidden;
}

/* If opened in new tab, use 90vh */
body.fullscreen #mainContainer {
    height: 90vh;
}

/* ===== INFO ICON ===== */
#infoIcon {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 28px;
    height: 28px;
    background: #4CAF50;
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 18px;
    z-index: 1000;
    box-shadow: 0 2px 6px rgba(0,0,0,0.2);
    transition: transform 0.2s;
}

#infoIcon:hover {
    transform: scale(1.1);
}

/* ===== TOOLTIP ===== */
.tooltip {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: white;
    border: 2px solid #4CAF50;
    border-radius: 12px;
    padding: 20px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.3);
    z-index: 2000;
    max-width: 90%;
    text-align: center;
}

.tooltip.hidden {
    display: none;
}

.tooltip h3 {
    color: #4CAF50;
    margin-bottom: 10px;
}

.tooltip p {
    margin: 8px 0;
    line-height: 1.6;
}

.close-tooltip {
    position: absolute;
    top: 8px;
    right: 12px;
    font-size: 24px;
    cursor: pointer;
    color: #999;
}

.close-tooltip:hover {
    color: #333;
}

/* ===== CONTROL PANEL ===== */
#controlPanel {
    background: #f5f5f5;
    padding: 10px;
    border-bottom: 2px solid #ddd;
    display: flex;
    flex-wrap: wrap;
    gap: 15px;
    align-items: center;
}

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

.control-group label {
    font-size: 14px;
    font-weight: 500;
    white-space: nowrap;
}

/* Mode Buttons */
.mode-btn {
    padding: 6px 12px;
    border: 2px solid #667eea;
    background: white;
    color: #667eea;
    border-radius: 20px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    transition: all 0.3s;
    white-space: nowrap;
}

.mode-btn:hover {
    background: #f0f0ff;
}

.mode-btn.active {
    background: #667eea;
    color: white;
}

/* Audio Controls */
.audio-controls input[type="range"] {
    width: 80px;
}

.audio-controls span {
    font-size: 13px;
    min-width: 35px;
    font-weight: 500;
}

/* ===== CONTENT AREA ===== */
#contentArea {
    flex: 1;
    overflow-y: auto;
    padding: 15px;
    position: relative;
}

.mode-content {
    display: none;
}

.mode-content.active {
    display: block;
}

/* ===== LEARN MODE: VOCABULARY GRID ===== */
#vocabGrid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 15px;
}

.vocab-card {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border-radius: 12px;
    padding: 15px;
    cursor: pointer;
    transition: all 0.3s;
    box-shadow: 0 4px 8px rgba(0,0,0,0.2);
    position: relative;
    min-height: 120px;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.vocab-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 8px 16px rgba(0,0,0,0.3);
}

.vocab-card:active {
    transform: scale(0.98);
}

.vocab-word {
    font-size: 28px;
    font-weight: bold;
    margin-bottom: 8px;
    text-align: center;
}

.vocab-pinyin {
    font-size: 14px;
    text-align: center;
    margin-bottom: 8px;
    opacity: 0.9;
}

.vocab-pinyin.hidden {
    display: none;
}

.vocab-meaning {
    font-size: 15px;
    text-align: center;
    opacity: 0.95;
    line-height: 1.4;
}

.vocab-number {
    position: absolute;
    top: 8px;
    left: 8px;
    background: rgba(255,255,255,0.3);
    width: 24px;
    height: 24px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: bold;
}

/* Tone Colors for Pinyin */
.tone1 { color: #ff4444; } /* Red - 1st tone */
.tone2 { color: #ffaa00; } /* Orange - 2nd tone */
.tone3 { color: #00cc00; } /* Green - 3rd tone */
.tone4 { color: #0088ff; } /* Blue - 4th tone */
.tone5 { color: #888888; } /* Gray - neutral tone */

/* ===== PRACTICE MODE: DRAG & MATCH ===== */
.practice-instruction {
    text-align: center;
    font-size: 16px;
    color: #667eea;
    font-weight: 500;
    margin-bottom: 15px;
    padding: 10px;
    background: #f0f0ff;
    border-radius: 8px;
}

/* MODIFIED: Changed practice area to use fixed heights and scrolling */
#practiceArea {
    display: flex;
    gap: 20px;
    margin-bottom: 15px;
    /* Removed min-height, added max-height for better control */
    max-height: 400px;
}

.column {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 10px;
    /* ADDED: Enable scrolling for both columns independently */
    overflow-y: auto;
    padding-right: 5px;
}

.word-slot {
    background: #f9f9f9;
    border: 2px dashed #ccc;
    border-radius: 10px;
    padding: 15px;
    min-height: 70px;
    /* ADDED: Prevent shrinking */
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    transition: all 0.3s;
}

.word-slot .word-label {
    font-size: 22px;
    font-weight: bold;
    color: #333;
}

.word-slot.has-card {
    border-style: solid;
    border-color: #667eea;
    background: #f0f0ff;
}

.word-slot.correct {
    border-color: #4CAF50;
    background: #e8f5e9;
}

.word-slot.incorrect {
    border-color: #f44336;
    background: #ffebee;
}

/* MODIFIED: Meaning cards now maintain space when dragged */
.meaning-card {
    background: white;
    border: 2px solid #667eea;
    border-radius: 10px;
    padding: 12px;
    cursor: move;
    cursor: grab;
    transition: all 0.3s;
    box-shadow: 0 2px 6px rgba(0,0,0,0.15);
    font-size: 15px;
    text-align: center;
    min-height: 60px;
    /* ADDED: Prevent shrinking */
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    touch-action: none;
}

.meaning-card:hover {
    box-shadow: 0 4px 12px rgba(0,0,0,0.25);
    transform: scale(1.02);
}

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

.meaning-card.placed {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    cursor: move;
}

/* ADDED: Placeholder to maintain space when card is dragged */
.meaning-placeholder {
    background: transparent;
    border: 2px dashed #ccc;
    border-radius: 10px;
    padding: 12px;
    font-size: 15px;
    text-align: center;
    min-height: 60px;
    /* ADDED: Prevent shrinking */
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0.5;
    color: #999;
}

.practice-controls {
    display: flex;
    gap: 10px;
    justify-content: center;
}

.action-btn {
    padding: 10px 24px;
    background: #667eea;
    color: white;
    border: none;
    border-radius: 25px;
    font-size: 15px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s;
    box-shadow: 0 2px 6px rgba(0,0,0,0.2);
    white-space: nowrap;
}

.action-btn:hover {
    background: #5568d3;
    transform: translateY(-2px);
    box-shadow: 0 4px 10px rgba(0,0,0,0.3);
}

.action-btn:active {
    transform: scale(0.98);
}

.action-btn.hidden {
    display: none;
}

/* ===== QUIZ MODE ===== */
#quizProgress {
    text-align: center;
    font-size: 16px;
    font-weight: 500;
    color: #667eea;
    margin-bottom: 15px;
    padding: 8px;
    background: #f0f0ff;
    border-radius: 8px;
}

#quizQuestion {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 20px;
    border-radius: 12px;
    font-size: 20px;
    text-align: center;
    margin-bottom: 15px;
    box-shadow: 0 4px 10px rgba(0,0,0,0.2);
}

#quizOptions {
    display: grid;
    grid-template-columns: 1fr;
    gap: 10px;
    margin-bottom: 15px;
}

.quiz-option {
    background: white;
    border: 2px solid #ddd;
    border-radius: 10px;
    padding: 15px;
    cursor: pointer;
    transition: all 0.3s;
    font-size: 16px;
    text-align: center;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    min-height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.quiz-option:hover {
    border-color: #667eea;
    background: #f0f0ff;
    transform: scale(1.02);
}

.quiz-option.selected {
    border-color: #667eea;
    background: #e0e7ff;
}

.quiz-option.correct {
    border-color: #4CAF50;
    background: #e8f5e9;
}

.quiz-option.incorrect {
    border-color: #f44336;
    background: #ffebee;
}

.quiz-option.disabled {
    cursor: not-allowed;
    opacity: 0.6;
}

#quizFeedback {
    text-align: center;
    font-size: 18px;
    font-weight: 500;
    padding: 12px;
    border-radius: 8px;
    margin-bottom: 15px;
    min-height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
}

#quizFeedback.correct {
    background: #e8f5e9;
    color: #2e7d32;
}

#quizFeedback.incorrect {
    background: #ffebee;
    color: #c62828;
}

.quiz-controls {
    display: flex;
    gap: 10px;
    justify-content: center;
}

/* ===== ANALYTICS PANEL ===== */
#analyticsPanel {
    background: #f9f9f9;
    border-top: 2px solid #ddd;
    max-height: 150px;
    display: flex;
    flex-direction: column;
    transition: max-height 0.3s;
}

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

#analyticsHeader {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    background: #e0e0e0;
    cursor: pointer;
    font-weight: 500;
    font-size: 14px;
}

#toggleAnalytics {
    background: none;
    border: none;
    font-size: 16px;
    cursor: pointer;
    transition: transform 0.3s;
}

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

#clearAnalytics {
    background: none;
    border: none;
    font-size: 18px;
    cursor: pointer;
    padding: 4px;
}

#clearAnalytics:hover {
    transform: scale(1.2);
}

#analyticsContent {
    flex: 1;
    overflow-y: auto;
    padding: 10px;
}

#actionLog {
    font-size: 12px;
    line-height: 1.6;
}

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

.log-entry.quiz-correct {
    border-left-color: #4CAF50;
    background: #f1f8f4;
}

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

.log-time {
    color: #999;
    font-size: 11px;
    margin-right: 8px;
}

.log-action {
    color: #333;
}

/* ===== RESPONSIVE DESIGN ===== */
@media (max-width: 600px) {
    #controlPanel {
        flex-direction: column;
        align-items: stretch;
    }
    
    .control-group {
        flex-wrap: wrap;
    }
    
    #vocabGrid {
        grid-template-columns: 1fr;
    }
    
    #practiceArea {
        flex-direction: column;
    }
    
    .mode-btn {
        flex: 1;
    }
}

/* ===== TOUCH TARGETS (minimum 44px) ===== */
.vocab-card,
.meaning-card,
.quiz-option,
.action-btn,
.mode-btn {
    min-height: 44px;
    min-width: 44px;
}

/* ===== SCROLLBAR STYLING ===== */
#contentArea::-webkit-scrollbar,
#analyticsContent::-webkit-scrollbar,
.column::-webkit-scrollbar {
    width: 8px;
}

#contentArea::-webkit-scrollbar-track,
#analyticsContent::-webkit-scrollbar-track,
.column::-webkit-scrollbar-track {
    background: #f1f1f1;
}

#contentArea::-webkit-scrollbar-thumb,
#analyticsContent::-webkit-scrollbar-thumb,
.column::-webkit-scrollbar-thumb {
    background: #888;
    border-radius: 4px;
}

#contentArea::-webkit-scrollbar-thumb:hover,
#analyticsContent::-webkit-scrollbar-thumb:hover,
.column::-webkit-scrollbar-thumb:hover {
    background: #555;
}