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

html, body {
  height: 100%;
  overflow: hidden;
  background: #000;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

.hidden {
  display: none !important;
}

/* App container */
.app {
  position: relative;
  width: 100%;
  height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* States */
.state {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
}

/* Video preview */
#video {
  flex: 1;
  width: 100%;
  object-fit: cover;
  background: #111;
}

/* Image preview */
#preview {
  flex: 1;
  width: 100%;
  object-fit: contain;
  background: #111;
}

/* Controls area */
.controls {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 24px;
  display: flex;
  justify-content: center;
  align-items: center;
  background: linear-gradient(transparent, rgba(0,0,0,0.6));
}

.controls-preview,
.controls-preview-processing,
.controls-result {
  gap: 16px;
}

/* Capture button */
.btn-capture {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  border: 4px solid #fff;
  background: transparent;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.1s ease;
  -webkit-tap-highlight-color: transparent;
}

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

.btn-capture-inner {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: #fff;
  transition: background 0.1s ease;
}

.btn-capture:active .btn-capture-inner {
  background: #ddd;
}

/* Action buttons */
.btn-action {
  padding: 14px 28px;
  border: none;
  border-radius: 12px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.1s ease, opacity 0.1s ease;
  -webkit-tap-highlight-color: transparent;
}

.btn-action:active {
  transform: scale(0.96);
}

.btn-retake {
  background: rgba(255,255,255,0.2);
  color: #fff;
}

.btn-confirm {
  background: #fff;
  color: #000;
}

.btn-secondary {
  background: rgba(255,255,255,0.2);
  color: #fff;
  margin-bottom: 12px;
}

/* Model status indicator */
.model-status {
  position: absolute;
  top: 16px;
  left: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(8px);
  border-radius: 20px;
  font-size: 12px;
  color: #fff;
  opacity: 0.8;
  transition: opacity 0.5s ease;
}

.model-status.fade-out {
  opacity: 0;
  pointer-events: none;
}

.model-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #f5a623;
  animation: pulse 1s ease-in-out infinite;
}

.model-status.ready .model-dot {
  background: #4ade80;
  animation: none;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* HD Processing Indicator */
.hd-processing-indicator {
  position: absolute;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(8px);
  border-radius: 24px;
  font-size: 13px;
  color: #fff;
  z-index: 10;
}

.hd-spinner {
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.hd-text {
  font-weight: 500;
}

.hd-progress {
  width: 60px;
  height: 4px;
  background: rgba(255,255,255,0.2);
  border-radius: 2px;
  overflow: hidden;
}

.hd-progress-fill {
  height: 100%;
  background: #4ade80;
  border-radius: 2px;
  transition: width 0.3s ease;
  width: 0%;
}

.hd-processing-indicator.error .hd-spinner {
  display: none;
}

.hd-processing-indicator.error .hd-text {
  color: #ff6b6b;
}

.hd-processing-indicator.timeout .hd-text {
  color: #f5a623;
}

/* HD Ready Badge */
.hd-ready-badge {
  position: absolute;
  top: 16px;
  right: 16px;
  padding: 6px 12px;
  background: linear-gradient(135deg, #4ade80, #22c55e);
  border-radius: 12px;
  font-size: 12px;
  font-weight: 700;
  color: #fff;
  opacity: 0;
  transform: scale(0.8);
  transition: all 0.3s ease;
  z-index: 10;
}

.hd-ready-badge.show {
  opacity: 1;
  transform: scale(1);
}

/* HD Reveal Animation */
.hd-reveal {
  animation: hdReveal 0.5s ease-out;
}

@keyframes hdReveal {
  from {
    filter: blur(3px);
    opacity: 0.8;
  }
  to {
    filter: blur(0);
    opacity: 1;
  }
}

/* Error state */
.state-error {
  justify-content: center;
  align-items: center;
  background: #111;
}

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

.error-content p {
  color: #fff;
  font-size: 18px;
  margin-bottom: 24px;
  opacity: 0.8;
}

.error-content .btn-action {
  background: #fff;
  color: #000;
}

/* Flash effect */
.flash {
  position: fixed;
  inset: 0;
  background: #fff;
  opacity: 0;
  pointer-events: none;
  z-index: 100;
}

.flash.active {
  animation: flash 0.15s ease-out;
}

@keyframes flash {
  0% { opacity: 0.8; }
  100% { opacity: 0; }
}

/* Processing state (fallback) */
.state-processing {
  justify-content: center;
  align-items: center;
  background: #111;
}

.processing-content {
  text-align: center;
  padding: 24px;
  width: 80%;
  max-width: 300px;
}

.processing-content p {
  color: #fff;
  font-size: 16px;
  margin-bottom: 16px;
  opacity: 0.9;
}

.progress-text {
  font-size: 14px !important;
  opacity: 0.6 !important;
  margin-top: 8px !important;
  margin-bottom: 0 !important;
}

/* Spinner */
.spinner {
  width: 48px;
  height: 48px;
  border: 3px solid rgba(255,255,255,0.2);
  border-top-color: #fff;
  border-radius: 50%;
  margin: 0 auto 24px;
  animation: spin 1s linear infinite;
}

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

/* Progress bar */
.progress-bar {
  width: 100%;
  height: 4px;
  background: rgba(255,255,255,0.2);
  border-radius: 2px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: #fff;
  border-radius: 2px;
  transition: width 0.3s ease;
  width: 0%;
}

/* Compare slider */
.state-result,
.state-preview-processing {
  background: #111;
}

.compare-slider {
  flex: 1;
  position: relative;
  overflow: hidden;
  touch-action: none;
  cursor: ew-resize;
}

.compare-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.compare-original {
  z-index: 1;
}

.compare-processed {
  z-index: 2;
  clip-path: inset(0 50% 0 0);
  background-image:
    linear-gradient(45deg, #808080 25%, transparent 25%),
    linear-gradient(-45deg, #808080 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #808080 75%),
    linear-gradient(-45deg, transparent 75%, #808080 75%);
  background-size: 20px 20px;
  background-position: 0 0, 0 10px, 10px -10px, -10px 0px;
  background-color: #c0c0c0;
}

.compare-handle {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 50%;
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

.compare-line {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 2px;
  background: #fff;
  box-shadow: 0 0 4px rgba(0,0,0,0.5);
}

.compare-circle {
  width: 40px;
  height: 40px;
  background: #fff;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 8px rgba(0,0,0,0.3);
  font-size: 16px;
  color: #333;
  user-select: none;
}

/* Warning state */
.state-warning {
  justify-content: center;
  align-items: center;
  background: #111;
}

.warning-content {
  text-align: center;
  padding: 24px;
  max-width: 400px;
}

.warning-title {
  color: #f5a623;
  font-size: 20px;
  font-weight: 600;
  margin-bottom: 16px;
}

.warning-content p {
  color: #fff;
  font-size: 14px;
  margin-bottom: 16px;
  opacity: 0.8;
  line-height: 1.5;
}

.warning-content code {
  display: block;
  background: #151515;
  border: 1px solid #333;
  color: #4ade80;
  padding: 12px;
  border-radius: 8px;
  font-size: 12px;
  text-align: left;
  margin-bottom: 16px;
  white-space: pre-wrap;
  word-break: break-all;
  user-select: all;
  cursor: pointer;
}

.warning-content code:hover {
  border-color: #444;
}

.warning-hint {
  font-size: 12px !important;
  opacity: 0.6 !important;
}

/* Safe area support */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
  .controls {
    padding-bottom: calc(24px + env(safe-area-inset-bottom));
  }
}
