*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg: #000;
  --panel: #fff;
  --ctrl-bg: rgba(0, 0, 0, 0.5);
  --accent: #0a66ff;
  --accent-text: #fff;
  --text: #fff;
  --dim: rgba(255, 255, 255, 0.5);
  --ink: #111;
  --ink-dim: #8a8a8a;
  --border: rgba(0, 0, 0, 0.08);
  --green: #30d158;
  --red: #ff453a;
}

html,
body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", sans-serif;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

#app {
  height: 100dvh;
  position: relative;
}

/* ── Screens ── */
.screen {
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  position: relative;
  background: var(--panel);
}

.screen.active {
  display: flex;
}

.screen>.brand-lockup,
.overlay-brand {
  position: absolute;
  top: max(24px, env(safe-area-inset-top));
  left: 0;
  right: 0;
  justify-content: center;
  color: var(--ink);
}

#screen-capture {
  align-items: stretch;
  justify-content: flex-start;
  background: var(--bg);
}

#screen-instructions .overlay-inner {
  max-width: 360px;
}

#instruction-steps {
  list-style: none;
  counter-reset: step;
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 32px;
}

#instruction-steps li {
  font-size: 14px;
  line-height: 1.45;
  counter-increment: step;
}

#instruction-steps li::before {
  content: counter(step) ". ";
  font-weight: 700;
  color: var(--accent);
}

/* ── Viewfinder ── */
#viewfinder {
  flex: 1;
  position: relative;
  overflow: hidden;
  background: #111;
  min-height: 0;
}

#preview {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* ── Trigger flash ── */
#flash-overlay {
  position: absolute;
  inset: 0;
  background: #fff;
  opacity: 0;
  pointer-events: none;
  z-index: 300;
}

#flash-overlay.flash {
  animation: flash-pulse 0.25s ease-out;
}

@keyframes flash-pulse {
  from {
    opacity: 0.9;
  }

  to {
    opacity: 0;
  }
}

/* ── Landscape: hide non-essential UI ── */
@media (orientation: landscape) {
  #top-bar {
    display: none;
  }

  #bottom-bar .action-btn {
    visibility: hidden;
  }
}

/* ── Spinner ── */
.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid rgba(255, 255, 255, 0.25);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ── Upload overlay ── */
#upload-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
  z-index: 400;
}

#upload-overlay.visible {
  opacity: 1;
  pointer-events: auto;
}

#upload-progress {
  width: 70%;
  max-width: 280px;
  height: 6px;
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.25);
  overflow: hidden;
}

#upload-progress-fill {
  height: 100%;
  width: 0%;
  background: var(--accent);
  transition: width 0.1s linear;
}

#upload-progress-text {
  font-size: 14px;
  color: var(--dim);
  font-variant-numeric: tabular-nums;
}

/* ── Result screen ── */
#screen-result {
  align-items: stretch;
  justify-content: flex-start;
  background: var(--panel);
  color: var(--ink);
}

#result-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 14px 16px;
  flex-shrink: 0;
}

#result-header h2 {
  flex: 1;
  text-align: center;
  font-size: 17px;
  font-weight: 700;
  color: var(--ink);
}

#result-body {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 24px;
  gap: 16px;
}

.zoom-wrap {
  width: 100%;
  overflow: hidden;
  border-radius: 12px;
  touch-action: none;
  cursor: grab;
}

.zoom-wrap:active {
  cursor: grabbing;
}

.zoom-wrap img {
  display: block;
  width: 100%;
  transform-origin: center center;
  will-change: transform;
  user-select: none;
  pointer-events: none;
}

#result-header .ctrl-btn {
  background: rgba(0, 0, 0, 0.06);
  color: var(--ink);
}

#result-body ul {
  list-style: none;
  width: 100%;
  max-width: 320px;
}

#result-body ul li {
  display: flex;
  justify-content: space-between;
  padding: 10px 4px;
  border-bottom: 1px solid var(--border);
  font-size: 15px;
}

#result-body .spinner {
  border: 3px solid rgba(0, 0, 0, 0.1);
  border-top-color: var(--accent);
}

#result-error {
  color: var(--red);
  font-weight: 600;
}

.dim-text {
  color: var(--ink-dim);
  font-size: 13px;
}

/* ── Recording progress ── */
#rec-progress {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 8px;
  background: rgba(255, 255, 255, 0.25);
  z-index: 250;
  opacity: 0;
  transition: opacity 0.15s;
  pointer-events: none;
}

#rec-progress.visible {
  opacity: 1;
}

#rec-progress-fill {
  height: 100%;
  width: 0%;
  background: var(--red);
  box-shadow: 0 0 8px var(--red);
  transition: width 0.05s linear;
}

/* ── Top bar ── */
#top-bar {
  position: absolute;
  top: 16px;
  left: 16px;
  right: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 14px 16px;
  /*background: linear-gradient(rgba(0, 0, 0, 0.55) 0%, transparent 100%);*/
  z-index: 50;
}

#top-bar .brand-lockup {
  color: #fff;
}

.spacer {
  flex: 1;
}

.ctrl-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: var(--ctrl-bg);
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  transition: background 0.15s, color 0.15s;
  flex-shrink: 0;
}

.ctrl-btn svg {
  width: 20px;
  height: 20px;
}

/* ── Viewfinder corner-bracket frame ── */
.scan-frame {
  position: absolute;
  top: 8px;
  left: 8px;
  right: 8px;
  bottom: calc(8px + env(safe-area-inset-bottom));
  pointer-events: none;
}

.scan-frame .corner {
  position: absolute;
  width: 28px;
  height: 28px;
  border: 2.5px solid rgba(255, 255, 255, 0.85);
}

.scan-frame .corner.tl {
  top: 0;
  left: 0;
  border-right: none;
  border-bottom: none;
  border-radius: 8px 0 0 0;
}

.scan-frame .corner.tr {
  top: 0;
  right: 0;
  border-left: none;
  border-bottom: none;
  border-radius: 0 8px 0 0;
}

.scan-frame .corner.bl {
  bottom: 0;
  left: 0;
  border-right: none;
  border-top: none;
  border-radius: 0 0 0 8px;
}

.scan-frame .corner.br {
  bottom: 0;
  right: 0;
  border-left: none;
  border-top: none;
  border-radius: 0 0 8px 0;
}

/* ── Bottom instruction overlay (floats over the live preview) ── */
#capture-card {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 80px;
  /*background: linear-gradient(to top, rgba(0, 0, 0, 0.8) 0%, rgba(0, 0, 0, 0.5) 50%, transparent 100%);*/
  color: var(--text);
  padding: 32px 20px max(16px, env(safe-area-inset-bottom));
  z-index: 60;
}

.capture-label {
  display: block;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.8px;
  text-transform: uppercase;
  color: var(--dim);
  margin-bottom: 4px;
}

/* ── Bottom bar ── */
#bottom-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: 14px;
}

.action-btn {
  width: 52px;
  height: 52px;
  background: none;
  border: none;
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  border-radius: 12px;
  flex-shrink: 0;
}

.action-btn svg {
  width: 26px;
  height: 26px;
}

#gallery-thumb {
  width: 52px;
  height: 52px;
  border-radius: 10px;
  overflow: hidden;
  border: 2px solid rgba(255, 255, 255, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.08);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  position: relative;
}

#gallery-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

#gallery-thumb svg {
  width: 22px;
  height: 22px;
  color: var(--dim);
}

/* Capture button — enlarged tap target */
#btn-capture {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: transform 0.08s ease, background 0.15s ease, box-shadow 0.15s ease;
}

#btn-capture svg {
  width: 32px;
  height: 32px;
}

#btn-capture:active {
  transform: scale(0.92);
}

#btn-capture.busy {
  opacity: 0.45;
  pointer-events: none;
}

/* ── Panels ── */
#settings-panel,
#inspections-panel {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--panel);
  color: var(--ink);
  border-radius: 18px 18px 0 0;
  padding: 12px 20px max(28px, env(safe-area-inset-bottom));
  transform: translateY(101%);
  transition: transform 0.3s cubic-bezier(0.32, 0.72, 0, 1);
  z-index: 200;
  max-height: 72vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  box-shadow: 0 -8px 30px rgba(0, 0, 0, 0.15);
}

#settings-panel.open,
#inspections-panel.open {
  transform: translateY(0);
}

.drag-handle {
  width: 38px;
  height: 4px;
  border-radius: 2px;
  background: rgba(0, 0, 0, 0.15);
  margin: 0 auto 18px;
}

#settings-panel h2,
#inspections-panel h2 {
  font-size: 17px;
  font-weight: 700;
  text-align: center;
  margin-bottom: 18px;
  color: var(--ink);
}

/* Settings rows */
.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  min-height: 54px;
  border-bottom: 1px solid var(--border);
}

.setting-label {
  font-size: 15px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.setting-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

input[type="range"] {
  width: 120px;
  accent-color: #fff;
  cursor: pointer;
}

/* Segmented control */
.seg-ctrl {
  display: flex;
  background: rgba(0, 0, 0, 0.06);
  border-radius: 8px;
  overflow: hidden;
}

.seg-btn {
  background: none;
  border: none;
  color: var(--ink-dim);
  font-size: 13px;
  padding: 7px 13px;
  cursor: pointer;
  transition: background 0.14s, color 0.14s;
}

.seg-btn.active {
  background: #fff;
  color: var(--ink);
  font-weight: 600;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
}

/* iOS-style toggle */
.ios-toggle {
  position: relative;
  display: inline-block;
  width: 51px;
  height: 31px;
  flex-shrink: 0;
  cursor: pointer;
}

.ios-toggle input {
  opacity: 0;
  width: 0;
  height: 0;
}

.ios-toggle .knob {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.14);
  border-radius: 15.5px;
  transition: background 0.2s;
}

.ios-toggle .knob::after {
  content: "";
  position: absolute;
  width: 25px;
  height: 25px;
  top: 3px;
  left: 3px;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.2s;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
}

.ios-toggle input:checked~.knob {
  background: var(--green);
}

.ios-toggle input:checked~.knob::after {
  transform: translateX(20px);
}

/* Capability badge */
.cap-badge {
  font-size: 11px;
  padding: 2px 7px;
  border-radius: 5px;
  background: rgba(0, 0, 0, 0.06);
  color: var(--ink-dim);
  font-weight: 500;
}

.cap-badge.ok {
  background: rgba(48, 209, 88, 0.15);
  color: var(--green);
}

.cap-badge.no {
  background: rgba(255, 69, 58, 0.15);
  color: var(--red);
}

/* ── Inspections list ── */
#inspections-list {
  display: flex;
  flex-direction: column;
}

.insp-item {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: opacity 0.15s;
}

.insp-item:active {
  opacity: 0.65;
}

.insp-thumb {
  width: 52px;
  height: 52px;
  border-radius: 8px;
  overflow: hidden;
  background: rgba(0, 0, 0, 0.06);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.insp-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.insp-info {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 5px;
  overflow: hidden;
}

.insp-id {
  font-size: 12px;
  color: var(--ink-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.insp-date {
  font-size: 12px;
  color: var(--ink-dim);
}

.empty-msg {
  text-align: center;
  padding: 48px 0;
  color: var(--ink-dim);
  font-size: 15px;
}

/* ── Toast ── */
#toast {
  position: fixed;
  top: 72px;
  left: 50%;
  transform: translateX(-50%) translateY(-4px);
  background: rgba(20, 20, 20, 0.88);
  color: #fff;
  padding: 9px 20px;
  border-radius: 20px;
  font-size: 14px;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 700;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

#toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ── Permission overlay ── */
#overlay {
  position: fixed;
  inset: 0;
  background: var(--panel);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 600;
  transition: opacity 0.3s;
}

#overlay.gone {
  opacity: 0;
  pointer-events: none;
}

.overlay-inner {
  text-align: center;
  padding: 40px 36px;
  max-width: 320px;
  color: var(--ink);
}

.brand-lockup {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 15px;
  font-weight: 700;
}

.brand-lockup svg {
  width: 22px;
  height: 22px;
  flex-shrink: 0;
}

.hero-icon {
  width: 56px;
  height: 56px;
  color: var(--accent);
  margin-bottom: 24px;
}

.overlay-inner h2 {
  font-size: 24px;
  font-weight: 700;
  margin-bottom: 10px;
  color: var(--ink);
}

.overlay-inner p {
  color: var(--ink-dim);
  line-height: 1.55;
  margin-bottom: 32px;
}

.btn-primary {
  background: var(--accent);
  color: var(--accent-text);
  border: none;
  padding: 14px 40px;
  border-radius: 24px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  margin-top: 16px;
}

.btn-primary:disabled {
  opacity: 0.35;
  pointer-events: none;
}

/* ── Recording indicator ── */
#rec-indicator {
  position: absolute;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(0, 0, 0, 0.55);
  padding: 6px 16px;
  border-radius: 20px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

#rec-indicator.visible {
  opacity: 1;
}

.rec-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #ff3b30;
  animation: blink 1.1s ease-in-out infinite;
}

@keyframes blink {

  0%,
  100% {
    opacity: 1;
  }

  50% {
    opacity: 0.25;
  }
}

#rec-timer {
  font-size: 15px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: #fff;
  letter-spacing: 0.5px;
  min-width: 24px;
  text-align: center;
}

/* ── Capture button — guided-flow states ── */
#btn-capture.disabled {
  opacity: 0.35;
  pointer-events: none;
}

#btn-capture.ready {
  box-shadow: 0 0 0 8px rgba(10, 102, 255, 0.18);
}

#btn-capture.armed {
  background: #ff3b30;
  animation: blink 1.1s ease-in-out infinite;
}

#btn-capture.recording {
  background: #ff3b30;
}

/* ── Guidance overlay (lives inside #capture-card) ── */
#guidance-overlay {
  display: flex;
  flex-direction: column;
  gap: 8px;
  text-align: left;
  transition: opacity 0.2s;
}

#guidance-overlay.gone {
  opacity: 0;
  height: 0;
  overflow: hidden;
}

#guidance-checks {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-start;
}

.check-item {
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(255, 255, 255, 0.12);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  border-radius: 20px;
  padding: 6px 12px;
  font-size: 12px;
  color: var(--text);
}

.check-icon {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--dim);
  flex-shrink: 0;
}

.check-icon.ok {
  background: var(--green);
}

.check-icon.bad {
  background: var(--red);
}

#guidance-status {
  font-size: 21px;
  font-weight: 700;
  color: #fff;
  animation: status-glow 2.2s ease-in-out infinite;
}

@keyframes status-glow {

  0%,
  100% {
    text-shadow: 0 0 8px rgba(255, 255, 255, 0.5), 0 0 18px rgba(10, 102, 255, 0.5), 0 1px 3px rgba(0, 0, 0, 0.6);
  }

  50% {
    text-shadow: 0 0 14px rgba(255, 255, 255, 0.8), 0 0 32px rgba(10, 102, 255, 0.9), 0 1px 3px rgba(0, 0, 0, 0.6);
  }
}

#debug-pitch {
  font-size: 12px;
  color: var(--dim);
  font-variant-numeric: tabular-nums;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.6);
}

/* ── Gallery grid items ── */
.grid-item {
  position: relative;
  aspect-ratio: 1;
  overflow: hidden;
  cursor: pointer;
  border-radius: 2px;
}

.grid-item img,
.grid-item video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.play-badge {
  position: absolute;
  bottom: 5px;
  right: 5px;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.62);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  color: #fff;
  padding-left: 2px;
}

.count-badge {
  position: absolute;
  bottom: 5px;
  right: 5px;
  min-width: 26px;
  height: 20px;
  padding: 0 7px;
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.62);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 600;
  color: #fff;
  font-variant-numeric: tabular-nums;
}

#gallery-thumb .count-badge {
  bottom: 2px;
  right: 2px;
  min-width: 18px;
  height: 14px;
  padding: 0 4px;
  border-radius: 7px;
  font-size: 8px;
}