:root {
  color-scheme: dark;
  --bg: #0c0f21;
  --panel: rgba(22, 27, 55, 0.88);
  --panel-border: rgba(164, 177, 255, 0.16);
  --text: #f5f6ff;
  --muted: #a7add0;
  --soft: #6f77a3;
  --accent: #9d8cff;
  --accent-2: #60e2d0;
  --danger: #ff7797;
  --shadow: 0 24px 70px rgba(0, 0, 0, 0.28);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  color: var(--text);
  background:
    radial-gradient(circle at 10% 0%, rgba(111, 91, 219, 0.32), transparent 34rem),
    radial-gradient(circle at 92% 8%, rgba(52, 189, 187, 0.16), transparent 30rem),
    linear-gradient(155deg, #10152f 0%, var(--bg) 52%, #11142a 100%);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "PingFang SC", "Microsoft YaHei", sans-serif;
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.app-shell {
  width: min(1120px, 100%);
  margin: 0 auto;
  padding: max(28px, env(safe-area-inset-top)) 20px calc(32px + env(safe-area-inset-bottom));
}

.hero {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  padding: 18px 2px 30px;
}

.eyebrow,
.section-kicker {
  margin: 0 0 8px;
  color: var(--accent-2);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.19em;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 8px;
  font-size: clamp(40px, 8vw, 66px);
  line-height: 0.95;
  letter-spacing: -0.06em;
}

h2 {
  margin-bottom: 0;
  font-size: 21px;
  letter-spacing: -0.03em;
}

.hero-copy {
  margin-bottom: 0;
  color: var(--muted);
  font-size: 15px;
}

.collection-badge {
  display: grid;
  min-width: 98px;
  padding: 14px 16px 12px;
  border: 1px solid rgba(157, 140, 255, 0.32);
  border-radius: 18px;
  background: rgba(31, 34, 72, 0.72);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08);
  text-align: right;
}

.collection-badge span {
  font-size: 30px;
  font-weight: 800;
  line-height: 1;
}

.collection-badge small {
  color: var(--soft);
  font-size: 13px;
}

.collection-badge em {
  margin-top: 6px;
  color: var(--muted);
  font-size: 11px;
  font-style: normal;
}

.game-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 18px;
}

.panel {
  border: 1px solid var(--panel-border);
  border-radius: 26px;
  background: var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.scanner-panel,
.card-panel {
  padding: 22px;
}

.panel-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
}

.live-dot {
  width: 10px;
  height: 10px;
  margin-top: 4px;
  border-radius: 50%;
  background: var(--soft);
  box-shadow: 0 0 0 5px rgba(111, 119, 163, 0.12);
}

.live-dot.active {
  background: var(--accent-2);
  box-shadow: 0 0 0 5px rgba(96, 226, 208, 0.13), 0 0 20px rgba(96, 226, 208, 0.7);
}

.camera-frame {
  position: relative;
  overflow: hidden;
  aspect-ratio: 4 / 3;
  border: 1px solid rgba(157, 140, 255, 0.22);
  border-radius: 19px;
  background: #080a15;
}

#camera {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
  transition: opacity 260ms ease;
}

#camera.active {
  opacity: 1;
}

.camera-empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  gap: 8px;
  color: var(--muted);
  text-align: center;
}

.camera-empty strong {
  color: var(--text);
  font-size: 17px;
}

.camera-icon,
.placeholder-symbol {
  color: var(--accent);
  font-size: 40px;
  line-height: 1;
}

.camera-empty span:last-child,
.card-placeholder span:last-child {
  color: var(--soft);
  font-size: 12px;
}

.scan-guide {
  position: absolute;
  inset: 16% 16%;
  pointer-events: none;
  opacity: 0;
  transition: opacity 260ms ease;
}

.scan-guide.visible {
  opacity: 1;
}

.scan-guide i {
  position: absolute;
  width: 24px;
  height: 24px;
  border-color: var(--accent-2);
  border-style: solid;
}

.scan-guide i:nth-child(1) { top: 0; left: 0; border-width: 3px 0 0 3px; border-radius: 8px 0 0 0; }
.scan-guide i:nth-child(2) { top: 0; right: 0; border-width: 3px 3px 0 0; border-radius: 0 8px 0 0; }
.scan-guide i:nth-child(3) { right: 0; bottom: 0; border-width: 0 3px 3px 0; border-radius: 0 0 8px 0; }
.scan-guide i:nth-child(4) { bottom: 0; left: 0; border-width: 0 0 3px 3px; border-radius: 0 0 0 8px; }

.scan-beam {
  position: absolute;
  top: 8%;
  right: 4%;
  left: 4%;
  height: 2px;
  background: var(--accent-2);
  box-shadow: 0 0 16px 2px rgba(96, 226, 208, 0.72);
  animation: scan 2.2s ease-in-out infinite;
}

@keyframes scan {
  0%, 100% { transform: translateY(0); opacity: 0.4; }
  50% { transform: translateY(520%); opacity: 1; }
}

.status-row {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  color: var(--muted);
  font-size: 13px;
}

.status-icon {
  color: var(--soft);
  font-size: 11px;
}

.status-icon.success { color: var(--accent-2); }
.status-icon.error { color: var(--danger); }

.primary-button,
.secondary-button {
  min-height: 48px;
  border: 0;
  border-radius: 14px;
  font-size: 15px;
  font-weight: 750;
  transition: transform 180ms ease, filter 180ms ease, background 180ms ease;
}

.primary-button {
  width: 100%;
  color: #121329;
  background: linear-gradient(135deg, #b4a7ff, #7eebdb);
  box-shadow: 0 12px 26px rgba(109, 141, 224, 0.22);
}

.primary-button.stop {
  color: var(--text);
  background: rgba(255, 119, 151, 0.18);
  box-shadow: none;
}

.secondary-button {
  padding: 0 17px;
  color: var(--text);
  background: rgba(157, 140, 255, 0.16);
}

.primary-button:active,
.secondary-button:active {
  transform: scale(0.98);
}

.primary-button:hover,
.secondary-button:hover {
  filter: brightness(1.1);
}

.manual-divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 20px 0 12px;
  color: var(--soft);
  font-size: 11px;
  letter-spacing: 0.04em;
}

.manual-divider::before,
.manual-divider::after {
  height: 1px;
  flex: 1;
  content: "";
  background: rgba(164, 177, 255, 0.13);
}

.manual-row {
  display: flex;
  gap: 8px;
}

.manual-row input {
  width: 100%;
  min-width: 0;
  border: 1px solid rgba(164, 177, 255, 0.2);
  border-radius: 14px;
  outline: none;
  padding: 0 15px;
  color: var(--text);
  background: rgba(8, 10, 21, 0.56);
}

.manual-row input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(157, 140, 255, 0.15);
}

.secure-note {
  margin: 12px 1px 0;
  color: var(--soft);
  font-size: 11px;
  line-height: 1.55;
}

.id-pill,
.history-count {
  padding: 6px 10px;
  border: 1px solid rgba(96, 226, 208, 0.2);
  border-radius: 999px;
  color: var(--accent-2);
  background: rgba(96, 226, 208, 0.08);
  font-size: 11px;
  white-space: nowrap;
}

.id-pill {
  color: var(--muted);
  border-color: rgba(164, 177, 255, 0.16);
  background: rgba(164, 177, 255, 0.07);
}

.card-stage {
  display: grid;
  min-height: 435px;
  place-items: center;
  overflow: hidden;
  border: 1px solid rgba(164, 177, 255, 0.13);
  border-radius: 20px;
  background:
    radial-gradient(circle at 50% 15%, rgba(157, 140, 255, 0.15), transparent 13rem),
    rgba(8, 10, 21, 0.55);
}

.card-placeholder {
  display: grid;
  place-items: center;
  gap: 10px;
  padding: 24px;
  color: var(--muted);
  text-align: center;
}

.card-placeholder strong {
  font-size: 16px;
}

#cardImage {
  display: block;
  width: auto;
  max-width: 100%;
  height: min(68vh, 470px);
  border-radius: 13px;
  box-shadow: 0 18px 45px rgba(0, 0, 0, 0.38);
}

.card-caption {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 14px;
  padding: 0 4px;
  color: var(--muted);
  font-size: 13px;
}

.card-caption strong {
  color: var(--accent-2);
  font-size: 15px;
}

.history-panel {
  margin-top: 18px;
  padding: 22px;
}

.compact-heading {
  align-items: center;
}

.history-list {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 10px;
}

.history-item {
  display: grid;
  justify-items: center;
  gap: 5px;
  padding: 12px 8px 10px;
  border: 1px solid rgba(164, 177, 255, 0.13);
  border-radius: 14px;
  color: var(--muted);
  background: rgba(8, 10, 21, 0.32);
}

.history-item strong {
  color: var(--text);
  font-size: 14px;
}

.history-item time {
  color: var(--soft);
  font-size: 10px;
}

.history-empty {
  grid-column: 1 / -1;
  margin: 0;
  padding: 15px 0 4px;
  color: var(--soft);
  font-size: 13px;
  text-align: center;
}

.footer-note {
  padding: 20px 0 0;
  color: var(--soft);
  font-size: 11px;
  text-align: center;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
}

@media (max-width: 760px) {
  .app-shell {
    padding-right: 14px;
    padding-left: 14px;
  }

  .hero {
    align-items: flex-start;
  }

  .game-layout {
    grid-template-columns: 1fr;
  }

  .card-stage {
    min-height: 0;
    padding: 18px;
  }

  #cardImage {
    height: auto;
    max-height: 620px;
  }

  .history-list {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 420px) {
  h1 {
    font-size: 44px;
  }

  .hero-copy {
    font-size: 13px;
  }

  .scanner-panel,
  .card-panel,
  .history-panel {
    padding: 17px;
    border-radius: 21px;
  }

  .manual-row {
    display: grid;
    grid-template-columns: 1fr auto;
  }
}
