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

body {
    font-family: 'Arial', sans-serif;
    line-height: 1.6;
    color: #333;
    max-width: 1000px;
    margin: 0 auto;
    padding: 20px;
    background-color: #f9f9f9;
}

/* === HEADER STYLES === */
header {
    text-align: center;
    margin-bottom: 30px;
    padding: 30px 20px;
    position: relative;
    border-bottom: 2px solid #e74c3c;
    min-height: 150px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    background: linear-gradient(to bottom, #f9f9f9, #e9e9e9);
    border-radius: 8px;
}

h1 {
    color: #e74c3c;
    font-size: 2.2em;
    margin-bottom: 10px;
    text-shadow: 1px 1px 3px rgba(0, 0, 0, 0.3);
}

.language-toggle {
    position: absolute;
    top: 20px;
    right: 20px;
}

.lang-btn {
    padding: 8px 16px;
    background-color: #3498db;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    transition: background-color 0.3s;
}

.lang-btn:hover {
    background-color: #2980b9;
}

.lang-btn.active {
    background-color: #e74c3c;
}

header p {
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.3);
    font-weight: bold;
}

h2 {
    color: #2c3e50;
    font-size: 1.5em;
    margin-top: 30px;
    margin-bottom: 15px;
}

/* === CONTAINER STYLES === */
.container {
    background-color: white;
    padding: 25px;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    margin-bottom: 20px;
}

.input-group {
    display: flex;
    flex-wrap: wrap;
    gap: 15px;
    margin-bottom: 20px;
    align-items: center;
}

label {
    font-weight: bold;
    margin-right: 10px;
    min-width: 80px;
}

select, button, input {
    padding: 10px 15px;
    border-radius: 4px;
    border: 1px solid #ddd;
    font-size: 16px;
}

select {
    flex: 1;
    min-width: 100px;
    background-color: white;
}

button {
    background-color: #e74c3c;
    color: white;
    border: none;
    cursor: pointer;
    transition: background-color 0.3s;
}

button:hover {
    background-color: #c0392b;
}

button:disabled {
    background-color: #95a5a6;
    cursor: not-allowed;
}

/* === RESULTS AREA === */
#results {
    margin-top: 30px;
    min-height: 100px;
}

.word-pair {
    background-color: #f0f0f0;
    padding: 15px;
    margin-bottom: 15px;
    border-radius: 5px;
    border-left: 4px solid #e74c3c;
}

.word-pair h3 {
    margin-top: 0;
    color: #2c3e50;
}

.pinyin {
    color: #7f8c8d;
    font-style: italic;
}

.meaning {
    margin-top: 5px;
}

.no-results {
    text-align: center;
    padding: 20px;
    color: #7f8c8d;
    font-style: italic;
}

/* === FOOTER === */
footer {
    text-align: center;
    margin-top: 40px;
    padding-top: 20px;
    border-top: 1px solid #ddd;
    color: #7f8c8d;
    font-size: 0.9em;
}

footer a {
    color: #e74c3c;
    text-decoration: none;
}

footer a:hover {
    text-decoration: underline;
}

/* === CUBE DISPLAY STYLES === */
.cube-display {
    display: flex;
    flex-wrap: wrap;
    gap: 20px;
    margin-bottom: 30px;
}

.cube-info {
    flex: 1;
    min-width: 300px;
}

.cube-info h3 {
    color: #e74c3c;
    border-bottom: 2px solid #e74c3c;
    padding-bottom: 5px;
    margin-bottom: 10px;
}

table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 10px;
}

th, td {
    padding: 8px;
    text-align: left;
    border-bottom: 1px solid #ddd;
}

th {
    background-color: #f2f2f2;
}

tr:hover {
    background-color: #f5f5f5;
}

/* === SECTION STYLES === */
.vocab-selector, .search-section {
    margin-bottom: 30px;
    padding: 20px;
    background-color: #f0f0f0;
    border-radius: 8px;
}

.game-selector {
    margin: 30px 0;
    padding: 20px;
    background-color: #f0f0f0;
    border-radius: 8px;
    text-align: center;
}

.game-buttons {
    display: flex;
    justify-content: center;
    gap: 15px;
    flex-wrap: wrap;
}

.game-btn {
    padding: 15px 25px;
    background-color: #3498db;
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 16px;
    cursor: pointer;
    transition: all 0.3s;
}

.game-btn:hover {
    background-color: #2980b9;
    transform: translateY(-2px);
}

.game-btn.active {
    background-color: #e74c3c;
}

.game-container {
    margin: 30px 0;
    padding: 25px;
    background-color: white;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

/* === CHARACTER LEARNING GAME STYLES === */
.character-game {
    justify-content: center;
    align-items: center;
    text-align: center;
}

.cube-info-title {
    margin-bottom: 20px;
    font-size: 18px;
    font-weight: bold;
    color: #e74c3c;
}

.character-grid {
    display: grid;
    grid-template-columns: 100px 100px;
    gap: 10px;
    margin: 20px auto;
    justify-content: center;
}

.character-cell {
    width: 100px;
    height: 100px;
    border: 2px solid #ddd;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    cursor: pointer;
    background-color: #f9f9f9;
    transition: all 0.3s;
    position: relative;
}

.character-cell.empty {
    background-color: #fff;
    border: 2px dashed #ccc;
}

.character-cell.empty:hover {
    background-color: #f0f0f0;
}

.character-cell.pinyin {
    background-color: #e8f4f8;
    font-weight: bold;
    cursor: pointer;
    position: relative;
}

.character-cell.pinyin:hover {
    background-color: #d4eaf4;
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}

.character-cell.pinyin.playing {
    background-color: #fff3cd;
    border-color: #ffc107;
    animation: pulse 1.5s infinite;
}

.character-cell.pinyin.copied {
    background-color: #d4edda;
    border-color: #28a745;
}

.character-cell.pinyin.copied::after {
    content: "✓ Copied!";
    position: absolute;
    top: -25px;
    left: 50%;
    transform: translateX(-50%);
    background-color: #28a745;
    color: white;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 12px;
    white-space: nowrap;
}

.character-cell.completed {
    background-color: #e8f4f8 !important;
    border: 2px solid #27ae60 !important;
}

/* Sound icon in pinyin cells */
.sound-icon {
    position: absolute;
    bottom: 5px;
    right: 5px;
    font-size: 12px;
    color: #3498db;
    opacity: 0.7;
    cursor: pointer;
}

.character-cell.pinyin:hover .sound-icon {
    opacity: 1;
}

.character-cell.pinyin.playing .sound-icon {
    color: #e74c3c;
    opacity: 1;
}

@keyframes pulse {
    0% { box-shadow: 0 0 0 0 rgba(255, 193, 7, 0.4); }
    70% { box-shadow: 0 0 0 10px rgba(255, 193, 7, 0); }
    100% { box-shadow: 0 0 0 0 rgba(255, 193, 7, 0); }
}

/* === TRADITIONAL 米字格 (Mi Zi Ge) RICE PAPER GRID === */
.drawing-area {
    display: flex;
    justify-content: center;
    align-items: center;
    margin: 20px 0;
    width: 100%;
}

.hanzi-writer-container {
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    width: 300px;
    height: 300px;
    margin: 0 auto;
    border: 1px solid #ddd;
    border-radius: 8px;
    background-color: #fff;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    touch-action: none;
    overflow: hidden;
}

#character-target, 
#listen-character-target, 
#compound-character-target {
    width: 100% !important;
    height: 100% !important;
    position: relative;
    background-color: white;
}

/* The Mi Zi Ge grid SVG */
.mizige-grid {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 5;
}

/* Make Hanzi Writer SVG transparent */
#character-target svg,
#listen-character-target svg,
#compound-character-target svg {
    position: absolute;
    top: 0;
    left: 0;
    background: transparent !important;
    z-index: 10;
    pointer-events: auto;
}

/* Remove any white background from Hanzi Writer */
#character-target svg rect,
#listen-character-target svg rect,
#compound-character-target svg rect {
    fill: transparent !important;
}

/* Remove any white background rectangles Hanzi Writer adds */
#character-target svg rect,
#listen-character-target svg rect,
#compound-character-target svg rect {
    fill: transparent !important;
}

.accuracy-display {
    margin: 10px 0;
    padding: 10px;
    background-color: #e8f4f8;
    border-radius: 5px;
    font-weight: bold;
}

.character-feedback {
    margin-top: 15px;
    padding: 20px;
    background-color: #f8f9fa;
    border-radius: 8px;
    text-align: center;
    border-left: 4px solid #3498db;
}

.correct-character {
    font-size: 48px;
    margin: 10px 0;
    color: #27ae60;
}

.character-details {
    margin: 15px 0;
    padding: 15px;
    background-color: #fff;
    border-radius: 5px;
    text-align: left;
}

.detail-link {
    display: inline-block;
    margin-top: 10px;
    padding: 8px 15px;
    background-color: #3498db;
    color: white;
    text-decoration: none;
    border-radius: 4px;
    transition: background-color 0.3s;
}

.detail-link:hover {
    background-color: #2980b9;
    text-decoration: none;
}

.progress-bar {
    width: 100%;
    height: 20px;
    background-color: #f0f0f0;
    border-radius: 10px;
    margin: 10px 0;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background-color: #27ae60;
    transition: width 0.3s ease;
}

/* === LISTEN GAME SPECIFIC STYLES === */
.listen-game-controls {
    display: flex;
    flex-wrap: wrap;
    gap: 15px;
    margin: 20px 0;
    padding: 15px;
    background-color: #f8f9fa;
    border-radius: 8px;
    align-items: center;
}

.cube-checkbox-group {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    max-height: 200px;
    overflow-y: auto;
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: 4px;
    background-color: white;
}

.cube-checkbox {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 5px 10px;
    background-color: #f0f0f0;
    border-radius: 4px;
    cursor: pointer;
}

.cube-checkbox:hover {
    background-color: #e0e0e0;
}

.cube-checkbox input[type="checkbox"] {
    width: auto;
    margin-right: 5px;
}

.listen-game-header {
    margin: 20px 0;
    padding: 15px;
    background-color: #f8f9fa;
    border-radius: 8px;
    text-align: center;
}

.play-sound-button {
    font-size: 24px;
    padding: 15px 30px;
    background-color: #3498db;
    color: white;
    border: none;
    border-radius: 50px;
    cursor: pointer;
    margin: 20px 0;
    transition: all 0.3s;
}

.play-sound-button:hover {
    background-color: #2980b9;
    transform: scale(1.05);
}

.play-sound-button.playing {
    background-color: #e74c3c;
    animation: pulse 1.5s infinite;
}

.listen-progress {
    margin: 20px 0;
    font-size: 18px;
    color: #666;
}

.skip-button {
    padding: 10px 20px;
    background-color: #95a5a6;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    margin: 10px;
}

.skip-button:hover {
    background-color: #7f8c8d;
}

/* === SEARCH RESULTS STYLES === */
.search-results {
    margin-top: 20px;
    max-height: 400px;
    overflow-y: auto;
    border: 1px solid #ddd;
    border-radius: 5px;
    background-color: white;
}

.search-result-item {
    padding: 15px;
    border-bottom: 1px solid #eee;
}

.search-result-item:last-child {
    border-bottom: none;
}

.search-result-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.search-result-chars {
    font-size: 1.5em;
    font-weight: bold;
    color: #e74c3c;
}

.search-result-cube {
    background-color: #e74c3c;
    color: white;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 0.9em;
}

.search-highlight {
    background-color: #fff3cd;
    padding: 2px 4px;
    border-radius: 3px;
    font-weight: bold;
}

.search-results-header {
    padding: 15px;
    background-color: #f8f9fa;
    border-bottom: 1px solid #ddd;
}

.search-match-types {
    font-size: 0.9em;
    color: #6c757d;
    margin-top: 5px;
    font-style: italic;
}

/* Sound button in search results */
.sound-button {
    background: none;
    border: none;
    color: #3498db;
    cursor: pointer;
    font-size: 1.2em;
    margin-left: 10px;
    padding: 2px 8px;
    border-radius: 4px;
    transition: all 0.3s;
}

.sound-button:hover {
    background-color: #f0f0f0;
    color: #2980b9;
}

.sound-button.playing {
    color: #e74c3c;
    background-color: #fff3cd;
}

/* TTS settings */
.tts-settings {
    margin: 10px 0;
    padding: 10px;
    background-color: #f8f9fa;
    border-radius: 5px;
    font-size: 0.9em;
}

.tts-controls {
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
    margin-top: 5px;
}

.tts-controls select {
    flex: 1;
    min-width: 150px;
    padding: 5px 10px;
}

.tts-test {
    padding: 5px 10px;
    background-color: #3498db;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.9em;
}

.tts-test:hover {
    background-color: #2980b9;
}

.tts-status {
    margin-top: 5px;
    font-size: 0.85em;
    color: #6c757d;
}

.tts-error {
    color: #e74c3c;
}

/* Store button styling */
.store-section {
    margin: 30px 0 20px;
    padding: 15px;
    background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
    border-radius: 12px;
    text-align: center;
}

.store-btn {
    background: #27ae60;
    padding: 12px 28px;
    font-size: 16px;
    border-radius: 50px;
    margin-top: 10px;
}

.store-btn:hover {
    background: #219a52;
    transform: scale(1.02);
}

/* === RESPONSIVE STYLES === */
@media (max-width: 768px) {
    body {
        padding: 15px;
    }
    
    header {
        padding: 20px 15px;
        min-height: 120px;
    }
    
    .language-toggle {
        position: relative;
        top: 0;
        right: 0;
        margin-bottom: 15px;
    }
    
    h1 {
        font-size: 1.8em;
    }
    
    .container {
        padding: 20px;
    }
    
    .input-group {
        flex-direction: column;
        align-items: stretch;
    }
    
    label {
        margin-bottom: 5px;
        margin-right: 0;
    }
    
    select, input, button {
        width: 100%;
    }
    
    .game-buttons {
        flex-direction: column;
    }
    
    .game-btn {
        width: 100%;
    }
    
    .cube-info {
        min-width: 100%;
    }
    
    .character-grid {
        grid-template-columns: 80px 80px;
    }
    
    .character-cell {
        width: 80px;
        height: 80px;
    }
    
    .hanzi-writer-container {
        width: 250px;
        height: 250px;
    }
    
    .sound-icon {
        font-size: 10px;
        bottom: 3px;
        right: 3px;
    }
    
    .correct-character {
        font-size: 36px;
    }
    
    .play-sound-button {
        font-size: 20px;
        padding: 12px 24px;
    }
}

@media (max-width: 480px) {
    h1 {
        font-size: 1.6em;
    }
    
    h2 {
        font-size: 1.3em;
    }
    
    .character-grid {
        grid-template-columns: 70px 70px;
        gap: 8px;
    }
    
    .character-cell {
        width: 70px;
        height: 70px;
        font-size: 14px;
    }
    
    .hanzi-writer-container {
        width: 220px;
        height: 220px;
    }
    
    .sound-icon {
        font-size: 9px;
    }
    
    .correct-character {
        font-size: 32px;
    }
    
    .play-sound-button {
        font-size: 18px;
        padding: 10px 20px;
    }
}