:root {
  --bg: #0b1020;
  --bg2: #0f1628;
  --panel: rgba(20, 30, 54, 0.72);
  --panel-border: rgba(96, 165, 250, 0.18);
  --fg: #e6edf7;
  --muted: #8aa0c4;
  --accent: #4ade80;
  --accent2: #60a5fa;
  --warn: #fbbf24;
  --danger: #f87171;
  --radius: 14px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background:
    radial-gradient(1200px 600px at 10% -10%, rgba(96, 165, 250, 0.12), transparent 60%),
    radial-gradient(1000px 500px at 100% 0%, rgba(74, 222, 128, 0.08), transparent 60%),
    var(--bg);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Helvetica Neue", Arial, sans-serif;
  min-height: 100vh;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 22px;
  border-bottom: 1px solid var(--panel-border);
  backdrop-filter: blur(8px);
  background: rgba(8, 12, 24, 0.6);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand { display: flex; align-items: baseline; gap: 10px; }
.brand .logo { color: var(--accent); font-size: 22px; }
.brand .name { font-weight: 700; font-size: 18px; letter-spacing: 0.5px; }
.brand .tag { color: var(--muted); font-size: 12px; }

.tabs { display: flex; gap: 6px; }
.tab {
  background: transparent;
  border: 1px solid var(--panel-border);
  color: var(--muted);
  padding: 8px 14px;
  border-radius: 999px;
  cursor: pointer;
  font-size: 13px;
  transition: all 0.15s;
}
.tab:hover { color: var(--fg); border-color: var(--accent2); }
.tab.active {
  background: linear-gradient(135deg, rgba(74, 222, 128, 0.18), rgba(96, 165, 250, 0.18));
  border-color: var(--accent);
  color: var(--fg);
}

main.view {
  display: none;
  max-width: 980px;
  margin: 0 auto;
  padding: 22px 16px 60px;
  gap: 16px;
  flex-direction: column;
}
main.view.active { display: flex; }

.panel {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  padding: 18px 18px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(6px);
}
.panel h2 {
  margin: 0 0 14px;
  font-size: 15px;
  font-weight: 600;
  color: var(--accent2);
  letter-spacing: 0.4px;
}

.dropzone {
  display: block;
  border: 1.5px dashed var(--panel-border);
  border-radius: var(--radius);
  padding: 28px;
  text-align: center;
  cursor: pointer;
  transition: all 0.15s;
  background: rgba(8, 12, 24, 0.4);
}
.dropzone:hover, .dropzone.drag {
  border-color: var(--accent);
  background: rgba(74, 222, 128, 0.06);
}
.dz-icon { font-size: 28px; color: var(--accent2); }
.dz-title { font-size: 15px; margin-top: 8px; }
.dz-sub { font-size: 12px; color: var(--muted); margin-top: 6px; word-break: break-all; }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
}
.field { display: flex; flex-direction: column; gap: 6px; font-size: 12px; color: var(--muted); }
.field.inline { flex-direction: row; align-items: center; gap: 8px; }
.field span { font-size: 12px; }
.field input, .field select {
  background: rgba(8, 12, 24, 0.7);
  border: 1px solid var(--panel-border);
  color: var(--fg);
  padding: 8px 10px;
  border-radius: 8px;
  font-size: 13px;
  outline: none;
}
.field input:focus, .field select:focus { border-color: var(--accent2); }
.field.inline input { width: auto; }

.hint {
  margin-top: 12px;
  font-size: 12px;
  color: var(--muted);
  line-height: 1.6;
  background: rgba(8, 12, 24, 0.4);
  padding: 10px 12px;
  border-radius: 8px;
  border-left: 2px solid var(--accent2);
}

.actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.btn {
  background: rgba(8, 12, 24, 0.6);
  border: 1px solid var(--panel-border);
  color: var(--fg);
  padding: 10px 18px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 13px;
  transition: all 0.15s;
}
.btn:hover:not(:disabled) { border-color: var(--accent2); transform: translateY(-1px); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn.primary {
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  border: none;
  color: #0b1020;
  font-weight: 600;
}
.btn.turbo {
  background: linear-gradient(135deg, #fbbf24, #f97316);
  border: none;
  color: #0b1020;
  font-weight: 700;
}
.btn.balance {
  background: linear-gradient(135deg, #34d399, #10b981);
  border: none;
  color: #0b1020;
  font-weight: 700;
}
.btn.danger { color: var(--danger); border-color: rgba(248, 113, 113, 0.4); }
.cam-sel {
  background: rgba(8, 12, 24, 0.7);
  border: 1px solid var(--panel-border);
  color: var(--fg);
  padding: 8px 10px;
  border-radius: 8px;
  font-size: 13px;
}

.stats {
  margin-top: 12px;
  font-size: 12px;
  color: var(--muted);
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  word-break: break-all;
}

.stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}
#qrCanvas {
  background: #fff;
  border-radius: 8px;
  max-width: 100%;
  image-rendering: pixelated;
}
.stage-info {
  font-size: 12px;
  color: var(--muted);
  font-family: ui-monospace, Menlo, monospace;
}

.scan-wrap {
  position: relative;
  width: 100%;
  max-width: 480px;
  aspect-ratio: 4 / 3;
  margin: 12px auto;
  background: #000;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--panel-border);
}
#video, #scanCanvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
#scanCanvas { opacity: 0; }
.debug-canvas {
  display: block;
  width: 100%;
  max-width: 480px;
  margin: 8px auto;
  background: #000;
  border-radius: 8px;
  border: 1px solid var(--panel-border);
  image-rendering: pixelated;
}
.scan-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}
.reticle {
  width: 70%;
  aspect-ratio: 1;
  border: 2px solid rgba(74, 222, 128, 0.7);
  border-radius: 12px;
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.25);
}
.scan-status {
  margin-top: 12px;
  font-size: 12px;
  color: var(--accent);
  background: rgba(0, 0, 0, 0.5);
  padding: 6px 12px;
  border-radius: 999px;
  font-family: ui-monospace, Menlo, monospace;
}

.progress { display: flex; align-items: center; gap: 12px; }
.bar {
  flex: 1;
  height: 10px;
  background: rgba(8, 12, 24, 0.7);
  border-radius: 999px;
  overflow: hidden;
  border: 1px solid var(--panel-border);
}
.fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent), var(--accent2));
  transition: width 0.2s;
}
.prog-text { font-size: 12px; color: var(--muted); font-family: ui-monospace, Menlo, monospace; }

.file-card {
  margin-top: 14px;
  background: rgba(8, 12, 24, 0.5);
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  padding: 12px;
}
.fc-row {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  padding: 4px 0;
}
.fc-row span { color: var(--muted); }
.fc-row strong { color: var(--fg); font-weight: 600; word-break: break-all; text-align: right; }

.foot {
  text-align: center;
  font-size: 11px;
  color: var(--muted);
  padding: 20px;
}

@media (max-width: 540px) {
  .topbar { flex-direction: column; gap: 10px; }
  main.view { padding: 14px; }
}
