@font-face {
  font-family: 'Roboto';
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url('fonts/roboto-600.woff2') format('woff2');
}

*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --bg: #0b0d11;
  --card-bg: #121214;
  --card-bg-phone: #181a1f;
  --text: #ffffff;
  --text-muted: #8e8e93;
  --text-hint: #949494;
  --link: #007aff;
  --input-bg: #2c2c2e;
  --input-bg-phone: #26272b;
  --btn-disabled-bg: #333438;
  --btn-disabled-text: #8e8e93;
  --divider: rgba(255, 255, 255, 0.18);
  --radius-modal: 28px;
  --radius-input: 12px;
  --radius-btn: 14px;
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  --font-brand: 'Roboto', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  --modal-width: 420px;
  --modal-pad-x: 28px;
  --modal-pad-top: 20px;
  --modal-pad-bottom: 28px;
}

html, body {
  height: 100%;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ========== Background ========== */
.bg-pattern {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  overflow: hidden;
}

.bg-pattern::before {
  content: '';
  position: absolute;
  inset: 0;
  background: var(--bg);
}

.bg-pattern::after {
  content: '';
  position: absolute;
  inset: 0;
  background-image: url('pattern.svg');
  background-repeat: repeat;
  background-size: 280px 280px;
  opacity: 0.085;
}

/* ========== Layout ========== */
.main {
  position: relative;
  z-index: 1;
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
}

/* ========== Modal Card ========== */
.modal {
  background: var(--card-bg);
  border-radius: var(--radius-modal);
  width: 100%;
  max-width: var(--modal-width);
  position: absolute;
  overflow: hidden;
  box-shadow:
    0 0 0 1px rgba(255, 255, 255, 0.04),
    0 24px 64px rgba(0, 0, 0, 0.55);
}

#step-phone {
  background: var(--card-bg-phone);
}

.modal__glow {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 210px;
  pointer-events: none;
  z-index: 0;
  overflow: hidden;
}

.modal__glow-disc {
  position: absolute;
  left: 50%;
  top: 0;
  width: 520px;
  height: 520px;
  transform: translate(-50%, -58%);
  border-radius: 50%;
  background: conic-gradient(
    from 0deg,
    #5eb3cc 0deg,
    #3d8fbf 40deg,
    #2a6db8 80deg,
    #1a3a6a 130deg,
    #3d3a8f 170deg,
    #7a4fa8 210deg,
    #8e3d9e 250deg,
    #5c3d8f 290deg,
    #3a2860 330deg,
    #1a3a6a 350deg,
    #5eb3cc 360deg
  );
  filter: blur(40px) saturate(0.85) brightness(0.72);
  opacity: 0.62;
  animation: glowSpin 14s linear infinite;
  will-change: transform;
}

.modal__glow::after {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(
    ellipse 90% 100% at 50% 0%,
    transparent 0%,
    rgba(24, 26, 31, 0.35) 40%,
    rgba(24, 26, 31, 0.72) 70%,
    var(--card-bg-phone) 92%
  );
  pointer-events: none;
}

@keyframes glowSpin {
  from { transform: translate(-50%, -58%) rotate(0deg); }
  to { transform: translate(-50%, -58%) rotate(360deg); }
}

.modal__toolbar {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--modal-pad-top) var(--modal-pad-x) 0;
  min-height: 44px;
}

.modal__toolbar--empty {
  min-height: 20px;
  padding-bottom: 0;
}

.modal__icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border: none;
  background: transparent;
  color: #ffffff;
  cursor: pointer;
  border-radius: 50%;
  text-decoration: none;
  transition: background 0.2s;
  flex-shrink: 0;
}

.modal__icon-btn:hover {
  background: rgba(255, 255, 255, 0.06);
}

/* ========== Step transitions ========== */
.step {
  opacity: 0;
  transform: translateY(16px) scale(0.98);
  pointer-events: none;
  transition: opacity 0.35s ease, transform 0.35s ease;
}

.step.active {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

/* ========== QR Auth ========== */
.qr-auth {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 8px var(--modal-pad-x) var(--modal-pad-bottom);
}

.qr-auth__canvas-wrap {
  position: relative;
  width: 240px;
  height: 240px;
  margin-bottom: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.qr-auth__qr-visual {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: filter 0.5s ease, opacity 0.5s ease;
}

.qr-auth__canvas-wrap--ready .qr-auth__qr-visual {
  animation: qrReveal 0.5s cubic-bezier(0.22, 1, 0.36, 1) both;
}

.qr-auth__canvas-wrap--expired .qr-auth__qr-visual {
  filter: blur(7px) brightness(0.85);
  opacity: 0.75;
  pointer-events: none;
}

#qr-canvas {
  display: block;
  width: 240px;
  height: 240px;
}

.qr-auth__loader {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2;
}

.qr-auth__loader.hidden {
  display: none;
}

.qr-auth__loader-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.qr-auth__loader-grid {
  display: grid;
  grid-template-columns: repeat(3, 16px);
  grid-template-rows: repeat(3, 16px);
  gap: 6px;
}

.qr-auth__loader-grid span {
  border-radius: 4px;
  background: rgba(142, 142, 147, 0.35);
  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; transform: scale(0.92); }
  50% { opacity: 1; transform: scale(1); }
}

.qr-auth__loader-text {
  font-size: 14px;
  color: var(--text-muted);
}

@keyframes qrReveal {
  from { opacity: 0; transform: scale(0.96); }
  to { opacity: 1; transform: scale(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(18, 18, 20, 0.92);
  backdrop-filter: blur(6px);
}

.qr-auth__success.hidden { display: none; }

.qr-auth__success-icon { color: #5ee09a; }

.qr-auth__success-text {
  font-size: 15px;
  font-weight: 600;
  color: #e8fff2;
}

.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 {
  width: 52px;
  height: 52px;
  border: none;
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  background: var(--link);
  cursor: pointer;
  box-shadow: 0 8px 24px rgba(0, 122, 255, 0.4);
  transition: transform 0.2s, filter 0.2s;
}

.qr-auth__refresh:hover {
  transform: scale(1.05);
  filter: brightness(1.08);
}

.qr-auth__title {
  font-size: 20px;
  font-weight: 700;
  line-height: 1.3;
  color: var(--text);
  margin-bottom: 8px;
  max-width: 320px;
}

.qr-auth__subtitle {
  font-size: 14px;
  font-weight: 400;
  line-height: 1.45;
  color: var(--text-muted);
  max-width: 340px;
  margin-bottom: 0;
}

.qr-auth__status {
  font-size: 13px;
  color: #c96a72;
  line-height: 1.4;
  margin-top: 12px;
}

.qr-auth__status.hidden { display: none; }

.qr-auth__error {
  font-size: 13px;
  color: #ff6b8a;
  margin-top: 8px;
}

.qr-auth__error.hidden { display: none; }

#step-qr .link-btn {
  margin-top: 40px;
}

/* ========== Phone Auth ========== */
.phone-auth {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 4px var(--modal-pad-x) var(--modal-pad-bottom);
}

.brand {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-bottom: 28px;
  animation: brandFloat 5s ease-in-out infinite;
  will-change: transform;
}

@keyframes brandFloat {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-6px); }
}

.brand__icon {
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  display: block;
  object-fit: contain;
}

.brand__text {
  font-family: var(--font-brand);
  font-size: 34px;
  font-weight: 600;
  letter-spacing: 0;
  color: var(--text);
  line-height: 1;
  text-transform: uppercase;
}

.phone-auth__title {
  font-size: 20px;
  font-weight: 700;
  line-height: 1.35;
  color: var(--text);
  margin-bottom: 8px;
  max-width: 340px;
}

.phone-auth__subtitle {
  font-size: 15px;
  font-weight: 400;
  line-height: 1.4;
  color: var(--text-hint);
  margin-bottom: 28px;
}

.phone-field {
  position: relative;
  display: flex;
  align-items: center;
  width: 100%;
  height: 52px;
  background: var(--input-bg-phone);
  border-radius: var(--radius-input);
  transition: box-shadow 0.2s;
}

.phone-field:focus-within {
  box-shadow: 0 0 0 2px rgba(0, 122, 255, 0.35);
}

.phone-field.input-wrap--error {
  box-shadow: 0 0 0 2px rgba(255, 59, 48, 0.35);
}

.country-select {
  display: flex;
  align-items: center;
  gap: 6px;
  height: 100%;
  padding: 0 4px 0 14px;
  border: none;
  background: transparent;
  cursor: pointer;
  flex-shrink: 0;
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
}

.country-select__flag {
  font-size: 20px;
  line-height: 1;
}

.country-select__dial {
  font-weight: 500;
  font-size: 16px;
  color: var(--text);
}

.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__divider {
  width: 1px;
  height: 24px;
  background: var(--divider);
  flex-shrink: 0;
}

.phone-field__input {
  flex: 1;
  min-width: 0;
  height: 100%;
  padding: 0 14px 0 10px;
  border: none;
  background: transparent;
  color: var(--text);
  font-size: 16px;
  font-family: var(--font);
  outline: none;
}

.phone-field__input::placeholder {
  color: var(--text-muted);
}

.phone-auth__hint {
  width: 100%;
  font-size: 12px;
  line-height: 1.45;
  color: var(--text-hint);
  text-align: left;
  margin-top: 10px;
}

/* ========== Buttons ========== */
.btn {
  display: block;
  width: 100%;
  height: 52px;
  margin-top: 20px;
  border: none;
  border-radius: var(--radius-btn);
  font-size: 16px;
  font-weight: 600;
  font-family: var(--font);
  cursor: pointer;
  transition: opacity 0.2s, transform 0.15s, background 0.2s;
}

.btn--primary {
  background: var(--link);
  color: #ffffff;
}

.btn--primary:not(:disabled):hover {
  filter: brightness(1.06);
}

.btn--primary:not(:disabled):active {
  transform: scale(0.98);
}

.btn--primary.btn--disabled,
.btn--primary:disabled {
  background: var(--btn-disabled-bg);
  color: var(--btn-disabled-text);
  cursor: default;
  transform: none;
  filter: none;
}

.btn__text,
.btn__loader {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.phone-auth__register {
  margin-top: 24px;
  font-size: 15px;
  font-weight: 500;
}

.phone-auth__legal {
  margin-top: 20px;
  font-size: 11px;
  line-height: 1.5;
  color: var(--text-muted);
  max-width: 340px;
}

.phone-auth__legal a {
  color: var(--text-muted);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.phone-auth__legal a:hover {
  color: var(--text);
}

/* ========== Links ========== */
.link-btn {
  background: none;
  border: none;
  color: var(--link);
  font-size: 15px;
  font-family: var(--font);
  font-weight: 500;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
  text-decoration: none;
  transition: opacity 0.2s;
}

.link-btn:not(:disabled):hover {
  opacity: 0.85;
}

.link-btn:disabled {
  color: var(--text-muted);
  cursor: default;
  opacity: 0.7;
}

.link-back {
  color: var(--link);
  text-decoration: none;
  cursor: pointer;
  font-weight: 500;
}

.link-back:hover {
  text-decoration: underline;
}

/* ========== Country dropdown ========== */
.country-dropdown {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  right: 0;
  z-index: 200;
  background: #26272b;
  border: 1px solid rgba(255, 255, 255, 0.08);
  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: #1a1a1c;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 8px;
  color: #fff;
  font-size: 14px;
  font-family: var(--font);
  outline: none;
}

.country-dropdown__search:focus {
  border-color: var(--link);
}

.country-dropdown__list {
  list-style: none;
  max-height: 240px;
  overflow-y: auto;
  padding: 6px;
  margin: 0;
}

.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(0, 122, 255, 0.15);
  outline: none;
}

.country-dropdown__item.is-active {
  background: rgba(0, 122, 255, 0.25);
}

.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;
}

/* ========== State screens (code, password, done) ========== */
.state-screen {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 8px var(--modal-pad-x) var(--modal-pad-bottom);
}

.state-screen__title {
  font-size: 20px;
  font-weight: 700;
  line-height: 1.35;
  color: var(--text);
  margin-bottom: 8px;
}

.state-screen__subtitle {
  font-size: 14px;
  color: var(--text-muted);
  line-height: 1.5;
  margin-bottom: 24px;
}

.state-screen__text {
  font-size: 14px;
  color: var(--text-muted);
}

.state-screen__success-icon {
  color: #5ee09a;
  margin-bottom: 16px;
}

/* ========== Inputs ========== */
.input {
  width: 100%;
  height: 52px;
  padding: 0 16px;
  background: var(--input-bg);
  border: none;
  border-radius: var(--radius-input);
  color: var(--text);
  font-size: 16px;
  font-family: var(--font);
  outline: none;
  transition: box-shadow 0.2s;
}

.input:focus {
  box-shadow: 0 0 0 2px rgba(0, 122, 255, 0.35);
}

.input--error {
  box-shadow: 0 0 0 2px rgba(255, 59, 48, 0.35) !important;
  animation: shake 0.35s ease;
}

.password-wrap {
  position: relative;
  width: 100%;
}

.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;
}

.password-toggle:hover {
  color: var(--text);
}

/* ========== Code boxes ========== */
.code-boxes {
  display: flex;
  gap: 10px;
  justify-content: center;
  margin: 8px 0 4px;
}

.code-box {
  width: 44px;
  height: 52px;
  text-align: center;
  font-size: 22px;
  font-weight: 600;
  background: var(--input-bg);
  color: var(--text);
  border: none;
  border-radius: var(--radius-input);
  outline: none;
  font-family: var(--font);
  caret-color: var(--link);
  transition: box-shadow 0.2s;
  -moz-appearance: textfield;
}

.code-box::-webkit-outer-spin-button,
.code-box::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.code-box:focus {
  box-shadow: 0 0 0 2px rgba(0, 122, 255, 0.35);
}

.code-boxes.is-error .code-box {
  box-shadow: 0 0 0 2px rgba(255, 59, 48, 0.35);
  animation: shake 0.35s ease;
}

.code-boxes.is-loading .code-box {
  opacity: 0.65;
  pointer-events: none;
}

.resend-row {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  margin-top: 18px;
}

.resend-timer {
  font-size: 13px;
  color: var(--text-muted);
  min-height: 18px;
}

.form-error {
  color: #ff3b30;
  font-size: 13px;
  margin-top: 12px;
  text-align: center;
  line-height: 1.4;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-6px); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(4px); }
}

/* ========== 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: 32px 0;
}

.hidden {
  display: none !important;
}

/* ========== Responsive ========== */
@media (max-width: 480px) {
  :root {
    --modal-pad-x: 20px;
    --radius-modal: 24px;
  }

  .qr-auth__title,
  .phone-auth__title,
  .state-screen__title {
    font-size: 18px;
  }

  .code-boxes { gap: 8px; }
  .code-box { width: 40px; height: 48px; font-size: 20px; }
}

@media (prefers-reduced-motion: reduce) {
  .step,
  .qr-auth__qr-visual,
  .qr-auth__loader-grid span,
  .code-boxes.is-error .code-box,
  .input--error,
  .modal__glow-disc,
  .brand {
    animation: none !important;
    transition: none !important;
  }
}
