:root {
  --bg-light: #ffffff;
  --bg-dark: #090d14;
  --text-main: #1e293b;
  --text-sub: #64748b;
  --accent-purple: #6366f1;
  --accent-hover: #4f46e5;
  --card-dark: rgba(15, 23, 42, 0.85);
  --border-light: #e2e8f0;
  --success: #10b981;
  --warning: #f59e0b;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-user-drag: none;
  touch-action: manipulation;
}

html, body {
  width: 100%;
  height: 100%;
  min-height: 100dvh;
  overflow: hidden;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background-color: var(--bg-light);
  color: var(--text-main);
}

.app-viewport {
  position: relative;
  width: 100vw;
  height: 100dvh;
  min-height: 100dvh;
  max-height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Camera & Canvas Stage */
.camera-stage {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
  background: #000;
}

#video, #mesh {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scaleX(-1);
}

.camera-stage.camera-loading #video {
  opacity: 0;
}

#mesh {
  pointer-events: none;
  z-index: 2;
}

.camera-stage.id-camera #video {
  transform: none;
}

/* Guided face target: keep the face naturally inside this circle. */
.face-guide {
  position: absolute;
  inset: 0;
  z-index: 4;
  pointer-events: none;
  display: flex;
  align-items: center;
  justify-content: center;
  padding-bottom: clamp(70px, 11vh, 110px);
}

.face-guide-circle {
  width: min(62vw, 270px);
  height: min(82vw, 360px);
  border: 2px solid rgba(255, 255, 255, 0.92);
  border-radius: 50% / 48%;
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.62),
              0 0 0 1px rgba(255, 255, 255, 0.08);
  transition: border-color .22s ease, box-shadow .22s ease, transform .22s ease;
}

.direction-arrow {
  position: absolute;
  z-index: 1;
  width: 24px;
  height: 24px;
  opacity: 0;
  transition: opacity .2s ease, transform .2s ease;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, .45));
}

.direction-arrow::before {
  content: '';
  position: absolute;
  top: 4px;
  left: 4px;
  width: 14px;
  height: 14px;
  border-right: 4px solid #fff;
  border-bottom: 4px solid #fff;
}

.direction-arrow.direction-left,
.direction-arrow.direction-right,
.direction-arrow.direction-up,
.direction-arrow.direction-down {
  opacity: 1;
}

.direction-arrow.direction-right::before {
  transform: rotate(-45deg);
}

.direction-arrow.direction-left::before {
  transform: rotate(135deg);
}

.direction-arrow.direction-up::before {
  transform: rotate(-135deg);
}

.direction-arrow.direction-down::before {
  transform: rotate(45deg);
}

.face-guide.good .face-guide-circle {
  border-color: #16a34a;
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.62),
              0 0 24px rgba(22, 163, 74, 0.28);
}

.face-guide.success .face-guide-circle {
  border-color: #16a34a;
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.58),
              0 0 30px rgba(22, 163, 74, 0.42);
  transform: scale(1.015);
}

.viewport-vignette {
  position: absolute;
  inset: 0;
  z-index: 3;
  pointer-events: none;
  background: transparent;
}

@media (max-width: 600px) {
  .face-guide-circle {
    width: min(64vw, 250px);
    height: min(86vw, 335px);
    border-radius: 50% / 48%;
  }
}

/* Onboarding Overlay — responsive MetaMap-like first step */
.intro-overlay {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: stretch;
  justify-content: center;
  background: #fff;
  padding: 18px max(16px, 4.5vw) 16px;
  transition: opacity .3s ease, visibility .3s ease;
  overflow: hidden;
}

.intro-overlay.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.onboarding-container {
  width: 100%;
  max-width: 390px;
  min-height: 100%;
  display: flex;
  flex-direction: column;
  margin: 0 auto;
}

/* Brand: compact and close to the top */
.brand-header {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 4px;
  margin: 0 0 clamp(26px, 6vh, 42px);
  padding: 0;
}

.brand-icon {
  width: 24px;
  height: 24px;
  flex: 0 0 24px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.brand-icon img {
  width: 24px;
  height: 24px;
  object-fit: contain;
  display: block;
}

.brand-name {
  font-size: 17px;
  line-height: 1;
  font-weight: 600;
  letter-spacing: -.25px;
  color: #202020;
}

/* Reference screenshot uses a left-aligned content column */
.content-body {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  text-align: left;
  margin: 0;
}

.main-title {
  margin: 0;
  font-size: clamp(20px, 5.8vw, 25px);
  line-height: 1.25;
  font-weight: 600;
  letter-spacing: -.55px;
  color: #171717;
}

.subtitle {
  margin: 5px 0 0;
  padding-left: 10px;
  font-size: clamp(10px, 3vw, 12px);
  line-height: 1.45;
  font-weight: 400;
  color: #707070;
}

/* Compact icon + label rows */
.steps-list {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: clamp(14px, 4vh, 22px);
  margin-top: clamp(39px, 8vh, 54px);
}

.step-item {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 10px;
  min-height: 25px;
  padding: 0;
  text-align: left;
}

.step-icon {
  width: 34px;
  height: 34px;
  flex: 0 0 34px;
  border-radius: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #606060;
}

.step-icon svg {
  width: 30px;
  height: 30px;
  stroke: currentColor;
  stroke-width: 1.35;
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.step-text {
  font-size: clamp(10px, 3vw, 12px);
  line-height: 1.35;
  font-weight: 400;
  color: #444;
}

.id-type-field {
  width: 100%;
  margin-top: clamp(24px, 5vh, 32px);
}

.id-type-select {
  width: 100%;
  min-height: 42px;
  padding: 10px 12px;
  border: 1px solid #d7d9e5;
  border-radius: 8px;
  background: #fff;
  color: #1a1a1a;
  font-size: 12px;
  line-height: 1.3;
  font-weight: 400;
  outline: none;
  box-sizing: border-box;
  appearance: none;
  -webkit-appearance: none;
}

.id-type-select option {
  color: #1a1a1a;
}

.id-type-select:invalid {
  color: #7a7a7a;
}

.id-type-select:focus {
  border-color: #6657e8;
  box-shadow: 0 0 0 3px rgba(102, 87, 232, 0.12);
}

.id-type-select:focus {
  border-color: #6657e8;
  box-shadow: 0 0 0 3px rgba(102, 87, 232, 0.12);
}

/* CTA stays at the bottom, like the reference, without fixed pixel width */
.action-footer {
  position: relative;
  width: 100%;
  margin-top: auto;
  padding: clamp(24px, 7vh, 42px) 0 0;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 7px;
}

.btn-primary {
  width: 100%;
  min-height: 39px;
  padding: 10px 18px;
  border: 0;
  border-radius: 4px;
  background: #6657e8;
  color: #fff;
  font-size: 12px;
  line-height: 1;
  font-weight: 500;
  cursor: pointer;
  box-shadow: none;
  transition: background-color .2s ease, transform .1s ease;
}

.btn-primary:hover {
  background: #5949dc;
}

.btn-primary:active {
  transform: scale(.99);
}

.btn-primary:disabled {
  opacity: .7;
  cursor: wait;
}

.error-msg {
  margin: 0 0 16px;
  font-size: 12px;
  line-height: 1.45;
  color: #d92d20;
  text-align: center;
}

.error-modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  opacity: 1;
  visibility: visible;
  transition: opacity .2s ease, visibility .2s ease;
}

.error-modal.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.error-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(10, 12, 18, 0.5);
}

.error-modal-card {
  position: relative;
  width: min(100%, 330px);
  padding: 22px 18px 18px;
  border-radius: 16px;
  background: #fff;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.22);
  text-align: center;
}

.error-modal-title {
  margin: 0 0 10px;
  font-size: 18px;
  line-height: 1.25;
  font-weight: 600;
  color: #171717;
}

.error-modal .btn-primary {
  width: 100%;
  min-height: 40px;
  border-radius: 8px;
}

@media (min-width: 600px) {
  .intro-overlay {
    padding-left: 24px;
    padding-right: 24px;
  }

  .onboarding-container {
    max-width: 420px;
  }

  .brand-header {
    margin-bottom: 42px;
  }

  .main-title {
    font-size: 25px;
  }

  .subtitle {
    font-size: 12px;
  }

  .step-text {
    font-size: 12px;
  }

  .btn-primary {
    min-height: 44px;
    font-size: 13px;
  }
}

@media (max-height: 560px) {
  .intro-overlay {
    padding-top: 12px;
    padding-bottom: 12px;
  }

  .brand-header {
    margin-bottom: 20px;
  }

  .steps-list {
    margin-top: 25px;
    gap: 11px;
  }

  .action-footer {
    padding-top: 18px;
  }
}

/* Uncluttered Bottom Controls (Active Scanning View) */
.bottom-drawer {
  position: absolute;
  bottom: clamp(16px, 4vh, 32px);
  left: 50%;
  transform: translateX(-50%);
  width: calc(100% - clamp(24px, 6vw, 48px));
  max-width: 400px;
  z-index: 10;
  padding: clamp(14px, 3vh, 20px) clamp(18px, 4vw, 24px);
  border-radius: clamp(16px, 4vw, 24px);
  background: var(--card-dark);
  border: 1px solid rgba(255, 255, 255, 0.12);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  box-shadow: 0 16px 36px rgba(0, 0, 0, 0.4);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.instruction-text {
  font-size: clamp(13px, 3.2vw, 15px);
  font-weight: 600;
  color: #ffffff;
  text-align: center;
  letter-spacing: -0.2px;
}

.id-scan-screen {
  position: absolute;
  inset: 0;
  z-index: 21;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  padding: clamp(28px, 8vh, 72px) max(20px, 5vw) clamp(28px, 8vh, 72px);
  color: #fff;
  text-align: center;
  pointer-events: none;
}

.id-scan-header {
  width: min(100%, 430px);
}

.id-scan-step {
  margin-bottom: 12px;
  color: rgba(255, 255, 255, .72);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .08em;
  text-transform: uppercase;
}

.id-scan-header h1 {
  font-size: clamp(22px, 5.8vw, 30px);
  line-height: 1.2;
  font-weight: 600;
}

.id-scan-header p {
  max-width: 340px;
  margin: 10px auto 0;
  color: rgba(255, 255, 255, .82);
  font-size: clamp(13px, 3.5vw, 16px);
  line-height: 1.45;
}

.id-card-guide {
  position: absolute;
  top: 50%;
  left: 50%;
  width: min(84vw, 420px);
  aspect-ratio: 1.586 / 1;
  border: 2px solid rgba(255, 255, 255, .92);
  border-radius: 14px;
  transform: translate(-50%, -50%);
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, .58), 0 0 28px rgba(255, 255, 255, .18);
  transition: border-color .2s ease, box-shadow .2s ease;
}

.id-card-guide.ready {
  border-color: #16a34a;
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, .58), 0 0 28px rgba(22, 163, 74, .5);
}

.id-card-corners {
  position: absolute;
  inset: -2px;
  border: 3px solid transparent;
  border-top-color: #2b7afb;
  border-bottom-color: #2b7afb;
  border-radius: 14px;
}

.id-scan-line {
  position: absolute;
  top: 12%;
  left: 5%;
  width: 90%;
  height: 2px;
  background: #2b7afb;
  box-shadow: 0 0 12px rgba(43, 122, 251, .9);
  animation: scan-id 2.2s ease-in-out infinite;
}

.id-scan-status {
  min-height: 22px;
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  text-shadow: 0 1px 4px rgba(0, 0, 0, .55);
}

@keyframes scan-id {
  0%, 100% { top: 12%; }
  50% { top: 88%; }
}


/* Result states — message centered in viewport, actions fixed at bottom */
.result-screen {
  position: absolute;
  inset: 0;
  z-index: 22;
  background: #fff;
  padding: 18px max(16px, 4.5vw) 16px;
  display: none;
  flex-direction: column;
  align-items: stretch;
  justify-content: center;
  text-align: center;
}

.result-content {
  width: min(100%, 390px);
  margin: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.result-content .main-title {
  margin-top: 18px;
  text-align: center;
}

.result-content .subtitle {
  max-width: 340px;
  padding-left: 0;
  text-align: center;
  margin-top: 8px;
}

.result-actions {
  width: min(100%, 390px);
  margin: auto auto 0;
  padding-top: 24px;
}

.result-actions .btn-primary {
  width: 100%;
}

.result-icon {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.result-icon svg {
  width: 34px;
  height: 34px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.success-result-icon {
  color: #16a34a;
  background: rgba(22, 163, 74, .10);
}

.failure-result-icon {
  color: #dc2626;
  background: rgba(220, 38, 38, .10);
}

@media (min-width: 600px) {
  .result-screen {
    padding-left: 24px;
    padding-right: 24px;
  }

  .result-content,
  .result-actions {
    width: min(100%, 420px);
  }
}

@media (max-height: 560px) {
  .result-screen {
    padding-top: 12px;
    padding-bottom: 12px;
  }

  .result-icon {
    width: 52px;
    height: 52px;
  }

  .result-icon svg {
    width: 28px;
    height: 28px;
  }

  .result-content .main-title {
    margin-top: 12px;
  }

  .result-actions {
    padding-top: 14px;
  }
}

/* Center the first-step branding and introduction copy */
.intro-overlay .onboarding-container {
  align-items: center;
}

.intro-overlay .brand-header {
  justify-content: center;
  width: 100%;
}

.intro-overlay .content-body {
  align-items: center;
  text-align: center;
}

.intro-overlay .main-title,
.intro-overlay .subtitle {
  text-align: center;
}

/* Error messages appear ABOVE action buttons */
.error-message,
.error-msg,
.camera-error,
.step-error,
.verification-error,
.error {
    order: -1;
    margin-bottom: 12px;
    margin-top: 0;
}

/* CamKYC: validation/camera errors must render above the action button */
.step-content .error-message,
.step-content .error-msg,
.step-content .camera-error,
.step-content .step-error,
.step-content .verification-error {
    display: block;
    width: 100%;
    margin: 0 0 12px 0;
    order: 0;
}
.step-content button,
.step-content .btn,
.step-content .action-button {
    order: 1;
}
