:root { color-scheme: dark; }
* { box-sizing: border-box; }
* { scrollbar-width: thin; scrollbar-color: rgba(255,255,255,.35) transparent; }
*::-webkit-scrollbar { width: 8px; height: 8px; }
*::-webkit-scrollbar-thumb { background: rgba(255,255,255,.35); border-radius: 8px; }
*::-webkit-scrollbar-track { background: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #000; font-family: -apple-system, "Segoe UI", Roboto, Arial, sans-serif; }
body.night-mode { background: #fff; }

.stage { position: fixed; inset: 0; overflow: hidden; background: #000; transition: background .2s ease; }
body.night-mode .stage { background: #fff; }
/* Mirror the selfie preview (natural, like a mirror). Display only — the captured
   frame is grabbed from the raw video, so recognition is unaffected. */
video, .freeze {
  position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; transform: scaleX(-1);
  transition: width .2s ease, height .2s ease, top .2s ease, left .2s ease, border-radius .2s ease, box-shadow .2s ease;
}
body.night-mode video,
body.night-mode .freeze {
  inset: auto; left: 50%; top: 44%; width: min(68vw, 320px); height: min(68vw, 320px);
  border-radius: 50%; object-fit: cover; transform: translate(-50%, -50%) scaleX(-1);
  box-shadow: 0 0 0 10px rgba(255,255,255,.96), 0 0 0 11px rgba(17,24,39,.08), 0 16px 42px rgba(17,24,39,.22);
}
.hidden { display: none !important; }

/* top overlay */
.top-ov {
  position: absolute; top: 0; left: 0; right: 0; z-index: 5;
  display: flex; align-items: center; gap: 10px;
  /* Sit below the device status bar / notch (standalone PWA, viewport-fit=cover). */
  padding: calc(env(safe-area-inset-top, 0px) + 12px) calc(env(safe-area-inset-right, 0px) + 14px) 12px calc(env(safe-area-inset-left, 0px) + 14px);
  color: #fff; background: linear-gradient(rgba(0,0,0,.6), rgba(0,0,0,0) 88%);
}
.top-ov .logo { font-weight: 600; }
.top-ov .clock { margin-left: auto; font-variant-numeric: tabular-nums; }
.geo-badge { font-size: 12px; padding: 3px 8px; border-radius: 8px; background: rgba(0,0,0,.45); }
.geo-badge.ok { background: rgba(33,128,80,.8); }
.geo-badge.err { background: rgba(190,40,40,.8); }
body.night-mode .top-ov {
  color: #111827; background: linear-gradient(rgba(255,255,255,1), rgba(255,255,255,.86) 72%, rgba(255,255,255,0));
}
body.night-mode .geo-badge { color: #fff; }

/* zone hint (name of the geozone you are inside) */
.zone-hint {
  position: absolute; top: calc(env(safe-area-inset-top, 0px) + 48px); left: 50%; transform: translateX(-50%); z-index: 5;
  max-width: calc(100% - 28px); color: #fff; background: rgba(33,128,80,.88); padding: 6px 14px; border-radius: 20px;
  font-size: 14px; font-weight: 600; box-shadow: 0 2px 8px rgba(0,0,0,.35);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.zone-hint.out { background: rgba(120,40,40,.85); }

.flip {
  position: absolute; right: 14px; bottom: calc(env(safe-area-inset-bottom, 0px) + 180px); z-index: 6;
  width: 52px; height: 52px; border-radius: 50%; border: none; background: rgba(255,255,255,.85); font-size: 22px;
}
.night-mode-toggle {
  position: absolute; right: 14px; bottom: calc(env(safe-area-inset-bottom, 0px) + 242px); z-index: 6;
  height: 44px; padding: 0 13px; border-radius: 22px; border: none; background: rgba(255,255,255,.88);
  color: #111827; font-size: 14px; font-weight: 800; box-shadow: 0 4px 14px rgba(0,0,0,.22);
}
.night-mode-toggle.active { background: #fff; outline: 3px solid rgba(37,99,235,.85); }
body.night-mode .flip,
body.night-mode .night-mode-toggle { background: rgba(17,24,39,.9); color: #fff; }
body.night-mode .night-mode-toggle.active { background: #2563eb; outline-color: rgba(255,255,255,.95); }

/* manual capture button (fallback when auto-scan can't recognize) */
.manual-btn {
  position: absolute; left: 50%; bottom: calc(env(safe-area-inset-bottom, 0px) + 104px); transform: translateX(-50%); z-index: 6;
  padding: 13px 22px; border: none; border-radius: 26px; background: #2563eb; color: #fff; font-size: 16px; font-weight: 700;
  box-shadow: 0 4px 14px rgba(0,0,0,.4);
}
.manual-btn:active { background: #1d4ed8; }

/* scanning hint */
.scan-hint {
  position: absolute; left: 50%; bottom: calc(env(safe-area-inset-bottom, 0px) + 48px); transform: translateX(-50%); z-index: 5;
  color: #fff; background: rgba(0,0,0,.5); padding: 10px 18px; border-radius: 24px; font-size: 15px;
  display: flex; align-items: center; gap: 10px;
}
body.night-mode .scan-hint { background: rgba(17,24,39,.9); }
.scan-hint::before { content: ''; width: 12px; height: 12px; border-radius: 50%; background: #4ade80; animation: pulse 1.2s infinite; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .25; } }

/* bottom panel (match / result) — lifted off the very bottom edge */
.panel {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 7;
  padding: 22px 16px calc(env(safe-area-inset-bottom, 0px) + 48px);
  background: linear-gradient(rgba(0,0,0,0), rgba(0,0,0,.85) 28%);
  color: #fff; text-align: center;
}
.panel.show { display: block; }

.match-name { font-size: 26px; font-weight: 800; }
.match-time { font-size: 18px; opacity: .9; margin-top: 2px; font-variant-numeric: tabular-nums; }
.match-loc { font-size: 14px; margin-top: 6px; opacity: .95; }
.match-loc.ok { color: #86efac; }
.match-loc.bad { color: #fca5a5; font-weight: 600; }
.match-q { font-size: 14px; opacity: .8; margin: 12px 0 10px; }
.choices { display: flex; gap: 12px; }
.choice {
  flex: 1; padding: 16px 10px; border: none; border-radius: 14px; color: #fff; font-size: 18px; font-weight: 700;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
}
.choice .sub { font-size: 12px; font-weight: 500; opacity: .9; }
.choice.in { background: #218050; }
.choice.out { background: #b3431f; }
.choice.suggested { outline: 3px solid #fff; }
.choice:disabled { opacity: .45; }
.cancel { margin-top: 14px; background: none; border: none; color: #cbd5e1; font-size: 14px; text-decoration: underline; }

.panel.result.success {
  top: 0; bottom: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: calc(env(safe-area-inset-top, 0px) + 22px) 18px calc(env(safe-area-inset-bottom, 0px) + 22px);
  background: rgba(3, 7, 18, .88);
}
body.night-mode .panel.result.success { background: rgba(255,255,255,.94); color: #111827; }
.success-card {
  width: min(420px, 100%);
  display: flex; flex-direction: column; align-items: center;
  padding: 20px 16px 18px;
}
.success-lottie {
  width: min(46vw, 190px); height: min(46vw, 190px);
  margin-bottom: 8px;
  display: grid; place-items: center;
}
.success-fallback-check {
  width: 132px; height: 132px; border-radius: 50%;
  background: #35c978; position: relative;
  box-shadow: 0 18px 48px rgba(53,201,120,.35);
  animation: successPop .35s ease-out both;
}
.success-fallback-check::after {
  content: ''; position: absolute; left: 36px; top: 39px;
  width: 58px; height: 30px;
  border-left: 12px solid #fff; border-bottom: 12px solid #fff;
  transform: rotate(-45deg);
  border-radius: 4px;
}
@keyframes successPop { from { transform: scale(.82); opacity: .2; } to { transform: scale(1); opacity: 1; } }
.result-kind { font-size: 20px; font-weight: 800; }
.result-name {
  max-width: 100%;
  font-size: clamp(24px, 8vw, 38px); line-height: 1.08;
  font-weight: 900; margin: 8px 0 4px;
  overflow-wrap: anywhere;
}
.result-time { font-size: clamp(34px, 12vw, 58px); font-weight: 900; font-variant-numeric: tabular-nums; }
.result-done {
  margin-top: 12px;
  font-size: 17px; line-height: 1.32; font-weight: 800;
  color: #bbf7d0;
}
body.night-mode .result-done { color: #047857; }
.result-sub { opacity: .85; font-size: 14px; margin-top: 6px; }
.result.in .result-kind { color: #4ade80; }
.result.out .result-kind { color: #fb923c; }
.result.duplicate .result-kind { color: #93c5fd; }
.result.warn .result-sub { color: #fcd34d; }
.panel.err { background: rgba(120,20,20,.85); }
