/**
 * 全局样式
 *
 * 双端布局策略：
 *   - 手机端（@media max-width: 768px）：全屏占满，像手机 app
 *   - 电脑端（@media min-width: 769px）：去掉手机框外壳，内容区居中（最大 560px），两侧灰边，符合 web 习惯
 *   - standalone（PWA/APK 全屏模式）：按平台自动适配
 */
* { box-sizing: border-box; }
body {
    background: #f0f2f5;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    margin: 0;
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: stretch; /* 电脑端：顶到底 */
    padding: 0;
}

/* ============ 默认布局：电脑端 web 风格（去掉手机框） ============ */
.phone-frame {
    width: 100%;
    max-width: 560px;      /* web 风格：居中，内容不超过 560px（类似 ChatGPT web 对话宽度） */
    height: 100vh;
    height: 100dvh;
    background: #ffffff;
    border-radius: 0;     /* 去掉手机圆角 */
    box-shadow: none;     /* 去掉手机阴影 */
    border-left: 1px solid #ececec;
    border-right: 1px solid #ececec;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    position: relative;
}

/* ============ 假状态栏：电脑端隐藏 ============ */
.status-bar {
    padding: 12px 20px 6px;
    display: none;
    justify-content: space-between;
    font-size: 12px;
    font-weight: 600;
    color: #1a1a1a;
    background: #fff;
    flex-shrink: 0;
}
.app-header {
    padding: 8px 20px 12px;
    border-bottom: 1px solid #f0f0f0;
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
    background: #fff;
}
.app-header .avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    object-fit: cover;
    box-shadow: 0 2px 8px rgba(79, 70, 229, 0.3);
}
.app-header .title { font-size: 18px; font-weight: 700; color: #1a1a1a; }
.app-header .subtitle { font-size: 12px; color: #8c8c8c; }
.app-header .badge {
    margin-left: auto;
    background: #e6f7ff;
    color: #1890ff;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 600;
}
.chat-area {
    flex: 1;
    overflow-y: auto;
    padding: 16px 16px 8px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    background: #fafafa;
    scroll-behavior: smooth;
}
.chat-area::-webkit-scrollbar { width: 4px; }
.chat-area::-webkit-scrollbar-thumb { background: #d9d9d9; border-radius: 4px; }

/* 进度指示器 */
.progress-indicator {
    background: linear-gradient(135deg, #e6f7ff 0%, #f0f5ff 100%);
    border: 1px solid #bae0ff;
    border-radius: 12px;
    padding: 10px 14px;
    margin-bottom: 8px;
    font-size: 13px;
}
.progress-label { font-weight: 600; color: #1890ff; margin-right: 8px; }
.progress-bar-wrapper {
    display: inline-block;
    width: 100px;
    height: 8px;
    background: #e8e8e8;
    border-radius: 4px;
    overflow: hidden;
    vertical-align: middle;
    margin: 0 8px;
}
.progress-bar {
    height: 100%;
    background: linear-gradient(90deg, #52c41a, #1890ff);
    border-radius: 4px;
    transition: width 0.3s ease;
}
.progress-text { color: #666; font-size: 12px; }
.progress-items {
    margin-top: 6px;
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}
.progress-item {
    font-size: 12px;
    padding: 2px 8px;
    border-radius: 10px;
}
.progress-item.done {
    background: #f6ffed;
    color: #52c41a;
    border: 1px solid #b7eb8f;
}
.progress-item.current {
    background: #fff7e6;
    color: #fa8c16;
    border: 1px solid #ffd591;
    animation: pulse 1.5s infinite;
}
@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}

/* 解答消息样式 */
.solution-message {
    background: linear-gradient(135deg, #fffbe6 0%, #fff7e6 100%) !important;
    border: 2px solid #ffd591 !important;
    border-radius: 16px !important;
    padding: 16px 20px !important;
    font-size: 14px !important;
    line-height: 1.8 !important;
    max-width: 100% !important;
    white-space: pre-wrap;
    word-break: break-word;
}
.solution-message::before {
    content: '📖 ';
    font-size: 16px;
}
.message {
    max-width: 88%;
    padding: 12px 16px;
    border-radius: 18px;
    font-size: 15px;
    line-height: 1.6;
    word-break: break-word;
    animation: fadeIn 0.3s ease;
    position: relative;
}
.message.user {
    align-self: flex-end;
    background: #4f46e5;
    color: #fff;
    border-bottom-right-radius: 4px;
}
.message.assistant {
    align-self: flex-start;
    background: #ffffff;
    color: #1a1a1a;
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.06);
}
.message.system {
    align-self: center;
    background: #f0f0f0;
    color: #666;
    font-size: 13px;
    padding: 8px 16px;
    border-radius: 20px;
    max-width: 90%;
}
.message .msg-time { font-size: 10px; color: #999; margin-top: 4px; text-align: right; }
.message.user .msg-time { color: rgba(255,255,255,0.7); }
.message .image-preview { max-width: 100%; max-height: 180px; border-radius: 12px; margin-top: 6px; border: 1px solid #e8e8e8; }
.message .file-name { font-size: 12px; color: #8c8c8c; margin-top: 4px; }
.message .thinking-indicator { display: flex; gap: 6px; padding: 4px 0; }

/* 子问题编号标签 */
.message.assistant .sub-question-tag {
    display: inline-block;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: #fff;
    font-size: 12px;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 10px;
    margin-right: 6px;
}
.message .thinking-indicator span {
    width: 8px;
    height: 8px;
    background: #bfbfbf;
    border-radius: 50%;
    animation: bounce 1.2s infinite ease-in-out;
}
.message .thinking-indicator span:nth-child(2) { animation-delay: 0.2s; }
.message .thinking-indicator span:nth-child(3) { animation-delay: 0.4s; }
@keyframes bounce { 0%,80%,100% { transform: scale(0.6); opacity: 0.4; } 40% { transform: scale(1); opacity: 1; } }
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

.input-area {
    padding: 10px 16px 16px;
    background: #fff;
    border-top: 1px solid #f0f0f0;
    display: flex;
    align-items: flex-end;
    gap: 10px;
    flex-shrink: 0;
    flex-wrap: wrap;
}
.input-area .input-wrapper {
    flex: 1;
    display: flex;
    align-items: flex-end;
    background: #f5f5f5;
    border-radius: 24px;
    padding: 4px 4px 4px 16px;
    border: 1px solid transparent;
    transition: border 0.2s;
    min-width: 120px;
}
.input-area .input-wrapper:focus-within { border-color: #4f46e5; background: #fff; }
.input-area textarea {
    flex: 1;
    border: none;
    outline: none;
    resize: none;
    font-size: 15px;
    padding: 8px 0;
    background: transparent;
    max-height: 100px;
    min-height: 40px;
    font-family: inherit;
}
.input-area textarea::placeholder { color: #bfbfbf; }
.input-area .action-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: none;
    background: transparent;
    color: #8c8c8c;
    font-size: 20px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
}
.input-area .action-btn:hover { background: #f0f0f0; }
.input-area .action-btn.primary { background: #4f46e5; color: #fff; }
.input-area .action-btn.primary:hover { background: #4338ca; }
.input-area .action-btn.primary:disabled { opacity: 0.5; cursor: not-allowed; }
.input-area .action-btn.camera { color: #4f46e5; }
.input-area .action-btn.camera:hover { background: #eef2ff; }
.input-area .action-btn.keyboard {
    color: #10b981;
    position: relative;
}
.input-area .action-btn.keyboard:hover { background: #d1fae5; }
.input-area .action-btn.keyboard:disabled { opacity: 0.5; cursor: not-allowed; }

.voice-press-wrapper {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 120px;
    margin-right: 14px;
}
.voice-press-btn {
    flex: 1;
    height: 40px;
    background: #f5f5f5;
    border-radius: 24px;
    border: 2px solid transparent;
    font-size: 15px;
    color: #333;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: all 0.15s ease;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
    touch-action: manipulation;
}
.voice-press-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}
.voice-press-btn i { font-size: 18px; color: #10b981; transition: color 0.15s; }
.voice-press-btn.recording {
    background: #fee2e2;
    border-color: #ef4444;
    color: #ef4444;
}
.voice-press-btn.recording i { color: #ef4444; animation: mic-pulse 1s ease-in-out infinite; }
.voice-press-btn.recording .voice-press-text::before { content: '松开 发送'; }
.voice-press-btn.recording .voice-press-text-default { display: none; }
.voice-press-btn.recording .voice-press-text { color: #ef4444; }
.voice-press-btn:active:not(:disabled) { transform: scale(0.97); }

.voice-toggle { width: 36px; height: 36px; font-size: 16px; }

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

#fileInput { display: none; }

.step-indicator {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 4px 44px 8px 12px;
    font-size: 12px;
    color: #8c8c8c;
    flex-shrink: 0;
    background: #fff;
    position: relative;
    flex-wrap: nowrap;
    overflow: hidden;
}
.step-indicator .dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #d9d9d9;
}
.step-indicator .dot.active { background: #4f46e5; width: 18px; border-radius: 4px; }
.step-indicator .dot.done { background: #52c41a; }
.step-indicator .label { margin: 0 8px; font-weight: 500; color: #1a1a1a; flex-shrink: 0; }

.step-indicator .step-end-btn {
    font-size: 12px;
    padding: 4px 12px;
    border-radius: 14px;
    background: linear-gradient(135deg, #f97316, #ea580c);
    color: #fff;
    border: none;
    cursor: pointer;
    white-space: nowrap;
    box-shadow: 0 2px 6px rgba(249, 115, 22, 0.3);
    margin: 0 4px;
    flex-shrink: 0;
    transition: transform 0.15s, box-shadow 0.15s;
}
.step-indicator .step-end-btn:active { transform: scale(0.96); box-shadow: 0 3px 10px rgba(249, 115, 22, 0.45); }

/* 固定题目展示区域 */
.problem-display {
    margin: 0 16px 8px;
    background: linear-gradient(135deg, #f0f5ff 0%, #f5f0ff 100%);
    border: 1px solid #d6e4ff;
    border-radius: 12px;
    overflow: hidden;
    flex-shrink: 0;
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.08);
    transition: box-shadow 0.2s;
}
.problem-display-header {
    display: flex;
    align-items: center;
    padding: 8px 12px;
    background: rgba(102, 126, 234, 0.08);
    cursor: pointer;
    user-select: none;
}
.problem-display-header:hover {
    background: rgba(102, 126, 234, 0.12);
}
.problem-icon {
    font-size: 14px;
    margin-right: 6px;
}
.problem-title {
    font-size: 13px;
    font-weight: 600;
    color: #4f46e5;
}
/* 题目栏 header 内的紧凑进度条（与题目同一行） */
.progress-header-inline {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    margin: 0 6px;
    vertical-align: middle;
}
.progress-bar-wrapper.compact {
    width: 50px;
    height: 6px;
    background: #e8e8e8;
    border-radius: 3px;
    overflow: hidden;
}
.progress-bar-wrapper.compact .progress-bar {
    height: 100%;
    background: linear-gradient(90deg, #10b981, #6366f1);
    border-radius: 3px;
    transition: width 0.3s ease;
}
.progress-compact-text {
    font-size: 11px;
    color: #667eea;
    font-weight: 500;
    white-space: nowrap;
}
.progress-items-row {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 6px 12px;
    background: rgba(102, 126, 234, 0.04);
}
.problem-collapse-btn {
    width: 24px;
    height: 24px;
    border: none;
    background: rgba(102, 126, 234, 0.15);
    border-radius: 50%;
    cursor: pointer;
    font-size: 10px;
    color: #667eea;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s;
}
.problem-collapse-btn:hover {
    background: rgba(102, 126, 234, 0.25);
}
.problem-display.collapsed .problem-collapse-btn {
    transform: rotate(-90deg);
}
.problem-display-body {
    padding: 12px;
    font-size: 14px;
    line-height: 1.7;
    color: #1a1a1a;
    max-height: 150px;
    overflow-y: auto;
    white-space: pre-wrap;
    word-break: break-word;
    transition: max-height 0.3s ease;
}
.problem-display.collapsed .problem-display-body {
    max-height: 0;
    padding-top: 0;
    padding-bottom: 0;
    overflow: hidden;
}
/* 题目栏折叠时，画板不再受影响（已移出 problem-display） */
.problem-display-body::-webkit-scrollbar {
    width: 3px;
}
.problem-display-body::-webkit-scrollbar-thumb {
    background: #d6e4ff;
    border-radius: 2px;
}
.problem-display-body .katex {
    font-size: 1em;
}

.voice-indicator {
    position: absolute;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0,0,0,0.7);
    color: #fff;
    padding: 8px 20px;
    border-radius: 30px;
    font-size: 14px;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.3s;
    z-index: 10;
}
.voice-indicator.show { opacity: 1; }

/* 光标 */
.typing-cursor::after {
    content: '▋';
    animation: blink 1s step-end infinite;
    color: #4f46e5;
}
@keyframes blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0; }
}

/* 数学可视化面板 */
/* 画板切换按钮：浮动圆形 FAB，在进度条区域右侧 */
.math-toggle-fab {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: linear-gradient(135deg, #6366f1, #8b5cf6);
    color: #fff;
    border: none;
    cursor: pointer;
    font-size: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 8px rgba(99, 102, 241, 0.4);
    transition: all 0.2s;
    z-index: 50;
}
.math-toggle-fab:active { transform: translateY(-50%) scale(0.9); }
.math-toggle-fab.show { background: linear-gradient(135deg, #10b981, #059669); box-shadow: 0 2px 8px rgba(16, 185, 129, 0.4); }
.math-toggle-fab.has-image::after {
    content: '';
    position: absolute;
    top: -2px;
    right: -2px;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #ef4444;
    border: 2px solid #fff;
    box-shadow: 0 0 0 2px rgba(239, 68, 68, 0.3);
}

/* 画板面板：独立浮动窗口，可拖动折叠 */
.math-panel {
    position: absolute;
    left: 12px;
    right: 12px;
    top: 60px;
    height: 50%;
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.18);
    z-index: 99;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    transform: translateY(-110%);
    opacity: 0;
    pointer-events: none;
    transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.2s ease;
}
.math-panel.open {
    transform: translateY(0);
    opacity: 1;
    pointer-events: auto;
}
.math-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    border-bottom: 1px solid #f0f0f0;
    flex-shrink: 0;
    cursor: grab;
    user-select: none;
    background: #fafbfc;
}
.math-panel-header:active { cursor: grabbing; }
.math-panel-header .title {
    font-size: 14px;
    font-weight: 600;
    color: #1a1a1a;
    display: flex;
    align-items: center;
    gap: 6px;
}
.math-panel-header .close-btn {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: #f5f5f5;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #666;
    font-size: 14px;
}
.math-panel-header .close-btn:hover { background: #fee2e2; color: #dc2626; }
.math-panel-body { flex: 1; overflow: hidden; position: relative; background: #fafbfc; }
.math-panel-body svg { width: 100%; height: 100%; display: block; }
.math-panel-toolbar {
    display: flex;
    gap: 6px;
    padding: 8px 12px;
    border-top: 1px solid #f0f0f0;
    flex-shrink: 0;
    overflow-x: auto;
}
.math-panel-toolbar .tool-btn {
    padding: 6px 12px;
    border-radius: 16px;
    border: 1px solid #e8e8e8;
    background: #fff;
    font-size: 12px;
    color: #666;
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.2s;
}
.math-panel-toolbar .tool-btn.active {
    background: #4f46e5;
    color: #fff;
    border-color: #4f46e5;
}
.math-panel-toolbar .tool-btn:hover { border-color: #4f46e5; color: #4f46e5; }

/* ============ 相机/相册 选择弹窗 ============ */
.source-sheet-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 1000;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    padding: 16px;
    animation: modal-fade-in 0.2s ease;
    backdrop-filter: blur(2px);
}
.source-sheet {
    width: 100%;
    max-width: 420px;
    background: #fff;
    border-radius: 16px;
    padding: 16px;
    animation: sheet-slide-up 0.25s ease;
    box-shadow: 0 20px 60px rgba(0,0,0,0.25);
}
.source-sheet-title {
    text-align: center;
    font-size: 15px;
    font-weight: 600;
    color: #1a1a1a;
    margin-bottom: 14px;
}
.source-sheet-body {
    display: flex;
    gap: 10px;
}
.source-btn {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 18px 10px;
    border: 1.5px solid #e8e8e8;
    border-radius: 14px;
    background: #fafafa;
    font-size: 13px;
    color: #333;
    cursor: pointer;
    transition: all 0.15s;
}
.source-btn:active {
    transform: scale(0.96);
    background: #eef2ff;
    border-color: #4f46e5;
}
.source-btn i {
    font-size: 26px;
    color: #4f46e5;
}
.source-sheet-cancel {
    width: 100%;
    margin-top: 12px;
    padding: 10px;
    border: none;
    border-radius: 10px;
    background: #f5f5f5;
    color: #666;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s;
}
.source-sheet-cancel:active { background: #e8e8e8; }

@keyframes sheet-slide-up {
    from { transform: translateY(40px); opacity: 0; }
    to   { transform: translateY(0);    opacity: 1; }
}
.math-legend {
    display: flex;
    gap: 12px;
    padding: 6px 16px;
    font-size: 11px;
    color: #666;
    flex-shrink: 0;
    flex-wrap: wrap;
}
.math-legend .item { display: flex; align-items: center; gap: 4px; }
.math-legend .dot { width: 10px; height: 10px; border-radius: 50%; }
.math-mode-indicator {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 11px;
    font-weight: 500;
    padding: 2px 8px;
    border-radius: 10px;
    margin-left: 8px;
}
.math-mode-indicator.coordinate { background: #e0e7ff; color: #4f46e5; }
.math-mode-indicator.geometry { background: #fef3c7; color: #d97706; }
.math-mode-indicator.hybrid { background: #fce7f3; color: #db2777; }
.subq-tag {
    display: inline-block;
    padding: 1px 6px;
    border-radius: 8px;
    font-size: 10px;
    margin-left: 4px;
}
.subq-tag.completed { background: #d1fae5; color: #059669; }
.subq-tag.current { background: #dbeafe; color: #2563eb; }
.empty-canvas {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: #999;
    font-size: 14px;
}

@media (max-width: 440px) {
    .phone-frame {
        border-radius: 0;
        height: 100vh;
        max-height: 100vh;
        padding: 0;
        box-shadow: none;
    }
    body { padding: 0; }
    .status-bar { padding: 8px 16px 4px; font-size: 11px; }
    .app-header { padding: 6px 16px 10px; }
    .chat-area { padding: 12px 12px 4px; }
    .message { font-size: 14px; padding: 10px 14px; }
    .input-area { padding: 8px 12px 12px; }
    .input-area .action-btn.end-btn { font-size: 12px; padding: 0 12px; }
}

/* 解析展示确认模态框（第 4 次认错后确认查看解析） */
.solution-confirm-modal {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,0.45);
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}
.solution-confirm-box {
    background: #fff;
    border-radius: 20px;
    padding: 20px 22px;
    max-width: 320px;
    box-shadow: 0 20px 40px rgba(0,0,0,0.25);
}
.solution-confirm-box h4 {
    margin: 0 0 10px;
    font-size: 16px;
    color: #1a1a1a;
}
.solution-confirm-box p {
    margin: 0 0 18px;
    font-size: 13px;
    color: #666;
    line-height: 1.6;
}
.solution-confirm-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
}
.solution-confirm-actions button {
    border: none;
    padding: 8px 18px;
    border-radius: 20px;
    font-size: 13px;
    cursor: pointer;
    font-weight: 600;
}
.solution-confirm-actions .btn-cancel {
    background: #f5f5f5;
    color: #666;
}
.solution-confirm-actions .btn-ok {
    background: #f59e0b;
    color: #fff;
}

/* ============ 全局原生 app 化优化 ============ */
/* 禁用长按弹出菜单（复制/选择等浏览器默认行为） */
* {
    -webkit-touch-callout: none;
    -webkit-tap-highlight-color: transparent;
}
/* 输入框和文本域允许选择文字 */
textarea, input {
    -webkit-touch-callout: default;
    -webkit-user-select: text;
    user-select: text;
}
/* 禁用非输入区域的文字选择 */
body {
    -webkit-user-select: none;
    user-select: none;
    -webkit-font-smoothing: antialiased;
    /* 禁用 iOS 橡皮筋滚动 */
    overscroll-behavior: none;
}

/* 按钮触摸反馈：按下时缩放 + 透明度，模拟原生水波纹 */
.action-btn, .tool-btn, .problem-collapse-btn {
    -webkit-tap-highlight-color: transparent;
    transition: transform 0.1s ease, opacity 0.1s ease, background 0.15s ease;
}
.action-btn:active, .tool-btn:active {
    transform: scale(0.92);
    opacity: 0.75;
}

/* ============ PWA standalone 模式（从桌面图标打开时） ============ */
@media (display-mode: standalone), (display-mode: fullscreen), (display-mode: minimal-ui) {
    html, body {
        margin: 0;
        padding: 0;
        width: 100%;
        height: 100%;
        background: #ffffff;
        overflow: hidden;
    }
    body {
        align-items: stretch;
        justify-content: stretch;
    }
    .phone-frame {
        max-width: 100%;
        width: 100%;
        height: 100vh;
        height: 100dvh;
        max-height: 100vh;
        max-height: 100dvh;
        border-radius: 0;
        box-shadow: none;
        border: none;
    }
    /* standalone 模式下隐藏假的手机状态栏（真实手机已有系统状态栏） */
    .status-bar {
        display: none;
    }
    /* 顶部留出刘海/灵动岛安全区 */
    .app-header {
        padding-top: max(8px, env(safe-area-inset-top));
        padding-left: max(20px, env(safe-area-inset-left));
        padding-right: max(20px, env(safe-area-inset-right));
    }
    /* 底部 home indicator 安全区 */
    .input-area {
        padding-bottom: max(12px, env(safe-area-inset-bottom));
        padding-left: max(16px, env(safe-area-inset-left));
        padding-right: max(16px, env(safe-area-inset-right));
    }
    /* 数学面板内嵌在题目栏中，无需安全区适配 */
}

/* PWA 安装悬浮按钮样式（由 JS 动态创建，这里给基础样式作兜底） */
.pwa-install-btn {
    position: fixed;
    bottom: 80px;
    right: 16px;
    z-index: 9999;
    background: #4f46e5;
    color: #fff;
    border: none;
    padding: 10px 16px;
    border-radius: 24px;
    font-size: 14px;
    font-weight: 600;
    box-shadow: 0 4px 12px rgba(79, 70, 229, 0.4);
    cursor: pointer;
    animation: pwa-install-pulse 2s infinite;
}
@keyframes pwa-install-pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.05); }
}

/* ============ 头部设置按钮 ============ */
.header-settings-btn {
    margin-left: auto;
    margin-right: 8px;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: none;
    background: #f0f0f0;
    color: #666;
    font-size: 15px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s;
    flex-shrink: 0;
}
.header-settings-btn:hover {
    background: #e0e0e0;
    transform: rotate(30deg);
}
.header-settings-btn:active {
    transform: scale(0.9);
}

/* ============ 设置/首次启动 弹窗通用样式 ============ */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    animation: modal-fade-in 0.2s ease;
    backdrop-filter: blur(4px);
}
@keyframes modal-fade-in {
    from { opacity: 0; }
    to { opacity: 1; }
}
.modal-box {
    background: #fff;
    border-radius: 16px;
    width: 100%;
    max-width: 420px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
    animation: modal-slide-up 0.25s ease;
    overflow: hidden;
}
@keyframes modal-slide-up {
    from { transform: translateY(30px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}
.modal-header {
    padding: 16px 20px;
    border-bottom: 1px solid #f0f0f0;
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.modal-title {
    font-size: 17px;
    font-weight: 700;
    color: #1a1a1a;
}
.modal-close {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: none;
    background: #f5f5f5;
    color: #666;
    font-size: 14px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}
.modal-close:hover { background: #e8e8e8; }
.modal-body {
    padding: 20px;
}
.modal-label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: #555;
    margin-bottom: 8px;
}
.modal-input {
    width: 100%;
    padding: 12px 14px;
    border: 1.5px solid #e0e0e0;
    border-radius: 10px;
    font-size: 15px;
    outline: none;
    transition: border-color 0.15s;
    box-sizing: border-box;
}
.modal-input:focus {
    border-color: #4f46e5;
}
.modal-input:disabled {
    background: #f5f5f5;
    color: #999;
}
.modal-hint {
    margin-top: 10px;
    padding: 10px 12px;
    background: #f8f9ff;
    border-radius: 8px;
    font-size: 12.5px;
    color: #666;
    line-height: 1.7;
}
.modal-hint code {
    background: #eef2ff;
    color: #4f46e5;
    padding: 1px 6px;
    border-radius: 4px;
    font-family: Consolas, Monaco, monospace;
    font-size: 12px;
}
.modal-status {
    margin-top: 10px;
    padding: 10px 12px;
    border-radius: 8px;
    font-size: 13px;
}
.modal-status.ok {
    background: #f6ffed;
    color: #389e0d;
    border: 1px solid #b7eb8f;
}
.modal-status.err {
    background: #fff1f0;
    color: #cf1322;
    border: 1px solid #ffa39e;
}
.modal-tip {
    padding: 12px 14px;
    background: linear-gradient(135deg, #eef2ff 0%, #f5f0ff 100%);
    border-radius: 10px;
    font-size: 14px;
    line-height: 1.7;
    margin-bottom: 14px;
    color: #333;
}
.modal-footer {
    padding: 12px 20px 16px;
    display: flex;
    gap: 10px;
    border-top: 1px solid #f8f8f8;
}
.modal-btn {
    flex: 1;
    padding: 10px 0;
    border-radius: 10px;
    border: none;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s;
}
.modal-btn:active { transform: scale(0.97); }
.modal-btn.primary {
    background: #4f46e5;
    color: #fff;
}
.modal-btn.primary:hover { background: #4338ca; }
.modal-btn.primary:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}
.modal-btn.secondary {
    background: #f0f0f0;
    color: #555;
}
.modal-btn.secondary:hover { background: #e5e5e5; }
.modal-btn.full {
    width: 100%;
    flex: none;
}

/* ============ 手机端（窄屏 ≤768px）：全屏，恢复手机风格 ============ */
@media (max-width: 768px) {
    body {
        align-items: stretch;
        justify-content: stretch;
        padding: 0;
        background: #ffffff;
    }
    .phone-frame {
        max-width: 100%;
        width: 100%;
        height: 100vh;
        height: 100dvh;
        max-height: 100vh;
        max-height: 100dvh;
        border-radius: 0;
        box-shadow: none;
        border: none;
    }
    /* 手机非 standalone 模式下显示假状态栏（更像 app） */
    .status-bar {
        display: flex;
    }
}

/* 超窄屏（≤420px，避免小屏居中列太宽） */
@media (max-width: 420px) {
    .phone-frame {
        border-left: none;
        border-right: none;
    }
}

