/* =========================================
1. GLOBAL STYLES
========================================= */
:root {
--primary-gradient: linear-gradient(135deg, #3a6ea5, #004e98);
--bg-gradient: linear-gradient(135deg, #f5f7fa 0%, #e4e8f0 100%);
--primary: #3a6ea5;
--secondary: #e67e22;
--dark: #2c3e50;
--fav-color: #e74c3c;
--chat-bg: #3498db;
}

* { -webkit-tap-highlight-color: transparent; box-sizing: border-box; }

body { 
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; 
background: var(--bg-gradient); 
display: flex; flex-direction: column; align-items: center; justify-content: flex-start;
min-height: 100vh; margin: 0; color: #333; 
overflow-x: hidden;
padding-top: 20px;
padding-bottom: 20px;
}

.container { 
background: white; 
padding: 0 2rem 2rem 2rem; 
border-radius: 15px; 
box-shadow: 0 10px 25px rgba(0,0,0,0.1); 
text-align: center; 
max-width: 90%; width: 600px; 
position: relative; 
min-height: 80vh; 
display: flex; flex-direction: column; justify-content: flex-start; 
overflow: visible; 
}

/* =========================================
2. MENU SCREEN
========================================= */
#menu-screen { 
display: flex; flex-direction: column; gap: 15px; align-items: center; width: 100%; 
height: 100%; flex: 1;
}

/* STICKY HEADER */
.menu-sticky-header {
position: sticky;
top: 0;
z-index: 100;
background: rgba(255, 255, 255, 0.85); 
backdrop-filter: blur(12px); 
-webkit-backdrop-filter: blur(12px);
width: 100%;
padding-top: 2rem;
padding-bottom: 15px;
border-radius: 15px 15px 0 0;
margin-bottom: 5px;
border-bottom: 1px solid rgba(0,0,0,0.05); 
}

.app-logo { font-size: 2.5rem; color: #3498db; margin-bottom: 5px; animation: floatLogo 3s ease-in-out infinite; }
@keyframes floatLogo { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-5px); } }

.app-title { font-size: 1.8rem; font-weight: 800; color: #2c3e50; margin: 0; }
.app-subtitle { color: #7f8c8d; font-size: 0.9rem; }

/* GRID LEVEL */
.level-cards-container { 
width: 100%; 
display: grid; 
grid-template-columns: 1fr 1fr; 
gap: 12px; 
padding: 5px;
}

.level-card {
background: white;
border-radius: 16px;
box-shadow: 0 4px 10px rgba(0,0,0,0.05);
border: 1px solid #f0f0f0;
display: flex; flex-direction: column; 
overflow: hidden;
transition: transform 0.2s;
position: relative;
}

.level-start-btn {
border: none; padding: 15px 10px; cursor: pointer; width: 100%;
display: flex; flex-direction: column; justify-content: center; align-items: center;
color: white; height: 100px; position: relative;
transition: all 0.2s;
}

/* Warna Level HSK 1-5 (Cerah & Ceria) */
.hsk-1-bg { background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%); }
.hsk-2-bg { background: linear-gradient(135deg, #43e97b 0%, #38f9d7 100%); }
.hsk-3-bg { background: linear-gradient(135deg, #fa709a 0%, #fee140 100%); }
.hsk-4-bg { background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); }
.hsk-5-bg { background: linear-gradient(135deg, #8e44ad 0%, #c0392b 100%); }
        /* Level Lanjutan — warna lebih dalam & elegan */
.hsk-6-bg { background: linear-gradient(135deg, #2c3e50 0%, #000000 100%); }       /* Hitam-Biru Tua (Profesional) */
.hsk-7-bg { background: linear-gradient(135deg, #2b7067 0%, #34527d 100%); }       /* Biru Navy (Lebih gelap dari HSK6) */
.hsk-8-bg { background: linear-gradient(135deg, #4a148c 0%, #7c0a02 100%); }       /* Ungu Gelap → Merah Bata (Kombinasi kuat) */
.hsk-9-bg { background: linear-gradient(135deg, #2c291d 0%, #1a1a1a 100%); }       /* Hitam Murni → Abu-abu Gelap (Puncak) */

        
.hsk-main-text { font-size: 1.3rem; font-weight: 800; margin-bottom: 4px; text-shadow: 0 1px 2px rgba(0,0,0,0.2); pointer-events: none; }
.word-count-sub { background: rgba(255,255,255,0.25); padding: 3px 8px; border-radius: 20px; font-size: 0.75rem; font-weight: 600; pointer-events: none; }

.level-start-btn:hover { transform: translateY(-2px); filter: brightness(1.05); }
.level-start-btn:active { transform: scale(0.98); filter: brightness(0.95); }

.level-list-btn {
background: #fff; color: #555; border: none; border-top: 1px solid #eee;
padding: 12px; font-size: 0.85rem; font-weight: 700; cursor: pointer;
display: flex; align-items: center; justify-content: center; gap: 5px;
z-index: 2; 
}
.level-list-btn:hover { background: #f9f9f9; color: var(--primary); }

/* ACTION BUTTONS */
.action-btn-group {
width: 100%;
display: flex;
flex-direction: row;
gap: 12px;
padding: 10px 5px;
box-sizing: border-box;
}

.review-fav-btn, .chat-tutor-btn {
flex: 1;
padding: 15px;
border: none;
border-radius: 16px;
font-weight: 700;
cursor: pointer;
transition: all 0.2s cubic-bezier(0.25, 0.8, 0.25, 1);
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
gap: 8px;
color: white;
box-shadow: 0 4px 10px rgba(0,0,0,0.05);
height: 90px;
font-size: 0.95rem;
}

.review-fav-btn { background: linear-gradient(135deg, #ff758c 0%, #ff7eb3 100%); }
.chat-tutor-btn { background: linear-gradient(135deg, #aad4eb 0%, #3498db 100%); }
.review-fav-btn:hover, .chat-tutor-btn:hover { transform: translateY(-3px); filter: brightness(1.05); }
.review-fav-btn i, .chat-tutor-btn i { font-size: 1.8rem; margin-bottom: 2px; }

.settings-btn {
position: absolute; top: 20px; right: 20px;
background: #f1f2f6; border: none; width: 40px; height: 40px;
border-radius: 50%; cursor: pointer; color: #555;
display: flex; align-items: center; justify-content: center;
transition: transform 0.2s; z-index: 110; 
}
.settings-btn:hover { transform: rotate(90deg); background: #e2e6ea; }

.app-footer {
margin-top: auto; padding-top: 15px; font-size: 0.85rem; color: #bdc3c7;
border-top: 1px solid #f5f7fa; width: 100%;
}
.app-footer a { color: var(--primary); text-decoration: none; font-weight: 600; }

/* =========================================
3. LEARNING SCREEN
========================================= */
#learning-screen { display: none; flex-direction: column; width: 100%; height: 100%; box-sizing: border-box; overflow-y: auto; position: relative; }

.learning-header-wrapper { 
position: sticky; top: 0; left: 0; width: 100%; z-index: 50; 
background: rgba(255, 255, 255, 0.9);
backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
}

.level-badge { width: 100%; padding: 15px 0; background: linear-gradient(135deg, rgba(58, 110, 165, 0.95), rgba(0, 78, 152, 0.95)); color: white; font-size: 1.2rem; font-weight: 800; text-align: center; box-shadow: 0 4px 15px rgba(0,0,0,0.1); }
.level-badge.fav-mode { background: linear-gradient(135deg, rgba(231, 76, 60, 0.9), rgba(192, 57, 43, 0.9)); }

.top-bar-controls { position: absolute; top: 50%; left: 0; width: 100%; transform: translateY(-50%); display: flex; justify-content: space-between; padding: 0 15px; box-sizing: border-box; z-index: 51; pointer-events: none; }
.top-right-group { display: flex; gap: 10px; pointer-events: auto; }
.back-btn, .audio-control, .fav-control { background: rgba(255, 255, 255, 0.2); border: 1px solid rgba(255, 255, 255, 0.3); color: white; width: 36px; height: 36px; border-radius: 50%; cursor: pointer; font-size: 1rem; display: flex; align-items: center; justify-content: center; transition: all 0.2s; pointer-events: auto; }
.back-btn:hover, .audio-control:hover, .fav-control:hover { background: rgba(255, 255, 255, 0.4); transform: scale(1.1); }
.fav-control.active { background: white; color: var(--fav-color); border-color: white; box-shadow: 0 0 10px rgba(255, 255, 255, 0.5); }

.learning-content-scroll { padding-top: 20px; padding-bottom: 20px; flex: 1; display: flex; flex-direction: column; }
.word-display-area { text-align: center; margin-bottom: 10px; }
.current-word-text { font-size: 3.5rem; font-weight: 400; color: #2c3e50; cursor: pointer; line-height: 1.2; margin-bottom: 0; transition: font-size 0.2s ease; }
.pinyin-text { font-size: 1.4rem; color: #e67e22; font-weight: 500; font-family: "Courier New", monospace; margin: 5px 0; }
.audio-status { font-size: 0.9rem; color: #3498db; font-weight: bold; min-height: 20px; display: flex; align-items: center; justify-content: center; gap: 5px; }

#character-stage { display: flex; justify-content: center; flex-wrap: wrap; gap: 10px; margin: 10px 0; min-height: 140px; align-items: center; }
.hanzi-box { border: 2px solid #eef2f7; border-radius: 12px; background: #fff; width: 120px; height: 120px; cursor: pointer; position: relative; overflow: hidden; }
.hanzi-box:hover { transform: scale(1.05); border-color: #3498db; }

.meaning-box { background-color: #f8f9fa; border-radius: 12px; padding: 15px; text-align: left; margin-bottom: 20px; border: 1px solid #eee; }
.meaning-item { margin: 6px 0; font-size: 0.95rem; }
.label { font-weight: bold; color: #fff; background: #95a5a6; font-size: 0.75rem; padding: 2px 6px; border-radius: 4px; margin-right: 8px; }
.progress { margin-top: 10px; font-size: 0.8rem; color: #bdc3c7; text-align: center; border-top: 1px solid #eee; padding-top: 8px; }

.controls { display: flex; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
.nav-btn, .ai-btn { border: none; padding: 12px; border-radius: 10px; font-weight: 600; cursor: pointer; transition: transform 0.2s; }
.nav-btn { background-color: #f1f2f6; color: #2c3e50; flex: 1; }
.nav-btn:hover { background-color: #e2e6ea; }
.ai-btn { background: var(--primary-gradient); color: white; flex: 1.5; box-shadow: 0 4px 10px rgba(58, 110, 165, 0.3); }
.ai-btn:hover { transform: translateY(-2px); }

/* =========================================
4. LIST SCREEN
========================================= */
.list-screen { display: none; flex-direction: column; width: 100%; height: 100%; position: absolute; top: 0; left: 0; background: white; z-index: 20; border-radius: 15px; overflow: hidden; }
.list-header-container { padding: 15px 20px; background: #fff; border-bottom: 1px solid #f0f0f0; display: flex; align-items: center; gap: 15px; z-index: 20; position: relative; box-shadow: 0 2px 5px rgba(0,0,0,0.02); }
.list-title { font-size: 1.4rem; font-weight: 800; color: var(--dark); margin: 0; flex-shrink: 0; }
.search-container { position: relative; flex-grow: 1; }
.search-input { width: 100%; padding: 10px 40px 10px 15px; border: 2px solid #e5e7eb; border-radius: 50px; font-size: 0.9rem; transition: 0.3s; box-sizing: border-box; background: #f8f9fa; }
.search-input:focus { outline: none; border-color: var(--primary); background: #fff; }
.search-btn { position: absolute; right: 8px; top: 50%; transform: translateY(-50%); width: 30px; height: 30px; border-radius: 50%; background: var(--primary-gradient); border: none; color: white; display: flex; align-items: center; justify-content: center; }
.list-close-btn { background: #f1f2f6; border: none; color: #7f8c8d; width: 40px; height: 40px; border-radius: 50%; cursor: pointer; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.list-close-btn:hover { background: #e74c3c; color: white; }
.list-table-container { flex: 1; overflow-y: auto; padding: 0 20px 20px; position: relative; -webkit-overflow-scrolling: touch; }
.list-table { width: 100%; border-collapse: separate; border-spacing: 0; margin-top: 0; }
.list-table th { text-align: left; padding: 15px 10px; color: var(--dark); font-weight: 700; font-size: 0.9rem; border-bottom: 2px solid #e2e8f0; background: #fff; position: sticky; top: 0; z-index: 10; white-space: nowrap; box-shadow: 0 2px 2px -1px rgba(0,0,0,0.05); }
.list-table td { padding: 12px 10px; border-bottom: 1px solid #f5f7fa; font-size: 0.95rem; cursor: pointer; }
.list-table tbody tr:hover { background: #f0f8ff; }
.list-hanzi { font-size: 1.3rem; font-weight: 700; color: var(--primary); }
.list-pinyin { color: var(--secondary); font-weight: 600; font-family: monospace; }

        /* API HELP BUTTON & TEXT */
        .api-help-text {
            font-size: 0.85rem;
            color: #7f8c8d;
            margin-top: 5px;
            margin-bottom: 10px;
        }

        .ai-help-btn {
            background: transparent;
            border: 1px solid #3a6ea5;
            color: #3a6ea5;
            border-radius: 999px;
            padding: 6px 12px;
            font-size: 0.8rem;
            font-weight: 600;
            cursor: pointer;
            display: inline-flex;
            align-items: center;
            gap: 6px;
            margin-top: 5px;
            box-shadow: 0 2px 4px rgba(58, 110, 165, 0.15);
            transition: all 0.25s ease;
        }

        .ai-help-btn i {
            font-size: 0.8rem;
        }

        .ai-help-btn:hover {
            background: #3a6ea5;
            color: #fff;
            transform: translateY(-2px);
            box-shadow: 0 4px 8px rgba(58, 110, 165, 0.25);
        }

/* =========================================
5. MODALS
========================================= */
.modal { display: none; position: fixed; z-index: 200; left: 0; top: 0; width: 100%; height: 100%; background-color: rgba(0,0,0,0.6); align-items: center; justify-content: center; backdrop-filter: blur(5px); }
.modal-content { background-color: #fefefe; margin: auto; padding: 30px; border-radius: 15px; width: 90%; max-width: 500px; text-align: center; position: relative; animation: slideIn 0.3s ease; max-height: 85vh; overflow-y: auto; display: flex; flex-direction: column; }
@keyframes slideIn { from { transform: translateY(20px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
.close-btn { color: #aaa; position: absolute; right: 20px; top: 15px; font-size: 28px; font-weight: bold; cursor: pointer; border: none; background: none; }

/* CHAT SPECIFIC */
.chat-modal-content { height: 90%; max-height: 700px; padding: 0; }
.chat-header { padding: 15px 20px; background: var(--chat-bg); color: white; border-radius: 15px 15px 0 0; display: flex; justify-content: space-between; align-items: center; font-size: 1.2rem; font-weight: 700; }
.chat-messages { flex: 1; padding: 20px; overflow-y: auto; display: flex; flex-direction: column; gap: 15px; background: #f8f9fa; -webkit-overflow-scrolling: touch; }
.chat-bubble { max-width: 80%; padding: 12px 16px; border-radius: 15px; font-size: 0.95rem; line-height: 1.5; text-align: left; }
.chat-bubble-user { align-self: flex-end; background: var(--primary); color: white; border-bottom-right-radius: 2px; }
.chat-bubble-ai { align-self: flex-start; background: white; color: #333; border: 1px solid #e0e0e0; border-bottom-left-radius: 2px; }
.chat-bubble-system { align-self: center; background: #ecf0f1; color: #7f8c8d; font-size: 0.8rem; border: none; text-align: center;}
.chat-input-area { padding: 15px; background: white; border-top: 1px solid #eee; display: flex; gap: 10px; }
.chat-input { flex: 1; padding: 12px 15px; border: 2px solid #e5e7eb; border-radius: 25px; outline: none; }
.send-btn { width: 45px; height: 45px; border-radius: 50%; background: var(--chat-bg); color: white; border: none; cursor: pointer; display: flex; align-items: center; justify-content: center; }

/* SETTINGS */
.api-config-section { width: 100%; margin-bottom: 20px; padding: 15px; background: #f8f9fa; border-radius: 10px; border: 1px dashed #bdc3c7; text-align: left; box-sizing: border-box; }
.api-input-group { display: flex; gap: 5px; margin-top: 5px; align-items: center;}
.api-input { flex: 1; padding: 8px; border: 1px solid #ddd; border-radius: 5px; width: 100%; box-sizing: border-box; }
.api-save-btn { background-color: #2ecc71; color: white; border: none; padding: 8px 15px; border-radius: 5px; cursor: pointer; margin-left: 5px;}
.clear-data-btn { width: 100%; padding: 10px; background: #fff; color: #e74c3c; border: 1px solid #e74c3c; border-radius: 8px; margin-top: 15px; cursor: pointer; font-weight: 600; }
.clear-data-btn:hover { background: #e74c3c; color: white; }
.api-status { font-size: 0.8rem; margin-top: 5px; color: #999; }
.api-status.saved { color: #27ae60; font-weight: bold; }

/* DATA MANAGER STYLES */
.data-status-item { display: flex; justify-content: space-between; align-items: center; padding: 8px 0; border-bottom: 1px solid #eee; font-size: 0.9rem; }
.status-badge { padding: 2px 8px; border-radius: 12px; font-size: 0.75rem; color: white; font-weight: bold; }
.status-ok { background-color: #2ecc71; }
.status-missing { background-color: #e74c3c; }
.file-upload-wrapper { position: relative; overflow: hidden; display: inline-block; cursor: pointer; color: #3a6ea5; font-weight: bold; margin-top: 5px; }
.file-upload-wrapper input[type=file] { font-size: 100px; position: absolute; left: 0; top: 0; opacity: 0; cursor: pointer; }

/* LOADER */
.loading-overlay { position: absolute; top:0; left:0; width:100%; height:100%; background: rgba(255,255,255,0.8); display: none; align-items: center; justify-content: center; z-index: 999; flex-direction: column; }
.spinner { border: 4px solid #f3f3f3; border-top: 4px solid var(--primary); border-radius: 50%; width: 40px; height: 40px; animation: spin 1s linear infinite; }
@keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }

/* AI EXPLAIN STYLES */
.ai-explanation { background: #fff3cd; border-left: 5px solid #ffc107; padding: 15px; margin-bottom: 15px; text-align: left; border-radius: 4px; font-size: 0.9rem; }
.ai-result-item { background: #fff; border-left: 5px solid #9b59b6; padding: 10px 15px; margin-bottom: 10px; text-align: left; border-radius: 4px; box-shadow: 0 1px 3px rgba(0,0,0,0.1); }
.ai-hanzi { font-size: 1.2rem; font-weight: bold; color: #333; display: flex; align-items: center; gap: 10px; }
.ai-pinyin { color: #555; font-family: 'Segoe UI', sans-serif; font-size: 1rem; margin-bottom: 2px; }
.ai-meaning { color: #666; font-size: 0.95rem; }

/* MOBILE OPTIMIZATION */
@media (max-width: 600px) {
body { padding-top: 0; padding-bottom: 0; }
.container { width: 100%; height: auto; min-height: 100vh; border-radius: 0; box-shadow: none; margin: 0; padding: 0 1rem 1rem 1rem; }
.menu-sticky-header { padding-top: 1.5rem; border-radius: 0; }
.level-cards-container { grid-template-columns: 1fr; max-height: none; overflow-y: visible; }
.level-card { min-height: 150px; }
}
