:root {
  --bg: #f5f6f8;
  --card: #ffffff;
  --text: #111827;
  --muted: #6b7280;
  --line: #e5e7eb;
  --line-strong: #d1d5db;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --ok: #059669;
  --ok-bg: #ecfdf5;
  --danger: #dc2626;
  --danger-bg: #fef2f2;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 8px 24px rgba(16, 24, 40, .06);
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; max-width: 100%; overflow-x: hidden; }

/* flex / grid 子项默认 min-width:auto，长文本会把容器撑破，统一放开 */
#app, .card, .row, .grid2, .field, .card-head, .topbar { min-width: 0; }
.row > *, .grid2 > *, .card-head > * { min-width: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
        "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
  padding-bottom: env(safe-area-inset-bottom);
}

[hidden] { display: none !important; }

/* ---------------- 通用 ---------------- */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  margin: 0 0 16px;
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.card-head h2 {
  font-size: 16px;
  margin: 0;
  font-weight: 650;
  letter-spacing: .2px;
}

h1 { font-size: 20px; margin: 0 0 6px; }

.muted { color: var(--muted); }
.xsmall { font-size: 12px; }
.req { color: var(--danger); }
.hint { color: var(--muted); font-style: normal; font-size: 12px; font-weight: 400; margin-left: 6px; }

.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.row.tight { gap: 8px; }

/* ---------------- 表单 ---------------- */
.field { display: block; margin-bottom: 14px; }
.field > span {
  display: block;
  font-size: 13px;
  font-weight: 550;
  margin-bottom: 6px;
  color: #374151;
}

input {
  width: 100%;
  height: 44px;
  padding: 0 13px;
  /* ≥16px：iOS 聚焦时不会自动放大页面 */
  font-size: 16px;
  color: var(--text);
  background: #fff;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
  font-family: inherit;
}

/* 模拟密码框：显示为圆点，但浏览器当普通文本框处理（不弹密码键盘/不提示保存密码） */
.masked { -webkit-text-security: disc; }

input::placeholder { color: #9ca3af; }

input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, .14);
}

.code-input {
  width: 150px;
  letter-spacing: .16em;
  font-family: var(--mono);
  text-align: center;
}
.code-input.wide { width: 190px; }

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }

/* ---------------- 按钮 ---------------- */
.btn {
  height: 40px;
  padding: 0 16px;
  font-size: 14px;
  font-weight: 550;
  font-family: inherit;
  color: var(--text);
  background: #fff;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  cursor: pointer;
  transition: background .15s, border-color .15s, transform .05s;
  white-space: nowrap;
}

.btn:hover { background: #f9fafb; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; transform: none; }

.btn.primary {
  color: #fff;
  background: var(--primary);
  border-color: var(--primary);
}
.btn.primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); }

.btn.ghost { background: transparent; border-color: var(--line); color: #374151; }
.btn.ghost:hover { background: #f3f4f6; }

.btn.sm { height: 34px; padding: 0 12px; font-size: 13px; border-radius: 9px; }
.btn.block { width: 100%; height: 46px; font-size: 15px; }

/* ---------------- 密码门 ---------------- */
.gate {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
}

.gate-card { width: 100%; max-width: 380px; text-align: center; }
.gate-card .field { text-align: left; margin-top: 18px; }
.gate-card h1 { margin-top: 10px; }
.gate-card .err { text-align: left; }

.brand-mark { font-size: 34px; line-height: 1; }
.brand-mark.sm { font-size: 18px; }

/* ---------------- 主界面 ---------------- */
#app { max-width: 860px; margin: 0 auto; padding: 16px; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 4px 2px 14px;
}

.brand { display: flex; align-items: center; gap: 8px; font-size: 15px; }
.topbar-right { display: flex; align-items: center; gap: 10px; }

/* 步骤 */
.steps {
  display: flex;
  align-items: center;
  gap: 6px;
  list-style: none;
  margin: 0;
  padding: 0;
  counter-reset: s;
}

.step {
  font-size: 12px;
  color: var(--muted);
  background: #f3f4f6;
  border-radius: 999px;
  padding: 4px 10px;
  counter-increment: s;
}

.step::before { content: counter(s) ". "; opacity: .65; }
.step.on { color: #fff; background: var(--primary); }
.step.done { color: var(--ok); background: var(--ok-bg); }

/* 图形码 */
.sub {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px dashed var(--line);
}

.cap-row { display: flex; align-items: center; gap: 14px; margin-bottom: 14px; }

#capImg {
  height: 52px;
  min-width: 120px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #f9fafb;
  cursor: pointer;
  object-fit: contain;
}

.cap-side { display: flex; flex-direction: column; gap: 6px; }

/* 结果 */
.result {
  margin-top: 16px;
  padding: 16px;
  border: 1px solid #a7f3d0;
  background: var(--ok-bg);
  border-radius: 12px;
}

.result-head { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.result-head b { color: var(--ok); font-size: 14px; }

.mono {
  font-family: var(--mono);
  font-size: 12.5px;
  line-height: 1.6;
}

.block-text {
  margin: 0 0 12px;
  padding: 12px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  white-space: pre-wrap;
  word-break: break-all;
  max-height: 220px;
  overflow: auto;
  user-select: all;
}

/* 诊断结果是给人读的多行报告，不该被限高截断，也不该把 LAX 拆成两行 */
#diagOut {
  max-height: none;
  font-size: 13px;
  line-height: 1.65;
  word-break: break-word;
  background: #fbfcfd;
}

/* 列表 */
.badge {
  display: inline-block;
  min-width: 22px;
  padding: 1px 7px;
  font-size: 12px;
  font-weight: 600;
  color: var(--primary);
  background: #eff6ff;
  border-radius: 999px;
  text-align: center;
  vertical-align: middle;
}

.list { display: flex; flex-direction: column; gap: 10px; margin-top: 12px; }

.rec {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
}

.rec-main { flex: 1; min-width: 0; }

.rec-note {
  display: inline-block;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 4px;
  padding: 1px 8px;
  border-radius: 6px;
  background: #f3f4f6;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.rec-cookie {
  display: block;
  font-family: var(--mono);
  font-size: 11.5px;
  color: #4b5563;
  word-break: break-all;
  cursor: pointer;
  line-height: 1.5;
}

.rec-cookie.open { color: var(--text); }

.rec-actions { display: flex; flex-direction: column; gap: 6px; }

/* 错误 / 提示 */
.err {
  margin: 12px 0 0;
  padding: 10px 12px;
  font-size: 13px;
  color: var(--danger);
  background: var(--danger-bg);
  border: 1px solid #fecaca;
  border-radius: 10px;
  word-break: break-word;
}

.foot { text-align: center; padding: 8px 0 32px; }

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(28px + env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(8px);
  max-width: min(90vw, 460px);
  padding: 10px 16px;
  font-size: 13px;
  color: #fff;
  background: #111827;
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(16, 24, 40, .22);
  opacity: 0;
  transition: opacity .18s, transform .18s;
  pointer-events: none;
  z-index: 50;
}

.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.bad { background: var(--danger); }

.mono-ellipsis {
  font-family: var(--mono);
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.is-busy { position: relative; pointer-events: none; opacity: .7; }

/* 小屏 */
@media (max-width: 560px) {
  .grid2 { grid-template-columns: 1fr; }
  .card { padding: 16px; border-radius: 12px; }
  .code-input, .code-input.wide { flex: 1; width: auto; min-width: 0; }
  .row > .btn { flex: 0 0 auto; }
  .row > input { flex: 1 1 140px; }
  .steps { order: 3; width: 100%; }
  #uaHint { flex: 1 1 100%; width: 100%; }
  #capImg { height: 46px; }
  .rec { flex-direction: column; gap: 8px; }
  .rec-actions { flex-direction: row; width: 100%; }
  .rec-actions .btn { flex: 1; }
  .topbar { flex-wrap: wrap; row-gap: 6px; }
  #sessionLeft { font-size: 11px; }
}
