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

body {
    font-family: 'Segoe UI', 'Microsoft YaHei', 'SimHei', sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    width: 100%;
    height: 100vh;
    overflow: hidden;
    touch-action: manipulation;
}

/* ===================================
   MAIN CONTAINER
   =================================== */
#mainContainer {
    width: 100%;
    height: 450px; /* Default iframe height */
    display: flex;
    flex-direction: column;
    background: white;
    overflow: hidden;
}

/* Adjust height when opened in new tab */
@media (min-height: 500px) {
    body.fullscreen #mainContainer {
        height: 90vh;
    }
}

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

.tooltip.hidden {
    display: none;
}

/* ===================================
   MAIN PANEL
   =================================== */
#mainPanel {
    flex: 1;
    overflow-y: auto;
    padding: 15px;
    background: linear-gradient(to bottom, #f8f9fa, #e9ecef);
}

/* ===================================
   CONTROLS SECTION
   =================================== */
#controlsSection {
    background: white;
    padding: 12px;
    border-radius: 10px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    margin-bottom: 15px;
}

.control-row {
    display: flex;
    align-items: center;
    margin-bottom: 10px;
    gap: 10px;
}

.control-row label {
    font-weight: 600;
    font-size: 14px;
    min-width: 80px;
    display: flex;
    align-items: center;
    gap: 5px;
}

.control-row input[type="range"] {
    flex: 1;
    height: 8px;
    border-radius: 5px;
    background: #ddd;
    outline: none;
    -webkit-appearance: none;
}

.control-row input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #667eea;
    cursor: pointer;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.control-row input[type="range"]::-moz-range-thumb {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #667eea;
    cursor: pointer;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.control-row span {
    font-weight: 600;
    color: #667eea;
    min-width: 50px;
    text-align: right;
}

.checkbox-row {
    display: flex;
    gap: 20px;
    flex-wrap: wrap;
}

.checkbox-row label {
    display: flex;
    align-items: center;
    gap: 5px;
    cursor: pointer;
    min-width: auto;
}

.checkbox-row input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
}

.button-row {
    display: flex;
    gap: 10px;
    margin-top: 12px;
    flex-wrap: wrap;
}

button {
    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;
    touch-action: manipulation;
}

.primary-btn {
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: white;
    box-shadow: 0 4px 8px rgba(102, 126, 234, 0.3);
}

.primary-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 12px rgba(102, 126, 234, 0.4);
}

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

.secondary-btn {
    background: white;
    color: #667eea;
    border: 2px solid #667eea;
}

.secondary-btn:hover {
    background: #f0f0f0;
}

.small-btn {
    padding: 5px 10px;
    font-size: 12px;
    min-height: 32px;
}

/* ===================================
   WORD CARDS CONTAINER
   =================================== */
#wordCardsContainer {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 12px;
    margin-bottom: 15px;
}

.word-card {
    background: white;
    border-radius: 10px;
    padding: 15px;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
    min-height: 120px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    position: relative;
    touch-action: manipulation;
}

.word-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 6px 12px rgba(0, 0, 0, 0.15);
}

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

.word-card.playing {
    animation: pulse 0.6s ease-in-out;
    box-shadow: 0 0 20px rgba(102, 126, 234, 0.6);
}

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

.word-card .hanzi {
    font-size: 48px;
    font-weight: bold;
    margin-bottom: 8px;
    line-height: 1;
}

.word-card .pinyin {
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 5px;
}

.word-card .meaning {
    font-size: 12px;
    color: #666;
    font-style: italic;
}

/* Tone Colors (Singapore Chinese curriculum standard) */
.tone1 { color: #e74c3c; } /* Red - First tone (flat) */
.tone2 { color: #f39c12; } /* Orange - Second tone (rising) */
.tone3 { color: #27ae60; } /* Green - Third tone (dipping) */
.tone4 { color: #3498db; } /* Blue - Fourth tone (falling) */
.tone5 { color: #95a5a6; } /* Gray - Neutral tone */

/* ===================================
   QUIZ SECTION
   =================================== */
#quizSection {
    background: white;
    border-radius: 10px;
    padding: 15px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    margin-bottom: 15px;
}

#quizHeader {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
    flex-wrap: wrap;
    gap: 10px;
}

#quizHeader h3 {
    font-size: 18px;
    color: #667eea;
}

#quizScore {
    font-weight: 600;
    color: #27ae60;
    font-size: 16px;
}

#quizContent {
    min-height: 100px;
}

#quizInstruction {
    text-align: center;
    color: #666;
    font-size: 14px;
    padding: 20px;
}

#quizQuestion {
    margin-top: 10px;
}

#questionText {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 15px;
    text-align: center;
    color: #333;
}

#quizOptions {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 10px;
    margin-bottom: 15px;
}

.quiz-option {
    padding: 15px;
    background: #f8f9fa;
    border: 2px solid #ddd;
    border-radius: 8px;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s ease;
    font-size: 24px;
    font-weight: bold;
    min-height: 60px;
    display: flex;
    align-items: center;
    justify-content: center;
    touch-action: manipulation;
}

.quiz-option:hover {
    background: #e9ecef;
    border-color: #667eea;
}

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

.quiz-option.correct {
    background: #27ae60;
    color: white;
    border-color: #27ae60;
    animation: correctAnswer 0.5s ease;
}

.quiz-option.incorrect {
    background: #e74c3c;
    color: white;
    border-color: #e74c3c;
    animation: shake 0.5s ease;
}

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

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

.quiz-option.disabled {
    pointer-events: none;
    opacity: 0.6;
}

/* ===================================
   ANALYTICS PANEL
   =================================== */
#analyticsPanel {
    background: #2c3e50;
    color: white;
    max-height: 200px;
    overflow: hidden;
    transition: max-height 0.3s ease;
}

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

#analyticsHeader {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 15px;
    background: #34495e;
    cursor: pointer;
    user-select: none;
}

#analyticsHeader h3 {
    font-size: 14px;
    margin: 0;
}

#toggleAnalytics {
    background: transparent;
    color: white;
    border: none;
    font-size: 16px;
    padding: 5px;
    cursor: pointer;
    min-height: auto;
}

#analyticsContent {
    padding: 10px 15px;
    overflow-y: auto;
    max-height: 160px;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 15px;
}

#actionLog, #quizAnalytics {
    background: rgba(255, 255, 255, 0.1);
    padding: 10px;
    border-radius: 5px;
}

#actionLog h4, #quizAnalytics h4 {
    font-size: 12px;
    margin-bottom: 8px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

#logEntries, #quizLogEntries {
    font-size: 11px;
    line-height: 1.6;
    max-height: 100px;
    overflow-y: auto;
}

.log-entry {
    margin-bottom: 5px;
    padding: 5px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 3px;
    border-left: 3px solid #3498db;
}

.log-entry.quiz-correct {
    border-left-color: #27ae60;
}

.log-entry.quiz-incorrect {
    border-left-color: #e74c3c;
}

.log-timestamp {
    color: #95a5a6;
    font-size: 10px;
}

/* ===================================
   UTILITY CLASSES
   =================================== */
.hidden {
    display: none !important;
}

.icon {
    font-size: 16px;
}

/* ===================================
   RESPONSIVE DESIGN (Mobile)
   =================================== */
@media (max-width: 768px) {
    #mainPanel {
        padding: 10px;
    }

    #controlsSection {
        padding: 10px;
    }

    .control-row label {
        min-width: 70px;
        font-size: 13px;
    }

    #wordCardsContainer {
        grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
        gap: 8px;
    }

    .word-card {
        padding: 10px;
        min-height: 100px;
    }

    .word-card .hanzi {
        font-size: 36px;
    }

    .word-card .pinyin {
        font-size: 14px;
    }

    .word-card .meaning {
        font-size: 10px;
    }

    #quizOptions {
        grid-template-columns: repeat(auto-fit, minmax(80px, 1fr));
    }

    .quiz-option {
        font-size: 20px;
        min-height: 50px;
        padding: 10px;
    }

    #analyticsContent {
        grid-template-columns: 1fr;
    }

    button {
        font-size: 13px;
        padding: 8px 15px;
    }
}

/* ===================================
   SCROLLBAR STYLING
   =================================== */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 10px;
}

::-webkit-scrollbar-thumb {
    background: #888;
    border-radius: 10px;
}

::-webkit-scrollbar-thumb:hover {
    background: #555;
}