/* ---------- Tokens ---------- */
:root {
  --bg: #0a0a0a;
  --bg-2: #111111;
  --surface: #161616;
  --surface-2: #1c1c1c;
  --line: #2a2a2a;
  --line-strong: #3a3a3a;
  --text: #ededed;
  --text-dim: #8a8a8a;
  --text-faint: #555555;
  --accent: #c6ff3d;      /* signal green */
  --accent-2: #9ee600;
  --danger: #ff5252;
  --warn: #ffb84d;
  --font-mono: 'JetBrains Mono', 'Fira Code', 'SF Mono', ui-monospace, Menlo, Consolas, monospace;
  --font-display: 'Space Mono', 'JetBrains Mono', ui-monospace, monospace;
  --radius: 6px;
  --tap: 56px;
}

@font-face {
  font-family: 'Space Mono';
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
  src: local('Space Mono'), local('SpaceMono-Regular');
}

* { box-sizing: border-box; margin: 0; padding: 0; }

/* The HTML `hidden` attribute must always win over component display rules */
[hidden] { display: none !important; }

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
}

/* Grain overlay for texture */
.grain {
  pointer-events: none;
  position: fixed;
  inset: 0;
  z-index: 1000;
  opacity: 0.04;
  mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='200' height='200'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2'/></filter><rect width='100%25' height='100%25' filter='url(%23n)'/></svg>");
}

/* ---------- Topbar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
  background: var(--bg);
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-display);
  font-weight: 700;
  letter-spacing: 0.12em;
}

.brand-dot {
  width: 8px; height: 8px;
  background: var(--accent);
  box-shadow: 0 0 12px var(--accent);
  animation: pulse 2s ease-in-out infinite;
}

.brand-name { font-size: 16px; }

.brand-version {
  color: var(--text-faint);
  font-size: 10px;
  font-weight: 400;
  margin-left: 4px;
}

.status {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  letter-spacing: 0.1em;
  color: var(--text-dim);
}

.status-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--text-faint);
  transition: background 0.2s, box-shadow 0.2s;
}

.status[data-state="active"] .status-dot {
  background: var(--accent);
  box-shadow: 0 0 8px var(--accent);
  animation: pulse 1.2s ease-in-out infinite;
}
.status[data-state="active"] .status-text { color: var(--accent); }

.status[data-state="error"] .status-dot { background: var(--danger); }
.status[data-state="error"] .status-text { color: var(--danger); }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* ---------- Stage ---------- */
.stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 16px;
  gap: 16px;
}

.viewport {
  position: relative;
  aspect-ratio: 1 / 1;
  width: 100%;
  max-width: 520px;
  margin: 0 auto;
  background: #000;
  border: 1px solid var(--line);
  overflow: hidden;
  border-radius: var(--radius);
}

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

/* Reticle */
.reticle {
  position: absolute;
  inset: 12%;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.3s;
}
.viewport.scanning .reticle { opacity: 1; }

.corner {
  position: absolute;
  width: 28px; height: 28px;
  border: 2px solid var(--accent);
  filter: drop-shadow(0 0 6px var(--accent));
}
.corner.tl { top: 0; left: 0; border-right: none; border-bottom: none; }
.corner.tr { top: 0; right: 0; border-left: none; border-bottom: none; }
.corner.bl { bottom: 0; left: 0; border-right: none; border-top: none; }
.corner.br { bottom: 0; right: 0; border-left: none; border-top: none; }

.scanline {
  position: absolute;
  left: 0; right: 0;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
  box-shadow: 0 0 12px var(--accent);
  animation: scan 2.4s ease-in-out infinite;
}

@keyframes scan {
  0%   { top: 0; opacity: 0; }
  10%  { opacity: 1; }
  50%  { top: calc(100% - 2px); opacity: 1; }
  90%  { opacity: 1; }
  100% { top: 0; opacity: 0; }
}

/* Idle overlay */
.overlay-idle {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background:
    radial-gradient(circle at center, rgba(198,255,61,0.04), transparent 60%),
    repeating-linear-gradient(0deg, transparent 0, transparent 19px, rgba(198,255,61,0.04) 20px),
    repeating-linear-gradient(90deg, transparent 0, transparent 19px, rgba(198,255,61,0.04) 20px),
    #050505;
  transition: opacity 0.3s;
}
.viewport.scanning .overlay-idle { opacity: 0; pointer-events: none; }

.idle-card {
  text-align: center;
  max-width: 280px;
  color: var(--text-dim);
}
.idle-glyph {
  color: var(--accent);
  width: 64px;
  height: 64px;
  margin: 0 auto 16px;
  filter: drop-shadow(0 0 8px rgba(198,255,61,0.4));
}
.idle-card h2 {
  font-family: var(--font-display);
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.2em;
  color: var(--text);
  margin-bottom: 8px;
}
.idle-card p {
  font-size: 12px;
  line-height: 1.6;
  color: var(--text-faint);
}

/* Capture flash */
.hit-flash {
  position: absolute;
  inset: 0;
  background: var(--accent);
  opacity: 0;
  pointer-events: none;
}
.hit-flash.fire {
  animation: flash 0.4s ease-out;
}
@keyframes flash {
  0%   { opacity: 0.7; }
  100% { opacity: 0; }
}

/* ---------- Controls ---------- */
.controls {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 12px;
  max-width: 520px;
  margin: 0 auto;
  width: 100%;
}

.ctrl {
  font-family: var(--font-display);
  font-weight: 700;
  letter-spacing: 0.1em;
  font-size: 11px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  cursor: pointer;
  transition: all 0.15s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: var(--tap);
}

.ctrl.secondary {
  padding: 12px 14px;
  flex-direction: column;
  gap: 4px;
}
.ctrl.secondary svg { color: var(--accent); }
.ctrl.secondary span { font-size: 10px; color: var(--text-dim); }

.ctrl:hover, .ctrl:active {
  background: var(--surface-2);
  border-color: var(--line-strong);
}

.ctrl.primary {
  width: 88px;
  height: 88px;
  border-radius: 50%;
  position: relative;
  background: var(--accent);
  color: var(--bg);
  border: none;
  box-shadow: 0 0 0 4px var(--bg), 0 0 0 5px var(--accent), 0 0 24px rgba(198,255,61,0.4);
}

.ctrl.primary:hover {
  background: var(--accent-2);
}

.trigger-ring {
  position: absolute;
  inset: -8px;
  border-radius: 50%;
  border: 1px dashed rgba(198,255,61,0.4);
  animation: spin 8s linear infinite;
  pointer-events: none;
}

.trigger-core {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.1em;
  z-index: 1;
}

.ctrl.primary[data-state="active"] {
  background: var(--danger);
  box-shadow: 0 0 0 4px var(--bg), 0 0 0 5px var(--danger), 0 0 24px rgba(255,82,82,0.4);
}
.ctrl.primary[data-state="active"] .trigger-ring { border-color: rgba(255,82,82,0.4); }

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ---------- Log ---------- */
.log {
  margin: 0 16px 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg-2);
  max-width: 520px;
  margin-left: auto;
  margin-right: auto;
  width: calc(100% - 32px);
}

.log-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
}
.log-header h3 {
  font-family: var(--font-display);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.16em;
  color: var(--text-dim);
}
.clear {
  background: none;
  border: none;
  color: var(--text-faint);
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.1em;
  cursor: pointer;
  padding: 4px 6px;
}
.clear:hover { color: var(--danger); }

.log-list {
  list-style: none;
  max-height: 240px;
  overflow-y: auto;
}

.log-empty {
  padding: 24px 14px;
  text-align: center;
  color: var(--text-faint);
  font-size: 11px;
}

.log-item {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 10px;
  align-items: center;
  transition: background 0.15s;
}
.log-item:last-child { border-bottom: none; }
.log-item:hover { background: var(--surface); }

.log-type {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.1em;
  color: var(--bg);
  background: var(--accent);
  padding: 3px 6px;
  border-radius: 3px;
}
.log-type.URL { background: var(--accent); }
.log-type.TEXT { background: var(--text-dim); }
.log-type.EMAIL, .log-type.PHONE, .log-type.SMS, .log-type.WIFI, .log-type.GEO, .log-type.VCARD { background: var(--warn); }

.log-value {
  font-size: 12px;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  user-select: text;
}

.log-time {
  font-size: 10px;
  color: var(--text-faint);
  white-space: nowrap;
}

/* ---------- Modal ---------- */
.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  animation: fadein 0.2s ease;
}
@keyframes fadein {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal-card {
  width: 100%;
  max-width: 520px;
  background: var(--bg-2);
  border-top: 2px solid var(--accent);
  border-radius: var(--radius) var(--radius) 0 0;
  padding-bottom: env(safe-area-inset-bottom);
  animation: slideup 0.25s cubic-bezier(.2,.7,.3,1);
}
@keyframes slideup {
  from { transform: translateY(100%); }
  to   { transform: translateY(0); }
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
}
.modal-type {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 11px;
  letter-spacing: 0.15em;
  color: var(--accent);
}
.modal-close {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 28px;
  line-height: 1;
  cursor: pointer;
  padding: 0 4px;
}
.modal-close:hover { color: var(--text); }

.modal-body {
  padding: 18px;
  max-height: 50vh;
  overflow-y: auto;
}
#modalContent {
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--text);
  white-space: pre-wrap;
  word-break: break-all;
  user-select: text;
  line-height: 1.6;
}

.modal-actions {
  display: flex;
  gap: 8px;
  padding: 14px 18px;
  border-top: 1px solid var(--line);
}
.action {
  flex: 1;
  padding: 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--text);
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 12px;
  letter-spacing: 0.12em;
  cursor: pointer;
  border-radius: var(--radius);
  transition: all 0.15s;
}
.action:hover { background: var(--surface-2); border-color: var(--accent); color: var(--accent); }

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--accent);
  color: var(--bg);
  padding: 10px 16px;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 11px;
  letter-spacing: 0.1em;
  z-index: 200;
  border-radius: var(--radius);
  box-shadow: 0 4px 20px rgba(0,0,0,0.4);
  animation: toastin 0.2s ease;
}
@keyframes toastin {
  from { transform: translate(-50%, 20px); opacity: 0; }
  to   { transform: translate(-50%, 0); opacity: 1; }
}

/* ---------- Install ---------- */
.install-toast {
  position: fixed;
  top: calc(env(safe-area-inset-top) + 56px);
  left: 16px;
  right: 16px;
  max-width: 488px;
  margin: 0 auto;
  background: var(--surface);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  padding: 10px 8px 10px 14px;
  display: flex;
  align-items: center;
  gap: 8px;
  z-index: 150;
  font-size: 12px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.5);
}
.install-toast span { flex: 1; color: var(--text); }
.install-toast button {
  font-family: var(--font-display);
  font-weight: 700;
  letter-spacing: 0.1em;
  font-size: 11px;
  background: var(--accent);
  color: var(--bg);
  border: none;
  padding: 10px 14px;
  border-radius: 4px;
  cursor: pointer;
  min-height: 40px;
  flex-shrink: 0;
}
.install-toast button.ghost {
  background: transparent;
  color: var(--text-dim);
  font-size: 22px;
  line-height: 1;
  min-width: 40px;
  min-height: 40px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
.install-toast button.ghost:active { color: var(--text); }

/* ---------- Responsive ---------- */
@media (min-width: 640px) {
  body { font-size: 15px; }
  .viewport { aspect-ratio: 4 / 3; }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
