/* Reset & Base */
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
    font-family: "PingFang SC", "Microsoft YaHei", Arial, sans-serif;
    background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
    color: #333;
    line-height: 1.6;
    min-height: 100vh;
}

/* Auth */
.auth-body {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
}
.auth-card {
    background: #fff;
    padding: 40px 30px;
    border-radius: 16px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.12);
    width: 90%;
    max-width: 420px;
    text-align: center;
}
.auth-card h2 { margin-bottom: 12px; color: #2c3e50; }
.auth-card form { margin-top: 20px; }
.auth-card input {
    width: 100%;
    padding: 14px;
    margin-bottom: 14px;
    border: 1px solid #ddd;
    border-radius: 10px;
    font-size: 16px;
}
.auth-card button {
    width: 100%;
    padding: 14px;
    background: #4facfe;
    color: #fff;
    border: none;
    border-radius: 10px;
    font-size: 16px;
    cursor: pointer;
    transition: .2s;
}
.auth-card button:hover { background: #00f2fe; }
.error { color: #e74c3c; margin: 10px 0; }
.small { color: #777; font-size: 14px; margin-top: 14px; }
.small a { color: #4facfe; }

/* Header */
.site-header {
    background: linear-gradient(90deg, #4facfe 0%, #00f2fe 100%);
    color: #fff;
    padding: 18px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    box-shadow: 0 4px 15px rgba(0,0,0,0.1);
    position: sticky;
    top: 0;
    z-index: 100;
}
.site-header h1 { font-size: 20px; }
.site-header a {
    color: #fff;
    text-decoration: none;
    background: rgba(255,255,255,0.2);
    padding: 6px 14px;
    border-radius: 20px;
    font-size: 14px;
}
.trial-bar {
    background: #fff3cd;
    color: #856404;
    padding: 10px 20px;
    font-size: 14px;
    text-align: center;
    border-bottom: 1px solid #ffeeba;
}

/* Container */
.container { max-width: 1100px; margin: 0 auto; padding: 20px; }

/* Intro */
.intro {
    background: #fff;
    padding: 24px;
    border-radius: 14px;
    margin-bottom: 24px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.06);
}
.intro h2 { color: #2c3e50; margin-bottom: 10px; }
.intro p { color: #555; margin-bottom: 8px; }
.tag-list { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 12px; }
.tag {
    background: #e8f6ff;
    color: #007bff;
    padding: 6px 14px;
    border-radius: 20px;
    font-size: 13px;
}

/* Topic Card */
.topic {
    background: #fff;
    border-radius: 16px;
    margin-bottom: 30px;
    overflow: hidden;
    box-shadow: 0 8px 24px rgba(0,0,0,0.08);
}
.topic-header {
    background: linear-gradient(90deg, #667eea 0%, #764ba2 100%);
    color: #fff;
    padding: 16px 22px;
    font-size: 18px;
    font-weight: bold;
}
.topic-body { padding: 22px; }

/* Grid */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 22px; }
@media (max-width: 800px) { .grid-2 { grid-template-columns: 1fr; } }

/* Calculator */
.calc {
    background: #f8faff;
    border-radius: 12px;
    padding: 18px;
    border: 1px solid #e1e8ff;
}
.calc h4 { margin-bottom: 14px; color: #2c3e50; }
.field { margin-bottom: 12px; }
.field label { display: block; margin-bottom: 6px; font-size: 14px; color: #555; }
.field input {
    width: 100%;
    padding: 10px;
    border: 1px solid #ccd6e0;
    border-radius: 8px;
    font-size: 15px;
}
.calc button {
    background: #28a745;
    color: #fff;
    border: none;
    padding: 10px 20px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 15px;
}
.calc button:hover { background: #218838; }
.result {
    margin-top: 14px;
    background: #fff;
    border-left: 4px solid #28a745;
    padding: 12px;
    border-radius: 0 8px 8px 0;
    min-height: 60px;
}
.result strong { color: #28a745; font-size: 18px; }

/* Formula */
.formula-box {
    background: #fff8e1;
    border-left: 4px solid #ffc107;
    padding: 12px 16px;
    border-radius: 0 10px 10px 0;
    margin: 14px 0;
}
.formula-box code {
    background: #fff;
    padding: 2px 6px;
    border-radius: 4px;
    font-family: "Courier New", monospace;
}

/* Mnemonic */
.mnemonic {
    background: #e8f5e9;
    border-radius: 10px;
    padding: 14px;
    margin: 14px 0;
    color: #2e7d32;
}
.mnemonic h5 { margin-bottom: 8px; }
.mnemonic p { margin: 0; font-style: italic; }

/* Derivation */
.derivation {
    background: #f3e5f5;
    border-radius: 10px;
    padding: 14px;
    margin: 14px 0;
    color: #6a1b9a;
}
.derivation h5 { margin-bottom: 8px; }
.derivation p { font-size: 14px; text-align: justify; }

/* 3D Canvas */
.canvas3d {
    width: 100%;
    height: 320px;
    background: #eef2f5;
    border-radius: 12px;
    margin-top: 14px;
    position: relative;
}

/* Paywall */
.paywall {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.75);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 999;
}
.paywall-content {
    background: #fff;
    padding: 40px 30px;
    border-radius: 16px;
    text-align: center;
    max-width: 420px;
    width: 90%;
}
.paywall-content h2 { margin-bottom: 14px; color: #e74c3c; }
.paywall-content button {
    background: #e74c3c;
    color: #fff;
    border: none;
    padding: 14px 30px;
    border-radius: 10px;
    font-size: 16px;
    margin-top: 14px;
    cursor: pointer;
}

footer {
    text-align: center;
    padding: 30px 20px;
    color: #777;
    font-size: 13px;
}

/* Animation Helpers */
.fade-in { animation: fadeIn .8s ease forwards; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.slide-up { animation: slideUp .8s ease forwards; }
@keyframes slideUp { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: translateY(0); } }
.pulse-soft { animation: pulseSoft 2s ease infinite; }
@keyframes pulseSoft { 0%,100% { transform: scale(1); } 50% { transform: scale(1.05); } }
.float-anim { animation: floatAnim 3s ease-in-out infinite; }
@keyframes floatAnim { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-8px); } }

/* PPT Step Animation */
.ppt-step { opacity: 0; transform: translateY(20px); transition: all .6s ease; }
.ppt-step.ppt-active { opacity: 1; transform: translateY(0); }
.set-rect { opacity: 0; transition: all .6s ease; transform: scale(0.8); }
.set-rect.ppt-active { opacity: 1; transform: scale(1); }
.set-rect.intersect { animation: intersectPulse 1.5s ease infinite; }
@keyframes intersectPulse { 0%,100% { filter: brightness(1); } 50% { filter: brightness(1.25); } }
.ppt-player { display: flex; gap: 10px; justify-content: center; margin: 14px 0; }
.ppt-player button { padding: 8px 18px; border: none; border-radius: 20px; cursor: pointer; background: #4facfe; color: #fff; }
.ppt-player button:hover { background: #00c6ff; }
.flash { animation: flashAnim 1s ease 2; }
@keyframes flashAnim { 0%,100% { opacity: 1; } 50% { opacity: .3; } }

/* Tips / Exam Cards */
.tip-card { background: #fff3e0; border-left: 4px solid #ff9800; border-radius: 0 10px 10px 0; padding: 14px; margin: 14px 0; color: #e65100; }
.tip-card h5 { margin-bottom: 6px; }
.tip-card ul { margin-left: 18px; font-size: 14px; }
.formula-card { background: #e3f2fd; border-left: 4px solid #2196f3; border-radius: 0 10px 10px 0; padding: 14px; margin: 14px 0; }
.formula-card h5 { margin-bottom: 6px; color: #1565c0; }

/* Presentation mode */
.presentation-mode .site-header, .presentation-mode .trial-bar, .presentation-mode footer { display: none !important; }
.presentation-mode .container { max-width: 100%; padding: 40px; }
.presentation-mode .section-card { font-size: 18px; }
.presentation-mode .graph-stage, .presentation-mode .canvas3d { height: 450px; }

/* Dark mode */
html.dark body { background: linear-gradient(135deg, #1e1e2f 0%, #2d2d44 100%); color: #e0e0e0; }
html.dark .site-header { background: linear-gradient(90deg, #2c3e50 0%, #34495e 100%); }
html.dark .intro, html.dark .topic, html.dark .section-card, html.dark .auth-card, html.dark .paywall-content, html.dark .progress-overview { background: #2b2b3d; color: #e0e0e0; }
html.dark .intro h2, html.dark .topic-header, html.dark .section-card h3 { color: #fff; }
html.dark .formula-box { background: #3e3e55; color: #ffe082; border-left-color: #ffb300; }
html.dark .mnemonic { background: #2e3b2e; color: #a5d6a7; }
html.dark .derivation { background: #3a2b42; color: #ce93d8; }
html.dark .graph-stage, html.dark .canvas3d { background: #1f1f2e; }
html.dark .q-input { background: #33334d; color: #fff; border-color: #555; }
html.dark footer { color: #aaa; }
html.dark .trial-bar { background: #4a3b1f; color: #ffecb3; }
html.dark .tip-card { background: #4e342e; color: #ffcc80; }
html.dark .formula-card { background: #1a2b3c; color: #90caf9; }

/* ===================== 全站响应式与性能优化 ===================== */

/* 1. 移动端基础设置 */
html {
    -webkit-text-size-adjust: 100%;
    -webkit-tap-highlight-color: transparent;
}

img, canvas, video, svg {
    max-width: 100%;
    height: auto;
}

/* 2. 防止 iOS 输入框自动放大 */
input, textarea, select, button {
    font-size: 16px;
}

/* 3. 触控目标尺寸优化 */
button, a, input[type="checkbox"], input[type="radio"] {
    min-height: 44px;
}

.site-header a, .func-btn, .ppt-player button, .mode-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

/* 4. 容器自适应 */
.container {
    padding: 16px;
}

/* 5. 章节卡片通用样式（兼容各章节内联样式） */
.section-card {
    padding: 16px;
    margin-bottom: 16px;
}

/* 6. 表格横向滚动容器 */
.table-wrap {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: 8px;
    border: 1px solid #eee;
}

.table-wrap table {
    min-width: 600px;
    width: 100%;
}

/* 7. Canvas 图形自适应 */
.graph-stage, .trig-canvas {
    width: 100% !important;
    height: auto !important;
    aspect-ratio: 16 / 10;
    max-height: 360px;
}

.canvas3d {
    width: 100% !important;
    height: auto !important;
    aspect-ratio: 4 / 3;
    max-height: 420px;
}

/* 8. 小屏优化 */
@media (max-width: 768px) {
    .site-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
        padding: 12px 16px;
    }
    .site-header h1 { font-size: 18px; }
    .site-header > div { width: 100%; display: flex; flex-wrap: wrap; gap: 8px; }
    .site-header a { font-size: 13px; padding: 4px 10px; flex: 1 1 auto; text-align: center; justify-content: center; }

    .container { padding: 12px; }
    .intro, .topic, .section-card, .auth-card, .paywall-content, .progress-overview { padding: 16px; }
    .intro h2, .topic-header, .section-card h3 { font-size: 18px; }

    .chapter-grid { grid-template-columns: 1fr; gap: 14px; }
    .chapter-card { padding: 18px; }
    .chapter-card h3 { font-size: 16px; }

    .admin-grid { grid-template-columns: 1fr; }
    .admin-card { padding: 16px; }

    .formula-box, .mnemonic, .derivation, .tip-card, .formula-card { padding: 12px; font-size: 14px; }
    .func-btn { padding: 10px 14px; font-size: 14px; }

    .graph-stage, .trig-canvas { max-height: 260px; }
    .canvas3d { max-height: 300px; }

    footer { padding: 20px 12px; }
}

/* 9. 超小屏优化 */
@media (max-width: 480px) {
    .auth-card { padding: 30px 20px; width: 95%; }
    .site-header h1 { font-size: 16px; }
    .quad-controls { flex-direction: column; align-items: stretch; }
    .trig-controls { gap: 6px; }
    .trig-controls .func-btn { flex: 1 1 auto; min-width: 80px; }
    .ppt-player { flex-direction: column; gap: 8px; }
}

/* 10. 性能优化：减少动画重绘区域 */
.fade-in, .slide-up, .pulse-soft, .float-anim, .ppt-step, .set-rect {
    will-change: transform, opacity;
}

/* 11. 偏好减少动画 */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* 12. 打印优化 */
@media print {
    .site-header, .trial-bar, footer, .ppt-player, .func-btn, button { display: none !important; }
    .container { max-width: 100%; padding: 0; }
    body { background: #fff; color: #000; }
}

/* 13. 管理员后台样式 */
.admin-dashboard-title {
    font-size: 22px;
    font-weight: 700;
    color: #2c3e50;
    margin-bottom: 18px;
    display: flex;
    align-items: center;
    gap: 10px;
}
.admin-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    gap: 22px;
}
.admin-card {
    background: #fff;
    border-radius: 14px;
    padding: 22px;
    box-shadow: 0 6px 18px rgba(0,0,0,0.06);
    transition: transform .2s, box-shadow .2s;
}
.admin-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 10px 24px rgba(0,0,0,0.1);
}
.admin-card h3 {
    font-size: 17px;
    color: #2c3e50;
    margin-bottom: 16px;
    padding-bottom: 10px;
    border-bottom: 2px solid #eef2f7;
}
.admin-card input,
.admin-card select,
.admin-card textarea {
    width: 100%;
    padding: 11px 13px;
    margin-bottom: 12px;
    border: 1px solid #dbe4ea;
    border-radius: 8px;
    font-size: 14px;
    transition: border-color .2s, box-shadow .2s;
}
.admin-card input:focus,
.admin-card select:focus {
    outline: none;
    border-color: #4facfe;
    box-shadow: 0 0 0 3px rgba(79,172,254,0.15);
}
.admin-card button {
    background: linear-gradient(90deg, #4facfe, #00f2fe);
    color: #fff;
    border: none;
    padding: 11px 22px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: opacity .2s;
}
.admin-card button:hover { opacity: .9; }
.stats-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 18px;
    margin-bottom: 26px;
}
.stat-box {
    background: linear-gradient(135deg, #4facfe, #00f2fe);
    color: #fff;
    border-radius: 14px;
    padding: 22px 16px;
    text-align: center;
    box-shadow: 0 6px 16px rgba(79,172,254,0.25);
    position: relative;
    overflow: hidden;
}
.stat-box::before {
    content: '';
    position: absolute;
    top: -40%;
    right: -20%;
    width: 100px;
    height: 100px;
    background: rgba(255,255,255,0.12);
    border-radius: 50%;
}
.stat-box h4 { font-size: 32px; margin: 0; position: relative; z-index: 1; }
.stat-box p { margin: 8px 0 0; font-size: 14px; opacity: .95; position: relative; z-index: 1; }
.stat-box.orange { background: linear-gradient(135deg, #f6d365, #fda085); box-shadow: 0 6px 16px rgba(246,211,101,0.3); }
.stat-box.purple { background: linear-gradient(135deg, #a18cd1, #fbc2eb); box-shadow: 0 6px 16px rgba(161,140,209,0.25); }
.stat-box.green { background: linear-gradient(135deg, #84fab0, #8fd3f4); box-shadow: 0 6px 16px rgba(132,250,176,0.25); }
.backup-list {
    max-height: 200px;
    overflow-y: auto;
    font-size: 13px;
    color: #555;
    margin-top: 12px;
    padding: 10px;
    background: #f8fafc;
    border-radius: 8px;
}
.backup-list div { padding: 6px 0; border-bottom: 1px solid #eef2f7; }
.backup-list div:last-child { border-bottom: none; }
@media (max-width: 768px) {
    .admin-grid { grid-template-columns: 1fr; }
    .stats-row { grid-template-columns: repeat(2, 1fr); }
    .admin-card { padding: 18px; }
}
@media (max-width: 480px) {
    .stats-row { grid-template-columns: 1fr; }
}
