@import url('https://fonts.googleapis.com/css2?family=Outfit:wght@300;400;600;800&display=swap');

:root {
  --bg-dark: #0a0a0f; --bg-panel: rgba(25, 25, 35, 0.65);
  --border-glass: rgba(255, 255, 255, 0.1); --text-primary: #f0f0f5;
  --text-secondary: #9aa0a6; --accent: #6d5dfc; --danger: #f85149;
  --water: #3b82f6; --fire: #ef4444; --acid: #22c55e;
}

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

html, body {
  font-family: 'Outfit', sans-serif; background-color: var(--bg-dark);
  color: var(--text-primary); overflow: hidden; height: 100vh; width: 100vw;
  position: relative;
}

.glass-panel {
  background: var(--bg-panel); backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px); border: 1px solid var(--border-glass);
  border-radius: 16px; box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.3);
}

.canvas-wrapper {
  position: absolute; top: 0; left: 0; width: 100vw; height: 100vh; z-index: 1;
  display: flex; justify-content: center; align-items: center;
  background: radial-gradient(circle at center, #1a1a24 0%, var(--bg-dark) 100%);
  overflow: hidden;
}

canvas {
  touch-action: none; cursor: crosshair; background-color: transparent;
  width: 100%; height: 100%; object-fit: fill;
  max-width: none; max-height: none;
}

.sidebar {
  position: absolute; top: 0; left: 0; z-index: 10;
  width: 320px; height: calc(100vh - 40px); margin: 20px; padding: 24px;
  display: flex; flex-direction: column; gap: 16px;
  animation: slideIn 0.6s cubic-bezier(0.16, 1, 0.3, 1); overflow-y: auto;
}
.sidebar::-webkit-scrollbar { width: 6px; }
.sidebar::-webkit-scrollbar-track { background: transparent; }
.sidebar::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.2); border-radius: 4px; }

.sidebar-header h1 {
  font-size: 24px; font-weight: 800; background: linear-gradient(135deg, #fff 0%, #a5b4fc 100%);
  -webkit-background-clip: text; -webkit-text-fill-color: transparent; margin-bottom: 4px;
}
.sidebar-header p { font-size: 13px; color: var(--text-secondary); }

.lang-toggle-container {
  display: flex; background: rgba(0,0,0,0.3); border-radius: 8px; padding: 4px;
  border: 1px solid var(--border-glass); flex-shrink: 0;
}
.lang-btn {
  flex: 1; background: transparent; border: none; color: var(--text-secondary);
  font-family: inherit; font-weight: 600; padding: 6px 0; border-radius: 4px;
  cursor: pointer; transition: all 0.2s; font-size: 13px;
}
.lang-btn.active { background: var(--text-primary); color: var(--bg-dark); }

.control-group { display: flex; flex-direction: column; gap: 8px; flex-shrink: 0; }
.control-group label {
  font-size: 13px; font-weight: 600; color: var(--text-primary);
  display: flex; justify-content: space-between; border-bottom: 1px solid rgba(255,255,255,0.05); padding-bottom: 2px;
}

input[type=range] { -webkit-appearance: none; width: 100%; background: transparent; }
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none; height: 16px; width: 16px; border-radius: 50%;
  background: var(--accent); cursor: pointer; margin-top: -6px; box-shadow: 0 0 10px var(--accent);
}
input[type=range]::-webkit-slider-runnable-track { width: 100%; height: 4px; cursor: pointer; background: rgba(255,255,255,0.1); border-radius: 2px; }

.btn {
  background: rgba(255,255,255,0.05); border: 1px solid var(--border-glass);
  color: var(--text-primary); padding: 8px 10px; border-radius: 8px;
  font-family: inherit; font-size: 13px; font-weight: 600; cursor: pointer;
  transition: all 0.2s ease; display: flex; align-items: center; justify-content: center; gap: 6px;
}
.btn:hover { background: rgba(255,255,255,0.1); transform: translateY(-1px); }
.btn.active { background: var(--accent); border-color: var(--accent); box-shadow: 0 0 15px rgba(109, 93, 252, 0.4); }
.btn-water.active { background: var(--water); border-color: var(--water); box-shadow: 0 0 15px rgba(59, 130, 246, 0.4); }
.btn-fire.active { background: var(--fire); border-color: var(--fire); box-shadow: 0 0 15px rgba(239, 68, 68, 0.4); }
.btn-acid.active { background: var(--acid); border-color: var(--acid); box-shadow: 0 0 15px rgba(34, 197, 94, 0.4); }
.btn-danger { color: var(--danger); border-color: rgba(248, 81, 73, 0.3); }
.btn-danger:hover { background: rgba(248, 81, 73, 0.1); }
.btn-seed.active { background: #16a34a; border-color: #16a34a; box-shadow: 0 0 15px rgba(22, 163, 74, 0.4); }
.btn-wire.active { background: #ca8a04; border-color: #ca8a04; box-shadow: 0 0 15px rgba(202, 138, 4, 0.4); }
.btn-spark.active { background: #06b6d4; border-color: #06b6d4; box-shadow: 0 0 15px rgba(6, 182, 212, 0.4); color: white; }
.btn-ant.active { background: #6b21a8; border-color: #6b21a8; box-shadow: 0 0 15px rgba(107, 33, 168, 0.4); color: white; }
.btn-c4.active { background: #3f3f46; border-color: #3f3f46; box-shadow: 0 0 15px rgba(63, 63, 70, 0.5); color: white; }
.btn-lava.active { background: #ea580c; border-color: #ea580c; box-shadow: 0 0 15px rgba(234, 88, 12, 0.5); color: white; }
.btn-portalin.active { background: #2563eb; border-color: #2563eb; box-shadow: 0 0 15px rgba(37, 99, 235, 0.5); color: white; }
.btn-portalout.active { background: #f97316; border-color: #f97316; box-shadow: 0 0 15px rgba(249, 115, 22, 0.5); color: white; }
.btn-cloud.active { background: #94a3b8; border-color: #94a3b8; box-shadow: 0 0 15px rgba(148, 163, 184, 0.5); color: white; }
.btn-emitter.active { background: #475569; border-color: #475569; box-shadow: 0 0 15px rgba(71, 85, 105, 0.5); color: white; }
.btn-vortex.active { background: #000000; border-color: #f472b6; box-shadow: 0 0 15px rgba(200, 20, 255, 0.8); color: white; }
.btn-virus.active { background: #16a34a; border-color: #39ff14; box-shadow: 0 0 15px rgba(50, 255, 50, 0.5); color: white; }
.btn-repulsor.active { background: #38bdf8; border-color: #38bdf8; box-shadow: 0 0 15px rgba(56, 189, 248, 0.5); color: white; }
.btn-piano.active { background: #facc15; border-color: #fce7f3; box-shadow: 0 0 15px rgba(250, 204, 21, 0.5); }
.btn-snow.active { background: #f8fafc; border-color: #e2e8f0; box-shadow: 0 0 15px rgba(255, 255, 255, 0.6); color: #0f172a; }
.btn-ice.active { background: #7dd3fc; border-color: #38bdf8; box-shadow: 0 0 15px rgba(125, 211, 252, 0.6); color: #0f172a; }
.btn-sensor.active { background: #818cf8; border-color: #6366f1; box-shadow: 0 0 15px rgba(129, 140, 248, 0.6); color: white; }
.btn-switch.active { background: #9d174d; border-color: #be185d; box-shadow: 0 0 15px rgba(157, 23, 77, 0.6); color: white; }
.btn-laser.active { background: #ef4444; border-color: #fca5a5; box-shadow: 0 0 15px rgba(239, 68, 68, 0.8); color: white; }
.btn-mirror.active { background: #94a3b8; border-color: #e2e8f0; box-shadow: 0 0 15px rgba(148, 163, 184, 0.6); color: white; }
.btn-fish.active { background: #f97316; border-color: #fdba74; box-shadow: 0 0 15px rgba(249, 115, 22, 0.6); color: white; }
.btn-bee.active { background: #eab308; border-color: #fef08a; box-shadow: 0 0 15px rgba(234, 179, 8, 0.6); color: #010101; }
.btn-conveyor.active { background: #64748b; border-color: #94a3b8; box-shadow: 0 0 15px rgba(100, 116, 139, 0.6); color: white; }
.btn-fan.active { background: #6ee7b7; border-color: #a7f3d0; box-shadow: 0 0 15px rgba(110, 231, 183, 0.6); color: #010101; }
.btn-3d { color: #f472b6; border-color: rgba(244, 114, 182, 0.3); }
.btn-3d.active { background: #f472b6; border-color: #f472b6; box-shadow: 0 0 15px rgba(244, 114, 182, 0.4); color: white; }
.btn-audio { color: #facc15; border-color: rgba(250, 204, 21, 0.3); }

.color-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; margin-top: 4px; }
.color-swatch { width: 100%; aspect-ratio: 1; border-radius: 50%; cursor: pointer; border: 2px solid transparent; transition: transform 0.2s ease, border 0.2s ease; }
.color-swatch:hover { transform: scale(1.1); }
.color-swatch.active { border-color: white; transform: scale(1.1); }
.color-picker-custom { width: 100%; height: 35px; padding: 0; border: none; border-radius: 8px; overflow: hidden; cursor: pointer; }
.color-picker-custom::-webkit-color-swatch-wrapper { padding: 0; }
.color-picker-custom::-webkit-color-swatch { border: none; }

.hidden { display: none !important; }

.recording-badge {
  position: absolute; top: 20px; right: 20px; background: rgba(248, 81, 73, 0.2);
  color: var(--danger); padding: 8px 16px; border-radius: 20px; display: flex;
  align-items: center; gap: 8px; font-weight: 600; font-size: 14px; animation: pulse 1.5s infinite; z-index: 20;
}
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(248, 81, 73, 0.4); } 70% { box-shadow: 0 0 0 10px rgba(248, 81, 73, 0); } 100% { box-shadow: 0 0 0 0 rgba(248, 81, 73, 0); } }

input[type="file"] { display: none; }

/* Image HUD */
#image-hud {
  position: absolute; top: 0; left: 0; right: 0; bottom: 0; z-index: 50; 
  display: flex; justify-content: center; align-items: center; background: rgba(0,0,0,0.5);
  backdrop-filter: blur(5px);
}
#image-hud-canvas {
  position: absolute; width: 100%; height: 100%; object-fit: contain;
  max-width: 1200px; max-height: 900px; opacity: 0.9; cursor: grab;
}
#image-hud-canvas:active {
  cursor: grabbing;
}
.hud-controls {
  position: absolute; bottom: 40px; right: 40px; padding: 20px; border-radius: 16px;
  display: flex; flex-direction: column; gap: 12px; width: 300px; z-index: 60;
  box-shadow: 0 10px 40px rgba(0,0,0,0.5);
}
.hud-controls h4 { margin-bottom: 4px; }
.hud-controls label { font-size: 12px; display: flex; justify-content: space-between; }

/* Stencil Library */
#stencil-lib {
  position: absolute; top: 0; left: 0; right: 0; bottom: 0; z-index: 40;
  display: flex; justify-content: center; align-items: center; background: rgba(0,0,0,0.8);
  backdrop-filter: blur(10px);
}
.lib-panel {
  width: 90%; max-width: 800px; max-height: 90%; background: var(--bg-panel);
  border-radius: 16px; border: 1px solid var(--border-glass); padding: 24px;
  display: flex; flex-direction: column; gap: 20px; overflow-y: auto;
}
.lib-section h3 {
  font-size: 18px; margin-bottom: 10px; color: var(--text-secondary);
  border-bottom: 1px solid rgba(255,255,255,0.1); padding-bottom: 5px;
}
.lib-grid {
  display: flex; flex-wrap: wrap; gap: 12px;
}
.lib-item {
  cursor: pointer; transition: transform 0.2s;
  background-color: white; border-radius: 12px;
  width: 90px; height: 90px;
  background-size: cover; background-position: center;
  position: relative; overflow: hidden; border: 2px solid transparent;
}
.lib-title-lb {
  position: absolute; bottom: 0; left: 0; right: 0;
  background: rgba(0,0,0,0.7); color: white;
  font-size: 10px; text-align: center; padding: 2px;
}
.lib-item:hover {
  transform: scale(1.15); border-color: var(--accent); box-shadow: 0 0 15px var(--accent); z-index: 10;
}
