:root {
  --bg: #0b1020;
  --bg2: #141b30;
  --card: #1a2238;
  --fg: #eef2ff;
  --muted: #94a3c4;
  --accent: #4f7cff;
  --accent-2: #6ea0ff;
  --danger: #ff6b6b;
  --ok: #46d39a;
  --radius: 16px;
}

* { box-sizing: border-box; }

/* The hidden attribute must always win over display rules below (e.g. .modal). */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, system-ui, sans-serif;
  min-height: 100%;
}

body {
  min-height: 100dvh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

#app { min-height: 100dvh; }

.view { display: none; min-height: 100dvh; flex-direction: column; }
.view.active { display: flex; }

#view-loading, #view-setup, #view-login {
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 24px;
  width: 100%;
  max-width: 420px;
  box-shadow: 0 10px 40px rgba(0,0,0,.4);
}

h1 { font-size: 1.5rem; margin: 0 0 4px; }
h2 { font-size: 1.2rem; margin: 0 0 8px; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }

form { display: flex; flex-direction: column; gap: 14px; margin-top: 16px; }
label { display: flex; flex-direction: column; gap: 6px; font-size: .9rem; color: var(--muted); }
input {
  background: var(--bg2);
  border: 1px solid #2a3554;
  border-radius: 10px;
  padding: 12px 14px;
  color: var(--fg);
  font-size: 1rem;
}
input:focus { outline: 2px solid var(--accent); border-color: var(--accent); }

button {
  border: none;
  border-radius: 12px;
  padding: 14px 16px;
  font-size: 1rem;
  font-weight: 600;
  background: var(--accent);
  color: white;
  cursor: pointer;
  transition: filter .15s ease;
}
button:hover { filter: brightness(1.08); }
button:disabled { opacity: .5; cursor: not-allowed; }
button.secondary { background: var(--bg2); border: 1px solid #2a3554; color: var(--fg); }
button.link { background: none; color: var(--accent-2); padding: 8px; font-weight: 500; }

.passkey-btn { width: 100%; margin-top: 16px; background: linear-gradient(135deg, var(--accent), #7b5cff); }

.divider { display: flex; align-items: center; gap: 10px; color: var(--muted); margin: 16px 0 0; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: #2a3554; }

.error { color: var(--danger); min-height: 1.2em; margin-top: 12px; font-size: .9rem; }

.spinner {
  width: 42px; height: 42px;
  border: 4px solid #2a3554;
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 18px;
  background: var(--bg2);
  position: sticky; top: 0;
}
.brand { font-weight: 700; letter-spacing: .3px; }

#view-vault, #view-upload { padding-bottom: 32px; }
#view-vault .card, #view-upload .card { max-width: 480px; margin: 18px auto; }

.id-card {
  background: linear-gradient(160deg, #1f2a4a, #141b30);
  border-radius: 20px;
  padding: 22px;
  max-width: 460px;
  margin: 22px auto 8px;
  box-shadow: 0 12px 36px rgba(0,0,0,.45);
}
.id-photo-wrap {
  width: 140px; height: 170px;
  margin: 0 auto 18px;
  border-radius: 14px;
  overflow: hidden;
  background: #0d1326;
  border: 1px solid #2a3554;
}
#id-photo { width: 100%; height: 100%; object-fit: cover; display: block; }
.id-fields { display: flex; flex-direction: column; gap: 12px; }
.field { display: flex; justify-content: space-between; align-items: baseline; border-bottom: 1px solid #232f4e; padding-bottom: 10px; }
.field .k { color: var(--muted); font-size: .85rem; }
.field .v { font-size: 1.15rem; font-weight: 600; text-align: right; }
#btn-show-full { width: 100%; margin-top: 20px; }

.vault-actions { display: flex; flex-direction: column; gap: 8px; align-items: center; max-width: 460px; margin: 0 auto; }
.vault-actions button { width: 100%; }

.file-label {
  display: block;
  border: 2px dashed #2a3554;
  border-radius: 12px;
  padding: 22px;
  text-align: center;
  color: var(--muted);
  cursor: pointer;
}
.file-label input { display: none; }

.crop-canvas-wrap { position: relative; touch-action: none; margin: 8px 0; }
#crop-canvas { width: 100%; border-radius: 10px; display: block; background: #0d1326; }
#crop-box { position: absolute; border: 2px solid var(--accent-2); background: rgba(79,124,255,.18); pointer-events: none; }
.crop-buttons { display: flex; justify-content: flex-end; }

.modal {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.92);
  display: flex; align-items: center; justify-content: center;
  z-index: 50; padding: 16px;
}
.modal-inner { position: relative; max-width: 100%; max-height: 100%; }
#full-img { max-width: 100%; max-height: 90dvh; border-radius: 12px; }
.modal-close {
  position: absolute; top: -8px; right: -8px;
  width: 40px; height: 40px; border-radius: 50%;
  background: var(--card); font-size: 1.4rem; line-height: 1; padding: 0;
}
