:root {
  --bg: #0a0a0b;
  --bg-soft: #141416;
  --accent: #00e5a0;
  --accent-dim: #00b380;
  --danger: #ff4757;
  --danger-dim: #cc3645;
  --text: #f5f5f7;
  --text-dim: #8a8a8e;
  --overlay-bg: rgba(0, 0, 0, 0.72);
  --radius: 16px;
  --font-ui: 'Inter', -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', 'SF Mono', Menlo, monospace;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  -webkit-font-smoothing: antialiased;
  user-select: none;
}

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

#canvas {
  display: none;
}

/* ---------- SCREENS ---------- */
.screen {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.35s ease;
}

.screen.active {
  display: flex;
  opacity: 1;
}

/* ---------- LOADING ---------- */
#loading-screen {
  background: radial-gradient(circle at 50% 35%, #1a1a1f, var(--bg));
  gap: 0;
}

.loading-content {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
}

.loading-icon {
  width: 72px;
  height: 72px;
  color: var(--accent);
  animation: pulse 1.6s ease-in-out infinite;
}

.loading-icon svg {
  width: 100%;
  height: 100%;
}

.loading-title {
  font-size: 1.3rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.loading-status {
  font-size: 0.9rem;
  color: var(--text-dim);
}

.loading-bar {
  width: 200px;
  height: 4px;
  background: var(--bg-soft);
  border-radius: 2px;
  overflow: hidden;
  margin-top: 12px;
}

.loading-bar-fill {
  height: 100%;
  width: 40%;
  background: var(--accent);
  border-radius: 2px;
  animation: loadingSlide 1.4s ease-in-out infinite;
}

@keyframes loadingSlide {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(350%); }
}

@keyframes pulse {
  0%, 100% { transform: scale(1); opacity: 0.6; }
  50% { transform: scale(1.08); opacity: 1; }
}

/* ---------- ERROR ---------- */
#error-screen {
  background: var(--bg);
  padding: 32px;
}

.error-content {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.error-icon {
  width: 64px;
  height: 64px;
  color: var(--danger);
}

.error-title {
  font-size: 1.2rem;
  font-weight: 700;
}

.error-message {
  font-size: 0.9rem;
  color: var(--text-dim);
  line-height: 1.5;
  max-width: 300px;
}

/* ---------- CAMERA ---------- */
#camera-screen {
  background: #000;
  justify-content: flex-end;
}

.camera-wrap {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

#video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* Live overlay */
.live-overlay {
  position: absolute;
  bottom: 20px;
  right: 20px;
  background: var(--overlay-bg);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-radius: 12px;
  padding: 14px 18px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  border: 1px solid rgba(255,255,255,0.08);
  z-index: 5;
  max-width: 280px;
}

.overlay-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.overlay-pin, .overlay-clock-icon, .overlay-place-icon, .overlay-accuracy-icon {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
}

.overlay-pin { color: var(--accent); }
.overlay-clock-icon { color: #87ceeb; }
.overlay-place-icon { color: #ffcc66; }
.overlay-accuracy-icon { color: #ffcc00; }

.overlay-pin svg, .overlay-clock-icon svg, .overlay-place-icon svg, .overlay-accuracy-icon svg {
  width: 100%;
  height: 100%;
}

.overlay-text {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-weight: 500;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Reticle */
.reticle {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 120px;
  height: 120px;
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 8px;
  pointer-events: none;
  z-index: 4;
}

.reticle::before,
.reticle::after {
  content: '';
  position: absolute;
  background: rgba(255,255,255,0.3);
}

.reticle::before {
  top: 50%;
  left: 0;
  right: 0;
  height: 1px;
}

.reticle::after {
  left: 50%;
  top: 0;
  bottom: 0;
  width: 1px;
}

/* Camera controls */
.camera-controls {
  position: relative;
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding-bottom: max(36px, env(safe-area-inset-bottom));
  background: linear-gradient(to top, rgba(0,0,0,0.6), transparent);
  width: 100%;
  padding-top: 60px;
}

.hint-text {
  font-size: 0.8rem;
  color: rgba(255,255,255,0.6);
  font-weight: 500;
  letter-spacing: 0.02em;
  transition: color 0.3s ease;
}

.hint-warning {
  color: #ffcc00 !important;
  font-weight: 700;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-8px); }
  40% { transform: translateX(8px); }
  60% { transform: translateX(-6px); }
  80% { transform: translateX(6px); }
}

.capture-btn.shake {
  animation: shake 0.4s ease;
}

.capture-btn.shake .capture-ring {
  border-color: #ff4757;
}

.capture-btn {
  width: 76px;
  height: 76px;
  border: none;
  background: transparent;
  cursor: pointer;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.15s ease;
}

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

.capture-ring {
  position: absolute;
  inset: 0;
  border: 4px solid #fff;
  border-radius: 50%;
}

.capture-dot {
  width: 58px;
  height: 58px;
  background: #fff;
  border-radius: 50%;
  transition: all 0.15s ease;
}

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

/* ---------- REVIEW ---------- */
#review-screen {
  background: #000;
  justify-content: flex-end;
}

.review-wrap {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

#captured-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.review-panel {
  position: relative;
  z-index: 10;
  width: 100%;
  padding: 20px 16px max(24px, env(safe-area-inset-bottom));
  background: linear-gradient(to top, rgba(0,0,0,0.85) 30%, transparent);
  display: flex;
  justify-content: center;
}

.review-actions {
  display: flex;
  gap: 10px;
  align-items: center;
  max-width: 380px;
  width: 100%;
}

.retake-btn, .send-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border: none;
  border-radius: 12px;
  font-family: var(--font-ui);
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  color: #fff;
}

.retake-btn svg, .send-btn svg {
  width: 18px;
  height: 18px;
}

.retake-btn {
  background: rgba(255,255,255,0.12);
  border: 1px solid rgba(255,255,255,0.15);
  padding: 12px 18px;
  font-size: 0.85rem;
}

.retake-btn:active {
  background: rgba(255,255,255,0.2);
  transform: scale(0.96);
}

.send-btn {
  background: var(--accent-dim);
  padding: 12px 24px;
  font-size: 0.9rem;
  flex: 1;
}

.send-btn:active {
  background: var(--accent);
  transform: scale(0.96);
}

/* ---------- UPLOADING ---------- */
#uploading-screen {
  background: var(--bg);
}

.uploading-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
}

.uploading-title {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text-dim);
}

.spinner-large {
  width: 48px;
  height: 48px;
  border: 4px solid var(--bg-soft);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* ---------- SUCCESS ---------- */
#success-screen {
  background: radial-gradient(circle at 50% 35%, #0f1a16, var(--bg));
}

.success-content {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.success-check {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  background: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  animation: checkPop 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.success-check svg {
  width: 40px;
  height: 40px;
  color: #002818;
}

@keyframes checkPop {
  0% { transform: scale(0); }
  100% { transform: scale(1); }
}

.success-title {
  font-size: 1.5rem;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.success-subtitle {
  font-size: 0.95rem;
  color: var(--text-dim);
  margin-bottom: 8px;
}

/* ---------- BUTTONS ---------- */
.btn-primary {
  background: var(--accent);
  color: #002818;
  border: none;
  padding: 14px 36px;
  border-radius: var(--radius);
  font-family: var(--font-ui);
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s ease;
}

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

.btn-secondary {
  background: rgba(255,255,255,0.08);
  color: var(--text);
  border: 1px solid rgba(255,255,255,0.12);
  padding: 12px 20px;
  border-radius: 12px;
  font-family: var(--font-ui);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}
.btn-secondary:hover { background: rgba(255,255,255,0.12); }
.btn-secondary:active { transform: scale(0.96); }
.btn-small { padding: 8px 16px; font-size: 0.82rem; border-radius: 10px; }

/* ---------- FLASH ---------- */
.flash {
  position: fixed;
  inset: 0;
  background: #fff;
  opacity: 0;
  pointer-events: none;
  z-index: 9999;
  transition: opacity 0.15s ease;
}

.flash.flash-active {
  opacity: 1;
  transition: opacity 0s;
}

.flash.flash-fade {
  opacity: 0;
  transition: opacity 0.4s ease;
}
