: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,
a {
  font: inherit;
  -webkit-tap-highlight-color: transparent;
}

button { cursor: pointer; }

button:disabled {
  cursor: not-allowed;
  opacity: 0.58;
}

.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: #0e141b;
}

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

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

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

.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(11, 16, 22, 0.98);
}

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

.camera-mark {
  display: grid;
  width: 56px;
  height: 56px;
  margin: 0 auto 20px;
  place-items: center;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--brand-strong);
}

.camera-mark svg { width: 28px; height: 28px; }

.startup-content h1,
.success-panel h2 {
  margin: 0;
  font-size: 24px;
  line-height: 1.35;
  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 minmax(0, 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 800ms linear infinite;
}

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

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

.primary-button,
.secondary-button,
.primary-link {
  display: inline-grid;
  min-height: 46px;
  padding: 0 18px;
  place-items: center;
  border-radius: 6px;
  font-weight: 650;
  text-decoration: none;
  transition: transform 150ms ease, border-color 150ms ease, background 150ms ease;
}

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

.primary-button,
.primary-link {
  border: 1px solid transparent;
  background: var(--brand);
  color: #06140f;
}

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

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

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

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

.face-guide {
  position: absolute;
  left: 50%;
  top: 43%;
  width: min(72vw, 300px, 42dvh);
  aspect-ratio: 4 / 5;
  transform: 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;
}

.camera-stage.ready .face-guide {
  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;
  transform: translateX(-50%);
  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;
  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;
  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,
.primary-link:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

.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(--brand);
  color: #07140f;
  font-size: 28px;
  font-weight: 800;
}

.success-actions {
  display: grid;
  width: min(100%, 340px);
  margin: 0 auto;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.consent-dialog,
.confirm-dialog {
  width: min(92vw, 400px);
  max-height: calc(100dvh - 32px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--text);
}

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

.consent-card,
.confirm-card {
  max-height: inherit;
  margin: 0;
  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);
}

.consent-card h2,
.dialog-heading h2 {
  margin: 0;
  font-size: 20px;
  font-weight: 700;
  line-height: 1.35;
}

.consent-card h2 { margin-bottom: 14px; }

.consent-copy {
  max-height: min(46dvh, 320px);
  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-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;
  background: none;
  color: var(--text);
  font-size: 13px;
  line-height: 1.4;
  cursor: pointer;
}

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

.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-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.58;
}

.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: 1px solid var(--line);
  border-radius: 6px;
  background: var(--stage);
}

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

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

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

@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,
  .primary-link: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,
.primary-link: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) {
  .startup-panel,
  .success-panel { padding-top: 16px; padding-bottom: 16px; }
  .camera-mark { width: 48px; height: 48px; margin-bottom: 14px; }
  .startup-content h1 { font-size: 21px; }
  #startupMessage { margin-bottom: 14px; }
  .state-row { min-height: 42px; }
  .face-guide { width: min(62vw, 250px, 40dvh); }
  .consent-card,
  .confirm-card { padding: 16px; }
  .consent-copy { max-height: 34dvh; }
}

@media (max-width: 340px) {
  .consent-card,
  .confirm-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;
  }
}
