: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 {
  min-height: 44px;
  padding: 8px 12px;
  border: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  color: rgba(255,255,255,.88);
  font-size: 14px;
  font-weight: 650;
  text-decoration: underline;
  cursor: pointer;
}

.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: 10px; }
.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-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: 52px 52px 86px 52px;
  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); }
.danger-action { color: #b3261e !important; }
.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; }
.charge-reward-card { display: grid; gap: 8px; padding: 14px; border: 1px solid #dfc45a; border-radius: 12px; background: #fff8d9; }
.charge-reward-card h2 { margin: 0; font-size: 17px; }
.charge-reward-card p { margin: 0; color: #66561d; font-size: 13px; line-height: 1.5; }
.charge-reward-status:empty { display: none; }
.charge-reward-actions { display: flex; gap: 8px; }
.charge-reward-card[data-state="granted"] { border-color: #4a9b6b; background: #eef9f1; }
.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; }
/* 骨架屏：形状与 .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: 8px;
  top: 8px;
  min-width: 70px;
  height: 44px;
  padding: 0 13px;
  border: 1px solid rgba(255,255,255,.35);
  border-radius: 7px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 700;
  line-height: 1;
  color: #fff;
  background: rgba(16,16,16,.78);
  box-shadow: 0 2px 12px rgba(0,0,0,.28);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  cursor: pointer;
}
.delete-job-icon { font-size: 15px; line-height: 1; }
.delete-job:active { transform: scale(.96); }
.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: 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; }
}
