* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    padding: 20px;
    color: #333;
    overflow-x: hidden;
    word-wrap: break-word;
}

.container {
    max-width: 960px;
    margin: 0 auto;
}

/* 头部 */
header {
    text-align: center;
    padding: 30px 20px;
    color: white;
}

.header-row {
    display: block;
    position: relative;
    max-width: 900px;
    margin: 0 auto;
}

.header-text {
    text-align: center;
    min-width: 0;
}

header h1 {
    font-size: 2.2rem;
    margin-bottom: 10px;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.2);
}

.subtitle {
    font-size: 1rem;
    opacity: 0.9;
}

/* 下载 APK 按钮：右上角小巧药丸 */
.download-apk-btn {
    position: absolute;
    top: 4px;
    right: 0;
    display: inline-block;
    padding: 5px 12px;
    background: linear-gradient(135deg, #43a047, #2e7d32);
    color: white;
    text-decoration: none;
    border-radius: 999px;
    font-size: 0.72rem;
    font-weight: 600;
    line-height: 1.4;
    cursor: pointer;
    transition: all 0.25s ease;
    box-shadow: 0 2px 6px rgba(46, 125, 50, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.35);
    white-space: nowrap;
    z-index: 5;
}

.download-apk-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 10px rgba(46, 125, 50, 0.4);
    filter: brightness(1.05);
}

.download-apk-btn:active {
    transform: translateY(0);
}

/* 模式切换 */
.mode-switcher {
    display: flex;
    gap: 16px;
    justify-content: center;
    margin-bottom: 24px;
    flex-wrap: wrap;
}

.mode-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 28px;
    border: none;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.25);
    color: white;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    backdrop-filter: blur(10px);
    border: 2px solid transparent;
}

.mode-btn:hover {
    background: rgba(255, 255, 255, 0.35);
    transform: translateY(-2px);
}

.mode-btn.active {
    background: white;
    color: #667eea;
    border-color: rgba(255, 255, 255, 0.8);
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.15);
}

.mode-icon {
    font-size: 1.2rem;
}

/* 输入面板 */
.input-panel {
    background: white;
    border-radius: 16px;
    padding: 24px;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
    gap: 16px;
    align-items: end;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.1);
    margin-bottom: 20px;
    max-width: 100%;
    min-width: 0;
}

.input-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
    min-width: 0;
}

.input-group label {
    font-size: 0.9rem;
    color: #666;
    font-weight: 500;
}

.input-group input,
.input-group select {
    padding: 12px 16px;
    border: 2px solid #e0e0e0;
    border-radius: 10px;
    font-size: 1.1rem;
    font-weight: 600;
    transition: all 0.2s ease;
    font-family: inherit;
    color: #333;
    background: #fafafa;
    width: 100%;
    max-width: 100%;
    min-width: 0;
}

.input-group input:focus,
.input-group select:focus {
    outline: none;
    border-color: #667eea;
    background: white;
    box-shadow: 0 0 0 4px rgba(102, 126, 234, 0.1);
}

.operator-group select {
    font-size: 1.3rem;
    min-width: 100px;
    text-align: center;
    color: #667eea;
}

.play-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 14px 24px;
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: white;
    border: none;
    border-radius: 10px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    white-space: nowrap;
}

.play-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(102, 126, 234, 0.4);
}

.play-btn:active {
    transform: translateY(0);
}

/* 画布独立小播放按钮 */
.mini-play-btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 6px 14px;
    background: linear-gradient(135deg, #42a5f5, #1e88e5);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.25s ease;
    margin-left: 8px;
    white-space: nowrap;
}

.mini-play-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(30, 136, 229, 0.35);
}

.mini-play-btn:active {
    transform: translateY(0);
}

.mini-play-btn.purple-btn {
    background: linear-gradient(135deg, #ab47bc, #8e24aa);
}

.mini-play-btn.purple-btn:hover {
    box-shadow: 0 4px 12px rgba(142, 36, 170, 0.35);
}

.mini-play-btn.orange-btn {
    background: linear-gradient(135deg, #ffa726, #fb8c00);
}

.mini-play-btn.orange-btn:hover {
    box-shadow: 0 4px 12px rgba(251, 140, 0, 0.35);
}

.mini-play-btn.playing {
    opacity: 0.85;
}

.mini-play-btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
    transform: none !important;
    box-shadow: none !important;
}

.mini-play-icon {
    font-size: 0.75rem;
    line-height: 1;
}

/* 结果预览 */
.result-preview {
    background: white;
    border-radius: 16px;
    padding: 20px;
    margin-bottom: 20px;
    text-align: center;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.1);
}

.result-formula {
    font-size: 2rem;
    font-weight: 700;
    color: #333;
    font-family: "Consolas", "Monaco", monospace;
}

/* 画布区域 */
.canvas-container {
    display: flex;
    flex-direction: column;
    gap: 16px;
    margin-bottom: 20px;
}

.canvas-card {
    background: white;
    border-radius: 16px;
    padding: 20px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.1);
}

.canvas-card.combined {
    border: 2px dashed #9b59b6;
    background: linear-gradient(135deg, #fdfbff 0%, #fff 100%);
}

.canvas-title {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 16px;
    font-weight: 600;
    font-size: 1rem;
    color: #444;
    padding-bottom: 12px;
    border-bottom: 1px solid #f0f0f0;
    flex-wrap: nowrap;
}

/* 画布2 标题可换行（分段控件 + 播放按钮） */
.canvas-title-wrapped {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
}

.canvas-title-main {
    display: flex;
    align-items: center;
    gap: 10px;
}

.canvas-title-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 10px;
    flex-wrap: wrap;
}

/* 分段控件：从A点/从零开始切换 */
.segmented-control {
    display: inline-flex;
    padding: 3px;
    background: #F5F5F5;
    border-radius: 10px;
    border: 1px solid #E0E0E0;
    gap: 2px;
}

.seg-btn {
    border: none;
    background: transparent;
    padding: 6px 14px;
    font-size: 0.82rem;
    font-weight: 600;
    color: #666;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.25s ease;
    white-space: nowrap;
    font-family: inherit;
}

.seg-btn:hover {
    color: #333;
    background: rgba(255, 255, 255, 0.6);
}

.seg-btn.seg-active {
    background: white;
    color: #E65100;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    border: 1px solid rgba(255, 152, 0, 0.4);
}

.canvas-num {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: white;
    border-radius: 50%;
    font-size: 0.85rem;
    font-weight: 700;
}

.badge {
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 600;
}

.canvas-title-text {
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.badge.blue {
    background: #e3f2fd;
    color: #1976d2;
}

.badge.orange {
    background: #fff3e0;
    color: #f57c00;
}

.badge.purple {
    background: #f3e5f5;
    color: #8e24aa;
}

canvas {
    width: 100%;
    height: auto;
    display: block;
    border-radius: 8px;
    background: #fafbfc;
}

/* 说明区 */
.explanation-panel {
    background: white;
    border-radius: 16px;
    padding: 24px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.1);
}

.explanation-panel h3 {
    color: #444;
    margin-bottom: 16px;
    font-size: 1.1rem;
    padding-bottom: 12px;
    border-bottom: 1px solid #f0f0f0;
}

.explanation-content {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.explain-step {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 12px 16px;
    background: #f8f9ff;
    border-radius: 10px;
    border-left: 4px solid #667eea;
}

.explain-step.step-2 {
    background: #fff8f0;
    border-left-color: #f57c00;
}

.explain-step.step-3 {
    background: #fdf3ff;
    border-left-color: #8e24aa;
}

.step-num {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 24px;
    height: 24px;
    background: #667eea;
    color: white;
    border-radius: 50%;
    font-size: 0.75rem;
    font-weight: 700;
    flex-shrink: 0;
}

.step-2 .step-num {
    background: #f57c00;
}

.step-3 .step-num {
    background: #8e24aa;
}

.step-text {
    color: #555;
    line-height: 1.6;
    font-size: 0.95rem;
}

.step-text strong {
    color: #333;
}

.compare-result {
    padding: 16px;
    background: linear-gradient(135deg, #e8f5e9 0%, #c8e6c9 100%);
    border-radius: 12px;
    text-align: center;
    font-size: 1.3rem;
    font-weight: 700;
    color: #2e7d32;
    margin-top: 8px;
}

.compare-result.less {
    background: linear-gradient(135deg, #fff3e0 0%, #ffe0b2 100%);
    color: #e65100;
}

.compare-result.equal {
    background: linear-gradient(135deg, #e3f2fd 0%, #bbdefb 100%);
    color: #1565c0;
}

/* 响应式 */
@media (max-width: 720px) {
    .input-panel {
        grid-template-columns: 1fr;
    }

    .operator-group {
        order: 2;
    }

    .play-btn {
        width: 100%;
    }

    header h1 {
        font-size: 1.6rem;
    }

    .result-formula {
        font-size: 1.4rem;
    }

    .mode-btn {
        flex: 1;
        min-width: 140px;
        justify-content: center;
    }
}
