:root {
  --ink: #232728;
  --muted: #626866;
  --line: #e0e4df;
  --soft: #f4f5f2;
  --accent: #25382d;
  font-family: Arial, Helvetica, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  color: var(--ink);
  background: white;
  color-scheme: light;
}
* {
  box-sizing: border-box;
}
body {
  margin: 0;
}
a {
  color: inherit;
  text-underline-offset: 4px;
}
main {
  width: 100%;
  max-width: 680px;
  min-height: 100vh;
  min-height: 100svh;
  margin: 0 auto;
  padding: calc(12px + env(safe-area-inset-top, 0px))
    max(20px, env(safe-area-inset-right, 0px))
    calc(24px + env(safe-area-inset-bottom, 0px))
    max(20px, env(safe-area-inset-left, 0px));
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.scanner-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex: 0 0 auto;
  min-height: 44px;
}
h1 {
  margin: 0;
  font-size: 1.125rem;
  line-height: 1.3;
  font-weight: 500;
}
h2 {
  margin: 0 0 16px;
  font-size: 1.25rem;
  font-weight: 500;
}
#exit-search {
  width: 44px;
  height: 44px;
  flex: 0 0 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  text-decoration: none;
  touch-action: manipulation;
}
.status {
  margin: 0;
  color: var(--muted);
}
.error {
  color: #922f2f;
  overflow-wrap: anywhere;
}
#search-capture {
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.stage {
  position: relative;
  background: var(--soft);
  width: 100%;
  height: min(56vh, 520px);
  height: min(56svh, 520px);
  min-height: 0;
  overflow: hidden;
  border-radius: 18px;
}
video,
.stage > img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.stage > img {
  object-fit: contain;
}
.camera-guide {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  height: 82%;
  max-width: 84%;
  aspect-ratio: 63/88;
  border: 2px solid white;
  border-radius: 12px;
  pointer-events: none;
  box-shadow: 0 0 0 999px #0002;
}
.file-guide {
  position: absolute;
  border: 3px solid white;
  box-shadow: 0 0 0 999px #0005;
  touch-action: none;
  cursor: move;
  border-radius: 6px;
}
.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  flex: 0 0 auto;
}
button {
  font: inherit;
  font-weight: 500;
  min-height: 56px;
  padding: 14px 24px;
  border: 0;
  border-radius: 999px;
  background: var(--soft);
  color: var(--ink);
  cursor: pointer;
  touch-action: manipulation;
}
.capture-actions > button {
  width: 100%;
}
.secondary-actions > button {
  flex: 1 1 auto;
}
button.primary {
  background: #eeeeec;
  color: var(--ink);
}
button:disabled {
  opacity: 0.5;
  cursor: default;
}
button:focus-visible,
a:focus-visible,
input:focus-visible,
summary:focus-visible,
.file-guide:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 4px;
}
.file-guide:focus-visible {
  outline-color: white;
  outline-offset: 6px;
}
#crop-size {
  width: 100%;
  min-height: 44px;
  margin: 0;
  accent-color: var(--accent);
}
#saved-photo {
  display: block;
  max-height: min(45svh, 320px);
  max-width: 80%;
  margin: 16px auto;
  object-fit: contain;
}
progress {
  display: block;
  width: 100%;
  height: 7px;
  margin: 20px 0;
  accent-color: var(--accent);
}
#result-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.result-card {
  display: flex;
  align-items: center;
  gap: 16px;
  text-decoration: none;
  background: white;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 16px;
  min-height: 100px;
}
.result-card:first-child {
  border: 2px solid var(--accent);
}
.result-card img {
  width: 64px;
  height: 90px;
  object-fit: contain;
  flex-shrink: 0;
}
.result-card:first-child img {
  width: 92px;
  height: 128px;
}
.result-copy {
  min-width: 0;
  overflow-wrap: anywhere;
}
.result-copy strong,
.result-copy span {
  display: block;
}
.result-copy span {
  font-size: 0.9rem;
  color: var(--muted);
}
.result-copy .result-link {
  margin-top: 6px;
  color: var(--accent);
  font-weight: 600;
}
a.result-card:hover .result-link {
  text-decoration: underline;
}

/* Keep live capture inside the smallest viewport, including expanded Safari chrome. */
body[data-phase="camera"] main {
  height: 100vh;
  height: 100svh;
  min-height: 0;
  overflow: hidden;
}
body[data-phase="camera"] #search-capture {
  flex: 1 1 0;
  min-height: 0;
}
body[data-phase="camera"] #camera-stage {
  height: auto;
  flex: 1 1 0;
  min-height: 0;
}
body[data-phase="camera"] .secondary-actions {
  display: none;
}
body[data-phase="idle"] #search-capture {
  margin-top: auto;
}
#choose-photo {
  display: none;
}
body[data-phase="idle"] #choose-photo,
body[data-phase="file"] #choose-photo,
body[data-phase="error"] #choose-photo {
  display: block;
}
.sr-only,
body[data-phase="idle"] .status,
body[data-phase="camera"] .status,
body[data-phase="file"] .status,
body[data-phase="results"] .status {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}
[hidden] {
  display: none !important;
}
#debug-report {
  display: none;
  color: var(--muted);
  font-size: 0.9rem;
}
body[data-phase="results"] #debug-report,
body[data-phase="error"] #debug-report,
body[data-phase="blocked"] #debug-report {
  display: block;
}
#debug-report summary {
  cursor: pointer;
  min-height: 44px;
  padding: 10px 0;
}
.debug-options {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 8px 0;
}
.debug-options p {
  margin: 0;
}
#debug-expected {
  font: inherit;
  font-size: 16px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  width: 100%;
}
.debug-photo-option {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
}
#debug-photo {
  width: 20px;
  height: 20px;
  accent-color: var(--accent);
}
#debug-status:empty {
  display: none;
}
@media (max-width: 380px) {
  main {
    padding-right: max(16px, env(safe-area-inset-right, 0px));
    padding-left: max(16px, env(safe-area-inset-left, 0px));
  }
  .result-card {
    gap: 12px;
    padding: 12px;
  }
}
@media (prefers-reduced-motion: reduce) {
  * {
    scroll-behavior: auto !important;
  }
}
