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

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  background: #000;
}

#app {
  width: 100%;
  height: 100%;
  position: relative;
  overflow: hidden;
}

#camera-container {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

#video {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

#overlay-canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 5;
}

#balloon-container {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 10;
}

.balloon {
  position: absolute;
  pointer-events: auto;
  min-width: 200px;
  max-width: 280px;
  padding: 14px 16px;
  border-radius: 16px;
  color: #fff;
  font-size: 14px;
  line-height: 1.4;
  box-shadow: 0 8px 32px rgba(0,0,0,0.4);
  transform: translate(-50%, -100%);
  transition: opacity 0.3s ease, transform 0.3s ease;
  z-index: 10;
  animation: balloon-enter 0.3s ease-out;
}

.balloon.hidden {
  opacity: 0;
  transform: translate(-50%, -100%) scale(0.8);
  pointer-events: none;
}

.balloon::after {
  content: '';
  position: absolute;
  bottom: -10px;
  left: 50%;
  transform: translateX(-50%);
  width: 0;
  height: 0;
  border-left: 10px solid transparent;
  border-right: 10px solid transparent;
  border-top: 10px solid inherit;
}

.balloon .balloon-arrow {
  position: absolute;
  bottom: -20px;
  left: 50%;
  transform: translateX(-50%);
  width: 0;
  height: 0;
  border-left: 10px solid transparent;
  border-right: 10px solid transparent;
  border-top: 12px solid currentColor;
  opacity: 0.9;
}

.balloon .balloon-name {
  font-weight: 700;
  font-size: 15px;
  margin-bottom: 4px;
}

.balloon .balloon-price {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 2px;
}

.balloon .balloon-promo {
  font-size: 14px;
  font-weight: 600;
  color: #fbbf24;
  margin-bottom: 4px;
}

.balloon .balloon-shelf {
  font-size: 12px;
  opacity: 0.85;
  margin-bottom: 2px;
}

.balloon .balloon-hint {
  font-size: 11px;
  opacity: 0.7;
  font-style: italic;
}

.balloon .balloon-desc {
  font-size: 12px;
  opacity: 0.8;
  margin-bottom: 4px;
}

.balloon .balloon-type-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  background: rgba(255,255,255,0.2);
  margin-bottom: 6px;
}

@keyframes balloon-enter {
  from {
    opacity: 0;
    transform: translate(-50%, -80%) scale(0.8);
  }
  to {
    opacity: 1;
    transform: translate(-50%, -100%) scale(1);
  }
}

.balloon-leaving {
  animation: balloon-leave 0.3s ease-in forwards;
}

@keyframes balloon-leave {
  to {
    opacity: 0;
    transform: translate(-50%, -80%) scale(0.8);
  }
}

#ui-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 20;
}

#ui-overlay > * {
  pointer-events: auto;
}

.ui-screen {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,0.85);
  z-index: 50;
}

.ui-screen.hidden {
  display: none;
}

.loading-content, .error-content {
  text-align: center;
  color: #fff;
  padding: 32px;
}

.store-name {
  font-size: 24px;
  font-weight: 700;
  margin-bottom: 24px;
}

.spinner {
  width: 48px;
  height: 48px;
  border: 4px solid rgba(255,255,255,0.15);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto 16px;
}

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

.loading-message {
  font-size: 14px;
  opacity: 0.7;
}

.error-icon {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: #ef4444;
  color: #fff;
  font-size: 32px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 16px;
}

.error-title {
  font-size: 20px;
  font-weight: 700;
  margin-bottom: 8px;
}

.error-message {
  font-size: 14px;
  opacity: 0.8;
  margin-bottom: 24px;
  line-height: 1.5;
}

.btn {
  padding: 14px 32px;
  border: none;
  border-radius: 12px;
  background: #fff;
  color: #000;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.2s;
  min-width: 200px;
}

.btn:active {
  opacity: 0.7;
}

#toast-container {
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast {
  padding: 12px 20px;
  border-radius: 12px;
  background: rgba(0,0,0,0.8);
  color: #fff;
  font-size: 14px;
  font-weight: 500;
  text-align: center;
  animation: toast-in 0.3s ease-out;
  pointer-events: auto;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  max-width: 90vw;
}

.toast.toast-out {
  animation: toast-out 0.3s ease-in forwards;
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(-20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes toast-out {
  to {
    opacity: 0;
    transform: translateY(-20px);
  }
}

#store-list {
  background: linear-gradient(135deg, #0f172a 0%, #1e293b 100%);
}

.store-list-content {
  text-align: center;
  padding: 40px 24px;
  max-width: 420px;
  width: 100%;
}

.store-list-header {
  font-size: 28px;
  font-weight: 800;
  color: #fff;
  margin-bottom: 4px;
}

.store-list-subtitle {
  font-size: 14px;
  color: #94a3b8;
  margin-bottom: 32px;
}

.store-list-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}

.store-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 130px;
  padding: 20px 16px;
  border-radius: 16px;
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.08);
  text-decoration: none;
  color: #fff;
  transition: all 0.2s;
  text-align: center;
}

.store-card:active {
  transform: scale(0.97);
  background: rgba(255,255,255,0.1);
}

.store-card-name {
  font-size: 16px;
  font-weight: 700;
  margin-bottom: 4px;
}

.store-card-desc {
  font-size: 12px;
  color: #94a3b8;
  line-height: 1.3;
}

.store-card-all {
  grid-column: 1 / -1;
  min-height: 80px;
}

.store-card-error {
  color: #94a3b8;
  font-size: 14px;
  padding: 20px;
}

.store-card-wrapper {
  display: contents;
}

.store-card-wrapper .store-card-link {
  grid-column: 1 / -1;
  padding: 10px;
  border-radius: 10px;
  background: rgba(255,255,255,0.04);
  color: #94a3b8;
  text-decoration: none;
  font-size: 12px;
  font-weight: 600;
  text-align: center;
  transition: all 0.2s;
  margin-top: -4px;
}

.store-card-wrapper .store-card-link:active {
  background: rgba(255,255,255,0.1);
  color: #fff;
}

.store-card-wrapper:last-child .store-card-link {
  margin-bottom: 0;
}

#product-list {
  background: linear-gradient(135deg, #0f172a 0%, #1e293b 100%);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.pl-content {
  padding: 24px 16px 40px;
  max-width: 500px;
  width: 100%;
  margin: 0 auto;
}

.pl-top {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
}

.pl-back {
  background: rgba(255,255,255,0.08);
  border: none;
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  padding: 10px 16px;
  border-radius: 10px;
  cursor: pointer;
  white-space: nowrap;
}

.pl-back:active {
  background: rgba(255,255,255,0.15);
}

.pl-store-name {
  font-size: 20px;
  font-weight: 800;
  color: #fff;
}

.pl-grid {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.pl-card {
  padding: 12px;
  border-radius: 14px;
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.1);
  border-left: 4px solid #22c55e;
}

.pl-card-row {
  display: flex;
  gap: 12px;
  align-items: flex-start;
}

.pl-card-left {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.pl-card-qr-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 80px;
  height: 80px;
  border-radius: 12px;
  text-decoration: none;
  transition: transform 0.2s, opacity 0.2s;
}

.pl-card-qr-btn:active {
  transform: scale(0.92);
  opacity: 0.8;
}

.pl-card-qr-icon {
  font-size: 28px;
  line-height: 1;
  color: #fff;
  margin-bottom: 2px;
}

.pl-card-qr-label {
  font-size: 11px;
  font-weight: 700;
  color: #fff;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.pl-card-right {
  flex: 1;
  min-width: 0;
}

.pl-card-store {
  font-size: 10px;
  font-weight: 600;
  color: #64748b;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 2px;
}

.pl-card-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 6px;
  font-size: 9px;
  font-weight: 700;
  text-transform: uppercase;
  color: #fff;
  white-space: nowrap;
}

.pl-card-name {
  font-size: 15px;
  font-weight: 700;
  color: #fff;
  margin-bottom: 2px;
  line-height: 1.2;
}

.pl-card-price {
  font-size: 18px;
  font-weight: 800;
  color: #fff;
  margin-bottom: 1px;
}

.pl-card-promo {
  font-size: 14px;
  font-weight: 700;
  color: #fbbf24;
  margin-bottom: 4px;
}

.pl-card-shelf {
  font-size: 12px;
  color: #94a3b8;
  margin-bottom: 2px;
}

.pl-card-desc {
  font-size: 11px;
  color: #94a3b8;
  margin-bottom: 2px;
  line-height: 1.3;
}

.pl-card-hint {
  font-size: 11px;
  color: #64748b;
  font-style: italic;
}

#debug-panel {
  position: fixed;
  bottom: 16px;
  right: 16px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
  pointer-events: none;
}

#debug-panel > * {
  pointer-events: auto;
}

.debug-toggle {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: none;
  background: rgba(0,0,0,0.6);
  color: #fff;
  font-size: 18px;
  cursor: pointer;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

.debug-toggle:active {
  background: rgba(0,0,0,0.8);
}

.debug-content {
  width: 260px;
  max-height: 240px;
  background: rgba(0,0,0,0.8);
  border-radius: 12px;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  overflow: hidden;
}

.debug-header {
  padding: 8px 12px;
  font-size: 11px;
  font-weight: 700;
  color: #94a3b8;
  text-transform: uppercase;
  letter-spacing: 1px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}

.debug-body {
  padding: 8px 12px;
  font-size: 11px;
  font-family: monospace;
  color: #22c55e;
  line-height: 1.6;
  max-height: 190px;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-all;
}

@media (prefers-color-scheme: dark) {
  .ui-screen {
    background: rgba(0,0,0,0.9);
  }
}
