/* QR RELAY — cyberpunk HUD theme */

:root {
  --bg: #04060c;
  --bg-soft: #070b14;
  --panel: rgba(8, 14, 26, 0.82);
  --line: rgba(0, 240, 255, 0.22);
  --line-soft: rgba(120, 200, 255, 0.12);
  --cyan: #00f0ff;
  --cyan-dim: #0aa3b3;
  --magenta: #ff2bd6;
  --violet: #8a5cff;
  --amber: #ffc857;
  --text: #d8f6ff;
  --muted: #6d8ba6;
  --ok: #35ffa8;
  --err: #ff4d6d;
  --font: ui-monospace, "JetBrains Mono", "Cascadia Mono", Consolas, "SFMono-Regular", monospace;
  --radius: 4px;
}

* { box-sizing: border-box; }

/* hidden 属性必须压过组件自身的 display 值（.empty / .btn / img 都设了 display） */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
}

body {
  background:
    radial-gradient(1200px 700px at 78% -12%, rgba(255, 43, 214, 0.14), transparent 60%),
    radial-gradient(1000px 620px at 8% 8%, rgba(0, 240, 255, 0.12), transparent 62%),
    var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

/* ---------- background layers ---------- */

.grid-bg {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background-image:
    linear-gradient(to right, rgba(0, 240, 255, 0.055) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(0, 240, 255, 0.055) 1px, transparent 1px);
  background-size: 48px 48px;
  mask-image: radial-gradient(ellipse 120% 90% at 50% 0%, #000 30%, transparent 85%);
  -webkit-mask-image: radial-gradient(ellipse 120% 90% at 50% 0%, #000 30%, transparent 85%);
}

.scanlines {
  position: fixed;
  inset: 0;
  z-index: 3;
  pointer-events: none;
  background: repeating-linear-gradient(
    to bottom,
    rgba(0, 0, 0, 0) 0px,
    rgba(0, 0, 0, 0) 2px,
    rgba(0, 0, 0, 0.24) 3px,
    rgba(0, 0, 0, 0.24) 4px
  );
  opacity: 0.35;
  mix-blend-mode: multiply;
}

.scanlines::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  height: 28vh;
  background: linear-gradient(to bottom, transparent, rgba(0, 240, 255, 0.05), transparent);
  animation: sweep 7s linear infinite;
}

@keyframes sweep {
  0% { transform: translateY(-30vh); }
  100% { transform: translateY(115vh); }
}

/* ---------- header ---------- */

.hud {
  position: relative;
  z-index: 4;
  display: flex;
  flex-wrap: wrap;
  gap: 14px 28px;
  align-items: center;
  justify-content: space-between;
  padding: 16px clamp(14px, 3vw, 34px);
  border-bottom: 1px solid var(--line);
  background: linear-gradient(to bottom, rgba(4, 10, 20, 0.95), rgba(4, 10, 20, 0.55));
  backdrop-filter: blur(6px);
}

.brand {
  display: flex;
  align-items: baseline;
  gap: 10px;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

.brand .glyph {
  color: var(--magenta);
  text-shadow: 0 0 14px rgba(255, 43, 214, 0.8);
  animation: blink 2.6s steps(1) infinite;
}

@keyframes blink {
  0%, 92%, 100% { opacity: 1; }
  94% { opacity: 0.25; }
}

.brand .accent {
  color: var(--cyan);
  text-shadow: 0 0 16px rgba(0, 240, 255, 0.75);
}

.brand small {
  font-size: 11px;
  letter-spacing: 0.1em;
  color: var(--muted);
  font-weight: 400;
}

.stats {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.stat {
  min-width: 92px;
  padding: 6px 12px;
  border: 1px solid var(--line-soft);
  border-left: 2px solid var(--cyan);
  background: rgba(0, 240, 255, 0.04);
}

.stat label {
  display: block;
  font-size: 9px;
  letter-spacing: 0.22em;
  color: var(--muted);
}

.stat b {
  font-size: 15px;
  letter-spacing: 0.08em;
  color: var(--cyan);
}

.stat b.ok { color: var(--ok); }
.stat b.err { color: var(--err); }

/* ---------- layout ---------- */

.pc-main {
  position: relative;
  z-index: 4;
  display: grid;
  grid-template-columns: minmax(280px, 1fr) minmax(360px, 1.5fr) minmax(280px, 1fr);
  gap: clamp(12px, 2vw, 22px);
  padding: clamp(14px, 2.4vw, 30px);
  align-items: stretch;
}

@media (max-width: 1180px) {
  .pc-main { grid-template-columns: 1fr 1fr; }
  .panel-preview { grid-column: 1 / -1; }
}

@media (max-width: 780px) {
  .pc-main { grid-template-columns: 1fr; }
  .panel-preview { grid-column: auto; }
}

.panel {
  position: relative;
  display: flex;
  flex-direction: column;
  padding: 16px 16px 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.02),
    0 18px 50px -30px rgba(0, 240, 255, 0.55);
  backdrop-filter: blur(4px);
}

.panel::before,
.panel::after {
  content: "";
  position: absolute;
  width: 12px;
  height: 12px;
  border: 1px solid var(--cyan);
  opacity: 0.85;
}

.panel::before {
  top: -1px;
  left: -1px;
  border-right: none;
  border-bottom: none;
}

.panel::after {
  right: -1px;
  bottom: -1px;
  border-left: none;
  border-top: none;
  border-color: var(--magenta);
}

.panel h2 {
  margin: 0 0 12px;
  font-size: 12px;
  letter-spacing: 0.24em;
  text-transform: uppercase;
  color: var(--cyan);
  text-shadow: 0 0 12px rgba(0, 240, 255, 0.5);
}

.panel h2 span { color: var(--magenta); }

.hint {
  margin: 0 0 12px;
  font-size: 12px;
  color: var(--muted);
  line-height: 1.6;
}

/* ---------- qr block ---------- */

.qr-shell {
  position: relative;
  display: grid;
  place-items: center;
  padding: 14px;
  background:
    linear-gradient(var(--bg-soft), var(--bg-soft)) padding-box,
    linear-gradient(135deg, var(--cyan), transparent 45%, var(--magenta)) border-box;
  border: 1px solid transparent;
  min-height: 220px;
}

.qr-shell #link-qr img,
.qr-shell #link-qr canvas {
  display: block;
  width: 190px !important;
  height: 190px !important;
  image-rendering: pixelated;
  filter: drop-shadow(0 0 14px rgba(0, 240, 255, 0.35));
}

.qr-shell .qr-frame {
  position: absolute;
  inset: 6px;
  pointer-events: none;
  background:
    linear-gradient(var(--cyan), var(--cyan)) left top / 22px 2px no-repeat,
    linear-gradient(var(--cyan), var(--cyan)) left top / 2px 22px no-repeat,
    linear-gradient(var(--magenta), var(--magenta)) right bottom / 22px 2px no-repeat,
    linear-gradient(var(--magenta), var(--magenta)) right bottom / 2px 22px no-repeat;
  opacity: 0.9;
  animation: pulse 3.4s ease-in-out infinite;
}

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

.link-row {
  display: flex;
  gap: 8px;
  margin-top: 14px;
}

.link-row input {
  flex: 1;
  min-width: 0;
  padding: 10px 12px;
  font-family: var(--font);
  font-size: 12px;
  color: var(--cyan);
  background: rgba(0, 240, 255, 0.05);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  outline: none;
}

.link-row input:focus {
  border-color: var(--cyan);
  box-shadow: 0 0 0 1px rgba(0, 240, 255, 0.35), 0 0 22px -6px rgba(0, 240, 255, 0.6);
}

.row-actions, .btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.pick-row {
  margin-top: 8px;
  align-items: center;
}
/* ---------- buttons ---------- */

.btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 16px;
  font-family: var(--font);
  font-size: 12px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text);
  text-decoration: none;
  cursor: pointer;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  transition: transform 0.12s ease, box-shadow 0.18s ease, border-color 0.18s ease, color 0.18s ease;
  user-select: none;
  white-space: nowrap;
}

.btn:hover:not(:disabled) {
  color: #fff;
  border-color: var(--cyan);
  box-shadow: 0 0 0 1px rgba(0, 240, 255, 0.35), 0 0 26px -8px rgba(0, 240, 255, 0.9);
  transform: translateY(-1px);
}

.btn:active:not(:disabled) { transform: translateY(0); }

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

.btn.primary {
  color: #031018;
  font-weight: 700;
  background: linear-gradient(135deg, var(--cyan), #6df7ff);
  border-color: transparent;
  box-shadow: 0 0 24px -6px rgba(0, 240, 255, 0.9);
}

.btn.primary:hover:not(:disabled) { color: #031018; }

.btn.danger {
  border-color: rgba(255, 77, 109, 0.55);
  color: #ffb3c1;
}

.btn.ghost {
  color: var(--muted);
}

.btn.ghost:hover:not(:disabled) { color: var(--cyan); }

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

/* ---------- viewport ---------- */

.viewport {
  position: relative;
  margin-top: 12px;
  aspect-ratio: 16 / 9;
  border: 1px solid var(--line);
  background: #01040a;
  overflow: hidden;
  user-select: none;
  touch-action: none;
}

.viewport.streaming {
  cursor: crosshair;
}

.roi-hint {
  margin: 10px 0 0;
  font-size: 11px;
  line-height: 1.7;
  color: var(--muted);
  border-left: 2px solid var(--cyan-dim);
  padding-left: 10px;
}

.roi-hint b {
  color: var(--cyan);
  font-weight: 600;
}

.viewport video {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
  filter: saturate(1.05) contrast(1.02);
}

.viewport canvas#overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.viewport-empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 12px;
  letter-spacing: 0.2em;
  color: var(--muted);
  text-align: center;
  padding: 20px;
  background:
    repeating-linear-gradient(135deg, rgba(0, 240, 255, 0.03) 0 8px, transparent 8px 16px);
}

.viewport-empty.hidden { display: none; }

.crosshair {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 44px;
  height: 44px;
  transform: translate(-50%, -50%);
  pointer-events: none;
  opacity: 0.5;
  background:
    linear-gradient(var(--cyan), var(--cyan)) center / 100% 1px no-repeat,
    linear-gradient(var(--cyan), var(--cyan)) center / 1px 100% no-repeat;
  border: 1px solid rgba(0, 240, 255, 0.28);
}

/* ---------- log ---------- */

.log {
  margin-top: 12px;
  flex: 1 1 148px;
  min-height: 110px;
  overflow-y: auto;
  padding: 10px 12px;
  font-size: 11.5px;
  line-height: 1.7;
  color: var(--muted);
  border: 1px solid var(--line-soft);
  background: rgba(0, 240, 255, 0.03);
  scrollbar-width: thin;
  scrollbar-color: var(--cyan-dim) transparent;
}

.log .line { display: flex; gap: 8px; }
.log time { color: rgba(0, 240, 255, 0.55); flex: none; }
.log .ok { color: var(--ok); }
.log .warn { color: var(--amber); }
.log .err { color: var(--err); }

/* ---------- pushed qr preview ---------- */

.last-qr {
  display: grid;
  place-items: center;
  min-height: 210px;
  padding: 12px;
  border: 1px dashed var(--line);
  background: rgba(0, 240, 255, 0.03);
}

.last-qr img {
  max-width: 100%;
  max-height: 260px;
  image-rendering: pixelated;
  filter: drop-shadow(0 0 16px rgba(255, 43, 214, 0.35));
  animation: pop 0.35s ease;
}

@keyframes pop {
  from { transform: scale(0.94); opacity: 0.2; }
  to { transform: scale(1); opacity: 1; }
}

#last-empty {
  font-size: 11px;
  letter-spacing: 0.2em;
  color: var(--muted);
}

.last-meta {
  margin-top: 12px;
  display: grid;
  gap: 8px;
  font-size: 12px;
}

.last-meta label {
  display: block;
  font-size: 9px;
  letter-spacing: 0.22em;
  color: var(--muted);
}

.last-meta code {
  display: block;
  padding: 6px 8px;
  color: var(--cyan);
  background: rgba(0, 240, 255, 0.05);
  border-left: 2px solid var(--cyan-dim);
  word-break: break-all;
  max-height: 76px;
  overflow-y: auto;
  font-size: 11px;
}

.last-meta .row2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

/* ---------- toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: 34px;
  z-index: 40;
  transform: translate(-50%, 22px);
  padding: 10px 20px;
  font-size: 12px;
  letter-spacing: 0.12em;
  color: #031018;
  background: linear-gradient(135deg, var(--cyan), #8ef9ff);
  border-radius: 999px;
  box-shadow: 0 0 32px -8px rgba(0, 240, 255, 0.95);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.22s ease, transform 0.22s ease;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

.toast.err {
  color: #fff;
  background: linear-gradient(135deg, var(--err), #ff8fa3);
  box-shadow: 0 0 32px -8px rgba(255, 77, 109, 0.95);
}

/* =================================================================
   MOBILE
   ================================================================= */

body.mobile {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.m-head {
  position: sticky;
  top: 0;
  z-index: 6;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  background: rgba(4, 10, 20, 0.92);
  backdrop-filter: blur(8px);
}

.m-head .brand { font-size: 15px; letter-spacing: 0.16em; }

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  font-size: 10px;
  letter-spacing: 0.16em;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
}

.pill .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--muted);
  box-shadow: 0 0 8px currentColor;
}

.pill.live { color: var(--ok); border-color: rgba(53, 255, 168, 0.5); }
.pill.live .dot { background: var(--ok); animation: beat 1.6s ease-in-out infinite; }
.pill.off { color: var(--err); border-color: rgba(255, 77, 109, 0.5); }
.pill.off .dot { background: var(--err); }

@keyframes beat {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.35; transform: scale(0.8); }
}

.m-main {
  position: relative;
  z-index: 4;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 16px 16px 26px;
  max-width: 560px;
  width: 100%;
  margin: 0 auto;
}

.code-strip {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.code-strip .cell {
  padding: 8px 10px;
  border: 1px solid var(--line-soft);
  border-left: 2px solid var(--cyan);
  background: rgba(0, 240, 255, 0.04);
}

.code-strip .cell label {
  display: block;
  font-size: 9px;
  letter-spacing: 0.2em;
  color: var(--muted);
}

.code-strip .cell b {
  font-size: 13px;
  color: var(--cyan);
  letter-spacing: 0.08em;
}

.qr-card {
  position: relative;
  display: grid;
  place-items: center;
  gap: 10px;
  padding: 20px 16px 18px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background:
    radial-gradient(circle at 50% 0%, rgba(0, 240, 255, 0.12), transparent 65%),
    var(--panel);
  box-shadow: 0 24px 60px -34px rgba(0, 240, 255, 0.75);
  overflow: hidden;
}

.qr-card::after {
  content: "";
  position: absolute;
  left: -40%;
  right: -40%;
  top: -20%;
  height: 30%;
  background: linear-gradient(to bottom, rgba(0, 240, 255, 0.16), transparent);
  transform: rotate(-8deg);
  animation: sweep2 4.5s linear infinite;
  pointer-events: none;
}

@keyframes sweep2 {
  0% { top: -30%; }
  100% { top: 120%; }
}

.qr-card img {
  position: relative;
  z-index: 1;
  width: min(78vw, 320px);
  height: auto;
  image-rendering: pixelated;
  background: #fff;
  padding: 8px;
  border-radius: 4px;
  box-shadow: 0 0 30px -6px rgba(0, 240, 255, 0.7);
  transition: transform 0.25s ease;
}

.qr-card img.flash { animation: flash 0.55s ease; }

@keyframes flash {
  0% { transform: scale(0.97); filter: brightness(1.9) saturate(1.4); }
  100% { transform: scale(1); filter: brightness(1); }
}

.qr-card .empty {
  display: grid;
  place-items: center;
  gap: 8px;
  width: min(78vw, 320px);
  aspect-ratio: 1;
  border: 1px dashed var(--line);
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0.18em;
  text-align: center;
  padding: 20px;
}

.qr-card .meta {
  position: relative;
  z-index: 1;
  font-size: 11px;
  color: var(--muted);
  text-align: center;
  word-break: break-all;
}

.qr-card .meta b { color: var(--cyan); font-weight: 500; }

.m-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.m-actions .btn { width: 100%; padding: 12px 10px; }

.m-actions .btn.wide { grid-column: 1 / -1; }

.panel-note {
  font-size: 11px;
  color: var(--muted);
  border-left: 2px solid var(--magenta);
  padding-left: 10px;
  line-height: 1.7;
}

.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--line-soft);
  background: rgba(0, 240, 255, 0.03);
  font-size: 12px;
  color: var(--muted);
}

.switch {
  position: relative;
  width: 46px;
  height: 24px;
  flex: none;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.04);
  cursor: pointer;
  transition: background 0.2s ease, border-color 0.2s ease;
}

.switch::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--muted);
  transition: transform 0.2s ease, background 0.2s ease;
}

.switch[aria-checked="true"] {
  background: rgba(0, 240, 255, 0.18);
  border-color: var(--cyan);
}

.switch[aria-checked="true"]::after {
  transform: translateX(22px);
  background: var(--cyan);
  box-shadow: 0 0 12px rgba(0, 240, 255, 0.9);
}

.m-foot {
  padding: 0 16px 22px;
  text-align: center;
  font-size: 10px;
  letter-spacing: 0.18em;
  color: rgba(109, 139, 166, 0.7);
}

/* 兜底：极小屏 */
@media (max-width: 360px) {
  .code-strip { grid-template-columns: 1fr 1fr; }
  .m-actions { grid-template-columns: 1fr; }
}
