/* ===== RESET AND BASE 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-x: hidden;
    touch-action: manipulation;
}

/* ===== MAIN CONTAINER ===== */
/* Adapts height based on whether in iframe or standalone */
#mainContainer {
    width: 100%;
    height: 450px; /* Default for iframe */
    max-width: 1200px;
    margin: 0 auto;
    background: #ffffff;
    position: relative;
    overflow-y: auto;
    overflow-x: hidden;
    box-shadow: 0 4px 20px rgba(0,0,0,0.2);
}

/* If opened in new tab, use 90vh */
@media (min-height: 600px) {
    body:not(.iframe-mode) #mainContainer {
        height: 90vh;
    }
}

/* ===== INFO ICON AND TOOLTIP ===== */
#infoIcon {
    position: absolute;
    top: 8px;
    right: 8px;
    font-size: 24px;
    cursor: pointer;
    z-index: 100;
    background: rgba(255,255,255,0.9);
    border-radius: 50%;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
    transition: transform 0.2s;
}

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

.tooltip {
    position: absolute;
    top: 50px;
    right: 10px;
    background: #fff;
    border: 2px solid #667eea;
    border-radius: 12px;
    padding: 16px;
    max-width: 320px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.2);
    z-index: 101;
    animation: fadeIn 0.3s;
}

.tooltip.hidden {
    display: none;
}

.tooltip h3 {
    color: #667eea;
    margin-bottom: 8px;
    font-size: 18px;
}

.tooltip p {
    font-size: 14px;
    line-height: 1.5;
    margin-bottom: 6px;
    color: #333;
}

.close-btn {
    position: absolute;
    top: 8px;
    right: 8px;
    cursor: pointer;
    font-size: 20px;
    color: #999;
    background: none;
    border: none;
    padding: 4px 8px;
    min-width: 44px;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
}

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

/* ===== PROGRESS BAR ===== */
#progressBar {
    position: relative;
    width: calc(100% - 20px);
    height: 28px;
    background: #e0e0e0;
    border-radius: 14px;
    margin: 10px;
    overflow: hidden;
}

#progressFill {
    height: 100%;
    background: linear-gradient(90deg, #4CAF50, #8BC34A);
    width: 0%;
    transition: width 0.5s ease;
    border-radius: 14px;
}

#progressText {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-weight: bold;
    color: #333;
    font-size: 14px;
}

/* ===== MODE SELECTOR ===== */
#modeSelector {
    display: flex;
    justify-content: center;
    gap: 8px;
    padding: 8px 10px;
    flex-wrap: wrap;
}

.mode-btn {
    padding: 8px 16px;
    border: 2px solid #667eea;
    background: #fff;
    color: #667eea;
    border-radius: 20px;
    cursor: pointer;
    font-size: 14px;
    font-weight: bold;
    transition: all 0.3s;
    min-height: 44px;
    white-space: nowrap;
}

.mode-btn:hover {
    background: #f0f0ff;
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(102, 126, 234, 0.3);
}

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

/* ===== GAME AREA ===== */
#gameArea {
    padding: 10px;
    min-height: 200px;
}

.game-mode {
    display: none;
}

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

/* ===== VOCABULARY CARDS (LEARN MODE) ===== */
#vocabCards {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 10px;
    margin-bottom: 16px;
}

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

.vocab-card:hover {
    transform: translateY(-4px) scale(1.05);
    box-shadow: 0 8px 16px rgba(0,0,0,0.2);
}

.vocab-card.flipped {
    background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
}

.vocab-word {
    font-size: 22px;
    font-weight: bold;
    margin-bottom: 8px;
}

.vocab-meaning {
    font-size: 14px;
    line-height: 1.4;
}

/* ===== QUIZ MODE ===== */
#questionArea {
    background: #f9f9ff;
    padding: 16px;
    border-radius: 12px;
    margin-bottom: 16px;
    border: 2px solid #667eea;
}

#questionText {
    font-size: 18px;
    font-weight: bold;
    color: #333;
    margin-bottom: 8px;
}

#hintArea {
    font-size: 14px;
    color: #666;
    font-style: italic;
}

#answerArea {
    min-height: 120px;
    margin-bottom: 16px;
}

/* Multiple choice options */
.option-btn {
    display: block;
    width: 100%;
    padding: 12px 16px;
    margin-bottom: 10px;
    background: #fff;
    border: 2px solid #ddd;
    border-radius: 8px;
    cursor: pointer;
    font-size: 16px;
    text-align: left;
    transition: all 0.3s;
    min-height: 44px;
}

.option-btn:hover {
    background: #f0f0ff;
    border-color: #667eea;
    transform: translateX(4px);
}

.option-btn.selected {
    background: #667eea;
    color: white;
    border-color: #667eea;
}

.option-btn.correct {
    background: #4CAF50;
    color: white;
    border-color: #4CAF50;
}

.option-btn.incorrect {
    background: #f44336;
    color: white;
    border-color: #f44336;
}

.option-btn:disabled {
    cursor: not-allowed;
    opacity: 0.7;
}

/* Drag and drop zones */
#dropZone {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    padding: 16px;
    background: #f0f0f0;
    border: 2px dashed #999;
    border-radius: 8px;
    min-height: 80px;
    margin-bottom: 16px;
}

.drop-slot {
    flex: 1;
    min-width: 100px;
    min-height: 50px;
    background: white;
    border: 2px dashed #ccc;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    color: #999;
    transition: all 0.3s;
}

.drop-slot.drag-over {
    background: #e3f2fd;
    border-color: #2196F3;
}

.drop-slot.filled {
    border-style: solid;
    border-color: #667eea;
}

#dragOptions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    justify-content: center;
}

.drag-item {
    padding: 10px 16px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border-radius: 8px;
    cursor: move;
    font-size: 16px;
    font-weight: bold;
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
    transition: all 0.3s;
    user-select: none;
    touch-action: none;
    min-width: 80px;
    text-align: center;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.drag-item:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}

.drag-item.dragging {
    opacity: 0.5;
}

.drag-item.placed {
    opacity: 0.3;
    cursor: not-allowed;
}

/* ===== FEEDBACK AREA ===== */
#feedbackArea {
    padding: 12px;
    border-radius: 8px;
    margin-bottom: 12px;
    font-size: 16px;
    font-weight: bold;
    text-align: center;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
}

#feedbackArea.correct {
    background: #C8E6C9;
    color: #2E7D32;
    border: 2px solid #4CAF50;
}

#feedbackArea.incorrect {
    background: #FFCDD2;
    color: #C62828;
    border: 2px solid #f44336;
}

/* ===== BUTTONS ===== */
.action-btn {
    padding: 12px 24px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    border-radius: 24px;
    cursor: pointer;
    font-size: 16px;
    font-weight: bold;
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
    transition: all 0.3s;
    margin: 4px;
    min-height: 44px;
    white-space: nowrap;
}

.action-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(0,0,0,0.3);
}

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

.action-btn.secondary {
    background: linear-gradient(135deg, #90CAF9 0%, #64B5F6 100%);
}

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

#quizControls {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: 8px;
}

#startQuizBtn {
    display: block;
    margin: 16px auto;
}

/* ===== SCORE BOARD ===== */
#scoreBoard {
    display: flex;
    justify-content: space-around;
    padding: 10px;
    background: #f0f0ff;
    border-top: 2px solid #667eea;
    font-weight: bold;
    font-size: 14px;
}

#scoreText {
    color: #4CAF50;
}

#accuracyText {
    color: #2196F3;
}

/* ===== ANALYTICS PANEL ===== */
#analyticsToggle {
    position: fixed;
    bottom: 10px;
    right: 10px;
    padding: 10px 16px;
    background: #FF9800;
    color: white;
    border: none;
    border-radius: 20px;
    cursor: pointer;
    font-size: 14px;
    font-weight: bold;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
    z-index: 50;
    min-height: 44px;
    transition: all 0.3s;
}

#analyticsToggle:hover {
    background: #F57C00;
    transform: scale(1.05);
}

#analyticsPanel {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: white;
    border-top: 3px solid #FF9800;
    box-shadow: 0 -4px 20px rgba(0,0,0,0.3);
    max-height: 60vh;
    overflow-y: auto;
    transition: transform 0.4s ease;
    z-index: 49;
    padding: 16px;
}

#analyticsPanel.collapsed {
    transform: translateY(100%);
}

.analytics-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
    flex-wrap: wrap;
    gap: 8px;
}

.analytics-header h3 {
    color: #FF9800;
    font-size: 18px;
}

.small-btn {
    padding: 6px 12px;
    background: #f44336;
    color: white;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    font-size: 12px;
    min-height: 36px;
}

.small-btn:hover {
    background: #d32f2f;
}

#analyticsContent {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

@media (max-width: 768px) {
    #analyticsContent {
        grid-template-columns: 1fr;
    }
}

#actionLog, #quizLog {
    background: #f9f9f9;
    padding: 12px;
    border-radius: 8px;
    border: 1px solid #ddd;
}

#actionLog h4, #quizLog h4 {
    color: #667eea;
    margin-bottom: 8px;
    font-size: 16px;
}

#actionLogContent, #quizLogContent {
    max-height: 200px;
    overflow-y: auto;
    font-size: 13px;
    line-height: 1.6;
}

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

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

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

.log-timestamp {
    color: #999;
    font-size: 11px;
}

/* ===== ANIMATIONS ===== */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes bounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-10px); }
}

/* ===== MOBILE RESPONSIVE ===== */
@media (max-width: 600px) {
    #vocabCards {
        grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
        gap: 8px;
    }
    
    .vocab-card {
        padding: 10px;
        min-height: 90px;
    }
    
    .vocab-word {
        font-size: 20px;
    }
    
    .vocab-meaning {
        font-size: 13px;
    }
    
    #questionText {
        font-size: 16px;
    }
    
    .option-btn {
        font-size: 14px;
        padding: 10px 12px;
    }
    
    .drag-item {
        font-size: 14px;
        padding: 8px 12px;
        min-width: 70px;
    }
    
    #modeSelector {
        gap: 6px;
    }
    
    .mode-btn {
        font-size: 13px;
        padding: 8px 12px;
    }
}

/* ===== ACCESSIBILITY ===== */
button:focus, .option-btn:focus, .drag-item:focus {
    outline: 3px solid #FF9800;
    outline-offset: 2px;
}

/* High contrast for better readability */
@media (prefers-contrast: high) {
    .vocab-card {
        border: 2px solid white;
    }
    
    .option-btn {
        border-width: 3px;
    }
}