:root {
  --bg: #0f172a;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --text: #0f172a;
  --muted: #64748b;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --secondary: #e2e8f0;
  --secondary-hover: #cbd5e1;
  --success: #10b981;
  --error: #ef4444;
  --warn: #f59e0b;
  --border: #e2e8f0;
  --radius: 12px;
  --shadow: 0 4px 16px rgba(15, 23, 42, 0.08);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  background: linear-gradient(135deg, #1e3a8a 0%, #0f172a 100%);
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

.page {
  max-width: 720px;
  margin: 0 auto;
  padding: 24px 16px 48px;
}

.topbar {
  text-align: center;
  margin-bottom: 24px;
  color: #fff;
}

.topbar h1 {
  font-size: 1.5rem;
  margin: 0 0 16px;
  font-weight: 600;
}

.steps {
  list-style: none;
  display: flex;
  justify-content: center;
  gap: 8px;
  padding: 0;
  margin: 0;
  font-size: 0.85rem;
  flex-wrap: wrap;
}

.step {
  padding: 6px 14px;
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.1);
  color: rgba(255, 255, 255, 0.6);
  transition: background 0.2s, color 0.2s;
}

.step.active {
  background: rgba(255, 255, 255, 0.95);
  color: var(--primary);
  font-weight: 600;
}

.step.done {
  background: rgba(16, 185, 129, 0.2);
  color: #6ee7b7;
}

.section {
  display: none;
}

.section.visible {
  display: block;
}

.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 28px;
  box-shadow: var(--shadow);
}

.field {
  margin-bottom: 16px;
}

.field label {
  display: block;
  font-size: 0.875rem;
  font-weight: 500;
  margin-bottom: 6px;
  color: var(--text);
}

.req {
  color: var(--error);
}

.field input,
.field select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.95rem;
  font-family: inherit;
  transition: border-color 0.15s, box-shadow 0.15s;
  background: var(--surface);
}

.field input:focus,
.field select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.hint {
  display: block;
  margin-top: 4px;
  font-size: 0.75rem;
  color: var(--muted);
}

.row {
  display: flex;
  gap: 12px;
}

.flex-1 { flex: 1; }

.consent {
  background: var(--surface-2);
  padding: 14px;
  border-radius: 8px;
  margin: 16px 0;
}

.checkbox {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  font-size: 0.875rem;
  cursor: pointer;
  line-height: 1.4;
}

.checkbox input[type="checkbox"] {
  margin-top: 2px;
  width: 16px;
  height: 16px;
  cursor: pointer;
}

.consent a {
  color: var(--primary);
  text-decoration: none;
}

.consent a:hover {
  text-decoration: underline;
}

.actions {
  display: flex;
  gap: 12px;
  justify-content: flex-end;
  margin-top: 8px;
  flex-wrap: wrap;
}

button {
  padding: 10px 20px;
  border: none;
  border-radius: 8px;
  font-size: 0.95rem;
  font-weight: 500;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.15s, transform 0.05s;
}

button:active:not(:disabled) {
  transform: translateY(1px);
}

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

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

button.primary:hover:not(:disabled) {
  background: var(--primary-hover);
}

button.secondary {
  background: var(--secondary);
  color: var(--text);
}

button.secondary:hover:not(:disabled) {
  background: var(--secondary-hover);
}

.error {
  background: #fef2f2;
  color: var(--error);
  border: 1px solid #fecaca;
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 0.875rem;
  margin-bottom: 12px;
}

/* ============ Photo capture ============ */

.photo-card .instruction {
  font-size: 0.9rem;
  color: var(--muted);
  margin: 0 0 14px;
  line-height: 1.5;
}

.pose {
  display: inline-block;
  background: var(--surface-2);
  padding: 2px 8px;
  border-radius: 4px;
  font-weight: 500;
  color: var(--text);
}

.capture-area {
  display: flex;
  gap: 18px;
  align-items: flex-start;
  flex-wrap: wrap;
}

.video-wrap {
  position: relative;
  flex: 2;
  min-width: 280px;
  aspect-ratio: 4 / 3;
  background: #000;
  border-radius: var(--radius);
  overflow: hidden;
}

.video-wrap video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scaleX(-1); /* mirror để giống gương */
}

.oval-guide {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 55%;
  aspect-ratio: 3 / 4;
  border: 3px dashed rgba(255, 255, 255, 0.6);
  border-radius: 50%;
  pointer-events: none;
}

/* ===== Pose guide overlay ===== */

.pose-guide {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(0, 0, 0, 0.75);
  color: #fff;
  padding: 8px 14px;
  border-radius: 24px;
  font-size: 0.95rem;
  font-weight: 500;
  white-space: nowrap;
  max-width: calc(100% - 24px);
  z-index: 5;
  backdrop-filter: blur(6px);
}

.pose-guide[hidden] { display: none; }

.pose-step {
  background: var(--primary);
  color: #fff;
  padding: 2px 10px;
  border-radius: 12px;
  font-size: 0.8rem;
  font-weight: 700;
  flex-shrink: 0;
}

.pose-text {
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Mũi tên hướng — pulse để dễ thấy */
.pose-arrow {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  font-size: 5rem;
  font-weight: bold;
  color: #fff;
  text-shadow: 0 0 12px rgba(0, 0, 0, 0.8), 0 0 24px rgba(37, 99, 235, 0.6);
  line-height: 1;
  pointer-events: none;
  z-index: 4;
  animation: pulse-arrow 1.2s ease-in-out infinite;
}

.pose-arrow[hidden] { display: none; }

.pose-arrow-left  { left: 8px; }
.pose-arrow-right { right: 8px; }

@keyframes pulse-arrow {
  0%, 100% { opacity: 0.7; transform: translateY(-50%) scale(1); }
  50%      { opacity: 1;   transform: translateY(-50%) scale(1.15); }
}

.capture-hint {
  position: absolute;
  bottom: 12px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.7);
  color: #fff;
  padding: 6px 14px;
  border-radius: 16px;
  font-size: 0.8rem;
  white-space: nowrap;
  display: none;
  max-width: 90%;
  overflow: hidden;
  text-overflow: ellipsis;
}

.capture-hint.visible { display: block; }
.capture-hint.error { background: var(--error); }
.capture-hint.success { background: var(--success); }

.thumbs {
  display: flex;
  flex-direction: column;
  gap: 10px;
  flex: 1;
  min-width: 90px;
}

.thumb {
  aspect-ratio: 1 / 1;
  background: var(--surface-2);
  border: 2px dashed var(--border);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
}

.thumb span {
  font-size: 1.5rem;
  color: var(--muted);
  font-weight: 600;
}

.thumb.filled {
  border-style: solid;
  border-color: var(--success);
}

.thumb.filled span { display: none; }

.thumb img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* ============ Mobile-friendly photo step ============ */

@media (max-width: 720px) {
  .page { padding: 12px 0 0; }

  .topbar { padding: 0 12px; margin-bottom: 14px; }
  .topbar h1 { font-size: 1.2rem; margin-bottom: 10px; }
  .steps { font-size: 0.75rem; gap: 4px; }
  .step { padding: 4px 10px; }

  .card { border-radius: 0; padding: 16px 14px; }

  /* Photo step layout: cố định nút ở đáy màn hình */
  #section-photo.visible {
    display: flex;
    flex-direction: column;
    min-height: calc(100vh - 110px);
  }
  .photo-card {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding-bottom: 90px; /* chừa chỗ cho sticky action bar */
  }
  .photo-card .instruction {
    font-size: 0.82rem;
    margin-bottom: 10px;
  }

  .capture-area {
    flex-direction: column;
    gap: 10px;
    flex: 1;
  }

  .video-wrap {
    width: 100%;
    aspect-ratio: auto;
    height: 50vh;
    max-height: 420px;
    flex: 0 0 auto;
  }

  /* Thumbs: dải ngang ở dưới video */
  .thumbs {
    flex-direction: row;
    gap: 8px;
    width: 100%;
    min-width: 0;
  }
  .thumb {
    flex: 1;
    max-width: 80px;
  }

  /* Action bar dính đáy màn hình */
  .photo-card .actions {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: #fff;
    padding: 12px 14px calc(12px + env(safe-area-inset-bottom));
    margin: 0;
    border-top: 1px solid var(--border);
    box-shadow: 0 -2px 12px rgba(0, 0, 0, 0.08);
    justify-content: stretch;
    z-index: 50;
    gap: 8px;
  }
  .photo-card .actions button {
    flex: 1;
    padding: 14px 12px;
    font-size: 0.95rem;
  }
  /* Nút "Quay lại" nhỏ hơn */
  .photo-card .actions #btn-back {
    flex: 0 0 auto;
    padding: 14px 16px;
  }

  /* Pose guide trên mobile */
  .pose-guide {
    font-size: 0.85rem;
    padding: 6px 12px;
    top: 8px;
  }
  .pose-step { font-size: 0.7rem; padding: 2px 8px; }
  .pose-arrow { font-size: 3.5rem; }
  .pose-arrow-left  { left: 4px; }
  .pose-arrow-right { right: 4px; }
}

/* ============ Done ============ */

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

.success-icon {
  width: 64px;
  height: 64px;
  margin: 0 auto 16px;
  border-radius: 50%;
  background: var(--success);
  color: #fff;
  font-size: 2rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

.success-card h2 {
  margin: 0 0 12px;
  color: var(--success);
}

.member-code {
  background: var(--surface-2);
  padding: 16px;
  border-radius: 10px;
  margin: 20px 0;
  display: inline-block;
}

.member-code .label {
  display: block;
  font-size: 0.75rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 4px;
}

.member-code .code {
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--primary);
  font-family: "SF Mono", "Monaco", "Courier New", monospace;
  letter-spacing: 0.05em;
}

.note {
  color: var(--muted);
  font-size: 0.875rem;
  margin: 12px 0 24px;
}

/* ============ Modal ============ */

.modal {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 16px;
}

.modal[hidden] { display: none; }

.modal-content {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 24px;
  max-width: 420px;
  width: 100%;
}

.modal-content h3 {
  margin: 0 0 12px;
}

/* ============ Policy page ============ */

.policy-page {
  background: #fff;
}

.policy-content {
  max-width: 720px;
  margin: 0 auto;
  padding: 32px 20px;
  line-height: 1.7;
  color: var(--text);
}

.policy-content h1 { color: var(--primary); }
.policy-content h2 { margin-top: 32px; }
