:root {
  --bg: #0b0d0f;
  --surface: #16191d;
  --surface-2: #22262c;
  --text: #eef1f4;
  --muted: #9aa3ad;
  --accent: #38bd94;
  --accent-text: #04140f;
  --link: #7cc7ff;
  --danger: #f07167;
  --radius: 12px;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}

[hidden] { display: none !important; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* Camera */

#camera {
  position: fixed;
  inset: 0;
  background: #000;
}

#video, #overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}
#video { object-fit: cover; }
#overlay { pointer-events: none; }

/* Where to aim. Only a guide: codes are read anywhere in the frame. */
.finder {
  position: absolute;
  left: 50%;
  top: 45%;
  width: min(70vw, 70vh, 320px);
  aspect-ratio: 1;
  transform: translate(-50%, -50%);
  border-radius: 20px;
  box-shadow: 0 0 0 100vmax rgba(0, 0, 0, 0.35);
  outline: 2px solid rgba(255, 255, 255, 0.7);
  pointer-events: none;
}

.status {
  position: absolute;
  top: calc(env(safe-area-inset-top) + 16px);
  left: 50%;
  transform: translateX(-50%);
  margin: 0;
  padding: 6px 14px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.55);
  white-space: nowrap;
  max-width: calc(100% - 32px);
  overflow: hidden;
  text-overflow: ellipsis;
}

.bar {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  justify-content: center;
  gap: 8px;
  padding: 16px;
  padding-bottom: calc(env(safe-area-inset-bottom) + 24px);
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.6));
}

/* ?debug: what the camera is and can do. */
.debug {
  position: absolute;
  top: calc(env(safe-area-inset-top) + 56px);
  left: 16px;
  right: 16px;
  margin: 0;
  padding: 8px 10px;
  border-radius: var(--radius);
  background: rgba(0, 0, 0, 0.65);
  font: 12px/1.4 ui-monospace, monospace;
  white-space: pre-wrap;
  pointer-events: none;
}

/* Where a tap asked the camera to focus. */
.focus-ring {
  position: absolute;
  width: 64px;
  height: 64px;
  margin: -32px 0 0 -32px;
  border: 2px solid #fff;
  border-radius: 50%;
  pointer-events: none;
  animation: focus-ring 0.8s ease-out forwards;
}
@keyframes focus-ring {
  from { transform: scale(1.4); opacity: 1; }
  to { transform: scale(1); opacity: 0; }
}

/* Buttons */

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  min-width: 96px;
  padding: 8px 16px;
  border: 0;
  border-radius: var(--radius);
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  text-decoration: none;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
}
.button.primary { background: var(--accent); color: var(--accent-text); font-weight: 600; }
.button.wide { width: 100%; }
#camera .button { background: rgba(0, 0, 0, 0.55); }
#torch[aria-pressed="true"] { background: var(--text); color: var(--bg); }

/* Result */

.sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  max-height: 75%;
  margin: 0 auto;
  max-width: 560px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 16px;
  padding-bottom: calc(env(safe-area-inset-bottom) + 16px);
  border-radius: 20px 20px 0 0;
  background: var(--surface);
  box-shadow: 0 -8px 32px rgba(0, 0, 0, 0.5);
}

.codes {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.code {
  padding: 12px;
  border-radius: var(--radius);
  background: var(--surface-2);
}

.code-kind {
  margin: 0 0 6px;
  color: var(--muted);
  font-size: 13px;
}

.code-text {
  margin: 0;
  font-size: 17px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  user-select: text;
  -webkit-user-select: text;
}
.code-text a { color: var(--link); }

.code-fields {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 4px 12px;
  margin: 10px 0 0;
}
.code-fields dt { color: var(--muted); }
.code-fields dd {
  margin: 0;
  overflow-wrap: anywhere;
  user-select: text;
  -webkit-user-select: text;
}

.code-actions {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}
.code-actions .button { flex: 1; }

.toast {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: calc(env(safe-area-inset-bottom) + 100px);
  margin: 0 auto;
  max-width: 480px;
  padding: 10px 14px;
  border-radius: var(--radius);
  background: var(--surface-2);
  border-left: 4px solid var(--accent);
  z-index: 10;
}
.toast.error { border-left-color: var(--danger); }
