/* LEGO Piece Finder - Mobile-First Styles */
:root {
  --bg-primary: #0f172a;
  --bg-secondary: #1e293b;
  --bg-card: #334155;
  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --accent: #f59e0b;
  --accent-hover: #d97706;
  --success: #22c55e;
  --warning: #eab308;
  --info: #3b82f6;
  --danger: #ef4444;
  --match-high: #3b82f6;
  --match-good: #22c55e;
  --match-possible: #eab308;
  --radius: 12px;
  --shadow: 0 4px 20px rgba(0,0,0,0.3);
}

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

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  overflow-x: hidden;
  -webkit-text-size-adjust: 100%;
}

body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: -webkit-fill-available;
}

/* Header */
.header {
  background: var(--bg-secondary);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  border-bottom: 2px solid var(--accent);
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-logo {
  font-size: 28px;
  line-height: 1;
}

.header h1 {
  font-size: 18px;
  font-weight: 700;
  color: var(--accent);
}

.header-back {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 24px;
  cursor: pointer;
  padding: 4px 8px;
  display: none;
}

/* Main Content */
.main {
  flex: 1;
  padding: 16px;
  max-width: 600px;
  margin: 0 auto;
  width: 100%;
}

/* Screens */
.screen { display: none; }
.screen.active { display: block; }

/* Step Indicator */
.steps {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-bottom: 20px;
  padding: 12px 0;
}

.step {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 14px;
  background: var(--bg-card);
  color: var(--text-secondary);
  transition: all 0.3s;
}

.step.active {
  background: var(--accent);
  color: var(--bg-primary);
  transform: scale(1.1);
}

.step.done {
  background: var(--success);
  color: white;
}

.step-line {
  width: 30px;
  height: 2px;
  background: var(--bg-card);
  align-self: center;
}

.step-line.done { background: var(--success); }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 14px 24px;
  border: none;
  border-radius: var(--radius);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  width: 100%;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.btn-primary {
  background: var(--accent);
  color: var(--bg-primary);
}
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:active { transform: scale(0.98); }
.btn-primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-secondary {
  background: var(--bg-card);
  color: var(--text-primary);
}

.btn-outline {
  background: transparent;
  color: var(--accent);
  border: 2px solid var(--accent);
}

.btn-sm {
  padding: 8px 16px;
  font-size: 14px;
  width: auto;
}

/* Cards */
.card {
  background: var(--bg-secondary);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}

.card-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 12px;
}

/* Home Screen */
.hero {
  text-align: center;
  padding: 30px 0;
}

.hero-icon {
  font-size: 80px;
  margin-bottom: 16px;
}

.hero h2 {
  font-size: 24px;
  margin-bottom: 8px;
}

.hero p {
  color: var(--text-secondary);
  margin-bottom: 24px;
  line-height: 1.5;
}

.feature-list {
  list-style: none;
  text-align: left;
  margin: 20px 0;
}

.feature-list li {
  padding: 8px 0;
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text-secondary);
}

.feature-list li .icon {
  font-size: 20px;
  width: 28px;
  text-align: center;
}

/* Image Capture */
.capture-area {
  border: 3px dashed var(--bg-card);
  border-radius: var(--radius);
  padding: 40px 20px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s;
  margin-bottom: 16px;
  min-height: 200px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.capture-area:hover { border-color: var(--accent); }
.capture-area.has-image {
  padding: 0;
  border-style: solid;
  border-color: var(--accent);
  overflow: hidden;
}

.capture-area img {
  max-width: 100%;
  max-height: 400px;
  object-fit: contain;
}

.capture-icon { font-size: 48px; margin-bottom: 12px; }
.capture-text { color: var(--text-secondary); font-size: 14px; }

.capture-buttons {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

.capture-buttons .btn { flex: 1; }

/* Cropper */
.crop-container {
  position: relative;
  width: 100%;
  max-height: 60vh;
  overflow: hidden;
  border-radius: var(--radius);
  background: #000;
  touch-action: none;
  margin-bottom: 16px;
}

.crop-container img {
  display: block;
  max-width: 100%;
  max-height: 60vh;
  margin: 0 auto;
}

.crop-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  pointer-events: none;
}

.crop-box {
  position: absolute;
  border: 3px solid var(--accent);
  box-shadow: 0 0 0 9999px rgba(0,0,0,0.6);
  pointer-events: auto;
  cursor: move;
  touch-action: none;
  min-width: 40px;
  min-height: 40px;
}

.crop-handle {
  position: absolute;
  width: 24px;
  height: 24px;
  background: var(--accent);
  border-radius: 50%;
  pointer-events: auto;
  touch-action: none;
}

.crop-handle.tl { top: -12px; left: -12px; cursor: nw-resize; }
.crop-handle.tr { top: -12px; right: -12px; cursor: ne-resize; }
.crop-handle.bl { bottom: -12px; left: -12px; cursor: sw-resize; }
.crop-handle.br { bottom: -12px; right: -12px; cursor: se-resize; }

/* Analysis Panel */
.analysis-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
}

.analysis-row {
  display: flex;
  justify-content: space-between;
  padding: 6px 0;
  border-bottom: 1px solid rgba(255,255,255,0.1);
}

.analysis-row:last-child { border: none; }
.analysis-label { color: var(--text-secondary); font-size: 14px; }
.analysis-value { font-weight: 600; font-size: 14px; }

.color-swatch {
  display: inline-block;
  width: 16px;
  height: 16px;
  border-radius: 4px;
  vertical-align: middle;
  margin-right: 6px;
  border: 1px solid rgba(255,255,255,0.3);
}

/* Results */
.results-canvas-wrap {
  position: relative;
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 16px;
  background: #000;
}

.results-canvas-wrap canvas {
  display: block;
  width: 100%;
  height: auto;
}

.match-legend {
  display: flex;
  gap: 16px;
  justify-content: center;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-secondary);
}

.legend-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
}

.match-list {
  list-style: none;
}

.match-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  background: var(--bg-card);
  border-radius: 8px;
  margin-bottom: 8px;
  cursor: pointer;
  transition: all 0.2s;
}

.match-item:hover { background: #475569; }

.match-badge {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 13px;
  color: white;
  flex-shrink: 0;
}

.match-badge.high { background: var(--match-high); }
.match-badge.good { background: var(--match-good); }
.match-badge.possible { background: var(--match-possible); }

.match-info { flex: 1; }
.match-confidence { font-weight: 700; font-size: 15px; }
.match-reason { font-size: 13px; color: var(--text-secondary); margin-top: 2px; }

.no-matches {
  text-align: center;
  padding: 30px;
  color: var(--text-secondary);
}

.no-matches .icon { font-size: 48px; margin-bottom: 12px; }

/* Progress */
.progress-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(15,23,42,0.9);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 200;
  flex-direction: column;
  gap: 16px;
}

.progress-overlay.active { display: flex; }

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

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

.progress-text {
  color: var(--text-secondary);
  font-size: 16px;
  text-align: center;
}

/* Tips */
.tips {
  background: rgba(59,130,246,0.1);
  border: 1px solid rgba(59,130,246,0.3);
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 16px;
}

.tips-title {
  font-weight: 700;
  font-size: 14px;
  color: var(--info);
  margin-bottom: 6px;
}

.tips ul {
  list-style: none;
  font-size: 13px;
  color: var(--text-secondary);
}

.tips li {
  padding: 2px 0;
}

.tips li::before {
  content: '💡 ';
}

/* Camera Stream */
.camera-container {
  position: relative;
  border-radius: var(--radius);
  overflow: hidden;
  background: #000;
  margin-bottom: 16px;
}

.camera-container video {
  display: block;
  width: 100%;
  max-height: 60vh;
  object-fit: cover;
}

.camera-shutter {
  position: absolute;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: white;
  border: 4px solid var(--accent);
  cursor: pointer;
  transition: all 0.1s;
}

.camera-shutter:active {
  transform: translateX(-50%) scale(0.9);
  background: var(--accent);
}

/* Responsive */
@media (min-width: 768px) {
  .main { padding: 24px; }
  .hero-icon { font-size: 100px; }
  .hero h2 { font-size: 28px; }
}

/* Safe area for iPhone notch */
@supports (padding-top: env(safe-area-inset-top)) {
  .header { padding-top: calc(12px + env(safe-area-inset-top)); }
  body { padding-bottom: env(safe-area-inset-bottom); }
}

/* Hidden utility */
.hidden { display: none !important; }
