:root {
  --bg-0: #0a111f;
  --bg-1: #0f1b2f;
  --ink: #eef3ff;
  --ink-muted: #aab6cd;
  --accent: #65d3ff;
  --accent-2: #75f2c5;
  --card: rgba(13, 21, 36, 0.86);
  --radius-xl: 28px;
  --radius-md: 14px;
  --gutter: 14px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

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

html {
  background: #0a111f;
}

body {
  min-height: 100vh;
  font-family: "Avenir Next", "SF Pro Rounded", "Helvetica Neue", sans-serif;
  color: var(--ink);
  background: linear-gradient(170deg, var(--bg-0) 0%, var(--bg-1) 55%, var(--bg-0) 100%);
  display: grid;
  place-items: center;
  padding: 24px 12px;
}

.app-shell {
  width: min(460px, 100%);
  overflow: hidden;
  position: relative;
  isolation: isolate;
}

.top-bar {
  padding: calc(14px + var(--safe-top)) 16px 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.logo-link {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
  color: var(--ink);
}

.logo-icon {
  width: 26px;
  height: 26px;
  color: var(--accent);
  flex: 0 0 auto;
}

.logo-word {
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1;
}

.logo-accent {
  color: var(--accent);
}

.camera-stage {
  position: relative;
  margin: 0 var(--gutter);
  border-radius: var(--radius-xl);
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: #060b14;
  aspect-ratio: 3 / 4;
  touch-action: manipulation;
  -webkit-touch-callout: none;
  user-select: none;
  transform-origin: top center;
  max-height: 1200px;
  transition: opacity 0.28s ease, transform 0.32s ease, max-height 0.32s ease, margin 0.32s ease, border-color 0.24s ease;
}

.app-shell.has-frozen-capture .camera-stage {
  opacity: 0;
  transform: translateY(-10px) scale(0.965);
  max-height: 0;
  margin-top: 0;
  margin-bottom: 0;
  border-color: transparent;
  pointer-events: none;
}

#video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  background: #05080f;
  transform: scaleX(-1);
}

.captured-preview {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  z-index: 1;
  background: #05080f;
}

.video-environment #video {
  transform: none;
}

.scan-frame {
  position: absolute;
  inset: 12% 10%;
  border-radius: 28px;
  border: 1.5px solid rgba(255, 255, 255, 0.45);
  box-shadow: inset 0 0 0 2px rgba(0, 0, 0, 0.08);
  pointer-events: none;
}

.scan-frame::before,
.scan-frame::after {
  content: "";
  position: absolute;
  left: 8%;
  right: 8%;
  height: 1.8px;
  background: linear-gradient(90deg, transparent, rgba(117, 242, 197, 0.8), transparent);
  animation: pulse 1.8s infinite;
  opacity: 0;
}

.scan-active .scan-frame::before,
.scan-active .scan-frame::after {
  opacity: 1;
}

.scan-frame::before {
  top: 28%;
  animation-delay: 0.12s;
}

.scan-frame::after {
  top: 68%;
  animation-delay: 0.44s;
}

.stage-hint {
  position: absolute;
  left: 50%;
  top: 22px;
  transform: translateX(-50%);
  z-index: 2;
  pointer-events: none;
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: 0.005em;
  color: rgba(238, 243, 255, 0.94);
  text-shadow: 0 2px 12px rgba(0, 0, 0, 0.55);
  transition: opacity 0.18s ease;
  opacity: 0.95;
}

.stage-hint.hidden {
  opacity: 0;
}

.capture-summary {
  margin: 0 var(--gutter) 10px;
  width: 108px;
  height: 108px;
  border-radius: 18px;
  overflow: hidden;
  position: relative;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(5, 10, 19, 0.7);
  box-shadow: 0 14px 28px rgba(0, 0, 0, 0.34);
  opacity: 0;
  transform: translateY(-8px) scale(0.9);
  transform-origin: top left;
  max-height: 0;
  margin-top: 0;
  margin-bottom: 0;
  pointer-events: none;
  transition: opacity 0.28s ease, transform 0.32s ease, max-height 0.32s ease, margin 0.32s ease;
}

.app-shell.has-frozen-capture .capture-summary {
  opacity: 1;
  transform: translateY(0) scale(1);
  max-height: 108px;
  margin-bottom: 10px;
  pointer-events: auto;
}

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

.capture-close {
  position: absolute;
  top: 6px;
  left: 6px;
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  background: rgba(8, 15, 27, 0.72);
  color: rgba(238, 243, 255, 0.95);
  border: 1px solid rgba(255, 255, 255, 0.24);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

.capture-close svg {
  width: 14px;
  height: 14px;
  stroke: currentColor;
  stroke-width: 2.2;
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.camera-fallback {
  position: absolute;
  inset: 0;
  padding: 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  text-align: center;
  color: var(--ink-muted);
  font-size: 0.93rem;
  line-height: 1.45;
  background: linear-gradient(150deg, rgba(7, 13, 24, 0.94), rgba(9, 17, 31, 0.94));
}

.camera-fallback.hidden {
  display: none;
}

.actions {
  padding: 14px var(--gutter) 0;
  display: flex;
  justify-content: flex-end;
  max-height: 80px;
  opacity: 1;
  transform: translateY(0);
  transition: opacity 0.24s ease, transform 0.28s ease, max-height 0.3s ease, padding 0.3s ease;
}

.app-shell.has-frozen-capture .actions {
  opacity: 0;
  transform: translateY(-8px);
  max-height: 0;
  padding-top: 0;
  pointer-events: none;
}

.action-btn {
  border: none;
  border-radius: 14px;
  padding: 13px 12px;
  min-height: 56px;
  font-size: 0.86rem;
  font-weight: 700;
  cursor: pointer;
  color: #091225;
  background: linear-gradient(140deg, var(--accent), var(--accent-2));
  box-shadow: 0 10px 22px rgba(71, 201, 255, 0.2);
  transition: transform 0.16s ease, opacity 0.16s ease;
}

.action-btn.secondary {
  color: var(--ink);
  background: linear-gradient(150deg, rgba(255, 255, 255, 0.16), rgba(255, 255, 255, 0.06));
  border: 1px solid rgba(255, 255, 255, 0.16);
  box-shadow: none;
}

.action-btn:active {
  transform: translateY(1px) scale(0.99);
}

.action-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
}

.action-btn.compact {
  padding: 0;
  font-size: 0.74rem;
  border-radius: 11px;
  width: 44px;
  min-height: 56px;
  box-shadow: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.action-btn.secondary.compact {
  border: none;
  background: transparent;
  color: var(--ink-muted);
}

.action-btn.compact svg {
  width: 18px;
  height: 18px;
  stroke: currentColor;
  stroke-width: 1.8;
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.fallback-open-btn {
  border: none;
  border-radius: 999px;
  padding: 10px 16px;
  font-size: 0.86rem;
  font-weight: 700;
  cursor: pointer;
  color: #091225;
  background: linear-gradient(140deg, var(--accent), var(--accent-2));
  box-shadow: 0 10px 22px rgba(71, 201, 255, 0.2);
}

.scan-meter {
  margin: 12px var(--gutter) 2px;
  padding: 12px;
  border-radius: 14px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(8, 16, 30, 0.62);
  backdrop-filter: blur(8px);
  display: none;
  animation: slideIn 0.24s ease;
}

.scan-meter.active {
  display: block;
}

.scan-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.78rem;
  color: var(--ink-muted);
  margin-bottom: 8px;
}

.scan-bar {
  width: 100%;
  height: 6px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.15);
  overflow: hidden;
}

.scan-fill {
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  transition: width 0.2s linear;
}

.scan-sub {
  margin-top: 8px;
  font-size: 0.75rem;
  color: var(--ink-muted);
}

.result-sheet {
  margin: 12px var(--gutter) 0;
  border-radius: 22px;
  border-top: 1px solid rgba(255, 255, 255, 0.16);
  background: linear-gradient(160deg, rgba(8, 14, 26, 0.94), rgba(11, 20, 34, 0.96));
  padding: 0 14px 0;
  min-height: 0;
  opacity: 0;
  transform: translateY(16px);
  max-height: 0;
  margin-top: 0;
  pointer-events: none;
  overflow: hidden;
  transition: opacity 0.3s ease, transform 0.34s ease, max-height 0.36s ease, margin 0.3s ease, padding 0.3s ease;
}

.result-sheet.visible {
  opacity: 1;
  transform: translateY(0);
  max-height: 2200px;
  margin-top: 12px;
  padding: 10px 14px calc(14px + var(--safe-bottom));
  min-height: 250px;
  pointer-events: auto;
}

.sheet-handle {
  width: 46px;
  height: 4px;
  border-radius: 999px;
  margin: 4px auto 10px;
  background: rgba(255, 255, 255, 0.23);
}

.sheet-head {
  display: flex;
  justify-content: flex-start;
  align-items: center;
  margin-bottom: 10px;
  gap: 12px;
}

.sheet-title {
  font-size: 0.95rem;
  font-weight: 700;
  letter-spacing: 0.01em;
}

.results-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

.result-card {
  display: grid;
  grid-template-columns: 88px 1fr;
  gap: 10px;
  align-items: stretch;
  border-radius: var(--radius-md);
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: var(--card);
  color: var(--ink);
  text-decoration: none;
  overflow: hidden;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.22);
  opacity: 0;
  transform: translateY(8px) scale(0.99);
  animation: cardIn 0.3s ease forwards;
}

.result-thumb {
  background: rgba(255, 255, 255, 0.05);
  width: 88px;
  height: 112px;
  display: grid;
  place-items: center;
  font-size: 0.72rem;
  color: var(--ink-muted);
}

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

.result-body {
  padding: 10px 10px 9px 0;
  display: grid;
  align-content: center;
  gap: 5px;
}

.result-name {
  font-size: 0.86rem;
  font-weight: 700;
  line-height: 1.26;
  max-height: 2.52em;
  overflow: hidden;
}

.result-meta {
  color: var(--ink-muted);
  font-size: 0.73rem;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.result-price {
  color: #e8ffef;
  font-size: 0.84rem;
  font-weight: 700;
}

.score-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.72rem;
  color: var(--ink-muted);
}

.score-track {
  flex: 1;
  height: 5px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.13);
  overflow: hidden;
}

.score-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  border-radius: inherit;
}

.empty-state {
  text-align: center;
  color: var(--ink-muted);
  font-size: 0.85rem;
  line-height: 1.5;
  padding: 36px 12px;
  border: 1px dashed rgba(255, 255, 255, 0.2);
  border-radius: 14px;
  background: rgba(5, 10, 19, 0.45);
}

.hidden {
  display: none !important;
}

@keyframes pulse {
  0% { transform: scaleX(0.94); opacity: 0.15; }
  50% { transform: scaleX(1); opacity: 0.85; }
  100% { transform: scaleX(0.94); opacity: 0.15; }
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes cardIn {
  from {
    opacity: 0;
    transform: translateY(8px) scale(0.99);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@media (max-width: 380px) {
  .top-bar {
    padding-inline: 12px;
  }
}
