:root {
    --primary-color: #4361ee;
    --secondary-color: #3a0ca3;
    --success-color: #4cc9f0;
    --danger-color: #f72585;
    --light-color: #f8f9fa;
    --dark-color: #212529;
    --border-color: #dee2e6;
    --shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    --radius: 12px;
    --radius-sm: 6px;
}

/* 重置和基础样式 */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
    -webkit-user-select: none;
    user-select: none;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    line-height: 1.6;
    color: var(--dark-color);
    background: #f5f7fa;
    height: 100vh;
    overflow: hidden;
    position: fixed;
    width: 100%;
    touch-action: pan-y;
}

/* 头部导航栏 */
.app-header {
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    color: white;
    padding: 12px 16px;
    box-shadow: var(--shadow);
    position: relative;
    z-index: 100;
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.menu-btn {
    background: none;
    border: none;
    width: 32px;
    height: 32px;
    padding: 0;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    align-items: center;
}

.menu-btn span {
    display: block;
    width: 100%;
    height: 3px;
    background: white;
    border-radius: 2px;
    transition: all 0.3s;
}

#course-title {
    font-size: 18px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 150px;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

/* 页面指示器 */
.page-indicator {
    display: flex;
    gap: 8px;
}

.page-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.5);
    transition: all 0.3s ease;
    cursor: pointer;
}

.page-dot.active {
    background: white;
    transform: scale(1.2);
}

#step-type {
    background: rgba(255, 255, 255, 0.2);
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 500;
}

/* 进度条 */
.progress-container {
    margin-top: 12px;
}

.progress-bar {
    height: 4px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 2px;
    overflow: hidden;
    margin-bottom: 6px;
}

.progress-fill {
    height: 100%;
    background: var(--success-color);
    width: 10%;
    transition: width 0.3s;
    border-radius: 2px;
}

.progress-text {
    font-size: 12px;
    opacity: 0.8;
    text-align: right;
}

/* 页面容器 - 关键部分 */
.pages-container {
    position: relative;
    width: 100%;
    height: calc(100vh - 160px);
    overflow: hidden;
    touch-action: pan-y;
}

/* 页面样式 */
.page {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: white;
    display: flex;
    flex-direction: column;
    transition: transform 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    will-change: transform;
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.1);
}

/* 页面1：预览页面 */
#page-preview {
    transform: translateX(0);
    z-index: 2;
}

/* 页面2：代码页面 */
#page-code {
    transform: translateX(100%);
    z-index: 1;
}

/* 页面滑动状态 */
.page.slide-left {
    transform: translateX(-100%);
}

.page.slide-right {
    transform: translateX(100%);
}

/* 页面激活状态 */
.page.active {
    transform: translateX(0) !important;
    z-index: 3;
}

/* 确保所有页面都可以触摸 */
.page {
    touch-action: pan-y;
}

/* 页面头部 */
.page-header {
    padding: 16px;
    background: white;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
    position: sticky;
    top: 0;
    z-index: 10;
}

.page-header h2 {
    font-size: 18px;
    font-weight: 600;
    color: var(--dark-color);
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 0;
}

.page-controls {
    display: flex;
    gap: 8px;
}

.icon-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: none;
    background: #f0f2f5;
    color: #666;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
}

.icon-btn:hover,
.icon-btn:active {
    background: var(--primary-color);
    color: white;
    transform: scale(1.05);
}

.icon-btn svg {
    pointer-events: none;
}

.small-btn {
    padding: 6px 12px;
    font-size: 12px;
    border: 1px solid var(--border-color);
    background: white;
    border-radius: var(--radius-sm);
    color: #666;
    cursor: pointer;
    transition: all 0.2s;
    font-weight: 500;
}

.small-btn:hover,
.small-btn:active {
    background: #f8f9fa;
    border-color: var(--primary-color);
    color: var(--primary-color);
}

/* 页面内容 */
.page-content {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    background: white;
    position: relative;
}

/* 预览页面内容 */
.preview-container {
    padding: 20px;
    background: #f8f9fa;
    height: 100%;
    overflow: auto;
}

/* 代码页面内容 */
.content-section {
    height: 100%;
    display: flex;
    flex-direction: column;
}

.step-explanation {
    padding: 20px;
    border-bottom: 1px solid var(--border-color);
    background: white;
}

.step-explanation h3 {
    font-size: 20px;
    margin-bottom: 12px;
    color: var(--dark-color);
    font-weight: 600;
}

.step-explanation p {
    font-size: 15px;
    line-height: 1.7;
    color: #555;
}

.code-display {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: #f8f9fa;
}

.section-header {
    padding: 12px 20px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: white;
}

.section-header h4 {
    font-size: 15px;
    color: #666;
    margin: 0;
    font-weight: 600;
}

#example-code {
    flex: 1;
    overflow: auto;
    padding: 20px;
    font-family: 'Menlo', 'Monaco', 'Consolas', monospace;
    font-size: 14px;
    line-height: 1.6;
    background: #f8f9fa;
    white-space: pre-wrap;
    word-break: break-word;
    margin: 0;
}

/* 练习内容 */
.practice-instructions {
    padding: 20px;
    border-bottom: 1px solid var(--border-color);
    background: white;
}

.practice-instructions h3 {
    font-size: 20px;
    margin-bottom: 16px;
    color: var(--dark-color);
    font-weight: 600;
}

#task-list {
    padding-left: 20px;
}

#task-list li {
    margin-bottom: 10px;
    font-size: 15px;
    color: #555;
    line-height: 1.6;
    position: relative;
}

#task-list li:before {
    content: "•";
    color: var(--primary-color);
    font-weight: bold;
    display: inline-block;
    width: 1em;
    margin-left: -1em;
}

.code-editor {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: #f8f9fa;
    min-height: 250px;
}

#code-editor {
    flex: 1;
    width: 100%;
    padding: 20px;
    border: none;
    resize: none;
    font-family: 'Menlo', 'Monaco', 'Consolas', monospace;
    font-size: 14px;
    line-height: 1.6;
    background: white;
    outline: none;
    -webkit-user-select: text;
    user-select: text;
}

.practice-hint {
    padding: 20px;
    border-top: 1px solid var(--border-color);
    background: white;
}

#hint-text {
    font-size: 15px;
    line-height: 1.6;
    color: #555;
    background: #f0f9ff;
    padding: 16px;
    border-radius: var(--radius-sm);
    border-left: 4px solid var(--primary-color);
    margin-top: 8px;
}

/* 底部导航 */
.app-footer {
    background: white;
    border-top: 1px solid var(--border-color);
    padding: 16px;
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.05);
    position: relative;
    z-index: 100;
    height: 120px;
}

.footer-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}

.nav-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 20px;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: var(--radius);
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    min-width: 100px;
    justify-content: center;
}

.nav-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    background: #adb5bd;
    transform: none !important;
}

.nav-btn:not(:disabled):hover,
.nav-btn:not(:disabled):active {
    background: var(--secondary-color);
    transform: translateY(-2px);
}

.nav-btn svg {
    pointer-events: none;
}

.step-info {
    text-align: center;
    max-width: 200px;
}

#step-title {
    font-size: 15px;
    font-weight: 600;
    color: var(--dark-color);
    display: block;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 4px;
}

.step-indicator {
    font-size: 13px;
    color: #666;
}

.swipe-hint {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    font-size: 13px;
    color: #666;
    padding: 8px;
    animation: pulse 2s infinite;
    opacity: 0.7;
}

.swipe-hint svg {
    animation: swipeHint 1.5s infinite alternate;
}

/* 动画效果 */
@keyframes pulse {
    0%, 100% { opacity: 0.7; }
    50% { opacity: 1; }
}

@keyframes swipeHint {
    0% { transform: translateX(0); }
    100% { transform: translateX(10px); }
}

@keyframes slideIn {
    from { transform: translateY(20px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.fade-in {
    animation: fadeIn 0.3s ease;
}

.slide-in {
    animation: slideIn 0.3s ease;
}

/* 触摸反馈 */
.touch-active {
    transition: transform 0.1s ease;
}

.touch-active:active {
    transform: scale(0.95);
}

/* 滑动提示覆盖层 */
.swipe-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.9);
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    flex-direction: column;
    gap: 30px;
    animation: fadeIn 0.3s ease;
}

.swipe-gesture {
    width: 120px;
    height: 120px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: pulse 2s infinite;
}

/* 响应式设计 */
@media (max-width: 767px) {
    .pages-container {
        height: calc(100vh - 180px);
    }
}

@media (min-width: 768px) {
    .pages-container {
        display: flex;
        height: 100vh;
        position: static;
        overflow: visible;
    }
    
    .page {
        position: relative;
        width: 50%;
        height: 100%;
        transform: none !important;
        display: flex;
        box-shadow: none;
        border-right: 1px solid var(--border-color);
    }
    
    .page:last-child {
        border-right: none;
    }
    
    .swipe-hint {
        display: none;
    }
}

/* 代码高亮样式覆盖 */
.hljs {
    background: transparent !important;
    padding: 0 !important;
}

pre code {
    display: block;
    padding: 20px !important;
    border-radius: var(--radius) !important;
    background: white !important;
    border: 1px solid #e1e4e8 !important;
    overflow-x: auto;
    font-size: 14px !important;
    line-height: 1.6 !important;
}

/* 滚动条样式 */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 3px;
}

::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: #a8a8a8;
}
