:root {
  --bg: #0f1115;
  --panel: rgba(255, 255, 255, 0.06);
  --panel-br: rgba(255, 255, 255, 0.1);
  --fg: #f2f3f5;
  --muted: rgba(231, 231, 231, 0.55);
  --accent: #007aff;
  --accent-2: #027feb;
  --ok: #1abe43;
  --err: #ff303c;
  --radius: 18px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  background-image: radial-gradient(1200px 800px at 20% -10%, rgba(2, 127, 235, 0.12), transparent 60%),
                    radial-gradient(900px 700px at 110% 110%, rgba(26, 190, 67, 0.08), transparent 60%);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

#stage {
  min-height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.screen {
  display: none;
  width: 100%;
  max-width: 400px;
}
.screen.active { display: flex; flex-direction: column; }

.card {
  width: 100%;
  padding: 28px 26px 30px;
  background: var(--panel);
  border: 1px solid var(--panel-br);
  border-radius: var(--radius);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  box-shadow: 0 18px 60px rgba(0, 0, 0, 0.45);
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.card.center { align-items: center; text-align: center; }

.logo { color: #e7e7e7; width: 54px; height: 54px; }
.logo.big { width: 84px; height: 84px; margin: 8px auto; }
.logo.ok { color: var(--ok); }
svg { width: 100%; height: 100%; display: block; }

.pulse { animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.55; transform: scale(0.94); }
}

h1 {
  margin: 4px 0 0;
  font-size: 21px;
  font-weight: 600;
  letter-spacing: -0.01em;
}
h1.err-title { color: var(--err); }
h1 b { font-weight: 700; }

.sub { margin: 0; color: var(--muted); font-size: 14.5px; }
.hint { margin: 2px 0 0; color: var(--muted); font-size: 12px; opacity: 0.8; }

.label { display: block; font-size: 12.5px; color: var(--muted); margin-bottom: 7px; }

.field { width: 100%; }
.input-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 14px;
  background: rgba(0, 0, 0, 0.28);
  border: 1px solid rgba(255, 255, 255, 0.09);
  border-radius: 14px;
  transition: border-color 0.15s ease, background 0.15s ease;
}
.input-row:focus-within { border-color: rgba(2, 127, 235, 0.65); background: rgba(0, 0, 0, 0.38); }
.plus { color: var(--muted); font-weight: 600; user-select: none; }
.input-row input {
  flex: 1;
  border: none;
  outline: none;
  background: transparent;
  color: var(--fg);
  font-size: 16px;
  padding: 13px 0;
  min-width: 0;
}
.input-row input::placeholder { color: rgba(231, 231, 231, 0.28); }

.digits {
  display: flex;
  gap: 8px;
  justify-content: space-between;
}
.digit {
  flex: 1;
  min-width: 0;
  max-width: 54px;
  margin: 0 auto;
  width: 100%;
  height: 58px;
  text-align: center;
  font-size: 24px;
  font-weight: 600;
  color: var(--fg);
  background: rgba(0, 0, 0, 0.28);
  border: 1px solid rgba(255, 255, 255, 0.09);
  border-radius: 14px;
  outline: none;
  transition: border-color 0.15s ease;
  caret-color: var(--accent);
}
.digit:focus { border-color: rgba(2, 127, 235, 0.65); }
.digit.shake { animation: shake 0.4s ease; }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-6px); }
  75% { transform: translateX(6px); }
}

.btn {
  appearance: none;
  border: none;
  border-radius: 14px;
  padding: 14px 18px;
  font-size: 15.5px;
  font-weight: 600;
  color: #fff;
  background: linear-gradient(180deg, var(--accent-2), var(--accent));
  cursor: pointer;
  transition: filter 0.15s ease, transform 0.05s ease;
}
.btn:hover:not(:disabled) { filter: brightness(1.08); }
.btn:active:not(:disabled) { transform: scale(0.99); }
.btn:disabled { opacity: 0.45; cursor: default; }

.btn-link {
  appearance: none;
  border: none;
  background: transparent;
  color: var(--accent);
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  padding: 4px;
}
.btn-link:disabled { opacity: 0.4; cursor: default; }
.btn-link:not(:disabled):hover { text-decoration: underline; }

.btn-ghost {
  appearance: none;
  border: none;
  background: rgba(255, 255, 255, 0.05);
  color: var(--muted);
  font-size: 13.5px;
  border-radius: 12px;
  padding: 9px 12px;
  cursor: pointer;
}
.btn-ghost:hover { background: rgba(255, 255, 255, 0.1); color: var(--fg); }

.loader-text { margin: 10px auto 0; color: var(--muted); font-size: 14px; text-align: center; }

.spinner-inline {
  width: 22px; height: 22px; margin-top: 14px;
  border-radius: 50%;
  border: 2.5px solid rgba(255, 255, 255, 0.15);
  border-top-color: var(--accent);
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

#error-text { max-width: 320px; }
#error-hint { white-space: pre-line; max-width: 320px; font-size: 12.5px; }
#err-action { display: block; margin: 0 auto; width: fit-content; }

#toast {
  position: fixed;
  left: 50%;
  bottom: 34px;
  transform: translate(-50%, 16px);
  max-width: min(90vw, 420px);
  padding: 12px 18px;
  background: rgba(20, 22, 28, 0.95);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-left: 3px solid var(--err);
  color: var(--fg);
  font-size: 13.5px;
  border-radius: 12px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  backdrop-filter: blur(12px);
  z-index: 10;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.ok { border-left-color: var(--ok); }

@media (max-width: 420px) {
  #stage { padding: 14px; }
  .card { padding: 22px 18px 24px; }
  .digit { height: 50px; font-size: 20px; }
  h1 { font-size: 19px; }
}

/* QR screen */
#qr-box { margin: 6px auto 14px; width: min(72vw, 300px); }
#qr-img { width: 100%; height: auto; display: block; border-radius: 18px; background: #fff; padding: 10px; }
.qr-actions { display: flex; flex-direction: column; align-items: center; gap: 10px; margin-top: 14px; }
.small { font-size: 12px; opacity: .7; }
