/* ============ QR · Style ============ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg-1: #0c0a1f;
  --bg-2: #160f2e;
  --bg-3: #221645;
  --fuchsia:   #d946ef;
  --fuchsia-2: #e879f9;
  --fuchsia-3: #f0abfc;
  --indigo:    #6366f1;
  --cream:     #fef3c7;
  --green:     #22c55e;
  --red:       #ef4444;
  --text:      #fdf4ff;
  --muted:     rgba(253,244,255,.55);
  --faint:     rgba(253,244,255,.32);
  --safe-top: env(safe-area-inset-top, 0);
  --safe-bot: env(safe-area-inset-bottom, 0);
}

html, body {
  background: var(--bg-1);
  color: var(--text);
  font-family: 'Heebo', -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
  font-weight: 400;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}
body {
  min-height: 100vh;
  position: relative;
  overflow-x: hidden;
  padding-top: calc(58px + var(--safe-top));
  padding-bottom: calc(28px + var(--safe-bot));
}

.ambient-bg {
  position: fixed;
  inset: 0;
  z-index: -3;
  overflow: hidden;
  background: var(--bg-1);
}
.orb-blur {
  position: absolute;
  border-radius: 50%;
  filter: blur(80px);
  opacity: .35;
  pointer-events: none;
  will-change: transform;
}
.orb-blur.o1 {
  width: 60vmax; height: 60vmax;
  background: radial-gradient(circle, var(--fuchsia) 0%, transparent 60%);
  top: -20vh; right: -10vw;
  animation: drift1 26s ease-in-out infinite;
}
.orb-blur.o2 {
  width: 55vmax; height: 55vmax;
  background: radial-gradient(circle, var(--indigo) 0%, transparent 60%);
  bottom: -15vh; left: -10vw;
  animation: drift2 30s ease-in-out infinite;
}
@keyframes drift1 { 0%,100%{transform:translate(0,0)scale(1);} 50%{transform:translate(-7vw,5vh)scale(1.05);} }
@keyframes drift2 { 0%,100%{transform:translate(0,0)scale(1);} 50%{transform:translate(7vw,-5vh)scale(.95);} }

.topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: calc(58px + var(--safe-top));
  padding-top: var(--safe-top);
  padding-inline: 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(12,10,31,.78);
  backdrop-filter: blur(18px) saturate(150%);
  -webkit-backdrop-filter: blur(18px) saturate(150%);
  border-bottom: 1px solid rgba(217,70,239,.18);
  z-index: 100;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand .mark {
  width: 30px; height: 30px;
  border-radius: 9px;
  background: linear-gradient(135deg, var(--fuchsia), var(--indigo));
  display: grid; place-items: center;
  color: #fff;
  box-shadow: 0 6px 18px rgba(217,70,239,.55);
}
.brand .mark svg { width: 16px; height: 16px; }
.brand span:not(.mark) {
  font-weight: 800;
  font-size: 18px;
  letter-spacing: -0.02em;
}
.header-actions { display: flex; gap: 8px; }
.icon-btn {
  width: 38px; height: 38px;
  border-radius: 50%;
  border: 1px solid rgba(217,70,239,.20);
  background: rgba(217,70,239,.06);
  color: var(--text);
  cursor: pointer;
  display: grid; place-items: center;
  font-size: 16px;
  transition: background .2s, transform .15s;
}
.icon-btn:hover { background: rgba(217,70,239,.14); }
.icon-btn:active { transform: scale(.92); }
.install-btn {
  background: linear-gradient(135deg, var(--fuchsia), var(--fuchsia-2));
  color: #fff;
  border: none;
  padding: 8px 16px;
  border-radius: 999px;
  font-family: inherit;
  font-weight: 700;
  font-size: 12px;
  cursor: pointer;
  box-shadow: 0 6px 16px rgba(217,70,239,.5);
}
.hidden { display: none !important; }

main { padding: 14px 18px; max-width: 540px; margin: 0 auto; }
.panel { animation: fade .35s cubic-bezier(.2,.9,.3,1.05); }
@keyframes fade { from{opacity:0; transform:translateY(8px);} to{opacity:1; transform:translateY(0);} }

/* Mode tabs */
.mode-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  background: rgba(217,70,239,.05);
  border: 1px solid rgba(217,70,239,.12);
  border-radius: 999px;
  padding: 4px;
  margin-bottom: 18px;
}
.mode-tab {
  padding: 10px 14px;
  background: transparent;
  border: none;
  color: var(--muted);
  font-family: inherit;
  font-weight: 600;
  font-size: 13px;
  border-radius: 999px;
  cursor: pointer;
  transition: all .25s;
}
.mode-tab:hover { color: var(--text); }
.mode-tab.active {
  background: linear-gradient(135deg, var(--fuchsia), var(--indigo));
  color: #fff;
  box-shadow: 0 4px 14px -4px rgba(217,70,239,.5);
}

/* Permission fallback */
.perm-fallback {
  text-align: center;
  padding: 50px 22px 30px;
  background: rgba(217,70,239,.04);
  border: 1px solid rgba(217,70,239,.12);
  border-radius: 22px;
}
.perm-icon {
  font-size: 56px;
  margin-bottom: 18px;
  filter: drop-shadow(0 0 20px rgba(217,70,239,.4));
}
.perm-fallback h2 {
  font-size: 22px;
  font-weight: 800;
  letter-spacing: -0.02em;
  margin-bottom: 10px;
}
.perm-fallback p {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.7;
  margin-bottom: 22px;
}
.perm-fallback strong { color: var(--fuchsia-3); }

/* Viewfinder */
.viewfinder {
  position: relative;
  width: 100%;
  aspect-ratio: 1;
  border-radius: 22px;
  overflow: hidden;
  background: #000;
  border: 1px solid rgba(217,70,239,.30);
  box-shadow: 0 0 40px rgba(217,70,239,.25);
}
.viewfinder video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.viewfinder-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
}
.viewfinder-mask {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(circle at 50% 50%, transparent 38%, rgba(12,10,31,0.65) 60%);
}
.crosshair {
  position: absolute;
  inset: 22%;
  border-radius: 14px;
  pointer-events: none;
}
.corner {
  position: absolute;
  width: 26px; height: 26px;
  border: 3px solid var(--fuchsia-2);
  filter: drop-shadow(0 0 6px var(--fuchsia));
}
.corner.tl { top: -3px; left: -3px; border-right: 0; border-bottom: 0; border-top-left-radius: 12px; }
.corner.tr { top: -3px; right: -3px; border-left: 0; border-bottom: 0; border-top-right-radius: 12px; }
.corner.bl { bottom: -3px; left: -3px; border-right: 0; border-top: 0; border-bottom-left-radius: 12px; }
.corner.br { bottom: -3px; right: -3px; border-left: 0; border-top: 0; border-bottom-right-radius: 12px; }
.scan-line {
  position: absolute;
  left: 8%; right: 8%;
  top: 0; height: 3px;
  background: linear-gradient(90deg, transparent, var(--fuchsia-2), transparent);
  box-shadow: 0 0 16px var(--fuchsia);
  animation: scan-sweep 2.4s ease-in-out infinite;
}
@keyframes scan-sweep {
  0%, 100% { top: 0; }
  50%      { top: calc(100% - 3px); }
}
.viewfinder-status {
  position: absolute;
  bottom: 16px; left: 16px; right: 16px;
  text-align: center;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 11px;
  letter-spacing: 2px;
  color: var(--fuchsia-3);
  text-transform: uppercase;
  text-shadow: 0 1px 4px rgba(0,0,0,.7);
}
.btn-stop {
  position: absolute;
  top: 14px; left: 14px;
  background: rgba(0,0,0,.55);
  border: 1px solid rgba(255,255,255,.22);
  color: #fff;
  padding: 6px 14px;
  border-radius: 999px;
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  backdrop-filter: blur(6px);
}

/* Scan result */
.scan-result {
  background: rgba(217,70,239,.05);
  border: 1px solid rgba(217,70,239,.20);
  border-radius: 22px;
  padding: 18px 20px;
  margin-top: 14px;
}
.scan-result.show {
  animation: result-in .4s cubic-bezier(.2,.9,.3,1.05);
}
@keyframes result-in {
  from { opacity: 0; transform: translateY(20px); }
  to   { opacity: 1; transform: translateY(0); }
}
.result-type {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 10px;
  letter-spacing: 2px;
  color: var(--fuchsia-3);
  text-transform: uppercase;
  margin-bottom: 8px;
}
.result-content {
  font-size: 16px;
  font-weight: 500;
  word-break: break-all;
  background: var(--bg-2);
  padding: 12px 14px;
  border-radius: 12px;
  margin-bottom: 14px;
  max-height: 200px;
  overflow-y: auto;
  direction: ltr;
  text-align: left;
  font-family: 'IBM Plex Mono', monospace;
  line-height: 1.5;
}
.result-actions {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 6px;
  margin-bottom: 12px;
}

/* Generate panel */
.gen-tabs {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
  background: rgba(217,70,239,.04);
  border: 1px solid rgba(217,70,239,.10);
  border-radius: 999px;
  padding: 4px;
  margin-bottom: 14px;
}
.gen-tab {
  padding: 8px 4px;
  background: transparent;
  border: none;
  color: var(--muted);
  font-family: inherit;
  font-weight: 500;
  font-size: 12px;
  border-radius: 999px;
  cursor: pointer;
  transition: all .2s;
}
.gen-tab:hover { color: var(--text); }
.gen-tab.active {
  background: rgba(217,70,239,.18);
  color: var(--fuchsia-3);
}

.gen-input-area {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 16px;
}
.gen-input, .gen-textarea {
  width: 100%;
  background: var(--bg-2);
  border: 1px solid rgba(217,70,239,.18);
  color: var(--text);
  padding: 12px 14px;
  border-radius: 12px;
  font-family: inherit;
  font-size: 15px;
  outline: none;
}
.gen-input:focus, .gen-textarea:focus { outline: 2px solid var(--fuchsia); outline-offset: 2px; }
.gen-textarea { resize: vertical; min-height: 80px; }

/* QR Output */
.gen-output {
  display: flex;
  justify-content: center;
  margin-bottom: 16px;
}
.qr-canvas-wrap {
  width: 280px;
  aspect-ratio: 1;
  background: var(--cream);
  border-radius: 22px;
  padding: 16px;
  display: grid;
  place-items: center;
  box-shadow: 0 16px 40px -8px rgba(217,70,239,.35);
  border: 1px solid rgba(217,70,239,.30);
  overflow: hidden;
}
.qr-canvas-wrap canvas {
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}
.qr-empty {
  text-align: center;
  color: rgba(34,15,75,0.5);
}
.qr-empty .qr-empty-icon {
  font-size: 56px;
  margin-bottom: 8px;
  color: rgba(217,70,239,.4);
}
.qr-empty p {
  font-size: 13px;
  font-weight: 500;
  color: rgba(34,15,75,0.6);
}

.gen-actions {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 6px;
}

.btn-mini {
  padding: 12px;
  background: rgba(217,70,239,.06);
  border: 1px solid rgba(217,70,239,.18);
  color: var(--text);
  font-family: inherit;
  font-weight: 600;
  font-size: 13px;
  border-radius: 12px;
  cursor: pointer;
  transition: background .2s;
}
.btn-mini:hover:not(:disabled) { background: rgba(217,70,239,.14); }
.btn-mini:disabled { opacity: .4; cursor: not-allowed; }

.btn-primary {
  padding: 14px;
  background: linear-gradient(135deg, var(--fuchsia), var(--fuchsia-2));
  color: #fff;
  border: none;
  border-radius: 14px;
  font-family: inherit;
  font-weight: 700;
  font-size: 15px;
  cursor: pointer;
  box-shadow: 0 14px 30px -8px rgba(217,70,239,.55);
  transition: transform .15s;
}
.btn-primary:active { transform: scale(.97); }

.btn-secondary {
  width: 100%;
  margin-top: 10px;
  padding: 13px;
  background: rgba(217,70,239,.06);
  border: 1px solid rgba(217,70,239,.18);
  color: var(--text);
  font-family: inherit;
  font-weight: 600;
  font-size: 14px;
  border-radius: 12px;
  cursor: pointer;
}
.btn-secondary:hover { background: rgba(217,70,239,.12); }

/* Modal */
.modal {
  position: fixed; inset: 0;
  background: rgba(12,10,31,.78);
  backdrop-filter: blur(8px);
  z-index: 200;
  display: grid;
  place-items: end center;
  animation: modal-in .25s ease;
}
@keyframes modal-in { from{opacity:0;} to{opacity:1;} }
.modal-card {
  background: rgba(22,15,46,.95);
  backdrop-filter: blur(18px) saturate(160%);
  border: 1px solid rgba(217,70,239,.20);
  border-top-left-radius: 28px;
  border-top-right-radius: 28px;
  padding: 24px 22px calc(28px + var(--safe-bot));
  width: 100%;
  max-width: 540px;
  animation: sheet-up .35s cubic-bezier(.2,.9,.3,1.05);
  max-height: 90vh;
  overflow-y: auto;
}
@keyframes sheet-up { from{transform:translateY(100%);} to{transform:translateY(0);} }
.modal-card .handle { width: 38px; height: 4px; background: rgba(217,70,239,.30); border-radius: 2px; margin: -8px auto 16px; }
.modal-card h3 { font-size: 20px; font-weight: 800; letter-spacing: -0.02em; margin-bottom: 6px; }
.modal-card p { color: var(--muted); font-size: 13px; margin-bottom: 18px; line-height: 1.7; }
.modal-card p strong { color: var(--fuchsia-3); }
.mark-big {
  width: 56px; height: 56px;
  border-radius: 14px;
  background: linear-gradient(135deg, var(--fuchsia), var(--indigo));
  margin: 0 auto 14px;
  display: grid; place-items: center;
  color: #fff;
  box-shadow: 0 10px 30px rgba(217,70,239,.55);
}
.mark-big svg { width: 28px; height: 28px; }

/* History */
.history-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  background: rgba(217,70,239,.04);
  border: 1px solid rgba(217,70,239,.10);
  border-radius: 999px;
  padding: 4px;
  margin-bottom: 14px;
}
.history-tab {
  padding: 8px 12px;
  background: transparent;
  border: none;
  color: var(--muted);
  font-family: inherit;
  font-weight: 500;
  font-size: 12px;
  border-radius: 999px;
  cursor: pointer;
  transition: all .2s;
}
.history-tab.active {
  background: rgba(217,70,239,.18);
  color: var(--fuchsia-3);
}

.history-list { max-height: 50vh; overflow-y: auto; }
.history-item {
  display: grid;
  grid-template-columns: 44px 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 12px;
  background: rgba(217,70,239,.04);
  border: 1px solid rgba(217,70,239,.12);
  border-radius: 12px;
  margin-bottom: 8px;
}
.history-item .h-icon {
  width: 44px; height: 44px;
  border-radius: 10px;
  background: rgba(217,70,239,.12);
  display: grid; place-items: center;
  font-size: 18px;
  color: var(--fuchsia-3);
}
.history-item .h-info .h-content {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 12px;
  word-break: break-all;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  direction: ltr;
  text-align: left;
}
.history-item .h-info .h-when {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 10px;
  color: var(--faint);
  margin-top: 2px;
}
.history-item .h-del {
  background: transparent;
  border: 1px solid rgba(217,70,239,.18);
  color: var(--muted);
  padding: 5px 9px;
  border-radius: 8px;
  font-size: 11px;
  cursor: pointer;
  font-family: inherit;
}

.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--muted);
}
.empty-state .ico { font-size: 48px; margin-bottom: 14px; opacity: .55; }

/* Toast */
.toast {
  position: fixed;
  top: calc(70px + var(--safe-top));
  left: 50%;
  transform: translateX(-50%);
  background: rgba(22,15,46,.96);
  border: 1px solid rgba(217,70,239,.30);
  color: var(--text);
  padding: 10px 22px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 500;
  z-index: 300;
  box-shadow: 0 18px 40px rgba(0,0,0,.5);
  backdrop-filter: blur(10px);
  animation: toast-in .25s ease;
}
@keyframes toast-in { from{opacity:0; transform:translate(-50%, -16px);} to{opacity:1; transform:translate(-50%, 0);} }
.toast.success { color: var(--green); border-color: rgba(34,197,94,.5); }
.toast.error { color: var(--red); border-color: rgba(239,68,68,.5); }
