:root {
  color-scheme: light;
  font-family: "Noto Sans TC", "Microsoft JhengHei", system-ui, sans-serif;
  color: #173a33;
  background: #eef6f2;
  --brand: #0f5b4c;
  --brand-dark: #0a463a;
  --line: #cbded6;
  --muted: #5f746d;
  --warning: #9b5a00;
  --success: #087443;
  --danger: #a22a2a;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: linear-gradient(180deg, #e9f4ef 0, #f7faf8 42rem);
}

button, a { -webkit-tap-highlight-color: transparent; }

.page-shell {
  width: min(100%, 46rem);
  margin: 0 auto;
  padding: max(1.25rem, env(safe-area-inset-top)) 1rem max(2rem, env(safe-area-inset-bottom));
}

.page-header { margin: 0 0 1rem; }
.environment, .step {
  margin: 0 0 .35rem;
  color: var(--brand);
  font-size: .82rem;
  font-weight: 800;
  letter-spacing: .08em;
}

h1 { margin: 0; font-size: clamp(1.55rem, 6vw, 2.2rem); line-height: 1.25; }
h2 { margin: 0; font-size: 1.2rem; }
.page-header > p:last-child { margin: .65rem 0 0; color: var(--muted); }

.notice, .scanner-card, .result-card, .acceptance-card {
  border: 1px solid var(--line);
  border-radius: 1rem;
  background: rgba(255, 255, 255, .96);
  box-shadow: 0 .5rem 1.6rem rgba(23, 58, 51, .07);
}

.notice {
  display: grid;
  gap: .25rem;
  margin: 0 0 1rem;
  padding: .9rem 1rem;
  color: #31584f;
  font-size: .9rem;
}

.scanner-card, .result-card, .acceptance-card { margin-top: 1rem; padding: 1rem; }
.scanner-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; }
.state { flex: none; border-radius: 999px; padding: .35rem .65rem; font-size: .78rem; font-weight: 800; }
.state-idle { color: #5e6e68; background: #edf1ef; }
.state-active { color: #075737; background: #d9f4e6; }
.state-success { color: #fff; background: var(--success); }
.state-error { color: #fff; background: var(--danger); }

.camera-stage {
  position: relative;
  overflow: hidden;
  min-height: 18rem;
  margin-top: 1rem;
  border-radius: .85rem;
  background: #14231f;
}

#camera { width: 100%; height: 100%; min-height: 18rem; object-fit: cover; display: block; }
.camera-placeholder { position: absolute; inset: 0; display: grid; place-items: center; margin: 0; padding: 1rem; color: #d9e5e0; text-align: center; }
.scan-mask { position: absolute; inset: 0; display: grid; place-items: center; pointer-events: none; background: linear-gradient(to bottom, rgba(0,0,0,.55) 0 36%, transparent 36% 64%, rgba(0,0,0,.55) 64% 100%); }
.scan-window { position: relative; width: 92%; height: 28%; min-height: 5.3rem; border: 3px solid #74f0bd; border-radius: .6rem; box-shadow: 0 0 0 1px rgba(0,0,0,.5), inset 0 0 1rem rgba(116,240,189,.15); }
.scan-line { position: absolute; left: 3%; right: 3%; top: 50%; height: 2px; background: #ffdf5d; box-shadow: 0 0 .5rem #ffdf5d; }

.help-text { margin: .85rem 0 0; color: var(--muted); font-size: .9rem; line-height: 1.6; }
.controls { display: grid; grid-template-columns: 1fr 1fr; gap: .65rem; margin-top: 1rem; }
.controls #torch-button { grid-column: 1 / -1; }
button { min-height: 3rem; border-radius: .65rem; padding: .75rem 1rem; font: inherit; font-weight: 800; cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .45; }
.primary-button { border: 1px solid var(--brand); color: white; background: var(--brand); }
.primary-button:hover:not(:disabled) { background: var(--brand-dark); }
.secondary-button { border: 1px solid #9bb9ae; color: var(--brand-dark); background: #f8fbfa; }
.full-width { width: 100%; margin-top: .85rem; }
.scanner-message { min-height: 1.5rem; margin: .8rem 0 0; color: var(--muted); font-size: .9rem; }
.scanner-message.warning { color: var(--warning); font-weight: 700; }
.scanner-message.error { color: var(--danger); font-weight: 700; }

.empty-result { margin-top: .85rem; border: 1px dashed #b8cbc4; border-radius: .7rem; padding: 1.2rem; color: var(--muted); text-align: center; }
.result-detail { margin: .85rem 0 0; }
.result-detail div { display: grid; gap: .3rem; padding: .8rem 0; border-top: 1px solid #e3ece8; }
.result-detail dt { color: var(--muted); font-size: .82rem; }
.result-detail dd { margin: 0; overflow-wrap: anywhere; font-weight: 800; }
#result-text { color: #063f34; font-family: ui-monospace, "Cascadia Mono", monospace; font-size: 1.18rem; }
.acceptance-card ol { margin: .8rem 0 0; padding-left: 1.35rem; color: #36574f; line-height: 1.7; }
.back-link { margin: 1.25rem 0 0; text-align: center; }
.back-link a { color: var(--brand); font-weight: 700; }

@media (min-width: 42rem) {
  .page-shell { padding-inline: 1.5rem; }
  .scanner-card, .result-card, .acceptance-card { padding: 1.35rem; }
  .camera-stage, #camera { min-height: 23rem; }
}

@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto !important; }
}
