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

html, body {
  height: 100%;
  background: #1a1a1a;
  color: #fff;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  overflow: hidden;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}

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

.view[hidden] {
  display: none !important;
}

/* ---------- login ---------- */
.login-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px;
}

.login-title {
  font-size: 32px;
  font-weight: 700;
  margin-bottom: 8px;
}

.login-sub {
  color: #888;
  font-size: 16px;
  margin-bottom: 40px;
}

.btn-google {
  display: inline-flex;
  align-items: center;
  background: #fff;
  color: #333;
  font-size: 16px;
  font-weight: 500;
  padding: 14px 28px;
  border-radius: 12px;
  border: none;
  cursor: pointer;
}

.btn-google:active {
  background: #eee;
}

/* ---------- ad banner ---------- */
.ad-banner {
  min-height: 50px;
  background: #111;
  text-align: center;
  overflow: hidden;
}

/* ---------- user avatar ---------- */
.user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  margin-right: 10px;
}

.topbar-left {
  display: flex;
  align-items: center;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ---------- top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: #222;
  min-height: 48px;
}

.topbar-title {
  font-size: 18px;
  font-weight: 600;
}

.btn-icon {
  background: none;
  border: none;
  color: #00d4ff;
  font-size: 24px;
  width: 40px;
  height: 40px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ---------- video / canvas ---------- */
video, .main-canvas {
  flex: 1;
  min-height: 0;
  width: 100%;
  max-height: 100%;
  object-fit: contain;
  background: #111;
}

.main-canvas {
  touch-action: none;
}

/* ---------- toolbar ---------- */
.toolbar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 16px 16px calc(16px + env(safe-area-inset-bottom));
  background: #1a1a1a;
}

/* ---------- buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 12px;
  font-size: 16px;
  font-weight: 600;
  padding: 14px 28px;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.1s;
  min-height: 48px;
  min-width: 48px;
}

.btn:active {
  transform: scale(0.95);
}

.btn:disabled {
  opacity: 0.4;
  pointer-events: none;
}

.btn-primary {
  background: #00d4ff;
  color: #000;
}

.btn-secondary {
  background: #333;
  color: #fff;
}

.btn-sm {
  padding: 8px 16px;
  font-size: 14px;
  min-height: 36px;
  border-radius: 8px;
}

.btn-danger {
  background: #ff4444;
  color: #fff;
}

/* Shutter button */
.btn-round {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  padding: 0;
  background: #fff;
}

.shutter {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: 3px solid #1a1a1a;
  background: #fff;
}

.btn-round:active .shutter {
  background: #ccc;
}

/* ---------- project list ---------- */
.project-list {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  -webkit-overflow-scrolling: touch;
}

.project-card {
  display: flex;
  align-items: center;
  background: #2a2a2a;
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 12px;
  cursor: pointer;
  transition: background 0.15s;
}

.project-card:active {
  background: #333;
}

.project-thumb {
  width: 60px;
  height: 60px;
  border-radius: 8px;
  background: #444;
  flex-shrink: 0;
  object-fit: cover;
}

.project-info {
  flex: 1;
  margin-left: 16px;
}

.project-name {
  font-size: 16px;
  font-weight: 600;
}

.project-dims {
  font-size: 13px;
  color: #888;
  margin-top: 4px;
}

.project-delete {
  background: none;
  border: none;
  color: #666;
  font-size: 20px;
  padding: 8px;
  cursor: pointer;
}

.project-delete:active {
  color: #ff4444;
}

.empty-state {
  text-align: center;
  color: #666;
  padding: 60px 20px;
  font-size: 16px;
}

/* ---------- captures list ---------- */
.captures-list {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.capture-row {
  position: relative;
  overflow: hidden;
}

.capture-content {
  display: flex;
  align-items: center;
  padding: 10px 16px;
  background: #1a1a1a;
  border-bottom: 1px solid #2a2a2a;
  cursor: pointer;
  position: relative;
  z-index: 1;
  transition: transform 0.2s;
}

.capture-content:active {
  background: #252525;
}

.capture-thumb {
  width: 72px;
  height: 54px;
  border-radius: 6px;
  object-fit: cover;
  flex-shrink: 0;
  background: #333;
}

.capture-info {
  margin-left: 14px;
  flex: 1;
}

.capture-date {
  font-size: 15px;
  font-weight: 500;
}

.capture-time {
  font-size: 13px;
  color: #888;
  margin-top: 2px;
}

.capture-delete-btn {
  position: absolute;
  right: 0;
  top: 0;
  bottom: 0;
  width: 90px;
  border-radius: 0;
  z-index: 0;
}

.gif-progress {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(0,0,0,0.85);
  color: #fff;
  padding: 24px 36px;
  border-radius: 12px;
  font-size: 16px;
  z-index: 100;
  text-align: center;
}

/* ---------- setup / forms ---------- */
.setup-step {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 20px;
  overflow-y: auto;
}

.setup-step[hidden] {
  display: none !important;
}

.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  font-size: 14px;
  color: #888;
  margin-bottom: 6px;
}

.form-row {
  display: flex;
  gap: 12px;
}

.form-row .form-group {
  flex: 1;
}

.input {
  width: 100%;
  padding: 12px;
  background: #2a2a2a;
  border: 1px solid #444;
  border-radius: 8px;
  color: #fff;
  font-size: 16px;
  outline: none;
}

.input:focus {
  border-color: #00d4ff;
}

/* ---------- canvas frame ---------- */
.canvas-frame-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px;
  min-height: 0;
}

.canvas-frame {
  position: relative;
  background: #fff;
  overflow: hidden;
  border: 2px solid #444;
}

.ref-image {
  position: absolute;
  transform-origin: 0 0;
  pointer-events: none;
}

/* ---------- mask ---------- */
.mask-layer {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
}

.mask-top {
  cursor: crosshair;
  touch-action: none;
}

.mask-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 16px;
  background: #222;
}

.mask-label {
  font-size: 13px;
  color: #888;
  white-space: nowrap;
}

/* ---------- sliders ---------- */
.slider {
  flex: 1;
  -webkit-appearance: none;
  appearance: none;
  height: 4px;
  background: #444;
  border-radius: 2px;
  outline: none;
}

.slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #00d4ff;
  cursor: pointer;
}

/* ---------- compare controls ---------- */
.compare-controls {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 20px;
  background: #222;
}

.slider-label {
  font-size: 13px;
  color: #888;
  white-space: nowrap;
}

/* ---------- detect status ---------- */
.detect-status {
  position: absolute;
  top: 12px;
  left: 0;
  right: 0;
  text-align: center;
  color: #00d4ff;
  font-size: 14px;
  z-index: 20;
  pointer-events: none;
}

/* ---------- progress ---------- */
.progress-wrap {
  position: absolute;
  bottom: 90px;
  left: 20px;
  right: 20px;
  height: 4px;
  background: #333;
  border-radius: 2px;
  overflow: hidden;
  z-index: 10;
}

.progress-bar {
  height: 100%;
  width: 0;
  background: #00d4ff;
  transition: width 0.1s;
}

/* ---------- no camera fallback ---------- */
.no-camera {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 32px;
  color: #888;
  font-size: 18px;
}
