/* ============================================================
   BASE
   ============================================================ */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

:root {
  --brand:      #1e3a5f;   /* deep navy */
  --brand-mid:  #2563eb;   /* blue */
  --brand-lite: #3b82f6;
  --accent:     #f59e0b;   /* amber */
  --green:      #16a34a;
  --red:        #dc2626;
  --bg:         #f0f4f8;
  --card:       #ffffff;
  --text:       #1e293b;
  --muted:      #64748b;
  --radius:     18px;
  --shadow:     0 8px 32px rgba(30,58,95,.15);
}

html, body {
  height: 100%;
  overflow: hidden;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}

/* ============================================================
   SCREENS (single-page router)
   ============================================================ */
.screen {
  display: none;
  height: 100dvh;          /* dynamic viewport height — safe on iOS */
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.screen.active {
  display: flex;
  flex-direction: column;
}

/* ============================================================
   WELCOME SCREEN
   ============================================================ */
.welcome-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  padding: 48px 24px 32px;
  background: linear-gradient(160deg, var(--brand) 0%, #1e40af 100%);
  min-height: 100dvh;
}

.welcome-logo {
  display: flex;
  align-items: center;
  gap: 14px;
}

.logo-mark {
  width: 56px;
  height: 56px;
  background: var(--accent);
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
  font-weight: 900;
  color: var(--brand);
  flex-shrink: 0;
}

.logo-text {
  display: flex;
  flex-direction: column;
}

.logo-brand {
  font-size: 1.5rem;
  font-weight: 800;
  color: #fff;
  letter-spacing: 2px;
}

.logo-sub {
  font-size: 0.75rem;
  color: rgba(255,255,255,.65);
  letter-spacing: 1.5px;
  text-transform: uppercase;
}

.welcome-body {
  text-align: center;
  width: 100%;
  max-width: 480px;
}

.welcome-title {
  font-size: 3rem;
  font-weight: 800;
  color: #fff;
  margin-bottom: 10px;
  letter-spacing: -1px;
}

.welcome-hint {
  color: rgba(255,255,255,.7);
  font-size: 1.05rem;
  margin-bottom: 40px;
}

.choice-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.choice-card {
  background: rgba(255,255,255,.12);
  border: 1.5px solid rgba(255,255,255,.2);
  border-radius: var(--radius);
  padding: 28px 16px;
  cursor: pointer;
  text-align: center;
  color: #fff;
  transition: all .2s ease;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.choice-card:active {
  transform: scale(.96);
  background: rgba(255,255,255,.22);
}

.choice-icon {
  font-size: 2.4rem;
  margin-bottom: 12px;
}

.choice-label {
  font-size: 1.05rem;
  font-weight: 700;
  margin-bottom: 6px;
}

.choice-desc {
  font-size: 0.78rem;
  color: rgba(255,255,255,.65);
  line-height: 1.4;
}

.welcome-footer {
  color: rgba(255,255,255,.35);
  font-size: 0.78rem;
}

/* ============================================================
   INNER PAGES (staff / face / qr / guest)
   ============================================================ */
.page-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 20px 20px 32px;
  max-width: 600px;
  width: 100%;
  margin: 0 auto;
}

.coming-soon-wrap {
  align-items: center;
  justify-content: center;
}

.back-btn {
  align-self: flex-start;
  background: none;
  border: none;
  color: var(--brand-mid);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  padding: 6px 0;
  margin-bottom: 18px;
}

.page-title {
  font-size: 1.8rem;
  font-weight: 800;
  color: var(--brand);
  margin-bottom: 6px;
}

.page-hint {
  color: var(--muted);
  font-size: 0.95rem;
  margin-bottom: 28px;
}

/* ============================================================
   STAFF METHOD CHOICE
   ============================================================ */
.method-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-top: 8px;
}

.method-card {
  background: var(--card);
  border: 2px solid #e2e8f0;
  border-radius: var(--radius);
  padding: 32px 20px;
  cursor: pointer;
  text-align: center;
  color: var(--text);
  transition: all .2s ease;
  box-shadow: var(--shadow);
}

.method-card:active {
  transform: scale(.96);
  border-color: var(--brand-mid);
}

.method-icon {
  font-size: 2.6rem;
  margin-bottom: 14px;
}

.method-label {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--brand);
  margin-bottom: 6px;
}

.method-desc {
  font-size: 0.78rem;
  color: var(--muted);
  line-height: 1.4;
}

/* ============================================================
   CAMERA / VIDEO
   ============================================================ */
.video-container {
  position: relative;
  width: 100%;
  border-radius: var(--radius);
  overflow: hidden;
  background: #000;
  box-shadow: var(--shadow);
  margin-bottom: 20px;
  aspect-ratio: 4/3;
}

.qr-video-container {
  aspect-ratio: 1/1;
}

video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

/* Face detection overlays */
.detection-overlay {
  position: absolute;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0,0,0,.75);
  padding: 14px 24px;
  border-radius: 12px;
  text-align: center;
  min-width: 220px;
}

.detection-overlay.hidden { display: none; }

.confidence-bar {
  width: 180px;
  height: 6px;
  background: rgba(255,255,255,.3);
  border-radius: 3px;
  overflow: hidden;
  margin: 0 auto 8px;
}

.confidence-progress {
  height: 100%;
  background: linear-gradient(90deg, #4ade80, #22c55e);
  width: 0%;
  transition: width .1s ease;
}

.detection-text  { color: #fff; font-size: .85rem; margin-bottom: 4px; }
.live-confidence { color: #fbbf24; font-size: .8rem; font-weight: 600; }

.confidence-indicator {
  position: absolute;
  top: 10px;
  right: 10px;
  background: rgba(0,0,0,.7);
  color: #fff;
  padding: 6px 10px;
  border-radius: 8px;
  font-size: .8rem;
  font-weight: 700;
  display: none;
  z-index: 10;
}

.confidence-indicator.visible  { display: block; }
.confidence-indicator.excellent { color: #22c55e; }
.confidence-indicator.good      { color: #4ade80; }
.confidence-indicator.fair      { color: #fbbf24; }
.confidence-indicator.low       { color: #f87171; }

/* QR target frame */
.qr-target {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 55%;
  aspect-ratio: 1/1;
  pointer-events: none;
}

.qr-corner {
  position: absolute;
  width: 24px;
  height: 24px;
  border-color: #fff;
  border-style: solid;
}

.qr-corner.tl { top: 0; left: 0;  border-width: 3px 0 0 3px; border-radius: 4px 0 0 0; }
.qr-corner.tr { top: 0; right: 0; border-width: 3px 3px 0 0; border-radius: 0 4px 0 0; }
.qr-corner.bl { bottom: 0; left: 0;  border-width: 0 0 3px 3px; border-radius: 0 0 0 4px; }
.qr-corner.br { bottom: 0; right: 0; border-width: 0 3px 3px 0; border-radius: 0 0 4px 0; }

.qr-scan-line {
  position: absolute;
  left: 22.5%;
  width: 55%;
  height: 2px;
  background: rgba(37,99,235,.8);
  top: 20%;
  animation: qrScan 2s ease-in-out infinite;
  box-shadow: 0 0 6px rgba(37,99,235,.6);
}

@keyframes qrScan {
  0%, 100% { top: 20%; }
  50%       { top: 80%; }
}

/* ============================================================
   RESULT PANELS
   ============================================================ */
.result-panel {
  background: var(--card);
  border-radius: var(--radius);
  padding: 28px 24px;
  text-align: center;
  box-shadow: var(--shadow);
  border: 2px solid #e2e8f0;
}

.result-panel.hidden { display: none; }

.result-panel.unknown {
  border-color: #fca5a5;
  background: #fff5f5;
}

.result-avatar {
  font-size: 2.8rem;
  margin-bottom: 10px;
}

.result-name {
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--brand);
  margin-bottom: 4px;
}

.result-meta {
  color: var(--muted);
  font-size: 0.9rem;
  margin-bottom: 4px;
}

.result-conf {
  color: var(--green);
  font-weight: 600;
  font-size: 0.9rem;
  margin-bottom: 20px;
}

.action-buttons {
  display: flex;
  gap: 12px;
  justify-content: center;
  margin-bottom: 14px;
}

.action-btn {
  flex: 1;
  max-width: 180px;
  padding: 16px 24px;
  font-size: 1rem;
  font-weight: 700;
  border: none;
  border-radius: 12px;
  cursor: pointer;
  transition: all .2s ease;
}

.action-btn:active { transform: scale(.96); }

.signin-btn {
  background: linear-gradient(135deg, #22c55e, #16a34a);
  color: #fff;
}

.signout-btn {
  background: linear-gradient(135deg, #f87171, #dc2626);
  color: #fff;
}

.timeout-text {
  color: var(--muted);
  font-size: 0.85rem;
}

#countdown, #qrCountdown {
  font-weight: 700;
  color: var(--red);
}

/* ============================================================
   QR MANUAL FALLBACK
   ============================================================ */
.qr-hint-manual {
  color: var(--muted);
  font-size: 0.85rem;
  text-align: center;
  margin-bottom: 16px;
}

.link-btn {
  background: none;
  border: none;
  color: var(--brand-mid);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: underline;
}

.manual-entry {
  display: flex;
  gap: 10px;
  margin-bottom: 16px;
}

.manual-entry.hidden { display: none; }

.manual-input {
  flex: 1;
  padding: 14px;
  border: 2px solid #e2e8f0;
  border-radius: 10px;
  font-size: 1rem;
  font-family: monospace;
  letter-spacing: 1px;
}

.manual-input:focus {
  outline: none;
  border-color: var(--brand-mid);
}

.manual-entry .action-btn {
  flex: 0 0 auto;
  max-width: none;
  background: var(--brand);
  color: #fff;
  padding: 14px 20px;
}

/* ============================================================
   COMING SOON
   ============================================================ */
.coming-soon-content {
  text-align: center;
  padding: 40px 20px;
}

.coming-soon-icon {
  font-size: 4rem;
  margin-bottom: 20px;
}

.coming-soon-content h2 {
  font-size: 2rem;
  font-weight: 800;
  color: var(--brand);
  margin-bottom: 12px;
}

.coming-soon-content p {
  color: var(--muted);
  font-size: 1rem;
}

/* ============================================================
   TOAST MESSAGES
   ============================================================ */
.message-box {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: #fff;
  padding: 16px 24px;
  border-radius: 12px;
  box-shadow: 0 10px 30px rgba(0,0,0,.25);
  z-index: 9999;
  max-width: 90%;
  font-weight: 600;
  animation: slideDown .3s ease;
}

.message-box.hidden { display: none; }
.message-box.success { border-left: 5px solid #22c55e; }
.message-box.error   { border-left: 5px solid #dc2626; }
.message-box.info    { border-left: 5px solid #3b82f6; }

@keyframes slideDown {
  from { transform: translate(-50%, -100%); opacity: 0; }
  to   { transform: translateX(-50%);       opacity: 1; }
}

/* ============================================================
   RESPONSIVE TWEAKS
   ============================================================ */
@media (max-width: 400px) {
  .choice-grid, .method-grid {
    grid-template-columns: 1fr;
  }

  .welcome-title { font-size: 2.4rem; }

  .action-buttons { flex-direction: column; align-items: stretch; }
  .action-btn { max-width: none; }
}

@media (min-width: 600px) {
  .video-container {
    max-width: 480px;
    margin-left: auto;
    margin-right: auto;
  }

  .qr-video-container {
    max-width: 380px;
  }
}
