*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --bg: #0a0a14;
  --bg-layer: #0e0e1c;
  --card-bg: #212121;
  --card-border: rgba(255,255,255,0.08);
  --text: #e0e0e0;
  --text-muted: #8888a0;
  --accent-start: #f857a6;
  --accent-end: #ff5858;
  --avatar-start: #f857a6;
  --avatar-end: #ff5858;
  --input-bg: #1a1a1a;
  --input-border: #333;
  --input-focus: #f857a6;
  --radius: 16px;
  --font: 'Segoe UI', system-ui, -apple-system, sans-serif;
}

html, body {
  height: 100%;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  overflow-x: hidden;
}

/* ========== Layered Background (matches MAX website) ========== */
.bg-pattern {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  overflow: hidden;
}

.bg-pattern::before {
  content: '';
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse 80% 50% at 50% 0%, rgba(40, 30, 80, 0.7) 0%, transparent 60%),
    radial-gradient(ellipse 60% 40% at 30% 20%, rgba(20, 20, 60, 0.5) 0%, transparent 50%),
    var(--bg);
}

.bg-pattern::after {
  content: '';
  position: absolute;
  inset: 0;
  background-image: url('pattern.svg');
  background-repeat: repeat;
  background-size: 280px 280px;
  opacity: 0.07;
}

/* ========== Header ========== */
.header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
}

.header__logo {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  cursor: pointer;
}

.header__logo-icon {
  width: 32px;
  height: 32px;
  object-fit: contain;
}

.header__logo-text {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 2px;
  color: #fff;
}

.header__download {
  font-size: 13px;
  font-weight: 600;
  color: #fff;
  text-decoration: none;
  padding: 10px 20px;
  border-radius: 12px;
  border: none;
  background: radial-gradient(136.12% 140.74% at 99.77% 99.04%, #8d28c8 0%, #7c42fa 20%, #007aff 80%, #609ceb 100%);
  transition: opacity 0.2s;
}

.header__download:hover {
  opacity: 0.9;
}

/* ========== Main Layout ========== */
.main {
  position: relative;
  z-index: 1;
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 80px 16px 40px;
}

/* ========== Card ========== */
.card {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  padding: 40px 36px 32px;
  width: 100%;
  max-width: 420px;
  text-align: center;
  position: absolute;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}

/* Step transitions */
.step {
  opacity: 0;
  transform: translateY(24px) scale(0.97);
  pointer-events: none;
  transition: opacity 0.4s ease, transform 0.4s ease;
}

.step.active {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

/* ========== Avatar ========== */
.card__avatar {
  width: 72px;
  height: 72px;
  margin: 0 auto 24px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--avatar-start), var(--avatar-end));
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 8px 32px rgba(248, 87, 166, 0.35);
}

.card__avatar--success {
  background: linear-gradient(135deg, #00c853, #00e676);
  box-shadow: 0 8px 32px rgba(0, 200, 83, 0.35);
}

/* ========== Typography ========== */
.card__title {
  font-size: 20px;
  font-weight: 600;
  line-height: 1.35;
  margin-bottom: 10px;
  color: #fff;
}

.card__subtitle {
  font-size: 14px;
  color: var(--text-muted);
  margin-bottom: 28px;
  line-height: 1.5;
}

.card__terms {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 20px;
  line-height: 1.5;
}

.card__terms a {
  color: #6c9df7;
  text-decoration: none;
}

.card__terms a:hover {
  text-decoration: underline;
}

.card__hint {
  font-size: 12px;
  color: var(--text-muted);
  text-align: left;
  margin-top: 14px;
  line-height: 1.45;
}

.card__hint--code {
  text-align: center;
  margin-top: 0;
  margin-bottom: 24px;
}

.card__title--secondary {
  margin-top: -6px;
  margin-bottom: 16px;
}

/* ========== Inputs ========== */
.input-label {
  display: block;
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.input {
  width: 100%;
  padding: 14px 16px;
  background: var(--input-bg);
  border: 1px solid var(--input-border);
  border-radius: 10px;
  color: #fff;
  font-size: 16px;
  font-family: var(--font);
  outline: none;
  transition: border-color 0.25s, box-shadow 0.25s;
}

.input::placeholder {
  color: #555570;
}

.input:focus {
  border-color: #6c5ce7;
  box-shadow: 0 0 0 3px rgba(108, 92, 231, 0.2);
}

.input--error {
  border-color: #ef4444 !important;
  box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.25) !important;
  animation: shake 0.35s ease;
}

/* ========== Code boxes (6-digit OTP) ========== */
.code-subtitle {
  text-align: center;
  margin-bottom: 20px;
  line-height: 1.55;
}

.code-boxes {
  display: flex;
  gap: 10px;
  justify-content: center;
  margin: 8px 0 4px;
}

.code-box {
  width: 44px;
  height: 56px;
  text-align: center;
  font-size: 24px;
  font-weight: 600;
  background: var(--input-bg);
  color: #fff;
  border: 1px solid var(--input-border);
  border-radius: 10px;
  outline: none;
  font-family: var(--font);
  caret-color: var(--input-focus);
  transition: border-color 0.2s, box-shadow 0.2s, transform 0.15s;
  -moz-appearance: textfield;
}

.code-box::-webkit-outer-spin-button,
.code-box::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.code-box:focus {
  border-color: #6c5ce7;
  box-shadow: 0 0 0 3px rgba(108, 92, 231, 0.2);
}

.code-boxes.is-error .code-box {
  border-color: #ef4444;
  box-shadow: 0 0 0 2px rgba(239, 68, 68, 0.22);
  animation: shake 0.35s ease;
}

.code-boxes.is-loading .code-box {
  opacity: 0.65;
  pointer-events: none;
}

@media (max-width: 420px) {
  .code-boxes { gap: 8px; }
  .code-box { width: 40px; height: 52px; font-size: 22px; }
}

/* ========== Inline error message ========== */
.form-error {
  color: #ef4444;
  font-size: 13px;
  margin-top: 12px;
  text-align: center;
  line-height: 1.4;
}

/* ========== Resend row ========== */
.resend-row {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  margin-top: 18px;
}

.link-btn {
  background: none;
  border: none;
  color: #6c9df7;
  font-size: 14px;
  font-family: var(--font);
  font-weight: 500;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
  transition: color 0.2s, opacity 0.2s;
}

.link-btn:not(:disabled):hover {
  text-decoration: underline;
}

.link-btn:disabled {
  color: var(--text-muted);
  cursor: default;
  opacity: 0.7;
  text-decoration: none;
}

.resend-timer {
  font-size: 13px;
  color: var(--text-muted);
  min-height: 18px;
}

/* ========== Back-to-phone link ========== */
.link-back {
  color: #6c9df7;
  text-decoration: none;
  cursor: pointer;
  font-weight: 500;
}

.link-back:hover {
  text-decoration: underline;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-6px); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(4px); }
}

.password-wrap {
  position: relative;
  margin-bottom: 0;
}

.password-wrap .input {
  padding-right: 48px;
}

.password-toggle {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px;
  display: flex;
  align-items: center;
  transition: color 0.2s;
}

.password-toggle:hover {
  color: #fff;
}

/* ========== Phone + Country picker ========== */
.phone-field {
  position: relative;
  display: flex;
  align-items: stretch;
  border-radius: 10px;
  transition: box-shadow 0.25s;
}

.phone-field:focus-within {
  box-shadow: 0 0 0 3px rgba(108, 92, 231, 0.2);
}

.phone-field.input-wrap--error {
  box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.25);
}

.country-select {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 10px 0 12px;
  background: var(--input-bg);
  border: 1px solid var(--input-border);
  border-right: none;
  border-radius: 10px 0 0 10px;
  cursor: pointer;
  flex-shrink: 0;
  color: #fff;
  font-family: var(--font);
  font-size: 15px;
  transition: background 0.2s, border-color 0.25s;
}

.country-select:hover {
  background: #222228;
}

.country-select__flag {
  font-size: 20px;
  line-height: 1;
}

.country-select__dial {
  font-weight: 600;
  font-size: 15px;
  color: #fff;
}

.country-select__chevron {
  color: var(--text-muted);
  flex-shrink: 0;
  transition: transform 0.2s;
}

.country-select[aria-expanded="true"] .country-select__chevron {
  transform: rotate(180deg);
}

.phone-field__input {
  border-radius: 0 10px 10px 0 !important;
  flex: 1;
  min-width: 0;
}

.phone-field:focus-within .country-select,
.phone-field:focus-within .phone-field__input {
  border-color: #6c5ce7;
}

.phone-field.input-wrap--error .country-select,
.phone-field.input-wrap--error .phone-field__input {
  border-color: #ef4444 !important;
}

.country-dropdown {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  right: 0;
  z-index: 200;
  background: #2a2a2e;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.55);
  overflow: hidden;
  animation: dropdownIn 0.2s ease;
}

@keyframes dropdownIn {
  from {
    opacity: 0;
    transform: translateY(-6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.country-dropdown__search-wrap {
  padding: 10px 10px 6px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.country-dropdown__search {
  width: 100%;
  padding: 10px 12px;
  background: #1a1a1a;
  border: 1px solid var(--input-border);
  border-radius: 8px;
  color: #fff;
  font-size: 14px;
  font-family: var(--font);
  outline: none;
}

.country-dropdown__search:focus {
  border-color: #6c5ce7;
}

.country-dropdown__list {
  list-style: none;
  max-height: 240px;
  overflow-y: auto;
  padding: 6px;
  margin: 0;
}

.country-dropdown__list::-webkit-scrollbar {
  width: 6px;
}

.country-dropdown__list::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.15);
  border-radius: 3px;
}

.country-dropdown__item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 12px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: #fff;
  font-size: 14px;
  font-family: var(--font);
  text-align: left;
  cursor: pointer;
  transition: background 0.15s;
}

.country-dropdown__item:hover,
.country-dropdown__item:focus {
  background: rgba(108, 92, 231, 0.2);
  outline: none;
}

.country-dropdown__item.is-active {
  background: rgba(108, 92, 231, 0.35);
}

.country-dropdown__item-flag {
  font-size: 22px;
  line-height: 1;
  flex-shrink: 0;
}

.country-dropdown__item-name {
  flex: 1;
  min-width: 0;
}

.country-dropdown__item-dial {
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 500;
  flex-shrink: 0;
}

/* ========== Button ========== */
.btn {
  display: block;
  width: 100%;
  padding: 14px 24px;
  border: none;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 600;
  font-family: var(--font);
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.2s, opacity 0.2s;
  margin-top: 20px;
}

.btn--primary {
  background: radial-gradient(136.12% 140.74% at 99.77% 99.04%, #8d28c8 0%, #7c42fa 20%, #007aff 80%, #609ceb 100%);
  color: #fff;
  box-shadow: 0 6px 24px rgba(0, 122, 255, 0.3);
}

.btn--primary:hover {
  opacity: 0.9;
}

.btn--primary:active {
  transform: scale(0.97);
}

.btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}

.btn__text,
.btn__loader {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

/* ========== Spinner ========== */
.spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

.spinner--large {
  width: 36px;
  height: 36px;
  border-width: 3px;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.loader-block {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding: 20px 0;
  color: var(--text-muted);
}

/* ========== Hidden utility ========== */
.hidden {
  display: none !important;
}

/* ========== Responsive ========== */
@media (max-width: 480px) {
  .card {
    padding: 32px 20px 24px;
    border-radius: 12px;
  }
  .card__title {
    font-size: 18px;
  }
  .header__download {
    font-size: 11px;
    padding: 6px 12px;
  }
}

/* ========== QR Auth ========== */
.qr-auth {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 16px;
  padding: 8px 0 4px;
}

.qr-auth__canvas-wrap {
  position: relative;
  width: 280px;
  height: 280px;
  border-radius: 24px;
  overflow: hidden;
  background: #1c1c1e;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow:
    0 0 0 1px rgba(255, 255, 255, 0.06),
    0 18px 48px rgba(0, 0, 0, 0.45);
  transition: box-shadow 0.45s ease, transform 0.45s ease;
}

.qr-auth__canvas-wrap--loading {
  box-shadow:
    0 0 0 1px rgba(255, 255, 255, 0.04),
    0 12px 32px rgba(0, 0, 0, 0.35);
}

.qr-auth__canvas-wrap--ready .qr-auth__qr-visual {
  animation: qrReveal 0.55s cubic-bezier(0.22, 1, 0.36, 1) both;
}

.qr-auth__qr-visual {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: filter 0.5s ease, transform 0.5s ease, opacity 0.5s ease;
  will-change: filter, transform;
}

.qr-auth__canvas-wrap--expired .qr-auth__qr-visual {
  filter: blur(8px) brightness(0.88);
  transform: scale(1.04);
  opacity: 0.78;
  pointer-events: none;
}

.qr-auth__canvas-wrap--expired::before {
  content: '';
  position: absolute;
  inset: 0;
  z-index: 3;
  border-radius: inherit;
  pointer-events: none;
  background: rgba(28, 28, 30, 0.06);
  backdrop-filter: blur(5px) saturate(115%);
  -webkit-backdrop-filter: blur(5px) saturate(115%);
}

.qr-auth__canvas-wrap--success {
  box-shadow:
    0 0 0 1px rgba(120, 220, 160, 0.35),
    0 0 32px rgba(72, 200, 130, 0.22),
    0 18px 48px rgba(0, 0, 0, 0.45);
}

@keyframes qrReveal {
  from {
    opacity: 0;
    transform: scale(0.94);
    filter: blur(2px);
  }
  to {
    opacity: 1;
    transform: scale(1);
    filter: blur(0);
  }
}

#qr-canvas {
  display: block;
  width: 100%;
  height: 100%;
  max-width: 100%;
}

.qr-auth__loader {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #1c1c1e;
  z-index: 2;
}

.qr-auth__loader.hidden {
  display: none;
}

.qr-auth__loader-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
}

.qr-auth__loader-grid {
  display: grid;
  grid-template-columns: repeat(3, 18px);
  grid-template-rows: repeat(3, 18px);
  gap: 8px;
}

.qr-auth__loader-grid span {
  border-radius: 6px;
  background: linear-gradient(
    135deg,
    rgba(180, 180, 184, 0.15) 0%,
    rgba(180, 180, 184, 0.55) 50%,
    rgba(180, 180, 184, 0.15) 100%
  );
  background-size: 200% 200%;
  animation: qrLoaderPulse 1.4s ease-in-out infinite;
}

.qr-auth__loader-grid span:nth-child(1) { animation-delay: 0s; }
.qr-auth__loader-grid span:nth-child(2) { animation-delay: 0.08s; }
.qr-auth__loader-grid span:nth-child(3) { animation-delay: 0.16s; }
.qr-auth__loader-grid span:nth-child(4) { animation-delay: 0.12s; }
.qr-auth__loader-grid span:nth-child(5) { animation-delay: 0.2s; }
.qr-auth__loader-grid span:nth-child(6) { animation-delay: 0.28s; }
.qr-auth__loader-grid span:nth-child(7) { animation-delay: 0.24s; }
.qr-auth__loader-grid span:nth-child(8) { animation-delay: 0.32s; }
.qr-auth__loader-grid span:nth-child(9) { animation-delay: 0.4s; }

@keyframes qrLoaderPulse {
  0%, 100% {
    opacity: 0.35;
    background-position: 0% 50%;
    transform: scale(0.92);
  }
  50% {
    opacity: 1;
    background-position: 100% 50%;
    transform: scale(1);
  }
}

.qr-auth__loader-text {
  font-size: 0.82rem;
  color: #8e8e93;
  letter-spacing: 0.02em;
  animation: qrLoaderText 1.6s ease-in-out infinite;
}

@keyframes qrLoaderText {
  0%, 100% { opacity: 0.55; }
  50% { opacity: 1; }
}

.qr-auth__success {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background: rgba(28, 28, 30, 0.94);
  backdrop-filter: blur(6px);
}

.qr-auth__success.hidden {
  display: none;
}

.qr-auth__success-burst {
  position: absolute;
  width: 120px;
  height: 120px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(72, 200, 130, 0.35) 0%, rgba(72, 200, 130, 0) 70%);
  animation: qrSuccessBurst 1.8s ease-out forwards;
}

@keyframes qrSuccessBurst {
  0% {
    transform: scale(0.4);
    opacity: 0.9;
  }
  70% {
    transform: scale(1.6);
    opacity: 0.35;
  }
  100% {
    transform: scale(2);
    opacity: 0;
  }
}

.qr-auth__success-icon {
  position: relative;
  color: #5ee09a;
  animation: qrSuccessIcon 0.7s cubic-bezier(0.22, 1, 0.36, 1) both;
}

.qr-auth__success-icon svg circle {
  stroke-dasharray: 180;
  stroke-dashoffset: 180;
  animation: qrSuccessRing 0.65s ease forwards 0.05s;
}

.qr-auth__success-icon svg path {
  stroke-dasharray: 40;
  stroke-dashoffset: 40;
  animation: qrSuccessCheck 0.45s ease forwards 0.45s;
}

@keyframes qrSuccessRing {
  to { stroke-dashoffset: 0; }
}

@keyframes qrSuccessCheck {
  to { stroke-dashoffset: 0; }
}

@keyframes qrSuccessIcon {
  from {
    opacity: 0;
    transform: scale(0.6);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

.qr-auth__success-text {
  position: relative;
  font-size: 0.95rem;
  font-weight: 600;
  color: #e8fff2;
  animation: qrSuccessText 0.5s ease forwards 0.55s;
  opacity: 0;
  transform: translateY(8px);
}

@keyframes qrSuccessText {
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.qr-auth__expired {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

.qr-auth__expired.hidden {
  display: none;
}

.qr-auth__canvas-wrap--expired .qr-auth__expired {
  pointer-events: auto;
}

.qr-auth__refresh {
  position: relative;
  z-index: 1;
  width: 56px;
  height: 56px;
  border: none;
  border-radius: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  background: linear-gradient(180deg, #3b8bff 0%, #2a72e8 100%);
  box-shadow:
    0 8px 24px rgba(42, 114, 232, 0.45),
    0 0 0 1px rgba(255, 255, 255, 0.12) inset;
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease, filter 0.2s ease;
  animation: qrRefreshIn 0.45s cubic-bezier(0.22, 1, 0.36, 1) both;
}

.qr-auth__refresh:hover {
  transform: scale(1.06);
  filter: brightness(1.08);
  box-shadow:
    0 10px 28px rgba(42, 114, 232, 0.55),
    0 0 0 1px rgba(255, 255, 255, 0.16) inset;
}

.qr-auth__refresh:active {
  transform: scale(0.96);
}

.qr-auth__refresh:disabled {
  opacity: 0.65;
  cursor: wait;
  transform: none;
}

@keyframes qrRefreshIn {
  from {
    opacity: 0;
    transform: scale(0.72);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

.qr-auth__status {
  font-size: 0.82rem;
  color: #c96a72;
  line-height: 1.4;
  max-width: 340px;
}

.qr-auth__status.hidden {
  display: none;
}

.qr-auth__title {
  font-size: 1.35rem;
  font-weight: 700;
  color: #fff;
  line-height: 1.25;
  max-width: 320px;
}

.qr-auth__subtitle {
  font-size: 0.9rem;
  color: var(--text-muted);
  line-height: 1.45;
  max-width: 340px;
}

.qr-auth__error {
  font-size: 0.85rem;
  color: #ff6b8a;
}

.qr-auth__error.hidden {
  display: none;
}

.qr-auth__switch,
.qr-auth__help {
  margin-top: 4px;
  color: #5eb3ff;
  font-size: 0.95rem;
  background: none;
  border: none;
  cursor: pointer;
  text-decoration: none;
}

.qr-auth__switch:hover,
.qr-auth__help:hover {
  text-decoration: underline;
}

#step-phone .qr-auth__switch {
  margin-top: 20px;
}
