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

[hidden] {
  display: none !important;
}

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;
}

/* ---------- loading spinner ---------- */
.loading-spinner {
  width: 32px;
  height: 32px;
  border: 3px solid #333;
  border-top-color: #00d4ff;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-top: 24px;
}

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

/* ---------- 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;
}

/* ---------- 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;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.btn-icon:active {
  opacity: 0.6;
}

/* ---------- 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.05s;
  min-height: 48px;
  min-width: 48px;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

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

.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;
}

/* Icon-only button (toolbar) */
.btn-icon-action {
  width: 48px;
  height: 48px;
  padding: 0;
  border-radius: 50%;
}

/* ---------- 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: linear-gradient(90deg, #333 25%, #444 50%, #333 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s ease-in-out infinite;
  flex-shrink: 0;
  opacity: 0.6;
  transition: opacity 0.3s ease;
}

.project-thumb.loaded {
  opacity: 1;
  animation: none;
}

.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;
}

/* ---------- delete section in edit ---------- */
.delete-section {
  margin-top: 32px;
  padding-top: 20px;
  border-top: 1px solid #333;
}

.delete-section[hidden] {
  display: none !important;
}

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

.free-limit-msg {
  text-align: center;
  color: #888;
  font-size: 13px;
  padding: 16px 20px;
  line-height: 1.5;
}

.free-limit-msg a {
  color: #00d4ff;
  text-decoration: none;
  font-weight: 600;
}

.free-limit-msg a:active {
  opacity: 0.7;
}

/* ---------- modal ---------- */
.modal-backdrop {
  display: none;
}

.modal-card {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 20px;
}

.modal-heading {
  display: none;
}

.modal-actions {
  display: flex;
  gap: 12px;
  justify-content: flex-end;
  margin-top: 24px;
}

@media (min-width: 640px) {
  #setup-step-1 {
    padding: 0;
    justify-content: center;
    align-items: center;
    background: none;
  }

  #setup-step-1 .modal-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.6);
    backdrop-filter: blur(4px);
  }

  #setup-step-1 .modal-card {
    position: relative;
    flex: none;
    width: 440px;
    max-width: 90vw;
    background: #2a2a2a;
    border-radius: 16px;
    border: 1px solid #444;
    padding: 32px;
    box-shadow: 0 16px 48px rgba(0,0,0,0.4);
    z-index: 1;
  }

  #setup-step-1 .modal-heading {
    display: block;
    font-size: 20px;
    font-weight: 600;
    margin-bottom: 24px;
  }

  #view-setup:has(#setup-step-1:not([hidden])) > .topbar {
    display: none;
  }
}

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

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

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

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

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

.preset-row .input {
  flex: 1;
}

.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;
  touch-action: none;
  cursor: grab;
  border: 2px solid #444;
}

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

.ref-sliders {
  padding: 8px 20px;
  background: #222;
  max-width: 500px;
  margin: 0 auto;
  width: 100%;
}

.ref-slider-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 4px 0;
}

.ref-slider-row .slider {
  flex: 1;
  min-width: 0;
}

.ref-slider-row .slider-label {
  min-width: 48px;
}

/* ---------- 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;
  max-width: 500px;
  margin: 0 auto;
  width: 100%;
}


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

/* ---------- bottom sheet ---------- */
.sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 50;
  backdrop-filter: blur(2px);
}

.sheet-backdrop[hidden] {
  display: none !important;
}

.bottom-sheet {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  max-height: 60vh;
  background: #222;
  border-radius: 16px 16px 0 0;
  z-index: 51;
  display: flex;
  flex-direction: column;
  transition: transform 0.3s ease-out;
}

.bottom-sheet[hidden] {
  display: none !important;
}

.sheet-handle {
  width: 36px;
  height: 4px;
  background: #444;
  border-radius: 2px;
  margin: 8px auto;
  flex-shrink: 0;
}

.sheet-header {
  display: flex;
  align-items: center;
  padding: 4px 16px 12px;
  flex-shrink: 0;
}

.sheet-title {
  font-size: 18px;
  font-weight: 600;
  flex: 1;
}

.sheet-count {
  font-size: 13px;
  color: #888;
  margin-right: 8px;
}

.captures-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 2px;
  padding: 0 2px 16px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.capture-grid-item {
  position: relative;
  aspect-ratio: 4/3;
  background: linear-gradient(90deg, #2a2a2a 25%, #3a3a3a 50%, #2a2a2a 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s ease-in-out infinite;
  border-radius: 4px;
  overflow: hidden;
  cursor: pointer;
}

.capture-grid-item:has(img[src]) {
  animation: none;
  background: #333;
}

.capture-grid-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
}

.capture-grid-spinner {
  width: 20px;
  height: 20px;
  border: 2px solid #444;
  border-top-color: #00d4ff;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.capture-grid-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.capture-grid-item.selected {
  outline: 2px solid #00d4ff;
  outline-offset: -2px;
}

.capture-grid-date {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 2px 4px;
  font-size: 10px;
  color: #fff;
  background: rgba(0,0,0,0.6);
  text-align: center;
}

/* ---------- export menu ---------- */
.export-menu {
  position: absolute;
  bottom: calc(88px + env(safe-area-inset-bottom));
  right: 16px;
  background: #2a2a2a;
  border: 1px solid #444;
  border-radius: 12px;
  overflow: hidden;
  z-index: 40;
  min-width: 200px;
}

.export-menu[hidden] {
  display: none !important;
}

.export-menu-item {
  display: block;
  width: 100%;
  padding: 14px 20px;
  background: none;
  border: none;
  color: #fff;
  font-size: 15px;
  text-align: left;
  cursor: pointer;
}

.export-menu-item:active {
  background: #333;
}

.export-menu-item:not(:last-child) {
  border-bottom: 1px solid #333;
}

.export-menu-item:disabled {
  color: #666;
  pointer-events: none;
}

/* ---------- capture badge ---------- */
.btn-badge {
  position: relative;
}

.badge {
  position: absolute;
  top: -4px;
  right: -4px;
  background: #00d4ff;
  color: #000;
  font-size: 11px;
  font-weight: 600;
  min-width: 18px;
  height: 18px;
  border-radius: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
}

/* ---------- delete toast ---------- */
.delete-toast {
  position: fixed;
  bottom: calc(20px + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  background: #2a2a2a;
  border: 1px solid #444;
  border-radius: 12px;
  padding: 12px 20px;
  display: flex;
  align-items: center;
  gap: 12px;
  z-index: 60;
  font-size: 15px;
}

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

/* ---------- spinner overlay ---------- */
.spinner-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  backdrop-filter: blur(2px);
}

.spinner-box {
  background: #2a2a2a;
  border-radius: 12px;
  padding: 24px 32px;
  text-align: center;
  color: #fff;
  font-size: 15px;
}

.spinner-ring {
  width: 32px;
  height: 32px;
  border: 3px solid #444;
  border-top-color: #00d4ff;
  border-radius: 50%;
  margin: 0 auto 12px;
  animation: spin 0.8s linear infinite;
}

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

@keyframes shimmer {
  0% { background-position: -200% 0; }
  100% { background-position: 200% 0; }
}

/* ---------- 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;
}

/* ---------- GIF progress (legacy, used by export) ---------- */
.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;
}

/* ---------- analysis legend ---------- */
.analysis-legend {
  position: absolute;
  bottom: 8px;
  left: 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  background: rgba(0, 0, 0, 0.65);
  border-radius: 8px;
  padding: 6px 10px;
}

.analysis-legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: #fff;
  white-space: nowrap;
  cursor: pointer;
  padding: 2px 4px;
  border-radius: 4px;
  transition: background 0.15s;
}

.analysis-legend-item:hover,
.analysis-legend-item.active {
  background: rgba(255, 255, 255, 0.2);
}

.analysis-legend-swatch {
  width: 10px;
  height: 10px;
  border-radius: 3px;
  flex-shrink: 0;
}

/* ---------- analysis strip ---------- */
.analysis-strip {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
  padding: 6px 12px;
  max-width: 500px;
  margin: 0 auto;
  width: 100%;
}

.analysis-strip .btn-sm {
  padding: 6px 10px;
  font-size: 12px;
  min-height: 30px;
}

/* ---------- toggle button ---------- */
.btn-toggle {
  transition: background 0.15s;
}

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

/* ---------- responsive ---------- */
@media (min-width: 640px) {
  .captures-grid {
    grid-template-columns: repeat(4, 1fr);
  }
}

@media (min-width: 1024px) {
  .captures-grid {
    grid-template-columns: repeat(6, 1fr);
  }
}

/* ---------- publish form ---------- */
.publish-form {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px;
  max-width: 500px;
  margin: 0 auto;
  width: 100%;
  -webkit-overflow-scrolling: touch;
}

.publish-preview {
  width: 100%;
  height: 160px;
  background: #222;
  border-radius: 12px;
  margin-bottom: 20px;
  background-size: contain;
  background-position: center;
  background-repeat: no-repeat;
}

.publish-label {
  display: block;
  font-size: 13px;
  color: #888;
  margin-bottom: 6px;
  margin-top: 16px;
}

.publish-input {
  width: 100%;
  padding: 12px;
  background: #222;
  border: 1px solid #333;
  border-radius: 8px;
  color: #fff;
  font-size: 16px;
  font-family: inherit;
  -webkit-appearance: none;
  appearance: none;
}

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

select.publish-input {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%23888' fill='none' stroke-width='2'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
}

.publish-dims {
  font-size: 16px;
  color: #ccc;
  padding: 12px;
  background: #222;
  border-radius: 8px;
}

.publish-price-row {
  display: flex;
  gap: 8px;
}

.publish-currency {
  width: 90px;
  flex-shrink: 0;
}

.publish-radio-group {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.publish-radio {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 15px;
  color: #ccc;
  cursor: pointer;
}

.publish-radio input {
  accent-color: #00d4ff;
}

.publish-checkbox {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 15px;
  color: #ccc;
  margin-top: 20px;
  cursor: pointer;
}

.publish-checkbox input {
  accent-color: #00d4ff;
}
