/* 小さい画面でも文字を縮めず、折り返して読めるようにする。 */
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { font-size: 18px; -webkit-text-size-adjust: 100%; }
body { margin: 0; background: #fff; color: #111; font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", sans-serif; line-height: 1.65; overflow-wrap: anywhere; }
main { max-width: 640px; margin: 0 auto; padding: max(20px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) 32px max(16px, env(safe-area-inset-left)); }
body.counting main { padding-bottom: calc(240px + env(safe-area-inset-bottom)); }
h1 { font-size: 30px; line-height: 1.4; margin: 12px 0 16px; }
h2 { font-size: 23px; line-height: 1.5; margin: 28px 0 12px; }
h3 { font-size: 20px; margin: 0; }
p { margin: 10px 0; }
button, input { font: inherit; }
button { min-height: 56px; padding: 12px 14px; border: 2px solid #222; border-radius: 10px; color: #111; background: #fff; line-height: 1.4; cursor: pointer; touch-action: manipulation; overflow-wrap: anywhere; }
button:disabled { color: #666; border-color: #bbb; background: #eee; cursor: default; }
button.primary { color: #fff; background: #111; }
button.primary:disabled { background: #666; }
button.quiet { border-color: transparent; text-decoration: underline; }
button:focus-visible, input:focus-visible { outline: 3px solid #175bcc; outline-offset: 3px; }
.actions { display: grid; gap: 12px; margin: 24px 0; }
.instructions { padding-left: 1.5em; }
.instructions li { margin-bottom: 18px; padding-left: 4px; }
.notice { border-left: 5px solid #a95000; background: #fff2de; padding: 12px; }
.error { color: #a51d1d; background: #fff0f0; padding: 12px; border-left: 5px solid #b02020; }
.two-buttons { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 10px; }
/* 長い案内の文字幅で列が広がらないよう、列と最小幅を四角の中に制限する。 */
.camera { width: min(100%, 50vh); width: min(100%, 50svh); min-width: 0; aspect-ratio: 1; position: relative; display: grid; grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr); background: #222; margin: 0 auto; border-radius: 12px; overflow: hidden; }
video { width: 100%; height: 100%; display: block; object-fit: cover; }
.camera > video { position: absolute; inset: 0; }
.camera-frame { position: absolute; inset: var(--crop-inset, 15%); border: 3px solid #fff; border-radius: 10px; box-shadow: 0 0 0 100px #0002; pointer-events: none; }
.read-card { padding: 14px; border: 3px solid #777; border-radius: 12px; margin: 16px 0; min-height: 144px; }
.read-card.success { background: #e1f7e8; border-color: #087334; }
.read-card.changed { background: #fff0d9; border-color: #ae5100; }
.read-card.failure { background: #fff0f0; border-color: #b02020; }
.read-card.neutral { background: #f0f0f0; border-color: #777; }
.read-card.flash { animation: read-flash .45s ease-out; }
@keyframes read-flash { from { box-shadow: 0 0 0 5px currentColor; } to { box-shadow: 0 0 0 0 transparent; } }
.item-line { display: flex; align-items: center; gap: 12px; min-width: 0; }
.item-info { flex: 1; min-width: 0; }
.size { width: 56px; height: 56px; border: 2px solid #111; border-radius: 5px; display: inline-flex; align-items: center; justify-content: center; flex: none; font-size: 28px; font-weight: 800; line-height: 1; background: #fff; color: #111; }
.size.black { background: #111; color: #fff; }
.sku { font-size: 18px; word-break: break-all; margin: 4px 0 0; }
.read-count { font-size: 28px; font-weight: 750; text-align: right; margin-bottom: 0; }
.big-number { font-size: 26px; font-weight: 750; }
.toggle { display: flex; align-items: center; gap: 12px; min-height: 56px; margin-bottom: 16px; }
.toggle input { width: 26px; height: 26px; flex: none; }
.item-row { display: flex; align-items: center; width: 100%; text-align: left; gap: 12px; margin-bottom: 10px; }
.item-row .quantity { margin-left: auto; font-size: 28px; font-weight: 750; flex: none; }
.review-card { border: 2px solid #aaa; padding: 16px; border-radius: 12px; margin-bottom: 16px; }
.review-card .actions { margin: 16px 0 0; }
.review-card.confirmed { border-color: #087334; background: #e1f7e8; }
.review-number { font-size: 22px; font-weight: 700; }
#send { width: 100%; margin: 24px 0; }
footer { position: fixed; inset: auto 0 0; background: #fff; border-top: 2px solid #222; padding: 10px max(16px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left)); z-index: 2; }
.bar-inner { max-width: 608px; margin: auto; }
footer p { margin: 0 0 8px; }
#save-status { font-size: 18px; line-height: 1.5; }
dialog { width: calc(100% - 24px); max-width: 480px; max-height: calc(100% - 32px); padding: 20px; border: 2px solid #111; border-radius: 14px; overflow: auto; }
dialog::backdrop { background: #0009; }
dialog h2 { margin-top: 0; }
dialog input { display: block; width: 100%; min-height: 72px; font-size: 36px; padding: 8px 12px; border: 2px solid #222; border-radius: 8px; margin: 8px 0 20px; }
.done-mark { font-size: 64px; color: #087334; margin-top: 48px; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; }
@media (prefers-reduced-motion: reduce) { .read-card.flash { animation: none; } }

/* 読む画面は帯も含めて画面の高さに収める。古い Safari は vh、対応端末は dvh を使う。
   通常: 帯126 + 札140 + 操作56 + 間12 + 上下8 = 342px。残りが正方形のカメラ。
   数え直し: 帯のボタンを入れ替え、上の説明104 + 間6 = 110px をカメラから引く。
   長い札の案内は2行にし、その間だけ札を22px広げてカメラから引く。 */
body.scanning { height: 100vh; height: 100svh; height: 100dvh; display: grid; grid-template-rows: minmax(0, 1fr) auto; }
body.scanning main { width: 100%; min-height: 0; padding: max(4px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-right)) 4px max(8px, env(safe-area-inset-left)); }
body.long-read-message { --read-card-height: 162px; --read-message-height: 44px; }
body.scanning #scan { height: 100%; min-height: 0; display: grid; grid-template-rows: minmax(0, 1fr) var(--read-card-height, 140px) 56px; gap: 6px; }
body.recounting #scan { grid-template-rows: 104px minmax(0, 1fr) var(--read-card-height, 140px) 56px; }
.camera-space { min-width: 0; min-height: 0; display: grid; place-items: center; }
body.scanning .camera { width: auto; height: 100%; max-width: 100%; max-height: min(624px, calc(100vw - 16px), 50vh); max-height: min(624px, calc(100vw - 16px), 50svh); max-height: min(624px, calc(100vw - 16px), 50dvh); aspect-ratio: 1; margin: 0; }
/* 再開ボタンの実際の高さを避け、残った領域の中央に札を置く。ボタンがなければ四角全体の中央。 */
#camera-restart { position: relative; z-index: 2; grid-row: 1; min-width: 0; max-width: calc(100% - 8px); margin: 4px 4px 0; padding: 4px; min-height: 56px; white-space: normal; overflow-wrap: anywhere; }
#camera-message { position: relative; z-index: 1; grid-row: 2; place-self: center; width: fit-content; max-width: 86%; max-height: 80%; min-width: 0; min-height: 0; margin: 0; padding: 10px 14px; border-radius: 10px; overflow: auto; overscroll-behavior: contain; color: #fff; background: #000c; font-size: 18px; line-height: 22px; text-align: center; white-space: normal; overflow-wrap: anywhere; }
body.scanning .read-card { margin: 0; min-height: 0; height: var(--read-card-height, 140px); padding: 6px 8px; border-width: 2px; display: grid; grid-template-rows: var(--read-message-height, 22px) 44px 22px 30px; gap: 2px; }
body.scanning .read-card p { margin: 0; }
body.scanning .read-message { font-size: 18px; line-height: 22px; }
body.scanning .read-card .item-line { gap: 8px; line-height: 22px; }
body.scanning .read-card .size { width: 44px; height: 44px; font-size: 28px; }
body.scanning .read-card .item-info { font-size: 20px; line-height: 22px; }
body.scanning .read-card .sku { font-family: ui-monospace, Menlo, monospace; font-size: 18px; line-height: 22px; }
body.scanning .read-count { font-size: 28px; line-height: 30px; }
body.scanning .read-card.failure { display: block; }
body.scanning .two-buttons { gap: 8px; }
body.scanning button { padding: 4px 6px; }
body.scanning footer { position: static; padding: 4px max(8px, env(safe-area-inset-right)) max(4px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left)); }
body.scanning .bar-inner { display: grid; gap: 4px; max-width: 624px; }
body.scanning footer p { margin: 0; }
body.scanning #total { font-size: 26px; line-height: 30px; }
body.scanning #save-status { line-height: 22px; }
body.scanning #scan-navigation, body.scanning #recount-end { height: 56px; }
#recount-band { margin: 0; padding: 4px 6px; border: 2px solid #a95000; border-radius: 8px; }
#recount-label { display: grid; grid-template-rows: 44px 22px 22px; gap: 2px; font-size: 18px; line-height: 22px; margin: 0; }
#recount-label .sku { margin: 0; font-family: ui-monospace, Menlo, monospace; line-height: 22px; }
#notice { position: fixed; z-index: 5; top: max(4px, env(safe-area-inset-top)); left: max(8px, env(safe-area-inset-left)); right: max(8px, env(safe-area-inset-right)); max-width: 624px; margin: 0 auto; display: flex; align-items: flex-start; gap: 8px; box-shadow: 0 2px 12px #0003; }
#notice-text { margin: 0; flex: 1; max-height: 25vh; overflow: auto; }
#notice-close { flex: none; min-width: 64px; }
