:root {
  --bg: #10151c;
  --bg-soft: #171e27;
  --surface: #1c2430;
  --ink: #f2f5f8;
  --muted: #8b97a8;
  --line: rgba(255, 255, 255, 0.08);
  --accent: #4f8cff;
  --accent-2: #6aa2ff;
  --accent-soft: rgba(79, 140, 255, 0.14);
  --ok: #3ecf8e;
  --danger: #ef6b7b;
  --shadow: 0 18px 40px rgba(0, 0, 0, 0.28);
  --radius: 20px;
  --font: "Manrope", sans-serif;
  --font-brand: "Space Grotesk", sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  color: var(--ink);
  font-family: var(--font);
  background: var(--bg);
}

body {
  min-height: 100dvh;
  position: relative;
}

.bg {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(900px 480px at 50% -10%, rgba(79, 140, 255, 0.16), transparent 60%),
    radial-gradient(700px 420px at 100% 100%, rgba(62, 207, 142, 0.06), transparent 55%),
    linear-gradient(180deg, #121821 0%, #10151c 55%, #0d1218 100%);
}

.scan-flash {
  pointer-events: none;
  position: fixed;
  inset: 0;
  z-index: 30;
  opacity: 0;
  background: radial-gradient(circle at center, rgba(79, 140, 255, 0.28), transparent 55%);
}

.scan-flash.is-on {
  animation: flashBurst 380ms ease-out;
}

@keyframes flashBurst {
  0% { opacity: 0; }
  25% { opacity: 1; }
  100% { opacity: 0; }
}

.app {
  position: relative;
  z-index: 1;
  width: min(480px, 100%);
  margin: 0 auto;
  padding: 1.25rem 1rem 1.5rem;
  display: grid;
  gap: 1rem;
}

.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-width: 0;
}

.brand-logo {
  width: 48px;
  height: 48px;
  border-radius: 14px;
  flex: 0 0 auto;
  box-shadow: 0 8px 20px rgba(79, 140, 255, 0.18);
}

.brand-text h1 {
  margin: 0;
  font-family: var(--font-brand);
  font-size: clamp(1.35rem, 5vw, 1.7rem);
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.1;
}

.brand-text h1 span {
  color: var(--accent-2);
}

.tagline {
  margin: 0.2rem 0 0;
  color: var(--muted);
  font-size: 0.92rem;
  font-weight: 500;
}

.live-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.4rem 0.7rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.live-pill i {
  width: 0.45rem;
  height: 0.45rem;
  border-radius: 50%;
  background: currentColor;
}

.live-pill[data-on="1"] {
  color: var(--ok);
  background: rgba(62, 207, 142, 0.1);
  border-color: rgba(62, 207, 142, 0.28);
}

.live-pill[data-on="1"] i {
  animation: blink 1.1s steps(1) infinite;
}

@keyframes blink {
  50% { opacity: 0.3; }
}

.main {
  display: grid;
  gap: 0.85rem;
}

.scanner-shell {
  position: relative;
  min-height: 360px;
  overflow: hidden;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.shell-mode {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 5;
  padding: 0.28rem 0.55rem;
  border-radius: 999px;
  background: rgba(16, 21, 28, 0.55);
  backdrop-filter: blur(6px);
  color: rgba(242, 245, 248, 0.85);
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  pointer-events: none;
}

.reader,
#reader__scan_region,
.reader video {
  width: 100% !important;
  min-height: 360px;
}

.reader video {
  object-fit: cover;
  display: block;
}

.reader img { max-width: 100%; }

.scan-overlay {
  pointer-events: none;
  position: absolute;
  inset: 0;
  z-index: 4;
  background: linear-gradient(
    to bottom,
    rgba(16, 21, 28, 0.35),
    transparent 22%,
    transparent 78%,
    rgba(16, 21, 28, 0.4)
  );
}

.scan-frame {
  position: absolute;
  inset: 16% 14%;
  border-radius: 18px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  box-shadow: 0 0 0 999px rgba(16, 21, 28, 0.22);
  overflow: hidden;
}

.bracket {
  position: absolute;
  width: 22px;
  height: 22px;
  border: 2.5px solid var(--accent);
  border-radius: 3px;
}

.b-tl { top: 8px; left: 8px; border-right: 0; border-bottom: 0; }
.b-tr { top: 8px; right: 8px; border-left: 0; border-bottom: 0; }
.b-bl { bottom: 8px; left: 8px; border-right: 0; border-top: 0; }
.b-br { bottom: 8px; right: 8px; border-left: 0; border-top: 0; }

.scan-beam {
  position: absolute;
  left: 10%;
  right: 10%;
  height: 2px;
  border-radius: 999px;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
  box-shadow: 0 0 12px rgba(79, 140, 255, 0.55);
  animation: beamSweep 2.2s ease-in-out infinite;
}

@keyframes beamSweep {
  0% { top: 12%; opacity: 0.2; }
  50% { opacity: 1; }
  100% { top: 86%; opacity: 0.2; }
}

body.is-scanning .scanner-shell {
  border-color: rgba(79, 140, 255, 0.35);
}

.status {
  margin: 0;
  text-align: center;
  min-height: 1.35em;
  color: var(--muted);
  font-size: 0.95rem;
  font-weight: 600;
}

.status[data-type="success"] { color: var(--ok); }
.status[data-type="error"] { color: var(--danger); }

.actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.65rem;
}

.actions .btn:only-child,
.actions .file-btn:only-child {
  grid-column: 1 / -1;
}

.btn {
  appearance: none;
  border: 1px solid transparent;
  border-radius: 14px;
  min-height: 48px;
  padding: 0.7rem 0.9rem;
  font: inherit;
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  transition: transform 0.15s ease, background 0.15s ease, border-color 0.15s ease;
}

.btn:active { transform: translateY(1px); }

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn-icon {
  width: 1.05rem;
  height: 1.05rem;
  flex: 0 0 auto;
}

/* Colorful action buttons */
.btn-start {
  background: linear-gradient(180deg, #5aa0ff, #3b82f6);
  color: #fff;
  box-shadow: 0 10px 22px rgba(59, 130, 246, 0.32);
}

.btn-stop {
  background: linear-gradient(180deg, #ff7b8a, #ef4444);
  color: #fff;
  box-shadow: 0 10px 22px rgba(239, 68, 68, 0.28);
}

.btn-upload {
  background: linear-gradient(180deg, #34d399, #10b981);
  color: #053527;
  box-shadow: 0 10px 22px rgba(16, 185, 129, 0.28);
}

.btn-flip {
  background: linear-gradient(180deg, #fbbf24, #f59e0b);
  color: #3b2500;
  box-shadow: 0 10px 22px rgba(245, 158, 11, 0.28);
}

.btn-start:hover,
.btn-stop:hover,
.btn-upload:hover,
.btn-flip:hover {
  filter: brightness(1.06);
}

/* Result page */
.type-pill {
  display: inline-flex;
  align-items: center;
  padding: 0.4rem 0.75rem;
  border-radius: 999px;
  border: 1px solid color-mix(in srgb, var(--pill-color, var(--accent)) 45%, transparent);
  background: color-mix(in srgb, var(--pill-color, var(--accent)) 16%, transparent);
  color: var(--pill-color, var(--accent-2));
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.03em;
  white-space: nowrap;
}

.result-card {
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--bg-soft);
  box-shadow: var(--shadow);
  padding: 1.1rem;
  min-height: 180px;
}

.result-loading {
  color: var(--muted);
  font-weight: 600;
  text-align: center;
  padding: 2rem 0.5rem;
}

.result-title {
  margin: 0 0 0.85rem;
  font-family: var(--font-brand);
  font-size: 1.25rem;
}

.result-body {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 1.05rem;
  line-height: 1.5;
  font-weight: 600;
}

.result-phone {
  font-size: 1.45rem;
  letter-spacing: 0.02em;
}

.kv-list {
  display: grid;
  gap: 0.55rem;
}

.kv {
  display: grid;
  gap: 0.15rem;
  padding: 0.65rem 0.75rem;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--line);
}

.kv span {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
}

.kv strong {
  font-size: 1rem;
  font-weight: 700;
  word-break: break-word;
}

.result-hint {
  margin: 0.85rem 0 0;
  color: var(--muted);
  font-size: 0.88rem;
}

.result-actions-inline {
  display: grid;
  gap: 0.55rem;
  margin-top: 0.95rem;
}

.result-image-wrap {
  border-radius: 14px;
  overflow: hidden;
  border: 1px solid var(--line);
  background: #0b1016;
}

.result-image {
  display: block;
  width: 100%;
  max-height: 360px;
  object-fit: contain;
  background: #0b1016;
}

.raw-box {
  margin-top: 1rem;
  border-top: 1px solid var(--line);
  padding-top: 0.75rem;
}

.raw-box summary {
  cursor: pointer;
  color: var(--muted);
  font-weight: 700;
  font-size: 0.85rem;
}

.raw-box pre {
  margin: 0.55rem 0 0;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 0.8rem;
  color: #c6d0db;
  line-height: 1.4;
}

.result-page-actions {
  margin-top: 0.15rem;
}

.file-btn {
  position: relative;
  overflow: hidden;
}

.file-btn input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.footer {
  text-align: center;
  color: var(--muted);
  font-size: 0.82rem;
}

.footer p { margin: 0; }

/* Hide html5-qrcode chrome that makes layout messy */
#reader__dashboard_section,
#reader__dashboard_section_csr,
#reader__dashboard_section_fsr,
#reader__status_span,
#reader__camera_selection,
#reader__scan_region > img,
#reader__header_message {
  display: none !important;
}

#reader__scan_region {
  min-height: 360px !important;
}

#reader video {
  border: none !important;
}

@media (max-width: 420px) {
  .scanner-shell,
  .reader,
  #reader__scan_region,
  .reader video {
    min-height: 320px;
  }

  .scan-frame { inset: 15% 11%; }

  .actions {
    grid-template-columns: 1fr 1fr;
  }

  .btn {
    font-size: 0.88rem;
    padding: 0.65rem 0.7rem;
  }

  .header {
    align-items: flex-start;
  }

  .live-pill {
    margin-top: 0.2rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation: none !important;
    transition: none !important;
  }
}
