/* ─── Reset ──────────────────────────────────────────────── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

button {
  font-family: inherit;
  cursor: pointer;
}

input {
  font-family: inherit;
}

/* ─── CSS Variables: Light theme ─────────────────────────── */
:root {
  --c-primary: #3B5BFE;
  --c-primary-dark: #2A48E0;
  --c-primary-grad: linear-gradient(160deg, #4D7BFF 0%, #3B5BFE 55%, #2E47D6 100%);
  --c-primary-soft: #EEF2FF;
  --c-bg: #F4F6FA;
  --c-card: #FFFFFF;
  --c-card-alt: #F7F8FC;
  --c-line: #EEF0F4;
  --c-line-dashed: rgba(0, 0, 0, 0.07);
  --c-text: #1F2330;
  --c-muted: #7A8295;
  --c-faint: #A8AFBE;
  --c-tip-fg: #4A5160;
  --c-input-bg: #FAFBFD;
  --c-tab-bg: #F1F3F8;
  --c-ok: #22C55E;
  --c-ok-bg: #E8F8EE;
  --c-err: #EF4444;
  --c-err-bg: #FEECEC;
  --c-warn: #F59E0B;
  --c-warn-bg: #FEF4E2;
  --c-plant: #10B981;
  --c-plant-bg: #ECFDF5;
  --c-proc: #3B82F6;
  --c-proc-bg: #EFF6FF;
  --c-dist: #8B5CF6;
  --c-dist-bg: #F5F3FF;
  --c-shadow-card: 0 2px 10px rgba(28, 40, 75, 0.05);
  --c-shadow-btn: 0 6px 18px rgba(59, 91, 254, 0.32);
  --c-shadow-ok: 0 6px 18px rgba(34, 197, 94, 0.25);
  --c-shadow-err: 0 6px 18px rgba(239, 68, 68, 0.25);
  --c-shadow-warn: 0 6px 18px rgba(245, 158, 11, 0.25);
  --c-card-border: 1px solid rgba(28, 40, 75, 0.04);
  --c-bottom-fade: linear-gradient(180deg, rgba(244, 246, 250, 0) 0%, #F4F6FA 30%);
  --c-reset-btn: #E9ECF2;
  --c-reset-btn-fg: #4A5160;
  --c-timeline-grad: linear-gradient(180deg, #10B981 0%, #3B82F6 50%, #8B5CF6 100%);
}

/* ─── CSS Variables: Dark theme ──────────────────────────── */
[data-theme="dark"] {
  --c-primary: #5B7BFF;
  --c-primary-dark: #3B5BFE;
  --c-primary-grad: linear-gradient(160deg, #4F70F0 0%, #3553D8 55%, #1F32A8 100%);
  --c-primary-soft: rgba(91, 123, 255, 0.15);
  --c-bg: #0E1116;
  --c-card: #181C25;
  --c-card-alt: #222632;
  --c-line: rgba(255, 255, 255, 0.06);
  --c-line-dashed: rgba(255, 255, 255, 0.10);
  --c-text: #E8EAF0;
  --c-muted: #8D94A6;
  --c-faint: #5A6172;
  --c-tip-fg: #B6BCC9;
  --c-input-bg: #222632;
  --c-tab-bg: rgba(255, 255, 255, 0.05);
  --c-ok: #34D17B;
  --c-ok-bg: rgba(52, 209, 123, 0.14);
  --c-err: #F87171;
  --c-err-bg: rgba(248, 113, 113, 0.14);
  --c-warn: #FBBF24;
  --c-warn-bg: rgba(251, 191, 36, 0.14);
  --c-plant: #34D399;
  --c-plant-bg: rgba(52, 211, 153, 0.12);
  --c-proc: #60A5FA;
  --c-proc-bg: rgba(96, 165, 250, 0.12);
  --c-dist: #A78BFA;
  --c-dist-bg: rgba(167, 139, 250, 0.14);
  --c-shadow-card: 0 2px 12px rgba(0, 0, 0, 0.35);
  --c-shadow-btn: 0 6px 18px rgba(91, 123, 255, 0.45);
  --c-shadow-ok: 0 6px 18px rgba(52, 209, 123, 0.30);
  --c-shadow-err: 0 6px 18px rgba(248, 113, 113, 0.30);
  --c-shadow-warn: 0 6px 18px rgba(251, 191, 36, 0.30);
  --c-card-border: 1px solid rgba(255, 255, 255, 0.05);
  --c-bottom-fade: linear-gradient(180deg, rgba(14, 17, 22, 0) 0%, #0E1116 30%);
  --c-reset-btn: rgba(255, 255, 255, 0.08);
  --c-reset-btn-fg: #C9CEDB;
  --c-timeline-grad: linear-gradient(180deg, #34D399 0%, #60A5FA 50%, #A78BFA 100%);
}

/* ─── Animations ─────────────────────────────────────────── */
@keyframes scanLine {
  0%   { top: 8px; }
  100% { top: calc(100% - 10px); }
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

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

/* ─── Base ───────────────────────────────────────────────── */
html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: -apple-system, "PingFang SC", "Hiragino Sans GB", system-ui, sans-serif;
  background: var(--c-bg);
  color: var(--c-text);
  font-size: 14px;
  line-height: 1.5;
  min-height: 100vh;
  transition: background 0.25s, color 0.25s;
}

#app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
  position: relative;
}

/* ─── Page wrapper ───────────────────────────────────────── */
.page {
  min-height: 100vh;
  animation: fadeIn 0.25s ease;
}

/* ─── Header ─────────────────────────────────────────────── */
.header {
  background: var(--c-primary-grad);
  color: #fff;
  border-radius: 0 0 22px 22px;
  position: relative;
  overflow: hidden;
}

.header--full {
  padding: 44px 16px 36px;
}

.header--compact {
  padding: 34px 16px 26px;
}

.header__deco-1 {
  position: absolute;
  top: -40px;
  right: -30px;
  width: 160px;
  height: 160px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.10);
  pointer-events: none;
}

.header__deco-2 {
  position: absolute;
  bottom: -50px;
  left: -20px;
  width: 120px;
  height: 120px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.08);
  pointer-events: none;
}

.header__inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  position: relative;
  z-index: 1;
}

.header__badge {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.22);
  border: 1px solid rgba(255, 255, 255, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  margin-bottom: 12px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.18);
}

.header__title {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: 1px;
}

.header__sub {
  font-size: 12px;
  opacity: 0.85;
  margin-top: 6px;
  letter-spacing: 2px;
}

/* ─── Card ───────────────────────────────────────────────── */
.card {
  background: var(--c-card);
  border-radius: 14px;
  padding: 16px;
  box-shadow: var(--c-shadow-card);
  border: var(--c-card-border);
  transition: background 0.25s;
}

/* ─── Section title ──────────────────────────────────────── */
.section-title {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 14px;
}

.section-title__text {
  font-size: 15px;
  font-weight: 700;
  color: var(--c-text);
}

/* ─── Tab switch ─────────────────────────────────────────── */
.tab-switch {
  display: flex;
  gap: 6px;
  padding: 4px;
  background: var(--c-tab-bg);
  border-radius: 10px;
}

.tab-btn {
  flex: 1;
  border: 0;
  background: transparent;
  color: var(--c-muted);
  padding: 10px 0;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: background 0.2s, color 0.2s, box-shadow 0.2s;
}

.tab-btn.active {
  background: var(--c-primary);
  color: #fff;
  box-shadow: 0 2px 6px rgba(59, 91, 254, 0.25);
}

/* ─── Input field ────────────────────────────────────────── */
.input-field {
  width: 100%;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1.5px solid var(--c-line);
  background: var(--c-input-bg);
  font-size: 14px;
  color: var(--c-text);
  outline: none;
  font-family: inherit;
  transition: border-color 0.2s, background 0.25s;
  -webkit-appearance: none;
  appearance: none;
}

.input-field:focus {
  border-color: var(--c-primary);
}

.input-field.error {
  border-color: var(--c-err);
}

.input-field--code {
  text-align: center;
  font-size: 22px;
  letter-spacing: 10px;
  font-weight: 600;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
}

/* ─── Error message ──────────────────────────────────────── */
.error-msg {
  font-size: 12px;
  color: var(--c-err);
  margin-top: 5px;
}

/* ─── Input hint ─────────────────────────────────────────── */
.input-hint {
  font-size: 11px;
  color: var(--c-faint);
  margin-top: 6px;
}

/* ─── Form label ─────────────────────────────────────────── */
.form-label {
  font-size: 13px;
  color: var(--c-text);
  font-weight: 500;
  margin-bottom: 8px;
  display: block;
}

/* ─── Primary button ─────────────────────────────────────── */
.primary-btn {
  width: 100%;
  border: 0;
  background: var(--c-primary-grad);
  color: #fff;
  font-weight: 600;
  font-size: 15px;
  padding: 14px 0;
  border-radius: 12px;
  box-shadow: var(--c-shadow-btn);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: opacity 0.2s, transform 0.1s;
  cursor: pointer;
}

.primary-btn:active {
  transform: scale(0.98);
}

.primary-btn:disabled {
  background: var(--c-line);
  color: var(--c-faint);
  box-shadow: none;
  cursor: not-allowed;
}

/* ─── Scan box ───────────────────────────────────────────── */
.scan-box {
  margin-top: 14px;
  border: 1.5px dashed var(--c-primary);
  border-radius: 12px;
  padding: 34px 0;
  text-align: center;
  background: var(--c-primary-soft);
  cursor: pointer;
  position: relative;
  overflow: hidden;
  transition: background 0.25s;
}

.scan-box__icon-wrap {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 76px;
  height: 76px;
  border-radius: 18px;
  background: var(--c-primary-soft);
  margin-bottom: 14px;
  position: relative;
}

.scan-line {
  position: absolute;
  left: 8px;
  right: 8px;
  height: 2px;
  background: var(--c-primary);
  border-radius: 2px;
  box-shadow: 0 0 8px var(--c-primary);
  animation: scanLine 1.4s linear infinite alternate;
}

/* ─── 摄像头扫码视图 ─────────────────────────────────────── */
.scan-box--camera {
  padding: 0;
  height: 260px;
  background: #000;
  border-color: var(--c-primary);
  cursor: default;
  position: relative;
  overflow: hidden;
}

.scan-video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.scan-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

.scan-frame {
  width: 180px;
  height: 180px;
  border-radius: 12px;
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.45);
  position: relative;
}

/* 四角标记 */
.scan-frame::before,
.scan-frame::after {
  content: '';
  position: absolute;
  width: 24px;
  height: 24px;
  border-color: #fff;
  border-style: solid;
}
.scan-frame::before {
  top: -2px;
  left: -2px;
  border-width: 3px 0 0 3px;
  border-radius: 4px 0 0 0;
}
.scan-frame::after {
  bottom: -2px;
  right: -2px;
  border-width: 0 3px 3px 0;
  border-radius: 0 0 4px 0;
}

.scan-hint {
  color: rgba(255, 255, 255, 0.85);
  font-size: 12px;
  margin-top: 14px;
  letter-spacing: 0.5px;
}

.scan-close-btn {
  position: absolute;
  top: 10px;
  right: 10px;
  background: rgba(0, 0, 0, 0.5);
  color: #fff;
  border: 0;
  border-radius: 16px;
  padding: 5px 12px;
  font-size: 12px;
  cursor: pointer;
  z-index: 10;
  font-family: inherit;
}

/* ─── 微信环境引导 ───────────────────────────────────────── */
.scan-box--wechat {
  border-color: var(--c-warn);
  background: var(--c-warn-bg);
  cursor: default;
  padding: 28px 20px;
}

.scan-box--wechat .scan-box__icon-wrap {
  background: var(--c-warn-bg);
}

.wechat-guide {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 12px;
  text-align: left;
}

.wechat-guide__step {
  font-size: 13px;
  color: var(--c-tip-fg);
  line-height: 1.6;
}

.scan-box__title {
  font-size: 15px;
  font-weight: 600;
  color: var(--c-text);
}

.scan-box__sub {
  font-size: 12px;
  color: var(--c-faint);
  margin-top: 6px;
}

/* ─── Stat grid ──────────────────────────────────────────── */
.stat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 18px;
}

.stat-item {
  background: var(--c-card-alt);
  border-radius: 10px;
  padding: 12px 0;
  text-align: center;
}

.stat-item__n {
  font-size: 24px;
  font-weight: 700;
  color: var(--c-primary);
  line-height: 1.1;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
}

.stat-item__label {
  font-size: 11.5px;
  color: var(--c-muted);
  margin-top: 6px;
}

/* ─── Verified block ─────────────────────────────────────── */
.verified-block {
  text-align: center;
  padding: 22px 16px 18px;
}

.verified-block__outer {
  width: 62px;
  height: 62px;
  margin: 0 auto;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.verified-block__inner {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.verified-block__title {
  font-size: 18px;
  font-weight: 700;
  color: var(--c-text);
  margin-top: 12px;
}

.verified-block__sub {
  font-size: 12px;
  color: var(--c-muted);
  margin-top: 6px;
  padding: 0 12px;
  line-height: 1.5;
}

.verified-block__note {
  margin-top: 14px;
  border-radius: 10px;
  padding: 10px 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-size: 12.5px;
  font-weight: 500;
}

/* ─── Product info rows ──────────────────────────────────── */
.info-rows {
  display: flex;
  flex-direction: column;
}

.info-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 11px 0;
  border-top: 1px dashed var(--c-line-dashed);
  gap: 14px;
}

.info-row:first-child {
  border-top: none;
  padding-top: 0;
}

.info-row__key {
  font-size: 13px;
  color: var(--c-muted);
  flex-shrink: 0;
}

.info-row__val {
  font-size: 13px;
  color: var(--c-text);
  font-weight: 500;
  text-align: right;
}

/* ─── Chain timeline ─────────────────────────────────────── */
.chain-timeline {
  position: relative;
  padding-left: 22px;
}

.chain-timeline__line {
  position: absolute;
  left: 6.5px;
  top: 6px;
  bottom: 6px;
  width: 2px;
  background: var(--c-timeline-grad);
  border-radius: 2px;
  opacity: 0.45;
}

.chain-stage {
  position: relative;
  margin-bottom: 16px;
}

.chain-stage:last-child {
  margin-bottom: 0;
}

.chain-stage__node {
  position: absolute;
  left: -22px;
  top: 4px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 3px solid;
  background: var(--c-card);
}

/* ─── Stage card ─────────────────────────────────────────── */
.stage-card {
  border-radius: 10px;
  padding: 12px 14px;
  border-left: 3px solid;
}

.stage-card.pending {
  opacity: 0.75;
}

.stage-card__header {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 4px;
}

.stage-card__title {
  font-size: 14px;
  font-weight: 700;
  color: var(--c-text);
}

.stage-card__pending-tag {
  font-size: 11px;
  color: var(--c-faint);
  font-weight: 500;
  margin-left: 8px;
}

.stage-card__sub {
  font-size: 11.5px;
  color: var(--c-muted);
  margin-bottom: 10px;
}

.stage-card__fields {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.stage-card__field {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.stage-card__field-key {
  font-size: 12px;
  color: var(--c-muted);
  flex-shrink: 0;
}

.stage-card__field-val {
  font-size: 12px;
  color: var(--c-text);
  font-weight: 500;
  text-align: right;
}

.stage-card__pending-text {
  font-size: 12px;
  color: var(--c-muted);
  line-height: 1.6;
}

.stage-card__hash {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px dashed var(--c-line-dashed);
  font-size: 11px;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}
.hash-copy-btn {
  display: inline-flex;
  align-items: center;
  background: none;
  border: none;
  padding: 2px;
  cursor: pointer;
  opacity: 0.85;
  flex-shrink: 0;
  line-height: 1;
}
.hash-copy-btn:active {
  opacity: 0.6;
}

/* ─── Blockchain block rows ──────────────────────────────── */
.blockchain-rows {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.blockchain-row__label {
  font-size: 12px;
  color: var(--c-muted);
  margin-bottom: 4px;
}

.blockchain-row__val {
  font-size: 13.5px;
  color: var(--c-text);
  font-weight: 500;
}

.blockchain-row__val--mono {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
}

.blockchain-row__val--hash {
  font-size: 12px;
  word-break: break-all;
  background: var(--c-card-alt);
  padding: 8px 10px;
  border-radius: 6px;
  line-height: 1.6;
}

/* ─── Safety tips ────────────────────────────────────────── */
.safety-tips {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.safety-tip {
  display: flex;
  align-items: flex-start;
  gap: 8px;
}

.safety-tip__icon {
  margin-top: 1px;
  flex-shrink: 0;
}

.safety-tip__text {
  font-size: 12.5px;
  color: var(--c-tip-fg);
  line-height: 1.55;
}

/* ─── Bottom bar ─────────────────────────────────────────── */
.bottom-bar {
  position: sticky;
  bottom: 0;
  background: var(--c-bottom-fade);
  padding: 16px 16px 18px;
  display: flex;
  gap: 10px;
  /* safe area */
  padding-bottom: calc(18px + env(safe-area-inset-bottom, 0px));
}

/* ─── Action button ──────────────────────────────────────── */
.action-btn {
  flex: 1;
  border: 0;
  font-size: 14px;
  font-weight: 600;
  padding: 12px 0;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.10);
  cursor: pointer;
  transition: opacity 0.15s, transform 0.1s;
}

.action-btn:active {
  transform: scale(0.97);
}

/* ─── How-to steps ───────────────────────────────────────── */
.howto-steps {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.howto-step {
  display: flex;
  align-items: flex-start;
  gap: 10px;
}

.howto-step__num {
  flex-shrink: 0;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--c-primary);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}

.howto-step__text {
  font-size: 13px;
  color: var(--c-tip-fg);
  line-height: 1.55;
  padding-top: 2px;
}

/* ─── Network error view ─────────────────────────────────── */
.net-error-view {
  min-height: 600px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 0 40px;
  gap: 16px;
}

.net-error-view__icon-wrap {
  width: 96px;
  height: 96px;
  border-radius: 50%;
  background: var(--c-err-bg);
  display: flex;
  align-items: center;
  justify-content: center;
}

.net-error-view__title {
  font-size: 18px;
  font-weight: 700;
  color: var(--c-text);
}

.net-error-view__desc {
  font-size: 13px;
  color: var(--c-muted);
  line-height: 1.6;
}

.net-error-view__btn {
  margin-top: 8px;
  padding: 11px 28px;
  border: 0;
  background: var(--c-primary);
  color: #fff;
  font-weight: 600;
  font-size: 14px;
  border-radius: 22px;
  box-shadow: var(--c-shadow-btn);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  transition: opacity 0.2s;
}

.net-error-view__btn:active {
  opacity: 0.85;
}

/* ─── Page content wrapper ───────────────────────────────── */
.page-content {
  padding: 0 16px 100px;
  margin-top: -16px;
}

.cards-stack {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 0 16px;
  padding-bottom: 100px;
  margin-top: -16px;
}

/* ─── Result page scroll wrapper ─────────────────────────── */
.result-page {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.result-scroll {
  flex: 1;
  overflow-y: auto;
}

/* ─── Dashed separator ───────────────────────────────────── */
.dashed-sep {
  border: none;
  border-top: 1px dashed var(--c-line-dashed);
}

/* ─── Utility ────────────────────────────────────────────── */
.mono {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
}

/* ─── Safe area support ──────────────────────────────────── */
@supports (padding: env(safe-area-inset-bottom)) {
  .header--full {
    padding-top: calc(44px + env(safe-area-inset-top, 0px));
  }
  .header--compact {
    padding-top: calc(34px + env(safe-area-inset-top, 0px));
  }
}
