:root {
  color-scheme: dark;
  --bg: #0b1016;
  --stage: #070b10;
  --surface: #171d25;
  --surface-hover: #1d2530;
  --line: rgba(255, 255, 255, 0.14);
  --line-strong: rgba(255, 255, 255, 0.24);
  --text: #f5f7fa;
  --muted: #a8b1bc;
  --brand: #38c994;
  --brand-strong: #52dda9;
  --warn: #e7b84b;
  --bad: #ef7171;
  --focus: rgba(56, 201, 148, 0.42);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html,
body {
  width: 100%;
  min-width: 320px;
  height: 100%;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button {
  font: inherit;
  -webkit-tap-highlight-color: transparent;
}

.capture-shell {
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
  background: #0e141b;
}

.camera-stage {
  position: relative;
  width: min(100vw, 520px);
  height: 100dvh;
  min-height: 480px;
  overflow: hidden;
  background: var(--stage);
}

#camera {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scaleX(-1);
  background: var(--stage);
}

.scan-mask {
  position: absolute;
  z-index: 3;
  inset: 0;
  pointer-events: none;
}

.face-guide {
  position: absolute;
  left: 50%;
  top: 43%;
  width: min(72vw, 300px, 42dvh);
  aspect-ratio: 4 / 5;
  translate: -50% -50%;
  border: 2px solid rgba(255, 255, 255, 0.58);
  border-radius: 50%;
  pointer-events: none;
  transition: border-color 180ms ease, box-shadow 180ms ease;
}

.face-guide.ready {
  border-color: rgba(82, 221, 169, 0.9);
  box-shadow: 0 0 0 1px rgba(56, 201, 148, 0.2);
}

.status-title {
  position: absolute;
  left: 50%;
  bottom: calc(100% + 14px);
  width: min(calc(100vw - 40px), 380px);
  min-height: 24px;
  translate: -50% 0;
  color: #fff;
  font-size: 16px;
  font-weight: 650;
  line-height: 1.4;
  text-align: center;
  text-shadow: 0 1px 6px rgba(0, 0, 0, 0.9);
}

.progress-track {
  position: absolute;
  top: calc(100% + 18px);
  left: 12%;
  right: 12%;
  height: 4px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.3);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.38);
}

.progress-fill {
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: var(--brand-strong);
  transition: width 100ms linear;
}

.top-bar {
  position: absolute;
  z-index: 5;
  top: calc(16px + env(safe-area-inset-top));
  left: 16px;
  right: 16px;
  display: flex;
  justify-content: flex-end;
}

.icon-button {
  display: grid;
  width: 44px;
  height: 44px;
  padding: 0;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 50%;
  background: rgba(12, 17, 23, 0.72);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.28), inset 0 1px 0 rgba(255, 255, 255, 0.1);
  color: #fff;
  cursor: pointer;
  backdrop-filter: blur(12px);
  transition: transform 150ms ease, border-color 150ms ease, background 150ms ease;
}

.icon-button svg { width: 21px; height: 21px; }
.icon-button:active { transform: scale(0.94); }

.icon-button:focus-visible,
.primary-button:focus-visible,
.secondary-button:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

.success-panel,
.recovery-panel {
  position: absolute;
  z-index: 12;
  inset: 0;
  display: grid;
  place-items: center;
  padding: calc(24px + env(safe-area-inset-top)) 24px calc(24px + env(safe-area-inset-bottom));
  background: rgba(11, 16, 22, 0.98);
  text-align: center;
}

.success-content,
.recovery-content { width: min(100%, 340px); }

.success-icon,
.recovery-icon {
  display: grid;
  width: 58px;
  height: 58px;
  margin: 0 auto 18px;
  place-items: center;
  border-radius: 50%;
  font-size: 28px;
  font-weight: 800;
}

.success-icon { background: var(--brand); color: #07140f; }
.recovery-icon { border: 1px solid rgba(239, 113, 113, 0.5); background: rgba(239, 113, 113, 0.12); color: var(--bad); }

.success-content h1,
.recovery-content h1 {
  margin: 0;
  font-size: 24px;
  line-height: 1.35;
}

.success-content p,
.recovery-content p {
  margin: 10px 0 24px;
  color: var(--muted);
  font-size: 15px;
  line-height: 1.6;
}

.success-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.recovery-content .primary-button { width: 100%; }

.modal[hidden] { display: none; }

.modal {
  position: fixed;
  z-index: 20;
  inset: 0;
  display: grid;
  place-items: center;
  padding: calc(16px + env(safe-area-inset-top)) 16px calc(16px + env(safe-area-inset-bottom));
  overflow-y: auto;
  background: rgba(0, 0, 0, 0.74);
  backdrop-filter: blur(8px);
}

.consent-modal { z-index: 30; }
.preparation-modal { z-index: 29; }

.modal-card {
  width: min(100%, 400px);
  max-height: calc(100dvh - 32px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
  overflow-y: auto;
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 24px 72px rgba(0, 0, 0, 0.48);
}

.modal-card h2 {
  margin: 0;
  font-size: 20px;
  font-weight: 700;
  line-height: 1.35;
}

.consent-copy {
  max-height: min(46dvh, 320px);
  margin-top: 14px;
  overflow-y: auto;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.7;
  scrollbar-width: thin;
}

.consent-copy p { margin: 0 0 10px; }
.consent-copy p:last-child { margin-bottom: 0; }

.consent-countdown {
  min-height: 20px;
  margin: 14px 0 8px;
  color: var(--warn);
  font-size: 13px;
  line-height: 1.5;
  font-variant-numeric: tabular-nums;
}

.consent-check {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 24px;
  color: var(--text);
  font-size: 13px;
  line-height: 1.4;
  cursor: pointer;
}

.consent-check span { min-width: 0; }

.consent-check input {
  width: 17px;
  height: 17px;
  flex: 0 0 auto;
  margin: 0;
  accent-color: var(--brand);
}

.consent-check.is-disabled {
  color: var(--muted);
  cursor: not-allowed;
  opacity: 0.72;
}

.consent-check.is-shaking { animation: consent-shake 360ms ease-in-out; }

.consent-actions .primary-button[aria-disabled="true"] {
  cursor: not-allowed;
  opacity: 0.55;
}

.consent-actions,
.dialog-actions {
  display: grid;
  grid-template-columns: minmax(0, 0.85fr) minmax(0, 1.15fr);
  gap: 10px;
  margin-top: 18px;
}

.preparation-summary {
  margin: 10px 0 18px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.6;
}

.preparation-list { border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }

.preparation-item {
  display: grid;
  grid-template-columns: 22px minmax(0, 1fr);
  gap: 12px;
  align-items: center;
  min-height: 64px;
  padding: 10px 0;
}

.preparation-item + .preparation-item { border-top: 1px solid rgba(255, 255, 255, 0.08); }
.preparation-item strong,
.preparation-item div > span { display: block; }
.preparation-item strong { margin-bottom: 4px; font-size: 14px; }

.preparation-item div > span {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.preparation-indicator {
  display: grid;
  width: 20px;
  height: 20px;
  place-items: center;
  border: 2px solid rgba(168, 177, 188, 0.32);
  border-radius: 50%;
}

.preparation-item.is-loading .preparation-indicator {
  border-color: rgba(56, 201, 148, 0.22);
  border-top-color: var(--brand);
  animation: spin 800ms linear infinite;
}

.preparation-item.is-ready .preparation-indicator { border-color: var(--brand); background: var(--brand); }
.preparation-item.is-ready .preparation-indicator::after { content: "✓"; color: #07140f; font-size: 12px; font-weight: 800; }
.preparation-item.is-error .preparation-indicator { border-color: var(--bad); }
.preparation-item.is-error .preparation-indicator::after { content: "!"; color: var(--bad); font-size: 12px; font-weight: 800; }

.preparation-retry { width: 100%; margin-top: 16px; }
.dialog-heading { margin-bottom: 16px; }

#cropPreview {
  display: block;
  width: min(100%, 32dvh, 240px);
  height: auto;
  margin: 0 auto;
  aspect-ratio: 4 / 5;
  object-fit: contain;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--stage);
}

.confirm-guidance,
.confirm-hint {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
  text-align: center;
}

.confirm-hint { color: var(--bad); }

.primary-button,
.secondary-button {
  min-height: 46px;
  padding: 0 18px;
  border-radius: 6px;
  font-weight: 650;
  cursor: pointer;
  transition: transform 150ms ease, border-color 150ms ease, background 150ms ease;
}

.primary-button { border: 1px solid transparent; background: var(--brand); color: #06140f; }
.secondary-button { border: 1px solid var(--line); background: transparent; color: var(--text); }
button:disabled { cursor: not-allowed; opacity: 0.55; }

@media (hover: hover) {
  .icon-button:hover { border-color: rgba(56, 201, 148, 0.62); background: rgba(24, 36, 43, 0.88); }
  .primary-button:not(:disabled):hover { background: var(--brand-strong); }
  .secondary-button:not(:disabled):hover { border-color: var(--line-strong); background: var(--surface-hover); }
}

.primary-button:not(:disabled):active,
.secondary-button:not(:disabled):active { transform: scale(0.98); }

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

@keyframes consent-shake {
  0%, 100% { transform: translateX(0); }
  20%, 60% { transform: translateX(-6px); }
  40%, 80% { transform: translateX(6px); }
}

@media (min-width: 700px) {
  .capture-shell { padding: 24px; }
  .camera-stage {
    height: min(860px, calc(100dvh - 48px));
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    box-shadow: 0 32px 96px rgba(0, 0, 0, 0.34);
  }
}

@media (max-height: 620px) {
  .modal { align-items: start; padding-top: 12px; padding-bottom: 12px; }
  .modal-card { max-height: calc(100dvh - 24px); padding: 16px; }
  .consent-copy { max-height: 34dvh; }
  .face-guide { width: min(62vw, 250px, 40dvh); }
}

@media (max-width: 340px) {
  .modal { padding-left: 10px; padding-right: 10px; }
  .modal-card { padding: 16px; }
  .consent-check { font-size: 12px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
