:root {
  --bg-body: #f0f2f5;
  --bg-card: #fff;
  --bg-input: #fff;
  --bg-placeholder: #fafafa;
  --bg-result: #f6ffed;
  --bg-jslogin: #f0f7ff;
  --bg-log: #1a1a1a;
  --text-primary: #1a1a1a;
  --text-secondary: #555;
  --text-muted: #888;
  --text-placeholder: #bbb;
  --border-color: #d9d9d9;
  --border-light: #eee;
  --border-result: #b7eb8f;
  --border-jslogin: #91caff;
  --shadow: 0 4px 20px rgba(0,0,0,.08);
  --divider: #f0f0f0;
}

[data-theme="dark"] {
  --bg-body: #1a1a1a;
  --bg-card: #2d2d2d;
  --bg-input: #3d3d3d;
  --bg-placeholder: #3d3d3d;
  --bg-result: #2a3d2a;
  --bg-jslogin: #2a3d4d;
  --bg-log: #1a1a1a;
  --text-primary: #e0e0e0;
  --text-secondary: #aaa;
  --text-muted: #888;
  --text-placeholder: #666;
  --border-color: #444;
  --border-light: #444;
  --border-result: #4a6b4a;
  --border-jslogin: #4a6b8a;
  --shadow: 0 4px 20px rgba(0,0,0,.3);
  --divider: #444;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg-body);
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  transition: background .3s;
}

.container {
  display: flex;
  flex-direction: column;
  gap: 16px;
  align-items: center;
  width: 100%;
  max-width: 800px;
}

.card {
  background: var(--bg-card);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 24px 20px;
  width: 100%;
  max-width: 420px;
  transition: background .3s, box-shadow .3s;
}

h2 {
  font-size: 18px;
  color: var(--text-primary);
  margin-bottom: 20px;
  text-align: center;
  transition: color .3s;
}

.field { margin-bottom: 16px; }

label {
  display: block;
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 6px;
  transition: color .3s;
}

input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border-color);
  border-radius: 6px;
  font-size: 16px; /* 防止iOS缩放 */
  outline: none;
  transition: border .2s, background .3s, color .3s;
  background: var(--bg-input);
  color: var(--text-primary);
}

input:focus { border-color: #07c160; }

.btn {
  width: 100%;
  padding: 12px;
  background: #07c160;
  color: #fff;
  border: none;
  border-radius: 6px;
  font-size: 16px;
  cursor: pointer;
  transition: background .2s;
  -webkit-tap-highlight-color: transparent;
}

.btn:hover { background: #06ad56; }
.btn:disabled { background: #a8d5b8; cursor: not-allowed; }

.qr-wrap {
  text-align: center;
  margin: 16px 0 8px;
}

.qr-wrap img {
  width: 180px;
  height: 180px;
  border: 1px solid var(--border-light);
  border-radius: 8px;
  margin: 0 auto;
  background: #fff;
  padding: 8px;
  transition: border .3s;
}

.qr-placeholder {
  width: 180px;
  height: 180px;
  border: 1px solid var(--border-light);
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-placeholder);
  font-size: 13px;
  background: var(--bg-placeholder);
  transition: border .3s, background .3s, color .3s;
  padding: 10px;
  text-align: center;
}

.status {
  text-align: center;
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 12px;
  transition: color .3s;
}

.status.ok { color: #07c160; }
.status.err { color: #e74c3c; }

.result {
  background: var(--bg-result);
  border: 1px solid var(--border-result);
  border-radius: 6px;
  padding: 12px;
  font-size: 13px;
  line-height: 1.8;
  margin-top: 12px;
  word-break: break-all;
  transition: background .3s, border .3s;
}

.result .row {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.result .lbl { color: var(--text-muted); font-size: 12px; }
.result .val { color: var(--text-primary); font-weight: 500; }

.divider {
  border: none;
  border-top: 1px solid var(--divider);
  margin: 20px 0;
  transition: border .3s;
}

.section-title {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 12px;
  transition: color .3s;
}

#jslogin-result {
  background: var(--bg-jslogin);
  border: 1px solid var(--border-jslogin);
  border-radius: 6px;
  padding: 12px;
  font-size: 13px;
  margin-top: 12px;
  word-break: break-all;
  transition: background .3s, border .3s;
}

.code-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 8px;
}

#code-value {
  font-family: 'Monaco', 'Menlo', monospace;
  color: #1890ff;
  word-break: break-all;
  flex: 1;
  min-width: 0;
}

.copy-btn {
  padding: 6px 12px;
  font-size: 13px;
  background: #1890ff;
  color: #fff;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  transition: background .2s;
  -webkit-tap-highlight-color: transparent;
  flex-shrink: 0;
}

.copy-btn:hover { background: #40a9ff; }

.log-panel {
  background: var(--bg-card);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 16px;
  width: 100%;
  max-width: 420px;
  transition: background .3s, box-shadow .3s;
}

.log-title {
  font-size: 14px;
  color: var(--text-primary);
  margin-bottom: 10px;
  font-weight: 500;
  display: flex;
  justify-content: space-between;
  align-items: center;
  transition: color .3s;
}

.log-clear {
  font-size: 12px;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px 8px;
}

.log-clear:hover { color: #1677ff; }

.log-content {
  background: var(--bg-log);
  border-radius: 8px;
  padding: 10px;
  height: 250px;
  overflow-y: auto;
  font-family: 'Monaco', 'Menlo', monospace;
  font-size: 11px;
  line-height: 1.6;
  -webkit-overflow-scrolling: touch;
}

.log-item { margin-bottom: 4px; }
.log-time { color: #888; }
.log-info { color: #52c41a; }
.log-warn { color: #faad14; }
.log-error { color: #ff4d4f; }
.log-debug { color: #1890ff; }

.theme-toggle {
  position: fixed;
  top: 12px;
  right: 12px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  box-shadow: var(--shadow);
  transition: all .3s;
  z-index: 100;
  -webkit-tap-highlight-color: transparent;
}

.theme-toggle:hover { transform: scale(1.1); }
.theme-toggle .icon-sun { display: block; }
.theme-toggle .icon-moon { display: none; }
[data-theme="dark"] .theme-toggle .icon-sun { display: none; }
[data-theme="dark"] .theme-toggle .icon-moon { display: block; }

/* 平板及以上 */
@media (min-width: 768px) {
  body { padding: 24px; }
  
  .container {
    flex-direction: row;
    align-items: flex-start;
    gap: 20px;
  }
  
  .card {
    padding: 32px 36px;
    width: 420px;
    max-width: 420px;
  }
  
  h2 { font-size: 20px; margin-bottom: 24px; }
  
  .qr-wrap img, .qr-placeholder { width: 200px; height: 200px; }
  
  .result .row { flex-direction: row; gap: 8px; }
  .result .lbl { min-width: 70px; }
  
  .log-panel { width: 360px; max-width: 360px; padding: 20px; }
  .log-content { height: 420px; font-size: 12px; }
  
  .theme-toggle { top: 20px; right: 20px; width: 44px; height: 44px; font-size: 20px; }
}

/* 安全区域适配（刘海屏） */
@supports (padding-top: env(safe-area-inset-top)) {
  body { padding-top: calc(16px + env(safe-area-inset-top)); }
  .theme-toggle { top: calc(12px + env(safe-area-inset-top)); }
}
