:root {
  --bg: #000;
  --fg: #f5f5f7;
  --muted: rgba(245, 245, 247, 0.56);
  --accent: #0a84ff;
  --card: #fff;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", system-ui, sans-serif;
  overscroll-behavior: none;
}

body { overflow: hidden; }

.app {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  padding: calc(var(--safe-top) + 14px) 18px calc(var(--safe-bottom) + 14px);
  background: radial-gradient(120% 80% at 50% 0%, #14141a 0%, #000 62%);
}

/* ---------------------------------------------------------------- 顶栏 */
.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  transition: opacity 0.25s ease, transform 0.25s ease;
}
.title-wrap h1 {
  margin: 0;
  font-size: 17px;
  font-weight: 600;
  letter-spacing: 0.02em;
}
.status {
  margin: 4px 0 0;
  font-size: 12.5px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.status .dot {
  display: inline-block;
  width: 6px;
  height: 6px;
  margin-right: 6px;
  border-radius: 50%;
  background: #30d158;
  vertical-align: 1px;
}
.status .dot.stale { background: #ff9f0a; }
.status .dot.error { background: #ff453a; }

.icon-btn {
  flex: none;
  width: 38px;
  height: 38px;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.08);
  color: var(--fg);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
}
.icon-btn:active { background: rgba(255, 255, 255, 0.16); }
.icon-btn svg { display: block; margin: 0 auto; }

/* ---------------------------------------------------------------- 舞台 */
.stage {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
  padding: 10px 0;
}

.card {
  position: relative;
  width: min(92vw, 74vh);
  max-width: 620px;
  aspect-ratio: 1 / 1;
  border-radius: 22px;
  background: var(--card);
  box-shadow: 0 18px 60px rgba(0, 0, 0, 0.55), 0 0 0 1px rgba(255, 255, 255, 0.06);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

#qr {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  opacity: 0;
  transition: opacity 0.2s ease;
  user-select: none;
}
#qr.ready { opacity: 1; }

.shimmer {
  position: absolute;
  inset: 0;
  background: linear-gradient(100deg, #f2f2f4 30%, #ffffff 48%, #f2f2f4 66%);
  background-size: 220% 100%;
  animation: shimmer 1.25s linear infinite;
}
.shimmer[hidden] { display: none; }
@keyframes shimmer {
  from { background-position: 130% 0; }
  to { background-position: -30% 0; }
}

.error {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 22px;
  background: #fff;
  color: #1c1c1e;
  text-align: center;
}
.error[hidden] { display: none; }
.error-icon { font-size: 30px; color: #ff9f0a; }
.error p { margin: 0; font-size: 14px; line-height: 1.5; color: #3a3a3c; word-break: break-word; }

/* ---------------------------------------------------------------- 底栏 */
.bottombar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  transition: opacity 0.25s ease, transform 0.25s ease;
}

.btn {
  appearance: none;
  border: 0;
  border-radius: 999px;
  padding: 13px 26px;
  font-size: 15px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: transform 0.12s ease, opacity 0.12s ease;
}
.btn:active { transform: scale(0.97); opacity: 0.85; }
.btn.primary { background: var(--accent); color: #fff; }
.btn.ghost { background: rgba(255, 255, 255, 0.1); color: var(--fg); }

/* 闲置时收起上下栏 */
.app.idle .topbar,
.app.idle .bottombar {
  opacity: 0;
  pointer-events: none;
  transform: translateY(-4px);
}
.app.idle .bottombar { transform: translateY(4px); }

/* ---------------------------------------------------------------- toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--safe-bottom) + 96px);
  transform: translate(-50%, 12px);
  padding: 10px 16px;
  border-radius: 999px;
  background: rgba(40, 40, 46, 0.92);
  color: #fff;
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  max-width: 80vw;
  text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------------------------------------------------------------- 保存预览层 */
.sheet {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(0, 0, 0, 0.92);
  backdrop-filter: blur(6px);
}
.sheet[hidden] { display: none; }
.sheet-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  max-width: 100%;
  max-height: 100%;
}
.sheet-inner img {
  max-width: min(92vw, 70vh);
  max-height: 70vh;
  border-radius: 12px;
  background: #fff;
}
.sheet-inner p { margin: 0; font-size: 13px; color: var(--muted); }

@media (prefers-reduced-motion: reduce) {
  .shimmer { animation: none; }
  * { transition: none !important; }
}