/* ============ ERCode Online 设计系统 ============ */

:root {
  --radius: 14px;
  --radius-sm: 10px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", sans-serif;
  --mono: ui-monospace, "Cascadia Code", Consolas, "JetBrains Mono", monospace;
}

:root[data-theme="light"] {
  --bg: #f2f4fa;
  --bg-soft: #e9edf7;
  --surface: #ffffff;
  --surface-2: #f7f9fd;
  --surface-3: #eef2fa;
  --text: #18213a;
  --text-strong: #0c1226;
  --muted: #5f6b87;
  --faint: #98a2bd;
  --border: #e2e8f5;
  --border-strong: #cbd5ec;
  --accent: #5457d6;
  --accent-strong: #4346c4;
  --accent-soft: rgba(84, 87, 214, 0.1);
  --accent-contrast: #ffffff;
  --grad: linear-gradient(135deg, #5457d6 0%, #8b5cf6 55%, #b45cf0 100%);
  --ok: #0a9d6c;
  --ok-soft: rgba(10, 157, 108, 0.12);
  --warn: #c2620a;
  --warn-soft: rgba(194, 98, 10, 0.12);
  --err: #d43d51;
  --err-soft: rgba(212, 61, 81, 0.1);
  --shadow-sm: 0 1px 2px rgba(16, 24, 52, 0.06);
  --shadow: 0 1px 2px rgba(16, 24, 52, 0.05), 0 10px 30px rgba(16, 24, 52, 0.08);
  --shadow-lg: 0 12px 44px rgba(16, 24, 52, 0.16);
  --drop-bg: rgba(246, 248, 253, 0.85);
  --code-bg: #f0f3fb;
}

:root[data-theme="dark"] {
  --bg: #0a0e1a;
  --bg-soft: #0d1324;
  --surface: #141b2f;
  --surface-2: #1a2340;
  --surface-3: #212c4e;
  --text: #e7ecf8;
  --text-strong: #ffffff;
  --muted: #9aa7c4;
  --faint: #67748f;
  --border: #263253;
  --border-strong: #3a4a77;
  --accent: #8789f2;
  --accent-strong: #a3a5ff;
  --accent-soft: rgba(135, 137, 242, 0.16);
  --accent-contrast: #0c0f22;
  --grad: linear-gradient(135deg, #6366f1 0%, #8b5cf6 55%, #c084fc 100%);
  --ok: #2ec98c;
  --ok-soft: rgba(46, 201, 140, 0.14);
  --warn: #f0a35c;
  --warn-soft: rgba(240, 163, 92, 0.14);
  --err: #ff7185;
  --err-soft: rgba(255, 113, 133, 0.13);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.35);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 12px 34px rgba(0, 0, 0, 0.38);
  --shadow-lg: 0 16px 50px rgba(0, 0, 0, 0.5);
  --drop-bg: rgba(19, 26, 47, 0.85);
  --code-bg: #1b2440;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  /* 用 clip 而非 hidden:hidden 会让 body 成为滚动容器,破坏后代 position:sticky */
  overflow-x: clip;
}

/* 防御:替换型元素与文本输入永不撑破 flex/grid 容器 */
input, select, textarea { min-width: 0; }
.qr-stage canvas, .qr-stage img, .qr-stage svg { max-width: 100%; height: auto; }
.history-item .h-text { min-width: 0; }
.url-row input { flex: 1 1 0; }

body {
  font-family: var(--font);
  background:
    radial-gradient(1100px 480px at 85% -10%, var(--accent-soft), transparent 60%),
    radial-gradient(900px 420px at -10% 0%, rgba(180, 92, 240, 0.08), transparent 55%),
    var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  transition: background-color 0.25s ease, color 0.25s ease;
}

::selection { background: var(--accent-soft); }

/* ---------- 顶栏 ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 10px clamp(14px, 4vw, 34px);
  background: color-mix(in srgb, var(--bg) 72%, transparent);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--text-strong);
  flex-shrink: 0;
}

.brand-logo {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 11px;
  background: var(--grad);
  color: #fff;
  box-shadow: var(--shadow-sm);
}

.brand-text {
  font-size: 17px;
  font-weight: 750;
  letter-spacing: 0.2px;
  display: flex;
  flex-direction: column;
  line-height: 1.15;
}

.brand-text small {
  font-size: 11px;
  font-weight: 500;
  color: var(--muted);
  letter-spacing: 0.5px;
}

.nav {
  display: flex;
  gap: 4px;
  margin: 0 auto;
  overflow-x: auto;
  scrollbar-width: none;
}

.nav::-webkit-scrollbar { display: none; }

.nav-btn {
  appearance: none;
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 14.5px;
  font-weight: 550;
  padding: 8px 16px;
  border-radius: 999px;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.16s ease;
}

.nav-btn:hover { color: var(--text); background: var(--surface-2); }

.nav-btn.active {
  color: var(--accent-contrast);
  background: var(--grad);
  box-shadow: 0 4px 14px rgba(99, 102, 241, 0.35);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.icon-btn {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
  transition: all 0.15s ease;
}

.icon-btn:hover { color: var(--text); border-color: var(--border-strong); transform: translateY(-1px); }

:root[data-theme="light"] .icon-moon { display: none; }
:root[data-theme="dark"] .icon-sun { display: none; }

.auth-area { display: flex; align-items: center; gap: 8px; }

.user-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px 6px 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 999px;
  font-size: 13.5px;
  font-weight: 600;
}

.user-chip .avatar {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--grad);
  color: #fff;
  display: grid;
  place-items: center;
  font-size: 12px;
  text-transform: uppercase;
}

.user-chip .uc-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-chip .badge-2fa {
  font-size: 10.5px;
  padding: 2px 7px;
  border-radius: 99px;
  background: var(--ok-soft);
  color: var(--ok);
  font-weight: 700;
}

.user-chip .badge-2fa.off { background: var(--warn-soft); color: var(--warn); }

/* ---------- 布局 ---------- */

.view {
  flex: 1;
  width: 100%;
  max-width: 1180px;
  margin: 0 auto;
  padding: 26px clamp(14px, 4vw, 34px) 60px;
}

.footer {
  border-top: 1px solid var(--border);
  padding: 16px clamp(14px, 4vw, 34px);
  display: flex;
  flex-wrap: wrap;
  gap: 6px 20px;
  justify-content: space-between;
  font-size: 12.5px;
  color: var(--faint);
}

.page-head { margin: 4px 0 22px; }

.page-head h1 {
  margin: 0 0 6px;
  font-size: clamp(21px, 3vw, 26px);
  font-weight: 780;
  color: var(--text-strong);
  letter-spacing: 0.2px;
}

.page-head h1 .grad-text {
  background: var(--grad);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.page-head p { margin: 0; color: var(--muted); font-size: 14px; }

/* ---------- 卡片 ---------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}

.card + .card { margin-top: 18px; }

.card-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 15px;
  font-weight: 700;
  color: var(--text-strong);
  margin: 0 0 14px;
}

.card-title .dot {
  width: 8px;
  height: 8px;
  border-radius: 3px;
  background: var(--grad);
  flex-shrink: 0;
}

.card-title .spacer { flex: 1; }

/* ---------- 表单 ---------- */

label.field { display: block; margin-bottom: 13px; }

.field > span {
  display: block;
  font-size: 12.5px;
  font-weight: 650;
  color: var(--muted);
  margin-bottom: 6px;
}

input[type="text"], input[type="password"], input[type="url"], input[type="number"], input[type="tel"], input[type="email"], select, textarea {
  width: 100%;
  font: inherit;
  font-size: 14px;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

textarea { resize: vertical; min-height: 84px; }

input[type="range"] { accent-color: var(--accent); width: 100%; }

input[type="color"] {
  width: 42px;
  height: 34px;
  padding: 2px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-2);
  cursor: pointer;
}

.btn {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  font: inherit;
  font-size: 14px;
  font-weight: 640;
  padding: 9px 18px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
}

.btn:disabled { opacity: 0.55; cursor: not-allowed; }

.btn-primary {
  background: var(--grad);
  color: #fff;
  box-shadow: 0 4px 16px rgba(99, 102, 241, 0.35);
}

.btn-primary:hover:not(:disabled) { transform: translateY(-1px); box-shadow: 0 6px 22px rgba(99, 102, 241, 0.45); }

.btn-ghost {
  background: var(--surface-2);
  color: var(--text);
  border-color: var(--border);
}

.btn-ghost:hover:not(:disabled) { border-color: var(--border-strong); background: var(--surface-3); }

.btn-danger { background: var(--err-soft); color: var(--err); border-color: transparent; }
.btn-danger:hover:not(:disabled) { background: var(--err); color: #fff; }

.btn-sm { padding: 6px 12px; font-size: 13px; border-radius: 8px; }

.btn-row { display: flex; flex-wrap: wrap; gap: 9px; align-items: center; }

/* ---------- Chips / 开关 ---------- */

.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  font-weight: 650;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--surface-3);
  color: var(--muted);
  border: 1px solid var(--border);
}

.chip.ok { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.chip.err { background: var(--err-soft); color: var(--err); border-color: transparent; }
.chip.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.chip.acc { background: var(--accent-soft); color: var(--accent); border-color: transparent; }

.seg {
  display: inline-flex;
  padding: 3px;
  gap: 3px;
  background: var(--surface-3);
  border: 1px solid var(--border);
  border-radius: 11px;
  flex-wrap: wrap;
}

.seg button {
  appearance: none;
  border: none;
  background: transparent;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  padding: 6px 13px;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.14s ease;
  white-space: nowrap;
}

.seg button:hover { color: var(--text); }

.seg button.active {
  background: var(--surface);
  color: var(--text-strong);
  box-shadow: var(--shadow-sm);
}

.switch { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-size: 13.5px; color: var(--muted); user-select: none; }
.switch input { display: none; }
.switch .track {
  width: 36px; height: 21px;
  border-radius: 99px;
  background: var(--border-strong);
  position: relative;
  transition: background 0.18s ease;
  flex-shrink: 0;
}
.switch .track::after {
  content: "";
  position: absolute;
  top: 2.5px; left: 3px;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0,0,0,0.3);
  transition: transform 0.18s ease;
}
.switch input:checked + .track { background: var(--accent); }
.switch input:checked + .track::after { transform: translateX(14px); }

/* ---------- 识别页 ---------- */

.decode-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

@media (max-width: 900px) { .decode-grid { grid-template-columns: 1fr; } }

.dropzone {
  border: 2px dashed var(--border-strong);
  border-radius: var(--radius);
  background: var(--drop-bg);
  padding: 38px 22px;
  text-align: center;
  cursor: pointer;
  transition: all 0.18s ease;
}

.dropzone:hover, .dropzone.dragover {
  border-color: var(--accent);
  background: var(--accent-soft);
  transform: translateY(-1px);
}

.dropzone .dz-icon {
  width: 58px;
  height: 58px;
  margin: 0 auto 12px;
  border-radius: 16px;
  background: var(--grad);
  color: #fff;
  display: grid;
  place-items: center;
  box-shadow: 0 8px 24px rgba(99, 102, 241, 0.4);
}

.dropzone h3 { margin: 0 0 6px; font-size: 16.5px; color: var(--text-strong); }

.dropzone p { margin: 0; color: var(--muted); font-size: 13px; }

.dz-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  margin-top: 16px;
}

.url-row { display: flex; gap: 9px; margin-top: 14px; }
.url-row input { flex: 1; }

.result-panel { min-height: 200px; }

/* 识别结果卡与其后的「最近识别」卡分属不同容器,需单独兜底间距 */
.result-panel { margin-bottom: 18px; }

.result-item {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  padding: 13px;
  margin-bottom: 11px;
}

.result-meta { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 9px; align-items: center; }

.result-text {
  font-family: var(--mono);
  font-size: 13.5px;
  line-height: 1.5;
  word-break: break-all;
  white-space: pre-wrap;
  background: var(--code-bg);
  border-radius: 8px;
  padding: 10px 12px;
  margin: 0 0 9px;
  max-height: 190px;
  overflow: auto;
}

.preview-thumb {
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background:
    repeating-conic-gradient(var(--surface-3) 0% 25%, var(--surface) 0% 50%) 0 0 / 18px 18px;
  max-width: 100%;
  object-fit: contain;
  display: block;
  margin: 0 auto 12px;
  max-height: 300px;
}

.history-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 4px;
  border-bottom: 1px dashed var(--border);
  font-size: 13px;
}

.history-item:last-child { border-bottom: none; }
.history-item .h-text { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text); }
.history-item .h-meta { color: var(--faint); font-size: 11.5px; flex-shrink: 0; }
.cap-row { display: flex; flex-wrap: wrap; gap: 7px; }

/* ---------- 生成页 ---------- */

.gen-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(0, 0.85fr);
  gap: 18px;
  /* 注意不设 align-items:start:预览列需拉伸到整行高度,sticky 才有滚动空间 */
}

/* 大屏:实时预览常驻可视区(sticky),滚动控制面板时预览不动 */
@media (min-width: 941px) {
  .gen-preview-col {
    position: sticky;
    top: 78px;
    /* start:按内容高度收缩,把整行高度留作 sticky 活动空间,保证全程钉住 */
    align-self: start;
    max-height: calc(100vh - 96px);
    overflow: auto;
    scrollbar-width: thin;
  }
}

@media (max-width: 940px) { .gen-grid { grid-template-columns: 1fr; } }

.preset-row { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }

.preset-btn {
  appearance: none;
  font: inherit;
  font-size: 12.5px;
  font-weight: 640;
  padding: 6px 13px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--muted);
  cursor: pointer;
  transition: all 0.15s ease;
}

.preset-btn:hover { color: var(--text); border-color: var(--accent); transform: translateY(-1px); }

.preset-btn.active { background: var(--grad); color: #fff; border-color: transparent; box-shadow: 0 4px 14px rgba(99,102,241,.35); }

.color-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px;
}

.color-field {
  display: flex;
  align-items: center;
  gap: 9px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 7px 9px;
}

.color-field .cf-label { flex: 1; font-size: 12.5px; color: var(--muted); font-weight: 600; }
.color-field code { font-size: 11px; color: var(--faint); font-family: var(--mono); }

.qr-stage {
  display: grid;
  place-items: center;
  padding: 26px 16px;
  border-radius: var(--radius);
  background:
    repeating-conic-gradient(var(--surface-3) 0% 25%, var(--surface) 0% 50%) 0 0 / 22px 22px;
  border: 1px solid var(--border);
  min-height: 320px;
}

.qr-stage .qr-holder { display: inline-block; line-height: 0; border-radius: 6px; overflow: hidden; }
.qr-stage svg, .qr-stage canvas, .qr-stage img { display: block; }

.accordion { border: 1px solid var(--border); border-radius: var(--radius-sm); overflow: hidden; margin-bottom: 12px; }
.accordion summary {
  cursor: pointer;
  padding: 11px 14px;
  font-size: 13.5px;
  font-weight: 680;
  color: var(--text);
  background: var(--surface-2);
  list-style: none;
  display: flex;
  align-items: center;
  gap: 8px;
  user-select: none;
}
.accordion summary::-webkit-details-marker { display: none; }
.accordion summary::after { content: "▾"; margin-left: auto; color: var(--faint); transition: transform .15s; }
.accordion[open] summary::after { transform: rotate(180deg); }
.accordion .acc-body { padding: 14px; border-top: 1px solid var(--border); }

.form-2col { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
@media (max-width: 560px) { .form-2col { grid-template-columns: 1fr; } }

/* ---------- 媒体页 ---------- */

.media-toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 16px; }
.media-toolbar .search { flex: 1; min-width: 200px; }

.media-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(172px, 1fr));
  gap: 14px;
}

.media-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  transition: all 0.16s ease;
  display: flex;
  flex-direction: column;
}

.media-card:hover { transform: translateY(-2px); box-shadow: var(--shadow); }

.media-thumb {
  aspect-ratio: 1;
  background: repeating-conic-gradient(var(--surface-3) 0% 25%, var(--surface-2) 0% 50%) 0 0 / 16px 16px;
  display: grid;
  place-items: center;
  overflow: hidden;
}

.media-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }

.media-info { padding: 10px 12px 12px; font-size: 12px; color: var(--muted); display: flex; flex-direction: column; gap: 4px; flex: 1; }
.media-name { font-weight: 650; color: var(--text); font-size: 12.5px; word-break: break-all; line-height: 1.35; max-height: 2.7em; overflow: hidden; }
.media-actions { display: flex; gap: 6px; margin-top: 8px; }
.media-actions .btn { flex: 1; }

.empty-state {
  text-align: center;
  padding: 54px 20px;
  color: var(--muted);
}
.empty-state .es-icon { font-size: 40px; margin-bottom: 10px; opacity: 0.75; }

/* ---------- 设置页 ---------- */

.settings-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 14px; margin-bottom: 18px; }

.stat-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 16px 18px;
  box-shadow: var(--shadow-sm);
}

.stat-card .sc-num { font-size: 25px; font-weight: 800; color: var(--text-strong); font-variant-numeric: tabular-nums; }
.stat-card .sc-label { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.stat-card .sc-sub { font-size: 11.5px; color: var(--faint); margin-top: 6px; }

.table-wrap { overflow-x: auto; }

table.list-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.list-table th { text-align: left; color: var(--faint); font-weight: 650; font-size: 12px; padding: 8px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.list-table td { padding: 9px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
.list-table tr:last-child td { border-bottom: none; }
.list-table code { font-family: var(--mono); font-size: 12px; }

/* ---------- 登录模态 / 2FA ---------- */

.modal-mask {
  position: fixed;
  inset: 0;
  background: rgba(8, 11, 24, 0.55);
  backdrop-filter: blur(6px);
  display: grid;
  place-items: center;
  z-index: 100;
  padding: 18px;
  animation: fadeIn 0.16s ease;
}

.modal {
  width: 100%;
  max-width: 430px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: var(--shadow-lg);
  padding: 24px;
  animation: popIn 0.2s cubic-bezier(0.2, 1.4, 0.4, 1);
  max-height: 90vh;
  overflow: auto;
}

.modal h3 { margin: 0 0 4px; font-size: 18px; color: var(--text-strong); }
.modal .modal-sub { color: var(--muted); font-size: 13px; margin: 0 0 16px; }
.modal .modal-actions { display: flex; gap: 9px; justify-content: flex-end; margin-top: 18px; }

.otp-input {
  font-family: var(--mono);
  font-size: 22px;
  letter-spacing: 8px;
  text-align: center;
  padding: 10px;
}

.totp-qr { display: grid; place-items: center; margin: 12px 0; }
.totp-qr img { border-radius: 12px; border: 6px solid #fff; box-shadow: var(--shadow); background: #fff; }
.secret-box {
  font-family: var(--mono);
  font-size: 12.5px;
  word-break: break-all;
  background: var(--code-bg);
  border-radius: 8px;
  padding: 9px 11px;
  text-align: center;
  color: var(--text);
  margin: 8px 0;
}

/* ---------- Toast ---------- */

.toasts {
  position: fixed;
  bottom: 22px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 9px;
  z-index: 200;
  width: min(430px, calc(100vw - 36px));
}

.toast {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-left: 4px solid var(--accent);
  border-radius: 12px;
  box-shadow: var(--shadow-lg);
  padding: 12px 15px;
  font-size: 13.5px;
  animation: toastIn 0.22s cubic-bezier(0.2, 1.2, 0.4, 1);
}

.toast.ok { border-left-color: var(--ok); }
.toast.err { border-left-color: var(--err); }
.toast.warn { border-left-color: var(--warn); }
.toast .t-close { margin-left: auto; cursor: pointer; color: var(--faint); background: none; border: none; font-size: 16px; line-height: 1; padding: 0 2px; }

@keyframes toastIn { from { opacity: 0; transform: translateY(14px) scale(0.97); } }
@keyframes fadeIn { from { opacity: 0; } }
@keyframes popIn { from { opacity: 0; transform: scale(0.94) translateY(8px); } }

/* ---------- 相机 ---------- */

.camera-modal .modal { max-width: 560px; }
.camera-video { width: 100%; border-radius: 12px; background: #000; aspect-ratio: 4/3; object-fit: cover; }
.camera-tip { text-align: center; color: var(--muted); font-size: 12.5px; margin-top: 8px; min-height: 18px; }

/* ---------- 加载 ---------- */

.loading-block { text-align: center; padding: 70px 0; color: var(--muted); }

.spinner {
  width: 34px;
  height: 34px;
  margin: 0 auto 12px;
  border-radius: 50%;
  border: 3px solid var(--accent-soft);
  border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.skeleton {
  border-radius: 8px;
  background: linear-gradient(90deg, var(--surface-2) 25%, var(--surface-3) 50%, var(--surface-2) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.3s infinite;
  min-height: 14px;
}

@keyframes shimmer { to { background-position: -200% 0; } }

/* ---------- 工具类 ---------- */

.muted { color: var(--muted); }
.faint { color: var(--faint); }
.small { font-size: 12.5px; }
.mono { font-family: var(--mono); }
.mt-0 { margin-top: 0; } .mb-0 { margin-bottom: 0; }
.flex { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.hidden { display: none !important; }
.mt-8 { margin-top: 8px; } .mt-16 { margin-top: 16px; }
.grow { flex: 1; }

a { color: var(--accent); }

@media (max-width: 640px) {
  .brand-text small { display: none; }
  .nav-btn { padding: 7px 12px; font-size: 13.5px; }
  .card { padding: 15px; }
  .view { padding-top: 18px; }

  /* 顶栏换行:第一行 品牌 + 主题/登录,第二行整行导航 */
  .topbar { flex-wrap: wrap; row-gap: 6px; gap: 10px; padding: 8px 12px; }
  .nav { order: 3; width: 100%; margin: 0 -4px; padding: 0 4px; }
  .topbar-actions { margin-left: auto; }
  .user-chip { max-width: 52vw; }
  .user-chip > span:not(.avatar) { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
}

@media (max-width: 480px) {
  .user-chip { padding: 4px 8px 4px 4px; font-size: 12.5px; gap: 6px; }
  .user-chip .badge-2fa { display: none; }
  .otp-input { font-size: 19px; letter-spacing: 5px; padding: 9px 6px; }
  .qr-stage { padding: 14px 10px; min-height: 220px; }
  .card { padding: 13px; border-radius: 12px; }
  .dropzone { padding: 26px 12px; }
  .dz-actions .btn { padding: 6px 10px; font-size: 12.5px; }
  .seg button { padding: 6px 10px; font-size: 12.5px; }
  .media-grid { grid-template-columns: repeat(auto-fill, minmax(146px, 1fr)); gap: 10px; }
  .result-text { font-size: 12.5px; padding: 9px 10px; }
  .modal { padding: 18px 14px; border-radius: 14px; }
  .totp-qr img { width: 180px; height: 180px; }
  .footer { flex-direction: column; gap: 4px; text-align: center; }
  /* 历史行:窄屏隐藏引擎/时间元数据,保住 文本+复制 不换行溢出 */
  .history-item { gap: 7px; }
  .history-item .h-meta { display: none; }
  .history-item .chip { font-size: 10.5px; padding: 2px 7px; flex-shrink: 0; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
