*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg: #0f1419;
  --surface: #1a2332;
  --border: #2d3a4f;
  --text: #e8edf4;
  --text-muted: #8b9cb3;
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --success: #22c55e;
  --warning: #f59e0b;
  --danger: #ef4444;
  --radius: 12px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

html,
body {
  height: 100%;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  overscroll-behavior: none;
}

.app {
  min-height: 100%;
  display: flex;
  flex-direction: column;
  max-width: 480px;
  margin: 0 auto;
  padding: 16px 16px calc(16px + var(--safe-bottom));
}

.header {
  text-align: center;
  padding: 12px 0 20px;
}

.header h1 {
  font-size: 1.5rem;
  font-weight: 700;
}

.subtitle {
  margin-top: 4px;
  font-size: 0.875rem;
  color: var(--text-muted);
}

.mode-tabs {
  display: flex;
  gap: 8px;
  padding: 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.mode-tab {
  flex: 1;
  padding: 10px 12px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
  -webkit-appearance: none;
  appearance: none;
}

.mode-tab--active {
  background: var(--primary);
  color: #fff;
}

.tips {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  font-size: 0.8125rem;
  color: var(--text-muted);
}

.tips p {
  color: var(--text);
  margin-bottom: 8px;
}

.tips ul {
  padding-left: 18px;
}

.tips li + li {
  margin-top: 4px;
}

.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.reader {
  width: 100%;
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--border);
  min-height: 320px;
}

.reader video {
  border-radius: var(--radius);
  object-fit: cover;
}

#reader__dashboard_section {
  display: none !important;
}

#reader__scan_region {
  min-height: 320px !important;
}

#reader__scan_region video {
  border-radius: var(--radius);
}

/* 条形码扫描框：横向长方形 */
#reader canvas {
  border-radius: var(--radius);
}

#reader__scan_region img {
  display: none;
}

.status {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 16px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border);
  font-size: 0.875rem;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-muted);
  flex-shrink: 0;
}

.status--idle .status-dot {
  background: var(--text-muted);
}

.status--scanning .status-dot {
  background: var(--success);
  animation: pulse 1.5s ease-in-out infinite;
}

.status--error .status-dot {
  background: var(--danger);
}

.status--success .status-dot {
  background: var(--success);
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

.actions {
  display: flex;
  gap: 12px;
}

.btn {
  flex: 1;
  padding: 14px 20px;
  border: none;
  border-radius: var(--radius);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
  -webkit-appearance: none;
  appearance: none;
}

.btn:active {
  transform: scale(0.98);
}

.btn--primary {
  background: var(--primary);
  color: #fff;
}

.btn--primary:hover,
.btn--primary:focus-visible {
  background: var(--primary-hover);
}

.btn--secondary {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn--outline {
  background: transparent;
  color: var(--primary);
  border: 1px solid var(--primary);
}

.result-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}

.result-section h2 {
  font-size: 0.875rem;
  color: var(--text-muted);
  font-weight: 500;
  margin-bottom: 10px;
}

.result-content {
  background: var(--bg);
  border-radius: 8px;
  padding: 14px;
  word-break: break-all;
  font-size: 0.9375rem;
  line-height: 1.6;
  max-height: 200px;
  overflow-y: auto;
}

.result-meta {
  margin-top: 8px;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.result-actions {
  display: flex;
  gap: 12px;
  margin-top: 14px;
}

.footer {
  margin-top: 24px;
  text-align: center;
}

.footer p {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.toast {
  position: fixed;
  bottom: calc(24px + var(--safe-bottom));
  left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 12px 20px;
  border-radius: 999px;
  font-size: 0.875rem;
  opacity: 0;
  transition: transform 0.3s, opacity 0.3s;
  z-index: 1000;
  pointer-events: none;
  white-space: nowrap;
}

.toast--show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}
