:root {
  --bg0: #070708;
  --bg1: #0c0d0f;
  --card: rgba(16, 17, 20, 0.78);
  --cardSolid: #101114;
  --text: #f4f4f5;
  --muted: #a1a1aa;
  --border: rgba(255, 255, 255, 0.10);
  --border2: rgba(255, 255, 255, 0.18);
  --accent: #a78bfa;
  --accent2: #60a5fa;
  --btn2: rgba(24, 24, 27, 0.92);
  --error: #fb7185;
  --ok: #34d399;
  --shadow: 0 22px 86px rgba(0, 0, 0, 0.68);
}

body {
  margin: 0;
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Arial, "Noto Sans", "PingFang SC", "Microsoft YaHei";
  background:
    radial-gradient(1200px 800px at 10% -10%, rgba(167, 139, 250, 0.16), transparent 55%),
    radial-gradient(900px 700px at 92% 8%, rgba(96, 165, 250, 0.12), transparent 60%),
    linear-gradient(180deg, var(--bg1), var(--bg0));
  color: var(--text);
}

.bg {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(900px 500px at 40% 110%, rgba(167, 139, 250, 0.10), transparent 70%),
    radial-gradient(700px 420px at 110% 45%, rgba(96, 165, 250, 0.08), transparent 70%);
  filter: saturate(1.05);
  animation: aurora 14s ease-in-out infinite alternate;
  opacity: 0.9;
}

.bg::before {
  content: "";
  position: absolute;
  inset: -20%;
  background:
    radial-gradient(800px 600px at 25% 20%, rgba(167, 139, 250, 0.12), transparent 55%),
    radial-gradient(720px 520px at 80% 30%, rgba(96, 165, 250, 0.10), transparent 60%),
    radial-gradient(860px 620px at 40% 85%, rgba(255, 255, 255, 0.05), transparent 70%);
  filter: blur(34px);
  opacity: 0.9;
  animation: aurora 16s ease-in-out infinite alternate-reverse;
}

.bg::after {
  content: "";
  position: absolute;
  inset: 0;
  opacity: 0.11;
  mix-blend-mode: overlay;
  background-image:
    repeating-linear-gradient(0deg, rgba(255, 255, 255, 0.035) 0 1px, transparent 1px 3px),
    repeating-linear-gradient(90deg, rgba(255, 255, 255, 0.03) 0 1px, transparent 1px 4px);
  transform: translateZ(0);
  animation: grainMove 10s steps(12, end) infinite;
}

@keyframes aurora {
  from { transform: translate3d(0, 0, 0) scale(1); }
  to { transform: translate3d(0, -12px, 0) scale(1.02); }
}

@keyframes grainMove {
  0% { transform: translate3d(0, 0, 0); }
  25% { transform: translate3d(-1%, 1%, 0); }
  50% { transform: translate3d(1%, -1%, 0); }
  75% { transform: translate3d(1%, 1%, 0); }
  100% { transform: translate3d(0, 0, 0); }
}

.container {
  max-width: 980px;
  margin: 26px auto;
  padding: 0 16px;
  animation: containerIn 360ms ease-out both;
}

@keyframes containerIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
}

.header h1 {
  margin: 0;
  font-size: 28px;
  letter-spacing: 0.2px;
}

.sub {
  margin: 8px 0 0;
  color: var(--muted);
}

.chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px 12px;
  border-radius: 999px;
  text-decoration: none;
  color: var(--text);
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border);
  transition: border-color 160ms ease, background 160ms ease;
}

.chip:hover {
  border-color: var(--border2);
  background: rgba(255, 255, 255, 0.09);
}

.card {
  margin-top: 0;
  background: var(--cardSolid);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
  box-shadow: var(--shadow);
  animation: pop 320ms ease-out both;
  transition: transform 220ms ease, border-color 220ms ease, box-shadow 220ms ease;
}

.glass {
  background: var(--card);
  backdrop-filter: blur(16px);
}

@keyframes pop {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.card:hover {
  transform: translateY(-1px);
  border-color: rgba(255, 255, 255, 0.22);
  box-shadow: 0 26px 96px rgba(0, 0, 0, 0.72);
}

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

.between {
  justify-content: space-between;
}

label {
  color: var(--muted);
  font-size: 14px;
}

.keyOk {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
  color: var(--ok);
  border: 1px solid rgba(52, 211, 153, 0.40);
  background: rgba(52, 211, 153, 0.10);
  box-shadow: 0 0 0 3px rgba(52, 211, 153, 0.08);
  transform: translateY(-1px);
}

.keyOk[hidden] {
  display: none !important;
}

select, textarea, input {
  background: rgba(12, 12, 14, 0.72);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 10px;
  outline: none;
  transition: border-color 160ms ease, box-shadow 160ms ease;
}

select:focus, textarea:focus, input:focus {
  border-color: rgba(167, 139, 250, 0.55);
  box-shadow: 0 0 0 4px rgba(167, 139, 250, 0.14);
}

select:focus-visible, textarea:focus-visible, input:focus-visible,
button:focus-visible, a:focus-visible {
  outline: 2px solid rgba(167, 139, 250, 0.55);
  outline-offset: 2px;
}

button {
  background: linear-gradient(180deg, rgba(167, 139, 250, 0.95), rgba(96, 165, 250, 0.92));
  color: white;
  border: 1px solid transparent;
  padding: 10px 14px;
  border-radius: 10px;
  cursor: pointer;
  font-weight: 600;
  transition: transform 160ms ease, box-shadow 160ms ease, background 160ms ease, border-color 160ms ease;
}

button.primary:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 12px 34px rgba(167, 139, 250, 0.20);
}

button.primary:active:not(:disabled) {
  transform: translateY(0);
}

button.secondary {
  background: var(--btn2);
  border-color: var(--border);
  font-weight: 500;
}

button.secondary:hover:not(:disabled) {
  border-color: var(--border2);
}

button.ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
  font-weight: 500;
  padding: 8px 12px;
  border-radius: 999px;
}

button.ghost:hover:not(:disabled) {
  border-color: var(--border2);
  background: rgba(255, 255, 255, 0.06);
}

button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.btnCompact {
  padding: 7px 10px;
  font-size: 12px;
  line-height: 1.1;
}

.topbar {
  display: grid;
  gap: 12px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}

.stepper {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  pointer-events: none;
  padding-bottom: 12px;
}

.stepper li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 26px 6px 6px;
  border-radius: 10px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  position: relative;
  overflow: hidden;
  cursor: default;
  user-select: none;
}

.stepDot {
  display: none;
}

.stepper li.active {
  color: var(--text);
  border-color: rgba(167, 139, 250, 0.40);
  background: rgba(167, 139, 250, 0.06);
}

.stepper li.done {
  color: rgba(232, 238, 252, 0.92);
  border-color: rgba(52, 211, 153, 0.30);
  background: rgba(52, 211, 153, 0.06);
}

.stepper li.error {
  border-color: rgba(251, 113, 133, 0.35);
  background: rgba(251, 113, 133, 0.08);
}

.stepper li.done::after {
  content: "✓";
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--ok);
  font-weight: 800;
  font-size: 14px;
}

.stepper li.active::after {
  content: "";
  position: absolute;
  right: 9px;
  top: 50%;
  width: 12px;
  height: 12px;
  transform: translateY(-50%);
  border-radius: 999px;
  border: 2px solid rgba(255, 255, 255, 0.22);
  border-top-color: rgba(167, 139, 250, 0.9);
  animation: spin 900ms linear infinite;
}

@keyframes spin {
  from { transform: translateY(-50%) rotate(0deg); }
  to { transform: translateY(-50%) rotate(360deg); }
}

.fingerprint {
  padding: 10px;
  display: grid;
  gap: 8px;
  border: 1px solid rgba(255, 255, 255, 0.10);
  background: rgba(12, 12, 14, 0.55);
  border-radius: 12px;
}

.fingerprint .row.between {
  flex-wrap: nowrap;
}

.fingerprint .ghost,
.fingerprint .secondary {
  padding: 6px 9px;
  border-radius: 12px;
  font-size: 12px;
  line-height: 1.1;
}

.fpBox {
  width: 100%;
  min-height: 90px;
  resize: none;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  font-size: 12px;
  line-height: 1.4;
}

.mainGrid {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 16px;
  margin-top: 14px;
  align-items: start;
}

.side {
  display: grid;
  gap: 10px;
}

.actions {
  display: grid;
  gap: 8px;
  padding: 10px;
  border: 1px solid rgba(255, 255, 255, 0.10);
  background: rgba(12, 12, 14, 0.55);
  border-radius: 12px;
}

.actionRow {
  flex-wrap: nowrap;
  gap: 8px;
  align-items: center;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
  padding: 6px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(12, 12, 14, 0.70);
  flex: 1;
  min-width: 0;
}

.segBtn {
  border-radius: 10px;
  padding: 8px 10px;
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.10);
  color: rgba(244, 244, 245, 0.88);
  font-weight: 650;
  cursor: pointer;
  transition: background 160ms ease, border-color 160ms ease, transform 160ms ease;
}

.segBtn:hover:not(.active) {
  background: rgba(255, 255, 255, 0.06);
  border-color: rgba(255, 255, 255, 0.16);
}

.segBtn.active {
  background: rgba(167, 139, 250, 0.16);
  border-color: rgba(167, 139, 250, 0.42);
  color: var(--text);
}

.actions #btnStart,
.actions #btnCancel {
  padding: 10px 12px;
  border-radius: 12px;
  min-width: 84px;
}

.keyInline {
  display: grid;
  gap: 6px;
  padding-top: 8px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.keyInline .row.between {
  flex-wrap: nowrap;
  align-items: center;
}

.keyInline label {
  font-size: 13px;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.keyInline .ghost {
  padding: 6px 9px;
  font-size: 12px;
  line-height: 1.1;
}

.keyInline .secondary {
  padding: 7px 10px;
  font-size: 12px;
  line-height: 1.1;
}

.keyInline .small {
  margin-top: 0;
  grid-template-columns: 1fr 1fr;
  gap: 8px 12px;
}

.keyBox {
  height: 34px;
  padding: 7px 10px;
  margin-top: 1px;
  border-radius: 10px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  font-size: 12px;
}

.qrBox {
  position: relative;
  width: 280px;
  height: 280px;
  background: rgba(12, 12, 14, 0.72);
  border: 1px solid var(--border);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  transition: border-color 220ms ease, box-shadow 220ms ease, transform 220ms ease;
}

.qrBox img {
  width: 260px;
  height: 260px;
  display: none;
}

.qr {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.qr .small {
  width: 280px;
  max-width: 100%;
}

.statusActions {
  justify-content: flex-start;
  width: 100%;
}

.qrBox.scanning::before {
  content: "";
  position: absolute;
  inset: 12px;
  border-radius: 10px;
  background: linear-gradient(90deg, rgba(255, 255, 255, 0.05), rgba(255, 255, 255, 0.11), rgba(255, 255, 255, 0.05));
  background-size: 220% 100%;
  opacity: 0.35;
  animation: skeleton 1.6s ease-in-out infinite;
}

@keyframes skeleton {
  0% { background-position: 0% 0%; }
  100% { background-position: 200% 0%; }
}

.scanLine {
  position: absolute;
  left: 12px;
  right: 12px;
  height: 2px;
  top: 14px;
  background: linear-gradient(90deg, transparent, rgba(167, 139, 250, 0.9), transparent);
  box-shadow: 0 0 24px rgba(167, 139, 250, 0.30);
  opacity: 0;
  transform: translateY(0);
  pointer-events: none;
}

.qrBox.scanning .scanLine {
  opacity: 1;
  animation: scan 1.4s ease-in-out infinite;
}

@keyframes scan {
  0% { transform: translateY(0); opacity: 0.0; }
  15% { opacity: 0.9; }
  50% { transform: translateY(240px); opacity: 0.65; }
  85% { opacity: 0.9; }
  100% { transform: translateY(0); opacity: 0.0; }
}

.qrBox.success {
  border-color: rgba(52, 211, 153, 0.40);
  box-shadow: 0 0 0 4px rgba(52, 211, 153, 0.10), 0 22px 80px rgba(0, 0, 0, 0.65);
}

.qrBox.failed {
  border-color: rgba(251, 113, 133, 0.42);
  box-shadow: 0 0 0 4px rgba(251, 113, 133, 0.12), 0 22px 80px rgba(0, 0, 0, 0.65);
}

.hint {
  color: var(--muted);
  padding: 10px;
  text-align: center;
}

.hint:empty {
  display: none;
}

.keyBox.masked {
  filter: blur(8px);
  user-select: none;
}

.keyInline.masked .small code {
  filter: blur(8px);
  user-select: none;
}

.fpBox.masked {
  filter: blur(10px);
  user-select: none;
}

.keyBox.pulse {
  animation: keyPulse 540ms ease-out both;
}

@keyframes keyPulse {
  0% { transform: translateY(0); box-shadow: none; border-color: var(--border); }
  45% { transform: translateY(-1px); box-shadow: 0 0 0 4px rgba(167, 139, 250, 0.14); border-color: rgba(167, 139, 250, 0.40); }
  100% { transform: translateY(0); box-shadow: none; border-color: var(--border); }
}

.small {
  margin-top: 10px;
  font-size: 12px;
  color: var(--muted);
  display: grid;
  gap: 6px;
}

.small code {
  display: inline-block;
  max-width: 100%;
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: break-all;
}

.smallNote {
  color: var(--muted);
  font-size: 12px;
}

.error {
  color: var(--error);
}

@media (max-width: 860px) {
  .mainGrid {
    grid-template-columns: 1fr;
  }
  .qrBox {
    width: 100%;
    max-width: 360px;
  }
  .stepper {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .actionRow {
    flex-wrap: wrap;
  }
  .actions #btnStart,
  .actions #btnCancel {
    flex: 1;
    min-width: 0;
  }
}

.logs {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

.logWrap.collapsed {
  max-height: 0;
  opacity: 0;
  overflow: hidden;
  pointer-events: none;
}

.logWrap {
  max-height: 340px;
  opacity: 1;
  overflow: hidden;
  transition: max-height 240ms ease, opacity 240ms ease;
}

.logList {
  margin-top: 10px;
  background: rgba(12, 12, 14, 0.72);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px;
  max-height: 260px;
  overflow: auto;
  font-size: 12px;
}

.logItem {
  display: flex;
  gap: 10px;
  align-items: baseline;
  padding: 6px 4px;
  border-bottom: 1px dashed rgba(148, 163, 184, 0.18);
}

.logItem:last-child {
  border-bottom: none;
}

.logLine {
  color: var(--text);
  word-break: break-word;
}

.logMeta {
  color: var(--muted);
  white-space: nowrap;
}

.logView {
  color: rgba(167, 139, 250, 0.95);
  background: transparent;
  border: none;
  padding: 0 0 0 6px;
  font: inherit;
  cursor: pointer;
}

.logView:hover {
  color: rgba(96, 165, 250, 0.98);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%);
  background: rgba(12, 12, 14, 0.88);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 12px;
  border-radius: 12px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(16px);
  z-index: 999;
  animation: toastIn 220ms cubic-bezier(0.2, 0.9, 0.2, 1) both;
}

.toast.hidden { display: none; }

@keyframes toastIn {
  from { opacity: 0; transform: translateX(-50%) translateY(10px) scale(0.98); }
  to { opacity: 1; transform: translateX(-50%) translateY(0) scale(1); }
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  z-index: 999;
  animation: fade 160ms ease-out both;
}

.modal.hidden {
  display: none;
}

@keyframes fade {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modalCard {
  width: min(980px, 100%);
  max-height: 84vh;
  background: var(--cardSolid);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow);
  animation: modalIn 240ms ease-out both;
}

.officialCard {
  width: fit-content;
  max-width: calc(100vw - 36px);
}

.officialCanvasWrap {
  margin-top: 10px;
  background: transparent;
  border: none;
  border-radius: 0;
  padding: 0;
  overflow: auto;
  max-width: calc(100vw - 36px);
}

.officialCanvas {
  display: block;
  max-width: 100%;
  height: auto;
}

@keyframes modalIn {
  from { opacity: 0; transform: translateY(8px) scale(0.985); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.modalHeader {
  justify-content: space-between;
}

.modalTitle {
  font-weight: 700;
}

.modalText {
  margin: 12px 0 0;
  padding: 12px;
  background: rgba(12, 12, 14, 0.72);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: auto;
  color: var(--text);
  font-size: 12px;
  white-space: pre-wrap;
}

@media (prefers-reduced-motion: reduce) {
  .bg,
  .bg::before,
  .bg::after,
  .container,
  .card,
  .toast,
  .modal,
  .modalCard,
  .stepper li.active::after,
  .qrBox.scanning::before,
  .qrBox.scanning .scanLine {
    animation: none !important;
  }
  button { transition: none !important; }
}
