/* 基础样式 */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary-color: #007AFF;
    --secondary-color: #34C759;
    --accent-color: #FF9500;
    --danger-color: #FF3B30;
    --bg-color: #F2F2F7;
    --card-bg: #FFFFFF;
    --text-primary: #000000;
    --text-secondary: #8E8E93;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--bg-color);
    color: var(--text-primary);
    min-height: 100vh;
    overflow-x: hidden;
}

#app {
    max-width: 480px;
    margin: 0 auto;
    min-height: 100vh;
    position: relative;
}

/* 页面切换 */
.page {
    display: none;
    min-height: 100vh;
    padding: 20px;
    animation: fadeIn 0.3s ease;
}

.page.active {
    display: block;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* 首页样式 */
.header {
    text-align: center;
    padding: 40px 0;
}

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

h1 {
    font-size: 28px;
    font-weight: 700;
    margin-bottom: 8px;
}

.subtitle {
    color: var(--text-secondary);
    font-size: 14px;
}

/* 操作按钮 */
.actions {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 24px;
}

.action-btn {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 16px;
    border: none;
    border-radius: 12px;
    background: var(--card-bg);
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    width: 100%;
    text-align: left;
}

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

.action-btn.primary {
    border-left: 4px solid var(--primary-color);
}

.action-btn.secondary {
    border-left: 4px solid var(--secondary-color);
}

.action-btn.accent {
    border-left: 4px solid var(--accent-color);
}

.action-btn.danger {
    border-left: 4px solid var(--danger-color);
}

.btn-icon {
    font-size: 32px;
    width: 50px;
    height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0,122,255,0.1);
    border-radius: 12px;
}

.btn-text {
    display: flex;
    flex-direction: column;
    flex: 1;
}

.btn-title {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
}

.btn-desc {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 2px;
}

/* 使用说明 */
.instructions {
    background: var(--card-bg);
    padding: 20px;
    border-radius: 16px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.instructions h3 {
    font-size: 16px;
    margin-bottom: 16px;
}

.instruction-item {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 12px;
    font-size: 14px;
    color: var(--text-secondary);
}

.instruction-item:last-child {
    margin-bottom: 0;
}

.num {
    width: 24px;
    height: 24px;
    background: var(--primary-color);
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 600;
}

/* 页面头部 */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 0 20px;
    margin: -20px -20px 20px;
    padding: 20px;
    background: var(--card-bg);
    position: sticky;
    top: 0;
    z-index: 100;
}

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

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

.page-header h2 {
    font-size: 18px;
    font-weight: 600;
}

/* 相机页面 */
.camera-container {
    position: relative;
    background: #000;
    border-radius: 16px;
    overflow: hidden;
    margin-bottom: 20px;
}

#camera-video, #captured-image {
    width: 100%;
    height: 400px;
    object-fit: cover;
    display: block;
}

#camera-canvas {
    width: 100%;
    height: auto;
}

.camera-controls {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 20px;
    padding: 20px;
    background: rgba(0,0,0,0.8);
}

.capture-btn {
    width: 70px;
    height: 70px;
    border-radius: 50%;
    background: white;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

.capture-circle {
    width: 60px;
    height: 60px;
    border: 3px solid var(--primary-color);
    border-radius: 50%;
}

.camera-controls button {
    background: var(--primary-color);
    color: white;
    border: none;
    padding: 12px 24px;
    border-radius: 8px;
    font-size: 14px;
    cursor: pointer;
}

/* 词汇选择页面 */
.selection-container {
    position: relative;
    margin-bottom: 20px;
}

.image-container {
    position: relative;
    border-radius: 12px;
    overflow: hidden;
    background: #000;
}

#selection-image {
    width: 100%;
    height: auto;
    display: block;
}

.selection-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    pointer-events: none;
}

.text-box {
    position: absolute;
    border: 2px solid rgba(255,193,7,0.6);
    background: rgba(255,193,7,0.2);
    cursor: pointer;
    pointer-events: auto;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.text-box.selected {
    border-color: var(--primary-color);
    background: rgba(0,122,255,0.3);
}

.text-box span {
    background: rgba(255,193,7,0.9);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 12px;
    font-weight: 500;
}

.text-box.selected span {
    background: var(--primary-color);
    color: white;
}

.selection-controls {
    background: var(--card-bg);
    padding: 16px;
    border-radius: 12px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.selection-info {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 12px;
    text-align: center;
}

#selected-count {
    color: var(--primary-color);
}

.selection-buttons {
    display: flex;
    gap: 8px;
}

.selection-buttons button {
    flex: 1;
    padding: 12px;
    border: none;
    border-radius: 8px;
    background: var(--bg-color);
    font-size: 14px;
    cursor: pointer;
}

.selection-buttons button:first-child {
    background: var(--primary-color);
    color: white;
}

/* 听写页面 */
.progress-bar {
    height: 8px;
    background: rgba(0,0,0,0.1);
    border-radius: 4px;
    overflow: hidden;
    margin-bottom: 8px;
}

.progress-fill {
    height: 100%;
    background: var(--primary-color);
    border-radius: 4px;
    transition: width 0.3s ease;
    width: 0%;
}

.progress-text {
    display: flex;
    justify-content: space-between;
    font-size: 14px;
    color: var(--text-secondary);
    margin-bottom: 30px;
}

.dictation-main {
    text-align: center;
    padding: 40px 0;
    min-height: 200px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.current-word {
    font-size: 72px;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 20px;
    min-height: 100px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--card-bg);
    padding: 30px;
    border-radius: 20px;
    width: 100%;
}

.command-feedback {
    font-size: 18px;
    color: var(--primary-color);
    padding: 8px 16px;
    background: rgba(0,122,255,0.1);
    border-radius: 20px;
    animation: popIn 0.3s ease;
}

@keyframes popIn {
    from { transform: scale(0.8); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

/* 语音提示 */
.voice-hints {
    background: var(--card-bg);
    padding: 20px;
    border-radius: 16px;
    margin-bottom: 20px;
    text-align: center;
}

.voice-hints h3 {
    font-size: 14px;
    color: var(--text-secondary);
    margin-bottom: 12px;
}

.hints {
    display: flex;
    gap: 12px;
    justify-content: center;
    flex-wrap: wrap;
}

.hint {
    background: rgba(0,122,255,0.1);
    color: var(--primary-color);
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 14px;
    font-weight: 500;
}

.listening-indicator {
    margin-top: 12px;
    color: var(--secondary-color);
    font-size: 14px;
}

.wave {
    animation: wave 1s ease-in-out infinite;
}

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

/* 听写控制 */
.dictation-controls {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 20px;
    margin-bottom: 16px;
}

.control-btn {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    border: none;
    background: var(--bg-color);
    font-size: 24px;
    cursor: pointer;
    transition: transform 0.2s;
}

.control-btn:active {
    transform: scale(0.95);
}

.control-btn.play {
    width: 80px;
    height: 80px;
    background: var(--secondary-color);
    font-size: 32px;
}

.manual-controls {
    display: flex;
    gap: 12px;
}

.manual-controls button {
    flex: 1;
    padding: 14px;
    border: none;
    border-radius: 12px;
    background: var(--bg-color);
    font-size: 14px;
    cursor: pointer;
}

.manual-controls button.primary {
    background: var(--primary-color);
    color: white;
}

/* 弹窗 */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 20px;
}

.modal-content {
    background: var(--card-bg);
    padding: 24px;
    border-radius: 16px;
    width: 100%;
    max-width: 360px;
}

.modal-content h3 {
    margin-bottom: 20px;
    font-size: 18px;
}

.setting-item {
    margin-bottom: 20px;
}

.setting-item label {
    display: block;
    font-size: 14px;
    margin-bottom: 8px;
    color: var(--text-secondary);
}

.setting-item input[type="range"] {
    width: 100%;
    margin-bottom: 4px;
}

.setting-item select {
    width: 100%;
    padding: 10px;
    border-radius: 8px;
    border: 1px solid rgba(0,0,0,0.1);
    font-size: 14px;
}

.modal-content button {
    width: 100%;
    padding: 14px;
    border: none;
    border-radius: 12px;
    background: var(--primary-color);
    color: white;
    font-size: 16px;
    cursor: pointer;
    margin-top: 8px;
}

#manual-word-input {
    width: 100%;
    padding: 12px;
    border: 1px solid rgba(0,0,0,0.1);
    border-radius: 8px;
    font-size: 16px;
    margin-bottom: 16px;
}

.modal-buttons {
    display: flex;
    gap: 12px;
}

.modal-buttons button {
    flex: 1;
    margin-top: 0;
}

.modal-buttons button:first-child {
    background: var(--bg-color);
    color: var(--text-primary);
}

/* 加载动画 */
.loading {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255,255,255,0.95);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.spinner {
    width: 50px;
    height: 50px;
    border: 4px solid rgba(0,122,255,0.1);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 16px;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.loading p {
    color: var(--text-secondary);
}

/* 工具类 */
.hidden {
    display: none !important;
}

/* 响应式 */
@media (max-width: 380px) {
    .current-word {
        font-size: 48px;
        padding: 20px;
    }

    .btn-title {
        font-size: 14px;
    }

    .btn-desc {
        font-size: 11px;
    }
}
