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

html, body {
  height: 100%;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: #1a1a2e;
  color: #fff;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

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

/* ===== States ===== */
.state {
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  width: 100%;
  position: absolute;
  top: 0;
  left: 0;
  transition: opacity 0.2s ease;
}

.state.active {
  display: flex;
}

/* ===== Scanning State ===== */
#state-scanning {
  justify-content: flex-start;
  background: #1a1a2e;
}

.scanner-header {
  text-align: center;
  padding: 20px 16px 12px;
  width: 100%;
}

.scanner-header h1 {
  font-size: 1.3rem;
  font-weight: 700;
  letter-spacing: 0.5px;
}

.subtitle {
  font-size: 0.85rem;
  opacity: 0.6;
  margin-top: 4px;
}

.badge {
  display: inline-block;
  margin-top: 8px;
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.badge.camera {
  background: rgba(52, 152, 219, 0.2);
  color: #5dade2;
  border: 1px solid rgba(52, 152, 219, 0.3);
}

.badge.zebra {
  background: rgba(46, 204, 113, 0.2);
  color: #58d68d;
  border: 1px solid rgba(46, 204, 113, 0.3);
}

/* ===== Camera Scanner ===== */
.scanner-area {
  flex: 1;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 0 16px 20px;
}

#qr-reader {
  width: 100%;
  max-width: 400px;
  border-radius: 16px;
  overflow: hidden;
}

#qr-reader video {
  border-radius: 16px;
}

#qr-reader__scan_region {
  min-height: 280px !important;
}

#qr-reader__dashboard {
  display: none !important;
}

#qr-reader img[alt="Info icon"] {
  display: none !important;
}

#qr-reader__header_message {
  display: none !important;
}

.hint {
  margin-top: 16px;
  font-size: 0.9rem;
  opacity: 0.5;
}

/* ===== Zebra Mode ===== */
#zebra-mode {
  justify-content: center;
}

.zebra-icon {
  color: rgba(255, 255, 255, 0.3);
  margin-bottom: 24px;
  animation: pulse-zebra 2s ease-in-out infinite;
}

@keyframes pulse-zebra {
  0%, 100% { opacity: 0.3; }
  50% { opacity: 0.7; }
}

.zebra-hint {
  font-size: 1.1rem;
  opacity: 0.6;
}

#zebra-input {
  position: absolute;
  left: -9999px;
  opacity: 0;
  width: 1px;
  height: 1px;
}

/* ===== Loading State ===== */
#state-loading {
  background: #1a1a2e;
}

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

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

#state-loading p {
  margin-top: 16px;
  font-size: 1rem;
  opacity: 0.7;
}

/* ===== Preview State ===== */
#state-preview {
  background: #1a1a2e;
}

.preview-content {
  text-align: center;
  padding: 24px;
  width: 100%;
  max-width: 360px;
}

.preview-cat-badge {
  display: inline-block;
  padding: 8px 24px;
  border-radius: 20px;
  font-size: 1.2rem;
  font-weight: 700;
  margin-bottom: 16px;
  letter-spacing: 0.5px;
}

.preview-code {
  font-size: 0.85rem;
  opacity: 0.4;
  font-family: monospace;
  margin-bottom: 24px;
}

.preview-uses-info {
  margin-bottom: 28px;
}

.preview-label {
  font-size: 0.85rem;
  opacity: 0.5;
  margin-bottom: 4px;
}

.preview-remaining {
  font-size: 2.5rem;
  font-weight: 900;
}

.preview-total {
  font-size: 1rem;
  font-weight: 400;
  opacity: 0.5;
}

/* ===== Quantity Selector ===== */
.quantity-selector {
  margin-bottom: 28px;
}

.qty-label {
  font-size: 0.85rem;
  opacity: 0.5;
  margin-bottom: 12px;
}

.qty-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 20px;
}

.qty-btn {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.3);
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
  font-size: 1.8rem;
  font-weight: 300;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, border-color 0.15s;
  -webkit-tap-highlight-color: transparent;
}

.qty-btn:active {
  background: rgba(255, 255, 255, 0.25);
  border-color: rgba(255, 255, 255, 0.6);
}

.qty-btn:disabled {
  opacity: 0.2;
}

.qty-value {
  font-size: 3rem;
  font-weight: 900;
  min-width: 60px;
  text-align: center;
}

/* ===== Redeem / Cancel Buttons ===== */
.btn-redeem {
  width: 100%;
  padding: 18px;
  border: none;
  border-radius: 14px;
  background: #27ae60;
  color: #fff;
  font-size: 1.3rem;
  font-weight: 800;
  letter-spacing: 2px;
  cursor: pointer;
  transition: background 0.15s;
  -webkit-tap-highlight-color: transparent;
}

.btn-redeem:active {
  background: #219a52;
}

.btn-cancel {
  width: 100%;
  padding: 14px;
  border: none;
  border-radius: 14px;
  background: transparent;
  color: rgba(255, 255, 255, 0.5);
  font-size: 1rem;
  cursor: pointer;
  margin-top: 10px;
  -webkit-tap-highlight-color: transparent;
}

.btn-cancel:active {
  color: rgba(255, 255, 255, 0.8);
}

/* ===== Result States ===== */
#state-approved,
#state-rejected {
  justify-content: center;
  cursor: pointer;
}

.result-content {
  text-align: center;
  padding: 24px;
}

.result-icon {
  font-size: 5rem;
  font-weight: 700;
  line-height: 1;
  margin-bottom: 16px;
}

.result-title {
  font-size: 3rem;
  font-weight: 900;
  letter-spacing: 4px;
  margin-bottom: 20px;
}

.result-category {
  font-size: 1.6rem;
  font-weight: 600;
  margin-bottom: 8px;
  opacity: 0.9;
}

.result-uses {
  font-size: 1.3rem;
  opacity: 0.75;
}

.result-reason {
  font-size: 1.4rem;
  opacity: 0.9;
  max-width: 300px;
  line-height: 1.4;
  white-space: pre-line;
}

/* ===== Tap hint ===== */
.tap-hint {
  position: absolute;
  bottom: 28px;
  font-size: 0.8rem;
  opacity: 0.5;
  transition: opacity 0.3s;
}

.tap-hint.paused {
  opacity: 0;
}

.tap-hint.holding {
  opacity: 0.8;
}

/* ===== Back to scan hint ===== */
.btn-back {
  position: absolute;
  bottom: 20px;
  padding: 12px 32px;
  border: 2px solid rgba(255, 255, 255, 0.4);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  display: none;
}

.btn-back.visible {
  display: block;
}

/* ===== Timer Bar ===== */
.timer-bar {
  position: absolute;
  bottom: 0;
  left: 0;
  height: 6px;
  width: 100%;
  transform-origin: left;
}

.timer-bar.running {
  animation: shrink 3s linear forwards;
}

.timer-bar.paused {
  animation-play-state: paused;
}

.approved-bar {
  background: rgba(255, 255, 255, 0.5);
}

.rejected-bar {
  background: rgba(255, 255, 255, 0.4);
}

@keyframes shrink {
  from { transform: scaleX(1); }
  to { transform: scaleX(0); }
}

/* ===== Result colors ===== */
#state-approved {
  background: #27ae60;
}

#state-rejected {
  background: #c0392b;
}

/* ===== Safe area ===== */
@supports (padding-top: env(safe-area-inset-top)) {
  .scanner-header {
    padding-top: calc(20px + env(safe-area-inset-top));
  }
}
