:root {
  --bg: #071018;
  --bg-elevated: #0b1722;
  --surface: #102130;
  --surface-2: #162b3d;
  --line: rgba(148, 185, 209, 0.18);
  --text: #f3f8fc;
  --muted: #9fb3c4;
  --accent: #2dd4bf;
  --accent-strong: #14b8a6;
  --accent-soft: rgba(45, 212, 191, 0.14);
  --danger: #fb7185;
  --radius-lg: 24px;
  --radius-md: 16px;
  --radius-pill: 999px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  height: 100%;
}

html {
  background: var(--bg);
}

body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(120% 80% at 50% -10%, rgba(45, 212, 191, 0.09), transparent 55%),
    radial-gradient(90% 60% at 100% 100%, rgba(56, 189, 248, 0.05), transparent 60%),
    var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overscroll-behavior: none;
}

button,
input {
  font: inherit;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

button {
  cursor: pointer;
  touch-action: manipulation;
}

.app {
  position: relative;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
  padding-top: env(safe-area-inset-top);
  padding-right: env(safe-area-inset-right);
  padding-bottom: env(safe-area-inset-bottom);
  padding-left: env(safe-area-inset-left);
}

.topbar {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 12px;
  padding: 18px 20px 8px;
}

.mark {
  display: grid;
  flex: 0 0 auto;
  width: 42px;
  height: 42px;
  color: var(--accent);
  background: var(--accent-soft);
  border: 1px solid rgba(45, 212, 191, 0.26);
  border-radius: 13px;
  place-items: center;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.07);
}

.mark svg {
  width: 23px;
  height: 23px;
}

.heading {
  min-width: 0;
}

.heading h1 {
  margin: 0;
  font-size: 17px;
  font-weight: 650;
  letter-spacing: 0.02em;
}

.status {
  margin: 3px 0 0;
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0.02em;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.stage {
  position: relative;
  flex: 1 1 auto;
  width: calc(100% - 32px);
  max-width: 760px;
  min-height: 0;
  margin: 12px auto 16px;
  overflow: hidden;
  background: var(--bg-elevated);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.35);
}

.app[data-state="scanning"] {
  padding-right: 0;
  padding-bottom: 0;
  padding-left: 0;
}

.app[data-state="scanning"] .topbar {
  padding-right: max(20px, env(safe-area-inset-right));
  padding-left: max(20px, env(safe-area-inset-left));
}

.app[data-state="scanning"] .stage {
  width: 100%;
  max-width: none;
  margin: 0;
  background: #000;
  border-right: 0;
  border-bottom: 0;
  border-left: 0;
  border-radius: 0;
  box-shadow: none;
}

.panel {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  padding: clamp(20px, 4.5vh, 38px) clamp(18px, 5vw, 32px);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.panel-inner {
  width: 100%;
  max-width: 520px;
  margin: auto;
}

.hero-icon {
  display: grid;
  width: 74px;
  height: 74px;
  margin-bottom: 22px;
  color: var(--accent);
  background: linear-gradient(145deg, rgba(45, 212, 191, 0.2), rgba(45, 212, 191, 0.05));
  border: 1px solid rgba(45, 212, 191, 0.3);
  border-radius: 22px;
  place-items: center;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

.hero-icon svg {
  width: 38px;
  height: 38px;
}

h2 {
  margin: 0 0 12px;
  font-size: clamp(24px, 6vw, 30px);
  font-weight: 650;
  letter-spacing: -0.01em;
  line-height: 1.2;
}

.lede {
  max-width: 36em;
  margin: 0 0 22px;
  color: var(--muted);
  font-size: 15px;
  line-height: 1.65;
}

.lede.compact {
  margin-top: -2px;
  margin-bottom: 18px;
  font-size: 14px;
}

.actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 22px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 52px;
  padding: 14px 20px;
  color: var(--text);
  font-size: 16px;
  font-weight: 600;
  letter-spacing: 0.01em;
  text-align: center;
  text-decoration: none;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-pill);
  touch-action: manipulation;
  transition: transform 0.12s ease, background 0.12s ease, border-color 0.12s ease;
}

.btn:active {
  transform: scale(0.985);
}

.btn:focus-visible,
.ctl:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

.btn-primary {
  color: #04201c;
  background: linear-gradient(180deg, #34e0ca, #14b8a6);
  box-shadow: 0 10px 24px rgba(20, 184, 166, 0.24);
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.06);
  border-color: var(--line);
}

.btn-text {
  min-height: 44px;
  color: var(--muted);
  font-weight: 500;
  background: transparent;
}

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

.hint.warn {
  color: #fcd34d;
}

.result-head {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 10px;
}

.result-head h2 {
  margin: 0;
}

.success-dot {
  width: 12px;
  height: 12px;
  background: var(--accent);
  border-radius: 50%;
  box-shadow: 0 0 0 6px var(--accent-soft);
}

.result-content {
  max-height: 38vh;
  margin: 0;
  padding: 18px;
  overflow-y: auto;
  overflow-wrap: anywhere;
  color: var(--text);
  font-family: var(--mono);
  font-size: 15px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
  -webkit-user-select: text;
  user-select: text;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
}

.result-content:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

.result-actions {
  flex-flow: row wrap;
}

.result-actions .btn {
  flex: 1 1 120px;
}

.error-icon {
  display: grid;
  width: 64px;
  height: 64px;
  margin-bottom: 20px;
  color: #fda4af;
  font-size: 28px;
  font-weight: 700;
  background: rgba(251, 113, 133, 0.12);
  border: 1px solid rgba(251, 113, 133, 0.3);
  border-radius: 20px;
  place-items: center;
}

.error-detail {
  margin: -10px 0 0;
  color: rgba(159, 179, 196, 0.72);
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.5;
  word-break: break-word;
}

.video-layer {
  position: absolute;
  inset: 0;
  background: #000;
}

#video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  background: #000;
  object-fit: cover;
}

.video-shade {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(ellipse at 50% 42%, transparent 28%, rgba(0, 0, 0, 0.18) 66%, rgba(0, 0, 0, 0.55) 100%);
}

.frame-group {
  position: absolute;
  top: 42%;
  left: 50%;
  display: flex;
  flex-direction: column;
  align-items: center;
  width: min(72vw, 62vh, 340px);
  pointer-events: none;
  transform: translate(-50%, -50%);
}

.viewfinder {
  position: relative;
  width: 100%;
  aspect-ratio: 1;
  filter: drop-shadow(0 0 18px rgba(45, 212, 191, 0.12));
}

.corner {
  position: absolute;
  width: 16%;
  height: 16%;
  border: 3px solid #5eead4;
}

.corner.tl {
  top: 0;
  left: 0;
  border-right: 0;
  border-bottom: 0;
  border-top-left-radius: 16px;
}

.corner.tr {
  top: 0;
  right: 0;
  border-bottom: 0;
  border-left: 0;
  border-top-right-radius: 16px;
}

.corner.bl {
  bottom: 0;
  left: 0;
  border-top: 0;
  border-right: 0;
  border-bottom-left-radius: 16px;
}

.corner.br {
  right: 0;
  bottom: 0;
  border-top: 0;
  border-left: 0;
  border-bottom-right-radius: 16px;
}

.scanline {
  position: absolute;
  top: 8%;
  right: 6%;
  left: 6%;
  height: 2px;
  background: linear-gradient(90deg, transparent, rgba(94, 234, 212, 0.85), transparent);
  border-radius: 2px;
  box-shadow: 0 0 12px rgba(94, 234, 212, 0.55);
  animation: scan 2.6s ease-in-out infinite alternate;
}

@keyframes scan {
  from {
    top: 8%;
  }
  to {
    top: 90%;
  }
}

.scan-hint {
  margin: 16px 0 0;
  padding: 8px 14px;
  color: #e6f5f3;
  font-size: 14px;
  letter-spacing: 0.02em;
  white-space: nowrap;
  background: rgba(4, 10, 16, 0.55);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: var(--radius-pill);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
}

.camera-bar {
  position: absolute;
  right: 0;
  bottom: 0;
  left: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  padding: 14px max(16px, env(safe-area-inset-right)) calc(14px + env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  background: linear-gradient(to top, rgba(4, 10, 16, 0.9), rgba(4, 10, 16, 0));
}

.ctl {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 46px;
  padding: 10px 15px;
  color: #f4fbfa;
  font-size: 13px;
  font-weight: 550;
  white-space: nowrap;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: var(--radius-pill);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  transition: background 0.12s ease, border-color 0.12s ease, transform 0.12s ease;
}

.ctl:active {
  transform: scale(0.97);
}

.ctl-icon {
  width: 18px;
  height: 18px;
}

.ctl.is-on {
  color: #04201c;
  background: var(--accent);
  border-color: var(--accent);
}

.ctl-stop {
  color: #fecdd3;
}

.busy {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 24px;
  color: var(--text);
  text-align: center;
  background: rgba(4, 10, 16, 0.74);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
}

.busy p {
  margin: 0;
  color: #d7e6ee;
  font-size: 14px;
  line-height: 1.5;
}

.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid rgba(255, 255, 255, 0.16);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

.noscript {
  margin: 24px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.6;
  text-align: center;
}

@media (min-width: 560px) {
  .actions {
    flex-direction: row;
    flex-wrap: wrap;
  }

  .actions .btn {
    flex: 1 1 160px;
  }

  .actions .btn-text {
    flex: 0 0 auto;
  }
}

@media (max-height: 560px) and (orientation: landscape) {
  .topbar {
    padding-top: 10px;
    padding-bottom: 4px;
  }

  .frame-group {
    top: 50%;
    width: min(48vh, 300px);
  }

  .scan-hint {
    display: none;
  }

  .camera-bar {
    padding-top: 8px;
    padding-bottom: calc(8px + env(safe-area-inset-bottom));
  }

  .result-content {
    max-height: 30vh;
  }
}

@media (prefers-reduced-motion: reduce) {
  .scanline {
    top: 50%;
    animation: none;
  }

  .spinner {
    animation-duration: 2s;
  }

  .btn,
  .ctl {
    transition: none;
  }
}
