/*  
   FONTS
*/
@font-face {
  font-family: "Space Grotesk";
  src: url("/assets/fonts/SpaceGrotesk-Regular.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Space Grotesk";
  src: url("/assets/fonts/SpaceGrotesk-Medium.woff2") format("woff2");
  font-weight: 500;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Space Grotesk";
  src: url("/assets/fonts/SpaceGrotesk-Bold.woff2") format("woff2");
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Space Mono";
  src: url("/assets/fonts/SpaceMono-Regular.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Space Mono";
  src: url("/assets/fonts/SpaceMono-Bold.woff2") format("woff2");
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

/*  
   DESIGN TOKENS
 */
:root {
  --red: #e50914;
  --red-dark: #b8070f;
  --red-muted: rgba(229, 9, 20, 0.08);
  --red-border: rgba(229, 9, 20, 0.28);

  --ink: #18181b;
  --ink-mid: #52525b;
  --ink-light: #71717a;
  --ink-ghost: #a1a1aa;

  --surface: #f5f4f2;
  --white: #ffffff;
  --border: #e0deda;
  --border-2: #ccc9c4;

  --green: #1a8a4a;
  --amber: #c27c00;

  --radius-lg: 18px;
  --radius-md: 12px;
  --radius-sm: 8px;

  --font: "Space Grotesk", sans-serif;
  --mono: "Space Mono", monospace;

  --shadow: 0 2px 14px rgba(0, 0, 0, 0.07);
  --shadow-lg: 0 8px 36px rgba(0, 0, 0, 0.11);
}

/*  
   RESET
 */
*,
*::before,
*::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  user-select: none;
}

html,
body {
  font-family: var(--font);
  background: var(--surface);
  color: var(--ink);
  width: 100%;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

/*  
   APP SHELL
 */
.app {
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
  padding: 0 16px 32px;
  min-height: 100svh;
  height: 100svh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

@media (min-width: 400px) {
  .app {
    padding: 0 20px 32px;
  }
}

/* Lock body scroll during camera steps */
body:has(#step2.active),
body:has(#step3.active),
body:has(#step4.active) {
  overflow: hidden;
  height: 100svh;
}

/*  
   STEP BAR
 */
.step-bar {
  display: none;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 14px 0 10px;
  flex-wrap: wrap;
}
.step-bar.visible {
  display: flex;
}

.step-pip {
  font-size: 11px;
  font-weight: 500;
  color: var(--ink-light);
  padding: 4px 10px;
  border-radius: 20px;
  transition:
    color 0.25s,
    background 0.25s,
    font-weight 0.25s;
}
.step-pip.active {
  color: var(--red);
  font-weight: 700;
  background: var(--red-muted);
}
.step-pip.done {
  color: var(--green);
  font-weight: 500;
}

.step-sep {
  color: var(--ink-ghost);
  font-size: 12px;
  user-select: none;
}

/*  
   STEPS
 */
.step {
  display: none;
  flex-direction: column;
  flex: 1;
}
.step.active {
  display: flex;
  animation: stepIn 0.28s cubic-bezier(0.22, 1, 0.36, 1) both;
}

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

/* Camera steps: fixed height, no scroll */
#step2.active,
#step3.active,
#step4.active {
  height: calc(100svh - 56px);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.step2-hint {
  margin-bottom: 20px;
}

#step2 .section-sub {
  min-height: 2.6em;
  line-height: 1.3;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Step 3 error state — shrinks camera to make room for error UI */
#step3.step3--error {
  height: calc(100svh - 56px);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}
#step3.step3--error #idCamWrap {
  height: 180px;
  max-height: 180px;
  flex-shrink: 0;
}
#step3.step3--error .cam-video {
  aspect-ratio: unset;
  height: 180px;
  object-fit: cover;
}
#step3.step3--error #idCanvas {
  display: none;
}

/* Step 5 scrolls independently */
#step5.active {
  height: calc(100svh - 56px);
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
#step5.active::-webkit-scrollbar {
  display: none;
}

/*  
   TYPOGRAPHY
 */
.hero-title {
  font-size: 24px;
  font-weight: 700;
  text-align: center;
  margin-bottom: 6px;
  letter-spacing: -0.02em;
}
.hero-sub {
  font-size: 13px;
  text-align: center;
  color: var(--ink-mid);
  margin-bottom: 20px;
  line-height: 1.55;
}
.section-title {
  font-size: 21px;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin-bottom: 3px;
  text-align: center;
}
.section-sub {
  font-size: 13px;
  color: var(--ink-mid);
  margin-bottom: 14px;
  text-align: center;
}

/*  
   GUIDE CARDS (Step 1)
 */
.guide-list {
  display: flex;
  flex-direction: column;
  gap: 9px;
  margin-bottom: 18px;
  flex: 1;
}
.guide-card {
  background: var(--white);
  border-radius: var(--radius-lg);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 13px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}
.guide-icon {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--red);
}
.guide-icon svg {
  width: 24px;
  height: 24px;
  stroke: currentColor;
  stroke-width: 2;
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.guide-text h4 {
  font-size: 13px;
  font-weight: 700;
  margin-bottom: 2px;
}
.guide-text p {
  font-size: 12px;
  color: var(--ink-mid);
  line-height: 1.5;
}

/*  
   DOC SELECTION (Step 2)
 */
.doc-grid {
  display: flex;
  flex-direction: column;
  gap: 11px;
  margin-bottom: 18px;
  flex: 1;
}
.doc-card {
  background: var(--white);
  border: 2px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px 16px;
  cursor: pointer;
  touch-action: manipulation;
  transition:
    border-color 0.2s,
    box-shadow 0.2s,
    transform 0.1s;
  display: flex;
  align-items: center;
  gap: 15px;
}
.doc-card.selected {
  border-color: var(--red);
  box-shadow: 0 0 0 3px rgba(229, 9, 20, 0.1);
  background: #fffafa;
}
.doc-card:active {
  transform: scale(0.98);
}
.doc-card-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.doc-card h3 {
  font-size: 15px;
  font-weight: 700;
  margin-bottom: 3px;
}
.doc-card p {
  font-size: 12px;
  color: var(--ink-mid);
}
.doc-card-icon svg {
  width: 28px;
  height: 28px;
  color: var(--red);
}

/*  
   BUTTONS
 */
.btn {
  background: var(--red);
  color: var(--white);
  border: none;
  border-radius: var(--radius-lg);
  padding: 0 28px;
  height: 52px;
  font-family: var(--font);
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.01em;
  cursor: pointer;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition:
    background 0.15s,
    transform 0.1s;
  appearance: none;
  -webkit-appearance: none;
  touch-action: manipulation;
  position: relative;
}
.btn:active {
  background: var(--red-dark);
  transform: scale(0.97);
}
.btn:disabled {
  background: #e4e4e7;
  color: var(--ink-ghost);
  cursor: not-allowed;
  transform: none;
}

/* Loading spinner inside button */
.btn.loading {
  color: transparent;
  pointer-events: none;
  cursor: wait;
}
.btn.loading::after {
  content: "";
  position: absolute;
  width: 18px;
  height: 18px;
  border: 2.5px solid rgba(255, 255, 255, 0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.72s linear infinite;
}

.btn.loading:disabled {
  background: var(--red);
  color: transparent;
}

/* Ghost variant */
.btn-ghost {
  background: transparent;
  color: var(--ink-mid);
  border: 1.5px solid var(--border-2);
}
.btn-ghost:active {
  background: var(--surface);
  transform: scale(0.97);
}
.btn-ghost:disabled {
  background: transparent;
  color: var(--ink-ghost);
  border-color: var(--border);
  cursor: not-allowed;
  transform: none;
}

.btn-row {
  display: flex;
  gap: 10px;
  margin-top: 10px;
}
.btn-row .btn {
  flex: 1;
}

/*  
   CAMERA
 */
.cam-wrap {
  position: relative;
  width: 100%;
  border-radius: var(--radius-lg);
  overflow: hidden;
  background: #111;
  margin-bottom: 10px;
  height: 52svh;
  flex-shrink: 0;
}
.cam-video {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
  background: #111;
}
.cam-canvas {
  position: absolute;
  inset: 0;
  pointer-events: none;
  width: 100%;
  height: 100%;
}
.cam-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.65);
  color: #fff;
  gap: 12px;
  z-index: 10;
}
.cam-overlay.hidden {
  display: none;
}

/* Front camera is CSS-mirrored so the user sees a natural reflection */
#selfieVideo,
#selfieCanvas {
  transform: scaleX(-1);
}

/*  
   CAPTURE RING
 */
.capture-ring-wrap {
  position: absolute;
  bottom: 14px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 20;
  display: none;
  flex-direction: column;
  align-items: center;
  gap: 5px;
}
.capture-ring-wrap.visible {
  display: flex;
}
.capture-ring-svg {
  width: 52px;
  height: 52px;
  transform: rotate(-90deg);
}
.capture-ring-track {
  fill: none;
  stroke: rgba(255, 255, 255, 0.18);
  stroke-width: 4;
}
.capture-ring-fill {
  fill: none;
  stroke: #4ade80;
  stroke-width: 4;
  stroke-linecap: round;
  stroke-dasharray: 138.2;
  stroke-dashoffset: 138.2;
  transition: stroke-dashoffset 0.1s linear;
}
.capture-ring-label {
  font-size: 10px;
  font-weight: 500;
  color: #fff;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

/*  
   FEEDBACK & NOTICES
 */
.feedback {
  background: rgba(15, 15, 15, 0.82);
  color: #fff;
  border-radius: var(--radius-sm);
  padding: 10px 16px;
  font-size: 13px;
  font-weight: 700;
  text-align: center;
  margin-bottom: 10px;
  min-height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(6px);
  transition: background 0.2s;
  letter-spacing: 0.02em;
}
.feedback.ok {
  background: rgba(26, 138, 74, 0.88);
}
.feedback.warn {
  background: rgba(194, 124, 0, 0.88);
}
.feedback.bad {
  background: rgba(15, 15, 15, 0.82);
}

.err-box {
  background: #fdecea;
  border: 1px solid #f5c6cb;
  color: #8b1a1a;
  border-radius: var(--radius-sm);
  padding: 11px 13px;
  font-size: 13px;
  margin-bottom: 10px;
}

.retry-notice {
  background: var(--amber);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  font-size: 13px;
  margin-bottom: 10px;
  line-height: 1.5;
  display: none;
  color: var(--white);
  text-align: center;
}
.retry-notice.visible {
  display: block;
}

/*  
   SPINNER
 */
.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid rgba(255, 255, 255, 0.22);
  border-top-color: var(--red);
  border-radius: 50%;
  animation: spin 0.72s linear infinite;
}
.spinner.dark {
  border-color: rgba(15, 15, 15, 0.1);
  border-top-color: var(--red);
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/*  
   SELFIE REVIEW OVERLAY
   Shown after capture so the user can confirm or retake.
   Sits inside .cam-wrap, above the canvas, below z-index 30.
 */
.selfie-review {
  position: absolute;
  inset: 0;
  z-index: 25;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.72);
  gap: 16px;
  padding: 20px 16px 16px;
  animation: reviewFadeIn 0.22s ease both;
}
.selfie-review.hidden {
  display: none;
}

@keyframes reviewFadeIn {
  from {
    opacity: 0;
    transform: scale(0.97);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

/* Oval preview — clips the captured image to match the guide shape */
.selfie-review__oval {
  width: 140px;
  height: 175px;
  border-radius: 50%;
  overflow: hidden;
  border: 3px solid #4ade80;
  flex-shrink: 0;
  box-shadow: 0 0 0 4px rgba(74, 222, 128, 0.2);
  background: #111;
}

.selfie-review__oval img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center top;
  display: block;
}

/* Label below the oval */
.selfie-review__label {
  font-size: 13px;
  font-weight: 700;
  color: #fff;
  letter-spacing: 0.02em;
  text-align: center;
}

/* Button row inside the overlay */
.selfie-review__actions {
  display: flex;
  gap: 10px;
  width: 100%;
}

/* "Use this photo" — green confirm button */
.selfie-review__confirm {
  flex: 1;
  height: 46px;
  border-radius: 40px;
  border: none;
  background: #4ade80;
  color: #052e16;
  font-family: var(--font);
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  touch-action: manipulation;
  transition:
    background 0.15s,
    transform 0.1s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}
.selfie-review__confirm:active {
  background: #22c55e;
  transform: scale(0.97);
}

/* "Retake" — ghost button */
.selfie-review__retake {
  flex: 1;
  height: 46px;
  border-radius: 40px;
  border: 1.5px solid rgba(255, 255, 255, 0.35);
  background: transparent;
  color: #fff;
  font-family: var(--font);
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  touch-action: manipulation;
  transition:
    background 0.15s,
    transform 0.1s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}
.selfie-review__retake:active {
  background: rgba(255, 255, 255, 0.1);
  transform: scale(0.97);
}

/*  
   RESULTS (Step 5)
 */
.results-card {
  background: var(--white);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: var(--shadow-lg);
  margin-bottom: 14px;
  border: 1px solid var(--border);
  flex: 0 0 auto;
}

.doc-expired-warning {
  background: #fdecea;
  border: 1px solid #f5c6cb;
  color: #8b1a1a;
  border-radius: var(--radius-sm);
  padding: 11px 13px;
  font-size: 13px;
  margin-bottom: 14px;
}

.book-review-notice {
  background: #fff8e1;
  border: 1px solid #ffe082;
  color: #7a5500;
  border-radius: var(--radius-sm);
  padding: 11px 13px;
  font-size: 13px;
  margin-bottom: 12px;
}

.fields-title {
  font-size: 11px;
  font-weight: 700;
  color: var(--ink);
  margin: 14px 0 9px;
  text-transform: uppercase;
  letter-spacing: 0.07em;
}

.field-row {
  position: relative;
  margin-bottom: 9px;
}
.field-label {
  font-size: 10px;
  color: var(--ink-light);
  margin-bottom: 3px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.field-input {
  width: 100%;
  height: 44px;
  padding: 0 12px;
  border: 1.5px solid var(--border-2);
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: 13px;
  background: var(--white);
  color: var(--ink);
  transition:
    border-color 0.15s,
    box-shadow 0.15s;
  appearance: none;
  -webkit-appearance: none;
  outline: none;
}
.field-input:focus {
  border-color: var(--red);
  box-shadow: 0 0 0 3px var(--red-muted);
  background: var(--white);
}
.field-input.error {
  border-color: #c0392b;
  background: #fff8f8;
}
.field-input.warn {
  border-color: var(--amber);
  background: #fffbf0;
}

.field-error {
  font-size: 11px;
  color: #c0392b;
  margin-top: 4px;
  max-height: 0;
  overflow: hidden;
  opacity: 0;
  transition:
    max-height 0.18s ease,
    opacity 0.18s ease;
  padding-left: 2px;
}
.field-error.visible {
  max-height: 32px;
  opacity: 1;
}

.field-warn {
  font-size: 11px;
  color: var(--amber);
  margin-top: 4px;
  max-height: 0;
  overflow: hidden;
  opacity: 0;
  transition:
    max-height 0.18s ease,
    opacity 0.18s ease;
  padding-left: 2px;
}
.field-warn.visible {
  max-height: 32px;
  opacity: 1;
}

.field-value {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--ink);
  padding: 9px 11px;
  background: var(--surface);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  opacity: 0.7;
}

/* Confirm checkbox */
.confirm-label {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  font-size: 13px;
  color: var(--ink-mid);
  margin-top: 10px;
  cursor: pointer;
}
.confirm-checkbox {
  margin: 4px;
  /* padding: 4px; */
  accent-color: var(--red);
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

.field-input,
.confirm-checkbox {
  -webkit-user-select: text;
  user-select: text;
}

/* Results actions row */
.results-actions {
  display: none;
  gap: 10px;
  margin-top: 10px;
}
.results-actions.visible {
  display: flex;
}

/* Results loading state */
.results-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 13px;
  padding: 40px 0;
  color: var(--ink-mid);
  font-size: 13px;
}

/*  
   MISC
 */
.cam-note {
  font-size: 12px;
  color: var(--ink-light);
  text-align: center;
  margin-top: 8px;
}
.cam-hint {
  font-size: 14px;
  color: var(--ink-light);
  text-align: center;
  margin-top: 8px;
  padding: 2px;
}

/*  
   SECURITY OVERLAY (no session)
 */
.security-overlay {
  position: fixed;
  inset: 0;
  background: var(--surface);
  z-index: 99999;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-family: var(--font);
  padding: 24px;
  text-align: center;
}
.security-overlay__card {
  max-width: 440px;
  width: 100%;
  padding: 36px 32px;
  box-shadow: var(--shadow-lg);
  border-radius: var(--radius-lg);
  background: var(--white);
  border: 1px solid var(--border);
}
.security-overlay__icon {
  font-size: 44px;
  margin-bottom: 20px;
  line-height: 1;
}
.security-overlay__title {
  margin: 0 0 12px;
  color: var(--ink);
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.02em;
}
.security-overlay__body {
  margin: 0 0 28px;
  color: var(--ink-mid);
  font-size: 14px;
  line-height: 1.6;
  font-family: var(--mono);
}
.security-overlay__link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  padding: 14px;
  background: var(--ink);
  color: var(--white);
  text-decoration: none;
  border-radius: var(--radius-md);
  font-size: 15px;
  font-weight: 500;
  transition: background 0.2s ease;
}
.security-overlay__link:hover {
  background: var(--ink-mid);
}

/* 
   SUBMIT MODAL
 */
.submit-modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(24, 24, 27, 0.72);
  z-index: 10000;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 0;
  backdrop-filter: blur(4px);
  animation: backdropIn 0.22s ease both;
}

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

.submit-modal {
  background: var(--white);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  padding: 32px 24px 40px;
  width: 100%;
  max-width: 480px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  animation: modalSlideUp 0.28s cubic-bezier(0.22, 1, 0.36, 1) both;
}

@keyframes modalSlideUp {
  from {
    transform: translateY(100%);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

.submit-modal__icon {
  font-size: 48px;
  line-height: 1;
  margin-bottom: 4px;
}

.submit-modal__title {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.02em;
  text-align: center;
  color: var(--ink);
}

.submit-modal__message {
  font-size: 14px;
  color: var(--ink-mid);
  text-align: center;
  line-height: 1.6;
  font-family: var(--mono);
}

.submit-modal__countdown {
  font-size: 13px;
  font-weight: 700;
  color: var(--ink-light);
  font-family: var(--mono);
  letter-spacing: 0.04em;
}

.submit-modal__btn {
  margin-top: 8px;
  width: 100%;
}

/* Variant colours */
.submit-modal--success .submit-modal__title {
  color: var(--green);
}
.submit-modal--error .submit-modal__title {
  color: var(--red);
}
.submit-modal--warning .submit-modal__title {
  color: var(--amber);
}
