:root {
  color-scheme: dark;
  --bg: #090c10;
  --surface: #171c22;
  --panel: rgba(14, 18, 23, 0.88);
  --line: rgba(255, 255, 255, 0.15);
  --text: #f7f9fb;
  --muted: #aeb8c3;
  --good: #35d39a;
  --warn: #f5bf4f;
  --bad: #ff6b6b;
  --brand: #2583ed;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

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

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

button {
  cursor: pointer;
}

button:disabled {
  cursor: wait;
  opacity: 0.68;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

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

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

#camera,
.capture-layer,
.startup-panel,
.success-panel {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

#camera {
  object-fit: cover;
  transform: scaleX(-1);
  background: var(--bg);
}

.startup-panel,
.success-panel {
  z-index: 5;
  display: grid;
  place-items: center;
  padding: calc(24px + env(safe-area-inset-top)) 24px
    calc(24px + env(safe-area-inset-bottom));
  background: rgba(9, 12, 16, 0.96);
}

.startup-content {
  width: min(100%, 360px);
  text-align: center;
}

.camera-mark {
  position: relative;
  width: 64px;
  height: 48px;
  margin: 0 auto 24px;
  border: 2px solid var(--text);
  border-radius: 8px;
}

.camera-mark::before {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 18px;
  height: 18px;
  border: 2px solid var(--good);
  border-radius: 50%;
  transform: translate(-50%, -50%);
}

.camera-mark::after {
  content: "";
  position: absolute;
  top: -8px;
  left: 9px;
  width: 18px;
  height: 7px;
  border: 2px solid var(--text);
  border-bottom: 0;
  border-radius: 4px 4px 0 0;
}

.startup-content h1,
.success-panel h2 {
  margin: 0;
  font-size: 24px;
  line-height: 1.3;
  letter-spacing: 0;
}

#startupMessage,
.success-panel p {
  margin: 10px auto 24px;
  color: var(--muted);
  font-size: 15px;
  line-height: 1.6;
}

.startup-status {
  margin-bottom: 20px;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.state-row {
  display: grid;
  grid-template-columns: 18px 1fr auto;
  align-items: center;
  gap: 10px;
  min-height: 48px;
  color: var(--muted);
  text-align: left;
  font-size: 14px;
}

.state-row + .state-row {
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.state-row strong {
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
}

.state-icon {
  position: relative;
  width: 12px;
  height: 12px;
  border: 2px solid var(--muted);
  border-radius: 50%;
}

.state-row.pending .state-icon {
  border-color: var(--warn);
  border-right-color: transparent;
  animation: spin 0.8s linear infinite;
}

.state-row.ok .state-icon {
  border-color: var(--good);
  background: var(--good);
}

.state-row.error .state-icon {
  border-color: var(--bad);
  background: var(--bad);
}

.primary-button,
.secondary-button,
.primary-link {
  display: inline-grid;
  min-height: 46px;
  place-items: center;
  border-radius: 6px;
  padding: 0 20px;
  border: 0;
  font-weight: 650;
  text-decoration: none;
}

.startup-content > .primary-button,
.startup-content > .primary-link {
  width: 100%;
}

.primary-button,
.primary-link {
  background: var(--brand);
  color: #fff;
}

.secondary-button {
  border: 1px solid var(--line);
  background: transparent;
  color: var(--text);
}

.privacy-note {
  margin: 14px 0 0;
  color: #7f8a96;
  font-size: 12px;
}

.capture-layer {
  z-index: 2;
}

.scan-mask {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: none;
}

.face-guide {
  position: absolute;
  left: 50%;
  top: 43%;
  width: min(72vw, 320px);
  max-height: 52vh;
  aspect-ratio: 0.78;
  transform: translate(-50%, -50%);
  border: 2px solid rgba(255, 255, 255, 0.58);
  border-radius: 50%;
  pointer-events: none;
  transition: border-color 160ms ease, box-shadow 160ms ease;
}

.camera-stage.ready .face-guide {
  box-shadow: 0 0 0 1px rgba(53, 211, 154, 0.28);
}

.top-bar {
  position: absolute;
  top: calc(16px + env(safe-area-inset-top));
  left: 16px;
  right: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.privacy-badge {
  padding: 6px 9px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.42);
  color: rgba(255, 255, 255, 0.8);
  font-size: 12px;
}

.icon-button {
  width: 42px;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.42);
  color: var(--text);
  font-size: 22px;
  line-height: 1;
}

.status-title {
  position: absolute;
  left: 50%;
  bottom: calc(100% + 14px);
  width: min(calc(100vw - 32px), 420px);
  min-height: 24px;
  transform: translateX(-50%);
  color: #fff;
  font-size: 16px;
  font-weight: 650;
  line-height: 1.4;
  text-align: center;
  text-shadow: 0 1px 5px rgba(0, 0, 0, 0.9);
  white-space: nowrap;
}

.state-row.ok .state-icon::after {
  content: "";
  position: absolute;
  left: 3px;
  top: 0;
  width: 3px;
  height: 6px;
  border: solid #06140f;
  border-width: 0 1.5px 1.5px 0;
  transform: rotate(45deg);
}

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

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

.success-panel {
  text-align: center;
}

.success-icon {
  display: grid;
  width: 58px;
  height: 58px;
  margin: 0 auto 18px;
  place-items: center;
  border-radius: 50%;
  background: var(--good);
  color: #07130f;
  font-size: 30px;
  font-weight: 800;
}

.consent-dialog,
.confirm-dialog {
  width: min(92vw, 390px);
  max-height: calc(100dvh - 32px);
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
}

.consent-dialog::backdrop,
.confirm-dialog::backdrop {
  background: rgba(0, 0, 0, 0.72);
  backdrop-filter: blur(3px);
}

.consent-card,
.confirm-card {
  margin: 0;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.consent-card h2 {
  margin: 0 0 14px;
  font-size: 19px;
  line-height: 1.35;
  letter-spacing: 0;
}

.consent-copy {
  max-height: min(52dvh, 350px);
  overflow-y: auto;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.7;
}

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

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

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

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

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

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

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

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

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

.consent-actions {
  grid-template-columns: minmax(0, 0.85fr) minmax(0, 1.15fr);
}

.dialog-heading h2 {
  margin: 0;
  font-size: 19px;
  line-height: 1.35;
  letter-spacing: 0;
}

.confirm-card .dialog-heading {
  margin-bottom: 16px;
}

#cropPreview {
  display: block;
  width: min(100%, 28dvh, 210px);
  height: auto;
  margin: 0 auto;
  aspect-ratio: 4 / 5;
  object-fit: contain;
  border-radius: 6px;
  background: #0b0d12;
}

.confirm-guidance,
.confirm-error {
  margin: 10px 0 0;
  font-size: 13px;
  line-height: 1.5;
  text-align: center;
}

.confirm-guidance {
  color: var(--muted);
}

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

.dialog-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 16px;
}

@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-radius: 8px;
  }
}

@media (max-height: 620px) {
  .startup-content h1 {
    font-size: 21px;
  }

  .camera-mark {
    margin-bottom: 16px;
  }

  #startupMessage {
    margin-bottom: 14px;
  }

  .state-row {
    min-height: 42px;
  }

  .face-guide {
    width: min(60vw, 260px);
  }
}

@media (max-width: 340px) {
  .consent-check {
    font-size: 12px;
  }
}

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