:root {
    --bg: #0f1117;
    --bg-card: #1a1d27;
    --bg-card-hover: #222632;
    --bg-input: #14161e;
    --border: #2a2e3a;
    --border-focus: #5b6ef5;
    --text: #e4e6eb;
    --text-dim: #8b8fa3;
    --text-muted: #565a6e;
    --accent: #5b6ef5;
    --accent-hover: #4a5de4;
    --accent-glow: rgba(91, 110, 245, 0.25);
    --danger: #e5484d;
    --danger-hover: #d43b3f;
    --success: #30a46c;
    --warning: #f5a623;
    --radius: 10px;
    --radius-lg: 16px;
    --shadow: 0 4px 24px rgba(0,0,0,0.3);
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    line-height: 1.6;
    overflow-x: hidden;
}

.hidden { display: none !important; }

/* --- Screens --- */
.screen { display: none; min-height: 100vh; }
.screen.active { display: flex; flex-direction: column; }

/* --- Login --- */
#screen-login {
    align-items: center;
    justify-content: center;
    background: radial-gradient(ellipse at 50% 30%, rgba(91,110,245,0.08) 0%, transparent 70%);
}

.login-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 48px 40px;
    width: 100%;
    max-width: 400px;
    box-shadow: var(--shadow);
}

.login-header { text-align: center; margin-bottom: 32px; }

.logo {
    width: 64px; height: 64px;
    background: linear-gradient(135deg, var(--accent), #8b5cf6);
    border-radius: 16px;
    display: inline-flex; align-items: center; justify-content: center;
    font-size: 24px; font-weight: 800; color: #fff;
    margin-bottom: 16px;
}

.login-header h1 { font-size: 28px; font-weight: 700; }
.subtitle { color: var(--text-dim); font-size: 14px; margin-top: 4px; }

.form-group { margin-bottom: 20px; }
.form-group label { display: block; font-size: 13px; color: var(--text-dim); margin-bottom: 6px; font-weight: 500; }

input[type="text"], input[type="password"], .input-lg {
    width: 100%;
    padding: 12px 16px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 15px;
    outline: none;
    transition: border-color 0.2s;
}
input:focus, .input-lg:focus { border-color: var(--border-focus); box-shadow: 0 0 0 3px var(--accent-glow); }

.login-footer { text-align: center; margin-top: 24px; }
.login-footer p { font-size: 12px; color: var(--text-muted); line-height: 1.8; }

/* --- Buttons --- */
.btn {
    display: inline-flex; align-items: center; justify-content: center;
    padding: 10px 24px;
    border: none; border-radius: var(--radius);
    font-size: 14px; font-weight: 600;
    cursor: pointer; transition: all 0.2s;
    text-decoration: none;
}
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled) { background: var(--danger-hover); }
.btn-ghost { background: transparent; color: var(--text-dim); border: 1px solid var(--border); }
.btn-ghost:hover { color: var(--text); border-color: var(--text-dim); }
.btn-block { width: 100%; }
.btn-sm { padding: 6px 14px; font-size: 13px; }

.error-msg { color: var(--danger); font-size: 13px; margin-top: 12px; text-align: center; }

/* --- Topbar --- */
.topbar {
    display: flex; align-items: center; justify-content: space-between;
    padding: 12px 24px;
    border-bottom: 1px solid var(--border);
    background: var(--bg-card);
    position: sticky; top: 0; z-index: 100;
}
.topbar-left { display: flex; align-items: center; gap: 12px; }
.logo-sm {
    width: 32px; height: 32px;
    background: linear-gradient(135deg, var(--accent), #8b5cf6);
    border-radius: 8px;
    display: inline-flex; align-items: center; justify-content: center;
    font-size: 13px; font-weight: 800; color: #fff;
}
.topbar-title { font-size: 16px; font-weight: 700; }
.topbar-right { display: flex; align-items: center; gap: 12px; }

.badge {
    padding: 4px 12px; border-radius: 20px;
    font-size: 12px; font-weight: 600;
}
.badge-offline { background: rgba(229,72,77,0.15); color: var(--danger); }
.badge-online { background: rgba(48,164,108,0.15); color: var(--success); }

/* --- Secure context / WebUSB banner --- */
.secure-context-banner {
    display: flex; align-items: flex-start; gap: 12px;
    padding: 12px 24px;
    background: rgba(245,166,35,0.12);
    border-bottom: 1px solid rgba(245,166,35,0.35);
    color: var(--text);
}
.secure-context-banner-icon {
    flex-shrink: 0; width: 24px; height: 24px;
    border-radius: 50%; background: var(--warning);
    color: #0f1117; font-weight: 800; font-size: 14px;
    display: flex; align-items: center; justify-content: center;
}
.secure-context-banner-text {
    display: flex; flex-direction: column; gap: 4px;
    font-size: 13px; line-height: 1.5;
}
.secure-context-banner-text strong { color: var(--warning); }
.public-https-banner { border-left: 3px solid var(--accent); }
.public-https-banner .secure-context-banner-text strong { color: var(--accent); }
.public-https-copy-wrap,
.troubleshoot-copy-wrap {
    margin: 0.6rem 0 0;
}
.troubleshoot-copy-wrap .btn { margin-top: 0.35rem; }
.troubleshoot-dbg-hint {
    margin: 0.5rem 0 0;
    font-size: 12px;
    color: var(--text-muted, #888);
    line-height: 1.45;
}
.troubleshoot-dbg-hint code {
    font-size: 11px;
    word-break: break-all;
}

.step-partition-hint {
    margin: 0.5rem 0 0.75rem;
    padding: 0.75rem 1rem;
    border-radius: 8px;
    border-left: 3px solid var(--accent);
    background: rgba(100, 180, 255, 0.08);
    font-size: 14px;
    line-height: 1.55;
    color: var(--text);
}
.step-partition-hint code {
    font-size: 13px;
}
.step-desc-muted {
    font-size: 13px;
    color: var(--text-muted, #888);
    line-height: 1.5;
    margin: 0 0 0.75rem;
}
.bundled-apk-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 1rem;
}
.bundled-apk-status {
    font-size: 13px;
    color: var(--text-muted, #888);
    max-width: 100%;
}
.bundled-apk-status.error {
    color: var(--danger, #e55);
}
.secure-context-banner-text code {
    background: var(--bg-input); padding: 1px 6px; border-radius: 4px;
    font-size: 12px;
}

.mode-card.mode-card-disabled {
    opacity: 0.45; cursor: not-allowed; pointer-events: none;
}
.mode-card.mode-card-disabled .mode-body p { color: var(--text-muted); }

.webusb-unavailable-note {
    color: var(--warning); font-size: 13px; margin: 8px 0 12px;
    padding: 10px; background: rgba(245,166,35,0.08);
    border-radius: var(--radius); border: 1px solid rgba(245,166,35,0.2);
}

/* --- Step Nav --- */
.steps-nav {
    display: flex; align-items: center; justify-content: center;
    padding: 20px 24px;
    gap: 0;
    border-bottom: 1px solid var(--border);
    background: var(--bg-card);
}
.step-item {
    display: flex; flex-direction: column; align-items: center; gap: 6px;
    cursor: default; opacity: 0.35;
    transition: opacity 0.3s;
}
.step-item.active, .step-item.done { opacity: 1; }
.step-num {
    width: 32px; height: 32px;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 14px; font-weight: 700;
    border: 2px solid var(--border);
    color: var(--text-dim);
    transition: all 0.3s;
}
.step-item.active .step-num { border-color: var(--accent); color: #fff; background: var(--accent); }
.step-item.done .step-num { border-color: var(--success); color: #fff; background: var(--success); }
.step-item span { font-size: 12px; color: var(--text-dim); white-space: nowrap; }
.step-item.active span { color: var(--text); }

.step-line {
    width: 48px; height: 2px;
    background: var(--border);
    margin: 0 8px;
    margin-bottom: 20px;
    transition: background 0.3s;
}
.step-line.done { background: var(--success); }

/* --- Main Content --- */
.main-content {
    flex: 1;
    max-width: 960px;
    margin: 0 auto;
    padding: 32px 24px;
    width: 100%;
}

.step-panel { display: none; animation: fadeIn 0.3s ease; }
.step-panel.active { display: block; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.step-panel h2 { font-size: 22px; font-weight: 700; margin-bottom: 8px; }
.step-desc { color: var(--text-dim); margin-bottom: 28px; font-size: 14px; }
.step-actions { display: flex; gap: 12px; justify-content: flex-end; margin-top: 32px; }

/* --- Solution Grid --- */
.solutions-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 16px;
}
.solution-card {
    background: var(--bg-card);
    border: 2px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 20px;
    cursor: pointer;
    transition: all 0.2s;
    position: relative;
}
.solution-card:hover { border-color: var(--text-muted); background: var(--bg-card-hover); }
.solution-card.selected { border-color: var(--accent); background: rgba(91,110,245,0.06); }
.solution-card .sol-name { font-size: 16px; font-weight: 700; margin-bottom: 4px; }
.solution-card .sol-desc { font-size: 13px; color: var(--text-dim); margin-bottom: 8px; }
.solution-card .sol-type {
    display: inline-block; padding: 2px 10px; border-radius: 12px;
    font-size: 11px; font-weight: 600;
    background: rgba(91,110,245,0.12); color: var(--accent);
}
.sol-type.magisk { background: rgba(48,164,108,0.12); color: var(--success); }
.sol-type.apatch { background: rgba(245,166,35,0.12); color: var(--warning); }
.solution-card .sol-check {
    position: absolute; top: 12px; right: 12px;
    width: 22px; height: 22px;
    border-radius: 50%;
    border: 2px solid var(--border);
    display: flex; align-items: center; justify-content: center;
    font-size: 12px;
    transition: all 0.2s;
}
.solution-card.selected .sol-check {
    border-color: var(--accent); background: var(--accent); color: #fff;
}

/* --- Mode Selector --- */
.mode-selector { display: flex; gap: 12px; margin-bottom: 24px; flex-wrap: wrap; }
.mode-card {
    flex: 1; min-width: 200px;
    cursor: pointer; display: block;
}
.mode-card input { display: none; }
.mode-body {
    padding: 16px 20px;
    background: var(--bg-card);
    border: 2px solid var(--border);
    border-radius: var(--radius);
    transition: all 0.2s;
    position: relative;
}
.mode-card input:checked + .mode-body {
    border-color: var(--accent);
    background: rgba(91,110,245,0.06);
}
.mode-card:hover .mode-body { border-color: var(--text-muted); }
.mode-body strong { font-size: 15px; display: block; margin-bottom: 4px; }
.mode-body p { font-size: 12px; color: var(--text-dim); margin: 0; }
.mode-badge {
    position: absolute; top: -8px; right: 12px;
    padding: 2px 10px; border-radius: 10px;
    font-size: 10px; font-weight: 700;
}
.mode-badge.recommended { background: var(--success); color: #fff; }

/* --- Agent Steps --- */
.agent-steps { margin: 16px 0 20px; }
.agent-step {
    display: flex; align-items: flex-start; gap: 10px;
    padding: 8px 0; font-size: 13px; color: var(--text-dim);
}
.agent-step-num {
    width: 22px; height: 22px; flex-shrink: 0;
    border-radius: 50%; background: var(--accent);
    color: #fff; font-size: 12px; font-weight: 700;
    display: flex; align-items: center; justify-content: center;
}
.agent-step code {
    background: var(--bg-input);
    padding: 2px 8px; border-radius: 4px;
    font-family: Consolas, monospace; font-size: 12px;
    color: var(--text);
}
.agent-alt-hint {
    margin: 0 0 16px;
    padding: 12px 14px;
    font-size: 12px;
    line-height: 1.55;
    color: var(--text-dim);
    text-align: left;
    background: var(--bg-input);
    border-radius: var(--radius);
    border: 1px solid var(--border);
}
.agent-alt-hint a { color: var(--accent); }

/* --- Connect Area --- */
.connect-area { display: flex; gap: 24px; flex-wrap: wrap; }
.connect-box {
    flex: 1; min-width: 280px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 32px;
    text-align: center;
}
.connect-icon { color: var(--accent); margin-bottom: 16px; }
.connect-box h3 { font-size: 18px; margin-bottom: 8px; }
.connect-box p { font-size: 13px; color: var(--text-dim); margin-bottom: 20px; }
.connect-status { margin-top: 16px; font-size: 13px; white-space: pre-line; word-break: break-word; text-align: left; }

.troubleshoot-box {
    margin-top: 20px; padding: 16px;
    background: rgba(245,166,35,0.08);
    border: 1px solid rgba(245,166,35,0.25);
    border-radius: var(--radius);
    font-size: 13px; text-align: left;
}
.troubleshoot-box strong { color: var(--warning); }
.troubleshoot-box ol { margin: 10px 0 0 16px; line-height: 1.9; color: var(--text-dim); }
.troubleshoot-box li { margin-bottom: 4px; }
.troubleshoot-box code {
    background: var(--bg-input);
    padding: 2px 8px; border-radius: 4px;
    font-family: Consolas, monospace; font-size: 12px;
}
.troubleshoot-box a { color: var(--accent); text-decoration: none; }
.troubleshoot-box a:hover { text-decoration: underline; }
.troubleshoot-kill-wrap { margin: 0 0 10px; font-size: 13px; line-height: 1.55; color: var(--text-dim); text-align: left; }
.troubleshoot-kill-btn { margin: 8px 0; width: 100%; max-width: 360px; }
.troubleshoot-kill-hint { margin: 0 0 12px; font-size: 12px; color: var(--text-dim); text-align: left; }
.troubleshoot-hr { border: none; border-top: 1px solid var(--border); margin: 14px 0; }

.device-info {
    flex: 1; min-width: 280px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 24px;
}
.device-info h3 { font-size: 16px; margin-bottom: 16px; }
.info-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.info-item { display: flex; flex-direction: column; }
.info-label { font-size: 12px; color: var(--text-muted); font-weight: 500; }
.info-value { font-size: 14px; font-weight: 600; margin-top: 2px; }

/* --- File Selectors --- */
.file-selectors { display: flex; gap: 24px; flex-wrap: wrap; }
.file-box {
    flex: 1; min-width: 280px;
    background: var(--bg-card);
    border: 2px dashed var(--border);
    border-radius: var(--radius-lg);
    padding: 32px;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s;
    position: relative;
}
.file-box:hover { border-color: var(--accent); background: var(--bg-card-hover); }
.file-box.has-file { border-style: solid; border-color: var(--success); }
.file-icon {
    width: 56px; height: 56px;
    background: rgba(91,110,245,0.1);
    border-radius: 14px;
    display: inline-flex; align-items: center; justify-content: center;
    font-size: 16px; font-weight: 800; color: var(--accent);
    margin-bottom: 16px;
}
.file-box.has-file .file-icon { background: rgba(48,164,108,0.1); color: var(--success); }
.file-box h3 { font-size: 16px; margin-bottom: 4px; }
.file-hint { font-size: 13px; color: var(--text-muted); }
.file-input-hidden { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.file-info { margin-top: 12px; font-size: 13px; color: var(--success); }

.superkey-section {
    margin-top: 24px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 24px;
}
.superkey-section h3 { font-size: 16px; margin-bottom: 8px; }
.superkey-section p { font-size: 13px; color: var(--text-dim); margin-bottom: 12px; }

/* --- Confirm --- */
.confirm-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 28px;
}
.confirm-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.confirm-item { display: flex; flex-direction: column; }
.confirm-label { font-size: 12px; color: var(--text-muted); font-weight: 500; }
.confirm-value { font-size: 15px; font-weight: 600; margin-top: 2px; }

.confirm-warning {
    margin-top: 20px; padding: 16px;
    background: rgba(229,72,77,0.08);
    border: 1px solid rgba(229,72,77,0.25);
    border-radius: var(--radius);
}
.confirm-warning strong { color: var(--danger); font-size: 14px; }
.confirm-warning p { color: var(--text-dim); font-size: 13px; margin-top: 4px; }

.flash-mode-select { margin-top: 24px; }
.flash-mode-select h3 { font-size: 16px; margin-bottom: 12px; }
.radio-card {
    display: inline-flex; cursor: pointer; margin-right: 12px;
}
.radio-card input { display: none; }
.radio-body {
    padding: 12px 20px;
    background: var(--bg-card);
    border: 2px solid var(--border);
    border-radius: var(--radius);
    transition: all 0.2s;
}
.radio-card input:checked + .radio-body { border-color: var(--accent); background: rgba(91,110,245,0.06); }
.radio-body strong { font-size: 14px; display: block; }
.radio-body p { font-size: 12px; color: var(--text-dim); margin-top: 2px; }

/* --- Execution --- */
.exec-status {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 24px;
    margin-bottom: 24px;
}
.exec-steps { margin-bottom: 20px; }
.exec-step {
    display: flex; align-items: center; gap: 12px;
    padding: 8px 0;
    font-size: 14px;
    color: var(--text-muted);
}
.exec-step.active { color: var(--text); }
.exec-step.done { color: var(--success); }
.exec-step.error { color: var(--danger); }
.exec-step-icon {
    width: 24px; height: 24px;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 12px; font-weight: 700;
    border: 2px solid var(--border);
    flex-shrink: 0;
}
.exec-step.active .exec-step-icon { border-color: var(--accent); color: var(--accent); }
.exec-step.done .exec-step-icon { border-color: var(--success); background: var(--success); color: #fff; }
.exec-step.error .exec-step-icon { border-color: var(--danger); background: var(--danger); color: #fff; }

@keyframes spin { to { transform: rotate(360deg); } }
.exec-step.active .exec-step-icon::after {
    content: '';
    width: 12px; height: 12px;
    border: 2px solid transparent;
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

.progress-section { display: flex; align-items: center; gap: 12px; }
.progress-bar-container {
    flex: 1; height: 8px;
    background: var(--bg-input);
    border-radius: 4px;
    overflow: hidden;
}
.progress-bar {
    height: 100%;
    background: linear-gradient(90deg, var(--accent), #8b5cf6);
    border-radius: 4px;
    transition: width 0.3s ease;
}
.progress-text { font-size: 13px; font-weight: 600; color: var(--text-dim); min-width: 36px; }

/* --- Fastboot Reconnect --- */
.fastboot-reconnect {
    text-align: center;
    padding: 32px;
    margin-bottom: 24px;
    background: var(--bg-card);
    border: 2px dashed var(--accent);
    border-radius: var(--radius-lg);
    animation: pulse-border 2s ease-in-out infinite;
}
@keyframes pulse-border {
    0%, 100% { border-color: var(--accent); }
    50% { border-color: var(--text-muted); }
}
.fastboot-reconnect .connect-icon { color: var(--warning); }
.fastboot-reconnect h3 { margin: 12px 0 8px; }
.fastboot-reconnect p { color: var(--text-dim); font-size: 13px; margin-bottom: 20px; }

/* --- Log --- */
.log-section {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
}
.log-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
}
.log-header h3 { font-size: 14px; }
.log-output {
    height: 280px;
    overflow-y: auto;
    padding: 12px 16px;
    font-family: 'Cascadia Code', 'Fira Code', 'SF Mono', Consolas, monospace;
    font-size: 12px;
    line-height: 1.7;
}
.log-output .log-line { white-space: pre-wrap; word-break: break-all; }
.log-line.log-info { color: var(--text-dim); }
.log-line.log-success { color: var(--success); }
.log-line.log-error { color: var(--danger); }
.log-line.log-warn { color: var(--warning); }
.log-line.log-cmd { color: var(--accent); }

/* --- Result --- */
.result-section {
    text-align: center;
    padding: 48px 24px;
    margin-top: 24px;
}
.result-icon {
    width: 80px; height: 80px;
    border-radius: 50%;
    display: inline-flex; align-items: center; justify-content: center;
    font-size: 36px; margin-bottom: 20px;
}
.result-icon.success { background: rgba(48,164,108,0.12); color: var(--success); }
.result-icon.error { background: rgba(229,72,77,0.12); color: var(--danger); }
.result-section h2 { margin-bottom: 8px; }
.result-section p { color: var(--text-dim); margin-bottom: 24px; }

/* --- Scrollbar --- */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* --- Responsive --- */
@media (max-width: 640px) {
    .login-card { margin: 16px; padding: 32px 24px; }
    .steps-nav { padding: 12px 8px; gap: 0; overflow-x: auto; }
    .step-line { width: 24px; }
    .step-item span { font-size: 10px; }
    .main-content { padding: 20px 16px; }
    .solutions-grid { grid-template-columns: 1fr; }
    .connect-area, .file-selectors { flex-direction: column; }
    .confirm-grid { grid-template-columns: 1fr; }
    .info-grid { grid-template-columns: 1fr; }
}
