/* 土耳其语学习平台 - 全局样式 (移动端优化版) */

:root {
    --primary: #e30a17;
    --primary-dark: #b30812;
    --secondary: #1a1a2e;
    --accent: #f4d03f;
    --bg: #f5f5f5;
    --card-bg: #ffffff;
    --text: #333333;
    --text-light: #666666;
    --border: #e0e0e0;
    --success: #27ae60;
    --warning: #f39c12;
    --error: #e74c3c;
    --shadow: 0 2px 8px rgba(0,0,0,0.1);
    --radius: 12px;
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --safe-left: env(safe-area-inset-left, 0px);
    --safe-right: env(safe-area-inset-right, 0px);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
    -webkit-user-select: text;
    user-select: text;
}

html, body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    height: 100%;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
    touch-action: manipulation;
}

/* 加载动画 */
#loading-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    transition: opacity 0.5s;
}

.loading-content {
    text-align: center;
    color: white;
}

.turkish-flag {
    font-size: 80px;
    margin-bottom: 20px;
    animation: bounce 1s infinite;
}

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

.loading-content h1 {
    font-size: 28px;
    margin-bottom: 10px;
}

.loading-content p {
    font-size: 16px;
    opacity: 0.8;
}

.loading-bar {
    width: 200px;
    height: 4px;
    background: rgba(255,255,255,0.2);
    border-radius: 2px;
    margin: 20px auto 0;
    overflow: hidden;
}

.loading-progress {
    width: 0%;
    height: 100%;
    background: var(--accent);
    border-radius: 2px;
    animation: loadProgress 2s ease-in-out forwards;
}

@keyframes loadProgress {
    0% { width: 0%; }
    100% { width: 100%; }
}

/* 主应用 */
#app {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
    height: -webkit-fill-available;
    padding-top: var(--safe-top);
    padding-bottom: var(--safe-bottom);
    padding-left: var(--safe-left);
    padding-right: var(--safe-right);
}

/* 顶部导航 */
.app-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 56px;
    background: var(--secondary);
    color: white;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    z-index: 100;
    box-shadow: var(--shadow);
}

.menu-btn, .settings-btn {
    background: none;
    border: none;
    color: white;
    font-size: 24px;
    cursor: pointer;
    padding: 8px;
}

.app-title {
    font-size: 18px;
    font-weight: 600;
}

/* 侧边菜单 */
.side-menu {
    position: fixed;
    top: 0;
    left: -280px;
    width: 280px;
    height: 100%;
    background: var(--card-bg);
    z-index: 200;
    transition: left 0.3s ease;
    box-shadow: 2px 0 8px rgba(0,0,0,0.1);
    overflow-y: auto;
}

.side-menu.open {
    left: 0;
}

.menu-header {
    padding: 20px;
    background: var(--secondary);
    color: white;
    position: relative;
}

.close-btn {
    position: absolute;
    top: 16px;
    right: 16px;
    font-size: 20px;
    cursor: pointer;
}

.menu-list {
    list-style: none;
    padding: 16px 0;
}

.menu-list li a {
    display: block;
    padding: 16px 20px;
    color: var(--text);
    text-decoration: none;
    font-size: 16px;
    border-bottom: 1px solid var(--border);
    transition: background 0.2s;
}

.menu-list li a:hover,
.menu-list li a:active {
    background: var(--bg);
}

/* 遮罩层 */
.overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 150;
    display: none;
}

.overlay.show {
    display: block;
}

/* 主内容区 */
.main-content {
    flex: 1;
    margin-top: 56px;
    margin-bottom: 64px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-y: contain;
}

/* 页面 */
.page {
    display: none;
    padding: 16px;
    padding-bottom: 80px;
    min-height: 100%;
}

.page.active {
    display: block;
}

/* 页面头部 */
.page-header {
    display: flex;
    align-items: center;
    margin-bottom: 20px;
    padding-bottom: 12px;
    border-bottom: 2px solid var(--primary);
}

.page-header h2 {
    font-size: 20px;
    margin-left: 12px;
}

.back-btn {
    background: none;
    border: none;
    color: var(--primary);
    font-size: 16px;
    cursor: pointer;
    padding: 8px;
}

/* 按钮 */
.btn-primary {
    background: var(--primary);
    color: white;
    border: none;
    padding: 14px 28px;
    border-radius: var(--radius);
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    width: 100%;
    transition: background 0.2s;
    -webkit-appearance: none;
    appearance: none;
    min-height: 48px;
}

.btn-primary:active {
    background: var(--primary-dark);
    transform: scale(0.98);
}

/* 输入框 */
input, textarea, select {
    -webkit-appearance: none;
    appearance: none;
    border-radius: 8px;
}

input:focus, textarea:focus, select:focus {
    outline: none;
    border-color: var(--primary);
}

/* 首页 */
.hero {
    text-align: center;
    padding: 40px 20px;
    background: var(--secondary);
    color: white;
    border-radius: var(--radius);
    margin-bottom: 20px;
}

.hero-icon {
    font-size: 60px;
    margin-bottom: 16px;
}

.hero h2 {
    font-size: 24px;
    margin-bottom: 8px;
}

.hero p {
    font-size: 16px;
    opacity: 0.9;
    margin-bottom: 20px;
}

.quick-stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    margin-bottom: 20px;
}

.stat-card {
    background: var(--card-bg);
    padding: 16px;
    border-radius: var(--radius);
    text-align: center;
    box-shadow: var(--shadow);
}

.stat-number {
    display: block;
    font-size: 28px;
    font-weight: 700;
    color: var(--primary);
}

.stat-label {
    display: block;
    font-size: 12px;
    color: var(--text-light);
    margin-top: 4px;
}

.continue-learning {
    background: var(--card-bg);
    padding: 16px;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.continue-learning h3 {
    margin-bottom: 12px;
    font-size: 18px;
}

.course-card {
    background: var(--bg);
    padding: 16px;
    border-radius: 8px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    transition: background 0.2s;
}

.course-card:active {
    background: var(--border);
}

.course-level {
    background: var(--primary);
    color: white;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 14px;
    font-weight: 600;
}

.course-title {
    flex: 1;
    margin: 0 12px;
    font-size: 16px;
}

.course-progress {
    color: var(--success);
    font-weight: 600;
}

/* 级别标签 */
.level-tabs {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
    overflow-x: auto;
    padding-bottom: 8px;
    -webkit-overflow-scrolling: touch;
}

.level-tab {
    background: var(--card-bg);
    border: 2px solid var(--border);
    padding: 10px 20px;
    border-radius: 20px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.2s;
}

.level-tab.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

/* 标签过滤 */
.tag-filters {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
    overflow-x: auto;
    padding-bottom: 8px;
}

.tag-btn {
    background: var(--bg);
    border: 1px solid var(--border);
    padding: 8px 16px;
    border-radius: 16px;
    font-size: 13px;
    cursor: pointer;
    white-space: nowrap;
}

.tag-btn.active {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--text);
}

/* 课程列表 */
.lesson-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.lesson-item {
    background: var(--card-bg);
    padding: 16px;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    cursor: pointer;
    transition: transform 0.2s;
}

.lesson-item:active {
    transform: scale(0.98);
}

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

.lesson-number {
    background: var(--primary);
    color: white;
    padding: 4px 12px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 600;
}

.lesson-tags {
    display: flex;
    gap: 4px;
}

.lesson-tag {
    background: var(--bg);
    padding: 2px 8px;
    border-radius: 8px;
    font-size: 11px;
}

.lesson-tag.grammar { background: #e3f2fd; color: #1976d2; }
.lesson-tag.bakery { background: #fff3e0; color: #f57c00; }
.lesson-tag.dessert { background: #fce4ec; color: #c2185b; }
.lesson-tag.culture { background: #f3e5f5; color: #7b1fa2; }

.lesson-title {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 4px;
}

.lesson-desc {
    font-size: 14px;
    color: var(--text-light);
}

/* 课程内容 */
.lesson-content {
    background: var(--card-bg);
    padding: 20px;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.lesson-section {
    margin-bottom: 24px;
}

.lesson-section h3 {
    font-size: 18px;
    margin-bottom: 12px;
    color: var(--primary);
    border-left: 4px solid var(--primary);
    padding-left: 12px;
}

.turkish-text {
    background: var(--bg);
    padding: 16px;
    border-radius: 8px;
    font-size: 18px;
    line-height: 1.8;
    margin-bottom: 12px;
}

.sentence-item {
    padding: 12px;
    border-bottom: 1px solid var(--border);
}

.sentence-turkish {
    font-size: 18px;
    color: var(--primary);
    margin-bottom: 4px;
}

.sentence-chinese {
    font-size: 16px;
    color: var(--text);
}

.sentence-note {
    font-size: 13px;
    color: var(--text-light);
    margin-top: 4px;
}

/* 音频播放 */
.audio-btn {
    background: var(--primary);
    color: white;
    border: none;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    font-size: 18px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin-left: 8px;
    vertical-align: middle;
}

.audio-btn.playing {
    animation: pulse 1s infinite;
}

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

/* 语法表格 */
.grammar-table {
    width: 100%;
    border-collapse: collapse;
    margin: 12px 0;
    font-size: 14px;
}

.grammar-table th,
.grammar-table td {
    border: 1px solid var(--border);
    padding: 10px;
    text-align: left;
}

.grammar-table th {
    background: var(--secondary);
    color: white;
}

.grammar-table tr:nth-child(even) {
    background: var(--bg);
}

/* 词汇表 */
.vocab-table {
    width: 100%;
    border-collapse: collapse;
    margin: 12px 0;
    font-size: 14px;
}

.vocab-table th,
.vocab-table td {
    border: 1px solid var(--border);
    padding: 10px;
    text-align: left;
}

.vocab-table th {
    background: var(--primary);
    color: white;
}

/* 练习 */
.exercise-item {
    background: var(--card-bg);
    padding: 16px;
    border-radius: var(--radius);
    margin-bottom: 12px;
    box-shadow: var(--shadow);
}

.exercise-question {
    font-size: 16px;
    margin-bottom: 12px;
}

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

.exercise-option {
    background: var(--bg);
    padding: 12px;
    border-radius: 8px;
    cursor: pointer;
    border: 2px solid transparent;
    transition: all 0.2s;
}

.exercise-option:hover {
    border-color: var(--primary);
}

.exercise-option.correct {
    background: #d4edda;
    border-color: var(--success);
}

.exercise-option.wrong {
    background: #f8d7da;
    border-color: var(--error);
}

/* 翻译页面 */
.translate-box {
    background: var(--card-bg);
    padding: 20px;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    margin-bottom: 20px;
}

.translate-direction {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
}

.dir-btn {
    flex: 1;
    background: var(--bg);
    border: 2px solid var(--border);
    padding: 12px;
    border-radius: 8px;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.2s;
}

.dir-btn.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

.translate-input {
    width: 100%;
    min-height: 120px;
    padding: 12px;
    border: 2px solid var(--border);
    border-radius: 8px;
    font-size: 16px;
    resize: vertical;
    margin-bottom: 12px;
}

.translate-result {
    background: var(--bg);
    padding: 16px;
    border-radius: 8px;
    margin-top: 16px;
    min-height: 80px;
}

/* 情境学习 */
.scenario-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
}

.scenario-card {
    background: var(--card-bg);
    padding: 20px;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    text-align: center;
    cursor: pointer;
    transition: transform 0.2s;
}

.scenario-card:active {
    transform: scale(0.95);
}

.scenario-icon {
    font-size: 40px;
    display: block;
    margin-bottom: 8px;
}

.scenario-title {
    font-size: 14px;
    font-weight: 600;
}

/* 对话气泡 */
.dialogue {
    margin: 16px 0;
}

.dialogue-bubble {
    background: var(--bg);
    padding: 16px;
    border-radius: 16px;
    margin-bottom: 12px;
    position: relative;
}

.dialogue-bubble.turkish {
    background: #e3f2fd;
    margin-left: 20px;
}

.dialogue-bubble.chinese {
    background: #f5f5f5;
    margin-right: 20px;
}

.dialogue-speaker {
    font-size: 12px;
    color: var(--text-light);
    margin-bottom: 4px;
}

.dialogue-text {
    font-size: 16px;
}

/* 进度页面 */
.progress-overview {
    background: var(--card-bg);
    padding: 20px;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    margin-bottom: 20px;
    text-align: center;
}

.progress-circle {
    width: 150px;
    height: 150px;
    margin: 0 auto 20px;
    position: relative;
}

.progress-circle svg {
    transform: rotate(-90deg);
    width: 100%;
    height: 100%;
}

.progress-bg {
    fill: none;
    stroke: var(--bg);
    stroke-width: 8;
}

.progress-bar {
    fill: none;
    stroke: var(--primary);
    stroke-width: 8;
    stroke-linecap: round;
    stroke-dasharray: 283;
    stroke-dashoffset: 283;
    transition: stroke-dashoffset 1s ease;
}

.progress-text {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 32px;
    font-weight: 700;
    color: var(--primary);
}

.progress-stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
}

.progress-stat {
    text-align: center;
}

.stat-value {
    display: block;
    font-size: 24px;
    font-weight: 700;
    color: var(--primary);
}

.stat-label {
    display: block;
    font-size: 12px;
    color: var(--text-light);
    margin-top: 4px;
}

/* 历史记录 */
.history-filters {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
    overflow-x: auto;
}

.history-filter {
    background: var(--bg);
    border: 1px solid var(--border);
    padding: 8px 16px;
    border-radius: 16px;
    font-size: 13px;
    cursor: pointer;
    white-space: nowrap;
}

.history-filter.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

.history-item {
    background: var(--card-bg);
    padding: 16px;
    border-radius: var(--radius);
    margin-bottom: 12px;
    box-shadow: var(--shadow);
}

.history-type {
    display: inline-block;
    background: var(--accent);
    padding: 2px 8px;
    border-radius: 8px;
    font-size: 11px;
    margin-bottom: 8px;
}

.history-content {
    font-size: 14px;
    margin-bottom: 8px;
}

.history-time {
    font-size: 12px;
    color: var(--text-light);
}

/* 底部导航 */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 64px;
    background: var(--card-bg);
    display: flex;
    justify-content: space-around;
    align-items: center;
    box-shadow: 0 -2px 8px rgba(0,0,0,0.1);
    z-index: 100;
    padding-bottom: env(safe-area-inset-bottom);
}

.nav-item {
    background: none;
    border: none;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 8px 16px;
    cursor: pointer;
    color: var(--text-light);
    transition: color 0.2s;
}

.nav-item.active {
    color: var(--primary);
}

.nav-icon {
    font-size: 24px;
    margin-bottom: 2px;
}

.nav-label {
    font-size: 11px;
}

/* FAQ */
.faq-item {
    background: var(--card-bg);
    padding: 16px;
    border-radius: var(--radius);
    margin-bottom: 12px;
    box-shadow: var(--shadow);
    cursor: pointer;
}

.faq-q {
    font-weight: 600;
    display: block;
    margin-bottom: 8px;
}

.faq-a {
    color: var(--text-light);
    font-size: 14px;
    display: none;
}

.faq-item.open .faq-a {
    display: block;
}

/* 字母表 */
.alphabet-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    margin: 16px 0;
}

.alphabet-item {
    background: var(--card-bg);
    padding: 16px;
    border-radius: var(--radius);
    text-align: center;
    box-shadow: var(--shadow);
    cursor: pointer;
}

.alphabet-letter {
    font-size: 24px;
    font-weight: 700;
    color: var(--primary);
    display: block;
}

.alphabet-ipa {
    font-size: 12px;
    color: var(--text-light);
}

/* iPhone Safari 专项修复 */
@supports (-webkit-touch-callout: none) {
    /* iOS 设备 */
    #app {
        height: 100dvh;
    }
    
    .main-content {
        -webkit-overflow-scrolling: touch;
    }
    
    /* 修复 iOS 底部导航遮挡 */
    .bottom-nav {
        padding-bottom: max(env(safe-area-inset-bottom), 8px);
    }
    
    /* 修复 iOS 输入框缩放 */
    input, textarea, select {
        font-size: 16px;
    }
}

/* Android Chrome 专项修复 */
@supports not (-webkit-touch-callout: none) {
    /* 非 iOS 设备 */
    .bottom-nav {
        padding-bottom: env(safe-area-inset-bottom, 0px);
    }
}

/* 微信内置浏览器修复 */
@media screen and (max-width: 430px) {
    .hero {
        padding: 30px 16px;
    }
    
    .hero h2 {
        font-size: 20px;
    }
    
    .quick-stats {
        grid-template-columns: repeat(3, 1fr);
        gap: 8px;
    }
    
    .stat-card {
        padding: 12px 8px;
    }
    
    .stat-number {
        font-size: 22px;
    }
    
    .level-tabs {
        gap: 6px;
    }
    
    .level-tab {
        padding: 8px 14px;
        font-size: 13px;
    }
    
    .lesson-card {
        padding: 12px;
    }
    
    .page-header h2 {
        font-size: 18px;
    }
}

/* 响应式 */
@media (min-width: 768px) {
    .scenario-grid {
        grid-template-columns: repeat(3, 1fr);
    }
    
    .alphabet-grid {
        grid-template-columns: repeat(6, 1fr);
    }
}

/* 暗色模式支持 */
@media (prefers-color-scheme: dark) {
    :root {
        --bg: #1a1a2e;
        --card-bg: #16213e;
        --text: #e0e0e0;
        --text-light: #a0a0a0;
        --border: #2a2a4a;
    }
}

/* 离线提示 */
.offline-banner {
    background: var(--warning);
    color: white;
    padding: 8px 16px;
    text-align: center;
    font-size: 14px;
    position: fixed;
    top: 56px;
    left: 0;
    right: 0;
    z-index: 90;
    display: none;
}

.offline-banner.show {
    display: block;
}


/* 课程列表 */
#lesson-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 16px;
    min-height: 200px;
}

.lesson-card {
    background: var(--card-bg);
    border-radius: 12px;
    padding: 16px;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    border: 1px solid var(--border);
}

.lesson-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}

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

.lesson-number {
    background: var(--primary);
    color: white;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: bold;
}

.lesson-tag {
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 12px;
    font-weight: 500;
}

.lesson-tag.grammar {
    background: #4a90d9;
    color: white;
}

.lesson-tag.bakery {
    background: #e67e22;
    color: white;
}

.lesson-tag.dessert {
    background: #e74c3c;
    color: white;
}

.lesson-tag.culture {
    background: #9b59b6;
    color: white;
}

.lesson-title {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 4px;
    color: var(--text);
}

.lesson-desc {
    font-size: 14px;
    color: var(--text-light);
    margin-bottom: 8px;
}

.lesson-meta {
    display: flex;
    justify-content: space-between;
    font-size: 12px;
    color: var(--text-light);
}

.empty-msg {
    text-align: center;
    padding: 40px;
    color: var(--text-light);
    font-size: 16px;
}

.error-msg {
    text-align: center;
    padding: 40px;
    color: #e74c3c;
    font-size: 16px;
}
