/* Reset & Base Styles */
:root {
    --primary-color: #2563eb;
    --primary-hover: #1d4ed8;
    --primary-light: #eff6ff;
    --secondary-color: #475569;
    --bg-color: #f8fafc;
    --card-bg: #ffffff;
    --text-main: #0f172a;
    --text-muted: #64748b;
    --border-color: #e2e8f0;
    --highlight-sentence: #dbeafe;
    --highlight-word: #fef08a;
    --accent-success: #16a34a;
    --accent-warning: #ea580c;
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.07), 0 2px 4px -1px rgba(0, 0, 0, 0.04);
    --radius-md: 12px;
    --radius-lg: 16px;
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    --font-heading: 'Lexend', var(--font-sans);
}

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

body {
    font-family: var(--font-sans);
    background-color: var(--bg-color);
    color: var(--text-main);
    line-height: 1.6;
    display: flex;
    justify-content: center;
    min-height: 100vh;
    padding: 0;
}

#app {
    width: 100%;
    max-width: 680px; /* Mobile first, optimized for phone/tablet container */
    background: var(--bg-color);
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* Header */
.app-header {
    background: var(--card-bg);
    padding: 14px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border-color);
}

.logo-area {
    display: flex;
    align-items: center;
    gap: 10px;
}

.app-icon {
    font-size: 20px;
    background: var(--primary-light);
    padding: 6px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.app-header h1 {
    font-family: var(--font-heading);
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--text-main);
}

.status-badge {
    font-size: 0.75rem;
    background: #f0fdf4;
    color: var(--accent-success);
    padding: 4px 10px;
    border-radius: 20px;
    border: 1px solid #bbf7d0;
    font-weight: 500;
}

/* Navigation Segmented Control Pills */
.nav-tabs {
    display: flex;
    background: #f1f5f9;
    padding: 4px;
    border-radius: 12px;
    margin: 12px 16px 4px 16px;
    overflow-x: auto;
    gap: 4px;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
}

.nav-tabs::-webkit-scrollbar {
    display: none;
}

.tab-btn {
    flex: 1;
    min-width: max-content;
    padding: 9px 12px;
    background: transparent;
    border: none;
    border-radius: 8px;
    font-size: 0.88rem;
    font-weight: 600;
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
    text-align: center;
}

.tab-btn:hover {
    color: var(--primary-color);
}

.tab-btn.active {
    background: #ffffff;
    color: var(--primary-color);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
}

/* Main Content */
.main-content {
    padding: 16px;
    flex: 1;
}

.tab-content {
    display: none;
}

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

/* Cards */
.card {
    background: var(--card-bg);
    border-radius: var(--radius-md);
    padding: 20px;
    margin-bottom: 16px;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-color);
}

/* Topic Card */
.topic-header label {
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--text-main);
}

.topic-options {
    display: flex;
    gap: 10px;
    margin-top: 10px;
    flex-wrap: wrap;
}

select {
    flex: 1;
    padding: 10px 14px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    background-color: var(--card-bg);
    font-size: 0.9rem;
    color: var(--text-main);
    outline: none;
}

.custom-input-box {
    margin-top: 10px;
}

.custom-input-box input {
    width: 100%;
    padding: 10px 14px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    font-size: 0.9rem;
}

/* Buttons */
.btn {
    padding: 10px 16px;
    border-radius: 8px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    border: none;
    transition: background-color 0.2s, transform 0.1s;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

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

.primary-btn {
    background: var(--primary-color);
    color: #ffffff;
}

.primary-btn:hover {
    background: var(--primary-hover);
}

.secondary-btn {
    background: #f1f5f9;
    color: var(--secondary-color);
    border: 1px solid var(--border-color);
}

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

.icon-btn {
    background: #f1f5f9;
    color: var(--secondary-color);
    padding: 6px 12px;
    font-size: 0.85rem;
}

.full-width {
    width: 100%;
}

/* Article Card & Interactive Reader */
.article-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    padding-bottom: 12px;
    border-bottom: 1px solid #f1f5f9;
}

.badge {
    font-size: 0.75rem;
    padding: 4px 8px;
    border-radius: 6px;
    background: var(--primary-light);
    color: var(--primary-color);
    font-weight: 600;
    margin-right: 6px;
}

.badge.difficulty {
    background: #fef3c7;
    color: var(--accent-warning);
}

.speed-control {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 0.8rem;
    color: var(--text-muted);
}

.speed-control select {
    padding: 4px 8px;
    font-size: 0.8rem;
}

.article-header {
    margin-bottom: 20px;
}

.article-title {
    font-family: var(--font-heading);
    font-size: 1.3rem;
    color: var(--primary-color);
    margin-bottom: 4px;
}

.article-title-zh {
    font-size: 0.95rem;
    color: var(--text-muted);
}

/* Article Sentences & Word Click Style */
.article-body {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.sentence-block {
    padding: 10px 12px;
    border-radius: 8px;
    transition: background-color 0.2s;
    border-left: 3px solid transparent;
    cursor: pointer;
}

.sentence-block:hover {
    background-color: #f1f5f9;
}

.sentence-block.playing {
    background-color: var(--highlight-sentence);
    border-left-color: var(--primary-color);
}

.sentence-en {
    font-size: 1.05rem;
    line-height: 1.7;
    color: #1e293b;
    margin-bottom: 4px;
}

/* Interactive Word Spans */
.word-span {
    display: inline-block;
    padding: 1px 2px;
    border-radius: 4px;
    transition: background 0.15s;
    user-select: none;
}

.word-span:hover, .word-span:active {
    background-color: var(--highlight-word);
    color: #000;
}

.sentence-zh {
    font-size: 0.9rem;
    color: #64748b;
    margin-top: 2px;
    transition: opacity 0.2s;
}

.sentence-zh.hidden {
    display: none;
}

.reader-tip {
    margin-top: 20px;
    padding: 12px;
    background: #f8fafc;
    border-radius: 8px;
    font-size: 0.8rem;
    color: var(--text-muted);
    border: 1px dashed var(--border-color);
}

/* Quiz Card */
.quiz-header {
    margin-bottom: 16px;
}

.quiz-header h2 {
    font-size: 1.1rem;
    font-family: var(--font-heading);
}

.quiz-desc {
    font-size: 0.85rem;
    color: var(--text-muted);
}

.quiz-item {
    margin-bottom: 20px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border-color);
}

.quiz-question {
    font-weight: 600;
    font-size: 0.95rem;
    margin-bottom: 10px;
}

.quiz-options {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.option-btn {
    padding: 10px 14px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    background: #ffffff;
    text-align: left;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.2s;
}

.option-btn:hover {
    background: #f8fafc;
    border-color: var(--primary-color);
}

.option-btn.selected {
    border-color: var(--primary-color);
    background: var(--primary-light);
    color: var(--primary-color);
    font-weight: 600;
}

.option-btn.correct {
    background: #dcfce7;
    border-color: var(--accent-success);
    color: #15803d;
    font-weight: 600;
}

.option-btn.wrong {
    background: #fee2e2;
    border-color: #ef4444;
    color: #b91c1c;
}

.quiz-explanation {
    margin-top: 8px;
    padding: 8px 12px;
    background: #f8fafc;
    border-radius: 6px;
    font-size: 0.85rem;
    color: var(--text-muted);
}

/* Aloud Practice Card */
.aloud-header h2 {
    font-size: 1.1rem;
    font-family: var(--font-heading);
}

.aloud-desc {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 16px;
}

.sentence-navigator {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

#sentence-counter {
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--text-muted);
}

.aloud-target-box {
    background: #ffffff;
    border-radius: var(--radius-lg);
    padding: 24px 20px;
    border: 1px solid #e2e8f0;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.03);
    text-align: left;
    margin-bottom: 24px;
}

.target-en {
    margin-bottom: 16px;
    padding-bottom: 14px;
    border-bottom: 1px dashed #e2e8f0;
}

.target-zh {
    background: #f8fafc;
    border-radius: var(--radius-sm);
    padding: 12px 16px;
}

.aloud-tag {
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    margin-bottom: 6px;
    letter-spacing: 0.5px;
}

.en-tag {
    color: #2563eb;
}

.zh-tag {
    color: #475569;
}

.aloud-text-en {
    font-size: 1.2rem;
    font-weight: 700;
    line-height: 1.6;
    color: #0f172a;
}

.aloud-text-zh {
    font-size: 1.0rem;
    font-weight: 500;
    line-height: 1.5;
    color: #334155;
}

.aloud-action-bar {
    display: flex;
    gap: 12px;
    justify-content: center;
}

.action-btn {
    padding: 12px 20px;
    font-size: 0.95rem;
}

.demo-btn {
    background: #e0e7ff;
    color: #4338ca;
}

.demo-btn:hover {
    background: #c7d2fe;
}

.record-btn {
    background: #dc2626;
    color: #ffffff;
}

.record-btn:hover {
    background: #b91c1c;
}

.record-btn.recording {
    animation: pulse 1.5s infinite;
    background: #991b1b;
}

@keyframes pulse {
    0% { opacity: 1; }
    50% { opacity: 0.6; }
    100% { opacity: 1; }
}

.speech-feedback {
    margin-top: 20px;
    padding: 16px;
    background: #ffffff;
    border-radius: 8px;
    border: 1px solid var(--border-color);
}

.feedback-score {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 8px;
}

.recognized-text {
    font-size: 0.95rem;
    font-weight: 500;
    color: var(--text-main);
    font-style: italic;
    margin-top: 4px;
}

.score-badge {
    display: inline-block;
    padding: 4px 10px;
    background: #dcfce7;
    color: #15803d;
    font-weight: 700;
    border-radius: 12px;
    font-size: 0.85rem;
    margin-top: 8px;
}

/* Config Card */
.config-group {
    margin-bottom: 24px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border-color);
}

.config-group h3 {
    font-size: 1rem;
    margin-bottom: 8px;
}

.config-tip {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 10px;
}

.file-list {
    list-style: none;
    margin-bottom: 12px;
}

.file-list li {
    font-size: 0.85rem;
    padding: 4px 8px;
    background: #f1f5f9;
    border-radius: 4px;
    margin-bottom: 4px;
}

.config-group input[type="password"] {
    width: 100%;
    padding: 10px 14px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    margin-bottom: 10px;
}

/* Word Definition Modal */
.word-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(15, 23, 42, 0.4);
    backdrop-filter: blur(4px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
    padding: 20px;
}

.word-modal.hidden {
    display: none;
}

.word-modal-content {
    background: #ffffff;
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 360px;
    padding: 24px;
    position: relative;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1);
}

.close-btn {
    position: absolute;
    top: 14px;
    right: 18px;
    background: none;
    border: none;
    font-size: 1.5rem;
    color: var(--text-muted);
    cursor: pointer;
}

.word-modal-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 6px;
}

.word-modal-header h3 {
    font-size: 1.4rem;
    color: var(--primary-color);
    font-family: var(--font-heading);
}

.word-phonetics {
    font-size: 0.9rem;
    color: var(--text-muted);
    margin-bottom: 12px;
}

.word-translation {
    font-size: 1.05rem;
    font-weight: 600;
    color: var(--text-main);
    margin-bottom: 12px;
    background: var(--primary-light);
    padding: 8px 12px;
    border-radius: 8px;
}

.word-context-sentence {
    font-size: 0.85rem;
    color: var(--text-muted);
    font-style: italic;
}

.hidden {
    display: none !important;
}

/* Progress Dashboard & Curriculum Map */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
    gap: 16px;
    margin: 20px 0;
}

.stat-card {
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: var(--radius-md);
    padding: 16px 12px;
    text-align: center;
}

.stat-value {
    font-size: 1.6rem;
    font-weight: 700;
    color: var(--primary-color);
    font-family: var(--font-heading);
}

.stat-label {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 4px;
}

.curriculum-section, .weakness-section {
    margin-top: 28px;
}

.level-map-container {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 14px;
    margin-top: 14px;
}

.level-card {
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: var(--radius-md);
    padding: 16px;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

.level-card:hover {
    border-color: var(--primary-color);
    box-shadow: var(--shadow-sm);
    transform: translateY(-2px);
}

.level-card.locked {
    opacity: 0.6;
    background: #f1f5f9;
    cursor: not-allowed;
}

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

.level-badge {
    font-size: 0.75rem;
    padding: 2px 8px;
    border-radius: 12px;
    font-weight: 600;
    background: #e2e8f0;
    color: #475569;
}

.level-card.unlocked .level-badge {
    background: #dbeafe;
    color: #1e40af;
}

.level-card.mastered .level-badge {
    background: #dcfce7;
    color: #15803d;
}

.level-title-zh {
    font-weight: 700;
    font-size: 1rem;
    color: var(--text-main);
}

.level-title-en {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-top: 2px;
}

.weakness-list {
    margin-top: 12px;
}

.weakness-item {
    background: #fef2f2;
    border: 1px solid #fecaca;
    border-radius: var(--radius-sm);
    padding: 12px;
    margin-bottom: 10px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.weakness-text {
    font-size: 0.95rem;
    color: #991b1b;
}

.empty-tip {
    color: var(--text-muted);
    font-size: 0.9rem;
    font-style: italic;
}

/* Mobile Textarea Optimization */
.mobile-textarea {
    width: 100%;
    font-size: 16px; /* Prevents auto-zoom on iOS safari */
    padding: 12px 14px;
    border: 1px solid var(--border-color);
    border-radius: 10px;
    outline: none;
    font-family: var(--font-sans);
    line-height: 1.5;
    background: #fff;
    resize: none;
    box-shadow: inset 0 1px 2px rgba(0,0,0,0.03);
    transition: border-color 0.2s, box-shadow 0.2s;
}

.mobile-textarea:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

/* Inline Quick Word Popover Banner */
.word-quick-banner {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #e0e7ff;
    border: 1px solid #c7d2fe;
    border-radius: 10px;
    padding: 10px 14px;
    margin-bottom: 16px;
    animation: fadeIn 0.2s ease;
}

.word-quick-banner.hidden {
    display: none;
}

.banner-content {
    display: flex;
    flex-direction: column;
}

.banner-word {
    font-size: 1rem;
    color: #3730a3;
}

.banner-phonetic {
    font-size: 0.82rem;
    color: #4f46e5;
    margin-left: 6px;
}

.banner-meaning {
    font-size: 0.88rem;
    color: #1e1b4b;
    font-weight: 500;
}

.banner-audio-btn {
    background: #4f46e5;
    color: #fff;
    border: none;
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
}

/* Interactive Quiz Options & Badges */
.quiz-badge {
    display: inline-block;
    background: #e0e7ff;
    color: #3730a3;
    font-size: 0.78rem;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 6px;
    margin-right: 6px;
}
