
        :root {
            --primary: #4f46e5;
            --primary-hover: #4338ca;
            --bg-color: #f3f4f6;
            --card-bg: #ffffff;
            --text-main: #1f2937;
            --text-sub: #6b7280;
            --border: #e5e7eb;
            --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
            --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
        }

        * {
            margin: 0; padding: 0; box-sizing: border-box; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
            -webkit-tap-highlight-color: transparent;
        }

        body { background-color: var(--bg-color); color: var(--text-main); padding: 20px; max-width: 600px; margin: 0 auto; }
        
        .panel { background: var(--card-bg); border-radius: 12px; padding: 20px; box-shadow: var(--shadow); margin-bottom: 20px; }
        
        h2 { font-size: 1.25rem; font-weight: 600; margin-bottom: 15px; color: var(--text-main); }
        
        /* Inputs */
        input[type="text"], input[type="number"], input[type="password"] {
            width: 100%; padding: 12px; border: 1px solid var(--border); border-radius: 8px; font-size: 16px; margin-bottom: 15px; outline: none; transition: border-color 0.2s;
        }
        .input-wrap { position: relative; }
        /* 给清除按钮预留空间，避免文字过长时与 × 重叠 */
        .input-wrap input[type="text"] { padding-right: 32px; }
        .input-wrap .clear-btn {
            position: absolute; right: 10px; top: 50%; transform: translateY(-50%);
            display: none; cursor: pointer; color: #9ca3af; font-size: 16px;
            line-height: 1; user-select: none; -webkit-user-select: none; padding: 4px;
        }
        .input-wrap .clear-btn:hover { color: #6b7280; }
        .input-wrap.has-val .clear-btn { display: block; }
        input:focus { border-color: var(--primary); }
        
        /* Buttons */
        .btn {
            background: var(--primary); color: white; border: none; padding: 12px 20px; border-radius: 8px; font-size: 16px; font-weight: 500; cursor: pointer; transition: all 0.2s; width: 100%; margin-bottom: 10px;
        }
        .btn:hover { background: var(--primary-hover); }
        .btn:active { transform: scale(0.98); }
        .btn-outline { background: transparent; color: var(--primary); border: 1px solid var(--primary); }
        .btn-outline:hover { background: #e0e7ff; }
        .btn-stop { background: #ef4444; }
        .btn-stop:hover { background: #dc2626; }

        .btn-group { display: flex; gap: 10px; }
        .btn-group .btn { margin-bottom: 0; }

        /* Device Pairing */
        .pairing-overlay { position: fixed; inset: 0; z-index: 1002; display: flex; align-items: center; justify-content: center; padding: 20px; background: rgba(15, 23, 42, 0.6); backdrop-filter: blur(5px); -webkit-backdrop-filter: blur(5px); }
        .pairing-card { width: min(100%, 390px); max-height: calc(100vh - 40px); overflow-y: auto; padding: 26px 22px 22px; border-radius: 16px; background: white; box-shadow: 0 24px 60px rgba(15, 23, 42, 0.28); text-align: center; }
        .pairing-icon { width: 52px; height: 52px; display: flex; align-items: center; justify-content: center; margin: 0 auto 12px; border-radius: 50%; background: #eef2ff; font-size: 1.45rem; }
        .pairing-card h2 { margin-bottom: 8px; }
        .pairing-description { color: var(--text-sub); font-size: 0.9rem; line-height: 1.6; margin-bottom: 18px; }
        .pairing-form { text-align: left; }
        .pairing-form label { display: block; margin: 0 0 6px 2px; color: var(--text-sub); font-size: 0.8rem; }
        .pairing-form input { margin-bottom: 13px; }
        .pairing-form .btn { margin: 3px 0 0; }
        .pairing-config-help { padding: 14px; border: 1px solid #fed7aa; border-radius: 10px; background: #fff7ed; color: #9a3412; font-size: 0.86rem; line-height: 1.6; }
        .pairing-config-help code { display: block; margin: 8px 0; padding: 7px 8px; border-radius: 6px; background: white; color: #c2410c; font-size: 0.78rem; word-break: break-all; }
        .pairing-config-help small { display: block; color: #9a3412; }
        .pairing-error { margin-top: 12px; padding: 9px 10px; border-radius: 8px; background: #fef2f2; color: #b91c1c; font-size: 0.82rem; line-height: 1.5; }
        .pairing-recovery { margin-top: 14px; }
        .pairing-recovery .btn { margin: 0; }
        .pairing-offline-btn { margin-top: 12px; padding: 5px; border: 0; background: transparent; color: #9ca3af; font-size: 0.8rem; cursor: pointer; }
        .pairing-offline-btn:hover { color: #6b7280; }

        /* Paired Devices */
        .device-manager-overlay { position: fixed; inset: 0; z-index: 1001; align-items: center; justify-content: center; padding: 20px; background: rgba(15, 23, 42, 0.6); backdrop-filter: blur(5px); -webkit-backdrop-filter: blur(5px); }
        .device-manager-card { width: min(100%, 430px); max-height: calc(100vh - 40px); overflow-y: auto; padding: 20px; border-radius: 16px; background: white; box-shadow: 0 24px 60px rgba(15, 23, 42, 0.28); }
        .device-manager-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
        .device-manager-heading h2 { margin-bottom: 5px; }
        .device-manager-heading p { color: var(--text-sub); font-size: 0.82rem; line-height: 1.5; }
        .device-manager-close { flex: 0 0 34px; width: 34px; height: 34px; border: 0; border-radius: 50%; background: #f3f4f6; color: #6b7280; font-size: 1.25rem; cursor: pointer; }
        .device-list { display: grid; gap: 10px; }
        .device-list-loading, .device-list-empty { padding: 20px 10px; color: var(--text-sub); font-size: 0.86rem; text-align: center; }
        .device-list-error { padding: 12px; border-radius: 8px; background: #fef2f2; color: #b91c1c; font-size: 0.82rem; line-height: 1.5; text-align: center; }
        .device-item { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 12px; border: 1px solid var(--border); border-radius: 10px; background: #f9fafb; }
        .device-item-info { min-width: 0; }
        .device-item-name { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; color: var(--text-main); font-size: 0.92rem; font-weight: 600; }
        .device-current-badge { padding: 2px 6px; border-radius: 10px; background: #e0e7ff; color: var(--primary); font-size: 0.68rem; font-weight: 500; }
        .device-item-meta { margin-top: 4px; color: #9ca3af; font-size: 0.72rem; line-height: 1.4; }
        .device-revoke-btn { flex: 0 0 auto; padding: 6px 9px; border: 1px solid #fca5a5; border-radius: 7px; background: white; color: #dc2626; font-size: 0.76rem; cursor: pointer; }
        .device-revoke-btn:hover { background: #fef2f2; }
        .device-access-entry { display: block; margin: -8px auto 24px; padding: 7px 12px; border: 0; background: transparent; color: #9ca3af; font-size: 0.78rem; cursor: pointer; }
        .device-access-entry:hover { color: var(--primary); }

        /* Presets */
        .preset-tags { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 15px; }
        .tag { background: #e0e7ff; color: var(--primary); padding: 6px 12px; border-radius: 20px; font-size: 14px; cursor: pointer; border: 1px solid transparent; transition: all 0.2s; }
        .tag:hover { border-color: var(--primary); }
        .tag-active { background: var(--primary); color: white; }
        .tag-add { background: #f3f4f6; color: var(--text-sub); border: 1px dashed var(--border); }

        /* Setup Grid */
        .setup-grid { display: grid; grid-template-columns: minmax(108px, 0.95fr) minmax(125px, 1.05fr); gap: 8px; margin-bottom: 15px; }
        .setup-field { display: block; min-width: 0; color: var(--text-sub); font-size: 0.76rem; }
        .setup-field > span { display: block; margin: 0 0 6px 2px; }
        .setup-grid input[type="number"] { min-width: 0; margin-bottom: 0; -moz-appearance: textfield; }
        .setup-grid input[type="number"]::-webkit-inner-spin-button,
        .setup-grid input[type="number"]::-webkit-outer-spin-button { margin: 0; -webkit-appearance: none; }
        .number-input-with-controls { position: relative; }
        .number-input-with-controls input { padding-right: 30px; }
        .number-input-controls { position: absolute; top: 1px; right: 1px; bottom: 1px; width: 25px; display: grid; grid-template-rows: 1fr 1fr; overflow: hidden; border-left: 1px solid var(--border); border-radius: 0 7px 7px 0; }
        .number-input-controls button { display: flex; align-items: center; justify-content: center; min-height: 0; padding: 0; border: 0; background: #f9fafb; color: #6b7280; font-size: 0.72rem; line-height: 1; cursor: pointer; }
        .number-input-controls button + button { border-top: 1px solid var(--border); }
        .number-input-controls button:active { background: #e0e7ff; color: var(--primary); }

        .checkbox-label { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--text-sub); cursor: pointer; margin-bottom: 15px; }
        .checkbox-label input { width: 18px; height: 18px; cursor: pointer; }

        /* Setup Actions */
        .setup-actions { display: grid; grid-template-columns: 1fr; gap: 10px; }
        .setup-actions > .btn { margin: 0; padding: 15px; font-size: 1.1rem; }
        .setup-more-actions { border: 1px solid var(--border); border-radius: 8px; overflow: hidden; background: white; }
        .setup-more-actions summary { display: flex; align-items: center; justify-content: center; gap: 6px; padding: 10px 12px; color: var(--text-sub); font-size: 0.9rem; cursor: pointer; list-style: none; user-select: none; -webkit-user-select: none; }
        .setup-more-actions summary::-webkit-details-marker { display: none; }
        .setup-more-actions summary::after { content: '▾'; color: #9ca3af; font-size: 0.75rem; line-height: 1; }
        .setup-more-actions[open] summary::after { content: '▴'; }
        .setup-more-actions[open] summary { border-bottom: 1px solid var(--border); }
        .setup-secondary-actions { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 8px; padding: 10px; }
        .setup-secondary-actions .btn { min-width: 0; margin: 0; padding: 10px 8px; font-size: 0.9rem; }
        .setup-secondary-actions #lastResultBtn { border-color: #6366f1; color: var(--primary); background: white; font-weight: 500; }
        .setup-secondary-actions #lastResultBtn:hover { background: #eef2ff; border-color: var(--primary); }
        .setup-secondary-actions #resetConditionsBtn { border-color: #d1d5db; color: #6b7280; background: white; }
        .setup-secondary-actions.no-last-result #resetConditionsBtn { grid-column: 1 / -1; }

        /* Mining UI */
        .mining-ui { display: none; text-align: center; padding: 30px 0; }
        .mining-title { font-size: 1.5rem; font-weight: bold; color: var(--primary); margin-bottom: 10px; animation: pulse 1.5s infinite; }
        .mining-stats { font-family: monospace; font-size: 1.2rem; color: var(--text-sub); margin-bottom: 20px; }
        @keyframes pulse { 0% { opacity: 0.6; } 50% { opacity: 1; } 100% { opacity: 0.6; } }

        /* Card Flip 3D */
        .scene { width: 100%; min-height: 250px; perspective: 1000px; display: none; margin-bottom: 20px; }
        .card { width: 100%; transition: transform 0.8s; transform-style: preserve-3d; cursor: pointer; position: relative; }
        .card.is-flipped { transform: rotateY(180deg); cursor: default; }
        .card__face { width: 100%; backface-visibility: hidden; -webkit-backface-visibility: hidden; -webkit-font-smoothing: antialiased; border-radius: 16px; box-shadow: var(--shadow-lg); display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 30px 20px; }
        .card__face--front { background: linear-gradient(135deg, #1e1b4b, #4338ca); color: white; position: absolute; top: 0; left: 0; height: 100%; }
        .card__face--back { background: white; transform: rotateY(180deg) translateZ(1px); border: 2px solid var(--primary); position: relative; padding-top: 44px; }
        .result-close-btn { position: absolute; top: 10px; left: 10px; z-index: 11; width: 34px; height: 34px; border: 0; border-radius: 50%; background: #f3f4f6; color: #6b7280; font-size: 1.35rem; line-height: 1; cursor: pointer; }
        .result-close-btn:hover { background: #e5e7eb; color: #374151; }
        .result-close-btn:active { transform: scale(0.94); }
        
        .front-title { font-size: 24px; font-weight: bold; letter-spacing: 2px; }
        .front-subtitle { font-size: 14px; opacity: 0.7; margin-top: 10px; }
        
        .back-result { font-size: 2.5rem; font-weight: 800; color: var(--primary); margin-bottom: 20px; }
        .stats-grid { width: 100%; display: grid; grid-template-columns: 1fr 1fr; gap: 10px; font-size: 0.9rem; }
        .stat-item { background: var(--bg-color); padding: 10px; border-radius: 8px; text-align: center; }
        .stat-label { color: var(--text-sub); font-size: 0.8rem; display: block; margin-bottom: 4px; }
        .stat-val { font-weight: bold; color: var(--text-main); }
        
        /* SSR/SR Badges */
        .badge { position: absolute; top: -10px; right: -10px; padding: 5px 15px; border-radius: 20px; font-weight: bold; font-size: 14px; box-shadow: var(--shadow); color: white; transform: rotate(15deg); z-index: 10; }
        .badge.ssr { background: linear-gradient(45deg, #fbbf24, #d97706); }
        .badge.sr { background: linear-gradient(45deg, #a78bfa, #7c3aed); }
        .badge.r { background: linear-gradient(45deg, #60a5fa, #2563eb); }

        /* History */
        .history-controls { display: flex; gap: 10px; margin-bottom: 15px; overflow-x: auto; padding-bottom: 5px; }
        .history-controls .tag { flex-shrink: 0; }
        .history-list { display: flex; flex-direction: column; gap: 12px; }
        .history-error { padding: 20px 12px; text-align: center; color: var(--text-sub); }
        .history-error small { display: block; margin-top: 6px; color: #9ca3af; word-break: break-word; }
        .history-retry-btn { width: auto; margin: 14px auto 0; padding: 7px 16px; font-size: 0.85rem; }
        .history-load-more { display: flex; justify-content: center; padding: 4px 0 8px; }
        .history-load-more .btn { width: auto; min-width: 180px; margin: 0; padding: 8px 18px; font-size: 0.88rem; }
        .history-card { background: var(--card-bg); padding: 15px; border-radius: 8px; border: 1px solid var(--border); box-shadow: 0 1px 3px rgba(0,0,0,0.05); display: flex; justify-content: space-between; align-items: center; }
        .timeline-content.history-card { display: flex; flex-direction: column; align-items: stretch; box-shadow: 0 2px 8px rgba(0,0,0,0.08); border: 1px solid #e5e7eb; }
        .history-info h4 { color: var(--primary); font-size: 1.2rem; margin-bottom: 5px; }
        .history-meta { font-size: 0.85rem; color: var(--text-sub); }
        .history-badge { padding: 4px 10px; border-radius: 12px; font-size: 0.8rem; font-weight: bold; color: white; }

        /* Timeline UI */
        .timeline {
            position: relative;
            padding: 10px 0;
            margin-left: 5px;
        }
        .timeline::before {
            content: '';
            position: absolute;
            top: 0;
            bottom: 0;
            left: 5px;
            width: 2px;
            background: #e5e7eb;
        }
        .timeline-item {
            position: relative;
            margin-bottom: 25px;
            padding-left: 20px;
        }
        .timeline-dot {
            position: absolute;
            left: 0;
            top: 20px;
            width: 12px;
            height: 12px;
            border-radius: 50%;
            background: white;
            border: 2px solid var(--border);
            z-index: 2;
        }
        .timeline-dot.ssr { border-color: #f59e0b; background: #fffbeb; box-shadow: 0 0 8px rgba(245,158,11,0.4); }
        .timeline-dot.sr { border-color: #8b5cf6; background: #f5f3ff; }
        .timeline-dot.r { border-color: #3b82f6; background: #eff6ff; }

        /* Day Group */
        .day-group { margin-bottom: 12px; }
        .day-header {
            display: flex; align-items: center; justify-content: space-between;
            padding: 10px 14px; background: var(--card-bg); border-radius: 10px;
            cursor: pointer; user-select: none; box-shadow: 0 1px 3px rgba(0,0,0,0.06);
            transition: background 0.2s, border-radius 0.2s;
        }
        .day-header:hover { background: #f9fafb; }
        .day-header-left { display: flex; align-items: center; gap: 8px; }
        .day-header-date { font-size: 0.9rem; font-weight: 600; color: var(--text-main); }
        .day-header-date .day-weekday { color: var(--text-sub); font-weight: 400; margin-left: 4px; font-size: 0.8rem; }
        .day-count {
            font-size: 0.7rem; color: var(--primary); background: #e0e7ff;
            padding: 2px 8px; border-radius: 10px; font-weight: 500;
        }
        .day-arrow {
            font-size: 0.65rem; color: var(--text-sub);
            transition: transform 0.25s ease;
        }
        .day-group.open .day-arrow { transform: rotate(90deg); }
        .day-group.open .day-header { border-radius: 10px 10px 0 0; box-shadow: 0 1px 3px rgba(0,0,0,0.06), 0 1px 0 rgba(0,0,0,0.04) inset; }
        .day-body {
            max-height: 0; overflow: hidden;
            transition: max-height 0.35s ease;
        }
        .day-body-inner { padding: 8px 0 4px 0; }

        /* Back to Top */
        .back-to-top {
            position: fixed; bottom: 30px; right: 20px; z-index: 100;
            width: 44px; height: 44px; border-radius: 50%;
            background: var(--primary); color: white; border: none;
            font-size: 20px; cursor: pointer; box-shadow: var(--shadow-lg);
            display: flex; align-items: center; justify-content: center;
            opacity: 0; visibility: hidden; transform: translateY(10px);
            transition: opacity 0.3s, visibility 0.3s, transform 0.3s, background 0.2s;
        }
        .back-to-top.visible { opacity: 1; visibility: visible; transform: translateY(0); }
        .back-to-top:hover { background: var(--primary-hover); }
        .back-to-top:active { transform: scale(0.92); }
