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

body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: #1a1a2e;
  color: #e0e0e0;
  min-height: 100vh;
}

#app {
  max-width: 1100px;
  margin: 0 auto;
  padding: 24px 16px 60px;
}

header {
  text-align: center;
  margin-bottom: 32px;
}

header h1 {
  font-size: 2.2rem;
  font-weight: 800;
  background: linear-gradient(135deg, #f9a825, #e91e63, #7c4dff);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 6px;
}

.subtitle {
  color: #aaa;
  font-size: 1rem;
}

/* Upload Zone */
#drop-zone {
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px dashed #7c4dff;
  border-radius: 16px;
  padding: 48px;
  cursor: pointer;
  background: rgba(124,77,255,0.05);
  transition: all 0.2s;
}
#drop-zone:hover, #drop-zone.drag-over {
  background: rgba(124,77,255,0.12);
  border-color: #e91e63;
}
.drop-inner { display: flex; flex-direction: column; align-items: center; gap: 8px; }
.drop-icon { font-size: 3rem; }
.drop-text { font-size: 1.1rem; font-weight: 600; color: #ccc; }
.drop-hint { font-size: 0.85rem; color: #777; }

/* Workspace */
#workspace { display: flex; flex-direction: column; gap: 20px; }
.hidden { display: none !important; }

#canvas-container {
  position: relative;
  display: inline-block;
  max-width: 100%;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
  cursor: crosshair;
  align-self: center;
}

#main-canvas { display: block; max-width: 100%; }
#overlay-canvas {
  position: absolute; top: 0; left: 0;
  pointer-events: none;
}

/* Magnifier */
#magnifier {
  position: absolute;
  width: 140px; height: 140px;
  border-radius: 50%;
  border: 3px solid #fff;
  box-shadow: 0 4px 20px rgba(0,0,0,0.6);
  pointer-events: none;
  overflow: hidden;
  display: none;
  z-index: 10;
}
#mag-canvas { position: absolute; top: 0; left: 0; }
#mag-crosshair-h {
  position: absolute; top: 50%; left: 0; right: 0;
  height: 1px; background: rgba(255,255,255,0.8);
  transform: translateY(-50%);
}
#mag-crosshair-v {
  position: absolute; left: 50%; top: 0; bottom: 0;
  width: 1px; background: rgba(255,255,255,0.8);
  transform: translateX(-50%);
}

/* Selection rect */
#selection-rect {
  position: absolute;
  border: 2px solid #fff;
  box-shadow: 0 0 0 1px rgba(0,0,0,0.5);
  background: rgba(255,255,255,0.08);
  pointer-events: none;
  z-index: 9;
}

/* Controls */
#controls { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.mode-toggle { display: flex; gap: 8px; }
.mode-btn {
  padding: 10px 22px;
  border: 2px solid #555;
  background: transparent;
  color: #ccc;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.95rem;
  font-weight: 600;
  transition: all 0.2s;
}
.mode-btn.active {
  border-color: #7c4dff;
  background: rgba(124,77,255,0.18);
  color: #fff;
}
.mode-btn:hover:not(.active) { border-color: #888; color: #fff; }
.mode-hint { font-size: 0.85rem; color: #888; text-align: center; }

/* Results */
#results { display: flex; flex-direction: column; gap: 24px; }

#color-hero {
  display: flex;
  gap: 24px;
  align-items: center;
  background: rgba(255,255,255,0.04);
  border-radius: 16px;
  padding: 24px;
  border: 1px solid rgba(255,255,255,0.08);
  flex-wrap: wrap;
}

#color-swatch {
  width: 120px; height: 120px;
  border-radius: 12px;
  flex-shrink: 0;
  box-shadow: 0 4px 20px rgba(0,0,0,0.4);
  border: 2px solid rgba(255,255,255,0.1);
  transition: background-color 0.2s;
}

#color-values { display: flex; flex-direction: column; gap: 8px; flex: 1; min-width: 200px; }
.val-row { display: flex; align-items: center; gap: 12px; }
.val-label {
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  color: #888;
  width: 40px;
  flex-shrink: 0;
}
.val-code {
  font-family: 'Cascadia Code', 'Fira Code', monospace;
  font-size: 0.95rem;
  color: #e0e0e0;
  background: rgba(255,255,255,0.06);
  padding: 4px 10px;
  border-radius: 6px;
}
.val-code.copyable { cursor: pointer; transition: background 0.15s; }
.val-code.copyable:hover { background: rgba(124,77,255,0.3); color: #fff; }

/* Paint Shop Card */
#paint-shop-card {
  background: linear-gradient(135deg, rgba(124,77,255,0.12), rgba(233,30,99,0.08));
  border: 1px solid rgba(124,77,255,0.3);
  border-radius: 16px;
  padding: 24px;
}
#paint-shop-card h3 { margin-bottom: 8px; font-size: 1.1rem; }
.shop-tip { font-size: 0.84rem; color: #999; margin-bottom: 16px; }
.shop-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 12px; }
.shop-item {
  background: rgba(255,255,255,0.05);
  border-radius: 10px;
  padding: 14px;
  border: 1px solid rgba(255,255,255,0.07);
}
.shop-label { font-size: 0.72rem; color: #888; text-transform: uppercase; letter-spacing: 0.08em; margin-bottom: 6px; }
.shop-value { font-size: 0.95rem; font-weight: 600; color: #e0e0e0; font-family: monospace; }

/* Manufacturer Matches */
#manufacturer-matches {
  background: rgba(255,255,255,0.03);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 16px;
  padding: 24px;
}
#manufacturer-matches h3 { margin-bottom: 8px; font-size: 1.1rem; }

#brand-tabs {
  display: flex; gap: 8px; flex-wrap: wrap;
  margin: 16px 0;
}
.brand-tab {
  padding: 6px 14px;
  border: 1px solid #444;
  background: transparent;
  color: #aaa;
  border-radius: 20px;
  cursor: pointer;
  font-size: 0.82rem;
  transition: all 0.2s;
}
.brand-tab.active {
  background: #7c4dff;
  border-color: #7c4dff;
  color: #fff;
}
.brand-tab:hover:not(.active) { border-color: #7c4dff; color: #ccc; }

#matches-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 12px;
}

.match-card {
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid rgba(255,255,255,0.08);
  background: rgba(255,255,255,0.03);
  transition: transform 0.15s, box-shadow 0.15s;
}
.match-card:hover { transform: translateY(-2px); box-shadow: 0 6px 20px rgba(0,0,0,0.4); }
.match-swatch { height: 64px; }
.match-info { padding: 10px 12px; }
.match-brand { font-size: 0.7rem; color: #888; text-transform: uppercase; letter-spacing: 0.08em; margin-bottom: 2px; }
.match-name { font-size: 0.9rem; font-weight: 600; color: #e0e0e0; margin-bottom: 2px; }
.match-code { font-size: 0.78rem; color: #aaa; font-family: monospace; }
.match-delta { font-size: 0.72rem; color: #888; margin-top: 4px; }
.delta-dot {
  display: inline-block;
  width: 8px; height: 8px;
  border-radius: 50%;
  margin-right: 4px;
}

/* Toast */
#toast {
  position: fixed;
  bottom: 30px; left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: #7c4dff;
  color: #fff;
  padding: 10px 24px;
  border-radius: 30px;
  font-size: 0.9rem;
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  transition: all 0.3s;
  z-index: 9999;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

@media (max-width: 600px) {
  header h1 { font-size: 1.6rem; }
  #color-hero { flex-direction: column; align-items: flex-start; }
  #color-swatch { width: 80px; height: 80px; }
}
