* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: #000;
  color: #f4f4f4;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang HK", "Noto Sans TC", "Helvetica Neue", sans-serif;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}
button { font: inherit; color: inherit; }
.hidden { display: none !important; }

.screen {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
}
.screen.center, .start {
  align-items: center;
  justify-content: center;
  padding: calc(24px + env(safe-area-inset-top)) 24px calc(24px + env(safe-area-inset-bottom));
  text-align: center;
  background: #0b0b0b;
}
.start-inner { max-width: 28rem; width: 100%; }
.badge {
  display: inline-block;
  margin: 0 0 12px;
  padding: 4px 10px;
  border: 1px solid #444;
  border-radius: 999px;
  font-size: 12px;
  letter-spacing: 0.04em;
  color: #cfcfcf;
}
h1 { font-size: 2rem; margin: 0 0 12px; font-weight: 650; }
.lead { margin: 0 0 12px; line-height: 1.55; color: #ddd; }
.note { margin: 0 0 24px; font-size: 13px; line-height: 1.5; color: #999; }
.muted { color: #888; font-size: 13px; }

.btn {
  display: block;
  width: 100%;
  margin: 0 0 12px;
  padding: 14px 18px;
  border-radius: 14px;
  border: 0;
  font-size: 17px;
  cursor: pointer;
}
.btn.primary { background: #f3f3f3; color: #111; font-weight: 600; }
.btn.ghost { background: #1c1c1c; color: #f3f3f3; border: 1px solid #333; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

.banner {
  text-align: left;
  margin: 0 0 16px;
  padding: 12px 14px;
  border-radius: 12px;
  background: #1a1a14;
  border: 1px solid #665;
  color: #f2e6b8;
  font-size: 14px;
  line-height: 1.5;
  white-space: pre-wrap;
}
.banner.error { background: #2a1212; border-color: #833; color: #ffd0d0; }

.viewfinder {
  position: absolute;
  inset: 0;
  background: #000;
  overflow: hidden;
}
#video, #still-preview {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #000;
}
#overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.cam-top, .result-top {
  position: relative;
  z-index: 2;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding: calc(10px + env(safe-area-inset-top)) 16px 8px;
  font-size: 15px;
  font-weight: 600;
  text-shadow: 0 1px 8px #000;
}
.cam-top { color: #fff; }
.cam-top > :first-child, .result-top > :first-child { justify-self: start; }
.cam-top > :last-child, .result-top > :last-child { justify-self: end; }

.icon-btn, .text-btn, .pill {
  background: transparent;
  border: 0;
  cursor: pointer;
  padding: 8px 10px;
}
.icon-btn, .cam-bottom .text-btn { color: #fff; }
.page-badge {
  background: rgba(255,255,255,0.16);
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 600;
}

.cam-hint {
  position: absolute;
  left: 0; right: 0;
  bottom: calc(168px + env(safe-area-inset-bottom));
  margin: 0;
  text-align: center;
  font-size: 15px;
  color: #fff;
  text-shadow: 0 1px 8px #000;
  z-index: 2;
  pointer-events: none;
}
.cam-hint.ok { color: #d9f5ff; }

.cam-bottom {
  position: absolute;
  left: 0; right: 0;
  bottom: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 28px calc(28px + env(safe-area-inset-bottom));
}
.cam-bottom .text-btn { min-width: 64px; font-size: 16px; }
.cam-bottom .spacer { visibility: hidden; min-width: 64px; }

.scan-btn {
  position: relative;
  width: 86px;
  height: 86px;
  border: 0;
  border-radius: 50%;
  background: #fff;
  color: #111;
  font-weight: 650;
  font-size: 14px;
  cursor: pointer;
  box-shadow: 0 0 0 6px rgba(255,255,255,0.18);
}
.scan-btn.ready { box-shadow: 0 0 0 6px rgba(120, 210, 255, 0.55); }
.scan-label { position: relative; z-index: 1; }
.scan-ring {
  position: absolute;
  inset: -10px;
  border-radius: 50%;
  border: 3px solid transparent;
  pointer-events: none;
}
.scan-btn.locking .scan-ring {
  border-color: rgba(140, 220, 255, 0.9);
  clip-path: inset(0 0 100% 0);
  animation: lock 1.2s linear forwards;
}
@keyframes lock {
  from { clip-path: inset(0 0 100% 0); }
  to { clip-path: inset(0 0 0 0); }
}

.result { background: #000; }
.result-top { color: #fff; }
.result-stage {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px 16px;
}
#result-img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  background: #111;
  box-shadow: 0 8px 32px rgba(0,0,0,0.4);
}
.result-tools {
  display: flex;
  justify-content: center;
  padding: 4px 16px 8px;
}
.pill {
  border: 1px solid #555;
  border-radius: 999px;
  padding: 8px 16px;
  font-size: 14px;
  background: #161616;
}
.pages {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 0 16px 8px;
}
.pages img {
  height: 72px;
  width: auto;
  border: 2px solid transparent;
  border-radius: 4px;
  background: #222;
  cursor: pointer;
}
.pages img.active { border-color: #8ad4ff; }
.result-bottom {
  display: flex;
  justify-content: space-between;
  padding: 8px 8px calc(16px + env(safe-area-inset-bottom));
  border-top: 1px solid #222;
}
.result-bottom .wide {
  flex: 1;
  font-size: 17px;
  font-weight: 600;
  padding: 16px 8px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(28px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 20;
  max-width: calc(100% - 32px);
  padding: 10px 14px;
  border-radius: 10px;
  background: rgba(30,30,30,0.92);
  color: #fff;
  font-size: 14px;
  line-height: 1.4;
}
.busy {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,0.55);
  gap: 12px;
}
.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid #444;
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

@media (min-width: 900px) {
  .start-inner { padding: 24px; }
  .viewfinder { background: #111; }
}
