/* ==================== 基础重置 ==================== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

:root {
    /* iOS风格颜色 */
    --primary: #007AFF;
    --success: #34C759;
    --warning: #FF9500;
    --danger: #FF3B30;
    --purple: #AF52DE;
    
    /* 背景色 */
    --bg-primary: #F2F2F7;
    --bg-secondary: #FFFFFF;
    --bg-tertiary: #E5E5EA;
    
    /* 文字色 */
    --text-primary: #000000;
    --text-secondary: #3C3C43;
    --text-tertiary: #8E8E93;
    
    /* 分隔线 */
    --border: rgba(60, 60, 67, 0.12);
    --separator: rgba(60, 60, 67, 0.18);
    
    /* 导航 */
    --tab-bar-height: 49px;
    --status-bar-height: env(safe-area-inset-top, 20px);
    --nav-height: 44px;
    
    /* 圆角 */
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 20px;
    
    /* 阴影 */
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.1);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.15);
}

html, body {
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Helvetica Neue', sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
}

/* ==================== 状态栏 ==================== */
.status-bar {
    height: var(--status-bar-height);
    background: var(--bg-secondary);
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 1000;
}

/* ==================== 主内容区 ==================== */
.main-content {
    position: fixed;
    top: var(--status-bar-height);
    left: 0;
    right: 0;
    bottom: calc(var(--tab-bar-height) + env(safe-area-inset-bottom, 0px));
    overflow: hidden;
}

/* ==================== 页面 ==================== */
.page {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: none;
    flex-direction: column;
    background: var(--bg-primary);
    opacity: 0;
    transform: translateX(20px);
    transition: opacity 0.25s ease, transform 0.25s ease;
}

.page.active {
    display: flex;
    opacity: 1;
    transform: translateX(0);
}

.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: var(--nav-height);
    padding: 0 16px;
    background: var(--bg-secondary);
    border-bottom: 0.5px solid var(--border);
    flex-shrink: 0;
}

.page-header h1 {
    font-size: 17px;
    font-weight: 600;
    letter-spacing: -0.41px;
}

.header-actions {
    display: flex;
    gap: 12px;
}

.icon-btn {
    width: 32px;
    height: 32px;
    border: none;
    background: transparent;
    font-size: 18px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background 0.2s;
}

.icon-btn:active {
    background: var(--bg-tertiary);
}

.page-body {
    flex: 1;
    overflow: hidden;
}

.page-body.scrollable {
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

/* ==================== 底部Tab Bar ==================== */
.tab-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: calc(var(--tab-bar-height) + env(safe-area-inset-bottom, 0px));
    padding-bottom: env(safe-area-inset-bottom, 0px);
    background: var(--bg-secondary);
    border-top: 0.5px solid var(--border);
    display: flex;
    justify-content: space-around;
    align-items: flex-end;
    z-index: 1000;
}

.tab-item {
    flex: 1;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    border: none;
    background: transparent;
    cursor: pointer;
    padding: 4px 0;
    transition: transform 0.15s ease;
}

.tab-item:active {
    transform: scale(0.92);
}

.tab-icon {
    font-size: 22px;
    line-height: 1;
}

.tab-label {
    font-size: 10px;
    font-weight: 500;
    color: var(--text-tertiary);
    letter-spacing: -0.24px;
}

.tab-item.active .tab-label {
    color: var(--primary);
}

.tab-item.active .tab-icon {
    transform: translateY(-1px);
}

/* ==================== 安全区域 ==================== */
.safe-area-bottom {
    height: env(safe-area-inset-bottom, 0px);
}

/* ==================== 章节列表 ==================== */
.chapters {
    padding: 12px 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.chapter-card {
    display: flex;
    align-items: center;
    padding: 14px 16px;
    background: var(--bg-secondary);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
}

.chapter-card:active {
    transform: scale(0.98);
    box-shadow: none;
}

.chapter-num {
    width: 36px;
    height: 36px;
    background: linear-gradient(135deg, var(--primary), var(--purple));
    color: white;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 600;
    margin-right: 14px;
    flex-shrink: 0;
}

.chapter-info {
    flex: 1;
    min-width: 0;
}

.chapter-info h3 {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 2px;
    letter-spacing: -0.32px;
}

.chapter-info p {
    font-size: 13px;
    color: var(--text-tertiary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chapter-arrow {
    font-size: 22px;
    color: var(--text-tertiary);
    margin-left: 8px;
}

/* ==================== 助记卡片 ==================== */
.card-filter {
    padding: 12px 0;
    background: var(--bg-primary);
}

.filter-scroll {
    display: flex;
    gap: 8px;
    padding: 0 16px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}

.filter-scroll::-webkit-scrollbar {
    display: none;
}

.filter-chip {
    flex-shrink: 0;
    padding: 8px 16px;
    background: var(--bg-secondary);
    border: none;
    border-radius: 20px;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s;
    box-shadow: var(--shadow-sm);
}

.filter-chip:active {
    transform: scale(0.95);
}

.filter-chip.active {
    background: var(--primary);
    color: white;
}

.filter-chip.wrong-filter.active {
    background: var(--danger);
}

.flashcard-container {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    perspective: 1000px;
}

.flashcard {
    width: 100%;
    max-width: 360px;
    aspect-ratio: 3/4;
    max-height: 420px;
}

.flashcard-inner {
    position: relative;
    width: 100%;
    height: 100%;
    transition: transform 0.5s cubic-bezier(0.4, 0, 0.2, 1);
    transform-style: preserve-3d;
    cursor: pointer;
}

.flashcard.flipped .flashcard-inner {
    transform: rotateY(180deg);
}

.flashcard-front,
.flashcard-back {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-md);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 24px;
    text-align: center;
}

.flashcard-front {
    background: linear-gradient(145deg, #5856D6, #007AFF);
    color: white;
}

.flashcard-back {
    background: var(--bg-secondary);
    color: var(--text-primary);
    transform: rotateY(180deg);
}

.card-type {
    font-size: 12px;
    font-weight: 600;
    padding: 4px 12px;
    background: rgba(255,255,255,0.2);
    border-radius: 12px;
    margin-bottom: 12px;
    color: white;
}

.flashcard-back .card-type {
    background: var(--primary);
    color: white;
}

.card-id {
    font-size: 13px;
    opacity: 0.8;
    margin-bottom: 16px;
}

.card-question {
    font-size: 18px;
    font-weight: 600;
    line-height: 1.4;
    letter-spacing: -0.4px;
}

.card-answer {
    font-size: 15px;
    line-height: 1.6;
    text-align: left;
    width: 100%;
}

.card-answer strong {
    color: var(--primary);
}

.card-progress {
    text-align: center;
    padding: 8px;
    font-size: 14px;
    color: var(--text-tertiary);
    font-weight: 500;
}

.card-controls {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 16px;
    padding: 16px 20px 24px;
    background: var(--bg-primary);
}

.control-btn {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    border: none;
    font-size: 24px;
    font-weight: 300;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    background: var(--bg-secondary);
    color: var(--text-primary);
    box-shadow: var(--shadow-sm);
}

.control-btn:active {
    transform: scale(0.9);
}

.control-btn.wrong {
    background: var(--bg-secondary);
    color: var(--danger);
    font-size: 20px;
}

.control-btn.wrong.active {
    background: var(--danger);
    color: white;
}

.control-btn.secondary {
    color: var(--text-secondary);
}

/* ==================== 播客播放器 ==================== */
.podcast-player {
    padding: 32px 24px;
    background: var(--bg-secondary);
    display: flex;
    flex-direction: column;
    align-items: center;
}

.player-cover {
    margin-bottom: 24px;
}

.cover-art {
    width: 180px;
    height: 180px;
    background: linear-gradient(135deg, #5856D6, #007AFF);
    border-radius: var(--radius-lg);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 64px;
    box-shadow: var(--shadow-md);
}

.player-title {
    font-size: 20px;
    font-weight: 700;
    text-align: center;
    margin-bottom: 4px;
    letter-spacing: -0.5px;
}

.player-subtitle {
    font-size: 14px;
    color: var(--text-tertiary);
    margin-bottom: 32px;
}

.player-progress {
    width: 100%;
    margin-bottom: 16px;
}

.progress-bar {
    height: 4px;
    background: var(--bg-tertiary);
    border-radius: 2px;
    overflow: hidden;
    margin-bottom: 8px;
}

.progress-fill {
    height: 100%;
    background: var(--primary);
    width: 0%;
    transition: width 0.1s linear;
}

.progress-time {
    display: flex;
    justify-content: space-between;
    font-size: 12px;
    color: var(--text-tertiary);
    font-variant-numeric: tabular-nums;
}

.audio-element {
    display: none;
}

.player-controls {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 32px;
    margin-bottom: 16px;
}

.player-btn {
    border: none;
    background: transparent;
    font-size: 14px;
    font-weight: 600;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 8px;
}

.player-btn:active {
    opacity: 0.6;
}

.play-btn {
    width: 64px;
    height: 64px;
    background: var(--primary);
    color: white;
    border-radius: 50%;
    font-size: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow-md);
}

.play-btn:active {
    transform: scale(0.95);
}

.player-extra {
    display: flex;
    justify-content: center;
}

.speed-btn {
    padding: 6px 12px;
    background: var(--bg-tertiary);
    border: none;
    border-radius: 16px;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    cursor: pointer;
}

.chapter-section {
    padding: 20px 16px;
}

.chapter-section h3 {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 12px;
    padding-left: 4px;
}

.chapter-list {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.chapter-item {
    display: flex;
    align-items: center;
    padding: 12px 14px;
    background: var(--bg-secondary);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background 0.2s;
}

.chapter-item:active {
    background: var(--bg-tertiary);
}

.ch-time {
    font-size: 14px;
    font-weight: 500;
    color: var(--primary);
    width: 48px;
    font-variant-numeric: tabular-nums;
}

.ch-title {
    font-size: 15px;
    color: var(--text-primary);
}

/* ==================== 思维导图 ==================== */
.mindmap-tabs {
    display: flex;
    gap: 8px;
    padding: 12px 16px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    background: var(--bg-primary);
}

.mindmap-tabs::-webkit-scrollbar {
    display: none;
}

.mindmap-tab {
    flex-shrink: 0;
    padding: 8px 16px;
    background: var(--bg-secondary);
    border: none;
    border-radius: 20px;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s;
    box-shadow: var(--shadow-sm);
}

.mindmap-tab:active {
    transform: scale(0.95);
}

.mindmap-tab.active {
    background: var(--primary);
    color: white;
}

.mindmap-views {
    flex: 1;
    position: relative;
    overflow: hidden;
}

.mindmap-view {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: none;
    flex-direction: column;
    padding: 16px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.mindmap-view.active {
    display: flex;
}

.mindmap-center {
    font-size: 20px;
    font-weight: 700;
    text-align: center;
    padding: 16px;
    background: linear-gradient(135deg, var(--primary), var(--purple));
    color: white;
    border-radius: var(--radius-lg);
    margin-bottom: 16px;
}

/* 结构图 */
.mindmap-tree {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.tree-branch {
    background: var(--bg-secondary);
    border-radius: var(--radius-md);
    padding: 14px;
    box-shadow: var(--shadow-sm);
}

.branch-node {
    font-size: 15px;
    font-weight: 600;
    margin-bottom: 10px;
    padding: 8px 12px;
    background: var(--primary);
    color: white;
    border-radius: var(--radius-sm);
}

.branch-children {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding-left: 12px;
}

.child-node {
    font-size: 13px;
    padding: 10px 12px;
    background: var(--bg-primary);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
}

.child-node small {
    color: var(--text-tertiary);
    font-size: 11px;
}

.mindmap-tip {
    margin-top: 16px;
    padding: 12px 16px;
    background: #FFF9E6;
    border-left: 4px solid var(--warning);
    border-radius: var(--radius-sm);
    font-size: 13px;
    color: var(--text-secondary);
}

/* 记忆卡片 */
.memory-cards {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.memory-card {
    background: var(--bg-secondary);
    border-radius: var(--radius-md);
    padding: 16px;
    box-shadow: var(--shadow-sm);
}

.mem-title {
    font-size: 16px;
    font-weight: 700;
    color: var(--primary);
    margin-bottom: 8px;
}

.mem-detail {
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: 4px;
}

.mem-tag {
    display: inline-block;
    margin-top: 8px;
    padding: 4px 10px;
    background: var(--bg-tertiary);
    border-radius: 12px;
    font-size: 12px;
    color: var(--text-tertiary);
}

.mindmap-flow {
    text-align: center;
    padding: 16px;
    font-size: 15px;
    font-weight: 600;
    color: var(--primary);
    background: var(--bg-secondary);
    border-radius: var(--radius-md);
    margin-top: 8px;
}

/* 言语中枢 */
.speech-cards {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.speech-card {
    background: var(--bg-secondary);
    border-radius: var(--radius-md);
    padding: 16px;
    box-shadow: var(--shadow-sm);
    border-left: 4px solid var(--primary);
}

.speech-card.danger { border-left-color: var(--danger); }
.speech-card.warning { border-left-color: var(--warning); }
.speech-card.success { border-left-color: var(--success); }

.speech-name {
    font-size: 16px;
    font-weight: 700;
    margin-bottom: 6px;
}

.speech-type {
    font-size: 13px;
    color: var(--text-secondary);
}

.speech-func {
    font-size: 13px;
    color: var(--text-secondary);
    margin: 4px 0;
}

.speech-result {
    font-size: 14px;
    font-weight: 600;
    color: var(--danger);
    margin-top: 8px;
}

/* 道德发展 */
.moral-levels {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.moral-level {
    background: var(--bg-secondary);
    border-radius: var(--radius-md);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
}

.level-header {
    padding: 12px 16px;
    font-size: 15px;
    font-weight: 600;
    color: white;
}

.level-header.level-1 { background: var(--danger); }
.level-header.level-2 { background: var(--warning); }
.level-header.level-3 { background: var(--success); }

.level-stages {
    padding: 12px;
}

.stage {
    padding: 10px 12px;
    font-size: 13px;
    color: var(--text-primary);
    border-bottom: 0.5px solid var(--border);
}

.stage:last-child {
    border-bottom: none;
}

/* 咨询技术 */
.therapy-grid {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.therapy-category {
    background: var(--bg-secondary);
    border-radius: var(--radius-md);
    padding: 16px;
    box-shadow: var(--shadow-sm);
}

.cat-title {
    font-size: 16px;
    font-weight: 700;
    margin-bottom: 10px;
    padding: 8px 12px;
    border-radius: var(--radius-sm);
}

.therapy-category.participate .cat-title {
    background: #E3F2FD;
    color: var(--primary);
}

.therapy-category.influence .cat-title {
    background: #FCE4EC;
    color: var(--danger);
}

.cat-items {
    font-size: 13px;
    color: var(--text-secondary);
    line-height: 1.8;
}

.therapy-key {
    margin-top: 12px;
    padding: 12px 16px;
    background: #FFF3E0;
    border-radius: var(--radius-sm);
    font-size: 13px;
    color: var(--warning);
    text-align: center;
}

/* ==================== 材料列表 ==================== */
.materials-list {
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.material-item {
    display: flex;
    align-items: center;
    padding: 16px;
    background: var(--bg-secondary);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
}

.material-icon {
    font-size: 32px;
    margin-right: 14px;
}

.material-info {
    flex: 1;
    min-width: 0;
}

.material-info h3 {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 2px;
}

.material-info p {
    font-size: 13px;
    color: var(--text-tertiary);
}

.material-actions {
    display: flex;
    gap: 8px;
}

.action-btn {
    padding: 8px 14px;
    background: var(--primary);
    color: white;
    text-decoration: none;
    border-radius: 18px;
    font-size: 13px;
    font-weight: 600;
    transition: opacity 0.2s;
}

.action-btn:active {
    opacity: 0.7;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
    padding: 16px;
}

.stat-card {
    background: var(--bg-secondary);
    border-radius: var(--radius-md);
    padding: 20px 12px;
    text-align: center;
    box-shadow: var(--shadow-sm);
}

.stat-num {
    font-size: 28px;
    font-weight: 700;
    color: var(--primary);
    line-height: 1;
    margin-bottom: 4px;
}

.stat-label {
    font-size: 12px;
    color: var(--text-tertiary);
}

/* ==================== 覆盖层（章节详情） ==================== */
.overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--bg-primary);
    z-index: 900;
    display: none;
    flex-direction: column;
    transform: translateX(100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.overlay.active {
    display: flex;
    transform: translateX(0);
}

.overlay-header {
    display: flex;
    align-items: center;
    height: var(--nav-height);
    padding: 0 8px;
    background: var(--bg-secondary);
    border-bottom: 0.5px solid var(--border);
    flex-shrink: 0;
}

.back-btn {
    border: none;
    background: transparent;
    font-size: 28px;
    color: var(--primary);
    cursor: pointer;
    padding: 8px 12px 8px 4px;
}

.overlay-header h2 {
    flex: 1;
    font-size: 17px;
    font-weight: 600;
    text-align: center;
    padding-right: 44px;
    letter-spacing: -0.41px;
}

.overlay-body {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 16px;
}

/* 章节内容样式 */
.chapter-content h2 {
    font-size: 18px;
    font-weight: 700;
    color: var(--primary);
    margin: 20px 0 12px;
    padding-bottom: 8px;
    border-bottom: 2px solid var(--primary);
}

.chapter-content h3 {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
    margin: 16px 0 10px;
}

.chapter-content h4 {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-secondary);
    margin: 14px 0 8px;
}

.chapter-content p {
    font-size: 15px;
    line-height: 1.7;
    color: var(--text-primary);
    margin-bottom: 12px;
}

.chapter-content ul,
.chapter-content ol {
    margin: 0 0 12px 20px;
}

.chapter-content li {
    font-size: 15px;
    line-height: 1.6;
    color: var(--text-primary);
    margin-bottom: 6px;
}

.chapter-content pre {
    background: var(--bg-tertiary);
    padding: 14px;
    border-radius: var(--radius-sm);
    overflow-x: auto;
    font-size: 13px;
    line-height: 1.5;
    margin-bottom: 12px;
}

.chapter-content table {
    width: 100%;
    border-collapse: collapse;
    margin: 12px 0;
    font-size: 14px;
}

.chapter-content th,
.chapter-content td {
    border: 0.5px solid var(--border);
    padding: 10px 8px;
    text-align: left;
}

.chapter-content th {
    background: var(--primary);
    color: white;
    font-weight: 600;
}

.chapter-content strong {
    color: var(--primary);
}

.chapter-content .highlight {
    background: #FFF9E6;
    padding: 2px 6px;
    border-radius: 4px;
    font-weight: 600;
}

/* ==================== 响应式 ==================== */
@media (min-width: 768px) {
    .page-body {
        max-width: 600px;
        margin: 0 auto;
    }
    
    .chapters {
        max-width: 600px;
        margin: 0 auto;
    }
    
    .flashcard {
        max-width: 400px;
    }
    
    .stats-grid {
        max-width: 600px;
        margin: 0 auto;
    }
}

@media (max-width: 374px) {
    .tab-label {
        font-size: 9px;
    }
    
    .tab-icon {
        font-size: 20px;
    }
}
