:root {
  color-scheme: dark;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
  background: #090909;
  color: #fff;
  letter-spacing: 0;
  --safe-top: max(18px, env(safe-area-inset-top));
  --safe-bottom: max(22px, env(safe-area-inset-bottom));
  --yellow: #ffd93d;
  --ink: #0d0d0d;
}

* { box-sizing: border-box; }
html, body { width: 100%; height: 100%; margin: 0; overflow: hidden; background: #090909; }
button, input { font: inherit; letter-spacing: 0; }
button { -webkit-tap-highlight-color: transparent; }
.hidden { display: none !important; }

.app, .view { position: fixed; inset: 0; width: 100%; height: 100%; }
.view { display: none; background: #090909; overflow: hidden; }
.view.active { display: block; }
.camera-view video, .result-view > img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
/* Preview only: the capture canvas mirrors itself, so this must not apply there. */
.camera-view video.mirrored { transform: scaleX(-1); }

.camera-shade {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: linear-gradient(to bottom, rgba(0,0,0,.42), transparent 25%, transparent 62%, rgba(0,0,0,.7));
}

/* Neutral placeholder so a host that refuses getUserMedia never shows a black frame. */
.camera-status {
  position: absolute;
  z-index: 3;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 0 34px;
  text-align: center;
  background: linear-gradient(160deg, #2a2a30, #16161a 62%, #202027);
}
.camera-status span {
  max-width: 300px;
  font-size: 14px;
  font-weight: 620;
  line-height: 1.7;
  color: rgba(255,255,255,.9);
  text-shadow: 0 1px 10px rgba(0,0,0,.5);
  white-space: pre-line;
}
.camera-status[data-mode="fallback"] span,
.camera-status[data-mode="retry"] span,
.camera-status[data-mode="ready"] span { color: #fff; }
/* Entry gate: the authorization prompt needs a user gesture, so the toy opens on a
   full-screen call to action instead of hiding it behind the shutter. It covers the
   viewfinder and the shutter, but stays under the topbar so the gallery is reachable
   without granting the camera. */
.camera-gate {
  position: absolute;
  z-index: 7;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 0 32px calc(24px + var(--safe-bottom));
  text-align: center;
  background: linear-gradient(165deg, rgba(16,16,20,.94), rgba(9,9,9,.97));
}
.camera-gate h2 {
  margin: 0;
  font-size: 26px;
  font-weight: 800;
  line-height: 1.3;
}
.gate-hint {
  margin: 0 0 8px;
  max-width: 280px;
  color: rgba(255,255,255,.7);
  font-size: 14px;
  line-height: 1.6;
}
.gate-primary {
  width: min(100%, 300px);
  height: 54px;
  padding: 0 24px;
  border: 0;
  border-radius: 7px;
  background: var(--yellow);
  color: #111;
  font-size: 17px;
  font-weight: 760;
  cursor: pointer;
}
.gate-primary:active { transform: scale(.97); }
.gate-secondary {
  padding: 8px 12px;
  border: 0;
  background: transparent;
  color: rgba(255,255,255,.78);
  font-size: 14px;
  font-weight: 620;
  text-decoration: underline;
  cursor: pointer;
}
.gate-trust {
  padding: 4px 10px;
  border: 0;
  background: transparent;
  color: rgba(255,255,255,.62);
  font-size: 13px;
  text-decoration: underline;
  cursor: pointer;
}
.trust-layer {
  position: fixed;
  z-index: 30;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(0,0,0,.68);
}
.trust-box {
  width: min(100%, 340px);
  padding: 24px 20px 20px;
  border-radius: 14px;
  background: #f7f7f3;
  color: #181818;
  box-shadow: 0 18px 54px rgba(0,0,0,.38);
}
.trust-box h2 { margin: 0 0 14px; font-size: 21px; }
.trust-box p { margin: 0 0 12px; color: #4f4d47; font-size: 14px; line-height: 1.7; }
.trust-box .gate-primary { width: 100%; height: 48px; margin-top: 4px; }

.camera-view::after {
  content: "";
  position: absolute;
  z-index: 12;
  inset: 0;
  background: #fff;
  opacity: 0;
  pointer-events: none;
}
.camera-view.captured::after { animation: capture-flash .25s ease-out; }
@keyframes capture-flash { 0% { opacity: 0; } 30% { opacity: .82; } 100% { opacity: 0; } }

.topbar {
  position: absolute;
  z-index: 8;
  top: 0;
  left: 0;
  right: 0;
  height: calc(56px + var(--safe-top));
  padding: var(--safe-top) 20px 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.brand-logo { width: 26px; height: 26px; flex: none; display: block; }
.brand { display: flex; align-items: center; gap: 8px; font-size: 18px; line-height: 1; font-weight: 760; text-shadow: 0 1px 8px rgba(0,0,0,.55); }
.credits-label { font-size: 12px; font-weight: 600; color: rgba(255,255,255,.72); }
.topbar-actions { display: flex; align-items: center; gap: 8px; }
.model-name {
  height: 34px;
  padding: 0 12px;
  border-radius: 17px;
  display: flex;
  align-items: center;
  color: #fff;
  background: rgba(20,20,20,.42);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .2px;
}
.gallery-model {
  position: absolute;
  left: 6px;
  bottom: 6px;
  padding: 2px 7px;
  border-radius: 8px;
  background: rgba(0,0,0,.62);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .2px;
}
.top-icon-button {
  position: relative;
  width: 42px;
  height: 42px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: #fff;
  background: rgba(20,20,20,.42);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}
.top-icon-button svg { width: 21px; height: 21px; }
.top-entry-label { display: none; }
.top-icon-button.receiving { animation: library-receive .52s ease; }
@keyframes library-receive { 50% { transform: scale(1.16); background: rgba(255,217,61,.85); color: #111; } }
.gallery-count {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 19px;
  height: 19px;
  padding: 0 5px;
  border: 2px solid #111;
  border-radius: 10px;
  display: grid;
  place-items: center;
  background: var(--yellow);
  color: #111;
  font-size: 10px;
  font-weight: 800;
}

.focus-frame {
  position: absolute;
  z-index: 2;
  top: 50%;
  left: 50%;
  width: min(66vw, 310px);
  aspect-ratio: 1;
  transform: translate(-50%, -50%);
  opacity: .65;
  pointer-events: none;
}
.focus-frame span { position: absolute; width: 30px; height: 30px; border-color: rgba(255,255,255,.84); }
.focus-frame span:nth-child(1) { top: 0; left: 0; border-top: 2px solid; border-left: 2px solid; }
.focus-frame span:nth-child(2) { top: 0; right: 0; border-top: 2px solid; border-right: 2px solid; }
.focus-frame span:nth-child(3) { bottom: 0; left: 0; border-bottom: 2px solid; border-left: 2px solid; }
.focus-frame span:nth-child(4) { bottom: 0; right: 0; border-bottom: 2px solid; border-right: 2px solid; }

.camera-controls, .result-controls {
  position: absolute;
  z-index: 5;
  left: 0;
  right: 0;
  bottom: 0;
  min-height: calc(112px + var(--safe-bottom));
  padding: 18px max(28px, env(safe-area-inset-left)) var(--safe-bottom) max(28px, env(safe-area-inset-right));
  display: grid;
  grid-template-columns: 54px 86px 54px;
  justify-content: space-between;
  align-items: center;
}
.icon-button, .floating-button {
  width: 52px;
  height: 52px;
  padding: 0;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: rgba(20,20,20,.55);
  color: #fff;
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  cursor: pointer;
}
.icon-button svg, .floating-button svg { width: 23px; height: 23px; stroke-width: 2; }
.icon-button:active, .floating-button:active { transform: scale(.94); }
.icon-button.light { color: #101010; background: rgba(255,255,255,.92); }
.icon-button.dark { background: #1b1b1b; }
.shutter { width: 84px; height: 84px; padding: 6px; border: 3px solid #fff; border-radius: 50%; background: transparent; cursor: pointer; }
.shutter span { display: block; width: 100%; height: 100%; border-radius: 50%; background: #fff; transition: transform .12s, background .12s; }
.shutter:active span { transform: scale(.86); background: var(--yellow); }

.maintenance-notice {
  position: absolute;
  z-index: 9;
  left: 20px;
  right: 20px;
  top: calc(62px + var(--safe-top));
  padding: 10px 14px;
  border-radius: 10px;
  background: rgba(24,24,24,.86);
  color: rgba(255,255,255,.9);
  font-size: 13px;
  line-height: 1.5;
  text-align: center;
}

.library-flight {
  position: fixed;
  z-index: 50;
  border: 2px solid rgba(255,255,255,.9);
  border-radius: 5px;
  object-fit: cover;
  box-shadow: 0 12px 40px rgba(0,0,0,.45);
  pointer-events: none;
}

.result-view > img { object-fit: contain; background: #080808; opacity: 1; transition: opacity .16s ease; }
.result-view > img.loading { opacity: 0; }
.result-loading { position: absolute; z-index: 4; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; pointer-events: none; }
/* 四帧雪碇图：用 steps() 逐帧跳转，避免补间模糊 */
.working-sprite { width: 128px; height: 128px; background-image: url("art/working.png"); background-repeat: no-repeat; background-size: 512px 128px; background-position: 0 0; animation: working-frames .72s steps(4) infinite; filter: drop-shadow(0 8px 18px rgba(0,0,0,.45)); }
@keyframes working-frames { to { background-position: -512px 0; } }
.working-label { font-size: 14px; font-weight: 650; color: rgba(255,255,255,.92); text-shadow: 0 1px 6px rgba(0,0,0,.6); letter-spacing: .3px; }
.working-sprite.small { width: 64px; height: 64px; background-size: 256px 64px; animation-name: working-frames-sm; filter: none; }
@keyframes working-frames-sm { to { background-position: -256px 0; } }
@media (prefers-reduced-motion: reduce) { .working-sprite { animation: none; } }
.result-shade { position: absolute; inset: 0; background: linear-gradient(to bottom, rgba(0,0,0,.36), transparent 28%, transparent 68%, rgba(0,0,0,.62)); pointer-events: none; }
.floating-button { position: absolute; z-index: 5; }
.top-left { top: var(--safe-top); left: max(18px, env(safe-area-inset-left)); }
.result-controls { grid-template-columns: 54px minmax(140px, 190px) 54px; }
.primary-action { height: 54px; padding: 0 24px; border: 0; border-radius: 7px; display: flex; align-items: center; justify-content: center; gap: 9px; background: var(--yellow); color: #111; font-size: 16px; font-weight: 760; cursor: pointer; }
.primary-action svg { width: 21px; height: 21px; }
.primary-action:active { transform: scale(.97); }

.rewards-panel {
  position: fixed;
  z-index: 12;
  inset: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: calc(var(--safe-top) + 12px) 20px calc(var(--safe-bottom) + 20px);
  background: #f2f2ef;
  color: #111;
  overflow-y: auto;
}
.rewards-header { display: flex; align-items: center; justify-content: space-between; }
.rewards-header h1 { margin: 0; font-size: 20px; font-weight: 800; }
.rewards-hint { margin: 0; color: #555; font-size: 13px; }
/* Issue #23 充电回馈常驻卡：故意与 .reward-card 拉开视觉差异（黄底、
   标题块），避免被当成一条普通任务。 */
.charge-reward-card {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 16px;
  border: 1px solid #e2c86a;
  border-radius: 14px;
  background: linear-gradient(180deg, #fff7d9, #fffdf3);
}
.charge-reward-title { margin: 0; font-size: 17px; font-weight: 800; }
.charge-reward-desc { margin: 0; color: #6b5a1e; font-size: 13px; line-height: 1.5; }
.charge-reward-status { margin: 0; color: #444; font-size: 13px; line-height: 1.5; }
.charge-reward-status:empty { display: none; }
.charge-reward-actions { display: flex; gap: 8px; }
.charge-reward-button {
  min-width: 108px;
  height: 42px;
  padding: 0 16px;
  border: 0;
  border-radius: 8px;
  background: var(--yellow);
  color: #111;
  font-size: 14px;
  font-weight: 760;
  cursor: pointer;
}
.charge-reward-button.ghost { background: #fff; border: 1px solid #d8cca0; color: #4a422a; }
.charge-reward-button:disabled { opacity: .55; cursor: default; }
.charge-reward-card[data-charge-state="charging"] { border-color: #4a9b6b; }

.rewards-list { display: flex; flex-direction: column; gap: 10px; }
.reward-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px;
  border: 1px solid #ddd;
  border-radius: 12px;
  background: #fff;
}
.reward-card-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.reward-card-title { font-size: 15px; font-weight: 700; }
.reward-card-reward { color: #7a5b00; font-size: 13px; font-weight: 700; }
.reward-card-status { color: #666; font-size: 12px; }
.reward-card-actions { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.reward-button {
  min-width: 84px;
  height: 38px;
  padding: 0 14px;
  border: 0;
  border-radius: 8px;
  background: var(--yellow);
  color: #111;
  font-size: 14px;
  font-weight: 760;
  cursor: pointer;
}
.reward-card-actions .reward-button { min-width: 72px; padding: 0 12px; }
.reward-button.ghost { background: #ececE6; color: #333; }
.reward-button:disabled { opacity: .5; cursor: default; }
.reward-card[data-state="claimed"] { opacity: .72; }
.rewards-empty { margin: 0; color: #666; font-size: 13px; text-align: center; }
.load-error {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 10px 12px 0;
  padding: 10px 12px;
  border: 1px solid #e0b4ad;
  border-radius: 9px;
  background: #fff1ef;
  color: #8a2720;
  font-size: 13px;
  line-height: 1.45;
}
.load-error button {
  flex: none;
  min-width: 60px;
  height: 34px;
  padding: 0 12px;
  border: 0;
  border-radius: 7px;
  background: #8a2720;
  color: #fff;
  font-weight: 700;
  cursor: pointer;
}
.rewards-panel > .load-error { margin: 0; }
/* 骨架屏：形状与 .reward-card 一一对应（图标位 + 标题行 + 按钮位），
   高度也对齐，数据到达时列表不会跳动。纯 CSS，无图片。 */
.rewards-skeleton { display: flex; flex-direction: column; gap: 10px; }
.reward-skeleton {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px;
  border: 1px solid #ddd;
  border-radius: 12px;
  background: #fff;
}
.skeleton-icon { width: 34px; height: 34px; border-radius: 10px; flex-shrink: 0; }
.skeleton-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 6px; }
.skeleton-line { height: 13px; border-radius: 5px; }
.skeleton-line.title { width: 46%; height: 15px; }
.skeleton-line:not(.title) { width: 30%; }
.skeleton-button { width: 72px; height: 38px; border-radius: 8px; flex-shrink: 0; }
/* 与 .mini-spinner 同一套语言：中性灰底 + 一道更亮的高光在其上匀速扫过。 */
.skeleton-icon, .skeleton-line, .skeleton-button {
  display: block;
  background: #ececE6;
  background-image: linear-gradient(90deg, #ececE6 0%, #f7f7f4 50%, #ececE6 100%);
  background-size: 220% 100%;
  animation: skeleton-sweep 1.2s linear infinite;
}
@keyframes skeleton-sweep { from { background-position: 120% 0; } to { background-position: -120% 0; } }

.gallery-dialog {
  position: fixed;
  inset: 0;
  width: 100%;
  max-width: none;
  height: 100%;
  max-height: none;
  margin: 0;
  padding: 0;
  border: 0;
  background: #f2f2ef;
  color: #111;
}
.gallery-dialog::backdrop { background: #000; }

/* Replaces window.confirm, which a cross-origin iframe host blocks outright. */
.confirm-layer {
  position: fixed;
  z-index: 20;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(0,0,0,.55);
}
.confirm-layer.hidden { display: none; }
.confirm-box {
  width: min(100%, 320px);
  padding: 22px 20px 16px;
  border-radius: 14px;
  background: #fff;
  box-shadow: 0 18px 48px rgba(0,0,0,.28);
}
.confirm-text {
  margin: 0 0 18px;
  color: #111;
  font-size: 15px;
  line-height: 1.55;
}
.confirm-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}
.confirm-cancel, .confirm-ok {
  min-width: 76px;
  height: 40px;
  padding: 0 16px;
  border: 0;
  border-radius: 8px;
  font-size: 15px;
  font-weight: 650;
  cursor: pointer;
}
.confirm-cancel { background: #ececec; color: #333; }
.confirm-ok { background: #e5484d; color: #fff; }
.confirm-cancel:active, .confirm-ok:active { transform: scale(.97); }
.gallery-header {
  position: sticky;
  z-index: 8;
  top: 0;
  min-height: calc(72px + var(--safe-top));
  padding: var(--safe-top) 18px 10px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(242,242,239,.93);
  border-bottom: 1px solid #ddd;
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
}
.gallery-header h1 { margin: 0; font-size: 22px; line-height: 1.2; }
.gallery-header-actions { display: flex; align-items: center; gap: 10px; }
.text-button {
  padding: 7px 12px;
  border: 1px solid #d8d4cc;
  border-radius: 999px;
  font-size: 13px;
  color: #55504a;
  background: transparent;
  cursor: pointer;
}
.text-button.danger { color: #b3261e; border-color: rgba(179,38,30,.32); }
.text-button:active { transform: scale(.96); }
.gallery-grid {
  padding: 10px 10px calc(24px + var(--safe-bottom));
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}
.gallery-item {
  position: relative;
  width: 100%;
  padding: 0;
  border: 0;
  border-radius: 5px;
  aspect-ratio: 3 / 4;
  overflow: hidden;
  background: #d9d9d5;
  display: block;
}
.gallery-item-main { width: 100%; height: 100%; padding: 0; border: 0; display: block; background: transparent; cursor: pointer; }
.gallery-item-main > img { width: 100%; height: 100%; object-fit: cover; display: block; }
.gallery-state { position: absolute; z-index: 2; inset: 0; padding: 18px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 9px; background: rgba(0,0,0,.58); color: #fff; font-size: 12px; font-weight: 700; }
.gallery-state svg { width: 25px; height: 25px; }
.gallery-error { width: 100%; display: -webkit-box; overflow: hidden; -webkit-box-orient: vertical; -webkit-line-clamp: 3; line-height: 1.45; text-align: center; overflow-wrap: anywhere; }
.retry-job { position: absolute; z-index: 4; right: 10px; bottom: 10px; width: 40px; height: 40px; padding: 0; border: 0; border-radius: 50%; display: grid; place-items: center; color: #111; background: var(--yellow); box-shadow: 0 3px 14px rgba(0,0,0,.3); cursor: pointer; }
.retry-job svg { width: 19px; height: 19px; }
.retry-job:active { transform: scale(.94); }
.gallery-quota-link { position: absolute; z-index: 4; left: 10px; bottom: 10px; padding: 6px 10px; border: 0; border-radius: 5px; background: var(--yellow); color: #111; font-size: 12px; font-weight: 760; cursor: pointer; }
.gallery-quota-link:active { transform: scale(.94); }
.delete-job {
  position: absolute;
  z-index: 5;
  right: 6px;
  top: 6px;
  width: 28px;
  height: 28px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 15px;
  line-height: 1;
  color: #fff;
  background: rgba(0,0,0,.52);
  cursor: pointer;
}
.delete-job:active { transform: scale(.92); }
.mini-spinner { width: 26px; height: 26px; border: 2px solid rgba(255,255,255,.3); border-top-color: #fff; border-radius: 50%; animation: spin .85s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
/* 顶部细进度条：绝对定位在 sticky 头部下沿，脱离文档流也不占高度，
   因此绝不遮挡刚拍的本地照片。 */
.gallery-progress {
  position: absolute;
  z-index: 9;
  left: 0;
  right: 0;
  bottom: -1px;
  height: 2px;
  overflow: hidden;
  background: rgba(17,17,17,.08);
  pointer-events: none;
}
.gallery-progress::after {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  width: 40%;
  background: var(--yellow);
  animation: gallery-progress-slide 1.1s linear infinite;
}
@keyframes gallery-progress-slide {
  from { transform: translateX(-100%); }
  to { transform: translateX(250%); }
}
.empty-gallery { min-height: 60vh; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; color: #777; }
.empty-gallery svg { width: 34px; height: 34px; }
.empty-art { width: 142px; height: auto; margin-bottom: 4px; }
.empty-title { font-size: 16px; font-weight: 700; color: #3d3a33; }
.empty-hint { font-size: 13px; color: #9a948a; }

.toast {
  position: fixed;
  z-index: 60;
  left: 50%;
  bottom: calc(132px + var(--safe-bottom));
  max-width: min(86vw, 360px);
  padding: 11px 15px;
  border-radius: 6px;
  color: #fff;
  background: rgba(16,16,16,.92);
  text-align: center;
  font-size: 14px;
  opacity: 0;
  transform: translate(-50%, 8px);
  pointer-events: none;
  transition: opacity .2s, transform .2s;
}
.toast.visible { opacity: 1; transform: translate(-50%, 0); }
/* 带按钮的 toast 才收事件；纯提示保持 pointer-events:none，不挡取景与快门。 */
.toast.with-action {
  display: flex;
  align-items: center;
  gap: 10px;
  text-align: left;
  padding-right: 8px;
}
.toast.with-action.visible { pointer-events: auto; }
.toast-action {
  flex: none;
  padding: 6px 12px;
  border: 0;
  border-radius: 5px;
  background: var(--yellow);
  color: #111;
  font-size: 13px;
  font-weight: 760;
  cursor: pointer;
}
.toast-dismiss {
  flex: none;
  width: 26px;
  height: 26px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: rgba(255,255,255,.72);
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
}

@media (min-width: 760px) {
  .app { left: 50%; width: min(100%, 520px); transform: translateX(-50%); box-shadow: 0 0 60px rgba(0,0,0,.6); }
  .gallery-dialog { left: 50%; width: min(100%, 760px); transform: translateX(-50%); }
  .rewards-panel { left: 50%; width: min(100%, 520px); transform: translateX(-50%); }
  .gallery-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 430px) {
  .topbar { padding-left: 12px; padding-right: 12px; }
  .brand { gap: 6px; font-size: 15px; }
  .brand-logo { width: 23px; height: 23px; }
  .credits-label { display: none; }
  .model-name { display: none; }
  .topbar-actions { gap: 5px; }
  .top-icon-button {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    grid-template-rows: 24px 13px;
    align-content: center;
  }
  .top-icon-button svg { width: 20px; height: 20px; }
  .top-entry-label { display: block; font-size: 10px; font-weight: 720; line-height: 1; }
}

@media (max-width: 360px) {
  .camera-controls { padding-left: 20px; padding-right: 20px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
  /* 动画被拿掉后扫光会停在随机位置，进度条也会缩在一角：
     这里退回静态占位，保证加载态依然看得懂。 */
  .skeleton-icon, .skeleton-line, .skeleton-button {
    background-image: none;
    animation: none !important;
  }
  .gallery-progress::after { width: 100%; transform: none; animation: none !important; opacity: .55; }
}

/* --------------------------------------------------- Issue #20 抽卡场景 */

.patrol-layer {
  position: fixed;
  z-index: 14;
  inset: 0;
  display: flex;
  flex-direction: column;
  padding: calc(var(--safe-top) + 10px) 16px calc(var(--safe-bottom) + 16px);
  background: #f2f2ef;
  color: #111;
  overflow: hidden;
}
.patrol-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.patrol-tabs { display: flex; gap: 6px; }
.patrol-tab {
  position: relative;
  padding: 7px 12px;
  border: 0;
  border-bottom: 2px solid transparent;
  background: transparent;
  color: #777;
  font-weight: 700;
  cursor: pointer;
}
.patrol-tab.active { border-bottom-color: #111; color: #111; }
.patrol-dot {
  position: absolute;
  top: 2px;
  right: 0;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #d5453c;
}
.patrol-feedback { margin: 10px 0 0; color: #4f7e65; font-size: 12px; font-weight: 700; }
.patrol-charge-cta {
  margin-top: 8px;
  padding: 9px 12px;
  border: 1px dashed #c8b98a;
  border-radius: 8px;
  background: #fffaf0;
  color: #7a6320;
  font-size: 12px;
  cursor: pointer;
}
.patrol-pane { display: none; flex: 1; min-height: 0; overflow-y: auto; }
.patrol-pane.active { display: block; }

#patrolScene {
  position: relative;
  display: flex;
  flex-direction: column;
  min-height: 100%;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}
#patrolScene:focus-visible { outline: 3px solid #79aaf0; outline-offset: -4px; }
.patrol-counter { padding: 8px 2px 0; font-size: 12px; }
.patrol-counter b { font-size: 19px; }
.patrol-stage { position: relative; flex: 1; display: grid; place-items: center; min-height: 320px; perspective: 1200px; }

.patrol-deck { position: relative; z-index: 1; width: min(42vw, 148px); aspect-ratio: 2/3; cursor: pointer; transition: transform .28s cubic-bezier(.22,1,.36,1), opacity .2s ease; }
.deck-layer { position: absolute; inset: 0; border-radius: 10px; overflow: hidden; box-shadow: 0 12px 26px rgba(0,0,0,.22); }
.deck-layer img { width: 100%; height: 100%; object-fit: cover; -webkit-user-drag: none; pointer-events: none; }
.deck-layer[data-depth="2"] { transform: translateY(11px) scale(.93); filter: brightness(.86); }
.deck-layer[data-depth="1"] { transform: translateY(5px) scale(.965); filter: brightness(.94); }
#patrolScene:not([data-state=deckReady]) .patrol-deck { transform: translateY(10px) scale(.9); opacity: .42; }
#patrolScene[data-hint=true] .patrol-deck { animation: patrol-hint 1.1s ease-in-out 2; }
@keyframes patrol-hint { 0%, 100% { transform: translateY(0) scale(1); } 50% { transform: translateY(-12px) scale(1.04); } }

.held-card {
  position: absolute;
  z-index: 3;
  top: 50%;
  left: 50%;
  width: min(70vw, 250px);
  aspect-ratio: 2/3;
  transform-style: preserve-3d;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, -50%) translateX(var(--drag-x, 0px)) rotateY(var(--yaw, 180deg));
  transition: transform .34s cubic-bezier(.22,1,.36,1), opacity .22s ease;
}
.held-card[data-present=true] { opacity: 1; pointer-events: auto; touch-action: none; -webkit-user-drag: none; cursor: grab; }
#patrolScene[data-state=turning] .held-card { transition: none; cursor: grabbing; }
#patrolScene[data-state=throwing] .held-card { transform: translate(-50%, -50%) translateX(-130%) rotate(-8deg); opacity: 0; }
.held-inner { position: relative; width: 100%; height: 100%; transform-style: preserve-3d; }
.held-card .card-face { position: absolute; inset: 0; border-radius: 11px; overflow: hidden; backface-visibility: hidden; -webkit-backface-visibility: hidden; box-shadow: 0 18px 38px rgba(0,0,0,.3); }
.held-card .held-back { background: var(--yellow); transform: rotateY(180deg) translateZ(1px); }
.held-card .held-back > img { width: 100%; height: 100%; object-fit: cover; -webkit-user-drag: none; pointer-events: none; }
.back-meta { position: absolute; right: 0; bottom: 0; left: 0; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 16px 8px 10px; background: linear-gradient(transparent, rgba(255,217,61,.94) 46%); color: #111; text-align: center; }
.back-meta b { font-size: 10px; font-weight: 800; }
.back-meta i { font-size: 8px; font-style: normal; opacity: .72; }
.held-card .held-front { padding: 6px; border: 2px solid #9c79bd; background: #eee7f5; transform: translateZ(1px); }
#patrolScene[data-state=launching] .held-front,
#patrolScene[data-state=waitingImage] .held-front { visibility: hidden; opacity: 0; }
.held-photo { position: relative; display: block; height: 74%; overflow: hidden; border-radius: 6px; background: #d9d9d5; }
.held-photo img { width: 100%; height: 100%; object-fit: cover; -webkit-user-drag: none; pointer-events: none; }
.held-photo b { position: absolute; top: 8px; left: 8px; padding: 3px 6px; border-radius: 4px; background: rgba(105,76,138,.85); color: #fff; font-size: 8px; }
.held-info { display: block; padding: 8px 6px; color: #111; text-align: left; }
.held-info small { display: block; color: #765794; font-size: 8px; font-weight: 800; }
.held-info strong { display: block; margin-top: 2px; font-size: 15px; }
.held-info em { display: block; margin-top: 3px; color: #6a6862; font-size: 8px; font-style: normal; }

/* 手印章与票根是卡面构图部件，随 3D 翻面，不是下方按钮栏。 */
.like-stamp, .keep-stub { position: absolute; padding: 0; border: 0; background: transparent; cursor: pointer; }
.like-stamp { right: 10px; bottom: 10px; display: grid; place-items: center; width: 52px; height: 52px; border: 3px solid #b8472f; border-radius: 50%; color: #b8472f; opacity: .55; transform: rotate(-16deg); }
.like-stamp svg { width: 26px; height: 26px; }
.held-card[data-liked=true] .like-stamp { opacity: 1; background: rgba(184,71,47,.12); }
.like-stamp.stamp-pulse { animation: stamp-press .42s cubic-bezier(.2,1.5,.4,1); }
@keyframes stamp-press { 0% { transform: rotate(-16deg) scale(1.5); } 55% { transform: rotate(-16deg) scale(.9); } 100% { transform: rotate(-16deg) scale(1); } }
.keep-stub { right: 10px; top: 10px; display: grid; place-items: center; width: 34px; height: 44px; color: rgba(17,17,17,.28); }
.keep-stub svg { width: 26px; height: 34px; }
.held-card[data-kept=true] .keep-stub { color: var(--yellow); filter: drop-shadow(0 2px 4px rgba(0,0,0,.35)); }
.reunion-stub { position: absolute; top: 46px; right: 0; width: max-content; padding: 3px 6px; border-radius: 4px; background: rgba(10,10,10,.72); color: var(--yellow); font-size: 8px; font-style: normal; font-weight: 800; }
.patrol-hint { position: absolute; inset: 0; pointer-events: none; }
.patrol-status { margin: 10px 0 0; min-height: 30px; color: #555; font-size: 11px; line-height: 1.5; text-align: center; }
.patrol-draw-error { margin: 4px auto 0; width: min(100%, 300px); }

.patrol-album-grid, .patrol-keepsake-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px; padding: 10px 0; }
.patrol-album-card, .keepsake-item { position: relative; aspect-ratio: 2/3; padding: 0; border: 2px solid transparent; border-radius: 8px; overflow: hidden; background: #eee7f5; cursor: pointer; }
.patrol-album-card img, .keepsake-item img { width: 100%; height: 100%; object-fit: cover; }
.patrol-album-card span, .keepsake-item span { position: absolute; right: 0; bottom: 0; left: 0; padding: 22px 8px 7px; background: linear-gradient(transparent, rgba(0,0,0,.86)); color: #fff; font-size: 11px; text-align: left; }
[data-level=bronze] { border-color: #a9743f; box-shadow: 0 0 0 1px rgba(169,116,63,.35); }
[data-level=silver] { border-color: #9aa3ad; box-shadow: 0 0 0 1px rgba(154,163,173,.4); }
[data-level=gold] { border-color: #d8a326; box-shadow: 0 0 0 2px rgba(216,163,38,.45), 0 8px 20px rgba(216,163,38,.25); }

.patrol-card-detail { padding: 12px 0; }
.patrol-detail-card { position: relative; width: min(60vw, 210px); aspect-ratio: 2/3; margin: 0 auto; border: 2px solid transparent; border-radius: 10px; overflow: hidden; }
.patrol-detail-card img { width: 100%; height: 100%; object-fit: cover; }
.patrol-detail-card .card-title { position: absolute; right: 0; bottom: 0; left: 0; padding: 20px 8px 8px; background: linear-gradient(transparent, rgba(0,0,0,.86)); color: var(--yellow); font-size: 12px; font-weight: 800; }
.growth-bar { height: 6px; margin: 12px 0 6px; border-radius: 3px; background: #e5e5df; overflow: hidden; }
.growth-bar span { display: block; height: 100%; background: #4f7e65; }
.growth-meta { margin: 0; color: #777; font-size: 11px; }

.patrol-preview { position: fixed; z-index: 20; inset: 0; background: #080808; }
.patrol-preview img { width: 100%; height: 100%; object-fit: contain; }
.patrol-preview .icon-button { position: absolute; top: var(--safe-top); }
#patrolPreviewClose { left: 18px; }
#patrolPreviewDownload { right: 18px; }

.patrol-charge-panel { position: fixed; z-index: 22; inset: 0; padding: calc(var(--safe-top) + 12px) 20px calc(var(--safe-bottom) + 20px); background: #f2f2ef; color: #111; overflow-y: auto; }
.patrol-charge-head { display: flex; align-items: center; justify-content: space-between; }
.patrol-charge-head h1 { margin: 0; font-size: 21px; }
.patrol-charge-note { color: #777; font-size: 12px; line-height: 1.6; }
.patrol-charge-tiers { display: grid; gap: 9px; margin: 12px 0; padding: 0; list-style: none; }
.charge-tier { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px; border: 1px solid #ddd; border-radius: 8px; background: #fff; }
.charge-tier b { font-size: 18px; }
.charge-tier span { color: #555; font-size: 12px; text-align: right; }
.patrol-charge-status { color: #777; font-size: 12px; }
.primary-button { width: 100%; min-height: 48px; border: 0; border-radius: 8px; background: var(--yellow); color: #111; font-weight: 760; cursor: pointer; }

.patrol-publish { display: grid; gap: 8px; padding: 12px; border: 1px solid #ddd; border-radius: 8px; background: #fff; }
.patrol-publish-title { color: #777; font-size: 11px; font-weight: 700; }
.patrol-publish label { display: flex; align-items: center; gap: 8px; font-size: 13px; }

@media (prefers-reduced-motion: reduce) {
  .patrol-deck, .held-card, .like-stamp { animation: none !important; transition-duration: .01ms !important; }
}

/* 顶栏入口红点：反馈未读时提示，独立于照片库任务角标。 */
.patrol-entry-dot {
  position: absolute;
  top: -2px;
  right: -2px;
  width: 10px;
  height: 10px;
  border: 2px solid #111;
  border-radius: 50%;
  background: #d5453c;
}
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* --------------------------------------------- Issue #21 新用户首体验 */

/* 空态：盲测里两个纯白页被当成"网页挂了"，插画+文案+去处三件套。 */
.patrol-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 30px 24px;
  text-align: center;
}
.patrol-empty.compact { padding: 16px 12px; gap: 8px; }
.empty-dragon { width: 76px; height: 95px; color: #d8b64a; }
.empty-copy { margin: 0; max-width: 260px; color: #6a6862; font-size: 13px; line-height: 1.7; }
.patrol-empty .primary-button { width: auto; min-width: 148px; padding: 0 20px; }

.patrol-section-title { margin: 12px 2px 6px; font-size: 13px; color: #777; }
.patrol-seen-section { margin-top: 6px; border-top: 1px solid #e2e2dc; }
.patrol-seen-wall { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 7px; padding: 8px 0; }
.seen-card {
  position: relative;
  aspect-ratio: 2/3;
  padding: 0;
  border: 1px solid #ddd;
  border-radius: 7px;
  overflow: hidden;
  background: #eee7f5;
  cursor: pointer;
}
.seen-card img { width: 100%; height: 100%; object-fit: cover; }
.seen-card > span:last-child {
  position: absolute;
  right: 0;
  bottom: 0;
  left: 0;
  padding: 16px 6px 5px;
  background: linear-gradient(transparent, rgba(0,0,0,.82));
  color: #fff;
  font-size: 10px;
  text-align: left;
}
/* 过期签名 URL 不渲染 <img>，用条纹占位代替，避免破图。 */
.seen-card[data-expired=true] { background: repeating-linear-gradient(135deg, #e8e6df, #e8e6df 6px, #dedbd2 6px, #dedbd2 12px); }
.seen-placeholder { position: absolute; inset: 0; }

.patrol-first-hint {
  margin: 6px 0 0;
  padding: 8px 12px;
  border-radius: 8px;
  background: rgba(255,217,61,.22);
  color: #5f5320;
  font-size: 11px;
  line-height: 1.6;
  text-align: center;
}

/* 一次性高亮：把注意力引到相册入口，盲测里没人注意到它。 */
.highlight { animation: album-highlight 1.6s ease-out 2; }
@keyframes album-highlight {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255,217,61,0); }
  40% { box-shadow: 0 0 0 6px rgba(255,217,61,.55); }
}
@media (prefers-reduced-motion: reduce) {
  .highlight { animation: none; outline: 3px solid var(--yellow); outline-offset: 2px; }
}
